linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Brian Gerst <brgerst@gmail.com>
Cc: Ard Biesheuvel <ardb+git@google.com>,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Ard Biesheuvel <ardb@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [RFC PATCH v2 3/6] x86/cpu: Allow caps to be set arbitrarily early
Date: Wed, 14 May 2025 10:17:23 +0200	[thread overview]
Message-ID: <aCRRk_4hLD36UQVd@gmail.com> (raw)
In-Reply-To: <CAMzpN2jTPFTA9NhXfsrTZ0-prUH-1DbZ5ewt92BZSMqBCZyskw@mail.gmail.com>


* Brian Gerst <brgerst@gmail.com> wrote:

> On Tue, May 13, 2025 at 7:40 AM Ard Biesheuvel <ardb+git@google.com> wrote:
> >
> > From: Ard Biesheuvel <ardb@kernel.org>
> >
> > cpu_feature_enabled() uses a ternary alternative, where the late variant
> > is based on code patching and the early variant accesses the capability
> > field in boot_cpu_data directly.
> >
> > This allows cpu_feature_enabled() to be called quite early, but it still
> > requires that the CPU feature detection code runs before being able to
> > rely on the return value of cpu_feature_enabled().
> >
> > This is a problem for the implementation of pgtable_l5_enabled(), which
> > is based on cpu_feature_enabled(X86_FEATURE_5LEVEL_PAGING), and may be
> > called extremely early. Currently, there is a hacky workaround where
> > some source files that may execute before (but also after) CPU feature
> > detection have a different version of pgtable_l5_enabled(), based on the
> > USE_EARLY_PGTABLE_L5 preprocessor macro.
> >
> > Instead, let's make it possible to set CPU feature arbitrarily early, so
> > that the X86_FEATURE_5LEVEL_PAGING capability can be set before even
> > entering C code.
> >
> > This involves relying on static initialization of boot_cpu_data and the
> > cpu_caps_set/cpu_caps_cleared arrays, so they all need to reside in
> > .data. This ensures that they won't be cleared along with the rest of
> > BSS.
> >
> > Note that forcing a capability involves setting it in both
> > boot_cpu_data.x86_capability[] and cpu_caps_set[].
> >
> > Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> > ---
> >  arch/x86/kernel/cpu/common.c | 10 ++++------
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> > index bbec5c4cd8ed..aaa6d9e51ef1 100644
> > --- a/arch/x86/kernel/cpu/common.c
> > +++ b/arch/x86/kernel/cpu/common.c
> > @@ -704,8 +704,8 @@ static const char *table_lookup_model(struct cpuinfo_x86 *c)
> >  }
> >
> >  /* Aligned to unsigned long to avoid split lock in atomic bitmap ops */
> > -__u32 cpu_caps_cleared[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
> > -__u32 cpu_caps_set[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
> > +__u32 __read_mostly cpu_caps_cleared[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
> > +__u32 __read_mostly cpu_caps_set[NCAPINTS + NBUGINTS] __aligned(sizeof(unsigned long));
> 
> Is there any scenario where capabilities are changed after boot?

Not supposed to...

> If not, this could possibly be __ro_after_init.

Yeah, and in a separate patch.

Thanks,

	Ingo

  reply	other threads:[~2025-05-14  8:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-13 11:11 [RFC PATCH v2 0/6] x86: Robustify pgtable_l5_enabled() Ard Biesheuvel
2025-05-13 11:11 ` [RFC PATCH v2 1/6] x86/boot: Defer initialization of VM space related global variables Ard Biesheuvel
2025-05-14  8:15   ` [tip: x86/core] " tip-bot2 for Ard Biesheuvel
2025-05-13 11:12 ` [RFC PATCH v2 2/6] x86/cpu: Use a new feature flag for 5 level paging Ard Biesheuvel
2025-05-13 19:49   ` Linus Torvalds
2025-05-14  7:32   ` Kirill A. Shutemov
2025-05-14  8:04     ` Ingo Molnar
2025-05-14  8:14       ` Ard Biesheuvel
2025-05-14  8:21         ` Kirill A. Shutemov
2025-05-14  8:31         ` Ingo Molnar
2025-05-14  8:39           ` Ingo Molnar
2025-05-14  8:19       ` Kirill A. Shutemov
2025-05-14  8:33         ` Ingo Molnar
2025-05-13 11:12 ` [RFC PATCH v2 3/6] x86/cpu: Allow caps to be set arbitrarily early Ard Biesheuvel
2025-05-13 18:37   ` Brian Gerst
2025-05-14  8:17     ` Ingo Molnar [this message]
2025-05-14  9:49       ` Ard Biesheuvel
2025-05-21 13:22     ` Ard Biesheuvel
2025-05-13 11:12 ` [RFC PATCH v2 4/6] x86/boot: Set 5-level paging CPU cap before entering C code Ard Biesheuvel
2025-05-14  8:15   ` Ingo Molnar
2025-05-14  8:18     ` Ard Biesheuvel
2025-05-14  8:37       ` Ingo Molnar
2025-05-14  8:40         ` Ard Biesheuvel
2025-05-13 11:12 ` [RFC PATCH v2 5/6] x86/boot: Drop the early variant of pgtable_l5_enabled() Ard Biesheuvel
2025-05-13 11:12 ` [RFC PATCH v2 6/6] x86/boot: Drop 5-level paging related variables and early updates Ard Biesheuvel

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=aCRRk_4hLD36UQVd@gmail.com \
    --to=mingo@kernel.org \
    --cc=ardb+git@google.com \
    --cc=ardb@kernel.org \
    --cc=brgerst@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).