From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Guenter Roeck <linux@roeck-us.net>, Jens Axboe <axboe@kernel.dk>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Peter Anvin <hpa@zytor.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
the arch/x86 maintainers <x86@kernel.org>
Subject: Re: Linux 6.11-rc1
Date: Wed, 31 Jul 2024 23:20:07 +0200 [thread overview]
Message-ID: <20240731212007.GW26599@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <87bk2d5v83.ffs@tglx>
On Wed, Jul 31, 2024 at 07:26:04PM +0200, Thomas Gleixner wrote:
> On Wed, Jul 31 2024 at 18:51, Peter Zijlstra wrote:
> > On Wed, Jul 31, 2024 at 06:31:05PM +0200, Peter Zijlstra wrote:
> > Thomas, this all still relies on the full text section being PMD mapped,
> > and since we don't have ALIGN_ENTRY_TEXT_END and _etext has PAGE_SIZE
> > alignment, can't have a PAGE mapped tail which then doesn't get cloned?
> >
> > Do we want to make pto_clone_entry_text() use PTI_LEVEL_KERNEL_IMAGE
> > such that it will clone whatever it has?
>
> Yes, I think so.
The alternative is ripping that level thing out entirely, and simply
duplicate anything we find in the page-tables.
We could add something like:
WARN_ON_ONCE(IS_ENABLED(CONFIG_X86_64));
in the PTE path, but do we really care?
---
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -47,16 +47,6 @@
#define __GFP_NOTRACK 0
#endif
-/*
- * Define the page-table levels we clone for user-space on 32
- * and 64 bit.
- */
-#ifdef CONFIG_X86_64
-#define PTI_LEVEL_KERNEL_IMAGE PTI_CLONE_PMD
-#else
-#define PTI_LEVEL_KERNEL_IMAGE PTI_CLONE_PTE
-#endif
-
static void __init pti_print_if_insecure(const char *reason)
{
if (boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
@@ -294,14 +284,7 @@ static void __init pti_setup_vsyscall(vo
static void __init pti_setup_vsyscall(void) { }
#endif
-enum pti_clone_level {
- PTI_CLONE_PMD,
- PTI_CLONE_PTE,
-};
-
-static void
-pti_clone_pgtable(unsigned long start, unsigned long end,
- enum pti_clone_level level)
+static void pti_clone_pgtable(unsigned long start, unsigned long end)
{
unsigned long addr;
@@ -341,7 +324,7 @@ pti_clone_pgtable(unsigned long start, u
continue;
}
- if (pmd_leaf(*pmd) || level == PTI_CLONE_PMD) {
+ if (pmd_leaf(*pmd)) {
target_pmd = pti_user_pagetable_walk_pmd(addr);
if (WARN_ON(!target_pmd))
return;
@@ -375,37 +358,33 @@ pti_clone_pgtable(unsigned long start, u
*target_pmd = *pmd;
addr = round_up(addr + 1, PMD_SIZE);
+ continue;
+ }
- } else if (level == PTI_CLONE_PTE) {
-
- /* Walk the page-table down to the pte level */
- pte = pte_offset_kernel(pmd, addr);
- if (pte_none(*pte)) {
- addr = round_up(addr + 1, PAGE_SIZE);
- continue;
- }
-
- /* Only clone present PTEs */
- if (WARN_ON(!(pte_flags(*pte) & _PAGE_PRESENT)))
- return;
+ /* Walk the page-table down to the pte level */
+ pte = pte_offset_kernel(pmd, addr);
+ if (pte_none(*pte)) {
+ addr = round_up(addr + 1, PAGE_SIZE);
+ continue;
+ }
- /* Allocate PTE in the user page-table */
- target_pte = pti_user_pagetable_walk_pte(addr);
- if (WARN_ON(!target_pte))
- return;
+ /* Only clone present PTEs */
+ if (WARN_ON(!(pte_flags(*pte) & _PAGE_PRESENT)))
+ return;
- /* Set GLOBAL bit in both PTEs */
- if (boot_cpu_has(X86_FEATURE_PGE))
- *pte = pte_set_flags(*pte, _PAGE_GLOBAL);
+ /* Allocate PTE in the user page-table */
+ target_pte = pti_user_pagetable_walk_pte(addr);
+ if (WARN_ON(!target_pte))
+ return;
- /* Clone the PTE */
- *target_pte = *pte;
+ /* Set GLOBAL bit in both PTEs */
+ if (boot_cpu_has(X86_FEATURE_PGE))
+ *pte = pte_set_flags(*pte, _PAGE_GLOBAL);
- addr = round_up(addr + 1, PAGE_SIZE);
+ /* Clone the PTE */
+ *target_pte = *pte;
- } else {
- BUG();
- }
+ addr = round_up(addr + 1, PAGE_SIZE);
}
}
@@ -475,7 +454,7 @@ static void __init pti_clone_user_shared
start = CPU_ENTRY_AREA_BASE;
end = start + (PAGE_SIZE * CPU_ENTRY_AREA_PAGES);
- pti_clone_pgtable(start, end, PTI_CLONE_PMD);
+ pti_clone_pgtable(start, end);
}
#endif /* CONFIG_X86_64 */
@@ -495,8 +474,7 @@ static void __init pti_setup_espfix64(vo
static void pti_clone_entry_text(void)
{
pti_clone_pgtable((unsigned long) __entry_text_start,
- (unsigned long) __entry_text_end,
- PTI_CLONE_PMD);
+ (unsigned long) __entry_text_end);
}
/*
@@ -571,7 +549,7 @@ static void pti_clone_kernel_text(void)
* pti_set_kernel_image_nonglobal() did to clear the
* global bit.
*/
- pti_clone_pgtable(start, end_clone, PTI_LEVEL_KERNEL_IMAGE);
+ pti_clone_pgtable(start, end_clone);
/*
* pti_clone_pgtable() will set the global bit in any PMDs
next prev parent reply other threads:[~2024-07-31 21:20 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-28 21:40 Linux 6.11-rc1 Linus Torvalds
2024-07-29 9:28 ` Build regressions/improvements in v6.11-rc1 Geert Uytterhoeven
2024-07-29 9:35 ` Geert Uytterhoeven
2024-07-29 9:54 ` Arnd Bergmann
2024-07-29 10:07 ` Geert Uytterhoeven
2024-07-29 15:29 ` Linux 6.11-rc1 Guenter Roeck
2024-07-29 19:23 ` Linus Torvalds
2024-07-29 19:50 ` Linus Torvalds
2024-07-29 21:34 ` Arnd Bergmann
2024-07-29 23:47 ` Linus Torvalds
2024-07-30 15:47 ` Arnd Bergmann
2024-07-30 7:54 ` Peter Zijlstra
2024-07-31 15:45 ` Guenter Roeck
2024-07-30 17:04 ` Guenter Roeck
2024-07-30 17:20 ` Jens Axboe
2024-07-30 18:22 ` Guenter Roeck
2024-07-30 18:35 ` Jens Axboe
2024-07-30 18:54 ` Jens Axboe
2024-07-30 18:53 ` Linus Torvalds
2024-07-30 19:22 ` Peter Zijlstra
2024-07-30 19:31 ` Jens Axboe
2024-07-30 19:34 ` Jens Axboe
2024-07-30 19:38 ` Peter Zijlstra
2024-07-30 19:41 ` Linus Torvalds
2024-07-30 20:04 ` Guenter Roeck
2024-07-30 20:09 ` Peter Zijlstra
2024-07-30 21:12 ` Peter Zijlstra
2024-07-30 23:29 ` Guenter Roeck
2024-07-30 23:54 ` Linus Torvalds
2024-07-31 8:21 ` Borislav Petkov
2024-07-31 9:11 ` Peter Zijlstra
2024-07-31 10:02 ` Borislav Petkov
2024-07-31 14:37 ` Guenter Roeck
2024-07-31 13:24 ` Jens Axboe
2024-07-30 20:13 ` Linus Torvalds
2024-07-30 20:24 ` Guenter Roeck
2024-07-31 12:20 ` Peter Zijlstra
2024-07-31 13:03 ` Thomas Gleixner
2024-07-31 15:55 ` Peter Zijlstra
2024-07-31 16:17 ` Linus Torvalds
2024-07-31 16:31 ` Peter Zijlstra
2024-07-31 16:50 ` Guenter Roeck
2024-07-31 16:51 ` Peter Zijlstra
2024-07-31 17:26 ` Thomas Gleixner
2024-07-31 21:20 ` Peter Zijlstra [this message]
2024-07-31 21:23 ` Linus Torvalds
2024-07-31 21:26 ` Peter Zijlstra
2024-07-31 21:41 ` Linus Torvalds
2024-07-31 21:47 ` Thomas Gleixner
2024-07-31 22:22 ` Guenter Roeck
2024-08-01 8:54 ` Peter Zijlstra
2024-08-01 10:55 ` [tip: x86/urgent] x86/mm: Fix pti_clone_pgtable() alignment assumption tip-bot2 for Peter Zijlstra
2024-08-01 13:03 ` tip-bot2 for Peter Zijlstra
2024-07-31 16:49 ` Linux 6.11-rc1 Guenter Roeck
2024-07-31 17:19 ` Thomas Gleixner
2024-07-31 10:33 ` Peter Zijlstra
2024-07-31 14:15 ` Peter Zijlstra
2024-08-02 17:35 ` Linus Walleij
2024-08-02 19:40 ` Guenter Roeck
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=20240731212007.GW26599@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=axboe@kernel.dk \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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