From: Dave Hansen <dave.hansen@intel.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>, linux-mm@kvack.org
Cc: linux-arch@vger.kernel.org, x86@kernel.org,
linux-s390@vger.kernel.org, sparclinux@vger.kernel.org,
linux-um@lists.infradead.org
Subject: Re: [PATCH 4/7] x86: Remove custom definition of mk_pte()
Date: Wed, 19 Feb 2025 12:53:41 -0800 [thread overview]
Message-ID: <940c4972-fad0-4d61-a7ce-1c5d52891a5e@intel.com> (raw)
In-Reply-To: <20250217190836.435039-5-willy@infradead.org>
On 2/17/25 11:08, Matthew Wilcox (Oracle) wrote:
> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
> index 593f10aabd45..9f480bdafd20 100644
> --- a/arch/x86/include/asm/pgtable.h
> +++ b/arch/x86/include/asm/pgtable.h
> @@ -784,6 +784,9 @@ static inline pgprotval_t check_pgprot(pgprot_t pgprot)
> static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
> {
> phys_addr_t pfn = (phys_addr_t)page_nr << PAGE_SHIFT;
> + /* This bit combination is used to mark shadow stacks */
> + WARN_ON_ONCE((pgprot_val(pgprot) & (_PAGE_DIRTY | _PAGE_RW)) ==
> + _PAGE_DIRTY);
Looks sane to me. Good riddance to unnecessary arch-specific code.
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Just one note (in case anyone ever trips over that WARN_ON_ONCE()): This
is a problem with the existing code and with your patch, but the
'pgprot' going to mk_pte() or pfn_pte() probably can't come from a
hardware PTE that has the dirty bit clear.
Old, pre-shadow-stack hardware could race between:
1. Software transitioning _PAGE_RW 1=>0
2. The CPU page walker trying to set
_PAGE_DIRTY in response to a write
and end up with a Write=0,Dirty=1 PTE.
That doesn't happen for kernel memory because most or all of the PTEs
that the kernel establishes have _PAGE_DIRTY=1 so the page walker never
tries to set _PAGE_DIRTY. It's also generally some kind of a bug if one
CPU is in the kernel trying to write to a page while another is making
the page read-only.
Anyway, I can basically see cases where this warning might trip, but
it's very likely on older hardware when the kernel is doing something
else silly.
next prev parent reply other threads:[~2025-02-19 21:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 19:08 [PATCH 0/7] Add folio_mk_pte() and simplify mk_pte() Matthew Wilcox (Oracle)
2025-02-17 19:08 ` [PATCH 1/7] mm: Set the pte dirty if the folio is already dirty Matthew Wilcox (Oracle)
2025-02-18 10:31 ` David Hildenbrand
2025-02-18 16:20 ` Alexander Gordeev
2025-02-18 17:06 ` Matthew Wilcox
2025-02-19 7:27 ` Alexander Gordeev
2025-02-19 7:33 ` Alexander Gordeev
2025-02-19 8:46 ` Alexander Gordeev
2025-02-17 19:08 ` [PATCH 2/7] mm: Introduce a common definition of mk_pte() Matthew Wilcox (Oracle)
2025-02-18 8:15 ` Geert Uytterhoeven
2025-02-18 10:32 ` David Hildenbrand
2025-02-19 9:07 ` Alexander Gordeev
2025-02-17 19:08 ` [PATCH 3/7] sparc32: Remove custom " Matthew Wilcox (Oracle)
2025-02-17 19:08 ` [PATCH 4/7] x86: " Matthew Wilcox (Oracle)
2025-02-19 20:53 ` Dave Hansen [this message]
2025-02-17 19:08 ` [PATCH 5/7] um: " Matthew Wilcox (Oracle)
2025-02-17 19:08 ` [PATCH 6/7] mm: Make mk_pte() definition unconditional Matthew Wilcox (Oracle)
2025-02-18 10:32 ` David Hildenbrand
2025-02-17 19:08 ` [PATCH 7/7] mm: Add folio_mk_pte() Matthew Wilcox (Oracle)
2025-02-18 10:33 ` David Hildenbrand
2025-02-18 10:29 ` [PATCH 0/7] Add folio_mk_pte() and simplify mk_pte() David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=940c4972-fad0-4d61-a7ce-1c5d52891a5e@intel.com \
--to=dave.hansen@intel.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=sparclinux@vger.kernel.org \
--cc=willy@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).