From: David Woodhouse <dwmw2@infradead.org>
To: "Dave Hansen" <dave.hansen@intel.com>,
kexec@lists.infradead.org, "Schönherr,
Jan H." <jschoenh@amazon.de>, "Rik van Riel" <riel@surriel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Kai Huang <kai.huang@intel.com>,
Nikolay Borisov <nik.borisov@suse.com>,
linux-kernel@vger.kernel.org, Simon Horman <horms@kernel.org>,
Dave Young <dyoung@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
jpoimboe@kernel.org, bsz@amazon.de
Subject: Re: [RFC PATCH] x86/mm: Disable PTI for kernel_ident_mapping_init()
Date: Tue, 26 Nov 2024 11:42:04 +0000 [thread overview]
Message-ID: <0c8fe87b34252966ecf558271b09c4b855700691.camel@infradead.org> (raw)
In-Reply-To: <5633d50d-0d61-4d18-b43f-11311b5ec920@intel.com>
[-- Attachment #1: Type: text/plain, Size: 4061 bytes --]
On Mon, 2024-11-25 at 11:13 -0800, Dave Hansen wrote:
> On 11/25/24 10:53, David Woodhouse wrote:
> > > I think we have a lot of software-available space in the page table
> > > pointer entries. What would folks think if we set a special bit in those
> > > p4d entries that said:
> > >
> > > "I don't need to be propagated to
> > > the user portion of the page tables."
> > >
> > > It would obviously get set in this code that you're trying to fix. It
> > > might _also_ be able to be set in in "_USR", like here:
> > >
> > > #define _KERNPG_TABLE_NOENC (__PP|__RW| 0|___A| 0|___D| 0| 0)
> > > #define _PAGE_TABLE_NOENC (__PP|__RW|_USR|___A| 0|___D| 0| 0)
> > >
> > > like:
> > >
> > > #define _USR _PAGE_USER|_PAGE_SW_WHATEVER
> > In fact, do we even need a separate bit? Any PTE without the _PAGE_USER
> > bit set clearly doesn't need to be mirrored into the user page
> > tables...?
>
> I can't think of any exceptions where this would break off the top of my
> head. It seems too simple to work. ;)
On IRC we discussed the fact that it's slightly non-trivial to use that
as the trigger for pgd_clear().
I threw this version together and it didn't immediately explode...
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
index 6f82e75b6149..4b804531b03c 100644
--- a/arch/x86/include/asm/pgtable_types.h
+++ b/arch/x86/include/asm/pgtable_types.h
@@ -36,10 +36,12 @@
#define _PAGE_BIT_DEVMAP _PAGE_BIT_SOFTW4
#ifdef CONFIG_X86_64
-#define _PAGE_BIT_SAVED_DIRTY _PAGE_BIT_SOFTW5 /* Saved Dirty bit */
+#define _PAGE_BIT_SAVED_DIRTY _PAGE_BIT_SOFTW5 /* Saved Dirty bit (leaf) */
+#define _PAGE_BIT_NOPTISHADOW _PAGE_BIT_SOFTW5 /* No PTI shadow (root PGD) */
#else
/* Shared with _PAGE_BIT_UFFD_WP which is not supported on 32 bit */
-#define _PAGE_BIT_SAVED_DIRTY _PAGE_BIT_SOFTW2 /* Saved Dirty bit */
+#define _PAGE_BIT_SAVED_DIRTY _PAGE_BIT_SOFTW2 /* Saved Dirty bit (leaf) */
+#define _PAGE_BIT_NOPTISHADOW _PAGE_BIT_SOFTW2 /* No PTI shadow (root PGD) */
#endif
/* If _PAGE_BIT_PRESENT is clear, we use these: */
@@ -139,6 +141,8 @@
#define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)
+#define _PAGE_NOPTISHADOW (_AT(pteval_t, 1) << _PAGE_BIT_NOPTISHADOW)
+
/*
* Set of bits not changed in pte_modify. The pte's
* protection key is treated like _PAGE_RW, for
diff --git a/arch/x86/mm/ident_map.c b/arch/x86/mm/ident_map.c
index 437e96fb4977..5ab7bd2f1983 100644
--- a/arch/x86/mm/ident_map.c
+++ b/arch/x86/mm/ident_map.c
@@ -174,7 +174,7 @@ static int ident_p4d_init(struct x86_mapping_info *info, p4d_t *p4d_page,
if (result)
return result;
- set_p4d(p4d, __p4d(__pa(pud) | info->kernpg_flag));
+ set_p4d(p4d, __p4d(__pa(pud) | info->kernpg_flag | _PAGE_NOPTISHADOW));
}
return 0;
@@ -218,14 +218,14 @@ int kernel_ident_mapping_init(struct x86_mapping_info *info, pgd_t *pgd_page,
if (result)
return result;
if (pgtable_l5_enabled()) {
- set_pgd(pgd, __pgd(__pa(p4d) | info->kernpg_flag));
+ set_pgd(pgd, __pgd(__pa(p4d) | info->kernpg_flag | _PAGE_NOPTISHADOW));
} else {
/*
* With p4d folded, pgd is equal to p4d.
* The pgd entry has to point to the pud page table in this case.
*/
pud_t *pud = pud_offset(p4d, 0);
- set_pgd(pgd, __pgd(__pa(pud) | info->kernpg_flag));
+ set_pgd(pgd, __pgd(__pa(pud) | info->kernpg_flag | _PAGE_NOPTISHADOW));
}
}
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index 851ec8f1363a..5f0d579932c6 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -132,7 +132,7 @@ pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd)
* Top-level entries added to init_mm's usermode pgd after boot
* will not be automatically propagated to other mms.
*/
- if (!pgdp_maps_userspace(pgdp))
+ if (!pgdp_maps_userspace(pgdp) || (pgd.pgd & _PAGE_NOPTISHADOW))
return pgd;
/*
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5965 bytes --]
next prev parent reply other threads:[~2024-11-26 11:42 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 9:54 [RFC PATCH v3 00/20] x86/kexec: Add exception handling for relocate_kernel and further yak-shaving David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 01/20] x86/kexec: Ensure control_code_page is mapped in kexec page tables David Woodhouse
2024-11-25 10:29 ` [EXTERNAL] " David Woodhouse
2024-11-25 13:19 ` David Woodhouse
2024-11-25 17:05 ` [RFC PATCH] x86/mm: Disable PTI for kernel_ident_mapping_init() David Woodhouse
2024-11-25 18:31 ` Dave Hansen
2024-11-25 18:53 ` David Woodhouse
2024-11-25 19:13 ` Dave Hansen
2024-11-25 19:36 ` David Woodhouse
2024-11-26 11:42 ` David Woodhouse [this message]
2024-11-26 15:49 ` Dave Hansen
2024-11-26 16:09 ` David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 02/20] x86/kexec: Restore GDT on return from preserve_context kexec David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 03/20] x86/kexec: Clean up and document register use in relocate_kernel_64.S David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 04/20] x86/kexec: Use named labels in swap_pages " David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 05/20] x86/kexec: Only swap pages for preserve_context mode David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 06/20] x86/kexec: Allocate PGD for x86_64 transition page tables separately David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 07/20] x86/kexec: Copy control page into place in machine_kexec_prepare() David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 08/20] x86/kexec: Invoke copy of relocate_kernel() instead of the original David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 09/20] x86/kexec: Move relocate_kernel to kernel .data section David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 10/20] x86/kexec: Add data section to relocate_kernel David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 11/20] x86/kexec: Drop page_list argument from relocate_kernel() David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 12/20] x86/kexec: Eliminate writes through kernel mapping of relocate_kernel page David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 13/20] x86/kexec: Clean up register usage in relocate_kernel() David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 14/20] x86/kexec: Mark relocate_kernel page as ROX instead of RWX David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 15/20] x86/kexec: Add CONFIG_KEXEC_DEBUG option David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 16/20] x86/kexec: Debugging support: load a GDT David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 17/20] x86/kexec: Debugging support: Load an IDT and basic exception entry points David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 18/20] x86/kexec: Debugging support: Dump registers on exception David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 19/20] x86/kexec: Add 8250 serial port output David Woodhouse
2024-11-25 9:54 ` [RFC PATCH v3 20/20] [DO NOT MERGE] x86/kexec: Add int3 in kexec path for testing David Woodhouse
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=0c8fe87b34252966ecf558271b09c4b855700691.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=bp@alien8.de \
--cc=bsz@amazon.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dyoung@redhat.com \
--cc=horms@kernel.org \
--cc=hpa@zytor.com \
--cc=jpoimboe@kernel.org \
--cc=jschoenh@amazon.de \
--cc=kai.huang@intel.com \
--cc=kexec@lists.infradead.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nik.borisov@suse.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®