mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] x86: Robustify pgtable_l5_enabled()
@ 2025-05-06 15:45 Ard Biesheuvel
  2025-05-06 15:45 ` [RFC PATCH 1/3] x86/boot: Use a single source of truth for pgtable_l5_enabled() Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Ard Biesheuvel @ 2025-05-06 15:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Ard Biesheuvel, Ingo Molnar, Linus Torvalds

From: Ard Biesheuvel <ardb@kernel.org>

This is a follow-up to the discussion at [0], broken out of that series
so we can progress while the SEV are being reviewed and tested.

The current implementation of pgtable_l5_enabled() is a bit problematic
because it has two implementations, and source files need to opt into
the correct one if they contain code that might be called very early.

pgtable_l5_enabled() is widely used in functions for control flow, but
also hidden in global expressions exposed via all caps macros, which
typically denote true constants, and not expressions that change value
based on whether some global variable is set.

So merge the two definitions into a single one that always produces the
correct value and is as efficient as the runtime one it replace. Then,
set the underlying __pgtable_l5_enabled variable before calling into C
code, so that inconsistencies are no longer possible.

Finally, replace some of these global expressions with an ALTERNATIVE()
based selector that does not use control flow to choose between the
values used for 4-level and 5-level paging.

Build and boot tested using QEMU with LA57 emulation.

[0] https://lore.kernel.org/all/20250504095230.2932860-28-ardb+git@google.com/

Cc: Ingo Molnar <mingo@kernel.org>
cc: Linus Torvalds <torvalds@linux-foundation.org>

Ard Biesheuvel (3):
  x86/boot: Use a single source of truth for pgtable_l5_enabled()
  x86/boot: Set __pgtable_l5_enabled correctly before calling into C
    code
  x86/boot: Use alternatives based selector for 5-level paging constants

 arch/x86/boot/compressed/head_64.S      |  6 +++
 arch/x86/boot/compressed/misc.h         |  3 --
 arch/x86/boot/compressed/pgtable_64.c   |  6 +--
 arch/x86/boot/compressed/vmlinux.lds.S  |  2 +
 arch/x86/boot/startup/map_kernel.c      |  1 -
 arch/x86/boot/startup/sme.c             |  9 ----
 arch/x86/include/asm/page_64_types.h    |  2 +-
 arch/x86/include/asm/pgtable_64_types.h | 54 +++++++++++++++-----
 arch/x86/kernel/alternative.c           | 12 -----
 arch/x86/kernel/cpu/common.c            |  2 -
 arch/x86/kernel/head64.c                |  5 +-
 arch/x86/kernel/head_64.S               |  7 +++
 arch/x86/mm/kasan_init_64.c             |  3 --
 13 files changed, 61 insertions(+), 51 deletions(-)


base-commit: ed4d95d033e359f9445e85bf5a768a5859a5830b
-- 
2.49.0.987.g0cc8ee98dc-goog


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2025-05-10 14:51 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-06 15:45 [RFC PATCH 0/3] x86: Robustify pgtable_l5_enabled() Ard Biesheuvel
2025-05-06 15:45 ` [RFC PATCH 1/3] x86/boot: Use a single source of truth for pgtable_l5_enabled() Ard Biesheuvel
2025-05-06 15:45 ` [RFC PATCH 2/3] x86/boot: Set __pgtable_l5_enabled correctly before calling into C code Ard Biesheuvel
2025-05-10 13:54   ` David Laight
2025-05-10 14:51     ` Ard Biesheuvel
2025-05-06 15:45 ` [RFC PATCH 3/3] x86/boot: Use alternatives based selector for 5-level paging constants Ard Biesheuvel
2025-05-06 16:23   ` Linus Torvalds
2025-05-06 16:34     ` Ard Biesheuvel
2025-05-06 17:03       ` Linus Torvalds
2025-05-06 17:25         ` Ard Biesheuvel
2025-05-06 17:39           ` Ingo Molnar
2025-05-06 17:47             ` Ard Biesheuvel
2025-05-06 17:43           ` Linus Torvalds
2025-05-06 17:52             ` Ard Biesheuvel
2025-05-06 18:17               ` Linus Torvalds
2025-05-06 18:39                 ` Linus Torvalds
2025-05-06 19:14                   ` Ard Biesheuvel
2025-05-06 19:41                     ` Linus Torvalds
2025-05-06 19:50                       ` Ard Biesheuvel
2025-05-07 13:51                         ` Ard Biesheuvel
2025-05-06 16:50   ` Ingo Molnar
2025-05-06 16:58     ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome