From nobody Mon Jun 8 14:36:11 2026 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 6CF773F2109 for ; Thu, 28 May 2026 15:39:44 +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=1779982784; cv=none; b=UOPwpLV3uzcnxnyEVAZKkcKHebrirPK4Fb/SQekop06J04IOSiDgWtiYwKHzd7Ca7WpKh8n9ImfHEPBs41dKEaYcbMLBMs5dDhQ134wmrGSWIc+rSFZIy3cScrxnJqUCFevCB9kepKujHCkihAZMJDk4mIr3AGGdwUKaHUO0HyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982784; c=relaxed/simple; bh=Ig/z0FPwjUkEY8P4s2fyeRs2/kG+1UjKWkvxSj7bHjw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RUHXDpqmJnFObGp7v4TiJDx0xopvMIAjO5fJ2Zno1tCU2KR8VxN/tc7Swb2yhQGABFMvtiYLg5B9vsBeq+447Dtd4D1YinC3ZEjmgvnTBFmmerGGHYGaXMjQP6NmNCYxHW1z15r8rQ3yU/b4WBwP3opXuZi5f+dPTSSuYtV2Mw8= 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=f/xFJH6H; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Oy05rU7v; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="f/xFJH6H"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Oy05rU7v" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Wv8TwKSlmi5MYZd9HJ9IoIoratGX0jpRaZ+QqQfUpA=; b=f/xFJH6HBD8YUmfjtOgFjOz/8hBn54NqmijvSCaM/BWIzXLipDPDYLxjxuco3m7HtemyE0 MK3+s9JNEX3uZFol/yxmFLkLebG4TmBESQ98zLVHu1ttTkoAeAv/B0yhL0qZQ3sRRbcL2F J92VgCg61Xk2MfzRvJMwItkFbYHu2AtJMmHbCwN2T8jc/dVQq8HHg3Cu4UqwwIT8O3ioIA XjaSJCKFe/7Ov8sNKr7tO9EnOzu4HSw3q0a3YhSodVrhhZO4rMlG4Y5f23GPrr27ub2ySi f0I/cUbH9sCiSKePYwtGEWsB4NAHKSUSdYMoRhL9Dp+yv4yZAkywVGGfu/DxUA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Wv8TwKSlmi5MYZd9HJ9IoIoratGX0jpRaZ+QqQfUpA=; b=Oy05rU7vZaCjcfogolRRYI3XI1y/KbviXTKUOFpBP1D1Qqxz650MNfCnCiBs/yp8qtTQEw gtdyBpq6tyqkrcAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 001/120] treewide: Explicitly include the x86 CPUID headers Date: Thu, 28 May 2026 17:37:23 +0200 Message-ID: <20260528153923.403473-2-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Modify all CPUID call sites which implicitly include any of the CPUID headers to explicitly include them instead. For KVM's reverse_cpuid.h, just include since it references the CPUID_EAX..EDX symbols without using the CPUID APIs. Note, this allows removing the inclusion of from within next. That allows the CPUID API headers to include without introducing a circular dependency. Signed-off-by: Ahmed S. Darwish Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/20260327021645.555257-1-darwi@linutronix.de --- arch/x86/boot/compressed/pgtable_64.c | 1 + arch/x86/boot/startup/sme.c | 1 + arch/x86/coco/tdx/tdx.c | 1 + arch/x86/events/amd/core.c | 2 ++ arch/x86/events/amd/ibs.c | 1 + arch/x86/events/amd/lbr.c | 2 ++ arch/x86/events/amd/power.c | 3 +++ arch/x86/events/amd/uncore.c | 1 + arch/x86/events/intel/core.c | 1 + arch/x86/events/intel/lbr.c | 1 + arch/x86/events/zhaoxin/core.c | 1 + arch/x86/include/asm/acrn.h | 2 ++ arch/x86/include/asm/microcode.h | 1 + arch/x86/include/asm/xen/hypervisor.h | 1 + arch/x86/kernel/apic/apic.c | 1 + arch/x86/kernel/cpu/amd.c | 1 + arch/x86/kernel/cpu/centaur.c | 1 + arch/x86/kernel/cpu/hygon.c | 1 + arch/x86/kernel/cpu/mce/core.c | 1 + arch/x86/kernel/cpu/mce/inject.c | 1 + arch/x86/kernel/cpu/microcode/amd.c | 1 + arch/x86/kernel/cpu/microcode/core.c | 1 + arch/x86/kernel/cpu/microcode/intel.c | 1 + arch/x86/kernel/cpu/mshyperv.c | 1 + arch/x86/kernel/cpu/resctrl/core.c | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 1 + arch/x86/kernel/cpu/scattered.c | 1 + arch/x86/kernel/cpu/sgx/driver.c | 3 +++ arch/x86/kernel/cpu/sgx/main.c | 3 +++ arch/x86/kernel/cpu/topology_amd.c | 1 + arch/x86/kernel/cpu/topology_common.c | 1 + arch/x86/kernel/cpu/topology_ext.c | 1 + arch/x86/kernel/cpu/transmeta.c | 3 +++ arch/x86/kernel/cpu/vmware.c | 1 + arch/x86/kernel/cpu/zhaoxin.c | 1 + arch/x86/kernel/cpuid.c | 1 + arch/x86/kernel/jailhouse.c | 1 + arch/x86/kernel/kvm.c | 1 + arch/x86/kernel/paravirt.c | 1 + arch/x86/kvm/mmu/mmu.c | 1 + arch/x86/kvm/mmu/spte.c | 1 + arch/x86/kvm/reverse_cpuid.h | 2 ++ arch/x86/kvm/svm/sev.c | 1 + arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/vmx/pmu_intel.c | 1 + arch/x86/kvm/vmx/sgx.c | 1 + arch/x86/kvm/vmx/vmx.c | 1 + arch/x86/mm/pti.c | 1 + arch/x86/pci/xen.c | 1 + arch/x86/xen/enlighten_hvm.c | 1 + arch/x86/xen/pmu.c | 1 + arch/x86/xen/time.c | 1 + drivers/char/agp/efficeon-agp.c | 1 + drivers/cpufreq/longrun.c | 1 + drivers/cpufreq/powernow-k7.c | 1 + drivers/cpufreq/powernow-k8.c | 1 + drivers/cpufreq/speedstep-lib.c | 1 + drivers/firmware/efi/libstub/x86-5lvl.c | 1 + drivers/gpu/drm/gma500/mmu.c | 2 ++ drivers/hwmon/fam15h_power.c | 1 + drivers/hwmon/k10temp.c | 2 ++ drivers/hwmon/k8temp.c | 1 + drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 1 + drivers/ras/amd/fmpm.c | 1 + drivers/thermal/intel/intel_hfi.c | 1 + drivers/thermal/intel/x86_pkg_temp_thermal.c | 1 + drivers/virt/acrn/hsm.c | 1 + drivers/xen/events/events_base.c | 1 + drivers/xen/grant-table.c | 1 + drivers/xen/xenbus/xenbus_xs.c | 3 +++ 70 files changed, 86 insertions(+) diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compress= ed/pgtable_64.c index 0e89e197e112..1b2fb35704f9 100644 --- a/arch/x86/boot/compressed/pgtable_64.c +++ b/arch/x86/boot/compressed/pgtable_64.c @@ -2,6 +2,7 @@ #include "misc.h" #include #include +#include #include #include #include diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c index b76a7c95dfe1..c07a2c381ed1 100644 --- a/arch/x86/boot/startup/sme.c +++ b/arch/x86/boot/startup/sme.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include =20 diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 186915a17c50..29b6f1ed59ec 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 0c92ed5f464b..d66a357f219d 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -8,8 +8,10 @@ #include #include #include + #include #include +#include #include #include =20 diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index e0bd5051db2a..20c2de5c697b 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -15,6 +15,7 @@ #include =20 #include +#include #include =20 #include "../perf_event.h" diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c index d24da377df77..5b437dc8e4ce 100644 --- a/arch/x86/events/amd/lbr.c +++ b/arch/x86/events/amd/lbr.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include + +#include #include #include =20 diff --git a/arch/x86/events/amd/power.c b/arch/x86/events/amd/power.c index dad42790cf7d..744dffa42dee 100644 --- a/arch/x86/events/amd/power.c +++ b/arch/x86/events/amd/power.c @@ -10,8 +10,11 @@ #include #include #include + #include +#include #include + #include "../perf_event.h" =20 /* Event code: LSB 8 bits, passed in attr->config any other bit is reserve= d. */ diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index dd956cfcadef..05cff39968ec 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -16,6 +16,7 @@ #include =20 #include +#include #include =20 #define NUM_COUNTERS_NB 4 diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index dd1e3aa75ee9..ea7507bb7047 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -17,6 +17,7 @@ #include =20 #include +#include #include #include #include diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index 72f2adcda7c6..cae2e02fe6cc 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -4,6 +4,7 @@ #include =20 #include +#include #include #include =20 diff --git a/arch/x86/events/zhaoxin/core.c b/arch/x86/events/zhaoxin/core.c index 4bdfcf091200..6ed644fe89aa 100644 --- a/arch/x86/events/zhaoxin/core.c +++ b/arch/x86/events/zhaoxin/core.c @@ -13,6 +13,7 @@ #include =20 #include +#include #include #include #include diff --git a/arch/x86/include/asm/acrn.h b/arch/x86/include/asm/acrn.h index fab11192c60a..db42b477c41d 100644 --- a/arch/x86/include/asm/acrn.h +++ b/arch/x86/include/asm/acrn.h @@ -2,6 +2,8 @@ #ifndef _ASM_X86_ACRN_H #define _ASM_X86_ACRN_H =20 +#include + /* * This CPUID returns feature bitmaps in EAX. * Guest VM uses this to detect the appropriate feature bit. diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microc= ode.h index 3c317d155771..9cd136d4515c 100644 --- a/arch/x86/include/asm/microcode.h +++ b/arch/x86/include/asm/microcode.h @@ -3,6 +3,7 @@ #define _ASM_X86_MICROCODE_H =20 #include +#include =20 struct cpu_signature { unsigned int sig; diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/x= en/hypervisor.h index c2fc7869b996..7c596cebfb78 100644 --- a/arch/x86/include/asm/xen/hypervisor.h +++ b/arch/x86/include/asm/xen/hypervisor.h @@ -37,6 +37,7 @@ extern struct shared_info *HYPERVISOR_shared_info; extern struct start_info *xen_start_info; =20 #include +#include #include =20 #define XEN_SIGNATURE "XenVMMXenVMM" diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 639904911444..8c614750a19b 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 2f8e8ff2d000..62f74a7f2f8d 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 81695da9c524..681d2da49341 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -5,6 +5,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c index 7f95a74e4c65..3e8891a9caf2 100644 --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -10,6 +10,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index f3a793e3a6c8..eebc60342cd6 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -49,6 +49,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inj= ect.c index d02c4f556cd0..42c82c14c48a 100644 --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -26,6 +26,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/micr= ocode/amd.c index e533881284a1..874b5b70c0d2 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -34,6 +34,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/mic= rocode/core.c index 651202e6fefb..56d791aeac4e 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -34,6 +34,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/mi= crocode/intel.c index 37ac4afe0972..18d2eff7a4b7 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -25,6 +25,7 @@ #include =20 #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index b5b6a58b67b0..640e6b223c2d 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resct= rl/core.c index 7667cf7c4e94..9c01d2562b7a 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -22,6 +22,7 @@ #include =20 #include +#include #include #include #include "internal.h" diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/re= sctrl/monitor.c index 9bd87bae4983..145be7abee52 100644 --- a/arch/x86/kernel/cpu/resctrl/monitor.c +++ b/arch/x86/kernel/cpu/resctrl/monitor.c @@ -21,6 +21,7 @@ #include =20 #include +#include #include =20 #include "internal.h" diff --git a/arch/x86/kernel/cpu/scattered.c b/arch/x86/kernel/cpu/scattere= d.c index 837d6a4b0c28..937129ce6a96 100644 --- a/arch/x86/kernel/cpu/scattered.c +++ b/arch/x86/kernel/cpu/scattered.c @@ -6,6 +6,7 @@ =20 #include #include +#include #include =20 #include "cpu.h" diff --git a/arch/x86/kernel/cpu/sgx/driver.c b/arch/x86/kernel/cpu/sgx/dri= ver.c index 473619741bc4..9268289cd9f9 100644 --- a/arch/x86/kernel/cpu/sgx/driver.c +++ b/arch/x86/kernel/cpu/sgx/driver.c @@ -6,7 +6,10 @@ #include #include #include + +#include #include + #include "driver.h" #include "encl.h" =20 diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 38b7fd2f63be..4505f808af5e 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -15,9 +15,12 @@ #include #include #include + +#include #include #include #include + #include "driver.h" #include "encl.h" #include "encls.h" diff --git a/arch/x86/kernel/cpu/topology_amd.c b/arch/x86/kernel/cpu/topol= ogy_amd.c index 6ac097e13106..cc103c85b96d 100644 --- a/arch/x86/kernel/cpu/topology_amd.c +++ b/arch/x86/kernel/cpu/topology_amd.c @@ -2,6 +2,7 @@ #include =20 #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/topology_common.c b/arch/x86/kernel/cpu/to= pology_common.c index d0d79d5b8eb9..cf7513416b70 100644 --- a/arch/x86/kernel/cpu/topology_common.c +++ b/arch/x86/kernel/cpu/topology_common.c @@ -6,6 +6,7 @@ #include #include #include +#include #include =20 #include "cpu.h" diff --git a/arch/x86/kernel/cpu/topology_ext.c b/arch/x86/kernel/cpu/topol= ogy_ext.c index 467b0326bf1a..eb915c73895f 100644 --- a/arch/x86/kernel/cpu/topology_ext.c +++ b/arch/x86/kernel/cpu/topology_ext.c @@ -2,6 +2,7 @@ #include =20 #include +#include #include #include =20 diff --git a/arch/x86/kernel/cpu/transmeta.c b/arch/x86/kernel/cpu/transmet= a.c index 42c939827621..1fdcd69c625c 100644 --- a/arch/x86/kernel/cpu/transmeta.c +++ b/arch/x86/kernel/cpu/transmeta.c @@ -3,8 +3,11 @@ #include #include #include + #include +#include #include + #include "cpu.h" =20 static void early_init_transmeta(struct cpuinfo_x86 *c) diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index eee0d1a48802..34b73573b108 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index 031379b7d4fa..761aef5590ac 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -4,6 +4,7 @@ =20 #include #include +#include #include =20 #include "cpu.h" diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c index dae436253de4..cbd04b677fd1 100644 --- a/arch/x86/kernel/cpuid.c +++ b/arch/x86/kernel/cpuid.c @@ -37,6 +37,7 @@ #include #include =20 +#include #include #include =20 diff --git a/arch/x86/kernel/jailhouse.c b/arch/x86/kernel/jailhouse.c index 9e9a591a5fec..f58ce9220e0f 100644 --- a/arch/x86/kernel/jailhouse.c +++ b/arch/x86/kernel/jailhouse.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 29226d112029..06534e16cfb5 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index 792fa96b3233..44f29fc05b3d 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index f0144ae8d891..91843e9224d0 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 85a0473809b0..4e753386c8d4 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -15,6 +15,7 @@ #include "x86.h" #include "spte.h" =20 +#include #include #include #include diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 657f5f743ed9..2ad25781cefb 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -3,8 +3,10 @@ #define ARCH_X86_KVM_REVERSE_CPUID_H =20 #include + #include #include +#include =20 /* * Define a KVM-only feature flag. diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index c2126b3c3072..e107f368ed2d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -23,6 +23,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index e02a38da5296..d38a21be099d 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 27eb76e6b6a0..74e0b01185b8 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "x86.h" #include "cpuid.h" #include "lapic.h" diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c index df1d0cf76947..29a1f8e3be60 100644 --- a/arch/x86/kvm/vmx/sgx.c +++ b/arch/x86/kvm/vmx/sgx.c @@ -2,6 +2,7 @@ /* Copyright(c) 2021 Intel Corporation. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include =20 diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b9103de01428..ede773ce065a 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 631f0375bd42..598f553cc871 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -31,6 +31,7 @@ =20 #include #include +#include #include #include #include diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c index 6818515a501b..550c631bc77f 100644 --- a/arch/x86/pci/xen.c +++ b/arch/x86/pci/xen.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include =20 diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c index 2f9fa27e5a3c..2bf05bf3e17b 100644 --- a/arch/x86/xen/enlighten_hvm.c +++ b/arch/x86/xen/enlighten_hvm.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include =20 diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c index 8f89ce0b67e3..5f50a3ee08f5 100644 --- a/arch/x86/xen/pmu.c +++ b/arch/x86/xen/pmu.c @@ -2,6 +2,7 @@ #include #include =20 +#include #include #include #include diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c index 6f9f665bb7ae..d62c14334b35 100644 --- a/arch/x86/xen/time.c +++ b/arch/x86/xen/time.c @@ -18,6 +18,7 @@ #include #include =20 +#include #include #include #include diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-ag= p.c index 0d25bbdc7e6a..4d0b7d7c0aad 100644 --- a/drivers/char/agp/efficeon-agp.c +++ b/drivers/char/agp/efficeon-agp.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "agp.h" #include "intel-agp.h" =20 diff --git a/drivers/cpufreq/longrun.c b/drivers/cpufreq/longrun.c index 1caaec7c280b..f3aaca0496a4 100644 --- a/drivers/cpufreq/longrun.c +++ b/drivers/cpufreq/longrun.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 static struct cpufreq_driver longrun_driver; =20 diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c index 6b7caf4ae20d..6a930d7e6a5c 100644 --- a/drivers/cpufreq/powernow-k7.c +++ b/drivers/cpufreq/powernow-k7.c @@ -29,6 +29,7 @@ #include /* Needed for recalibrate_cpu_khz() */ #include #include +#include =20 #ifdef CONFIG_X86_POWERNOW_K7_ACPI #include diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c index 4d77eef53fe0..2b791f1ec51b 100644 --- a/drivers/cpufreq/powernow-k8.c +++ b/drivers/cpufreq/powernow-k8.c @@ -39,6 +39,7 @@ =20 #include #include +#include =20 #include #include diff --git a/drivers/cpufreq/speedstep-lib.c b/drivers/cpufreq/speedstep-li= b.c index f8b42e981635..973716c1c29c 100644 --- a/drivers/cpufreq/speedstep-lib.c +++ b/drivers/cpufreq/speedstep-lib.c @@ -15,6 +15,7 @@ #include #include =20 +#include #include #include #include "speedstep-lib.h" diff --git a/drivers/firmware/efi/libstub/x86-5lvl.c b/drivers/firmware/efi= /libstub/x86-5lvl.c index c00d0ae7ed5d..c3da05c0df8b 100644 --- a/drivers/firmware/efi/libstub/x86-5lvl.c +++ b/drivers/firmware/efi/libstub/x86-5lvl.c @@ -2,6 +2,7 @@ #include =20 #include +#include #include #include =20 diff --git a/drivers/gpu/drm/gma500/mmu.c b/drivers/gpu/drm/gma500/mmu.c index 6b6b44e426cf..4fbc22a59ac7 100644 --- a/drivers/gpu/drm/gma500/mmu.c +++ b/drivers/gpu/drm/gma500/mmu.c @@ -7,6 +7,8 @@ #include #include =20 +#include + #include "mmu.h" #include "psb_drv.h" #include "psb_reg.h" diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c index efcbea2d070e..ad4ed4162b57 100644 --- a/drivers/hwmon/fam15h_power.c +++ b/drivers/hwmon/fam15h_power.c @@ -19,6 +19,7 @@ #include #include #include +#include #include =20 MODULE_DESCRIPTION("AMD Family 15h CPU processor power monitor"); diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index a5d8f45b7881..de0760dc597d 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -20,7 +20,9 @@ #include #include #include + #include +#include #include =20 MODULE_DESCRIPTION("AMD Family 10h+ CPU core temperature monitor"); diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c index 2b80ac410cd1..53241164570e 100644 --- a/drivers/hwmon/k8temp.c +++ b/drivers/hwmon/k8temp.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #define TEMP_FROM_REG(val) (((((val) >> 16) & 0xff) - 49) * 1000) #define REG_TEMP 0xe4 diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c b/drivers/ne= t/ethernet/stmicro/stmmac/dwmac-intel.c index 7898b5075a8b..b8d467ba6d72 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "dwmac-intel.h" #include "dwmac4.h" #include "stmmac.h" diff --git a/drivers/ras/amd/fmpm.c b/drivers/ras/amd/fmpm.c index 34ef75af31cb..4ccaaf7b70bf 100644 --- a/drivers/ras/amd/fmpm.c +++ b/drivers/ras/amd/fmpm.c @@ -52,6 +52,7 @@ #include =20 #include +#include #include =20 #include "../debugfs.h" diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/inte= l_hfi.c index 8c4ae75231f8..3273b8fe3d4d 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -41,6 +41,7 @@ #include #include =20 +#include #include =20 #include "intel_hfi.h" diff --git a/drivers/thermal/intel/x86_pkg_temp_thermal.c b/drivers/thermal= /intel/x86_pkg_temp_thermal.c index 540109761f0a..d1dd2f5910e4 100644 --- a/drivers/thermal/intel/x86_pkg_temp_thermal.c +++ b/drivers/thermal/intel/x86_pkg_temp_thermal.c @@ -20,6 +20,7 @@ #include =20 #include +#include #include =20 #include "thermal_interrupt.h" diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c index 74f2086fa59f..f170ff4617fd 100644 --- a/drivers/virt/acrn/hsm.c +++ b/drivers/virt/acrn/hsm.c @@ -16,6 +16,7 @@ #include =20 #include +#include #include =20 #include "acrn_drv.h" diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index bc9a41662efc..6ea945508a89 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -40,6 +40,7 @@ #include =20 #ifdef CONFIG_X86 +#include #include #include #include diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index a6abf1ccd54c..35f879dc5dfb 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c @@ -59,6 +59,7 @@ #include #include #ifdef CONFIG_X86 +#include #include #endif #include diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index 82b0a34ded70..c202e7c553a6 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -47,6 +47,9 @@ #include #include #include +#ifdef CONFIG_X86 +#include +#endif #include #include #include "xenbus.h" --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A4E283EF66B for ; Thu, 28 May 2026 15:39:47 +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=1779982787; cv=none; b=g2ObZ3DYsrN1sbPyY3coItWGHM4haQESZY3tYV1IxaKnhICNQJGAxxi5z+VAJjfbi8aYV3wnI+SYhDJytcWr0i6z5zGuCJEoSaRAhUQJYrKfGwQOr5NfQilfWXKCxN+qUa0uDUbsk+NVQ8HYBbUtBcSBjJyu/0oQmNLD/ylPe/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982787; c=relaxed/simple; bh=+brV3ZQPPQ2cCxlKjcdbgUKWMovVZ8rQth391vdm4jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOGnPrR8kvnDjfDqWFedgLSdZ2oFDTM8/CzIXhPfHXt+Uj/hLZiPFDgI/Zmk1fW6wi1jvXQtJqWHWmo+qXqM40atv8VUhO4XV/Ry002LvIfX9n3rnRdchNqJQlN/xFrXUe6T2OpoEvt/Tbn44iSRGvJO/3IdW7UWwUc2l135V4Q= 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=l5/LzA7b; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=S9elNFfz; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="l5/LzA7b"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S9elNFfz" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mgMZSbnt4GCgcZiHfWFL2Y/XXryRB498L+LKgmIGuNs=; b=l5/LzA7bGCJUeUlwPh66uMPYKFJlape+NdeLLpkhdLm55okdRIzp/OhNkMhTdKv/l2VNgn Zqj/jZ+nYAORONPPJf6nWvho+RVx5OYteQRKwFHhrlaCiSuF5tCGVSZbZPOhe4JKXky+YV pdF7RYObHibhKPi2Njo+azFPtBxwVEzb8kPcTvBH4HjZ5M2/0uMm8i+CDekBwjpA9iVhDo QcY7iPWEMAknCTZnl9c1Uy54ZgRIyliMZXbEgicktEyhHtTAsZzuI1w0pQOXsFQmEfsFhB DRED10pC6oWkby95/XV6h4mIfOXYFka+dkAWmqKeXJxvS3UFAuAZPp26S2lodw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982786; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mgMZSbnt4GCgcZiHfWFL2Y/XXryRB498L+LKgmIGuNs=; b=S9elNFfzV2/xT7gcZfqXDs3JBF7NhxNj+pfWokyJ1uPHpT7WUWy/uByE7qYFqYq3W4kpxR Z/pOeLyyxbL7RBDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 002/120] x86/cpu: : Do not include the CPUID API header Date: Thu, 28 May 2026 17:37:24 +0200 Message-ID: <20260528153923.403473-3-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" includes but it does not need it. Remove the include. This allows the CPUID APIs header to include at a later step without introducing a circular dependency. Note, all call sites which implicitly included the CPUID API through have been modified to explicitly include the CPUID APIs instead. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/processor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index 10b5355b323e..4f4356b13158 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -16,7 +16,6 @@ struct vm86; #include #include #include -#include #include #include #include --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 BA8ED3F787B for ; Thu, 28 May 2026 15:39:50 +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=1779982791; cv=none; b=s9rT2alLgzdzcYKdswUCn/h7Uh1opHnRsCgRkN4x9Rjp5D+19XwXVV816V94KLsK27raMVlH+J4ou+G/k7yKvNh4XnXawQw3zSM78EA8rlFehukdZPpTl5tKcHhtjeW4dxWp8/LBsIym20MbDUG6pNIKVdQSiME05O26t9JsTg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982791; c=relaxed/simple; bh=5MNiV//yLnTfWQdKAEIU0TaOYqq4CvGA1IxNYDd1uoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdP+BGZoCz5xn3CcaKFMGKYnK2CTou0p4WKrG2n8+Sy0vNCDj8DABm+dVDGlK+lFhA3NjpskJ/3IbYzZjCa8SWkrBSiHqd/b10eMIcpR3ZjAQIhbEbAGJ8AzAGRhMF42GhPL9ulsJ981a94WPEvadA11XW2tVPJVIajSQ7+Jov8= 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=QcxhrseW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Rz1Y8ilj; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QcxhrseW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Rz1Y8ilj" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PM1swt867eWt9MTI12IENI13z/LP2kaeLFO5PfqEbPs=; b=QcxhrseWIKAvw8NVEXY1WfU8vqXgjbooVNHKut4oAsEIiT81zu6GbUHOAmGMoUDJGZ+2cb b/BBvkWMOUPs2TD7cBi0SfFeYi0F1Uo21EZcHPbEOcceVcO5HhLGy2kTmN5XS6opxh6Lgv gBg45dcDafuLpB/Iff5+wMFYJ4ghir6q+f7HS6CbSwfXSK1/Yn30yHKj+J5Cf/PLAWVzPG pwlq3pbwDHgNawXtIGwahfgrQ9okxOeTSB3udL9dXErbSuraKb+efqAkVjAlm+J8BsOKBb YlIq5QvdzKce8iM9DZcqEQQpBGPmCZspiIOEAJvOaL53oXgmb+6nhQrID4VtBw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982789; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PM1swt867eWt9MTI12IENI13z/LP2kaeLFO5PfqEbPs=; b=Rz1Y8ilj9kkRiGfCf0pSmyT1b0/okxR/6PtJH4qf4i6wdUwksSwBl/hKQ15Hr4xG7M4WRv poFNuDJIebwX2YCA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 003/120] x86/cpuid: Rename cpuid_leaf()/cpuid_subleaf() APIs Date: Thu, 28 May 2026 17:37:25 +0200 Message-ID: <20260528153923.403473-4-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A new CPUID model will be added where its APIs will be designated as the official CPUID API. Free the cpuid_leaf() and cpuid_subleaf() function names for that API. Rename them accordingly to cpuid_read() and cpuid_read_subleaf(). For kernel/cpuid.c, rename its local file operations read function from cpuid_read() to cpuid_read_f() so that it does not conflict with the new API. No functional change. Signed-off-by: Ahmed S. Darwish Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/20260327021645.555257-1-darwi@linutronix.de --- arch/x86/include/asm/cpuid/api.h | 6 +++--- arch/x86/kernel/cpu/topology_amd.c | 2 +- arch/x86/kernel/cpu/topology_ext.c | 2 +- arch/x86/kernel/cpuid.c | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 44fa82e1267c..2b9750cc8a75 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -131,12 +131,12 @@ static inline void __cpuid_read(u32 leaf, u32 subleaf= , u32 *regs) __cpuid(regs + CPUID_EAX, regs + CPUID_EBX, regs + CPUID_ECX, regs + CPUI= D_EDX); } =20 -#define cpuid_subleaf(leaf, subleaf, regs) { \ +#define cpuid_read_subleaf(leaf, subleaf, regs) { \ static_assert(sizeof(*(regs)) =3D=3D 16); \ __cpuid_read(leaf, subleaf, (u32 *)(regs)); \ } =20 -#define cpuid_leaf(leaf, regs) { \ +#define cpuid_read(leaf, regs) { \ static_assert(sizeof(*(regs)) =3D=3D 16); \ __cpuid_read(leaf, 0, (u32 *)(regs)); \ } @@ -228,7 +228,7 @@ static inline u32 cpuid_base_hypervisor(const char *sig= , u32 leaves) */ static inline void cpuid_leaf_0x2(union leaf_0x2_regs *regs) { - cpuid_leaf(0x2, regs); + cpuid_read(0x2, regs); =20 /* * All Intel CPUs must report an iteration count of 1. In case diff --git a/arch/x86/kernel/cpu/topology_amd.c b/arch/x86/kernel/cpu/topol= ogy_amd.c index cc103c85b96d..da080d732e10 100644 --- a/arch/x86/kernel/cpu/topology_amd.c +++ b/arch/x86/kernel/cpu/topology_amd.c @@ -80,7 +80,7 @@ static bool parse_8000_001e(struct topo_scan *tscan) if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) return false; =20 - cpuid_leaf(0x8000001e, &leaf); + cpuid_read(0x8000001e, &leaf); =20 /* * If leaf 0xb/0x26 is available, then the APIC ID and the domain diff --git a/arch/x86/kernel/cpu/topology_ext.c b/arch/x86/kernel/cpu/topol= ogy_ext.c index eb915c73895f..60dfaa02ffd0 100644 --- a/arch/x86/kernel/cpu/topology_ext.c +++ b/arch/x86/kernel/cpu/topology_ext.c @@ -71,7 +71,7 @@ static inline bool topo_subleaf(struct topo_scan *tscan, = u32 leaf, u32 subleaf, default: return false; } =20 - cpuid_subleaf(leaf, subleaf, &sl); + cpuid_read_subleaf(leaf, subleaf, &sl); =20 if (!sl.num_processors || sl.type =3D=3D INVALID_TYPE) return false; diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c index cbd04b677fd1..b55fe9c7359a 100644 --- a/arch/x86/kernel/cpuid.c +++ b/arch/x86/kernel/cpuid.c @@ -59,8 +59,7 @@ static void cpuid_smp_cpuid(void *cmd_block) complete(&cmd->done); } =20 -static ssize_t cpuid_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) +static ssize_t cpuid_read_f(struct file *file, char __user *buf, size_t co= unt, loff_t *ppos) { char __user *tmp =3D buf; struct cpuid_regs_done cmd; @@ -120,7 +119,7 @@ static int cpuid_open(struct inode *inode, struct file = *file) static const struct file_operations cpuid_fops =3D { .owner =3D THIS_MODULE, .llseek =3D no_seek_end_llseek, - .read =3D cpuid_read, + .read =3D cpuid_read_f, .open =3D cpuid_open, }; =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 D80053F39C2 for ; Thu, 28 May 2026 15:39:54 +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=1779982795; cv=none; b=CXf9nBZv+7oKlp3oFadg8Wxfh3z3KKRphlbln/swag6EdnxGhvI0R4RFe0vKU4vw7xlBmTR1Zp+hKqXz8dcJ36y+eoVLUju50PTigUsJzdmHaM3SvgoI0Y7/nc0Vpx7oz+jPXXAkh6L11KXWllaMKOwo2H7XL/IN4AA5HwFJILE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982795; c=relaxed/simple; bh=FAfxZB4/CMNRCI4Dzq5QiDv0URbwM1KSz3xldzNKwrA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lEKxIMTI08P6Y9BiGlnUk1IGrtCnUXzvMoHV5PtD0GrjC/cFuqHW2dTlvpvZ0+vrf70ZpkRa+NfnNFFiMMFf/Z0dIKW2YQ1n3Of42uepcAkV/liLI1oOAQjENYv0hVRS1HjUDPVg/FmLWJl3jdCgz7G614Q6Pv3vjG/4J06A2gw= 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=4yqYLGGr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Zuw2IiDr; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4yqYLGGr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Zuw2IiDr" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982792; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khUk4mUgaMtjhFVlgWWxlYs9KtUMIk3Cv+fMVi59hTc=; b=4yqYLGGryucPa2wm+hNNJO6ztKIdqR3KAc33VuyIbckWEXuYPuoNyLGmn4yvc++Ia7Dwmj K86Ytcho6NBDNtUr/8FTrXDepnEPO3BSWsTALMpcUvnoSAKwl5o6fNfU+lWSJVZaZ0yYRs E1Tz7kh0YYQ2mqi2QxfIMTeobiP4g5wrhAJ0vKDHxcVM/PU7pBd6BXDH6WVhB+fsjUiAV2 ZPFDBIuE/qf9p7oYesr8GcorVA71lARRXA2OJcUzbNBG1duxwkV9kNSkkOZ7x/Wj+NZ8PE klga3WLYqkf4gWGD44FQcjxEPEXwvjsJjo12kUHWG9T9414s3Jk/A+2DwYAX5A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982792; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khUk4mUgaMtjhFVlgWWxlYs9KtUMIk3Cv+fMVi59hTc=; b=Zuw2IiDr+5WDV23adD9rkATzkv4iodAiQzlLyqj/8Upg1gYzguF5phmCDT8Hhz4MUSwexT R4khnTwR6mtoVvDQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 004/120] x86/cpuid: Introduce Date: Thu, 28 May 2026 17:37:26 +0200 Message-ID: <20260528153923.403473-5-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable To centralize all CPUID access across the x86 subsystem, introduce . It is generated by the x86-cpuid-db project=C2= =B9 and provides C99 bitfield listings for all publicly known CPUID leaves. =C2=B9 https://gitlab.com/x86-cpuid.org/x86-cpuid-db/-/blob/v3.0/CHANGELOG.= rst Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/20260327021645.555257-1-darwi@linutronix.de --- MAINTAINERS | 1 + arch/x86/include/asm/cpuid/leaf_types.h | 2350 +++++++++++++++++++++++ 2 files changed, 2351 insertions(+) create mode 100644 arch/x86/include/asm/cpuid/leaf_types.h diff --git a/MAINTAINERS b/MAINTAINERS index b539be153f6a..a0137a898927 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -28869,6 +28869,7 @@ R: Ahmed S. Darwish L: x86-cpuid@lists.linux.dev S: Maintained W: https://x86-cpuid.org +F: arch/x86/include/asm/cpuid/leaf_types.h F: tools/arch/x86/kcpuid/ =20 X86 ENTRY CODE diff --git a/arch/x86/include/asm/cpuid/leaf_types.h b/arch/x86/include/asm= /cpuid/leaf_types.h new file mode 100644 index 000000000000..5b0008e455e2 --- /dev/null +++ b/arch/x86/include/asm/cpuid/leaf_types.h @@ -0,0 +1,2350 @@ +/* SPDX-License-Identifier: MIT */ +/* Generator: x86-cpuid-db v3.0 */ + +/* + * Auto-generated file. + * Please submit all updates and bugfixes to https://x86-cpuid.org + */ + +#ifndef _ASM_X86_CPUID_LEAF_TYPES +#define _ASM_X86_CPUID_LEAF_TYPES + +#include + +/* + * Leaf 0x0 + * Maximum standard leaf + CPU vendor string + */ + +struct leaf_0x0_0 { + // eax + u32 max_std_leaf : 32; // Highest standard CPUID leaf + // ebx + u32 cpu_vendorid_0 : 32; // CPU vendor ID string bytes 0 - 3 + // ecx + u32 cpu_vendorid_2 : 32; // CPU vendor ID string bytes 8 - 11 + // edx + u32 cpu_vendorid_1 : 32; // CPU vendor ID string bytes 4 - 7 +}; + +/* + * Leaf 0x1 + * CPU FMS (Family/Model/Stepping) + standard feature flags + */ + +struct leaf_0x1_0 { + // eax + u32 stepping : 4, // Stepping ID + base_model : 4, // Base CPU model ID + base_family_id : 4, // Base CPU family ID + cpu_type : 2, // CPU type + : 2, // Reserved + ext_model : 4, // Extended CPU model ID + ext_family : 8, // Extended CPU family ID + : 4; // Reserved + // ebx + u32 brand_id : 8, // Brand index + clflush_size : 8, // CLFLUSH instruction cache line size + n_logical_cpu : 8, // Logical CPU count + local_apic_id : 8; // Initial local APIC physical ID + // ecx + u32 sse3 : 1, // Streaming SIMD Extensions 3 (SSE3) + pclmulqdq : 1, // PCLMULQDQ instruction support + dtes64 : 1, // 64-bit DS save area + monitor : 1, // MONITOR/MWAIT support + dscpl : 1, // CPL Qualified Debug Store + vmx : 1, // Virtual Machine Extensions + smx : 1, // Safer Mode Extensions + est : 1, // Enhanced Intel SpeedStep + tm2 : 1, // Thermal Monitor 2 + ssse3 : 1, // Supplemental SSE3 + cntxt_id : 1, // L1 Context ID + sdbg : 1, // Silicon Debug + fma : 1, // FMA extensions using YMM state + cx16 : 1, // CMPXCHG16B instruction support + xtpr_update : 1, // xTPR Update Control + pdcm : 1, // Perfmon and Debug Capability + : 1, // Reserved + pcid : 1, // Process-context identifiers + dca : 1, // Direct Cache Access + sse4_1 : 1, // SSE4.1 + sse4_2 : 1, // SSE4.2 + x2apic : 1, // X2APIC support + movbe : 1, // MOVBE instruction support + popcnt : 1, // POPCNT instruction support + tsc_deadline_timer : 1, // APIC timer one-shot operation + aes : 1, // AES instructions + xsave : 1, // XSAVE (and related instructions) support + osxsave : 1, // XSAVE (and related instructions) are enabled by OS + avx : 1, // AVX instructions support + f16c : 1, // Half-precision floating-point conversion support + rdrand : 1, // RDRAND instruction support + guest_status : 1; // System is running as guest; (para-)virtualized s= ystem + // edx + u32 fpu : 1, // Floating-Point Unit on-chip (x87) + vme : 1, // Virtual-8086 Mode Extensions + de : 1, // Debugging Extensions + pse : 1, // Page Size Extension + tsc : 1, // Time Stamp Counter + msr : 1, // Model-Specific Registers (RDMSR and WRMSR support) + pae : 1, // Physical Address Extensions + mce : 1, // Machine Check Exception + cx8 : 1, // CMPXCHG8B instruction + apic : 1, // APIC on-chip + : 1, // Reserved + sep : 1, // SYSENTER, SYSEXIT, and associated MSRs + mtrr : 1, // Memory Type Range Registers + pge : 1, // Page Global Extensions + mca : 1, // Machine Check Architecture + cmov : 1, // Conditional Move Instruction + pat : 1, // Page Attribute Table + pse36 : 1, // Page Size Extension (36-bit) + psn : 1, // Processor Serial Number + clflush : 1, // CLFLUSH instruction + : 1, // Reserved + ds : 1, // Debug Store + acpi : 1, // Thermal monitor and clock control + mmx : 1, // MMX instructions + fxsr : 1, // FXSAVE and FXRSTOR instructions + sse : 1, // SSE instructions + sse2 : 1, // SSE2 instructions + selfsnoop : 1, // Self Snoop + htt : 1, // Hyper-threading + tm : 1, // Thermal Monitor + ia64 : 1, // Legacy IA-64 (Itanium) support bit, now reserved + pbe : 1; // Pending Break Enable +}; + +/* + * Leaf 0x2 + * Intel cache and TLB information one-byte descriptors + */ + +struct leaf_0x2_0 { + // eax + u32 iteration_count : 8, // Number of times this leaf must be queried + desc1 : 8, // Descriptor #1 + desc2 : 8, // Descriptor #2 + desc3 : 7, // Descriptor #3 + eax_invalid : 1; // Descriptors 1-3 are invalid if set + // ebx + u32 desc4 : 8, // Descriptor #4 + desc5 : 8, // Descriptor #5 + desc6 : 8, // Descriptor #6 + desc7 : 7, // Descriptor #7 + ebx_invalid : 1; // Descriptors 4-7 are invalid if set + // ecx + u32 desc8 : 8, // Descriptor #8 + desc9 : 8, // Descriptor #9 + desc10 : 8, // Descriptor #10 + desc11 : 7, // Descriptor #11 + ecx_invalid : 1; // Descriptors 8-11 are invalid if set + // edx + u32 desc12 : 8, // Descriptor #12 + desc13 : 8, // Descriptor #13 + desc14 : 8, // Descriptor #14 + desc15 : 7, // Descriptor #15 + edx_invalid : 1; // Descriptors 12-15 are invalid if set +}; + +/* + * Leaf 0x4 + * Intel deterministic cache parameters + */ + +struct leaf_0x4_n { + // eax + u32 cache_type : 5, // Cache type field + cache_level : 3, // Cache level (1-based) + cache_self_init : 1, // Self-initializing cache level + fully_associative : 1, // Fully-associative cache + : 4, // Reserved + num_threads_sharing : 12, // Number logical CPUs sharing this cache + num_cores_on_die : 6; // Number of cores in the physical package + // ebx + u32 cache_linesize : 12, // System coherency line size (0-based) + cache_npartitions : 10, // Physical line partitions (0-based) + cache_nways : 10; // Ways of associativity (0-based) + // ecx + u32 cache_nsets : 31, // Cache number of sets (0-based) + : 1; // Reserved + // edx + u32 wbinvd_rll_no_guarantee : 1, // WBINVD/INVD not guaranteed for Remo= te Lower-Level caches + ll_inclusive : 1, // Cache is inclusive of Lower-Level caches + complex_indexing : 1, // Not a direct-mapped cache (complex function) + : 29; // Reserved +}; + +#define LEAF_0x4_SUBLEAF_N_FIRST 0 +#define LEAF_0x4_SUBLEAF_N_LAST 31 + +/* + * Leaf 0x5 + * MONITOR/MWAIT instructions + */ + +struct leaf_0x5_0 { + // eax + u32 min_mon_size : 16, // Smallest monitor-line size, in bytes + : 16; // Reserved + // ebx + u32 max_mon_size : 16, // Largest monitor-line size, in bytes + : 16; // Reserved + // ecx + u32 mwait_ext : 1, // MONITOR/MWAIT extensions + mwait_irq_break : 1, // Interrupts as a break event for MWAIT + : 30; // Reserved + // edx + u32 n_c0_substates : 4, // Number of C0 sub C-states + n_c1_substates : 4, // Number of C1 sub C-states + n_c2_substates : 4, // Number of C2 sub C-states + n_c3_substates : 4, // Number of C3 sub C-states + n_c4_substates : 4, // Number of C4 sub C-states + n_c5_substates : 4, // Number of C5 sub C-states + n_c6_substates : 4, // Number of C6 sub C-states + n_c7_substates : 4; // Number of C7 sub C-states +}; + +/* + * Leaf 0x6 + * Thermal and power management + */ + +struct leaf_0x6_0 { + // eax + u32 digital_temp : 1, // Digital temperature sensor + turbo_boost : 1, // Intel Turbo Boost + lapic_timer_always_on : 1, // Always-Running APIC Timer (not affected = by p-state) + : 1, // Reserved + power_limit_event : 1, // Power Limit Notification (PLN) event + ecmd : 1, // Clock modulation duty cycle extension + package_thermal : 1, // Package thermal management + hwp_base_regs : 1, // HWP (Hardware P-states) base registers + hwp_notify : 1, // HWP notification (IA32_HWP_INTERRUPT MSR) + hwp_activity_window : 1, // HWP activity window (IA32_HWP_REQUEST[bits= 41:32]) + hwp_energy_perf_pr : 1, // HWP Energy Performance Preference + hwp_package_req : 1, // HWP Package Level Request + : 1, // Reserved + hdc_base_regs : 1, // HDC base registers + turbo_boost_3_0 : 1, // Intel Turbo Boost Max 3.0 + hwp_capabilities : 1, // HWP Highest Performance change + hwp_peci_override : 1, // HWP PECI override + hwp_flexible : 1, // Flexible HWP + hwp_fast : 1, // IA32_HWP_REQUEST MSR fast access mode + hw_feedback : 1, // HW_FEEDBACK MSRs + hwp_ignore_idle : 1, // Ignoring idle logical CPU HWP request is supp= orted + : 1, // Reserved + hwp_ctl : 1, // IA32_HWP_CTL MSR + thread_director : 1, // Intel thread director + therm_interrupt_bit25 : 1, // IA32_THERM_INTERRUPT MSR bit 25 + : 7; // Reserved + // ebx + u32 n_therm_thresholds : 4, // Digital thermometer thresholds + : 28; // Reserved + // ecx + u32 aperf_mperf : 1, // MPERF/APERF MSRs (effective frequency interfac= e) + : 2, // Reserved + energy_perf_bias : 1, // IA32_ENERGY_PERF_BIAS MSR + : 4, // Reserved + thrd_director_nclasses : 8, // Number of classes, Intel thread director + : 16; // Reserved + // edx + u32 perfcap_reporting : 1, // Performance capability reporting + encap_reporting : 1, // Energy efficiency capability reporting + : 6, // Reserved + feedback_sz : 4, // Feedback interface structure size, in 4K pages + : 4, // Reserved + this_lcpu_hwfdbk_idx : 16; // This logical CPU hardware feedback interf= ace index +}; + +/* + * Leaf 0x7 + * Extended CPU features + */ + +struct leaf_0x7_0 { + // eax + u32 leaf7_n_subleaves : 32; // Number of leaf 0x7 subleaves + // ebx + u32 fsgsbase : 1, // FSBASE/GSBASE read/write + tsc_adjust : 1, // IA32_TSC_ADJUST MSR + sgx : 1, // Intel SGX (Software Guard Extensions) + bmi1 : 1, // Bit manipulation extensions group 1 + hle : 1, // Hardware Lock Elision + avx2 : 1, // AVX2 instruction set + fdp_excptn_only : 1, // FPU Data Pointer updated only on x87 exceptio= ns + smep : 1, // Supervisor Mode Execution Protection + bmi2 : 1, // Bit manipulation extensions group 2 + erms : 1, // Enhanced REP MOVSB/STOSB + invpcid : 1, // INVPCID instruction (Invalidate Processor Context ID) + rtm : 1, // Intel restricted transactional memory + pqm : 1, // Intel RDT-CMT / AMD Platform-QoS cache monitoring + zero_fcs_fds : 1, // Deprecated FPU CS/DS (stored as zero) + mpx : 1, // Intel memory protection extensions + rdt_a : 1, // Intel RDT / AMD Platform-QoS Enforcement + avx512f : 1, // AVX-512 foundation instructions + avx512dq : 1, // AVX-512 double/quadword instructions + rdseed : 1, // RDSEED instruction + adx : 1, // ADCX/ADOX instructions + smap : 1, // Supervisor mode access prevention + avx512ifma : 1, // AVX-512 integer fused multiply add + : 1, // Reserved + clflushopt : 1, // CLFLUSHOPT instruction + clwb : 1, // CLWB instruction + intel_pt : 1, // Intel processor trace + avx512pf : 1, // AVX-512 prefetch instructions + avx512er : 1, // AVX-512 exponent/reciprocal instructions + avx512cd : 1, // AVX-512 conflict detection instructions + sha : 1, // SHA/SHA256 instructions + avx512bw : 1, // AVX-512 byte/word instructions + avx512vl : 1; // AVX-512 VL (128/256 vector length) extensions + // ecx + u32 prefetchwt1 : 1, // PREFETCHWT1 (Intel Xeon Phi only) + avx512vbmi : 1, // AVX-512 Vector byte manipulation instructions + umip : 1, // User mode instruction protection + pku : 1, // Protection keys for user-space + ospke : 1, // OS protection keys enable + waitpkg : 1, // WAITPKG instructions + avx512_vbmi2 : 1, // AVX-512 vector byte manipulation instructions gr= oup 2 + cet_ss : 1, // CET shadow stack features + gfni : 1, // Galois field new instructions + vaes : 1, // Vector AES instructions + vpclmulqdq : 1, // VPCLMULQDQ 256-bit instruction + avx512_vnni : 1, // Vector neural network instructions + avx512_bitalg : 1, // AVX-512 bitwise algorithms + tme : 1, // Intel total memory encryption + avx512_vpopcntdq : 1, // AVX-512: POPCNT for vectors of DWORD/QWORD + : 1, // Reserved + la57 : 1, // 57-bit linear addresses (five-level paging) + mawau_val_lm : 5, // BNDLDX/BNDSTX MAWAU value in 64-bit mode + rdpid : 1, // RDPID instruction + key_locker : 1, // Intel key locker + bus_lock_detect : 1, // OS bus-lock detection + cldemote : 1, // CLDEMOTE instruction + : 1, // Reserved + movdiri : 1, // MOVDIRI instruction + movdir64b : 1, // MOVDIR64B instruction + enqcmd : 1, // Enqueue stores (ENQCMD{,S}) + sgx_lc : 1, // Intel SGX launch configuration + pks : 1; // Protection keys for supervisor-mode pages + // edx + u32 : 1, // Reserved + sgx_keys : 1, // Intel SGX attestation services + avx512_4vnniw : 1, // AVX-512 neural network instructions + avx512_4fmaps : 1, // AVX-512 multiply accumulation single precision + fsrm : 1, // Fast short REP MOV + uintr : 1, // User interrupts + : 2, // Reserved + avx512_vp2intersect : 1, // VP2INTERSECT{D,Q} instructions + srdbs_ctrl : 1, // SRBDS mitigation MSR + md_clear : 1, // VERW MD_CLEAR microcode + rtm_always_abort : 1, // XBEGIN (RTM transaction) always aborts + : 1, // Reserved + tsx_force_abort : 1, // MSR TSX_FORCE_ABORT, RTM_ABORT bit + serialize : 1, // SERIALIZE instruction + hybrid_cpu : 1, // The CPU is identified as a 'hybrid part' + tsxldtrk : 1, // TSX suspend/resume load address tracking + : 1, // Reserved + pconfig : 1, // PCONFIG instruction + arch_lbr : 1, // Intel architectural LBRs + cet_ibt : 1, // CET indirect branch tracking + : 1, // Reserved + amx_bf16 : 1, // AMX-BF16: tile bfloat16 + avx512_fp16 : 1, // AVX-512 FP16 instructions + amx_tile : 1, // AMX-TILE: tile architecture + amx_int8 : 1, // AMX-INT8: tile 8-bit integer + spec_ctrl : 1, // Speculation Control (IBRS/IBPB: indirect branch res= trictions) + intel_stibp : 1, // Single thread indirect branch predictors + flush_l1d : 1, // FLUSH L1D cache: IA32_FLUSH_CMD MSR + arch_capabilities : 1, // Intel IA32_ARCH_CAPABILITIES MSR + core_capabilities : 1, // IA32_CORE_CAPABILITIES MSR + spec_ctrl_ssbd : 1; // Speculative store bypass disable +}; + +struct leaf_0x7_1 { + // eax + u32 : 4, // Reserved + avx_vnni : 1, // AVX-VNNI instructions + avx512_bf16 : 1, // AVX-512 bfloat16 instructions + lass : 1, // Linear address space separation + cmpccxadd : 1, // CMPccXADD instructions + arch_perfmon_ext : 1, // ArchPerfmonExt: leaf 0x23 + : 1, // Reserved + fzrm : 1, // Fast zero-length REP MOVSB + fsrs : 1, // Fast short REP STOSB + fsrc : 1, // Fast Short REP CMPSB/SCASB + : 4, // Reserved + fred : 1, // FRED: Flexible return and event delivery transitions + lkgs : 1, // LKGS: Load 'kernel' (userspace) GS + wrmsrns : 1, // WRMSRNS instruction (WRMSR-non-serializing) + nmi_src : 1, // NMI-source reporting with FRED event data + amx_fp16 : 1, // AMX-FP16: FP16 tile operations + hreset : 1, // HRESET (Thread director history reset) + avx_ifma : 1, // Integer fused multiply add + : 2, // Reserved + lam : 1, // Linear address masking + rd_wr_msrlist : 1, // RDMSRLIST/WRMSRLIST instructions + : 4; // Reserved + // ebx + u32 intel_ppin : 1, // Protected processor inventory number (PPIN{,_CT= L} MSRs) + : 31; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 4, // Reserved + avx_vnni_int8 : 1, // AVX-VNNI-INT8 instructions + avx_ne_convert : 1, // AVX-NE-CONVERT instructions + : 2, // Reserved + amx_complex : 1, // AMX-COMPLEX instructions (starting from Granite R= apids) + : 5, // Reserved + prefetchit_0_1 : 1, // PREFETCHIT0/1 instructions + : 3, // Reserved + cet_sss : 1, // CET supervisor shadow stacks safe to use + : 13; // Reserved +}; + +struct leaf_0x7_2 { + // eax + u32 : 32; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 intel_psfd : 1, // Intel predictive store forward disable + ipred_ctrl : 1, // MSR bits IA32_SPEC_CTRL.IPRED_DIS_{U,S} + rrsba_ctrl : 1, // MSR bits IA32_SPEC_CTRL.RRSBA_DIS_{U,S} + ddp_ctrl : 1, // MSR bit IA32_SPEC_CTRL.DDPD_U + bhi_ctrl : 1, // MSR bit IA32_SPEC_CTRL.BHI_DIS_S + mcdt_no : 1, // MCDT mitigation not needed + uclock_disable : 1, // UC-lock disable + : 25; // Reserved +}; + +/* + * Leaf 0x9 + * Intel DCA (Direct Cache Access) + */ + +struct leaf_0x9_0 { + // eax + u32 dca_enabled_in_bios : 1, // DCA is enabled in BIOS + : 31; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0xa + * Intel PMU (Performance Monitoring Unit) + */ + +struct leaf_0xa_0 { + // eax + u32 pmu_version : 8, // Performance monitoring unit version ID + num_counters_gp : 8, // Number of general-purpose PMU counters per lo= gical CPU + bit_width_gp : 8, // Bitwidth of PMU general-purpose counters + events_mask_len : 8; // Length of CPUID(0xa).EBX bit vector + // ebx + u32 no_core_cycle : 1, // Core cycle event not available + no_instruction_retired : 1, // Instruction retired event not available + no_reference_cycles : 1, // Reference cycles event not available + no_llc_reference : 1, // LLC-reference event not available + no_llc_misses : 1, // LLC-misses event not available + no_br_insn_retired : 1, // Branch instruction retired event not availa= ble + no_br_misses_retired : 1, // Branch mispredict retired event not avail= able + no_topdown_slots : 1, // Topdown slots event not available + no_backend_bound : 1, // Topdown backend bound not available + no_bad_speculation : 1, // Topdown bad speculation not available + no_frontend_bound : 1, // Topdown frontend bound not available + no_retiring : 1, // Topdown retiring not available + no_lbr_inserts : 1, // LBR inserts not available + : 19; // Reserved + // ecx + u32 pmu_fcounters_bitmap : 32; // Fixed-function PMU counters support bi= tmap + // edx + u32 num_counters_fixed : 5, // Number of fixed PMU counters + bitwidth_fixed : 8, // Bitwidth of PMU fixed counters + : 2, // Reserved + anythread_deprecation : 1, // AnyThread mode deprecation + : 16; // Reserved +}; + +/* + * Leaf 0xb + * CPU extended topology v1 + */ + +struct leaf_0xb_n { + // eax + u32 x2apic_id_shift : 5, // Bit width of this level (previous levels i= nclusive) + : 27; // Reserved + // ebx + u32 domain_lcpus_count : 16, // Logical CPUs count across all instances = of this domain + : 16; // Reserved + // ecx + u32 domain_nr : 8, // This domain level (subleaf ID) + domain_type : 8, // This domain type + : 16; // Reserved + // edx + u32 x2apic_id : 32; // x2APIC ID of current logical CPU +}; + +#define LEAF_0xb_SUBLEAF_N_FIRST 0 +#define LEAF_0xb_SUBLEAF_N_LAST 1 + +/* + * Leaf 0xd + * CPU extended state + */ + +struct leaf_0xd_0 { + // eax + u32 xcr0_x87 : 1, // XCR0.X87 + xcr0_sse : 1, // XCR0.SSE + xcr0_avx : 1, // XCR0.AVX + xcr0_mpx_bndregs : 1, // XCR0.BNDREGS: MPX BND0-BND3 registers + xcr0_mpx_bndcsr : 1, // XCR0.BNDCSR: MPX BNDCFGU/BNDSTATUS registers + xcr0_avx512_opmask : 1, // XCR0.OPMASK: AVX-512 k0-k7 registers + xcr0_avx512_zmm_hi256 : 1, // XCR0.ZMM_Hi256: AVX-512 ZMM0->ZMM7/15 re= gisters + xcr0_avx512_hi16_zmm : 1, // XCR0.HI16_ZMM: AVX-512 ZMM16->ZMM31 regis= ters + : 1, // Reserved + xcr0_pkru : 1, // XCR0.PKRU: XSAVE PKRU registers + : 1, // Reserved + xcr0_cet_u : 1, // XCR0.CET_U: CET user state + xcr0_cet_s : 1, // XCR0.CET_S: CET supervisor state + : 4, // Reserved + xcr0_tileconfig : 1, // XCR0.TILECONFIG: AMX can manage TILECONFIG + xcr0_tiledata : 1, // XCR0.TILEDATA: AMX can manage TILEDATA + : 13; // Reserved + // ebx + u32 xsave_sz_xcr0 : 32; // XSAVE/XRSTOR area byte size, for XCR0 enable= d features + // ecx + u32 xsave_sz_max : 32; // XSAVE/XRSTOR area max byte size, all CPU feat= ures + // edx + u32 : 30, // Reserved + xcr0_lwp : 1, // AMD XCR0.LWP: Light-weight Profiling + : 1; // Reserved +}; + +struct leaf_0xd_1 { + // eax + u32 xsaveopt : 1, // XSAVEOPT instruction + xsavec : 1, // XSAVEC instruction + xgetbv1 : 1, // XGETBV instruction with ECX =3D 1 + xsaves : 1, // XSAVES/XRSTORS instructions (and XSS MSR) + xfd : 1, // Extended feature disable + : 27; // Reserved + // ebx + u32 xsave_sz_xcr0_xss : 32; // XSAVES/XSAVEC area byte size, for XCR0|XS= S enabled features + // ecx + u32 : 8, // Reserved + xss_pt : 1, // PT state + : 1, // Reserved + xss_pasid : 1, // PASID state + xss_cet_u : 1, // CET user state + xss_cet_p : 1, // CET supervisor state + xss_hdc : 1, // HDC state + xss_uintr : 1, // UINTR state + xss_lbr : 1, // LBR state + xss_hwp : 1, // HWP state + : 15; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0xd_n { + // eax + u32 xsave_sz : 32; // Subleaf-N feature save area size, in bytes + // ebx + u32 xsave_offset : 32; // Subleaf-N feature save area offset, in bytes + // ecx + u32 is_xss_bit : 1, // Subleaf N describes an XSS bit (otherwise XCR0) + compacted_xsave_64byte_aligned : 1, // When compacted, subleaf-N XSAVE = area is 64-byte aligned + : 30; // Reserved + // edx + u32 : 32; // Reserved +}; + +#define LEAF_0xd_SUBLEAF_N_FIRST 2 +#define LEAF_0xd_SUBLEAF_N_LAST 63 + +/* + * Leaf 0xf + * Intel RDT / AMD PQoS resource monitoring + */ + +struct leaf_0xf_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 core_rmid_max : 32; // RMID max within this core (0-based) + // ecx + u32 : 32; // Reserved + // edx + u32 : 1, // Reserved + llc_qos_mon : 1, // LLC QoS-monitoring + : 30; // Reserved +}; + +struct leaf_0xf_1 { + // eax + u32 l3c_qm_bitwidth : 8, // L3 QoS-monitoring counter bitwidth (24-bas= ed) + l3c_qm_overflow_bit : 1, // QM_CTR MSR bit 61 is an overflow bit + io_rdt_cmt : 1, // non-CPU agent supporting Intel RDT CMT present + io_rdt_mbm : 1, // non-CPU agent supporting Intel RDT MBM present + : 21; // Reserved + // ebx + u32 l3c_qm_conver_factor : 32; // QM_CTR MSR conversion factor to bytes + // ecx + u32 l3c_qm_rmid_max : 32; // L3 QoS-monitoring max RMID + // edx + u32 l3c_qm_occupancy : 1, // L3 QoS occupancy monitoring + l3c_qm_mbm_total : 1, // L3 QoS total bandwidth monitoring + l3c_qm_mbm_local : 1, // L3 QoS local bandwidth monitoring + : 29; // Reserved +}; + +/* + * Leaf 0x10 + * Intel RDT / AMD PQoS allocation + */ + +struct leaf_0x10_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 : 1, // Reserved + cat_l3 : 1, // L3 Cache Allocation Technology + cat_l2 : 1, // L2 Cache Allocation Technology + mba : 1, // Memory Bandwidth Allocation + : 28; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x10_n { + // eax + u32 cat_cbm_len : 5, // L3/L2_CAT capacity bitmask length, minus-one n= otation + : 27; // Reserved + // ebx + u32 cat_units_bitmap : 32; // L3/L2_CAT allocation units bitmap + // ecx + u32 : 1, // Reserved + l3_cat_cos_infreq_updates : 1, // L3_CAT COS updates should be infreque= nt + cat_cdp_supported : 1, // L3/L2_CAT Code and Data Prioritization + cat_sparse_1s : 1, // L3/L2_CAT non-contiguous 1s value + : 28; // Reserved + // edx + u32 cat_cos_max : 16, // L3/L2_CAT max Class of Service + : 16; // Reserved +}; + +#define LEAF_0x10_SUBLEAF_N_FIRST 1 +#define LEAF_0x10_SUBLEAF_N_LAST 2 + +struct leaf_0x10_3 { + // eax + u32 mba_max_delay : 12, // Max MBA throttling value; minus-one notation + : 20; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 mba_per_thread : 1, // Per-thread MBA controls + : 1, // Reserved + mba_delay_linear : 1, // Delay values are linear + : 29; // Reserved + // edx + u32 mba_cos_max : 16, // MBA max Class of Service + : 16; // Reserved +}; + +/* + * Leaf 0x12 + * Intel SGX (Software Guard Extensions) + */ + +struct leaf_0x12_0 { + // eax + u32 sgx1 : 1, // SGX1 leaf functions + sgx2 : 1, // SGX2 leaf functions + : 3, // Reserved + enclv_leaves : 1, // ENCLV leaves + encls_leaves : 1, // ENCLS leaves + enclu_everifyreport2 : 1, // ENCLU leaf EVERIFYREPORT2 + : 2, // Reserved + encls_eupdatesvn : 1, // ENCLS leaf EUPDATESVN + enclu_edeccssa : 1, // ENCLU leaf EDECCSSA + : 20; // Reserved + // ebx + u32 miscselect_exinfo : 1, // SSA.MISC frame: Enclave #PF and #GP repor= ting + miscselect_cpinfo : 1, // SSA.MISC frame: Enclave #CP reporting + : 30; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 max_enclave_sz_not64 : 8, // Maximum enclave size in non-64-bit mod= e (log2) + max_enclave_sz_64 : 8, // Maximum enclave size in 64-bit mode (log2) + : 16; // Reserved +}; + +struct leaf_0x12_1 { + // eax + u32 secs_attr_init : 1, // Enclave initialized by EINIT + secs_attr_debug : 1, // Enclave permits debugger read/write + secs_attr_mode64bit : 1, // Enclave runs in 64-bit mode + : 1, // Reserved + secs_attr_provisionkey : 1, // Provisioning key + secs_attr_einittoken_key : 1, // EINIT token key + secs_attr_cet : 1, // CET attributes + secs_attr_kss : 1, // Key Separation and Sharing + : 2, // Reserved + secs_attr_aexnotify : 1, // Enclave threads: AEX notifications + : 21; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 xfrm_x87 : 1, // Enclave XFRM.X87 + xfrm_sse : 1, // Enclave XFRM.SEE + xfrm_avx : 1, // Enclave XFRM.AVX + xfrm_mpx_bndregs : 1, // Enclave XFRM.BNDREGS (MPX BND0-BND3 registers) + xfrm_mpx_bndcsr : 1, // Enclave XFRM.BNDCSR (MPX BNDCFGU/BNDSTATUS re= gisters) + xfrm_avx512_opmask : 1, // Enclave XFRM.OPMASK (AVX-512 k0-k7 register= s) + xfrm_avx512_zmm_hi256 : 1, // Enclave XFRM.ZMM_Hi256 (AVX-512 ZMM0->ZM= M7/15 registers) + xfrm_avx512_hi16_zmm : 1, // Enclave XFRM.HI16_ZMM (AVX-512 ZMM16->ZMM= 31 registers) + : 1, // Reserved + xfrm_pkru : 1, // Enclave XFRM.PKRU (XSAVE PKRU registers) + : 7, // Reserved + xfrm_tileconfig : 1, // Enclave XFRM.TILECONFIG (AMX can manage TILEC= ONFIG) + xfrm_tiledata : 1, // Enclave XFRM.TILEDATA (AMX can manage TILEDATA) + : 13; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x12_n { + // eax + u32 subleaf_type : 4, // Subleaf type + : 8, // Reserved + epc_sec_base_addr_0 : 20; // EPC section base address, bits[12:31] + // ebx + u32 epc_sec_base_addr_1 : 20, // EPC section base address, bits[32:51] + : 12; // Reserved + // ecx + u32 epc_sec_type : 4, // EPC section type / property encoding + : 8, // Reserved + epc_sec_size_0 : 20; // EPC section size, bits[12:31] + // edx + u32 epc_sec_size_1 : 20, // EPC section size, bits[32:51] + : 12; // Reserved +}; + +#define LEAF_0x12_SUBLEAF_N_FIRST 2 +#define LEAF_0x12_SUBLEAF_N_LAST 31 + +/* + * Leaf 0x14 + * Intel Processor Trace + */ + +struct leaf_0x14_0 { + // eax + u32 pt_max_subleaf : 32; // Maximum leaf 0x14 subleaf + // ebx + u32 cr3_filtering : 1, // IA32_RTIT_CR3_MATCH is accessible + psb_cyc : 1, // Configurable PSB and cycle-accurate mode + ip_filtering : 1, // IP/TraceStop filtering; Warm-reset PT MSRs prese= rvation + mtc_timing : 1, // MTC timing packet; COFI-based packets suppression + ptwrite : 1, // PTWRITE instruction + power_event_trace : 1, // Power Event Trace + psb_pmi_preserve : 1, // PSB and PMI preservation + event_trace : 1, // Event Trace packet generation + tnt_disable : 1, // TNT packet generation disable + : 23; // Reserved + // ecx + u32 topa_output : 1, // ToPA output scheme + topa_multiple_entries : 1, // ToPA tables can hold multiple entries + single_range_output : 1, // Single-range output + trance_transport_output : 1, // Trace Transport subsystem output + : 27, // Reserved + ip_payloads_lip : 1; // IP payloads have LIP values (CS base included) + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x14_1 { + // eax + u32 num_address_ranges : 3, // Number of configurable Address Ranges + : 13, // Reserved + mtc_periods_bmp : 16; // MTC period encodings bitmap + // ebx + u32 cycle_thresholds_bmp : 16, // Cycle Threshold encodings bitmap + psb_periods_bmp : 16; // Configurable PSB frequency encodings bitmap + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x15 + * Intel TSC (Time Stamp Counter) + */ + +struct leaf_0x15_0 { + // eax + u32 tsc_denominator : 32; // Denominator of the TSC/'core crystal clock= ' ratio + // ebx + u32 tsc_numerator : 32; // Numerator of the TSC/'core crystal clock' ra= tio + // ecx + u32 cpu_crystal_hz : 32; // Core crystal clock nominal frequency, in Hz + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x16 + * Intel processor frequency + */ + +struct leaf_0x16_0 { + // eax + u32 cpu_base_mhz : 16, // Processor base frequency, in MHz + : 16; // Reserved + // ebx + u32 cpu_max_mhz : 16, // Processor max frequency, in MHz + : 16; // Reserved + // ecx + u32 bus_mhz : 16, // Bus reference frequency, in MHz + : 16; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x17 + * Intel SoC vendor attributes + */ + +struct leaf_0x17_0 { + // eax + u32 soc_max_subleaf : 32; // Maximum leaf 0x17 subleaf + // ebx + u32 soc_vendor_id : 16, // SoC vendor ID + is_vendor_scheme : 1, // Assigned by industry enumeration scheme (not = Intel) + : 15; // Reserved + // ecx + u32 soc_proj_id : 32; // SoC project ID, assigned by vendor + // edx + u32 soc_stepping_id : 32; // Soc project stepping ID, assigned by vendor +}; + +struct leaf_0x17_n { + // eax + u32 vendor_brand_a : 32; // Vendor Brand ID string, bytes subleaf_nr * = (0 -> 3) + // ebx + u32 vendor_brand_b : 32; // Vendor Brand ID string, bytes subleaf_nr * = (4 -> 7) + // ecx + u32 vendor_brand_c : 32; // Vendor Brand ID string, bytes subleaf_nr * = (8 -> 11) + // edx + u32 vendor_brand_d : 32; // Vendor Brand ID string, bytes subleaf_nr * = (12 -> 15) +}; + +#define LEAF_0x17_SUBLEAF_N_FIRST 1 +#define LEAF_0x17_SUBLEAF_N_LAST 3 + +/* + * Leaf 0x18 + * Intel deterministic address translation (TLB) parameters + */ + +struct leaf_0x18_n { + // eax + u32 tlb_max_subleaf : 32; // Maximum leaf 0x18 subleaf + // ebx + u32 tlb_4k_page : 1, // TLB supports 4KB-page entries + tlb_2m_page : 1, // TLB supports 2MB-page entries + tlb_4m_page : 1, // TLB supports 4MB-page entries + tlb_1g_page : 1, // TLB supports 1GB-page entries + : 4, // Reserved + hard_partitioning : 3, // Partitioning between logical CPUs + : 5, // Reserved + n_way_associative : 16; // Ways of associativity + // ecx + u32 n_sets : 32; // Number of sets + // edx + u32 tlb_type : 5, // Translation cache type (TLB type) + tlb_cache_level : 3, // Translation cache level (1-based) + is_fully_associative : 1, // Fully-associative + : 5, // Reserved + tlb_max_addressible_ids : 12, // Max number of addressable IDs - 1 + : 6; // Reserved +}; + +#define LEAF_0x18_SUBLEAF_N_FIRST 0 +#define LEAF_0x18_SUBLEAF_N_LAST 31 + +/* + * Leaf 0x19 + * Intel key locker + */ + +struct leaf_0x19_0 { + // eax + u32 kl_cpl0_only : 1, // CPL0-only key Locker restriction + kl_no_encrypt : 1, // No-encrypt key locker restriction + kl_no_decrypt : 1, // No-decrypt key locker restriction + : 29; // Reserved + // ebx + u32 aes_keylocker : 1, // AES key locker instructions + : 1, // Reserved + aes_keylocker_wide : 1, // AES wide key locker instructions + : 1, // Reserved + kl_msr_iwkey : 1, // Key locker MSRs and IWKEY backups + : 27; // Reserved + // ecx + u32 loadiwkey_no_backup : 1, // LOADIWKEY NoBackup parameter + iwkey_rand : 1, // IWKEY randomization + : 30; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x1a + * Intel hybrid CPUs identification (e.g. Atom, Core) + */ + +struct leaf_0x1a_0 { + // eax + u32 core_native_model : 24, // This core's native model ID + core_type : 8; // This core's type + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x1b + * Intel PCONFIG (Platform configuration) + */ + +struct leaf_0x1b_n { + // eax + u32 pconfig_subleaf_type : 12, // CPUID 0x1b subleaf type + : 20; // Reserved + // ebx + u32 pconfig_target_id_x : 32; // A supported PCONFIG target ID + // ecx + u32 pconfig_target_id_y : 32; // A supported PCONFIG target ID + // edx + u32 pconfig_target_id_z : 32; // A supported PCONFIG target ID +}; + +#define LEAF_0x1b_SUBLEAF_N_FIRST 0 +#define LEAF_0x1b_SUBLEAF_N_LAST 31 + +/* + * Leaf 0x1c + * Intel LBR (Last Branch Record) + */ + +struct leaf_0x1c_0 { + // eax + u32 lbr_depth_mask : 8, // Max LBR stack depth bitmask + : 22, // Reserved + lbr_deep_c_reset : 1, // LBRs maybe cleared on MWAIT C-state > C1 + lbr_ip_is_lip : 1; // LBR IP contain Last IP (otherwise effective IP) + // ebx + u32 lbr_cpl : 1, // CPL filtering + lbr_branch_filter : 1, // Branch filtering + lbr_call_stack : 1, // Call-stack mode + : 29; // Reserved + // ecx + u32 lbr_mispredict : 1, // Branch misprediction bit + lbr_timed_lbr : 1, // Timed LBRs (CPU cycles since last LBR entry) + lbr_branch_type : 1, // Branch type field + : 13, // Reserved + lbr_events_gpc_bmp : 4, // PMU-events logging support + : 12; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x1d + * Intel AMX (Advanced Matrix Extensions) tile information + */ + +struct leaf_0x1d_0 { + // eax + u32 amx_max_palette : 32; // Highest palette ID / subleaf ID + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x1d_1 { + // eax + u32 amx_palette_size : 16, // AMX palette total tiles size, in bytes + amx_tile_size : 16; // AMX single tile's size, in bytes + // ebx + u32 amx_tile_row_size : 16, // AMX tile single row's size, in bytes + amx_palette_nr_tiles : 16; // AMX palette number of tiles + // ecx + u32 amx_tile_nr_rows : 16, // AMX tile max number of rows + : 16; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x1e + * Intel TMUL (Tile-matrix Multiply) + */ + +struct leaf_0x1e_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 tmul_maxk : 8, // TMUL unit maximum height, K (rows or columns) + tmul_maxn : 16, // TMUL unit maximum SIMD dimension, N (column bytes) + : 8; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x1f + * Intel extended topology v2 + */ + +struct leaf_0x1f_n { + // eax + u32 x2apic_id_shift : 5, // Bit width of this level (previous levels i= nclusive) + : 27; // Reserved + // ebx + u32 domain_lcpus_count : 16, // Logical CPUs count across all instances = of this domain + : 16; // Reserved + // ecx + u32 domain_level : 8, // This domain level (subleaf ID) + domain_type : 8, // This domain type + : 16; // Reserved + // edx + u32 x2apic_id : 32; // x2APIC ID of current logical CPU +}; + +#define LEAF_0x1f_SUBLEAF_N_FIRST 0 +#define LEAF_0x1f_SUBLEAF_N_LAST 5 + +/* + * Leaf 0x20 + * Intel HRESET (History Reset) + */ + +struct leaf_0x20_0 { + // eax + u32 hreset_nr_subleaves : 32; // CPUID 0x20 max subleaf + 1 + // ebx + u32 hreset_thread_director : 1, // Intel thread director HRESET + : 31; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x21 + * Intel TD (Trust Domain) + */ + +struct leaf_0x21_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 tdx_vendorid_0 : 32; // TDX vendor ID string bytes 0 - 3 + // ecx + u32 tdx_vendorid_2 : 32; // CPU vendor ID string bytes 8 - 11 + // edx + u32 tdx_vendorid_1 : 32; // CPU vendor ID string bytes 4 - 7 +}; + +/* + * Leaf 0x23 + * Intel Architectural Performance Monitoring Extended (ArchPerfmonExt) + */ + +struct leaf_0x23_0 { + // eax + u32 subleaf_0 : 1, // Subleaf 0, this subleaf + counters_subleaf : 1, // Subleaf 1, PMU counter bitmaps + acr_subleaf : 1, // Subleaf 2, Auto Counter Reload bitmaps + events_subleaf : 1, // Subleaf 3, PMU event bitmaps + pebs_caps_subleaf : 1, // Subleaf 4, PEBS capabilities + pebs_subleaf : 1, // Subleaf 5, Arch PEBS bitmaps + : 26; // Reserved + // ebx + u32 unitmask2 : 1, // IA32_PERFEVTSELx MSRs UnitMask2 bit + eq : 1, // IA32_PERFEVTSELx MSRs EQ bit + rdpmc_user_disable : 1, // RDPMC userspace disable + : 29; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x23_1 { + // eax + u32 gp_counters : 32; // Bitmap of general-purpose PMU counters + // ebx + u32 fixed_counters : 32; // Bitmap of fixed PMU counters + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x23_2 { + // eax + u32 acr_gp_reload : 32; // Bitmap of general-purpose counters that can = be reloaded + // ebx + u32 acr_fixed_reload : 32; // Bitmap of fixed counters that can be reloa= ded + // ecx + u32 acr_gp_trigger : 32; // Bitmap of general-purpose counters that can= trigger reloads + // edx + u32 acr_fixed_trigger : 32; // Bitmap of fixed counters that can trigger= reloads +}; + +struct leaf_0x23_3 { + // eax + u32 core_cycles_evt : 1, // Core cycles event + insn_retired_evt : 1, // Instructions retired event + ref_cycles_evt : 1, // Reference cycles event + llc_refs_evt : 1, // Last-level cache references event + llc_misses_evt : 1, // Last-level cache misses event + br_insn_ret_evt : 1, // Branch instruction retired event + br_mispr_evt : 1, // Branch mispredict retired event + td_slots_evt : 1, // Topdown slots event + td_backend_bound_evt : 1, // Topdown backend bound event + td_bad_spec_evt : 1, // Topdown bad speculation event + td_frontend_bound_evt : 1, // Topdown frontend bound event + td_retiring_evt : 1, // Topdown retiring event + : 20; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x23_4 { + // eax + u32 : 32; // Reserved + // ebx + u32 : 3, // Reserved + allow_in_record : 1, // ALLOW_IN_RECORD bit in MSRs + counters_gp : 1, // Counters group sub-group general-purpose counters + counters_fixed : 1, // Counters group sub-group fixed-function counte= rs + counters_metrics : 1, // Counters group sub-group performance metrics + : 1, // Reserved + lbr : 2, // LBR group + : 6, // Reserved + xer : 8, // XER group + : 5, // Reserved + gpr : 1, // GPR group + aux : 1, // AUX group + : 1; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x23_5 { + // eax + u32 pebs_gp : 32; // Architectural PEBS general-purpose counters + // ebx + u32 pebs_pdist_gp : 32; // Architectural PEBS PDIST general-purpose cou= nters + // ecx + u32 pebs_fixed : 32; // Architectural PEBS fixed counters + // edx + u32 pebs_pdist_fixed : 32; // Architectural PEBS PDIST fixed counters +}; + +/* + * Leaf 0x40000000 + * Maximum hypervisor leaf + hypervisor vendor string + */ + +struct leaf_0x40000000_0 { + // eax + u32 max_hyp_leaf : 32; // Maximum hypervisor leaf + // ebx + u32 hypervisor_id_0 : 32; // Hypervisor ID string bytes 0 - 3 + // ecx + u32 hypervisor_id_1 : 32; // Hypervisor ID string bytes 4 - 7 + // edx + u32 hypervisor_id_2 : 32; // Hypervisor ID string bytes 8 - 11 +}; + +/* + * Leaf 0x4c780001 + * Linux-defined synthetic feature flags + */ + +struct leaf_0x4c780001_0 { + // eax + u32 cxmmx : 1, // Cyrix MMX extensions + k6_mtrr : 1, // AMD K6 nonstandard MTRRs + cyrix_arr : 1, // Cyrix ARRs (=3D MTRRs) + centaur_mcr : 1, // Centaur MCRs (=3D MTRRs) + k8 : 1, // Opteron, Athlon64 + zen5 : 1, // CPU based on Zen5 micro-architecture + zen6 : 1, // CPU based on Zen6 micro-architecture + : 1, // Reserved + constant_tsc : 1, // TSC ticks at a constant rate + up : 1, // SMP kernel running on UP + art : 1, // Always running timer (ART) + arch_perfmon : 1, // Intel Architectural PerfMon + pebs : 1, // Precise-Event Based Sampling + bts : 1, // Branch Trace Store + syscall32 : 1, // SYSCALL in IA32 userspace + sysenter32 : 1, // SYSENTER in IA32 userspace + rep_good : 1, // REP microcode works well + amd_lbr_v2 : 1, // AMD Last Branch Record Extension version 2 + clear_cpu_buf : 1, // Clear CPU buffers using VERW + acc_power : 1, // AMD Accumulated Power Mechanism + nopl : 1, // The NOPL instructions + always : 1, // Always-present feature + xtopology : 1, // CPU topology enumeration extensions + tsc_reliable : 1, // TSC is known to be reliable + nonstop_tsc : 1, // TSC does not stop in C states + cpuid : 1, // CPU has the CPUID instruction + extd_apicid : 1, // Extended APIC ID (8 bits) + amd_dcm : 1, // AMD multi-node processor + aperfmperf : 1, // APERF/MPERF MSRs: P-State hardware coordination fe= edback + rapl : 1, // AMD/Hygon RAPL interface + nonstop_tsc_s3 : 1, // TSC does not stop in S3 state + tsc_known_freq : 1; // TSC has known frequency + // ebx + u32 ring3mwait : 1, // Ring 3 MONITOR/MWAIT instructions + cpuid_fault : 1, // Intel CPUID faulting + cpb : 1, // AMD Core Performance Boost + epb : 1, // IA32_ENERGY_PERF_BIAS support + cat_l3 : 1, // Cache Allocation Technology L3 + cat_l2 : 1, // Cache Allocation Technology L2 + cdp_l3 : 1, // Code and Data Prioritization L3 + tdx_host_platform : 1, // Platform supports being a TDX host + hw_pstate : 1, // AMD Hardware P-state control + proc_feedback : 1, // AMD Processor Feedback Interface + xcompacted : 1, // Use compacted XSTATE (XSAVES or XSAVEC) + pti : 1, // Kernel Page Table Isolation enabled + kernel_ibrs : 1, // Set/clear IBRS on kernel entry/exit + rsb_vmexit : 1, // Fill RSB on VM-Exit + intel_ppin : 1, // Intel Processor Inventory Number + cdp_l2 : 1, // Code and Data Prioritization L2 + msr_spec_ctrl : 1, // MSR SPEC_CTRL is implemented + ssbd : 1, // Speculative Store Bypass Disable + mba : 1, // Memory Bandwidth Allocation + rsb_ctxsw : 1, // Fill RSB on context switches + perfmon_v2 : 1, // AMD Performance Monitoring Version 2 + : 1, // Reserved + use_ibrs_fw : 1, // Use IBRS during runtime firmware calls + ss_bypass_disable : 1, // Disable Speculative Store Bypass + ls_cfg_ssbd : 1, // AMD SSBD implementation via LS_CFG MSR + ibrs : 1, // Indirect Branch Restricted Speculation + ibpb : 1, // Indirect Branch Prediction Barrier (without RSB flush g= uarantee) + stibp : 1, // Single Thread Indirect Branch Predictors + zen : 1, // Generic flag for all Zen and newer + l1tf_pteinv : 1, // L1TF workaround PTE inversion + ibrs_enhanced : 1, // Enhanced IBRS + msr_ia32_feat_ctl : 1; // MSR IA32_FEAT_CTL configured + // ecx + u32 tpr_shadow : 1, // Intel TPR Shadow + flexpriority : 1, // Intel FlexPriority + ept : 1, // Intel Extended Page Table + vpid : 1, // Intel Virtual Processor ID + coherency_sfw_no : 1, // SNP cache coherency software work around not = needed + : 10, // Reserved + vmmcall : 1, // Prefer VMMCALL to VMCALL + xenpv : 1, // Xen paravirtual guest + ept_ad : 1, // Intel Extended Page Table access-dirty bit + VMCALL : 1, // Hypervisor supports the VMCALL instruction + vmw_vmmcall : 1, // VMware prefers the VMMCALL instruction + pvunlock : 1, // PV unlock function + vcpupreempt : 1, // PV vcpu_is_preempted function + tdx_guest : 1, // Intel Trust Domain Extensions Guest + : 9; // Reserved + // edx + u32 cqm_llc : 1, // LLC QoS + cqm_occup_llc : 1, // LLC occupancy monitoring + cqm_mbm_total : 1, // LLC Total MBM monitoring + cqm_mbm_local : 1, // LLC Local MBM monitoring + fence_swapgs_user : 1, // LFENCE in user entry SWAPGS path + fence_swapgs_kernel : 1, // LFENCE in kernel entry SWAPGS path + split_lock_detect : 1, // #AC for split lock + per_thread_mba : 1, // Per-thread Memory Bandwidth Allocation + sgx1 : 1, // SGX Basic + sgx2 : 1, // SGX Enclave Dynamic Memory Management (EDMM) + entry_ibpb : 1, // Issue an IBPB on kernel entry + rrsba_ctrl : 1, // RET prediction control + retpoline : 1, // Generic Retpoline mitigation for Spectre variant 2 + retpoline_lfence : 1, // Use LFENCE for Spectre variant 2 + rethunk : 1, // Use Return THUNK + unret : 1, // AMD BTB untrain return + use_ibpb_fw : 1, // Use IBPB during runtime firmware calls + rsb_vmexit_lite : 1, // Fill RSB on VM exit when EIBRS is enabled + sgx_edeccssa : 1, // SGX EDECCSSA user leaf function + call_depth : 1, // Call depth tracking for RSB stuffing + msr_tsx_ctrl : 1, // MSR IA32_TSX_CTRL (Intel) implemented + smba : 1, // Slow Memory Bandwidth Allocation + bmec : 1, // Bandwidth Monitoring Event Configuration + user_shstk : 1, // Shadow stack support for user mode applications + srso : 1, // AMD BTB untrain RETs + srso_alias : 1, // AMD BTB untrain RETs through aliasing + ibpb_on_vmexit : 1, // Issue an IBPB only on VMEXIT + apic_msrs_fence : 1, // IA32_TSC_DEADLINE and X2APIC MSRs need fencing + zen2 : 1, // CPU based on Zen2 microarchitecture + zen3 : 1, // CPU based on Zen3 microarchitecture + zen4 : 1, // CPU based on Zen4 microarchitecture + zen1 : 1; // CPU based on Zen1 microarchitecture +}; + +struct leaf_0x4c780001_1 { + // eax + u32 overflow_recov : 1, // MCA overflow recovery support + succor : 1, // Uncorrectable error containment and recovery + : 1, // Reserved + smca : 1, // Scalable MCA + : 28; // Reserved + // ebx + u32 amd_lbr_pmc_freeze : 1, // AMD LBR and PMC Freeze + clear_bhb_loop : 1, // Clear branch history at SYSCALL entry using SW= loop + bhi_ctrl : 1, // BHI_DIS_S HW control available + clear_bhb_hw : 1, // BHI_DIS_S HW control enabled + clear_bhb_vmexit : 1, // Clear branch history at VMEXIT using SW loop + amd_fast_cppc : 1, // AMD fast Collaborative Processor Performance Co= ntrol + amd_htr_cores : 1, // Heterogeneous Core Topology + amd_workload_class : 1, // Workload Classification + prefer_ymm : 1, // Avoid ZMM registers due to downclocking + apx : 1, // Advanced Performance Extensions + indirect_thunk_its : 1, // Use thunk for indirect branches in lower ha= lf of cache line + tsa_sq_no : 1, // AMD CPU not vulnerable to TSA-SQ + tsa_l1_no : 1, // AMD CPU not vulnerable to TSA-L1 + clear_cpu_buf_vm : 1, // Clear CPU buffers using VERW before VMRUN + ibpb_exit_to_user : 1, // Use IBPB on exit-to-userspace, see VMSCAPE b= ug + : 17; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x4c780002 + * Linux-defined synthetic CPU bug flags + */ + +struct leaf_0x4c780002_0 { + // eax + u32 f00f : 1, // Intel F00F + fdiv : 1, // FPU FDIV + coma : 1, // Cyrix 6x86 coma + amd_tlb_mmatch : 1, // AMD Erratum 383 + amd_apic_c1e : 1, // AMD Erratum 400 + bug_11ap : 1, // Bad local APIC aka 11AP + fxsave_leak : 1, // FXSAVE leaks FOP/FIP/FOP + clflush_monitor : 1, // AAI65, CLFLUSH required before MONITOR + sysret_ss_attrs : 1, // SYSRET does not fix up SS attributes + espfix : 1, // IRET to 16-bit SS corrupts ESP/RSP high bits (x86-32) + null_seg : 1, // Setting a selector to NULL preserves the base + swapgs_fence : 1, // SWAPGS without input dep on GS + monitor : 1, // IPI required to wake up remote CPU + amd_e400 : 1, // CPU is among the affected by Erratum 400 + cpu_meltdown : 1, // CPU affected by meltdown; needs kernel page tabl= e isolation + spectre_v1 : 1, // CPU affected by Spectre variant 1 with conditional= branches + specture_v2 : 1, // CPU affected by Spectre variant 2 with indirect b= ranches + spec_store_bypass : 1, // CPU affected by speculative store bypass att= ack + l1tf : 1, // CPU affected by L1 Terminal Fault + mds : 1, // CPU affected by Microarchitectural data sampling + msbds_only : 1, // Microarchitectural data sampling: CPU only affecte= d by the MSDBS variant + swapgs : 1, // CPU affected by speculation through SWAPGS + taa : 1, // CPU is affected by TSX Async Abort (TAA) + itlb_multihit : 1, // CPU may incur MCE during certain page attribute= changes + srbds : 1, // CPU may leak RNG bits if not mitigated + mmio_stale_data : 1, // CPU affected by Processor MMIO Stale Data vul= nerabilities + : 1, // Reserved + retbleed : 1, // CPU affected by Retbleed + eibrs_pbrsb : 1, // EIBRS is vulnerable to Post Barrier RSB Predictio= ns + smt_rsb : 1, // CPU vulnerable to Cross-Thread Return Address Predic= tions + gds : 1, // CPU affected by Gather Data Sampling + tdx_pw_mce : 1; // CPU may incur #MC if non-TD software does partial = write to TDX private memory + // ebx + u32 srso : 1, // AMD SRSO bug + div0 : 1, // AMD DIV0 speculation bug + rfds : 1, // CPU vulnerable to Register File Data Sampling + bhi : 1, // CPU affected by Branch History Injection + ibpb_no_ret : 1, // IBPB omits return target predictions + spectre_v2_user : 1, // CPU affected by Spectre variant 2 between use= r processes + old_microcode : 1, // CPU has old microcode; it must be vulnerable to= something + its : 1, // CPU affected by Indirect Target Selection + its_native_only : 1, // CPU affected by ITS; VMX is not affected + tsa : 1, // CPU affected by Transient Scheduler Attacks + vmscape : 1, // CPU affected by VMSCAPE attacks from guests + : 21; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x80000000 + * Maximum extended leaf + CPU vendor string + */ + +struct leaf_0x80000000_0 { + // eax + u32 max_ext_leaf : 32; // Maximum extended CPUID leaf + // ebx + u32 cpu_vendorid_0 : 32; // Vendor ID string bytes 0 - 3 + // ecx + u32 cpu_vendorid_2 : 32; // Vendor ID string bytes 8 - 11 + // edx + u32 cpu_vendorid_1 : 32; // Vendor ID string bytes 4 - 7 +}; + +/* + * Leaf 0x80000001 + * Extended CPU features + */ + +struct leaf_0x80000001_0 { + // eax + u32 e_stepping_id : 4, // Stepping ID + e_base_model : 4, // Base processor model + e_base_family : 4, // Base processor family + e_base_type : 2, // Base processor type (Transmeta) + : 2, // Reserved + e_ext_model : 4, // Extended processor model + e_ext_family : 8, // Extended processor family + : 4; // Reserved + // ebx + u32 brand_id : 16, // Brand ID + : 12, // Reserved + pkg_type : 4; // Package type + // ecx + u32 lahf_lm : 1, // LAHF and SAHF in 64-bit mode + cmp_legacy : 1, // Multi-processing legacy mode (No HT) + svm : 1, // Secure Virtual Machine + extapic : 1, // Extended APIC space + cr8_legacy : 1, // LOCK MOV CR0 means MOV CR8 + lzcnt_abm : 1, // LZCNT advanced bit manipulation + sse4a : 1, // SSE4A support + misaligned_sse : 1, // Misaligned SSE mode + _3dnow_prefetch : 1, // 3DNow PREFETCH/PREFETCHW support + osvw : 1, // OS visible workaround + ibs : 1, // Instruction based sampling + xop : 1, // XOP: extended operation (AVX instructions) + skinit : 1, // SKINIT/STGI support + wdt : 1, // Watchdog timer support + : 1, // Reserved + lwp : 1, // Lightweight profiling + fma4 : 1, // 4-operand FMA instruction + tce : 1, // Translation cache extension + : 1, // Reserved + nodeid_msr : 1, // NodeId MSR (0xc001100c) + : 1, // Reserved + tbm : 1, // Trailing bit manipulations + topoext : 1, // Topology Extensions (leaf 0x8000001d) + perfctr_core : 1, // Core performance counter extensions + perfctr_nb : 1, // NB/DF performance counter extensions + : 1, // Reserved + data_bp_ext : 1, // Data access breakpoint extension + perf_tsc : 1, // Performance time-stamp counter + perfctr_llc : 1, // LLC (L3) performance counter extensions + mwaitx : 1, // MWAITX/MONITORX support + addr_mask_ext : 1, // Breakpoint address mask extension (to bit 31) + : 1; // Reserved + // edx + u32 e_fpu : 1, // Floating-Point Unit on-chip (x87) + e_vme : 1, // Virtual-8086 Mode Extensions + e_de : 1, // Debugging Extensions + e_pse : 1, // Page Size Extension + e_tsc : 1, // Time Stamp Counter + e_msr : 1, // Model-Specific Registers (RDMSR and WRMSR support) + pae : 1, // Physical Address Extensions + mce : 1, // Machine Check Exception + cx8 : 1, // CMPXCHG8B instruction + apic : 1, // APIC on-chip + : 1, // Reserved + syscall : 1, // SYSCALL and SYSRET instructions + mtrr : 1, // Memory Type Range Registers + pge : 1, // Page Global Extensions + mca : 1, // Machine Check Architecture + cmov : 1, // Conditional Move Instruction + pat : 1, // Page Attribute Table + pse36 : 1, // Page Size Extension (36-bit) + : 1, // Reserved + obsolete_mp_bit : 1, // Out-of-spec AMD Multiprocessing bit + nx : 1, // No-execute page protection + : 1, // Reserved + mmxext : 1, // AMD MMX extensions + e_mmx : 1, // MMX instructions + e_fxsr : 1, // FXSAVE and FXRSTOR instructions + fxsr_opt : 1, // FXSAVE and FXRSTOR optimizations + page1gb : 1, // 1-GB large page support + rdtscp : 1, // RDTSCP instruction + : 1, // Reserved + lm : 1, // Long mode (x86-64, 64-bit support) + _3dnowext : 1, // AMD 3DNow extensions + _3dnow : 1; // 3DNow instructions +}; + +/* + * Leaf 0x80000002 + * CPU brand ID string, bytes 0 - 15 + */ + +struct leaf_0x80000002_0 { + // eax + u32 cpu_brandid_0 : 32; // CPU brand ID string, bytes 0 - 3 + // ebx + u32 cpu_brandid_1 : 32; // CPU brand ID string, bytes 4 - 7 + // ecx + u32 cpu_brandid_2 : 32; // CPU brand ID string, bytes 8 - 11 + // edx + u32 cpu_brandid_3 : 32; // CPU brand ID string, bytes 12 - 15 +}; + +/* + * Leaf 0x80000003 + * CPU brand ID string, bytes 16 - 31 + */ + +struct leaf_0x80000003_0 { + // eax + u32 cpu_brandid_4 : 32; // CPU brand ID string bytes, 16 - 19 + // ebx + u32 cpu_brandid_5 : 32; // CPU brand ID string bytes, 20 - 23 + // ecx + u32 cpu_brandid_6 : 32; // CPU brand ID string bytes, 24 - 27 + // edx + u32 cpu_brandid_7 : 32; // CPU brand ID string bytes, 28 - 31 +}; + +/* + * Leaf 0x80000004 + * CPU brand ID string, bytes 32 - 47 + */ + +struct leaf_0x80000004_0 { + // eax + u32 cpu_brandid_8 : 32; // CPU brand ID string, bytes 32 - 35 + // ebx + u32 cpu_brandid_9 : 32; // CPU brand ID string, bytes 36 - 39 + // ecx + u32 cpu_brandid_10 : 32; // CPU brand ID string, bytes 40 - 43 + // edx + u32 cpu_brandid_11 : 32; // CPU brand ID string, bytes 44 - 47 +}; + +/* + * Leaf 0x80000005 + * AMD/Transmeta L1 cache and TLB + */ + +struct leaf_0x80000005_0 { + // eax + u32 l1_itlb_2m_4m_nentries : 8, // L1 ITLB #entries, 2M and 4M pages + l1_itlb_2m_4m_assoc : 8, // L1 ITLB associativity, 2M and 4M pages + l1_dtlb_2m_4m_nentries : 8, // L1 DTLB #entries, 2M and 4M pages + l1_dtlb_2m_4m_assoc : 8; // L1 DTLB associativity, 2M and 4M pages + // ebx + u32 l1_itlb_4k_nentries : 8, // L1 ITLB #entries, 4K pages + l1_itlb_4k_assoc : 8, // L1 ITLB associativity, 4K pages + l1_dtlb_4k_nentries : 8, // L1 DTLB #entries, 4K pages + l1_dtlb_4k_assoc : 8; // L1 DTLB associativity, 4K pages + // ecx + u32 l1_dcache_line_size : 8, // L1 dcache line size, in bytes + l1_dcache_nlines : 8, // L1 dcache lines per tag + l1_dcache_assoc : 8, // L1 dcache associativity + l1_dcache_size_kb : 8; // L1 dcache size, in KB + // edx + u32 l1_icache_line_size : 8, // L1 icache line size, in bytes + l1_icache_nlines : 8, // L1 icache lines per tag + l1_icache_assoc : 8, // L1 icache associativity + l1_icache_size_kb : 8; // L1 icache size, in KB +}; + +/* + * Leaf 0x80000006 + * (Mostly AMD) L2/L3 cache and TLB + */ + +struct leaf_0x80000006_0 { + // eax + u32 l2_itlb_2m_4m_nentries : 12, // L2 iTLB #entries, 2M and 4M pages + l2_itlb_2m_4m_assoc : 4, // L2 iTLB associativity, 2M and 4M pages + l2_dtlb_2m_4m_nentries : 12, // L2 dTLB #entries, 2M and 4M pages + l2_dtlb_2m_4m_assoc : 4; // L2 dTLB associativity, 2M and 4M pages + // ebx + u32 l2_itlb_4k_nentries : 12, // L2 iTLB #entries, 4K pages + l2_itlb_4k_assoc : 4, // L2 iTLB associativity, 4K pages + l2_dtlb_4k_nentries : 12, // L2 dTLB #entries, 4K pages + l2_dtlb_4k_assoc : 4; // L2 dTLB associativity, 4K pages + // ecx + u32 l2_line_size : 8, // L2 cache line size, in bytes + l2_nlines : 4, // L2 cache number of lines per tag + l2_assoc : 4, // L2 cache associativity + l2_size_kb : 16; // L2 cache size, in KB + // edx + u32 l3_line_size : 8, // L3 cache line size, in bytes + l3_nlines : 4, // L3 cache number of lines per tag + l3_assoc : 4, // L3 cache associativity + : 2, // Reserved + l3_size_range : 14; // L3 cache size range +}; + +/* + * Leaf 0x80000007 + * CPU power management (mostly AMD) and AMD RAS + */ + +struct leaf_0x80000007_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 mca_overflow_recovery : 1, // MCA overflow conditions not fatal + succor : 1, // Software containment of uncorrectable errors + hw_assert : 1, // Hardware assert MSRs + scalable_mca : 1, // Scalable MCA (MCAX MSRs) + : 28; // Reserved + // ecx + u32 cpu_pwr_sample_ratio : 32; // CPU power sample time ratio + // edx + u32 digital_temp : 1, // Digital temperature sensor + powernow_freq_id : 1, // PowerNOW! frequency scaling + powernow_volt_id : 1, // PowerNOW! voltage scaling + thermal_trip : 1, // THERMTRIP (Thermal Trip) + hw_thermal_control : 1, // Hardware thermal control + sw_thermal_control : 1, // Software thermal control + _100mhz_steps : 1, // 100 MHz multiplier control + hw_pstate : 1, // Hardware P-state control + constant_tsc : 1, // TSC ticks at constant rate across all P and C st= ates + core_perf_boost : 1, // Core performance boost + eff_freq_ro : 1, // Read-only effective frequency interface + proc_feedback : 1, // Processor feedback interface (deprecated) + proc_power_reporting : 1, // Processor power reporting interface + connected_standby : 1, // CPU Connected Standby support + rapl_interface : 1, // Runtime Average Power Limit interface + : 17; // Reserved +}; + +/* + * Leaf 0x80000008 + * CPU capacity parameters and extended feature flags (mostly AMD) + */ + +struct leaf_0x80000008_0 { + // eax + u32 phys_addr_bits : 8, // Max physical address bits + virt_addr_bits : 8, // Max virtual address bits + guest_phys_addr_bits : 8, // Max nested-paging guest physical address = bits + : 8; // Reserved + // ebx + u32 clzero : 1, // CLZERO instruction + insn_retired_perf : 1, // Instruction retired counter MSR + xsave_err_ptr : 1, // XSAVE/XRSTOR always saves/restores FPU error po= inters + invlpgb : 1, // INVLPGB broadcasts a TLB invalidate + rdpru : 1, // RDPRU (Read Processor Register at User level) + : 1, // Reserved + mba : 1, // Memory Bandwidth Allocation (AMD bit) + : 1, // Reserved + mcommit : 1, // MCOMMIT instruction + wbnoinvd : 1, // WBNOINVD instruction + : 2, // Reserved + ibpb : 1, // Indirect Branch Prediction Barrier + wbinvd_int : 1, // Interruptible WBINVD/WBNOINVD + ibrs : 1, // Indirect Branch Restricted Speculation + stibp : 1, // Single Thread Indirect Branch Prediction mode + ibrs_always_on : 1, // IBRS always-on preferred + stibp_always_on : 1, // STIBP always-on preferred + ibrs_fast : 1, // IBRS is preferred over software solution + ibrs_same_mode : 1, // IBRS provides same mode protection + no_efer_lmsle : 1, // Long-Mode Segment Limit Enable unsupported + tlb_flush_nested : 1, // INVLPGB RAX[5] bit can be set + : 1, // Reserved + amd_ppin : 1, // Protected Processor Inventory Number + amd_ssbd : 1, // Speculative Store Bypass Disable + virt_ssbd : 1, // virtualized SSBD (Speculative Store Bypass Disable) + amd_ssb_no : 1, // SSBD is not needed (fixed in hardware) + cppc : 1, // Collaborative Processor Performance Control + amd_psfd : 1, // Predictive Store Forward Disable + btc_no : 1, // CPU not affected by Branch Type Confusion + ibpb_ret : 1, // IBPB clears RSB/RAS too + branch_sampling : 1; // Branch Sampling + // ecx + u32 cpu_nthreads : 8, // Number of physical threads - 1 + : 4, // Reserved + apicid_coreid_len : 4, // Number of thread core ID bits (shift) in API= C ID + perf_tsc_len : 2, // Performance time-stamp counter size + : 14; // Reserved + // edx + u32 invlpgb_max_pages : 16, // INVLPGB maximum page count + rdpru_max_reg_id : 16; // RDPRU max register ID (ECX input) +}; + +/* + * Leaf 0x8000000a + * AMD SVM (Secure Virtual Machine) + */ + +struct leaf_0x8000000a_0 { + // eax + u32 svm_version : 8, // SVM revision number + : 24; // Reserved + // ebx + u32 svm_nasid : 32; // Number of address space identifiers (ASID) + // ecx + u32 : 4, // Reserved + pml : 1, // Page Modification Logging (PML) + : 27; // Reserved + // edx + u32 nested_pt : 1, // Nested paging + lbr_virt : 1, // LBR virtualization + svm_lock : 1, // SVM lock + nrip_save : 1, // NRIP save support on #VMEXIT + tsc_rate_msr : 1, // MSR based TSC rate control + vmcb_clean : 1, // VMCB clean bits support + flush_by_asid : 1, // Flush by ASID + Extended VMCB TLB_Control + decode_assists : 1, // Decode Assists support + : 2, // Reserved + pause_filter : 1, // Pause intercept filter + : 1, // Reserved + pf_threshold : 1, // Pause filter threshold + avic : 1, // Advanced virtual interrupt controller + : 1, // Reserved + v_vmsave_vmload : 1, // Virtual VMSAVE/VMLOAD (nested virtualization) + v_gif : 1, // Virtualize the Global Interrupt Flag + gmet : 1, // Guest mode execution trap + x2avic : 1, // Virtual x2APIC + sss_check : 1, // Supervisor Shadow Stack restrictions + v_spec_ctrl : 1, // Virtual SPEC_CTRL + ro_gpt : 1, // Read-Only guest page table support + : 1, // Reserved + h_mce_override : 1, // Host MCE override + tlbsync_int : 1, // TLBSYNC intercept + INVLPGB/TLBSYNC in VMCB + nmi_virt : 1, // NMI virtualization + ibs_virt : 1, // IBS Virtualization + ext_lvt_off_chg : 1, // Extended LVT offset fault change + svme_addr_chk : 1, // Guest SVME address check + : 3; // Reserved +}; + +/* + * Leaf 0x80000019 + * AMD TLB characteristics for 1GB pages + */ + +struct leaf_0x80000019_0 { + // eax + u32 l1_itlb_1g_nentries : 12, // L1 iTLB #entries, 1G pages + l1_itlb_1g_assoc : 4, // L1 iTLB associativity, 1G pages + l1_dtlb_1g_nentries : 12, // L1 dTLB #entries, 1G pages + l1_dtlb_1g_assoc : 4; // L1 dTLB associativity, 1G pages + // ebx + u32 l2_itlb_1g_nentries : 12, // L2 iTLB #entries, 1G pages + l2_itlb_1g_assoc : 4, // L2 iTLB associativity, 1G pages + l2_dtlb_1g_nentries : 12, // L2 dTLB #entries, 1G pages + l2_dtlb_1g_assoc : 4; // L2 dTLB associativity, 1G pages + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x8000001a + * AMD instruction optimizations + */ + +struct leaf_0x8000001a_0 { + // eax + u32 fp_128 : 1, // Internal FP/SIMD exec data path is 128-bits wide + movu_preferred : 1, // SSE: MOVU* better than MOVL*/MOVH* + fp_256 : 1, // internal FP/SSE exec data path is 256-bits wide + : 29; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x8000001b + * AMD IBS (Instruction-Based Sampling) + */ + +struct leaf_0x8000001b_0 { + // eax + u32 ibs_flags : 1, // IBS feature flags + ibs_fetch_sampling : 1, // IBS fetch sampling + ibs_op_sampling : 1, // IBS execution sampling + ibs_rdwr_op_counter : 1, // IBS read/write of op counter + ibs_op_count : 1, // IBS OP counting mode + ibs_branch_target : 1, // IBS branch target address reporting + ibs_op_counters_ext : 1, // IBS IbsOpCurCnt/IbsOpMaxCnt extend by 7 bi= ts + ibs_rip_invalid_chk : 1, // IBS invalid RIP indication + ibs_op_branch_fuse : 1, // IBS fused branch micro-op indication + ibs_fetch_ctl_ext : 1, // IBS Fetch Control Extended MSR + ibs_op_data_4 : 1, // IBS op data 4 MSR + ibs_l3_miss_filter : 1, // IBS L3-miss filtering (Zen4+) + : 20; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x8000001c + * AMD LWP (Lightweight Profiling) + */ + +struct leaf_0x8000001c_0 { + // eax + u32 os_lwp_avail : 1, // OS: LWP is available to application programs + os_lpwval : 1, // OS: LWPVAL instruction + os_lwp_ire : 1, // OS: Instructions Retired Event + os_lwp_bre : 1, // OS: Branch Retired Event + os_lwp_dme : 1, // OS: Dcache Miss Event + os_lwp_cnh : 1, // OS: CPU Clocks Not Halted event + os_lwp_rnh : 1, // OS: CPU Reference clocks Not Halted event + : 22, // Reserved + os_lwp_cont : 1, // OS: LWP sampling in continuous mode + os_lwp_ptsc : 1, // OS: Performance Time Stamp Counter in event recor= ds + os_lwp_int : 1; // OS: Interrupt on threshold overflow + // ebx + u32 lwp_lwpcb_sz : 8, // Control Block size, in quadwords + lwp_event_sz : 8, // Event record size, in bytes + lwp_max_events : 8, // Max EventID supported + lwp_event_offset : 8; // Control Block events area offset + // ecx + u32 lwp_latency_max : 5, // Cache latency counters number of bits + lwp_data_addr : 1, // Cache miss events report data cache address + lwp_latency_rnd : 3, // Cache latency rounding amount + lwp_version : 7, // LWP version + lwp_buf_min_sz : 8, // LWP event ring buffer min size, 32 event recor= ds units + : 4, // Reserved + lwp_branch_predict : 1, // Branches Retired events can be filtered + lwp_ip_filtering : 1, // IP filtering (IPI, IPF, BaseIP, and LimitIP @= LWPCP) + lwp_cache_levels : 1, // Cache-related events: filter by cache level + lwp_cache_latency : 1; // Cache-related events: filter by latency + // edx + u32 hw_lwp_avail : 1, // HW: LWP available + hw_lpwval : 1, // HW: LWPVAL available + hw_lwp_ire : 1, // HW: Instructions Retired Event + hw_lwp_bre : 1, // HW: Branch Retired Event + hw_lwp_dme : 1, // HW: Dcache Miss Event + hw_lwp_cnh : 1, // HW: Clocks Not Halted event + hw_lwp_rnh : 1, // HW: Reference clocks Not Halted event + : 22, // Reserved + hw_lwp_cont : 1, // HW: LWP sampling in continuous mode + hw_lwp_ptsc : 1, // HW: Performance Time Stamp Counter in event recor= ds + hw_lwp_int : 1; // HW: Interrupt on threshold overflow +}; + +/* + * Leaf 0x8000001d + * AMD deterministic cache parameters + */ + +struct leaf_0x8000001d_n { + // eax + u32 cache_type : 5, // Cache type field + cache_level : 3, // Cache level (1-based) + cache_self_init : 1, // Self-initializing cache level + fully_associative : 1, // Fully-associative cache + : 4, // Reserved + num_threads_sharing : 12, // Number of logical CPUs sharing cache + : 6; // Reserved + // ebx + u32 cache_linesize : 12, // System coherency line size (0-based) + cache_npartitions : 10, // Physical line partitions (0-based) + cache_nways : 10; // Ways of associativity (0-based) + // ecx + u32 cache_nsets : 31, // Cache number of sets (0-based) + : 1; // Reserved + // edx + u32 wbinvd_rll_no_guarantee : 1, // WBINVD/INVD not guaranteed for Remo= te Lower-Level caches + ll_inclusive : 1, // Cache is inclusive of Lower-Level caches + : 30; // Reserved +}; + +#define LEAF_0x8000001d_SUBLEAF_N_FIRST 0 +#define LEAF_0x8000001d_SUBLEAF_N_LAST 31 + +/* + * Leaf 0x8000001e + * AMD CPU topology + */ + +struct leaf_0x8000001e_0 { + // eax + u32 ext_apic_id : 32; // Extended APIC ID + // ebx + u32 core_id : 8, // Unique per-socket logical core unit ID + core_nthreads : 8, // #Threads per core (zero-based) + : 16; // Reserved + // ecx + u32 node_id : 8, // Node (die) ID of invoking logical CPU + nnodes_per_socket : 3, // #nodes in invoking logical CPU's package/soc= ket + : 21; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x8000001f + * AMD encrypted memory capabilities (SME/SEV) + */ + +struct leaf_0x8000001f_0 { + // eax + u32 sme : 1, // Secure Memory Encryption + sev : 1, // Secure Encrypted Virtualization + vm_page_flush : 1, // VM Page Flush MSR + sev_encrypted_state : 1, // SEV Encrypted State + sev_nested_paging : 1, // SEV secure nested paging + vm_permission_levels : 1, // VMPL + rpmquery : 1, // RPMQUERY instruction + vmpl_sss : 1, // VMPL supervisor shadow stack + secure_tsc : 1, // Secure TSC + virt_tsc_aux : 1, // Hardware virtualizes TSC_AUX + sme_coherent : 1, // Cache coherency enforcement across encryption do= mains + req_64bit_hypervisor : 1, // SEV guest mandates 64-bit hypervisor + restricted_injection : 1, // Restricted Injection supported + alternate_injection : 1, // Alternate Injection supported + debug_swap : 1, // SEV-ES: Full debug state swap + disallow_host_ibs : 1, // SEV-ES: Disallowing IBS use by the host + virt_transparent_enc : 1, // Virtual Transparent Encryption + vmgexit_parameter : 1, // SEV_FEATURES: VmgexitParameter + virt_tom_msr : 1, // Virtual TOM MSR + virt_ibs : 1, // SEV-ES guests: IBS state virtualization + : 4, // Reserved + vmsa_reg_protection : 1, // VMSA register protection + smt_protection : 1, // SMT protection + : 2, // Reserved + svsm_page_msr : 1, // SVSM communication page MSR + nested_virt_snp_msr : 1, // VIRT_RMPUPDATE/VIRT_PSMASH MSRs + : 2; // Reserved + // ebx + u32 pte_cbit_pos : 6, // PTE bit number to enable memory encryption + phys_addr_reduction_nbits : 6, // Reduction of phys address space in bi= ts + vmpl_count : 4, // Number of VM permission levels (VMPL) + : 16; // Reserved + // ecx + u32 enc_guests_max : 32; // Max number of simultaneous encrypted guests + // edx + u32 min_sev_asid_no_sev_es : 32; // Minimum ASID for SEV-enabled SEV-ES-= disabled guest +}; + +/* + * Leaf 0x80000020 + * AMD PQoS (Platform QoS) extended features + */ + +struct leaf_0x80000020_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 : 1, // Reserved + mba : 1, // Memory Bandwidth Allocation support + smba : 1, // Slow Memory Bandwidth Allocation support + bmec : 1, // Bandwidth Monitoring Event Configuration support + l3rr : 1, // L3 Range Reservation support + abmc : 1, // Assignable Bandwidth Monitoring Counters + sdciae : 1, // Smart Data Cache Injection (SDCI) Allocation Enforcem= ent + : 25; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +struct leaf_0x80000020_1 { + // eax + u32 mba_limit_len : 32; // MBA enforcement limit size + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 mba_cos_max : 32; // MBA max Class of Service number (zero-based) +}; + +struct leaf_0x80000020_2 { + // eax + u32 smba_limit_len : 32; // SMBA enforcement limit size + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 smba_cos_max : 32; // SMBA max Class of Service number (zero-based) +}; + +struct leaf_0x80000020_3 { + // eax + u32 : 32; // Reserved + // ebx + u32 bmec_num_events : 8, // BMEC number of bandwidth events available + : 24; // Reserved + // ecx + u32 bmec_local_reads : 1, // Local NUMA reads can be tracked + bmec_remote_reads : 1, // Remote NUMA reads can be tracked + bmec_local_nontemp_wr : 1, // Local NUMA non-temporal writes can be tr= acked + bmec_remote_nontemp_wr : 1, // Remote NUMA non-temporal writes can be = tracked + bmec_local_slow_mem_rd : 1, // Local NUMA slow-memory reads can be tra= cked + bmec_remote_slow_mem_rd : 1, // Remote NUMA slow-memory reads can be t= racked + bmec_all_dirty_victims : 1, // Dirty QoS victims to all types of memor= y can be tracked + : 25; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x80000021 + * AMD extended CPU features 2 + */ + +struct leaf_0x80000021_0 { + // eax + u32 no_nested_data_bp : 1, // No nested data breakpoints + fsgs_non_serializing : 1, // WRMSR to {FS,GS,KERNEL_GS}_BASE is non-se= rializing + lfence_serializing : 1, // LFENCE always serializing / synchronizes RD= TSC + smm_page_cfg_lock : 1, // SMM paging configuration lock + : 2, // Reserved + null_sel_clr_base : 1, // Null selector clears base + upper_addr_ignore : 1, // EFER MSR Upper Address Ignore + auto_ibrs : 1, // EFER MSR Automatic IBRS + no_smm_ctl_msr : 1, // SMM_CTL MSR not available + fsrs : 1, // Fast Short Rep STOSB + fsrc : 1, // Fast Short Rep CMPSB + : 1, // Reserved + prefetch_ctl_msr : 1, // Prefetch control MSR + : 2, // Reserved + opcode_reclaim : 1, // Reserves opcode space + user_cpuid_disable : 1, // #GP when executing CPUID at CPL > 0 + epsf : 1, // Enhanced Predictive Store Forwarding + : 3, // Reserved + wl_feedback : 1, // Workload-based heuristic feedback to OS + : 1, // Reserved + eraps : 1, // Enhanced Return Address Predictor Security + : 2, // Reserved + sbpb : 1, // Selective Branch Predictor Barrier + ibpb_brtype : 1, // Branch predictions flushed from CPU branch predic= tor + srso_no : 1, // No SRSO vulnerability + srso_uk_no : 1, // No SRSO at user-kernel boundary + srso_msr_fix : 1; // MSR BP_CFG[BpSpecReduce] SRSO mitigation + // ebx + u32 microcode_patch_size : 16, // Microcode patch size, in 16-byte units + rap_size : 8, // Return Address Predictor size + : 8; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x80000022 + * AMD extended performance monitoring + */ + +struct leaf_0x80000022_0 { + // eax + u32 perfmon_v2 : 1, // Performance monitoring v2 + lbr_v2 : 1, // Last Branch Record v2 extensions (LBR Stack) + lbr_pmc_freeze : 1, // Freezing core performance counters / LBR Stack + : 29; // Reserved + // ebx + u32 n_pmc_core : 4, // Number of core performance counters + lbr_v2_stack_size : 6, // Number of LBR stack entries + n_pmc_northbridge : 6, // Number of northbridge performance counters + n_pmc_umc : 6, // Number of UMC performance counters + : 10; // Reserved + // ecx + u32 active_umc_bitmask : 32; // Active UMCs bitmask + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x80000023 + * AMD multi-key encrypted memory + */ + +struct leaf_0x80000023_0 { + // eax + u32 mem_hmk_mode : 1, // MEM-HMK encryption mode + : 31; // Reserved + // ebx + u32 mem_hmk_avail_keys : 16, // Total number of available encryption keys + : 16; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x80000026 + * AMD extended CPU topology + */ + +struct leaf_0x80000026_n { + // eax + u32 x2apic_id_shift : 5, // Bit width of this level (previous levels i= nclusive) + : 24, // Reserved + core_has_pwreff_ranking : 1, // This core has a power efficiency ranki= ng + domain_has_hybrid_cores : 1, // This domain level has hybrid (E, P) co= res + domain_core_count_asymm : 1; // The 'Core' domain has asymmetric cores= count + // ebx + u32 domain_lcpus_count : 16, // Number of logical CPUs at this domain in= stance + core_pwreff_ranking : 8, // This core's static power efficiency ranking + core_native_model_id : 4, // This core's native model ID + core_type : 4; // This core's type + // ecx + u32 domain_level : 8, // This domain level (subleaf ID) + domain_type : 8, // This domain type + : 16; // Reserved + // edx + u32 x2apic_id : 32; // x2APIC ID of current logical CPU +}; + +#define LEAF_0x80000026_SUBLEAF_N_FIRST 0 +#define LEAF_0x80000026_SUBLEAF_N_LAST 3 + +/* + * Leaf 0x80860000 + * Maximum Transmeta leaf + CPU vendor string + */ + +struct leaf_0x80860000_0 { + // eax + u32 max_tra_leaf : 32; // Maximum Transmeta leaf + // ebx + u32 cpu_vendorid_0 : 32; // Transmeta Vendor ID string bytes 0 - 3 + // ecx + u32 cpu_vendorid_2 : 32; // Transmeta Vendor ID string bytes 8 - 11 + // edx + u32 cpu_vendorid_1 : 32; // Transmeta Vendor ID string bytes 4 - 7 +}; + +/* + * Leaf 0x80860001 + * Transmeta extended CPU features + */ + +struct leaf_0x80860001_0 { + // eax + u32 stepping : 4, // Stepping ID + base_model : 4, // Base CPU model ID + base_family_id : 4, // Base CPU family ID + cpu_type : 2, // CPU type + : 18; // Reserved + // ebx + u32 cpu_rev_mask_minor : 8, // CPU revision ID, mask minor + cpu_rev_mask_major : 8, // CPU revision ID, mask major + cpu_rev_minor : 8, // CPU revision ID, minor + cpu_rev_major : 8; // CPU revision ID, major + // ecx + u32 cpu_base_mhz : 32; // CPU nominal frequency, in MHz + // edx + u32 recovery : 1, // Recovery CMS is active (after bad flush) + longrun : 1, // LongRun power management capabilities + : 1, // Reserved + lrti : 1, // LongRun Table Interface + : 28; // Reserved +}; + +/* + * Leaf 0x80860002 + * Transmeta CMS (Code Morphing Software) + */ + +struct leaf_0x80860002_0 { + // eax + u32 cpu_rev_id : 32; // CPU revision ID + // ebx + u32 cms_rev_mask_2 : 8, // CMS revision ID, mask component 2 + cms_rev_mask_1 : 8, // CMS revision ID, mask component 1 + cms_rev_minor : 8, // CMS revision ID, minor + cms_rev_major : 8; // CMS revision ID, major + // ecx + u32 cms_rev_mask_3 : 32; // CMS revision ID, mask component 3 + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0x80860003 + * Transmeta CPU information string, bytes 0 - 15 + */ + +struct leaf_0x80860003_0 { + // eax + u32 cpu_info_0 : 32; // CPU info string bytes 0 - 3 + // ebx + u32 cpu_info_1 : 32; // CPU info string bytes 4 - 7 + // ecx + u32 cpu_info_2 : 32; // CPU info string bytes 8 - 11 + // edx + u32 cpu_info_3 : 32; // CPU info string bytes 12 - 15 +}; + +/* + * Leaf 0x80860004 + * Transmeta CPU information string, bytes 16 - 31 + */ + +struct leaf_0x80860004_0 { + // eax + u32 cpu_info_4 : 32; // CPU info string bytes 16 - 19 + // ebx + u32 cpu_info_5 : 32; // CPU info string bytes 20 - 23 + // ecx + u32 cpu_info_6 : 32; // CPU info string bytes 24 - 27 + // edx + u32 cpu_info_7 : 32; // CPU info string bytes 28 - 31 +}; + +/* + * Leaf 0x80860005 + * Transmeta CPU information string, bytes 32 - 47 + */ + +struct leaf_0x80860005_0 { + // eax + u32 cpu_info_8 : 32; // CPU info string bytes 32 - 35 + // ebx + u32 cpu_info_9 : 32; // CPU info string bytes 36 - 39 + // ecx + u32 cpu_info_10 : 32; // CPU info string bytes 40 - 43 + // edx + u32 cpu_info_11 : 32; // CPU info string bytes 44 - 47 +}; + +/* + * Leaf 0x80860006 + * Transmeta CPU information string, bytes 48 - 63 + */ + +struct leaf_0x80860006_0 { + // eax + u32 cpu_info_12 : 32; // CPU info string bytes 48 - 51 + // ebx + u32 cpu_info_13 : 32; // CPU info string bytes 52 - 55 + // ecx + u32 cpu_info_14 : 32; // CPU info string bytes 56 - 59 + // edx + u32 cpu_info_15 : 32; // CPU info string bytes 60 - 63 +}; + +/* + * Leaf 0x80860007 + * Transmeta live CPU information + */ + +struct leaf_0x80860007_0 { + // eax + u32 cpu_cur_mhz : 32; // Current CPU frequency, in MHz + // ebx + u32 cpu_cur_voltage : 32; // Current CPU voltage, in millivolts + // ecx + u32 cpu_cur_perf_pctg : 32; // Current CPU performance percentage, 0 - 1= 00 + // edx + u32 cpu_cur_gate_delay : 32; // Current CPU gate delay, in femtoseconds +}; + +/* + * Leaf 0xc0000000 + * Maximum Centaur/Zhaoxin leaf + */ + +struct leaf_0xc0000000_0 { + // eax + u32 max_cntr_leaf : 32; // Maximum Centaur/Zhaoxin leaf + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 : 32; // Reserved +}; + +/* + * Leaf 0xc0000001 + * Centaur/Zhaoxin extended CPU features + */ + +struct leaf_0xc0000001_0 { + // eax + u32 : 32; // Reserved + // ebx + u32 : 32; // Reserved + // ecx + u32 : 32; // Reserved + // edx + u32 ccs_sm2 : 1, // CCS SM2 instructions + ccs_sm2_en : 1, // CCS SM2 enabled + rng : 1, // Random Number Generator + rng_en : 1, // RNG enabled + ccs_sm3_sm4 : 1, // CCS SM3 and SM4 instructions + ccs_sm3_sm4_en : 1, // CCS SM3/SM4 enabled + ace : 1, // Advanced Cryptography Engine + ace_en : 1, // ACE enabled + ace2 : 1, // Advanced Cryptography Engine v2 + ace2_en : 1, // ACE v2 enabled + phe : 1, // PadLock Hash Engine + phe_en : 1, // PHE enabled + pmm : 1, // PadLock Montgomery Multiplier + pmm_en : 1, // PMM enabled + : 2, // Reserved + parallax : 1, // Parallax auto adjust processor voltage + parallax_en : 1, // Parallax enabled + : 2, // Reserved + tm3 : 1, // Thermal Monitor v3 + tm3_en : 1, // TM v3 enabled + : 3, // Reserved + phe2 : 1, // PadLock Hash Engine v2 (SHA384/SHA512) + phe2_en : 1, // PHE v2 enabled + rsa : 1, // RSA instructions (XMODEXP/MONTMUL2) + rsa_en : 1, // RSA instructions enabled + : 3; // Reserved +}; + +#endif /* _ASM_X86_CPUID_LEAF_TYPES */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 51BC73F23B1 for ; Thu, 28 May 2026 15:39:58 +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=1779982798; cv=none; b=Aatqp3g19U0/KMWIFj4NdV7nCs/P0Tfg/udjtR1NVFGZdyknHM2Go3eyImjZURpRKZ0/X62JIv0TcSSMQy5e2dusvah3ol8ryP/NpMksgLgk31ofFxPW1cIuaCKOCaDXLf8Ve8/Ri7ZdbFhI5O2XINQoV1pn1AeVACpbPLhdXZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982798; c=relaxed/simple; bh=RGZf6sOCjuKGvICAPpiTH0M+nTFVIHiXASQKSFHm1tA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nY1KtfVWnZHbVXfDFDQW8hAoRVpfaY92gts+Q2rmfCommjUo2IF+g9pUl94DbQooUaWVACHASwVIHO8zWqeAD30AGjsuL1Br+o4w0BMoWOKhsqm3suyqBEu1LGVGtLk3mMm8lBlAIzErAcdSUCwys7xM06PAfHMeouSIHJjyJcg= 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=EyIst51b; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1ruUAOyh; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EyIst51b"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1ruUAOyh" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982796; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Mfx8JrK8BMzU6wUGUEjBH2smqOkRrDzeLGmr2axVaw=; b=EyIst51b8fyEsLHandR3orAqZZn2MNGYvueLQWnkjwt3hFxm3LcCRAKEVQQYnNj6Rx7gnn UEtULbeL3y7vaBg7B9Kkxu0r4PPaBeBm7pw0q3wbc9Jdd5iZ/4dwF3V9HbC3zinPyRpUeu b5t49kwNe5oboPXI+IDgSeje2Ez/ovfjM/NW1muzcBUn6XWEheAHWveAk3Xv1a5jjs6SdY r1phO1STW25Vcxq9hmXCdqtvCdRi8dFtzF0dJSNwYT9In9e5H2NMqzVNZ6VU/DkXOs52Vx JmQDzFs7NA2Civ8i7dOfd82b2h0+AXG4CoDVdn7YTLTAlsKbmXU8heSWyqZE9w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982796; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Mfx8JrK8BMzU6wUGUEjBH2smqOkRrDzeLGmr2axVaw=; b=1ruUAOyhMc4iz+FnNUa/sF/C08qrsSsgxv8T2DSLmhmh6PeQ68xukpk3Y3BB+ql9719pKu DZtfcudbeWWEUQBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 005/120] x86/cpu: Introduce a centralized CPUID data model Date: Thu, 28 May 2026 17:37:27 +0200 Message-ID: <20260528153923.403473-6-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable ** Context The x86-cpuid-db project generates a C header file with full C99 bitfield listings for all known CPUID leaf/subleaf query outputs. That header is now merged by parent commits at , and is of the form: struct leaf_0x0_0 { /* CPUID(0x0).0 C99 bitfields */ }; ... struct leaf_0x4_n { /* CPUID(0x4).n C99 bitfields */ }; ... struct leaf_0xd_0 { /* CPUID(0xd).0 C99 bitfields */ }; struct leaf_0xd_1 { /* CPUID(0xd).1 C99 bitfields */ }; struct leaf_0xd_n { /* CPUID(0xd).n C99 bitfields */ }; ... ** Goal Introduce a structured, size-efficient, per-CPU, CPUID data repository. Use the x86-cpuid-db auto-generated data types, and custom CPUID leaf parsers, to build that repository. Given a leaf, subleaf, and index, provide direct memory access to the parsed and cached per-CPU CPUID output. ** Long-term goal Remove the need for drivers and other areas in the kernel to invoke direct CPUID queries. Only one place in the kernel should be allowed to use the CPUID instruction: the CPUID parser code. ** Implementation Introduce CPUID_LEAF()/CPUID_LEAF_N() to build a compact CPUID storage layout in the form: struct leaf_0x0_0 leaf_0x0_0[1]; struct leaf_parse_info leaf_0x0_0_info; struct leaf_0x1_0 leaf_0x1_0[1]; struct leaf_parse_info leaf_0x0_0_info; struct leaf_0x4_n leaf_0x4_n[8]; struct leaf_parse_info leaf_0x4_n_info; ... where each CPUID query stores its output at the designated leaf/subleaf array and has an associated "CPUID query info" structure. Embed the CPUID tables inside "struct cpuinfo_x86" to ensure early-boot and per-CPU access through the CPUs capability structures. Use an array of CPUID output storage entries for each leaf/subleaf combination to accommodate leaves which produce the same output format for a large subleaf range. This is typical for CPUID leaves enumerating hierarchical objects; e.g. CPUID(0x4) cache topology enumeration, CPUID(0xd) XSAVE enumeration, and CPUID(0x12) SGX Enclave Page Cache enumeration. ** New CPUID APIs Assuming a CPU capability structure 'c', provide macros to access the parsed and cached CPUID leaf/subleaf output. These macros resolve to a compile-time tokenization that ensures type-safety: const struct leaf_0x7_0 *l7_0; l7_0 =3D cpuid_subleaf(c, 0x7, 0); | | =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 | =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 | * * * &c.cpuid.leaf_0x7_0[0] For CPUID leaves with multiple subleaves having the same output format, provide the APIs: const struct leaf_0x4_n *l4_0, *l4_1; l4_0 =3D cpuid_subleaf_n(c, 0x4, 0); | | =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 | =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 | * * v &c.cpuid.leaf_0x4_n[0] l4_1 =3D cpuid_subleaf_n(c, 0x4, 1); | | =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 | =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=90 | * * v &c.cpuid.leaf_0x4_n[1] where the indices 0, 1, n above can be passed dynamically; e.g., in an enumeration for loop. Add a clear rationale on why call sites should use the these new APIs instead of directly invoking CPUID. ** Next steps For now, define cached parse entries for CPUID(0x0) and CPUID(0x1). Generic parser logic to fill the CPUID tables, along with more CPUID leaves support, will be added next. Suggested-by: Thomas Gleixner # CPUID data model Suggested-by: Andrew Cooper # x86-cpuid-db sche= ma Suggested-by: Borislav Petkov # Early CPUID centralization = drafts Suggested-by: Ingo Molnar # CPUID headers restructuring Suggested-by: Sean Christopherson # cpuid_subleaf_n() A= PIs Signed-off-by: Ahmed S. Darwish Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/all/20260327021645.555257-1-darwi@linutronix.= de Link: https://lore.kernel.org/all/874ixernra.ffs@tglx Link: https://gitlab.com/x86-cpuid.org/x86-cpuid-db Link: https://lore.kernel.org/all/aBnSgu_JyEi8fvog@gmail.com Link: https://lore.kernel.org/all/aJ9TbaNMgaplKSbH@google.com --- arch/x86/include/asm/cpuid/api.h | 238 +++++++++++++++++++++++++++++ arch/x86/include/asm/cpuid/types.h | 98 ++++++++++++ arch/x86/include/asm/processor.h | 2 + 3 files changed, 338 insertions(+) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 2b9750cc8a75..b868902dbf5f 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -289,4 +289,242 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) return cpuid_edx(0x80000006); } =20 +/* + * 'struct cpuid_leaves' accessors (without sanity checks): + * + * For internal use by the CPUID parser. + */ + +/* Return constified pointers for all call-site APIs */ +#define __const_ptr(_ptr) \ + ((const __typeof__(*(_ptr)) *)(_ptr)) + +#define __cpuid_leaves_subleaf(_leaves, _leaf, _subleaf) \ + __const_ptr(&((_leaves)->leaf_ ## _leaf ## _ ## _subleaf)[0]) + +#define __cpuid_leaves_subleaf_n(_leaves, _leaf, _index) \ + __const_ptr(&((_leaves)->leaf_ ## _leaf ## _ ## n)[_index]) + +#define __cpuid_leaves_subleaf_info(_leaves, _leaf, _subleaf) \ + __const_ptr(&((_leaves)->leaf_ ## _leaf ## _ ## _subleaf ## _ ## info)) + +/* + * 'struct cpuid_table' accessors (with sanity checks): + * + * For internal use by the CPUID parser. + */ + +#define __cpuid_table_nr_filled_subleaves(_table, _leaf, _subleaf) \ + __cpuid_leaves_subleaf_info(&((_table)->leaves), _leaf, _subleaf)->nr_ent= ries + +#define __cpuid_table_subleaf_range_size(_table, _leaf) \ + ARRAY_SIZE((_table)->leaves.leaf_ ## _leaf ## _n) + +#define __cpuid_table_invalid_subleaf(_table, _leaf, _subleaf) \ + (((_subleaf) < (__cpuid_leaf_first_subleaf(_leaf))) || \ + ((_subleaf) > (__cpuid_leaf_first_subleaf(_leaf) + \ + __cpuid_table_subleaf_range_size(_table, _leaf) - 1))) + +/* Return NULL if the parser did not fill that leaf. Check cpuid_subleaf(= ). */ +#define __cpuid_table_subleaf(_table, _leaf, _subleaf) \ +({ \ + unsigned int ____f =3D __cpuid_table_nr_filled_subleaves(_table, _leaf, _= subleaf); \ + \ + (____f !=3D 1) ? NULL : __cpuid_leaves_subleaf(&((_table)->leaves), _leaf= , _subleaf); \ +}) + +/* + * Return NULL if the CPUID parser did not fill this leaf, or if the given + * dynamic subleaf value is out of range. Check cpuid_subleaf_n(). + */ +#define __cpuid_table_subleaf_n(_table, _leaf, _subleaf) \ +({ \ + unsigned int ____i =3D (_subleaf) - __cpuid_leaf_first_subleaf(_leaf); \ + unsigned int ____f =3D __cpuid_table_nr_filled_subleaves(_table, _leaf, n= ); \ + \ + /* CPUID parser might not have filled the entire subleaf range */ \ + ((____i >=3D ____f) || __cpuid_table_invalid_subleaf(_table, _leaf, _subl= eaf)) ? \ + NULL : __cpuid_leaves_subleaf_n(&((_table)->leaves), _leaf, ____i); \ +}) + +/* + * Compile-time checks for leaves with a subleaf range: + */ + +#define __cpuid_assert_subleaf_range(_cpuinfo, _leaf) \ + static_assert(__cpuid_table_subleaf_range_size(&(_cpuinfo)->cpuid, _leaf)= > 1) + +#define __cpuid_assert_subleaf_within_range(_cpuinfo, _leaf, _subleaf) \ + BUILD_BUG_ON(__builtin_constant_p(_subleaf) && \ + __cpuid_table_invalid_subleaf(&(_cpuinfo)->cpuid, _leaf, _subleaf)) + +/* + * CPUID Parser Call-site APIs + * + * Call sites should use below APIs instead of invoking direct CPUID queri= es. + * + * Benefits include: + * + * - Return CPUID output as typed C structures that are auto-generated fro= m a + * centralized database (see data type: 'struct leaf_0xM_N', wh= ere + * 0xM is the token provided at @_leaf, and N is the token provided at + * @_subleaf; e.g. struct leaf_0x7_0. + * + * Returns NULL if the requested CPUID @_leaf/@_subleaf query output is not + * present at the parsed CPUID table inside @_cpuinfo. This can happen if: + * + * - The CPUID table inside @_cpuinfo has not yet been populated. + * - The CPUID table inside @_cpuinfo was populated, but the CPU does not + * implement the requested CPUID @_leaf/@_subleaf combination. + * - The CPUID table inside @_cpuinfo was populated, but the kernel's CPUID + * parser has predetermined that the requested CPUID @_leaf/@_subleaf + * hardware output is invalid or unsupported. + * + * Example usage:: + * + * const struct leaf_0x7_0 *l7_0 =3D cpuid_subleaf(c, 0x7, 0); + * if (!l7_0) { + * // Handle error + * } + * + * const struct leaf_0x7_1 *l7_1 =3D cpuid_subleaf(c, 0x7, 1); + * if (!l7_1) { + * // Handle error + * } + */ +#define cpuid_subleaf(_cpuinfo, _leaf, _subleaf) \ + __cpuid_table_subleaf(&(_cpuinfo)->cpuid, _leaf, _subleaf) \ + +/** + * cpuid_leaf() - Access parsed CPUID data + * @_cpuinfo: CPU capability structure reference ('struct cpuinfo_x86') + * @_leaf: CPUID leaf, in compile-time 0xN format; e.g. 0x0, 0x2, 0x800000= 00 + * + * Similar to cpuid_subleaf(), but with a CPUID subleaf =3D 0. + * + * Example usage:: + * + * const struct leaf_0x0_0 *l0 =3D cpuid_leaf(c, 0x0); + * if (!l0) { + * // Handle error + * } + * + * const struct leaf_0x80000000_0 *el0 =3D cpuid_leaf(c, 0x80000000); + * if (!el0) { + * // Handle error + * } + */ +#define cpuid_leaf(_cpuinfo, _leaf) \ + cpuid_subleaf(_cpuinfo, _leaf, 0) + +/** + * cpuid_leaf_raw() - Access parsed CPUID data in raw format + * @_cpuinfo: CPU capability structure reference ('struct cpuinfo_x86') + * @_leaf: CPUID leaf, in compile-time 0xN format + * + * Similar to cpuid_leaf(), but returns a raw 'struct cpuid_regs' pointer = to + * the parsed CPUID data instead of a "typed" poi= nter. + */ +#define cpuid_leaf_raw(_cpuinfo, _leaf) \ + ((const struct cpuid_regs *)(cpuid_leaf(_cpuinfo, _leaf))) + +/* + * Call-site APIs for CPUID leaves with a subleaf range: + */ + +/** + * cpuid_subleaf_n() - Access parsed CPUID data for leaf with a subleaf ra= nge + * @_cpuinfo: CPU capability structure reference ('struct cpuinfo_x86') + * @_leaf: CPUID leaf, in compile-time 0xN format; e.g. 0x4, 0x8000001d + * @_subleaf: Subleaf number, which can be passed dynamically. It must be= smaller + * than cpuid_subleaf_count(@_cpuinfo, @_leaf). + * + * Build-time errors will be emitted in the following cases: + * + * - @_leaf has no subleaf range. Leaves with a subleaf range have an '_n= ' type + * suffix and are listed at using the CPUID_LEAF_N()= macro. + * + * - @_subleaf is known at compile-time but is out of range. + * + * Example usage:: + * + * const struct leaf_0x4_n *l4; + * + * for (int i =3D 0; i < cpuid_subleaf_count(c, 0x4); i++) { + * l4 =3D cpuid_subleaf_n(c, 0x4, i); + * if (!l4) { + * // Handle error + * } + * ... + * } + * + * Beside the standard error situations detailed at cpuid_subleaf(), this + * macro will also return NULL if @_subleaf is out of the leaf's subleaf r= ange. + */ +#define cpuid_subleaf_n(_cpuinfo, _leaf, _subleaf) \ +({ \ + __cpuid_assert_subleaf_range(_cpuinfo, _leaf); \ + __cpuid_assert_subleaf_within_range(_cpuinfo, _leaf, _subleaf); \ + __cpuid_table_subleaf_n(&(_cpuinfo)->cpuid, _leaf, _subleaf); \ +}) + +/** + * cpuid_subleaf_n_raw() - Access parsed CPUID data for leaf with subleaf = range + * @_cpuinfo: CPU capability structure reference ('struct cpuinfo_x86') + * @_leaf: CPUID leaf, in compile-time 0xN format; e.g. 0x4, 0x8000001d + * @_subleaf: Subleaf number, which can be passed dynamically. It must be= smaller + * than cpuid_subleaf_count(@_cpuinfo, @_leaf). + * + * Similar to cpuid_subleaf_n(), but returns a raw 'struct cpuid_regs' poi= nter to + * the parsed CPUID data instead of a "typed" poi= nter. + */ +#define cpuid_subleaf_n_raw(_cpuinfo, _leaf, _subleaf) \ + ((const struct cpuid_regs *)cpuid_subleaf_n(_cpuinfo, _leaf, _subleaf)) + +/** + * cpuid_subleaf_count() - Number of filled subleaves for @_leaf + * @_cpuinfo: CPU capability structure reference ('struct cpuinfo_x86') + * @_leaf: CPUID leaf, in compile-time 0xN format; e.g. 0x4, 0x8000001d + * + * Return the number of subleaves filled by the CPUID parser for @_leaf. + * + * @_leaf must have subleaf range. Leaves with a subleaf range have an '_= n' type + * suffix and are listed at using the CPUID_LEAF_N() m= acro. + */ +#define cpuid_subleaf_count(_cpuinfo, _leaf) \ +({ \ + __cpuid_assert_subleaf_range(_cpuinfo, _leaf); \ + __cpuid_table_nr_filled_subleaves(&(_cpuinfo)->cpuid, _leaf, n); \ +}) + #endif /* _ASM_X86_CPUID_API_H */ diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 8a00364b79de..3d0e611c97ba 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -5,6 +5,8 @@ #include #include =20 +#include + /* * Types for raw CPUID access: */ @@ -30,6 +32,12 @@ enum cpuid_regs_idx { #define CPUID_LEAF_FREQ 0x16 #define CPUID_LEAF_TILE 0x1d =20 +#define CPUID_RANGE(idx) ((idx) & 0xffff0000) +#define CPUID_RANGE_MAX(idx) (CPUID_RANGE(idx) + 0xffff) + +#define CPUID_BASE_START 0x00000000 +#define CPUID_BASE_END CPUID_RANGE_MAX(CPUID_BASE_START) + /* * Types for CPUID(0x2) parsing: */ @@ -124,4 +132,94 @@ extern const struct leaf_0x2_table cpuid_0x2_table[256= ]; */ #define TLB_0x63_2M_4M_ENTRIES 32 =20 +/* + * Types for centralized CPUID tables: + * + * For internal use by the CPUID parser. + */ + +/** + * struct leaf_parse_info - CPUID query parse info + * @nr_entries: Number of valid entries filled by the CPUID parser + */ +struct leaf_parse_info { + unsigned int nr_entries; +}; + +/** + * __CPUID_LEAF() - Define a CPUID output and parse info entry + * @_name: Struct type name of the CPUID leaf/subleaf (e.g. 'leaf_0x7_0').= Such + * types are defined at and follow the leaf_0xM_N + * format, where 0xM is the leaf and N is the subleaf. + * @_count: Number of storage entries to allocate for this leaf/subleaf. + * + * For a given leaf/subleaf, define an array of CPUID storage entries and = an associated + * query info structure. + * + * Use an array of storage entries to accommodate CPUID leaves with multip= le subleaves + * having the same output format. This is common for hierarchical enumera= tion; e.g., + * CPUID(0x4), CPUID(0x12), and CPUID(0x8000001d). + */ +#define __CPUID_LEAF(_name, _count) \ + struct _name _name[_count]; \ + struct leaf_parse_info _name##_info + +/** + * CPUID_LEAF() - Define a 'struct cpuid_leaves' storage entry + * @_leaf: Leaf number, in compile-time 0xN format + * @_subleaf: Subleaf number, in compile-time decimal format + * + * Convenience wrapper around __CPUID_LEAF(). + */ +#define CPUID_LEAF(_leaf, _subleaf) \ + __CPUID_LEAF(leaf_ ## _leaf ## _ ## _subleaf, 1) + +#define __cpuid_leaf_first_subleaf(_l) \ + LEAF_ ## _l ## _ ## SUBLEAF_N_FIRST +#define __cpuid_leaf_last_subleaf(_l) \ + LEAF_ ## _l ## _ ## SUBLEAF_N_LAST + +#define __cpuid_leaf_subleaf_count_min(_l) 2 +#define __cpuid_leaf_subleaf_count_max(_l) \ + (__cpuid_leaf_last_subleaf(_l) - __cpuid_leaf_first_subleaf(_l) + 1) + +/** + * CPUID_LEAF_N() - Define a 'struct cpuid_leaves' storage entry + * @_leaf: Leaf number, in compile-time 0xN format + * @_count: Number of storage entries to allocate for that leaf. It must n= ot exceed + * the limits defined at . + * + * Convenience wrapper around __CPUID_LEAF(). + */ +#define CPUID_LEAF_N(_leaf, _count) \ + static_assert(_count >=3D __cpuid_leaf_subleaf_count_min(_leaf)); \ + static_assert(_count <=3D __cpuid_leaf_subleaf_count_max(_leaf)); \ + __CPUID_LEAF(leaf_ ## _leaf ## _ ## n, _count) + +/* + * struct cpuid_leaves - Parsed CPUID data + */ +struct cpuid_leaves { + /* Leaf Subleaf number (or max number of subleaves) */ + CPUID_LEAF ( 0x0, 0 ); + CPUID_LEAF ( 0x1, 0 ); +}; + +/* + * Types for centralized CPUID tables: + * + * For external use. + */ + +/** + * struct cpuid_table - Per-CPU CPUID data repository + * @leaves: Parsed CPUID queries output and their metadata + * + * This is to be embedded inside 'struct cpuinfo_x86' to provide parsed and + * sanitized CPUID data per CPU. + */ +struct cpuid_table { + struct cpuid_leaves leaves; +}; + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index 4f4356b13158..70c414eab154 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -16,6 +16,7 @@ struct vm86; #include #include #include +#include #include #include #include @@ -169,6 +170,7 @@ struct cpuinfo_x86 { char x86_vendor_id[16]; char x86_model_id[64]; struct cpuinfo_topology topo; + struct cpuid_table cpuid; /* in KB - valid for CPUS which support this call: */ unsigned int x86_cache_size; int x86_cache_alignment; /* In bytes */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A79E53F44EC for ; Thu, 28 May 2026 15:40:01 +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=1779982802; cv=none; b=FCU4kJS8V2yFkJLzK58YmB6bYr6qVWQIrO+iDkA7r40VxNJCHjSfIm0O+XgMdutG2TjDkpgakOfkT5aGr1iTbMDm+72i+GpkIxzd+woehubiLKVJCeAmNByT9Dq1+bazQ9VFqjAxy7CI1YyepfyY7dGK6055lyBZIiydKeOBdrU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982802; c=relaxed/simple; bh=LZFQa4r7dQwW0D63y9o+FzskqM6W+2NhNRWbJ5zhsVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HAwwWhU34ke65pQHyYdNL31MGoytFwrWf2GlNSLfRS1n5KXWEbsGsNIv7VHrnxMI6Q6X9nJ9J24THqxs+mK7Idd+5klObrKkfmRaW/6wujARjAvnyjYcEdNUj+qOOOVpC8dADNPBOXPuZmZYLsER/1xEO7qdehUZCtO0iw43g14= 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=QotZvUNj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LcPWsfwU; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QotZvUNj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LcPWsfwU" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OH1/2uFrWR4JrgFZTbNNA2v5e+Hn8BpDrCW4qRW/2vw=; b=QotZvUNjpO6X94n2lUge/lHqkfCZtpfoTzVAryCTIbskswxdkHrjwRyVrbQR2beUBG4IP0 a9pP++GFOLmFORI47n2HW6x3VWpEDtuqdNT3l7kuTEnZbUThqvAHIv7OU0hL8pKOVz7hmj bsfmvGyZL65n/cM68WfSOv/R/LD763UKcH8t0t15UdN3CJjD5mdnyGTVg1JSpDLZGItBwp 5W5l1arJhgZrD4viT4dBzL+epa8lEnzw5Udph/m8Q27RBbavwolTUwVNOPVCIGj7rXCnf1 uZNbn/FScdVz/gPStug7bpPoT/XhOzqmnSpUB6z25aHyWS6i9g9HIs50UAO49A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OH1/2uFrWR4JrgFZTbNNA2v5e+Hn8BpDrCW4qRW/2vw=; b=LcPWsfwUbj5jLgEkG1XX9hooLJqR6Ei/7DkolWJiPD8hLNczUiZ+yhAsCDelDl3uLcs8IA CjxF5fOB7I1Rz5AQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 006/120] x86/cpuid: Introduce a centralized CPUID parser Date: Thu, 28 May 2026 17:37:28 +0200 Message-ID: <20260528153923.403473-7-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a CPUID parser for populating the system's CPUID tables. Since accessing a leaf within the CPUID table requires compile time tokenization, split the parser into two stages: (a) Compile-time macros for tokenizing the leaf/subleaf offsets within the CPUID table. (b) Generic runtime code to fill the CPUID data, using a parsing table which collects these compile-time offsets. For actual CPUID output parsing, support both generic and leaf-specific read functions. To ensure CPUID data early availability, invoke the parser during early boot, early Xen boot, and at early secondary CPUs bring up. Provide call site APIs to refresh a single leaf, or a leaf range, within the CPUID tables. This is for sites issuing MSR writes that partially change the CPU's CPUID layout. Doing full CPUID table rescans in such cases will be destructive since the CPUID tables will host all of the kernel's X86_FEATURE flags at a later stage. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/all/20260327021645.555257-1-darwi@linutronix.= de --- arch/x86/include/asm/cpuid/api.h | 9 ++ arch/x86/kernel/cpu/Makefile | 1 + arch/x86/kernel/cpu/common.c | 5 +- arch/x86/kernel/cpu/cpuid_parser.c | 182 +++++++++++++++++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 120 +++++++++++++++++++ arch/x86/xen/enlighten.c | 3 +- arch/x86/xen/enlighten_pv.c | 1 + 7 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 arch/x86/kernel/cpu/cpuid_parser.c create mode 100644 arch/x86/kernel/cpu/cpuid_parser.h diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index b868902dbf5f..82eddfa2347b 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -7,6 +7,7 @@ #include #include =20 +#include #include =20 /* @@ -527,4 +528,12 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) __cpuid_table_nr_filled_subleaves(&(_cpuinfo)->cpuid, _leaf, n); \ }) =20 +/* + * CPUID parser exported APIs: + */ + +void cpuid_scan_cpu(struct cpuinfo_x86 *c); +void cpuid_refresh_leaf(struct cpuinfo_x86 *c, u32 leaf); +void cpuid_refresh_range(struct cpuinfo_x86 *c, u32 start, u32 end); + #endif /* _ASM_X86_CPUID_API_H */ diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 2f8a58ef690e..d2e8a849f180 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -19,6 +19,7 @@ KCSAN_SANITIZE_common.o :=3D n =20 obj-y :=3D cacheinfo.o scattered.o obj-y +=3D topology_common.o topology_ext.o topology_amd.o +obj-y +=3D cpuid_parser.o obj-y +=3D common.o obj-y +=3D rdrand.o obj-y +=3D match.o diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index a4268c47f2bc..5cae6c48dd25 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1791,6 +1791,7 @@ static void __init cpu_parse_early_param(void) static void __init early_identify_cpu(struct cpuinfo_x86 *c) { memset(&c->x86_capability, 0, sizeof(c->x86_capability)); + memset(&c->cpuid, 0, sizeof(c->cpuid)); c->extended_cpuid_level =3D 0; =20 if (!cpuid_feature()) @@ -1798,6 +1799,7 @@ static void __init early_identify_cpu(struct cpuinfo_= x86 *c) =20 /* cyrix could have cpuid enabled via c_identify()*/ if (cpuid_feature()) { + cpuid_scan_cpu(c); cpu_detect(c); get_cpu_vendor(c); intel_unlock_cpuid_leafs(c); @@ -1970,8 +1972,8 @@ static void generic_identify(struct cpuinfo_x86 *c) if (!cpuid_feature()) return; =20 + cpuid_scan_cpu(c); cpu_detect(c); - get_cpu_vendor(c); intel_unlock_cpuid_leafs(c); get_cpu_cap(c); @@ -2023,6 +2025,7 @@ static void identify_cpu(struct cpuinfo_x86 *c) #endif c->x86_cache_alignment =3D c->x86_clflush_size; memset(&c->x86_capability, 0, sizeof(c->x86_capability)); + memset(&c->cpuid, 0, sizeof(c->cpuid)); #ifdef CONFIG_X86_VMX_FEATURE_NAMES memset(&c->vmx_capability, 0, sizeof(c->vmx_capability)); #endif diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c new file mode 100644 index 000000000000..898b0c441431 --- /dev/null +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * CPUID parser; for populating the system's CPUID tables. + */ + +#include + +#include +#include + +#include "cpuid_parser.h" + +/* Clear a single CPUID table entry */ +static void cpuid_clear(const struct cpuid_parse_entry *e, const struct cp= uid_read_output *output) +{ + struct cpuid_regs *regs =3D output->regs; + + for (int i =3D 0; i < e->maxcnt; i++, regs++) + memset(regs, 0, sizeof(*regs)); + + memset(output->info, 0, sizeof(*output->info)); +} + +/* + * Leaf read functions: + */ + +/* + * Default CPUID read function + * Satisfies the requirements stated at 'struct cpuid_parse_entry'->read(). + */ +static void +cpuid_read_generic(const struct cpuid_parse_entry *e, const struct cpuid_r= ead_output *output) +{ + struct cpuid_regs *regs =3D output->regs; + + for (int i =3D 0; i < e->maxcnt; i++, regs++, output->info->nr_entries++) + cpuid_read_subleaf(e->leaf, e->subleaf + i, regs); +} + +/* + * CPUID parser table: + */ + +static const struct cpuid_parse_entry cpuid_parse_entries[] =3D { + CPUID_PARSE_ENTRIES +}; + +/* + * Leaf-independent parser code: + */ + +static unsigned int cpuid_range_max_leaf(const struct cpuid_table *t, unsi= gned int range) +{ + const struct leaf_0x0_0 *l0 =3D __cpuid_table_subleaf(t, 0x0, 0); + + switch (range) { + case CPUID_BASE_START: return l0 ? l0->max_std_leaf : 0; + default: return 0; + } +} + +static void +__cpuid_reset_table(struct cpuid_table *t, const struct cpuid_parse_entry = entries[], + unsigned int nr_entries, unsigned int start, unsigned int end, bool = fill) +{ + const struct cpuid_parse_entry *entry =3D entries; + unsigned int range =3D CPUID_RANGE(start); + + for (unsigned int i =3D 0; i < nr_entries; i++, entry++) { + struct cpuid_read_output output =3D { + .regs =3D cpuid_table_regs_p(t, entry->regs_offs), + .info =3D cpuid_table_info_p(t, entry->info_offs), + }; + + if (entry->leaf < start || entry->leaf > end) + continue; + + cpuid_clear(entry, &output); + + /* + * Read the range's anchor leaf unconditionally so that the cached + * maximum valid leaf value is available for the remaining entries. + */ + if (fill && (entry->leaf =3D=3D range || entry->leaf <=3D cpuid_range_ma= x_leaf(t, range))) + entry->read(entry, &output); + } +} + +/* + * Zero all cached CPUID entries within [@start-@end] range. This is need= ed when + * certain operations like MSR writes induce changes to the CPU's CPUID la= yout. + */ +static void +__cpuid_zero_table(struct cpuid_table *t, const struct cpuid_parse_entry e= ntries[], + unsigned int nr_entries, unsigned int start, unsigned int end) +{ + __cpuid_reset_table(t, entries, nr_entries, start, end, false); +} + +static void +__cpuid_fill_table(struct cpuid_table *t, const struct cpuid_parse_entry e= ntries[], + unsigned int nr_entries, unsigned int start, unsigned int end) +{ + __cpuid_reset_table(t, entries, nr_entries, start, end, true); +} + +static void +cpuid_fill_table(struct cpuid_table *t, const struct cpuid_parse_entry ent= ries[], unsigned int nr_entries) +{ + static const struct { + unsigned int start; + unsigned int end; + } ranges[] =3D { + { CPUID_BASE_START, CPUID_BASE_END }, + }; + + for (unsigned int i =3D 0; i < ARRAY_SIZE(ranges); i++) + __cpuid_fill_table(t, entries, nr_entries, ranges[i].start, ranges[i].en= d); +} + +static void __cpuid_scan_cpu_full(struct cpuinfo_x86 *c) +{ + unsigned int nr_entries =3D ARRAY_SIZE(cpuid_parse_entries); + struct cpuid_table *table =3D &c->cpuid; + + cpuid_fill_table(table, cpuid_parse_entries, nr_entries); +} + +static void +__cpuid_scan_cpu_partial(struct cpuinfo_x86 *c, unsigned int start_leaf, u= nsigned int end_leaf) +{ + unsigned int nr_entries =3D ARRAY_SIZE(cpuid_parse_entries); + struct cpuid_table *table =3D &c->cpuid; + + __cpuid_zero_table(table, cpuid_parse_entries, nr_entries, start_leaf, en= d_leaf); + __cpuid_fill_table(table, cpuid_parse_entries, nr_entries, start_leaf, en= d_leaf); +} + +/* + * Call-site APIs: + */ + +/** + * cpuid_scan_cpu() - Populate current CPU's CPUID table + * @c: CPU capability structure associated with the current CPU + * + * Populate the CPUID table embedded within @c with parsed CPUID data. Al= l CPUID + * instructions are invoked locally, so this must be called on the CPU ass= ociated + * with @c. + */ +void cpuid_scan_cpu(struct cpuinfo_x86 *c) +{ + __cpuid_scan_cpu_full(c); +} + +/** + * cpuid_refresh_range() - Rescan a CPUID table's leaf range + * @c: CPU capability structure associated with the current CPU + * @start: Start of leaf range to be re-scanned + * @end: End of leaf range + */ +void cpuid_refresh_range(struct cpuinfo_x86 *c, u32 start, u32 end) +{ + if (WARN_ON_ONCE(start > end)) + return; + + if (WARN_ON_ONCE(CPUID_RANGE(start) !=3D CPUID_RANGE(end))) + return; + + __cpuid_scan_cpu_partial(c, start, end); +} + +/** + * cpuid_refresh_leaf() - Rescan a CPUID table's leaf + * @c: CPU capability structure associated with the current CPU + * @leaf: Leaf to be re-scanned + */ +void cpuid_refresh_leaf(struct cpuinfo_x86 *c, u32 leaf) +{ + cpuid_refresh_range(c, leaf, leaf); +} diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h new file mode 100644 index 000000000000..df627306cc8c --- /dev/null +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ARCH_X86_CPUID_PARSER_H +#define _ARCH_X86_CPUID_PARSER_H + +#include + +/* + * Since accessing the CPUID leaves at 'struct cpuid_leaves' require compi= le time + * tokenization, split the CPUID parser into two stages: compile time macr= os for + * tokenizing the leaf/subleaf output offsets within the table, and generi= c runtime + * code to write to the relevant CPUID leaves using such offsets. + * + * The output of the compile time macros is cached by a compile time "pars= e entry" + * table (see 'struct cpuid_parse_entry'). The runtime parser code will u= tilize + * such offsets by passing them to the cpuid_table_*_p() functions. + */ + +/* + * Compile time CPUID table offset calculations: + * + * @_leaf: CPUID leaf, in 0xN format + * @_subleaf: CPUID subleaf, in decimal format + */ + +#define __cpuid_leaves_regs_offset(_leaf, _subleaf) \ + offsetof(struct cpuid_leaves, leaf_ ## _leaf ## _ ## _subleaf) + +#define __cpuid_leaves_info_offset(_leaf, _subleaf) \ + offsetof(struct cpuid_leaves, leaf_ ## _leaf ## _ ## _subleaf ## _ ## inf= o) + +#define __cpuid_leaves_regs_maxcnt(_leaf, _subleaf) \ + ARRAY_SIZE(((struct cpuid_leaves *)NULL)->leaf_ ## _leaf ## _ ## _subleaf) + +/* + * Translation of compile time offsets to generic runtime pointers: + */ + +static inline struct cpuid_regs * +cpuid_table_regs_p(const struct cpuid_table *t, unsigned long regs_offset) +{ + return (struct cpuid_regs *)((unsigned long)(&t->leaves) + regs_offset); +} + +static inline struct leaf_parse_info * +cpuid_table_info_p(const struct cpuid_table *t, unsigned long info_offset) +{ + return (struct leaf_parse_info *)((unsigned long)(&t->leaves) + info_offs= et); +} + +/** + * struct cpuid_read_output - Output of a CPUID read operation + * @regs: Pointer to an array of CPUID outputs, where each array element c= overs the + * full EAX->EDX output range. + * @info: Pointer to query info; for saving the number of filled elements = at @regs. + * + * A CPUID parser read function like cpuid_read_generic() or cpuid_read_0x= N() uses this + * structure to save the CPUID query outputs. Actual storage for @regs an= d @info is + * provided by the read function caller, and is typically within the CPU's= CPUID table. + * + * See struct cpuid_parse_entry.read(). + */ +struct cpuid_read_output { + struct cpuid_regs *regs; + struct leaf_parse_info *info; +}; + +/** + * struct cpuid_parse_entry - CPUID parse table entry + * @leaf: Leaf number to be parsed + * @subleaf: Subleaf number to be parsed + * @regs_offs: Offset within 'struct cpuid_leaves' for saving the CPUID qu= ery output; to be + * passed to cpuid_table_regs_p(). + * @info_offs: Offset within 'struct cpuid_leaves' for saving the CPUID qu= ery parse info; to be + * passed to cpuid_table_info_p(). + * @maxcnt: Maximum number of output storage entries available for the CPU= ID query. + * @read: Read function for this entry. It must save the parsed CPUID out= put to the passed + * 'struct cpuid_read_output'->regs array of size >=3D @maxcnt. It must = set + * 'struct cpuid_read_output'->info.nr_entries to the number of CPUID out= put entries + * parsed and filled. A generic implementation is provided at cpuid_read= _generic(). + */ +struct cpuid_parse_entry { + unsigned int leaf; + unsigned int subleaf; + unsigned int regs_offs; + unsigned int info_offs; + unsigned int maxcnt; + void (*read)(const struct cpuid_parse_entry *e, const struct cpuid_read_= output *o); +}; + +#define __CPUID_PARSE_ENTRY(_leaf, _subleaf, _suffix, _reader_fn) \ + { \ + .leaf =3D _leaf, \ + .subleaf =3D _subleaf, \ + .regs_offs =3D __cpuid_leaves_regs_offset(_leaf, _suffix), \ + .info_offs =3D __cpuid_leaves_info_offset(_leaf, _suffix), \ + .maxcnt =3D __cpuid_leaves_regs_maxcnt(_leaf, _suffix), \ + .read =3D cpuid_read_ ## _reader_fn, \ + } + +/* + * CPUID_PARSE_ENTRY_N() is for parsing CPUID leaves with a subleaf range. + * Check __CPUID_LEAF() vs. CPUID_LEAF_N(). + */ + +#define CPUID_PARSE_ENTRY(_leaf, _subleaf, _reader_fn) \ + __CPUID_PARSE_ENTRY(_leaf, _subleaf, _subleaf, _reader_fn) + +#define CPUID_PARSE_ENTRY_N(_leaf, _reader_fn) \ + __CPUID_PARSE_ENTRY(_leaf, __cpuid_leaf_first_subleaf(_leaf), n, _reader_= fn) + +/* + * CPUID parser table: + */ + +#define CPUID_PARSE_ENTRIES \ + /* Leaf Subleaf Reader function */ \ + CPUID_PARSE_ENTRY ( 0x0, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x1, 0, generic ), \ + +#endif /* _ARCH_X86_CPUID_PARSER_H */ diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 23b91bf9b663..cf061ed45ce8 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -17,7 +17,7 @@ #include #include #include -#include =20 +#include #include =20 #include "xen-ops.h" @@ -76,6 +76,7 @@ unsigned long xen_released_pages; static __ref void xen_get_vendor(void) { init_cpu_devs(); + cpuid_scan_cpu(&boot_cpu_data); cpu_detect(&boot_cpu_data); get_cpu_vendor(&boot_cpu_data); } diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index ed2d7a3756ce..223e9a2eb2d5 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -1429,6 +1429,7 @@ asmlinkage __visible void __init xen_start_kernel(str= uct start_info *si) xen_build_dynamic_phys_to_machine(); =20 /* Work out if we support NX */ + cpuid_scan_cpu(&boot_cpu_data); get_cpu_cap(&boot_cpu_data); x86_configure_nx(); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 E364B3F926D for ; Thu, 28 May 2026 15:40:04 +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=1779982805; cv=none; b=oAhGRA2195DsUK9FZupXUmh4OGP4jyoEg/hb1GQTGhbxcN8X9lVqRZLKrR6qFz8KvtRqlwC8B3M1KHsjX02i/KermVWlKY67/gRnSDzlwL070xtGS24CMmD/prROQuzjf8AZQEF3Bzt2c/CzjD6hQwHrQ5UEbpP058zRObebCBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982805; c=relaxed/simple; bh=s5spO4YsKmrxHCvSzKfWWzJ+KMRBpjtwvYcStZyCIls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZIekoMguSWZonecATQjT1xXKUfBzsC6vGe5nxMZLYIUlLUsYoPHxatAHPzNukWIPTRHeAs8hKmUhn8iqmH+/rXG3oDEbYp3qtlhgzVwQPJ9P4AvHzHojo2Y7niBHWkHv95ToCXgy32zBWeAHEGOkHPXlgvf6AZ1+k6lt25tzDhw= 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=Agq9jjrP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Z0WtzJ9c; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Agq9jjrP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Z0WtzJ9c" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y7NOvfnNl63vEh6Rxxpapu432IoxwbHBeaGZYezXAto=; b=Agq9jjrP0Ukk3pMxDJVwFWGDMWjV1fqiVYYHRhAMZDHLKm3Nez1Ws5tkvdSRgbWtBADO9A 8X3kUFnAiBNHu0C5RR16PUQK8q1pqPH67iIFsr457LnWV4nOLEoCi1QGdH3EU4qapJ1LgH Iruk7U4bBd0kRr+8ZLyll51h31exMgtK+odarULem21eVj/Zebm4QExG22tCeOEWDp26Rk 2mJLLnlJuuu6ariV/FGU9bHXt+1eQVIncMSX/Cuql9uKD+1F/K96Y2KqPen2L2jZSMNTLt Vkm2LF5aqQFjkLsWaOLgfECiDQoBz+VmWjGWsHec3jwuXJRJWSy4SEvvQ7UyBQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y7NOvfnNl63vEh6Rxxpapu432IoxwbHBeaGZYezXAto=; b=Z0WtzJ9cYB1QUDVSCuYtQTlwH5+lciCwVgYOLKWg8DzHd9CSfvSMJItdZd1P4za+/gRTP8 m+0FSNVLbdFBjSDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 007/120] x86/cpu: centaur/zhaoxin: Rescan CPUID(0xc0000001) after MSR writes Date: Thu, 28 May 2026 17:37:29 +0200 Message-ID: <20260528153923.403473-8-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Force-enabling Centaur/Zhaoxin CPU features through MSR writes leads to the CPUID(0xc0000001) EDX feature flags getting changed. Rescan CPUID(0xc0000001) in that case. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/centaur.c | 6 ++++-- arch/x86/kernel/cpu/zhaoxin.c | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 681d2da49341..a97e38fa6a9f 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -44,9 +44,11 @@ static void init_c3(struct cpuinfo_x86 *c) pr_info("CPU: Enabled h/w RNG\n"); } =20 - /* store Centaur Extended Feature Flags as - * word 5 of the CPU capability bit array + /* + * Force-enabling CPU features affects the CPUID(0xc0000001) + * EDX feature bits. Refresh the leaf. */ + cpuid_refresh_leaf(c, 0xc0000001); c->x86_capability[CPUID_C000_0001_EDX] =3D cpuid_edx(0xC0000001); } #ifdef CONFIG_X86_32 diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index 761aef5590ac..55bc656aaa95 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -46,9 +46,10 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c) } =20 /* - * Store Extended Feature Flags as word 5 of the CPU - * capability bit array + * Force-enabling CPU features affects the CPUID(0xc0000001) + * EDX feature bits. Refresh the leaf. */ + cpuid_refresh_leaf(c, 0xc0000001); c->x86_capability[CPUID_C000_0001_EDX] =3D cpuid_edx(0xC0000001); } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 E90923F44C1 for ; Thu, 28 May 2026 15:40:07 +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=1779982809; cv=none; b=T7FriHv32Wf0sR5J08rdWgo0PAnWk2DTAaHO3P3tesP0ljr1jbv0sS73dIDDsDaFgIzwva/gvLOwk3Qk9LzDBzQn4qB5Bk/syKel+cFlMX+WMrMaCg6xroJGn3JTHRYwH/DorRq3Jl5aibiUs932Elk9e2Ghe0bB9+7LZ/3Tg3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982809; c=relaxed/simple; bh=tXyMvxn4UMBT3PCejOr6UJi6Lo7MqYMdOc9grr9tpUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tBUZ1sNONaByPnu4zTj7LqVSwX04Omf67HrXTGhDy9xKleNmEx2coH8rEz7lHTCiiBDQWPLPVKi0AUwFq4+mx9bH/kpT2nvMlGeKK+5VJbHSaFE0gVdXAKE9UxvFGBCUaUsHVMk8D2nGIynwdkDoLfjPLl2fFlkNsfG8+XqtvR0= 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=OVzdZVNJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mAM2TRQy; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OVzdZVNJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mAM2TRQy" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zHfWDOXFp5/ApvTNX+Xe8ELUIriZCivm0dp52YbxHnI=; b=OVzdZVNJ93boXYRlkNU3BguuhWB1tBbe37c44kHYCyiyihkkUt9F46G654gxW7dfjncemR ++dK2imssAevlFJcm8+tE98SF6LJ+mdD9gzBR7vawI/RWMQNisT8OmgX7YOg4d72rRH4qq T7HLqfWS3g0tnKRWhuxkp9JwpU3R8DS5WWt25idDgQB3abt1dNkMh2liASW1mr4FrAeGXR g82d9S5KITy0l6VvuR+rEcHW7L4febpQZN6O0zYBaOFqSSruw/1V6qx7y7NgJcEFh7BUDx aksAdy1ByeK2nLeL7yXoc8xx0FSa/G1A+hnfoIIZPH4easovJ4tVzIg67WGDlg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zHfWDOXFp5/ApvTNX+Xe8ELUIriZCivm0dp52YbxHnI=; b=mAM2TRQybHG4/sgt2QM1rl/wFuO0pv0vFY0PrL4qyazvGXE4eN/vrdpTscExGVFOO3H/UU 37crqLAa6LP4kYDA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 008/120] x86/cpu/transmeta: Rescan CPUID(0x1) after capability unhide Date: Thu, 28 May 2026 17:37:30 +0200 Message-ID: <20260528153923.403473-9-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Transmeta CPUs allow masking CPUID(0x1).EDX feature flags via MSR writes. If a bit is cleared in the 0x80860004 MSR, its corresponding feature flag is not reported by CPUID. Refresh the CPUID parser's CPUID(0x1) cache while all of that MSR bits are unmasked. Note, the MSR 0x80860004 semantics are documented at the "BIOS Programmer's Guide: Transmeta Crusoe Processor", dated June 14, 2002. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/transmeta.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/kernel/cpu/transmeta.c b/arch/x86/kernel/cpu/transmet= a.c index 1fdcd69c625c..d9e0edb379b8 100644 --- a/arch/x86/kernel/cpu/transmeta.c +++ b/arch/x86/kernel/cpu/transmeta.c @@ -88,6 +88,7 @@ static void init_transmeta(struct cpuinfo_x86 *c) /* Unhide possibly hidden capability flags */ rdmsr(0x80860004, cap_mask, uk); wrmsr(0x80860004, ~0, uk); + cpuid_refresh_leaf(c, 0x1); c->x86_capability[CPUID_1_EDX] =3D cpuid_edx(0x00000001); wrmsr(0x80860004, cap_mask, uk); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 113E23F9F47 for ; Thu, 28 May 2026 15:40:11 +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=1779982812; cv=none; b=OywYaUdqAsNKVwzZQe88PJOtYIHcGOrQYIyFwM715+HeCbLR5YpS37LmRyH8l4O3VNWs3e8EIS9rcwia6hykbxzc4rLTvpAgPGACjM0LCDbDh0RKoKAFyotjTc2heQxTasN8/ImRHvnxg8jFPQsVFyclLyK9upGCfKHjMT5jh6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982812; c=relaxed/simple; bh=l9ot3O6NqYhKS+hmIUpBl2Ce7dmNkP6NLp0oGF/D5FY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GG4fSYDdJFjfiGcol+XG1eNcrrCvOzl4GsG1waazDQU7x3tZWmxM6cwp8ijjoEBQ/PNMZPIGIlPxB1S7xMRbgmCsmIMd3Rx7t158NJjcBXeMzFw1fhLv7LgqWZ2rp+aULCkIYjtsjPvIAk2U+89XsvFDYGYZCoz5PU5CyApk4b4= 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=Nr41vQjS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NLNGuIV4; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Nr41vQjS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NLNGuIV4" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BNvmMQEZWmBYKIETeBYYEEai3qIMsPFTzSyzSDJnFJo=; b=Nr41vQjS5KdLJGpWN8RmyP1yB7dcfzGH4MznwZBD96o0GACNDq6g5cYpCJH7OVUFUeqr7X pcplIyHwHIlNV/V09Pm3Ld7ikvo9GZUrFM8ggHUQlj6UPsn6eWoJOUIr66d9Y66SMir5L4 F2CTwEtzheyc1SVb28l9q+NJE9QdQNkFlfI9c6/75QaMKn1DwOXQDoEYBsJ6Q0b4o5afUG Za1YHjVNb7e1lcwRYmVbrj0wajJ8LbmklNQcLuVNNeZ9fSsEO9j2L70agHMuy8HHPaVpSH +u6K6oKNTqG4LuCxe5RvPUVDeVWggm+MG949kzqgnzFxKzrMCtzZMd0PmM1Fag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982809; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BNvmMQEZWmBYKIETeBYYEEai3qIMsPFTzSyzSDJnFJo=; b=NLNGuIV4M7d+1PRVVnPhagyR7IBa9cOGnmz4ypSWCkc+gr2DDO9rY/xNwv9bYuMM3CXSPh IqmFKetVt2hcAuCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 009/120] x86/cpu: Use parsed CPUID(0x0) Date: Thu, 28 May 2026 17:37:31 +0200 Message-ID: <20260528153923.403473-10-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x0) instead of a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 5cae6c48dd25..281dc591ea79 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -942,11 +942,15 @@ void get_cpu_vendor(struct cpuinfo_x86 *c) =20 void cpu_detect(struct cpuinfo_x86 *c) { - /* Get vendor name */ - cpuid(0x00000000, (unsigned int *)&c->cpuid_level, - (unsigned int *)&c->x86_vendor_id[0], - (unsigned int *)&c->x86_vendor_id[8], - (unsigned int *)&c->x86_vendor_id[4]); + const struct leaf_0x0_0 *l0 =3D cpuid_leaf(c, 0x0); + + if (!l0) + return; + + c->cpuid_level =3D l0->max_std_leaf; + *(u32 *)&c->x86_vendor_id[0] =3D l0->cpu_vendorid_0; + *(u32 *)&c->x86_vendor_id[4] =3D l0->cpu_vendorid_1; + *(u32 *)&c->x86_vendor_id[8] =3D l0->cpu_vendorid_2; =20 c->x86 =3D 4; /* Intel-defined flags: level 0x00000001 */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 5F8AF3FBB72 for ; Thu, 28 May 2026 15:40:14 +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=1779982815; cv=none; b=u+1uTsVuEQokqZRTCxZ71EBdsKpmkQ8G5dk7L0I10Mos2gAHHQZsF5Uh18K0+X9ZTaYOj/b68gzFrrWxz84M1LN0HPQfqPKnYRcozuELwYjGAqAm0lecwzTHsau9P8TD4UYR6hPypUobOgAmMm5AOHGKdqAJyzA58imXbKVR8x0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982815; c=relaxed/simple; bh=Ptq0AD/07FTZfn1MZVuzGMv3/AgW/073H//my5s7Lts=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dWLaBPGS0h+7CrO/IJZvYSSDDEmHncFDGwunZQO/VnSVXKlXRPyx9G1wXIRbgQnbbHY4uHhYShRjVm7FtzeTtqIYVdzx2t3CooBq4ujhtAU7zeMgtLpsGsEY07wrJ88YFtuH1ThnWJsUh864CA3APLmHdOhRJx28IbuzCSsb95g= 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=mkN2RcsG; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UhzwJjK7; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mkN2RcsG"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UhzwJjK7" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pxCdJ5pnBRYs8UEPoOd/2jW8v7PBGNRqmHGJxzIH8o4=; b=mkN2RcsGXDFXmbiSsaZmGyYz57rJe2UU/yYgg6qw+NZfDymMC/izbTJUiatsAihZ9Ioo6o muLFYC9cCPwGT0mKBhmSKKe1QGNireQoDkO1ZvZvotA4SopdmMnR4W7X7Gi28M9ES5sOtU 9WdIRpLWkR6v7ilBrXOul86PZpUN5+tEa4czO5jbzf6gHnJxr9KdSNNi02soM/D8xL+dSo r4Y+4Ol4e2ZeD+OCEMyI74/4XGOfHjC27xSfKlFxM3k8J+pvB265TIBv40WfUqRq95LiNM 3D2TBZ7I/SVLuUEILNcj0BhuZmRjIilSTe+FAf5RZU32gpIACdpxL85BiY9HaQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982813; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pxCdJ5pnBRYs8UEPoOd/2jW8v7PBGNRqmHGJxzIH8o4=; b=UhzwJjK7rjTfQWF0fDo5LH0j4E3AUN6No55hvfrM2BM6Hn6kd0OxoLZ+vpc5yPUZcnnKgO HWmWOUr/JnkyTICA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 010/120] x86/lib: Add CPUID(0x1) family and model calculation Date: Thu, 28 May 2026 17:37:32 +0200 Message-ID: <20260528153923.403473-11-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The x86 library provides x86_family() and x86_model(). They take raw CPUID(0x1) register output and calculate the CPU family and model from it. In follow-up work, the x86 subsystem will use parsed CPUID APIs instead of invoking direct CPUID queries. These new APIs force using the auto generated leaf data types at . Introduce x86 family and model calculation functions that take these auto-generated data types. Refactor the original code so that no logic is duplicated. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpu.h | 6 +++++ arch/x86/lib/cpu.c | 45 ++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index 57a0786dfd75..01313070b2da 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -7,7 +7,9 @@ #include #include #include + #include +#include =20 #ifndef CONFIG_SMP #define cpu_physical_id(cpu) boot_cpu_physical_apicid @@ -24,6 +26,10 @@ int mwait_usable(const struct cpuinfo_x86 *); unsigned int x86_family(unsigned int sig); unsigned int x86_model(unsigned int sig); unsigned int x86_stepping(unsigned int sig); + +unsigned int cpuid_family(const struct leaf_0x1_0 *l); +unsigned int cpuid_model(const struct leaf_0x1_0 *l); + #ifdef CONFIG_X86_BUS_LOCK_DETECT extern void __init sld_setup(struct cpuinfo_x86 *c); extern bool handle_user_split_lock(struct pt_regs *regs, long error_code); diff --git a/arch/x86/lib/cpu.c b/arch/x86/lib/cpu.c index 7ad68917a51e..4d0beeeb4885 100644 --- a/arch/x86/lib/cpu.c +++ b/arch/x86/lib/cpu.c @@ -1,33 +1,36 @@ // SPDX-License-Identifier: GPL-2.0-only #include #include + #include +#include =20 -unsigned int x86_family(unsigned int sig) +static unsigned int __x86_family(unsigned int base_fam, unsigned int ext_f= am) { - unsigned int x86; + if (base_fam =3D=3D 0xf) + base_fam +=3D ext_fam; =20 - x86 =3D (sig >> 8) & 0xf; + return base_fam; +} =20 - if (x86 =3D=3D 0xf) - x86 +=3D (sig >> 20) & 0xff; +static unsigned int +__x86_model(unsigned int family, unsigned int base_model, unsigned int ext= _model) +{ + if (family >=3D 0x6) + base_model |=3D ext_model << 4; =20 - return x86; + return base_model; +} + +unsigned int x86_family(unsigned int sig) +{ + return __x86_family((sig >> 8) & 0xf, (sig >> 20) & 0xff); } EXPORT_SYMBOL_GPL(x86_family); =20 unsigned int x86_model(unsigned int sig) { - unsigned int fam, model; - - fam =3D x86_family(sig); - - model =3D (sig >> 4) & 0xf; - - if (fam >=3D 0x6) - model +=3D ((sig >> 16) & 0xf) << 4; - - return model; + return __x86_model(x86_family(sig), (sig >> 4) & 0xf, (sig >> 16) & 0xf); } EXPORT_SYMBOL_GPL(x86_model); =20 @@ -36,3 +39,13 @@ unsigned int x86_stepping(unsigned int sig) return sig & 0xf; } EXPORT_SYMBOL_GPL(x86_stepping); + +unsigned int cpuid_family(const struct leaf_0x1_0 *l) +{ + return __x86_family(l->base_family_id, l->ext_family); +} + +unsigned int cpuid_model(const struct leaf_0x1_0 *l) +{ + return __x86_model(cpuid_family(l), l->base_model, l->ext_model); +} --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 8C2213FAE00 for ; Thu, 28 May 2026 15:40:17 +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=1779982819; cv=none; b=qmVFz+ODpbBkIafq1gspEonjh6DrWOA62flK6+E4boPhkVO3sfwXINWSxVFz432Wga27nUmVvFXAVW5B50ZdZlwZ6XFAKp7WopvCkTb6GeSBZPmyVoggVd2G9BNituyeH9mUbAZxIrqkTmQOT5dlIVdgurX1cHUbHZoqK0ftjak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982819; c=relaxed/simple; bh=qIPi3ZCZvU7QCQVGe1Zitd1V/S/Wf3QdHZV6GRCHH8w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aHNoa2YY8hi+B4n0qklKmAwTtSCPR0p1yJq3418kchEfxwDwb8syDkDe1b0fh6bQVVsXXNnhgjYRj6lXlxTMKs3qMzRkPd6RobuG1GTq29PLmKPPeZNcOki5uzvXjzuAFk8ENvXsfdm8J3M0RX13W8Czr1UMNVeFMv/njyhGNKM= 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=X0rXGVON; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2Z2Y1XeA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X0rXGVON"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2Z2Y1XeA" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jGguF42oBDJHVXC2ASPZX9r/bkhMUjBRb7A9QBXOkRM=; b=X0rXGVONca15CXP2vp/TzB+nbBlwQpunNE030ZhGBVKQOLp2dcCofBb0YUBSrgO8y53AKv /iMK1r/WrtYuTqkFtdf3/gsylB69XWDMpL4S5bUYwmNwjKfOnGVIGgRE5YIYF5DKtogjvD O2eFlUROMRYSXwvN2WOqrFr1wmp2kR7sqv55stKDtpJ13Lsaiqsk9r4stGhVP5uydtgylW lzXaDBhxzuXhSAnUwcxH/AUEf/JRQi9L0CeUtUCdXxwvZVb9Qu7X3KegIIVXeVT994dn2M slLqDqk9Fyw1LtK/7lIaohktGj8Xd3sEqop61iPPGnpPnEEn+6KJ80I7mYaZaA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jGguF42oBDJHVXC2ASPZX9r/bkhMUjBRb7A9QBXOkRM=; b=2Z2Y1XeAEv5AXRsqh8vEYuYlQh89sKFGnBwSP0E7Leuqf6dl+nfUYFR+BUyc7j59q0W6He dU2v42A2oDZ69yAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 011/120] x86/cpu: Use parsed CPUID(0x1) Date: Thu, 28 May 2026 17:37:33 +0200 Message-ID: <20260528153923.403473-12-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On early boot CPU detection, use parsed CPUID(0x1) instead of a direct CPUID query. Beside the parser's centralization benefits, this allows using the auto generated CPUID data types, and their C99 bitfields, instead of doing ugly bitwise operations. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 281dc591ea79..257808609ef5 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -943,6 +943,7 @@ void get_cpu_vendor(struct cpuinfo_x86 *c) void cpu_detect(struct cpuinfo_x86 *c) { const struct leaf_0x0_0 *l0 =3D cpuid_leaf(c, 0x0); + const struct leaf_0x1_0 *l1 =3D cpuid_leaf(c, 0x1); =20 if (!l0) return; @@ -953,17 +954,13 @@ void cpu_detect(struct cpuinfo_x86 *c) *(u32 *)&c->x86_vendor_id[8] =3D l0->cpu_vendorid_2; =20 c->x86 =3D 4; - /* Intel-defined flags: level 0x00000001 */ - if (c->cpuid_level >=3D 0x00000001) { - u32 junk, tfms, cap0, misc; - - cpuid(0x00000001, &tfms, &misc, &junk, &cap0); - c->x86 =3D x86_family(tfms); - c->x86_model =3D x86_model(tfms); - c->x86_stepping =3D x86_stepping(tfms); + if (l1) { + c->x86 =3D cpuid_family(l1); + c->x86_model =3D cpuid_model(l1); + c->x86_stepping =3D l1->stepping; =20 - if (cap0 & (1<<19)) { - c->x86_clflush_size =3D ((misc >> 8) & 0xff) * 8; + if (l1->clflush) { + c->x86_clflush_size =3D l1->clflush_size * 8; c->x86_cache_alignment =3D c->x86_clflush_size; } } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 D3B623FDC03 for ; Thu, 28 May 2026 15:40:20 +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=1779982822; cv=none; b=F5HQ2hGhy58FLCdZokB5zI2T+HNoBQfp/UXnwm00HuxPMbwc73V84oYWHSuFQ5a0se4LZJ3LbFj5K0Mj7eYzEYJdH2g9llSsWLnyieaKxO0BVv16d5wbp9HX/eBqAyUV/gyj8CXi4gFiWCYoP8ygz7LdRm4iD5WEpEsVFF52dJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982822; c=relaxed/simple; bh=wBpDZ8ZYwQZs5UPZpt2jKk/ecqdBJL5Cz6NIBSpEz/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TY4q1FhSndWtBneDim8KdO66mZAi93dlTS1TUoroClx++1xqvXOvnzxDQCrBWpu3UWpMR6y7iqkbhjM3zJ+NibeF0oSlBXayYEgijOk7m+IIuHeREITXCya4bjIyyDxonx6Q9l62Bx/TLL9sIsdqjbGvvyggw8cOuC7NET+a7is= 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=BJJlw/mN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MfiIHljX; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BJJlw/mN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MfiIHljX" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b1pJKumQpKk9xRz20NXWO08mDN5NfovKWNISL2IUrh8=; b=BJJlw/mNRTttX1q5Zb6F+ziFgxK80Gn8LrNAsE96vmKJ5WCpa909/B2Be8qUUYKtBZIknO /RDqYbvakfdv0vBbXDpP4LqkD6Dz1SwLLmFLIKS3HSyPqB5CpeZCyXVQeOIxLL8HbIIeFW RgmRKatgMuP41KADBwBsVIlZvs4ogl3PZUqNlpOZOgl0Q/8bCi48fba+oRHENBXGkT8oK6 v+kLSNd4KmPM8mm7h2gWZCTjRgyoMEbEoF+6F1cfxTw0Hi7ftt0Z7fZLYg7/O/5DGKjKe/ V7ImhD9Qs9gRFnVorZnTopeE1/3wObLZNNepm4KC0JBDB1Co5y7G5J0rnor09w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b1pJKumQpKk9xRz20NXWO08mDN5NfovKWNISL2IUrh8=; b=MfiIHljXBdT+gTBpTmFtrz3v3CPsH5C2s9om19FDZ6ClsIfXYvuaS5lKW4ZmSdP5v6LUD/ LFHtDUhPlgKX3eDQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 012/120] x86/cpuid: Parse CPUID(0x80000000) Date: Thu, 28 May 2026 17:37:34 +0200 Message-ID: <20260528153923.403473-13-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add CPUID parser logic for CPUID(0x80000000). Verify the CPUID output since legacy Intel machines without an extended range will repeat the highest standard CPUID leaf output instead. This verification is similar to what is done at arch/x86/kernel/head_32.S and arch/x86/kernel/cpu/common.c. References: 8a50e5135af0 ("x86-32: Use symbolic constants, safer CPUID when= enabling EFER.NX") References: 67ad24e6d39c ("- pre5: - Rasmus Andersen: add proper...") #= Historical git Signed-off-by: Ahmed S. Darwish Cc: "H. Peter Anvin" Link: https://lore.kernel.org/r/d4fcfd91-cc92-4b3c-9dd2-56ecd754cecc@citrix= .com --- arch/x86/include/asm/cpuid/types.h | 4 ++++ arch/x86/kernel/cpu/cpuid_parser.c | 21 +++++++++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 1 + 3 files changed, 26 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 3d0e611c97ba..c020fb8fed59 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -36,7 +36,10 @@ enum cpuid_regs_idx { #define CPUID_RANGE_MAX(idx) (CPUID_RANGE(idx) + 0xffff) =20 #define CPUID_BASE_START 0x00000000 +#define CPUID_EXT_START 0x80000000 + #define CPUID_BASE_END CPUID_RANGE_MAX(CPUID_BASE_START) +#define CPUID_EXT_END CPUID_RANGE_MAX(CPUID_EXT_START) =20 /* * Types for CPUID(0x2) parsing: @@ -203,6 +206,7 @@ struct cpuid_leaves { /* Leaf Subleaf number (or max number of subleaves) */ CPUID_LEAF ( 0x0, 0 ); CPUID_LEAF ( 0x1, 0 ); + CPUID_LEAF ( 0x80000000, 0 ); }; =20 /* diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index 898b0c441431..2cebe15f75d4 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -38,6 +38,24 @@ cpuid_read_generic(const struct cpuid_parse_entry *e, co= nst struct cpuid_read_ou cpuid_read_subleaf(e->leaf, e->subleaf + i, regs); } =20 +static void +cpuid_read_0x80000000(const struct cpuid_parse_entry *e, const struct cpui= d_read_output *output) +{ + struct leaf_0x80000000_0 *el0 =3D (struct leaf_0x80000000_0 *)output->reg= s; + + cpuid_read_subleaf(e->leaf, e->subleaf, el0); + + /* + * Protect against Intel 32-bit CPUs lacking an extended CPUID range. A + * CPUID(0x80000000) query on such machines will repeat the output of the + * highest standard CPUID leaf instead. + */ + if (CPUID_RANGE(el0->max_ext_leaf) !=3D CPUID_EXT_START) + return; + + output->info->nr_entries =3D 1; +} + /* * CPUID parser table: */ @@ -53,9 +71,11 @@ static const struct cpuid_parse_entry cpuid_parse_entrie= s[] =3D { static unsigned int cpuid_range_max_leaf(const struct cpuid_table *t, unsi= gned int range) { const struct leaf_0x0_0 *l0 =3D __cpuid_table_subleaf(t, 0x0, 0); + const struct leaf_0x80000000_0 *el0 =3D __cpuid_table_subleaf(t, 0x800000= 00, 0); =20 switch (range) { case CPUID_BASE_START: return l0 ? l0->max_std_leaf : 0; + case CPUID_EXT_START: return el0 ? el0->max_ext_leaf : 0; default: return 0; } } @@ -113,6 +133,7 @@ cpuid_fill_table(struct cpuid_table *t, const struct cp= uid_parse_entry entries[] unsigned int end; } ranges[] =3D { { CPUID_BASE_START, CPUID_BASE_END }, + { CPUID_EXT_START, CPUID_EXT_END }, }; =20 for (unsigned int i =3D 0; i < ARRAY_SIZE(ranges); i++) diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index df627306cc8c..7d41bde0c0ec 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -116,5 +116,6 @@ struct cpuid_parse_entry { /* Leaf Subleaf Reader function */ \ CPUID_PARSE_ENTRY ( 0x0, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x1, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ =20 #endif /* _ARCH_X86_CPUID_PARSER_H */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 3DA913FE364 for ; Thu, 28 May 2026 15:40:24 +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=1779982825; cv=none; b=VRuw7DiT6rGLTQ01qYiv8jHJ4SVnFtAslXSacKJp05NyRCKpbUaWoRvvCTdHS6H/t2uEt/yFy+yGHR8lPBEu7xpu/wEjuOfeSzZuUqdCAC8Zmeb86d88y983e9ROyROhiGSZKmb6+WElx7vyhdr6JIbXqdZ3QWsa5cv3GqC2nl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982825; c=relaxed/simple; bh=sl6C0wJhIFidfHLcpnMa5hAhYTKn2SOK2ff5l5LU10A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oXCGrhm1nq4SmqDdGNttbjpMkSZBdHthpoPROytm6+AQ1qwuBcx9e83dNerUZr0H4mczRENh+SU496iPfm/gPhTW/QQ+4fh8PoKQbhjkMg27D6NQajmpQ0bS5JoGKAAhoWdGoHgi/XPvKa6bhG9hk/luLLU2H9e4SVAMvWjD2Pc= 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=bB0YzQFt; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=R/3HlCOm; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bB0YzQFt"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="R/3HlCOm" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982822; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zTVNWRQPCqzGBrFVhtMiodywZ6GPWl7y/Gu9wWG7slI=; b=bB0YzQFtoxGXwmw7S5Sxhwbr6otQ55bYW6p3myNVhhhfiqn++aKmonL7/MGnBZagT7Ncvi nsL1RGLP5ec/1a3yb4IDFHiAEFEu6121sgCkp3hZUmDIfTNBHZ7MA+daTgZmjUEEi3Jtr2 JjCXiTT04b5PuNKDi/ZA+5D8YZ8ImmPzjm6EAQ4zV3JM/QmKxyLE3T6rhILsxapjsEW+S7 +r7LP2+GbHsK6ZpLw3YwjaqfkjYZPUQQNjpiDEu9r+sS83RFHjr2nyJZkT3MigkxXQ8zbZ RubxARf87QV5zBK3OBv6DEeer0xKXgMz5r4fMmLxcryj2l8jShfR3cUAim9ONw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982822; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zTVNWRQPCqzGBrFVhtMiodywZ6GPWl7y/Gu9wWG7slI=; b=R/3HlCOmL9Gi/Ul3Jx1Ykp1LyyBQ+5kRWnnVtSGH8EG6X/7ZC7OgAm21HBkSkBg27d9gkm J1sZl5DJL7QMPkAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 013/120] x86/cpu: Use parsed CPUID(0x80000000) Date: Thu, 28 May 2026 17:37:35 +0200 Message-ID: <20260528153923.403473-14-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At early boot code, use parsed CPUID(0x80000000) instead of invoking a direct CPUID query. The original code has the check: extended_cpuid_level =3D ((eax & 0xffff0000) =3D=3D 0x80000000) ? eax := 0; to protect against Intel 32-bit machines without an extended range, where a CPUID(0x80000000) query will repeat the output of the max-valid standard CPUID leaf output. A similar check is already done at the CPUID parser's own CPUID(0x80000000) read function: if (CPUID_RANGE(el0->max_ext_leaf) !=3D CPUID_EXT_START) { // Handle error } Thus, for the call-site, the parsed CPUID NULL check below: el0 =3D cpuid_leaf(c, 0x80000000); extended_cpuid_level =3D el0 ? el0->max_ext_leaf : 0; is sufficient. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 257808609ef5..9b05a747161f 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1019,6 +1019,7 @@ static void init_speculation_control(struct cpuinfo_x= 86 *c) =20 void get_cpu_cap(struct cpuinfo_x86 *c) { + const struct leaf_0x80000000_0 *el0 =3D cpuid_leaf(c, 0x80000000); u32 eax, ebx, ecx, edx; =20 /* Intel-defined flags: level 0x00000001 */ @@ -1054,12 +1055,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c) c->x86_capability[CPUID_D_1_EAX] =3D eax; } =20 - /* - * Check if extended CPUID leaves are implemented: Max extended - * CPUID leaf must be in the 0x80000001-0x8000ffff range. - */ - eax =3D cpuid_eax(0x80000000); - c->extended_cpuid_level =3D ((eax & 0xffff0000) =3D=3D 0x80000000) ? eax = : 0; + c->extended_cpuid_level =3D el0 ? el0->max_ext_leaf : 0; =20 if (c->extended_cpuid_level >=3D 0x80000001) { cpuid(0x80000001, &eax, &ebx, &ecx, &edx); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 258933FE66C for ; Thu, 28 May 2026 15:40:28 +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=1779982830; cv=none; b=OGOLBkF2so0NOeyYNZzbHF/KNWadZN3tLxinBC68p9nP6avZ9QmE/B6ZiQ+VjNT14651UkprIxPzIKE6kIiv3JR3pDlPZMcHKuL9abELUU+Elb4Ytxva7sGWnPgojNfS5/hICqxYECMCC+bdzb+EneD7fqOlLGo1Rnx2DELwtmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982830; c=relaxed/simple; bh=1HCZ5l9RxCU3IUPSCzTHfvMvvUidzbrY6BQsFnBw3Dc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MdAwevMb+wKCX4lbWUD1Gd4Pg8FqMf+/zcEzq2MCZeODgjyJp9dyh49XFva0Dq0Gw1ohHdbQ3gdL+s+aLQYE9d7lr5lqwRee1lih5/U2XYKK3q4kdW3ckQMsC10wbiSUmSDOMkKsHb3a8uB8b6zoSwg+pAoPf4YQCJnMRrxCyXY= 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=QQBE3Izy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GsnZ4KZb; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QQBE3Izy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GsnZ4KZb" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Enkiw++N0BixPy49r1hKo68/Y20Z8aSvogyYQ0bhJhE=; b=QQBE3IzyKnPRTAM+AxAdP6A6QLd6E1Y95N8R2iPs6CS3oHqFeWpM7Z0XLcQUZ0qklJ0oxN jrwzT5VdO/J3vFFZMNCVyfDXoTrVgNIyK5EzMz5o6oKClpMwcunOHhYrVFNkFAI9MCc5JN qY5xJREmTHRRwUTOf9TnAWaefrN1zrP9Gze59pVlR8QUB7PVIAdd0yD4lYAA11dqnZSmCW OpiJLlJSXSQv/CmITyRu/Ny9+JpXvPYCGSr8gnN1PchPs4O643lqVGmkae43x/X/vNFrCT VClPNfPJ84CBFClqgyJZ3oRHlPXtlhsJGJs2azMXiAgrPYWpR5uf8DtfZY7kjQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Enkiw++N0BixPy49r1hKo68/Y20Z8aSvogyYQ0bhJhE=; b=GsnZ4KZbl+0ukePd6N8CuBirzDBaFBDBldRxwBGCuI3xHwNu+JRPl8honR8GQRbVJ7B3J3 QVnwE5gTTWqaI6Aw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 014/120] x86/cpuid: Parse CPUID(0x80000002) to CPUID(0x80000004) Date: Thu, 28 May 2026 17:37:36 +0200 Message-ID: <20260528153923.403473-15-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add CPUID(0x80000002) =3D> CPUID(0x80000004) support to the CPUID parser. This allows converting their call sites to the CPUID API next. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 3 +++ arch/x86/kernel/cpu/cpuid_parser.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index c020fb8fed59..8be2c2ba874a 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -207,6 +207,9 @@ struct cpuid_leaves { CPUID_LEAF ( 0x0, 0 ); CPUID_LEAF ( 0x1, 0 ); CPUID_LEAF ( 0x80000000, 0 ); + CPUID_LEAF ( 0x80000002, 0 ); + CPUID_LEAF ( 0x80000003, 0 ); + CPUID_LEAF ( 0x80000004, 0 ); }; =20 /* diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 7d41bde0c0ec..3e11e13fa76c 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -117,5 +117,8 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x0, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x1, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ + CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ =20 #endif /* _ARCH_X86_CPUID_PARSER_H */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 9023D3FDC03 for ; Thu, 28 May 2026 15:40:34 +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=1779982836; cv=none; b=aF+7dwIdS+K5FOt9rBqPF5I6yDxlAhkjkOspcj48HWTxOVoy6lNZfS0UElD0FLQ/3Se7xlggp2MTa6EGq/5BVQcW3q1rMqe+f4W/V7flGZHLY2X05lYxbBptAfvRB334EKPhdCsDvvQi+gjBairt1IYglt8+WhmNBcXDEIRVuU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982836; c=relaxed/simple; bh=egJtEUgAAOv+REXJnPKTatiACh6x5W3wIvM/iV2OfNw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q3i/Bh07TMN6r7NEj61SIajGeUAT6sGW87FzTx40zUrvT0z5lWrs6//5c5q0nqo1ND+/quGdMCWjiHb6YtOoJ3dh+muXdYrcXnhCTc7fcnDydoAUthy/K723cj487gA9d4WbMKkbRqF+z9pMbBVrCDgI5I6ExGNQljTZAjNT3So= 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=11kRacLW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EmIfIPQl; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="11kRacLW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EmIfIPQl" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P1fKBOdy7Ox4wwAyB5ruCggSZ6NrUZ+tCeO0Em2q5Sw=; b=11kRacLWTCLWQTVh4HQDLcaPRL/e4wOKIcik4vM9SWqEt6LaeCzT4VLrVa2F2p3FftIucK vOq6k5q4ZBls8dTl06a2NqiSfb2qBy+KwDjjZSUAodU4D/nJfl5PLHOQcEgVbuW/GjXuzZ E2Zyc9dz66mM/0Q7EUBnrCtluG5Hd3EiCXLcl526W5EjXxwSpbpQjczJkEw9IcxGj7x9ri 6upCP9it2MO0QUHIeugKsTjuuz1NszWe26O3YNQ0+2oRrGmBx3ZOP0IIOFEP22OzVn++vt JGfv6hK+5s6Zskp0UrtmGhC5J00izRV+Fm5xrM/QTMG0OYBRmvCiPMlSdg+2og== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P1fKBOdy7Ox4wwAyB5ruCggSZ6NrUZ+tCeO0Em2q5Sw=; b=EmIfIPQlftyVP5hk417TNkCJBUwQ+9su8PlqHcdz2MlLv+U4CAhHCAcSKaylMUJrDlycoJ zGeKiz7EGXOkOMDA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 015/120] x86/cpu: Use parsed CPUID(0x80000002) to CPUID(0x80000004) Date: Thu, 28 May 2026 17:37:37 +0200 Message-ID: <20260528153923.403473-16-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For CPU brand string enumeration, use parsed CPUID(0x80000002) to CPUID(0x80000004) instead of invoking direct CPUID queries. This centralizes CPUID invocation to the system's CPUID parser. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 9b05a747161f..3d5b5df544d1 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -826,16 +826,18 @@ static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM]= =3D {}; =20 static void get_model_name(struct cpuinfo_x86 *c) { - unsigned int *v; + const struct leaf_0x80000002_0 *l2 =3D cpuid_leaf(c, 0x80000002); + const struct leaf_0x80000003_0 *l3 =3D cpuid_leaf(c, 0x80000003); + const struct leaf_0x80000004_0 *l4 =3D cpuid_leaf(c, 0x80000004); char *p, *q, *s; =20 - if (c->extended_cpuid_level < 0x80000004) + if (!l2 || !l3 || !l4) return; =20 - v =3D (unsigned int *)c->x86_model_id; - cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]); - cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]); - cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]); + *(struct leaf_0x80000002_0 *)&c->x86_model_id[0] =3D *l2; + *(struct leaf_0x80000003_0 *)&c->x86_model_id[16] =3D *l3; + *(struct leaf_0x80000004_0 *)&c->x86_model_id[32] =3D *l4; + c->x86_model_id[48] =3D 0; =20 /* Trim whitespace */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 28F8D3F888A for ; Thu, 28 May 2026 15:40:39 +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=1779982841; cv=none; b=KmVOgdshp7r5s8wKrucrx5tJwTsHHCVymYBewGWop7ABkJXtKGFTnzuSLIdK0C8bUak8+oZDKnkv4UOnaupvWhWhpIyGER8ZiiyJfgbA3Q++tPQMsuy3fy2KPumfu+DxX5igQ4zYDWClcNFAhAGDnm4xdyIkpEszfa8g7bRKtn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982841; c=relaxed/simple; bh=x0H7EDQSQDzozuBi6yY8P63753NIyQjB7Ye44PRzOYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nI+FlIYrJJGbJDUFz37xyJ3Nth8vjYt6DKGL8l5zcBlrw7oS6O5LZD4aAyWPv+pxKm6lY+ihZu/MZ/DRbUkYzzd9vQ3tUou4cq4VScWBVPCrnLka8DgmDOkPgaQqB2WdHkZumwAh+40hlY6JXMkXhREhDD9nAUQLwYB/cRAAkq0= 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=GrB3SrzM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aXPYHqmx; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GrB3SrzM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aXPYHqmx" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lhvXydeK4qGnjCuLdcKfLEXDwg2fe5aKCCDZ/2rwZpo=; b=GrB3SrzM+CH7xbmh8VzJZn7mzHyR2GhwgWJScTJyW/cuOSaMXbBG/zyenyaCS4y8FiGvyY d9FsU1VE6PfEZY+DNVsuA+f7PnvTJoiT7EMJ8NwOqKUaUezB6jQUdTNbEOhZrDLAy8E0eI qVEjNteJAVfekdGd0YR+uOt42eWMSoDhWMgSu2E8saY+RiVi7SYFbkuf5v+BXpTaK/qDNr htqaShp7+k+EaBRxNrQHf1vnwBHSQsM3pB7i3BhhY+yXCyXFNcdkWYERQfiQTDG+wsVFP/ cpM1Q/hihBu2kTh2dM5Hum9Pz75MkGd9b7e1jm/aIJYYSJPKa+cAXko5EjgEtw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lhvXydeK4qGnjCuLdcKfLEXDwg2fe5aKCCDZ/2rwZpo=; b=aXPYHqmxvcrArwVPL7dDvsLJ9gFDwbBfMd1R32Vu09+pI3S4aknqSpuRLsFdY4ABPdpmLN MOCZ7e3uFdGD04Cg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 016/120] x86/cpuid: Split parser tables and add vendor-qualified parsing Date: Thu, 28 May 2026 17:37:38 +0200 Message-ID: <20260528153923.403473-17-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For the CPUID parser, introduce a table listing vendor-specific CPUID leaves. Not all CPUID leaves should be queried on all x86 vendors, so the parser will enumerate such leaves only if the boot machine's x86 vendor is listed as supported. This provides the following benefits: (a) Even when a CPUID leaf falls within the CPU's standard or extended maximum leaf range, querying architecturally unsupported and reserved CPUID leaves may trigger new kernel boot behaviors or subtle bugs; especially on legacy machines. (b) Associating x86 vendor information with CPUID leaves will enable the CPUID parser to emit (lightweight) error messages when malformed CPUID leaf output is detected. This is due to the parser now being more certain that the queried leaf is valid on the machine. (c) Attaching x86 vendor information to CPUID leaves will relieve call sites, especially drivers, from ugly x86 vendor checks before querying a CPUID leaf. Just checking if the CPUID APIs did not return NULL will be sufficient. Split the CPUID parsing table into an "early boot" table and a standard one. The early boot phase parses only CPUID(0x0) and CPUID(0x1) since they are needed to identify the CPU's x86 vendor. Once the x86 vendor info is saved to the CPU's capability structure, invoke the CPUID parser again to parse the rest of the CPUID table. In that second phase, the parser assumes that "boot_cpu_data.x86_vendor" is valid and uses it for the CPUID leaves x86 vendor validity checks. For each vendor-specific CPUID leaf, build its list of matching x86 vendors using CPP varargs. Encoding this as bitflags was not doable, since the x86 vendor IDs are just raw monotonic numbers from 0 (Intel) to 11 (Vortex). Keep the CPUID parser's leaf vendors table empty for now. Leaves like CPUID(0x2), CPUID(0x4), CPUID(0x16), and CPUID(0x8000001d) will be added to the parser vendor table once their support is actually implemented. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 1 + arch/x86/kernel/cpu/common.c | 9 ++- arch/x86/kernel/cpu/cpuid_parser.c | 100 +++++++++++++++++++++++++---- arch/x86/kernel/cpu/cpuid_parser.h | 52 ++++++++++++++- arch/x86/xen/enlighten.c | 2 +- 5 files changed, 146 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 82eddfa2347b..3d5a0d4918cc 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -532,6 +532,7 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) * CPUID parser exported APIs: */ =20 +void cpuid_scan_cpu_early(struct cpuinfo_x86 *c); void cpuid_scan_cpu(struct cpuinfo_x86 *c); void cpuid_refresh_leaf(struct cpuinfo_x86 *c, u32 leaf); void cpuid_refresh_range(struct cpuinfo_x86 *c, u32 start, u32 end); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 3d5b5df544d1..67dd2c5b9680 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1021,9 +1021,11 @@ static void init_speculation_control(struct cpuinfo_= x86 *c) =20 void get_cpu_cap(struct cpuinfo_x86 *c) { - const struct leaf_0x80000000_0 *el0 =3D cpuid_leaf(c, 0x80000000); + const struct leaf_0x80000000_0 *el0; u32 eax, ebx, ecx, edx; =20 + cpuid_scan_cpu(c); + /* Intel-defined flags: level 0x00000001 */ if (c->cpuid_level >=3D 0x00000001) { cpuid(0x00000001, &eax, &ebx, &ecx, &edx); @@ -1057,6 +1059,7 @@ void get_cpu_cap(struct cpuinfo_x86 *c) c->x86_capability[CPUID_D_1_EAX] =3D eax; } =20 + el0 =3D cpuid_leaf(c, 0x80000000); c->extended_cpuid_level =3D el0 ? el0->max_ext_leaf : 0; =20 if (c->extended_cpuid_level >=3D 0x80000001) { @@ -1798,7 +1801,7 @@ static void __init early_identify_cpu(struct cpuinfo_= x86 *c) =20 /* cyrix could have cpuid enabled via c_identify()*/ if (cpuid_feature()) { - cpuid_scan_cpu(c); + cpuid_scan_cpu_early(c); cpu_detect(c); get_cpu_vendor(c); intel_unlock_cpuid_leafs(c); @@ -1971,7 +1974,7 @@ static void generic_identify(struct cpuinfo_x86 *c) if (!cpuid_feature()) return; =20 - cpuid_scan_cpu(c); + cpuid_scan_cpu_early(c); cpu_detect(c); get_cpu_vendor(c); intel_unlock_cpuid_leafs(c); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index 2cebe15f75d4..97b7f296df03 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -21,6 +21,10 @@ static void cpuid_clear(const struct cpuid_parse_entry *= e, const struct cpuid_re memset(output->info, 0, sizeof(*output->info)); } =20 +static const struct cpuid_vendor_entry cpuid_vendor_entries[] =3D { + CPUID_VENDOR_ENTRIES +}; + /* * Leaf read functions: */ @@ -57,17 +61,57 @@ cpuid_read_0x80000000(const struct cpuid_parse_entry *e= , const struct cpuid_read } =20 /* - * CPUID parser table: + * CPUID parser tables: + * + * At early boot, only leaves at cpuid_early_entries[] should be parsed. */ =20 -static const struct cpuid_parse_entry cpuid_parse_entries[] =3D { - CPUID_PARSE_ENTRIES +static const struct cpuid_parse_entry cpuid_early_entries[] =3D { + CPUID_EARLY_ENTRIES +}; + +static const struct cpuid_parse_entry cpuid_common_entries[] =3D { + CPUID_COMMON_ENTRIES +}; + +static const struct { + const struct cpuid_parse_entry *table; + int nr_entries; +} cpuid_phases[] =3D { + { cpuid_early_entries, ARRAY_SIZE(cpuid_early_entries) }, + { cpuid_common_entries, ARRAY_SIZE(cpuid_common_entries) }, }; =20 /* * Leaf-independent parser code: */ =20 +static bool cpuid_leaf_matches_vendor(unsigned int leaf, u8 cpu_vendor) +{ + const struct cpuid_parse_entry *p =3D cpuid_early_entries; + const struct cpuid_vendor_entry *v =3D cpuid_vendor_entries; + + /* Leaves in the early boot parser table are vendor agnostic */ + for (int i =3D 0; i < ARRAY_SIZE(cpuid_early_entries); i++, p++) + if (p->leaf =3D=3D leaf) + return true; + + /* Leaves in the vendor table must pass a CPU vendor check */ + for (int i =3D 0; i < ARRAY_SIZE(cpuid_vendor_entries); i++, v++) { + if (v->leaf !=3D leaf) + continue; + + for (unsigned int j =3D 0; j < v->nvendors; j++) + if (cpu_vendor =3D=3D v->vendors[j]) + return true; + + return false; + } + + /* Remaining leaves are vendor agnostic */ + return true; +} + static unsigned int cpuid_range_max_leaf(const struct cpuid_table *t, unsi= gned int range) { const struct leaf_0x0_0 *l0 =3D __cpuid_table_subleaf(t, 0x0, 0); @@ -96,6 +140,9 @@ __cpuid_reset_table(struct cpuid_table *t, const struct = cpuid_parse_entry entrie if (entry->leaf < start || entry->leaf > end) continue; =20 + if (!cpuid_leaf_matches_vendor(entry->leaf, boot_cpu_data.x86_vendor)) + continue; + cpuid_clear(entry, &output); =20 /* @@ -140,28 +187,51 @@ cpuid_fill_table(struct cpuid_table *t, const struct = cpuid_parse_entry entries[] __cpuid_fill_table(t, entries, nr_entries, ranges[i].start, ranges[i].en= d); } =20 -static void __cpuid_scan_cpu_full(struct cpuinfo_x86 *c) +static void __cpuid_scan_cpu_full(struct cpuinfo_x86 *c, bool early_boot) { - unsigned int nr_entries =3D ARRAY_SIZE(cpuid_parse_entries); + int nphases =3D early_boot ? 1 : ARRAY_SIZE(cpuid_phases); struct cpuid_table *table =3D &c->cpuid; =20 - cpuid_fill_table(table, cpuid_parse_entries, nr_entries); + for (int i =3D 0; i < nphases; i++) + cpuid_fill_table(table, cpuid_phases[i].table, cpuid_phases[i].nr_entrie= s); } =20 static void -__cpuid_scan_cpu_partial(struct cpuinfo_x86 *c, unsigned int start_leaf, u= nsigned int end_leaf) +__cpuid_scan_cpu_partial(struct cpuinfo_x86 *c, bool early_boot, unsigned = int start_leaf, unsigned int end_leaf) { - unsigned int nr_entries =3D ARRAY_SIZE(cpuid_parse_entries); + int nphases =3D early_boot ? 1 : ARRAY_SIZE(cpuid_phases); struct cpuid_table *table =3D &c->cpuid; =20 - __cpuid_zero_table(table, cpuid_parse_entries, nr_entries, start_leaf, en= d_leaf); - __cpuid_fill_table(table, cpuid_parse_entries, nr_entries, start_leaf, en= d_leaf); + for (int i =3D 0; i < nphases; i++) { + const struct cpuid_parse_entry *entries =3D cpuid_phases[i].table; + unsigned int nr_entries =3D cpuid_phases[i].nr_entries; + + __cpuid_zero_table(table, entries, nr_entries, start_leaf, end_leaf); + __cpuid_fill_table(table, entries, nr_entries, start_leaf, end_leaf); + } } =20 /* * Call-site APIs: */ =20 +/** + * cpuid_scan_cpu_early() - Populate CPUID table on early boot + * @c: CPU capability structure associated with the current CPU + * + * Populate the CPUID table embedded within @c with parsed CPUID data. + * + * This must be called at early boot, so that early boot code can identify= the + * CPU's x86 vendor. Only CPUID(0x0) and CPUID(0x1) are parsed. + * + * cpuid_scan_cpu() must be called later to complete the CPUID table. Tha= t is, + * after saving the x86 vendor info to the CPU capability structure @c. + */ +void cpuid_scan_cpu_early(struct cpuinfo_x86 *c) +{ + __cpuid_scan_cpu_full(c, true); +} + /** * cpuid_scan_cpu() - Populate current CPU's CPUID table * @c: CPU capability structure associated with the current CPU @@ -169,10 +239,12 @@ __cpuid_scan_cpu_partial(struct cpuinfo_x86 *c, unsig= ned int start_leaf, unsigne * Populate the CPUID table embedded within @c with parsed CPUID data. Al= l CPUID * instructions are invoked locally, so this must be called on the CPU ass= ociated * with @c. + * + * cpuid_scan_cpu_early() must have been called earlier on @c. */ void cpuid_scan_cpu(struct cpuinfo_x86 *c) { - __cpuid_scan_cpu_full(c); + __cpuid_scan_cpu_full(c, false); } =20 /** @@ -180,6 +252,8 @@ void cpuid_scan_cpu(struct cpuinfo_x86 *c) * @c: CPU capability structure associated with the current CPU * @start: Start of leaf range to be re-scanned * @end: End of leaf range + * + * cpuid_scan_cpu_early() must have been called earlier on @c. */ void cpuid_refresh_range(struct cpuinfo_x86 *c, u32 start, u32 end) { @@ -189,13 +263,15 @@ void cpuid_refresh_range(struct cpuinfo_x86 *c, u32 s= tart, u32 end) if (WARN_ON_ONCE(CPUID_RANGE(start) !=3D CPUID_RANGE(end))) return; =20 - __cpuid_scan_cpu_partial(c, start, end); + __cpuid_scan_cpu_partial(c, false, start, end); } =20 /** * cpuid_refresh_leaf() - Rescan a CPUID table's leaf * @c: CPU capability structure associated with the current CPU * @leaf: Leaf to be re-scanned + * + * cpuid_scan_cpu_early() must have been called earlier on @c. */ void cpuid_refresh_leaf(struct cpuinfo_x86 *c, u32 leaf) { diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 3e11e13fa76c..a3f7dcc6c03f 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -2,6 +2,7 @@ #ifndef _ARCH_X86_CPUID_PARSER_H #define _ARCH_X86_CPUID_PARSER_H =20 +#include #include =20 /* @@ -109,16 +110,63 @@ struct cpuid_parse_entry { __CPUID_PARSE_ENTRY(_leaf, __cpuid_leaf_first_subleaf(_leaf), n, _reader_= fn) =20 /* - * CPUID parser table: + * CPUID parser tables: */ =20 -#define CPUID_PARSE_ENTRIES \ +/* + * Early-boot CPUID leaves (to be parsed before x86 vendor detection) + * + * These leaves must be parsed at early boot to identify the x86 vendor. T= he + * parser treats them as universally valid across all vendors. + * + * At early boot, only leaves in this table must be parsed. For all other + * leaves, the CPUID parser will assume that "boot_cpu_data.x86_vendor" is + * properly set beforehand. + * + * Note: If these entries are to be modified, please adapt the kernel-doc = of + * cpuid_scan_cpu_early() accordingly. + */ +#define CPUID_EARLY_ENTRIES \ /* Leaf Subleaf Reader function */ \ CPUID_PARSE_ENTRY ( 0x0, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x1, 0, generic ), \ + +/* + * Common CPUID leaves + * + * These leaves can be parsed once basic x86 vendor detection is in place. + * Further vendor-agnostic leaves, which are not needed at early boot, are= also + * listed here. + * + * For vendor-specific leaves, a matching entry must be added to the CPUID= leaf + * vendor table later defined. Leaves which are here, but without a match= ing + * vendor entry, are treated by the CPUID parser as valid for all x86 vend= ors. + */ +#define CPUID_COMMON_ENTRIES \ + /* Leaf Subleaf Reader function */ \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ =20 +/* + * CPUID leaf vendor table: + */ + +struct cpuid_vendor_entry { + unsigned int leaf; + u8 vendors[X86_VENDOR_NUM]; + u8 nvendors; +}; + +#define CPUID_VENDOR_ENTRY(_leaf, ...) \ + { \ + .leaf =3D _leaf, \ + .vendors =3D { __VA_ARGS__ }, \ + .nvendors =3D (sizeof((u8[]){__VA_ARGS__})/sizeof(u8)), \ + } + +#define CPUID_VENDOR_ENTRIES \ + /* Leaf Vendor list */ \ + #endif /* _ARCH_X86_CPUID_PARSER_H */ diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index cf061ed45ce8..b8444fdf77dc 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -76,7 +76,7 @@ unsigned long xen_released_pages; static __ref void xen_get_vendor(void) { init_cpu_devs(); - cpuid_scan_cpu(&boot_cpu_data); + cpuid_scan_cpu_early(&boot_cpu_data); cpu_detect(&boot_cpu_data); get_cpu_vendor(&boot_cpu_data); } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 800703F39F1 for ; Thu, 28 May 2026 15:40: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=1779982844; cv=none; b=uX7213FEU12ZXb0yh9TdH1oG2ExsEEY0SaTZFFO+jncf3BG5leTxV84hIGZVO1KkOi5yCGTrv3r8am1gIQK26yAMQzzvsJshFkAHaKOUiozV+qzT2+cDmIsF2OKSOS0SykyrLte27hAlBZamJ9Pa1uIwNoSvH1QNoMcVmOaW3eI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982844; c=relaxed/simple; bh=dWTL/d6FiC+fuMPbFMn51DnCb2UiLmEa+mLigFa6Y80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L3Q6CxLTEnYvXdHFpndzH3QQ0Otnj0xSRGB6XvUJD/eT3TRA2Mvt4hm7KbxQsmVuVo9uTW9P0We3ya6TXdEWh0FwEQd0E/DXbPVd3BaKI2HkJKQ+nJyiSun1f2B7RFySDRpLYlfy9xbfHR5W/PwZQnzMfuYqt49i9XdN2UKF9+I= 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=rPzbBOw9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WubyUERk; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rPzbBOw9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WubyUERk" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=58FpnmPZ4RRqupoXM59HDl482hi6e8CrBLHxpS3ngRA=; b=rPzbBOw9sBmjM3umC6lAP/epHlDscCudwqg0K9xp8oqfDlGgf7wh+4sg95WiqQsB9gBbMn YhLebi0LDUwBjX+YI9L1s3F660mQmqkn21BqSPEDBkK4LpZyBisrPQ+0DBsOdcws/MGuYs ro+rNUpjsgOnY+ie0k7edwimYgjMH1cM4M7lkkaMaIiXaWIBipMKI3Lq9iKWIL80TI9uyM WfIkBpu3+4v92rQsaX903NnEuEqsmJU9oMgAsW9RIK2NT13fMd1nhyhA5nrHc6On9021D3 ZQohv2RG0NopjeJzyZI+gBEQ603jpIBEuL5n0Tt/W5sCx8kzWEaiuJaKqJeBoQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982841; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=58FpnmPZ4RRqupoXM59HDl482hi6e8CrBLHxpS3ngRA=; b=WubyUERk+VMyhvTajUNf7pmrA9BhEUD2oF6qFbXHWQ5CZsSc0IBK4dtD7pIgiee+Ab3oSt vd1BU4uc+z0wtGAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 017/120] x86/cpuid: Introduce a parser debugfs interface Date: Thu, 28 May 2026 17:37:39 +0200 Message-ID: <20260528153923.403473-18-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce the debugfs files "x86/cpuid/[0-ncpus]" to dump each CPU's cached CPUID table. For each cached leaf/subleaf, invoke the CPUID instruction on the target CPU and compare the hardware result against its cached values. Mark any mismatched cached CPUID output value with an asterisk. This should help with tricky bug reports in the future if the cached CPUID data get unexpectedly out of sync with actual hardware state. Note, expose cpuid_phases[] via "cpuid_parser.h" to allow the debugfs code to traverse and dump parsed CPUID data. Note, this debugfs interface also simplifies the development and testing of adding new leaves to the CPUID parser. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/cpuid_debugfs.c | 108 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.c | 9 ++- arch/x86/kernel/cpu/cpuid_parser.h | 12 ++++ 4 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 arch/x86/kernel/cpu/cpuid_debugfs.c diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index d2e8a849f180..d62e2d60a965 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -62,7 +62,7 @@ obj-$(CONFIG_HYPERVISOR_GUEST) +=3D vmware.o hypervisor.= o mshyperv.o obj-$(CONFIG_BHYVE_GUEST) +=3D bhyve.o obj-$(CONFIG_ACRN_GUEST) +=3D acrn.o =20 -obj-$(CONFIG_DEBUG_FS) +=3D debugfs.o +obj-$(CONFIG_DEBUG_FS) +=3D debugfs.o cpuid_debugfs.o =20 obj-$(CONFIG_X86_BUS_LOCK_DETECT) +=3D bus_lock.o =20 diff --git a/arch/x86/kernel/cpu/cpuid_debugfs.c b/arch/x86/kernel/cpu/cpui= d_debugfs.c new file mode 100644 index 000000000000..0cafe0afefdd --- /dev/null +++ b/arch/x86/kernel/cpu/cpuid_debugfs.c @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * CPUID parser debugfs entries: x86/cpuid/[0-ncpus] + * + * Dump each CPU's cached CPUID table and compare its values against curre= nt + * CPUID output on that CPU. Mark changed entries with an asterisk. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "cpuid_parser.h" + +static void cpuid_this_cpu(void *info) +{ + struct cpuid_regs *regs =3D info; + + __cpuid(®s->eax, ®s->ebx, ®s->ecx, ®s->edx); +} + +static void +cpuid_show_leaf(struct seq_file *m, uintptr_t cpu_id, const struct cpuid_p= arse_entry *entry, + const struct leaf_parse_info *info, const struct cpuid_regs *cached) +{ + for (int j =3D 0; j < info->nr_entries; j++) { + u32 subleaf =3D entry->subleaf + j; + struct cpuid_regs regs =3D { + .eax =3D entry->leaf, + .ecx =3D subleaf, + }; + int ret; + + seq_printf(m, "Leaf 0x%08x, subleaf %u:\n", entry->leaf, subleaf); + + ret =3D smp_call_function_single(cpu_id, cpuid_this_cpu, ®s, true); + if (ret) { + seq_printf(m, "Failed to invoke CPUID on CPU %lu: %d\n\n", cpu_id, ret); + continue; + } + + seq_printf(m, " cached: %cEAX=3D0x%08x %cEBX=3D0x%08x %cECX=3D0x%= 08x %cEDX=3D0x%08x\n", + cached[j].eax =3D=3D regs.eax ? ' ' : '*', cached[j].eax, + cached[j].ebx =3D=3D regs.ebx ? ' ' : '*', cached[j].ebx, + cached[j].ecx =3D=3D regs.ecx ? ' ' : '*', cached[j].ecx, + cached[j].edx =3D=3D regs.edx ? ' ' : '*', cached[j].edx); + seq_printf(m, " actual: EAX=3D0x%08x EBX=3D0x%08x ECX=3D0x%08x= EDX=3D0x%08x\n", + regs.eax, regs.ebx, regs.ecx, regs.edx); + } +} + +static void __cpuid_debug_show(struct seq_file *m, uintptr_t cpu_id, + const struct cpuid_parse_entry *entry, int nr_entries) +{ + const struct cpuinfo_x86 *c =3D per_cpu_ptr(&cpu_info, cpu_id); + const struct cpuid_table *t =3D &c->cpuid; + + for (int i =3D 0; i < nr_entries; i++, entry++) { + const struct leaf_parse_info *qi =3D cpuid_table_info_p(t, entry->info_o= ffs); + const struct cpuid_regs *qr =3D cpuid_table_regs_p(t, entry->regs_offs); + + cpuid_show_leaf(m, cpu_id, entry, qi, qr); + } +} + +static int cpuid_debug_show(struct seq_file *m, void *p) +{ + uintptr_t cpu_id =3D (uintptr_t)m->private; + + for (int i =3D 0; i < cpuid_nphases; i++) + __cpuid_debug_show(m, cpu_id, cpuid_phases[i].table, cpuid_phases[i].nr_= entries); + + return 0; +} + +static int cpuid_debug_open(struct inode *inode, struct file *file) +{ + return single_open(file, cpuid_debug_show, inode->i_private); +} + +static const struct file_operations cpuid_ops =3D { + .open =3D cpuid_debug_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D single_release, +}; + +static __init int cpuid_init_debugfs(void) +{ + struct dentry *dir; + char cpu_name[24]; + uintptr_t cpu_id; + + dir =3D debugfs_create_dir("cpuid", arch_debugfs_dir); + + for_each_possible_cpu(cpu_id) { + scnprintf(cpu_name, sizeof(cpu_name), "%lu", cpu_id); + debugfs_create_file(cpu_name, 0444, dir, (void *)cpu_id, &cpuid_ops); + } + + return 0; +} +late_initcall(cpuid_init_debugfs); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index 97b7f296df03..ab736f03051e 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -74,14 +74,13 @@ static const struct cpuid_parse_entry cpuid_common_entr= ies[] =3D { CPUID_COMMON_ENTRIES }; =20 -static const struct { - const struct cpuid_parse_entry *table; - int nr_entries; -} cpuid_phases[] =3D { +const struct cpuid_phase cpuid_phases[] =3D { { cpuid_early_entries, ARRAY_SIZE(cpuid_early_entries) }, { cpuid_common_entries, ARRAY_SIZE(cpuid_common_entries) }, }; =20 +const int cpuid_nphases =3D ARRAY_SIZE(cpuid_phases); + /* * Leaf-independent parser code: */ @@ -189,7 +188,7 @@ cpuid_fill_table(struct cpuid_table *t, const struct cp= uid_parse_entry entries[] =20 static void __cpuid_scan_cpu_full(struct cpuinfo_x86 *c, bool early_boot) { - int nphases =3D early_boot ? 1 : ARRAY_SIZE(cpuid_phases); + int nphases =3D early_boot ? 1 : cpuid_nphases; struct cpuid_table *table =3D &c->cpuid; =20 for (int i =3D 0; i < nphases; i++) diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index a3f7dcc6c03f..8b0d44b745c5 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -149,6 +149,18 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ =20 +/* + * CPUID parser phases: + */ + +struct cpuid_phase { + const struct cpuid_parse_entry *table; + int nr_entries; +}; + +extern const struct cpuid_phase cpuid_phases[]; +extern const int cpuid_nphases; + /* * CPUID leaf vendor table: */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C9812400DE4 for ; Thu, 28 May 2026 15:40:45 +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=1779982847; cv=none; b=Q8aPq6aonuVe8pzyWhTM9ifvZID4+Pi57QfvlIDgd+lhM4vbdN1BWycp23lccIXYu/zjxv9lOI6D0GqVU8r0buvVBLAEPDqERFArAEITrbFDnvJ7FLjBPnbDhirzk97EQLDJUq4CdxBAlFO3j7b5uYxSoy2xBN4NyZHALUwd1VM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982847; c=relaxed/simple; bh=bckdrD49L2/AZ2tkSWSTKN7QRStl712WfL/vLsR5dxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUFR1KD0NscXVfSNAYrYrud9sgdHYnwCNPyWAhGVJ/Onjv5BAj9jJtjuJbO9RMJcQ/VVq9OVLIKLb9N082lfJ6kB1rFU0V5g0HmREJleLOWYOsmIxv7axSnE/teE7lUBT2wL7okP50YWcqZaQXBAkQVG1n2FlWNZTSKHakwbSoA= 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=FRONDEpL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RA7jm6D3; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FRONDEpL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RA7jm6D3" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/QukyByt1lrRdMx1M1JtApj2ylPv5Ge00pO+icphAoM=; b=FRONDEpLpDyzHRJHP9S6YHr9GLSZWW8lPsN03T8PbrQD3pbPRC5sgPl8X54MX+4p5tCRvh aUE8zlf4m5ZmyXzKC1lR3WWNpzR9duwuoIC8u80AbRVoVBGvGNWwDSjm4RGPLjRr1fwSR9 KhztaLqHzykxNJhMG+KtyTTWNLqn2+FfJuQ1g0Mp0iAAiV3jX6wkAvl1kEsnTfFNvpBwy6 iL8rFaiR6w/PgaV0uWGVfs8M0kmogiR/g3xnyKdPrOsVgeIMQJtGMopfm5g1p02UAJ6eDr LxKdzhL7yRqy6keX1mOBSfjGvT2CAiyVgbeqbspU2FYatC89uDlWyl+TdHnkTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/QukyByt1lrRdMx1M1JtApj2ylPv5Ge00pO+icphAoM=; b=RA7jm6D3Zjve7ve9ovEPXMheES0P2n03wC5FuuVNhqIMPKvyeJJCScAI/sjOGEmVD9Gcgh kgx5Or4x5u2DKiDg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 018/120] x86/cpuid: Parse CPUID(0x16) Date: Thu, 28 May 2026 17:37:40 +0200 Message-ID: <20260528153923.403473-19-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add CPUID(0x16) support to the CPUID parser. The leaf enumerates the CPU's frequency information and is only supported on Intel machines. This allows converting CPUID(0x16) call sites to the CPUID APIs next. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 1 + arch/x86/kernel/cpu/cpuid_parser.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 8be2c2ba874a..2939ad095f6c 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -206,6 +206,7 @@ struct cpuid_leaves { /* Leaf Subleaf number (or max number of subleaves) */ CPUID_LEAF ( 0x0, 0 ); CPUID_LEAF ( 0x1, 0 ); + CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 8b0d44b745c5..ee1958f3d369 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -144,6 +144,7 @@ struct cpuid_parse_entry { */ #define CPUID_COMMON_ENTRIES \ /* Leaf Subleaf Reader function */ \ + CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ @@ -180,5 +181,6 @@ struct cpuid_vendor_entry { =20 #define CPUID_VENDOR_ENTRIES \ /* Leaf Vendor list */ \ + CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ =20 #endif /* _ARCH_X86_CPUID_PARSER_H */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 D3A7E400E1E for ; Thu, 28 May 2026 15:40:48 +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=1779982850; cv=none; b=gf6LTWWHhCriFYC6ijQH09YeiCO96lZjzAERCf8lvz41yqN5MgIBRABnLfUJve83SPS6JafPT7D8r9KAPfgqydWDQ8MGXKhCuW0JwUGKQ9lJniO8KMYyYIJKlZKjLns3QS3v8DVTQ8npX+42HqOvoHaMD63uhqUJOKdBQeObymI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982850; c=relaxed/simple; bh=m0DY/le5OA+z21u8MoM2o4qd3b0XSKW/pJSo4SWhVYI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eiITp3yyLKMk8FTtlVBW4kcbYRNgsXUqgsVsb9zUY42vT68P8tb2mLCu8qDyUvUNLxnfRMKlDmo8zStVl/tniqvwPwFVbJDLk6Ec0/1RiY08v5aBz9+6CxX3bEU2HuXijWBy+Mzn53Z9qzAHEM7dOhDOGc2F4soo85/gxvQ1Kxc= 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=19QcD0nm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cy1a+sti; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="19QcD0nm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cy1a+sti" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HJHgOflxzKxO02RFGmkZqr9sbCX1DNem7jOTKTHQ2bs=; b=19QcD0nmZtLWg37apEfVdLPc5Oxu6xWEpyj80eINnr8UwZu5j72PLL+zzMeu/w7cbk2rt3 o4H0X5wIIfRDxY2FRpxQfGaRFDNN0Ifx7Odofh7U7gcfMQpuEXAVboHx35m0aa8CYi8B2T CNhJl948cWwgsS6iHgeNVaAvNmdpsX3KB3LgWCjc3rgNjZx1312IsYgPOXOnt3hyq8zHJX 7HqmWDlvoEFNoTMoqHTiV70G9LzFN7/7fGIXvlcPsurF+OE6QsSjEga1RLLgpSzUwpESjU LAFOdQSOgW9/V55ZR3WcyWSKpYWNJByo7pGh4NlrHpWlejEKVsVvl1/ZZAXUhw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HJHgOflxzKxO02RFGmkZqr9sbCX1DNem7jOTKTHQ2bs=; b=cy1a+sti1WisHtbly03ntSi0ujk27nmCfLs4R4Bm8wB7BUQfJvRU/bXJWnk6QmJuhCMfSZ lEFHl3BzZFP0hCBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 019/120] x86/tsc: Use parsed CPUID(0x16) Date: Thu, 28 May 2026 17:37:41 +0200 Message-ID: <20260528153923.403473-20-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At the x86 timestamp counter code, use parsed CPUID(0x16) access instead of a direct CPUID query. Beside the CPUID parser centralization benefits, this allows using the auto-generated data types, and their full C99 bitfields, instead of doing ugly bitwise operations on CPUID output. Remove the "max standard level >=3D CPUID_LEVEL_FREQ" check since the CPUID parser API's NULL check is equivalent. Remove the Intel vendor check since the CPUID parser does a similar check before caching CPUID(0x16) output. Thus the CPUID API's NULL check is also equivalent. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/tsc.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index c5110eb554bc..0043ed398578 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c @@ -664,6 +664,7 @@ static unsigned long quick_pit_calibrate(void) */ unsigned long native_calibrate_tsc(void) { + const struct leaf_0x16_0 *l16 =3D cpuid_leaf(&boot_cpu_data, 0x16); unsigned int eax_denominator, ebx_numerator, ecx_hz, edx; unsigned int crystal_khz; =20 @@ -705,13 +706,8 @@ unsigned long native_calibrate_tsc(void) * clock, but we can easily calculate it to a high degree of accuracy * by considering the crystal ratio and the CPU speed. */ - if (crystal_khz =3D=3D 0 && boot_cpu_data.cpuid_level >=3D CPUID_LEAF_FRE= Q) { - unsigned int eax_base_mhz, ebx, ecx, edx; - - cpuid(CPUID_LEAF_FREQ, &eax_base_mhz, &ebx, &ecx, &edx); - crystal_khz =3D eax_base_mhz * 1000 * - eax_denominator / ebx_numerator; - } + if (crystal_khz =3D=3D 0 && l16) + crystal_khz =3D l16->cpu_base_mhz * 1000 * eax_denominator / ebx_numerat= or; =20 if (crystal_khz =3D=3D 0) return 0; @@ -738,19 +734,9 @@ unsigned long native_calibrate_tsc(void) =20 static unsigned long cpu_khz_from_cpuid(void) { - unsigned int eax_base_mhz, ebx_max_mhz, ecx_bus_mhz, edx; - - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL) - return 0; - - if (boot_cpu_data.cpuid_level < CPUID_LEAF_FREQ) - return 0; - - eax_base_mhz =3D ebx_max_mhz =3D ecx_bus_mhz =3D edx =3D 0; - - cpuid(CPUID_LEAF_FREQ, &eax_base_mhz, &ebx_max_mhz, &ecx_bus_mhz, &edx); + const struct leaf_0x16_0 *l16 =3D cpuid_leaf(&boot_cpu_data, 0x16); =20 - return eax_base_mhz * 1000; + return l16 ? (l16->cpu_base_mhz * 1000) : 0; } =20 /* --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 0B7F540245A for ; Thu, 28 May 2026 15:40:51 +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=1779982853; cv=none; b=TsWfN0kYTH6quE8eXcZ/l+cGgFB5GPBg+dT+9LkUEvFLL1gsJhzj4vy2ke+vyoEr68um7BIV4RAcK16CAG7r0KDk4uvwjOW7G2o+An/7grmWKS7YkhNg72A1qMy3Av3TacnN8M0+l+J1Z55mHKehHe9M6/UGmzj0BRAIvhbwstM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982853; c=relaxed/simple; bh=ydHPv7fmHv1JzEW1FzW4Y61d/BGZPKPLyjXn7yZ7gTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZTxH+uP+GlyfcSaR0DX1yVDqAldPfeCiNXve1ifATY1rd054yuyLvty1gi/3pU/MLitFDEhkpMrkl+o7a3xLLSZzyrtXcJrW7gKcaMACr6rJKnHRxXi3hCP8rBIy0Jj+jnoqdmUqyZ1FA094hX7QqwntIP1nCjicGmQOXc7GD5o= 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=Owcnq1yI; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k7S5/ZY6; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Owcnq1yI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k7S5/ZY6" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3whWOY414cV6/V1ssDuQm1WPHOhn7VoY/VIHM54nKs=; b=Owcnq1yIUf7Bto/myYAgcsWAMTve28bLzN4nKI6su3csj8yC7B4vuPY1/UxlqYkQh84m8n Za+kU6rQECX5zm7H6EvucJrhEcpaOm2CjwQJzhsDMdVZ6csrRBRpYfBQr1JG+Z13pwCh97 RMNWuYyvnv4q1/Gz7rHLJPJGHu8Vdu88kXQ4kiVV7+/Eys7dPdFx9tidbVBEcZztyl2PlM 7oU85Q5g5eENX0SFPl9w0jS4RlT1xHZIDI4d2k/2B6yEwrS2ly7xnq+hFhdIGeiuqXZqkZ jz+kGLT4fmjOw6z3jvVjBcbi02L7ZoBFE9lJmUaKX1tfSYdar+waB1njqfmZkA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H3whWOY414cV6/V1ssDuQm1WPHOhn7VoY/VIHM54nKs=; b=k7S5/ZY6wXPuv3QYQ3vPsDk9sCPt18T7+MORB/J99V4Pll8KDR9AQjTPdHhHWRPanmfKLM cleSiPLeyPmZQ/Cw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 020/120] x86/cpuid: Parse Transmeta and Centaur extended ranges Date: Thu, 28 May 2026 17:37:42 +0200 Message-ID: <20260528153923.403473-21-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse the Transmeta extended CPUID(0x80860000)->CPUID(0x80860006) range. Reuse the CPUID(0x80000000) read function and its safety guards against CPUs repeating the output of the highest standard CPUID leaf. Transmeta's code at early_init_transmeta() already carries a similar guard. Parse Centaur/Zhaoxin extended CPUID(0xc0000000) and CPUID(0xc0000001). Add x86 vendor tags for the Transmeta and Centaur/Zhaoxin CPUID leaves so that they are not parsed on other vendors. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 13 ++++++++ arch/x86/kernel/cpu/cpuid_parser.c | 48 +++++++++++++++++++----------- arch/x86/kernel/cpu/cpuid_parser.h | 18 +++++++++++ 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 2939ad095f6c..8cc9f81e9526 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -37,9 +37,13 @@ enum cpuid_regs_idx { =20 #define CPUID_BASE_START 0x00000000 #define CPUID_EXT_START 0x80000000 +#define CPUID_TMX_START 0x80860000 +#define CPUID_CTR_START 0xc0000000 =20 #define CPUID_BASE_END CPUID_RANGE_MAX(CPUID_BASE_START) #define CPUID_EXT_END CPUID_RANGE_MAX(CPUID_EXT_START) +#define CPUID_TMX_END CPUID_RANGE_MAX(CPUID_TMX_START) +#define CPUID_CTR_END CPUID_RANGE_MAX(CPUID_CTR_START) =20 /* * Types for CPUID(0x2) parsing: @@ -211,6 +215,15 @@ struct cpuid_leaves { CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); CPUID_LEAF ( 0x80000004, 0 ); + CPUID_LEAF ( 0x80860000, 0 ); + CPUID_LEAF ( 0x80860001, 0 ); + CPUID_LEAF ( 0x80860002, 0 ); + CPUID_LEAF ( 0x80860003, 0 ); + CPUID_LEAF ( 0x80860004, 0 ); + CPUID_LEAF ( 0x80860005, 0 ); + CPUID_LEAF ( 0x80860006, 0 ); + CPUID_LEAF ( 0xc0000000, 0 ); + CPUID_LEAF ( 0xc0000001, 0 ); }; =20 /* diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index ab736f03051e..a7e6692f767b 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -42,24 +42,30 @@ cpuid_read_generic(const struct cpuid_parse_entry *e, c= onst struct cpuid_read_ou cpuid_read_subleaf(e->leaf, e->subleaf + i, regs); } =20 -static void -cpuid_read_0x80000000(const struct cpuid_parse_entry *e, const struct cpui= d_read_output *output) -{ - struct leaf_0x80000000_0 *el0 =3D (struct leaf_0x80000000_0 *)output->reg= s; - - cpuid_read_subleaf(e->leaf, e->subleaf, el0); - - /* - * Protect against Intel 32-bit CPUs lacking an extended CPUID range. A - * CPUID(0x80000000) query on such machines will repeat the output of the - * highest standard CPUID leaf instead. - */ - if (CPUID_RANGE(el0->max_ext_leaf) !=3D CPUID_EXT_START) - return; - - output->info->nr_entries =3D 1; +/* + * Define an extended range CPUID read function + * + * Guard against CPUs lacking the passed range leaf; e.g. Intel 32-bit CPU= s lacking + * CPUID(0x80000000). A query on such machines will just repeat the outpu= t of the + * highest standard CPUID leaf. + */ +#define define_cpuid_range_read_function(_range, _name) \ +static void \ +cpuid_read_##_range(const struct cpuid_parse_entry *e, const struct cpuid_= read_output *output) \ +{ \ + struct leaf_##_range##_0 *l =3D (struct leaf_##_range##_0 *)output->regs;= \ + \ + cpuid_read_subleaf(e->leaf, e->subleaf, l); \ + if (CPUID_RANGE(l->max_##_name##_leaf) !=3D _range) \ + return; \ + \ + output->info->nr_entries =3D 1; \ } =20 +define_cpuid_range_read_function(0x80000000, ext); +define_cpuid_range_read_function(0x80860000, tra); +define_cpuid_range_read_function(0xc0000000, cntr); + /* * CPUID parser tables: * @@ -115,10 +121,14 @@ static unsigned int cpuid_range_max_leaf(const struct= cpuid_table *t, unsigned i { const struct leaf_0x0_0 *l0 =3D __cpuid_table_subleaf(t, 0x0, 0); const struct leaf_0x80000000_0 *el0 =3D __cpuid_table_subleaf(t, 0x800000= 00, 0); + const struct leaf_0x80860000_0 *tl0 =3D __cpuid_table_subleaf(t, 0x808600= 00, 0); + const struct leaf_0xc0000000_0 *cl0 =3D __cpuid_table_subleaf(t, 0xc00000= 00, 0); =20 switch (range) { - case CPUID_BASE_START: return l0 ? l0->max_std_leaf : 0; - case CPUID_EXT_START: return el0 ? el0->max_ext_leaf : 0; + case CPUID_BASE_START: return l0 ? l0->max_std_leaf : 0; + case CPUID_EXT_START: return el0 ? el0->max_ext_leaf : 0; + case CPUID_TMX_START: return tl0 ? tl0->max_tra_leaf : 0; + case CPUID_CTR_START: return cl0 ? cl0->max_cntr_leaf : 0; default: return 0; } } @@ -180,6 +190,8 @@ cpuid_fill_table(struct cpuid_table *t, const struct cp= uid_parse_entry entries[] } ranges[] =3D { { CPUID_BASE_START, CPUID_BASE_END }, { CPUID_EXT_START, CPUID_EXT_END }, + { CPUID_TMX_START, CPUID_TMX_END }, + { CPUID_CTR_START, CPUID_CTR_END }, }; =20 for (unsigned int i =3D 0; i < ARRAY_SIZE(ranges); i++) diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index ee1958f3d369..76a87a71b430 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -149,6 +149,15 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80860000, 0, 0x80860000 ), \ + CPUID_PARSE_ENTRY ( 0x80860001, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80860002, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80860003, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80860004, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80860005, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80860006, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0xc0000000, 0, 0xc0000000 ), \ + CPUID_PARSE_ENTRY ( 0xc0000001, 0, generic ), \ =20 /* * CPUID parser phases: @@ -182,5 +191,14 @@ struct cpuid_vendor_entry { #define CPUID_VENDOR_ENTRIES \ /* Leaf Vendor list */ \ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ + CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0x80860001, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0x80860002, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0x80860003, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0x80860004, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0x80860005, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0x80860006, X86_VENDOR_TRANSMETA), \ + CPUID_VENDOR_ENTRY(0xc0000000, X86_VENDOR_CENTAUR, X86_VENDOR_ZHAOXIN), \ + CPUID_VENDOR_ENTRY(0xc0000001, X86_VENDOR_CENTAUR, X86_VENDOR_ZHAOXIN), \ =20 #endif /* _ARCH_X86_CPUID_PARSER_H */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 DA5A53F8EAF for ; Thu, 28 May 2026 15:40:55 +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=1779982857; cv=none; b=N708tRGbEfmafGwdI+b3JuyGQNIJW/rpOJuZY/5y2o2sbBrpfkOuja8GNCR/i3TmuRSbfZsYT8r99bTRwNLD9mlrlh2bMnZjMwABpgOKZ7VZ5TVZ9Ggu3S1Xh/se/lAt87GrLmKEmPJ/KnxSmARnGTm9p/QP0fTeil1WX0wlgcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982857; c=relaxed/simple; bh=5DOLcoETmE70C7vuVqf3+MQ9fzuAsNFwjsKwjfTIayU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5565YncqRGcx6bCwllLA332d1gPq4+1Vem03n93mAloUdPB52VldwMN+I/imA/1sBJ0vAvZYfwOdlAbuifJOJbH4X95kjDINh4SL8vzYl7xBTsPklZARBmeaAsfwQ+F57mo8BHJ9dkJX1TmFCIoSyaSXs7zXAwPU3zHG0f8NLs= 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=tPTX5rWW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hIf6tDrx; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tPTX5rWW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hIf6tDrx" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d0Q95badfD6sRWtaLkalhs67E09vO6zjI9swf0uVxps=; b=tPTX5rWW2Ym1+l9mimumUXXo0BLbW6qurikvH6qtWGuPhaBawxjryezzbPtFlnopp2uKnf PLSXW4/mkRznb3BT20B5LDtpgEyvfF8hQO6s+B1pxPdgNDZFAAgVi0Sx2uecfpvSNc0RtI QsmfNlZPkz3fqUcdhwpTIoC2BfT6hTsDpP98SwGivMgIPPB42pfOEUOfjLmt4Aw5PBdgBb x97CNZIOyTvgBpQSbHXs6NutVmnbxQn3HwXKA3cWbdi+Zh5xGmUW1tiym+5eWrd9En2li4 KZeMKq2186HX6UjA/3r1ATeBdAvjr0B74gowA8eDLowHy+dEhJu4NUw7/MTiSw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982853; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d0Q95badfD6sRWtaLkalhs67E09vO6zjI9swf0uVxps=; b=hIf6tDrxK3TB4BKSD5OxrzVtJvectOnYpWOrzgEyL+GNBIjXAPXqrUIKUSmkrID6zxjSp0 vkmOS222zHxIkhAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 021/120] x86/cpu/transmeta: Use parsed CPUID(0x80860000)->CPUID(0x80860006) Date: Thu, 28 May 2026 17:37:43 +0200 Message-ID: <20260528153923.403473-22-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x80860000) to CPUID(0x80860006). Beside the CPUID parser centralization benefits, this allows using the auto-generated x86-cpuid-db data types, and their full C99 bitfields, instead of doing ugly bitwise operations on the CPUID output. Keep the x86_capability[] CPUID(0x80860001).EDX assignment. It will be removed when X86_FEATURE translation is integrated into the CPUID table. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/transmeta.c | 102 ++++++++++++++------------------ 1 file changed, 44 insertions(+), 58 deletions(-) diff --git a/arch/x86/kernel/cpu/transmeta.c b/arch/x86/kernel/cpu/transmet= a.c index d9e0edb379b8..4b77dc1a7d9e 100644 --- a/arch/x86/kernel/cpu/transmeta.c +++ b/arch/x86/kernel/cpu/transmeta.c @@ -12,77 +12,63 @@ =20 static void early_init_transmeta(struct cpuinfo_x86 *c) { - u32 xlvl; + const struct leaf_0x80860000_0 *l =3D cpuid_leaf(c, 0x80860000); =20 - /* Transmeta-defined flags: level 0x80860001 */ - xlvl =3D cpuid_eax(0x80860000); - if ((xlvl & 0xffff0000) =3D=3D 0x80860000) { - if (xlvl >=3D 0x80860001) - c->x86_capability[CPUID_8086_0001_EDX] =3D cpuid_edx(0x80860001); - } + if (l && l->max_tra_leaf >=3D 0x80860001) + c->x86_capability[CPUID_8086_0001_EDX] =3D cpuid_edx(0x80860001); +} + +/* + * If CPU revision is 0x02000000, then CPUID(0x80860002) should be used in= stead. + */ +static bool is_legacy_revision(const struct leaf_0x80860001_0 *l1) +{ + return !(l1->cpu_rev_major =3D=3D 2 && l1->cpu_rev_minor =3D=3D 0 && + l1->cpu_rev_mask_major =3D=3D 0 && l1->cpu_rev_mask_minor =3D=3D 0); } =20 static void init_transmeta(struct cpuinfo_x86 *c) { - unsigned int cap_mask, uk, max, dummy; - unsigned int cms_rev1, cms_rev2; - unsigned int cpu_rev, cpu_freq =3D 0, cpu_flags, new_cpu_rev; - char cpu_info[65]; + const struct leaf_0x80860001_0 *l1 =3D cpuid_leaf(c, 0x80860001); + const struct leaf_0x80860002_0 *l2 =3D cpuid_leaf(c, 0x80860002); + const struct leaf_0x80860003_0 *l3 =3D cpuid_leaf(c, 0x80860003); + const struct leaf_0x80860004_0 *l4 =3D cpuid_leaf(c, 0x80860004); + const struct leaf_0x80860005_0 *l5 =3D cpuid_leaf(c, 0x80860005); + const struct leaf_0x80860006_0 *l6 =3D cpuid_leaf(c, 0x80860006); + unsigned int cap_mask, uk; =20 early_init_transmeta(c); =20 cpu_detect_cache_sizes(c); =20 - /* Print CMS and CPU revision */ - max =3D cpuid_eax(0x80860000); - cpu_rev =3D 0; - if (max >=3D 0x80860001) { - cpuid(0x80860001, &dummy, &cpu_rev, &cpu_freq, &cpu_flags); - if (cpu_rev !=3D 0x02000000) { - pr_info("CPU: Processor revision %u.%u.%u.%u, %u MHz\n", - (cpu_rev >> 24) & 0xff, - (cpu_rev >> 16) & 0xff, - (cpu_rev >> 8) & 0xff, - cpu_rev & 0xff, - cpu_freq); - } + if (l1 && is_legacy_revision(l1)) { + pr_info("CPU: Processor revision %u.%u.%u.%u, %u MHz\n", + l1->cpu_rev_major, l1->cpu_rev_minor, + l1->cpu_rev_mask_major, l1->cpu_rev_mask_minor, + l1->cpu_base_mhz); } - if (max >=3D 0x80860002) { - cpuid(0x80860002, &new_cpu_rev, &cms_rev1, &cms_rev2, &dummy); - if (cpu_rev =3D=3D 0x02000000) { - pr_info("CPU: Processor revision %08X, %u MHz\n", - new_cpu_rev, cpu_freq); - } + + if (l1 && l2 && !is_legacy_revision(l1)) { + pr_info("CPU: Processor revision %08X, %u MHz\n", + l2->cpu_rev_id, l1->cpu_base_mhz); + } + + if (l2) { pr_info("CPU: Code Morphing Software revision %u.%u.%u-%u-%u\n", - (cms_rev1 >> 24) & 0xff, - (cms_rev1 >> 16) & 0xff, - (cms_rev1 >> 8) & 0xff, - cms_rev1 & 0xff, - cms_rev2); + l2->cms_rev_major, l2->cms_rev_minor, + l2->cms_rev_mask_1, l2->cms_rev_mask_2, + l2->cms_rev_mask_3); } - if (max >=3D 0x80860006) { - cpuid(0x80860003, - (void *)&cpu_info[0], - (void *)&cpu_info[4], - (void *)&cpu_info[8], - (void *)&cpu_info[12]); - cpuid(0x80860004, - (void *)&cpu_info[16], - (void *)&cpu_info[20], - (void *)&cpu_info[24], - (void *)&cpu_info[28]); - cpuid(0x80860005, - (void *)&cpu_info[32], - (void *)&cpu_info[36], - (void *)&cpu_info[40], - (void *)&cpu_info[44]); - cpuid(0x80860006, - (void *)&cpu_info[48], - (void *)&cpu_info[52], - (void *)&cpu_info[56], - (void *)&cpu_info[60]); - cpu_info[64] =3D '\0'; - pr_info("CPU: %s\n", cpu_info); + + if (l3 && l4 && l5 && l6) { + u32 info[] =3D { + l3->cpu_info_0, l3->cpu_info_1, l3->cpu_info_2, l3->cpu_info_3, + l4->cpu_info_4, l4->cpu_info_5, l4->cpu_info_6, l4->cpu_info_7, + l5->cpu_info_8, l5->cpu_info_9, l5->cpu_info_10, l5->cpu_info_11, + l6->cpu_info_12, l6->cpu_info_13, l6->cpu_info_14, l6->cpu_info_15, + 0 /* Null terminator */, + }; + pr_info("CPU: %s\n", (char *)info); } =20 /* Unhide possibly hidden capability flags */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 311BD4028FB for ; Thu, 28 May 2026 15:40:58 +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=1779982860; cv=none; b=W5wUrdo3CeFYpTFT2e+3Hp7qktboXSjJh2gvi+5XWnN24v/6GxNj2YIoz6BZJguo2ijfu4FRXR1ktIrDQ3pM/zedUllU6aBwm4zFT9cA1aC3B3ta/AG6U3/T0PEF9DF3ohkIi3cFBCw+wakP/B/4pLFYxKxY8JX6l0iFYGbkObg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982860; c=relaxed/simple; bh=6nYGK6cTkFvIvqLpGyHcil1tmHLs1GZfE2XIBAE079M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PQUgIjl1CfPi+kVOUQWGSFFqe5+jOTJ3s0YLp1za178CGA7mkPkyG9/6y8QOWWxO83nQKCCEiwPS+FXDVu9wb1eJfzEEV17m6DLIy2zP71U8hkJwdQ3VBZLHuao+lu8wuwWD9+hJRXv9zfONzjTrjA7MjBdQto8e2+lyLKsPa8g= 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=xRyrhV2Z; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=egeQ0H3x; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xRyrhV2Z"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="egeQ0H3x" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=puHuIwGOVqYUhkXtksvKr6uZsnRiiikagIfNnV38R68=; b=xRyrhV2ZfTwp6KYFRO+tpdvf+9ENriZT8VJXe52JgJ0aXRvk5peEiDdnx6CstItSyjQZ0a OwKwLFndL/kv/jgvgAVMTOkEaZUC6QuISGtUrqAGZrW4JLCzU5vN+V7Q36ceAkgHJNep1q no8f+9cmNPIT3VRTMu41QJNio802DRVTN6mj2iVpfJqAaaf1uZCaGj/LQD0h6/qU+KgNmS Lm48vhTRDCvmFNjX0n29H6TF7zmB1ZndqqnbNe3H7492/qLJ/d/H7ksa5HHZOO9Aj8CBIB MdjFHYBTpzBtPsIXvLMD/Sb/y72clFBpx0Xk6OMmz+kc1iOZs7dU5B4VfITxJg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=puHuIwGOVqYUhkXtksvKr6uZsnRiiikagIfNnV38R68=; b=egeQ0H3xAnTVa5WHo6HkZ1I6EjYy7CCAjq+gQSrlm1BaAd6NJs4WrDsx8osBuSadlwQWCj gYQhMOPL+CY9TmBg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 022/120] x86/cpu/transmeta: Refactor CPU information printing Date: Thu, 28 May 2026 17:37:44 +0200 Message-ID: <20260528153923.403473-23-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the Transmeta init code has been converted to the CPUID API, refactor it into two separate functions for readability. No functional change. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/transmeta.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/transmeta.c b/arch/x86/kernel/cpu/transmet= a.c index 4b77dc1a7d9e..991e11d5c28a 100644 --- a/arch/x86/kernel/cpu/transmeta.c +++ b/arch/x86/kernel/cpu/transmeta.c @@ -27,19 +27,10 @@ static bool is_legacy_revision(const struct leaf_0x8086= 0001_0 *l1) l1->cpu_rev_mask_major =3D=3D 0 && l1->cpu_rev_mask_minor =3D=3D 0); } =20 -static void init_transmeta(struct cpuinfo_x86 *c) +static void print_cpu_revision(struct cpuinfo_x86 *c) { const struct leaf_0x80860001_0 *l1 =3D cpuid_leaf(c, 0x80860001); const struct leaf_0x80860002_0 *l2 =3D cpuid_leaf(c, 0x80860002); - const struct leaf_0x80860003_0 *l3 =3D cpuid_leaf(c, 0x80860003); - const struct leaf_0x80860004_0 *l4 =3D cpuid_leaf(c, 0x80860004); - const struct leaf_0x80860005_0 *l5 =3D cpuid_leaf(c, 0x80860005); - const struct leaf_0x80860006_0 *l6 =3D cpuid_leaf(c, 0x80860006); - unsigned int cap_mask, uk; - - early_init_transmeta(c); - - cpu_detect_cache_sizes(c); =20 if (l1 && is_legacy_revision(l1)) { pr_info("CPU: Processor revision %u.%u.%u.%u, %u MHz\n", @@ -59,6 +50,14 @@ static void init_transmeta(struct cpuinfo_x86 *c) l2->cms_rev_mask_1, l2->cms_rev_mask_2, l2->cms_rev_mask_3); } +} + +static void print_cpu_info_string(struct cpuinfo_x86 *c) +{ + const struct leaf_0x80860003_0 *l3 =3D cpuid_leaf(c, 0x80860003); + const struct leaf_0x80860004_0 *l4 =3D cpuid_leaf(c, 0x80860004); + const struct leaf_0x80860005_0 *l5 =3D cpuid_leaf(c, 0x80860005); + const struct leaf_0x80860006_0 *l6 =3D cpuid_leaf(c, 0x80860006); =20 if (l3 && l4 && l5 && l6) { u32 info[] =3D { @@ -70,6 +69,17 @@ static void init_transmeta(struct cpuinfo_x86 *c) }; pr_info("CPU: %s\n", (char *)info); } +} + +static void init_transmeta(struct cpuinfo_x86 *c) +{ + unsigned int cap_mask, uk; + + early_init_transmeta(c); + cpu_detect_cache_sizes(c); + + print_cpu_revision(c); + print_cpu_info_string(c); =20 /* Unhide possibly hidden capability flags */ rdmsr(0x80860004, cap_mask, uk); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 36032403144 for ; Thu, 28 May 2026 15:41:02 +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=1779982863; cv=none; b=nc7ybkpe/B2bRahMGYtDLXupeMigmlNGgjTpYr5nEJZZEepvHVpTJwkpJujJVSeTix/OvpVS7lJqLt7TDv2Xs3J2UiJZng0Awdvd9/N26h7oTnd/kyC2pdv/gK6dnab2iLwBGuK03O734MnoHABDtkH3dyzRUaE8MCepcdusliY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982863; c=relaxed/simple; bh=2MYmYEoTe4gDRhW+YTtVBmmOU/3wWbo/afTJgYsDN6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d1VDURh6R212V8coC1JiRPHstVGVMbOBBKQnuZG2F7MYUDHsyEFLXoDLbHDctOy/4V74SMtL4fTBY26WEmcWVnbq1DXqscbsAppZImyi7HdxxcQBht/Q5LoMIYxQf7SngshrdM8aMZWwi6D2+OXRCYvbIRY4DLnIjwyvjX9BM28= 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=JJsJv6pw; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iI7xIylX; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JJsJv6pw"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iI7xIylX" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+03p+dvS4on0GGtOvXY/3IirK9+SFchKNpf1GDWcpfc=; b=JJsJv6pw01vTtkBHRptnQlB8s8555WZeKU4jyCri8IGwBqyfViJd5lUfkj70jw4PLXbtNs yCanOepTBHKRvZyzBU6rf5TLoqDhzj7LSaFB+pklg18caloOhWLrMDXFjun1sK1lLBXbCt OVrXQYlhx3qLVZkqhaxki9YZ6zXn6wERz/+sQeL3odBCCOWkraKVx5j48wJQCz3pVJxQMf c1uCRd0Bp5bBTTSPXBDEecytORrLhxnTLk//g39gKgaSx/2L+GTy1VBJMglGAPgWcQTtQk z7bq4vy1HgmsuCONvZgnlEqPT0y5AFvz4iwir8zgGFHZsyKJXCRk13PtInfqyA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+03p+dvS4on0GGtOvXY/3IirK9+SFchKNpf1GDWcpfc=; b=iI7xIylX2IXqI3gjZegtjFXxzJfyzwWyo9NIT2sxeUTMVPFZWSwidflTSiprg+5MG731RM LPTtHera3kIdDjCg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 023/120] x86/cpu/centaur: Use parsed CPUID(0xc0000001) Date: Thu, 28 May 2026 17:37:45 +0200 Message-ID: <20260528153923.403473-24-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0xc0000001). Beside the CPUID parser centralization benefits, this allows using the auto-generated x86-cpuid-db data types, and their full C99 bitfields, instead of doing ugly bitwise operations on the CPUID output. Keep the x86_capability[] CPUID(0xc0000001).EDX assignment. It will be removed once X86_FEATURE translation is integrated into the CPUID model. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/centaur.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index a97e38fa6a9f..5f09bce3aaa7 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -12,34 +12,27 @@ =20 #include "cpu.h" =20 -#define ACE_PRESENT (1 << 6) -#define ACE_ENABLED (1 << 7) #define ACE_FCR (1 << 28) /* MSR_VIA_FCR */ - -#define RNG_PRESENT (1 << 2) -#define RNG_ENABLED (1 << 3) #define RNG_ENABLE (1 << 6) /* MSR_VIA_RNG */ =20 static void init_c3(struct cpuinfo_x86 *c) { - u32 lo, hi; - - /* Test for Centaur Extended Feature Flags presence */ - if (cpuid_eax(0xC0000000) >=3D 0xC0000001) { - u32 tmp =3D cpuid_edx(0xC0000001); + const struct leaf_0xc0000001_0 *l1 =3D cpuid_leaf(c, 0xc0000001); + u32 lo, hi; =20 - /* enable ACE unit, if present and disabled */ - if ((tmp & (ACE_PRESENT | ACE_ENABLED)) =3D=3D ACE_PRESENT) { + if (l1) { + /* Enable ACE unit, if present and disabled */ + if (l1->ace && !l1->ace_en) { rdmsr(MSR_VIA_FCR, lo, hi); - lo |=3D ACE_FCR; /* enable ACE unit */ + lo |=3D ACE_FCR; wrmsr(MSR_VIA_FCR, lo, hi); pr_info("CPU: Enabled ACE h/w crypto\n"); } =20 - /* enable RNG unit, if present and disabled */ - if ((tmp & (RNG_PRESENT | RNG_ENABLED)) =3D=3D RNG_PRESENT) { + /* Enable RNG unit, if present and disabled */ + if (l1->rng && !l1->rng_en) { rdmsr(MSR_VIA_RNG, lo, hi); - lo |=3D RNG_ENABLE; /* enable RNG unit */ + lo |=3D RNG_ENABLE; wrmsr(MSR_VIA_RNG, lo, hi); pr_info("CPU: Enabled h/w RNG\n"); } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 49CEF405C5F for ; Thu, 28 May 2026 15:41:05 +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=1779982866; cv=none; b=GQXJReEbgDsz39DaWHr9I4T/QKBD69Xqr7vQUaN/FkxkiC+kIUxEuV/hSaSsV8nsPlpUxk7kHI8B4CoEAul9YEDQ1owTxb5VN8ygA9hb+dRz/0PjMlx3fvcDhELenO2RsKhIzEJqCi8UFH5DMJL6Ip++aTXT38ku4h5Q7skY6aE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982866; c=relaxed/simple; bh=K8l+CMt1nhsrtKmoUFIE9d1CJpJ/ZoJUHTFsX4Iuclc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FHAcsnuHGDslHJYn7I8ObwZcrMIPNVHOWluUQBXeuWdIsIeErG14rJyQNdnCXojtSCzFTut+vWNf6btAQS96981RZVbYc39MRrNXnPuc1qlC+80/zPcSXPMRoUwdmYXIX2C9fciJKacJU4HQZKfSkaL0wNx0cTKXhMFrWjmVooU= 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=U60MAgr9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MsL7VmDf; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="U60MAgr9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MsL7VmDf" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a6l2gTcdCR+q7YNOUBkwn1Odim7pWnPFKOhf0ZGlErA=; b=U60MAgr9rpv+85Qym3p1r4F6YBl0jWZKOQgiyqEfagmtG0x7HbGJHJskVeMEf/qLJEu5Dk IKEsA3yp6m1jeeM00rlwe55MV3uearqphVVk8+vrCqU3U2Zyey64xwjfHNvp5ZU2lI2dlO 2+eMhu7c8Z8TClTLoUFhYdjsmx+cbQDGm6N34wxPw2zarJfue7jEhKrQJJGOUh0QVPdHj5 UYiMs9D4/kSIkSXcZIjYzf1DQEczPMKqEvfP3+Gn31oFD8APQ3O1vYYjVdlDV6MPSNdjMD sLjWlrZ4m8kNsh0cukQTs9RU6TdRzsRoTyRRD7wqVq9UKuVKDXejyRshA4Kvlw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a6l2gTcdCR+q7YNOUBkwn1Odim7pWnPFKOhf0ZGlErA=; b=MsL7VmDfP1O9JsIUqI6vRga7lwODsrr6NuqhqEXCb9lWpKRAaO+0yeoyJ+typT7x5ZouSf 0uqhfnEG25TE7gBg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 024/120] x86/cpu/zhaoxin: Use parsed CPUID(0xc0000001) Date: Thu, 28 May 2026 17:37:46 +0200 Message-ID: <20260528153923.403473-25-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0xc0000001). Beside the CPUID parser centralization benefits, this allows using the auto-generated x86-cpuid-db data types, and their full C99 bitfields, instead of doing ugly bitwise operations on the CPUID output. Keep the x86_capability[] CPUID(0xc0000001).EDX assignment. It will be removed once X86_FEATURE translation is integrated into the CPUID model. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/zhaoxin.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index 55bc656aaa95..ea76e9594453 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -11,35 +11,26 @@ =20 #define MSR_ZHAOXIN_FCR57 0x00001257 =20 -#define ACE_PRESENT (1 << 6) -#define ACE_ENABLED (1 << 7) #define ACE_FCR (1 << 7) /* MSR_ZHAOXIN_FCR */ - -#define RNG_PRESENT (1 << 2) -#define RNG_ENABLED (1 << 3) #define RNG_ENABLE (1 << 8) /* MSR_ZHAOXIN_RNG */ =20 static void init_zhaoxin_cap(struct cpuinfo_x86 *c) { - u32 lo, hi; - - /* Test for Extended Feature Flags presence */ - if (cpuid_eax(0xC0000000) >=3D 0xC0000001) { - u32 tmp =3D cpuid_edx(0xC0000001); + const struct leaf_0xc0000001_0 *l1 =3D cpuid_leaf(c, 0xc0000001); + u32 lo, hi; =20 + if (l1) { /* Enable ACE unit, if present and disabled */ - if ((tmp & (ACE_PRESENT | ACE_ENABLED)) =3D=3D ACE_PRESENT) { + if (l1->ace && !l1->ace_en) { rdmsr(MSR_ZHAOXIN_FCR57, lo, hi); - /* Enable ACE unit */ lo |=3D ACE_FCR; wrmsr(MSR_ZHAOXIN_FCR57, lo, hi); pr_info("CPU: Enabled ACE h/w crypto\n"); } =20 /* Enable RNG unit, if present and disabled */ - if ((tmp & (RNG_PRESENT | RNG_ENABLED)) =3D=3D RNG_PRESENT) { + if (l1->rng && !l1->rng_en) { rdmsr(MSR_ZHAOXIN_FCR57, lo, hi); - /* Enable RNG unit */ lo |=3D RNG_ENABLE; wrmsr(MSR_ZHAOXIN_FCR57, lo, hi); pr_info("CPU: Enabled h/w RNG\n"); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6663740800D for ; Thu, 28 May 2026 15:41:08 +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=1779982869; cv=none; b=sTKE4wFEK9yTWoQBCHWSzQnuiLJTpE5VQ9YKE0UFSSglSKlL7r7U2KXB8b0Sl8H2rT6trWbjIGr+I/lBeO3EGPVokRtrhr3fpbWauqlQ72PaWKn/lByFgxukQfJXA6J5DoPoVZx1itIiU8SVhOQqexJa2oKy8UqtPfBTPVHfkxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982869; c=relaxed/simple; bh=tBeu2Ko24X82EtlnhU6jCsXdM8G44EzwA24PXzun26I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SJux4ovuFMk/Or7C00FCOqeE/0/z21aeT3KvH3y0KQOd3Sl4jpPbPFsHsVQRqH1Kj6aKF5quHOhYqxmRbG9HARw5DFh47QId9cePY+S2izOa4Ogfb9+tPdlmnY5nAZTwBr6iTvjHdQ35NktIkvvUzEoqci85X5Y7X3XxPfrfMEI= 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=bqwUo18m; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=KbdcERy7; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bqwUo18m"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="KbdcERy7" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wi4VM8vMO7tNjuxY9IdYcZ9dRCqO598/xFz1Lsgn8Tc=; b=bqwUo18mYfOVH+91cUiFMgT1gWYD1CREGc0vDHcHUExULQKwqowK909xkX/G1lg24SQyU0 qCncfBnaBbDz7f6FwWFtnVOfFSrwW9hQHusxSChZzOe6DZ+7yXbYq3N9hYcv1XcNFTIMUb R6n63x9nORIih7h86pJZ1gYxmdAIn9fQsljZUWg81PhwPRi2R5zMIcm0I/CK4ZpUJh3xHV e60UrYTJRMvPHqE71gUSsGGV67Ir+Ncx/qWMcZXE4ODdfz2gqBZKF448BQReQ2OQuky1m7 U1wvZjApNp8VBgY/75ZQGzFflHkgWo0F8ZmLJhPM5zdXpCS9ReDSUEdGU3tUJw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wi4VM8vMO7tNjuxY9IdYcZ9dRCqO598/xFz1Lsgn8Tc=; b=KbdcERy7HC/BGK3xWQY8uSCRX0FJcaVcAPeDjbhmjcKsc+H25VYz4CXZ4Gp6wWXHyrD8x9 q/11fiiLDtg/6wCA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 025/120] x86/cpuid: Parse CPUID(0x2) Date: Thu, 28 May 2026 17:37:47 +0200 Message-ID: <20260528153923.403473-26-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x2). Query it only for Intel, Centaur, and Zhaoxin, given that kernel/cpu/cacheinfo.c :: init_intel_cacheinfo() is called by: kernel/cpu/intel.c cpu_dev.c_x86_vendor =3D X86_VENDOR_INTEL kernel/cpu/centaur.c cpu_dev.c_x86_vendor =3D X86_VENDOR_CENTAUR kernel/cpu/zhaoxin.c cpu_dev.c_x86_vendor =3D X86_VENDOR_ZHAOXIN At the CPUID tables, keep CPUID(0x2) marked as invalid if the whole leaf, or all of its output registers separately, were malformed. Note, cpuid_leaf_0x2() at will be removed once all call sites are transformed to new CPUID APIs. References: fe78079ec07f ("x86/cpu: Introduce and use CPUID leaf 0x2 parsin= g helpers") Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 1 + arch/x86/kernel/cpu/cpuid_parser.c | 36 ++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 2 ++ 3 files changed, 39 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 8cc9f81e9526..c35de721f652 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -210,6 +210,7 @@ struct cpuid_leaves { /* Leaf Subleaf number (or max number of subleaves) */ CPUID_LEAF ( 0x0, 0 ); CPUID_LEAF ( 0x1, 0 ); + CPUID_LEAF ( 0x2, 0 ); CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index a7e6692f767b..be340b202182 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -42,6 +42,42 @@ cpuid_read_generic(const struct cpuid_parse_entry *e, co= nst struct cpuid_read_ou cpuid_read_subleaf(e->leaf, e->subleaf + i, regs); } =20 +static void +cpuid_read_0x2(const struct cpuid_parse_entry *e, const struct cpuid_read_= output *output) +{ + union leaf_0x2_regs *regs =3D (union leaf_0x2_regs *)output->regs; + struct leaf_0x2_0 *l =3D (struct leaf_0x2_0 *)output->regs; + int invalid_regs =3D 0; + + /* + * All Intel CPUs must report an iteration count of 1. For broken hardwar= e, + * keep the leaf marked as invalid at the CPUID table. + */ + cpuid_read_subleaf(e->leaf, e->subleaf, l); + if (l->iteration_count !=3D 0x01) + return; + + /* + * The most significant bit (MSB) of each CPUID(0x2) register must be cle= ar. + * If a register is malformed, replace its 1-byte descriptors with NULL. + */ + for (int i =3D 0; i < 4; i++) { + if (regs->reg[i].invalid) { + regs->regv[i] =3D 0; + invalid_regs++; + } + } + + /* + * If all of the CPUID(0x2) output registers were malformed, keep the leaf + * marked as invalid at the CPUID table. + */ + if (invalid_regs =3D=3D 4) + return; + + output->info->nr_entries =3D 1; +} + /* * Define an extended range CPUID read function * diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 76a87a71b430..1de239370652 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -144,6 +144,7 @@ struct cpuid_parse_entry { */ #define CPUID_COMMON_ENTRIES \ /* Leaf Subleaf Reader function */ \ + CPUID_PARSE_ENTRY ( 0x2, 0, 0x2 ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ @@ -190,6 +191,7 @@ struct cpuid_vendor_entry { =20 #define CPUID_VENDOR_ENTRIES \ /* Leaf Vendor list */ \ + CPUID_VENDOR_ENTRY(0x2, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860001, X86_VENDOR_TRANSMETA), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 AC93D409102 for ; Thu, 28 May 2026 15:41:11 +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=1779982873; cv=none; b=KFlMTS0n/K+sWBJNNiAivN0M6i6Is/ExD5BqWC/h1n77pjGKRf5zXLBWr4RE0BiDHWg0XlzgQyoeRIickToFGQu0CEParmUnOpq0LjXRbYRYS0WtYxBagZC5SGi0K3SqL3htwJvb8tBsKJa+C9LDn9e4rWQhf6f/WrlMcDNxXv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982873; c=relaxed/simple; bh=xXpYSPGnl9wGRjVPGtJ7eD41YmoGyyY8TKActvqc1qc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5I5Opcz7QI0opV7EiJBoooc18vagBRzzzy3Yx3MZx/giwNJTbXJCFxHl4Qnob7PMD8xjBpnz9SsH5bkRgr9etdiCJBaJPPx7jRvv+ED9pRlsBdSvP0g3JcrVc2ae7OxXR/cnsXp2y9VdZDYCUrmJqSUio44m+FhPH6wCUSAPjk= 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=s5ysqe0/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=65MPGMF+; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="s5ysqe0/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="65MPGMF+" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O9FO+vvb9UphE4+7KwO+yOpwkc4NCAq8vBqHWXdky1M=; b=s5ysqe0/Gt+aBMLbDUFlJ59YhV/i1bZon9RVkGrnm99rc1wRltjF8e4MizLiKQzDEkHx6B EYM9iZXwlxWBfc53ZtIU2gDHldi44LY5yhWDsB4JUYavj9R+0sgS7n/Ho2HYj3PbcTksCA bzvo2YkMtPheZueG15NbOih9GSf5muKGUpqZDmLeA0UKPRIjoKjdu2X/8p3/9SPs+zCTOI V2YPNo2a9HoirFoSlBd6oOe4cQFQ5dAaHjmA0FjrcHfh/Wv0bz5k6aTSuqbh1wLPniPXl8 db+BU0p2WmmoMvp0n/dTUmvugQ4NS02a06kF6aVIeVordE7102l9RejWn9/uRQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O9FO+vvb9UphE4+7KwO+yOpwkc4NCAq8vBqHWXdky1M=; b=65MPGMF+VEsv2jInfscC3tZzJGbGWh6sPPWSUZdQEvK6pvR5Ea1un7eg+gQroy+N1nxKq1 nFTREnEaj1L9viAQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 026/120] x86/cpuid: Warn once on invalid CPUID(0x2) iteration count Date: Thu, 28 May 2026 17:37:48 +0200 Message-ID: <20260528153923.403473-27-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CPUID(0x2) output includes a "query count" byte. That byte was supposed to specify the number of repeated CPUID(0x2) subleaf 0 queries needed to extract all of the CPU's cache and TLB descriptors. Per current Intel manuals, all CPUs supporting this leaf "will always" return an iteration count of 1. Since the CPUID parser ignores any CPUID(0x2) output with an invalid iteration count, lightly warn about this once in the kernel log. Do not emit a warning if some of the CPUID(0x2) output registers, or even all of them, are invalid. This is an architecturally-defined response. Suggested-by: Ingo Molnar Signed-off-by: Ahmed S. Darwish References: b5969494c8d8 ("x86/cpu: Remove CPUID leaf 0x2 parsing loop") Link: https://lore.kernel.org/lkml/aBnmy_Bmf-H0wxqz@gmail.com --- arch/x86/kernel/cpu/cpuid_parser.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index be340b202182..bddd9937bb2b 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -3,6 +3,8 @@ * CPUID parser; for populating the system's CPUID tables. */ =20 +#define pr_fmt(fmt) "x86/cpuid: " fmt + #include =20 #include @@ -54,8 +56,11 @@ cpuid_read_0x2(const struct cpuid_parse_entry *e, const = struct cpuid_read_output * keep the leaf marked as invalid at the CPUID table. */ cpuid_read_subleaf(e->leaf, e->subleaf, l); - if (l->iteration_count !=3D 0x01) + if (l->iteration_count !=3D 0x01) { + pr_warn_once("Ignoring CPUID(0x2) due to invalid iteration count =3D %d", + l->iteration_count); return; + } =20 /* * The most significant bit (MSB) of each CPUID(0x2) register must be cle= ar. --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A4D15409600 for ; Thu, 28 May 2026 15:41:14 +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=1779982876; cv=none; b=oOACNq5nPpCegyd0JErSnP4s4m0wWdwOhS8+dwGqZ3v8Rt05pJF1WdHMZy3nquIdSRQgAQvXUx++b//y6GxPjXWF5q/dZjDoHabN0A/g4qKy9ptAttmwKnRrBWq4GsYz8yNJDfcMHdtoF97XpljnMNbQaWTYop4wk1pvVExrVFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982876; c=relaxed/simple; bh=DpgLb1QI5HapytyIpVZZuRmyECFlpNBIFtkJYJhlQMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uGNWcBf89VHIyNpSTnjECEEa2OYBMIMB65oESeaeLB1XDe5XSp0kgX1cEhG39l2lQbuYLY26/qd83NTj+NyM/jGnGm8C0yLoxoC6khw3T7jPc8ZaGpC5lSCnXjmGmDlu+6ZxJVV55nzoX4WGdwPoISrsGDJukbUnwLYzYOTaqDE= 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=lA6O27Hy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/5NWM1+N; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lA6O27Hy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/5NWM1+N" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EI+dfaFdAQKqy0pHAjqC9zxFU8QxmQJhWZqHplFvRjk=; b=lA6O27HyZph/z8gFDC11YAHe/C2fxz+TYAioihKH4YWxBoOSwMqohHx4lIltQkN3I7DcZY dWAIq+cjVq0cEeHSff02OFZf9cqGaTJbxZzB2SSGafXjKAnwD3OjamJiyoGKOhYlT8o2mj q41NYPR3NWHF66ksJRuYI2wIrwTAGKKbmVpBo3yUUXdEEgtd8InWD6Ob9kNzGIyzIudopi WFQhROXazEOCGkdXWpgbGHt7f9si1SoWK022byjk6tHLKTUN2nDnkqRzmd1bG+kgelTcOh GshvqHFxKGaG/QKScK3WmH/WcVnv4GbEjOed1YLAOPVbKCNs/q+4sCfFZd+k9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EI+dfaFdAQKqy0pHAjqC9zxFU8QxmQJhWZqHplFvRjk=; b=/5NWM1+NZ4LLQMfePMZK1KDIaOSfjS2kCRXTJfEflgCG2MLEqtuxeblK9FTbPEQQfKUWET ssWoFtdJPG0uI7Dg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 027/120] x86/cpuid: Introduce parsed CPUID(0x2) API Date: Thu, 28 May 2026 17:37:49 +0200 Message-ID: <20260528153923.403473-28-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new iterator, for_each_parsed_cpuid_0x2_desc(), for retrieving parsed CPUID(0x2) entries as 1-byte descriptors. This new macro is aimed to replace for_each_cpuid_0x2_desc(), which operates on directly queried CPUID data instead. Assert that the passed "regs" are the same size as "union leaf_0x2_regs". Use a size equivalence check, instead of a typeof() check, to give callers the freedom to either pass a "struct cpuid_regs" pointer or a "struct leaf_0x2_0" pointer; where both can returned by the parsed CPUID API at . This size comparison matches what other kernel CPUID APIs do; e.g. cpuid_read() and cpuid_read_subleaf() at . Put the size equivalence check inside a GNU statement expression, ({..}) so that it can be placed inside the macro's loop initialization. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 3d5a0d4918cc..a55a28e9f0f6 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -528,6 +528,49 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) __cpuid_table_nr_filled_subleaves(&(_cpuinfo)->cpuid, _leaf, n); \ }) =20 +/* + * Convenience leaf-specific functions (using parsed CPUID data): + */ + +/* + * CPUID(0x2) + */ + +/** + * for_each_parsed_cpuid_0x2_desc() - Iterator for parsed CPUID(0x2) descr= iptors + * @_regs: Leaf 0x2 register output, as returned by cpuid_leaf_raw() + * @_ptr: u8 pointer, for macro internal use only + * @_desc: Pointer to parsed descriptor information at each iteration + * + * Loop over the 1-byte descriptors in the passed CPUID(0x2) output regist= ers + * @_regs. Provide the parsed information for each descriptor through @_d= esc. + * + * To handle cache-specific descriptors, switch on @_desc->c_type. For TLB + * descriptors, switch on @_desc->t_type. + * + * Example usage for cache descriptors:: + * + * const struct leaf_0x2_table *desc; + * const struct cpuid_regs *regs; + * const u8 *ptr; + * + * regs =3D cpuid_leaf_raw(c, 0x2); + * if (!regs) { + * // Handle error + * } + * + * for_each_parsed_cpuid_0x2_desc(regs, ptr, desc) { + * switch (desc->c_type) { + * ... + * } + * } + */ +#define for_each_parsed_cpuid_0x2_desc(_regs, _ptr, _desc) \ + for (({ static_assert(sizeof(*_regs) =3D=3D sizeof(union leaf_0x2_regs));= }), \ + _ptr =3D &((const union leaf_0x2_regs *)(_regs))->desc[1]; \ + _ptr < &((const union leaf_0x2_regs *)(_regs))->desc[16] && (_desc = =3D &cpuid_0x2_table[*_ptr]);\ + _ptr++) + /* * CPUID parser exported APIs: */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 4DFA1409623 for ; Thu, 28 May 2026 15:41:18 +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=1779982883; cv=none; b=GkJMkWZdf6YjXRWoAGySO7/qIbk/GDTLY/Jr87sHhaCUhIxr0pCA7rzRkORAvxo3teFVUuiGo49juIoRc3SI8UDVeWhVTbhqmvkr+dzHuBmEbubN+TTVFTC4InztFOp9chfKPPAsTtmnTcVeLZyX3ML+EpIL/Hk8gJJ7lITya/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982883; c=relaxed/simple; bh=Z98TVhkH6+aGiydyxHKpCGX/azCbJ65l/IXIELgxR+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nmVWlou5alXTOmx+ps2bmjy5Mr3ORNZ0B2ApgRQcPfAF1yzCJPk1SzD6PZweFutarJaLhe7SW0qaID4B7rYiPqv73V/T39iNWILApm9go8Lk8tl2Wotmjv7ig9lCOQr152XoqUdR9fZERjYeAe0afO6/YgIhVEW3+JLiBW5CS64= 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=ODPoJu8X; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YoiwBOyS; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ODPoJu8X"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YoiwBOyS" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c9Ql/vXzqLMu77lSwsIR2ztTMeL1uBfD+VHcsu7CIx0=; b=ODPoJu8XZ0aVw+aV1o9CmCPj59vr9eH91q1m+ngRtjAnZd6KhC5dRAPDVbt1O7hBoy6rJI F9nDesXmQWBYF4cZvxyCIQrKEWaZICv/ss9/C+vKwAvwAfpVePqafQgpZGpyRwSB5fz8jr XeKXH6isePUcHNd7gmZWKqsZ20GYQPtInJuSE/YLIJZAre9x1h/o3TxpqIuqb5sMCh2v8O i1obw2e0tT/7Bh5nrmAjO2TOYAk19/7gfDFiTT0jcBJQxzcorCWmoZTvWfOGYXOGrYoPPM CnJD/6qj9D9uSyN/DnM8qrVsyQ4bIMrMCHHVLZXxMvOXmh3EKma2ZBXekgD0xg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c9Ql/vXzqLMu77lSwsIR2ztTMeL1uBfD+VHcsu7CIx0=; b=YoiwBOySm3THu8/9vw8Uoc0cSREYHlGaVmJq1pz7MqtD2upVp1NNbjBHnT2LFdhkojrhAm rgSMgiA+xLVZmkBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 028/120] x86/cpu: Use parsed CPUID(0x2) Date: Thu, 28 May 2026 17:37:50 +0200 Message-ID: <20260528153923.403473-29-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel TLB detection, use parsed CPUID(0x2) instead of a direct CPUID query. Remove the maximum CPUID level check since the CPUID API's NULL check is equivalent. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/intel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index f28c0efb7c8f..4d190dd64e95 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -709,14 +709,14 @@ static void intel_tlb_lookup(const struct leaf_0x2_ta= ble *desc) static void intel_detect_tlb(struct cpuinfo_x86 *c) { const struct leaf_0x2_table *desc; - union leaf_0x2_regs regs; - u8 *ptr; + const struct cpuid_regs *regs; + const u8 *ptr; =20 - if (c->cpuid_level < 2) + regs =3D cpuid_leaf_raw(c, 0x2); + if (!regs) return; =20 - cpuid_leaf_0x2(®s); - for_each_cpuid_0x2_desc(regs, ptr, desc) + for_each_parsed_cpuid_0x2_desc(regs, ptr, desc) intel_tlb_lookup(desc); } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C2261409624 for ; Thu, 28 May 2026 15:41:21 +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=1779982884; cv=none; b=cvTw/zqnMbENqhB0TCV4kzKp4UiS5g9EJPtppwqufdpIgOPNuKmBf4+OLsiSnlPqs74VehPqYlj3YdIBV+et1MuOnE+Bc4hLlfAbKm1I82ZgKKozWCVYoqHopnW2BtJ3zaFoDv6kjOXFPtMEwZqaGxc4T+aJI1NiA2UnCKdQJ28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982884; c=relaxed/simple; bh=mJ93X1ivE2oqgltkL//rGGTPFa8WKLjw+oBgw2R5aw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pgzmqK2UjTQrP/k00mT8eKnkBY1WT5+vsTCRjYrR25exb8qsK2Bv+2fULjZnmByQdcJJHjxdzgVoy/CM52GNgQG43dSQVw9N02RqKD7Pmy+oXtBqLbXPc3S1QemLz97bCaur7x8Rs6dlYBL7rRzFnbxlsZof4N4rGTZYqBMpHeU= 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=xlKi0myS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Vbvlo/54; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xlKi0myS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Vbvlo/54" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AzDWHxSccHBy86sBlw6tGBt2CNdcE0O8iEr9zpIE3Uc=; b=xlKi0mySQW+abV1H4YNhFjbGVg6RWMC6yhDeQXBiGuxL9VDSwmtgYpHCjTfC5ODuA9aynk firQfd60qMT0BZV3ZyxrUAriVrMv7+uOofoXjrW47qsAUITn7p/M6GZVNsuD1FfYqCXMA9 5koa0+BhV40D6KwYJJ+DRQfM1LgCwZAbNuniCzQyciKITBu7hxHiFGwMoOoHJPvTCIC5xS dQpucnYebncE2lYBnwO5ojgdhV64YIl11kk0uGfYsgfeUxV2BoY+4kS2JlkmELg+PIaoKZ VN4lYjdC5ok+ngJpE4XrVq0OZztjh3mgusJiybObOzK0O8fJljmWT3ByOrfMag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AzDWHxSccHBy86sBlw6tGBt2CNdcE0O8iEr9zpIE3Uc=; b=Vbvlo/54zLc3H0QUcSbI7XlbwRJ8owrHgdKDg1YdUrcQ6Mz16Omuwp4L3QkbjUaV3YpIUN tZHYV00sJnaRLeCg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 029/120] x86/cacheinfo: Use parsed CPUID(0x2) Date: Thu, 28 May 2026 17:37:51 +0200 Message-ID: <20260528153923.403473-30-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel cacheinfo, use parsed CPUID(0x2) instead of a direct CPUID query. Remove the maximum CPUID level check since the CPUID API's NULL check is equivalent. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 51a95b07831f..6fded356f2ee 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -391,14 +391,14 @@ static void intel_cacheinfo_0x2(struct cpuinfo_x86 *c) { unsigned int l1i =3D 0, l1d =3D 0, l2 =3D 0, l3 =3D 0; const struct leaf_0x2_table *desc; - union leaf_0x2_regs regs; - u8 *ptr; + const struct cpuid_regs *regs; + const u8 *ptr; =20 - if (c->cpuid_level < 2) + regs =3D cpuid_leaf_raw(c, 0x2); + if (!regs) return; =20 - cpuid_leaf_0x2(®s); - for_each_cpuid_0x2_desc(regs, ptr, desc) { + for_each_parsed_cpuid_0x2_desc(regs, ptr, desc) { switch (desc->c_type) { case CACHE_L1_INST: l1i +=3D desc->c_size; break; case CACHE_L1_DATA: l1d +=3D desc->c_size; break; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C27B8409637 for ; Thu, 28 May 2026 15:41:24 +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=1779982888; cv=none; b=Lp41RpYGxQ/uM5UfixA4ztPtcRSRxWBetu6V0+GlhDNXovuUvd+Qfv70WB7Ya8AWzrhU3dr8NIu3kx49aiEJY6N5uRHAHP1idRLCLFKsBDsA8x/zVMrXH3N2eqBxXXUXrJyOO/cE9vFLichlT4D+s0jph3wdNuqSDFfUv+z2FvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982888; c=relaxed/simple; bh=foNoRaHZufNq1AhxJpngnI4WOK61pRXu8RfjVzssd3U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DF2BEVIqVR8atoZlwztnXOzQFQRuU8hDuvNJMkw2PTwMohI2+QB9nbY05r5HKdDe/jMbzTiYGvXPSxIYsJmjpWMlKvQiVOj3lORavTn3CTeKgEhgC+99EV4+PnZIZknUKVCFMnIlw6k6OoM+s3ZqIEwS0auvMrSlnS5t4NtJYmo= 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=Op+eo4Or; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5vnJRNQT; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Op+eo4Or"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5vnJRNQT" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982883; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6pq1CKWWUzQqX7SBhdjyherkdAFiuqo0mZsZokxw8oE=; b=Op+eo4OrFW6U3NQ4xp3rM5ubNeA7QY7TtgooUPttvfy+KgPebLeP4XwD5OwMbpU+86cZtQ qD3i3+6ZEDt/MbFdEOkStDPrdXgXNO99iHGGE2Uje4/3RoMNYnB6SMVSwU8iqtWXM6BFUX /hzkJhHRBhiOiDJTS7HqaDXTmyHVeKTeitlNkiUN1ei12bAKktJ0j8I9h6VMIMm+Yeazm4 E8WukvFYdaStXXjGVW9Wm99jL1LvXaeIVhcTNU3WJcKVzGNyT78fch0/ql/jNUltH/yh2m UMXcRjeqhLg8J/SkhS0qA8oKQv4lsaWAwRmIHrnNExuCYPFNhaGUYKJMgZd1zQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982883; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6pq1CKWWUzQqX7SBhdjyherkdAFiuqo0mZsZokxw8oE=; b=5vnJRNQTN9DjdEEhkgWgO0dtjYMe2PJ+ORMQoUW3as8Z50s43cwRF3lPR1cSy6lisFppWh venjbg3LRUXRK+Bg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 030/120] x86/cpuid: Remove direct CPUID(0x2) query helpers Date: Thu, 28 May 2026 17:37:52 +0200 Message-ID: <20260528153923.403473-31-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All call sites at x86/cpu and x86/cacheinfo have been converted from directly invoking CPUID(0x2) queries to parsed CPUID access. Remove the direct CPUID(0x2) query helpers cpuid_leaf_0x2() for_each_cpuid_0x2_desc() And rename the parsed CPUID(0x2) iterator macro for_each_parsed_cpuid_0x2_desc() back to for_each_cpuid_0x2_desc() since by now only parsed CPUID(0x2) access is allowed. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 75 ++------------------------------ arch/x86/kernel/cpu/cacheinfo.c | 2 +- arch/x86/kernel/cpu/intel.c | 2 +- 3 files changed, 5 insertions(+), 74 deletions(-) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index a55a28e9f0f6..f4bdfe3c9325 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -212,75 +212,6 @@ static inline u32 cpuid_base_hypervisor(const char *si= g, u32 leaves) return 0; } =20 -/* - * CPUID(0x2) parsing: - */ - -/** - * cpuid_leaf_0x2() - Return sanitized CPUID(0x2) register output - * @regs: Output parameter - * - * Query CPUID(0x2) and store its output in @regs. Force set any - * invalid 1-byte descriptor returned by the hardware to zero (the NULL - * cache/TLB descriptor) before returning it to the caller. - * - * Use for_each_cpuid_0x2_desc() to iterate over the register output in - * parsed form. - */ -static inline void cpuid_leaf_0x2(union leaf_0x2_regs *regs) -{ - cpuid_read(0x2, regs); - - /* - * All Intel CPUs must report an iteration count of 1. In case - * of bogus hardware, treat all returned descriptors as NULL. - */ - if (regs->desc[0] !=3D 0x01) { - for (int i =3D 0; i < 4; i++) - regs->regv[i] =3D 0; - return; - } - - /* - * The most significant bit (MSB) of each register must be clear. - * If a register is invalid, replace its descriptors with NULL. - */ - for (int i =3D 0; i < 4; i++) { - if (regs->reg[i].invalid) - regs->regv[i] =3D 0; - } -} - -/** - * for_each_cpuid_0x2_desc() - Iterator for parsed CPUID(0x2) descriptors - * @_regs: CPUID(0x2) register output, as returned by cpuid_leaf_0x2() - * @_ptr: u8 pointer, for macro internal use only - * @_desc: Pointer to the parsed CPUID(0x2) descriptor at each iteration - * - * Loop over the 1-byte descriptors in the passed CPUID(0x2) output regist= ers - * @_regs. Provide the parsed information for each descriptor through @_d= esc. - * - * To handle cache-specific descriptors, switch on @_desc->c_type. For TLB - * descriptors, switch on @_desc->t_type. - * - * Example usage for cache descriptors:: - * - * const struct leaf_0x2_table *desc; - * union leaf_0x2_regs regs; - * u8 *ptr; - * - * cpuid_leaf_0x2(®s); - * for_each_cpuid_0x2_desc(regs, ptr, desc) { - * switch (desc->c_type) { - * ... - * } - * } - */ -#define for_each_cpuid_0x2_desc(_regs, _ptr, _desc) \ - for (_ptr =3D &(_regs).desc[1]; \ - _ptr < &(_regs).desc[16] && (_desc =3D &cpuid_0x2_table[*_ptr]); \ - _ptr++) - /* * CPUID(0x80000006) parsing: */ @@ -537,7 +468,7 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) */ =20 /** - * for_each_parsed_cpuid_0x2_desc() - Iterator for parsed CPUID(0x2) descr= iptors + * for_each_cpuid_0x2_desc() - Iterator for parsed CPUID(0x2) descriptors * @_regs: Leaf 0x2 register output, as returned by cpuid_leaf_raw() * @_ptr: u8 pointer, for macro internal use only * @_desc: Pointer to parsed descriptor information at each iteration @@ -559,13 +490,13 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) * // Handle error * } * - * for_each_parsed_cpuid_0x2_desc(regs, ptr, desc) { + * for_each_cpuid_0x2_desc(regs, ptr, desc) { * switch (desc->c_type) { * ... * } * } */ -#define for_each_parsed_cpuid_0x2_desc(_regs, _ptr, _desc) \ +#define for_each_cpuid_0x2_desc(_regs, _ptr, _desc) \ for (({ static_assert(sizeof(*_regs) =3D=3D sizeof(union leaf_0x2_regs));= }), \ _ptr =3D &((const union leaf_0x2_regs *)(_regs))->desc[1]; \ _ptr < &((const union leaf_0x2_regs *)(_regs))->desc[16] && (_desc = =3D &cpuid_0x2_table[*_ptr]);\ diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 6fded356f2ee..d933d58a5a61 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -398,7 +398,7 @@ static void intel_cacheinfo_0x2(struct cpuinfo_x86 *c) if (!regs) return; =20 - for_each_parsed_cpuid_0x2_desc(regs, ptr, desc) { + for_each_cpuid_0x2_desc(regs, ptr, desc) { switch (desc->c_type) { case CACHE_L1_INST: l1i +=3D desc->c_size; break; case CACHE_L1_DATA: l1d +=3D desc->c_size; break; diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 4d190dd64e95..51078ffee16c 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -716,7 +716,7 @@ static void intel_detect_tlb(struct cpuinfo_x86 *c) if (!regs) return; =20 - for_each_parsed_cpuid_0x2_desc(regs, ptr, desc) + for_each_cpuid_0x2_desc(regs, ptr, desc) intel_tlb_lookup(desc); } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 ED28B409635 for ; Thu, 28 May 2026 15:41:27 +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=1779982890; cv=none; b=ighGio0P+F+fjmLzoZQcCk5+W/UEtYRZfbR5J28hdew1RZUWLhc1BYWsacwGSzgffSmswTolwkyUzDhfIAudeiLL75CNaseVHKb5KU4Z0KE9ZgHa0YJZII8XQ06vCsIhrjWmq/ZBjOWuL4+CPLU58FzvlWsrC5aNcjkiJ/nO5EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982890; c=relaxed/simple; bh=gugfPwIVW6Z23h4Zjwchn/ZC84hbXBcCOZsvKdU7KWA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OunMBCEsRHeETk8rKmjT+rlgDo8mnEb329r00s91osDx373x4oZhC03lFcz8ie2Ns+J9S+UxPc23R3toO8unTBghqlghZu4gEx8rkVmQgn5amxBRZ0pb0YXwmePGUgyH/ZrBhEcCkyp2uk8l7KBuRJ74rfpqFAzKrmccWXeCR2E= 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=sp6o2zQT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nzRXI/Xp; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sp6o2zQT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nzRXI/Xp" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aW/+CALsoqbaO0yECpY9fnloQniYFrOWJkJUj7JZneo=; b=sp6o2zQTaIW5tD5GC0yQ4nIyP2og6hJWTPfoPohGtDDQDrKR9eNrvxRc184GtL09Z0X/fj hrG18YzoUM9TkOO/iqMcSgnmxcQBCAQD/9eNo1tCKfngkCpZoZDvoOu4bzn7n/5tZ5P+go h96nm1j17tHluXdfPZ8Rw/UQ5k90R52HxmpNkn4kuGHdgKPjMELpF8g9CiI2HdOpl4LBKW 5cTc6PdoeMD6UO5zE8SPzvoTuZ8/yBTWN54jzUud3XOTIGaM/at/Fm18BwXfEK52raT960 +FBLWjCEjDUSvpomHMT98OCY2FmQh4gaAjjMRhIMlMRJt+6OS75KYpp74OGMkw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aW/+CALsoqbaO0yECpY9fnloQniYFrOWJkJUj7JZneo=; b=nzRXI/XpsQ5S+nu/XvyqxpKPc1eYyDNMYgszm+/pu7CJvlWgtsVjD401Rnrbdohqwj0+E6 BqmVgfptdY9092Ag== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 031/120] x86/cpuid: Parse deterministic cache parameters CPUID leaves Date: Thu, 28 May 2026 17:37:53 +0200 Message-ID: <20260528153923.403473-32-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x4) and CPUID(0x8000001d). Query CPUID(0x4) only for Intel, Centaur, and Zhaoxin as these are the x86 vendors where it is supported. Query CPUID(0x8000001d) for AMD and Hygon. Define a single CPUID parser read function for both leaves, as they have the same subleaf cache enumeration logic. Introduce the macro define_cpuid_read_function() to avoid code duplication between the CPUID parser default read function, cpuid_read_generic(), and the new CPUID(0x4)/CPUID(0x8000001d) logic. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 2 ++ arch/x86/kernel/cpu/cpuid_parser.c | 40 ++++++++++++++++++++++-------- arch/x86/kernel/cpu/cpuid_parser.h | 4 +++ 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index c35de721f652..f77659303569 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -211,11 +211,13 @@ struct cpuid_leaves { CPUID_LEAF ( 0x0, 0 ); CPUID_LEAF ( 0x1, 0 ); CPUID_LEAF ( 0x2, 0 ); + CPUID_LEAF_N ( 0x4, 8 ); CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); CPUID_LEAF ( 0x80000004, 0 ); + CPUID_LEAF_N ( 0x8000001d, 8 ); CPUID_LEAF ( 0x80860000, 0 ); CPUID_LEAF ( 0x80860001, 0 ); CPUID_LEAF ( 0x80860002, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index bddd9937bb2b..ee34894c79ef 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -31,19 +31,33 @@ static const struct cpuid_vendor_entry cpuid_vendor_ent= ries[] =3D { * Leaf read functions: */ =20 -/* - * Default CPUID read function - * Satisfies the requirements stated at 'struct cpuid_parse_entry'->read(). +/** + * define_cpuid_read_function() - Generate a CPUID parser read function + * @suffix: Generated function name suffix (full name becomes: cpuid_read_= @suffix()) + * @_leaf_t: Type to cast the CPUID output storage pointer + * @_leaf: Name of the CPUID output storage pointer + * @_break_c: Condition to break the CPUID parsing loop, which may referen= ce @_leaf, + * and where @_leaf stores each iteration's CPUID output. + * + * Define a CPUID parser read function according to the requirements state= d at + * 'struct cpuid_parse_entry'->read(). */ -static void -cpuid_read_generic(const struct cpuid_parse_entry *e, const struct cpuid_r= ead_output *output) -{ - struct cpuid_regs *regs =3D output->regs; - - for (int i =3D 0; i < e->maxcnt; i++, regs++, output->info->nr_entries++) - cpuid_read_subleaf(e->leaf, e->subleaf + i, regs); +#define define_cpuid_read_function(suffix, _leaf_t, _leaf, _break_c) \ +static void \ +cpuid_read_##suffix(const struct cpuid_parse_entry *e, const struct cpuid_= read_output *output) \ +{ \ + struct _leaf_t *_leaf =3D (struct _leaf_t *)output->regs; \ + \ + for (int i =3D 0; i < e->maxcnt; i++, _leaf++, output->info->nr_entries++= ) { \ + cpuid_read_subleaf(e->leaf, e->subleaf + i, _leaf); \ + if (_break_c) \ + break; \ + } \ } =20 +/* cpuid_read_generic() */ +define_cpuid_read_function(generic, cpuid_regs, ignored, false); + static void cpuid_read_0x2(const struct cpuid_parse_entry *e, const struct cpuid_read_= output *output) { @@ -83,6 +97,12 @@ cpuid_read_0x2(const struct cpuid_parse_entry *e, const = struct cpuid_read_output output->info->nr_entries =3D 1; } =20 +/* + * Shared read function for Intel CPUID(0x4) and AMD CPUID(0x8000001d), as= both have + * the same subleaf enumeration logic and register output format. + */ +define_cpuid_read_function(deterministic_cache, leaf_0x4_n, l, l->cache_ty= pe =3D=3D 0); + /* * Define an extended range CPUID read function * diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 1de239370652..25ca9b19e8cf 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -145,11 +145,13 @@ struct cpuid_parse_entry { #define CPUID_COMMON_ENTRIES \ /* Leaf Subleaf Reader function */ \ CPUID_PARSE_ENTRY ( 0x2, 0, 0x2 ), \ + CPUID_PARSE_ENTRY_N ( 0x4, deterministic_cache ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ + CPUID_PARSE_ENTRY_N ( 0x8000001d, deterministic_cache ), \ CPUID_PARSE_ENTRY ( 0x80860000, 0, 0x80860000 ), \ CPUID_PARSE_ENTRY ( 0x80860001, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80860002, 0, generic ), \ @@ -192,7 +194,9 @@ struct cpuid_vendor_entry { #define CPUID_VENDOR_ENTRIES \ /* Leaf Vendor list */ \ CPUID_VENDOR_ENTRY(0x2, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ + CPUID_VENDOR_ENTRY(0x4, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ + CPUID_VENDOR_ENTRY(0x8000001d, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860001, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860002, X86_VENDOR_TRANSMETA), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 46CA43EFFDD for ; Thu, 28 May 2026 15:41:30 +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=1779982898; cv=none; b=Z8TtOGhVDqeNiFLMTcUaUmT0S0BOVVh/fqxPpawm65S4X7MzrpMDOSD8e+IqyM07ZD5BPCCbtolTESWxXpHHw6Wq4gi2EfjoHs/ujSo9vY3TwCJApa5LyRNieCj/aWJDTIEjc3dBb2wy80RjsAhIzYvRx1e2b2kQJlOYGL+S88M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982898; c=relaxed/simple; bh=asmsKTgbHE9koFljta6pJaueSFWxw/PmAgxd4HYmcy0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KGAS9HS39hkd2/iHbQnH1rVlY8OnjQ9Cl7dKWR0rKSirC6iCc9aO8r6+tAq6D5u/9HbJ5yfa+hOo4QD+AufJGHhFaxanUZoCfDPHsW6r9Vm+UY/t5HT050oFQeWdU3N6Luivjvaqu696e1e75kHDYdany1iyVTioRpqNEJAo1J4= 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=sZpJr3ft; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JwLYCOA1; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sZpJr3ft"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JwLYCOA1" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fc7etnUnxpviEWTMshgDDXsfeYrPyAO6HhpCwUqQOG0=; b=sZpJr3ft5V6BHcTuwrkMHib1GfrtNgs1v3vgNYI/U99x4awDTupHJcG7tabgQdINahyA+b KQx4qhwQFkxzC1evWnLjBpjs5aqJVjB5uxFe/qQczc3l+1eDDSZXRWQnmFBLjowqjRQirC /xai0NovCTBsvYxWFa5EIk4pplJiT4KmhgYnVgQPKQJFNSaEH2yrR4JdcKAsxdYBfmudLZ b4W86XlfeIS5VzP2XjgQVU4Bt7MnTHcWSLdBgypZwFkbuHrqj9AUAEO8k4u5Zj0U2N8MR9 +7T/8tEILTbxsemsPmjnw2YLVFgXo5UKmD/tU/+m+lBN9HNRzsjm7+Ceif/81g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fc7etnUnxpviEWTMshgDDXsfeYrPyAO6HhpCwUqQOG0=; b=JwLYCOA11dyrkoP1ebbzfjuDQ98ic3xEbyiCuV9nb2d6eVeMHXdTb6FYZs9MCjPfkllFaw eHZiBnge118OhZBA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 032/120] x86/cacheinfo: Pass a 'struct cpuinfo_x86' reference to CPUID(0x4) code Date: Thu, 28 May 2026 17:37:54 +0200 Message-ID: <20260528153923.403473-33-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Prepare the CPUID(0x4) cache topology code for using the parsed CPUID API instead of invoking direct CPUID queries. Since the CPUID API requires a 'struct cpuinfo_x86' reference, trickle it from 's populate_cache_leaves() x86 implementation down to fill_cpuid4_info() and its Intel-specific CPUID(0x4) code. No functional change intended. Suggested-by: Ingo Molnar Signed-off-by: Ahmed S. Darwish Link: https://lore.kernel.org/lkml/aBnEBbDATdE2LTGU@gmail.com --- arch/x86/kernel/cpu/cacheinfo.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index d933d58a5a61..07f7e7b667ed 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -252,7 +252,7 @@ static int amd_fill_cpuid4_info(int index, struct _cpui= d4_info *id4) return cpuid4_info_fill_done(id4, eax, ebx, ecx); } =20 -static int intel_fill_cpuid4_info(int index, struct _cpuid4_info *id4) +static int intel_fill_cpuid4_info(struct cpuinfo_x86 *unused, int index, s= truct _cpuid4_info *id4) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; @@ -264,13 +264,13 @@ static int intel_fill_cpuid4_info(int index, struct _= cpuid4_info *id4) return cpuid4_info_fill_done(id4, eax, ebx, ecx); } =20 -static int fill_cpuid4_info(int index, struct _cpuid4_info *id4) +static int fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct _cpui= d4_info *id4) { u8 cpu_vendor =3D boot_cpu_data.x86_vendor; =20 return (cpu_vendor =3D=3D X86_VENDOR_AMD || cpu_vendor =3D=3D X86_VENDOR_= HYGON) ? amd_fill_cpuid4_info(index, id4) : - intel_fill_cpuid4_info(index, id4); + intel_fill_cpuid4_info(c, index, id4); } =20 static int find_num_cache_leaves(struct cpuinfo_x86 *c) @@ -443,7 +443,7 @@ static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) struct _cpuid4_info id4 =3D {}; int ret; =20 - ret =3D intel_fill_cpuid4_info(i, &id4); + ret =3D intel_fill_cpuid4_info(c, i, &id4); if (ret < 0) continue; =20 @@ -612,17 +612,17 @@ int populate_cache_leaves(unsigned int cpu) struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci =3D this_cpu_ci->info_list; u8 cpu_vendor =3D boot_cpu_data.x86_vendor; - u32 apicid =3D cpu_data(cpu).topo.apicid; + struct cpuinfo_x86 *c =3D &cpu_data(cpu); struct amd_northbridge *nb =3D NULL; struct _cpuid4_info id4 =3D {}; int idx, ret; =20 for (idx =3D 0; idx < this_cpu_ci->num_leaves; idx++) { - ret =3D fill_cpuid4_info(idx, &id4); + ret =3D fill_cpuid4_info(c, idx, &id4); if (ret) return ret; =20 - id4.id =3D get_cache_id(apicid, &id4); + id4.id =3D get_cache_id(c->topo.apicid, &id4); =20 if (cpu_vendor =3D=3D X86_VENDOR_AMD || cpu_vendor =3D=3D X86_VENDOR_HYG= ON) nb =3D amd_init_l3_cache(idx); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 4A2FB3AF65B for ; Thu, 28 May 2026 15:41:34 +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=1779982898; cv=none; b=LSL464GfS7pVbzYXRI3Kp8vUlF8q4JePvHgSAyhGyplSfxwv4JD/+5jxELhc7F2I9Fp0FJyRCgb2a5rV39FwNGWF4MPbfJ+RHj1q/0eu/b8RzoZzN0XIBODpHniOLJoGRN63C+EHay+9NY4a3KolXrA9yLA2UaeY+WXaDm3OM80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982898; c=relaxed/simple; bh=7AYTYMTDZYM4RusPqr/AAR9GqJZtxYrUmF4BOJcTSaI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O01NShW/0gVEpjrq81/LhsJi//jk5skQ/8GKoQbP5vnUzupNGwUH5oKaLhn1jk+dy4FtJGIzSTUe7SOg931Wwcq3ObCZsc+lc83HZF6GPot2hY26o8+Dx6GR++MuQDqoleQhzBnBfG/+zcCpGLXdhvaKnVKIVjzhPRjkJFM18CI= 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=Baa7qsUQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wUd3iJN1; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Baa7qsUQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wUd3iJN1" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpdQ6+hAOM3XilPdWRjoWXgtfgUoW3JKHlz20f2egYc=; b=Baa7qsUQGVJOT7c92qBQUrcLgrHyhqqX0BnZEMnKoyI11UtLO/MhesdNQJULO94XwlPqlK XWvDGIVdjzLzHJkOkKl47hslCBxSTD2a5FiXjTb75ChKejEfu9Jn5bMUsZHYCYUfk+LBIs ZAPKLE70W6fgpCa+xywhEUYrWR1+Wmljg61zRD8Qm1lwcBGDeQ9noukeub7GkizrDHeRfh rTg+TD+MshmHNnaFWeGWDyTD2oL2BDcICDGYMtwUX4kPgaHa9rq9iHgvlWBvBJ2/orYnZq AhKLzZ5dHfMCZY83PB0LX5/G4lcIRFyJNvC3/qifGj2vljC4RQNJPtbhKmnH+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpdQ6+hAOM3XilPdWRjoWXgtfgUoW3JKHlz20f2egYc=; b=wUd3iJN1yfcswkYqCjfUJOd4s4n8EZMyUlIDqIWmeTPQOHrrAqDG1Y5SaeAuGtlQM8cgpW cImSOT3CnnZcFMAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 033/120] x86/cacheinfo: Use parsed CPUID(0x4) Date: Thu, 28 May 2026 17:37:55 +0200 Message-ID: <20260528153923.403473-34-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel cacheinfo, use parsed CPUID(0x4) instead of a direct CPUID query. Use the CPUID API cpuid_subleaf_count(c, 0x4) to determine the number of CPUID(0x4) cache subleaves instead of calling find_num_cache_leaves(). The latter function internally invokes direct CPUID(0x4) queries. Since find_num_cache_leaves() is no longer needed for Intel code paths, make its name and implementation AMD-specific. Adjust the AMD code paths accordingly. At intel_cacheinfo_0x4(), remove the max CPUID level check since cpuid_subleaf_count(c, 0x4) will return zero if CPUID(0x4) is not valid. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 40 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 07f7e7b667ed..91020f85c000 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -252,16 +252,17 @@ static int amd_fill_cpuid4_info(int index, struct _cp= uid4_info *id4) return cpuid4_info_fill_done(id4, eax, ebx, ecx); } =20 -static int intel_fill_cpuid4_info(struct cpuinfo_x86 *unused, int index, s= truct _cpuid4_info *id4) +static int intel_fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct= _cpuid4_info *id4) { - union _cpuid4_leaf_eax eax; - union _cpuid4_leaf_ebx ebx; - union _cpuid4_leaf_ecx ecx; - u32 ignored; + const struct cpuid_regs *regs =3D cpuid_subleaf_n_raw(c, 0x4, index); =20 - cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &ignored); + if (!regs) + return -EIO; =20 - return cpuid4_info_fill_done(id4, eax, ebx, ecx); + return cpuid4_info_fill_done(id4, + (union _cpuid4_leaf_eax)(regs->eax), + (union _cpuid4_leaf_ebx)(regs->ebx), + (union _cpuid4_leaf_ecx)(regs->ecx)); } =20 static int fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct _cpui= d4_info *id4) @@ -273,17 +274,16 @@ static int fill_cpuid4_info(struct cpuinfo_x86 *c, in= t index, struct _cpuid4_inf intel_fill_cpuid4_info(c, index, id4); } =20 -static int find_num_cache_leaves(struct cpuinfo_x86 *c) +static int amd_find_num_cache_leaves(struct cpuinfo_x86 *c) { - unsigned int eax, ebx, ecx, edx, op; union _cpuid4_leaf_eax cache_eax; + unsigned int eax, ebx, ecx, edx; int i =3D -1; =20 - /* Do a CPUID(op) loop to calculate num_cache_leaves */ - op =3D (c->x86_vendor =3D=3D X86_VENDOR_AMD || c->x86_vendor =3D=3D X86_V= ENDOR_HYGON) ? 0x8000001d : 4; + /* Do a CPUID(0x8000001d) loop to calculate num_cache_leaves */ do { ++i; - cpuid_count(op, i, &eax, &ebx, &ecx, &edx); + cpuid_count(0x8000001d, i, &eax, &ebx, &ecx, &edx); cache_eax.full =3D eax; } while (cache_eax.split.type !=3D CTYPE_NULL); return i; @@ -328,7 +328,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u= 16 die_id) * Newer families: LLC ID is calculated from the number * of threads sharing the L3 cache. */ - u32 llc_index =3D find_num_cache_leaves(c) - 1; + u32 llc_index =3D amd_find_num_cache_leaves(c) - 1; struct _cpuid4_info id4 =3D {}; =20 if (!amd_fill_cpuid4_info(llc_index, &id4)) @@ -353,7 +353,7 @@ void init_amd_cacheinfo(struct cpuinfo_x86 *c) struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); =20 if (boot_cpu_has(X86_FEATURE_TOPOEXT)) - ci->num_leaves =3D find_num_cache_leaves(c); + ci->num_leaves =3D amd_find_num_cache_leaves(c); else if (c->extended_cpuid_level >=3D 0x80000006) ci->num_leaves =3D (cpuid_edx(0x80000006) & 0xf000) ? 4 : 3; } @@ -362,7 +362,7 @@ void init_hygon_cacheinfo(struct cpuinfo_x86 *c) { struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); =20 - ci->num_leaves =3D find_num_cache_leaves(c); + ci->num_leaves =3D amd_find_num_cache_leaves(c); } =20 static void intel_cacheinfo_done(struct cpuinfo_x86 *c, unsigned int l3, @@ -426,15 +426,9 @@ static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) unsigned int l2_id =3D BAD_APICID, l3_id =3D BAD_APICID; unsigned int l1d =3D 0, l1i =3D 0, l2 =3D 0, l3 =3D 0; =20 - if (c->cpuid_level < 4) - return false; - - /* - * There should be at least one leaf. A non-zero value means - * that the number of leaves has been previously initialized. - */ + /* Non-zero means that it has been previously initialized */ if (!ci->num_leaves) - ci->num_leaves =3D find_num_cache_leaves(c); + ci->num_leaves =3D cpuid_subleaf_count(c, 0x4); =20 if (!ci->num_leaves) return false; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 4EA853FAE11 for ; Thu, 28 May 2026 15:41:37 +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=1779982900; cv=none; b=qVIB8rCOTey1AmgMLPikmm+vs0QAou2gRUtOxgEmBAC1mDVAnsR5WmtFX/NtG52UDu11DRVQTlHJClCtkusKzSPKJToYvkN7fx/Dm0zXVhiHuP+bXH/Kp97lFWBJTDeMG826bnBTW2QaiEx11y6uVEg/ytCoKnvVrerMPi1HUwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982900; c=relaxed/simple; bh=TZKkHujQONFQLhuZLzxCw4a2HlymLOLTsRGBFY/DRD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T3dkw+s2WSKN36Jc0spQ+mR3kS/uZZdYsNOkl6Cjtp2yBmPsv5QZI1IY6vzArn6OEHFvHNOGzGNqeMSusXjzTe0rqruvrsxw2XBmBizz+WR3mvpceyOD1Hel4P2yB2I8/jH/p1XJYfMlRY+/pqRsthYupZ/cY5fqkXADszcpba8= 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=dEG4j2DE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dK4kaTgA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dEG4j2DE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dK4kaTgA" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rf+QrdhYaX5GSWMv+3qrA1ngrG48lPw0VwDzeiVlk3Y=; b=dEG4j2DEJEi2dUvJOSX4lYv9BqjPab/jxMHFtIIIYtNjK7BcZhhhp7R82GHCEr8EOEutoR jKhqr0ogSDfoI5lmSO0/7e7J+MVYCZvEYQEvYc4RvLlB70xsqC+nxpCOL4pUDl8kbF3gkX jQUpRQQ1is4YFT/89cng4zvtFeAQO7vlqujGgQ61LlszBGNdsLfZ77uggRMbB0e+2sE4vV 6zwXoPFTuM+9wvOUnBc8pwN5dpXC4Q38/B8CnOiIYzBtzo+M2dQqojfITlH+CMk+fXnaor s5lBwaY8qXYuiRcfwrJKAFKxnIYwTOes4o2Lt+hM9cWi9PAwMPjnTNksQRrgjA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Rf+QrdhYaX5GSWMv+3qrA1ngrG48lPw0VwDzeiVlk3Y=; b=dK4kaTgAESXy1sn2B7xxbiQM0JDi9zjREF5oi4T4D0xjUzgdeo8iU1ZdoX/TNOtVxCn/wz m3oygv8evhoxE5Bw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 034/120] x86/cacheinfo: Use parsed CPUID(0x8000001d) Date: Thu, 28 May 2026 17:37:56 +0200 Message-ID: <20260528153923.403473-35-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD cacheinfo, use parsed CPUID(0x8000001d) instead of CPUID queries. Beside the CPUID parser centralization benefits, this allows using the auto-generated x86-cpuid-db data types, and their C99 bitfields, instead of doing ugly bitwise operations on the CPUID output. Trickle down a 'struct cpuinfo_x86' reference to the relevant functions as the CPUID APIs require it. Use the parsed CPUID API cpuid_subleaf_count(c, 0x8000001d) instead of calling amd_find_num_cache_leaves() and its direct CPUID queries. Remove the latter function as it is no longer used. Keep using the 'union _cpuid4_leaf_eax/ebx/ecx' data types as they are required by the AMD CPUID(0x4) emulation code. A follow up commit will replace them with their auto-generated x86-cpuid-db equivalents. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 41 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 91020f85c000..86a8e1dad935 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -237,16 +237,22 @@ static int cpuid4_info_fill_done(struct _cpuid4_info = *id4, union _cpuid4_leaf_ea return 0; } =20 -static int amd_fill_cpuid4_info(int index, struct _cpuid4_info *id4) +static int amd_fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct _= cpuid4_info *id4) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; union _cpuid4_leaf_ecx ecx; - u32 ignored; =20 - if (boot_cpu_has(X86_FEATURE_TOPOEXT) || boot_cpu_data.x86_vendor =3D=3D = X86_VENDOR_HYGON) - cpuid_count(0x8000001d, index, &eax.full, &ebx.full, &ecx.full, &ignored= ); - else + if (boot_cpu_has(X86_FEATURE_TOPOEXT) || boot_cpu_data.x86_vendor =3D=3D = X86_VENDOR_HYGON) { + const struct cpuid_regs *regs =3D cpuid_subleaf_n_raw(c, 0x8000001d, ind= ex); + + if (!regs) + return -EIO; + + eax.full =3D regs->eax; + ebx.full =3D regs->ebx; + ecx.full =3D regs->ecx; + } else legacy_amd_cpuid4(index, &eax, &ebx, &ecx); =20 return cpuid4_info_fill_done(id4, eax, ebx, ecx); @@ -270,25 +276,10 @@ static int fill_cpuid4_info(struct cpuinfo_x86 *c, in= t index, struct _cpuid4_inf u8 cpu_vendor =3D boot_cpu_data.x86_vendor; =20 return (cpu_vendor =3D=3D X86_VENDOR_AMD || cpu_vendor =3D=3D X86_VENDOR_= HYGON) ? - amd_fill_cpuid4_info(index, id4) : + amd_fill_cpuid4_info(c, index, id4) : intel_fill_cpuid4_info(c, index, id4); } =20 -static int amd_find_num_cache_leaves(struct cpuinfo_x86 *c) -{ - union _cpuid4_leaf_eax cache_eax; - unsigned int eax, ebx, ecx, edx; - int i =3D -1; - - /* Do a CPUID(0x8000001d) loop to calculate num_cache_leaves */ - do { - ++i; - cpuid_count(0x8000001d, i, &eax, &ebx, &ecx, &edx); - cache_eax.full =3D eax; - } while (cache_eax.split.type !=3D CTYPE_NULL); - return i; -} - /* * The max shared threads number comes from CPUID(0x4) EAX[25-14] with inp= ut * ECX as cache index. Then right shift apicid by the number's order to get @@ -328,10 +319,10 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c,= u16 die_id) * Newer families: LLC ID is calculated from the number * of threads sharing the L3 cache. */ - u32 llc_index =3D amd_find_num_cache_leaves(c) - 1; + u32 llc_index =3D cpuid_subleaf_count(c, 0x8000001d) - 1; struct _cpuid4_info id4 =3D {}; =20 - if (!amd_fill_cpuid4_info(llc_index, &id4)) + if (!amd_fill_cpuid4_info(c, llc_index, &id4)) c->topo.llc_id =3D get_cache_id(c->topo.apicid, &id4); } } @@ -353,7 +344,7 @@ void init_amd_cacheinfo(struct cpuinfo_x86 *c) struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); =20 if (boot_cpu_has(X86_FEATURE_TOPOEXT)) - ci->num_leaves =3D amd_find_num_cache_leaves(c); + ci->num_leaves =3D cpuid_subleaf_count(c, 0x8000001d); else if (c->extended_cpuid_level >=3D 0x80000006) ci->num_leaves =3D (cpuid_edx(0x80000006) & 0xf000) ? 4 : 3; } @@ -362,7 +353,7 @@ void init_hygon_cacheinfo(struct cpuinfo_x86 *c) { struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); =20 - ci->num_leaves =3D amd_find_num_cache_leaves(c); + ci->num_leaves =3D cpuid_subleaf_count(c, 0x8000001d); } =20 static void intel_cacheinfo_done(struct cpuinfo_x86 *c, unsigned int l3, --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 60CB1413D96 for ; Thu, 28 May 2026 15:41:40 +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=1779982904; cv=none; b=uYoNcl3Oc78itxOKJnutRWtqC7XNkHotnX/MkbJLd9NQNmidwUobHTW8+EQmiN1Rj3ab3JJ8kbEv/dN9G5CCk9ajJqVkpBw6dUbAtrO4SY1iJ//25quXlTcrNCTfz71bd6PDNZdJYnaHEyGhD2I3ttVHPCtj5rjgAdqjnsB3hHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982904; c=relaxed/simple; bh=+5160CUx3bMjP4MFYfjyT2v5byZbBbmfyOYp9Lf055I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dNQICKTT+R/Y1Y5jtU23CePx4EeLdVazenSvCNKPhtoqLySxuFvv9ed6zMIWwzmcKpzPzk5DxiLuyYHO2tOF1zOqW7xTSyNisGI6XF21wEn/rdnSbWrT0YOnxBb2QB2JNVfqMFASsyYYK7x8tGiVZ4WPYLjYw2G6w/P2TZuyh9M= 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=Wb37Qe/I; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=06Zpshhe; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wb37Qe/I"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="06Zpshhe" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MeqQN/cTZey7eZJe3LuSGFfFoxDqcsiyXuwKpw5Zhek=; b=Wb37Qe/ISU/mqCjpr13Ze8HJh9Q3gywjndrwjlUsJxOGptfdAWaoWT7g4KnEcMj+UGJQL+ BjDZs6Jz7xNRzVjX9bL6HO5FgL62pWWHBiq3epXyhvDGAP17FRvK7ptZMTCRjxskp39iTB TvkF5Fj4yNag72gHG4X5S03hD3P4gkkH8/qwjyrZhY/sChhLjCQ8Rny7ozo/Na/vit+kqM G5TI+JpN9T9dbm6b4LjYFnachNEZJMg9G+VfhKPHjeIHPues/9XzgI6pCEdZdvkOlEK40E nnVU+zFmeuVeIQ6gkM1QaW1eCPVDYwHd7Y79OKiUu0GvfbVLLzsRWlNnKjl8qA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MeqQN/cTZey7eZJe3LuSGFfFoxDqcsiyXuwKpw5Zhek=; b=06Zpshhe7gRi9gEGXFa9PS/Wtn+YEXVBbs7T8kMiErbaU2utY6ZwCVcgbWB6gyiiUWSIxh Ywj76hVFcf9csvCQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 035/120] x86/cpuid: Parse CPUID(0x80000005), CPUID(0x80000006), CPUID(0x80000008) Date: Thu, 28 May 2026 17:37:57 +0200 Message-ID: <20260528153923.403473-36-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse AMD cacheinfo CPUID(0x80000005) and CPUID(0x80000006). Also parse the CPU capacity parameters at CPUID(0x80000008). This allows converting their call sites to parsed CPUID access instead of issuing CPUID queries. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 3 +++ arch/x86/kernel/cpu/cpuid_parser.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index f77659303569..f50e54bfb514 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -217,6 +217,9 @@ struct cpuid_leaves { CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); CPUID_LEAF ( 0x80000004, 0 ); + CPUID_LEAF ( 0x80000005, 0 ); + CPUID_LEAF ( 0x80000006, 0 ); + CPUID_LEAF ( 0x80000008, 0 ); CPUID_LEAF_N ( 0x8000001d, 8 ); CPUID_LEAF ( 0x80860000, 0 ); CPUID_LEAF ( 0x80860001, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 25ca9b19e8cf..ab391de03a92 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -151,6 +151,9 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000005, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000006, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000008, 0, generic ), \ CPUID_PARSE_ENTRY_N ( 0x8000001d, deterministic_cache ), \ CPUID_PARSE_ENTRY ( 0x80860000, 0, 0x80860000 ), \ CPUID_PARSE_ENTRY ( 0x80860001, 0, generic ), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A6E7741C30B for ; Thu, 28 May 2026 15:41:43 +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=1779982907; cv=none; b=KvpBGrZjIwxpSBg8exM0SIZ+odStkeAiNNOeqFinbTkb4aZxqwA8wXAF7ZigXOuYrcAtIKBDCeMI7r23eeN0TMoppGIYm8cEoA9N2LaRNtXzJjERUV79bVMP+x/zMB0RG9UdTYNnyJdo8dNViY1qtI+3k/4d1poNrvTXkDCC6H4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982907; c=relaxed/simple; bh=h0BXVA4ylCZ9fzoIE+74Nh2dw0+UcGdbMClpz+sfwG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u45LKJrTGxTxUiFf8S0Gz3Ep4x9o8OrqQjEEYLTHB5lx+X2zAXC9+KT/WEliwidfjkAn1lWAgmuDvsvxm6EVe9xeRJXlbizTsB7v1cqYw1tZXyPPvzcb/yVD30sBjvvgRXF9Z7RrFxcpZ5AVfrDXs0dd0uQSI+RIkbDiDXrvztE= 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=o4RwPWqV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=u/WCTP8H; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="o4RwPWqV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="u/WCTP8H" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PSTqrRP3UaNiHd/4AJjBRu1ie73dfUswU8MxnhQ7b9E=; b=o4RwPWqVqGUaD2hc8n2iQPdoXld8PFtwxgVDn8YZc2J3myoZpdXq48Wrj4Yz3JdpUGLSo3 C402z2Y/VzmXL5U+SbWtDm7ZAdWkfasN4T1eOOzItV4ofmXcoiAD0BfUK7YtDyCE1EWShP E64W3Ezxgw6XdUsb7hnAb0XgkY8HoDwV4vasGGM9LmbgqhKAhUcC/GX/aU4d8opzzrmywU iCfZknvZZ1mpxkXfkltdIdjfiCjfw5IqdHiV2C2/BiMbpYvOhg31mNCuLVg0YTHKY8VLZt aSxNMxaWG/Laf6qjxoMa43zFKA3yYG/VOgN2Aekorh0CQWRdzePRdcbxAd2rdA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PSTqrRP3UaNiHd/4AJjBRu1ie73dfUswU8MxnhQ7b9E=; b=u/WCTP8HLQqq4FKFy5D0NVY4QdLOuwpZFxZKMMwyKKmD1CDeGczd7CNR07GTn4oeKDVOWY vUGpvzzcSLyFsfAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 036/120] x86/cacheinfo: Use auto-generated data types Date: Thu, 28 May 2026 17:37:58 +0200 Message-ID: <20260528153923.403473-37-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For the AMD CPUID(0x4) emulation logic, use the auto-generated data type: struct leaf_0x4_n instead of the manually-defined: union _cpuid4_leaf_{eax,ebx,ecx} ones. Remove such unions entirely as they are no longer used. Signed-off-by: Ahmed S. Darwish Link: https://gitlab.com/x86-cpuid.org/x86-cpuid-db --- arch/x86/kernel/cpu/cacheinfo.c | 127 +++++++++++--------------------- 1 file changed, 42 insertions(+), 85 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 86a8e1dad935..209a0c708213 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -41,39 +41,8 @@ enum _cache_type { CTYPE_UNIFIED =3D 3 }; =20 -union _cpuid4_leaf_eax { - struct { - enum _cache_type type :5; - unsigned int level :3; - unsigned int is_self_initializing :1; - unsigned int is_fully_associative :1; - unsigned int reserved :4; - unsigned int num_threads_sharing :12; - unsigned int num_cores_on_die :6; - } split; - u32 full; -}; - -union _cpuid4_leaf_ebx { - struct { - unsigned int coherency_line_size :12; - unsigned int physical_line_partition :10; - unsigned int ways_of_associativity :10; - } split; - u32 full; -}; - -union _cpuid4_leaf_ecx { - struct { - unsigned int number_of_sets :32; - } split; - u32 full; -}; - struct _cpuid4_info { - union _cpuid4_leaf_eax eax; - union _cpuid4_leaf_ebx ebx; - union _cpuid4_leaf_ecx ecx; + struct leaf_0x4_n regs; unsigned int id; unsigned long size; }; @@ -148,17 +117,14 @@ static const unsigned short assocs[] =3D { static const unsigned char levels[] =3D { 1, 1, 2, 3 }; static const unsigned char types[] =3D { 1, 2, 3, 3 }; =20 -static void legacy_amd_cpuid4(int index, union _cpuid4_leaf_eax *eax, - union _cpuid4_leaf_ebx *ebx, union _cpuid4_leaf_ecx *ecx) +static void legacy_amd_cpuid4(int index, struct leaf_0x4_n *regs) { unsigned int dummy, line_size, lines_per_tag, assoc, size_in_kb; union l1_cache l1i, l1d, *l1; union l2_cache l2; union l3_cache l3; =20 - eax->full =3D 0; - ebx->full =3D 0; - ecx->full =3D 0; + *regs =3D (struct leaf_0x4_n){ }; =20 cpuid(0x80000005, &dummy, &dummy, &l1d.val, &l1i.val); cpuid(0x80000006, &dummy, &dummy, &l2.val, &l3.val); @@ -204,71 +170,62 @@ static void legacy_amd_cpuid4(int index, union _cpuid= 4_leaf_eax *eax, return; } =20 - eax->split.is_self_initializing =3D 1; - eax->split.type =3D types[index]; - eax->split.level =3D levels[index]; - eax->split.num_threads_sharing =3D 0; - eax->split.num_cores_on_die =3D topology_num_cores_per_package(); + regs->cache_self_init =3D 1; + regs->cache_type =3D types[index]; + regs->cache_level =3D levels[index]; + regs->num_threads_sharing =3D 0; + regs->num_cores_on_die =3D topology_num_cores_per_package(); =20 if (assoc =3D=3D AMD_CPUID4_FULLY_ASSOCIATIVE) - eax->split.is_fully_associative =3D 1; + regs->fully_associative =3D 1; =20 - ebx->split.coherency_line_size =3D line_size - 1; - ebx->split.ways_of_associativity =3D assoc - 1; - ebx->split.physical_line_partition =3D lines_per_tag - 1; - ecx->split.number_of_sets =3D (size_in_kb * 1024) / line_size / - (ebx->split.ways_of_associativity + 1) - 1; + regs->cache_linesize =3D line_size - 1; + regs->cache_nways =3D assoc - 1; + regs->cache_npartitions =3D lines_per_tag - 1; + regs->cache_nsets =3D (size_in_kb * 1024) / line_size / + (regs->cache_nways + 1) - 1; } =20 -static int cpuid4_info_fill_done(struct _cpuid4_info *id4, union _cpuid4_l= eaf_eax eax, - union _cpuid4_leaf_ebx ebx, union _cpuid4_leaf_ecx ecx) +static int cpuid4_info_fill_done(struct _cpuid4_info *id4, const struct le= af_0x4_n *regs) { - if (eax.split.type =3D=3D CTYPE_NULL) + if (regs->cache_type =3D=3D CTYPE_NULL) return -EIO; =20 - id4->eax =3D eax; - id4->ebx =3D ebx; - id4->ecx =3D ecx; - id4->size =3D (ecx.split.number_of_sets + 1) * - (ebx.split.coherency_line_size + 1) * - (ebx.split.physical_line_partition + 1) * - (ebx.split.ways_of_associativity + 1); + id4->regs =3D *regs; + id4->size =3D (regs->cache_nsets + 1) * + (regs->cache_linesize + 1) * + (regs->cache_npartitions + 1) * + (regs->cache_nways + 1); =20 return 0; } =20 static int amd_fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct _= cpuid4_info *id4) { - union _cpuid4_leaf_eax eax; - union _cpuid4_leaf_ebx ebx; - union _cpuid4_leaf_ecx ecx; + struct leaf_0x4_n l_0x4_regs; =20 if (boot_cpu_has(X86_FEATURE_TOPOEXT) || boot_cpu_data.x86_vendor =3D=3D = X86_VENDOR_HYGON) { - const struct cpuid_regs *regs =3D cpuid_subleaf_n_raw(c, 0x8000001d, ind= ex); + const struct leaf_0x8000001d_n *regs =3D cpuid_subleaf_n(c, 0x8000001d, = index); =20 if (!regs) return -EIO; =20 - eax.full =3D regs->eax; - ebx.full =3D regs->ebx; - ecx.full =3D regs->ecx; + /* CPUID(0x8000001d) and CPUID(0x4) have the same bitfields */ + l_0x4_regs =3D *(struct leaf_0x4_n *)regs; } else - legacy_amd_cpuid4(index, &eax, &ebx, &ecx); + legacy_amd_cpuid4(index, &l_0x4_regs); =20 - return cpuid4_info_fill_done(id4, eax, ebx, ecx); + return cpuid4_info_fill_done(id4, &l_0x4_regs); } =20 static int intel_fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct= _cpuid4_info *id4) { - const struct cpuid_regs *regs =3D cpuid_subleaf_n_raw(c, 0x4, index); + const struct leaf_0x4_n *regs =3D cpuid_subleaf_n(c, 0x4, index); =20 if (!regs) return -EIO; =20 - return cpuid4_info_fill_done(id4, - (union _cpuid4_leaf_eax)(regs->eax), - (union _cpuid4_leaf_ebx)(regs->ebx), - (union _cpuid4_leaf_ecx)(regs->ecx)); + return cpuid4_info_fill_done(id4, regs); } =20 static int fill_cpuid4_info(struct cpuinfo_x86 *c, int index, struct _cpui= d4_info *id4) @@ -290,7 +247,7 @@ static unsigned int get_cache_id(u32 apicid, const stru= ct _cpuid4_info *id4) unsigned long num_threads_sharing; int index_msb; =20 - num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->regs.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); =20 return apicid >> index_msb; @@ -406,7 +363,7 @@ static unsigned int calc_cache_topo_id(struct cpuinfo_x= 86 *c, const struct _cpui unsigned int num_threads_sharing; int index_msb; =20 - num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->regs.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); return c->topo.apicid & ~((1 << index_msb) - 1); } @@ -432,11 +389,11 @@ static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) if (ret < 0) continue; =20 - switch (id4.eax.split.level) { + switch (id4.regs.cache_level) { case 1: - if (id4.eax.split.type =3D=3D CTYPE_DATA) + if (id4.regs.cache_type =3D=3D CTYPE_DATA) l1d =3D id4.size / 1024; - else if (id4.eax.split.type =3D=3D CTYPE_INST) + else if (id4.regs.cache_type =3D=3D CTYPE_INST) l1i =3D id4.size / 1024; break; case 2: @@ -497,7 +454,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, } else if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { unsigned int apicid, nshared, first, last; =20 - nshared =3D id4->eax.split.num_threads_sharing + 1; + nshared =3D id4->regs.num_threads_sharing + 1; apicid =3D cpu_data(cpu).topo.apicid; first =3D apicid - (apicid % nshared); last =3D first + nshared - 1; @@ -544,7 +501,7 @@ static void __cache_cpumap_setup(unsigned int cpu, int = index, } =20 ci =3D this_cpu_ci->info_list + index; - num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->regs.num_threads_sharing; =20 cpumask_set_cpu(cpu, &ci->shared_cpu_map); if (num_threads_sharing =3D=3D 1) @@ -571,13 +528,13 @@ static void ci_info_init(struct cacheinfo *ci, const = struct _cpuid4_info *id4, { ci->id =3D id4->id; ci->attributes =3D CACHE_ID; - ci->level =3D id4->eax.split.level; - ci->type =3D cache_type_map[id4->eax.split.type]; - ci->coherency_line_size =3D id4->ebx.split.coherency_line_size + 1; - ci->ways_of_associativity =3D id4->ebx.split.ways_of_associativity + 1; + ci->level =3D id4->regs.cache_level; + ci->type =3D cache_type_map[id4->regs.cache_type]; + ci->coherency_line_size =3D id4->regs.cache_linesize + 1; + ci->ways_of_associativity =3D id4->regs.cache_nways + 1; ci->size =3D id4->size; - ci->number_of_sets =3D id4->ecx.split.number_of_sets + 1; - ci->physical_line_partition =3D id4->ebx.split.physical_line_partition + = 1; + ci->number_of_sets =3D id4->regs.cache_nsets + 1; + ci->physical_line_partition =3D id4->regs.cache_npartitions + 1; ci->priv =3D nb; } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 F21B641C2F6 for ; Thu, 28 May 2026 15:41:46 +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=1779982909; cv=none; b=Toiv1/dXjHyS5au65tu1UFT9YtmpVRpfkfuvIxdArCmllkK4mHLC8n06rcv6yp+JY4KmCB3tstUsk8eZ1JAJcHWKOYs3+KC973XRmoc9ZKF8natpADF7K6nomsUimjZsUOJWTqoi9y54xd+8ddKZ0gnQ6FK7ph2roVDImtTXp+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982909; c=relaxed/simple; bh=4Uobgi05lwFGgCCIX2zjPYZK8R471mlh44TPDuDud1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F06ScTct5K0h6Ym4mWFFjtiFrTaHn1ClXsRDTIk3fP2trcGglKntne28C0b4KCXVMYwNErxoPH7FTikYH7XIO6GkZ927vkUAHGerZvTokQN9JKNlF9JfGq8wxiLeLWQUJsNYLm+LEuqwNM8UjeOZT2PNwDEEnOUzyo7GrcZlp4A= 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=a8VdSrl0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xW7VrgND; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="a8VdSrl0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xW7VrgND" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aiGfhNyYp68g38e7FWsCeHJurzgGYRzmuGFV0tjptEo=; b=a8VdSrl0YsSwcxnelkCs4ArraSL3GWuEewsUWZ+dm5x+N2ucDvS5GKKNz83kG5PfjlMpkD KWC/SAMH/mllYMIUH5wnIBYW5jzCZz3Psf3ZsOun4qr6Xm5xdxUU8bnEggG6L0TLVAt3K9 Jg4w1aE3A9pFMmFEJ0BCPePx1bBDN2Ero8toUkKfK+p6vKGvKBxabXuFCo8mb3EGPoxP+m /KMr4YSrfr30d5PzWr3L7Nui1XDA2oboVlS+iTkSKUBcczhXWQHuPBBBuZPmUJ1wjmGeM1 kBk9xxrrI5yuZ+SnfQbj7OacOCewCCiyCpwuvr8E4ZUaAI3bduh3KFNpK86vZQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982905; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aiGfhNyYp68g38e7FWsCeHJurzgGYRzmuGFV0tjptEo=; b=xW7VrgNDyZUhy0+AI9tX4mxeEGK+bJXqR9MZaYLId+BXi82Km9maI5cp9ehOpsBmpBJjZB uGmrNbNcDHQ2G3AA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 037/120] x86/cacheinfo: Use parsed CPUID(0x80000005) and CPUID(0x80000006) Date: Thu, 28 May 2026 17:37:59 +0200 Message-ID: <20260528153923.403473-38-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD CPUID(0x4)-emulation logic, use parsed CPUID(0x80000005) and CPUID(0x80000006) instead of invoking CPUID queries. Beside the CPUID parser centralization benefits, this allows using the auto generated x86-cpuid-db data types, and their C99 bitfields, instead of doing ugly bitwise operations or defining custom call site types. Remove the 'union l[123]_cache' data types as they are no longer needed. Replace the expression: ci->num_leaves =3D (cpuid_edx(0x80000006) & 0xf000) ? 4 : 3; with: ci->num_leaves =3D cpuid_leaf(c, 0x80000006)->l3_assoc ? 4 : 3; since per AMD manuals, an L3 associativity level of zero implies the absence of a CPU L3 cache. While at it, separate the "Fallback AMD CPUID(0x4) emulation" comment from the "AMD_L2_L3_INVALID_ASSOC" one. The former is as a code section header. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 103 +++++++++++++------------------- 1 file changed, 40 insertions(+), 63 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 209a0c708213..7dab0d7152cc 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -56,47 +56,17 @@ static const enum cache_type cache_type_map[] =3D { }; =20 /* - * Fallback AMD CPUID(0x4) emulation + * Fallback AMD CPUID(0x4) emulation: * AMD CPUs with TOPOEXT can just use CPUID(0x8000001d) - * + */ + +/* * @AMD_L2_L3_INVALID_ASSOC: cache info for the respective L2/L3 cache sho= uld * be determined from CPUID(0x8000001d) instead of CPUID(0x80000006). */ - #define AMD_CPUID4_FULLY_ASSOCIATIVE 0xffff #define AMD_L2_L3_INVALID_ASSOC 0x9 =20 -union l1_cache { - struct { - unsigned line_size :8; - unsigned lines_per_tag :8; - unsigned assoc :8; - unsigned size_in_kb :8; - }; - unsigned int val; -}; - -union l2_cache { - struct { - unsigned line_size :8; - unsigned lines_per_tag :4; - unsigned assoc :4; - unsigned size_in_kb :16; - }; - unsigned int val; -}; - -union l3_cache { - struct { - unsigned line_size :8; - unsigned lines_per_tag :4; - unsigned assoc :4; - unsigned res :2; - unsigned size_encoded :14; - }; - unsigned int val; -}; - /* L2/L3 associativity mapping */ static const unsigned short assocs[] =3D { [1] =3D 1, @@ -117,50 +87,52 @@ static const unsigned short assocs[] =3D { static const unsigned char levels[] =3D { 1, 1, 2, 3 }; static const unsigned char types[] =3D { 1, 2, 3, 3 }; =20 -static void legacy_amd_cpuid4(int index, struct leaf_0x4_n *regs) +static void legacy_amd_cpuid4(struct cpuinfo_x86 *c, int index, struct lea= f_0x4_n *regs) { - unsigned int dummy, line_size, lines_per_tag, assoc, size_in_kb; - union l1_cache l1i, l1d, *l1; - union l2_cache l2; - union l3_cache l3; + const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); + const struct leaf_0x80000006_0 *el6 =3D cpuid_leaf(c, 0x80000006); + const struct cpuid_regs *el5_raw =3D cpuid_leaf_raw(c, 0x80000005); + unsigned int line_size, lines_per_tag, assoc, size_in_kb; =20 *regs =3D (struct leaf_0x4_n){ }; =20 - cpuid(0x80000005, &dummy, &dummy, &l1d.val, &l1i.val); - cpuid(0x80000006, &dummy, &dummy, &l2.val, &l3.val); - - l1 =3D &l1d; switch (index) { - case 1: - l1 =3D &l1i; - fallthrough; case 0: - if (!l1->val) + if (!el5 || !el5_raw->ecx) return; =20 - assoc =3D (l1->assoc =3D=3D 0xff) ? AMD_CPUID4_FULLY_ASSOCIATIVE : l1->= assoc; - line_size =3D l1->line_size; - lines_per_tag =3D l1->lines_per_tag; - size_in_kb =3D l1->size_in_kb; + assoc =3D el5->l1_dcache_assoc; + line_size =3D el5->l1_dcache_line_size; + lines_per_tag =3D el5->l1_dcache_nlines; + size_in_kb =3D el5->l1_dcache_size_kb; + break; + case 1: + if (!el5 || !el5_raw->edx) + return; + + assoc =3D el5->l1_icache_assoc; + line_size =3D el5->l1_icache_line_size; + lines_per_tag =3D el5->l1_icache_nlines; + size_in_kb =3D el5->l1_icache_size_kb; break; case 2: - if (!l2.assoc || l2.assoc =3D=3D AMD_L2_L3_INVALID_ASSOC) + if (!el6 || !el6->l2_assoc || el6->l2_assoc =3D=3D AMD_L2_L3_INVALID_ASS= OC) return; =20 /* Use x86_cache_size as it might have K7 errata fixes */ - assoc =3D assocs[l2.assoc]; - line_size =3D l2.line_size; - lines_per_tag =3D l2.lines_per_tag; + assoc =3D assocs[el6->l2_assoc]; + line_size =3D el6->l2_line_size; + lines_per_tag =3D el6->l2_nlines; size_in_kb =3D __this_cpu_read(cpu_info.x86_cache_size); break; case 3: - if (!l3.assoc || l3.assoc =3D=3D AMD_L2_L3_INVALID_ASSOC) + if (!el6 || !el6->l3_assoc || el6->l3_assoc =3D=3D AMD_L2_L3_INVALID_ASS= OC) return; =20 - assoc =3D assocs[l3.assoc]; - line_size =3D l3.line_size; - lines_per_tag =3D l3.lines_per_tag; - size_in_kb =3D l3.size_encoded * 512; + assoc =3D assocs[el6->l3_assoc]; + line_size =3D el6->l3_line_size; + lines_per_tag =3D el6->l3_nlines; + size_in_kb =3D el6->l3_size_range * 512; if (boot_cpu_has(X86_FEATURE_AMD_DCM)) { size_in_kb =3D size_in_kb >> 1; assoc =3D assoc >> 1; @@ -170,6 +142,10 @@ static void legacy_amd_cpuid4(int index, struct leaf_0= x4_n *regs) return; } =20 + /* For L1d and L1i caches, 0xff is the full associativity marker */ + if ((index =3D=3D 0 || index =3D=3D 1) && assoc =3D=3D 0xff) + assoc =3D AMD_CPUID4_FULLY_ASSOCIATIVE; + regs->cache_self_init =3D 1; regs->cache_type =3D types[index]; regs->cache_level =3D levels[index]; @@ -213,7 +189,7 @@ static int amd_fill_cpuid4_info(struct cpuinfo_x86 *c, = int index, struct _cpuid4 /* CPUID(0x8000001d) and CPUID(0x4) have the same bitfields */ l_0x4_regs =3D *(struct leaf_0x4_n *)regs; } else - legacy_amd_cpuid4(index, &l_0x4_regs); + legacy_amd_cpuid4(c, index, &l_0x4_regs); =20 return cpuid4_info_fill_done(id4, &l_0x4_regs); } @@ -298,12 +274,13 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *= c) =20 void init_amd_cacheinfo(struct cpuinfo_x86 *c) { + const struct leaf_0x80000006_0 *el6 =3D cpuid_leaf(c, 0x80000006); struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); =20 if (boot_cpu_has(X86_FEATURE_TOPOEXT)) ci->num_leaves =3D cpuid_subleaf_count(c, 0x8000001d); - else if (c->extended_cpuid_level >=3D 0x80000006) - ci->num_leaves =3D (cpuid_edx(0x80000006) & 0xf000) ? 4 : 3; + else if (el6) + ci->num_leaves =3D (el6->l3_assoc) ? 4 : 3; } =20 void init_hygon_cacheinfo(struct cpuinfo_x86 *c) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 1C98B41B369 for ; Thu, 28 May 2026 15:41:49 +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=1779982911; cv=none; b=Pi+/jOeUudow9WDT9zUwLW3OEu78v4LAtMj9f8wVTRrHZDTEhHJNf2SuTGMxdIMvCyXExD53odYbRZhfFZE5aIObWk/+l/UQRxEv4NQvX8Kd0mkRcEVwrxWmknSo0HmMFIbacE0GRCOphfNCs03hu7ZgSsYVKJKeHT2+Ds6Nc5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982911; c=relaxed/simple; bh=u74xiCZHSHXLNvgTjRmIVTA9pWovHlOz8YhmMxVR/qU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=stghVdwF2BsHqQUuGqHDMqLTWQAP11QqVAB9EQ+4JaLRCkqDQvXoq0ZBRIFG9gKCcmqvaJF4R4xQyZQP/ni3o2gRk0zybUILqtKnv7kIno8rY/WRG8czpuckxnfMJln+eDKLDm3fbokSTE+0bpwi6R+evi/h0RG4YbAfz0qpOfs= 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=E8d14iEq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bsIY7vN+; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E8d14iEq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bsIY7vN+" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u+56/9BbScZtE3iCsmY5n2kRW8Y+J/nkE1ONDKXlgJ0=; b=E8d14iEqhrSUucWq0TFexJklOAaVl1Itju9iovFatmcPctdZyv0OdscEVDGkonlDJpZGFR U1xisNVoT5/bDUZT65KkyxVjbeX6dRtenJUaQUSYFjCYwz5SJbu5Lsx0il5oSXVV3r+JM4 OXHGyJljTmymDmk8qPN12AY+/ihxcgXZzZR9jCztw9GWiTM5XPdAHtZPwnv/ZBojYvtgS6 cFvGJYILgNeERbQlmvtDd6NqVBlnLS2WgVWmZjg4dPpg6Z2YZDOd9F+ogTPXr0gLWaJk5F QHpkD+X2R3nZWjEspgMu9dwJC5AoJ/nB2D+mxndw/azLr3PqC7fWEBoe+SWuAA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u+56/9BbScZtE3iCsmY5n2kRW8Y+J/nkE1ONDKXlgJ0=; b=bsIY7vN+HUuy+PwtEOA7eK1DrDq+kAeCrtFLllejIwgZT72EwHLOfJ3o9DgUttTkI2oAnO D4pVNjS06mVrQ0Aw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 038/120] x86/cacheinfo: Use parsed CPUID(0x80000006) Date: Thu, 28 May 2026 17:38:00 +0200 Message-ID: <20260528153923.403473-39-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD cacheinfo, use parsed CPUID(0x80000006) instead of issuing a direct CPUID query. Beside the CPUID parser centralization benefits, this allows using the auto-generated x86-cpuid-db data types, and their C99 bitfields, instead of doing ugly bitwise operations on CPUID output. For enumerating L3 cache availability, check if CPUID(0x80000006).EDX l3_assoc output is not zero. Per AMD manuals, an L3 associativity of zero implies the absence of a CPU L3 cache. Since cpuid_amd_hygon_has_l3_cache() is now using the CPUID parser APIs, move its definition under the section: "Convenience leaf-specific functions (using parsed CPUID)." Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 20 +++++++++++--------- arch/x86/kernel/amd_nb.c | 3 ++- arch/x86/kernel/cpu/cacheinfo.c | 6 +++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index f4bdfe3c9325..611ee8596115 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -212,15 +212,6 @@ static inline u32 cpuid_base_hypervisor(const char *si= g, u32 leaves) return 0; } =20 -/* - * CPUID(0x80000006) parsing: - */ - -static inline bool cpuid_amd_hygon_has_l3_cache(void) -{ - return cpuid_edx(0x80000006); -} - /* * 'struct cpuid_leaves' accessors (without sanity checks): * @@ -502,6 +493,17 @@ static inline bool cpuid_amd_hygon_has_l3_cache(void) _ptr < &((const union leaf_0x2_regs *)(_regs))->desc[16] && (_desc = =3D &cpuid_0x2_table[*_ptr]);\ _ptr++) =20 +/* + * CPUID(0x80000006) + */ + +static inline bool cpuid_amd_hygon_has_l3_cache(struct cpuinfo_x86 *c) +{ + const struct leaf_0x80000006_0 *el6 =3D cpuid_leaf(c, 0x80000006); + + return el6 && el6->l3_assoc; +} + /* * CPUID parser exported APIs: */ diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index 5d364540673d..06ebbd564945 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -16,6 +16,7 @@ =20 #include #include +#include =20 static u32 *flush_words; =20 @@ -93,7 +94,7 @@ static int amd_cache_northbridges(void) if (amd_gart_present()) amd_northbridges.flags |=3D AMD_NB_GART; =20 - if (!cpuid_amd_hygon_has_l3_cache()) + if (!cpuid_amd_hygon_has_l3_cache(&boot_cpu_data)) return 0; =20 /* diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 7dab0d7152cc..3e40bcca1c3b 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -235,7 +235,7 @@ static unsigned int get_cache_id(u32 apicid, const stru= ct _cpuid4_info *id4) =20 void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) { - if (!cpuid_amd_hygon_has_l3_cache()) + if (!cpuid_amd_hygon_has_l3_cache(c)) return; =20 if (c->x86 < 0x17) { @@ -262,7 +262,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u= 16 die_id) =20 void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) { - if (!cpuid_amd_hygon_has_l3_cache()) + if (!cpuid_amd_hygon_has_l3_cache(c)) return; =20 /* @@ -280,7 +280,7 @@ void init_amd_cacheinfo(struct cpuinfo_x86 *c) if (boot_cpu_has(X86_FEATURE_TOPOEXT)) ci->num_leaves =3D cpuid_subleaf_count(c, 0x8000001d); else if (el6) - ci->num_leaves =3D (el6->l3_assoc) ? 4 : 3; + ci->num_leaves =3D cpuid_amd_hygon_has_l3_cache(c) ? 4 : 3; } =20 void init_hygon_cacheinfo(struct cpuinfo_x86 *c) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 DEA05421F12 for ; Thu, 28 May 2026 15:41:52 +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=1779982914; cv=none; b=ohLFaD0bbhWzYoIaKdEQ5GN2+tVPtrB+/sEXlEY1L5rH24pzf6tQ4oBDrsnM8zzhuPKa8AOj1T32Q7c/99MdDN982N8I6yRnGS02NyO/86s3jnfCNIrM+xMPFkv1UOQp4vSc6hL+9N7eldBBlH1/cV+EupFwNmGCbExLOTW9Bgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982914; c=relaxed/simple; bh=K9Hd9KRBXXzaoWZRUxkIIh8zCbwff5DN1ZoYoC3OR/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uZGRn8GDjQnhXfEoyu6NWeyYzUHW0R3D1ZB7E52gzS1YnvzAIQPNh4ZqDjumqw2j+m40iHc38wfP3oNPhc7uV0SKbnLYWxUL1lr8muCjhlIDAGm/W4aUICl6vSX0Xo/BM2EkGUR0aGtKjNaxG9RU0odw4LhHx0v0L+OXDynIk9s= 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=u6pNDoU3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=B897kNhf; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="u6pNDoU3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="B897kNhf" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DX68GFCCdUlwvGFnyuuOptO176Td4/bZkuAoc6lLyhU=; b=u6pNDoU3uikxShoZofcI490aiZw9RNG8jz/yRacXJmjJCCsW93AiFsig6XOahqsCcqJ2PH FhstGJcQRQbrCSO98cqgu8JG3xpRN2mDMgqgj63yp01GO9KD9bABnOMxWaJdqIyirnAC+A APFg7QMhN3sCv8x5kof95Oo3IwV4wXIuAIKlGpsJsJGeCwBeTxM6GwD5G9AJJHgE/0FaB9 BZi1VDu8Pil/V1ujIiWj37wVoCUWtRG2cDgiZB/6Agabat4rySaSIrohe5U5pSlRyrSdpd gbI1J1SkssCeSRASgY8OLC8rPMkQ25uVwz7Mxfv3Jq7l3213hQTl9+5FxOALbQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982911; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DX68GFCCdUlwvGFnyuuOptO176Td4/bZkuAoc6lLyhU=; b=B897kNhfeYivZF+3g1Ra/KYaoNV7JWm7NKKovkVisTyiUKLp1iNW0E/MXUr+4YO4NIOcZb vej6NhJa04vwOPBQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 039/120] x86/cpu: Use parsed CPUID(0x80000005) and CPUID(0x80000006) Date: Thu, 28 May 2026 17:38:01 +0200 Message-ID: <20260528153923.403473-40-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x80000005) and CPUID(0x80000006) instead of issuing CPUID queries and doing ugly bitwise operations. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 67dd2c5b9680..d8e46eb0f5c5 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -859,27 +859,26 @@ static void get_model_name(struct cpuinfo_x86 *c) =20 void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) { - unsigned int n, dummy, ebx, ecx, edx, l2size; + const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); + const struct leaf_0x80000006_0 *el6 =3D cpuid_leaf(c, 0x80000006); + unsigned int l2size; =20 - n =3D c->extended_cpuid_level; - - if (n >=3D 0x80000005) { - cpuid(0x80000005, &dummy, &ebx, &ecx, &edx); - c->x86_cache_size =3D (ecx>>24) + (edx>>24); + if (el5) { + c->x86_cache_size =3D el5->l1_dcache_size_kb + el5->l1_icache_size_kb; #ifdef CONFIG_X86_64 /* On K8 L1 TLB is inclusive, so don't count it */ c->x86_tlbsize =3D 0; #endif } =20 - if (n < 0x80000006) /* Some chips just has a large L1. */ + /* Some chips only have a large L1 */ + if (!el6) return; =20 - cpuid(0x80000006, &dummy, &ebx, &ecx, &edx); - l2size =3D ecx >> 16; + l2size =3D el6->l2_size_kb; =20 #ifdef CONFIG_X86_64 - c->x86_tlbsize +=3D ((ebx >> 16) & 0xfff) + (ebx & 0xfff); + c->x86_tlbsize +=3D el6->l2_dtlb_4k_nentries + el6->l2_itlb_4k_nentries; #else /* do processor-specific cache resizing */ if (this_cpu->legacy_cache_size) @@ -889,8 +888,9 @@ void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) if (cachesize_override !=3D -1) l2size =3D cachesize_override; =20 + /* Again, no L2 cache is possible */ if (l2size =3D=3D 0) - return; /* Again, no L2 cache is possible */ + return; #endif =20 c->x86_cache_size =3D l2size; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 0FC1A425CF9 for ; Thu, 28 May 2026 15:41:57 +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=1779982919; cv=none; b=rsD/uV4XIByuXlZhpBPa4Qc0OdGoD4CrT6eu8v8MoO2lmsGw8wTfq4uzsDLy4nlzn85GcM3EEjNrvY6G5Y4J4ShXouuhC1Y6WgsZVDXPuf1cuH6tXujjusVdOrVGZGgvp+16zih2tbhjEP6Y5+anKe2A+p2/uWoKh1IfYZ3HIzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982919; c=relaxed/simple; bh=GzAUVyIogj6AouCFNHtpIwBgpkyL9Xs+cgNMrHo2xTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M7DCzEKw4x2ypuGQx1A0ohBpuAFjPo+702Zo4yqY2xePXvFS9bPXjoEOiACUCXEvIcLEwYCnv/L3kXhLGMoHPcKhF2cSfcE2ruIeCEbQfX/ANI/vzWsx+ozKcQENGu6jaVt+Y7btaB0GXxVVRp3sY9GdTZ4PIlLOZe10GK+ndH4= 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=VSKnHeHg; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cwup18nL; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VSKnHeHg"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cwup18nL" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0x06ll8spNqNNsBVO/bvbZgTxlsANK8gWX8aScs9QVE=; b=VSKnHeHgp2Rj6J8M6gKtZ2aDUDzmeEuc5rPbX8yAGvazxkigK7mUKjPvE4vSB7p1bDYVQK ZT1zIYi/UBNxxevWGos7Ejgn7uvP2j7syvsi7qRrP+mz1qK7QyP061AkxIDNGz8qqdX7Mn zRCNXc7uou+a7Hwm1GlpEEC2SD5JXjl+gxHeJe4JnIDh3eMKjQDaDbf/IRqkwn/2PM+fB9 y0GP9WY0zmbL6gT6N7l/iXMONJF5KG3cxl4A6ZRZNiSG3sb9I6Dh7W+teDQVEEtfmjxhrG hu5q1oT66PnQV1NGBEdM2M8cPPFg/XeAt3KzFoCBJZcrYIlk0IQHN9qwshU2Iw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0x06ll8spNqNNsBVO/bvbZgTxlsANK8gWX8aScs9QVE=; b=cwup18nLv7fJdMbAtA6ED7TWsblPNHHHcmcWGMIGWH2jH1MXusUe3yTFtITNbfike3Tdqz eBpsm1peP0qbuQBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 040/120] x86/cpu/amd: Use parsed CPUID(0x80000005) Date: Thu, 28 May 2026 17:38:02 +0200 Message-ID: <20260528153923.403473-41-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD BSP init, use parsed CPUID(0x80000005) instead of issuing a direct CPUID query and doing ugly bitwise operations. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 62f74a7f2f8d..4fa16f2fd402 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -422,6 +423,8 @@ static void tsa_init(struct cpuinfo_x86 *c) =20 static void bsp_init_amd(struct cpuinfo_x86 *c) { + const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { =20 if (c->x86 > 0x10 || @@ -434,13 +437,8 @@ static void bsp_init_amd(struct cpuinfo_x86 *c) } } =20 - if (c->x86 =3D=3D 0x15) { - unsigned long upperbit; - u32 cpuid, assoc; - - cpuid =3D cpuid_edx(0x80000005); - assoc =3D cpuid >> 16 & 0xff; - upperbit =3D ((cpuid >> 24) << 10) / assoc; + if (c->x86 =3D=3D 0x15 && el5) { + unsigned long upperbit =3D (el5->l1_icache_size_kb * SZ_1K) / el5->l1_ic= ache_assoc; =20 va_align.mask =3D (upperbit - 1) & PAGE_MASK; va_align.flags =3D ALIGN_VA_32 | ALIGN_VA_64; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 9D2B43F6C56 for ; Thu, 28 May 2026 15:42:00 +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=1779982925; cv=none; b=oBsVqqua3+5IB/ezgPTjEPpqkpK7zOqsVIySJWLWc020O0pC2aczLXSrMzzoNXHPkCfvKPc0c62kcb/Ti5O2l9KcMx4//UgtpWfqWGGajbV79BXUQVxwRKT6WAjdbnB59ox+Viah4LSLN6HmHtGWBkyX6x8LwcTwl84mFCHB8kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982925; c=relaxed/simple; bh=ls52o/+0n/oyBy5+3dcjZ3Jn6o3kFQh2nb/7fu/2Hwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uQQwwFu8gBRDMyTcSS4fjXxlqSveVFeE5CJT/SsE4klPTybz53dtBDpZBu3tQ2P5dwlVMuYdybz77pSNsAAY/471hxFI5FI83A04k8+WsGgN5mpjsg4y9phyDw5wAMTZL/j6mSdXGai/XM/EyzyBC76c3y/DqwFED8DFTC3ZKEo= 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=WrPXlghP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oSRvCf45; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WrPXlghP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oSRvCf45" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kuibS2UE6uskMT++84iYFg6jbKd27L4S+aSTBgNRgLE=; b=WrPXlghPgdNrqA92ZgCGcYgYxrJt2NA2K3FUJw+o7+eiUmYFt5GdFhAakwmCxXsu2U8w6E //IerS9UhHy/DWckZMF1qg86TN9Y/I4tTXjEvGAv5SivEW0NeJ334DHsQZgKcnDsvcimsg P030DXUDxcjZ/27yaZ9cwvYXKib9874VQZktE86lPV+of92YIm1xo7A3LqDmF8MZweWWeS wJ01YA14AUPg5wALWX6PFWg6ZSzwp8Qs4Yr8TB8ONmryoDnD5+jBlZBIaMZ2r2jhz2I+ii IBJoWbgSvagDQQFoOKLeqFEvC4Z9bzTxOuhXat/8KFlEO6i27/WTJ8+uPi87hw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kuibS2UE6uskMT++84iYFg6jbKd27L4S+aSTBgNRgLE=; b=oSRvCf45KFYqOxXD+62eqNnwgxrinm+56FKtQvr2G9YoHHV8/GqOTN2QZ+7HqYa2tAAPb5 7SqQvMxfsMy/vcDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 041/120] x86/cpu/amd: Refactor TLB detection code Date: Thu, 28 May 2026 17:38:03 +0200 Message-ID: <20260528153923.403473-42-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" AMD's TLB init code fills below global variables: - tlb_lld_4k, tlb_lli_4k - tlb_lld_2m, tlb_lli_2m - tlb_lld_4m, tlb_lli_4m CPUID(0x80000006) reports these DTLB/ITLB numbers for L2, while CPUID(0x80000005) reports such numbers for L1. The code sets these variables with the L2 numbers by default. If the latter is not available, then the L1 numbers are used as a fallback. Refactor the TLB init logic before converting it to the parsed CPUID API. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd.c | 54 ++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 4fa16f2fd402..36276a21b840 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1186,50 +1186,40 @@ static unsigned int amd_size_cache(struct cpuinfo_x= 86 *c, unsigned int size) =20 static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c) { - u32 ebx, eax, ecx, edx; - u16 mask =3D 0xfff; + u32 l2_tlb_eax, l2_tlb_ebx, l1_tlb_eax; + u16 l2_mask =3D 0xfff, l1_mask =3D 0xff; =20 - if (c->x86 < 0xf) + if (c->x86 < 0xf || c->extended_cpuid_level < 0x80000006) return; =20 - if (c->extended_cpuid_level < 0x80000006) - return; - - cpuid(0x80000006, &eax, &ebx, &ecx, &edx); + l2_tlb_eax =3D cpuid_eax(0x80000006); + l2_tlb_ebx =3D cpuid_ebx(0x80000006); + l1_tlb_eax =3D cpuid_eax(0x80000005); =20 - tlb_lld_4k =3D (ebx >> 16) & mask; - tlb_lli_4k =3D ebx & mask; + tlb_lld_4k =3D (l2_tlb_ebx >> 16) & l2_mask; + tlb_lli_4k =3D l2_tlb_ebx & l2_mask; =20 /* - * K8 doesn't have 2M/4M entries in the L2 TLB so read out the L1 TLB - * characteristics from the CPUID function 0x80000005 instead. + * K8 does not report 2M/4M entries in the L2 TLB, so always use + * the L1 TLB information there. On later CPUs, fall back to L1 + * when the L2 entry count is zero. */ - if (c->x86 =3D=3D 0xf) { - cpuid(0x80000005, &eax, &ebx, &ecx, &edx); - mask =3D 0xff; - } =20 - /* Handle DTLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ - if (!((eax >> 16) & mask)) - tlb_lld_2m =3D (cpuid_eax(0x80000005) >> 16) & 0xff; - else - tlb_lld_2m =3D (eax >> 16) & mask; - - /* a 4M entry uses two 2M entries */ - tlb_lld_4m =3D tlb_lld_2m >> 1; + tlb_lld_2m =3D (l2_tlb_eax >> 16) & l2_mask; + if (c->x86 =3D=3D 0xf || !tlb_lld_2m) + tlb_lld_2m =3D (l1_tlb_eax >> 16) & l1_mask; =20 - /* Handle ITLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ - if (!(eax & mask)) { + tlb_lli_2m =3D l2_tlb_eax & l2_mask; + if (c->x86 =3D=3D 0xf || !tlb_lli_2m) { /* Erratum 658 */ - if (c->x86 =3D=3D 0x15 && c->x86_model <=3D 0x1f) { + if (c->x86 =3D=3D 0x15 && c->x86_model <=3D 0x1f) tlb_lli_2m =3D 1024; - } else { - cpuid(0x80000005, &eax, &ebx, &ecx, &edx); - tlb_lli_2m =3D eax & 0xff; - } - } else - tlb_lli_2m =3D eax & mask; + else + tlb_lli_2m =3D l1_tlb_eax & l1_mask; + } =20 + /* A 4M entry uses two 2M entries */ + tlb_lld_4m =3D tlb_lld_2m >> 1; tlb_lli_4m =3D tlb_lli_2m >> 1; =20 /* Max number of pages INVLPGB can invalidate in one shot */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A40EE3FBED1 for ; Thu, 28 May 2026 15:42:03 +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=1779982930; cv=none; b=L1NMypYAoQItWY22ajEm6tfVlzK0T8t6JN9HKLK9y1ypBOohy8y5GGdIXz7p9hcJRSl+OrtWPNrdAv/YjT9Fpjo2D5M8b5p7CmJhv4pIWPkZ/p+4lW1hFCRyNovMIgvnafIITsPCWL4WyXAb5YiL0C5+Ih7Zff9HW6iVilVjcTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982930; c=relaxed/simple; bh=jaR3cKV9wO0opnz5SEB9YrjqoO+iFvaaL0OOr0qBijM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cJW20bDlXCfGJ9vXaRVpxQruDEN674IuN4ATJ9c1s4vLCiALJVyUghlFJSsjaxtVCC4HQ3g2jXL49WnFFE/lPDTZX2YwRQpYU0OrXTmFEM6HlcmS2EfDVMq9evFrrIiIfEo2KFBjKNz0SsQpHK9hHwCarIZbznaBxJWJwoFXqqw= 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=Zz56L23L; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6Q6osTmE; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Zz56L23L"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6Q6osTmE" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WDpd4Vd4cRA9btC/46nogzrNmedlT9Ey6oVyVY5keuI=; b=Zz56L23Lf0uQj6rmKtdAtY3WN+BQYj9CFkstD5T84rKrrckoc/US1ZTRgYv88fhbGCewYe I+CXq8wIN72bQDI8PPozqaN9i5qGVO8Dcb69ZBa3KpZREHLvdSxhT0h1PSlUCxCc9bMlW+ hX9xqfCDkEQPCOo56dm+T+gXVlQ8ftIxKS+XFTP7+bhRtJpPL+gMKdyKoeFPtSDefFBKKQ DXVC1RZkwJ2hC0/JL9sEiRN5PxMibwKialVKoH9kgBqTpfSaPjSKS9v6GnSpOOtxO0Un/q 1tALxg+ImFeCik9DWlkGzPJV91cy0muwNd9e+o22xg3a8V6UCK6P9B7Fsl58oA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WDpd4Vd4cRA9btC/46nogzrNmedlT9Ey6oVyVY5keuI=; b=6Q6osTmEGXWW0UtBVsL34RcdMPBI0NUhWWKo2XjrBtlBA2iwk2PeOKXuo6HwgM1KIUbKDu SmC9x41VbIPvbOCQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 042/120] x86/cpu/amd: Use parsed CPUID(0x80000005) and CPUID(0x80000006) Date: Thu, 28 May 2026 17:38:04 +0200 Message-ID: <20260528153923.403473-43-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD TLB detection, use parsed CPUID(0x80000005) and CPUID(0x80000006) instead of direct CPUID queries and ugly bitwise operations. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 36276a21b840..50bbf9f33501 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1186,18 +1186,14 @@ static unsigned int amd_size_cache(struct cpuinfo_x= 86 *c, unsigned int size) =20 static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c) { - u32 l2_tlb_eax, l2_tlb_ebx, l1_tlb_eax; - u16 l2_mask =3D 0xfff, l1_mask =3D 0xff; + const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); + const struct leaf_0x80000006_0 *el6 =3D cpuid_leaf(c, 0x80000006); =20 - if (c->x86 < 0xf || c->extended_cpuid_level < 0x80000006) + if (c->x86 < 0xf || !el5 || !el6) return; =20 - l2_tlb_eax =3D cpuid_eax(0x80000006); - l2_tlb_ebx =3D cpuid_ebx(0x80000006); - l1_tlb_eax =3D cpuid_eax(0x80000005); - - tlb_lld_4k =3D (l2_tlb_ebx >> 16) & l2_mask; - tlb_lli_4k =3D l2_tlb_ebx & l2_mask; + tlb_lld_4k =3D el6->l2_dtlb_4k_nentries; + tlb_lli_4k =3D el6->l2_itlb_4k_nentries; =20 /* * K8 does not report 2M/4M entries in the L2 TLB, so always use @@ -1205,17 +1201,17 @@ static void cpu_detect_tlb_amd(struct cpuinfo_x86 *= c) * when the L2 entry count is zero. */ =20 - tlb_lld_2m =3D (l2_tlb_eax >> 16) & l2_mask; + tlb_lld_2m =3D el6->l2_dtlb_2m_4m_nentries; if (c->x86 =3D=3D 0xf || !tlb_lld_2m) - tlb_lld_2m =3D (l1_tlb_eax >> 16) & l1_mask; + tlb_lld_2m =3D el5->l1_dtlb_2m_4m_nentries; =20 - tlb_lli_2m =3D l2_tlb_eax & l2_mask; + tlb_lli_2m =3D el6->l2_itlb_2m_4m_nentries; if (c->x86 =3D=3D 0xf || !tlb_lli_2m) { /* Erratum 658 */ if (c->x86 =3D=3D 0x15 && c->x86_model <=3D 0x1f) tlb_lli_2m =3D 1024; else - tlb_lli_2m =3D l1_tlb_eax & l1_mask; + tlb_lli_2m =3D el5->l1_itlb_2m_4m_nentries; } =20 /* A 4M entry uses two 2M entries */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 BBD81426D0A for ; Thu, 28 May 2026 15:42:06 +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=1779982933; cv=none; b=lQldCpaErlUzgC/cEtHiwNohP8N8NIeMeYEsSEYv6G6oe0Kk6FkbFA9WPLHPXzNRf3d10S9TbhITf24/DCh5irid+j4vBbUJOzUxkYzuE3eAu78qsD2DDV0H8r6vgFr34tmiwVYC/re9tyqvL49ChRU7KlX0I50tDSem5+LVR8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982933; c=relaxed/simple; bh=o7nCI0supCtVW4W+1kVJUIuf25pCI3qhaeHkIcNn/fo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lK31r6agq+SrNwna0WAYLzMdjyeSosokg5ofiyp04+hhNNA1PfDLSxKlYPsVOeREgBEuSnF9dEnXPrBmFx9dhB8xCXLbirkY9zy4uUh/NZJMB6r1GjLx8WHMe/NjNYp1fSNwjcqMc47T5TZcqHxBRdiUwmIq1EwD9W49OMEY/pU= 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=101K6kzf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Qtl8LuGo; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="101K6kzf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Qtl8LuGo" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W/fIK0E8z0Ml5W1Krli7k2nqmXNcjvGhQsxgYl+RdTE=; b=101K6kzfimDOsRXhNcaBqyzDlxdRLH3niFlWKwFQI4Z6uuSRWfaYNm0I0lWXTw7OHvYAYy TBx6RMLPguMsD0q0pc6zP+qFNBINO3cBqrGYDUACAVB/OMPFHBBSnTvXbDov6UE7bgezbR RO8pZhNoA8tMxsww7Vq1Iwj/r7DhBPtcs9u8qHku+v+D1zrfst8NyPg50mGMQZX4V5A1rP tQxw/VyNAmV8dYBHxh/AmCZ5qzLVDxWzV5497LCprdNyv2Isc3CdtwPzNP38d1BAZW1MNy tY1Ok1a1oDZeDWPHyN4ZminGDzvwIUdMed3RZlNdmaGiRg2kd/XARxTdtx/6yA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W/fIK0E8z0Ml5W1Krli7k2nqmXNcjvGhQsxgYl+RdTE=; b=Qtl8LuGo6gMLTbkvvW7RCViBbuYq5TuuQ2TqNQ+s2UhVtR0scZWU8FCt5rm4BD9CrBOCw7 LaVafU6KSAfHT9BA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 043/120] x86/cpu/hygon: Use parsed CPUID(0x80000005) and CPUID(0x80000006) Date: Thu, 28 May 2026 17:38:05 +0200 Message-ID: <20260528153923.403473-44-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Hygon init, use parsed CPUID(0x80000005) and CPUID(0x80000006) instead of direct CPUID queries and ugly bitwise operations. Consolidate all comments; the code has now clear logic and bitfield names. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/hygon.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c index 3e8891a9caf2..4a63538c2b3f 100644 --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -229,35 +229,32 @@ static void init_hygon(struct cpuinfo_x86 *c) clear_cpu_cap(c, X86_FEATURE_APIC_MSRS_FENCE); } =20 +/* + * For DTLB/ITLB 2M-4M detection, fall back to L1 if L2 is disabled + */ static void cpu_detect_tlb_hygon(struct cpuinfo_x86 *c) { - u32 ebx, eax, ecx, edx; - u16 mask =3D 0xfff; + const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); + const struct leaf_0x80000006_0 *el6 =3D cpuid_leaf(c, 0x80000006); =20 - if (c->extended_cpuid_level < 0x80000006) + if (!el5 || !el6) return; =20 - cpuid(0x80000006, &eax, &ebx, &ecx, &edx); + tlb_lld_4k =3D el6->l2_dtlb_4k_nentries; + tlb_lli_4k =3D el6->l2_itlb_4k_nentries; =20 - tlb_lld_4k =3D (ebx >> 16) & mask; - tlb_lli_4k =3D ebx & mask; + if (el6->l2_dtlb_2m_4m_nentries) + tlb_lld_2m =3D el6->l2_dtlb_2m_4m_nentries; + else + tlb_lld_2m =3D el5->l1_dtlb_2m_4m_nentries; =20 - /* Handle DTLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ - if (!((eax >> 16) & mask)) - tlb_lld_2m =3D (cpuid_eax(0x80000005) >> 16) & 0xff; + if (el6->l2_itlb_2m_4m_nentries) + tlb_lli_2m =3D el6->l2_itlb_2m_4m_nentries; else - tlb_lld_2m =3D (eax >> 16) & mask; + tlb_lli_2m =3D el5->l1_itlb_2m_4m_nentries; =20 - /* a 4M entry uses two 2M entries */ + /* A 4M TLB entry uses two 2M entries */ tlb_lld_4m =3D tlb_lld_2m >> 1; - - /* Handle ITLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ - if (!(eax & mask)) { - cpuid(0x80000005, &eax, &ebx, &ecx, &edx); - tlb_lli_2m =3D eax & 0xff; - } else - tlb_lli_2m =3D eax & mask; - tlb_lli_4m =3D tlb_lli_2m >> 1; } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A4BA042848B for ; Thu, 28 May 2026 15:42:10 +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=1779982937; cv=none; b=gh7k2nsq6D+plBEvK9XXksDJEJFYJDVntsOqxcMqnXo3U2SRArgQ6fv+2NKFYBqp3dvN76AXuZEXcXOJ5JOKc8fuC0J1zQ3vdJSbxYLTWC6MwVapervYLm1t7Tt834CNcL/lYwLWsQ6DhHFWCAUDEjwmYwE/ZeqS3LUFffwozXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982937; c=relaxed/simple; bh=F9nXpe25/9NhA1dhT8lwC4lrSqRwHg/IDSwUoluZTpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gvRFJTyHmkzUdHbETzp9/sQ+cpwHZVwUgWZ45wpQTwgC2yzZLUGO2TfNvElWsFhVDPaL/IvZMnok+SBNzl6shlpvy8bZbtD/mAmoBbmdVoivc9bBfXbvE+MHq35M3i0v3/UFuN+9/dUuiqMPvHSX9ILW/6liNiSABb/Gzqei0ZY= 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=4oN+/W0X; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6y02XxQT; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4oN+/W0X"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6y02XxQT" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjQE8S6M58khNUKdSRbVbD9yQ5dHzjnErXIrgDoGlec=; b=4oN+/W0X/qA9J/mp6x+XyNpEAw2D/5iquVVy7umwGXByra1eM/JnwoQ0MhrNloL0kC/lej dZKymJlGhjw9Z5j9WMsK0AVTSB12nx912XUMsYIJ5bSSNcKGrbn/AyiFdYtgb9AffsOK/h L+6QzcTGNiNIF7pUSv1j7i6s9QgOhCzfqgqQpfijEa21kB35Q76QgWJkmyFLfbATz5+O6S mT+URg3JmIlN1tjrmnbxR5EtKSMe6Qq1XVWAtgChkmebqQfR4GLxS0wIhs69hpkaJByQ1C byeNwDbjlKo6YiMmECLYO/556G9KMWYH8/Ggdh7FKY+Lo8VjLecv7U/xI1PGsg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjQE8S6M58khNUKdSRbVbD9yQ5dHzjnErXIrgDoGlec=; b=6y02XxQTdHgvoe0fwLwIJZK/r9gyf/DBDoQy4fDFmhgSSRgkPNkdZO/eGHWy+ld9Nw3BpL kY0pmxx+lgfMABCQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 044/120] x86/cpu/centaur: Use parsed CPUID(0x80000005) Date: Thu, 28 May 2026 17:38:06 +0200 Message-ID: <20260528153923.403473-45-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x80000005) instead of issuing a CPUID query and doing ugly bitwise operations. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/centaur.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 5f09bce3aaa7..895cf00919d3 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -107,11 +107,11 @@ static void early_init_centaur(struct cpuinfo_x86 *c) static void init_centaur(struct cpuinfo_x86 *c) { #ifdef CONFIG_X86_32 - char *name; + const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); + u32 lo, hi, newlo; u32 fcr_set =3D 0; u32 fcr_clr =3D 0; - u32 lo, hi, newlo; - u32 aa, bb, cc, dd; + char *name; #endif early_init_centaur(c); init_intel_cacheinfo(c); @@ -181,13 +181,8 @@ static void init_centaur(struct cpuinfo_x86 *c) /* Set 3DNow! on Winchip 2 and above. */ if (c->x86_model >=3D 8) set_cpu_cap(c, X86_FEATURE_3DNOW); - /* See if we can find out some more. */ - if (cpuid_eax(0x80000000) >=3D 0x80000005) { - /* Yes, we can. */ - cpuid(0x80000005, &aa, &bb, &cc, &dd); - /* Add L1 data and code cache sizes. */ - c->x86_cache_size =3D (cc>>24)+(dd>>24); - } + if (el5) + c->x86_cache_size =3D el5->l1_dcache_size_kb + el5->l1_icache_size_kb; sprintf(c->x86_model_id, "WinChip %s", name); } #endif --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 CFED33F888F for ; Thu, 28 May 2026 15:42:13 +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=1779982940; cv=none; b=lYig46UFHJxm+24GDwSuh/WZjFjaAir1YB5ds6niUskUjW0WmGN3xlAi+5QJI1It3itr9yFj+oXc43pJlmCQCKY7sziQK+K/DLwNEZ+X3QnWuMWXU05dov9SHRjcWiWN7vfxDuNKXWBDPfjGC1w626ZZthHcmSta/F9MyheDHFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982940; c=relaxed/simple; bh=f9/sxAse2Ljjii9UG6fNUelSBBwUXFLcb+EWyBounsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZggyyJgvaQ7hUzlPyfpmWchZiB9DnwI4LYI+/IRK1IphU7ogI3lSGFjoYzNi2IVSVwd4Uf4W7mhxubNn8YX841833h9cqepVk67/wIBmde86jlGVsX8gUnV9F0swgrg5fkSPVQM8SiwmqSmv/Bb3sVkIo5/vvRr1LYHu125rEkk= 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=HYzICl6v; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=N+jDQjd4; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HYzICl6v"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="N+jDQjd4" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8vPV5cBhASNOsauOImhCjtz8dudxfhPoXcQ1YNmmcyE=; b=HYzICl6v1jwQUQoj4u5o01Sdxoe+DbN45gC9iqEwQlYxKvJ9H1KZHafsIIT11rFjzYe3Ec cM31Kl4pw9haS8OdOlFfvI7nIml5E1ZM5DpA76QY9tIg4dHCOuYWSSOBqQTsXNi76IBs2a 1oOIVCm/e+40Vv6F45bK5ZtR1jb112s4zgIP+Cbfb7qw6RgStX2hgZvEpxEEzcC1t9Icxg rkknIT2yDPGG4/wCeEAbQnO38DgxfFIburr1znjrsoA8pC3YXfGpVtFP0LvfywLNR4IHhK gd3Ywa4RbHGogcAzhyvHIXWkPaSZfKcyk1tLMVDMFwnpfhAs6GIs+jiGBJPolw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8vPV5cBhASNOsauOImhCjtz8dudxfhPoXcQ1YNmmcyE=; b=N+jDQjd4Iwvt4LxJcTyXyt84MXNf5ipEJ/xJiWG9uhlvtecyNOK9Nevx8yfMi7cS4r+L/j uIZE/eIX6pLyxYAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 045/120] x86/cpu: Use parsed CPUID(0x80000008) Date: Thu, 28 May 2026 17:38:07 +0200 Message-ID: <20260528153923.403473-46-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x80000008) instead of issuing a direct CPUID query and doing ugly bitwise operations. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index d8e46eb0f5c5..d78063e4e665 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1102,10 +1102,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c) =20 void get_cpu_address_sizes(struct cpuinfo_x86 *c) { - u32 eax, ebx, ecx, edx; + const struct leaf_0x80000008_0 *el8 =3D cpuid_leaf(c, 0x80000008); =20 - if (!cpu_has(c, X86_FEATURE_CPUID) || - (c->extended_cpuid_level < 0x80000008)) { + if (!cpu_has(c, X86_FEATURE_CPUID) || !el8) { if (IS_ENABLED(CONFIG_X86_64)) { c->x86_clflush_size =3D 64; c->x86_phys_bits =3D 36; @@ -1120,10 +1119,8 @@ void get_cpu_address_sizes(struct cpuinfo_x86 *c) c->x86_phys_bits =3D 36; } } else { - cpuid(0x80000008, &eax, &ebx, &ecx, &edx); - - c->x86_virt_bits =3D (eax >> 8) & 0xff; - c->x86_phys_bits =3D eax & 0xff; + c->x86_virt_bits =3D el8->virt_addr_bits; + c->x86_phys_bits =3D el8->phys_addr_bits; =20 /* Provide a sane default if not enumerated: */ if (!c->x86_clflush_size) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 667FC426ED3 for ; Thu, 28 May 2026 15:42:17 +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=1779982944; cv=none; b=fT/H2D9pUqj0Id5VTgriiqyGN8Q/bUG/gIDKYa9oit43d5nbWs/aCm+nBYV9Ix3aWpRfVknRR5a8MH/ZhLY//aToXSX7scy8Of6ezvIBmz4SOKx9kssZ3FGtuLahfm6hP/nEwjaUybxWt5P6REt/8RZdSfgRKe//y6hwxHQ6r6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982944; c=relaxed/simple; bh=gGhihDs0BAA5VjAUcgAGwyIPFVLeqlKbeWaemapl464=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p71Ez25i1q0UrxRIqf2Ud2uTGP+k/SadioO+en27ymJsyjTTZcXydRQnwr6EQH+P+FeosKosmpPVoHygAjFCrWAiLAlYb1qIgqmK/IFWVnW3+X08+EuS94cPjDN63+6yNbmQMkGoPkJT9NiJ+kLfsiGocerRWPBkgg3BPvKg/n8= 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=QSdMJbI6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=W/65t2R0; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QSdMJbI6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="W/65t2R0" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wRBgO/dDvAeEyj4PQoDeQ9tFsc/1XuxnxwFhtOqd9dk=; b=QSdMJbI6i8tKoPodgpqq+NSvlfKKiJiL7Pwr9JyQaiHVlPNHEJEt36e3zdEqQCam9qZinK gZcYH6gDiekoAeYMs5TfMPo7f0pUIrCCOK2Kl9/lSyww8mepY5EXiDqRTQypQRllGblmee rFWYSgv4wBAIAtcZICErUl+9H8sAr6NDIx1Wx8BIakyFd/XaaurHzSVXKTveaE8/BlvGEX Mkl85JuoOy4uqrqA8h9V3Ea54b1gYu5Af8tjjDavEGo/+j+WQLETfP2os/rMnpfDWisEQI Fdibr2k7QGghqaY//p+J32mfo3Dvqx1cqeMDnxqiPhyDLiQcl1DL5qKNP4cAzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wRBgO/dDvAeEyj4PQoDeQ9tFsc/1XuxnxwFhtOqd9dk=; b=W/65t2R0kU7vFJ8Oyz9yXRzg8qNQlKzNR/UCm3puGPSthsKhqbgzSnOqbDQp+w6R0Pfb6C w+WuMjIa+dnGmgBQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 046/120] x86/apic: Use parsed and refreshed CPUID(0x1) Date: Thu, 28 May 2026 17:38:08 +0200 Message-ID: <20260528153923.403473-47-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x1) instead of doing manual bitwise operations and a direct CPUID query. Refresh CPUID(0x1).EDX since one apic_verify() caller may force local APIC enablement through an MSR write beforehand. Note, using the CPUID APIs here is safe since setup_arch() calls early_cpu_init() way before invoking any of the APIC initialization code. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/apic/apic.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c index 8c614750a19b..0ecd923b5809 100644 --- a/arch/x86/kernel/apic/apic.c +++ b/arch/x86/kernel/apic/apic.c @@ -1960,14 +1960,15 @@ static bool __init detect_init_APIC(void) =20 static bool __init apic_verify(unsigned long addr) { - u32 features, h, l; + const struct leaf_0x1_0 *l1; + u32 h, l; =20 /* - * The APIC feature bit should now be enabled - * in `cpuid' + * The APIC feature bit should now be enabled in CPUID */ - features =3D cpuid_edx(1); - if (!(features & (1 << X86_FEATURE_APIC))) { + cpuid_refresh_leaf(&boot_cpu_data, 0x1); + l1 =3D cpuid_leaf(&boot_cpu_data, 0x1); + if (!l1 || !l1->apic) { pr_warn("Could not enable APIC!\n"); return false; } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6185342847C for ; Thu, 28 May 2026 15:42:20 +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=1779982947; cv=none; b=ZMTcaM+WOVtu5+QgxuQ2MoS8xDz7WSAyaSv9ssVfIRQhQVYP1O/CCmIPyTWPD1TVrPHhNBQhZWeqDiyYOzm6xt7S94fLFsKxebey1qPxECsvQ3vVS6UwL3Zqcvh7HYw6B9HDaAd7XWsdyTdral6F6cW7ypOys+lXD+zxr2ybDdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982947; c=relaxed/simple; bh=g6FzSkK406zdlUICG0D3qkRD1Baoy9YqOnHbXtIBrCI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R4I1BkTifmIJ3eBpfWhbYHKIZzrbl8uZHXOaBgma9uJk7kdhxPoF1zVKg5PDCQDxAI7BFYYvObOEVUkZYv34c3HtPf0CKc2QCV60xjMWBmH/WN40w3CbYJu+iPKvq/FtjfDLdmrIut4H2HcLy4v8ydOR3DTV28o5p9c97Dq37x8= 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=2VXHSVeM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gpv354aW; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2VXHSVeM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gpv354aW" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+CE+siywCqRIvJ4ysTV7EQuPL252QrJxvsb/WCBpzo=; b=2VXHSVeMHAwo3d2Wb8Kcwf8bE5DOUCbSsVvDhC3NPsZyzJCl7hPrVjHUYbIioRtTChVhde sCMIUPzcTazHo7CEJ8Snl/Lmlbmr1oYJvNiIarjUQkjIFzJEGJrDj+WNNbEKKZPR+GY7+S SPAac1S+EQQTiUk6nUsywBJv6ioH7i2yJKz9GElw2n+dNyAaTrhp4pU2h5bt4+bFBbimPU bKOL8c0oE/pAj1Kz11Ldybv1ZIkpO5KnUw0erOMhlgQAnKoEurwwgAS1quPAA82caIaN4u MYFPJ3BZQ0Vg3Fc2ZCNAXD/JtK8tsKPEaedKrUpyhXS4Z+NeFyIqFljUNvKBHA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982938; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+CE+siywCqRIvJ4ysTV7EQuPL252QrJxvsb/WCBpzo=; b=gpv354aWm3paYQ0r80VrQklqP8pN6j6+jIog0FGAcrSQ+zuK0ugOu2CthwKboPmgQuQiwQ Q81hBiD1YiyNAvDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 047/120] x86/cpu/amd: Refactor CPUID(0x1) level calculation Date: Thu, 28 May 2026 17:38:09 +0200 Message-ID: <20260528153923.403473-48-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" AMD K8 init code has the cryptic CPUID(0x1).EAX level check: (level >=3D 0x0f48 && level < 0x0f50) || level >=3D 0x0f58 Given that: EAX[0:3] is the CPU stepping EAX[4:7] is the CPU base model EAX[8:11] is the base family ID, with 0xf as the largest EAX[16:19] is the CPU extended model then "level >=3D 0x0f58" translates to: model > 5 || (model =3D=3D 5 && stepping >=3D 8) and "level >=3D 0x0f48 && level < 0x0f50" translates to: model =3D=3D 4 && stepping >=3D 8 The two expressions can then be combined as: model > 5 || ((model =3D=3D 0x4 || model =3D=3D 0x5) && stepping >=3D 0= x8) and further combined as: model > 5 || (model >=3D 4 && stepping >=3D 8) where "model" in all translations above is the decoded CPUID model: base_model | (ext_model << 4) Using all the information above, convert that CPUID(0x1).EAX level check into a more readable form. Avoid a direct CPUID query by using the already cached CPU model and stepping values at struct cpuinfo_x86. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 50bbf9f33501..0e077a4f2646 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -691,12 +691,10 @@ static void early_init_amd(struct cpuinfo_x86 *c) =20 static void init_amd_k8(struct cpuinfo_x86 *c) { - u32 level; u64 value; =20 /* On C+ stepping K8 rep microcode works well for copy/memset */ - level =3D cpuid_eax(1); - if ((level >=3D 0x0f48 && level < 0x0f50) || level >=3D 0x0f58) + if (c->x86_model > 5 || (c->x86_model >=3D 4 && c->x86_stepping >=3D 8)) set_cpu_cap(c, X86_FEATURE_REP_GOOD); =20 /* --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C2475426697 for ; Thu, 28 May 2026 15:42:23 +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=1779982949; cv=none; b=g6obsDot1pVm83tyesQl61osUj9HjKaeaGr5kKiZXTzuwCZ48k9GGuE9GSU6a3k3lZX5eTQH0bg1yatQ7I+Ju1tun+qBUBMdGhFL6m1cka/JqEfD9JbAh/WLsnzhqX7swGpxv6k+suTtBEv3o7R1iTL26VK17YhE4CLFcSNyf68= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982949; c=relaxed/simple; bh=+24yF5ZuVAL93pZG4RtA1ttuWoIDj3wBRSaFyrhMEKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xfv7peCrrV9l/rHTHbdF2762UdXkX3g7G3Z9U31lF99UKDVaBfT8FYZDJXVIp2zqws++vfxXnpTxRbEerOTNklA6v2C16fOgm5mjQZCkBEkPq5DJpcsuv+Cx7b6PxgvcqzbsPt0KKJ+lY2r4YXW9DTIxx1gdOjWXAcDEQfSCbF0= 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=WUx69PB4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8PnyZwxe; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WUx69PB4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8PnyZwxe" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ccCjOCYWJxzcOWh9aDfzlst+Yr7nfMsCk5H+Xgm695U=; b=WUx69PB4F6T7HaOmtI9MLi6q9XjAAEEZZ05yhGy4/wctc9RkOjhp9oEgLiJLbrxkFz/Zbi QEdBDSdkDekHOGNgy+27fgRlFny5a52Q3sDOF077AeSOVGCYu5mOxS+TESPX919c9XlMSs vMU6LPp66MVh2Gej9N1STG4iUv3GfjMa4IqrMwtwOy5tmUNjNeL3olC+DXB65YmMVf0sdF L2CZ9V72D2dd6lR1gSQBMM6stAXz6aiG1jin5jzGK/n2YZ8QeKR/ZomJE32MdGj6IqodAP ZzX6g1xhIWVKnqeJhZGr16/o6zc2idc7KQkJsNadRIRA8oDNVRmxQtVZfEapIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ccCjOCYWJxzcOWh9aDfzlst+Yr7nfMsCk5H+Xgm695U=; b=8PnyZwxezFdFczzjk53mq3syQqKEuaUBZbQ+i0BTrgQTQegb2AajzvsRT4vXK7Mre3mjDV XERRP+MA1z/vsSBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 048/120] x86/mce: core: Use parsed CPUID(0x1) Date: Thu, 28 May 2026 17:38:10 +0200 Message-ID: <20260528153923.403473-49-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For MCE record preparation, use parsed CPUID(0x1) instead of a direct CPUID query. Keep storing the raw EAX output into struct mce. As documented within __print_mce(), the raw value is parsed by external tools. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/mce/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index eebc60342cd6..821cac467c9f 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -120,7 +120,7 @@ BLOCKING_NOTIFIER_HEAD(x86_mce_decoder_chain); =20 void mce_prep_record_common(struct mce *m) { - m->cpuid =3D cpuid_eax(1); + m->cpuid =3D cpuid_leaf_raw(&boot_cpu_data, 0x1)->eax; m->cpuvendor =3D boot_cpu_data.x86_vendor; m->mcgcap =3D native_rdmsrq(MSR_IA32_MCG_CAP); /* need the internal __ version to avoid deadlocks */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 756BA428841 for ; Thu, 28 May 2026 15:42:27 +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=1779982950; cv=none; b=nsYdfZGWVNjfNE4dVztDskBuWbaeFBo/diksb/CqRSjn/6edGFRh+raWXnssRhOdoIpFSFDWQIm3CGxBRzylEKe9jLF0zjCR8gRWt/4VGe4QAHL7c/k244z3PnafnFDf6Qdi/IXlFbXwhBNdefoGzWLE+6hFcQzOWGJmmKLxVXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982950; c=relaxed/simple; bh=IlUpfz34PwuSRIS0hkELKWJYU5OlYjvc/aXYrGwIFek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t1NkrPfZumSeqNDkU6x+yVBjCUCQmcyYUUdkFpjR4mm/c/b9yAWgl1VJ61iJruuPSiYALik5QMdtjV2whG2v1C9r5zpDYcfM1M7SAUiWqEIiG7xOsj5/vUzVw98wNhSWdBYwbZRDr9Le/Xo1FDc9+1orrCs671vfevnr2XeTWaI= 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=GqpOIIik; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aN25URfl; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GqpOIIik"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aN25URfl" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FVnCG2+9w9VOS4Pd7LNuPbFVDSk+dhXSqDBYDFECFV0=; b=GqpOIIikaY8nBIV/gj9LEz3/CTQlzYMW2+e04ql6a0I6j8/1ZPjt3s1WHudgmasYrEq+3x sD+Q44j9L3BVTgr2LFFSMOAl/Gf02xR7GSfvbkENZVhaopNBsMVP6SPxGGChwVM1kMPtHS HM5QbD5hb9SadrrIUipoZKUY2d4nCWwzPsXLxfN0lpcJcQmc9xpOrDOQLpaE2/gO+hi1uq ztnCg3DIVaYMPrhnqCzF1z0GGSyiLN1zetLsr9QtkWyVL1WtnT6ky8OGU21joRwHmFvYcW y1zC58JUSBoA5UaEkBLtraHxTdJfv2iuZh0cxed0blKLdOL8zaD0ro+2DtxnNQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FVnCG2+9w9VOS4Pd7LNuPbFVDSk+dhXSqDBYDFECFV0=; b=aN25URflo/KhNTTi7L0LMWQB8/DtDRQUARQ+O4lnMedJ/t+p0p8Yj/65DwhR6YF5HN7Jl/ BOJCCJgUwuBlmKAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 049/120] x86/mce: inject: Use parsed CPUID(0x1) Date: Thu, 28 May 2026 17:38:11 +0200 Message-ID: <20260528153923.403473-50-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For MCE injection, use parsed CPUID(0x1) instead of a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/mce/inject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inj= ect.c index 42c82c14c48a..10fe9bdd62d1 100644 --- a/arch/x86/kernel/cpu/mce/inject.c +++ b/arch/x86/kernel/cpu/mce/inject.c @@ -120,7 +120,7 @@ static void setup_inj_struct(struct mce *m) =20 m->cpuvendor =3D boot_cpu_data.x86_vendor; m->time =3D ktime_get_real_seconds(); - m->cpuid =3D cpuid_eax(1); + m->cpuid =3D cpuid_leaf_raw(&boot_cpu_data, 0x1)->eax; m->microcode =3D boot_cpu_data.microcode; } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 2E85F42EEC7 for ; Thu, 28 May 2026 15:42:31 +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=1779982955; cv=none; b=QF+8FsOKQEnc/W+BGxZL+/KF2pGGjYhvaaBZHaz9gk53ULWtg8v3T6M8pTV8PmPC+qgm5jxJF/hF7fuLQYG2tDCzJYd0e/lsE2O9i1wnL9v4u/NuKDndHbX5qYeAyc9MPwVkiIJ5840snkhBjBpADqaOxLrarvU0QtVPaumHJIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982955; c=relaxed/simple; bh=tjuZ+0GD4eBIUAXvjxE4ebmDt3Q1LWU6wnHhkzwkeDI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cQf1SguUfLXjpMITcK9EJnDb88BHNQ2r3dlkYU9WvwsgFrIOBxNj3a7WC19Qx0/KMW2jjD3iN0aZOvgVOvHeYgos6lpryS7zLCFLMRRP3lzn58BLbR4CyQZ5mVUXh3k8xtLGTo9SwJVTOsCUBSCAg2ifYE6+HInyqKyaOYgnBuo= 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=gyM2cGfO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yt4Xa4aG; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gyM2cGfO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yt4Xa4aG" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M3Xp7NTc9XgPz0DKWH7ntegGmM3R2oGxlKaZ/aijIIg=; b=gyM2cGfOG5gqAoS/jLNkUM0+v6pj0+LJNPtLrqiRoUn9PLlEkPKW1hEqDgES4Iw797oegU tZcxCcb9mZ4RRC7Ljov+TGOEhR9dPVEG54wDV6O2bRmA/qQEWJvln5Bfqbf24emjUF6y3r Zq4Ee8zX4wrUD49T/LwzSZ2kdDS1MnpKpOMPa2GGRjK7C+SNYvrZQSfXQy7vghrxmLSMCY FE6eNGqKSWz8bIh9lHgDcFFOW/ys9eDYq9IBXLayqgUzLhn6yGyCoviLVtv05N2wt7soo+ mzAc5pYXrn5YFsH5bXCZvmmuGkq5GVtAkIJodnSOgS2K/67WRCau9rt7tmaDKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982949; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M3Xp7NTc9XgPz0DKWH7ntegGmM3R2oGxlKaZ/aijIIg=; b=yt4Xa4aG2H52FGUPtc/GI4CSDiV2LPPPqLAn8UbC4Cp0LTobEhy4F98iEtMzAiSu4QsY8i UfG5h7LZSIi+XkCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 050/120] x86/microcode/amd: Use standard CPUID(0x1) types Date: Thu, 28 May 2026 17:38:12 +0200 Message-ID: <20260528153923.403473-51-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use standard CPUID(0x1) data types from x86-cpuid-db instead of defining and using custom ones. Remove the local union cpuid_1_eax since it has no more users. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/microcode/amd.c | 106 +++++++++++++--------------- 1 file changed, 49 insertions(+), 57 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/micr= ocode/amd.c index 874b5b70c0d2..f609645f1254 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -107,19 +107,6 @@ union zen_patch_rev { __u32 ucode_rev; }; =20 -union cpuid_1_eax { - struct { - __u32 stepping : 4, - model : 4, - family : 4, - __reserved0 : 4, - ext_model : 4, - ext_fam : 8, - __reserved1 : 4; - }; - __u32 full; -}; - /* * This points to the current valid container of microcode patches which w= e will * save from the initrd/builtin before jettisoning its contents. @mc is the @@ -148,7 +135,7 @@ ucode_path[] __maybe_unused =3D "kernel/x86/microcode/A= uthenticAMD.bin"; * already contains the f/m/s for which the microcode is destined * for. */ -static u32 bsp_cpuid_1_eax __ro_after_init; +static struct leaf_0x1_0 leaf1 __ro_after_init; =20 static bool sha_check =3D true; =20 @@ -159,6 +146,11 @@ struct patch_digest { =20 #include "amd_shas.c" =20 +static u32 __eax(const struct leaf_0x1_0 *l) +{ + return ((const struct cpuid_regs *)l)->eax; +} + static int cmp_id(const void *key, const void *elem) { struct patch_digest *pd =3D (struct patch_digest *)elem; @@ -172,17 +164,14 @@ static int cmp_id(const void *key, const void *elem) return 1; } =20 -static u32 cpuid_to_ucode_rev(unsigned int val) +static u32 cpuid_to_ucode_rev(const struct leaf_0x1_0 *l) { union zen_patch_rev p =3D {}; - union cpuid_1_eax c; - - c.full =3D val; =20 - p.stepping =3D c.stepping; - p.model =3D c.model; - p.ext_model =3D c.ext_model; - p.ext_fam =3D c.ext_fam; + p.stepping =3D l->stepping; + p.model =3D l->base_model; + p.ext_model =3D l->ext_model; + p.ext_fam =3D l->ext_family; =20 return p.ucode_rev; } @@ -235,7 +224,7 @@ static bool need_sha_check(u32 cur_rev) u32 cutoff; =20 if (!cur_rev) { - cur_rev =3D cpuid_to_ucode_rev(bsp_cpuid_1_eax); + cur_rev =3D cpuid_to_ucode_rev(&leaf1); pr_info_once("No current revision, generating the lowest one: 0x%x\n", c= ur_rev); } =20 @@ -244,14 +233,14 @@ static bool need_sha_check(u32 cur_rev) return cur_rev <=3D cutoff; =20 pr_info("You should not be seeing this. Please send the following couple = of lines to x86--kernel.org\n"); - pr_info("CPUID(1).EAX: 0x%x, current revision: 0x%x\n", bsp_cpuid_1_eax, = cur_rev); + pr_info("CPUID(1).EAX: 0x%x, current revision: 0x%x\n", __eax(&leaf1), cu= r_rev); return true; } =20 static bool cpu_has_entrysign(void) { - unsigned int fam =3D x86_family(bsp_cpuid_1_eax); - unsigned int model =3D x86_model(bsp_cpuid_1_eax); + unsigned int fam =3D cpuid_family(&leaf1); + unsigned int model =3D cpuid_model(&leaf1); =20 if (fam =3D=3D 0x17 || fam =3D=3D 0x19) return true; @@ -302,21 +291,20 @@ static bool verify_sha256_digest(u32 patch_id, u32 cu= r_rev, const u8 *data, unsi return true; } =20 -static union cpuid_1_eax ucode_rev_to_cpuid(unsigned int val) +static struct leaf_0x1_0 ucode_rev_to_cpuid(unsigned int val) { + struct leaf_0x1_0 leaf =3D { }; union zen_patch_rev p; - union cpuid_1_eax c; =20 p.ucode_rev =3D val; - c.full =3D 0; =20 - c.stepping =3D p.stepping; - c.model =3D p.model; - c.ext_model =3D p.ext_model; - c.family =3D 0xf; - c.ext_fam =3D p.ext_fam; + leaf.stepping =3D p.stepping; + leaf.base_model =3D p.model; + leaf.ext_model =3D p.ext_model; + leaf.base_family_id =3D 0xf; + leaf.ext_family =3D p.ext_fam; =20 - return c; + return leaf; } =20 static u32 get_patch_level(void) @@ -328,7 +316,7 @@ static u32 get_patch_level(void) =20 if (!microcode_rev[cpu]) { if (!base_rev) - base_rev =3D cpuid_to_ucode_rev(bsp_cpuid_1_eax); + base_rev =3D cpuid_to_ucode_rev(&leaf1); =20 microcode_rev[cpu] =3D base_rev; =20 @@ -348,7 +336,7 @@ static u16 find_equiv_id(struct equiv_cpu_table *et, u3= 2 sig) unsigned int i; =20 /* Zen and newer do not need an equivalence table. */ - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) + if (cpuid_family(&leaf1) >=3D 0x17) return 0; =20 if (!et || !et->num_entries) @@ -398,7 +386,7 @@ static bool verify_equivalence_table(const u8 *buf, siz= e_t buf_size) return false; =20 /* Zen and newer do not need an equivalence table. */ - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) + if (cpuid_family(&leaf1) >=3D 0x17) return true; =20 cont_type =3D hdr[1]; @@ -465,7 +453,7 @@ static bool __verify_patch_section(const u8 *buf, size_= t buf_size, u32 *sh_psize */ static bool __verify_patch_size(u32 sh_psize, size_t buf_size) { - u8 family =3D x86_family(bsp_cpuid_1_eax); + u8 family =3D cpuid_family(&leaf1); u32 max_size; =20 if (family >=3D 0x15) @@ -504,7 +492,7 @@ static bool __verify_patch_size(u32 sh_psize, size_t bu= f_size) */ static int verify_patch(const u8 *buf, size_t buf_size, u32 *patch_size) { - u8 family =3D x86_family(bsp_cpuid_1_eax); + u8 family =3D cpuid_family(&leaf1); struct microcode_header_amd *mc_hdr; u32 cur_rev, cutoff, patch_rev; u32 sh_psize; @@ -578,10 +566,13 @@ static int verify_patch(const u8 *buf, size_t buf_siz= e, u32 *patch_size) static bool mc_patch_matches(struct microcode_amd *mc, u16 eq_id) { /* Zen and newer do not need an equivalence table. */ - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) - return ucode_rev_to_cpuid(mc->hdr.patch_id).full =3D=3D bsp_cpuid_1_eax; - else + if (cpuid_family(&leaf1) >=3D 0x17) { + struct leaf_0x1_0 l =3D ucode_rev_to_cpuid(mc->hdr.patch_id); + + return __eax(&l) =3D=3D __eax(&leaf1); + } else { return eq_id =3D=3D mc->hdr.processor_rev_id; + } } =20 /* @@ -612,7 +603,7 @@ static size_t parse_container(u8 *ucode, size_t size, s= truct cont_desc *desc) * doesn't contain a patch for the CPU, scan through the whole container * so that it can be skipped in case there are other containers appended. */ - eq_id =3D find_equiv_id(&table, bsp_cpuid_1_eax); + eq_id =3D find_equiv_id(&table, __eax(&leaf1)); =20 buf +=3D hdr[2] + CONTAINER_HDR_SZ; size -=3D hdr[2] + CONTAINER_HDR_SZ; @@ -702,7 +693,7 @@ static bool __apply_microcode_amd(struct microcode_amd = *mc, u32 *cur_rev, =20 native_wrmsrq(MSR_AMD64_PATCH_LOADER, p_addr); =20 - if (x86_family(bsp_cpuid_1_eax) =3D=3D 0x17) { + if (cpuid_family(&leaf1) =3D=3D 0x17) { unsigned long p_addr_end =3D p_addr + psize - 1; =20 invlpg(p_addr); @@ -732,7 +723,7 @@ static bool __apply_microcode_amd(struct microcode_amd = *mc, u32 *cur_rev, static bool get_builtin_microcode(struct cpio_data *cp) { char fw_name[36] =3D "amd-ucode/microcode_amd.bin"; - u8 family =3D x86_family(bsp_cpuid_1_eax); + u8 family =3D cpuid_family(&leaf1); struct firmware fw; =20 if (IS_ENABLED(CONFIG_X86_32)) @@ -777,6 +768,7 @@ static bool __init find_blobs_in_containers(struct cpio= _data *ret) */ void __init load_ucode_amd_bsp(struct early_load_data *ed, unsigned int cp= uid_1_eax) { + struct cpuid_regs *leaf1_regs =3D (struct cpuid_regs *)&leaf1; struct cont_desc desc =3D { }; struct microcode_amd *mc; struct cpio_data cp =3D { }; @@ -791,7 +783,7 @@ void __init load_ucode_amd_bsp(struct early_load_data *= ed, unsigned int cpuid_1_ } } =20 - bsp_cpuid_1_eax =3D cpuid_1_eax; + leaf1_regs->eax =3D cpuid_1_eax; =20 rev =3D get_patch_level(); ed->old_rev =3D rev; @@ -825,16 +817,16 @@ static inline bool patch_cpus_equivalent(struct ucode= _patch *p, bool ignore_stepping) { /* Zen and newer hardcode the f/m/s in the patch ID */ - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) { - union cpuid_1_eax p_cid =3D ucode_rev_to_cpuid(p->patch_id); - union cpuid_1_eax n_cid =3D ucode_rev_to_cpuid(n->patch_id); + if (cpuid_family(&leaf1) >=3D 0x17) { + struct leaf_0x1_0 p_leaf =3D ucode_rev_to_cpuid(p->patch_id); + struct leaf_0x1_0 n_leaf =3D ucode_rev_to_cpuid(n->patch_id); =20 if (ignore_stepping) { - p_cid.stepping =3D 0; - n_cid.stepping =3D 0; + p_leaf.stepping =3D 0; + n_leaf.stepping =3D 0; } =20 - return p_cid.full =3D=3D n_cid.full; + return __eax(&p_leaf) =3D=3D __eax(&n_leaf); } else { return p->equiv_cpu =3D=3D n->equiv_cpu; } @@ -861,7 +853,7 @@ static struct ucode_patch *cache_find_patch(struct ucod= e_cpu_info *uci, u16 equi static inline int patch_newer(struct ucode_patch *p, struct ucode_patch *n) { /* Zen and newer hardcode the f/m/s in the patch ID */ - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) { + if (cpuid_family(&leaf1) >=3D 0x17) { union zen_patch_rev zp, zn; =20 zp.ucode_rev =3D p->patch_id; @@ -921,7 +913,7 @@ static struct ucode_patch *find_patch(unsigned int cpu) =20 uci->cpu_sig.rev =3D get_patch_level(); =20 - if (x86_family(bsp_cpuid_1_eax) < 0x17) { + if (cpuid_family(&leaf1) < 0x17) { equiv_id =3D find_equiv_id(&equiv_table, uci->cpu_sig.sig); if (!equiv_id) return NULL; @@ -1036,7 +1028,7 @@ static size_t install_equiv_cpu_table(const u8 *buf, = size_t buf_size) equiv_tbl_len =3D hdr[2]; =20 /* Zen and newer do not need an equivalence table. */ - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) + if (cpuid_family(&leaf1) >=3D 0x17) goto out; =20 equiv_table.entry =3D vmalloc(equiv_tbl_len); @@ -1055,7 +1047,7 @@ static size_t install_equiv_cpu_table(const u8 *buf, = size_t buf_size) =20 static void free_equiv_cpu_table(void) { - if (x86_family(bsp_cpuid_1_eax) >=3D 0x17) + if (cpuid_family(&leaf1) >=3D 0x17) return; =20 vfree(equiv_table.entry); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 F22D5436378 for ; Thu, 28 May 2026 15:42:35 +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=1779982959; cv=none; b=aJjlmRY9zGm+erxHqhIj7gAerC9XvOfccwrMDle2pgI7nmiKmdHRZA8lk8G7riNkENInTGxxUPK9HmLa9Jd6fX++2HrnYtBWFdJjtKmaDbXgAYnt5eXJdiwia7HiAz1GuxQ8moQL7AjkJUnzurhpt4seIHulKph6B8AZ7WQoCbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982959; c=relaxed/simple; bh=UmIuUJT0nMgKKbt+ogQzcEA4UuBVmDeZtClx90JlwHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xt8GeDki3j41rnDjxqIyWOYtbCM9Cb3NelxHdIKf8yV1JyGUbG8dM4QFo6T7K3+Vw1n35THWKlrgfO2ioQDGnqCC0wB3/CYFNbx2kbI/a94Efw1naWTi8l5i1crP79NTtnYYcC99uKgjDdTGF3nPSUCBfGIHKL4Om3c3cJFldH4= 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=wr37eegH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5rPom+43; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wr37eegH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5rPom+43" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KojHsUmnaKlAnVKLT+0v3BUrTmPahlzMHsR5eizc+bo=; b=wr37eegHVfXp2lq3ICPplXn0WQEUpOdroNOhoRZA2nCH9UFTgNrnj+/MxI/SU/baK1Rv+n cWRyProtK7anwrpIz6b9zeHNIL8FTiDDyGfeWWT8nNa9MxQ7xxkiw4zcsShwf6RHPNklhi hsnS+Q0VMY/aN0RcFR8+8lV3GrNoSQI2ELVscfnQoDlU0CYKhHOE5qOIvbSOvH9JJZ+UBh ajMRY4gpdYr9l4bWt95wTgSeF/AnR8tkosTtm1DjcPLRsrutmlfwtLV7DWYL7aXSe0FSr3 KSTtXtGF5HyrCl62fBessMBz+lukVwhzXtVfG0iTLP4tGGn7P+e+FzXCG2dJJQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KojHsUmnaKlAnVKLT+0v3BUrTmPahlzMHsR5eizc+bo=; b=5rPom+431AlLnuEmw1tIp4YKVzatpXFNlvW7IHFD1HIyQ/zNO/B7PFsKhI6o4Of5/CVW8n 153iRPvFTvi9QCCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 051/120] x86/microcode/amd: rdrand: Use standard CPUID(0x1) types Date: Thu, 28 May 2026 17:38:13 +0200 Message-ID: <20260528153923.403473-52-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use standard CPUID(0x1) types from x86-cpuid-db instead of doing manual bitwise operations. Keep using a direct CPUID query, instead of the CPUID parser API. At a later step, clearing a feature bit like X86_FEATURE_RDRAND will also clear its cached backing CPUID bit, while the code clearly mentions that it wants to query the CPUID state regardless of the X86_FEATURE_RDRAND bit state. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 0e077a4f2646..5f885fafa238 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -807,6 +807,8 @@ early_param("rdrand", rdrand_cmdline); =20 static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *c) { + struct leaf_0x1_0 l1; + /* * Saving of the MSR used to hide the RDRAND support during * suspend/resume is done by arch/x86/power/cpu.c, which is @@ -819,7 +821,8 @@ static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *= c) * The self-test can clear X86_FEATURE_RDRAND, so check for * RDRAND support using the CPUID function directly. */ - if (!(cpuid_ecx(1) & BIT(30)) || rdrand_force) + cpuid_read(0x1, &l1); + if (!l1.rdrand || rdrand_force) return; =20 msr_clear_bit(MSR_AMD64_CPUID_FN_1, 62); @@ -828,7 +831,8 @@ static void clear_rdrand_cpuid_bit(struct cpuinfo_x86 *= c) * Verify that the CPUID change has occurred in case the kernel is * running virtualized and the hypervisor doesn't support the MSR. */ - if (cpuid_ecx(1) & BIT(30)) { + cpuid_read(0x1, &l1); + if (l1.rdrand) { pr_info_once("BIOS may not properly restore RDRAND after suspend, but hy= pervisor does not support hiding RDRAND via CPUID.\n"); return; } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 82347438FF4 for ; Thu, 28 May 2026 15:42: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=1779982967; cv=none; b=Up3BrqZPUSLWYueo5EkfSJThlA3Y3AKclnz+uskvASoj9Rg9melw3g6hg5NOg8lMve0BwNhe/jKP8pZgYxSLEuRdXGzp7mLEQ24DE0qUI6UtoFGV16rA1dTHoToB8lLfppYSoLYANzdEWAVWrGz/xYNcW7gUyYs6GPRB+txESsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982967; c=relaxed/simple; bh=47zD+8J/8CbmBWJ5KTw468g0/eK/SOXKQkm9KaesEPA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JAcPvoT/eKA9VF8zNSeVArIpYG89HKe6ZIprGS6YHNQxV3sizYjLnaQe1TiCOiVrolkj35+PR3X12kdvbNEFFP5fjE2JHcGo8geURmBOPvJoRu2Vjw6gcfW92ADn0YEEcuDWGCkd1jjn0AmRKaNihiipCLl1Rx7CV2YxHVkjJ/E= 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=uY24mQ4a; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vRMp24H6; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uY24mQ4a"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vRMp24H6" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P92cwmICW7XddJY+iMJcvZ9lc5RFe5xb/yx8TGv/6yw=; b=uY24mQ4aV2aHGOqkdVwxZTb14L7H5jb7WuFNRXVfh6Xbo2PLKmgl363gS8DHWKARUDuqva tn2a3EhG6vKWNAq+SECOVl4D10xxQ+sjqaHgHMYvKnStFcm10UB0E7edpGDTRq0ewRS6oP hh8mAkMg8mbTspTDH6OjmMZ1cFkBB4mlGhjN6iSFYV7k/XpvkTdF4UDSD3/2R8746B4H1E 0wLJkLxVtR/F+m+BytXKRBA1wdf9/N8bo+dyNbj90evFwR+eFrmrWNuTyX1jhTXQX3rRmt we1bFPq3X0wrzKeMqGJ4FD+Bkpj6EB0+oxTSnpnZ9wVgC2i88L+TG3Fl8TXFjw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P92cwmICW7XddJY+iMJcvZ9lc5RFe5xb/yx8TGv/6yw=; b=vRMp24H6T3M8QxaTEpBLPDxKzlkc2/L5zu6JSSjecAjnyVkA5vhiFuw6jfZ61Sb7vlVu61 ifoHhEeU8FE+2vBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 052/120] x86/microcode/intel: Explain CPUID parser APIs unavailability Date: Thu, 28 May 2026 17:38:14 +0200 Message-ID: <20260528153923.403473-53-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" intel_cpuid_vfm() is defined so that it can be used before cpuinfo_x86 structures are populated. Explain why it should not use the CPUID parser APIs as well. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/microcode/intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/mi= crocode/intel.c index 18d2eff7a4b7..a3d0f8197d4d 100644 --- a/arch/x86/kernel/cpu/microcode/intel.c +++ b/arch/x86/kernel/cpu/microcode/intel.c @@ -123,8 +123,8 @@ static inline unsigned int exttable_size(struct extende= d_sigtable *et) =20 =20 /* - * Use CPUID to generate a "vfm" value. Useful before cpuinfo_x86 - * structures are populated. + * Use a direct CPUID query to generate a "vfm" value. To be used before + * the CPUID parser is initialized; e.g. head's load_ucode_bsp() stage. */ static u32 intel_cpuid_vfm(void) { --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 1F69D43901A for ; Thu, 28 May 2026 15:42:46 +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=1779982970; cv=none; b=lCeeyw5GjGGXGQbZynSY/wolmu40vxSIIjm+lCBzfak6XTpjJ9IsRcAqjjilgqBv49XiO19deUWn8AvS5oYjNVYXox8zlwj+S7XFkcCD5LhnbxjoS9Wp6oPrVKehnfIshTpn7/k4l4QL/cSqH2xIdyeeah5EDhMWYowgAqzikAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982970; c=relaxed/simple; bh=6xUL5WMCAhMH7AxwEc+7wIL9NBviw4BJq67doOtj318=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SCPtFjifwWn2oUJjd3jb3Nk7zHL1uyMzxnt5om5sLKkw60hP69/sIrcgUIRjNcJ2/qMf51RdONNlddD5vSCDOIM5Cn76HBKnixX26AelDgPYaOiffF9j5CepU1JcIYoXMh5lIyROkolSQ7Pql6ppspu2JWG2amWbNss+oeJC4Us= 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=IDAQZzuF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xk91rWWi; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IDAQZzuF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xk91rWWi" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Z/vIg9LVX8/DLgPonJDlTDUj6Wxqd64AUvq7JbaCko=; b=IDAQZzuFW6QPQkx94CnrqRinyLf7tUd10fdmT5FJQMjEkMwPRP15dIprimj/D44Hv2FgQm XIO7bSObPe2k801rvtpIuPYLJlyxO1uA5qz3wGR9RxjUk5QiaSooPCu+bRljqjoj4gpCNy 1CQ5HNfsohVL3zz24cdHU8M9Z0UxfVteYMSk3eBIuxXEx82MEC2Y8TanqKFHDYiPBdmbgz eMZQJPlbsgciUEVO6NbMgxqjKe4crCjpUGLOv7jPMBbF/q/29KP9kkNkoQ8STcBGrJVZqE f5l2/CgxyaKkpTseP9Y+nMvdOeXevR6iCC1bIRaCYEWhOAXOFHgwTt5Y+MT+5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982964; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Z/vIg9LVX8/DLgPonJDlTDUj6Wxqd64AUvq7JbaCko=; b=xk91rWWipOXb2hEVyySYF1KGMAsRdjm5IsyOf1EiYs6Zl26sTjEyhRdScNQ4JVVRID676k zoO1NuSYo9bftACQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 053/120] x86/mm/pti: Use standard CPUID(0x1) types Date: Thu, 28 May 2026 17:38:15 +0200 Message-ID: <20260528153923.403473-54-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use standard CPUID(0x1) types from x86-cpuid-db instead of a manual bitwise operation. Note, keep issuing a direct CPUID query since disabling a feature bit like X86_FEATURE_PCID will disable its backing cached CPUID bit in the future. Signed-off-by: Ahmed S. Darwish --- arch/x86/mm/pti.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 598f553cc871..1f0a5e84cdca 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -631,13 +631,16 @@ void __init pti_init(void) pr_info("enabled\n"); =20 #ifdef CONFIG_X86_32 + struct leaf_0x1_0 l1; + /* * We check for X86_FEATURE_PCID here. But the init-code will * clear the feature flag on 32 bit because the feature is not * supported on 32 bit anyway. To print the warning we need to * check with cpuid directly again. */ - if (cpuid_ecx(0x1) & BIT(17)) { + cpuid_read(0x1, &l1); + if (l1.pcid) { /* Use printk to work around pr_fmt() */ printk(KERN_WARNING "\n"); printk(KERN_WARNING "***************************************************= *********\n"); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 28548436376 for ; Thu, 28 May 2026 15:42:49 +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=1779982972; cv=none; b=asYOuNVLuhS0usEe7AnLsC4aX+Xe3/e2thZkvgBf0OSo7cCCfv29Ga6ympJSIgbzx1xnVGzMd+6eWgmnQq2JUY/CIA/fevWi9RErNv4OBW+ezhITUCfjeBHcmYAus936KZhuBAs6eukBFPzGvxsyIvDioLOiTxjWlvjKmKsVGAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982972; c=relaxed/simple; bh=1ITqrBZMy3NZZZPnFPTp5jm2M3p9SayouHCM7d2b+l8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rIXYRLzAcQS0y+Lm6CpTltVh3MeipBRH6990i9qWvaMUSjfs37aq7G25WkwjBDG9ewyf3YTTkc/Zj9oPbB5nwaL5awGVFFlVJFlB9tigujdTCF1GmMHUzBGLkXyilS768bhmEMUXKdnBpuKl18dEQ4a04+QsvrCvpCQNBTkqC0w= 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=YVJ6bZmh; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Wxn/MI46; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YVJ6bZmh"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wxn/MI46" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBP+DUsQYUpIxnHnXTXZoOg/tXyMJG1c85t1PxQvzXg=; b=YVJ6bZmhAg0hwry8lggRx5qlJlSCc80IOUbS3WvEZk5cIcyLrtQZAC/ajZVKRuc4OfAAQl 06QMau9kCetT9cvHILnVgpa2a+oDk6IjVDbw8DmM3CS4ZAkBQ22EjysORROv5FMl2qgfs8 aqOCp+CozeRCCEeQvJWaQv7VgzViIZFnssN4vB65OHrsd7x3lJMHKWS/xGnvfCpodPaB/C tfaiRQ26vHCer+El1deOtGwwyjvMpJOp1TVO3k/bk8rEa0XqF0PaI4K1Cv+xh8OebPi5Kk ZhmVK4sdnO8nTLJT+J6M92UDQ3pFZKuEVPlVdDFhZsCfDB/4+YcmcWdhThFW7w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBP+DUsQYUpIxnHnXTXZoOg/tXyMJG1c85t1PxQvzXg=; b=Wxn/MI46v/dK1dCfrgmncsMj/Yh3Rgig+T6S4MrgDppwZjo7v+7Tbnv61di7ltvr/FWulG Wz7Ud42UkeEyDwAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 054/120] x86/xen: Use parsed CPUID(0x1) Date: Thu, 28 May 2026 17:38:16 +0200 Message-ID: <20260528153923.403473-55-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Xen init, use parsed CPUID(0x1) instead of manual bitwise operations and a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- arch/x86/xen/enlighten_pv.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 223e9a2eb2d5..4883d6095436 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -369,15 +369,13 @@ static bool __init xen_check_mwait(void) =20 static bool __init xen_check_xsave(void) { - unsigned int cx, xsave_mask; + const struct leaf_0x1_0 *l1 =3D cpuid_leaf(&boot_cpu_data, 0x1); =20 - cx =3D cpuid_ecx(1); - - xsave_mask =3D (1 << (X86_FEATURE_XSAVE % 32)) | - (1 << (X86_FEATURE_OSXSAVE % 32)); + if (!l1) + return false; =20 /* Xen will set CR4.OSXSAVE if supported and not disabled by force */ - return (cx & xsave_mask) =3D=3D xsave_mask; + return l1->xsave && l1->osxsave; } =20 static void __init xen_init_capabilities(void) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 2E02A3FD979 for ; Thu, 28 May 2026 15:42:53 +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=1779982975; cv=none; b=u3WE5ifDCGc1ZG5WTDk2mesw+z3ORdqLVJ0mr1Gf8EghL1Cs+9dwiWFBOFtz6As/2ptsu1vc+aqDSX0PmCYhikm9iI6sBxvOqbWrLsizyRkFvgwoVjiC49nUREN34wPykXlPhyydp6dqkYUs/p+xuKd7IZtFSrGgjh0Yce4j7os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982975; c=relaxed/simple; bh=M1FfwpmHGvkUWxsr3uPbna8zV//R1dZn4K/pzKppGTg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lpIxNuqAJ46MWUskAenqneWExXCgy57yMrKLKfkLvCQBi4+PzVExIhdB3A3qtzeTuGNu+/UBw46JtmxZNiI1K9505CoOlLUhm3uTStVjJLkKpxECvsyTusq72VvvSRi6WHfG9+MdDBzTOIKYKZEUL1QJZLAa0vUX8Z9jcl8oMFg= 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=jWIQjF3L; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=oMfvtdtW; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jWIQjF3L"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oMfvtdtW" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xKAWjziCCTKGcDvNT4l2z03TJf8ssVK695haTJMaG3A=; b=jWIQjF3L2RcYQEtwYbj1ytlzdMaTsC7jidsWSJ3yHGjdjtkUEPIrVrUzyCuJ+vAr4bOXUe 67+iBQBqzlwLI37fI8vftE7tSbxFWrhTjJoWgbwJ9vgVTRWey4AsIjReyOlNBurPKITsMe g4TeDkQZRd3gwBiAq7vkRBl2NXhXHS09gemM7zxEpv+m7Gk5J9xnVkNm0fW4JthhLq+ZNX CaR45RfqU/6tJfinZD9YLn3OUlBi39X+di9hOagLhtkmc/0lV8VK57VBk3dmMNZs2BVs6d AdVaHyWBHNac9y+SSCR3NBCsautz2NNOUdqM1yHZKXpgBeAeLxqZGfSMoPyiAQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xKAWjziCCTKGcDvNT4l2z03TJf8ssVK695haTJMaG3A=; b=oMfvtdtW5iwvgsMlxWwhrs92K/ELk+Tnz4ZpjCl/6jH4eKTf8LCTdwI7XzQXeP6NHp/UuC ljh/T7X61grvsCAQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 055/120] x86/xen: Use standard CPUID(0x1) types Date: Thu, 28 May 2026 17:38:17 +0200 Message-ID: <20260528153923.403473-56-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For early Xen init code, use x86-cpuid-db's CPUID(0x1) C99 data types instead of doing manual bitwise operations. Note, CPUID APIs like cpuid_leaf() cannot be used here since the CPUID tables are filled using paravirt __cpuid() instead of native CPUID. Signed-off-by: Ahmed S. Darwish --- arch/x86/xen/enlighten_pv.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 4883d6095436..3f9e90d3784e 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -303,9 +303,14 @@ static bool __init xen_check_mwait(void) .u.set_pminfo.id =3D -1, .u.set_pminfo.type =3D XEN_PM_PDC, }; - uint32_t buf[3]; unsigned int ax, bx, cx, dx; - unsigned int mwait_mask; + union { + struct cpuid_regs r; + struct leaf_0x1_0 l; + } c1 =3D { + .r.eax =3D 1, + }; + uint32_t buf[3]; =20 /* We need to determine whether it is OK to expose the MWAIT * capability to the kernel to harvest deeper than C3 states from ACPI @@ -325,15 +330,8 @@ static bool __init xen_check_mwait(void) if (!xen_running_on_version_or_later(4, 2)) return false; =20 - ax =3D 1; - cx =3D 0; - - native_cpuid(&ax, &bx, &cx, &dx); - - mwait_mask =3D (1 << (X86_FEATURE_EST % 32)) | - (1 << (X86_FEATURE_MWAIT % 32)); - - if ((cx & mwait_mask) !=3D mwait_mask) + native_cpuid(&c1.r.eax, &c1.r.ebx, &c1.r.ecx, &c1.r.edx); + if (!c1.l.est || !c1.l.monitor) return false; =20 /* We need to emulate the MWAIT_LEAF and for that we need both --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 665E643C061 for ; Thu, 28 May 2026 15:42:56 +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=1779982979; cv=none; b=rMKc7h7zhfxqsgRQfTLtSfgG8D6eOHnODu7PQ2TdEEMsoMnCRqwfrNxzq/e7VY//IML/7qUqYIygPvzLgzzc1Ouf3Igbcv42Hc0POHHJ+WHnAwgPc0U0L3WGSYNkJlzSQT2d2dH7FlcqgUC3VZnuvkQ6s4EyPgarkaoXu3sSTVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982979; c=relaxed/simple; bh=3Hk8qjTpkD/7lz2aOCXBHOQmkw6L0XKu4Gx5z0ZyY/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mKD61oTgcsV3n0euEolexgb+UjCK5kV6S0k/FIvu9m8XZIzsDvHuVxiI+T5zUWYPLa0LXd0e3nfGScpQvmUPKifIk/MgSq5gj8WDvAXDvRgtIG7ku1tOPphiinUU3MZg36zj0wOvl3VjnPwKM/YtGmHlFTiBPZ8yuwhpbKbA2Zg= 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=jhHafDgT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=M8CwjRTz; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jhHafDgT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="M8CwjRTz" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pHOcoIQB4PK6V6qk2S6ufDKHEJiNbyx4GdwjToAzx30=; b=jhHafDgTH5tYXwWESEb+aGL+sHQ34qXc+jmj+LmW2Wgy1QE+zQ/wXSzWW8OqzFaUOPNUir b4WuzR33RVfIV8cEBRt4KKUydPXlWTRcvkbGxL3nZ1ARhXeTtpiU38RqnusunOfpwEczap vE2ng2k41MMuN7b5PBUo45OGBE2TmsAtJFPjBosQv90zkXBR+V/AHrXPJZF5E2wmPnXpUb BgrNWGxIVsDaTcsFLI16maFciSfpl6bR7tlpFX6L9kEHywMmeIlSNz82p4D6qKuZVVFyXm JEelxGmrj8hQE/khcWZl2GGntvOpHjjAC8lrRITGTkl1XHBavB3LaHpD8DIcOQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pHOcoIQB4PK6V6qk2S6ufDKHEJiNbyx4GdwjToAzx30=; b=M8CwjRTzhAEpVpDlrHDNjLfEhmavEN+ew3rdT+T8mf7vlsqMH4z+W3eCOqK0J8ZiDyG2la DFn8xb1bkRHQ49Ag== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 056/120] agp/efficeon: Use parsed CPUID(0x1) Date: Thu, 28 May 2026 17:38:18 +0200 Message-ID: <20260528153923.403473-57-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x1) instead of manual bitwise operations and a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- drivers/char/agp/efficeon-agp.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-ag= p.c index 4d0b7d7c0aad..41c7dac096ab 100644 --- a/drivers/char/agp/efficeon-agp.c +++ b/drivers/char/agp/efficeon-agp.c @@ -192,21 +192,24 @@ static int efficeon_free_gatt_table(struct agp_bridge= _data *bridge) =20 static int efficeon_create_gatt_table(struct agp_bridge_data *bridge) { - int index; - const int pati =3D EFFICEON_PATI; + const struct leaf_0x1_0 *l =3D cpuid_leaf(&boot_cpu_data, 0x1); + int num_entries, l1_pages, clflush_chunk; const int present =3D EFFICEON_PRESENT; - const int clflush_chunk =3D ((cpuid_ebx(1) >> 8) & 0xff) << 3; - int num_entries, l1_pages; + const int pati =3D EFFICEON_PATI; =20 num_entries =3D A_SIZE_LVL2(agp_bridge->current_size)->num_entries; =20 printk(KERN_DEBUG PFX "efficeon_create_gatt_table(%d)\n", num_entries); =20 + if (!l) + return -EIO; + /* There are 2^10 PTE pages per PDE page */ BUG_ON(num_entries & 0x3ff); l1_pages =3D num_entries >> 10; =20 - for (index =3D 0 ; index < l1_pages ; index++) { + clflush_chunk =3D l->clflush_size * 8; + for (int index =3D 0; index < l1_pages; index++) { int offset; unsigned long page; unsigned long value; @@ -236,13 +239,19 @@ static int efficeon_create_gatt_table(struct agp_brid= ge_data *bridge) =20 static int efficeon_insert_memory(struct agp_memory * mem, off_t pg_start,= int type) { - int i, count =3D mem->page_count, num_entries; + const struct leaf_0x1_0 *l1 =3D cpuid_leaf(&boot_cpu_data, 0x1); + int count =3D mem->page_count, num_entries, clflush_chunk; unsigned int *page, *last_page; - const int clflush_chunk =3D ((cpuid_ebx(1) >> 8) & 0xff) << 3; - const unsigned long clflush_mask =3D ~(clflush_chunk-1); + unsigned long clflush_mask; =20 printk(KERN_DEBUG PFX "efficeon_insert_memory(%lx, %d)\n", pg_start, coun= t); =20 + if (!l1) + return -EIO; + + clflush_chunk =3D l1->clflush_size * 8; + clflush_mask =3D ~(clflush_chunk - 1); + num_entries =3D A_SIZE_LVL2(agp_bridge->current_size)->num_entries; if ((pg_start + mem->page_count) > num_entries) return -EINVAL; @@ -255,7 +264,7 @@ static int efficeon_insert_memory(struct agp_memory * m= em, off_t pg_start, int t } =20 last_page =3D NULL; - for (i =3D 0; i < count; i++) { + for (int i =3D 0; i < count; i++) { int index =3D pg_start + i; unsigned long insert =3D efficeon_mask_memory(mem->pages[i]); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 4167343CEE3 for ; Thu, 28 May 2026 15:43:00 +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=1779982982; cv=none; b=lQks2CqF4lhYt7Fba7wyhlvUwdcpFyXCvlGKFiei1h+M/A+0uNH5qSSV1FRy3JnJ6xwXMr+bZ7VxXXwLsQbIRlse20uYA4dbjdZebJwM9e5qF6VPYLHMoKCIN8JCkebXCBfq6fP0x/RYhBw9YUrgOgUCFZkRyuux9INHEMuNSX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982982; c=relaxed/simple; bh=NtBL1kPLdTCcwDrVgLNh7UBCqxh5930n9Yp5tQPf5zw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uctfeZ+zGNS8tX+CtvnG+vUD2DdRkfaEknihLe4tQwE+sTGyDKOK+g9+yuCbA7Cj+OCuH885gShtldOVMjrwVtNTjVMq/YMjMB6ykm+ZRr/KXujeVZX/gMc56ynXgVC5AmcGmxiexukjN+JRf3zSvqb7NXs5tJ6qC+IxSecPUn8= 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=2Tx71IqM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3EZS2pll; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2Tx71IqM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3EZS2pll" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XHKPVJcm9wUI5iSR08ga4f6o1fMgcl4v5dV8T+G6oJk=; b=2Tx71IqMcLjc6U/uNnwc85aeVkBkYzZUKIp3SaspxaIjX8e+W6qPDCNZimD95xo2t+e5LH iN4OYKExh+U540Bvo4Se1VH/M6bV/gBInUZcYPJIS/yZy5Sb7241bL3Hb637YUnTdtZNux boRjNRD0eCznS3fAA9NljhU55M1D/NsqZT2HiDbNcuBRZb+TQ4s/RomADx+IEjF6UUfOQJ 7qWxw9xJ3V608wtTbwNq7Z1ZHLtpbPrFTILJNmqD7HCKL5oM+XcxN9P0HEoeWAfqN9HiHo DqQEHh3oDg+WyLCB/HqbizGjnNW6LUqTkHHmDLptzCKRCGiDwVVCz1RhiL++Zw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XHKPVJcm9wUI5iSR08ga4f6o1fMgcl4v5dV8T+G6oJk=; b=3EZS2pllXQr0CphgLxmjxoLxrN6r8UqW2OUfH35wI0aa106DDULwCAW7ya4sc7NXC7hVLF aGIFd5mBHvP25mAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 057/120] dmaengine: ioatdma: Remove custom UP local APID IC code Date: Thu, 28 May 2026 17:38:19 +0200 Message-ID: <20260528153923.403473-58-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since commit b4033c1715cb ("[PATCH] PCI: Change MSI to use physical delivery mo= de always") and a cpu_physical_id() implementation exists for UP kernels. Replace the driver's private UP APIC ID implementation with the kernel's generic cpu_physical_id() helper. This also avoids a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- drivers/dma/ioat/dca.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/dma/ioat/dca.c b/drivers/dma/ioat/dca.c index 5d3c0ae6b342..07c977bef5f8 100644 --- a/drivers/dma/ioat/dca.c +++ b/drivers/dma/ioat/dca.c @@ -11,13 +11,9 @@ #include =20 #include - -/* either a kernel change is needed, or we need something like this in ker= nel */ -#ifndef CONFIG_SMP +#include +#include #include -#undef cpu_physical_id -#define cpu_physical_id(cpu) (cpuid_ebx(1) >> 24) -#endif =20 #include "dma.h" #include "registers.h" --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 DB99B43CEFF for ; Thu, 28 May 2026 15:43:03 +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=1779982986; cv=none; b=NRSEs6vycnhmSk9wRJPX61amh4Ks8tPrDl7VwCGzGnfvhhipz4kWgnJmO746vz2BbrpqH04j3XO1c4tzPxqyYYlE6tTYh/jicz5PFJPGcz7Uzaxjh6gL1BQaBBJ131XZ96/eibR8NnG6J0xJCuCyz25oMsSGXAOAIiWzkGHcqKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982986; c=relaxed/simple; bh=OzbMkNfvSgMjh17hw6oBkatjeyZ9fdpsDpYZanXEb6M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F/Uf81f8chZuLMKt8sn4/C5Oye2bDqp9tihpvym6xQ+8o4wF5GvwtKlp+Xg8zpD9TuSJ4jTiTgOpikXJpZmjFVNAws17HBMdw/Ebmm9WDC8MnXCI9JsnHxt0H2ukPvFQEptpBpvYuByBMuodl2iWKCpYBrImZuwl67CPe8LHGpE= 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=HVAtGMRK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DOLiKCnM; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HVAtGMRK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DOLiKCnM" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uJEK5e8SMRKJ40GkJz3gEJhbYerJ6L85sZzUjPynPZQ=; b=HVAtGMRKs6JJe0RyjWSGRw3yM//aRpmIOZ9870dLl909IwaMt5VlMfDJivFi8cPqZe+2zv FNxVofjRZMn/93XT2nBm+z5Z6nr9e2KR9vOWdTgGrMvetOBy0Z0uIe2WDW+c+8W21v/9hr bxStT8mzC2jgODphF2FkdS/Y6NH7w3Cs6vbpn5YNroYqRED455Dgm3GD5Z4OMTll1NatHf AHnvbn5SrAceiWv1pRBdZM9e19vdyksc7eXTQz24ynzMVFybi3SXLL/7hVdNE1xYoQJ9qR sadx0LPqqmnMmnTz7gsXwSBGGLbZ3NMhfshAYKK4kjeWBobOOhbyvFHwMWc1Yg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uJEK5e8SMRKJ40GkJz3gEJhbYerJ6L85sZzUjPynPZQ=; b=DOLiKCnMNtBlu5yxyVMl288kAuRgAyk7GBHEsh/V6Cg9yfSnIvQWSA7vQB0v1ENf+M9mDj rHMYlQICgAkiiIDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 058/120] RAS/AMD/FMPM: Use parsed CPUID(0x1) Date: Thu, 28 May 2026 17:38:20 +0200 Message-ID: <20260528153923.403473-59-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x1) instead of a direct CPUID query. This centralizes CPUID parsing and access for the kernel. Note, follow the API requirements by checking the for NULL beforehand. Signed-off-by: Ahmed S. Darwish --- drivers/ras/amd/fmpm.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/ras/amd/fmpm.c b/drivers/ras/amd/fmpm.c index 4ccaaf7b70bf..bd8450ec61e2 100644 --- a/drivers/ras/amd/fmpm.c +++ b/drivers/ras/amd/fmpm.c @@ -564,11 +564,15 @@ static int save_new_records(void) /* Check that the record matches expected types for the current system.*/ static bool fmp_is_usable(struct fru_rec *rec) { + const struct cpuid_regs *l1 =3D cpuid_leaf_raw(&boot_cpu_data, 0x1); struct cper_sec_fru_mem_poison *fmp =3D &rec->fmp; u64 cpuid; =20 pr_debug("Validation bits: 0x%016llx\n", fmp->validation_bits); =20 + if (!l1) + return false; + if (!(fmp->validation_bits & FMP_VALID_ARCH_TYPE)) { pr_debug("Arch type unknown\n"); return false; @@ -584,7 +588,7 @@ static bool fmp_is_usable(struct fru_rec *rec) return false; } =20 - cpuid =3D cpuid_eax(1); + cpuid =3D l1->eax; if (fmp->fru_arch !=3D cpuid) { pr_debug("Arch value mismatch: record =3D 0x%016llx, system =3D 0x%016ll= x\n", fmp->fru_arch, cpuid); @@ -719,15 +723,19 @@ static int get_saved_records(void) return ret; } =20 -static void set_fmp_fields(struct fru_rec *rec, unsigned int cpu) +static int set_fmp_fields(struct fru_rec *rec, unsigned int cpu) { + const struct cpuid_regs *l1 =3D cpuid_leaf_raw(&boot_cpu_data, 0x1); struct cper_sec_fru_mem_poison *fmp =3D &rec->fmp; =20 + if (!l1) + return -EIO; + fmp->fru_arch_type =3D FMP_ARCH_TYPE_X86_CPUID_1_EAX; fmp->validation_bits |=3D FMP_VALID_ARCH_TYPE; =20 /* Assume all CPUs in the system have the same value for now. */ - fmp->fru_arch =3D cpuid_eax(1); + fmp->fru_arch =3D l1->eax; fmp->validation_bits |=3D FMP_VALID_ARCH; =20 fmp->fru_id_type =3D FMP_ID_TYPE_X86_PPIN; @@ -735,6 +743,8 @@ static void set_fmp_fields(struct fru_rec *rec, unsigne= d int cpu) =20 fmp->fru_id =3D topology_ppin(cpu); fmp->validation_bits |=3D FMP_VALID_ID; + + return 0; } =20 static int init_fmps(void) @@ -761,7 +771,9 @@ static int init_fmps(void) break; } =20 - set_fmp_fields(rec, fru_cpu); + ret =3D set_fmp_fields(rec, fru_cpu); + if (ret) + break; } =20 return ret; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 15DAD43636D for ; Thu, 28 May 2026 15:43:07 +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=1779982991; cv=none; b=GWjA4LTvYn6LW2nRCj1pjrC4TZfAWIAwWJNvYTTPZYOIK4rthJsLwE00tc/FpiEtPOSEV4IDAHXqFNgE23/i4VcaSmXtf0HQATbzB2CTMNJxUKWm7Rf+wrwK4YcYzKo79l4ggtFehYGZjuXDDnNeA3m1EQ4bOX1g88MCmmsID08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982991; c=relaxed/simple; bh=uhJjxP2ljnilFAbPDK/cNwgzDiQTgwEof3SscxyDo8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qtde8QJFoRV4VaeHIjx6xzXCyT+VpPOrw38FViwlD+JCU4JH2z0x2CYMtXiEWI8O2E1NrWeOg/RdI3qHNFUXwIelv2PlvVLZ7dCjjwjth1hMECEVF1UYsKwHmB4D5QOyJUlywSCxX8DGMc06OSBBqkVD9wmApiY/igaaG4I5qR8= 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=cCUBlJtO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BGWx+l6O; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cCUBlJtO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BGWx+l6O" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982985; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CRel2xHP5UT8l6ZG5h7n1bmUYlPE1sIeazfmiafXKJE=; b=cCUBlJtOLrtstwgj0LuEtJPaoCXPGtJsSOUQc0PbwUUd4IFJmE0d8iG9/d/d1EHEfm/Aus R42wjwnZxraoYs7slRChTXRXJSV8IZ4gfZ5daVuQ4gDA4bW5wT/v91/vl1X0G0A0phN7kn cv5mJ/j39d/8tZFLHoHVKMFaiasBGt+DOSEDjDLtye0rwat0vY6DOc922N/flITh9+hnSJ c8KgdSO6vjMHYXts4Da8hHKKpG+3tWT9NkBbYJfUcH7aOLd6pvLqp9YF/VWy3GTCjeRCtK scQQuHvHGtgJDg3gk6Q86qu1DS6auMakj22DYeS0cNcML/H4j7EwPn9f7AYSRQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982985; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CRel2xHP5UT8l6ZG5h7n1bmUYlPE1sIeazfmiafXKJE=; b=BGWx+l6OdWI6VHo7NEmXHaD3Q6vgD4L6gMLgOZ3+HEtdm9jDMFnytVe9gpL8Iw/Pz8CDNI TuptOwnqiE/S63BQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 059/120] x86/cpuid: Parse CPUID(0x5) Date: Thu, 28 May 2026 17:38:21 +0200 Message-ID: <20260528153923.403473-60-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x5), CPUID_LEAF_MWAIT, so that its call sites can be converted to the CPUID API next. Introduce cpuid_mwait_n_substates() since its logic is required by multiple call sits. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 19 +++++++++++++++++++ arch/x86/include/asm/cpuid/types.h | 1 + arch/x86/kernel/cpu/cpuid_parser.h | 1 + 3 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 611ee8596115..540f886a61cd 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -493,6 +493,25 @@ static inline u32 cpuid_base_hypervisor(const char *si= g, u32 leaves) _ptr < &((const union leaf_0x2_regs *)(_regs))->desc[16] && (_desc = =3D &cpuid_0x2_table[*_ptr]);\ _ptr++) =20 +/* + * CPUID(0x5) + */ + +static inline unsigned int cpuid_mwait_n_substates(const struct leaf_0x5_0= *l5, unsigned int cstate) +{ + switch (cstate) { + case 0: return l5->n_c0_substates; + case 1: return l5->n_c1_substates; + case 2: return l5->n_c2_substates; + case 3: return l5->n_c3_substates; + case 4: return l5->n_c4_substates; + case 5: return l5->n_c5_substates; + case 6: return l5->n_c6_substates; + case 7: return l5->n_c7_substates; + default: return 0; + } +} + /* * CPUID(0x80000006) */ diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index f50e54bfb514..50156e9883a3 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -212,6 +212,7 @@ struct cpuid_leaves { CPUID_LEAF ( 0x1, 0 ); CPUID_LEAF ( 0x2, 0 ); CPUID_LEAF_N ( 0x4, 8 ); + CPUID_LEAF ( 0x5, 0 ); CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index ab391de03a92..3a60dad4e861 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -146,6 +146,7 @@ struct cpuid_parse_entry { /* Leaf Subleaf Reader function */ \ CPUID_PARSE_ENTRY ( 0x2, 0, 0x2 ), \ CPUID_PARSE_ENTRY_N ( 0x4, deterministic_cache ), \ + CPUID_PARSE_ENTRY ( 0x5, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C5DDF43DA4C for ; Thu, 28 May 2026 15:43:10 +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=1779982996; cv=none; b=WNNYR466gniscW9drtiqKkNYmrUx4E5gpOlYKOLS5koN8z9NNZ2URmeAZDWElHUZf43DuiwN6JjmtcBRqNniotk/hi/dksqCXlAmhVj4wRlvXHSby3OFvxiRQiNy+UORG2GSqb7h9Kl1HVnEmUgtPVQ7wrnUtSCpQBg8kq2BU2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982996; c=relaxed/simple; bh=iVDWm1TtnXk/T6tJCLOV8wgq9OCpsSx5iq7QQh1/eNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GZaqi02G2Stdi7E313Jwl+rR9QhkG9GRvt7e+ShWP8+LfcZAamoTDD28pwL6oAcw4SIoH0g4liGWN3BJU+Etdz1Tz/SpDo2Z4cGlffzQ0tkiVlQrdeJ4TgnrSxJ0eiJp4tsEFh5DS4eZh8+DrBr42RIqyuHTAelZEWC5+TRNcVA= 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=iMhQvazS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Wg6s7nFz; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iMhQvazS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Wg6s7nFz" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O945PT5mgFGGsD+3CsmT7+wcn/pRG5zNHz1p7UPjKAY=; b=iMhQvazSLdF5xNkc4yLYjThhfhcvUy6fxxpC4R5FlV2orFPCew+zgbaMD4VDQmFYskmFyD T22fdtcyLJKfpp5/oaPFTeSe4z74mQXpWVm8xqmgErHg12SM2/Jo4rLBPBq5OZUKH6taHk ADP5yOznoOpDYHAnIsRMsBpOdKZGBEDb7kWrRL00yuOqcnRXJTkS4LYd6/q5+fhiTg4U5j Y6b6fOVfFY7JPh7U1E9ba281dJOJeMPjvgGAt4t+Qq7mJvB1+UmgfD6sLwz4IRaDuOLARc M0eH4YdazlW6bCsyNpUuvKZ6gjcNnoyjKY+Ggb1YrGzoaUaRJ+1dfRJxrcLeDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O945PT5mgFGGsD+3CsmT7+wcn/pRG5zNHz1p7UPjKAY=; b=Wg6s7nFzZOxZxDLnYPTiVyTB6poS8vkGGsQb6uBTOlsq3fmN6g2Cou6G780w+UNau9OBvh kwgloChiRnJPBZBA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 060/120] x86/acpi/cstate: Remove superfluous retval logic Date: Thu, 28 May 2026 17:38:22 +0200 Message-ID: <20260528153923.403473-61-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Just return the error or success state directly. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/acpi/cstate.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c index 0281703da5e2..f6bd7214fec4 100644 --- a/arch/x86/kernel/acpi/cstate.c +++ b/arch/x86/kernel/acpi/cstate.c @@ -124,7 +124,6 @@ static short mwait_supported[ACPI_PROCESSOR_MAX_POWER]; static long acpi_processor_ffh_cstate_probe_cpu(void *_cx) { struct acpi_processor_cx *cx =3D _cx; - long retval; unsigned int eax, ebx, ecx, edx; unsigned int edx_part; unsigned int cstate_type; /* C-state type and not ACPI C-state type */ @@ -138,21 +137,16 @@ static long acpi_processor_ffh_cstate_probe_cpu(void = *_cx) edx_part =3D edx >> (cstate_type * MWAIT_SUBSTATE_SIZE); num_cstate_subtype =3D edx_part & MWAIT_SUBSTATE_MASK; =20 - retval =3D 0; /* If the HW does not support any sub-states in this C-state */ if (num_cstate_subtype =3D=3D 0) { pr_warn(FW_BUG "ACPI MWAIT C-state 0x%x not supported by HW (0x%x)\n", cx->address, edx_part); - retval =3D -1; - goto out; + return -1; } =20 /* mwait ecx extensions INTERRUPT_BREAK should be supported for C2/C3 */ - if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) || - !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) { - retval =3D -1; - goto out; - } + if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) || !(ecx & CPUID5_ECX_INTERR= UPT_BREAK)) + return -1; =20 if (!mwait_supported[cstate_type]) { mwait_supported[cstate_type] =3D 1; @@ -163,8 +157,8 @@ static long acpi_processor_ffh_cstate_probe_cpu(void *_= cx) snprintf(cx->desc, ACPI_CX_DESC_LEN, "ACPI FFH MWAIT 0x%x", cx->address); -out: - return retval; + + return 0; } =20 int acpi_processor_ffh_cstate_probe(unsigned int cpu, --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 BF5E343E487 for ; Thu, 28 May 2026 15:43:13 +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=1779982999; cv=none; b=XLTnlMM7d6LVHzOH2sAWPR85cS1wJyu2Nrwi2wilm1TrAb/EEwsxpcVNoKT5p8QlBmi5K5gEKP29zDTduzpefNp2ukfNO+67p9N0cJnlUM+RJpMDpLvR3sTkoKBTJUug7bs3YgkPNF9nuP8uluWnqzt1e+5ZOS1JqezR/XV54pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779982999; c=relaxed/simple; bh=CzU626xh4+g/BtRfruWcH4vyGNF8gxkk++waKovub60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUGEQMeHwnYMDRkcLl6aXNPi1RSJ5PT+DjVW24IN2Exwcbj71afH6WYDNhxoGS+s0sxxAwIzhgasUb/5lHnVFqJgDKY2YGS88KFsGpe88lrj9Piey2EY7fRKL+3N2d0+tu7rWpa/lQ8mcRMel+Pw+UwZWFG8wxMr5D+TFTpRmZw= 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=nHIKbpBi; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vC38LxMG; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nHIKbpBi"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vC38LxMG" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GXVF7Zk/72ix9wX9ncM5wA+01plTJ9IQoNnnBYHMDcc=; b=nHIKbpBiVcVZjvXZAtCWY/nGQ5JFB4jF6P6+BNfyvGm93LzRX4AAaxRRr51TVFNlRYOcH+ 8UyDr24+GiOrhbZFEIbw7pMVLXxsX8scySSXK4e8mCeu+a1R6Nf/RcGA3yr1oGwxaQXZmE uXl3G2m7WfmHl77+XWHqiuEpd+slQD1ZrpuFHdGWVvHPPUQQlvl/I0yKd6qI+OPL4oFDnn bxICb03OwZqygWyPcc93vmeQZ/U5P3+shSnDCvvUy7f+DopHUakyAhqeHB7/0WZDrIXDsY SK2Sv2XM/ZpT1SdlFQoFGxphTqMaP1xAzHkcqjPVyE7A53DaueDSHK0TCrAXKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GXVF7Zk/72ix9wX9ncM5wA+01plTJ9IQoNnnBYHMDcc=; b=vC38LxMG0bmLHTBqlHd7Ewr2wcLh6DL1QvricSESoqTCyZpwGlLhjVRhTYBagsZV5uNrHt 6M4rKLTumtwk4BAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 061/120] x86/acpi/cstate: Clarify unsupported MWAIT hint warning Date: Thu, 28 May 2026 17:38:23 +0200 Message-ID: <20260528153923.403473-62-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MWAIT hint warning calls the ACPI FFH address an "ACPI MWAIT C-state" which is misleading. It is the firmware-provided MWAIT hint, where the C-state type is decoded separately from that hint. Clarify the warning message. Also remove the printed CPUID(0x5).EDX part value. The value printed is the shifted remainder used to extract the sub-state count, not the 4-bit sub-state field itself. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/acpi/cstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c index f6bd7214fec4..dbdacfbf53bd 100644 --- a/arch/x86/kernel/acpi/cstate.c +++ b/arch/x86/kernel/acpi/cstate.c @@ -139,8 +139,8 @@ static long acpi_processor_ffh_cstate_probe_cpu(void *_= cx) =20 /* If the HW does not support any sub-states in this C-state */ if (num_cstate_subtype =3D=3D 0) { - pr_warn(FW_BUG "ACPI MWAIT C-state 0x%x not supported by HW (0x%x)\n", - cx->address, edx_part); + pr_warn(FW_BUG "ACPI MWAIT hint 0x%x for MWAIT C-state type %u not suppo= rted by HW\n", + cx->address, cstate_type); return -1; } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 3A78043E4A6 for ; Thu, 28 May 2026 15:43:16 +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=1779983004; cv=none; b=hk2A62BvIfbNI1ouQK37aLbq1evNFvgQebtHMHh7FTeSKCpCPN4Iq5zIKcBv1O+VQl1DKvkK6QhAt6VmcS92p0l2UX2797v+ShrEvsWYC95+OQhoMJytqKqITSh1S6u5UdCL+gGq6UqZBNKpXHG1zjDdxO4kyMB3MDW1vdc2g2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983004; c=relaxed/simple; bh=T86cZtGPufTmePBb6EYD8QONTl3jM5ym9m6Ty8wWFMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TLr9L48XtyWGR3J9OGxm4d9iPCM/X92bmuaTMdPNWvfj0pySL31QlYms2hN0WyUIAgaXxSRlW9qvhxKaDoisBnfIXBb/+8LhqdWaE7zRapbmEtqCF4XnHY8bFeEgBBPY33/MjwUdpUrLfAYWTWfDtq92DnrYGz4A+WbvSB4BNTI= 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=AJnlj0jJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=XNEoQvSR; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="AJnlj0jJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XNEoQvSR" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C+hCepVpmdllDQi9UGntbSGdJI5SWxWNRWhxaHafejY=; b=AJnlj0jJgRP+to9DkZoY90IhAMLqXExvOT+y/SkAqD1MBSKtSIrrJVRTV4FIQqnUs4nTRN qIBrGmvvMhPnQB8L1SAohUhbmVZLK5dzfCQ8RII4VhSbgBRIjYqDcXaQTe9qwuGpNtXVgx za9i+cth0tEV0XhasSk/Pp3Etm7nqPAj86JvApa31obaTfOjWvnfzORdggYKEGzP0nilsw Et6fPAukpYyrzdGmSY5rn3YAKO1Y122CELPirOKtaXH5AaxeqrjCtONaQ7dMXDnrR/yUnP cwy43zceAm22Pv1uy+bDyCWKrw4UEHmvw0Sn+glSzZPJDcqSWbOyR8fUG8G8DQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982995; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C+hCepVpmdllDQi9UGntbSGdJI5SWxWNRWhxaHafejY=; b=XNEoQvSRhojqUe+gQKojDwBavthFuyaXqiTrbUtdfxiTdjnOxUoLr+mBXTxwJVh0FJcoji 28jTQtUo5+3fNJCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 062/120] x86/acpi/cstate: Use MWAIT helper macros Date: Thu, 28 May 2026 17:38:24 +0200 Message-ID: <20260528153923.403473-63-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use MWAIT_HINT2CSTATE() instead of open-coding its logic. No functional change. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/acpi/cstate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c index dbdacfbf53bd..4e7142d977c8 100644 --- a/arch/x86/kernel/acpi/cstate.c +++ b/arch/x86/kernel/acpi/cstate.c @@ -132,8 +132,7 @@ static long acpi_processor_ffh_cstate_probe_cpu(void *_= cx) cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &edx); =20 /* Check whether this particular cx_type (in CST) is supported or not */ - cstate_type =3D (((cx->address >> MWAIT_SUBSTATE_SIZE) & - MWAIT_CSTATE_MASK) + 1) & MWAIT_CSTATE_MASK; + cstate_type =3D (MWAIT_HINT2CSTATE(cx->address) + 1) & MWAIT_CSTATE_MASK; edx_part =3D edx >> (cstate_type * MWAIT_SUBSTATE_SIZE); num_cstate_subtype =3D edx_part & MWAIT_SUBSTATE_MASK; =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 4D0FB43E4BE for ; Thu, 28 May 2026 15:43:20 +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=1779983007; cv=none; b=em2EMRQ0fRhTg/N1KQOvQTUYnRwbMq5LXCm2iXTvbDpz38vQ2KzkXpFkF1BzQmLat42xzvhiep/dhnl3kXY4fWbemuaj43mDnC4Q4EFnghVTkJxVY+vZ+0JEUOCkQEd9OBFm76U1hwfV0wDxfHk+c+DhTagdYbME03ZfAUtKajQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983007; c=relaxed/simple; bh=GK/v5tNIQdJYpJzvLfMQhao5u3flgWTkR/U4OysxEZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u/0sLapD/iSo/vagdq/RLaWERNJqSHsG9NWoD7fzqchvT3z2JbpYukUKuQKieHB4wnxtVkwZtT/aVJ4XtCxFVsifMmo1lnidJE+yt11FZXnOUoTG3+hvXvR0GPHIVjPAhgPMRAqp0NENTzxQqU3bR3JDQy585IwdQmaM23uFUJA= 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=yYa1ZMUA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RkTsHTyg; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yYa1ZMUA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RkTsHTyg" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779982998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/TKCqzKq0KxicgXb/jFmqiHdFtBTUVE0X364IodOqok=; b=yYa1ZMUAT9SDPodYlwGGprmV67ZgzKv1pcZp9PwnBqF7CPhUYg9oN2gPCZSWJ+2ToidjjE L/rkD7kXAazh8ykGnEM/Hrf2fwdI0m3JdrnaDVcwcnZtrmhblxLEerZUQCfWXzXVx1TXYy dHdvrfQoNCw2nnxqG2+8ZuE13zaVaU4OKAU6SCbT4Zlkk4n1yFX2r1MsyMUeinpF2Y0lDR lOPGxn+XUALU2BbPGQOqqE2He+w0OoAdMCRhNKtrvzdrIqDluKxkJP8prihHYbidrTG43Y QeyyXuvJPaqe7zCrm4K3/zWBO5ymrwczeowd16/YVBqJldNvAWVBqvE92O9apw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779982998; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/TKCqzKq0KxicgXb/jFmqiHdFtBTUVE0X364IodOqok=; b=RkTsHTygQSQyHXZPpcW+Wync+4KK8BZLO4IBdHo0ysEOgJdJu5NpZJffsTIg2FZn2KPq4j +4R/MSSyo07570Cg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 063/120] x86/acpi: Use parsed CPUID(0x5) Date: Thu, 28 May 2026 17:38:25 +0200 Message-ID: <20260528153923.403473-64-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x5), plus CPUID(0x5) APIs, instead of doing ugly bitwise operations and a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/acpi/cstate.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c index 4e7142d977c8..75db968473e8 100644 --- a/arch/x86/kernel/acpi/cstate.c +++ b/arch/x86/kernel/acpi/cstate.c @@ -123,18 +123,18 @@ static short mwait_supported[ACPI_PROCESSOR_MAX_POWER= ]; =20 static long acpi_processor_ffh_cstate_probe_cpu(void *_cx) { + struct cpuinfo_x86 *c =3D &cpu_data(smp_processor_id()); + const struct leaf_0x5_0 *l5 =3D cpuid_leaf(c, 0x5); struct acpi_processor_cx *cx =3D _cx; - unsigned int eax, ebx, ecx, edx; - unsigned int edx_part; unsigned int cstate_type; /* C-state type and not ACPI C-state type */ unsigned int num_cstate_subtype; =20 - cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &edx); + if (!l5) + return -1; =20 /* Check whether this particular cx_type (in CST) is supported or not */ cstate_type =3D (MWAIT_HINT2CSTATE(cx->address) + 1) & MWAIT_CSTATE_MASK; - edx_part =3D edx >> (cstate_type * MWAIT_SUBSTATE_SIZE); - num_cstate_subtype =3D edx_part & MWAIT_SUBSTATE_MASK; + num_cstate_subtype =3D cpuid_mwait_n_substates(l5, cstate_type); =20 /* If the HW does not support any sub-states in this C-state */ if (num_cstate_subtype =3D=3D 0) { @@ -144,7 +144,7 @@ static long acpi_processor_ffh_cstate_probe_cpu(void *_= cx) } =20 /* mwait ecx extensions INTERRUPT_BREAK should be supported for C2/C3 */ - if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) || !(ecx & CPUID5_ECX_INTERR= UPT_BREAK)) + if (!l5->mwait_ext || !l5->mwait_irq_break) return -1; =20 if (!mwait_supported[cstate_type]) { @@ -163,11 +163,13 @@ static long acpi_processor_ffh_cstate_probe_cpu(void = *_cx) int acpi_processor_ffh_cstate_probe(unsigned int cpu, struct acpi_processor_cx *cx, struct acpi_power_register *reg) { - struct cstate_entry *percpu_entry; struct cpuinfo_x86 *c =3D &cpu_data(cpu); + struct cstate_entry *percpu_entry; + const struct leaf_0x5_0 *l5; long retval; =20 - if (!cpu_cstate_entry || c->cpuid_level < CPUID_LEAF_MWAIT) + l5 =3D cpuid_leaf(c, 0x5); + if (!cpu_cstate_entry || !l5) return -1; =20 if (reg->bit_offset !=3D NATIVE_CSTATE_BEYOND_HALT) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 33AAB43E4A3 for ; Thu, 28 May 2026 15:43:24 +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=1779983012; cv=none; b=GOMhSOdla2XYvLbN6IRKpVQrvFcA/E3+SmXwEYM0fQuWIvjBQkY7my9oIn5oC2oMY5V6PAbwptENSNLfnsRZx8U9hCyumyKz4gFawO6kSuKLoTZnaVHtXEm+NU9/0+PehVucue3NOjmGxDLrVUBSLrn78GABBzympnjHKs6sIr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983012; c=relaxed/simple; bh=Ay8jRlRhMa11kVphSg2fA0IvQ6NnDAjbsAKjqz7HKks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rl560K2SmGkgGoySXa+stH0njSFFBICixaWDIf+cGsOXpPuakJRR7/cinvm/V6jqLd7fdVY5/BoF+Amy+neToWhKsTbxZQ5usjIzWDiKF2awyhF7Axr5dRqNKIDcfYyVRI8uGCHPGv4kmaqiEjqkZuIIfSRP4ADAosptYnPOaI4= 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=LlybJ7M+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LG81Xy8a; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LlybJ7M+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LG81Xy8a" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=enZw8stDcOdPph8kfKDf63ZaVueS30wf93Ur4ndtgr4=; b=LlybJ7M+QMA49jHT64OUTWXeg40fVFIaOHI+W/OadkcVV8AZuFaoD+3Fz256G8FUXmiZjl tBlsEnj7nRgqg48LXxEbALBjTh68dvujK2MJzB7IEBIeArABvcQkC/5xgK+Np+JJRkgaPB ggeov6PVkfjSuddZsA9cF8nEbap8srMRHjYUHmkGi1jOF+aibjCl8tAdIgQcmYyPB5JjrZ yyW2fhRcVGtx3oAFeguUhstLnK/e6nBknuwmNV/SlXCaQ8bkM8cU9zR61uAK7XGAROMvq/ VNE2Yxb4/n6jw2YgD3KVvB2PsXza+kU1ztC5kR2/gWT/TlkrrPNzz0ClGMPKmg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=enZw8stDcOdPph8kfKDf63ZaVueS30wf93Ur4ndtgr4=; b=LG81Xy8ajLFyaoBs5zXCsCdavpMGcNvsvH6JLUcZckEP1HfGhh+yHP65ayuCYDb0Em2sNE jqZ0XJW4vIoR2JBg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 064/120] x86/process: Use parsed CPUID(0x5) Date: Thu, 28 May 2026 17:38:26 +0200 Message-ID: <20260528153923.403473-65-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x5) instead of doing manual bitwise operations and a direct CPUID query.. Remove the MWAIT_C1_SUBSTATE_MASK flag as it has no more users. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/mwait.h | 1 - arch/x86/kernel/process.c | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index e4815e15dc9a..40c827e7929e 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -13,7 +13,6 @@ #define MWAIT_SUBSTATE_SIZE 4 #define MWAIT_HINT2CSTATE(hint) (((hint) >> MWAIT_SUBSTATE_SIZE) & MWAIT_= CSTATE_MASK) #define MWAIT_HINT2SUBSTATE(hint) ((hint) & MWAIT_CSTATE_MASK) -#define MWAIT_C1_SUBSTATE_MASK 0xf0 =20 #define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1 #define CPUID5_ECX_INTERRUPT_BREAK 0x2 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 4c718f8adc59..6c1a69dbc71f 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -876,34 +876,32 @@ void __noreturn stop_this_cpu(void *dummy) static __init bool prefer_mwait_c1_over_halt(void) { const struct cpuinfo_x86 *c =3D &boot_cpu_data; - u32 eax, ebx, ecx, edx; + const struct leaf_0x5_0 *l5 =3D cpuid_leaf(c, 0x5); =20 /* If override is enforced on the command line, fall back to HALT. */ if (boot_option_idle_override !=3D IDLE_NO_OVERRIDE) return false; =20 /* MWAIT is not supported on this platform. Fallback to HALT */ - if (!cpu_has(c, X86_FEATURE_MWAIT)) + if (!cpu_has(c, X86_FEATURE_MWAIT) || !l5) return false; =20 /* Monitor has a bug or APIC stops in C1E. Fallback to HALT */ if (boot_cpu_has_bug(X86_BUG_MONITOR) || boot_cpu_has_bug(X86_BUG_AMD_API= C_C1E)) return false; =20 - cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &edx); - /* * If MWAIT extensions are not available, it is safe to use MWAIT * with EAX=3D0, ECX=3D0. */ - if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED)) + if (!l5->mwait_ext) return true; =20 /* * If MWAIT extensions are available, there should be at least one * MWAIT C1 substate present. */ - return !!(edx & MWAIT_C1_SUBSTATE_MASK); + return l5->n_c1_substates; } =20 /* --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 3248A44102F for ; Thu, 28 May 2026 15:43:27 +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=1779983016; cv=none; b=nq2EKuYLO3sOwsTZ9rbkDU0tGaOlt3LfwXd1dbTRT0Q6smw9v+o078xZTkYZvpToJ/cScyVW8H32I6L6da1NjfHIn/l8GBmaLAHMWj6Cvq/VLTzp+oZj7HtPVGTeyPXVIApWf67ABx9+F9LT4kHCaoGNNyD+e/aYI1in01DPY7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983016; c=relaxed/simple; bh=uF8Eykkg9lSIwPeMksAZ4aD/pH6c/vTY6DN7kYGk07Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wp7V/dnocALRiih/LWtGsaeHv5gTM0nEW/eI+NP/VZ9e2oSbeN1Bbe0iKwNngMHC0E+tcmIKC3wObMjK1CiOnlwdZOAjY1xJalL8v58fLVmaBDSt55cXZ0eFik7GS8bI7jLIAQYuuXzPg+OCd23RmTnjklaWpGvLiTWqzmhh8WE= 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=Dsno1Zym; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZRrFl/G3; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Dsno1Zym"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZRrFl/G3" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZiFXoaO6qqBLy37324cJNlU+dL5PUYM73cbVmeRGrHk=; b=Dsno1Zym2KE9X9CTeN31YNL8sM0gd37oTX0SX7QwZLC1/ZGxbn0rC7Bobj8NA7IbYCVQlM QDWAQahs/F0feCwUEcD4s4mHDhM1/ekfSpdEusmPAvblydlbzghM1fVcnjzN6u45jeVM5i +qA0zEywQSthkeqbYEPJNPJwydVM9K/R/iApGgQvhKVRh7CXysJOmY9J91ZvtxjgvcrCrD HEtTlwZJqdR/eebHyd+c6IKpyZcfpXXkvYDvMG+DYw5OS5aTH0n6yLiumELaKFPNcZT4oz Qn/Ck4PySQTsm0V1lU6mpFCAuMJVpBmwfTfxGq29mnoMPbUwI4HKlVe09lGe1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZiFXoaO6qqBLy37324cJNlU+dL5PUYM73cbVmeRGrHk=; b=ZRrFl/G3BNufOFEHhlcBK+N1oRA8sG3Op6ikac5/SGq2V17v1SVi6r9EPJmIWPHd3MZQFk yI3f1PfR4NGZ1EAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 065/120] x86/hpet: Use parsed CPUID(0x5) Date: Thu, 28 May 2026 17:38:27 +0200 Message-ID: <20260528153923.403473-66-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x5) instead of doing ugly bitwise operations and a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/hpet.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c index 8dc7b710e125..6f6f4e5072f2 100644 --- a/arch/x86/kernel/hpet.c +++ b/arch/x86/kernel/hpet.c @@ -11,7 +11,6 @@ #include #include #include -#include #include =20 #undef pr_fmt @@ -913,19 +912,15 @@ static bool __init hpet_counting(void) =20 static bool __init mwait_pc10_supported(void) { - unsigned int eax, ebx, ecx, mwait_substates; + const struct leaf_0x5_0 *l5 =3D cpuid_leaf(&boot_cpu_data, 0x5); =20 if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_INTEL) return false; =20 - if (!cpu_feature_enabled(X86_FEATURE_MWAIT)) + if (!l5 || !cpu_feature_enabled(X86_FEATURE_MWAIT)) return false; =20 - cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &mwait_substates); - - return (ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) && - (ecx & CPUID5_ECX_INTERRUPT_BREAK) && - (mwait_substates & (0xF << 28)); + return l5->mwait_ext && l5->mwait_irq_break && l5->n_c7_substates; } =20 /* --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 5749243E9DC for ; Thu, 28 May 2026 15:43:30 +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=1779983018; cv=none; b=VuWFf6mO/9z3XmQ43tNMx6YDmaCeJ5bJ99eroiEa8Zj0B4NOaWlAJej20tCv3Ff2z+Oxi7UA9cAa5/+3yk8LvsWO/Uv2gHa2pFhAxqnwl72aPUAhkl1Rq0InedSwAECLHWQL3k/t+Dw/9yCQGcSpeYwOj1SW1frjr+Uu7H5nhTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983018; c=relaxed/simple; bh=24UwSiiUnq91m0gUmYRYtiucM9buj3GOtlBsdEugwtE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qG0S9oHemr71I5EDw/2xxmwOCbRytghQc9HzPnKuGiIrtMEiTxexD/1BEkPX91BSBagEOt/jb6V+RFWGvPoff/y2huehRmBV2mQSlkCvIQQvLlfSz5B6jRRZaUTEgd6HxCyrUiDbqqn7vas5XbYQ3jVLkU/RerkLbu9YgbVyYaI= 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=4T5fMfT9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wxFiun+J; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4T5fMfT9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wxFiun+J" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PgZZ71omZMRVxIG6jBJNdV70OAiiP5NqOfaciMt/Bkg=; b=4T5fMfT9SMsn1h8xtW6GJOSjnoraj+E0odE6zrAdZDunxKOSVoACaW9stcAgE9VBV0nP9F B9ihw8slxDZMxC4aTKvNnnG2jsMtmQW5jtZ7SntTSXn6WhMEsTduc0gvuE1Fzgej2GOeFF FyQ7vz86yPKJ/cfwYw4rdiphNtnes4hY0puRgCCAxynaUBBZIZvD0o26DrN+ePyvfaR3bR qmW0MMYCelv31WbebdGs8dJtInAAa3uC+46YllPfdt+bHQ+tMc3Ix6Ea6zZoNBd5CeoFsS x3rcU/q0HpwUiH3MpHSw6BfNvmA3g8KRS7ndxgE/666UT5XJDgLRd/ej2u+JbA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PgZZ71omZMRVxIG6jBJNdV70OAiiP5NqOfaciMt/Bkg=; b=wxFiun+JIS3WvSuP1Ivz+vqtgRgyR7nNmEs05i7t1Fw9976nA/1lCFZPnyec1UYwBS/IWd VAsjBfjVYbeh/3Cg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 066/120] ACPI: PAD: Use Parsed CPUID(0x5) Date: Thu, 28 May 2026 17:38:28 +0200 Message-ID: <20260528153923.403473-67-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x5), plus CPUID(0x5) APIs, instead of doing ugly bitwise operations and a direct CPUID query. Note, preserve EDX walk semantics: the original code shifted EDX by MWAIT_SUBSTATE_SIZE before entering the loop, hence skipping the C0 substate count. Start the parsed lookup at C1 for the same reason. Note, the original "&& edx" loop condition avoided trailing zero nibbles but dropping it should not be problematic: zero substate counts are always ignored. Signed-off-by: Ahmed S. Darwish --- drivers/acpi/acpi_pad.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c index ec94b09bb747..45b1793cd3b4 100644 --- a/drivers/acpi/acpi_pad.c +++ b/drivers/acpi/acpi_pad.c @@ -38,27 +38,27 @@ static unsigned char tsc_marked_unstable; =20 static void power_saving_mwait_init(void) { - unsigned int eax, ebx, ecx, edx; + const struct leaf_0x5_0 *l5 =3D cpuid_leaf(&boot_cpu_data, 0x5); unsigned int highest_cstate =3D 0; unsigned int highest_subcstate =3D 0; int i; =20 - if (!boot_cpu_has(X86_FEATURE_MWAIT)) + if (!l5 || !boot_cpu_has(X86_FEATURE_MWAIT)) return; =20 - cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &edx); - - if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) || - !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) + if (!l5->mwait_ext || !l5->mwait_irq_break) return; =20 - edx >>=3D MWAIT_SUBSTATE_SIZE; - for (i =3D 0; i < 7 && edx; i++, edx >>=3D MWAIT_SUBSTATE_SIZE) { - if (edx & MWAIT_SUBSTATE_MASK) { - highest_cstate =3D i; - highest_subcstate =3D edx & MWAIT_SUBSTATE_MASK; - } + for (i =3D 0; i < 7; i++) { + unsigned int nsubstates =3D cpuid_mwait_n_substates(l5, i + 1); + + if (!nsubstates) + continue; + + highest_cstate =3D i; + highest_subcstate =3D nsubstates; } + power_saving_mwait_eax =3D (highest_cstate << MWAIT_SUBSTATE_SIZE) | (highest_subcstate - 1); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 97D3D4418EE for ; Thu, 28 May 2026 15:43:33 +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=1779983018; cv=none; b=NsFZ68QzAniv4TkvmrhjdALOFwwCkYkNw1/vKt1fM3l1fplVk//Qf7Gygv1v32syXRW7lWvKfMSe472pp/kBc/HJXfFy+vrYRArQweWWwW2be+njsDIegbxRlZ49vzvJmf3L83CvSlyrOTlVNVC1Xva++6r7udPFDlxQVB0k4cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983018; c=relaxed/simple; bh=oJbzE3XXdZOz0MA1OWa2Z/1p1LG8DGkZdXZAzMjz/bg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JM25x7ib+PNqdkxNxNJoDeQsXgYAs0TVcS+FRwCyEwPLcYbnLI85NlsRYa24gs9r7MEep2AIioDYwhd4xO2bZilyv/0dwpGmyrhg2MGAAvDnDWtpd07LxMGnrY/wEIwmFC1pyJjFUbm/ftq45a2Di0TaaUj4FqfXf1WhdRactfc= 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=ICkY8O80; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GfxxnY56; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ICkY8O80"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GfxxnY56" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xaROBArRkuazSJcno8u12j6VwuHC1hoJddM5EQabGF4=; b=ICkY8O80+MbcLSPkALrBIesUK/wpWplATWuWNAfsYytn/wISqj/zL6x6xrSSJeI9A9ZWJX ND6NyDaFAQNxWGljgKwa4zxTBdzGoFEeizxRDa8eqGG6cz/KYGRvWitODLCHULTjvgK7oB 6yxHkLJflZt4v7R4JhMQlMJhOzyayFIuO2vlSvxuHaytXnPgHWd8JFdYxYgicYSYaxbFK6 DlDQ4wDvezOQakId6yplnsWh73wCnEotun0BP6yfHPcmmaeJ+qj6FYXD5KX6NmcFxb7sP2 0RHQ0ZWfkMITdsJau0h21lwbXLcPdoWTPTp1FziXVYkWSxH8fyA/auGSg+6S2A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xaROBArRkuazSJcno8u12j6VwuHC1hoJddM5EQabGF4=; b=GfxxnY56kWD9qRMIFLMKazCEVn33UNYPb0yd4duZ4ZsjW43IWY5K0MBf0vtfiOAv1WITcq pIE2KDoEQs/4j8Cg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 067/120] intel_idle: Use parsed CPUID(0x5) Date: Thu, 28 May 2026 17:38:29 +0200 Message-ID: <20260528153923.403473-68-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x5), plus CPUID(0x5) APIs, instead of doing ugly bitwise operations and a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- drivers/idle/intel_idle.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index f49354e37777..e1cf5ed4b995 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -113,12 +113,11 @@ static struct device *sysfs_root __initdata; =20 static const struct idle_cpu *icpu __initdata; static struct cpuidle_state *cpuidle_state_table __initdata; +static const struct leaf_0x5_0 *mwait_leaf __initdata; =20 /* C-states data from the 'intel_idle.table' cmdline parameter */ static struct cpuidle_state cmdline_states[CPUIDLE_STATE_MAX] __initdata; =20 -static unsigned int mwait_substates __initdata; - /* * Enable interrupts before entering the C-state. On some platforms and for * some C-states, this may measurably decrease interrupt latency. @@ -2047,7 +2046,7 @@ static void __init sklh_idle_state_table_update(void) return; =20 /* if PC10 not present in CPUID.MWAIT.EDX */ - if ((mwait_substates & (0xF << 28)) =3D=3D 0) + if (mwait_leaf->n_c7_substates =3D=3D 0) return; =20 rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr); @@ -2135,10 +2134,8 @@ static void __init byt_cht_auto_demotion_disable(voi= d) =20 static bool __init intel_idle_verify_cstate(unsigned int mwait_hint) { - unsigned int mwait_cstate =3D (MWAIT_HINT2CSTATE(mwait_hint) + 1) & - MWAIT_CSTATE_MASK; - unsigned int num_substates =3D (mwait_substates >> mwait_cstate * 4) & - MWAIT_SUBSTATE_MASK; + unsigned int mwait_cstate =3D (MWAIT_HINT2CSTATE(mwait_hint) + 1) & MWAIT= _CSTATE_MASK; + unsigned int num_substates =3D cpuid_mwait_n_substates(mwait_leaf, mwait_= cstate); =20 /* Ignore the C-state if there are NO sub-states in CPUID for it. */ if (num_substates =3D=3D 0) @@ -2641,8 +2638,8 @@ static void __init cmdline_table_adjust(struct cpuidl= e_driver *drv) =20 static int __init intel_idle_init(void) { + const struct cpuid_regs *mwait_leaf_raw; const struct x86_cpu_id *id; - unsigned int eax, ebx, ecx; int retval; =20 /* Do not load intel_idle at all for now if idle=3D is passed */ @@ -2666,14 +2663,15 @@ static int __init intel_idle_init(void) return -ENODEV; } =20 - cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &mwait_substates); + mwait_leaf =3D cpuid_leaf(&boot_cpu_data, 0x5); + if (!mwait_leaf || !mwait_leaf->mwait_ext || !mwait_leaf->mwait_irq_break) + return -ENODEV; =20 - if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) || - !(ecx & CPUID5_ECX_INTERRUPT_BREAK) || - !mwait_substates) - return -ENODEV; + mwait_leaf_raw =3D cpuid_leaf_raw(&boot_cpu_data, 0x5); + if (!mwait_leaf_raw || !mwait_leaf_raw->edx) + return -ENODEV; =20 - pr_debug("MWAIT substates: 0x%x\n", mwait_substates); + pr_debug("MWAIT substates: 0x%x\n", mwait_leaf_raw->edx); =20 icpu =3D (const struct idle_cpu *)id->driver_data; if (icpu && ignore_native()) { --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C1719449EC3 for ; Thu, 28 May 2026 15:43:36 +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=1779983022; cv=none; b=ttaAosa1qyZGttBHAThalhcGdIf/g9L/A0b0qpo+2H2Sw4j712yOAbkdwB3fv5NEDX2qJCe4rNNO5IqKovvtWGHaOpQJUtZcd91a+3FpNS6GdBXKf+hbOOIMVx7pR1UkvPx7iVMW6B4Z+DMY98Lv4sCRPvcraZcTUf7b7Z0rFjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983022; c=relaxed/simple; bh=LfTIHOhdzKz6hHYy5kzhI50FlFLOCljxHq5Yu5JM58g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t/ZL/20APNszaTUVBsxhflbO9Q6TN3os7imez7ycFSvgsjPa+GTlIiy+t3idTUuOvvm2AV45k6bAG5xHTL02a+JR2UCvi3aIs0HrK3dfSMjsr0d+AWTHDZbTma1mONP3bDIByslWREnM0KSiLHMpIWV40yY2mVuvq82yqlmeTOM= 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=aZGCxeD7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6ZYHMh5z; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aZGCxeD7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6ZYHMh5z" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Zff6XG4XO2ypjJhAunZCDvk8Njw4n25Y2L6J5oUGrs=; b=aZGCxeD7ozmOtriXZJuZuivTuH0WiyV1ypkTYwmI2Cj6ZCRs4SAYHf2txXJCH3I1PqB6u0 JIFWhAhj4vBE7rB7lIo9V9b+X5NjiiAfpGQSAY+HqTupG9VJZr8sZ+BJ9hORvZGcH63TAE Bpg74i3yMbYS6h5aoe1haJCG+s2Aw+apUJKYJSU6yQFYK4cyGkv8swA4JwSt5OxePpAcmW BumYqMDoskDh2dWeymb+Y4ESAwrOP3HWs2w2d6036dLRn8unyD8vk03FHtfdKTX1dsMqgj bt5HLiamaEV4ZwB82nh/7KHPIgYX7jc9ij+S80kkGou8Wu/l1xbkVZEgcUuOTA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Zff6XG4XO2ypjJhAunZCDvk8Njw4n25Y2L6J5oUGrs=; b=6ZYHMh5zEiCHR20JgzkaS1qmkjx1pSM8aDZPZijmb2DxKrk8+54g48S+RzkgFUAKcGIBvi es3fhdhFebjfX5Cw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 068/120] x86/idle: Remove unused CPUID(0x5) symbols Date: Thu, 28 May 2026 17:38:30 +0200 Message-ID: <20260528153923.403473-69-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All CPUID(0x5) call sites have been converted to the CPUID API, where x86-cpuid-db data types with full C99 bitfields are returned. Remove the no longer used CPUID(0x5).ECX bitmasks. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/mwait.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index 40c827e7929e..ef400fa6343f 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -14,9 +14,6 @@ #define MWAIT_HINT2CSTATE(hint) (((hint) >> MWAIT_SUBSTATE_SIZE) & MWAIT_= CSTATE_MASK) #define MWAIT_HINT2SUBSTATE(hint) ((hint) & MWAIT_CSTATE_MASK) =20 -#define CPUID5_ECX_EXTENSIONS_SUPPORTED 0x1 -#define CPUID5_ECX_INTERRUPT_BREAK 0x2 - #define MWAIT_ECX_INTERRUPT_BREAK 0x1 #define MWAITX_ECX_TIMER_ENABLE BIT(1) #define MWAITX_MAX_WAIT_CYCLES UINT_MAX --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 DBE0B43E4B3 for ; Thu, 28 May 2026 15:43:39 +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=1779983023; cv=none; b=ClTn49CyBCeTsDXT63ZSoooPATXl8HUSU+VSsynBzEJdBq/G+/ouIoj77KNPnHGYvwZmfCBfEbOSJcSCjUWBHM2dILvUoMhXFlAQKa+mwcA3YQZCn5MhQ5k8J0Si7YCxW1hjRLyohYZrZx8QA2eH6SJAy4FJmTTDLV9rT/6pqs4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983023; c=relaxed/simple; bh=KTcG/XTJOlno6t2yjiGRtG11hsuByuAw3l0qI3DHej0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O9pg+EJhF8k15kw9Rox1bEQU73j4zAe7snRA3u7Z05EEWRS9Z9nUkoQxpLo+srrmwNrGAoSDLYRXdEOFpCrLrhl6zPfPfJno3QqjklO6+S+QUjhkJRQmmZpFKAvCS2uTQs7RMivytVLLLm1AySerVRf9KL1YGyY7CWpQ49x1i9E= 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=wTzRBTFX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jKSOz7TP; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wTzRBTFX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jKSOz7TP" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2VRNlbpKam19rn3Wb8IoFcn9Eb9LWbfddMmh/eVXZ7A=; b=wTzRBTFX/V2uctLXA92hZTzAO2Tsz9qDybPDGUYi4Hfav1AoCpFTFUHQCfEt8/aQ1O8mHw r3ivFjnZ//BMIMzKMRqMxsi+BaiyPKlfYdlZ4Bel3i9HJ7bBaRcuqYfLnr/2BBkAARaS6E quBn1DVOMIjyDFgO2lFSh5jLrrLj61PO3ok4MtcXBYo83lJkM8KALNWVbhqmLJUMSMKnLm gUI3JF1xvJHN5zzVjr+GUEmdtAqTq51PgKY9Ok/Plzap6YVtzClEBdUtuanhGr47T64toc KU8x6NZ1MLYNkVKysIuLhLhN02GAYbEOUjqwj1PFZyivW+cxiCEfqJBjRpOpKA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2VRNlbpKam19rn3Wb8IoFcn9Eb9LWbfddMmh/eVXZ7A=; b=jKSOz7TPCHMjWslEZIuSUI1eEtgMB8JKW1Ogk+VYm1A2IGrmKPPZL+AqYL4IKzClu+rd5s /T/O7IJKLhdpCYCg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 069/120] x86/cpuid: Parse CPUID(0x6), CPUID(0x9), and CPUID(0x15) Date: Thu, 28 May 2026 17:38:31 +0200 Message-ID: <20260528153923.403473-70-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x6), CPUID(0x9), and CPUID(0x15). Their call sites will be converted next. For HFI CPUID(0x6), do not add an Intel vendor tag. It is architecturally defined for AMD, even though the kernel only uses it on Intel boxes so far. For DCA CPUID(0x9), per the hardware manuals, check the CPUID(0x1).ECX.DCA bit before declaring the leaf as valid. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 3 +++ arch/x86/kernel/cpu/cpuid_parser.c | 12 ++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 50156e9883a3..2949584e85cc 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -213,6 +213,9 @@ struct cpuid_leaves { CPUID_LEAF ( 0x2, 0 ); CPUID_LEAF_N ( 0x4, 8 ); CPUID_LEAF ( 0x5, 0 ); + CPUID_LEAF ( 0x6, 0 ); + CPUID_LEAF ( 0x9, 0 ); + CPUID_LEAF ( 0x15, 0 ); CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index ee34894c79ef..f563834a082e 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -103,6 +103,18 @@ cpuid_read_0x2(const struct cpuid_parse_entry *e, cons= t struct cpuid_read_output */ define_cpuid_read_function(deterministic_cache, leaf_0x4_n, l, l->cache_ty= pe =3D=3D 0); =20 +static void +cpuid_read_0x9(const struct cpuid_parse_entry *e, const struct cpuid_read_= output *output) +{ + struct leaf_0x1_0 l1; + + cpuid_read(0x1, &l1); + if (!l1.dca) + return; + + cpuid_read_generic(e, output); +} + /* * Define an extended range CPUID read function * diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 3a60dad4e861..800a7bd6dca2 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -147,6 +147,9 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x2, 0, 0x2 ), \ CPUID_PARSE_ENTRY_N ( 0x4, deterministic_cache ), \ CPUID_PARSE_ENTRY ( 0x5, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x6, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x9, 0, 0x9 ), \ + CPUID_PARSE_ENTRY ( 0x15, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ @@ -199,6 +202,7 @@ struct cpuid_vendor_entry { /* Leaf Vendor list */ \ CPUID_VENDOR_ENTRY(0x2, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x4, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ + CPUID_VENDOR_ENTRY(0x15, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x8000001d, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 0917C44BCB0 for ; Thu, 28 May 2026 15:43: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=1779983026; cv=none; b=lCeMB64Mjy02S+1hPA1ilJaFdKSdRU5ipp4cFk3fq3GbBQK46qay0++KCmnEmNPqTCKWXVZYNvkntxlMW7duixFVEV7k5KzqALy/9H874A5qquIXt6JmsHAazE973lPrRPRXuXMmnRtQTlfLJMhhJTeX+GCsp55b3yNGfNWJwXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983026; c=relaxed/simple; bh=OKbnhTkPhgK6INNjtjCVeg1lJtYM2Yiq1vQD/tf6zzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XV1YgfOWHS9ASKIordsbpq+2F11kzsMnF/vckYp7vXr46EXDfAVX77nNZ2GpD7DJIuQmRlU8XxsScDxhGomQVB+pafxuXctvTMiqAWbcxBaWSVs1r5ZvQuBac+8m5+OaIggR8jvPhB+0mKjHoRGDZn/gvc7i/BmujC7hP7QKHXs= 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=uVLakavx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7SvJ6a8d; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uVLakavx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7SvJ6a8d" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i8HZRhvQnYXxWvoFsDDlVx2lpylcfTxeUNOZlofeZaE=; b=uVLakavxIz6oFdCaW1lrUSNRmBcoYgUyGANvJF3J6ZZ7c7ERLGDduFVwpED20YXvYV9lU2 5/UBIqt9yrc9eB1lCUk76RoYlVSu1ipn2hggAQ20O48geCQ+8iMzgc89jevaNBcv8gXAFy 6idWEM5V0SNGd1sBfEvmAgvq7frubIie3FId76m56BfEfdcH6i2LDxAxB5Nhywy3oNHI7z /Pg349mrLNKSj2xBFwHIKhaqVGTSHHcQrSRtq+hjTrF+0ZJuWKYUChQ7vlIvWAMEjj/6bu D5sPH/NhxezBnxZmdIFwMW4AdHJ8O+leNDQt0LTIZqQ5Q15AP5II8C+yFnXc5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i8HZRhvQnYXxWvoFsDDlVx2lpylcfTxeUNOZlofeZaE=; b=7SvJ6a8dcdlp+2AVRtxVNVbq2dvta0BiUSV6fCnqYdvQMzvzXg91yPjpZ7Cb2GJ83uT3TR +oTBM/3JObLgbsDQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 070/120] thermal: intel: hfi: Use parsed CPUID(0x6) Date: Thu, 28 May 2026 17:38:32 +0200 Message-ID: <20260528153923.403473-71-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x6) instead of direct CPUID queries and custom data types. Signed-off-by: Ahmed S. Darwish --- drivers/thermal/intel/intel_hfi.c | 62 ++++++++++--------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/inte= l_hfi.c index 3273b8fe3d4d..4f0cb157b5d8 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -53,29 +53,6 @@ #define HW_FEEDBACK_PTR_VALID_BIT BIT(0) #define HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT BIT(0) =20 -/* CPUID detection and enumeration definitions for HFI */ - -#define CPUID_HFI_LEAF 6 - -union hfi_capabilities { - struct { - u8 performance:1; - u8 energy_efficiency:1; - u8 __reserved:6; - } split; - u8 bits; -}; - -union cpuid6_edx { - struct { - union hfi_capabilities capabilities; - u32 table_pages:4; - u32 __reserved:4; - s32 index:16; - } split; - u32 full; -}; - /** * struct hfi_cpu_data - HFI capabilities per CPU * @perf_cap: Performance capability @@ -326,16 +303,20 @@ void intel_hfi_process_event(__u64 pkg_therm_status_m= sr_val) msecs_to_jiffies(HFI_UPDATE_DELAY_MS)); } =20 -static void init_hfi_cpu_index(struct hfi_cpu_info *info) +static bool init_hfi_cpu_index(struct hfi_cpu_info *info, int cpu) { - union cpuid6_edx edx; + const struct leaf_0x6_0 *l6 =3D cpuid_leaf(&cpu_data(cpu), 0x6); =20 /* Do not re-read @cpu's index if it has already been initialized. */ if (info->index > -1) - return; + return true; + + /* Cannot do anything if CPUID(0x6) is missing */ + if (!l6) + return false; =20 - edx.full =3D cpuid_edx(CPUID_HFI_LEAF); - info->index =3D edx.split.index; + info->index =3D l6->this_lcpu_hwfdbk_idx; + return true; } =20 /* @@ -436,7 +417,8 @@ void intel_hfi_online(unsigned int cpu) info->hfi_instance =3D hfi_instance; } =20 - init_hfi_cpu_index(info); + if (!init_hfi_cpu_index(info, cpu)) + return; =20 /* * Now check if the HFI instance of the package of @cpu has been @@ -535,19 +517,13 @@ void intel_hfi_offline(unsigned int cpu) =20 static __init int hfi_parse_features(void) { - unsigned int nr_capabilities; - union cpuid6_edx edx; + const struct leaf_0x6_0 *l6 =3D cpuid_leaf(&boot_cpu_data, 0x6); + unsigned int nr_capabilities =3D 0; =20 - if (!boot_cpu_has(X86_FEATURE_HFI)) + if (!boot_cpu_has(X86_FEATURE_HFI) || !l6) return -ENODEV; =20 - /* - * If we are here we know that CPUID_HFI_LEAF exists. Parse the - * supported capabilities and the size of the HFI table. - */ - edx.full =3D cpuid_edx(CPUID_HFI_LEAF); - - if (!edx.split.capabilities.split.performance) { + if (!l6->perfcap_reporting) { pr_debug("Performance reporting not supported! Not using HFI\n"); return -ENODEV; } @@ -556,11 +532,13 @@ static __init int hfi_parse_features(void) * The number of supported capabilities determines the number of * columns in the HFI table. Exclude the reserved bits. */ - edx.split.capabilities.split.__reserved =3D 0; - nr_capabilities =3D hweight8(edx.split.capabilities.bits); + if (l6->perfcap_reporting) + nr_capabilities++; + if (l6->encap_reporting) + nr_capabilities++; =20 /* The number of 4KB pages required by the table */ - hfi_features.nr_table_pages =3D edx.split.table_pages + 1; + hfi_features.nr_table_pages =3D l6->feedback_sz + 1; =20 /* * The header contains change indications for each supported feature. --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 2915344CF2E for ; Thu, 28 May 2026 15:43:45 +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=1779983028; cv=none; b=ut6ANadzzNAXSmfOz/pu8Ek37pTqPAVS3RddulHhbe+HDsCtdYbMLhqVRyNZCyFaT43pVnUgofpSmK1ToTHxmiG+ZNU4o+LxbsOJ4y+2aenTxp6heznRlF5dYbUqvmZpYl12nuv/bE2SQLdOLUNnK639+8x8V3fh16fptaRkmJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983028; c=relaxed/simple; bh=WOab32jdw8sm3GN0zq/J40YE7QiEgeUG+RH8k1O31hM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sDIds47EfVChz31UMNs8Oc6pharoEwRyFy3MC9sLHlmUTCItMb6UvtIZMCQG6yuQPh3ethnppvUqVB41wFHMBj0ReNFq26fJ9fRkgLqHbFet5tsoISDwFuQh1+cHPmEzFkHlEiNdEy7NR8eZX4Q523w4NMYSSk7dtJrVUHvLvZ4= 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=2wCkSEk5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/jbF0Mo6; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2wCkSEk5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/jbF0Mo6" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Vz6EhzOUrUOcHq6+oVxPxYasPkNQRCkfShP6hvtt90=; b=2wCkSEk5PtdtywAeiyhRI97lBRjezZk4oq5NN8tEmXC0DQ1eAMz+gnAoy1gU9U4w1me4Kd ti2f7IUmftiUBajfHhDXM6qgHXqPbMd5RjLncO04a7+tvKYHtoxOoyyJKb0gB3SQ1Yzntl QYn4RHZ1YgeLN4h+jsrqdyleS3TUxfnQwSGStpFWvwDmisbs+npMbEjTv/66RhsMNCbc5d WEM9DViMfxjRvQOoDCQu8qXxM7boh9sE5jYbjGr8t5o0E+3TTOB+pjxM604905/X/xPQzK FHVzCk9cxvxd7pKiTgkkCNJ89Jbu0r6+lR920IigzqyDeFgdrsSg1AM6AtSH2g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Vz6EhzOUrUOcHq6+oVxPxYasPkNQRCkfShP6hvtt90=; b=/jbF0Mo6u4RZXljtJJPWNqiGsFsbX0XOrvOfSAmtweqrSCNLPxNlZ/RjgfBGim/E0kRSGx l/IGEaorh+LGT1BQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 071/120] dmaengine: ioatdma: Use parsed CPUID(0x9) Date: Thu, 28 May 2026 17:38:33 +0200 Message-ID: <20260528153923.403473-72-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x9) instead of manual bitwise operations and a direct CPUID query. Signed-off-by: Ahmed S. Darwish --- drivers/dma/ioat/dca.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/dma/ioat/dca.c b/drivers/dma/ioat/dca.c index 07c977bef5f8..5e9b43b0b6dc 100644 --- a/drivers/dma/ioat/dca.c +++ b/drivers/dma/ioat/dca.c @@ -52,25 +52,12 @@ static inline u16 dcaid_from_pcidev(struct pci_dev *pci) return pci_dev_id(pci); } =20 -static int dca_enabled_in_bios(struct pci_dev *pdev) -{ - /* CPUID level 9 returns DCA configuration */ - /* Bit 0 indicates DCA enabled by the BIOS */ - u32 eax; - int res; - - eax =3D cpuid_eax(CPUID_LEAF_DCA); - res =3D eax & BIT(0); - if (!res) - dev_dbg(&pdev->dev, "DCA is disabled in BIOS\n"); - - return res; -} - int system_has_dca_enabled(struct pci_dev *pdev) { - if (boot_cpu_has(X86_FEATURE_DCA)) - return dca_enabled_in_bios(pdev); + const struct leaf_0x9_0 *l9 =3D cpuid_leaf(&boot_cpu_data, 0x9); + + if (l9 && boot_cpu_has(X86_FEATURE_DCA)) + return l9->dca_enabled_in_bios; =20 dev_dbg(&pdev->dev, "boot cpu doesn't have X86_FEATURE_DCA\n"); return 0; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 1516B43E4B3 for ; Thu, 28 May 2026 15:43:48 +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=1779983031; cv=none; b=k4vwp7WvfUA00gDEWqffMX7RGziQwfUV/kumPB2y01CqEte9Ues0q6NrgQNR/QqC/YDtopaI0dGcqpV1SLg/NPnMtxrW/HeZ8nIdIhDSXQWNhgyNkR5xi8cRK2dzqWu2tjWHinAffjjoOe9TMlOUj9eehgEqGgY3+ssXQphD25c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983031; c=relaxed/simple; bh=GsfqZ4AH01Sc/djHFURU3Zfm+tiG6HnRvpuSoMWoohk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lg1w3HIEnPSJGzWGglSlBo5pyNX3O275d0qZ1XFJyH4bmxsNz1w/rBcPZaWnfmLiVTJE1luzkAudSUkO7e0uX51HyTAJZLaQ0qXCyEWsYadR8MQtlvQWDqp5z/QcudZQGGs+iVipAC+OdEHccSyLx+5czSw41SR75nTdKtV6T9E= 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=GN3MDaez; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fr37o7Wb; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GN3MDaez"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fr37o7Wb" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lxP14JpeWfYUl3vDBfyma6XrpNfSgBT3QgJlY9gqEzI=; b=GN3MDaezusCiezyyRYLnTuiOfnk9m/LtXE+bzOy+5kwLa4u/bcC58OnXGhB8VskRecD2lA yHqxmpRzA3+chbxKeMybaNQr7PUQczYAvq2k2dtxcEbCOFolkPHXDIz54PNgoO3kMxvG5K hEHhV/7wUXWHcoJpxssulvT5VaU6HfWyNP31ibSm/Z7S06cYnx7rhRiGGG/bTjONWOCABC 0lp2mkHa2FfayN+9sfoAEzbi1nebI3KeeJB1Z3oLflyTrYXAJSDNyXxQ4E5gwljkNCU5mb ccczI0XYXGpT0eo/PVlC6Anajx09RnY4TQ8d9EgvrG+zqTXYPcqF130ntygI4g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lxP14JpeWfYUl3vDBfyma6XrpNfSgBT3QgJlY9gqEzI=; b=fr37o7WbYaOMrHeouRCg1PCUCOVk5uNGQRmRQ4+RZ3fN7y01MopGNcimSTFLd7dKN0M8JH GdBylVVnwItkLqAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 072/120] ASoC: Intel: avs: Use parsed CPUID(0x15) Date: Thu, 28 May 2026 17:38:34 +0200 Message-ID: <20260528153923.403473-73-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x15) instead of doing a direct CPUID query and manual registers access on the output. Remove the max CPUID level check as it is already implied by the CPUID APIs returning NULL. Signed-off-by: Ahmed S. Darwish --- sound/soc/intel/avs/tgl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/intel/avs/tgl.c b/sound/soc/intel/avs/tgl.c index a7123639de43..d691ba06a4f7 100644 --- a/sound/soc/intel/avs/tgl.c +++ b/sound/soc/intel/avs/tgl.c @@ -45,13 +45,14 @@ static int avs_tgl_dsp_core_stall(struct avs_dev *adev,= u32 core_mask, bool stal */ static int avs_tgl_set_xtal_freq(struct avs_dev *adev) { + const struct leaf_0x15_0 *l =3D cpuid_leaf(&boot_cpu_data, 0x15); unsigned int freq; int ret; =20 - if (boot_cpu_data.cpuid_level < CPUID_LEAF_TSC) + if (!l) return 0; =20 - freq =3D cpuid_ecx(CPUID_LEAF_TSC); + freq =3D l->cpu_crystal_hz; if (freq) { ret =3D avs_ipc_set_fw_config(adev, 1, AVS_FW_CFG_XTAL_FREQ_HZ, sizeof(f= req), &freq); if (ret) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 54F9144E02C for ; Thu, 28 May 2026 15:43:52 +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=1779983034; cv=none; b=FkQGw2MePlWw1MvIODStVWx6DT5J7WExSULaFv5DNzJDeXV+zbifLwF8yyG1btVkHllsfQTqZJtSlQRMZfheEJfVNd3+UTFuGwctCI9Ur/BZBBAQbjfuMPSOnGHiF8hcTzomp1L85dIGmo6ivYgOVfv4346OBqMeP0Bfx3cVWWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983034; c=relaxed/simple; bh=6iwWiEZpjq46yvEEL4/0Yv1P3YTbWsL9QC+szUTpZ1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E/5iVolCiGSzcuDMVhGtiRIF8q2gKpmuLZze+/WaLDnl3Z+kEWAgoEDEqcxyucxonXJEOFtS0mhsfv8OPjaaZNGuJPGp2jg+8/ctk6XqC/pqEYwflzg9Gy+dpxGYjoQXZ/VJ6EukQkHofXqQLPoqzQR9dWfduyMcaUXQRz0wQ34= 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=OmuRCdHv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bn6zcIka; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OmuRCdHv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bn6zcIka" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+nd/NmEhNyF21nuREqSFFUH5qua7zbrhz6reJSpDQNw=; b=OmuRCdHv/CRddthyFo/QDT0rC5uUV1srsBoJFOgH/8w42Ww1wjYTVi/xdhV/UIeyy4Ksoo 3k5nHj4jTyekGToCk2wgY4q/oHB93G/fKTc6J0pZJQLgXTgwTjqICd9f41PT4dklyJa50N Abw6+VIQaVT54VWe7A7HHWiJk+OsmXinQtDR3LLHi7GDFZP01OkfMVQnDzDZwzjSD4jr0z OF2KMEU5tlogsjy9b03uRG4h2ViKpRIuIAipXt1h7HBvI0mpXV56T4GPykAQ4SxplZcvIe KERwUzVs5rmEYxozuGkic7rCbKOcRMsAUpVljxfHRtGzqpS1iX5qMUZdQJkqUQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+nd/NmEhNyF21nuREqSFFUH5qua7zbrhz6reJSpDQNw=; b=bn6zcIkaU5g5r3q+SvieNBWsTQve21ZKZOHs8ti7XJ5Bzy15yl6SxaT6cqruGl/Bq/iy9D 2Hv9gqNO+PSg3uAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 073/120] perf/x86/intel: Use parsed CPUID(0x15) Date: Thu, 28 May 2026 17:38:35 +0200 Message-ID: <20260528153923.403473-74-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x15) instead of a direct CPUID query and raw register access. Remove the maximum CPUID level check as it is implied by the CPUID API not returning NULL. Remove the excessive details regarding CPUID(0x15).EBX being zero since it is not relevant to the actual code beneath it. The code only caches the TSC to core crystal clock ration numerator and denominator. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/intel/pt.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index b5726b50e77d..b938acac9cee 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -189,6 +189,7 @@ static const struct attribute_group *pt_attr_groups[] = =3D { =20 static int __init pt_pmu_hw_init(void) { + const struct leaf_0x15_0 *l15; struct dev_ext_attribute *de_attrs; struct attribute **attrs; size_t size; @@ -199,18 +200,11 @@ static int __init pt_pmu_hw_init(void) rdmsrq(MSR_PLATFORM_INFO, reg); pt_pmu.max_nonturbo_ratio =3D (reg & 0xff00) >> 8; =20 - /* - * if available, read in TSC to core crystal clock ratio, - * otherwise, zero for numerator stands for "not enumerated" - * as per SDM - */ - if (boot_cpu_data.cpuid_level >=3D CPUID_LEAF_TSC) { - u32 eax, ebx, ecx, edx; - - cpuid(CPUID_LEAF_TSC, &eax, &ebx, &ecx, &edx); - - pt_pmu.tsc_art_num =3D ebx; - pt_pmu.tsc_art_den =3D eax; + /* Save the TSC to core crystal clock ratio, if available */ + l15 =3D cpuid_leaf(&boot_cpu_data, 0x15); + if (l15) { + pt_pmu.tsc_art_num =3D l15->tsc_numerator; + pt_pmu.tsc_art_den =3D l15->tsc_denominator; } =20 /* model-specific quirks */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6128F4534AE for ; Thu, 28 May 2026 15:43:55 +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=1779983039; cv=none; b=qH7Gf2oTh6lKnBYiu7ikUz6tF3czDh+pVCxzcUJ+zUn0TvTk7tFJVd/aXvb8Mzbz7I0UqM0Tu+QsZ+EobSi8mC0r9JXWCGJyrxzJr7EUFpLYZl1eReAjuv/AJYQGk2uKt8+N2BO8SB3euX1b/xqpxhL5VyosUcr/WJ/rpsH/R/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983039; c=relaxed/simple; bh=Ff4+FiBGIpxPXnvfl1uOHJ3saZhN1E2po0LrA0eWVdI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fnXZaUQyGg45UUVb5C/7ohESJ5txowDqE7CnliBmZKp4jHC2VoDML6QFbpI8Pmfoc5JXyjhloMccJrqfOlJ/9XnaMdiHk9UY/DYPQLqpfP3RLO/KcNCl66fXEYFj6dKI8cNfWHCh9RHVibfOd8lFemYKMoL3b64/zUOBtDR/qPU= 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=BamogDXM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=x5tTn38E; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BamogDXM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="x5tTn38E" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KBr1jJ+QjArFOXCK3XemCt5rGp0KR7bzprPyXJ0oU9w=; b=BamogDXMejdixo5gJNEG2X1BU81jpzHPx2+fTX6qyCE9G8krryGSzRhuuPoKlfXD89/+R8 oh+uRFzU3Q8NDOwrqXNXXbk7JnZubIaumdf4cj7Lg7GhHxpcTdBlJwEZWOwplDf4p0GfBR HkEvV91r3ddRMnMqpOaF7gaXoMKuMmxCucDQSbW99ss19YRfAqpUxPIqa57Gf/BPT9ec25 6d6JG48HxafGnCs3xPJyWEpmBV0cXjbUFZlzMTHBEpd6xj/1aoE/HB/n19zTy2bMkpEGy8 Oi9co27OEO5AvmjdHLiumapHYyAFWkSKdeZMhpj5VewWHpEeVhzZasiAwSj9uw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KBr1jJ+QjArFOXCK3XemCt5rGp0KR7bzprPyXJ0oU9w=; b=x5tTn38EQEBN5mYbmPY/qiSQPaK5y8FO7pSQmbWf9P1kXCNIUCxJoujwV34iH6DwTf3Iui HzPRVtofRX1CuTAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 074/120] x86/cpuid: Introduce cpuid_subleaf_raw() Date: Thu, 28 May 2026 17:38:36 +0200 Message-ID: <20260528153923.403473-75-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is required for the conversion of SGX CPUID(0x12) call sites to the parsed CPUI API. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 540f886a61cd..1c0bb7ed4d45 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -381,6 +381,18 @@ static inline u32 cpuid_base_hypervisor(const char *si= g, u32 leaves) #define cpuid_leaf_raw(_cpuinfo, _leaf) \ ((const struct cpuid_regs *)(cpuid_leaf(_cpuinfo, _leaf))) =20 +/** + * cpuid_subleaf_raw() - Access parsed CPUID data in raw format + * @_cpuinfo: CPU capability structure reference ('struct cpuinfo_x86') + * @_leaf: CPUID leaf, in compile-time 0xN format + * @_subleaf: CPUID subleaf, in compile-time decimal format + * + * Similar to cpuid_subleaf(), but returns a raw 'struct cpuid_regs' point= er to + * the parsed CPUID data instead of a "typed" poi= nter. + */ +#define cpuid_subleaf_raw(_cpuinfo, _leaf, _subleaf) \ + ((const struct cpuid_regs *)(cpuid_subleaf(_cpuinfo, _leaf, _subleaf))) + /* * Call-site APIs for CPUID leaves with a subleaf range: */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 7D549451071 for ; Thu, 28 May 2026 15:43:58 +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=1779983042; cv=none; b=lv7z9Fbg4AR64lRlHhY5vjQ++Kg5wpKsk8/UehOZyOrdTxcdAK1ucFiGOBUo2pgTihcV4PkrI+qRcWa3EbqwLosGWwBHuRzLGvRVPTb5ewCOw06qpQNRg+C/JHbM70gPkwfYVgRDiSkCo4e7uuBDkZ6yFv1a9+p7j/4kZ+CtMa0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983042; c=relaxed/simple; bh=cze5oUt3gf8JtJvTP11YbawmBVVqStzReMp+ECeiR+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jo0ib3fhZzSUw+UdCKjqM7SBdI67V/Ftn7BlDmyJiNRBonUhfR5OFiTdbBr9s+1CBM9CSVu02FTUK+WGjFnsd1+t5Q3QQpNtpoYl/jOZ63zvF4QqlQkYLgD4XYH85XO5hB1cFhgsBnHbhb/6iD7wGMZbkZrFlgLbeJdY+EuggY8= 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=YVyj2GTa; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=DESAXgDX; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YVyj2GTa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="DESAXgDX" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iQ2/RpNiehvCL9CFQsul8ZFVhED1qVLMWTHYTxMGsuc=; b=YVyj2GTaCyRYq4yrVxtSAr4e2ewwI5AMYjglykfFUisGIE7J1Hnw9S1sBVHTjeN0zapUGM /ndb/b7s7MZogPN2TQ7cWAF5UDX59vrRTc34E4EP35mN7Eboubcc7eTyJFOrc1AMTPyKdn Y+Zclmy/29jL/pblU5bmt6Ojaq8mMvlnT9pE2R9zVwVvA7ccecaLDr1x6iF3qxG6QapcGR X1ISJxPD9ZnQIejRWsXZttFYbMGc1gTQTlGbWuTvJUTx2bVbQGO1Z2ncPk+plBWsrR+Adh dqeA7tlRYHmK0mShqNBWIDpZp3dWzNsfkj6RKyjQTioimOSa9rqkCJ/SRY2Z6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iQ2/RpNiehvCL9CFQsul8ZFVhED1qVLMWTHYTxMGsuc=; b=DESAXgDXpoWPYdVCjokoByzmy1xgDge3xKmkxin5izDdZXR3w636m78GPYDpLavJ7Rz1VT liVunyoj+5Q04eAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 075/120] x86/cpuid: Parse CPUID(0x12) Date: Thu, 28 May 2026 17:38:37 +0200 Message-ID: <20260528153923.403473-76-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x12).0, CPUID(0x12).1, and CPUID(0x12).n so that their call sites can be converted to the CPUID API next. Parse 8 subleaves for CPUID(0x12).n to match SGX_MAX_EPC_SECTIONS definition at kernel/cpu/sgx/sgx.h. Limit CPUID parsing to Intel x86 machines. As stated in the hardware manuals, CPUID(0x12).0 and CPUID(0x12).1 are valid only if CPUID(0x7).EBX.SGX is true. Ensure that their CPUID parser read functions follow this. Introduce cpuid_read_sgx_epc_sections() for CPUID(0x12).n parsing where an EPC section type of 0 (SGX_CPUID_EPC_INVALID) means an invalid EPC section subleaf. This matches the hardware manuals and the existing subleaf iteration logic at kernel/cpu/sgx/main.c::sgx_page_cache_init(). Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 3 +++ arch/x86/kernel/cpu/cpuid_parser.c | 14 ++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 2949584e85cc..91ed4dd3c6c2 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -215,6 +215,9 @@ struct cpuid_leaves { CPUID_LEAF ( 0x5, 0 ); CPUID_LEAF ( 0x6, 0 ); CPUID_LEAF ( 0x9, 0 ); + CPUID_LEAF ( 0x12, 0 ); + CPUID_LEAF ( 0x12, 1 ); + CPUID_LEAF_N ( 0x12, 8 ); CPUID_LEAF ( 0x15, 0 ); CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x80000000, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index f563834a082e..7ab4e01c6c33 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -115,6 +115,20 @@ cpuid_read_0x9(const struct cpuid_parse_entry *e, cons= t struct cpuid_read_output cpuid_read_generic(e, output); } =20 +static void +cpuid_read_0x12(const struct cpuid_parse_entry *e, const struct cpuid_read= _output *output) +{ + struct leaf_0x7_0 l7; + + cpuid_read(0x7, &l7); + if (!l7.sgx) + return; + + cpuid_read_generic(e, output); +} + +define_cpuid_read_function(sgx_epc_sections, leaf_0x12_n, l, l->subleaf_ty= pe =3D=3D 0); + /* * Define an extended range CPUID read function * diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 800a7bd6dca2..d12d1c2b459b 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -149,6 +149,9 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x5, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x6, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x9, 0, 0x9 ), \ + CPUID_PARSE_ENTRY ( 0x12, 0, 0x12 ), \ + CPUID_PARSE_ENTRY ( 0x12, 1, 0x12 ), \ + CPUID_PARSE_ENTRY_N ( 0x12, sgx_epc_sections ), \ CPUID_PARSE_ENTRY ( 0x15, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ @@ -202,6 +205,7 @@ struct cpuid_vendor_entry { /* Leaf Vendor list */ \ CPUID_VENDOR_ENTRY(0x2, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x4, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ + CPUID_VENDOR_ENTRY(0x12, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x15, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x8000001d, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6B42E45BD78 for ; Thu, 28 May 2026 15:44:01 +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=1779983045; cv=none; b=RsZ1Q5hOQdTFVYqtaz+EbtZSaCwh82ldDYJ8jULkc8m6i1SyrQOL33EY/jWS5AhN6GIYwXV0Yc9Jrkug0U5L7Oap0BZNP2yGUmaLBSCy/WCOeq3BYc/tycYlFvkycHaFPtgWuPxX6HBLQdBhevh5R5eVUTHLHTed9a8Gwo6UHfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983045; c=relaxed/simple; bh=ruz7+nd3k7vLPBLCqHGmdk0F9FtgvWgcb2HIiBa47+k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ek1G7IMC7jbhz0jiP/Oi0QVtX6HifHdPSHwvk4k/Wh73fwsRr8+lxOAgHEcLnDI7Q/f4i2IGJG9/a/vC3X4IzHJr7e32bBWDUq34bc6zBld3/4q65Rx5tnrw5Db2CR72kkeVIIM+QQayeTmGNmRNwDgJQM5tKMYDkPrDcKIU4J8= 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=sg0dp2r1; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/VxUAi1h; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sg0dp2r1"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/VxUAi1h" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+UoFtz68Y7oDHlqIDp2/1Ccnc/PAMoFWCAbKpUAVw2o=; b=sg0dp2r1MjWiWYt9MYauTBeAi/k4wn4tlT7VUx25a2Iw8jWGisNQ5qKVHf/E5F2mVj9k3x EhKVTwWYBPsWy9i0atXLKPn0hcUJtRmdLeje6P9RpY4uRwguXCtykaTIdvOC++eZtdJ/Re v8BGga4HF5A18oDz0vLnfudjEbHnUoXRxOMfcW3R0fAAb76epRFyL76noWn7xE24BYVb6e BVptIwjpmEaIEPT2Teat74g1YNzank4T5KeQCIlC88r7Ypq6/7we3f09p0E45+lX0MOPzr FJPrB29NlHHzXqu3DY+PA1NvNPoqpHwcKItltY2OLQtcEwGeiccrYZ/Z279M6w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+UoFtz68Y7oDHlqIDp2/1Ccnc/PAMoFWCAbKpUAVw2o=; b=/VxUAi1hpS9/IEYWTD0Rje47cQV6ZDtaearvRJB0cFSeS3bD+3HWXd7eZnxl9aG/0xINH0 kXETDTisvS4EE6Cg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 076/120] x86/sgx/driver: Use parsed CPUID(0x12) Date: Thu, 28 May 2026 17:38:38 +0200 Message-ID: <20260528153923.403473-77-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x12).0 and CPUID(0x12).1 instead of doing bitwise operations and direct CPUID queries. Since SGX feature availablility mandates the existence of both CPUID(0x12).0 and CPUID(0x12).1, exit the driver early in case any one of them is not available. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/sgx/driver.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/driver.c b/arch/x86/kernel/cpu/sgx/dri= ver.c index 9268289cd9f9..c5bc3f85ad97 100644 --- a/arch/x86/kernel/cpu/sgx/driver.c +++ b/arch/x86/kernel/cpu/sgx/driver.c @@ -165,32 +165,33 @@ static struct miscdevice sgx_dev_enclave =3D { =20 int __init sgx_drv_init(void) { - unsigned int eax, ebx, ecx, edx; + const struct leaf_0x12_0 *l0 =3D cpuid_leaf(&boot_cpu_data, 0x12); + const struct cpuid_regs *l0r =3D cpuid_leaf_raw(&boot_cpu_data, 0x12); + const struct cpuid_regs *l1r =3D cpuid_subleaf_raw(&boot_cpu_data, 0x12, = 1); u64 attr_mask; u64 xfrm_mask; int ret; =20 + if (!l0 || !l0r || !l1r) + return -ENODEV; + if (!cpu_feature_enabled(X86_FEATURE_SGX_LC)) { pr_info("SGX disabled: SGX launch control CPU feature is not available, = /dev/sgx_enclave disabled.\n"); return -ENODEV; } =20 - cpuid_count(SGX_CPUID, 0, &eax, &ebx, &ecx, &edx); - - if (!(eax & 1)) { + if (!l0->sgx1) { pr_info("SGX disabled: SGX1 instruction support not available, /dev/sgx_= enclave disabled.\n"); return -ENODEV; } =20 - sgx_misc_reserved_mask =3D ~ebx | SGX_MISC_RESERVED_MASK; - - cpuid_count(SGX_CPUID, 1, &eax, &ebx, &ecx, &edx); + sgx_misc_reserved_mask =3D ~l0r->ebx | SGX_MISC_RESERVED_MASK; =20 - attr_mask =3D (((u64)ebx) << 32) + (u64)eax; + attr_mask =3D (((u64)l1r->ebx) << 32) + (u64)l1r->eax; sgx_attributes_reserved_mask =3D ~attr_mask | SGX_ATTR_RESERVED_MASK; =20 if (cpu_feature_enabled(X86_FEATURE_OSXSAVE)) { - xfrm_mask =3D (((u64)edx) << 32) + (u64)ecx; + xfrm_mask =3D (((u64)l1r->edx) << 32) + (u64)l1r->ecx; sgx_xfrm_reserved_mask =3D ~xfrm_mask; } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6749B4657D0 for ; Thu, 28 May 2026 15:44:04 +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=1779983048; cv=none; b=KGBXJ0aulwJJAReUYUFilvVGvMRDc0HdhHsaeY4Dj5mtMyeLZfoUVmIfEJAmL0ORYs3eAbZc42MsMVNP41BnuMU7uX3YFncef98K/rrlinn8EOYlx6sCsXQEyFhi4tmJ+VDFYFb6n7b59KliHtVwUCQ1+yv6G0htuGc29bBUijI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983048; c=relaxed/simple; bh=Cqmkc6ziRX8vTg6v0K8RgdcbLnAEsdHv9VQ25MHatBQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tPSocUvswcwWqcl4uqkmdR09xqMIgk59PtS0LWQCZk69LOAjGMmrNPllRNRQqzDaQ90ikI1JK9uQmyShI3OsDx3qdZs7u9d+h9HYD0WilOr5BqNMwHCJj/pkgUHip9+Qw3y2y4SPKRr5nI970NwN8pt8dBCwYk8gjj0yzci7hGQ= 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=S5VbDWP4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0sVDdLEe; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S5VbDWP4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0sVDdLEe" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=io8uJI5ZUXWYShYYxjsQoGaewBoR08MQe30r4f4klSQ=; b=S5VbDWP47fs4JaqE+zl0ttQ7l2/HCK5TmjNtsT47W2vufME6nl+dH95XTeECPTJUMYWVGI lGnRHmuOT7NAEiWDfiN1/GJd/f/wpPQKTLkZg3Uvry9x4opT1wmvz6imcN9FxtrlY25HX8 vpBRRDoGC4cky5ExkX+1Rrf278uQIoro0sTvW7FXXfxlAUgA20ySXUtmworcY5ihhgsECb ngmei1FH0E3Ifl8+P9ZHpzN6Cw1xefGQXwSZal14CVvUjXd5uyUD91/O5GQY6+vcP7dP86 fbEPzm7Ra6NR9HWNS2OSHmzevUfugHlC0jBHndMZIH/TFgfjX3IcKJNJ3fcGMA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=io8uJI5ZUXWYShYYxjsQoGaewBoR08MQe30r4f4klSQ=; b=0sVDdLEeA7h58HjjNT7bt+PKlNahdpD6bl5wh/dHuf/3LGF7WAtVO98fNQgc/szAKBcZYN xddHVb8YUNErN+CA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 077/120] x86/sgx: Use parsed CPUID(0x12) Date: Thu, 28 May 2026 17:38:39 +0200 Message-ID: <20260528153923.403473-78-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x12) instead of doing direct CPUID queries and manually extracting the fields with bitwise operations. Remove the subleaf's SGX_CPUID_EPC_INVALID type check since this is already done by the parser's CPUID(0x12).n read function. cpuid_subleaf_n() just returns NULL in that case. Rework sgx_calc_section_metric() to build-up the SGX metric directly from the passed fields. There is no need for extracting them with GENMASK operations as this is already handled by the C99 bitfields. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/sgx/main.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 4505f808af5e..071f034f8b2c 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -742,14 +742,12 @@ int arch_memory_failure(unsigned long pfn, int flags) } =20 /* - * A section metric is concatenated in a way that @low bits 12-31 define t= he - * bits 12-31 of the metric and @high bits 0-19 define the bits 32-51 of t= he - * metric. + * A section metric is concatenated in a way that @low bits define the bits + * 12-31 of the metric and @high bits define the bits 32-51 of the metric. */ -static inline u64 __init sgx_calc_section_metric(u64 low, u64 high) +static inline u64 __init sgx_calc_section_metric(u32 low, u32 high) { - return (low & GENMASK_ULL(31, 12)) + - ((high & GENMASK_ULL(19, 0)) << 32); + return ((u64)high << 32) | (low << 12); } =20 #ifdef CONFIG_NUMA @@ -796,29 +794,28 @@ static void __init arch_update_sysfs_visibility(int n= id) {} =20 static bool __init sgx_page_cache_init(void) { - u32 eax, ebx, ecx, edx, type; + const struct leaf_0x12_n *sl; u64 pa, size; int nid; - int i; =20 sgx_numa_nodes =3D kmalloc_objs(*sgx_numa_nodes, num_possible_nodes()); if (!sgx_numa_nodes) return false; =20 - for (i =3D 0; i < ARRAY_SIZE(sgx_epc_sections); i++) { - cpuid_count(SGX_CPUID, i + SGX_CPUID_EPC, &eax, &ebx, &ecx, &edx); + for (int i =3D 0; i < ARRAY_SIZE(sgx_epc_sections); i++) { + u32 subleaf =3D SGX_CPUID_EPC + i; =20 - type =3D eax & SGX_CPUID_EPC_MASK; - if (type =3D=3D SGX_CPUID_EPC_INVALID) + sl =3D cpuid_subleaf_n(&boot_cpu_data, 0x12, subleaf); + if (!sl) break; =20 - if (type !=3D SGX_CPUID_EPC_SECTION) { - pr_err_once("Unknown EPC section type: %u\n", type); + if (sl->subleaf_type !=3D SGX_CPUID_EPC_SECTION) { + pr_err_once("Unknown EPC section type: %u\n", sl->subleaf_type); break; } =20 - pa =3D sgx_calc_section_metric(eax, ebx); - size =3D sgx_calc_section_metric(ecx, edx); + pa =3D sgx_calc_section_metric(sl->epc_sec_base_addr_0, sl->epc_sec_ba= se_addr_1); + size =3D sgx_calc_section_metric(sl->epc_sec_size_0, sl->epc_sec_size_1); =20 pr_info("EPC section 0x%llx-0x%llx\n", pa, pa + size - 1); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 BE5733FFAA6 for ; Thu, 28 May 2026 15:44:07 +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=1779983049; cv=none; b=IFEQC04gZGNNXpZy9hbZrgRL8Jfq/+1EcdbBMc193Q0EQWZMuX6VTQhkad0f4aSatvFUEwh2nL/EqFiCZVvnOznhVKy5YB9jKMt/EA3kDO0mGxTu5cQCsxWV53vw4cpYnM/voKiXteHmCXRukKlWLSPHP2OLs1f5fm4PrsQDya0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983049; c=relaxed/simple; bh=O3i2oif+oGGamDWEXbp1yTDyQaSEUs1kLrOWHirpsQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sC6BL/4eXOMRwEriapW4NzdWKLqTrKNe/sG6v84z6GZVpMGcP+Savm3Kjo+FqUfs+MNAc2OAEJ0UoxFMP1mAI9Bwsv0ZHoz3amOW4C1phUbv8GdAUgBIBNkYjpl+8YCnvO32H0sqk2vcpvCSCmJFg30isjN8odg6wH3lNiU3hGE= 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=tRRVBJ+h; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SHViSYEb; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tRRVBJ+h"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SHViSYEb" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WkEC6lf3SUuIXoXlnT9WA5c9bDEzPLRW/frQJYtnm5A=; b=tRRVBJ+hjFxbIidLHJnQvMRjWJ9SqmeReUlEhmQHkVW9QPSc24zYfXvPpSt5r0GTQ+CDAg 7ZYnLzDfts80jXSVIZgA5nnMGncuvhzPmpb8t0EEA6yUi+PqWoMaakPwIxpes9CmtjBFfz 0OCu2QVIWQJUYCyviqtOq9sepgmRvAnvfna25cEIyCXo6gTF0slB4b0AW5oVh9SWtREBbr qNmV3xBfBI52KmcOuVpOY/wcQMXXTCSpyDHkg+XENptuoceE7BYawqqHvXWHBH/PsyxZ4I NqrQ1xsiimOioVll0QI9ixZ4l1oCFDMCz67NU6lPPa4ArTusuILTI8B83DjNkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WkEC6lf3SUuIXoXlnT9WA5c9bDEzPLRW/frQJYtnm5A=; b=SHViSYEbFLVLTzv0cnSsE+I5LX/zEenSpGacJf/CEkrqXf/JzNwM9x262t7ExqpAeMNxN9 gsWfTydzKoBH0VAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 078/120] KVM: x86: Use parsed CPUID(0x12) Date: Thu, 28 May 2026 17:38:40 +0200 Message-ID: <20260528153923.403473-79-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For KVM's SGX ECREATE intercept logic, use parsed CPUID(0x12).0 and CPUID(0x12).1 instead of issuing direct CPUID queries. This centralizes CPUID parsing and cached access across the kernel. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/vmx/sgx.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c index 29a1f8e3be60..3f381f0f2395 100644 --- a/arch/x86/kvm/vmx/sgx.c +++ b/arch/x86/kvm/vmx/sgx.c @@ -440,8 +440,12 @@ void vcpu_setup_sgx_lepubkeyhash(struct kvm_vcpu *vcpu) */ static bool sgx_intercept_encls_ecreate(struct kvm_vcpu *vcpu) { + const struct cpuid_regs *sl0 =3D cpuid_subleaf_raw(&boot_cpu_data, 0x12, = 0); + const struct cpuid_regs *sl1 =3D cpuid_subleaf_raw(&boot_cpu_data, 0x12, = 1); struct kvm_cpuid_entry2 *guest_cpuid; - u32 eax, ebx, ecx, edx; + + if (!sl0 || !sl1) + return true; =20 if (!vcpu->kvm->arch.sgx_provisioning_allowed) return true; @@ -450,17 +454,15 @@ static bool sgx_intercept_encls_ecreate(struct kvm_vc= pu *vcpu) if (!guest_cpuid) return true; =20 - cpuid_count(0x12, 0, &eax, &ebx, &ecx, &edx); - if (guest_cpuid->ebx !=3D ebx || guest_cpuid->edx !=3D edx) + if (guest_cpuid->ebx !=3D sl0->ebx || guest_cpuid->edx !=3D sl0->edx) return true; =20 guest_cpuid =3D kvm_find_cpuid_entry_index(vcpu, 0x12, 1); if (!guest_cpuid) return true; =20 - cpuid_count(0x12, 1, &eax, &ebx, &ecx, &edx); - if (guest_cpuid->eax !=3D eax || guest_cpuid->ebx !=3D ebx || - guest_cpuid->ecx !=3D ecx || guest_cpuid->edx !=3D edx) + if (guest_cpuid->eax !=3D sl1->eax || guest_cpuid->ebx !=3D sl1->ebx || + guest_cpuid->ecx !=3D sl1->ecx || guest_cpuid->edx !=3D sl1->edx) return true; =20 return false; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 5F88A46AEE8 for ; Thu, 28 May 2026 15:44:11 +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=1779983053; cv=none; b=LIoYYj/wYIBUPJaFqCgfSy8zt1GZW9XCgrt0qabUDyxCU/BXgE+10sh8f9piphHbEjEsJIJ1dOYBCvr2eh2Q6nqCJKPdLwrK2L+eva1WI9A6Jb2stZS8jQrvRrCIqC6+CRo6SW4ILIh3wXGcMdPOO+RZD4dI/AVgCEieIofIrys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983053; c=relaxed/simple; bh=LKJOtwG6C8o/leu7Xb5nC4aEkev2kczK7C8K0xwWmj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dynw2E7NF55xGO/YTlw+cK5OSsY2vLsCfCb0nNON3mxWOzGf7usy07qtlfZ8cPV5BXfdnSrGBVehp9uu+6Xi09QS2xcqnp9hpOs1BFAeYtWtoPW6nl2Qm9Sb2zdO/Z8olJ98FtQD6I9ryRggVq+PucXbfHxG8GPflyxaaRQO9wo= 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=ETRDO9VM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tu/5Otrh; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ETRDO9VM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tu/5Otrh" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EN6slcgnZ1ln8G4qeRj2q9GWg4ufK7GATbksP0bKUfo=; b=ETRDO9VMTkWwdQLugJPW2ryH4H7L5Dz1pEPyaCXPZ5K/6nyuBZ8E8fo0Y7nBDeRo5puuZa IkAhmupidhwkLosHIJWdSTVmyEGVR83qI26wVQPVAtUEuexlGrvgJUDJ3bM18shpeytm2e lKB2qrVEQa93W5/b956WiS5l2mmifKNIOEea90zE01Y+g194CvGG6hHBoRL9rw8hxNeaRR kfrZ6JafNsYk7yG/XEk2kJXrODX9e4m8WUZUGV2E8vlRXFvqAT1lS7bEN69KWOPsRWHYi8 b3uW9TiKHalQq8qKsNef6++mrcfWhbx71nlx8FMZ+ViQiQO3iYjEGRfBrgZDLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EN6slcgnZ1ln8G4qeRj2q9GWg4ufK7GATbksP0bKUfo=; b=tu/5Otrho9eT+c88AbBUm4AE2B95uHfktNuH/wUEv9pUgvy3YbhaRuDensjwjNy8qc0/y9 8q8DybJzzxCSXvBA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 079/120] KVM: VMX: Use standard CPUID(0x12) types Date: Thu, 28 May 2026 17:38:41 +0200 Message-ID: <20260528153923.403473-80-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For VMX processor compatibility checks, use standard CPUID(0x12) data types from x86-cpuid-db instead of doing manual bitwise operations. Do not use parsed CPUID access since mutating X86_FEATURE_SGX1 state will affect its cached hardware-backed CPUID bit in the future. Update cpu_has_sgx()'s comment to match current x86 kernel state. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/vmx/vmx.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index ede773ce065a..20d5397436bf 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2642,14 +2642,21 @@ void vmx_cache_reg(struct kvm_vcpu *vcpu, enum kvm_= reg reg) } =20 /* - * There is no X86_FEATURE for SGX yet, but anyway we need to query CPUID - * directly instead of going through cpu_has(), to ensure KVM is trapping - * ENCLS whenever it's supported in hardware. It does not matter whether - * the host OS supports or has enabled SGX. + * Do a direct CPUID query instead of checking X86_FEATURE_SGX1 or parsed + * CPUID access. KVM needs to trap ENCLS whenever SGX is supported in + * hardware, regardless of whether the host OS supports or has enabled SGX. */ static bool cpu_has_sgx(void) { - return cpuid_eax(0) >=3D 0x12 && (cpuid_eax(0x12) & BIT(0)); + struct leaf_0x12_0 l12; + struct leaf_0x0_0 l0; + + cpuid_read(0, &l0); + if (l0.max_std_leaf < 0x12) + return false; + + cpuid_read(0x12, &l12); + return l12.sgx1; } =20 static int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, u32 msr, u32 *res= ult) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 DE21B46AF20 for ; Thu, 28 May 2026 15:44:14 +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=1779983057; cv=none; b=sC+xk5OVG/lFAWLNOGCr/ghGlmps2Uwy+RAMU3YaG1m3Lpkwi7K3f1aa7fEJn3ZJNDzkkh3FQ4DONJxsuqsBdTQ+mrb3s0BrrWZoHb2+hcTTmlFEoYmkjK06QmdZD/PiPSe0UcY7Qd0y1CiUBbS6lo7R0zM+Vh1XM34Z6GUd6yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983057; c=relaxed/simple; bh=L/1ikR02exlB2c3QbIKqepsPr7AmfW4/46RPeFrE5gU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mi3vMccKVTW3d5Eio3mfVG84OEeoEIdBVloMChEhyKcJqwU64N+WBuqWe77wAY+qd9M+Pr/VeHAZmKqXUlA7QigW1AKYewqdwGWEPLmCJFmPIUgeeTJ8WSIwYAmoeZDeoXdrAmjRHay2naiQsOcHK9HKBu4fGGpyxorw+DC1bFk= 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=VO0FCheP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+9sSw2hz; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VO0FCheP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+9sSw2hz" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XhOq7bjuxKHILY+GaiuJSrtf8kbVxcqX/3Xm7uhrUxc=; b=VO0FCheP7EeTgNSyVKQDNnV1N6RXex4skauUFsweT7uV0H9tFA/WTJRPZ+sFKuTdT2A43k Fv0AXo077d9NEzagwW9vNDF3IXo4kBsQd9TErTmZB81GoIIEB9NYVBDbanInPwCVqq8kni lJuN87rMlNKYhC6p2CSyKCauqtYJKkPCmkxD6AvYTTpS7Vi9f7tfjwOIuvkOctN48IuAbx 3w0LC5ZFVj/08HlFRbgCoKB5r2H48M5H2tejdDf3gGTIDBGMpqiw7bcllZIy5zx2qHY2SR WB+B+eHL02LwvztIfMyj0CR0GoYMS+JLqZl7k8ib+6gUbMjUENtAeNmDqxzGPA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XhOq7bjuxKHILY+GaiuJSrtf8kbVxcqX/3Xm7uhrUxc=; b=+9sSw2hzeo0ILXwL6jq7qJRcWBRhOcYIVK+oXHV0ab8K18kMHYq35loDKIKBwTHAgZ41bf NIQKm3AdF1XDBkCA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 080/120] x86/sgx: Move unused CPUID(0x12) symbols Date: Thu, 28 May 2026 17:38:42 +0200 Message-ID: <20260528153923.403473-81-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Kernel CPUID(0x12) call sites have been converted to the CPUID parser API. They should no longer issue manual CPUID queries on their own. Remove all symbols previously used for manual CPUID(0x12) enumeration move them to the SGX selftests where they are still needed. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/sgx.h | 10 ++-------- tools/testing/selftests/sgx/defines.h | 9 +++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/sgx.h b/arch/x86/include/asm/sgx.h index 04958459a7ca..bbd68fc0f839 100644 --- a/arch/x86/include/asm/sgx.h +++ b/arch/x86/include/asm/sgx.h @@ -16,16 +16,10 @@ * together for better readability. The architectural definitions come fi= rst. */ =20 -/* The SGX specific CPUID function. */ -#define SGX_CPUID 0x12 -/* EPC enumeration. */ +/* First CPUID(0x12) subleaf for EPC enumeration */ #define SGX_CPUID_EPC 2 -/* An invalid EPC section, i.e. the end marker. */ -#define SGX_CPUID_EPC_INVALID 0x0 -/* A valid EPC section. */ +/* Valid subleaf EPC section */ #define SGX_CPUID_EPC_SECTION 0x1 -/* The bitmask for the EPC section type. */ -#define SGX_CPUID_EPC_MASK GENMASK(3, 0) =20 enum sgx_encls_function { ECREATE =3D 0x00, diff --git a/tools/testing/selftests/sgx/defines.h b/tools/testing/selftest= s/sgx/defines.h index 402f8787a71c..e1ab3b36e827 100644 --- a/tools/testing/selftests/sgx/defines.h +++ b/tools/testing/selftests/sgx/defines.h @@ -20,6 +20,15 @@ #include "../../../../arch/x86/include/asm/enclu.h" #include "../../../../arch/x86/include/uapi/asm/sgx.h" =20 +/* The SGX specific CPUID function */ +#define SGX_CPUID 0x12 + +/* An invalid EPC section, i.e. the end marker */ +#define SGX_CPUID_EPC_INVALID 0x0 + +/* The bitmask for the EPC section type */ +#define SGX_CPUID_EPC_MASK GENMASK(3, 0) + enum encl_op_type { ENCL_OP_PUT_TO_BUFFER, ENCL_OP_GET_FROM_BUFFER, --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 E88EE46AF35 for ; Thu, 28 May 2026 15:44:17 +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=1779983060; cv=none; b=fpD2jNmPaqqYZtdHGcr/lxVufZBjOncNGh32ZdiWHglAsZ3kneNdXyYHxFOU4cDFQLTL6m+/ObottWhxrdZtS1TAbDF3j7s2umYwMjTBE2qGItfDsotTVVZXWKwUnKN75jYTrez9ZPDCQ1bt+00xtihRY0hPRqCijyEOebC0V7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983060; c=relaxed/simple; bh=atExEPaQj5VXLbdz4SrCXstPUfhb09Qy2BnQQU7ah/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DyazcqHtFvldJVNo9vg4lvNWIumrAy3Lx3ys4Jl3NpL5WoxXsTbq378d8aFqLF2vDQitpQVyS5uutp7MwnMV807Hc7HdRA139XTiplYxfH7o3nM0ANmax+fH8I0I9cvnOOIW5zDKZPjQc/kejIhl7WtM3XMMgj+PqCLIGtkaDYw= 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=EyqrT+dq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aXINI3gb; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EyqrT+dq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aXINI3gb" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N9JR8+Kh5H+k9Y6c85wbZ8l/7PBM9jCXslxVh27Smj0=; b=EyqrT+dqj7oTb60EEz2qLN/bNR6ESTVOVqIjOlBhPo14aq0xpJxanTbz0YdzsKr6wRasv6 Qj0T1deHXQJvokaQYiIjFQKbua6z4GgjbKgbpDUz+BNJ1GeOY0kDYMI1/rnVLD8yo47HRp kBX+hM9YQKuRNCwrPWuWXXupj9/oivjYntx0VbzRQeR8wrsRYrSwsV/c6TpdgC1jI6fGR4 iHRhOkKrVP7iEKsHfHa3n6Lw1sm8xnMpGp4sLAnivrNflT51oXQP/oVTk61CpJSrYAiQlm To0PC5Q6AR0rjBrx7ZPyfbfRFyFN3oiZtZyoD8V/LfLzWrBzQogvF59vZbaevA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N9JR8+Kh5H+k9Y6c85wbZ8l/7PBM9jCXslxVh27Smj0=; b=aXINI3gbkfcXEBsVDAGMG71GAeT1y9fq7SzpOczoey20UaSiP0gAkYQ72+nj84iRCgiGSz 0KeP8+TfHup1BKAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 081/120] x86/cpuid: Parse CPUID(0xa) and CPUID(0x1c) Date: Thu, 28 May 2026 17:38:43 +0200 Message-ID: <20260528153923.403473-82-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0xa) and CPUID(0x1c). This allows their call sites to be converted to the CPUID APIs next. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 2 ++ arch/x86/kernel/cpu/cpuid_parser.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 91ed4dd3c6c2..81a84483297c 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -215,11 +215,13 @@ struct cpuid_leaves { CPUID_LEAF ( 0x5, 0 ); CPUID_LEAF ( 0x6, 0 ); CPUID_LEAF ( 0x9, 0 ); + CPUID_LEAF ( 0xa, 0 ); CPUID_LEAF ( 0x12, 0 ); CPUID_LEAF ( 0x12, 1 ); CPUID_LEAF_N ( 0x12, 8 ); CPUID_LEAF ( 0x15, 0 ); CPUID_LEAF ( 0x16, 0 ); + CPUID_LEAF ( 0x1c, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index d12d1c2b459b..bd3c99cb985c 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -149,11 +149,13 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x5, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x6, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x9, 0, 0x9 ), \ + CPUID_PARSE_ENTRY ( 0xa, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x12, 0, 0x12 ), \ CPUID_PARSE_ENTRY ( 0x12, 1, 0x12 ), \ CPUID_PARSE_ENTRY_N ( 0x12, sgx_epc_sections ), \ CPUID_PARSE_ENTRY ( 0x15, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x1c, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ @@ -205,9 +207,11 @@ struct cpuid_vendor_entry { /* Leaf Vendor list */ \ CPUID_VENDOR_ENTRY(0x2, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x4, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ + CPUID_VENDOR_ENTRY(0xa, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x12, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x15, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ + CPUID_VENDOR_ENTRY(0x1c, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x8000001d, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860001, X86_VENDOR_TRANSMETA), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 0171146AF11 for ; Thu, 28 May 2026 15:44:21 +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=1779983062; cv=none; b=U8gkxMmCEDYZC7CN9pDLnfALuRz+rLw6+D11Lrkeo25j1C3FNRAJOnfrqL6wg/cxepGIRHfd0D+x/+KX+M2MB8RhlguyjCU1fgPoj/xzudibGuC9j2aDXMYbRBA2zURzXUQSr2P6Hy6nq4inzv/wZt5FHCvIYYgXdO6ET1TuM80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983062; c=relaxed/simple; bh=XiFxPkLhYbX9QLMJoAg2kwa2wqyT/N1MdE7O2hUjNRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AU2j8wvx+ka2LmKJMEdnD9DjVcfFAe9ppCHQoD0IioY0E1ZELYDiUnd0JX+1Hfbf63uT2aExUwAw3fj+4dpUf6WHmey+uYKSyOm9t1pvuWyAhfy7JVu35WJyrUrUBhTDSTLkBxpYJkIHsQf5Ez8DaK0MJ4uX2TOXJ98pSTYAgDQ= 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=vZkoduRM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zLqFXrT8; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vZkoduRM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zLqFXrT8" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H2BSQqdGpNJkQse8VR3+cNBbUKumENGCenMOjs/togw=; b=vZkoduRMy6aXrEEIItLDV/B3Us6v63ig2ggONhY1s8K3TKIqquPSE4nq/0Vn3O5CxnBKRz tyCea33H0rEubvb8HmW+8h/sGxWyCbyCbfiCaiDG1V8QTWFxXgTH/DUY/U827un/zl4773 DNBZIpVe+5S3Wnx1B4VeFU9QEyR1EPAjJDO9yvBHH6l2WtOjrrZSIIHxh7+liIotl1jSai piIoc/cyN15kapYJkJ9n4RYbDT7owabZnGH0uWfAvKRBVFB1lcwP5C0kUda7Mjumo5r71T Dk8r4CU/rqIc/i5oo0584Qecr2QlKItw8IZqAc9c1a947m4NApaiVfAWlEehQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H2BSQqdGpNJkQse8VR3+cNBbUKumENGCenMOjs/togw=; b=zLqFXrT8macK1jOZzMT6JvkT2BBRvJpHQz6MAf8e4v1y2ZRfHm/uTRyOak6fwZyD2Gs78k K0XOxTcjMWs/KxCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 082/120] x86/cpu/intel: Use parsed CPUID(0xa) Date: Thu, 28 May 2026 17:38:44 +0200 Message-ID: <20260528153923.403473-83-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel's PMU enumeration, use parsed CPUID(0xa) instead of a CPUID query and ugly bitwise operations. Remove comments; the generated bitfield names already make everything clear. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/intel.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 51078ffee16c..7ef3ba2eca3a 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -534,18 +534,16 @@ static const struct x86_cpu_id zmm_exclusion_list[] = =3D { =20 static void init_intel(struct cpuinfo_x86 *c) { + const struct leaf_0xa_0 *la =3D cpuid_leaf(c, 0xa); + early_init_intel(c); =20 intel_workarounds(c); =20 init_intel_cacheinfo(c); =20 - if (c->cpuid_level > 9) { - unsigned eax =3D cpuid_eax(10); - /* Check for version and the number of counters */ - if ((eax & 0xff) && (((eax>>8) & 0xff) > 1)) - set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); - } + if (la && la->pmu_version && la->num_counters_gp > 1) + set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); =20 if (cpu_has(c, X86_FEATURE_XMM2)) set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 52D61477986 for ; Thu, 28 May 2026 15:44:24 +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=1779983066; cv=none; b=lG9db4+LOQhyZmnc6bPzplGhrZMoCpddAjSR9Nn/G69CQrI8Rhi8Z7LnKLQC2b2mKcmNf7i2ldIr8JcBJx1L3sw7AqKijNUjhOVwKP3m0VBLSyNtzcqM3b/hTuXcluookTGQ+TAKblSJYGOFV3Sc36WxN4pwlXuJIGkAbVVtats= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983066; c=relaxed/simple; bh=yHW9V1A2BQR4bDofDcUzcs8oedumY+JMCo6rYr49hRk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rQ7xE8KVT6a3OdWtRJiDnn3aFs8eyXl4AGqA90woDr/a8gzrtVdPqREgrxaWbo0VFBs236Op0baQsfkYxTsKBlHVt2wlPXMOCEwS9CB9Brb460afyIV2Xjf0UilfHeqnk4IbVThDPDjLqRWK3FJ/IbfbYn3f/okiRtEc7Y2bq88= 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=eoTKXB2H; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=0B70BZpT; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eoTKXB2H"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="0B70BZpT" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x1+DpAEONFohVtaQVhJCcQ6qez7fy7CNdepuo79ZG7Y=; b=eoTKXB2Hl9u+ZSomzoOJUZDE72dQAl+J70uLjGemb2t27B//wRTIfGvrKgPYvtk/aYRekx m2/trEzwS5umyarUR0Fhgu+Qf/xTyWXRUc4r84rSGWxqwru9XYmYaIVv6TXdll5ixriMUJ 8UbxnT7PCMNDaf1CbRxMCy/f2/OQzG26YTMx8QSLDUiwdoVjAQhHErUBOokK6HOsFal7O3 hFHlU9mXp8gFqd8CCmSoRT/7U+MlPuIbp3CBBtkX9yCK9zvxzpmnaKgAyjiqxlO19vQqJI siRy267Y77eXG1LdBquBOQPGpL0qw77UkQJneoO5Z3/cb3MKKa4YUp8q8LKBhg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x1+DpAEONFohVtaQVhJCcQ6qez7fy7CNdepuo79ZG7Y=; b=0B70BZpThKdtjXtlPVla/b0/Yjw/TveWXkL8hCgFpFqqg1+ygp+PFybUvf9wMNFFQmDToW i/zUXrFz+j5WKPCQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 083/120] x86/cpu/centaur: Use parsed CPUID(0xa) Date: Thu, 28 May 2026 17:38:45 +0200 Message-ID: <20260528153923.403473-84-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Centaur's PMU enumeration, use parsed CPUID(0xa) instead of a direct CPUID query and ugly bitwise operations. Remove comments; the generated bitfield names already make everything clear. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/centaur.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 895cf00919d3..86cbe4427453 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -106,6 +106,7 @@ static void early_init_centaur(struct cpuinfo_x86 *c) =20 static void init_centaur(struct cpuinfo_x86 *c) { + const struct leaf_0xa_0 *la =3D cpuid_leaf(c, 0xa); #ifdef CONFIG_X86_32 const struct leaf_0x80000005_0 *el5 =3D cpuid_leaf(c, 0x80000005); u32 lo, hi, newlo; @@ -116,17 +117,8 @@ static void init_centaur(struct cpuinfo_x86 *c) early_init_centaur(c); init_intel_cacheinfo(c); =20 - if (c->cpuid_level > 9) { - unsigned int eax =3D cpuid_eax(10); - - /* - * Check for version and the number of counters - * Version(eax[7:0]) can't be 0; - * Counters(eax[15:8]) should be greater than 1; - */ - if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1)) - set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); - } + if (la && la->pmu_version && la->num_counters_gp > 1) + set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); =20 #ifdef CONFIG_X86_32 if (c->x86 =3D=3D 5) { --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 5E754472792 for ; Thu, 28 May 2026 15:44:27 +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=1779983068; cv=none; b=f9GlDyRSmIur1br2yi3TpnkEVB0S07MJfYnnjD1r9MExnx9IQCQSd0c5WxxzJV2QNX4qZTWar8v8vxHg82KJvBXCbLyKNZ6lcugBGfLKe0NRIOy1zUdTRFz6lqYZRScublwwaTMh7KG7f55p6Ppt4U3frvBwvgBXTvQMhdsEc5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983068; c=relaxed/simple; bh=ZwVJ6pp+lyRC77pJoa3ltQw2exv/jl+UBJqpTaFCBjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hiv4dQRsubtLXenGOlgNQ92wQKdJfWWNVpvTlej7mH0ZtmUrZBHkvq5pbtubMcjv2840wqsm5kdWmwtcw48V0T8or7+rHLJCDAkfl3F3QHKIJ9bS5Vlz78IjMsHNS3EWELnGOgE/N0kwq1fudlZo4R4WaHHhkHz1l1qq6ZeqfiQ= 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=u7IgP+QT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vG/w7Q/p; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="u7IgP+QT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vG/w7Q/p" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omxTm3xXvQxj0iNQGH6ByRIK7ce+ms9b+rbAsmHGgh8=; b=u7IgP+QTu8IPTjDGoymH+dwmQWAnZBUggE4wc6CHKs4fevyduQuCLWbl4/1kl4r3t2pmjD PSSc83oahCVSjpdU7vGKhodJmnoq10qsJ4TwnnnxS+cPWc5m7v298Eux7vTQWSFkBTdA4L 6ro5cwQR9sOQ19A0n7Vlai4oH14UlBoGaLn/2YB6Bw4KP736grnUWVzp/VktRoFymt9V7U aV/A93lYavnOZ/vcGX0KKT2DW/5zb/OBH9Rp3WDJ6kc5Q9rookIXduWXRf74YJFlH/gQT0 jnKUQkWw4FTRUzp+vYq2Rksj/oOco9/5XlwNv6UYYUTmL5ynxCbefgBblUf86w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omxTm3xXvQxj0iNQGH6ByRIK7ce+ms9b+rbAsmHGgh8=; b=vG/w7Q/p2MwZfrUk1czSmkw/udHanFcoLM0/yWlr7tzwLAMtEgTwpFD3oS0ArUyiChtlT2 GYBg9joXH/3apMAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 084/120] x86/cpu/zhaoxin: Use parsed CPUID(0xa) Date: Thu, 28 May 2026 17:38:46 +0200 Message-ID: <20260528153923.403473-85-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Zhaoxin's PMU enumeration, use parsed CPUID(0xa) instead of a direct CPUID query and ugly bitwise operations. Remove comments; the generated bitfield names already make everything clear. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/zhaoxin.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index ea76e9594453..b068922efed9 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -61,20 +61,13 @@ static void early_init_zhaoxin(struct cpuinfo_x86 *c) =20 static void init_zhaoxin(struct cpuinfo_x86 *c) { + const struct leaf_0xa_0 *la =3D cpuid_leaf(c, 0xa); + early_init_zhaoxin(c); init_intel_cacheinfo(c); =20 - if (c->cpuid_level > 9) { - unsigned int eax =3D cpuid_eax(10); - - /* - * Check for version and the number of counters - * Version(eax[7:0]) can't be 0; - * Counters(eax[15:8]) should be greater than 1; - */ - if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1)) - set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); - } + if (la && la->pmu_version && la->num_counters_gp > 1) + set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON); =20 if (c->x86 >=3D 0x6) init_zhaoxin_cap(c); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 90CC547278A for ; Thu, 28 May 2026 15:44:30 +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=1779983072; cv=none; b=P6XegvzXVQckFW2a11LcQVLBiFW9p9kNMtcL/zVH0sgaYUSPXNipLDfYal3oMIbOXm0AOuovgdbGwntzvHSAA66XwKJMo1Sgzqd9uz+OkHTUoYCwMiR4fPhKjb2z7wxb9KNrBhCUPTLG6xoplESHpA9j34+Vep0CwlfylYLMhFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983072; c=relaxed/simple; bh=NUOCGS99Vck8biaCr0xWLcUa5k7xD/Y6THW6wi3/q+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IKVWaok8QCyCryR/g+g1RMRqY43gU14f81QN4A+d8bnPJ3eFoeQDrRRaspU09tR8vk4mOt/Yq3Y9ZIxB1muSlkwCWlZYA4iKrHcqHvoAQCcXz+Fd4UsU7e4K/zbwGZo6UJRO2uzgJbOdhDoDOs63auNwERFB8qLwIsO0TOw9/xs= 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=xzUu2mtl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GZIVkNnU; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xzUu2mtl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GZIVkNnU" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhCjCJni4mRVwiJTlRqiqt97Sj2p2flgvvbNsg5HUIc=; b=xzUu2mtlETX6cH75ur5q6oAL0L0gKLOeF4OFJIgzrtmAotWzrPVw0KDy+1lG9uYjQ51OAH 3kUSPs5p2H8DQvg3TxbN4aSoEHGIGhq47K5C1i3bFRRXt0X87qhAwkvG2HoAtdWYdgxc88 efEkcsJvqp/QEU1LeFvC7N/QEmQctLdRRUQIqSGAbHcUZzv+22z4F+978W1zIZDwbIGsp5 qbnnWfwiVsy6Elr2HMI/LdNPdqo8Ee1hvplU96qLK62eNXYg9Wjt+uIpPM6eSNWyT1Jl0b vaQFscpwQaOfEXITpX7rTmEyvsdyFRafYS3DUMM4bEbvGpDAIuJSVvFFYMxvTQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983069; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhCjCJni4mRVwiJTlRqiqt97Sj2p2flgvvbNsg5HUIc=; b=GZIVkNnUMs2/bepVkTY0GD1ZX8ROLveZuMeHUzwbGMqmYAUnCVk8+QPSZs79fSEGSVy8OJ 0gwI19zJIlqs9wBw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 085/120] perf/x86/intel: Use parsed CPUID(0xa) Date: Thu, 28 May 2026 17:38:47 +0200 Message-ID: <20260528153923.403473-86-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel perfmon, use parsed CPUID(0xa) instead of issuing CPUID queries and defining custom CPUID output data types. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/intel/core.c | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index ea7507bb7047..53c614c61531 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -6612,10 +6612,11 @@ static __init void intel_arch_events_quirk(void) =20 static __init void intel_nehalem_quirk(void) { - union cpuid10_ebx ebx; + struct leaf_0xa_0 l =3D { }; + struct cpuid_regs *regs =3D (struct cpuid_regs *)&l; =20 - ebx.full =3D x86_pmu.events_maskl; - if (ebx.split.no_branch_misses_retired) { + regs->ebx =3D x86_pmu.events_maskl; + if (l.no_br_misses_retired) { /* * Erratum AAJ80 detected, we work it around by using * the BR_MISP_EXEC.ANY event. This will over-count @@ -6623,8 +6624,8 @@ static __init void intel_nehalem_quirk(void) * architectural event which is often completely bogus: */ intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] =3D 0x7f89; - ebx.split.no_branch_misses_retired =3D 0; - x86_pmu.events_maskl =3D ebx.full; + l.no_br_misses_retired =3D 0; + x86_pmu.events_maskl =3D regs->ebx; pr_info("CPU erratum AAJ80 worked around\n"); } } @@ -7558,15 +7559,13 @@ static __always_inline void intel_pmu_init_arw(stru= ct pmu *pmu) =20 __init int intel_pmu_init(void) { + const struct cpuid_regs *regs =3D cpuid_leaf_raw(&boot_cpu_data, 0xa); + const struct leaf_0xa_0 *leaf =3D cpuid_leaf(&boot_cpu_data, 0xa); struct attribute **extra_skl_attr =3D &empty_attrs; struct attribute **extra_attr =3D &empty_attrs; struct attribute **td_attr =3D &empty_attrs; struct attribute **mem_attr =3D &empty_attrs; struct attribute **tsx_attr =3D &empty_attrs; - union cpuid10_edx edx; - union cpuid10_eax eax; - union cpuid10_ebx ebx; - unsigned int fixed_mask; bool pmem =3D false; int version, i; char *name; @@ -7590,27 +7589,29 @@ __init int intel_pmu_init(void) return -ENODEV; } =20 + if (!leaf || !regs) + return -ENODEV; + /* * Check whether the Architectural PerfMon supports * Branch Misses Retired hw_event or not. */ - cpuid(10, &eax.full, &ebx.full, &fixed_mask, &edx.full); - if (eax.split.mask_length < ARCH_PERFMON_EVENTS_COUNT) + if (leaf->events_mask_len < ARCH_PERFMON_EVENTS_COUNT) return -ENODEV; =20 - version =3D eax.split.version_id; + version =3D leaf->pmu_version; if (version < 2) x86_pmu =3D core_pmu; else x86_pmu =3D intel_pmu; =20 x86_pmu.version =3D version; - x86_pmu.cntr_mask64 =3D GENMASK_ULL(eax.split.num_counters - 1, 0); - x86_pmu.cntval_bits =3D eax.split.bit_width; - x86_pmu.cntval_mask =3D (1ULL << eax.split.bit_width) - 1; + x86_pmu.cntr_mask64 =3D GENMASK_ULL(leaf->num_counters_gp - 1, 0); + x86_pmu.cntval_bits =3D leaf->bit_width_gp; + x86_pmu.cntval_mask =3D (1ULL << leaf->bit_width_gp) - 1; =20 - x86_pmu.events_maskl =3D ebx.full; - x86_pmu.events_mask_len =3D eax.split.mask_length; + x86_pmu.events_maskl =3D regs->ebx; + x86_pmu.events_mask_len =3D leaf->events_mask_len; =20 x86_pmu.pebs_events_mask =3D intel_pmu_pebs_mask(x86_pmu.cntr_mask64); x86_pmu.pebs_capable =3D PEBS_COUNTER_MASK; @@ -7624,9 +7625,9 @@ __init int intel_pmu_init(void) int assume =3D 3 * !boot_cpu_has(X86_FEATURE_HYPERVISOR); =20 x86_pmu.fixed_cntr_mask64 =3D - GENMASK_ULL(max((int)edx.split.num_counters_fixed, assume) - 1, 0); + GENMASK_ULL(max((int)leaf->num_counters_fixed, assume) - 1, 0); } else if (version >=3D 5) - x86_pmu.fixed_cntr_mask64 =3D fixed_mask; + x86_pmu.fixed_cntr_mask64 =3D leaf->pmu_fcounters_bitmap; =20 if (boot_cpu_has(X86_FEATURE_PDCM)) { u64 capabilities; @@ -7648,7 +7649,7 @@ __init int intel_pmu_init(void) x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last= */ =20 if (version >=3D 5) { - x86_pmu.intel_cap.anythread_deprecated =3D edx.split.anythread_deprecate= d; + x86_pmu.intel_cap.anythread_deprecated =3D leaf->anythread_deprecation; if (x86_pmu.intel_cap.anythread_deprecated) pr_cont(" AnyThread deprecated, "); } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 DA1C6478859 for ; Thu, 28 May 2026 15:44:33 +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=1779983080; cv=none; b=jFfTTK6Vqy81ghwjV0o6svbzRoddLVbHbTFDpPfDsp2JbTqnWbFcKuAGt9tjEGbbVQ6oogVQtX8FgbV3fAskQJF7QGkC/BPTTm8/TcoKGWGRfUpgi+cEtR48uvuhAzAPrs1ZBODWbnhRByHYngKE7ntx9J9CNTbnjIDbLoVqlgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983080; c=relaxed/simple; bh=OxBGYtK8SVSdlUybsVJ2yt3KgRlue5jlBwm9ItNRWbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o0fg9xpB99jCYTMRgYTrkBvE+NSdUzwlmy2XNfXIElI6ZYHhwW5/p2DFwoBR2zwY2ix14VsqZZj8m7VD6FoPdz3bTHSQEH85o4qS+AuTai0sIpeayq9c0MgkNox/uoVP2QcKaGVrfN+U2l4EbxIk/cLNG+GDkuthrdWPPbYYFpA= 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=pfeyMlNk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/+8ssEvb; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pfeyMlNk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/+8ssEvb" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XAoJLp9hUgxb0OpTSFds5r+hHb5dZuQVfxSIcQLvDOU=; b=pfeyMlNk3na7m98GhJiqv5DGKNSIQsGQu3iLjmFG0CTVYX7bAujRsyuYgVFpfYIonYv8+1 hwoNEZX8Kix6xgD8nfnabcRhhmq7tJ3ygBcUZNRuD7jGIVZaQUwSSa8mciIPLGpz9Jh5xo sz7pm/TsDxq5JxWxOqdtqs0tT23g8v+zE+wKZnUrJjZb/6osDCJkpSV7iiDcTK8NMtnz+o q4x0dgv85YjmlnRSTELQBb4A+ejC3llkmqROyxbTe+pp9aIaTV+vvnHSAcHAiuterXeEtG Sz4LtV22D88MWlrDRsArza4L/LL7+zuW3zsAcYg69Mcxl//iKxvvfsJruH4DCw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XAoJLp9hUgxb0OpTSFds5r+hHb5dZuQVfxSIcQLvDOU=; b=/+8ssEvbkH74EKPrNAzrwbJmGebqPE6rAjvVUySbhl80ywIGatLwX9+7dnHZst8JWR8v8a oQIMflLBihODYpDg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 086/120] perf/x86/zhaoxin: Use parsed CPUID(0xa) Date: Thu, 28 May 2026 17:38:48 +0200 Message-ID: <20260528153923.403473-87-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Zhaoxin perfmon, use parsed CPUID(0xa) instead of issuing CPUID queries and defining custom CPUID output data types. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/zhaoxin/core.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/arch/x86/events/zhaoxin/core.c b/arch/x86/events/zhaoxin/core.c index 6ed644fe89aa..1c487d09f65c 100644 --- a/arch/x86/events/zhaoxin/core.c +++ b/arch/x86/events/zhaoxin/core.c @@ -505,39 +505,36 @@ static __init void zhaoxin_arch_events_quirk(void) =20 __init int zhaoxin_pmu_init(void) { - union cpuid10_edx edx; - union cpuid10_eax eax; - union cpuid10_ebx ebx; + const struct cpuid_regs *regs =3D cpuid_leaf_raw(&boot_cpu_data, 0xa); + const struct leaf_0xa_0 *leaf =3D cpuid_leaf(&boot_cpu_data, 0xa); struct event_constraint *c; - unsigned int unused; - int version; =20 pr_info("Welcome to zhaoxin pmu!\n"); =20 + if (!leaf || !regs) + return -ENODEV; + /* * Check whether the Architectural PerfMon supports * hw_event or not. */ - cpuid(10, &eax.full, &ebx.full, &unused, &edx.full); - - if (eax.split.mask_length < ARCH_PERFMON_EVENTS_COUNT - 1) + if (leaf->events_mask_len < ARCH_PERFMON_EVENTS_COUNT - 1) return -ENODEV; =20 - version =3D eax.split.version_id; - if (version !=3D 2) + if (leaf->pmu_version !=3D 2) return -ENODEV; =20 x86_pmu =3D zhaoxin_pmu; pr_info("Version check pass!\n"); =20 - x86_pmu.version =3D version; - x86_pmu.cntr_mask64 =3D GENMASK_ULL(eax.split.num_counters - 1, 0); - x86_pmu.cntval_bits =3D eax.split.bit_width; - x86_pmu.cntval_mask =3D (1ULL << eax.split.bit_width) - 1; - x86_pmu.events_maskl =3D ebx.full; - x86_pmu.events_mask_len =3D eax.split.mask_length; + x86_pmu.version =3D leaf->pmu_version; + x86_pmu.cntr_mask64 =3D GENMASK_ULL(leaf->num_counters_gp - 1, 0); + x86_pmu.cntval_bits =3D leaf->bit_width_gp; + x86_pmu.cntval_mask =3D (1ULL << leaf->bit_width_gp) - 1; + x86_pmu.events_maskl =3D regs->ebx; + x86_pmu.events_mask_len =3D leaf->events_mask_len; =20 - x86_pmu.fixed_cntr_mask64 =3D GENMASK_ULL(edx.split.num_counters_fixed - = 1, 0); + x86_pmu.fixed_cntr_mask64 =3D GENMASK_ULL(leaf->num_counters_fixed - 1, 0= ); x86_add_quirk(zhaoxin_arch_events_quirk); =20 switch (boot_cpu_data.x86) { @@ -617,4 +614,3 @@ __init int zhaoxin_pmu_init(void) =20 return 0; } - --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 D4AEE4779B8 for ; Thu, 28 May 2026 15:44:36 +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=1779983081; cv=none; b=jLuHE573lWl/KoEXKvAl0z66cmRiFDkDE6XQkTl10Xzm2jg0x+FnqZG1ynFAWgl8rC+ganNU3B+iRdc0dmYnU7oGqXjyljN5SxjhvXoQRxewGcUdVR7tOWaME0/ppaudgFKBs1IDnnBskCWYU9Lk8UomegZ0OP3pV7xH4qmeB38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983081; c=relaxed/simple; bh=YVgTt8HIIwTAp+Pa5a6iVUPNemV47ySAcssRH68JK+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WuYve2VwsqbYq3kmqzs3RUY75jovmq3apo5803y+qpmyGxXV9JPWAIVEDsZ1Un/VxeOlVUbrjUPh0ClUwQqKyv2Veu8wjPdvokhqtz7tPP/PAzUxetS3lkivzoMT725RScFzNgOYQohE5eIVUGyStK2fh2L5yV6XWQfXdLpdbxc= 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=YrPvGbcq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EvsuuunP; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YrPvGbcq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EvsuuunP" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/Ga/F62UWiylqt22ElnnYk+f5snfpub5VnpyZuFiaDI=; b=YrPvGbcq9xTPE4XI1NkSpTNBedkSD9VwbHuNgKLBb3Ymby2S1Ak8IOMvYG1EP7VNzu1GBW GauItKoCsuSTDB7coLdRiRUwugG+tlpDP/8mrSsOXPZfL6q9OV19gFOZclg4WyL9embB4B McE5v5RnL0u729nqS2M6XrGGmh5BrIlbYE66kEZIpgsGf92Hp5rqRw+vEysSVUEtaC1QeL wxPvGTnuFu46jez2jNby0b5i9n89lDUv6ftOh8PbEq52GEidjQ6mfahAHG9Kpi7DfmKghg InESFzfeCeUNS3FD3LUh8/1AO2kVse9WjNyYMYoHbIK8RQZPhJMnzHn3p7nWQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/Ga/F62UWiylqt22ElnnYk+f5snfpub5VnpyZuFiaDI=; b=EvsuuunPCixGtuKYdY5GSfiGfoNQxOBaRRDvtUgxgmKRgrupk3P3NczUB5GBxyacRLhT82 bW55UUZWm/JN1VDg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 087/120] x86/xen: Use parsed CPUID(0xa) Date: Thu, 28 May 2026 17:38:49 +0200 Message-ID: <20260528153923.403473-88-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Xen PMU, use parsed CPUID(0xa) instead of a direct CPUID query and ugly bitwise operations. Remove the PMU_{GENERAL,FIXED}_NR macros as they are no longer needed. Signed-off-by: Ahmed S. Darwish --- arch/x86/xen/pmu.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c index 5f50a3ee08f5..b0ef35f2bad3 100644 --- a/arch/x86/xen/pmu.c +++ b/arch/x86/xen/pmu.c @@ -48,18 +48,6 @@ static __read_mostly int amd_num_counters; #define MSR_TYPE_ARCH_COUNTER 3 #define MSR_TYPE_ARCH_CTRL 4 =20 -/* Number of general pmu registers (CPUID.EAX[0xa].EAX[8..15]) */ -#define PMU_GENERAL_NR_SHIFT 8 -#define PMU_GENERAL_NR_BITS 8 -#define PMU_GENERAL_NR_MASK (((1 << PMU_GENERAL_NR_BITS) - 1) \ - << PMU_GENERAL_NR_SHIFT) - -/* Number of fixed pmu registers (CPUID.EDX[0xa].EDX[0..4]) */ -#define PMU_FIXED_NR_SHIFT 0 -#define PMU_FIXED_NR_BITS 5 -#define PMU_FIXED_NR_MASK (((1 << PMU_FIXED_NR_BITS) - 1) \ - << PMU_FIXED_NR_SHIFT) - /* Alias registers (0x4c1) for full-width writes to PMCs */ #define MSR_PMC_ALIAS_MASK (~(MSR_IA32_PERFCTR0 ^ MSR_IA32_PMC0)) =20 @@ -70,6 +58,8 @@ static __read_mostly int intel_num_arch_counters, intel_n= um_fixed_counters; =20 static void xen_pmu_arch_init(void) { + const struct leaf_0xa_0 *leaf_a =3D cpuid_leaf(&boot_cpu_data, 0xa); + if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD) { =20 switch (boot_cpu_data.x86) { @@ -98,15 +88,9 @@ static void xen_pmu_arch_init(void) amd_ctrls_base =3D MSR_K7_EVNTSEL0; amd_msr_step =3D 1; k7_counters_mirrored =3D 0; - } else { - uint32_t eax, ebx, ecx, edx; - - cpuid(0xa, &eax, &ebx, &ecx, &edx); - - intel_num_arch_counters =3D (eax & PMU_GENERAL_NR_MASK) >> - PMU_GENERAL_NR_SHIFT; - intel_num_fixed_counters =3D (edx & PMU_FIXED_NR_MASK) >> - PMU_FIXED_NR_SHIFT; + } else if (leaf_a) { + intel_num_arch_counters =3D leaf_a->num_counters_gp; + intel_num_fixed_counters =3D leaf_a->num_counters_fixed; } } =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 EAF74478870 for ; Thu, 28 May 2026 15:44:39 +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=1779983085; cv=none; b=GmcDy2YG5+F37iMZwXc4vXEefhEbEwF5caoUiKoR2lSYV9A9wiSqys4c/8zQfwJeVmLozsIE7iV27TIbeLzUamHfFBiqn7cVtZYzod2cqhhNjkFh5Tyi4fG+oOGmzoQAbRtkdksgBCjPqr1Eo3cc8UZcPxTHRZbzSQH6xL+R4Tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983085; c=relaxed/simple; bh=NnO7/noqKNFe+3JsdizDXVc5KUWBSnOHU7OfJH/J9Ng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HLFZZU6yhcnLygIkpA2YEaKpIeLthFSEVND3R3saxkBjFVaQdj7j83FayvLINWX8a45ISZrLoNDpGgqKl1Nn+ZIFIa5NzpXTCZgLKEDO6HMiEO4JT2FDlTRI7zV5zH1w0hwgZLGpOwYUeRKGToqtECY3Nx0xo9g65+bsR/myNQw= 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=zOpQFxOk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c2wQATmv; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zOpQFxOk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c2wQATmv" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oweeJd31OFo+A+nUfcK3yCZwyXozLa5TrlFjLLvORW4=; b=zOpQFxOkqPdhe9Rv5bUL/jtRaYrRGqL+/NmC1URu4Qy+LbPH2UzWgkMEai8aY+pzwbcQGF Q5amHCXxi3XNm7VtYBMgNapJMQqsbubIy5rN4Uoavos4aJ/L2q6x04QKSQLjGPo1hMQtWu oDv1kj7cL6Mf+KiAY0QOeYa737WmyvvLcTYkdWA1vj8EPeoIdlWDbu7o5XCRT/JGBZCXRw RYk+SttVy38lnY35WQyW+Ler9elswLQndgDFHK8fcs8yK7uzKR6H1+dFtcGlz3VIL226wn MQcM75msiPnYc65MJMgn1BpXQEow7nHUWxne1yzpDU2b8ChQ5rim5Ky/vtu4qA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oweeJd31OFo+A+nUfcK3yCZwyXozLa5TrlFjLLvORW4=; b=c2wQATmvusWD/N6PP5zpP8c0m+r5F2yn+2CWqD48eVz2il4rppm+3FGWR+JG6FLcoK+d9g /1FNmTwkKekzmYDQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 088/120] KVM: x86: Use standard CPUID(0xa) types Date: Thu, 28 May 2026 17:38:50 +0200 Message-ID: <20260528153923.403473-89-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For KVM guest CPUID build-up, use the auto-generated CPUID(0xa) types from x86-cpuid-db instead of relying on the custom perf types. The latter types are in process of getting removed from the kernel. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/cpuid.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index e69156b54cff..706903ad6628 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1504,28 +1504,28 @@ static inline int __do_cpuid_func(struct kvm_cpuid_= array *array, u32 function) } break; case 0xa: { /* Architectural Performance Monitoring */ - union cpuid10_eax eax =3D { }; - union cpuid10_edx edx =3D { }; + struct leaf_0xa_0 l =3D { }; + struct cpuid_regs *regs =3D (struct cpuid_regs *)&l; =20 if (!enable_pmu || !static_cpu_has(X86_FEATURE_ARCH_PERFMON)) { entry->eax =3D entry->ebx =3D entry->ecx =3D entry->edx =3D 0; break; } =20 - eax.split.version_id =3D kvm_pmu_cap.version; - eax.split.num_counters =3D kvm_pmu_cap.num_counters_gp; - eax.split.bit_width =3D kvm_pmu_cap.bit_width_gp; - eax.split.mask_length =3D kvm_pmu_cap.events_mask_len; - edx.split.num_counters_fixed =3D kvm_pmu_cap.num_counters_fixed; - edx.split.bit_width_fixed =3D kvm_pmu_cap.bit_width_fixed; + l.pmu_version =3D kvm_pmu_cap.version; + l.num_counters_gp =3D kvm_pmu_cap.num_counters_gp; + l.bit_width_gp =3D kvm_pmu_cap.bit_width_gp; + l.events_mask_len =3D kvm_pmu_cap.events_mask_len; + l.num_counters_fixed =3D kvm_pmu_cap.num_counters_fixed; + l.bitwidth_fixed =3D kvm_pmu_cap.bit_width_fixed; =20 if (kvm_pmu_cap.version) - edx.split.anythread_deprecated =3D 1; + l.anythread_deprecation =3D 1; =20 - entry->eax =3D eax.full; + entry->eax =3D regs->eax; entry->ebx =3D kvm_pmu_cap.events_mask; entry->ecx =3D 0; - entry->edx =3D edx.full; + entry->edx =3D regs->edx; break; } case 0x1f: --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 1325F478E25 for ; Thu, 28 May 2026 15:44:43 +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=1779983086; cv=none; b=GFyqi+ZpSmfe50+DzVfBW1EIuqwGiriZMlZKwsxFrRrVFjnW+IXzmMReTvcA8qOmlHk54vySTxGTX7xu0Ux3IlK3bPt1y7DG7M/TZNN6LE/Y97lmFLYkjZeyD37sy/0m3oI6Cnhth8w7PrNSAzjkWo45p0KlZQvU7eT8xeWWPpw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983086; c=relaxed/simple; bh=/4fyUs/FN0eINi2/Sj5+6zpNvqPWactAT8RK7UF0XD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PqlVG0J/+mSvxf6vB0Uu5Pbp6P9UXgwPsZ8gLakSAHSDqZGmnxbdoZOxdcLxX/qmKK4tzo0hpF6dxTe+pf3aA6wAk7hnmL47+XlU1PsfAOIMjrjIgElvkooWd9wUm9K8lLWZ0vaVyPl7HoLTySD3HzySBdiVzEk3ha8YyWfW27Y= 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=qKQZznTL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=m7GM+PRb; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qKQZznTL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="m7GM+PRb" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lAlRHoXDgY0nwQIpO8zaRGhH8pU9gbDX1nbxv2MEQBA=; b=qKQZznTLbi4NmI0thuUxS77mVvmK+yaq0Y1lsT7p3UWBlKxIyDgMipDa8zGzxTC7us+bYQ NqNdUnTI13743+T54wYmekR8nBSWWGeywaeY90gNOJufaPbJlnD+k7NWPYuMYiZJ5lbSSp 96K5w5Ye7+6IEgcAlqmqMDeR8yLBkKL3HG9yM6IeqliGb+pYdmS1qbCho4Jl0FL5hTHZ1b 6m6UOeiBawWANuULmBgmk6NoZklJE0GjRghBe2HDRvuCzvNxSS9Xf/PKd7CYUb6HaryaWl EM+9AodqX3E/jphXr8Zop32dtc7avSBUvT8KKBvFOvmwl27/InjWgwfvu09twA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lAlRHoXDgY0nwQIpO8zaRGhH8pU9gbDX1nbxv2MEQBA=; b=m7GM+PRbqcXqSHQCUWvFBuXH0DfXwyPLRkxVuvFV76lZLhJeSD1bcPu/mpacSNo6kNn6ul 6KlTDe/lXBsAzMCg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 089/120] KVM: x86/pmu: Use standard CPUID(0xa) types Date: Thu, 28 May 2026 17:38:51 +0200 Message-ID: <20260528153923.403473-90-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For KVM PMU refresh, use the auto-generated CPUID(0xa) types from x86-cpuid-db instead of relying on the custom perf types. The latter types are in process of getting removed from the kernel. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/vmx/pmu_intel.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 74e0b01185b8..e0aeb1bc04ca 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -493,8 +493,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) struct kvm_pmu *pmu =3D vcpu_to_pmu(vcpu); struct lbr_desc *lbr_desc =3D vcpu_to_lbr_desc(vcpu); struct kvm_cpuid_entry2 *entry; - union cpuid10_eax eax; - union cpuid10_edx edx; + struct leaf_0xa_0 l =3D { }; + struct cpuid_regs *regs =3D (struct cpuid_regs *)&l; u64 perf_capabilities; u64 counter_rsvd; =20 @@ -515,21 +515,18 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) if (!entry) return; =20 - eax.full =3D entry->eax; - edx.full =3D entry->edx; + regs->eax =3D entry->eax; + regs->edx =3D entry->edx; =20 - pmu->version =3D eax.split.version_id; + pmu->version =3D l.pmu_version; if (!pmu->version) return; =20 - pmu->nr_arch_gp_counters =3D min_t(int, eax.split.num_counters, - kvm_pmu_cap.num_counters_gp); - eax.split.bit_width =3D min_t(int, eax.split.bit_width, - kvm_pmu_cap.bit_width_gp); - pmu->counter_bitmask[KVM_PMC_GP] =3D BIT_ULL(eax.split.bit_width) - 1; - eax.split.mask_length =3D min_t(int, eax.split.mask_length, - kvm_pmu_cap.events_mask_len); - pmu->available_event_types =3D ~entry->ebx & (BIT_ULL(eax.split.mask_leng= th) - 1); + pmu->nr_arch_gp_counters =3D min_t(int, l.num_counters_gp, kvm_pmu_cap.nu= m_counters_gp); + l.bit_width_gp =3D min_t(int, l.bit_width_gp, kvm_pmu_cap.bit_width_gp); + pmu->counter_bitmask[KVM_PMC_GP]=3D BIT_ULL(l.bit_width_gp) - 1; + l.events_mask_len =3D min_t(int, l.events_mask_len, kvm_pmu_cap.events_m= ask_len); + pmu->available_event_types =3D ~entry->ebx & (BIT_ULL(l.events_mask_len) = - 1); =20 entry =3D kvm_find_cpuid_entry_index(vcpu, 7, 0); if (entry && @@ -552,11 +549,9 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) if (pmu->version =3D=3D 1) return; =20 - pmu->nr_arch_fixed_counters =3D min_t(int, edx.split.num_counters_fixed, - kvm_pmu_cap.num_counters_fixed); - edx.split.bit_width_fixed =3D min_t(int, edx.split.bit_width_fixed, - kvm_pmu_cap.bit_width_fixed); - pmu->counter_bitmask[KVM_PMC_FIXED] =3D BIT_ULL(edx.split.bit_width_fixed= ) - 1; + pmu->nr_arch_fixed_counters =3D min_t(int, l.num_counters_fixed, kvm_pmu_= cap.num_counters_fixed); + l.bitwidth_fixed =3D min_t(int, l.bitwidth_fixed, kvm_pmu_cap.bit_wid= th_fixed); + pmu->counter_bitmask[KVM_PMC_FIXED] =3D BIT_ULL(l.bitwidth_fixed) - 1; =20 intel_pmu_enable_fixed_counter_bits(pmu, INTEL_FIXED_0_KERNEL | INTEL_FIXED_0_USER | --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 7AE7E477986 for ; Thu, 28 May 2026 15:44:47 +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=1779983094; cv=none; b=YWoLQ1tWHPs6zmhqVx9IwJl11TZCT5Vv4bL8dfenlnK5NOuMvYxahCpA804V7EAFEsDd1+K/cGC7IhnfD+kmahfc25bxd+EiKyoTLNjF3OI5zePR9igHounjzlNRSkKi6Vy5QsyYZPHpHTm9Z8N8VVu1MDh+XZEwUyJ6vXptfBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983094; c=relaxed/simple; bh=H9pCmISX3Q0c0zjOfqm6CssmNdVASdSJLCL6CRM7xJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dTiS7X9+P2eIyeGM0ciR2qhEcPQfQQ5R82x5mltArH7kr9Ulg84ISzLne1wEDs8/b4epyOxx9ZHZFOaerUndZmLStLz/vUgNTELIRKNJjRkmbFjY/JK6gZCXaqKwiVnBOPvfQrc7YELS/7bXAvo8J+IaNwG3wQT4AFS3OSylC2I= 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=EKuT6dsS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iUVceLvq; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EKuT6dsS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iUVceLvq" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BdCO+X3DDz9sv2KnfeZGJWy7WRmJro+j+/GrBftBzUc=; b=EKuT6dsSXPO8OAEqjs1M2P6ohJRzCc6Mry2KkhmoXbOo89KvgiTjIwikC5C+mZ0HjQbyEd svEp3tfSjyKPUGHnV1foSDNh1zZF0lb1ooQbY4oKIIsmjLBZNWesbOC0j/oLhvNh0nVWHE xyKb+XwkCWW9TCdxFcftj33+UOgiU1lAFqQ6R/SVtT+q1QfOj0/JKCVkeT9iTR+78RHZMc FsUQ9GPRgwNGhEU0JhrB0nv04odQvfL9uWINVbC9x+cG9JVPQUuhgdJAerCx64PSn16WAg Vb2PcvoTwyCz/Jb4NslI9OPfYpH6rmPoL05MbIGatA5dYbEqSkyJyaN3cEcmrA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BdCO+X3DDz9sv2KnfeZGJWy7WRmJro+j+/GrBftBzUc=; b=iUVceLvqyIeErOyGf7Tj3S7+G178L2Gme6TZ0nytLOwQuxyq8S5j6JHaiVnKYhb62pMKb+ FjmPhUc2IYseK2CA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 090/120] perf/x86: Remove custom CPUID(0xa) types Date: Thu, 28 May 2026 17:38:52 +0200 Message-ID: <20260528153923.403473-91-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All CPUID(0xa) sites have been transformed from direct CPUID queries to the CPUID parser APIs. Pure users of perf's custom CPUID(0xa) types have also been converted to the auto generated x86-cpuid-db data types. Remove the now-unused CPUID(0xa) types from . Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/perf_event.h | 38 ------------------------------- 1 file changed, 38 deletions(-) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 752cb319d5ea..02f804788daf 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -157,44 +157,6 @@ /* Steal the highest bit of pebs_data_cfg for SW usage */ #define PEBS_UPDATE_DS_SW BIT_ULL(63) =20 -/* - * Intel "Architectural Performance Monitoring" CPUID - * detection/enumeration details: - */ -union cpuid10_eax { - struct { - unsigned int version_id:8; - unsigned int num_counters:8; - unsigned int bit_width:8; - unsigned int mask_length:8; - } split; - unsigned int full; -}; - -union cpuid10_ebx { - struct { - unsigned int no_unhalted_core_cycles:1; - unsigned int no_instructions_retired:1; - unsigned int no_unhalted_reference_cycles:1; - unsigned int no_llc_reference:1; - unsigned int no_llc_misses:1; - unsigned int no_branch_instruction_retired:1; - unsigned int no_branch_misses_retired:1; - } split; - unsigned int full; -}; - -union cpuid10_edx { - struct { - unsigned int num_counters_fixed:5; - unsigned int bit_width_fixed:8; - unsigned int reserved1:2; - unsigned int anythread_deprecated:1; - unsigned int reserved2:16; - } split; - unsigned int full; -}; - /* * Intel "Architectural Performance Monitoring extension" CPUID * detection/enumeration details: --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6833147A0DA for ; Thu, 28 May 2026 15:44:50 +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=1779983098; cv=none; b=Eo16n6Picne51rXZmrI1y0NoztaTb2Ng/6RW9LaTpI7COlFz/g82xKRoNZqIrUKOa1tTsYsNUP6KePxT68ISRD78+oC9i+QumdKUHbapCZg43N+yA7d7Ob3S1TWAXt3IkAUYCFEriSgsB1vq4yroK6T5ly2cqQGsU2U3LzCFUP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983098; c=relaxed/simple; bh=ePXl5vv82gnhcqr/N8k4LBUE6iQTrlx9g2cyD4BSOXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m1+xZ5+xh9FULlkbcUSd4e2nPyMMdPpZVGUfg9D6voWLUz0lqoWfggUWp5yA+1wwqKxRbeXvo0RswV+bbDAzLItGTuNIPg1BdP7t0keCU53cM4KrHqqc9S5+nV0Bb8yO7mi0LlJ6cSi/vaGgFO5YMEPHupU+f1HwanYdmwokgBg= 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=czKl0Vpn; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wKzyyNgG; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="czKl0Vpn"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wKzyyNgG" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e25+zWiMK424bRvB3b2r/6PxBzokv8pdpLpq3y3ZxY4=; b=czKl0VpntEvIEwvp51100ztteRetyQCtEdByxGZDPNdK9v6jVEokh4XHCWEYPb8Aofy+AL NBn9bUWS5EpeuRBa2s8aWXxULWoEHGxkvC5WdPtm1gY0ZmWVxWiqXEgatSI3b37hs90OSQ 5xy3Kt3taSktk6hCa5QjQBCnWqFg5+Yvvhh2R4GHLM+JbNGpNRzeGMT3n9v9l6bfBJ9gF/ LwJX5V/wyPiBIhNSXwWknqgMU/aceiI1n0pBGDNYYNrpoln4iB8pgIYtyEI9Pu26dZbVap rQoS8UV9V5Jy/1xW4myokV6sfk2H8kqCCOhP1stl26Udlc/4vHpXj/cfSjJWKw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983088; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e25+zWiMK424bRvB3b2r/6PxBzokv8pdpLpq3y3ZxY4=; b=wKzyyNgGKss9mG9YZAtjF836cFO0c7HygfJa/v21bcYt3Z8mHKVNPy94VxysH4A15RZh5X Cqd2HMwRehu0yUDA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 091/120] perf/x86/lbr: Use parsed CPUID(0x1c) Date: Thu, 28 May 2026 17:38:53 +0200 Message-ID: <20260528153923.403473-92-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x1c) instead of a direct CPUID query and custom perf CPUID(0x1c) data types. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/intel/lbr.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index cae2e02fe6cc..7bc48f5e5e52 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -1587,19 +1587,16 @@ static bool is_arch_lbr_xsave_available(void) =20 void __init intel_pmu_arch_lbr_init(void) { + const struct leaf_0x1c_0 *l =3D cpuid_leaf(&boot_cpu_data, 0x1c); struct pmu *pmu =3D x86_get_pmu(smp_processor_id()); - union cpuid28_eax eax; - union cpuid28_ebx ebx; - union cpuid28_ecx ecx; - unsigned int unused_edx; bool arch_lbr_xsave; size_t size; u64 lbr_nr; =20 - /* Arch LBR Capabilities */ - cpuid(28, &eax.full, &ebx.full, &ecx.full, &unused_edx); + if (!l) + goto clear_arch_lbr; =20 - lbr_nr =3D fls(eax.split.lbr_depth_mask) * 8; + lbr_nr =3D fls(l->lbr_depth_mask) * 8; if (!lbr_nr) goto clear_arch_lbr; =20 @@ -1607,17 +1604,17 @@ void __init intel_pmu_arch_lbr_init(void) if (wrmsrq_safe(MSR_ARCH_LBR_DEPTH, lbr_nr)) goto clear_arch_lbr; =20 - x86_pmu.lbr_depth_mask =3D eax.split.lbr_depth_mask; - x86_pmu.lbr_deep_c_reset =3D eax.split.lbr_deep_c_reset; - x86_pmu.lbr_lip =3D eax.split.lbr_lip; - x86_pmu.lbr_cpl =3D ebx.split.lbr_cpl; - x86_pmu.lbr_filter =3D ebx.split.lbr_filter; - x86_pmu.lbr_call_stack =3D ebx.split.lbr_call_stack; - x86_pmu.lbr_mispred =3D ecx.split.lbr_mispred; - x86_pmu.lbr_timed_lbr =3D ecx.split.lbr_timed_lbr; - x86_pmu.lbr_br_type =3D ecx.split.lbr_br_type; - x86_pmu.lbr_counters =3D ecx.split.lbr_counters; - x86_pmu.lbr_nr =3D lbr_nr; + x86_pmu.lbr_depth_mask =3D l->lbr_depth_mask; + x86_pmu.lbr_deep_c_reset =3D l->lbr_deep_c_reset; + x86_pmu.lbr_lip =3D l->lbr_ip_is_lip; + x86_pmu.lbr_cpl =3D l->lbr_cpl; + x86_pmu.lbr_filter =3D l->lbr_branch_filter; + x86_pmu.lbr_call_stack =3D l->lbr_call_stack; + x86_pmu.lbr_mispred =3D l->lbr_mispredict; + x86_pmu.lbr_timed_lbr =3D l->lbr_timed_lbr; + x86_pmu.lbr_br_type =3D l->lbr_branch_type; + x86_pmu.lbr_counters =3D l->lbr_events_gpc_bmp; + x86_pmu.lbr_nr =3D lbr_nr; =20 if (!!x86_pmu.lbr_counters) x86_pmu.flags |=3D PMU_FL_BR_CNTR | PMU_FL_DYN_CONSTRAINT; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 74FA04028DC for ; Thu, 28 May 2026 15:44:53 +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=1779983099; cv=none; b=MZ/p5OYqqmHJ5WR5/4/cTkQWFEz8fWXajEHyj4IaterNQMBeHUNRxDF1f/TW7YCYw5dtwOE8qvi/EERGHXGymBEfymAB8nFEi9CZUU91nzFVtGX9EbS8aHnA2EWu+TDgHKyA5Pbbrb5EZjw+/BK5wXMXMT8EsYCC8Jf8yXlSsEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983099; c=relaxed/simple; bh=l/ciwg2vMBBaoVG9nus4f97XA4XXtMlzOMYW1wFuT7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J2SXxmx/Y1Kz07kxpJLHR8U2txuytMNMssnu+aw7ARm4AicMbzzkyNwXLEOFaaaf1hZjsdHXw2i9Dx6wKaQaPSNDKm+ebgOkVPvZee1X7Ndz/xdClTxrQubyTh+v9zaOBGiFDY01kLu9rhxYYuOq1IvQR+IFxqBMg86zg37Pg88= 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=xlKa2QK3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=P/aDjwPk; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xlKa2QK3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="P/aDjwPk" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aL0LzMpZRPBlhYur073q9t7Ua/vy+3rD6Ljc4SH0Mp0=; b=xlKa2QK3rYgA4TXKsX6G7xdbBfGKoyan2r7hUYuK2ObPn3dJCR3Awasm7HEnnEht7lGkD9 +8ZYwMzqnH5vGBCi9FG0L35YRMdHddiWap6/+a2hkNBIrkY+u/vm2lNUhVWvVdLT8+d57t 6j8jEo6y4Y4JpjD0WTfCKwUcZNQFzYKw8Hg6mbwvWtmLYuooS38i96a51zKl3kZb4zOr7Q rzSj/7GrG2J5I7YJgCC7rSvXXcmuswClMqxeaGN8EHIvOUpha6QsAEgS0ckQX7OUatG4Hi h+gsMGWLaRYx+hGoQW5TY4/EkX8vgetYVZ0nxVmIJAEJLvl+UfZpm/nKXWE3Xg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aL0LzMpZRPBlhYur073q9t7Ua/vy+3rD6Ljc4SH0Mp0=; b=P/aDjwPklSHwpQjUAtjzvRRuLEirdG2ualnsjOdBo78gs2Macql72DBYMkgoVl81PVYGG8 9KnDtpgPgrOxHxCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 092/120] perf/x86/lbr: Remove custom CPUID(0x1c) types Date: Thu, 28 May 2026 17:38:54 +0200 Message-ID: <20260528153923.403473-93-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All CPUID(0x1c) call sites have been converted from direct CPUID queries to the CPUID API and its x86-cpuid-db auto generated types. Remove the custom CPUID(0x1c) types from . Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/perf_event.h | 43 ------------------------------- 1 file changed, 43 deletions(-) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 02f804788daf..6270f4a26a59 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -197,49 +197,6 @@ union cpuid35_ebx { unsigned int full; }; =20 -/* - * Intel Architectural LBR CPUID detection/enumeration details: - */ -union cpuid28_eax { - struct { - /* Supported LBR depth values */ - unsigned int lbr_depth_mask:8; - unsigned int reserved:22; - /* Deep C-state Reset */ - unsigned int lbr_deep_c_reset:1; - /* IP values contain LIP */ - unsigned int lbr_lip:1; - } split; - unsigned int full; -}; - -union cpuid28_ebx { - struct { - /* CPL Filtering Supported */ - unsigned int lbr_cpl:1; - /* Branch Filtering Supported */ - unsigned int lbr_filter:1; - /* Call-stack Mode Supported */ - unsigned int lbr_call_stack:1; - } split; - unsigned int full; -}; - -union cpuid28_ecx { - struct { - /* Mispredict Bit Supported */ - unsigned int lbr_mispred:1; - /* Timed LBRs Supported */ - unsigned int lbr_timed_lbr:1; - /* Branch Type Field Supported */ - unsigned int lbr_br_type:1; - unsigned int reserved:13; - /* Branch counters (Event Logging) Supported */ - unsigned int lbr_counters:4; - } split; - unsigned int full; -}; - /* * AMD "Extended Performance Monitoring and Debug" CPUID * detection/enumeration details: --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 93A143F88BA for ; Thu, 28 May 2026 15:44:56 +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=1779983103; cv=none; b=TQYZaq4NQMyK1ZOkQqsEBhsZYbbcyBA1qgysabC0gJ2u9gL46RlUABSLhtgWfCHTprDWVioWlz/7bhD3o/yfeU9+4KASFIXpklysteiYc+Y39rsgWAGNh/n6LlvGEEzu3zQ7fc/vvy1kj4qcU8uqOheH6y+SeihgrvD3qeXRQ6I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983103; c=relaxed/simple; bh=FtQXGMWuayRy+bH81gjDzv0tv82WzJJKn4w1Ltqp8cA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VCMw2R218nnzu3DVe3nSDkO7oIKlrqQ3gO5rakRtC6AFRvXN1aVWHRZL7krVdMkWZOSXr4mdlnPSRQ/0O+oZ4vViFHUcanFiMtWzMmE8g5z0Ae085/ugo7vAWl/u1cr1ighdZ1LeKGsxyjbU1jFLkSGSu44PxyhwipLvdGVQMAU= 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=Z1w+fIs9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ep3BOmzc; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Z1w+fIs9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ep3BOmzc" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7pNKAnFAGPXZWg5tzGB+nUpY+CLlCRNx39ezJ3W05Lw=; b=Z1w+fIs9Fk/ws4eapDknklO05NuKVGjLhDTHNJNY0eczMDaB3FbBX+iAYPGyvUtt7WIn3s AgRdgciIznILJZAn3Mg6DLIzcx9PiqYt1E78fAyDa1Wk/aw6fq/NdsqNCnZ0vZ+HHpW3XM 9jbZIzeiwdO7Ogy7F1jribT+eamWJ3fdpmDfTmoHvNLRWafYBYbfXGpyAbVZzdGkYMXbO0 WEhwy70Jwp7n2VRHemB81hU28TR3f2Dd4foa9vAKlYEM5Sw21D3yZWA2zaRReThOga0YqZ y7f7EnIgTr4wbdYOrqfHneA0DwW/NfG/lHME1we//KohAF7d37PsMrNfGQ/gIA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983095; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7pNKAnFAGPXZWg5tzGB+nUpY+CLlCRNx39ezJ3W05Lw=; b=ep3BOmzcG4IqhqrWxtA6Gj+NEq+EC4fKBPMw4k1ApljCRvOisC4UgnLjz+HDMAw2R1EV4t /B5I+3q/RkmXoqCw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 093/120] x86/cpuid: Parse CPUID(0x23) Date: Thu, 28 May 2026 17:38:55 +0200 Message-ID: <20260528153923.403473-94-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse Intel PMU CPUID(0x23), and all its known subleaves. This allows converting their call sites to the CPUID API next. Note, for all subleaves, make sure that subleaf 0 declares their support beforehand. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 6 ++++++ arch/x86/kernel/cpu/cpuid_parser.c | 33 ++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 7 +++++++ 3 files changed, 46 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 81a84483297c..08c338909506 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -222,6 +222,12 @@ struct cpuid_leaves { CPUID_LEAF ( 0x15, 0 ); CPUID_LEAF ( 0x16, 0 ); CPUID_LEAF ( 0x1c, 0 ); + CPUID_LEAF ( 0x23, 0 ); + CPUID_LEAF ( 0x23, 1 ); + CPUID_LEAF ( 0x23, 2 ); + CPUID_LEAF ( 0x23, 3 ); + CPUID_LEAF ( 0x23, 4 ); + CPUID_LEAF ( 0x23, 5 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index 7ab4e01c6c33..452b5b317e4d 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -97,6 +97,39 @@ cpuid_read_0x2(const struct cpuid_parse_entry *e, const = struct cpuid_read_output output->info->nr_entries =3D 1; } =20 +static bool cpuid_0x23_has_subleaf(u32 subleaf) +{ + struct leaf_0x23_0 l; + + cpuid_read_subleaf(0x23, 0, &l); + + switch (subleaf) { + case 0: return l.subleaf_0; + case 1: return l.counters_subleaf; + case 2: return l.acr_subleaf; + case 3: return l.events_subleaf; + case 4: return l.pebs_caps_subleaf; + case 5: return l.pebs_subleaf; + default: return false; + } +} + +#define define_cpuid_0x23_subleaf_read_function(subl) \ +static void \ +cpuid_read_0x23_##subl(const struct cpuid_parse_entry *e, const struct cpu= id_read_output *output) \ +{ \ + if (!cpuid_0x23_has_subleaf(subl)) \ + return; \ + \ + cpuid_read_generic(e, output); \ +} + +define_cpuid_0x23_subleaf_read_function(1); +define_cpuid_0x23_subleaf_read_function(2); +define_cpuid_0x23_subleaf_read_function(3); +define_cpuid_0x23_subleaf_read_function(4); +define_cpuid_0x23_subleaf_read_function(5); + /* * Shared read function for Intel CPUID(0x4) and AMD CPUID(0x8000001d), as= both have * the same subleaf enumeration logic and register output format. diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index bd3c99cb985c..6767923f86d9 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -156,6 +156,12 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x15, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x16, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x1c, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x23, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x23, 1, 0x23_1 ), \ + CPUID_PARSE_ENTRY ( 0x23, 2, 0x23_2 ), \ + CPUID_PARSE_ENTRY ( 0x23, 3, 0x23_3 ), \ + CPUID_PARSE_ENTRY ( 0x23, 4, 0x23_4 ), \ + CPUID_PARSE_ENTRY ( 0x23, 5, 0x23_5 ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ @@ -212,6 +218,7 @@ struct cpuid_vendor_entry { CPUID_VENDOR_ENTRY(0x15, X86_VENDOR_INTEL, X86_VENDOR_CENTAUR, X86_VENDOR= _ZHAOXIN),\ CPUID_VENDOR_ENTRY(0x16, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x1c, X86_VENDOR_INTEL), \ + CPUID_VENDOR_ENTRY(0x23, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x8000001d, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860001, X86_VENDOR_TRANSMETA), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C396F47AF60 for ; Thu, 28 May 2026 15:44:59 +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=1779983107; cv=none; b=E0axGKOGzs2pJNkaiQFlzoSMTYtGpQUAldT8EbmVaNMobx9Wo0dSvp1puEWTj4S4rhQ398vmS5Yg6wRaFu2wtYOLmXgmdbmjbchigVAMjKmHycAhXtQuHyuFcDz9ib+Mk3uemzkJl/oVRmx+njs9VSuetpG3HQPh2iET6urOeu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983107; c=relaxed/simple; bh=PLwbz1v8EDRcQ8a3v8SRnErGjeGdEeiS/RYfP97t/KE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VJMMZ+HMasGqquW1g2RENUVMvzfDOCUJnN2oUlTcOmQrGzLppyKL3mNovK5neYaC4vfeVyr+u3TOhh2TQwA9s8SQQtpYCFBe2FCYk/3UdI8VFTYuqku0YpTx+z53H2rivHhc+fz3q3deUcY69nlnJ89djqNh/YjgUqIvw4BEX1I= 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=Z68lnBqk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=b0NLFhu+; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Z68lnBqk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="b0NLFhu+" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hDnA2M3jSSM0SmRpPh8nZgNIuIo7ocPnD9bEREQCtX8=; b=Z68lnBqkutE6yzLvqvP36fvkjLnrFw9OW1JE9UkSviogyEBdUbh78uru8s6jMerQZlCnNX xjah8h87L10BeBBAVnVPVTWcCd7GLT8C/uEUKyAOZmekRk5Wf8NS8wBLyc5k8SUIrRlG3x tmzI2dUQ32h0BfB0D3bpPjG0V85CSkssAahQlrO5kWtJdT0t/fgv2ReJBnJm214v7MCdG0 rhTKG8Y3C03tVJm7gGLxNgpiseQEX47g0C19oSwzB4jfYdA9cvLeQlv0Qeh/DTdMoprBAI vHkVOZY1tZnsfm6MoeO/4OksFEXFmbsC2OqextEP1QOtmXRVz7nzP7MBlR2uhw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hDnA2M3jSSM0SmRpPh8nZgNIuIo7ocPnD9bEREQCtX8=; b=b0NLFhu+4FfvpojHJkyVDa8U5hdHbTZOy7FJMrlOL0ui8U/LE+vX1+4nUZAwJzu7o+Knav JY9A/J7FCySewZCg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 094/120] perf/x86/intel: Use parsed per-CPU CPUID(0x23) Date: Thu, 28 May 2026 17:38:56 +0200 Message-ID: <20260528153923.403473-95-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel PMU capabilities, use parsed CPUID(0x23) instead of direct CPUID queries and custom perf CPUID(0x23) data types. Replace manual subleaves availability checks with checking whether the CPUID APIs return NULL. This is sufficient since the CPUID parser validates all the leaves and subleaves beforehand. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/intel/core.c | 62 +++++++++++++++++------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 53c614c61531..2effa7269c3c 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5926,51 +5926,49 @@ static inline void __intel_update_large_pebs_flags(= struct pmu *pmu) =20 #define counter_mask(_gp, _fixed) ((_gp) | ((u64)(_fixed) << INTEL_PMC_IDX= _FIXED)) =20 -static void update_pmu_cap(struct pmu *pmu) -{ - unsigned int eax, ebx, ecx, edx; - union cpuid35_eax eax_0; - union cpuid35_ebx ebx_0; +static void update_pmu_cap(struct pmu *pmu, int cpu) +{ + struct cpuinfo_x86 *cpuinfo =3D is_hybrid() ? &cpu_data(cpu) : &boot_cpu_= data; + const struct leaf_0x23_0 *sl0 =3D cpuid_subleaf(cpuinfo, 0x23, 0); + const struct leaf_0x23_1 *sl1 =3D cpuid_subleaf(cpuinfo, 0x23, 1); + const struct leaf_0x23_2 *sl2 =3D cpuid_subleaf(cpuinfo, 0x23, 2); + const struct leaf_0x23_4 *sl4 =3D cpuid_subleaf(cpuinfo, 0x23, 4); + const struct leaf_0x23_5 *sl5 =3D cpuid_subleaf(cpuinfo, 0x23, 5); + u64 pdists_mask =3D 0; u64 cntrs_mask =3D 0; u64 pebs_mask =3D 0; - u64 pdists_mask =3D 0; =20 - cpuid(ARCH_PERFMON_EXT_LEAF, &eax_0.full, &ebx_0.full, &ecx, &edx); + if (!sl0) + return; =20 - if (ebx_0.split.umask2) + if (sl0->unitmask2) hybrid(pmu, config_mask) |=3D ARCH_PERFMON_EVENTSEL_UMASK2; - if (ebx_0.split.eq) + if (sl0->eq) hybrid(pmu, config_mask) |=3D ARCH_PERFMON_EVENTSEL_EQ; - if (ebx_0.split.rdpmc_user_disable) + if (sl0->rdpmc_user_disable) hybrid(pmu, config_mask) |=3D ARCH_PERFMON_EVENTSEL_RDPMC_USER_DISABLE; =20 - if (eax_0.split.cntr_subleaf) { - cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF, - &eax, &ebx, &ecx, &edx); - hybrid(pmu, cntr_mask64) =3D eax; - hybrid(pmu, fixed_cntr_mask64) =3D ebx; - cntrs_mask =3D counter_mask(eax, ebx); + if (sl1) { + hybrid(pmu, cntr_mask64) =3D sl1->gp_counters; + hybrid(pmu, fixed_cntr_mask64) =3D sl1->fixed_counters; + cntrs_mask =3D counter_mask(sl1->gp_counters, sl1->fixed_counters); } =20 - if (eax_0.split.acr_subleaf) { - cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_ACR_LEAF, - &eax, &ebx, &ecx, &edx); + if (sl2) { /* The mask of the counters which can be reloaded */ - hybrid(pmu, acr_cntr_mask64) =3D counter_mask(eax, ebx); + hybrid(pmu, acr_cntr_mask64) =3D counter_mask(sl2->acr_gp_reload, sl2->a= cr_fixed_reload); /* The mask of the counters which can cause a reload of reloadable count= ers */ - hybrid(pmu, acr_cause_mask64) =3D counter_mask(ecx, edx); + hybrid(pmu, acr_cause_mask64) =3D counter_mask(sl2->acr_gp_trigger, sl2-= >acr_fixed_trigger); } =20 - /* Bits[5:4] should be set simultaneously if arch-PEBS is supported */ - if (eax_0.split.pebs_caps_subleaf && eax_0.split.pebs_cnts_subleaf) { - cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_PEBS_CAP_LEAF, - &eax, &ebx, &ecx, &edx); - hybrid(pmu, arch_pebs_cap).caps =3D (u64)ebx << 32; + /* Both subleaves should be available if arch-PEBS is supported */ + if (sl4 && sl5) { + const struct cpuid_regs *sl4_regs =3D (const struct cpuid_regs *)sl4; + + hybrid(pmu, arch_pebs_cap).caps =3D (u64)sl4_regs->ebx << 32; =20 - cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_PEBS_COUNTER_LEAF, - &eax, &ebx, &ecx, &edx); - pebs_mask =3D counter_mask(eax, ecx); - pdists_mask =3D counter_mask(ebx, edx); + pebs_mask =3D counter_mask(sl5->pebs_gp, sl5->pebs_fixed); + pdists_mask =3D counter_mask(sl5->pebs_pdist_gp, sl5->pebs_pdist_fixed); hybrid(pmu, arch_pebs_cap).counters =3D pebs_mask; hybrid(pmu, arch_pebs_cap).pdists =3D pdists_mask; =20 @@ -6073,7 +6071,7 @@ static bool init_hybrid_pmu(int cpu) goto end; =20 if (this_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT)) - update_pmu_cap(&pmu->pmu); + update_pmu_cap(&pmu->pmu, cpu); =20 intel_pmu_check_hybrid_pmus(pmu); =20 @@ -8488,7 +8486,7 @@ __init int intel_pmu_init(void) * when a new type is online. */ if (!is_hybrid() && boot_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT)) - update_pmu_cap(NULL); + update_pmu_cap(NULL, 0); =20 if (x86_pmu.arch_pebs) { static_call_update(intel_pmu_disable_event_ext, --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 E8C4C47B426 for ; Thu, 28 May 2026 15:45:02 +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=1779983109; cv=none; b=mCbzjpLur9L4l4JRlggI23iEsEK9ocLe7M5dE2kScMNp1g+incibdGAA3FqQRuEYjnrKyOq9yb9/u8a3WoQ6UBMAK2IW6psr+jLsp5K3nHylA8X0iUVBsrSXOE6pz740lJn3F1zrkLkbXCE6F8lUHgD4ObsZpq5CX/wTFfHhAyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983109; c=relaxed/simple; bh=KK9kC9xxUwIFWD7ws+buwaJbXM0b/ccm+VzfjYi+sfA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=soSH5LhLh8ZWK4ueg6GUxHleOHunoPkrt8AvWakjquBXNuGmZxv3NWPiXqnXMhAsV7WS3968Y579TChDeQf0qhKNhjIq63fiknWLYSnwKM6dVFWUfFk2CY/ZZoKgVKlyqYY7wJCV8f28D3E5TxZ85LjAYl5XfMTi2eLDUr6gjrc= 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=tfl2UNVF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=VnBJL7IG; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tfl2UNVF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VnBJL7IG" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XwtSzNQ4yoJqt77kf9CQcQ+HEsOJ17/pX7Pa+LfpgjQ=; b=tfl2UNVFa0lRAp5ILvL+hI6u/kGv1DV9i907hTiAUf8Xmg8etlJBd8fNSE0BXvnp10FA/S ZsJwxDK1lLLxPV/6TUVeRrnVoZU6u2fF3YvmFVoivJkRn81MboTtYX3DKEJI3U5egWh1Sd nTR2iZcMKZLF11VMT/eAf7L6VJw8x2mlRvLg6b7hEk7tSXsy0JQKYsiwChwYR3vu9ObvlK OrxR3iw6RDaBTxSZ5+CXnv+vZjiRhHYhojyyzuw+hf+HAC8m/CEFvOjRK4Lr0LNIpdZiqy gspNLlS1+fy4LqGaszBD9IXFt3thRFPGN2D/Xoi0dNWWUJKeMGJAZihZJZEcbg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XwtSzNQ4yoJqt77kf9CQcQ+HEsOJ17/pX7Pa+LfpgjQ=; b=VnBJL7IGgvVPlEgS5Tr8PjEZbP+avqjjC/mP2qBn0jC99T8vDg0An3j/qhVaXqvqvuuh+4 LQ2CJg1enyfpfyDg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 095/120] perf/x86/intel: Remove custom CPUID(0x23) types Date: Thu, 28 May 2026 17:38:57 +0200 Message-ID: <20260528153923.403473-96-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All CPUID(0x23) call sites have been converted to the CPUID API and its auto generated x86-cpuid-db data types. Remove the custom CPUID(0x23) types from perf. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/perf_event.h | 38 +------------------------------ 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index 6270f4a26a59..ff844cec22ab 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -157,46 +157,10 @@ /* Steal the highest bit of pebs_data_cfg for SW usage */ #define PEBS_UPDATE_DS_SW BIT_ULL(63) =20 -/* - * Intel "Architectural Performance Monitoring extension" CPUID - * detection/enumeration details: - */ -#define ARCH_PERFMON_EXT_LEAF 0x00000023 -#define ARCH_PERFMON_NUM_COUNTER_LEAF 0x1 -#define ARCH_PERFMON_ACR_LEAF 0x2 +// _CPUID_TODO_: Remove subleaf 4 and 5 after defining them #define ARCH_PERFMON_PEBS_CAP_LEAF 0x4 #define ARCH_PERFMON_PEBS_COUNTER_LEAF 0x5 =20 -union cpuid35_eax { - struct { - unsigned int leaf0:1; - /* Counters Sub-Leaf */ - unsigned int cntr_subleaf:1; - /* Auto Counter Reload Sub-Leaf */ - unsigned int acr_subleaf:1; - /* Events Sub-Leaf */ - unsigned int events_subleaf:1; - /* arch-PEBS Sub-Leaves */ - unsigned int pebs_caps_subleaf:1; - unsigned int pebs_cnts_subleaf:1; - unsigned int reserved:26; - } split; - unsigned int full; -}; - -union cpuid35_ebx { - struct { - /* UnitMask2 Supported */ - unsigned int umask2:1; - /* EQ-bit Supported */ - unsigned int eq:1; - /* rdpmc user disable Supported */ - unsigned int rdpmc_user_disable:1; - unsigned int reserved:29; - } split; - unsigned int full; -}; - /* * AMD "Extended Performance Monitoring and Debug" CPUID * detection/enumeration details: --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 193C847CC94 for ; Thu, 28 May 2026 15:45:06 +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=1779983115; cv=none; b=tRDLZh1ftjQk2Z0yMKMW2SZ3FWe313O2P5Jl2yVPXjBbODmW4Cd33o3f1u9R43sgRKXalWxVJ4p4GhzkV/mwxOMmDYvdeECYK7pPOuCaVmRopabPMoNWDSEqsxqm1ypupVwocCSyroQIdc8fsxhcv/PTBv3LkgFfoK5781+OWkg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983115; c=relaxed/simple; bh=AWsNKOvI9804PLzQZcZ51kJawuW7uwDaU9sjxjjRRU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NqwVM6RVIuT1urcK7XQ8LxGz1KyhU1WMYtPLJ58ZSefToBgCevVX6LNITk+Ev4uyTNUsvmGUeIVqTspw/SU32PW4QOIgyfQwq4zx1NGCfoUGk0wjNavAT3r2ZmgmiU5fkhPtb3cKNst6unRaU21O/HogPwXgHwPypijd0xhByXc= 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=g7Z6nIho; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nojQCU7w; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="g7Z6nIho"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nojQCU7w" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qelKDVVuZAtL+G162mjH24+v52Ue4liAmxcTECpMT/g=; b=g7Z6nIhovybaqG5NJG6//CUuYR4lLrpUY5ulC4Su2J0Pa5vUIkXjXKbVc1HmCgD0aHjxHv BVjks7xXWIuPvphXgrno4yAiSaS0CR0LoutvpuCYIe/Ou+B1h/O+mEr+i57dATItGWOHmi c1qcjFAyva+ME5nEFRl3fKuK40rGyKoL7ph1NmNfHwn9lTUEoIH1nWpxmuavdeoQaC1LNx YF6SYejqnt53OOlMJDbTqLdutCDbAFHULTy7e9XaTso7ioASoAUaYHjo5yTMGWa3L245o9 QfL/V6fA4e19nfid0wRBWLrEspBgbRat60ATwmqaKMuN4s0kFfey4l8OVOmbYQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qelKDVVuZAtL+G162mjH24+v52Ue4liAmxcTECpMT/g=; b=nojQCU7wAcVHaPhrHI7gZNPEeRtkfgnFPk7+KFgxEjPfQPPAJ539d9MsyCwX0xe2LdEwPk HUX6694unUkQu/CQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 096/120] x86/cpuid: Parse CPUID(0x80000022) Date: Thu, 28 May 2026 17:38:58 +0200 Message-ID: <20260528153923.403473-97-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x80000022). Add AMD and Hygon vendor tags as it is only supported on these CPUs. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 1 + arch/x86/kernel/cpu/cpuid_parser.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 08c338909506..a49b3df2bdf8 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -236,6 +236,7 @@ struct cpuid_leaves { CPUID_LEAF ( 0x80000006, 0 ); CPUID_LEAF ( 0x80000008, 0 ); CPUID_LEAF_N ( 0x8000001d, 8 ); + CPUID_LEAF ( 0x80000022, 0 ); CPUID_LEAF ( 0x80860000, 0 ); CPUID_LEAF ( 0x80860001, 0 ); CPUID_LEAF ( 0x80860002, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 6767923f86d9..2de27a86861d 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -170,6 +170,7 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x80000006, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000008, 0, generic ), \ CPUID_PARSE_ENTRY_N ( 0x8000001d, deterministic_cache ), \ + CPUID_PARSE_ENTRY ( 0x80000022, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80860000, 0, 0x80860000 ), \ CPUID_PARSE_ENTRY ( 0x80860001, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80860002, 0, generic ), \ @@ -220,6 +221,7 @@ struct cpuid_vendor_entry { CPUID_VENDOR_ENTRY(0x1c, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x23, X86_VENDOR_INTEL), \ CPUID_VENDOR_ENTRY(0x8000001d, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ + CPUID_VENDOR_ENTRY(0x80000022, X86_VENDOR_AMD, X86_VENDOR_HYGON), \ CPUID_VENDOR_ENTRY(0x80860000, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860001, X86_VENDOR_TRANSMETA), \ CPUID_VENDOR_ENTRY(0x80860002, X86_VENDOR_TRANSMETA), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 393DD47887E for ; Thu, 28 May 2026 15:45:09 +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=1779983117; cv=none; b=XJIbchPCkDhKBuWBHGex2m61nkgurOW3QotFEHVWmcdWsdw2dCJ7SDntvAqQrHGVGkdd3c2N7dPt/4vmkoiblbksi17n/OCkQSCZil4Od+kKQpJ6s5aNJUWNNOUO0V4a/r+jPbZBmcvwB8e+ZSXo9Ybbpw9G0sxmE0sYN+TG+Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983117; c=relaxed/simple; bh=rNb/T4Zus7JiWIXVpMiWHgHM40BoYPMiYqxWRz6Z7ko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fVdRRXb1NzI4HAbPBWM6V/qHKOXvMTko94jRYKA2n8/lL9I9rEx04yQEa6ec3RSt1Pn0ZkfCQuTtLK85ePopD/R+ehzWJoUga3MyFFEOAsHdBfrfCM6AeDe6KZXajpC6CCqO2eN5UWWbsasvTE9FADxmg4OamAXmm5hy2AWnmlo= 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=zNOTUJUe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2z7fGsDr; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zNOTUJUe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2z7fGsDr" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CC3FPCkBych/Q9MupCJVqCJWZ9FNhKO3UOw+uDEYWCc=; b=zNOTUJUeW4HWVSKIiPcq4ZP2PtKPD1bg4M+3l3TWAzL9qWxd9j3+Y37P9Bn5gVuqbSUYlv vagNC2E7odwnSTeoehJTjrRGdwXhCWCzAh12YS6GFhDCWuiObaJTPgWk65f71a9hNjzqhR V1EiVj+cUtcBpEAx86iSIh6rdaUWRDXaOPdtZQDbhTQGxxjCfkzsYuGgA/4tPm1ZYL+aF3 V5zDORMu4Ohh/DrmFV2VbEtHbXgIPuErOxT8w7wzX8LZhqwUFzITP/PUfCX9LQZOclFSQm 8PpkLoOlc/OBpoIn326yWCMo7929B1rMK49ULlxnvxTP5qsjaLi4NzbdUNM0ZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CC3FPCkBych/Q9MupCJVqCJWZ9FNhKO3UOw+uDEYWCc=; b=2z7fGsDrgbkeuAoEhqqux/A8H0l5VuYvCwpQhNszuOE3hAq4CANxyTvTLupkFS9vG0hEtB uCjVFShFe9sWMoBQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 097/120] perf/x86/amd/lbr: Use parsed CPUID(0x80000022) Date: Thu, 28 May 2026 17:38:59 +0200 Message-ID: <20260528153923.403473-98-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD LBR, use parsed CPUID(0x80000022) instead of a direct CPUID query and custom perf data types. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/amd/lbr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/x86/events/amd/lbr.c b/arch/x86/events/amd/lbr.c index 5b437dc8e4ce..e5a16266545f 100644 --- a/arch/x86/events/amd/lbr.c +++ b/arch/x86/events/amd/lbr.c @@ -423,14 +423,13 @@ void amd_pmu_lbr_disable_all(void) =20 __init int amd_pmu_lbr_init(void) { - union cpuid_0x80000022_ebx ebx; + const struct leaf_0x80000022_0 *l =3D cpuid_leaf(&boot_cpu_data, 0x800000= 22); =20 - if (x86_pmu.version < 2 || !boot_cpu_has(X86_FEATURE_AMD_LBR_V2)) + if (!l || x86_pmu.version < 2 || !boot_cpu_has(X86_FEATURE_AMD_LBR_V2)) return -EOPNOTSUPP; =20 /* Set number of entries */ - ebx.full =3D cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES); - x86_pmu.lbr_nr =3D ebx.split.lbr_v2_stack_sz; + x86_pmu.lbr_nr =3D l->lbr_v2_stack_size; =20 pr_cont("%d-deep LBR, ", x86_pmu.lbr_nr); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 69E9F47D945 for ; Thu, 28 May 2026 15:45:12 +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=1779983120; cv=none; b=bBPvhNcxh6+8XaJAGwQjaaAIKkTFOORdl2+rTTCsvxO8/qlzjDvuK8xueLIDA92+h8RWjRr+YKq6iy8KQbqpvvE2vGkzLlR5js1Q8wdwFTHVuEFHjiKzMBqf6oE1ooqRXRmNxTRm6uKs3lNwErxfe+95PW4bCVVnRqBRrX/I6Us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983120; c=relaxed/simple; bh=VhGrs3bP7IQqFV96JRyFv/OuuYovutuzXux64dV8A98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GDpm9lD7WEq30guZZbJrJ8rNpG9AXQMKraYlVr7O//3pxllgFxRzOOp4fgZ+UGXjU5ngGhLnRFkyWhqb6d3LguVmiQefPLdH/B17EaRznih0XuimDfH7UT5wFrljhZDOoNUEa5sCbxwl8kcF+G33HIQTbX/K8vRlkJjlC6EMrMA= 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=RdGoqpyv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jIrc3RO7; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RdGoqpyv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jIrc3RO7" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zCTfxpXdaW9qpQOGTE5yg0Y1hc+Y+zTSRa5GepkIlN8=; b=RdGoqpyvXBb8lc+VKjWD6pNY5kaU9tOY93+ozgTB9tXnVnengrg2W2in6pKGu7XOdyhw3d y5KFJw8rTKnf0I/TPQMkGl7EWLGNkHwltMUDs4Ps0wuKFPMBfS9gOpuyXv/5wNNerLzklS CeXopZuT8C5cMrWad1xfvc4XcMX97a6WC0kyM3VZ2ix1pteKcbaTI9G+6udGxBwEyR6QGi iLe0n4HpveL/3SNf5J+P1iye6J74gIxnXEki6QjlPz3olV61eKSAaaH3JVCtgQE0DN3Fi5 aBQs5047LniT92aEeclJziAPs5s338AAoOmM0amW0AzAoejIaMeAzpKTdWAJ1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zCTfxpXdaW9qpQOGTE5yg0Y1hc+Y+zTSRa5GepkIlN8=; b=jIrc3RO7YOJiWMoDgaK3C79GMkL2iIIgIGcHbEMxS5TCzWkVYiM63dPgJk3/IJsuxaO7ua AsOLnNzc8th+r2Ag== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 098/120] perf/x86/amd: Use parsed CPUID(0x80000022) Date: Thu, 28 May 2026 17:39:00 +0200 Message-ID: <20260528153923.403473-99-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For AMD perf, use parsed CPUID(0x80000022) instead of direct CPUID queries and custom perf data types. For the uncore CPU hotplug callbacks, ensure that the correct per-CPU CPUID table is queried. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/amd/core.c | 8 +++----- arch/x86/events/amd/uncore.c | 18 +++++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index d66a357f219d..b070d0be36c4 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -1410,7 +1410,7 @@ static const struct attribute_group *amd_attr_update[= ] =3D { =20 static int __init amd_core_pmu_init(void) { - union cpuid_0x80000022_ebx ebx; + const struct leaf_0x80000022_0 *leaf =3D cpuid_leaf(&boot_cpu_data, 0x800= 00022); u64 even_ctr_mask =3D 0ULL; int i; =20 @@ -1430,14 +1430,12 @@ static int __init amd_core_pmu_init(void) x86_pmu.cntr_mask64 =3D GENMASK_ULL(AMD64_NUM_COUNTERS_CORE - 1, 0); =20 /* Check for Performance Monitoring v2 support */ - if (boot_cpu_has(X86_FEATURE_PERFMON_V2)) { - ebx.full =3D cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES); - + if (leaf && boot_cpu_has(X86_FEATURE_PERFMON_V2)) { /* Update PMU version for later usage */ x86_pmu.version =3D 2; =20 /* Find the number of available Core PMCs */ - x86_pmu.cntr_mask64 =3D GENMASK_ULL(ebx.split.num_core_pmc - 1, 0); + x86_pmu.cntr_mask64 =3D GENMASK_ULL(leaf->n_pmc_core - 1, 0); =20 amd_pmu_global_cntr_mask =3D x86_pmu.cntr_mask64; =20 diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 05cff39968ec..6a5d8f8cfbc0 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -692,7 +692,7 @@ static int amd_uncore_df_add(struct perf_event *event, = int flags) static void amd_uncore_df_ctx_scan(struct amd_uncore *uncore, unsigned int cpu) { - union cpuid_0x80000022_ebx ebx; + const struct leaf_0x80000022_0 *leaf =3D cpuid_leaf(&cpu_data(cpu), 0x800= 00022); union amd_uncore_info info; =20 if (!boot_cpu_has(X86_FEATURE_PERFCTR_NB)) @@ -703,10 +703,8 @@ void amd_uncore_df_ctx_scan(struct amd_uncore *uncore,= unsigned int cpu) info.split.gid =3D 0; info.split.cid =3D topology_logical_package_id(cpu); =20 - if (pmu_version >=3D 2) { - ebx.full =3D cpuid_ebx(EXT_PERFMON_DEBUG_FEATURES); - info.split.num_pmcs =3D ebx.split.num_df_pmc; - } + if (leaf && pmu_version >=3D 2) + info.split.num_pmcs =3D leaf->n_pmc_northbridge; =20 *per_cpu_ptr(uncore->info, cpu) =3D info; } @@ -990,16 +988,14 @@ static void amd_uncore_umc_read(struct perf_event *ev= ent) static void amd_uncore_umc_ctx_scan(struct amd_uncore *uncore, unsigned int cpu) { - union cpuid_0x80000022_ebx ebx; + const struct leaf_0x80000022_0 *leaf =3D cpuid_leaf(&cpu_data(cpu), 0x800= 00022); union amd_uncore_info info; - unsigned int eax, ecx, edx; =20 - if (pmu_version < 2) + if (!leaf || pmu_version < 2) return; =20 - cpuid(EXT_PERFMON_DEBUG_FEATURES, &eax, &ebx.full, &ecx, &edx); - info.split.aux_data =3D ecx; /* stash active mask */ - info.split.num_pmcs =3D ebx.split.num_umc_pmc; + info.split.aux_data =3D leaf->active_umc_bitmask; + info.split.num_pmcs =3D leaf->n_pmc_umc; info.split.gid =3D topology_logical_package_id(cpu); info.split.cid =3D topology_logical_package_id(cpu); *per_cpu_ptr(uncore->info, cpu) =3D info; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A347847D957 for ; Thu, 28 May 2026 15:45:15 +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=1779983121; cv=none; b=or5toQUiBOuYSowK5UGjfzHx2ei2iJesIGhzEcU/Rpdy3ZfVPCpaxOHeQ42qwbY5nMmg07B0nOCpigjM54xigqQDhosw3Zd4aEHkTK8z6xMxwWljOiyDHgzdDYh1T8ywDZMeE+oTQO9pJHDgM0MMeebRmrz6vtBjUTC71rG8lDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983121; c=relaxed/simple; bh=NNMPX8ZLNHD4/uhiUcRulAJd/QG2w1JQm6FskXl2GCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TPYelpd2Op18HwaXGaWp+CgmqhD8QW3TnEsPoglCoG1uRHUervFElv8loly/Ub8jaGmKIlD8N4ISXtDPnvif2BH80/WFQS9sZGMgh7mp9r24IKUuMI5fihNX7BxxCte/Lv0PHJi2Cnonhx8R/u3yLxekhaK26SanNQ+WYFO/NoY= 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=osbrFHps; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/D7uHDhc; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="osbrFHps"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/D7uHDhc" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oV8JuRV/XrK5lokYUmrPNY++3JPySR4ABGDAdCwCodw=; b=osbrFHpsmy5K4WL6Hh1BzArVCaq2QHgcHV1jmNLWqrPKPKEc8P3jdNIfHCKjCDcl8rSI79 ItxORDhZa+I9LGaCTVqsEL9DENwMYKgjlvNFoy38jKc9ZeQnjbqm2zmwak60EfJnadjNwO hl0Etb1/AlFsYxw+Da5/bjpF9fFr5g4/B3ML1Rj9c85SuFdo6lysa5kT3eCftVSwJ/Agnd fPVayfnMMmIeloGy7WFnlZ6DpoLnGNYjck9JkTlz01FJvm35kSQNv021Z+f+mhLTR6BViY lPsL4I/AuLtDyNNm2/WtdL7JDUrsVZvrO7qeALmjVh13laxiF9syaATTpo6Qzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oV8JuRV/XrK5lokYUmrPNY++3JPySR4ABGDAdCwCodw=; b=/D7uHDhc3OwCYUk0P5rdxQ3O8qvW/xXojAlJfVam0SFByrvJ7M1seaEnAYLJJHeGivsuV0 jcN9uG0LoYlvfxAQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 099/120] KVM: x86: Use standard CPUID(0x80000022) types Date: Thu, 28 May 2026 17:39:01 +0200 Message-ID: <20260528153923.403473-100-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use standard CPUID(0x80000022) types from x86-cpuid-db instead of relying on custom perf types. The latter are in process of getting removed from the kernel. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/cpuid.c | 7 ++++--- arch/x86/kvm/svm/pmu.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 706903ad6628..040e15ff87c5 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1871,7 +1871,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_ar= ray *array, u32 function) break; /* AMD Extended Performance Monitoring and Debug */ case 0x80000022: { - union cpuid_0x80000022_ebx ebx =3D { }; + struct leaf_0x80000022_0 leaf =3D { }; + struct cpuid_regs *regs =3D (struct cpuid_regs *)&leaf; =20 entry->ecx =3D entry->edx =3D 0; if (!enable_pmu || !kvm_cpu_cap_has(X86_FEATURE_PERFMON_V2)) { @@ -1881,8 +1882,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_ar= ray *array, u32 function) =20 cpuid_entry_override(entry, CPUID_8000_0022_EAX); =20 - ebx.split.num_core_pmc =3D kvm_pmu_cap.num_counters_gp; - entry->ebx =3D ebx.full; + leaf.n_pmc_core =3D kvm_pmu_cap.num_counters_gp; + entry->ebx =3D regs->ebx; break; } /*Add support for Centaur's CPUID instruction*/ diff --git a/arch/x86/kvm/svm/pmu.c b/arch/x86/kvm/svm/pmu.c index 7aa298eeb072..7c89b330fb73 100644 --- a/arch/x86/kvm/svm/pmu.c +++ b/arch/x86/kvm/svm/pmu.c @@ -179,7 +179,8 @@ static int amd_pmu_set_msr(struct kvm_vcpu *vcpu, struc= t msr_data *msr_info) static void amd_pmu_refresh(struct kvm_vcpu *vcpu) { struct kvm_pmu *pmu =3D vcpu_to_pmu(vcpu); - union cpuid_0x80000022_ebx ebx; + struct leaf_0x80000022_0 leaf =3D { }; + struct cpuid_regs *regs =3D (struct cpuid_regs *)&leaf; =20 pmu->version =3D 1; if (guest_cpu_cap_has(vcpu, X86_FEATURE_PERFMON_V2)) { @@ -190,8 +191,8 @@ static void amd_pmu_refresh(struct kvm_vcpu *vcpu) */ BUILD_BUG_ON(x86_feature_cpuid(X86_FEATURE_PERFMON_V2).function !=3D 0x8= 0000022 || x86_feature_cpuid(X86_FEATURE_PERFMON_V2).index); - ebx.full =3D kvm_find_cpuid_entry_index(vcpu, 0x80000022, 0)->ebx; - pmu->nr_arch_gp_counters =3D ebx.split.num_core_pmc; + regs->ebx =3D kvm_find_cpuid_entry_index(vcpu, 0x80000022, 0)->ebx; + pmu->nr_arch_gp_counters =3D leaf.n_pmc_core; } else if (guest_cpu_cap_has(vcpu, X86_FEATURE_PERFCTR_CORE)) { pmu->nr_arch_gp_counters =3D AMD64_NUM_COUNTERS_CORE; } else { --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C2EC147D93B for ; Thu, 28 May 2026 15:45:18 +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=1779983124; cv=none; b=A4SrexisBXPcHBcmfVm/joHNsE2/InQP8heD3KXLaZJZNwhYbyyC/65Eb3ch8uXHbkkwH9WRBgdUOiNJea7yVa0BizU12hVNIfMq9DJP+VoXHU4bWiVDaj6hIzfoRRTOadLdz4l18tO938Fo7w8OwxcwS5Zfyc8Jau72hl3puX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983124; c=relaxed/simple; bh=9te8/wZu4c7n99hnkC0stjRuHzkibHN44Uebt4LZvkU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=euEMn+zdFZUAUTDkQqM3Z7DL66Nj+Jw0n7XM7NM0rxPbinfVIriBe9zmK6W2dVyYuFxVosSzLYsFfrZhjzABapFyWCDXTZfXJqx0acm9Wx1ePVOQlArmlF9AFyfpaXeXQhnRlRr6DlQbZ7NMJt3a7qwcPl502qHw7O7daz4Lf70= 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=1s4+jVH2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Kcv9Y5sg; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1s4+jVH2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Kcv9Y5sg" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gkODCsKD2v6DKO+d9ptCe0Xo2luXxqr8GFYoUCpPhcE=; b=1s4+jVH24e+dRxU85xkkdKvk4gsM64joZUg7D2F1cHdzuPtIXZWj6Ul5AJT9WFljIcz0s+ Dk0eP32+VsECEhOZ5c2lG0lmme0W0zEKpertzqddk3oMWeyDlWUd0vNc5Jr4J/mXv/kFpg gKa35DUoj6jRRWd188kN9UgFvStrut81bR7Na4fmPKhlyQjkaoOtBk11/1c+MVPyq4HTE7 CGaGUCO7JpnPeLwVfkZk6ZIsWlqRzFW/4HWFx+hvvSVYgagMqAaD70bvXn+TFvotMpXxIi pwwTcd+Jq+4W0XLVR+ZzRfu3tW9spN2DeBw6+6K+ladPiVE8Z1TIr/bEGs5/Sw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gkODCsKD2v6DKO+d9ptCe0Xo2luXxqr8GFYoUCpPhcE=; b=Kcv9Y5sguGt260sVRor2aaI+jrZ7vutJTs6Bo8QcqfwXKp+62uyFeiWVekITMrA0Z3UpuN eNNfSBNgVrui39CA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 100/120] perf/x86: Remove custom CPUID(0x80000022) types Date: Thu, 28 May 2026 17:39:02 +0200 Message-ID: <20260528153923.403473-101-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All CPUID(0x80000022) call sites have been converted to the CPUID API and its auto generated x86-cpuid-db data types. Remove the custom CPUID(0x80000022) types from perf. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/perf_event.h | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_= event.h index ff844cec22ab..61da03dfb642 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -161,24 +161,6 @@ #define ARCH_PERFMON_PEBS_CAP_LEAF 0x4 #define ARCH_PERFMON_PEBS_COUNTER_LEAF 0x5 =20 -/* - * AMD "Extended Performance Monitoring and Debug" CPUID - * detection/enumeration details: - */ -union cpuid_0x80000022_ebx { - struct { - /* Number of Core Performance Counters */ - unsigned int num_core_pmc:4; - /* Number of available LBR Stack Entries */ - unsigned int lbr_v2_stack_sz:6; - /* Number of Data Fabric Counters */ - unsigned int num_df_pmc:6; - /* Number of Unified Memory Controller Counters */ - unsigned int num_umc_pmc:6; - } split; - unsigned int full; -}; - struct x86_pmu_capability { int version; int num_counters_gp; @@ -498,11 +480,6 @@ struct arch_pebs_cntr_header { u32 reserved; }; =20 -/* - * AMD Extended Performance Monitoring and Debug cpuid feature detection - */ -#define EXT_PERFMON_DEBUG_FEATURES 0x80000022 - /* * IBS cpuid feature detection */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 E573547DD6C for ; Thu, 28 May 2026 15:45:21 +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=1779983125; cv=none; b=jFdJOfbDHcIAY8WRF0NlN8iBdt3Pr8lb93xr9Ob6buapzqJabxUtxu5pmX8YsLcNK3fRGeTRTluK/H8PShJhcge8S1290m1V80sT4aXFO+vJm8oHVO/W/6koiF7uNSvmFeIIq6VVjYXDr+TSlmpu7tTEmIsdog7JrvCgF4+5YtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983125; c=relaxed/simple; bh=EIflR/OndVkpsRYn0nON167x8TX21su2tmH91K2IdEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XkvADqrN6MPE2BJKsfVP2bam9Sy4s6FSXIYcSf3AXuUqR5C3faX9HjMZeFHCULBHZpK6rSRw2t0gn3RQ624VzMiaAu67hE1phgoGSHxIMbVDzS8C9B1ryAowftgtafBlsqWI09DOhaMzUAM9CxZGsPAD/feg5Kn/4A2/vZ8o+R0= 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=t0rq+ucZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Tkc9sMMU; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="t0rq+ucZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Tkc9sMMU" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2SiZ39qOQKRlJAtxJKPYuPxnFDXfsI3Arxg15wPbFOU=; b=t0rq+ucZiss351YFzyKNg5lMMqY3QHdAlvu377F7ot3PixEzhvICE+Q35RqeNaXSRSo32h 70JZZ1MO6hF0DbOYsT/g5HwKlLRFYfjtGAOfkbP9W16ZWxf8geGPk9lBnapYvQJNf8ltG1 icjy07Sxc4KrBqpIZTs50a3dPTh49PZitLIwoCOl7MdErZo3a+58cMpw/GlHLo7rOBTXTJ JqujbeeIc3RBXN4MX87FmbMeboN8tZQrZsssxSxrE7Z6Yt2/4V3GHu8kWMCx4Wrf3B8Z5z XiFR109q59ONtVWkzaEWTG5rxNF8D/aqbIbOsJKqS46ptd7IVuzYl88ZKbLj6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2SiZ39qOQKRlJAtxJKPYuPxnFDXfsI3Arxg15wPbFOU=; b=Tkc9sMMU1L2mLdy2F6qntZMrazpZRpKljLD09wwX6k1B/chEW4RkLLL970Alg+h2Z+vTot XW6MjYAjUStlhqAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 101/120] x86/cpuid: Parse CPUID(0x80000007) Date: Thu, 28 May 2026 17:39:03 +0200 Message-ID: <20260528153923.403473-102-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse CPUID(0x80000007). This allows the cpuinfo_x86::x86_power call sites to be converted to the CPUID APIs next. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 1 + arch/x86/kernel/cpu/cpuid_parser.h | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index a49b3df2bdf8..7671f8d24014 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -234,6 +234,7 @@ struct cpuid_leaves { CPUID_LEAF ( 0x80000004, 0 ); CPUID_LEAF ( 0x80000005, 0 ); CPUID_LEAF ( 0x80000006, 0 ); + CPUID_LEAF ( 0x80000007, 0 ); CPUID_LEAF ( 0x80000008, 0 ); CPUID_LEAF_N ( 0x8000001d, 8 ); CPUID_LEAF ( 0x80000022, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 2de27a86861d..799714300bfb 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -168,6 +168,7 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000005, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000006, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000007, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000008, 0, generic ), \ CPUID_PARSE_ENTRY_N ( 0x8000001d, deterministic_cache ), \ CPUID_PARSE_ENTRY ( 0x80000022, 0, generic ), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 1C080403142 for ; Thu, 28 May 2026 15:45:25 +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=1779983130; cv=none; b=ckIgnIza0jKzSGJViAMSxGjJJRru5YizYAA8grcayGVmfw2aGsEpbvbXks78DZVCU14hwp52X9QcNRngsv9akvtJruT3Fz0VV12SfPsorBm0TKgSN1Lonyl75qLzNRbNEfuYyvMtQNCLhJ1dOxzrQwolSmOhuLjW1ezAbtiT9xE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983130; c=relaxed/simple; bh=BHWsYoAm4KFcpsaQEBxWbKAXPBaLIGGTiI+pbY1P3bY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eoj4fWBwjjkDXME5jLi42i+4Fk3GrEAnN1p+1ZwWE3ZYlfSrUA0/Yhp3saiVCFEXQRGirOdigtMIM5fRU7KhqlvLH+b1X/I6mrID1HFt6KzPlMtaHZYfoNa8SmV0jGBq3hNYk6sdMrXREqF+n+ZzOC9fA6JHf7Qq4jj7qwK/HMQ= 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=Ui7PlsNV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=X23cuzdH; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ui7PlsNV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X23cuzdH" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wRcDGGOVZ1LZ25yuMoSMO7ckXFHBDPeZI42oxlLlIKU=; b=Ui7PlsNV56drEEmh+07ctPKSZlBfJX9OK2R04ig2NHOtpUpNXbhljtCPDsK4Tm3NhS/Xrh 8kqAbt4T/XD116R+k3JpjGYw/PLQpm23O7T7DIxJvloIYUaeT8sfXtKTik/w9vIa/OM7gg mW2dAw6RET2qJNQadwJfgnMIhKG70h7PIuikpkRrDU8Ep26sSgiUJVMo4Ipdj9eHTSGrnz 5yo58h5kZ7zdPo76oL6ShRhrfOn+VuUNOpAI0tV5NK4Dgwx67x37/pRn+B5gP9FNgnZGxr RggshhXrBcVjAc2TpxDce3NM25BhfG0LttDaZ7ohdjo+deXVwVUeWKaM+bQ4eA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wRcDGGOVZ1LZ25yuMoSMO7ckXFHBDPeZI42oxlLlIKU=; b=X23cuzdHS7NKhSjUMH8bp273LLN5pPVIvwm/v1Bht5cXD6j7ChtAoBGnU5QQeCBbj0oYOU I7nd8u+XvXSN8HBg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 102/120] x86/cpu: Use parsed CPUID(0x80000007) Date: Thu, 28 May 2026 17:39:04 +0200 Message-ID: <20260528153923.403473-103-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For Intel, Centar, and Zhaoxin early init, use parsed CPUID(0x80000007) instead of doing ugly bitwise operations on cpuinfo_x86::x86_power. The latter is backed by a direct CPUID query and will be later removed. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/centaur.c | 4 +++- arch/x86/kernel/cpu/intel.c | 13 +++++++------ arch/x86/kernel/cpu/zhaoxin.c | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 86cbe4427453..29688aec2231 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -89,6 +89,8 @@ enum { =20 static void early_init_centaur(struct cpuinfo_x86 *c) { + const struct leaf_0x80000007_0 *el7 =3D cpuid_leaf(c, 0x80000007); + #ifdef CONFIG_X86_32 /* Emulate MTRRs using Centaur's MCR. */ if (c->x86 =3D=3D 5) @@ -98,7 +100,7 @@ static void early_init_centaur(struct cpuinfo_x86 *c) (c->x86 >=3D 7)) set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); =20 - if (c->x86_power & (1 << 8)) { + if (el7 && el7->constant_tsc) { set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); } diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 7ef3ba2eca3a..7b1944260004 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -201,6 +201,7 @@ void intel_unlock_cpuid_leafs(struct cpuinfo_x86 *c) =20 static void early_init_intel(struct cpuinfo_x86 *c) { + const struct leaf_0x80000007_0 *el7 =3D cpuid_leaf(c, 0x80000007); u64 misc_enable; =20 if (c->x86 >=3D 6 && !cpu_has(c, X86_FEATURE_IA64)) @@ -249,16 +250,16 @@ static void early_init_intel(struct cpuinfo_x86 *c) c->x86_phys_bits =3D 36; =20 /* - * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate - * with P/T states and does not stop in deep C-states. + * CPUID(0x80000007).constant_tsc implies that TSC runs at constant + * rate with P/T states and does not stop in deep C-states * - * It is also reliable across cores and sockets. (but not across - * cabinets - we turn it off in that case explicitly.) + * It is also reliable across cores and sockets, but not across + * cabinets; disable it explicitly in that case. * * Use a model-specific check for some older CPUs that have invariant - * TSC but may not report it architecturally via 8000_0007. + * TSC but may not report it architecturally via CPUID(0x80000007). */ - if (c->x86_power & (1 << 8)) { + if (el7 && el7->constant_tsc) { set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); } else if ((c->x86_vfm >=3D INTEL_P4_PRESCOTT && c->x86_vfm <=3D INTEL_P4= _CEDARMILL) || diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index b068922efed9..5918f9387c87 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -50,10 +50,12 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c) =20 static void early_init_zhaoxin(struct cpuinfo_x86 *c) { + const struct leaf_0x80000007_0 *el7 =3D cpuid_leaf(c, 0x80000007); + if (c->x86 >=3D 0x6) set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); =20 - if (c->x86_power & (1 << 8)) { + if (el7 && el7->constant_tsc) { set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 2BABA47D94A for ; Thu, 28 May 2026 15:45:28 +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=1779983133; cv=none; b=m5f77mjFTKz1ReE1jrRuAWLdtaiHrtlJfUg6A+7r5GMTqTO4JJ0CfmpFKjGgXo7ZhuCTL0sPkMHlRXhNXHCpdFzw0u1f9ghDNUL0t+yVcb7ygm4xICirB6P52bg/42k8p55J+9K3sN5i/U6zmbYOpGLVl0BEn4fpfCCS9sTBcf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983133; c=relaxed/simple; bh=+9GqzYCneIMUGG6+8LnjxX+VIZvFOunAdboY3sOnz0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rOY4fMCDBl8s/1sPvQzHGa0ZKdad1qmpW9h3H+9qKrwm/9kz0XGJDMwbT8NUI0VhRIW8RDjQnZ2i6MCOGx/nVYUtERGpYxegnXfxit3YtWzQleC5bysAsEsy44Tafj5o1is4HWJj4PfCNbKhvJB2CVe8O5FzbuCHsd6uVr4OyPU= 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=d/J1biVt; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tjTezFPH; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d/J1biVt"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tjTezFPH" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OwjloHBK6gIX0SpDJctI4hTTjjQ1Z/VZ2N2dXQU/+GE=; b=d/J1biVtj14d20YG9QDxeLIejhvRsbfnORsMQ+fLmvalkfPlK94QWezaQl19CMR1/bW57H /Ffp3Mrdjk6KCG7gyHimEeYnN4wMPRjBlgNVUKqSlDCBE61jU2KlO8Om/tcGvUtxHeR8y/ 5kdn+SHSXypnhFLyAJJWrvakpyYIsVM9f4DLOwsFR+vWb+2SDFZ1VPVhB1TLFpbtxuMDXr 0zdtV/n192tsyToMdtLENaH6K8aJtEWBVWM0qZ9mIe7+ehw3jHDXkF9DdQ9z7mP5s7OK3U LbGN5SJp7dC8YS5hSzdz/bAWv1C+U9czA7QodzeYQygWDfgCP5R4WD4S2+rYZw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OwjloHBK6gIX0SpDJctI4hTTjjQ1Z/VZ2N2dXQU/+GE=; b=tjTezFPHZ5Qw3ZasBKaML/6M48Y7JX/1nbLoiRK+4gcWFDa81l+3huevEIk+989H75ANuE oULtEGmPHbL4XaAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 103/120] x86/cpu: amd/hygon: Use parsed CPUID(0x80000007) Date: Thu, 28 May 2026 17:39:05 +0200 Message-ID: <20260528153923.403473-104-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use parsed CPUID(0x80000007) instead of doing ugly bitwise operations on cpuinfo_x86::x86_power. The latter is backed by a direct CPUID query and will be later removed. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd.c | 25 +++++++++++-------------- arch/x86/kernel/cpu/hygon.c | 25 +++++++++++-------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 5f885fafa238..0b5d8d0c3d29 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -612,6 +612,7 @@ static void early_detect_mem_encrypt(struct cpuinfo_x86= *c) =20 static void early_init_amd(struct cpuinfo_x86 *c) { + const struct leaf_0x80000007_0 *el7 =3D cpuid_leaf(c, 0x80000007); u32 dummy; =20 if (c->x86 >=3D 0xf) @@ -619,22 +620,18 @@ static void early_init_amd(struct cpuinfo_x86 *c) =20 rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy); =20 - /* - * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate - * with P/T states and does not stop in deep C-states - */ - if (c->x86_power & (1 << 8)) { - set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); - set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); - } + if (el7) { + if (el7->constant_tsc) { + set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); + set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); + } =20 - /* Bit 12 of 8000_0007 edx is accumulated power mechanism. */ - if (c->x86_power & BIT(12)) - set_cpu_cap(c, X86_FEATURE_ACC_POWER); + if (el7->proc_power_reporting) + set_cpu_cap(c, X86_FEATURE_ACC_POWER); =20 - /* Bit 14 indicates the Runtime Average Power Limit interface. */ - if (c->x86_power & BIT(14)) - set_cpu_cap(c, X86_FEATURE_RAPL); + if (el7->rapl_interface) + set_cpu_cap(c, X86_FEATURE_RAPL); + } =20 #ifdef CONFIG_X86_64 set_cpu_cap(c, X86_FEATURE_SYSCALL32); diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c index 4a63538c2b3f..8f31005bc802 100644 --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -125,28 +125,25 @@ static void bsp_init_hygon(struct cpuinfo_x86 *c) =20 static void early_init_hygon(struct cpuinfo_x86 *c) { + const struct leaf_0x80000007_0 *el7 =3D cpuid_leaf(c, 0x80000007); u32 dummy; =20 set_cpu_cap(c, X86_FEATURE_K8); =20 rdmsr_safe(MSR_AMD64_PATCH_LEVEL, &c->microcode, &dummy); =20 - /* - * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate - * with P/T states and does not stop in deep C-states - */ - if (c->x86_power & (1 << 8)) { - set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); - set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); - } + if (el7) { + if (el7->constant_tsc) { + set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); + set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC); + } =20 - /* Bit 12 of 8000_0007 edx is accumulated power mechanism. */ - if (c->x86_power & BIT(12)) - set_cpu_cap(c, X86_FEATURE_ACC_POWER); + if (el7->proc_power_reporting) + set_cpu_cap(c, X86_FEATURE_ACC_POWER); =20 - /* Bit 14 indicates the Runtime Average Power Limit interface. */ - if (c->x86_power & BIT(14)) - set_cpu_cap(c, X86_FEATURE_RAPL); + if (el7->rapl_interface) + set_cpu_cap(c, X86_FEATURE_RAPL); + } =20 #ifdef CONFIG_X86_64 set_cpu_cap(c, X86_FEATURE_SYSCALL32); --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 5274D47DD7E for ; Thu, 28 May 2026 15:45:31 +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=1779983138; cv=none; b=BWSGE+zG+zJXLk0GB3fYhARCMc97eYq1UgIvkoLG1WPvqoYZ6F2H+30o1LUzsPhBqED2tbC6Xk2fjY3Ik7ICb5ZJRq9JDjizSRwelIam/KjXxMZ75S5OuYadmKDoRJGSvR0DwAOa2L73eN9+VCthsQpID602VVrWJeoaCpk2UIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983138; c=relaxed/simple; bh=/QDeZBNG1vI/bEqqo25VNTa0+Z0FhCZyA7SYTEW+LmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RRBD0n8oXeAOUu1mUPUBO2IScP/aorS2AT0Q82UyTHj/geHiO3xDlFz8DWju5jf3NZ8lci4yEq1UHCBWZh+PQuP6xtsVwSIJCKSt6tynjqBBcBHO+0u/flluSt4z0dgNkujlPpFJxvlS++YMFXrK0d8Dkh3ZYnyDe5tKRLNuMYA= 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=XJj8WYzo; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QOnoumIA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="XJj8WYzo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QOnoumIA" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CJexGsf+qYIlnM1vpHMPn4lQHsp+Bjthkuhk9PQKOWo=; b=XJj8WYzovJrT9emT+tgJhBTGOhNHesrhGFa0rk3gwFUobx7s0qgAqWgUXiCzkAvD+n+eC4 LO1CgPmOboecRbNWD6ejg3rTvr47z4HL7MV2vZxmqwOvsOpfwCEXWUfFzaD5M1je6z16SM ZzNK3cICdPJ4ONyERzR6mI1LeTJNjCe3bD9+V5k5LoNrh1/24vJeNgeFdvGbNY0ztal6AW VpV0SetBA3fTC/w/qMGDFxENaHwxteahVZRH4XBW+U0MoA++7GGtiHx5egawQ0QUfPhhwz 9uPgCQ/ZT7+WiWoeEG8ScNkbdFZ87PHe4NH2hNAjOGqOmlg0WdwSzCbl3IykDA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CJexGsf+qYIlnM1vpHMPn4lQHsp+Bjthkuhk9PQKOWo=; b=QOnoumIAI20W22oKuPd4hoe5fGOQllmjm6g0j9lLBvr0xeu/AmHlSkPQFbc8N7KeNf1MOR LHDXcGtSftfnpJDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 104/120] x86/cpu: cpuinfo: Use parsed CPUID(0x80000007) Date: Thu, 28 May 2026 17:39:06 +0200 Message-ID: <20260528153923.403473-105-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For /proc/cpuinfo "power management" line, use parsed CPUID(0x80000007) instead of poking at cpuinfo_x86::x86_power. The latter is backed by a direct CPUID query and will be later removed. Remove the x86_power_flags[] strings table as it has no more users. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpufeature.h | 1 - arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/powerflags.c | 24 ------------ arch/x86/kernel/cpu/proc.c | 61 ++++++++++++++++++++++++------- 4 files changed, 49 insertions(+), 39 deletions(-) delete mode 100644 arch/x86/kernel/cpu/powerflags.c diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index 3ddc1d33399b..520949560138 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -39,7 +39,6 @@ enum cpuid_leafs }; =20 extern const char * const x86_cap_flags[NCAPINTS*32]; -extern const char * const x86_power_flags[32]; =20 /* * In order to save room, we index into this array by doing diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index d62e2d60a965..5c091d9fc9ee 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -27,7 +27,7 @@ obj-y +=3D bugs.o obj-y +=3D aperfmperf.o obj-y +=3D cpuid-deps.o cpuid_0x2_table.o obj-y +=3D umwait.o -obj-y +=3D capflags.o powerflags.o +obj-y +=3D capflags.o =20 obj-$(CONFIG_X86_LOCAL_APIC) +=3D topology.o =20 diff --git a/arch/x86/kernel/cpu/powerflags.c b/arch/x86/kernel/cpu/powerfl= ags.c deleted file mode 100644 index fd6ec2aa0303..000000000000 --- a/arch/x86/kernel/cpu/powerflags.c +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Strings for the various x86 power flags - * - * This file must not contain any executable code. - */ - -#include - -const char *const x86_power_flags[32] =3D { - "ts", /* temperature sensor */ - "fid", /* frequency id control */ - "vid", /* voltage id control */ - "ttp", /* thermal trip */ - "tm", /* hardware thermal control */ - "stc", /* software thermal control */ - "100mhzsteps", /* 100 MHz multiplier control */ - "hwpstate", /* hardware P-state control */ - "", /* tsc invariant mapped to constant_tsc */ - "cpb", /* core performance boost */ - "eff_freq_ro", /* Readonly aperf/mperf */ - "proc_feedback", /* processor feedback interface */ - "acc_power", /* accumulated power mechanism */ -}; diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c index 6571d432cbe3..89471bcfcc32 100644 --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -4,9 +4,11 @@ #include #include #include -#include #include =20 +#include +#include + #include "cpu.h" =20 #ifdef CONFIG_X86_VMX_FEATURE_NAMES @@ -60,6 +62,50 @@ static void show_cpuinfo_misc(struct seq_file *m, struct= cpuinfo_x86 *c) } #endif =20 +static void show_cpuinfo_power(struct cpuinfo_x86 *c, struct seq_file *m) +{ + const struct cpuid_regs *el7_regs =3D cpuid_leaf_raw(c, 0x80000007); + const struct leaf_0x80000007_0 *el7 =3D cpuid_leaf(c, 0x80000007); + + seq_puts(m, "power management:"); + + if (!el7_regs || !el7) + return; + + if (el7->digital_temp) + seq_puts(m, " ts"); + if (el7->powernow_freq_id) + seq_puts(m, " fid"); + if (el7->powernow_volt_id) + seq_puts(m, " vid"); + if (el7->thermal_trip) + seq_puts(m, " ttp"); + if (el7->hw_thermal_control) + seq_puts(m, " tm"); + if (el7->sw_thermal_control) + seq_puts(m, " stc"); + if (el7->_100mhz_steps) + seq_puts(m, " 100mhzsteps"); + if (el7->hw_pstate) + seq_puts(m, " hwpstate"); + + /* Keep constant_tsc off the power management line */ + + if (el7->core_perf_boost) + seq_puts(m, " cpb"); + if (el7->eff_freq_ro) + seq_puts(m, " eff_freq_ro"); + if (el7->proc_feedback) + seq_puts(m, " proc_feedback"); + if (el7->proc_power_reporting) + seq_puts(m, " acc_power"); + + /* Afterwards, just output the offsets of set bits */ + for (int i =3D 13; i < 32; i++) + if (el7_regs->edx & BIT(i)) + seq_printf(m, " [%d]", i); +} + static int show_cpuinfo(struct seq_file *m, void *v) { struct cpuinfo_x86 *c =3D v; @@ -138,18 +184,7 @@ static int show_cpuinfo(struct seq_file *m, void *v) seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n", c->x86_phys_bits, c->x86_virt_bits); =20 - seq_puts(m, "power management:"); - for (i =3D 0; i < 32; i++) { - if (c->x86_power & (1 << i)) { - if (i < ARRAY_SIZE(x86_power_flags) && - x86_power_flags[i]) - seq_printf(m, "%s%s", - x86_power_flags[i][0] ? " " : "", - x86_power_flags[i]); - else - seq_printf(m, " [%d]", i); - } - } + show_cpuinfo_power(c, m); =20 seq_puts(m, "\n\n"); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 8D09B403EBC for ; Thu, 28 May 2026 15:45:34 +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=1779983139; cv=none; b=cqa0QRqpWOFxBUgkR2Mb47We0Ho79G8uBHgtkl7ztrRRsWsR7vMp2cVTV/JTVTCicWrT/gOaIG/uVFZJi4QTeZGepHUCvIQG02zvSDUpw8ZLwdBXMA1gAmKyZ6WZjKIynxVvpKLFZ9Fx8U//kJD7BXXQsBvJb/nJVsZmEzIUGjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983139; c=relaxed/simple; bh=7PsV/lPJUipHrTfXVY36m34aQ2nGBD+pTn/Z24Ffaqg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i0/uCAJfOAWaYRQPwvR7frKjNpKcplb0sHmKqneOL/QBgOTHmVA4O5ougYchxk0wCZp5uf/yxLz+LdDyuRpiuPhiZjoWK/AE3eHIIITiy6f/4gjow8j3QFUKgHY/CEX1kswIlfwU5D/D4DmqYX2Gqr0GRX3DPYf3vqtnb5lUxnI= 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=f2z7dh8d; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=q2DhBNIQ; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="f2z7dh8d"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="q2DhBNIQ" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KxgFHB4mmTpW3f7Yfqq79u+k/lebkmZ2DbSwyYqnAbM=; b=f2z7dh8dnPpGBAltYWm7EW/14Fy4LPo3C7tgLRX/tJoIYIOWhDe36viI8KH6HOL5SJ/UWe lHsBKE7qc4Koj3JP5651W7W+b42+/kVLFjUTnB9Rpdsizfbel9xFAreLNNK6cMhw42DKj+ qJfZsjIpgdz7oj/0/6kr40GKw2NFnsRRgbb9ZbV4XEPJr5Y4iTlIcpqG+5qWSaWwvL5CBo lc9o3DbZoe89f5DOzAQTs07q9Cshku0dNdFIJZlkqSIk2NaI5CCqCaRiC0R3JIt60/Tds/ 7rlzoqqSqs2r8swcLqgtXqNpqOyTzrI+0LcFTrX43ECy1P+AK3K0c0O3QY28xQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KxgFHB4mmTpW3f7Yfqq79u+k/lebkmZ2DbSwyYqnAbM=; b=q2DhBNIQHERt+k27LQuLNUQ7cjkQsqT0AsjJvSfU25TrrdTsqZ1c3/PxV6HagsiJ5nkj+S 7Yg7OLnETygvS7CQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 105/120] KVM: x86: Use parsed CPUID(0x80000007) Date: Thu, 28 May 2026 17:39:07 +0200 Message-ID: <20260528153923.403473-106-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For KVM cpuid, use parsed CPUID(0x80000007) instead of poking at x86_power. The latter is backed by a direct CPUID query and will be removed later. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/cpuid.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 040e15ff87c5..ad0a5410899d 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -1764,13 +1764,18 @@ static inline int __do_cpuid_func(struct kvm_cpuid_= array *array, u32 function) /* Drop reserved bits, pass host L2 cache and TLB info. */ entry->edx &=3D ~GENMASK(17, 16); break; - case 0x80000007: /* Advanced power management */ + case 0x80000007: { /* Advanced power management */ + const struct cpuid_regs *el7 =3D cpuid_leaf_raw(&boot_cpu_data, 0x800000= 07); + cpuid_entry_override(entry, CPUID_8000_0007_EDX); =20 - /* mask against host */ - entry->edx &=3D boot_cpu_data.x86_power; + /* Mask against host */ + if (el7) + entry->edx &=3D el7->edx; + entry->eax =3D entry->ebx =3D entry->ecx =3D 0; break; + } case 0x80000008: { /* * GuestPhysAddrSize (EAX[23:16]) is intended for software --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 6535F47ECDE for ; Thu, 28 May 2026 15:45:38 +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=1779983143; cv=none; b=h7QStaPnrwpteUNRj09X2aR5nF9d4cBselMwTpqQc9EtSJ/+beIR8Ga6TbO4/p772DBl/gdWDhlCmVHf9G0//m/IOixd4HoskpAEiYKd2kPlwkbi51Nea/b5nLMD/OGV+NKZfcys+JTZ7ldb2Sw6nd40aqfxrspUAYskNZLzwJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983143; c=relaxed/simple; bh=/+g0P7BlkUBU5/CP6EIZ9Om/dRb+w98SvUrSJD7sCvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K1c8i661RSL0ievQ1EvKLw/qHemlQE8JfrAXHmw08aGRrdHZNAC/tmQu4Jla+/ZNeEnQMQnosYvlZ9UGeMY3ist6OXdN9k+mO11UcI7fw+7Hp7NgUpvbfB9sxYH2Pwwb5jwX82fIYxMtyvGKtjLbRw2eWtgl6Iz6a5N5ILTi35c= 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=zZgxTOIP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bV4F8ai8; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zZgxTOIP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bV4F8ai8" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l3YnuoTW582QSiSINfEO33oPRdnAjkCClmMq5boZbRI=; b=zZgxTOIPgxYXaCJ1OBw+FGEyCRmyewfvhUKMJk9Bfz5oViAcwJmL7S4bYSjBWabZY3UQrj C2dLHmVcZz4UoxPYar2zAo1GEbxX/G4RxJaewjGitR3xtrC3dwSNY1OIePliVJ6xa4TpvU LbqURz7p+o5frZjBoeoiU8+wUKrza15hzd2WjBGUA1DPjEk1W1fQYQWBZtX/j+gVz7kl7n n9t6s/BYb81lgghnk2mZIfkEyPDRWyo51E5obceV2OpxMEzzuE5pBKC1ymplRxxKfwMAUl xRRKB8mfkvIN1sdkmykTXk8E8vs4m3SSfu3f/3YOuL94KpWMwsndg5Ya3+6H/w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983136; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l3YnuoTW582QSiSINfEO33oPRdnAjkCClmMq5boZbRI=; b=bV4F8ai83tNWai9mkQneZlUQHSe/SUKMfdzVuyMykx1YD3bAinAkd+WZSx+2Usz2r79an7 y+L+7kzjJ7bApqBQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 106/120] x86/microcode: Allocate cpuinfo_x86 snapshots on the heap Date: Thu, 28 May 2026 17:39:08 +0200 Message-ID: <20260528153923.403473-107-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" load_late_stop_cpus() snapshots CPU capabilities before a late microcode update, while microcode_check() snapshots the capabilities again after the update. Both functions allocate their struct cpuinfo_x86 snapshots on the stack. Meanwhile, cpuinfo_x86 contains the parsed CPUID tables where more leaves will be added; resulting in "stack frame length exceeded" warnings. Allocate the before/after cpuinfo_x86 snapshots on the heap. For load_late_stop_cpus(), do the memory allocation before the microcode staging step. This leaves no leaked or stale microcode state in -ENOMEM failure modes. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 11 ++++++++--- arch/x86/kernel/cpu/microcode/core.c | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index d78063e4e665..f5e3aaed67ef 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2551,15 +2551,20 @@ void store_cpu_caps(struct cpuinfo_x86 *curr_info) */ void microcode_check(struct cpuinfo_x86 *prev_info) { - struct cpuinfo_x86 curr_info; + struct cpuinfo_x86 *curr_info __free(kfree) =3D kmalloc_obj(*curr_info); =20 perf_check_microcode(); =20 amd_check_microcode(); =20 - store_cpu_caps(&curr_info); + if (!curr_info) { + pr_warn("x86/CPU: Microcode update CPU capability changes check was skip= ped (ENOMEM)\n"); + return; + } + + store_cpu_caps(curr_info); =20 - if (!memcmp(&prev_info->x86_capability, &curr_info.x86_capability, + if (!memcmp(&prev_info->x86_capability, &curr_info->x86_capability, sizeof(prev_info->x86_capability))) return; =20 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/mic= rocode/core.c index 56d791aeac4e..7a00671540bc 100644 --- a/arch/x86/kernel/cpu/microcode/core.c +++ b/arch/x86/kernel/cpu/microcode/core.c @@ -588,16 +588,19 @@ static int load_cpus_stopped(void *unused) =20 static int load_late_stop_cpus(bool is_safe) { + struct cpuinfo_x86 *prev_info __free(kfree) =3D kmalloc_obj(*prev_info); unsigned int cpu, updated =3D 0, failed =3D 0, timedout =3D 0, siblings = =3D 0; unsigned int nr_offl, offline =3D 0; int old_rev =3D boot_cpu_data.microcode; - struct cpuinfo_x86 prev_info; =20 if (!is_safe) { pr_err("Late microcode loading without minimal revision check.\n"); pr_err("You should switch to early loading, if possible.\n"); } =20 + if (!prev_info) + return -ENOMEM; + /* * Pre-load the microcode image into a staging device. This * process is preemptible and does not require stopping CPUs. @@ -617,7 +620,7 @@ static int load_late_stop_cpus(bool is_safe) * Take a snapshot before the microcode update in order to compare and * check whether any bits changed after an update. */ - store_cpu_caps(&prev_info); + store_cpu_caps(prev_info); =20 if (microcode_ops->use_nmi) static_branch_enable_cpuslocked(µcode_nmi_handler_enable); @@ -666,7 +669,7 @@ static int load_late_stop_cpus(bool is_safe) num_online_cpus() - (updated + siblings)); } pr_info("revision: 0x%x -> 0x%x\n", old_rev, boot_cpu_data.microcode); - microcode_check(&prev_info); + microcode_check(prev_info); =20 return updated + siblings =3D=3D num_online_cpus() ? 0 : -EIO; } --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 8609D47ECF7 for ; Thu, 28 May 2026 15:45:41 +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=1779983146; cv=none; b=s2kPx/x4fRtmoa7zic0Z4wC8MIIQNvyHvFOdUVdktMJ8tKrSDAZxYEmwt2hNgULZadL+8s3ByD6CdV88qF9ECsOvPT3cnaAbq3SYTvnON0FpZyrd9ZOExh+ShCJllMc/+e60QdgOjQXocjQaO3xCxDJEKKToFHGrU4CtjGCze/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983146; c=relaxed/simple; bh=++kGsxBKtBMWqK3YV56MhYqTJHTslZ01lEwYiJyFqto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GkkH4RiEnUvj/xCKCtFtwM29/FTg/jim5oxpQixxXRjfp8EG5aBHFylhwIHX2ieUxVNWs7NP1Aj0JkAkef8r7S2+MoRslskdrHy00lLkoAbphBjxdzJYKkTSGK1NaVvWWethTcQfmFNwvk4Mc/P4fHenhLy1GeE4c0/VCextNsQ= 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=3uh2g05K; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kiIy0jQj; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3uh2g05K"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kiIy0jQj" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OCGi1hP7Dp3SyKS4KD3q6tJT6BNNpYDbXg3XI7OwFwE=; b=3uh2g05KSsE9KQaJC8iOAjr4QpufOSOPKhn1RtTBN5QCqzTPgIym6OM15rFBWkn/k1qu/l q2wjokzG9GVSbgdrNzWBZZvhWfcNox1dpsYyC/JqVR3tRbodNVQratKTXToY4+izP7hxvW 6HitI+Wkb1NTPO+S8DGhmCmms1RW1LBkLQo6lVL0U5PFXyiOlzAhixw3zDBwbeXaVRq4Qq fiL47lIE3Vspqy7XcJ9w2sDeOeiS8Pw+BnPXaC+1+Wxvk0dFQKDcsiXuAb4u3G5LqAmbnN gAE4Yqp8d9vr2dRnRvL9OWZBpvTKpNz3/Qj7Ljw1lvWC4VYmO86DltcXMQsSGQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OCGi1hP7Dp3SyKS4KD3q6tJT6BNNpYDbXg3XI7OwFwE=; b=kiIy0jQjrAX8Ylccq6FezRl6f/lAhwwVOAHSY1/AGA13aev6MtS6uC4RjfCiTcY27T4MpD 7c/8CPop1b2MGtDg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 107/120] x86/cpuid: Parse leaves backing X86_FEATURE words Date: Thu, 28 May 2026 17:39:09 +0200 Message-ID: <20260528153923.403473-108-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add CPUID parser support for: CPUID(0x7) CPUID(0x7).1 CPUID(0xd).1 CPUID(0x80000001) CPUID(0x8000000a) CPUID(0x8000001f) CPUID(0x80000021) where one or more of these leaves output registers back the X86_FEATURE words at . Handle CPUID(0x7).1 via a custom reader. Its availability depends on the subleaf count reported by CPUID(0x7).0, so check that first. Do not use a custom reader for CPUID(0xd).1. Per the Intel SDM regarding CPUID(0xd)'s subleaf availability: "sub-leafs 0 and 1 are always valid". Note, this prepares for later changes that will route X86_FEATURE queries from cpuinfo_x86::x86_capability[] to the system's CPUID tables. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 7 +++++++ arch/x86/kernel/cpu/cpuid_parser.c | 13 +++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 7671f8d24014..1de66781cb5c 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -214,8 +214,11 @@ struct cpuid_leaves { CPUID_LEAF_N ( 0x4, 8 ); CPUID_LEAF ( 0x5, 0 ); CPUID_LEAF ( 0x6, 0 ); + CPUID_LEAF ( 0x7, 0 ); + CPUID_LEAF ( 0x7, 1 ); CPUID_LEAF ( 0x9, 0 ); CPUID_LEAF ( 0xa, 0 ); + CPUID_LEAF ( 0xd, 1 ); CPUID_LEAF ( 0x12, 0 ); CPUID_LEAF ( 0x12, 1 ); CPUID_LEAF_N ( 0x12, 8 ); @@ -229,6 +232,7 @@ struct cpuid_leaves { CPUID_LEAF ( 0x23, 4 ); CPUID_LEAF ( 0x23, 5 ); CPUID_LEAF ( 0x80000000, 0 ); + CPUID_LEAF ( 0x80000001, 0 ); CPUID_LEAF ( 0x80000002, 0 ); CPUID_LEAF ( 0x80000003, 0 ); CPUID_LEAF ( 0x80000004, 0 ); @@ -236,7 +240,10 @@ struct cpuid_leaves { CPUID_LEAF ( 0x80000006, 0 ); CPUID_LEAF ( 0x80000007, 0 ); CPUID_LEAF ( 0x80000008, 0 ); + CPUID_LEAF ( 0x8000000a, 0 ); CPUID_LEAF_N ( 0x8000001d, 8 ); + CPUID_LEAF ( 0x8000001f, 0 ); + CPUID_LEAF ( 0x80000021, 0 ); CPUID_LEAF ( 0x80000022, 0 ); CPUID_LEAF ( 0x80860000, 0 ); CPUID_LEAF ( 0x80860001, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index 452b5b317e4d..1655e35b6310 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -130,6 +130,19 @@ define_cpuid_0x23_subleaf_read_function(3); define_cpuid_0x23_subleaf_read_function(4); define_cpuid_0x23_subleaf_read_function(5); =20 +static void +cpuid_read_0x7_1(const struct cpuid_parse_entry *e, const struct cpuid_rea= d_output *output) +{ + struct leaf_0x7_0 l7; + + cpuid_read_subleaf(0x7, 0, &l7); + if (l7.leaf7_n_subleaves =3D=3D 0) + return; + + cpuid_read_subleaf(e->leaf, e->subleaf, output->regs); + output->info->nr_entries =3D 1; +} + /* * Shared read function for Intel CPUID(0x4) and AMD CPUID(0x8000001d), as= both have * the same subleaf enumeration logic and register output format. diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 799714300bfb..123433a4b210 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -149,7 +149,10 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x5, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x6, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x9, 0, 0x9 ), \ + CPUID_PARSE_ENTRY ( 0x7, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x7, 1, 0x7_1 ), \ CPUID_PARSE_ENTRY ( 0xa, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0xd, 1, generic ), \ CPUID_PARSE_ENTRY ( 0x12, 0, 0x12 ), \ CPUID_PARSE_ENTRY ( 0x12, 1, 0x12 ), \ CPUID_PARSE_ENTRY_N ( 0x12, sgx_epc_sections ), \ @@ -163,6 +166,7 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x23, 4, 0x23_4 ), \ CPUID_PARSE_ENTRY ( 0x23, 5, 0x23_5 ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ + CPUID_PARSE_ENTRY ( 0x80000001, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000003, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000004, 0, generic ), \ @@ -170,7 +174,10 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x80000006, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000007, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000008, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x8000000a, 0, generic ), \ CPUID_PARSE_ENTRY_N ( 0x8000001d, deterministic_cache ), \ + CPUID_PARSE_ENTRY ( 0x8000001f, 0, generic ), \ + CPUID_PARSE_ENTRY ( 0x80000021, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000022, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80860000, 0, 0x80860000 ), \ CPUID_PARSE_ENTRY ( 0x80860001, 0, generic ), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 9E90147F2C5 for ; Thu, 28 May 2026 15:45:44 +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=1779983148; cv=none; b=O4857AJ+6WjsK4meowQhPPer2XLv43psTBtqRCh8NkyhmHMNuEUk/2oDHwNkcR05R+F1kVDppd9Uymm7f6BJ3oR4t6GSaluzbGaZ+VmsDd9O7Luv++U9w8tJRpge0/kTyILHxiDBr3NJUbI3rfIHBreNhUrtOfXFMmfg9IKCVQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983148; c=relaxed/simple; bh=4e/ycHyhl59Yen795SWx+clPiEad3zpokLdJKcnH7WI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FVoryYio9WKEZL6rxcWWLuRFf8EMHgGw7RVHrlvW7MsSp6TJyRBDWPe78N1BrLFoqV8O9ZrBCuvAvNs40eCO66JHAlWyMJD3D27sxWUG2CcctxJBybLb1cmetfyxJNDeuSRY2Nx5gee7AtzIgAlUnkzC8LYjn9AOWHF7ZNWbJdg= 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=3LS9k7n6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FBiPnDux; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3LS9k7n6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FBiPnDux" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fxc3eKqY1kuYFpAu6wDUMdUMxCxj1SRDS61RwcuM8Ms=; b=3LS9k7n6KnAE4GpVPop7kxvvfasm0+pOjELpFLyFcggqTtBH454vxhgZeFRNeaNZTR7xDm rSllb9gbyL68LbQImPy143pkzw/WTMBpJtziMPeh/eEGXgxX6030isQJ1I6KViqkFDD3ve dGPtUbjCW3mtflcgg+9RCGuubdlH9ssl2NFBuzzkNgEHXokr/xlvIvF/CpIYiaPwAy1KT0 C6OP8v9M7jEzCnbN2KEk+L9TsLk7swEaYKyIoC4LdcwDVdSC6RPmv4IaEPpj/r9lv9G4S3 pBmAloYGgLArbmrcCPxd138LcMAKeXTumHqae62oJbMsiwMNYuz3eGu/Sb9grw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fxc3eKqY1kuYFpAu6wDUMdUMxCxj1SRDS61RwcuM8Ms=; b=FBiPnDuxyQPriJHXpw/WQ2OWgR+hB1qtZJ4HCQWN121kTRfGtnNPv39i/F/+eO8pm4+krb 0ITLwUjEugcPUYAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 108/120] x86/cpuid: Parse Linux synthetic CPUID leaves Date: Thu, 28 May 2026 17:39:10 +0200 Message-ID: <20260528153923.403473-109-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The X86_FEATURE words at contain both hardware-defined CPUID register bits and Linux-defined synthetic bits. The hardware-defined bits already map naturally into the parsed CPUID tables, but the synthetic bits do not. This gets feature enumeration split between the CPUID parser and the feature APIs. For this, the x86-cpuid-db project provides a 1:1 bitfield mapping for the synthetic X86_FEATURE words using the CPUID range 0x4c780000. The range prefix 0x4c78 is for Linux in its shorthand ASCII form Lx, where Linux becomes a virtual vendor mirroring hardware vendors like AMD and Intel. Cover all the synthetic feature and bug words by parsing CPUID(0x4c780001), CPUID(0x4c780001).1, and CPUID(0x4c780002). Skip these synthetic CPUID leaves in the debugfs code which compares each cached CPUID value against its actual hardware backing. Signed-off-by: Ahmed S. Darwish Link: https://lore.kernel.org/lkml/874ixernra.ffs@tglx Link: https://gitlab.com/x86-cpuid.org/x86-cpuid-db/-/blob/v3.0/CHANGELOG.r= st --- arch/x86/include/asm/cpuid/types.h | 5 +++++ arch/x86/kernel/cpu/cpuid_debugfs.c | 4 ++++ arch/x86/kernel/cpu/cpuid_parser.c | 17 +++++++++++++++++ arch/x86/kernel/cpu/cpuid_parser.h | 3 +++ 4 files changed, 29 insertions(+) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 1de66781cb5c..27bcf4eea8dc 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -39,11 +39,13 @@ enum cpuid_regs_idx { #define CPUID_EXT_START 0x80000000 #define CPUID_TMX_START 0x80860000 #define CPUID_CTR_START 0xc0000000 +#define CPUID_LNX_START 0x4c780000 =20 #define CPUID_BASE_END CPUID_RANGE_MAX(CPUID_BASE_START) #define CPUID_EXT_END CPUID_RANGE_MAX(CPUID_EXT_START) #define CPUID_TMX_END CPUID_RANGE_MAX(CPUID_TMX_START) #define CPUID_CTR_END CPUID_RANGE_MAX(CPUID_CTR_START) +#define CPUID_LNX_END CPUID_RANGE_MAX(CPUID_LNX_START) =20 /* * Types for CPUID(0x2) parsing: @@ -231,6 +233,9 @@ struct cpuid_leaves { CPUID_LEAF ( 0x23, 3 ); CPUID_LEAF ( 0x23, 4 ); CPUID_LEAF ( 0x23, 5 ); + CPUID_LEAF ( 0x4c780001, 0 ); + CPUID_LEAF ( 0x4c780001, 1 ); + CPUID_LEAF ( 0x4c780002, 0 ); CPUID_LEAF ( 0x80000000, 0 ); CPUID_LEAF ( 0x80000001, 0 ); CPUID_LEAF ( 0x80000002, 0 ); diff --git a/arch/x86/kernel/cpu/cpuid_debugfs.c b/arch/x86/kernel/cpu/cpui= d_debugfs.c index 0cafe0afefdd..65d68728157d 100644 --- a/arch/x86/kernel/cpu/cpuid_debugfs.c +++ b/arch/x86/kernel/cpu/cpuid_debugfs.c @@ -36,6 +36,10 @@ cpuid_show_leaf(struct seq_file *m, uintptr_t cpu_id, co= nst struct cpuid_parse_e }; int ret; =20 + /* Ignore synthetic ranges as they have no hardware backing */ + if (CPUID_RANGE(entry->leaf) =3D=3D CPUID_LNX_START) + continue; + seq_printf(m, "Leaf 0x%08x, subleaf %u:\n", entry->leaf, subleaf); =20 ret =3D smp_call_function_single(cpu_id, cpuid_this_cpu, ®s, true); diff --git a/arch/x86/kernel/cpu/cpuid_parser.c b/arch/x86/kernel/cpu/cpuid= _parser.c index 1655e35b6310..848b9f772232 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.c +++ b/arch/x86/kernel/cpu/cpuid_parser.c @@ -175,6 +175,21 @@ cpuid_read_0x12(const struct cpuid_parse_entry *e, con= st struct cpuid_read_outpu =20 define_cpuid_read_function(sgx_epc_sections, leaf_0x12_n, l, l->subleaf_ty= pe =3D=3D 0); =20 +/* + * Synthetic CPUID leaves read function + * + * These leaves do not exist in hardware. They reserve slots in the per-C= PU + * CPUID tables for the synthetic Linux-defined X86_FEATURE and X86_BUG wo= rds. + * + * Always mark the read as successful; the actual bits will be populated v= ia + * the X86_FEATURE bit update helpers at . + */ +static void +cpuid_read_synthetic(const struct cpuid_parse_entry *e, const struct cpuid= _read_output *output) +{ + output->info->nr_entries =3D 1; +} + /* * Define an extended range CPUID read function * @@ -262,6 +277,7 @@ static unsigned int cpuid_range_max_leaf(const struct c= puid_table *t, unsigned i case CPUID_EXT_START: return el0 ? el0->max_ext_leaf : 0; case CPUID_TMX_START: return tl0 ? tl0->max_tra_leaf : 0; case CPUID_CTR_START: return cl0 ? cl0->max_cntr_leaf : 0; + case CPUID_LNX_START: return CPUID_LNX_END; default: return 0; } } @@ -325,6 +341,7 @@ cpuid_fill_table(struct cpuid_table *t, const struct cp= uid_parse_entry entries[] { CPUID_EXT_START, CPUID_EXT_END }, { CPUID_TMX_START, CPUID_TMX_END }, { CPUID_CTR_START, CPUID_CTR_END }, + { CPUID_LNX_START, CPUID_LNX_END }, }; =20 for (unsigned int i =3D 0; i < ARRAY_SIZE(ranges); i++) diff --git a/arch/x86/kernel/cpu/cpuid_parser.h b/arch/x86/kernel/cpu/cpuid= _parser.h index 123433a4b210..22903701b8fe 100644 --- a/arch/x86/kernel/cpu/cpuid_parser.h +++ b/arch/x86/kernel/cpu/cpuid_parser.h @@ -165,6 +165,9 @@ struct cpuid_parse_entry { CPUID_PARSE_ENTRY ( 0x23, 3, 0x23_3 ), \ CPUID_PARSE_ENTRY ( 0x23, 4, 0x23_4 ), \ CPUID_PARSE_ENTRY ( 0x23, 5, 0x23_5 ), \ + CPUID_PARSE_ENTRY ( 0x4c780001, 0, synthetic ), \ + CPUID_PARSE_ENTRY ( 0x4c780001, 1, synthetic ), \ + CPUID_PARSE_ENTRY ( 0x4c780002, 0, synthetic ), \ CPUID_PARSE_ENTRY ( 0x80000000, 0, 0x80000000 ), \ CPUID_PARSE_ENTRY ( 0x80000001, 0, generic ), \ CPUID_PARSE_ENTRY ( 0x80000002, 0, generic ), \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C774847F2E9 for ; Thu, 28 May 2026 15:45:47 +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=1779983156; cv=none; b=pfkYgnh0iQwOqT2n1/m+x/5eht5YL5xcawbKbtoBfg2RD9a0fuIGdnOyqyVVIBXH/gv3W2SC97R7SHD8TywIGxtLd5bpzqQbB91aZER0MStRZg4s/MyxPZ4Gw5bdVe3sNruOkw9ynC1EZWXEywuVHOr49XcTHGZ421KqpFPHy7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983156; c=relaxed/simple; bh=n4YCaxov80zZp1g8PIvOdTArsJf7jqweWh34brIBbJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BgfLDWyoYRmMU8z+J/0dMQYoinbC3/5C0l4nR6G/42KcsE6/ubg8poKG71IVTb1dUe8dwcqrNcgjjG8OTnscnzE8IZ7mX5nkEzzk3vjG5pqMyY5KqNncNrGPQQ1frHBMVU+q4Q44NgHtb6A64YJiKH2Jw479MtRQyavf0uhMcrs= 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=C1LidY6r; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eC1nzp43; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="C1LidY6r"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eC1nzp43" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jYByR6a/NDdJzlNCvjaDl47BEyIrYg5KyzzduISgnRw=; b=C1LidY6rDPxvvmAB1BpewA2EvPyC6SVPG9hFqt11YSTLRAmbzX6b7qFH5ckKnpsHG0VipL 8o+3qzW1rivZHZ+cJJxl9lvEZdfHzgXkyv1vEpN0unvaCnUeqepB08LVtp95lhotYNcEY9 IenEP0upJ64WMxEEXXqwtQ6M85Ubh+lDFUdqIT7aIceboozdiu0O+VSSeGGs7AzoU9voBY 61lJwegvrnK0GTRLrsI8Gg9GCSMu5VfO7MVAbXHRSpFSwpbJZ46rViqb+VLHZAnpflXqs4 oTH73V71p1pCJw36y/n9mKb0CuLSDJSAlHpOUK/i8lJGgFpHxljjuN5sp3Nt1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jYByR6a/NDdJzlNCvjaDl47BEyIrYg5KyzzduISgnRw=; b=eC1nzp43Ywhe7x68/gO3DNb+MiQJX7+3LQvTwbr2FEOKB2Z6DxAoB8yyC2A4RO9Io+10QV nRB63pAmwwpo61DQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 109/120] x86/cpuid: Introduce a compile-time X86_FEATURE word map Date: Thu, 28 May 2026 17:39:11 +0200 Message-ID: <20260528153923.403473-110-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Prepare for routing X86_FEATURE queries to the CPUID tables instead of to cpuinfo_x86::x86_capability[]. The latter will be later removed to make the CPUID tables a "single source of Truth" for all x86 feature state. Build a compile time map from an X86_FEATURE word to its cached CPUID leaf/subleaf register output. Use a compile time table to preserve the feature querying optimizations at . Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 59 +++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 27bcf4eea8dc..85be453834fd 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -168,9 +168,12 @@ struct leaf_parse_info { * Use an array of storage entries to accommodate CPUID leaves with multip= le subleaves * having the same output format. This is common for hierarchical enumera= tion; e.g., * CPUID(0x4), CPUID(0x12), and CPUID(0x8000001d). + * + * Align all CPUID outputs to unsigned long. They're passed to bitops for= X86_FEATURE + * queries, which require the alignment. */ #define __CPUID_LEAF(_name, _count) \ - struct _name _name[_count]; \ + struct _name _name[_count] __aligned(sizeof(unsigned long));\ struct leaf_parse_info _name##_info =20 /** @@ -273,9 +276,61 @@ struct cpuid_leaves { * * This is to be embedded inside 'struct cpuinfo_x86' to provide parsed and * sanitized CPUID data per CPU. + * + * Align the leaves to unsigned long since their elements are passed to bi= tops + * for X86_FEATURE querying. */ struct cpuid_table { - struct cpuid_leaves leaves; + struct cpuid_leaves leaves __aligned(sizeof(unsigned long)); +}; + +/* + * X86_FEATURE word mappings: + * + * Build a compile-time mapping table from an X86_FEAT= URE + * word to its corresponding cached entry in a CPUID table. + */ + +#define __BUG(n) (NCAPINTS + (n)) + +struct cpuid_cpufeature { + unsigned int leaves_offset; /* Offset from a struct cpuid_leaves instance= */ + unsigned int cpuid_reg; /* Output register: CPUID_EAX -> CPUID_EDX */ }; =20 +#define __cpu_feature_word(_word, _leaf, _subleaf, _reg) \ + [_word] =3D { \ + .leaves_offset =3D offsetof(struct cpuid_leaves, leaf_##_leaf##_##_suble= af),\ + .cpuid_reg =3D _reg, \ + } + +#define CPUID_FEATURE_WORDS_MAP \ +{ \ + /* X86_FEATURE word, Leaf, Subleaf, Output reg */ \ + __cpu_feature_word(0, 0x1, 0, CPUID_EDX), \ + __cpu_feature_word(1, 0x80000001, 0, CPUID_EDX), \ + __cpu_feature_word(2, 0x80860001, 0, CPUID_EDX), \ + __cpu_feature_word(3, 0x4c780001, 0, CPUID_EAX), \ + __cpu_feature_word(4, 0x1, 0, CPUID_ECX), \ + __cpu_feature_word(5, 0xc0000001, 0, CPUID_EDX), \ + __cpu_feature_word(6, 0x80000001, 0, CPUID_ECX), \ + __cpu_feature_word(7, 0x4c780001, 0, CPUID_EBX), \ + __cpu_feature_word(8, 0x4c780001, 0, CPUID_ECX), \ + __cpu_feature_word(9, 0x7, 0, CPUID_EBX), \ + __cpu_feature_word(10, 0xd, 1, CPUID_EAX), \ + __cpu_feature_word(11, 0x4c780001, 0, CPUID_EDX), \ + __cpu_feature_word(12, 0x7, 1, CPUID_EAX), \ + __cpu_feature_word(13, 0x80000008, 0, CPUID_EBX), \ + __cpu_feature_word(14, 0x6, 0, CPUID_EAX), \ + __cpu_feature_word(15, 0x8000000a, 0, CPUID_EDX), \ + __cpu_feature_word(16, 0x7, 0, CPUID_ECX), \ + __cpu_feature_word(17, 0x4c780001, 1, CPUID_EAX), \ + __cpu_feature_word(18, 0x7, 0, CPUID_EDX), \ + __cpu_feature_word(19, 0x8000001f, 0, CPUID_EAX), \ + __cpu_feature_word(20, 0x80000021, 0, CPUID_EAX), \ + __cpu_feature_word(21, 0x4c780001, 1, CPUID_EBX), \ + __cpu_feature_word(__BUG(0), 0x4c780002, 0, CPUID_EAX), \ + __cpu_feature_word(__BUG(1), 0x4c780002, 0, CPUID_EBX), \ +} + #endif /* _ASM_X86_CPUID_TYPES_H */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 335FA480328 for ; Thu, 28 May 2026 15:45:50 +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=1779983157; cv=none; b=TE8RjiaD5M4Fx2mGOnSFnOyut09dT8usjnbKFZ246VBbVn2N4A5+8lnLwTvgptHSUnFsXTmlqakdBpLNrrvrs1KI5s/3s3fvwjkQAD1o/WtoZQreZziBJZOUAG/bQltrSMRjlFToAIsLZxgr3bU/Uqochk9nNnmg+1R9GXW51yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983157; c=relaxed/simple; bh=CrixgFgtmFg1mHoLKm5+K6Zcps4vf0dZAyqszPxBEbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qyMkQkFOXs9Hy7wOnqyHj7LrUit45KmqagbJEDi7NZXEoaPAEP+OF0BcLjT0E+CAPQRZr9Eq6wZ1MdZKz+iKG4CpP2SZ0x4vukBIMS/YZ/ZjdXzqQxL53qyrhbfAKSffZme0F0ZtMDUWtFiXbj4vYl8ngIJJHvQdU1s6aifGUt4= 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=TGV1ik+y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JQ/1TW+V; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TGV1ik+y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JQ/1TW+V" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lP6ersgMpmH4epNlmF/TFLHGTSSP8tAphSitkWlaXQ0=; b=TGV1ik+yaKz8VbcQVZJx75Mv+S6YdpyzK401ciVwnqATtCG2s2sSyzR+n8WrF28eyBtNMR b9pRw7EBwfrzOxTCYy+4QK9CXoWU9ffwaoiMrPC4pGfAcP1qP76XOQ7KaXmlcOTd26cpr/ TTUCNmlHcnQE1NkUhFPwLxog2sO858hdsxPWSDh0taeF/5vJntSu12SsYIsgE4ZdfYU2/d xG3NYqLQCHiShnR0rE8nLfOHt0/AQfrt8oKoCa9NtQ56YBTTzzzpODHgcC3QzfdwebPVch GdDVavGw80G9gVT+BTIBvKzzEgMa0IVsCCvuuigmxb9o25HI/NEuct+jVqzPKA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lP6ersgMpmH4epNlmF/TFLHGTSSP8tAphSitkWlaXQ0=; b=JQ/1TW+V42xx6yyy/xL515whPZ0XJsy/xzt3agSDLfeo04MvA/cx7yTsQB/DkDt7wiPNtn nfi1+u+wC1VP3pCg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 110/120] x86/cpuid: Introduce X86_FEATURE and CPUID word APIs Date: Thu, 28 May 2026 17:39:12 +0200 Message-ID: <20260528153923.403473-111-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce helper APIs to translate: - X86_FEATURE symbols from - CPUID word indices from into offsets within the cached CPUID tables. These helpers will be used to route all X86_FEATURE and CPUID word querying into the centralized CPUID tables, instead of their current routing to cpuinfo_x86::x86_capability[]. Thus removing the latter from the kernel. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/api.h | 125 +++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/arch/x86/include/asm/cpuid/api.h b/arch/x86/include/asm/cpuid/= api.h index 1c0bb7ed4d45..efa1e924d6d3 100644 --- a/arch/x86/include/asm/cpuid/api.h +++ b/arch/x86/include/asm/cpuid/api.h @@ -535,6 +535,131 @@ static inline bool cpuid_amd_hygon_has_l3_cache(struc= t cpuinfo_x86 *c) return el6 && el6->l3_assoc; } =20 +/* + * X86_FEATURE mapping: + * + * These macros are for the internal X86_FEATURE queryi= ng. + * Do everything at compile-time to preserve that header's query optimizat= ions. + * + * @_feature: X86_FEATURE symbol + */ + +#define __feature_word(_feature) ((_feature) / 32) +#define __feature_word_bit(_feature) ((_feature) % 32) + +/* + * Return cached CPUID output offset for @_feature; within 'struct cpuid_l= eaves'. + */ +#define __feature_byte_offset(_feature) \ +({ \ + struct cpuid_cpufeature ____map[] =3D CPUID_FEATURE_WORDS_MAP; \ + unsigned int ____word =3D __feature_word(_feature); \ + \ + ____map[____word].leaves_offset; \ +}) + +/* + * Return CPUID output register for @_feature; i.e., CPUID_EAX -> CPUID_ED= X. + */ +#define __feature_register(_feature) \ +({ \ + struct cpuid_cpufeature ____map[] =3D CPUID_FEATURE_WORDS_MAP; \ + unsigned int ____word =3D __feature_word(_feature); \ + \ + ____map[____word].cpuid_reg; \ +}) + +/* + * Return bit offset for @_feature. This is for bitops, where the offset = is + * relative to ((u8 *)&cpuid_leaves + __feature_byte_offset(@_feature)). + */ +#define __feature_bit_offset(_feature) \ +({ \ + 32 * __feature_register(_feature) + __feature_word_bit(_feature); \ +}) + +/** + * cpuid_feature_byte_offset() - Return X86_FEATURE byte offset + * @_feature: X86_FEATURE symbol from + * + * Return CPUID table 'struct cpuid_leaves' byte offset, for @_feature. + */ +#define cpuid_feature_byte_offset(_feature) __feature_byte_offset(_feature) + +/** + * cpuid_feature_bitmap() - Return X86_FEATURE bitmap + * @_cpuinfo: CPU capability structure ('struct cpuinfo_x86') + * @_feature: X86_FEATURE symbol from + * + * Return CPUID table bitmap, within @_cpuinfo, for @_feature. The return= ed + * bitmap is unsigned long aligned, for bitops access. + */ +#define cpuid_feature_bitmap(_cpuinfo, _feature) \ + (unsigned long *)((u8 *)&(_cpuinfo)->cpuid.leaves + __feature_byte_offset= (_feature)) + +/** + * cpuid_feature_bit_offset() + * @_feature: X86_FEATURE symbol from + * + * Return CPUID table bit offset, for @_feature, within the bitmap returne= d by + * cpuid_feature_bitmap(). + */ +#define cpuid_feature_bit_offset(_feature) __feature_bit_offset(_feature) + +/* + * CPUID word mapping: + */ + +static inline u32 *__cpuid_word_address(struct cpuinfo_x86 *c, u16 word) +{ + u16 feature =3D word * 32; + + return (u32 *)cpuid_feature_bitmap(c, feature) + __feature_register(featu= re); +} + +/** + * cpuid_word() - Return the CPUID word's raw u32 value + * @c: CPU capability structure ('struct cpuinfo_x86') + * @word: CPUID word number as defined at "enum cpuid_leafs" + */ +static inline u32 cpuid_word(struct cpuinfo_x86 *c, u16 word) +{ + return *__cpuid_word_address(c, word); +} + +/** + * cpuid_word_set() - Set the CPUID word's raw u32 value + * @c: CPU capability structure ('struct cpuinfo_x86') + * @word: CPUID word number as defined at "enum cpuid_leafs" + * @val: Raw u32 value to set the word to + */ +static inline void cpuid_word_set(struct cpuinfo_x86 *c, u16 word, u32 val) +{ + *__cpuid_word_address(c, word) =3D val; +} + +/** + * cpuid_word_set_bits() - Set bits at CPUID word according to passed map + * @c: CPU capability structure ('struct cpuinfo_x86') + * @word: CPUID word number as defined at "enum cpuid_leafs" + * @map: Map of bits to be set + */ +static inline void cpuid_word_set_bits(struct cpuinfo_x86 *c, u16 word, u3= 2 map) +{ + *__cpuid_word_address(c, word) |=3D map; +} + +/** + * cpuid_word_clear_bits() - Clear bits at CPUID word according to passed = map + * @c: CPU capability structure ('struct cpuinfo_x86') + * @word: CPUID word number as defined at "enum cpuid_leafs" + * @map: Map of bits to be cleared + */ +static inline void cpuid_word_clear_bits(struct cpuinfo_x86 *c, u16 word, = u32 map) +{ + *__cpuid_word_address(c, word) &=3D ~map; +} + /* * CPUID parser exported APIs: */ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 1669847F2E5 for ; Thu, 28 May 2026 15:45:54 +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=1779983159; cv=none; b=rlipIcXkVaSdqsPLI7muddsDuzz1HpgRr+tpWfFVbPDWEio/U/MXCRIx/5B8VKTDQ+G/wnAt5lhsQGPTqQe0Xslr8yc48cHRFH2yLgFsgFsEavFwsHarWjPBaqkT3nRuXmINy7WE+7q0BdaG2LFlvx1QvM4POA/eCFEB23ELghg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983159; c=relaxed/simple; bh=iYl1o7pffe54rRCv2+GpMYL0NBAoEC4t7k5pUMXDE6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H3sb/8bkNqML7DlFN64Umn5tntBCHkN1ov/PWaDfU31eeYqpTgQCyRDRv9sE6YYRn2hjapqN95zayOx80kb4ZI/c126+XPQt56Aifw6Iq1b05NnZQjOZq20UwlMR/x05ICuxBQ/9B4IApSKQbs9pdEFjnZjADM6xeMCnt2MPkIM= 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=BKGBb2qE; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yfTSUyBj; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BKGBb2qE"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yfTSUyBj" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yAiB+kWZAA0BC3O8l7lcQ9GmdFwRRVMBmwOZGoqly6E=; b=BKGBb2qEPOo+Hik+tjiOKO2+ZeMSBp5oMpAMNAkMjtq7iWpokLdREwtNzC84lwce8F5buV wef/TBmk+evluLyMOwvJo6LyI5j9VpKJLNATJ5eW9BLQlUCtB9cRPK51m0li4/KjjLrQpy J+FnITcm5qQ8q18LCn/qKu8sP2E1GSdTg17bkR39jRP0+Qwumf2HryHbUBKuCh9G1z+PY1 dxq7va0x5iECKLLNsYxe/EpJz36xaTTb9iTx8V/BsWOGA27I4+igv5a+tIJ//4DK4bRmkY Hei/Y0URO+annhrnBVzX7RmTHnPUPdmMlQA84DEcNW2YMsNLW20HaxIgzreYFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yAiB+kWZAA0BC3O8l7lcQ9GmdFwRRVMBmwOZGoqly6E=; b=yfTSUyBj/qlaNPk+Nt3xJNbQKeapCTjbNGKxFix6F1N9PFTIJxU8O0PdLL//t2SYmR5Auu k+/3yIJU8JS00uDw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 111/120] x86/percpu: Add offset argument to x86_this_cpu_test_bit() Date: Thu, 28 May 2026 17:39:13 +0200 Message-ID: <20260528153923.403473-112-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" x86_this_cpu_test_bit() assumes that the queried bitmap starts at the base address of the percpu object. For X86_FEATURE bitops, this matches the current cpuinfo_x86::x86_capability[] layout. Upcoming changes though will route all X86_FEATURE queries to the CPUID tables, where the bitmap resides at the per-CPU CPUID table plus an offset. Add an offset argument to x86_this_cpu_test_bit(). Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpufeature.h | 2 +- arch/x86/include/asm/percpu.h | 34 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index 520949560138..b12bde4986b5 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -56,7 +56,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; =20 #define this_cpu_has(bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ - x86_this_cpu_test_bit(bit, cpu_info.x86_capability)) + x86_this_cpu_test_bit(bit, cpu_info.x86_capability, 0)) =20 /* * This is the default CPU features testing macro to use in code. diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index 409981468cba..8a36f0bb979d 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -89,15 +89,17 @@ #endif /* CONFIG_SMP */ =20 #if defined(CONFIG_USE_X86_SEG_SUPPORT) && defined(USE_TYPEOF_UNQUAL) -# define __my_cpu_type(var) typeof(var) -# define __my_cpu_ptr(ptr) (ptr) -# define __my_cpu_var(var) (var) +# define __my_cpu_type(var) typeof(var) +# define __my_cpu_ptr(ptr) (ptr) +# define __my_cpu_ptr_off(ptr, off) (typeof(ptr))((uintptr_t)(ptr) + (off)) +# define __my_cpu_var(var) (var) =20 -# define __percpu_qual __percpu_seg_override +# define __percpu_qual __percpu_seg_override #else -# define __my_cpu_type(var) typeof(var) __percpu_seg_override -# define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr) -# define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) +# define __my_cpu_type(var) typeof(var) __percpu_seg_override +# define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(pt= r) +# define __my_cpu_ptr_off(ptr, off) (__my_cpu_type(*(ptr))*)((__force uint= ptr_t)(ptr) + (off)) +# define __my_cpu_var(var) (*__my_cpu_ptr(&(var))) #endif =20 #define __force_percpu_arg(x) __force_percpu_prefix "%" #x @@ -570,29 +572,33 @@ do { \ */ #define this_cpu_read_stable(pcp) __pcpu_size_call_return(this_cpu_read_= stable_, pcp) =20 -#define x86_this_cpu_constant_test_bit(_nr, _var) \ +#define x86_this_cpu_constant_test_bit(_nr, _var, _offset) \ ({ \ unsigned long __percpu *addr__ =3D \ - (unsigned long __percpu *)&(_var) + BIT_WORD(_nr); \ + (unsigned long __percpu *)((u8 __percpu *)&(_var) + (_offset)) +\ + BIT_WORD(_nr); \ + \ + /* Ensure bitops safety */ \ + BUILD_BUG_ON(!IS_ALIGNED((unsigned long)(_offset), sizeof(unsigned long))= );\ \ !!(BIT_MASK(_nr) & raw_cpu_read(*addr__)); \ }) =20 -#define x86_this_cpu_variable_test_bit(_nr, _var) \ +#define x86_this_cpu_variable_test_bit(_nr, _var, _offset) \ ({ \ bool oldbit; \ \ asm volatile("btl %[nr], " __percpu_arg([var]) \ : "=3D@ccc" (oldbit) \ - : [var] "m" (__my_cpu_var(_var)), \ + : [var] "m" (*__my_cpu_ptr_off(&(_var), _offset)), \ [nr] "rI" (_nr)); \ oldbit; \ }) =20 -#define x86_this_cpu_test_bit(_nr, _var) \ +#define x86_this_cpu_test_bit(_nr, _var, _offset) \ (__builtin_constant_p(_nr) \ - ? x86_this_cpu_constant_test_bit(_nr, _var) \ - : x86_this_cpu_variable_test_bit(_nr, _var)) + ? x86_this_cpu_constant_test_bit(_nr, _var, _offset) \ + : x86_this_cpu_variable_test_bit(_nr, _var, _offset)) =20 =20 #include --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 22C91480332 for ; Thu, 28 May 2026 15:45:58 +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=1779983161; cv=none; b=LLFEJ6HPKKPmfvaUitfxrD/mHM3NlQjvt4mi/NCe8+7YgFUEsnJnSFffDLQJq/JgTnEVs25s1MkixgXJOJArr0gWPYXU8i9+/RFf6oyHhBUii7dpv0GGx7CsXMi7Ilhsb8fokw98j2bCJrnMie1wMNdwz+UADc8YfN8D3DaXY6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983161; c=relaxed/simple; bh=K9j2/WlVWhjCqAJmD0adWgGGyqwMcXKARxbjL9bDzGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bWUiX+EZNCIVLSkztqrlzmC4pXqYITkI3kmVmiP579We4FTkXgZDfokbzzNduquyzSUBE0/iBq6Qeonc6Laq256TJuro2GZ31q7QjbHNroCyipnsBw5uol+TjjXhRBMGp9y/JWoD87ac+19MrhLTgFRWqHIw+fuFu/U0ANy2HF4= 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=PisIygss; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TFxIEvly; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="PisIygss"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TFxIEvly" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f45qYuzQRP0FuT9KNF1JajDuu9b/pV8A8JURH7HJwvA=; b=PisIygssCdMMzz3gDJLoUfc0gON0pjwr5x8eZKBT64iUiHd+efSHRBzK3ijCnByxAsLM54 Pvfe97bcWe0fvfmLNbIOTOgjUyr3bvuCYcp1AxFcpOObK24gOFx1S4h7fDNV7n0O14CRx0 q9h3+yzNzx+R05rmGxiau7O9niZ+9wBAAK7sW6JMS/ZAA8rv3uMrwV5KVgNJYchwHb2u5Z IGmV6eOORf4e6RmI4AIpsNNNihUlSkULebMVBKAg9i4ewD1vGg6brwFsr1+F3h8siAn0aa rYzab2tHQbtuiybraucVEs/W6+MFlHfggFLCHJDHqFBpwjht7oStDG9Mh4PM0Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f45qYuzQRP0FuT9KNF1JajDuu9b/pV8A8JURH7HJwvA=; b=TFxIEvly4hv5UefRbrMABCbW+dYQLuJYhqYowUd64sm4/rKhdw8m00XqP3225tuqwnNxUs IY9zVR8nCHCZo6CA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 112/120] x86/cpufeature: Factor out a __static_cpu_has() helper Date: Thu, 28 May 2026 17:39:14 +0200 Message-ID: <20260528153923.403473-113-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Later changes will route X86_FEATURE querying to centralized CPUID tables. In that case, the X86_FEATURE's bit value from is different from the bitmap's own bit value to be checked by the fallback capability-byte "testb" check. Factor the asm goto fallback code out of _static_cpu_has() and into __static_cpu_has(). Pass the X86_FEATURE bit, and the bitmap offset bit, separately. No functional change intended. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpufeature.h | 44 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index b12bde4986b5..48643b4b1e24 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -90,29 +90,33 @@ void check_cpufeature_deps(struct cpuinfo_x86 *c); #define setup_force_cpu_bug(bit) setup_force_cpu_cap(bit) =20 /* - * Do not use an "m" constraint for [cap_byte] here: gcc doesn't know - * that this is only used on a fallback path and will sometimes cause - * it to manifest the address of boot_cpu_data in a register, fouling - * the mainline (post-initialization) code. + * Helper macro for CPU feature detection with alternative instructions. + * + * Do not use an "m" constraint for [cap_byte]: GCC does not know that thi= s is + * only used on a fallback path and will sometimes manifest the address of + * boot_cpu_data in a register, fouling the mainline post-initialization c= ode. */ +#define __static_cpu_has(_feature_bit, _bitmap, _bitmap_bit) \ + asm goto(ALTERNATIVE_TERNARY("jmp 6f", %c[feature], "", "jmp %l[t_no]") \ + ".pushsection .altinstr_aux,\"ax\"\n" \ + "6:\n" \ + ANNOTATE_DATA_SPECIAL "\n" \ + " testb %[bitnum], %a[cap_byte]\n" \ + " jnz %l[t_yes]\n" \ + " jmp %l[t_no]\n" \ + ".popsection\n" \ + : : [feature] "i" (_feature_bit), \ + [bitnum] "i" (1 << ((_bitmap_bit) & 7)), \ + [cap_byte] "i" (&((const char *)(_bitmap))[(_bitmap_bit) >> 3]) \ + : : t_yes, t_no); \ + t_yes: \ + return true; \ + t_no: \ + return false \ + static __always_inline bool _static_cpu_has(u16 bit) { - asm goto(ALTERNATIVE_TERNARY("jmp 6f", %c[feature], "", "jmp %l[t_no]") - ".pushsection .altinstr_aux,\"ax\"\n" - "6:\n" - ANNOTATE_DATA_SPECIAL "\n" - " testb %[bitnum], %a[cap_byte]\n" - " jnz %l[t_yes]\n" - " jmp %l[t_no]\n" - ".popsection\n" - : : [feature] "i" (bit), - [bitnum] "i" (1 << (bit & 7)), - [cap_byte] "i" (&((const char *)boot_cpu_data.x86_capability)[bit >= > 3]) - : : t_yes, t_no); -t_yes: - return true; -t_no: - return false; + __static_cpu_has(bit, &boot_cpu_data.x86_capability, bit); } =20 #define static_cpu_has(bit) \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 55D2847F2D8 for ; Thu, 28 May 2026 15:46:01 +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=1779983164; cv=none; b=koUIy2cLeZDpM5cKl0FQLNTJwYajVyxKZwNVWKa0UPRWIxkJkKBizYXJ9dnUQ9p9g45R41uyehpwEfx4/HylxWwoUJ4ph0syQdDFLQLlTYMhfXpc2xalsi/9e8/dLBgovQTfm5idx89U1zyCdgFTzyd7RqmTgXBr+Ne7KuLCq2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983164; c=relaxed/simple; bh=v5dEQN/5OtFimdbi2W5aWc3hjPbjR04LM+TQb5t8uWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nwjadx7ykH5wovTNijMTeiYhvnvp4lmRzUN7T60Bcju+vZfB+s+ZfKYM5PuyXNokkcUips8Ffg8t3TEP62XsPkbn4CHn92ZtF31Q6P8mhOrS97V3lgSlLiHi1FfrTsiIeBKGFAUobGf/rm3YwWatTaTwSH/9I8/zl2K5TC1TLGQ= 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=xDnt6ySv; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QgssBaBn; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xDnt6ySv"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QgssBaBn" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VoTSC6BEeBdJZhx5ZUeoYzL3q1EhGIOH0U60+M3kJmk=; b=xDnt6ySvdDAHIGPGUaiPHyCtqOEHraWEI8j5VYjBi7uyKnhwNdzgPjljfDN9Za0LRWmf5T U+Rknat25CvdkP4oqt9DJqrty5WO5rKsjeBQH2dIZMfq1Mpya0eyiaAhoWj9HwFeadN/pu HUB1LKyvzC23ZbBnbrgwxBZRPcJcYLZv8k6N24LSphULL6WOzV44fyITDYxpsR+F6xis/3 APHgZNStP+Shpz6moigAZ2HW/ekEGj3XIdOyLZvb/o2fOL8jgqIypTRpPD6HQMfNm2nht1 U6u5im4N3bWsc8uaC3YdfGgjZMoAldxFveQHKEGNBIfizPISgo4Hq12CixomBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VoTSC6BEeBdJZhx5ZUeoYzL3q1EhGIOH0U60+M3kJmk=; b=QgssBaBnNYG790nxeoSyKAYt+RdeIgWxyRHgobwh9kXiuxwXKosrhOJ0k8ybRCFo2I9FBN phxTyoflDjXVBJAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 113/120] x86/asm/32: Cache CPUID(0x1).EDX in cpuid_table Date: Thu, 28 May 2026 17:39:15 +0200 Message-ID: <20260528153923.403473-114-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The x86-32 early boot code initializes new_cpu_data from the boot CPU and stores CPUID(0x1).EDX in cpuinfo_x86::x86_capability[]. Introduce the CPUINFO_CPUID_0x1_EDX asm-offset, and store %edx in the cached CPUID table entry for new_cpu_data. This prepares for the removal of cpuinfo_x86::x86_capability[]. Note that the definition of CPUINFO_CPUID_0x1_EDX is much more complex than X86_CAPABILITY, even though both are used as: movl $1,%eax cpuid ... movl %edx,X86_CAPABILITY movl %edx,CPUINFO_CPUID_0x1_EDX This is because CPUID(0x1).EDX is conveniently the first word of cpuinfo_x86::x86_capability[], but not of cpuinfo_x86::cpuid_table. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/asm-offsets.c | 5 +++++ arch/x86/kernel/head_32.S | 2 ++ 2 files changed, 7 insertions(+) diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c index 081816888f7a..0bc36d617801 100644 --- a/arch/x86/kernel/asm-offsets.c +++ b/arch/x86/kernel/asm-offsets.c @@ -40,6 +40,11 @@ static void __used common(void) OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level); OFFSET(CPUINFO_x86_capability, cpuinfo_x86, x86_capability); OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id); + DEFINE(CPUINFO_CPUID_0x1_EDX, + offsetof(struct cpuinfo_x86, cpuid) + + offsetof(struct cpuid_table, leaves) + + offsetof(struct cpuid_leaves, leaf_0x1_0) + + offsetof(struct cpuid_regs, edx)); =20 BLANK(); OFFSET(TASK_threadsp, task_struct, thread.sp); diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S index 5171cb746444..9c96fdf66aa9 100644 --- a/arch/x86/kernel/head_32.S +++ b/arch/x86/kernel/head_32.S @@ -43,6 +43,7 @@ #define X86_CPUID new_cpu_data+CPUINFO_cpuid_level #define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability #define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id +#define X86_FEATUREFLAG new_cpu_data+CPUINFO_CPUID_0x1_EDX =20 /* * Worst-case size of the kernel mapping we need to make: @@ -263,6 +264,7 @@ SYM_FUNC_START(startup_32_smp) andb $0x0f,%cl # mask mask revision movb %cl,X86_STEPPING movl %edx,X86_CAPABILITY + movl %edx,X86_FEATUREFLAG =20 .Lis486: movl $0x50022,%ecx # set AM, WP, NE and MP --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 52A9C480947 for ; Thu, 28 May 2026 15:46:04 +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=1779983167; cv=none; b=koF3c4REC5kzEr9oyDLluAKjx2o+IQ6QW/SnOGOdPhQ64cNpFCcQGBuOoX7Y4GUSeDM4lpKRs4+zJz2mk3HNaoMNp9UFgW4Xy/yXKhlsrKrXWwJAPG9RxWUL+NJ86Jb1unMsvlEsgxe4Bv0gneVqXYXO6chqgxX2NEMYcLDqmKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983167; c=relaxed/simple; bh=hdQtjDUOkOlQaCBA35rfc5359lfl0sf2nJ71Nil9l6Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ITPTH/nt9d5knJys3mudUbcnoSD+DyvGhx0WoYzQQTElHN9ctz/WSSkNpxcBy8aRBwTP9lv3SGM2K8CsOvq3g/8lULFj/+cIorEWFmWMFDwiROqo92IiFW3dtAtZno3plTqSLId4iabLWRkMhgFob2NkF2glwwo8FYJxwRjpyiQ= 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=dzKeiZJ8; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZoCoy0p0; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dzKeiZJ8"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZoCoy0p0" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=82Qq4fMjZ7hLOeObyY1Y0tNKkDVJXtBv4FJz4MaCLGU=; b=dzKeiZJ8Yk8t99R52vaJYnoVoGm1IwmQXu9Gl+FJQLSrCA9MbgVdJ3o5KNNbl8sQwjQlYg u1I2kPE52O6XiPezlUDOyddcKmQIZCIcmZR/Z+qQhSnN+KjZbOMzOqcIeXLYKxWxvqqbE6 EBDjRYaCf93pAjCZhvL5BF31tRU3HlTmPsdsCGNo7TbwvteLSyIIqgkUeBIMO8Mz+1uxex jbuq2yRrkW4Vw96bbKvwWjl95DpvXc6AMMh+olb59Q5APwypfme8isTHXORt0VmvNC27SZ 8MgRpq9sVGCGtFDqJ83CNaPLrM0jrXL2jk/hzi+05MDdKWg0TnuwsRxfPb0FDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=82Qq4fMjZ7hLOeObyY1Y0tNKkDVJXtBv4FJz4MaCLGU=; b=ZoCoy0p0s9ss/ASAaLiBvOcfZ8AM6Oy2CiQ2Mdh9wlyhznn0RZugUkp399SpEu2o4iLAqT 72x2G4h9BFIX4OAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 114/120] x86: Route all feature queries to the CPUID tables Date: Thu, 28 May 2026 17:39:16 +0200 Message-ID: <20260528153923.403473-115-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the CPUID API's cpuid_feature_*() and cpuid_word_*() helpers to route all feature querying to the CPUID tables instead of to x86_capability[]. This allows the CPUID tables to act as a single source of truth for x86 feature state; both hardware-backed and synthetic. Do this routing in one shot, not to fragment x86 state tracking between CPUID tables and x86_capability[]. The latter will be fully removed. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpufeature.h | 12 ++++++--- arch/x86/include/asm/elf.h | 2 +- arch/x86/kernel/cpu/common.c | 41 +++++++++++++++++-------------- arch/x86/kernel/cpu/cpuid-deps.c | 2 +- arch/x86/kernel/mpparse.c | 2 +- arch/x86/kvm/cpuid.c | 3 +-- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufe= ature.h index 48643b4b1e24..58d5e4f3891c 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -10,6 +10,7 @@ #include #include #include +#include =20 enum cpuid_leafs { @@ -48,7 +49,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; #define x86_bug_flag(flag) x86_bug_flags[flag] =20 #define test_cpu_cap(c, bit) \ - arch_test_bit(bit, (unsigned long *)((c)->x86_capability)) + arch_test_bit(cpuid_feature_bit_offset(bit), cpuid_feature_bitmap(c, bit)) =20 #define cpu_has(c, bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ @@ -56,7 +57,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; =20 #define this_cpu_has(bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \ - x86_this_cpu_test_bit(bit, cpu_info.x86_capability, 0)) + x86_this_cpu_test_bit(cpuid_feature_bit_offset(bit), cpu_info.cpuid.leav= es, cpuid_feature_byte_offset(bit))) =20 /* * This is the default CPU features testing macro to use in code. @@ -72,7 +73,8 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; =20 #define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit) =20 -#define set_cpu_cap(c, bit) set_bit(bit, (unsigned long *)((c)->x86_capabi= lity)) +#define set_cpu_cap(c, bit) \ + set_bit(cpuid_feature_bit_offset(bit), cpuid_feature_bitmap(c, bit)) =20 extern void setup_clear_cpu_cap(unsigned int bit); extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit); @@ -116,7 +118,9 @@ void check_cpufeature_deps(struct cpuinfo_x86 *c); =20 static __always_inline bool _static_cpu_has(u16 bit) { - __static_cpu_has(bit, &boot_cpu_data.x86_capability, bit); + __static_cpu_has(bit, + cpuid_feature_bitmap(&boot_cpu_data, bit), + cpuid_feature_bit_offset(bit)); } =20 #define static_cpu_has(bit) \ diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index c7f98977663c..abf3142bb255 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -238,7 +238,7 @@ extern int force_personality32; instruction set this CPU supports. This could be done in user space, but it's not easy, and we've already done it here. */ =20 -#define ELF_HWCAP (boot_cpu_data.x86_capability[CPUID_1_EDX]) +#define ELF_HWCAP cpuid_word(&boot_cpu_data, CPUID_1_EDX) =20 extern u32 elf_hwcap2; =20 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index f5e3aaed67ef..d6b3550b9f11 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -970,11 +970,9 @@ void cpu_detect(struct cpuinfo_x86 *c) =20 static void apply_forced_caps(struct cpuinfo_x86 *c) { - int i; - - for (i =3D 0; i < NCAPINTS + NBUGINTS; i++) { - c->x86_capability[i] &=3D ~cpu_caps_cleared[i]; - c->x86_capability[i] |=3D cpu_caps_set[i]; + for (int i =3D 0; i < NCAPINTS + NBUGINTS; i++) { + cpuid_word_clear_bits(c, i, cpu_caps_cleared[i]); + cpuid_word_set_bits(c, i, cpu_caps_set[i]); } } =20 @@ -2004,8 +2002,6 @@ static void generic_identify(struct cpuinfo_x86 *c) */ static void identify_cpu(struct cpuinfo_x86 *c) { - int i; - c->loops_per_jiffy =3D loops_per_jiffy; c->x86_cache_size =3D 0; c->x86_vendor =3D X86_VENDOR_UNKNOWN; @@ -2107,13 +2103,13 @@ static void identify_cpu(struct cpuinfo_x86 *c) * executed, c =3D=3D &boot_cpu_data. */ if (c !=3D &boot_cpu_data) { - /* AND the already accumulated flags with these */ - for (i =3D 0; i < NCAPINTS; i++) - boot_cpu_data.x86_capability[i] &=3D c->x86_capability[i]; + /* Clear boot_cpu_data features that are not on this CPU */ + for (int i =3D 0; i < NCAPINTS; i++) + cpuid_word_clear_bits(&boot_cpu_data, i, ~cpuid_word(c, i)); =20 - /* OR, i.e. replicate the bug flags */ - for (i =3D NCAPINTS; i < NCAPINTS + NBUGINTS; i++) - c->x86_capability[i] |=3D boot_cpu_data.x86_capability[i]; + /* Replicate boot_cpu_data's bug flags to this CPU */ + for (int i =3D NCAPINTS; i < NCAPINTS + NBUGINTS; i++) + cpuid_word_set_bits(c, i, cpuid_word(&boot_cpu_data, i)); } =20 ppin_init(c); @@ -2529,12 +2525,17 @@ void cpu_init(void) */ void store_cpu_caps(struct cpuinfo_x86 *curr_info) { + const struct leaf_0x0_0 *l0; + /* Reload CPUID max function as it might've changed. */ - curr_info->cpuid_level =3D cpuid_eax(0); + cpuid_refresh_leaf(curr_info, 0x0); + l0 =3D cpuid_leaf(curr_info, 0x0); + if (l0) + curr_info->cpuid_level =3D l0->max_std_leaf; =20 /* Copy all capability leafs and pick up the synthetic ones. */ - memcpy(&curr_info->x86_capability, &boot_cpu_data.x86_capability, - sizeof(curr_info->x86_capability)); + for (int i =3D 0; i < NCAPINTS + NBUGINTS; i++) + cpuid_word_set(curr_info, i, cpuid_word(&boot_cpu_data, i)); =20 /* Get the hardware CPUID leafs */ get_cpu_cap(curr_info); @@ -2564,10 +2565,12 @@ void microcode_check(struct cpuinfo_x86 *prev_info) =20 store_cpu_caps(curr_info); =20 - if (!memcmp(&prev_info->x86_capability, &curr_info->x86_capability, - sizeof(prev_info->x86_capability))) - return; + for (int i =3D 0; i < NCAPINTS + NBUGINTS; i++) + if (cpuid_word(prev_info, i) !=3D cpuid_word(curr_info, i)) + goto err; =20 + return; +err: pr_warn("x86/CPU: CPU features have changed after loading microcode, but = might not take effect.\n"); pr_warn("x86/CPU: Please consider either early loading through initrd/bui= lt-in or a potential BIOS update.\n"); } diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-d= eps.c index 99801e844b30..da4fc649f857 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -107,7 +107,7 @@ static inline void clear_feature(struct cpuinfo_x86 *c,= unsigned int feature) clear_cpu_cap(&boot_cpu_data, feature); set_bit(feature, (unsigned long *)cpu_caps_cleared); } else { - clear_bit(feature, (unsigned long *)c->x86_capability); + clear_bit(cpuid_feature_bit_offset(feature), cpuid_feature_bitmap(c, fea= ture)); } } =20 diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c index 4a1b1b28abf9..a66f22db640f 100644 --- a/arch/x86/kernel/mpparse.c +++ b/arch/x86/kernel/mpparse.c @@ -384,7 +384,7 @@ static inline void __init construct_default_ISA_mptable= (int mpc_default_type) processor.cpuflag =3D CPU_ENABLED; processor.cpufeature =3D (boot_cpu_data.x86 << 8) | (boot_cpu_data.x86_model << 4) | boot_cpu_data.x86_stepping; - processor.featureflag =3D boot_cpu_data.x86_capability[CPUID_1_EDX]; + processor.featureflag =3D cpuid_word(&boot_cpu_data, CPUID_1_EDX); processor.reserved[0] =3D 0; processor.reserved[1] =3D 0; for (i =3D 0; i < 2; i++) { diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index ad0a5410899d..018cd3078306 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -704,7 +704,6 @@ static __always_inline u32 raw_cpuid_get(struct cpuid_r= eg cpuid) do { \ const struct cpuid_reg cpuid =3D x86_feature_cpuid(leaf * 32); \ const u32 __maybe_unused kvm_cpu_cap_init_in_progress =3D leaf; \ - const u32 *kernel_cpu_caps =3D boot_cpu_data.x86_capability; \ u32 kvm_cpu_cap_passthrough =3D 0; \ u32 kvm_cpu_cap_synthesized =3D 0; \ u32 kvm_cpu_cap_emulated =3D 0; \ @@ -715,7 +714,7 @@ do { \ kvm_cpu_caps[leaf] =3D kvm_cpu_cap_features; \ \ if (leaf < NCAPINTS) \ - kvm_cpu_caps[leaf] &=3D kernel_cpu_caps[leaf]; \ + kvm_cpu_caps[leaf] &=3D cpuid_word(&boot_cpu_data, leaf);\ \ kvm_cpu_caps[leaf] |=3D kvm_cpu_cap_passthrough; \ kvm_cpu_caps[leaf] &=3D (raw_cpuid_get(cpuid) | \ --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 638B448096B for ; Thu, 28 May 2026 15:46:07 +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=1779983169; cv=none; b=s1bKyBsJJbzy+4tE+tbtb+Us0STuEdO9K16ewPzKusm8LFA/eJEELU9YieUXGu64baA8XJG0sj4RftEgKvoPrvDyt9ccm9oUqw4oMpRn5HspLSHOcgDe+u4MC05hB27jHr70WylROR3YRoq8JhKtU017M548IYC2byTuKN4izKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983169; c=relaxed/simple; bh=ClYMYMB+DJcuC/0CGYbYjuXf4kU6sUlmszbs30kV5Os=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WZE+zKWtNHAUfMpHqbIyDAJgoTottawYYDIAazSPz6UuMtvr2MpD8Ar6CrAtda3+94EDYaTx0xeM2epNGLH4fL3wNyHN3KSQZGC5xxd5OB3nQEKfA7djkrzJxOIdB/AdCjRNb6/gz0bht4aP8wgo5ujaksepisFynWjOBgv9FFk= 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=FzidPPfr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=qVPlz115; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FzidPPfr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qVPlz115" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7nCEbPCdbAbCe5gGNYzmr1UTgO0IgjQS43dsg5YKpDg=; b=FzidPPfrrwWf8P/MPgA+B43JZbxhJCMxIl28KHNECTvl0zcihwErsnQczuJ8hNS55nsgDz aaSWf9vIkJKgiD7GvbD1Cc7VskjRgKFc2Mf/aCa8ArIRc1dOAoxGxxh1Trzupu626wi5Kh gjPmFjKPnAR6oL2dUd9UywL56LlkKjV0x9/pW86FKpjS4TegJ5p470dxZIPyx3PyLQ9klS Jhii/B5VT3eiMR9m+F3wOdkMYlypF7HoPEPTjTc3w9tTXqB3KdACguK1eumGhcylGk7HMd QSub42TDpJvMdUq4fWA4AtWFEdv3RRHQw8t/N1RtgOmt2Aa9EhP8gOjpiUsn0g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7nCEbPCdbAbCe5gGNYzmr1UTgO0IgjQS43dsg5YKpDg=; b=qVPlz1156moMY7uOVF52v/jqZjcoWsWyQaQXblX4AtF+v02Nsx/Cz10DyD7s3VLAB+P/HO VdbXC1cxXlGCr+DQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 115/120] x86/cpu: Remove x86_capability[] and x86_power initialization Date: Thu, 28 May 2026 17:39:17 +0200 Message-ID: <20260528153923.403473-116-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X86_FEATURE queries are now routed to the CPUID tables instead of to x86_capability[]. x86_power call sites have all been converted to parsed CPUID(0x80000007) access. Remove all direct CPUID queries which populate x86_capability[] and x86_power. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/common.c | 58 ------------------------------------ 1 file changed, 58 deletions(-) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index d6b3550b9f11..08e7c44dbc77 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1020,70 +1020,12 @@ static void init_speculation_control(struct cpuinfo= _x86 *c) void get_cpu_cap(struct cpuinfo_x86 *c) { const struct leaf_0x80000000_0 *el0; - u32 eax, ebx, ecx, edx; =20 cpuid_scan_cpu(c); =20 - /* Intel-defined flags: level 0x00000001 */ - if (c->cpuid_level >=3D 0x00000001) { - cpuid(0x00000001, &eax, &ebx, &ecx, &edx); - - c->x86_capability[CPUID_1_ECX] =3D ecx; - c->x86_capability[CPUID_1_EDX] =3D edx; - } - - /* Thermal and Power Management Leaf: level 0x00000006 (eax) */ - if (c->cpuid_level >=3D 0x00000006) - c->x86_capability[CPUID_6_EAX] =3D cpuid_eax(0x00000006); - - /* Additional Intel-defined flags: level 0x00000007 */ - if (c->cpuid_level >=3D 0x00000007) { - cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx); - c->x86_capability[CPUID_7_0_EBX] =3D ebx; - c->x86_capability[CPUID_7_ECX] =3D ecx; - c->x86_capability[CPUID_7_EDX] =3D edx; - - /* Check valid sub-leaf index before accessing it */ - if (eax >=3D 1) { - cpuid_count(0x00000007, 1, &eax, &ebx, &ecx, &edx); - c->x86_capability[CPUID_7_1_EAX] =3D eax; - } - } - - /* Extended state features: level 0x0000000d */ - if (c->cpuid_level >=3D 0x0000000d) { - cpuid_count(0x0000000d, 1, &eax, &ebx, &ecx, &edx); - - c->x86_capability[CPUID_D_1_EAX] =3D eax; - } - el0 =3D cpuid_leaf(c, 0x80000000); c->extended_cpuid_level =3D el0 ? el0->max_ext_leaf : 0; =20 - if (c->extended_cpuid_level >=3D 0x80000001) { - cpuid(0x80000001, &eax, &ebx, &ecx, &edx); - - c->x86_capability[CPUID_8000_0001_ECX] =3D ecx; - c->x86_capability[CPUID_8000_0001_EDX] =3D edx; - } - - if (c->extended_cpuid_level >=3D 0x80000007) - c->x86_power =3D cpuid_edx(0x80000007); - - if (c->extended_cpuid_level >=3D 0x80000008) { - cpuid(0x80000008, &eax, &ebx, &ecx, &edx); - c->x86_capability[CPUID_8000_0008_EBX] =3D ebx; - } - - if (c->extended_cpuid_level >=3D 0x8000000a) - c->x86_capability[CPUID_8000_000A_EDX] =3D cpuid_edx(0x8000000a); - - if (c->extended_cpuid_level >=3D 0x8000001f) - c->x86_capability[CPUID_8000_001F_EAX] =3D cpuid_eax(0x8000001f); - - if (c->extended_cpuid_level >=3D 0x80000021) - c->x86_capability[CPUID_8000_0021_EAX] =3D cpuid_eax(0x80000021); - init_scattered_cpuid_features(c); init_speculation_control(c); =20 --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 8668A480DC1 for ; Thu, 28 May 2026 15:46:10 +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=1779983171; cv=none; b=iuk9uiiPwnk+559HJQ7Pd9VBIC3IQw7JD2aKZrVJkpSUJ0CVWXdfRRBjw2K98piAt6k9DudzVuRJIPf2sdlI7bb3V4QP0gS8SQEmbqnLaY5BuLqs6DjR895iXlqsVHHlFshaLddu3Hq58kx3beyIwhzvbEWWzp0vMICFb2g2xx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983171; c=relaxed/simple; bh=GRArbWGCLUNF1IhY4Py7B4eTp8EiDj0kJjX+HC18f9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YLo9Gmo9m9SR3iu/znqGW6mSHIQJuLAxOmsqZqmBhwkizMjKsTKYTgTk0wdxQEY7wkREUYzLCNI7vV9Q1o3rW+k0UKvR4rxabn+C+ZFlU9MOOvylnTQyXxNb03+2L4qYpl6Ks/K0BREqzHN5hyqZWkf4beyZGI+DVByafrOOdZ8= 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=qWImwcKJ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=okTD4S5o; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qWImwcKJ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="okTD4S5o" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N8do4H5kJox+y3INC4ESOvFMwsTpuxfXZFgUnVTKIOU=; b=qWImwcKJ0F7vzv8OXKjESlpzRqq7AotIwU5WRbCbhkwGQ0AHCqkoBR9/PxB5gWMcJBMs8r 9+f55kFjz1gr3oTiFvQ2LjBebg2X19wt2EVZlSmBieBm2T1JjHn64yTurQDONCfWdaBJPS wCI5H9AfkQxLyaU1/fQwI6JLeOkHQi5BqD1TFWyhoD+6SXEuNVLgt2eA7x/4JZQayuokoI +qwb+HXp/B4hnSTZLOdUu/HZnPW419Hs6RJptkddTfKjUXrZ11YipaR/gI5Ujk1S+QtS/w ydmap8krZn/T+4cDjYHQtBEL5DXkh0XOvTxglDS7TaiQzAWh9nZi4zqB0XlfQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N8do4H5kJox+y3INC4ESOvFMwsTpuxfXZFgUnVTKIOU=; b=okTD4S5onIJIlMd6kA84E+zlaO/Bola+X9QtlSDmycNWXF+ThTh2Amrpp47avvZU7ZgIpf Rz//2bGzhYOzEuBQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 116/120] x86/cpu/transmeta: Remove x86_capability[] CPUID initialization Date: Thu, 28 May 2026 17:39:18 +0200 Message-ID: <20260528153923.403473-117-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X86_FEATURE queries are now routed to the CPUID tables instead of to x86_capability[]. Remove all direct CPUID queries which populate x86_capability[]. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/transmeta.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/arch/x86/kernel/cpu/transmeta.c b/arch/x86/kernel/cpu/transmet= a.c index 991e11d5c28a..5e848f4eb5f5 100644 --- a/arch/x86/kernel/cpu/transmeta.c +++ b/arch/x86/kernel/cpu/transmeta.c @@ -10,14 +10,6 @@ =20 #include "cpu.h" =20 -static void early_init_transmeta(struct cpuinfo_x86 *c) -{ - const struct leaf_0x80860000_0 *l =3D cpuid_leaf(c, 0x80860000); - - if (l && l->max_tra_leaf >=3D 0x80860001) - c->x86_capability[CPUID_8086_0001_EDX] =3D cpuid_edx(0x80860001); -} - /* * If CPU revision is 0x02000000, then CPUID(0x80860002) should be used in= stead. */ @@ -75,7 +67,6 @@ static void init_transmeta(struct cpuinfo_x86 *c) { unsigned int cap_mask, uk; =20 - early_init_transmeta(c); cpu_detect_cache_sizes(c); =20 print_cpu_revision(c); @@ -85,7 +76,6 @@ static void init_transmeta(struct cpuinfo_x86 *c) rdmsr(0x80860004, cap_mask, uk); wrmsr(0x80860004, ~0, uk); cpuid_refresh_leaf(c, 0x1); - c->x86_capability[CPUID_1_EDX] =3D cpuid_edx(0x00000001); wrmsr(0x80860004, cap_mask, uk); =20 /* All Transmeta CPUs have a constant TSC */ @@ -103,7 +93,6 @@ static void init_transmeta(struct cpuinfo_x86 *c) static const struct cpu_dev transmeta_cpu_dev =3D { .c_vendor =3D "Transmeta", .c_ident =3D { "GenuineTMx86", "TransmetaCPU" }, - .c_early_init =3D early_init_transmeta, .c_init =3D init_transmeta, .c_x86_vendor =3D X86_VENDOR_TRANSMETA, }; --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 AB6F5480DE2 for ; Thu, 28 May 2026 15:46:13 +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=1779983175; cv=none; b=kVPJRBKD0L+LUY4AokEtGhArbXUl7ku51vWEVoDflOqjHItyPS9GsN55L0Dnp5CJqkZ4Qzt2p7p6x7XgGHzPv5/utGKgAYnXrwcN/uEWc0VVjlcNFbWBoVRP+oxRMbRciJlpbMnJ04r1YCrf87KcDkcWKlCUI6qOHuM7XvvZrqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983175; c=relaxed/simple; bh=eiTjC6XdxxaMaG+n0lN+zFGQdX7SOF0LgoSLd8xT8MI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dJNrchLSmFY+yr/8oxTi8+aS995a0xK4mZc7Xkrrq9BVxWh/yL7LUqidw1lbdKacfoFrCIHoydV5pjVIz6Jwns9Je02GDeJdMcD9QGJxo2uMm34/5f0ghp6SrxykosLb77eehdQK2kMjgk7CQ5B0EYSdXJCT3fzr3d2l6Aosb7c= 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=oRVtuhl5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=QgykNngS; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="oRVtuhl5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QgykNngS" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1yP+ZMRXDKqNHlIBM5skecC+OJMl24gnBBEp9hL2E2M=; b=oRVtuhl5gz4oSFGqv1qiICoL5wXhEH1GGypl3UVlf0RyYnKqEH/EHbZOajw06aV21vT/3r h/XL0hmjVfU+9S0au+Ub29Rywap3VvHmmlj87caNXykyZFUcFAOAsas2aenIoQiSj4v702 4dIIq8N810JfLZdrUiHw2wBDiPN5EIgrmnWksLU9rsNROSqCSSexFoDvMLBsEwQ7p3d00/ zExs9jqsJ0EpC1f1TIkyDTV1vyPHJmH1lBsmZnTMNiTxyCOy/VejJGQH+G/VG0roJeAzkx I3DXTcEUtPOGZslfm2Uzw4TNkjntJozjhy4iRuwNAyegLF1puqdviPZ83rsNXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1yP+ZMRXDKqNHlIBM5skecC+OJMl24gnBBEp9hL2E2M=; b=QgykNngS9pCx8kvQ5SpaBK9cZskQ3p/OINwkO7NPYs818obwFbtc3eSpcblMw7HeMi9fMH 3FGXI1+LX+SMaoDQ== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 117/120] x86/cpu: centaur/zhaoxin: Remove x86_capability[] initialization Date: Thu, 28 May 2026 17:39:19 +0200 Message-ID: <20260528153923.403473-118-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X86_FEATURE queries are now routed to the CPUID tables instead of to x86_capability[]. Remove all direct CPUID queries which populate x86_capability[]. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/centaur.c | 1 - arch/x86/kernel/cpu/zhaoxin.c | 1 - 2 files changed, 2 deletions(-) diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 29688aec2231..8f614003d82c 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -42,7 +42,6 @@ static void init_c3(struct cpuinfo_x86 *c) * EDX feature bits. Refresh the leaf. */ cpuid_refresh_leaf(c, 0xc0000001); - c->x86_capability[CPUID_C000_0001_EDX] =3D cpuid_edx(0xC0000001); } #ifdef CONFIG_X86_32 /* Cyrix III family needs CX8 & PGE explicitly enabled. */ diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index 5918f9387c87..7f576f0296b7 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -41,7 +41,6 @@ static void init_zhaoxin_cap(struct cpuinfo_x86 *c) * EDX feature bits. Refresh the leaf. */ cpuid_refresh_leaf(c, 0xc0000001); - c->x86_capability[CPUID_C000_0001_EDX] =3D cpuid_edx(0xC0000001); } =20 if (c->x86 >=3D 0x6) --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 C85D1406261 for ; Thu, 28 May 2026 15:46:16 +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=1779983178; cv=none; b=WDTUowvK44sc7mikm6N7p28PuKz75f0a6k7Qli65DwTyHpB4hx+cmrzKIyAGAf0eSq2vq8D85Qy8MYMLWmebCJlsUhtrVgS3NK9KWEF/+2aCohIg6C2lLmhXDrLIgkFI7WRjeA+WK6SFwmIZ4fy3ikKSVz/kx5UfivIe0fWzHHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983178; c=relaxed/simple; bh=iBRRLiUxWodNmlPKVM5/jYN886wgy2LwpLWXU0ifRSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u04o1Y0qClLre15ae/qyg+6KOGyVwVtblCW4l11398XbU8bkzeBOAlrXMzAAsVng9Xd+gSGt1Lk+rmZlP62HSx/pgIiDCL6KV0tI9Dzamtuggnt0qaLExRByxP2o+IZk+FZBl1sFtDKmgnFZua23n4ELmqbH0c4jYlgYZG8g9C4= 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=vGmZyLJj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xT2z9PGG; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vGmZyLJj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xT2z9PGG" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JFmlmvv63iXFQkrPpyanL5QtPWMBp2U8gW/uj5jrdfU=; b=vGmZyLJjV1unDtDjk3ZoVZ0621jxGpIxwLwMnuqSRb7qweDPjxqv9zfayl+1n+bxD8AmlC qmURXeVJK/DUKlf0DdD5B2YQmis2qxIxVYoB6RvWJGcEEZXXPPy1922AnsoKJrMnzqf/Pd 0ymcpw5cjObliOZAE4/NfTYPZqgzTmNzMGFQVWqK8XYpEqscGoxAr0vZwO44Ne520q2gDo hfUY1r3lZA/6CVF1rNNf2KtlJACIlwchaAsZNklrRgpLXG7T/AU19CY0CMQ334OQlwl+bU 2qaz5Rgb6vLCow7k3aW9+VRsas4IlfGR8glu/Eu/mh7OY9AJgU2pifXNCwNObA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JFmlmvv63iXFQkrPpyanL5QtPWMBp2U8gW/uj5jrdfU=; b=xT2z9PGGBz0zNM3bSRDRwNp1eOdxelws7dcvGeDiRFwEIIiwNFL5/99YZLxNhUlsU3Z09n QVeSaRutU6lzMFAw== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 118/120] KVM: x86: Remove BUILD_BUG_ON() x86_capability[] check Date: Thu, 28 May 2026 17:39:20 +0200 Message-ID: <20260528153923.403473-119-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" KVM's direct access to cpuinfo_x86::x86_capability[] has been replaced with the cpuid_word_*() APIs. The former is getting removed from the kernel. Adjust the kvm_cpu_caps[] alignment comment accordingly. Remove BUILD_BUG_ON() related to x86_capability[] as it does not matte anymore. Signed-off-by: Ahmed S. Darwish --- arch/x86/kvm/cpuid.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 018cd3078306..5ed45353802b 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -30,8 +30,8 @@ #include "xen.h" =20 /* - * Unlike "struct cpuinfo_x86.x86_capability", kvm_cpu_caps doesn't need t= o be - * aligned to sizeof(unsigned long) because it's not accessed via bitops. + * No unsigned long alignment is needed. The CPUID tables X86_FEATURE + * words are accessed by bitops, but this table is not. */ u32 kvm_cpu_caps[NR_KVM_CPU_CAPS] __read_mostly; EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_cpu_caps); @@ -838,9 +838,6 @@ void kvm_initialize_cpu_caps(void) WARN_ON_ONCE(kvm_is_configuring_cpu_caps); kvm_is_configuring_cpu_caps =3D true; =20 - BUILD_BUG_ON(sizeof(kvm_cpu_caps) - (NKVMCAPINTS * sizeof(*kvm_cpu_caps))= > - sizeof(boot_cpu_data.x86_capability)); - kvm_cpu_cap_init(CPUID_1_ECX, F(XMM3), F(PCLMULQDQ), --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 5944248122F for ; Thu, 28 May 2026 15:46:20 +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=1779983182; cv=none; b=Czo0Vrjl4I4aVG070jI0nbehEO7uXSuD5ZO+4aP8kVbE2xzkLYMdbSlGDEjkM3n3WB21xQC6W5j8RI4pSKAdVf0feEQ/dJ0rG53tM7AiWSYpWxpNaZ1ZSaUiAGXWuWl+JoyNLlB6bER1HcC5URpm2z/srOw1KwBYY2qqsQqmhPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983182; c=relaxed/simple; bh=W7U6wWe/I2+lT3vCDE2qREnRZ9fFkarc9o491wkV1xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2Ul8mB4WQqFlOEYeg7B6hKqH5yXdhClQlSivIKNMM5EJVycEf7v/fEJ7GFgT0f5xrGWm2DrBH2BkQHffGBeNxMoa3QhoErKp6qTSHyfPzb2M9juzAdPzU2QvH7OLOmdL9rdI57Jx7e3XYYiCYXG7ouYzkJoVcLTW6bPcbel91E= 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=z+CaIWz3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UNJ94m7J; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="z+CaIWz3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UNJ94m7J" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OCsDXxYBoKdnZ5dXB3QihAcAs8Sqv94XNjh5VkbTMPk=; b=z+CaIWz3QHqdpDY7NtcPPv2FgZJ9VNULwfL0oh4Y2rOpQlEXTNP1dCrc1bBbN5Io7EcH5b qnwTu44YZjgUfpdAQhfTQnfs9t2b1mQ29CMJSPXZi+TSRiFwpFlJRorVDEz+rKH1xGqVvX r5ZVkdnewdxgAMX1dzCM0r5RfBGwlzqASFbMaet/XzQGFb/jboxTTWsvz9i+8FzCIiDkUS siSTJJF34twfndWcG0auAMrbt10qbeVZcldp8ium6tS0nQXZcb73o9QWqu8bJC3F81p5FR 4IFfeonEcqkW+JWX6J1bB+cbugI8/28Wg7PqKJsbmfzFj1dX2uXLqDh4V3Y0CA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OCsDXxYBoKdnZ5dXB3QihAcAs8Sqv94XNjh5VkbTMPk=; b=UNJ94m7JlxfwqscX7BS8wZGBk+6TauXqTaiUiUUh7zbNqut0jOoHjVWoTPMOl1YVrXqSDg HsyJcYbytUoHtuAg== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 119/120] x86/cpu: Remove x86_capability[] and x86_power Date: Thu, 28 May 2026 17:39:21 +0200 Message-ID: <20260528153923.403473-120-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X86_FEATURE queries are now routed to the CPUID tables instead of to x86_capability[]. x86_power call sites have all been converted to parsed CPUID(0x80000007) access. Remove x86_capability[] and x86_power from struct cpuinfo_x86. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/processor.h | 10 ---------- arch/x86/kernel/asm-offsets.c | 1 - arch/x86/kernel/cpu/common.c | 5 ----- arch/x86/kernel/head_32.S | 2 -- 4 files changed, 18 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index 70c414eab154..cdd6ba7e3e5c 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -158,15 +158,6 @@ struct cpuinfo_x86 { __u32 extended_cpuid_level; /* Maximum supported CPUID level, -1=3Dno CPUID: */ int cpuid_level; - /* - * Align to size of unsigned long because the x86_capability array - * is passed to bitops which require the alignment. Use unnamed - * union to enforce the array is aligned to size of unsigned long. - */ - union { - __u32 x86_capability[NCAPINTS + NBUGINTS]; - unsigned long x86_capability_alignment; - }; char x86_vendor_id[16]; char x86_model_id[64]; struct cpuinfo_topology topo; @@ -178,7 +169,6 @@ struct cpuinfo_x86 { int x86_cache_max_rmid; /* max index */ int x86_cache_occ_scale; /* scale to bytes */ int x86_cache_mbm_width_offset; - int x86_power; unsigned long loops_per_jiffy; /* protected processor identification number */ u64 ppin; diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c index 0bc36d617801..98d2cd03d0af 100644 --- a/arch/x86/kernel/asm-offsets.c +++ b/arch/x86/kernel/asm-offsets.c @@ -38,7 +38,6 @@ static void __used common(void) OFFSET(CPUINFO_x86_model, cpuinfo_x86, x86_model); OFFSET(CPUINFO_x86_stepping, cpuinfo_x86, x86_stepping); OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level); - OFFSET(CPUINFO_x86_capability, cpuinfo_x86, x86_capability); OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id); DEFINE(CPUINFO_CPUID_0x1_EDX, offsetof(struct cpuinfo_x86, cpuid) + diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 08e7c44dbc77..8c52503ae360 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1729,7 +1729,6 @@ static void __init cpu_parse_early_param(void) */ static void __init early_identify_cpu(struct cpuinfo_x86 *c) { - memset(&c->x86_capability, 0, sizeof(c->x86_capability)); memset(&c->cpuid, 0, sizeof(c->cpuid)); c->extended_cpuid_level =3D 0; =20 @@ -1961,7 +1960,6 @@ static void identify_cpu(struct cpuinfo_x86 *c) c->x86_virt_bits =3D 32; #endif c->x86_cache_alignment =3D c->x86_clflush_size; - memset(&c->x86_capability, 0, sizeof(c->x86_capability)); memset(&c->cpuid, 0, sizeof(c->cpuid)); #ifdef CONFIG_X86_VMX_FEATURE_NAMES memset(&c->vmx_capability, 0, sizeof(c->vmx_capability)); @@ -1989,9 +1987,6 @@ static void identify_cpu(struct cpuinfo_x86 *c) * features a certain CPU supports which CPUID doesn't * tell us, CPUID claiming incorrect flags, or other bugs, * we handle them here. - * - * At the end of this section, c->x86_capability better - * indicate the features this CPU genuinely supports! */ if (this_cpu->c_init) this_cpu->c_init(c); diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S index 9c96fdf66aa9..8e90999fbf5b 100644 --- a/arch/x86/kernel/head_32.S +++ b/arch/x86/kernel/head_32.S @@ -41,7 +41,6 @@ #define X86_STEPPING new_cpu_data+CPUINFO_x86_stepping #define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math #define X86_CPUID new_cpu_data+CPUINFO_cpuid_level -#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability #define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id #define X86_FEATUREFLAG new_cpu_data+CPUINFO_CPUID_0x1_EDX =20 @@ -263,7 +262,6 @@ SYM_FUNC_START(startup_32_smp) movb %al,X86_MODEL andb $0x0f,%cl # mask mask revision movb %cl,X86_STEPPING - movl %edx,X86_CAPABILITY movl %edx,X86_FEATUREFLAG =20 .Lis486: --=20 2.54.0 From nobody Mon Jun 8 14:36:11 2026 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 A19AB481235 for ; Thu, 28 May 2026 15:46:23 +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=1779983186; cv=none; b=nVt3ZqJ9xNtB37Rd8btwlCq23IH8csEUk1snloOsmhHoGf+uY27qN3UnJOIPuzeNEKeO2+ejUuyctrOLsalpac455YSFehfLqkwXJ/4W+A7WV3hHAVwUrCaf/GsKsvym8Wx6ipyoFHR7H2ZMt1uEFz297LFfgheDmcyNj+REeVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779983186; c=relaxed/simple; bh=8Dysoy4GcAk7pdX2Dppk+9sUkzCkm3WjcIV7eAxf77c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nayVECaKpOro6y+3nr+XJdRhHhxsj2TKv4RQDE+y7aReMDimYCEv61r6QINEDkJC+NMixS1DVvjFehXDCRf9NfhGuCYjj016FMRKaumP7UCIa1uUfGWIfqRocHS9+m49lMtFh9dnfR3gg4pwbKPCYCVykDOkq8ezqy/QBN5ylw8= 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=VsECp1uS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+4BjLC8G; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="VsECp1uS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+4BjLC8G" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779983182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g0uBWGq3OqkcYh6bkNnYpZN2OjwIrkUnZ89AV24E6zw=; b=VsECp1uSBT8S+VBFVm242FpeJsn58PtuCQrCI5Q5YY4tQiXXRy44dZfiDsumaZvbN1BI76 JRqtMPSfn8V0Yv4surX8EcnLikCvIPaPVdwgOVTAJBLTyo0fAK4mhf2ULt6/Sd30hJ2MOQ nv6S4Ku7HctzfI+v/r2MorLplinj3/NEy/yCl7IQgy7A76HjnWsaj1uHztwD2GJM7VAPKl +i/4k3/Kak3Ay684zFUnVXozIA2Ck07uuC0Yg0lU7r9XuKq+81T5u26VHsfN0R7QX3xxe3 K63hkVMDX6S7/85cIysXUMWMWtRzdPiEXkW/+MT84AlVB+ryC1Q7gLvviVP1iw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779983182; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g0uBWGq3OqkcYh6bkNnYpZN2OjwIrkUnZ89AV24E6zw=; b=+4BjLC8GtBlxzaBcp4KzGJfnRyVJoyuFVLk/ezwNinqvOjg2hlMUOPobYsjsdCM2Fi0O61 HhbEQFcfd8JjqAAA== To: Borislav Petkov , Dave Hansen , Ingo Molnar Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , Christian Ludloff , Maciej Wieczor-Retman , Sohil Mehta , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v7 120/120] MAINTAINERS: Extend x86 CPUID DATABASE file coverage Date: Thu, 28 May 2026 17:39:22 +0200 Message-ID: <20260528153923.403473-121-darwi@linutronix.de> In-Reply-To: <20260528153923.403473-1-darwi@linutronix.de> References: <20260528153923.403473-1-darwi@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add arch/x86/include/asm/cpuid/ since the new CPUID APIs are now at and . The x86-cpuid-db C99 bitfields header is also under that folder. Add arch/x86/include/asm/cpufeature.h since it has the X86_FEATURE word names listing, along with the X86_FEATURE APIs, which are now both routed to the CPUID API. Add arch/x86/include/asm/cpufeatures.h since it has the X86_FEATURE bit listings, where by now new feature bits should only be appended to; never modified in-place. Add arch/x86/kernel/cpu/cpuid_parser.{c,h} since they have the CPUID parser implementation. Adding these files ensures that myself and the x86-cpuid mailing list are CCed on related patches. Signed-off-by: Ahmed S. Darwish --- MAINTAINERS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index a0137a898927..5fe7150a542e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -28869,7 +28869,9 @@ R: Ahmed S. Darwish L: x86-cpuid@lists.linux.dev S: Maintained W: https://x86-cpuid.org -F: arch/x86/include/asm/cpuid/leaf_types.h +F: arch/x86/include/asm/cpufeature*.h +F: arch/x86/include/asm/cpuid/ +F: arch/x86/kernel/cpu/cpuid_parser.* F: tools/arch/x86/kcpuid/ =20 X86 ENTRY CODE --=20 2.54.0