stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Peter Schneider <pschneider1968@googlemail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	x86@kernel.org, stable@vger.kernel.org,
	regressions@lists.linux.dev
Subject: Re: Kernel 6.9 regression: X86: Bogus messages from topology detection
Date: Fri, 31 May 2024 10:33:11 +0200	[thread overview]
Message-ID: <87ikyu8jp4.ffs@tglx> (raw)
In-Reply-To: <bd7ff2f3-bf2c-4431-9848-8eb41e7422c6@googlemail.com>

Peter!

On Fri, May 31 2024 at 08:52, Peter Schneider wrote:
> Am 30.05.2024 um 18:24 schrieb Thomas Gleixner:
> With that patch applied, I now get a build error:
>
> arch/x86/xen/enlighten_pv.c: In Funktion »xen_start_kernel«:
> arch/x86/xen/enlighten_pv.c:1388:9: Fehler: Implizite Deklaration der Funktion 
> »get_cpu_cap«; meinten Sie »set_cpu_cap«? [-Werror=implicit-function-declaration]
>   1388 |         get_cpu_cap(&boot_cpu_data);

Bah. Updated patch below.

Thanks,

        tglx
---
Subject: x86/topology/intel: Unlock CPUID before evaluating anything
From: Thomas Gleixner <tglx@linutronix.de>
Date: Thu, 30 May 2024 17:29:18 +0200

Intel CPUs have a MSR bit to limit CPUID enumeration to leaf two. If this
bit is set by the BIOS then CPUID evaluation including topology enumeration
does not work correctly as the evaluation code does not try to analyze any
leaf greater than two.

This went unnoticed before because the original topology code just repeated
evaluation several times and managed to overwrite the initial limited
information with the correct one later. The new evaluation code does it
once and therefore ends up with the limited and wrong information.

Cure this by unlocking CPUID right before evaluating anything which depends
on the maximum CPUID leaf being greater than two instead of rereading stuff
after unlock.

Fixes: 22d63660c35e ("x86/cpu: Use common topology code for Intel")
Reported-by: Peter Schneider <pschneider1968@googlemail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/cpu/common.c |    3 ++-
 arch/x86/kernel/cpu/intel.c  |   25 ++++++++++++++++---------
 2 files changed, 18 insertions(+), 10 deletions(-)

--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1585,6 +1585,7 @@ static void __init early_identify_cpu(st
 	if (have_cpuid_p()) {
 		cpu_detect(c);
 		get_cpu_vendor(c);
+		intel_unlock_cpuid_leafs(c);
 		get_cpu_cap(c);
 		setup_force_cpu_cap(X86_FEATURE_CPUID);
 		get_cpu_address_sizes(c);
@@ -1744,7 +1745,7 @@ static void generic_identify(struct cpui
 	cpu_detect(c);
 
 	get_cpu_vendor(c);
-
+	intel_unlock_cpuid_leafs(c);
 	get_cpu_cap(c);
 
 	get_cpu_address_sizes(c);
--- a/arch/x86/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
@@ -269,19 +269,26 @@ static void detect_tme_early(struct cpui
 	c->x86_phys_bits -= keyid_bits;
 }
 
+void intel_unlock_cpuid_leafs(struct cpuinfo_x86 *c)
+{
+	if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
+		return;
+
+	if (c->x86 < 6 || (c->x86 == 6 && c->x86_model < 0xd))
+		return;
+
+	/*
+	 * The BIOS can have limited CPUID to leaf 2, which breaks feature
+	 * enumeration. Unlock it and update the maximum leaf info.
+	 */
+	if (msr_clear_bit(MSR_IA32_MISC_ENABLE, MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0)
+		c->cpuid_level = cpuid_eax(0);
+}
+
 static void early_init_intel(struct cpuinfo_x86 *c)
 {
 	u64 misc_enable;
 
-	/* Unmask CPUID levels if masked: */
-	if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
-		if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
-				  MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0) {
-			c->cpuid_level = cpuid_eax(0);
-			get_cpu_cap(c);
-		}
-	}
-
 	if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
 		(c->x86 == 0x6 && c->x86_model >= 0x0e))
 		set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);

  reply	other threads:[~2024-05-31  8:33 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27  7:29 Kernel 6.9 regression: X86: Bogus messages from topology detection Peter Schneider
2024-05-27 13:14 ` Thomas Gleixner
2024-05-27 20:49   ` Thomas Gleixner
2024-05-27 21:06   ` Peter Schneider
2024-05-27 21:15     ` Peter Schneider
2024-05-27 21:34       ` Christian Heusel
2024-05-30  8:30       ` Thomas Gleixner
2024-05-30 10:06         ` Peter Schneider
2024-05-30 13:35           ` Thomas Gleixner
2024-05-30 15:53             ` Thomas Gleixner
2024-05-30 16:24               ` Thomas Gleixner
2024-05-31  6:52                 ` Peter Schneider
2024-05-31  8:33                   ` Thomas Gleixner [this message]
2024-05-31  8:42                     ` Thomas Gleixner
2024-05-31  9:41                       ` Peter Schneider
2024-05-31 10:07                         ` Thomas Gleixner
2024-05-31 10:22                           ` Peter Schneider
2024-06-01  7:06                       ` Linux regression tracking (Thorsten Leemhuis)
2024-06-01  7:20                         ` Thomas Gleixner
2024-06-01  7:25                           ` Linux regression tracking (Thorsten Leemhuis)
2024-05-31  8:13                 ` Christian Heusel
2024-05-31  8:16                   ` Christian Heusel
2024-05-31  8:48                     ` Thomas Gleixner
2024-05-31  9:11                       ` Thomas Gleixner
2024-05-31 13:08                         ` Christian Heusel
2024-05-31 13:42                           ` Thomas Gleixner
2024-05-31 14:29                             ` Christian Heusel
2024-05-31 15:25                               ` Thomas Gleixner
2024-05-31 11:06                     ` Thomas Gleixner

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=87ikyu8jp4.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pschneider1968@googlemail.com \
    --cc=regressions@lists.linux.dev \
    --cc=stable@vger.kernel.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).