Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1413937lqb; Thu, 30 May 2024 09:24:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzw253kPctccv+DBhDzYS3dtxxlKl2airfMuiswHd3R7aP4Uo0A323Z8JHBmsyKgAnk5Cfvlm+KgfBE/x1kU1T5wt6lCiUAj8df5KDOQ== X-Google-Smtp-Source: AGHT+IE+gBGvzOKivNhYt8IO2EmrwGvhrPb33cAcRqaxKqReEvp/dPlkwR+hCGEfWhlsU7mI5buS X-Received: by 2002:a0d:e6ca:0:b0:61d:fd33:d065 with SMTP id 00721157ae682-62c6f93ac93mr17058587b3.15.1717086292925; Thu, 30 May 2024 09:24:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717086292; cv=pass; d=google.com; s=arc-20160816; b=rAIZz2TdFpVg72ix4DqS+RuLu2gJ5k4EXUt2dE5XTDEwQA/gnUlb25PMjYkdstyw+f N2LR6Y7sNJdIftXMaKqYGovBXEumt44/C0MJg9oyFS+UlImHlahA8xfdFvqhOA2Mr0CO YhIAkY3xwqNhds6N9vEB84D6ZmkLHDQ25i0Re23GUlnirQQDhEx/Am/gdNfXD0EctqKP 28sjixrq4mHxF+oWlSuKtSrVPSYPfNDcD9gBP0PxtGXfZgWNK2def+xuX8SxHWPwO39Z sliYBp/dyBZOtujKO79q+DrGY8vr6WqchvpxTpKTLReinK0fEZruLD0RId91FL0hhb2k mU0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=su+nBpg+I//Su4qJT5o+I2Xt7bzzHBxGQXv4g2dGYMs=; fh=BcVcGina2nBMs11Vn/xTZYZTdWbDfuFQHT71XvA50qw=; b=pSg2Q1E0nMqU9Oz8H6Y5ekmcImMDW9iy7kQt7BbHRylhXL73lZxFN3gfqF+4SRJBU4 JS3XANvnt8VMVV6ehmDdQva5h9+q/pck2yYie8LWgrDVwPMp3bbLjip4GhtRGxIBEHjD zEMcvwWkLSL6oYWeKE+aEebzZyusvVVolE6mRo6RLaHI0agfm44s0yVfYfyaXFE6Emml xP5eqc50RrCPn2IFaeiQM1225QW/4jvB3rjndzTw/bW9w2YhmRvW0qs5D6l3lKKKZKCg htrohUMAeUhzOcDztm7TEY5DG5J0L/8g3a8FaxVHUpIamP2dsTGuXaOgG09t2FVuKdtw QKQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1VW6tcj8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-195652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195652-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a1e0cc1a2514c-808957dedb3si863397241.6.2024.05.30.09.24.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 09:24:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1VW6tcj8; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-195652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195652-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 930B31C22380 for ; Thu, 30 May 2024 16:24:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4400B23741; Thu, 30 May 2024 16:24:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1VW6tcj8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dlTcygrV" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 150A8219F6; Thu, 30 May 2024 16:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717086284; cv=none; b=W055kUA8bkbBkUdfStG3Mw80uj/R75nhrij4wRxkqgS14S7RbovOY5ScT+6+FfirAZqmi8grhLgQ3oBjXMRVbOXCSilVkpQPrpTXQA32KDwkMly6j+2+hALU/Lz9Jkb1fwrZn8IevKKpH4tiJGmqRCG5+NWAFX/8Sd8MCCDtW+Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717086284; c=relaxed/simple; bh=vXWTXGZIzOjj6SO56PbBHSdngFth82k1cfiLOtC6JKI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=tKUieBYdTzyw99ag/BcpuedkKx2hi+MBbBmzgzp+NK0R/BWbL46xcsqBb0iroImfK0yz/5nqbZymc2Pg5dKWy3Doa+3avtQk8SzkxtJaLvKtP13LANPMEt0RWIMapOLA3YD4X3mQla3Q3Xm9OokqMMwEzLPkOuNd4H/kbWDioyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1VW6tcj8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dlTcygrV; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1717086281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=su+nBpg+I//Su4qJT5o+I2Xt7bzzHBxGQXv4g2dGYMs=; b=1VW6tcj85D/9Rn/mj6JEpzRAiK5GP8ZWQTlhFkL8PZwhIbwZInZ5VCYIJOWuBCKjQCNCYy 7fGWWLd3i305NyzYV0dGY7UqA0Gzl+v3zQKHcRyT65f6xvTnxnNM794z05JFVHbrpYLZFH ZA1COKQJExm9AEQ9e7nhMtQKhSfdYfH6WWxrC5co8Krpo2Y1dJAcuq1OJIWPJ1cHrCkOw5 +Em7rhn1IoKGBa880/fjgt7DILsh5XSHg23J1/q/DTnivbYRVMkP+fSZh0S7koFiqGO8Hy AEJHxUabb9+o/31dVH1ZGb53cB0uvTM4bvjaUjyNsyKpoP5QFAuJ+bkixEQJyQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717086281; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=su+nBpg+I//Su4qJT5o+I2Xt7bzzHBxGQXv4g2dGYMs=; b=dlTcygrV0LHqp6LzvKBkScrYdBB2Ubuu4Y459H4noqSYzuOyO2U4dEwVtUopkQld0T5RJ9 j/DF0JgPa4eUzGDQ== To: Peter Schneider Cc: LKML , x86@kernel.org, stable@vger.kernel.org, regressions@lists.linux.dev Subject: Re: Kernel 6.9 regression: X86: Bogus messages from topology detection In-Reply-To: <87o78n8fe2.ffs@tglx> References: <877cffcs7h.ffs@tglx> <16cd76b1-a512-4a7b-a304-5e4e31af3c8a@googlemail.com> <87zfs78zxq.ffs@tglx> <76b1e0b9-26ae-4915-920d-9093f057796b@googlemail.com> <87r0dj8ls4.ffs@tglx> <87o78n8fe2.ffs@tglx> Date: Thu, 30 May 2024 18:24:39 +0200 Message-ID: <87le3r8dyw.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Thu, May 30 2024 at 17:53, Thomas Gleixner wrote: > On Thu, May 30 2024 at 15:35, Thomas Gleixner wrote: >> On Thu, May 30 2024 at 12:06, Peter Schneider wrote: >> Now the million-dollar question is what unlocks CPUID to read the proper >> value of EAX of leaf 0. All I could come up with is to sprinkle a dozen >> of printks into that code. Updated debug patch below. > > Don't bother. Dave pointed out to me that this is unlocked in > early_init_intel() via MSR_IA32_MISC_ENABLE_LIMIT_CPUID... > > Let me figure out how to fix that sanely. The original code just worked because it was reevaluating this stuff over and over until it magically became "correct". The proper fix is obviously to unlock CPUID on Intel _before_ anything which depends on cpuid_level is evaluated. Thanks, tglx --- --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -969,7 +969,7 @@ static void init_speculation_control(str } } -void get_cpu_cap(struct cpuinfo_x86 *c) +static void get_cpu_cap(struct cpuinfo_x86 *c) { u32 eax, ebx, ecx, edx; @@ -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/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -61,14 +61,15 @@ extern __ro_after_init enum tsx_ctrl_sta extern void __init tsx_init(void); void tsx_ap_init(void); +void intel_unlock_cpuid_leafs(struct cpuinfo_x86 *c); #else static inline void tsx_init(void) { } static inline void tsx_ap_init(void) { } +static inline void intel_unlock_cpuid_leafs(struct cpuinfo_x86 *c) { } #endif /* CONFIG_CPU_SUP_INTEL */ extern void init_spectral_chicken(struct cpuinfo_x86 *c); -extern void get_cpu_cap(struct cpuinfo_x86 *c); extern void get_cpu_address_sizes(struct cpuinfo_x86 *c); extern void cpu_detect_cache_sizes(struct cpuinfo_x86 *c); extern void init_scattered_cpuid_features(struct cpuinfo_x86 *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);