mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jürgen Groß" <jgross@suse.com>
To: Dave Hansen <dave.hansen@linux.intel.com>, linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, x86@kernel.org, bp@alien8.de
Subject: Re: [PATCH 4/4] x86/xen: Enumerate NX from CPUID directly
Date: Thu, 4 Apr 2024 12:44:20 +0200	[thread overview]
Message-ID: <67938940-a7b9-4a75-883e-cc49c6097fcc@suse.com> (raw)
In-Reply-To: <20240403153514.CC2C9D13@davehans-spike.ostc.intel.com>

On 03.04.24 17:35, Dave Hansen wrote:
> From: Dave Hansen <dave.hansen@linux.intel.com>
> 
> xen_start_kernel() is some of the first C code run "Xen PV" systems.

Nit: s/run/run on/

> It precedes things like setup_arch() or processor initialization code
> that would be thought of as "very early".
> 
> That means that 'boot_cpu_data' is garbage.  It has not even
> established the utter basics like if the CPU supports the CPUID
> instruction.  Unfortunately get_cpu_cap() requires this exact
> information.
> 
> Nevertheless, xen_start_kernel() calls get_cpu_cap().  But it
> works out in practice because it's looking for the NX bit which
> comes from an extended CPUID leaf that doesn't depend on
> c->cpuid_level being set.
> 
> Stop calling get_cpu_cap().  Use CPUID directly.  Add a little
> helper to avoid cluttering up the xen_start_kernel() flow.
> 
> This removes the risky, barely-working call to get_cpu_cap().
> 
> Note: The '& 31' strips the "capability" word off of an
>        X86_FEATURE_* value.  It's a magic number, but there are
>        a few of them sparsely scattered around and it's way
>        shorter than any helper.
> 
> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Juergen Gross <jgross@suse.com>
> ---
> 
>   b/arch/x86/xen/enlighten_pv.c |   19 ++++++++++++++++---
>   1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff -puN arch/x86/xen/enlighten_pv.c~xen-explain1 arch/x86/xen/enlighten_pv.c
> --- a/arch/x86/xen/enlighten_pv.c~xen-explain1	2024-04-02 15:23:00.046913557 -0700
> +++ b/arch/x86/xen/enlighten_pv.c	2024-04-02 15:23:00.050913562 -0700
> @@ -1306,6 +1306,21 @@ static void __init xen_domu_set_legacy_f
>   
>   extern void early_xen_iret_patch(void);
>   
> +/*
> + * It is too early for boot_cpu_has() and friends to work.
> + * Use CPUID to directly enumerate NX support.
> + */
> +static inline void xen_configure_nx(void)
> +{
> +	bool nx_supported;
> +	u32 eax = 0;

I'd prefer to name this variable edx.

> +
> +	get_cpuid_region_leaf(0x80000001, CPUID_EDX, &eax);
> +
> +	nx_supported = eax & (X86_FEATURE_NX & 31);
> +	x86_configure_nx(nx_supported);
> +}
> +
>   /* First C function to be called on Xen boot */
>   asmlinkage __visible void __init xen_start_kernel(struct start_info *si)
>   {
> @@ -1369,9 +1384,7 @@ asmlinkage __visible void __init xen_sta
>   	/* Get mfn list */
>   	xen_build_dynamic_phys_to_machine();
>   
> -	/* Work out if we support NX */
> -	get_cpu_cap(&boot_cpu_data);
> -	x86_configure_nx(boot_cpu_has(X86_FEATURE_NX));
> +	xen_configure_nx();
>   
>   	/*
>   	 * Set up kernel GDT and segment registers, mainly so that
> _


Juergen

  reply	other threads:[~2024-04-04 10:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 15:35 [PATCH 0/4] [v2] x86: Add CPUID region helper and clarify Xen startup Dave Hansen
2024-04-03 15:35 ` [PATCH 1/4] x86/cpu: Add and use new CPUID region helper Dave Hansen
2024-04-04  9:04   ` Jürgen Groß
2024-04-08 16:25     ` Borislav Petkov
2024-04-03 15:35 ` [PATCH 2/4] perf/x86/ibs: Use " Dave Hansen
2024-04-16 15:12   ` Borislav Petkov
2024-04-16 15:23     ` Dave Hansen
2024-04-16 17:48       ` Borislav Petkov
2024-04-18 12:05         ` Robert Richter
2024-04-22 17:20           ` Borislav Petkov
2024-04-22 20:09             ` Robert Richter
2024-04-22 20:41               ` Borislav Petkov
2024-04-22 21:30                 ` Robert Richter
2024-04-22 21:45                   ` Borislav Petkov
2024-04-23  7:45                     ` Robert Richter
2024-04-23  8:33                       ` Borislav Petkov
2024-04-03 15:35 ` [PATCH 3/4] x86/boot: Explicitly pass NX enabling status Dave Hansen
2024-04-04 10:33   ` Jürgen Groß
2024-04-03 15:35 ` [PATCH 4/4] x86/xen: Enumerate NX from CPUID directly Dave Hansen
2024-04-04 10:44   ` Jürgen Groß [this message]
2024-04-04 14:24     ` Dave Hansen
2024-04-04 15:05   ` Sean Christopherson
2024-04-22 17:44     ` Borislav Petkov
  -- strict thread matches above, loose matches on Subject: below --
2024-03-22 17:56 [PATCH 0/4] x86: Add CPUID region helper and clarify Xen startup Dave Hansen
2024-03-22 17:56 ` [PATCH 4/4] x86/xen: Enumerate NX from CPUID directly Dave Hansen

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=67938940-a7b9-4a75-883e-cc49c6097fcc@suse.com \
    --to=jgross@suse.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --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®