From nobody Wed Apr 1 19:57:17 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 757F61FA164 for ; Tue, 4 Mar 2025 08:52: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=1741078339; cv=none; b=kDwBzOQuhDnq0IVORjzncUwtDQ7k0rAmoesLbkLYm4CkqDFpvG/tPrl9eFaFPvHk7iWwnOyJ5b4HYsnUYGnGGWg6rTUNpsej8Vol7qK7/5dTJdrHB8Id15EGdunnqDjE3CzvesdXT/na9HYOafYPTqx0Bf/o4ionn+BMVWQtr10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078339; c=relaxed/simple; bh=gk5AGbk0kzwhq8R9XZgwdnq/DqFd/AKnMvDgDFnCTTY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H3kTw1HX63isFrkXtGmAruPPewyMO1aoo5oWzJMYOI51YQoKagc/Wan4LMlfLPG9Vo80agh+JtKjjwVKJGlFmqQ/R+5IvFV3G8SeL7ax0T2ZHjtfH17JwxI9MvD1V6AGyV7s/50DWVAZuRgoYutmDFtKZ+v1YeCUcOCgMy8F1Qc= 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=YxhnarNr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ea7GkIjq; 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="YxhnarNr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ea7GkIjq" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078336; 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=j+KvDJVu1Ky1rLsDmAWr+vqFmwFPA2dEWmX61TYg2ck=; b=YxhnarNrSZFVg8S5QCA0TWfCgqorG/tpMyS33ZBS/g+c+wF/lbetZEUj0YhtW5L8aC3huM LIW7USk8D4R6477fnRz8KtrSvz4zeH6k6sPUcEMMPh/NjvBVaqugc8uasXy+JMF0CBkUsz tZpe28QwwkEQj+0sZqLm9aX3yatoE29N2FYP5Y1MXg3xeECvaIZaas14+DuTtd6bLtUAhA QUTBi8dqHkWIL4lpZbeGpPKlqA2tv4QN2++d4mzvVLIKU6pvzWCGX5CRpMo+0AvyY2tVrV cABVlqYDSBxJIvKpmO+gvtL2jeON6IAAAawY/ael/1RXhO1LI7AwgnoZGwTluA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078336; 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=j+KvDJVu1Ky1rLsDmAWr+vqFmwFPA2dEWmX61TYg2ck=; b=ea7GkIjqokwDLLmLGUT/yxdtQh4eS+tkS43jl8GQDSlBVLDanJPfFcPoczAb2Lf6dwXTNZ vtCWSZLV3veBBRAg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 01/40] x86/cacheinfo: Validate cpuid leaf 0x2 EDX output Date: Tue, 4 Mar 2025 09:51:12 +0100 Message-ID: <20250304085152.51092-2-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 emits one-byte descriptors in its four output registers EAX, EBX, ECX, and EDX. For these descriptors to be valid, the most significant bit (MSB) of each register must be clear. The historical git commit (019361a20f016: "- pre6: Intel: start to add Pentium IV specific stuff (128-byte cacheline etc)...") introduced leaf 0x2 output parsing. It only validated the MSBs of EAX, EBX, and ECX, but left EDX unchecked. Validate EDX's most-significant bit. Cc: stable@vger.kernel.org Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index e6fa03ed9172..a6c6bccfa8b8 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -808,7 +808,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]); =20 /* If bit 31 is set, this is an unknown format */ - for (j =3D 0 ; j < 3 ; j++) + for (j =3D 0 ; j < 4 ; j++) if (regs[j] & (1 << 31)) regs[j] =3D 0; =20 --=20 2.48.1 From nobody Wed Apr 1 19:57:17 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 583051FCCE4 for ; Tue, 4 Mar 2025 08:52: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=1741078343; cv=none; b=mMK04qBMXYnZRPhBOjM3cB/lcgIBj9aRYgiA5/An18Zm4aNM+A9aHsF2FD/K0f/ag601y7oVUolm0e9peASbsJO/aXgr2Qgy3zKRAXDtkT8IYyDKfQTnMc+YdLYww6ExN7ExQNbXAEs1b3et1QJwdgGdT5PQZ42KsmRWMhcNK3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078343; c=relaxed/simple; bh=xoCoR4iPrwQyVQGckm5Vqfe5UKuVECUPdXQKBlWYyHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JfREieV4iMIm5l0MRFByOs8suK68zRiw5uYfmC1gjTA54FPfe5bduSluwPv/BGbeFQr3pSoMcHHh2ywdWwxCsuzG7SwZRUco0R2un531Y0FKHZlA6ylCCC+mzXtzUzugNNE8mOIQqGsJG4M/NQWrhtEEkIx4yOyq9UJnaVqGGK4= 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=ekKChPvA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IdU94Jse; 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="ekKChPvA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IdU94Jse" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078339; 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=9YtJrmgYZNvEEH6ObCih4a8AsX+g3T5HhHN+0iOuL38=; b=ekKChPvABa+AY28JUEM6KBebWYtYA3/0dWJWhIZVSAg/H4CoNobegnXz+Yaxg3LrHp+A0g +w8GbXoUe5oNd/gHIIVfBkfVeYgTrqUf2MNM4MYFX1hoC7GHQ+lFb/1z97Y0mZeItXeYLQ 30GiWT/cYNduBbJkQ0m9xE7PY6Fyepez6vWc55eQtJJWBmr5B+kh9BjxQcsXCGTKT80yTN owWLs5yYVD4n31rNZ+u6oTBWwOjOg3RlB4+bzy7O5dcLtpkUXKUC0q62DKd5WjTLSJZc5o 0WGNPsj3T989AgSALUxQe87nAkauVxD45Qv4RRCM/fJ/fHI/J4GvqYEgGWm8dA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078339; 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=9YtJrmgYZNvEEH6ObCih4a8AsX+g3T5HhHN+0iOuL38=; b=IdU94JseYg6XKF7DqvaQ5Xr1QsOoBG6k1eeq6vpEXmK41A9SMLrc5zRECc4rJN9h1tg5EC YtDYhVdT5rcCW8DQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 02/40] x86/cpu: Validate cpuid leaf 0x2 EDX output Date: Tue, 4 Mar 2025 09:51:13 +0100 Message-ID: <20250304085152.51092-3-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 emits one-byte descriptors in its four output registers EAX, EBX, ECX, and EDX. For these descriptors to be valid, the most significant bit (MSB) of each register must be clear. Leaf 0x2 parsing at intel.c only validated the MSBs of EAX, EBX, and ECX, but left EDX unchecked. Validate EDX's most-significant bit as well. Fixes: e0ba94f14f74 ("x86/tlb_info: get last level TLB entry number of CPU") Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/intel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 3dce22f00dc3..2a3716afee63 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -799,7 +799,7 @@ static void intel_detect_tlb(struct cpuinfo_x86 *c) cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]); =20 /* If bit 31 is set, this is an unknown format */ - for (j =3D 0 ; j < 3 ; j++) + for (j =3D 0 ; j < 4 ; j++) if (regs[j] & (1 << 31)) regs[j] =3D 0; =20 --=20 2.48.1 From nobody Wed Apr 1 19:57:17 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 5F3CF1FCD0F for ; Tue, 4 Mar 2025 08:52: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=1741078346; cv=none; b=qhzqJSDor4yWL60Azgin7PKluFsusUQS6xeL1D6rMQx5dkVdGD4X6bxjN1DfXL47Dnaf/t5+nOCEQonBSBJJx2dDy5PxdZc8Negp6ykSfngA5PzaMsE1QsWANcJR/tw/uZOQhAkZ4KIuZF6LsKF5Hj3D8xCw2Cf+Clsk58sQCOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078346; c=relaxed/simple; bh=vKqcvavr9pOXr6uy7VVLJhpPYo3fWrUTp4PYQ+J/dPA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IdLUiErEB9evqVy+hrFuLUrnchviZXezwghtOVJDvmuTlQBqVF0mTQzOI1dR7x8iovjXQ2mRDLQsN+kCKXv+T3DdLYaSj9ujgsXZSjM3g4qZq/N9Ia6UAYI2HCPGKwIJP1ejtjcU2ldZ9DHwWl7mfZYR+++3ClhmGicvw1l4/nA= 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=eSqUSpGY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=U3BcREA2; 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="eSqUSpGY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="U3BcREA2" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078342; 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=pdHm42jE7oEmVWRACBGiP+be9b9OnOGdWQRJRma4eKg=; b=eSqUSpGYrAoTNVcBvE0xDr8/JtsygooxxhDah9fw1V62d6PMncx11ZMl+w8O9bhXARR8jv kcCvGuM48LgP2mzKjuiq/67/7cyQVbutjwzfRwWUf9vW+v2MDvUP/jFrDK/CeWEY3EiQ8r AtUd+wx131dlaihvRbnQC3dHpPzbW+svjUHQLjWKRrdSGsy9CmVD5YCSwrO8WwMce8epHd H2+Sv5OCGOsbgjyQcpLMpcLIy4p+Isy5jUBIznD/kkV1+F6/wY6jeVh5bXsr+5CtFRtqsz CQRKm5s29U1dJiLWTip3xnLD6/modFBXA7N1HGIIHidZmAvenkaiCslmjUJm2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078342; 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=pdHm42jE7oEmVWRACBGiP+be9b9OnOGdWQRJRma4eKg=; b=U3BcREA2vQjZWiH0h08wAyOPE8n9hiXCkSGLvRj/bi5jxdPHUCSYAkr0b7A6c3CBTs/Hyb SOTD0H4x0ymPXLAA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 03/40] x86/cpu: Properly parse leaf 0x2 TLB descriptor 0x63 Date: Tue, 4 Mar 2025 09:51:14 +0100 Message-ID: <20250304085152.51092-4-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2's one-byte TLB descriptors report the number of entries for specific TLB types, among other properties. Typically, each emitted descriptor implies the same number of entries for its respective TLB type(s). An emitted 0x63 descriptor is an exception: it implies 4 data TLB entries for 1GB pages and 32 data TLB entries for 2MB or 4MB pages. For the TLB descriptors parsing code, the entry count for 1GB pages is encoded at the intel_tlb_table[] mapping, but the 2MB/4MB entry count is totally ignored. Update leaf 0x2's parsing logic 0x2 to account for 32 data TLB entries for 2MB/4MB pages implied by the 0x63 descriptor. Fixes: e0ba94f14f74 ("x86/tlb_info: get last level TLB entry number of CPU") Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/intel.c | 50 +++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 2a3716afee63..134368a3f4b1 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -635,26 +635,37 @@ static unsigned int intel_size_cache(struct cpuinfo_x= 86 *c, unsigned int size) } #endif =20 -#define TLB_INST_4K 0x01 -#define TLB_INST_4M 0x02 -#define TLB_INST_2M_4M 0x03 +#define TLB_INST_4K 0x01 +#define TLB_INST_4M 0x02 +#define TLB_INST_2M_4M 0x03 =20 -#define TLB_INST_ALL 0x05 -#define TLB_INST_1G 0x06 +#define TLB_INST_ALL 0x05 +#define TLB_INST_1G 0x06 =20 -#define TLB_DATA_4K 0x11 -#define TLB_DATA_4M 0x12 -#define TLB_DATA_2M_4M 0x13 -#define TLB_DATA_4K_4M 0x14 +#define TLB_DATA_4K 0x11 +#define TLB_DATA_4M 0x12 +#define TLB_DATA_2M_4M 0x13 +#define TLB_DATA_4K_4M 0x14 =20 -#define TLB_DATA_1G 0x16 +#define TLB_DATA_1G 0x16 +#define TLB_DATA_1G_2M_4M 0x17 =20 -#define TLB_DATA0_4K 0x21 -#define TLB_DATA0_4M 0x22 -#define TLB_DATA0_2M_4M 0x23 +#define TLB_DATA0_4K 0x21 +#define TLB_DATA0_4M 0x22 +#define TLB_DATA0_2M_4M 0x23 =20 -#define STLB_4K 0x41 -#define STLB_4K_2M 0x42 +#define STLB_4K 0x41 +#define STLB_4K_2M 0x42 + +/* + * All of leaf 0x2's one-byte TLB descriptors implies the same number of + * entries for their respective TLB types. The 0x63 descriptor is an + * exception: it implies 4 dTLB entries for 1GB pages 32 dTLB entries + * for 2MB or 4MB pages. Encode descriptor 0x63 dTLB entry count for + * 2MB/4MB pages here, as its count for dTLB 1GB pages is already at the + * intel_tlb_table[] mapping. + */ +#define TLB_0x63_2M_4M_ENTRIES 32 =20 static const struct _tlb_table intel_tlb_table[] =3D { { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative= " }, @@ -676,7 +687,8 @@ static const struct _tlb_table intel_tlb_table[] =3D { { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" }, { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" }, { 0x61, TLB_INST_4K, 48, " TLB_INST 4 KByte pages, full associative" }, - { 0x63, TLB_DATA_1G, 4, " TLB_DATA 1 GByte pages, 4-way set associative"= }, + { 0x63, TLB_DATA_1G_2M_4M, 4, " TLB_DATA 1 GByte pages, 4-way set associa= tive" + " (plus 32 entries TLB_DATA 2 MByte or 4 MByte pages, not encoded he= re)" }, { 0x6b, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 8-way associative" }, { 0x6c, TLB_DATA_2M_4M, 128, " TLB_DATA 2 MByte or 4 MByte pages, 8-way = associative" }, { 0x6d, TLB_DATA_1G, 16, " TLB_DATA 1 GByte pages, fully associative" }, @@ -776,6 +788,12 @@ static void intel_tlb_lookup(const unsigned char desc) if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) tlb_lld_4m[ENTRIES] =3D intel_tlb_table[k].entries; break; + case TLB_DATA_1G_2M_4M: + if (tlb_lld_2m[ENTRIES] < TLB_0x63_2M_4M_ENTRIES) + tlb_lld_2m[ENTRIES] =3D TLB_0x63_2M_4M_ENTRIES; + if (tlb_lld_4m[ENTRIES] < TLB_0x63_2M_4M_ENTRIES) + tlb_lld_4m[ENTRIES] =3D TLB_0x63_2M_4M_ENTRIES; + fallthrough; case TLB_DATA_1G: if (tlb_lld_1g[ENTRIES] < intel_tlb_table[k].entries) tlb_lld_1g[ENTRIES] =3D intel_tlb_table[k].entries; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 4D1971FCFCC for ; Tue, 4 Mar 2025 08:52:26 +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=1741078349; cv=none; b=bPrR6ZmSFhc4M9vt6IA4fw5oZUizSSDzv/bF8Z3OFbCR8jsZP1Q/HgIK0vJr9kSJSAsuvoK15ryzPZY5T0omWBo7ycqBYh1jZv62JyZJ5c8qxidBAGVuqsVMNfl1oVL3bUwWigTSDUfYoJXm4cQW2HPuM+JbVuXiK8mxOx61L2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078349; c=relaxed/simple; bh=5R5FE9TBno8bHASjorKr+3tKjY9/T52usXX+Kih2N34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tH5c9dT/nhkoMzGi9HVtJmrkzeM/+wJZj4XDdkUhGhQ0+5mQF3FXv9mr+EV7rBHozzHIbE6c+HUX8RTVV/wMBbK72k+Z7eDbCxK2lWV820GmcZyvqah/S0C3TMq32JYw5FQGy12+Af6iG4frkA/663lUV8E5qkgv4IgPSDTxQ4Q= 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=mutIu1WI; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Un1TY1Kg; 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="mutIu1WI"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Un1TY1Kg" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078345; 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=AMot0Gu34Xummmuek6iZ/AeZrZnzUrZ28r3TjZqYytU=; b=mutIu1WI+DvXDePbVIE4pJNbGdkIjbsT+X+Rf6M+H2Xc7e+Lf3Esn8MDo3mhtHtdpYq6B5 s5MV2V7aJxQku3xMYNt8jtQMPM1oMgqBMSHFqkFXzMlv9sVwwT5Bh9jOGLLhWp/ZsIcpbH NuWZA2J+Mn1qMaK5OBnAexiDOuHBRp5sAe6v8JsRN6E6D5tYksHxsTxIQMnym2Rvk/6ZOw hM0qJsoMBitvaDSxHP0yaRDBRsfvtIuYZ6q46PbaQZ9zfnHXZr5X0WpgPRiQw4mdl7LHDQ BeMbHf2LjumcWD7R4MiSKRvWJcWmGAI5c3TrXN4QnWAiB2BZV3kz2ZAgQBRbXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078345; 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=AMot0Gu34Xummmuek6iZ/AeZrZnzUrZ28r3TjZqYytU=; b=Un1TY1Kg1fBmOTNBb6dhmepkGMTrf9Ocb4al7aWZNp8kWHUd9r7VG926lNkMgWxmO05gWI t72Urru6w9W4tsBg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 04/40] x86/cpuid: Include linux/build_bug.h Date: Tue, 4 Mar 2025 09:51:15 +0100 Message-ID: <20250304085152.51092-5-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" asm/cpuid.h uses static_assert() at multiple locations but it does not include the CPP macro's definition at linux/build_bug.h. Include the needed header. This gets triggered when cpuid.h is included in new C files, which is to be done in further commits. Fixes: 43d86e3cd9a7 ("x86/cpu: Provide cpuid_read() et al.") Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/include/asm/cpuid.h b/arch/x86/include/asm/cpuid.h index b2b9b4ef3dae..a92e4b08820a 100644 --- a/arch/x86/include/asm/cpuid.h +++ b/arch/x86/include/asm/cpuid.h @@ -6,6 +6,7 @@ #ifndef _ASM_X86_CPUID_H #define _ASM_X86_CPUID_H =20 +#include #include =20 #include --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 EABC81FCFF3 for ; Tue, 4 Mar 2025 08:52:29 +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=1741078351; cv=none; b=uOsT7zfgUYLVkuo9DucNwpxIUTPp8MUGhZCkEf9srXwrcubgwsGV6KZ587kYqCLvSMtP/vnR0rkx2LIMlgjKssGTvPCHf0VW8ovJWJeSyYp+tQz8W878XhXU4b8igK4LA2nc+GT25P76iPeIrIYyQJg2FnU1TI8UtkHMzvJv1CY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078351; c=relaxed/simple; bh=TtkjCaEfovdST0vQ/3l+CT6q0XDurgzYkizr7i+OBGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K5+tMkL6Q/pa62ujLwdC55krmI/iqpo/740XL7PXStJc8i+fckHfLxr4SROZD26nT4qLAk3nHPnRo3PALTbeA9IHXl55g6dacQTn4KbAzxmN8pf72spyy1NHMxVwcdKz4veJKwPGVYJsatKvBQcr6mYkskt7W3WAk+J1/8dsA54= 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=wYm5Ig67; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vc/f4lqp; 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="wYm5Ig67"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vc/f4lqp" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078348; 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=yF4ckw4bp1d8zZFTp92YozOjejKXwsco3zqZ2FJcqLM=; b=wYm5Ig67OoGCCtfh53NPxUaGJ9jM8G0PVyiAoAvFMJKIT1vN0BI2Gu4HBWHHF/2GmR6ZQE XK7hqoQ5h6wjPUaNstrKRcXoUrkaaO2QeFQ4Wy+fGqbD3HaSk2VKvv7Ae3BqHksDbFHDWv Uvr/bX5OU0U4C2oLxPD/ozNaMqE5KDOS+aLAw7EbLwq8hoYGR2YqatUwfzzvQmwdgo7L/U wJG91jiiMXaGB+4O3D/5hJJf/gRlRVg8aCCv9I/1EkjHA2iFw5DdDqyhJTI1uPHZGV2PhZ XfuQ7mTpCel4a/CvdDjhsWpJoCALZRgSq28urRdDrgual5fk8hq7vSFVuV4yEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078348; 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=yF4ckw4bp1d8zZFTp92YozOjejKXwsco3zqZ2FJcqLM=; b=vc/f4lqpJTv7MldpX5Pc3umWonX2Wi0uMAlw+NuMKhUtfhFxdJ/NqNcppMipMGobjz9Wd7 JUCqkyThVmbPzQBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 05/40] x86/cpu: Remove unnecessary headers and reorder the rest Date: Tue, 4 Mar 2025 09:51:16 +0100 Message-ID: <20250304085152.51092-6-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Remove the headers at intel.c that are no longer required. Alphabetically reorder what remains since more headers will be included in further commits. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/intel.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 134368a3f4b1..72f519534e2b 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -1,40 +1,29 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include =20 -#include #include -#include -#include -#include -#include #include -#include +#include +#include +#include + +#ifdef CONFIG_X86_64 +#include +#endif =20 -#include -#include #include +#include +#include #include +#include #include #include -#include -#include -#include -#include +#include #include +#include #include =20 -#ifdef CONFIG_X86_64 -#include -#endif - #include "cpu.h" =20 -#ifdef CONFIG_X86_LOCAL_APIC -#include -#include -#endif - /* * Processors which have self-snooping capability can handle conflicting * memory type across CPUs by snooping its own cache. However, there exists --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 DBE101FDE03 for ; Tue, 4 Mar 2025 08:52:32 +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=1741078354; cv=none; b=HDie/VVbQUJ7Gn5C7UREhlWoSzBNASaStSknA6D/N9TPcAzB+TBaOA3Ec16+PMGvuJ4CFHUaEYYkKfVfNhhb6aR7YUuLgZl+7z+GEyvm5QLrTGK4oNjPIv52BYS8+jADt5Kj9rVnJOxRFYuLHEX8OL/7TNRLGRA7r3IcJKL8qPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078354; c=relaxed/simple; bh=q5G/qiY7yo3xCX0EWSKwfQpg5lBB95uOvEaDNzMqeqU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QoUm0r83hQhuPIxiIVtSD37eXxwJeBJYG1M464d3uTpYOg11jd0kz+2Cn56aJJlCYFr+ImY2MyLGJw9MpQuxnsI3MdH4BjG62yd4z+pmmqaxaIq7tBHFUdnyjG5+9kJ51Lkkb1k4iWnVt0s3BMFjSdB4VUVnt3nmvN0x8ZDf/xg= 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=vX3Qs06K; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZvSwHJ5+; 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="vX3Qs06K"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZvSwHJ5+" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078351; 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=LRpaNf+WhdKXg5YRbfSJcTqZ3UgP8MUrCu753p8Ma1I=; b=vX3Qs06KMu5x0Ule9pw0kSq78wETl7wYXcOj2TaYb+e9IUtKzcwQtKEglruHDNuDY2undV dXJCZJCJRJsTZGwJcSdsUr+k57MrGasS/LT7rdIxIcdN/JZjuyvzuOw/6TMZofEi/jMDy5 6MFmeFsnqBGcCIN6OzAVyQ/Xx4bBX69bAe4HdT2oQZoSPWiRmVhdB7+b/Fguu7/Hw02f/G aaZSPtSdSQriKBAPpSOiOb4nUgCUoKUrNvNqxmsWNgAPS8zR7BaQnfjSSU0+Z3HGAkTJCk H2INwtMulVSBWGMVrAyZ2sbNTcfZDSfdm5pTit/BHF4EQoUJaDzmO/NydP57yA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078351; 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=LRpaNf+WhdKXg5YRbfSJcTqZ3UgP8MUrCu753p8Ma1I=; b=ZvSwHJ5+SC64G2KffrOlTaoJSF0s9dX1dduLXYExJg1q52Rto/11/YSwFWvSz27Oe4z24X FVN203bErzZsbDDg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 06/40] x86/cpu: Use max() for leaf 0x2 TLB descriptors parsing Date: Tue, 4 Mar 2025 09:51:17 +0100 Message-ID: <20250304085152.51092-7-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 conditional statement "if (x < y) { x =3D y; }" appears 22 times at the Intel leaf 0x2 descriptors parsing logic. Replace each of such instances with a max() expression. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/intel.c | 76 ++++++++++++++----------------------- 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 72f519534e2b..e972c72e2b5d 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include =20 @@ -699,7 +700,9 @@ static const struct _tlb_table intel_tlb_table[] =3D { =20 static void intel_tlb_lookup(const unsigned char desc) { + unsigned int entries; unsigned char k; + if (desc =3D=3D 0) return; =20 @@ -711,81 +714,58 @@ static void intel_tlb_lookup(const unsigned char desc) if (intel_tlb_table[k].tlb_type =3D=3D 0) return; =20 + entries =3D intel_tlb_table[k].entries; switch (intel_tlb_table[k].tlb_type) { case STLB_4K: - if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4k[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4k[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); + tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); break; case STLB_4K_2M: - if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4k[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4k[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_2m[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_2m[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4m[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); + tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); + tlb_lli_2m[ENTRIES] =3D max(tlb_lli_2m[ENTRIES], entries); + tlb_lld_2m[ENTRIES] =3D max(tlb_lld_2m[ENTRIES], entries); + tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); + tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); break; case TLB_INST_ALL: - if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4k[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_2m[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); + tlb_lli_2m[ENTRIES] =3D max(tlb_lli_2m[ENTRIES], entries); + tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); break; case TLB_INST_4K: - if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4k[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); break; case TLB_INST_4M: - if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); break; case TLB_INST_2M_4M: - if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_2m[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lli_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lli_2m[ENTRIES] =3D max(tlb_lli_2m[ENTRIES], entries); + tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); break; case TLB_DATA_4K: case TLB_DATA0_4K: - if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4k[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); break; case TLB_DATA_4M: case TLB_DATA0_4M: - if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); break; case TLB_DATA_2M_4M: case TLB_DATA0_2M_4M: - if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_2m[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lld_2m[ENTRIES] =3D max(tlb_lld_2m[ENTRIES], entries); + tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); break; case TLB_DATA_4K_4M: - if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4k[ENTRIES] =3D intel_tlb_table[k].entries; - if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_4m[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); + tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); break; case TLB_DATA_1G_2M_4M: - if (tlb_lld_2m[ENTRIES] < TLB_0x63_2M_4M_ENTRIES) - tlb_lld_2m[ENTRIES] =3D TLB_0x63_2M_4M_ENTRIES; - if (tlb_lld_4m[ENTRIES] < TLB_0x63_2M_4M_ENTRIES) - tlb_lld_4m[ENTRIES] =3D TLB_0x63_2M_4M_ENTRIES; + tlb_lld_2m[ENTRIES] =3D max(tlb_lld_2m[ENTRIES], TLB_0x63_2M_4M_ENTRIES); + tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], TLB_0x63_2M_4M_ENTRIES); fallthrough; case TLB_DATA_1G: - if (tlb_lld_1g[ENTRIES] < intel_tlb_table[k].entries) - tlb_lld_1g[ENTRIES] =3D intel_tlb_table[k].entries; + tlb_lld_1g[ENTRIES] =3D max(tlb_lld_1g[ENTRIES], entries); break; } } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 3823C1FDE23 for ; Tue, 4 Mar 2025 08:52: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=1741078358; cv=none; b=TOZYqH9/5WtchMlAh1MEqwwrY0q3vCPlE6n6UKJpb9ICEUzNff7eIhpmWn65d2Qte5+yOg2KBVxOexPqJGSRHtv0sVaS+5bN0uXXj+LrXXXgLcmtsaEAL+NrJjSwo+RDNbb5pM76ufCJNkMZOU0j1j17vdqZoU6GLYH6FR/1sJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078358; c=relaxed/simple; bh=id36i8J/zyy5ThlQnMyoIPAp4eLTHBrmXgVUE22Q5Vk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LRDpmbs+hlwtjyGOkhvk4OA+/B6XPLPPHlA4ypH9LRXw0TSBOFzwJqkYOsfNWGlSYRvHmFM6EwhApf/tztrOHpJh1u2K9spwoF7i5jnyJE+1RzqMqnWroD3eavI8Bss+BZIEnMZ+SJQOHW95QkpVeBCZ3c7dbQ2p+eWsv30gKNw= 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=gA8FnjaQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Re+7GWGU; 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="gA8FnjaQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Re+7GWGU" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078354; 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=uldPKprmaw7IDxQ/zbMkEdchvGCL/8P/7tZVYavu56A=; b=gA8FnjaQj7K0Mn8XxFnAqU824K0CdwTtojvIJH3Y9drK+KdMgKlauRBlwtKJfQ6Sumg8eb R+zi1aquaaNO5S2LQSfzJ2uYJm9EzGvhBwSIYwXFw5M4K7bs4BQ+8nPbc4+l1GNGij43n7 /g0FQF/Of3S+/u10BvGsxqfgNKs5tsinccZsapqskD2wgi6SACUnxox5LOo/IeYux02l+7 Bkfulimenw5owtewUdNIeIjU7SZS92K08sEsfxI8CylFt9DsV7oRPRQcvprLV1UY+ixYOT qFRQgxVnQ8p/uYJ6RYCv57jAo3ldOSBao2U9ceBUHc/tgYG0RU2nLM4iyvwUDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078354; 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=uldPKprmaw7IDxQ/zbMkEdchvGCL/8P/7tZVYavu56A=; b=Re+7GWGUO7spRUWKSkKL3M9NIVQEtplHgs+4L81Oqq/yKgJbqQ8rzADr5smRP/ZI4bjWe1 XECoF2QBUZuzGwCw== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 07/40] x86/cpu: Simplify TLB entry count storage Date: Tue, 4 Mar 2025 09:51:18 +0100 Message-ID: <20250304085152.51092-8-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Commit e0ba94f14f74 ("x86/tlb_info: get last level TLB entry number of CPU") introduced u16 "info" arrays for each TLB type. Since 2012 and each array stores just one type of information: the number of TLB entries for its respective TLB type. Replace such arrays with simple variables. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/processor.h | 19 +++++-------- arch/x86/kernel/cpu/amd.c | 18 ++++++------ arch/x86/kernel/cpu/common.c | 20 ++++++------- arch/x86/kernel/cpu/hygon.c | 16 +++++------ arch/x86/kernel/cpu/intel.c | 48 ++++++++++++++++---------------- 5 files changed, 57 insertions(+), 64 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index c0cd10182e90..0ea227fa027c 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -60,18 +60,13 @@ struct vm86; # define ARCH_MIN_MMSTRUCT_ALIGN 0 #endif =20 -enum tlb_infos { - ENTRIES, - NR_INFO -}; - -extern u16 __read_mostly tlb_lli_4k[NR_INFO]; -extern u16 __read_mostly tlb_lli_2m[NR_INFO]; -extern u16 __read_mostly tlb_lli_4m[NR_INFO]; -extern u16 __read_mostly tlb_lld_4k[NR_INFO]; -extern u16 __read_mostly tlb_lld_2m[NR_INFO]; -extern u16 __read_mostly tlb_lld_4m[NR_INFO]; -extern u16 __read_mostly tlb_lld_1g[NR_INFO]; +extern u16 __read_mostly tlb_lli_4k; +extern u16 __read_mostly tlb_lli_2m; +extern u16 __read_mostly tlb_lli_4m; +extern u16 __read_mostly tlb_lld_4k; +extern u16 __read_mostly tlb_lld_2m; +extern u16 __read_mostly tlb_lld_4m; +extern u16 __read_mostly tlb_lld_1g; =20 /* * CPU type and hardware bug flags. Kept separately for each CPU. diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 54194f5995de..c43e5d4033bb 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1105,8 +1105,8 @@ static void cpu_detect_tlb_amd(struct cpuinfo_x86 *c) =20 cpuid(0x80000006, &eax, &ebx, &ecx, &edx); =20 - tlb_lld_4k[ENTRIES] =3D (ebx >> 16) & mask; - tlb_lli_4k[ENTRIES] =3D ebx & mask; + tlb_lld_4k =3D (ebx >> 16) & mask; + tlb_lli_4k =3D ebx & mask; =20 /* * K8 doesn't have 2M/4M entries in the L2 TLB so read out the L1 TLB @@ -1119,26 +1119,26 @@ static void cpu_detect_tlb_amd(struct cpuinfo_x86 *= c) =20 /* Handle DTLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ if (!((eax >> 16) & mask)) - tlb_lld_2m[ENTRIES] =3D (cpuid_eax(0x80000005) >> 16) & 0xff; + tlb_lld_2m =3D (cpuid_eax(0x80000005) >> 16) & 0xff; else - tlb_lld_2m[ENTRIES] =3D (eax >> 16) & mask; + tlb_lld_2m =3D (eax >> 16) & mask; =20 /* a 4M entry uses two 2M entries */ - tlb_lld_4m[ENTRIES] =3D tlb_lld_2m[ENTRIES] >> 1; + tlb_lld_4m =3D tlb_lld_2m >> 1; =20 /* Handle ITLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ if (!(eax & mask)) { /* Erratum 658 */ if (c->x86 =3D=3D 0x15 && c->x86_model <=3D 0x1f) { - tlb_lli_2m[ENTRIES] =3D 1024; + tlb_lli_2m =3D 1024; } else { cpuid(0x80000005, &eax, &ebx, &ecx, &edx); - tlb_lli_2m[ENTRIES] =3D eax & 0xff; + tlb_lli_2m =3D eax & 0xff; } } else - tlb_lli_2m[ENTRIES] =3D eax & mask; + tlb_lli_2m =3D eax & mask; =20 - tlb_lli_4m[ENTRIES] =3D tlb_lli_2m[ENTRIES] >> 1; + tlb_lli_4m =3D tlb_lli_2m >> 1; } =20 static const struct cpu_dev amd_cpu_dev =3D { diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 7cce91b19fb2..486395356faf 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -846,13 +846,13 @@ void cpu_detect_cache_sizes(struct cpuinfo_x86 *c) c->x86_cache_size =3D l2size; } =20 -u16 __read_mostly tlb_lli_4k[NR_INFO]; -u16 __read_mostly tlb_lli_2m[NR_INFO]; -u16 __read_mostly tlb_lli_4m[NR_INFO]; -u16 __read_mostly tlb_lld_4k[NR_INFO]; -u16 __read_mostly tlb_lld_2m[NR_INFO]; -u16 __read_mostly tlb_lld_4m[NR_INFO]; -u16 __read_mostly tlb_lld_1g[NR_INFO]; +u16 __read_mostly tlb_lli_4k; +u16 __read_mostly tlb_lli_2m; +u16 __read_mostly tlb_lli_4m; +u16 __read_mostly tlb_lld_4k; +u16 __read_mostly tlb_lld_2m; +u16 __read_mostly tlb_lld_4m; +u16 __read_mostly tlb_lld_1g; =20 static void cpu_detect_tlb(struct cpuinfo_x86 *c) { @@ -860,12 +860,10 @@ static void cpu_detect_tlb(struct cpuinfo_x86 *c) this_cpu->c_detect_tlb(c); =20 pr_info("Last level iTLB entries: 4KB %d, 2MB %d, 4MB %d\n", - tlb_lli_4k[ENTRIES], tlb_lli_2m[ENTRIES], - tlb_lli_4m[ENTRIES]); + tlb_lli_4k, tlb_lli_2m, tlb_lli_4m); =20 pr_info("Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d, 1GB %d\n", - tlb_lld_4k[ENTRIES], tlb_lld_2m[ENTRIES], - tlb_lld_4m[ENTRIES], tlb_lld_1g[ENTRIES]); + tlb_lld_4k, tlb_lld_2m, tlb_lld_4m, tlb_lld_1g); } =20 void get_cpu_vendor(struct cpuinfo_x86 *c) diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c index c5191b06f9f2..6af4a4a90a52 100644 --- a/arch/x86/kernel/cpu/hygon.c +++ b/arch/x86/kernel/cpu/hygon.c @@ -240,26 +240,26 @@ static void cpu_detect_tlb_hygon(struct cpuinfo_x86 *= c) =20 cpuid(0x80000006, &eax, &ebx, &ecx, &edx); =20 - tlb_lld_4k[ENTRIES] =3D (ebx >> 16) & mask; - tlb_lli_4k[ENTRIES] =3D ebx & mask; + tlb_lld_4k =3D (ebx >> 16) & mask; + tlb_lli_4k =3D ebx & mask; =20 /* Handle DTLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ if (!((eax >> 16) & mask)) - tlb_lld_2m[ENTRIES] =3D (cpuid_eax(0x80000005) >> 16) & 0xff; + tlb_lld_2m =3D (cpuid_eax(0x80000005) >> 16) & 0xff; else - tlb_lld_2m[ENTRIES] =3D (eax >> 16) & mask; + tlb_lld_2m =3D (eax >> 16) & mask; =20 /* a 4M entry uses two 2M entries */ - tlb_lld_4m[ENTRIES] =3D tlb_lld_2m[ENTRIES] >> 1; + tlb_lld_4m =3D tlb_lld_2m >> 1; =20 /* 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[ENTRIES] =3D eax & 0xff; + tlb_lli_2m =3D eax & 0xff; } else - tlb_lli_2m[ENTRIES] =3D eax & mask; + tlb_lli_2m =3D eax & mask; =20 - tlb_lli_4m[ENTRIES] =3D tlb_lli_2m[ENTRIES] >> 1; + tlb_lli_4m =3D tlb_lli_2m >> 1; } =20 static const struct cpu_dev hygon_cpu_dev =3D { diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index e972c72e2b5d..905f39fce375 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -717,55 +717,55 @@ static void intel_tlb_lookup(const unsigned char desc) entries =3D intel_tlb_table[k].entries; switch (intel_tlb_table[k].tlb_type) { case STLB_4K: - tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); - tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); + tlb_lli_4k =3D max(tlb_lli_4k, entries); + tlb_lld_4k =3D max(tlb_lld_4k, entries); break; case STLB_4K_2M: - tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); - tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); - tlb_lli_2m[ENTRIES] =3D max(tlb_lli_2m[ENTRIES], entries); - tlb_lld_2m[ENTRIES] =3D max(tlb_lld_2m[ENTRIES], entries); - tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); - tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); + tlb_lli_4k =3D max(tlb_lli_4k, entries); + tlb_lld_4k =3D max(tlb_lld_4k, entries); + tlb_lli_2m =3D max(tlb_lli_2m, entries); + tlb_lld_2m =3D max(tlb_lld_2m, entries); + tlb_lli_4m =3D max(tlb_lli_4m, entries); + tlb_lld_4m =3D max(tlb_lld_4m, entries); break; case TLB_INST_ALL: - tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); - tlb_lli_2m[ENTRIES] =3D max(tlb_lli_2m[ENTRIES], entries); - tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); + tlb_lli_4k =3D max(tlb_lli_4k, entries); + tlb_lli_2m =3D max(tlb_lli_2m, entries); + tlb_lli_4m =3D max(tlb_lli_4m, entries); break; case TLB_INST_4K: - tlb_lli_4k[ENTRIES] =3D max(tlb_lli_4k[ENTRIES], entries); + tlb_lli_4k =3D max(tlb_lli_4k, entries); break; case TLB_INST_4M: - tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); + tlb_lli_4m =3D max(tlb_lli_4m, entries); break; case TLB_INST_2M_4M: - tlb_lli_2m[ENTRIES] =3D max(tlb_lli_2m[ENTRIES], entries); - tlb_lli_4m[ENTRIES] =3D max(tlb_lli_4m[ENTRIES], entries); + tlb_lli_2m =3D max(tlb_lli_2m, entries); + tlb_lli_4m =3D max(tlb_lli_4m, entries); break; case TLB_DATA_4K: case TLB_DATA0_4K: - tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); + tlb_lld_4k =3D max(tlb_lld_4k, entries); break; case TLB_DATA_4M: case TLB_DATA0_4M: - tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); + tlb_lld_4m =3D max(tlb_lld_4m, entries); break; case TLB_DATA_2M_4M: case TLB_DATA0_2M_4M: - tlb_lld_2m[ENTRIES] =3D max(tlb_lld_2m[ENTRIES], entries); - tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); + tlb_lld_2m =3D max(tlb_lld_2m, entries); + tlb_lld_4m =3D max(tlb_lld_4m, entries); break; case TLB_DATA_4K_4M: - tlb_lld_4k[ENTRIES] =3D max(tlb_lld_4k[ENTRIES], entries); - tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], entries); + tlb_lld_4k =3D max(tlb_lld_4k, entries); + tlb_lld_4m =3D max(tlb_lld_4m, entries); break; case TLB_DATA_1G_2M_4M: - tlb_lld_2m[ENTRIES] =3D max(tlb_lld_2m[ENTRIES], TLB_0x63_2M_4M_ENTRIES); - tlb_lld_4m[ENTRIES] =3D max(tlb_lld_4m[ENTRIES], TLB_0x63_2M_4M_ENTRIES); + tlb_lld_2m =3D max(tlb_lld_2m, TLB_0x63_2M_4M_ENTRIES); + tlb_lld_4m =3D max(tlb_lld_4m, TLB_0x63_2M_4M_ENTRIES); fallthrough; case TLB_DATA_1G: - tlb_lld_1g[ENTRIES] =3D max(tlb_lld_1g[ENTRIES], entries); + tlb_lld_1g =3D max(tlb_lld_1g, entries); break; } } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 337581EB9E2 for ; Tue, 4 Mar 2025 08:52: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=1741078360; cv=none; b=k88Z8Qjg35vBx7839Ku5Odx0LKj60wm78sioLQQQxCg1jbCo8IK0ajJxICSuocN+U0+UPu4xuQTtW4afc8KQPh5uuVNbreDZF1O0S/AK3/z8+OUs+lKw+bLBuK6cBZVe+64+ROC4xVnh8zpOLpVUybOvR8FqUNQIensOiMHE+wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078360; c=relaxed/simple; bh=CmXBmlxisxYfICcVVw72tCNLH2pkwCIh/kTyeLQccfk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RrVRN8trhkFi5iWQd6uiJ1mFbgiOmvs2+4Y8aH5o8McMLRSYLhZidhBSCYr9ClZ1O7hXsTIycGUNJ4tOuigoK5emFPrqa8r+WStqJvctS9n9G3dZMnOwDLk9blMpDpO4KAl0XN4DMwvb6IVTcq1kMfRQ8ckF/1xYvWaFG9ZftfM= 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=CmlqvT5a; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=7Zs17dyD; 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="CmlqvT5a"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="7Zs17dyD" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078357; 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=kIj6d0Awb9GmuBboZEo5cpoLvkz83NhzBB7Rnz7sfts=; b=CmlqvT5aYkmw3pQ/WF8kLw3aV+ngJGOOKq9sfhrRv3SpQ1j4qVNTdTh7ReBl3udZt/JqRK xgta5qrUUht5hBe335Ake4VDz+jb2AK6Y3Eu9cb4hChMNyKwkLf2PdbJawWxbGu1gK/FOP y4UHFnhzimqQ+0QOiTAKeDLa0+sLCBmeULoIebfoAMrfPNsnZgTX0lLfYSVPwMsP9Qa8iR w06pjDuxuMBi1y/qdDzF2HTxD/D83HLmk9p1IQYUxNgir7soR+AiMZuAI7GWRY7wQ7LLtj crYVP0Cd7Y5qQWCO3NNm0BEHAYfXmQyywi0u7AIEEzWJabIVMVtGKqsx7xXFlQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078357; 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=kIj6d0Awb9GmuBboZEo5cpoLvkz83NhzBB7Rnz7sfts=; b=7Zs17dyDMB9arkZoBq54GdkMuJEt9c6s6f6MegBEQSap/1EJpXVgqfvw8Vn1QA6ySGl8l4 EqD3/1+/O2aB4cAQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 08/40] x86/cpu: Get rid of smp_store_cpu_info() indirection Date: Tue, 4 Mar 2025 09:51:19 +0100 Message-ID: <20250304085152.51092-9-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner smp_store_cpu_info() is just a wrapper around identify_secondary_cpu() without further value. Move the extra bits from smp_store_cpu_info() into identify_secondary_cpu() and remove the wrapper. [darwi: Make it compile and fixup the xen/smp_pv.c instance] Signed-off-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/processor.h | 2 +- arch/x86/include/asm/smp.h | 2 -- arch/x86/kernel/cpu/common.c | 11 +++++++++-- arch/x86/kernel/smpboot.c | 24 ++---------------------- arch/x86/xen/smp_pv.c | 2 +- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index 0ea227fa027c..d5d9a071cddc 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -229,7 +229,7 @@ static inline unsigned long long l1tf_pfn_limit(void) void init_cpu_devs(void); void get_cpu_vendor(struct cpuinfo_x86 *c); extern void early_cpu_init(void); -extern void identify_secondary_cpu(struct cpuinfo_x86 *); +extern void identify_secondary_cpu(unsigned int cpu); extern void print_cpu_info(struct cpuinfo_x86 *); void print_cpu_msr(struct cpuinfo_x86 *); =20 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h index ca073f40698f..820a90d2fb4a 100644 --- a/arch/x86/include/asm/smp.h +++ b/arch/x86/include/asm/smp.h @@ -119,8 +119,6 @@ void native_smp_send_reschedule(int cpu); void native_send_call_func_ipi(const struct cpumask *mask); void native_send_call_func_single_ipi(int cpu); =20 -void smp_store_cpu_info(int id); - asmlinkage __visible void smp_reboot_interrupt(void); __visible void smp_reschedule_interrupt(struct pt_regs *regs); __visible void smp_call_function_interrupt(struct pt_regs *regs); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 486395356faf..749fe02ef1f7 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1960,9 +1960,15 @@ static __init void identify_boot_cpu(void) lkgs_init(); } =20 -void identify_secondary_cpu(struct cpuinfo_x86 *c) +void identify_secondary_cpu(unsigned int cpu) { - BUG_ON(c =3D=3D &boot_cpu_data); + struct cpuinfo_x86 *c =3D &cpu_data(cpu); + + /* Copy boot_cpu_data only on the first bringup */ + if (!c->initialized) + *c =3D boot_cpu_data; + c->cpu_index =3D cpu; + identify_cpu(c); #ifdef CONFIG_X86_32 enable_sep_cpu(); @@ -1973,6 +1979,7 @@ void identify_secondary_cpu(struct cpuinfo_x86 *c) update_gds_msr(); =20 tsx_ap_init(); + c->initialized =3D true; } =20 void print_cpu_info(struct cpuinfo_x86 *c) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index c10850ae6f09..e199465dc9e1 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -190,7 +190,7 @@ static void ap_starting(void) apic_ap_setup(); =20 /* Save the processor parameters. */ - smp_store_cpu_info(cpuid); + identify_secondary_cpu(cpuid); =20 /* * The topology information must be up to date before @@ -215,7 +215,7 @@ static void ap_calibrate_delay(void) { /* * Calibrate the delay loop and update loops_per_jiffy in cpu_data. - * smp_store_cpu_info() stored a value that is close but not as + * identify_secondary_cpu() stored a value that is close but not as * accurate as the value just calculated. * * As this is invoked after the TSC synchronization check, @@ -315,26 +315,6 @@ static void notrace start_secondary(void *unused) cpu_startup_entry(CPUHP_AP_ONLINE_IDLE); } =20 -/* - * The bootstrap kernel entry code has set these up. Save them for - * a given CPU - */ -void smp_store_cpu_info(int id) -{ - struct cpuinfo_x86 *c =3D &cpu_data(id); - - /* Copy boot_cpu_data only on the first bringup */ - if (!c->initialized) - *c =3D boot_cpu_data; - c->cpu_index =3D id; - /* - * During boot time, CPU0 has this setup already. Save the info when - * bringing up an AP. - */ - identify_secondary_cpu(c); - c->initialized =3D true; -} - static bool topology_same_node(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) { diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c index 6863d3da7dec..688ff59318ae 100644 --- a/arch/x86/xen/smp_pv.c +++ b/arch/x86/xen/smp_pv.c @@ -70,7 +70,7 @@ static void cpu_bringup(void) xen_enable_syscall(); } cpu =3D smp_processor_id(); - smp_store_cpu_info(cpu); + identify_secondary_cpu(cpu); set_cpu_sibling_map(cpu); =20 speculative_store_bypass_ht_init(); --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 BA80B1FE45B for ; Tue, 4 Mar 2025 08:52: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=1741078363; cv=none; b=UcDej3fk5RkVxZg9vXq8XaLzaZl4gjV6MqFKTXA5FLbp1cf35+ttWQyJfvn6KOjFDThOVJmaT80yXEBj+8B0kp1a5UomRpVaNTYj+6x2oIso3Yi6WZ7X8VW4ieBV6OhBpNOha0dp2KaxoQ5ZJQ9yqze+rvaACPXEDvmwbunHWmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078363; c=relaxed/simple; bh=I7lWy4oxXtM92TgxDHeDJE8J2SKPngVboSsqddFra7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OWCduV6LEH9gIci8M4ikqYMGd6Q0UVxVhReUZrazUjUigK4fEcaI5AIAxGUvu0QFaidMOrS4kil60uRAbuH26n44kER2x7vj4LR3P0p6L8BdpoWWrWVj+59ASorxfXdtinRdMl+NqsFxV7vZI0b8MY2ewit5d/EMI1V2IiFuRnA= 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=OBsb5RRy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BIgxgf7m; 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="OBsb5RRy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BIgxgf7m" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078360; 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=Dop/qkJkK0O7Tda551vacFbdZKiU0QbyO4ChptChL2o=; b=OBsb5RRyruCefHZyHXyusry/xryMJ8ZSn2DSfuPUVzc4jhy0I8367ao3MFaidff6ziINxY jDK1ax9GO8XL9AXzKJfTemVDw2TrY5WLE8WyPJ0NtkaiPOe1ix6YHXXA+t8hMFoe2Y792A mXytNRWBL9YT5btU9Fui6cJzogDLmSNes6DCM+AdXqx0qKjmE7silY6d6eGtAwZb/262NU qN6Q4g3oyzB4FIOmChfsyxsiL7phS24R2Kj6x3T8pf8tPrc9H1d9lB+uxdGiOFhCOn+cmd LLysmx3RYTSJPqdNn0F3UiwHZkh00ldnRlFd+PssQ/IcqCZXk8BEUSc/c+1Ndw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078360; 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=Dop/qkJkK0O7Tda551vacFbdZKiU0QbyO4ChptChL2o=; b=BIgxgf7mVuYP57mgI/v5ygZis/MiYYkq2XTWLTy6pZP8QddV1ETA0aU9IWZO38Kkedcc4U zxvjv0vJYYqnf/Bw== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 09/40] x86/cpu: Remove unused TLB strings Date: Tue, 4 Mar 2025 09:51:20 +0100 Message-ID: <20250304085152.51092-10-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner commit e0ba94f14f74 ("x86/tlb_info: get last level TLB entry number of CPU") added the TLB table for parsing CPUID(0x4) including strings describing them. The string entry in the table was never used. Convert it to a comment. Signed-off-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cpu.h | 8 ---- arch/x86/kernel/cpu/intel.c | 80 ++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index 1beccefbaff9..51deb60a9d26 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -33,14 +33,6 @@ struct cpu_dev { #endif }; =20 -struct _tlb_table { - unsigned char descriptor; - char tlb_type; - unsigned int entries; - /* unsigned int ways; */ - char info[128]; -}; - #define cpu_dev_register(cpu_devX) \ static const struct cpu_dev *const __cpu_dev_##cpu_devX __used \ __section(".x86_cpu_dev.init") =3D \ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 905f39fce375..cfd492cf9c3b 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -657,44 +657,50 @@ static unsigned int intel_size_cache(struct cpuinfo_x= 86 *c, unsigned int size) */ #define TLB_0x63_2M_4M_ENTRIES 32 =20 +struct _tlb_table { + unsigned char descriptor; + char tlb_type; + unsigned int entries; +}; + static const struct _tlb_table intel_tlb_table[] =3D { - { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative= " }, - { 0x02, TLB_INST_4M, 2, " TLB_INST 4 MByte pages, full associative" }, - { 0x03, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way set associative= " }, - { 0x04, TLB_DATA_4M, 8, " TLB_DATA 4 MByte pages, 4-way set associative"= }, - { 0x05, TLB_DATA_4M, 32, " TLB_DATA 4 MByte pages, 4-way set associative= " }, - { 0x0b, TLB_INST_4M, 4, " TLB_INST 4 MByte pages, 4-way set associative"= }, - { 0x4f, TLB_INST_4K, 32, " TLB_INST 4 KByte pages" }, - { 0x50, TLB_INST_ALL, 64, " TLB_INST 4 KByte and 2-MByte or 4-MByte page= s" }, - { 0x51, TLB_INST_ALL, 128, " TLB_INST 4 KByte and 2-MByte or 4-MByte pag= es" }, - { 0x52, TLB_INST_ALL, 256, " TLB_INST 4 KByte and 2-MByte or 4-MByte pag= es" }, - { 0x55, TLB_INST_2M_4M, 7, " TLB_INST 2-MByte or 4-MByte pages, fully as= sociative" }, - { 0x56, TLB_DATA0_4M, 16, " TLB_DATA0 4 MByte pages, 4-way set associati= ve" }, - { 0x57, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, 4-way associative" = }, - { 0x59, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, fully associative" = }, - { 0x5a, TLB_DATA0_2M_4M, 32, " TLB_DATA0 2-MByte or 4 MByte pages, 4-way = set associative" }, - { 0x5b, TLB_DATA_4K_4M, 64, " TLB_DATA 4 KByte and 4 MByte pages" }, - { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" }, - { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" }, - { 0x61, TLB_INST_4K, 48, " TLB_INST 4 KByte pages, full associative" }, - { 0x63, TLB_DATA_1G_2M_4M, 4, " TLB_DATA 1 GByte pages, 4-way set associa= tive" - " (plus 32 entries TLB_DATA 2 MByte or 4 MByte pages, not encoded he= re)" }, - { 0x6b, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 8-way associative" }, - { 0x6c, TLB_DATA_2M_4M, 128, " TLB_DATA 2 MByte or 4 MByte pages, 8-way = associative" }, - { 0x6d, TLB_DATA_1G, 16, " TLB_DATA 1 GByte pages, fully associative" }, - { 0x76, TLB_INST_2M_4M, 8, " TLB_INST 2-MByte or 4-MByte pages, fully as= sociative" }, - { 0xb0, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 4-way set associativ= e" }, - { 0xb1, TLB_INST_2M_4M, 4, " TLB_INST 2M pages, 4-way, 8 entries or 4M p= ages, 4-way entries" }, - { 0xb2, TLB_INST_4K, 64, " TLB_INST 4KByte pages, 4-way set associative"= }, - { 0xb3, TLB_DATA_4K, 128, " TLB_DATA 4 KByte pages, 4-way set associativ= e" }, - { 0xb4, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 4-way associative" }, - { 0xb5, TLB_INST_4K, 64, " TLB_INST 4 KByte pages, 8-way set associative= " }, - { 0xb6, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 8-way set associativ= e" }, - { 0xba, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way associative" }, - { 0xc0, TLB_DATA_4K_4M, 8, " TLB_DATA 4 KByte and 4 MByte pages, 4-way a= ssociative" }, - { 0xc1, STLB_4K_2M, 1024, " STLB 4 KByte and 2 MByte pages, 8-way associ= ative" }, - { 0xc2, TLB_DATA_2M_4M, 16, " TLB_DATA 2 MByte/4MByte pages, 4-way assoc= iative" }, - { 0xca, STLB_4K, 512, " STLB 4 KByte pages, 4-way associative" }, + { 0x01, TLB_INST_4K, 32}, /* TLB_INST 4 KByte pages, 4-way set associati= ve */ + { 0x02, TLB_INST_4M, 2}, /* TLB_INST 4 MByte pages, full associative */ + { 0x03, TLB_DATA_4K, 64}, /* TLB_DATA 4 KByte pages, 4-way set associati= ve */ + { 0x04, TLB_DATA_4M, 8}, /* TLB_DATA 4 MByte pages, 4-way set associativ= e */ + { 0x05, TLB_DATA_4M, 32}, /* TLB_DATA 4 MByte pages, 4-way set associati= ve */ + { 0x0b, TLB_INST_4M, 4}, /* TLB_INST 4 MByte pages, 4-way set associativ= e */ + { 0x4f, TLB_INST_4K, 32}, /* TLB_INST 4 KByte pages */ + { 0x50, TLB_INST_ALL, 64}, /* TLB_INST 4 KByte and 2-MByte or 4-MByte pa= ges */ + { 0x51, TLB_INST_ALL, 128}, /* TLB_INST 4 KByte and 2-MByte or 4-MByte p= ages */ + { 0x52, TLB_INST_ALL, 256}, /* TLB_INST 4 KByte and 2-MByte or 4-MByte p= ages */ + { 0x55, TLB_INST_2M_4M, 7}, /* TLB_INST 2-MByte or 4-MByte pages, fully = associative */ + { 0x56, TLB_DATA0_4M, 16}, /* TLB_DATA0 4 MByte pages, 4-way set associa= tive */ + { 0x57, TLB_DATA0_4K, 16}, /* TLB_DATA0 4 KByte pages, 4-way associative= */ + { 0x59, TLB_DATA0_4K, 16}, /* TLB_DATA0 4 KByte pages, fully associative= */ + { 0x5a, TLB_DATA0_2M_4M, 32}, /* TLB_DATA0 2-MByte or 4 MByte pages, 4-wa= y set associative */ + { 0x5b, TLB_DATA_4K_4M, 64}, /* TLB_DATA 4 KByte and 4 MByte pages */ + { 0x5c, TLB_DATA_4K_4M, 128}, /* TLB_DATA 4 KByte and 4 MByte pages */ + { 0x5d, TLB_DATA_4K_4M, 256}, /* TLB_DATA 4 KByte and 4 MByte pages */ + { 0x61, TLB_INST_4K, 48}, /* TLB_INST 4 KByte pages, full associative */ + { 0x63, TLB_DATA_1G_2M_4M, 4}, /* TLB_DATA 1 GByte pages, 4-way set assoc= iative + * (plus 32 entries TLB_DATA 2 MByte or 4 MByte pages, not encoded h= ere) */ + { 0x6b, TLB_DATA_4K, 256}, /* TLB_DATA 4 KByte pages, 8-way associative = */ + { 0x6c, TLB_DATA_2M_4M, 128}, /* TLB_DATA 2 MByte or 4 MByte pages, 8-wa= y associative */ + { 0x6d, TLB_DATA_1G, 16}, /* TLB_DATA 1 GByte pages, fully associative */ + { 0x76, TLB_INST_2M_4M, 8}, /* TLB_INST 2-MByte or 4-MByte pages, fully = associative */ + { 0xb0, TLB_INST_4K, 128}, /* TLB_INST 4 KByte pages, 4-way set associat= ive */ + { 0xb1, TLB_INST_2M_4M, 4}, /* TLB_INST 2M pages, 4-way, 8 entries or 4M= pages, 4-way entries */ + { 0xb2, TLB_INST_4K, 64}, /* TLB_INST 4KByte pages, 4-way set associativ= e */ + { 0xb3, TLB_DATA_4K, 128}, /* TLB_DATA 4 KByte pages, 4-way set associat= ive */ + { 0xb4, TLB_DATA_4K, 256}, /* TLB_DATA 4 KByte pages, 4-way associative = */ + { 0xb5, TLB_INST_4K, 64}, /* TLB_INST 4 KByte pages, 8-way set associati= ve */ + { 0xb6, TLB_INST_4K, 128}, /* TLB_INST 4 KByte pages, 8-way set associat= ive */ + { 0xba, TLB_DATA_4K, 64}, /* TLB_DATA 4 KByte pages, 4-way associative */ + { 0xc0, TLB_DATA_4K_4M, 8}, /* TLB_DATA 4 KByte and 4 MByte pages, 4-way= associative */ + { 0xc1, STLB_4K_2M, 1024}, /* STLB 4 KByte and 2 MByte pages, 8-way asso= ciative */ + { 0xc2, TLB_DATA_2M_4M, 16}, /* TLB_DATA 2 MByte/4MByte pages, 4-way ass= ociative */ + { 0xca, STLB_4K, 512}, /* STLB 4 KByte pages, 4-way associative */ { 0x00, 0, 0 } }; =20 --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 3497A1FC7F5 for ; Tue, 4 Mar 2025 08:52: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=1741078366; cv=none; b=WKCSYzJE1HAqrR+rT4huqQLjS7D/u4ddLIF7j+C1uVncq4StQEnm9LrTV+QjpfeLonzHBRgFUNjca1KD+NVlZ2zz2yhWNLzj22CJJXbSKeDrFaf+sJL/eZ9rPFvzljXBlhVboC6DmU7aCu4pG30efh9/8Ff8Nr3J8NC0RS8U/+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078366; c=relaxed/simple; bh=kr0XFF8MATjQQ8C5nVeTvNNWXuZKh754nmloxOWRwRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dZWx5wqjQFqLwSt8M7CEh5oLk1IbzaU4cOOwAZ++gSm3LbPRkVbV/w9gZHQts7Wl7x3xrge6HamEqs6oQv2d1aOhjDEdyoExJxM0Ic2xWfZN+cctZPHOWWycQMWry8kNR6ZNHLkAdsi/nVgJirG+QXBHveMJCC5T8mvhk/Wc6CU= 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=Qxe3EL5b; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bvNB2p5l; 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="Qxe3EL5b"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bvNB2p5l" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078363; 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=ZetDRpn0NcCndrg1Y0AubvUguUN9OJwsJpVg/UfAF+0=; b=Qxe3EL5bbQMYBElxFRalaAWvamj7kuDM/ifC2mi0lhqSsq0A5J6mXLng5XaF4x9q/HuAs0 YA5oU6K8m5OYL1BMQKvxnA2KBNs5Bm4DTw2OVaeUesD0FjegXbij26fPsYTw/+GQqCjy7h O+Zux/+MLxpnfuxiz8YHVkOcP/UiVXJNhFU+aap2nxIygyfIuetWqq5x16L3/mOn415lAO i41yRARrnUYIwtGJm27XqCFyTHWA0cDlS8K91wpUlnLNZxI9IRtMvZVvtc7ePO3wxyVldi dllRxvn8BagojKn75A4rfhArvfz6EXEYjjY+GQmnZH50OZJJNqUVXJd3fenaXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078363; 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=ZetDRpn0NcCndrg1Y0AubvUguUN9OJwsJpVg/UfAF+0=; b=bvNB2p5lGRYEUh/arP4vpio5KpMEmxqA+ANr08oz8KulnxWhTp1CHVHOeG0/8U1Jt6OSrE ji2OKTPXZP3pqQCA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 10/40] x86/cpu: Remove leaf 0x2 parsing loop and add helpers Date: Tue, 4 Mar 2025 09:51:21 +0100 Message-ID: <20250304085152.51092-11-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Leaf 0x2 output includes a "query count" byte where it was supposed to specify the number of repeated cpuid leaf 0x2 subleaf 0 queries needed to extract all of the hardware's cache and TLB descriptors. Per current Intel manuals, all CPUs supporting this leaf "will always" return an iteration count of 1. Remove the leaf 0x2 query count loop and just query the hardware once. Parse the output with C99 bitfields instead of ugly bitwise operations. Provide leaf 0x2 parsing helpers at asm/cpuid/types.h to do all that. Use the new leaf 0x2 parsing helpers at x86/cpu intel.c. Further commits will also use them for x86/cacheinfo. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 79 ++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/intel.c | 24 +++------ 2 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 arch/x86/include/asm/cpuid/types.h diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h new file mode 100644 index 000000000000..50f6046a57b9 --- /dev/null +++ b/arch/x86/include/asm/cpuid/types.h @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_CPUID_TYPES_H +#define _ASM_X86_CPUID_TYPES_H + +#include + +#include + +/* + * CPUID(0x2) parsing helpers + * Check for_each_leaf_0x2_desc() documentation. + */ + +struct leaf_0x2_reg { + u32 : 31, + invalid : 1; +}; + +union leaf_0x2_regs { + struct leaf_0x2_reg reg[4]; + u32 regv[4]; + u8 desc[16]; +}; + +/** + * get_leaf_0x2_regs() - Return sanitized leaf 0x2 register output + * @regs: Output parameter + * + * Get leaf 0x2 register output and store it in @regs. Invalid byte + * descriptors returned by the hardware will be force set to zero (the + * NULL cache/TLB descriptor) before returning them to the caller. + */ +static inline void get_leaf_0x2_regs(union leaf_0x2_regs *regs) +{ + cpuid_leaf(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_leaf_0x2_desc() - Iterator for leaf 0x2 descriptors + * @regs: Leaf 0x2 register output, as returned by get_leaf_0x2_regs() + * @desc: Pointer to the returned descriptor for each iteration + * + * Loop over the 1-byte descriptors in the passed leaf 0x2 output registers + * @regs. Provide each descriptor through @desc. + * + * Sample usage:: + * + * union leaf_0x2_regs regs; + * u8 *desc; + * + * get_leaf_0x2_regs(®s); + * for_each_leaf_0x2_desc(regs, desc) { + * // Handle *desc value + * } + */ +#define for_each_leaf_0x2_desc(regs, desc) \ + /* Skip the first byte as it is not a descriptor */ \ + for (desc =3D &(regs).desc[1]; desc < &(regs).desc[16]; desc++) + +#endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index cfd492cf9c3b..57e170ffe3ba 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -778,28 +779,15 @@ static void intel_tlb_lookup(const unsigned char desc) =20 static void intel_detect_tlb(struct cpuinfo_x86 *c) { - int i, j, n; - unsigned int regs[4]; - unsigned char *desc =3D (unsigned char *)regs; + union leaf_0x2_regs regs; + u8 *desc; =20 if (c->cpuid_level < 2) return; =20 - /* Number of times to iterate */ - n =3D cpuid_eax(2) & 0xFF; - - for (i =3D 0 ; i < n ; i++) { - cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]); - - /* If bit 31 is set, this is an unknown format */ - for (j =3D 0 ; j < 4 ; j++) - if (regs[j] & (1 << 31)) - regs[j] =3D 0; - - /* Byte 0 is level count, not a descriptor */ - for (j =3D 1 ; j < 16 ; j++) - intel_tlb_lookup(desc[j]); - } + get_leaf_0x2_regs(®s); + for_each_leaf_0x2_desc(regs, desc) + intel_tlb_lookup(*desc); } =20 static const struct cpu_dev intel_cpu_dev =3D { --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 A425E1FECA6 for ; Tue, 4 Mar 2025 08:52: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=1741078369; cv=none; b=qLAGxW0k5D7xWyusY/mkwAZebT9qjDoO52dwzB2EOCYUxEi7d1/oH32xBYkU4UuQqbeVtp+4vxUayAAbo9HWG3AGTM7P8ulMSlT2yDfRh0CNekqb+UQzmC6YAzSRuncGTFmVBtfpNkEh/kpMo7bJzaoUnIJRtkp+WB6D6hLIAuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078369; c=relaxed/simple; bh=Tmj/cLIyeG6+f+uZ16VKIG/sVwDhoLo8Vqglr6TX98c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LA9vifDXxi1UAxvrpytjibXGIwoowRzsUAMpkhsyUoWzuPm6gUwpl7UHIYxdnlKpvBg+gEhrwq2PrRS1D34dRAt+ICZuZ7kPxlXzEcmgYz9egJ82l2jGt0NiQz2I3Q74bbcsfMX3C4E/1ZTgP+/Rpj83g5E7FYKJClQ4NRx12E8= 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=Xnj8RG68; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BFom4vVq; 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="Xnj8RG68"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BFom4vVq" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078366; 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=wyMX8soR+fgFHwjHOc5NCrkcv2E7TNoGZkTf9OqgSm4=; b=Xnj8RG68pM6Lfmqt0AXl376Sbv8mDwI62MG8Hw/Ls6hpS9ettgFhHrcqGBiPNpDfznljc+ lqCYq62U1RZBF1sH7LIEBtjmDgk5yVCGfrtLvYTP0oqtzBFQaCS3HeABXWfPmszMaYxi+i 5vtFiH2DJD2sjt+VGzYufzoH7YBxp8qeAolWh3QxAndsQ8go6q+tAgRYfAjpf3JrXMKRQY 5jOh4wfJrdpg608MLRTF0xXjzE8UvPV5FjVM2Oq3FfDIKQcf6NPDVIGn/j/uNQ2XZ4YJdu NY1rGBRXy3tWQ8nQySVPXEj0JBnB4Jcpj0MQUNeTv8KIZ+47Qw180VSvvSsjdw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078366; 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=wyMX8soR+fgFHwjHOc5NCrkcv2E7TNoGZkTf9OqgSm4=; b=BFom4vVq9eGlnA1qDBWMLueLbFD8L1M/odxgkol3x6ij1I+XlgnSVjOa670jdm3jT+adza YOvbh7Z2ibRfKBBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 11/40] x86/cacheinfo: Remove the P4 trace leftovers for real Date: Tue, 4 Mar 2025 09:51:22 +0100 Message-ID: <20250304085152.51092-12-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner commit 851026a2bf54 ("x86/cacheinfo: Remove unused trace variable") removed the switch case for LVL_TRACE but did not get rid of the surrounding gunk. Signed-off-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index a6c6bccfa8b8..eccffe2ea06c 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -31,7 +31,6 @@ #define LVL_1_DATA 2 #define LVL_2 3 #define LVL_3 4 -#define LVL_TRACE 5 =20 /* Shared last level cache maps */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); @@ -96,10 +95,6 @@ static const struct _cache_table cache_table[] =3D { 0x66, LVL_1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ { 0x67, LVL_1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte lin= e size */ { 0x68, LVL_1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte lin= e size */ - { 0x70, LVL_TRACE, 12 }, /* 8-way set assoc */ - { 0x71, LVL_TRACE, 16 }, /* 8-way set assoc */ - { 0x72, LVL_TRACE, 32 }, /* 8-way set assoc */ - { 0x73, LVL_TRACE, 64 }, /* 8-way set assoc */ { 0x78, LVL_2, MB(1) }, /* 4-way set assoc, 64 byte line size */ { 0x79, LVL_2, 128 }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ { 0x7a, LVL_2, 256 }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ @@ -787,19 +782,13 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) } } } - /* - * Don't use cpuid2 if cpuid4 is supported. For P4, we use cpuid2 for - * trace cache - */ - if ((!ci->num_leaves || c->x86 =3D=3D 15) && c->cpuid_level > 1) { + + /* Don't use CPUID(2) if CPUID(4) is supported. */ + if (!ci->num_leaves && c->cpuid_level > 1) { /* supports eax=3D2 call */ int j, n; unsigned int regs[4]; unsigned char *dp =3D (unsigned char *)regs; - int only_trace =3D 0; - - if (ci->num_leaves && c->x86 =3D=3D 15) - only_trace =3D 1; =20 /* Number of times to iterate */ n =3D cpuid_eax(2) & 0xFF; @@ -820,8 +809,6 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) /* look up this descriptor in the table */ while (cache_table[k].descriptor !=3D 0) { if (cache_table[k].descriptor =3D=3D des) { - if (only_trace && cache_table[k].cache_type !=3D LVL_TRACE) - break; switch (cache_table[k].cache_type) { case LVL_1_INST: l1i +=3D cache_table[k].size; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 969B21FECDF for ; Tue, 4 Mar 2025 08:52: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=1741078372; cv=none; b=bR8u6q03k/TA46r7otm+kW8cNzaF14m5+1Z29DiFZtmjTa7U2lrm2aIHnGxo3wVtQcFAFFFq/SBSWJZabSORAv7lsWuCIkNm72E6GAdXIsjzrpvgkk3M3ODAb6q0eo6kJLJrPWxdM3twdp0mV/Nr72zW9zUCMvzxPX9gGIfyE2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078372; c=relaxed/simple; bh=ka6KnAwJyLF+pZAcSuUypA3tLRXWbzf3/ahC0RCkJ5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GoA+QU3Aoq2HcPfaJij15cJihSw7iFYVbWjClB8IzXeMR+spYxPDsOuHYHs24WjEFK+9FE46DES8fnJGEGRBPidca1PXEPYT9HNwM6vQ85ZoX5dIj0CBiwFGWBrKROjrnygq0Kb3dsii40cMpOiYA7g1XhmRp+UHQ8CwGDhoYsI= 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=L72zysiZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ff5CIIAX; 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="L72zysiZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ff5CIIAX" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078369; 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=dBenYQvYHCMUAVdV1uDeDm0GAHb1Xqw9kFWAtKQ364A=; b=L72zysiZeaquGuhk+c8CdDE7BL5EPdJhAPttcsoqRp9u/+JsaqW7ryjdTRA42uRIxLOHf7 exb6nWsPVtuei4T9maGlc7asHWTKKkLjW4iGi9ULpqOpYivH+Mdm0tcyaIXoe90cl7AJlp ZelzZ6rF/HCo9gkayseqkCaKJIgM/rDNE811KVtFJxfXOfFrO4O9XNWtM+IPj9qPkFyWXI H+OIII6CkUhASy4+WoVyGYyMrzdQyKQH8o/113q/41VehY8DSdAX+Ws6gG8UR/6KiruGnJ wPC73FY/X+OGDXzUwvVOdguIzJYlAFnsFZi1Fa4fGTmqL1Lu/ZvXNOdvXY3Mxg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078369; 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=dBenYQvYHCMUAVdV1uDeDm0GAHb1Xqw9kFWAtKQ364A=; b=ff5CIIAXtWGu/8dy6eRsJTD1pRl8ogujd3bMgPJNNHrWZKhrWZVyrXOqgAAO/BnBfeWk/e 1/Ih/8rkjpCZDUCA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 12/40] x86/cacheinfo: Remove unnecessary headers and reorder the rest Date: Tue, 4 Mar 2025 09:51:23 +0100 Message-ID: <20250304085152.51092-13-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Remove the headers at cacheinfo.c that are no longer required. Alphabetically reorder what remains since more headers will be included in further commits. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index eccffe2ea06c..b3a520959b51 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -8,21 +8,19 @@ * Andi Kleen / Andreas Herrmann : CPUID4 emulation on AMD. */ =20 -#include #include +#include #include #include -#include -#include -#include #include #include +#include =20 -#include -#include #include -#include +#include +#include #include +#include #include =20 #include "cpu.h" --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 9E43F1FCF45 for ; Tue, 4 Mar 2025 08:52: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=1741078375; cv=none; b=dBpu8swg4xkhrRwq537+wHuKZARdZ4wxp97kG/+3LBQb2MZnWfmeva5ng07j0nQmqNuyIAKtjJ0FZzIr8xHTwdU81Cj9Cp79qHBxjw10z9E9sa61MXt5UQDWEcx66T+2nrIlgTVVmEZqEJOUpRLKbSkJ3GBjuWdPMchtHnBEIqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078375; c=relaxed/simple; bh=P7qlq6ZvwZDsjPBTexjUFuLSgzMlMlKKacbkQDaQfEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ge2i2xvBxKx+5NkKXhZ5LDz0oPsC7O8IX8hGQ2HxjzslnMd8p7+blvCBDjbr3irqm2NaEQm5/dJmv8XTq3+lfWgebZdKeX5fZoZOPCevOVzDPZKJ9/QrYHqPNAK0cZWM2N6uEBTGO+JVTte5hd8FJeIYAagugapzf3JX04w2sDI= 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=o6wIki+A; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zTXMQpbj; 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="o6wIki+A"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zTXMQpbj" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078372; 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=Ec7bhkZNZivmIllIc/9fS7tooTG3RoeriGRfob1Am3g=; b=o6wIki+A/58P5BL6w7/cmGJ/1iUpMKgi6YbnvfhRYcY5Y2sJvL+tD3yzwy5zV4+X2sF/oM m/TRZ1IgijZRM0h06jcjOWnHrFLTb+tbVAb99gHBXWvf5qSLCE55wo6udRzcCea5ic1JlT SNgjIfpg2hO9UDSpp9lMvNelhnFfaz44yQu6+FDuvbYRCm3Brg0JXI5Sm3Kk5NaLLXufjJ ioKEMCmmBxqi2Ae2MsiHX5JwLL+PsbmLgMCzCIjgudp0IIHY72Ohg8scLathf2oyFuVsbP /bsbJKvx1G5MdCLvwUjdllVBnND2JaYsK1FmKrXJloGiE83zpqeMShyUZrebLA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078372; 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=Ec7bhkZNZivmIllIc/9fS7tooTG3RoeriGRfob1Am3g=; b=zTXMQpbjJYiDL9SUwOo7IwX3r2wbqva+BDK8b2RB++dAmrsORSsObXt/XcC9Z9I52+cmUG surjLxPddcBrvUBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 13/40] x86/cacheinfo: Use cpuid leaf 0x2 parsing helpers Date: Tue, 4 Mar 2025 09:51:24 +0100 Message-ID: <20250304085152.51092-14-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 parsing helpers added in previous commits, which queries the cpuid leaf just once. Note, this also makes the leaf 0x2 parsing logic be shared with x86/cpu intel.c Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 66 +++++++++++++-------------------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index b3a520959b51..ebd72016e7a2 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -783,50 +784,35 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) =20 /* Don't use CPUID(2) if CPUID(4) is supported. */ if (!ci->num_leaves && c->cpuid_level > 1) { - /* supports eax=3D2 call */ - int j, n; - unsigned int regs[4]; - unsigned char *dp =3D (unsigned char *)regs; - - /* Number of times to iterate */ - n =3D cpuid_eax(2) & 0xFF; - - for (i =3D 0 ; i < n ; i++) { - cpuid(2, ®s[0], ®s[1], ®s[2], ®s[3]); - - /* If bit 31 is set, this is an unknown format */ - for (j =3D 0 ; j < 4 ; j++) - if (regs[j] & (1 << 31)) - regs[j] =3D 0; - - /* Byte 0 is level count, not a descriptor */ - for (j =3D 1 ; j < 16 ; j++) { - unsigned char des =3D dp[j]; - unsigned char k =3D 0; - - /* look up this descriptor in the table */ - while (cache_table[k].descriptor !=3D 0) { - if (cache_table[k].descriptor =3D=3D des) { - switch (cache_table[k].cache_type) { - case LVL_1_INST: - l1i +=3D cache_table[k].size; - break; - case LVL_1_DATA: - l1d +=3D cache_table[k].size; - break; - case LVL_2: - l2 +=3D cache_table[k].size; - break; - case LVL_3: - l3 +=3D cache_table[k].size; - break; - } - + union leaf_0x2_regs regs; + u8 *desc; + + get_leaf_0x2_regs(®s); + for_each_leaf_0x2_desc(regs, desc) { + unsigned char k =3D 0; + + /* look up this descriptor in the table */ + while (cache_table[k].descriptor !=3D 0) { + if (cache_table[k].descriptor =3D=3D *desc) { + switch (cache_table[k].cache_type) { + case LVL_1_INST: + l1i +=3D cache_table[k].size; + break; + case LVL_1_DATA: + l1d +=3D cache_table[k].size; + break; + case LVL_2: + l2 +=3D cache_table[k].size; + break; + case LVL_3: + l3 +=3D cache_table[k].size; break; } =20 - k++; + break; } + + k++; } } } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 A65CB1FF1CC for ; Tue, 4 Mar 2025 08:52: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=1741078378; cv=none; b=EU2miwXEr3ZBHxccLIUfSrgyWcEFO+qijPtbAqYJCzUBvgZyJ1vqlk3NRo/7W3mafxoIyO27Zd8cJBALPziIYkL9b+adW7U9j1NGegIfkOuwz1eNx3d3fgBef93BpFmjWuu4Z6pVeAYXUxhl+KqlDzoId9HtFBq8eEPjVHw5VtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078378; c=relaxed/simple; bh=EnEH/HxL7CFApfE2738rn4UaluGnGilQnm9yKXmH4pM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fYE6ObufytM81aDXx6yKDb3k3k2JgyHOXgJhy2Pr1iYk1SS41qzheo9pYQH217wPedWHmKMdQ8XqWnNHRCGWDAYGCSbzDQvL+QAIb2pj6ehHTjfMfGZEul6Hzg+799vkHKnOYDTx3d4kljE13hoMdV6vqs+9+5d/jCqTOD/NL2A= 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=CFg9Antq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3WGlTcb0; 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="CFg9Antq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3WGlTcb0" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078375; 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=gIkB3EWOtaCyLLbuByoHG0PeQx63B1yTmcOIalcAzmE=; b=CFg9Antq/UQcZuu6IrARirHs+nWuVHcFNTarQvG6e529eblIKQKundAaYXS7vyBhfMZ3lh iX243a0zFhI6xXfVktxAQNrqsexIrE/fQmUToOp5WbSw9QVTcqW58xhzEHzVVMm5/VRjz0 lmV1uFMBRgAKyZ+KFHgtfBH9jSqMc5Z/O6vd/su2d9G2Sr515aa3983wugT0j4a1x9ixwQ rsPJOjt28mDGdvfw9BY47+m2VfLRn2N8QmJHgfUcpiB6DpHYZ8sLbXAyGDvqbiEvLWmbq9 tzhhUBv6MrZNExxRz03HvfthnXWPVXTgSiHCxmVT7brWwrCQkUE/uLqTRLvq/Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078375; 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=gIkB3EWOtaCyLLbuByoHG0PeQx63B1yTmcOIalcAzmE=; b=3WGlTcb08Zk/VlD+EYPxL7YSE+/5yDkNPktNeGTZp/kSE9SUDT8XeOOBdtN+Hq5S1+uG0e vNdvaHciFcQyScBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 14/40] x86/cacheinfo: Refactor leaf 0x2 cache descriptor lookup Date: Tue, 4 Mar 2025 09:51:25 +0100 Message-ID: <20250304085152.51092-15-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner Extract the cache descriptor lookup logic out of the leaf 0x2 parsing code and into a dedicated function. This disentangles such lookup from the deeply nested leaf 0x2 parsing loop. Remove the cache table termination entry, as it is no longer needed after the ARRAY_SIZE()-based lookup. [darwi: Move refactoring logic into this separate commit + commit log. Remove the cache table termination entry.] Signed-off-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 45 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index ebd72016e7a2..3be7ea8444ec 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -123,7 +123,6 @@ static const struct _cache_table cache_table[] =3D { 0xea, LVL_3, MB(12) }, /* 24-way set assoc, 64 byte line size */ { 0xeb, LVL_3, MB(18) }, /* 24-way set assoc, 64 byte line size */ { 0xec, LVL_3, MB(24) }, /* 24-way set assoc, 64 byte line size */ - { 0x00, 0, 0} }; =20 =20 @@ -728,6 +727,16 @@ void init_hygon_cacheinfo(struct cpuinfo_x86 *c) ci->num_leaves =3D find_num_cache_leaves(c); } =20 +static const struct _cache_table *cache_table_get(u8 desc) +{ + for (int i =3D 0; i < ARRAY_SIZE(cache_table); i++) { + if (cache_table[i].descriptor =3D=3D desc) + return &cache_table[i]; + } + + return NULL; +} + void init_intel_cacheinfo(struct cpuinfo_x86 *c) { /* Cache sizes */ @@ -784,35 +793,21 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) =20 /* Don't use CPUID(2) if CPUID(4) is supported. */ if (!ci->num_leaves && c->cpuid_level > 1) { + const struct _cache_table *entry; union leaf_0x2_regs regs; u8 *desc; =20 get_leaf_0x2_regs(®s); for_each_leaf_0x2_desc(regs, desc) { - unsigned char k =3D 0; - - /* look up this descriptor in the table */ - while (cache_table[k].descriptor !=3D 0) { - if (cache_table[k].descriptor =3D=3D *desc) { - switch (cache_table[k].cache_type) { - case LVL_1_INST: - l1i +=3D cache_table[k].size; - break; - case LVL_1_DATA: - l1d +=3D cache_table[k].size; - break; - case LVL_2: - l2 +=3D cache_table[k].size; - break; - case LVL_3: - l3 +=3D cache_table[k].size; - break; - } - - break; - } - - k++; + entry =3D cache_table_get(*desc); + if (!entry) + continue; + + switch (entry->cache_type) { + case LVL_1_INST: l1i +=3D entry->size; break; + case LVL_1_DATA: l1d +=3D entry->size; break; + case LVL_2: l2 +=3D entry->size; break; + case LVL_3: l3 +=3D entry->size; break; } } } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 9FABF1FF5F1 for ; Tue, 4 Mar 2025 08:52: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=1741078381; cv=none; b=I/T87Gfx0Hne5k1giPFrH/UxjX14atlDzz4H+v/qeflThEPtaZ2etDjXrEwdFT0g/OWEaxel5Aqp29gQ6f8E4FjC5sd+XTC/MWSxZaihXzJGwMjW1EF5pAjGMAiZK7UGBIBvg4zB3mkFxfDvom7Qlpx33rDqROrKQRE89t4T12U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078381; c=relaxed/simple; bh=2ISi/BmkfTGvQiIunIigGmW6qc7/h3mdah4zLn6e808=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pgp/a5U3X02Ne/z+v3vqrJbQQdrHLsLOq1NfYMSN5yywKWz0wdtaskgAi3pkaCj6MpBJ0n5GY8WpIzpvqMGMzpGvSRfbVS1JuOMlh31UxCUhDfbyyirzNr1vuBHfxImUopfydZb+u2S4xU9cJRcgKdOMT0BExLsT99fcQjDIhdA= 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=eNm4AuxD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yfc74S8C; 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="eNm4AuxD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yfc74S8C" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078378; 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=dEB1hgCePv+Z7eLVlwXr81lW6Eepp/nb4cZzNnOU4zE=; b=eNm4AuxDKI+Iznd/DSfUs3X7G0l0krIVgfu9p1n18jDtJmcFdwm9ReZ0zRTRLpPd6K5pH6 0IQEjLLcRKSeCzNOCFsQgivMiWI+co+BcwNxuM2QnnrNAF44OkClqBw1IjzBxS9fohbepR rYcpI8epwwBTHRd8Lvx7wciEZm2fKqPQdAPrjYxZrsMOu3nV9FIl7mW4bmVYOApjNI8ReI 7yHTNV4SrmmdYMxRelEtjE7P3LvzC5++uVIhnjiofEeRQiynRjBLQgem1r3H8Ja0pH5qTS 842487dFhRRdUfduhjAAV8sqm/buEHSeZzwV6pOjNkst/5C498d7H9Zpv0Vxmw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078378; 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=dEB1hgCePv+Z7eLVlwXr81lW6Eepp/nb4cZzNnOU4zE=; b=yfc74S8CthYcAJri1vgvQ2qzJT3z32Q4wDS7oPWCN82jTXeWj0qsn3ZiSHUZsc97yzG1bb 3LZdaSkr0+x6CeCw== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 15/40] x86/cacheinfo: Properly name amd_cpuid4()'s first parameter Date: Tue, 4 Mar 2025 09:51:26 +0100 Message-ID: <20250304085152.51092-16-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner amd_cpuid4()'s first parameter, "leaf", is not a cpuid leaf as the name implies. Rather, it's an index emulating CPUID(4)'s subleaf semantics; i.e. an ID for the cache object currently enumerated. Rename that parameter to "index". Apply minor coding style fixes to the rest of the function as well. [darwi: Move into a separate commit and write commit log. Use "index" instead of "subleaf" for amd_cpuid4() first param, as that's the name typically used at the whole of cacheinfo.c.] Signed-off-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 3be7ea8444ec..24a7503f37e2 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -233,12 +233,10 @@ static const enum cache_type cache_type_map[] =3D { }; =20 static void -amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, - union _cpuid4_leaf_ebx *ebx, - union _cpuid4_leaf_ecx *ecx) +amd_cpuid4(int index, union _cpuid4_leaf_eax *eax, + union _cpuid4_leaf_ebx *ebx, union _cpuid4_leaf_ecx *ecx) { - unsigned dummy; - unsigned line_size, lines_per_tag, assoc, size_in_kb; + unsigned int dummy, line_size, lines_per_tag, assoc, size_in_kb; union l1_cache l1i, l1d; union l2_cache l2; union l3_cache l3; @@ -251,7 +249,7 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, cpuid(0x80000005, &dummy, &dummy, &l1d.val, &l1i.val); cpuid(0x80000006, &dummy, &dummy, &l2.val, &l3.val); =20 - switch (leaf) { + switch (index) { case 1: l1 =3D &l1i; fallthrough; @@ -289,12 +287,11 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax, } =20 eax->split.is_self_initializing =3D 1; - eax->split.type =3D types[leaf]; - eax->split.level =3D levels[leaf]; + 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(); =20 - if (assoc =3D=3D 0xffff) eax->split.is_fully_associative =3D 1; ebx->split.coherency_line_size =3D line_size - 1; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 4F4B01FF613 for ; Tue, 4 Mar 2025 08:53: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=1741078385; cv=none; b=oVi9yXSRK/j0lNb1UUP4FQRXlciXzAr1qiOpcuaAdbJuxuEh01MBhQruYJnNdSXz4HyZ/pxH2nIbtTZlEsJ72bT3X38DUdN+CHXU6ebrdyWrPWVSjeS5OdNuQqhJR6dikokNJ2QC120F+47Dq9+b9uV/hHm0Ri7uFKFvCjJn8j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078385; c=relaxed/simple; bh=FXI0EngGufpm1ClJZawAgo79SDBHK0lEe5QmJ9Fn4/I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VUsjr9q32JZ/FdTQRTL6HIZVPjMBHhDnGiMtOb49P+3aVTeJ7KTNu1LpR+2dfSTzvEa4s7mcII9V4jiH3WOEOba0CmtwGNHegPebR6pvhTwr46vSMo3txW5Lt0fZlMcFx8BW1bjcp1FamOTjEsj/QV9rClnNAhU0qWlyru/lhUU= 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=iFCv2pcC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=cTjxwVqC; 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="iFCv2pcC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="cTjxwVqC" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078381; 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=nR43TTpUL94TkpNNz9T2pfL2pjZcLoSQvUc3OWGFnAg=; b=iFCv2pcC45HY4800VbKA7hrUIFvD7VmWxvhzljI/iYPx4hx7wpJN0Ww9XQqNmuID7JFw2H /8YU6dEZY9Zb/clIuCxdhReqWXaRMpm3V5NBaPw720t3GIznFKu7a3NLkjs4fmvAh29t0Z Jtb/NioUy/Z4UkvDTS4YQ0MHWC+bORNWWrgNxmrkslSgrZ0dYBcEBccFc8wNf01zSLFvd+ S53Aqzksj2/ov+uOn2htS5DFm8fA6ym1aCJi3gxff7Y7wjZkZvDldmTEqIJ/O/dQilmAf1 tOfdHVaTQsv12y6bDeJNOoG4VHRu+EptaOyiXc2IPfC7THodn2uhe/mrKviISw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078381; 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=nR43TTpUL94TkpNNz9T2pfL2pjZcLoSQvUc3OWGFnAg=; b=cTjxwVqCdCjMALGXTIoPPDefM9V/PzFet7H1lbrojf7uFADcW4ObKLVBZdSEBkEgdm72/O hNS2Xcocu9gMDUDw== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 16/40] x86/cacheinfo: Use proper name for cacheinfo instances Date: Tue, 4 Mar 2025 09:51:27 +0100 Message-ID: <20250304085152.51092-17-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner The cacheinfo structure defined at include/linux/cacheinfo.h is a generic cache info object representation. Calling its instances at x86 cacheinfo.c "leaf" confuses it with a cpuid leaf -- especially that multiple cpuid calls are already sprinkled across that file. Most of such instances also have a redundant "this_" prefix. Rename all of the cacheinfo "this_leaf" instances to just "ci". [darwi: Move into separate commit and write commit log] Signed-off-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 89 ++++++++++++++++----------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 24a7503f37e2..5deffc834291 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -349,11 +349,10 @@ static int amd_get_l3_disable_slot(struct amd_northbr= idge *nb, unsigned slot) return -1; } =20 -static ssize_t show_cache_disable(struct cacheinfo *this_leaf, char *buf, - unsigned int slot) +static ssize_t show_cache_disable(struct cacheinfo *ci, char *buf, unsigne= d int slot) { int index; - struct amd_northbridge *nb =3D this_leaf->priv; + struct amd_northbridge *nb =3D ci->priv; =20 index =3D amd_get_l3_disable_slot(nb, slot); if (index >=3D 0) @@ -367,8 +366,8 @@ static ssize_t \ cache_disable_##slot##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ - struct cacheinfo *this_leaf =3D dev_get_drvdata(dev); \ - return show_cache_disable(this_leaf, buf, slot); \ + struct cacheinfo *ci =3D dev_get_drvdata(dev); \ + return show_cache_disable(ci, buf, slot); \ } SHOW_CACHE_DISABLE(0) SHOW_CACHE_DISABLE(1) @@ -435,18 +434,17 @@ static int amd_set_l3_disable_slot(struct amd_northbr= idge *nb, int cpu, return 0; } =20 -static ssize_t store_cache_disable(struct cacheinfo *this_leaf, - const char *buf, size_t count, - unsigned int slot) +static ssize_t store_cache_disable(struct cacheinfo *ci, const char *buf, + size_t count, unsigned int slot) { unsigned long val =3D 0; int cpu, err =3D 0; - struct amd_northbridge *nb =3D this_leaf->priv; + struct amd_northbridge *nb =3D ci->priv; =20 if (!capable(CAP_SYS_ADMIN)) return -EPERM; =20 - cpu =3D cpumask_first(&this_leaf->shared_cpu_map); + cpu =3D cpumask_first(&ci->shared_cpu_map); =20 if (kstrtoul(buf, 10, &val) < 0) return -EINVAL; @@ -467,8 +465,8 @@ cache_disable_##slot##_store(struct device *dev, \ struct device_attribute *attr, \ const char *buf, size_t count) \ { \ - struct cacheinfo *this_leaf =3D dev_get_drvdata(dev); \ - return store_cache_disable(this_leaf, buf, count, slot); \ + struct cacheinfo *ci =3D dev_get_drvdata(dev); \ + return store_cache_disable(ci, buf, count, slot); \ } STORE_CACHE_DISABLE(0) STORE_CACHE_DISABLE(1) @@ -476,8 +474,8 @@ STORE_CACHE_DISABLE(1) static ssize_t subcaches_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct cacheinfo *this_leaf =3D dev_get_drvdata(dev); - int cpu =3D cpumask_first(&this_leaf->shared_cpu_map); + struct cacheinfo *ci =3D dev_get_drvdata(dev); + int cpu =3D cpumask_first(&ci->shared_cpu_map); =20 return sprintf(buf, "%x\n", amd_get_subcaches(cpu)); } @@ -486,8 +484,8 @@ static ssize_t subcaches_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct cacheinfo *this_leaf =3D dev_get_drvdata(dev); - int cpu =3D cpumask_first(&this_leaf->shared_cpu_map); + struct cacheinfo *ci =3D dev_get_drvdata(dev); + int cpu =3D cpumask_first(&ci->shared_cpu_map); unsigned long val; =20 if (!capable(CAP_SYS_ADMIN)) @@ -511,10 +509,10 @@ cache_private_attrs_is_visible(struct kobject *kobj, struct attribute *attr, int unused) { struct device *dev =3D kobj_to_dev(kobj); - struct cacheinfo *this_leaf =3D dev_get_drvdata(dev); + struct cacheinfo *ci =3D dev_get_drvdata(dev); umode_t mode =3D attr->mode; =20 - if (!this_leaf->priv) + if (!ci->priv) return 0; =20 if ((attr =3D=3D &dev_attr_subcaches.attr) && @@ -562,11 +560,11 @@ static void init_amd_l3_attrs(void) } =20 const struct attribute_group * -cache_get_priv_group(struct cacheinfo *this_leaf) +cache_get_priv_group(struct cacheinfo *ci) { - struct amd_northbridge *nb =3D this_leaf->priv; + struct amd_northbridge *nb =3D ci->priv; =20 - if (this_leaf->level < 3 || !nb) + if (ci->level < 3 || !nb) return NULL; =20 if (nb && nb->l3_cache.indices) @@ -846,7 +844,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, struct _cpuid4_info_regs *base) { struct cpu_cacheinfo *this_cpu_ci; - struct cacheinfo *this_leaf; + struct cacheinfo *ci; int i, sibling; =20 /* @@ -858,12 +856,12 @@ static int __cache_amd_cpumap_setup(unsigned int cpu,= int index, this_cpu_ci =3D get_cpu_cacheinfo(i); if (!this_cpu_ci->info_list) continue; - this_leaf =3D this_cpu_ci->info_list + index; + ci =3D this_cpu_ci->info_list + index; for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) { if (!cpu_online(sibling)) continue; cpumask_set_cpu(sibling, - &this_leaf->shared_cpu_map); + &ci->shared_cpu_map); } } } else if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { @@ -883,14 +881,14 @@ static int __cache_amd_cpumap_setup(unsigned int cpu,= int index, if ((apicid < first) || (apicid > last)) continue; =20 - this_leaf =3D this_cpu_ci->info_list + index; + ci =3D this_cpu_ci->info_list + index; =20 for_each_online_cpu(sibling) { apicid =3D cpu_data(sibling).topo.apicid; if ((apicid < first) || (apicid > last)) continue; cpumask_set_cpu(sibling, - &this_leaf->shared_cpu_map); + &ci->shared_cpu_map); } } } else @@ -903,7 +901,7 @@ static void __cache_cpumap_setup(unsigned int cpu, int = index, struct _cpuid4_info_regs *base) { struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); - struct cacheinfo *this_leaf, *sibling_leaf; + struct cacheinfo *ci, *sibling_ci; unsigned long num_threads_sharing; int index_msb, i; struct cpuinfo_x86 *c =3D &cpu_data(cpu); @@ -914,10 +912,10 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, return; } =20 - this_leaf =3D this_cpu_ci->info_list + index; + ci =3D this_cpu_ci->info_list + index; num_threads_sharing =3D 1 + base->eax.split.num_threads_sharing; =20 - cpumask_set_cpu(cpu, &this_leaf->shared_cpu_map); + cpumask_set_cpu(cpu, &ci->shared_cpu_map); if (num_threads_sharing =3D=3D 1) return; =20 @@ -929,28 +927,27 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, =20 if (i =3D=3D cpu || !sib_cpu_ci->info_list) continue;/* skip if itself or no cacheinfo */ - sibling_leaf =3D sib_cpu_ci->info_list + index; - cpumask_set_cpu(i, &this_leaf->shared_cpu_map); - cpumask_set_cpu(cpu, &sibling_leaf->shared_cpu_map); + sibling_ci =3D sib_cpu_ci->info_list + index; + cpumask_set_cpu(i, &ci->shared_cpu_map); + cpumask_set_cpu(cpu, &sibling_ci->shared_cpu_map); } } =20 -static void ci_leaf_init(struct cacheinfo *this_leaf, - struct _cpuid4_info_regs *base) +static void ci_info_init(struct cacheinfo *ci, struct _cpuid4_info_regs *b= ase) { - this_leaf->id =3D base->id; - this_leaf->attributes =3D CACHE_ID; - this_leaf->level =3D base->eax.split.level; - this_leaf->type =3D cache_type_map[base->eax.split.type]; - this_leaf->coherency_line_size =3D + ci->id =3D base->id; + ci->attributes =3D CACHE_ID; + ci->level =3D base->eax.split.level; + ci->type =3D cache_type_map[base->eax.split.type]; + ci->coherency_line_size =3D base->ebx.split.coherency_line_size + 1; - this_leaf->ways_of_associativity =3D + ci->ways_of_associativity =3D base->ebx.split.ways_of_associativity + 1; - this_leaf->size =3D base->size; - this_leaf->number_of_sets =3D base->ecx.split.number_of_sets + 1; - this_leaf->physical_line_partition =3D + ci->size =3D base->size; + ci->number_of_sets =3D base->ecx.split.number_of_sets + 1; + ci->physical_line_partition =3D base->ebx.split.physical_line_partition + 1; - this_leaf->priv =3D base->nb; + ci->priv =3D base->nb; } =20 int init_cache_level(unsigned int cpu) @@ -984,7 +981,7 @@ int populate_cache_leaves(unsigned int cpu) { unsigned int idx, ret; struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); - struct cacheinfo *this_leaf =3D this_cpu_ci->info_list; + struct cacheinfo *ci =3D this_cpu_ci->info_list; struct _cpuid4_info_regs id4_regs =3D {}; =20 for (idx =3D 0; idx < this_cpu_ci->num_leaves; idx++) { @@ -992,7 +989,7 @@ int populate_cache_leaves(unsigned int cpu) if (ret) return ret; get_cache_id(cpu, &id4_regs); - ci_leaf_init(this_leaf++, &id4_regs); + ci_info_init(ci++, &id4_regs); __cache_cpumap_setup(cpu, idx, &id4_regs); } this_cpu_ci->cpu_map_populated =3D true; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 A27751FCFD2 for ; Tue, 4 Mar 2025 08:53: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=1741078388; cv=none; b=NDQsKmW52zJKX31H+I22HyX6Aczr96D2U85qVFronKAjL2/7CIyDF2tXMS6qOD7PSfCpryk4LMfJxhHyxfsO+6iRlw8AyUxrTuNA2tJmajbVhrS003zCPsSt3aS13s+NOKgc5xnxeQTt4ccP4ymBTJ0+daWB7oJJ7pTkGkpt6y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078388; c=relaxed/simple; bh=CZOBlrKslq4YWqHeNKiFoVf0iAMklIwd5UDHUvzTcG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M2F38biYlksEFlVamvKaBP39TGyIOoxiooKrHe4k9yzUxLEnegtqwaf4lNGOqUyjXC8yM6/32jbftYuD/B1P36fZV5ZTb7N2AyrPQb8jcgz89qNr9IcDH2rxHUMpeZCGsCz+QcPcuNrqTg5BeMgV/4Lrrl5bdTpxa5CXgJ34I2E= 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=Ed8RF6tw; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JhWCumRj; 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="Ed8RF6tw"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JhWCumRj" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078385; 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=N9GXN+I+HxjtZy8DzjkmjTZt67y3X5bRcXOLv7ZM9iU=; b=Ed8RF6tw5GsGELM7gXSqyOqP0VWC+RPN/yG/Ub/vdiMAxzZl3B9P2H5Vx/1M7RZNN6isHd d9CF//yjCCMHXxxzjEMjDdCfC2zPJ/cdXaA+QINlkLigMP/xyqz+DPrtZCsgpodKe3JosI 00dzlyy9y+VlXqYPUMQVqzhKnK8EfiwCEVAkSkqek65cDZH+HaMFbjOXAEhs5bLl1vE2oy VeYakuUfTdcFawp/GyB4JnmnBAP+6UqkYSvqA0m3HqH0tIwVbPdLDWYt8uHXieHTfjmXFq YOvMSJzGDydPtzquI3N1ahp+dmmzx6icVz3Dj1fZKpsY79yr49m40iZRM67sMA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078385; 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=N9GXN+I+HxjtZy8DzjkmjTZt67y3X5bRcXOLv7ZM9iU=; b=JhWCumRjFt5iuaKHPL3bnnW/KSR4OfOZNrBNtPDJh4rgWE+scOTsWbgmdrolhsQ5CYmYmX ZBNaNga05SawnACA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 17/40] x86/cacheinfo: Constify _cpuid4_info_regs instances Date: Tue, 4 Mar 2025 09:51:28 +0100 Message-ID: <20250304085152.51092-18-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" _cpuid4_info_regs instances are passed through a large number of functions at cacheinfo.c. For clarity, constify the instance parameters where _cpuid4_info_regs is only read from. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 5deffc834291..15ae12c92a83 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -841,7 +841,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) } =20 static int __cache_amd_cpumap_setup(unsigned int cpu, int index, - struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *base) { struct cpu_cacheinfo *this_cpu_ci; struct cacheinfo *ci; @@ -898,7 +898,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, } =20 static void __cache_cpumap_setup(unsigned int cpu, int index, - struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *base) { struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci, *sibling_ci; @@ -933,7 +933,8 @@ static void __cache_cpumap_setup(unsigned int cpu, int = index, } } =20 -static void ci_info_init(struct cacheinfo *ci, struct _cpuid4_info_regs *b= ase) +static void ci_info_init(struct cacheinfo *ci, + const struct _cpuid4_info_regs *base) { ci->id =3D base->id; ci->attributes =3D CACHE_ID; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 57EA11FF7C9 for ; Tue, 4 Mar 2025 08:53: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=1741078390; cv=none; b=qQ5mzzhx0jcwHnWrbRZrZQ0pbT7F7SPQ7x8uYPH+dA5/hWKL7btENh1PZce0r/pN9hpMt5Lr6ZMm395nJPYmd96J2YXo31Ve1+mMzMoPH9kQcJ6oAbxbpNeUtY0jjHQRABib3f5pMRddtI5Pq1LxYBLKlFXNdqaErTgPKvIYP8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078390; c=relaxed/simple; bh=Kim3Ql4VpH7O2dg8cgk7RCn41yCK6GPz5lqei6i/q90=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LqEVKSaVpy4DSLnPw0rRtaxFRRv4FhhT7gfkmLK2SayzhqqrDR2hYwdUBDmL8ff3oE5t/bUL8DsL9Jw6CO+XpgNNQav/RJtectmziU/e9btUrwg8JzWtjaRX+vmPcPdyoz4hN4PBNs1POUkp+/d+hLHh3/AQa4OvJRWRu3/heT0= 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=vubWpRqZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fUFMznx/; 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="vubWpRqZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fUFMznx/" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078388; 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=8Y2lm76UT6sjXHq4RDQHsnw2W5bv5hekdL5WgofSYTg=; b=vubWpRqZA8PiHtWqi+ENhgZxW5Xw3+ZIrvn4yXx4lK8F41h+JdeLlfg0xyLDoEFENNHuEx XiKqJDwJZGjKEaJmXmV+VNtEGFiyQkKpolhe21jeWcNSrcb32+by8qenIcJvaFNe3GY/WN 7kBI2vVWa39BSS3dUUfzq98itGhPhXZ+JL5FY3uR8CLEW4VyXejZ8D1WrQkFev4VMHBw+o i8LErh9yOADsHkS4g8jCrjcfTtY3QqODqjkwLU+DpgzoUzHywSUaGGaiJncR5f2r3cP0rG 1/PJ3f2b88GzlMi50A8SzHtFtjM/gttT4yrtc/8BlQXjanI5CMyZZWp5jwlx/w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078388; 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=8Y2lm76UT6sjXHq4RDQHsnw2W5bv5hekdL5WgofSYTg=; b=fUFMznx/soCargjOSQVd9namUY7UgVL2duPUhhnwM738ezNMzkQutIJNvUTWYx4XH81oMX M7cmTaepMAsP/aAg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 18/40] x86/cacheinfo: Align ci_info_init() assignment expressions Date: Tue, 4 Mar 2025 09:51:29 +0100 Message-ID: <20250304085152.51092-19-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 ci_info_init() function initializes 10 members of a struct cacheinfo instance using passed data from cpuid leaf 0x4. Such assignment expressions are difficult to read in their current form. Align them for clarity. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 15ae12c92a83..f825d68e8de6 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -936,19 +936,16 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, static void ci_info_init(struct cacheinfo *ci, const struct _cpuid4_info_regs *base) { - ci->id =3D base->id; - ci->attributes =3D CACHE_ID; - ci->level =3D base->eax.split.level; - ci->type =3D cache_type_map[base->eax.split.type]; - ci->coherency_line_size =3D - base->ebx.split.coherency_line_size + 1; - ci->ways_of_associativity =3D - base->ebx.split.ways_of_associativity + 1; - ci->size =3D base->size; - ci->number_of_sets =3D base->ecx.split.number_of_sets + 1; - ci->physical_line_partition =3D - base->ebx.split.physical_line_partition + 1; - ci->priv =3D base->nb; + ci->id =3D base->id; + ci->attributes =3D CACHE_ID; + ci->level =3D base->eax.split.level; + ci->type =3D cache_type_map[base->eax.split.type]; + ci->coherency_line_size =3D base->ebx.split.coherency_line_size + 1; + ci->ways_of_associativity =3D base->ebx.split.ways_of_associativity + 1; + ci->size =3D base->size; + ci->number_of_sets =3D base->ecx.split.number_of_sets + 1; + ci->physical_line_partition =3D base->ebx.split.physical_line_partition += 1; + ci->priv =3D base->nb; } =20 int init_cache_level(unsigned int cpu) --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 4414C1FFC54 for ; Tue, 4 Mar 2025 08:53: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=1741078394; cv=none; b=gCwitCMdcygyD9ihlzMwv54Y0hCU5p/p4vcAT8gl3xDgJ2lRvNdsMEZnEwpHue1roVVeDwrywGhnDb8DtSwEDtYeNBbsyTzTUkOtVW9z71uIWWBJixJVs+U+tFyX+ppxKRS2k7h9UBrzyND1o/7sBhHhntPG8/EBF6bZhY98kMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078394; c=relaxed/simple; bh=4OMUhk8gV/GVTTRsBV4hI78HAG/JzdeLKoG8yY12nJo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OErq0kaxGAzo4ftof8kb1jNZxaG5ukltk7LSt5xn6ztTyBZtal+RIBqfR2C61h7jchnOwKCbADGB8CYGqUjBrWTIJAyCEEEcFQ1UDWCGtngxlzYF1FtnZ6e9p4knlY3yUwMrv+iLGvx62fjWoq6cumkpjNo9SjW6KIuGvF0co58= 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=iBGBm9Q1; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=lGKAkupY; 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="iBGBm9Q1"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="lGKAkupY" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078391; 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=znaERUgOHhEL9pgrdSNyK5mzYUTwqjRpM0omk77NMPY=; b=iBGBm9Q1FBLAp6YxE6NqAY8lE/xt8xiWFt2sUyCRaPhNNc4hYjru0v0VagWQjCaEKQgUJv LMfguOVR3SYDMLi5yzRqZaz035fd1Vh0wjWUQ8vU8JvTR3krEgc11tjpmUCVXQiroi8qyG SNMNE/cjkrYH5iSgJV9RWeKSUvPzyXIa2iqeL6EIxw+ODTurmRu/ZsgKPuTRW5u7xA6Dll DQqSJes55xUJdRNbuOqJYHYcRuhiUtSE+FnIm+mlfhSzpppl3S5dvs3S5e+C4MSKubZkD1 4IuKNa/lrPngTDMXFVBYyPwYVN4eJQUbCBNK7I9ywrj5OrlZJM4e94XQXFglCQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078391; 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=znaERUgOHhEL9pgrdSNyK5mzYUTwqjRpM0omk77NMPY=; b=lGKAkupYmvZKdrL4G5A5bOsgd7ed4k31LPDfOMbEecn+pX0Xr4y29zkEMGgCDUO8HVGuub Mbxvj3QYDoS/+ZAg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 19/40] x86/cacheinfo: Standardize _cpuid4_info_regs instance naming Date: Tue, 4 Mar 2025 09:51:30 +0100 Message-ID: <20250304085152.51092-20-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 cacheinfo code frequently uses the output registers from cpuid leaf 0x4. Such registers are cached at struct _cpuid4_info_regs, augmented with related information, and are then passed across functions. The naming of these _cpuid4_info_regs instances is confusing at best. Some instances are called "this_leaf", which is vague as "this" lacks context and "leaf" is overly generic given that other cpuid leaves are also processed within cacheinfo. Other _cpuid4_info_regs instances are just called "base", adding further ambiguity. Standardize on id4 for all instances. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 97 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index f825d68e8de6..74a2949ff872 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -573,7 +573,7 @@ cache_get_priv_group(struct cacheinfo *ci) return &cache_private_group; } =20 -static void amd_init_l3_cache(struct _cpuid4_info_regs *this_leaf, int ind= ex) +static void amd_init_l3_cache(struct _cpuid4_info_regs *id4, int index) { int node; =20 @@ -582,16 +582,16 @@ static void amd_init_l3_cache(struct _cpuid4_info_reg= s *this_leaf, int index) return; =20 node =3D topology_amd_node_id(smp_processor_id()); - this_leaf->nb =3D node_to_amd_nb(node); - if (this_leaf->nb && !this_leaf->nb->l3_cache.indices) - amd_calc_l3_indices(this_leaf->nb); + id4->nb =3D node_to_amd_nb(node); + if (id4->nb && !id4->nb->l3_cache.indices) + amd_calc_l3_indices(id4->nb); } #else #define amd_init_l3_cache(x, y) #endif /* CONFIG_AMD_NB && CONFIG_SYSFS */ =20 static int -cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *this_leaf) +cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *id4) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; @@ -604,11 +604,11 @@ cpuid4_cache_lookup_regs(int index, struct _cpuid4_in= fo_regs *this_leaf) &ebx.full, &ecx.full, &edx); else amd_cpuid4(index, &eax, &ebx, &ecx); - amd_init_l3_cache(this_leaf, index); + amd_init_l3_cache(id4, index); } else if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) { cpuid_count(0x8000001d, index, &eax.full, &ebx.full, &ecx.full, &edx); - amd_init_l3_cache(this_leaf, index); + amd_init_l3_cache(id4, index); } else { cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); } @@ -616,13 +616,14 @@ cpuid4_cache_lookup_regs(int index, struct _cpuid4_in= fo_regs *this_leaf) if (eax.split.type =3D=3D CTYPE_NULL) return -EIO; /* better error ? */ =20 - this_leaf->eax =3D eax; - this_leaf->ebx =3D ebx; - this_leaf->ecx =3D ecx; - this_leaf->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->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); + return 0; } =20 @@ -754,29 +755,29 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) * parameters cpuid leaf to find the cache details */ for (i =3D 0; i < ci->num_leaves; i++) { - struct _cpuid4_info_regs this_leaf =3D {}; + struct _cpuid4_info_regs id4 =3D {}; int retval; =20 - retval =3D cpuid4_cache_lookup_regs(i, &this_leaf); + retval =3D cpuid4_cache_lookup_regs(i, &id4); if (retval < 0) continue; =20 - switch (this_leaf.eax.split.level) { + switch (id4.eax.split.level) { case 1: - if (this_leaf.eax.split.type =3D=3D CTYPE_DATA) - new_l1d =3D this_leaf.size/1024; - else if (this_leaf.eax.split.type =3D=3D CTYPE_INST) - new_l1i =3D this_leaf.size/1024; + if (id4.eax.split.type =3D=3D CTYPE_DATA) + new_l1d =3D id4.size/1024; + else if (id4.eax.split.type =3D=3D CTYPE_INST) + new_l1i =3D id4.size/1024; break; case 2: - new_l2 =3D this_leaf.size/1024; - num_threads_sharing =3D 1 + this_leaf.eax.split.num_threads_sharing; + new_l2 =3D id4.size/1024; + num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); l2_id =3D c->topo.apicid & ~((1 << index_msb) - 1); break; case 3: - new_l3 =3D this_leaf.size/1024; - num_threads_sharing =3D 1 + this_leaf.eax.split.num_threads_sharing; + new_l3 =3D id4.size/1024; + num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); l3_id =3D c->topo.apicid & ~((1 << index_msb) - 1); break; @@ -841,7 +842,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) } =20 static int __cache_amd_cpumap_setup(unsigned int cpu, int index, - const struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *id4) { struct cpu_cacheinfo *this_cpu_ci; struct cacheinfo *ci; @@ -867,7 +868,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 base->eax.split.num_threads_sharing + 1; + nshared =3D id4->eax.split.num_threads_sharing + 1; apicid =3D cpu_data(cpu).topo.apicid; first =3D apicid - (apicid % nshared); last =3D first + nshared - 1; @@ -898,7 +899,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, } =20 static void __cache_cpumap_setup(unsigned int cpu, int index, - const struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *id4) { struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci, *sibling_ci; @@ -908,12 +909,12 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, =20 if (c->x86_vendor =3D=3D X86_VENDOR_AMD || c->x86_vendor =3D=3D X86_VENDOR_HYGON) { - if (__cache_amd_cpumap_setup(cpu, index, base)) + if (__cache_amd_cpumap_setup(cpu, index, id4)) return; } =20 ci =3D this_cpu_ci->info_list + index; - num_threads_sharing =3D 1 + base->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; =20 cpumask_set_cpu(cpu, &ci->shared_cpu_map); if (num_threads_sharing =3D=3D 1) @@ -934,18 +935,18 @@ static void __cache_cpumap_setup(unsigned int cpu, in= t index, } =20 static void ci_info_init(struct cacheinfo *ci, - const struct _cpuid4_info_regs *base) + const struct _cpuid4_info_regs *id4) { - ci->id =3D base->id; + ci->id =3D id4->id; ci->attributes =3D CACHE_ID; - ci->level =3D base->eax.split.level; - ci->type =3D cache_type_map[base->eax.split.type]; - ci->coherency_line_size =3D base->ebx.split.coherency_line_size + 1; - ci->ways_of_associativity =3D base->ebx.split.ways_of_associativity + 1; - ci->size =3D base->size; - ci->number_of_sets =3D base->ecx.split.number_of_sets + 1; - ci->physical_line_partition =3D base->ebx.split.physical_line_partition += 1; - ci->priv =3D base->nb; + 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->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->priv =3D id4->nb; } =20 int init_cache_level(unsigned int cpu) @@ -964,15 +965,15 @@ int init_cache_level(unsigned int cpu) * ECX as cache index. Then right shift apicid by the number's order to get * cache id for this cache node. */ -static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4_regs) +static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4) { struct cpuinfo_x86 *c =3D &cpu_data(cpu); unsigned long num_threads_sharing; int index_msb; =20 - num_threads_sharing =3D 1 + id4_regs->eax.split.num_threads_sharing; + num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); - id4_regs->id =3D c->topo.apicid >> index_msb; + id4->id =3D c->topo.apicid >> index_msb; } =20 int populate_cache_leaves(unsigned int cpu) @@ -980,15 +981,15 @@ int populate_cache_leaves(unsigned int cpu) unsigned int idx, ret; struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci =3D this_cpu_ci->info_list; - struct _cpuid4_info_regs id4_regs =3D {}; + struct _cpuid4_info_regs id4 =3D {}; =20 for (idx =3D 0; idx < this_cpu_ci->num_leaves; idx++) { - ret =3D cpuid4_cache_lookup_regs(idx, &id4_regs); + ret =3D cpuid4_cache_lookup_regs(idx, &id4); if (ret) return ret; - get_cache_id(cpu, &id4_regs); - ci_info_init(ci++, &id4_regs); - __cache_cpumap_setup(cpu, idx, &id4_regs); + get_cache_id(cpu, &id4); + ci_info_init(ci++, &id4); + __cache_cpumap_setup(cpu, idx, &id4); } this_cpu_ci->cpu_map_populated =3D true; =20 --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 3A9A71FFC62 for ; Tue, 4 Mar 2025 08:53: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=1741078397; cv=none; b=HLsXRbuo/bSHyxCyCIHApOmT4tV5RZrh9Qrg2W2zA6UcGxrgV6+ppd2xo7DSqb7Raxv7GD4GjQW0ww+5Z46V0pzEpQ3/r6FG6HHZksuuB1NzAWzAYFUMT3RkxsBCQ4ppucBbu1C29jRax6pDcS5/ZGKgMlTLdYNqDmrYt1NFexM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078397; c=relaxed/simple; bh=4mVs32IP/JJwhwIrsKAxI9VHzWvehSi+ZVAbjv/FwJ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fwDEMHBakTt6UOAwKHdp0CohkEgy9f4A+WnrHMGo4oayFfx+5+2ls1VNU70FiVweBVmN1QJlPhZwK0nRQN6LjTb1ayU5nVS7O6kxCL/WroqaQ+A2bztA6tS0PHpNm3Qzo6A4Yqh0+e5jzTtv04qZPTRDXVK26viz0Py79aIE/Zs= 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=LBlbMNX6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=/qZbgqsG; 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="LBlbMNX6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="/qZbgqsG" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078393; 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=1f/wmwFxuOm6NrbQ051GrZqcSL5nUPMeX+arERDp4+A=; b=LBlbMNX69QeNxID6lY+6SSLV0ftXgGZm/0OwqJbLdAahr9dXp2KzVp95uFrSM18+uQ7ROm vghxaHCZBUBrDFj45jfFfLF5GGcmaiDUZvZYfHKWGha96F4+N7zU7ZZwhlFq/EVbZdtg5r 8M9DN/pho85RiTAGTeQAjbTEPkTSuxHFhai9FSjUBYk7LGrPqNCBEoMTVkRfvPJ7avEbi6 B+n4jhxJqcua59CROeGoZzUU/u+zMAVpstOnl8L7PgUbtwClhGOzqSRdyMsCKUNNnJJtkO NdtqSL7cGAknQaXcGZ3PVx3A2RQyY0PaX3rOUin7q45bLZeombHTR2YvAVNsHg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078393; 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=1f/wmwFxuOm6NrbQ051GrZqcSL5nUPMeX+arERDp4+A=; b=/qZbgqsGs98NaRjGy5tp9QX7DUnBpESXsJf7rCQ/yu4VdyOFuhmWT00M+SlWy5s88/1Z8Z 3Ii29lcB7cwgTjCA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 20/40] x86: treewide: Introduce x86_vendor_amd_or_hygon() Date: Tue, 4 Mar 2025 09:51:31 +0100 Message-ID: <20250304085152.51092-21-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 pattern to check if an x86 vendor is AMD or HYGON (or not both), is pretty common across the x86 tree. Introduce x86_vendor_amd_or_hygon() macro at asm/processor.h, and use it across the x86 tree. Signed-off-by: Ahmed S. Darwish --- arch/x86/events/amd/uncore.c | 3 +-- arch/x86/events/rapl.c | 3 +-- arch/x86/include/asm/processor.h | 5 +++++ arch/x86/kernel/amd_nb.c | 9 +++------ arch/x86/kernel/cpu/bugs.c | 12 ++++-------- arch/x86/kernel/cpu/cacheinfo.c | 7 ++----- arch/x86/kernel/cpu/mce/core.c | 4 ++-- arch/x86/kernel/cpu/mce/severity.c | 3 +-- arch/x86/kernel/cpu/mtrr/cleanup.c | 3 +-- arch/x86/kernel/smpboot.c | 3 +-- arch/x86/kvm/svm/svm.c | 3 +-- arch/x86/pci/amd_bus.c | 3 +-- arch/x86/xen/enlighten.c | 15 +++++---------- arch/x86/xen/pmu.c | 3 +-- 14 files changed, 29 insertions(+), 47 deletions(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 49c26ce2b115..5141c0375990 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -1023,8 +1023,7 @@ static int __init amd_uncore_init(void) int ret =3D -ENODEV; int i; =20 - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return -ENODEV; =20 if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index 6941f4811bec..999ea90059ae 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -123,8 +123,7 @@ static struct perf_pmu_events_attr event_attr_##v =3D {= \ * them as die-scope. */ #define rapl_pkg_pmu_is_pkg_scope() \ - (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || \ - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) + x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor) =20 struct rapl_pmu { raw_spinlock_t lock; diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index d5d9a071cddc..0f586c638e87 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -203,6 +203,11 @@ struct cpuinfo_x86 { =20 #define X86_VENDOR_UNKNOWN 0xff =20 +static inline bool x86_vendor_amd_or_hygon(u8 vendor) +{ + return (vendor =3D=3D X86_VENDOR_AMD || vendor =3D=3D X86_VENDOR_HYGON); +} + /* * capabilities of CPUs */ diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index 11fac09e3a8c..bac8d3b6f12b 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -127,8 +127,7 @@ bool __init early_is_amd_nb(u32 device) const struct pci_device_id *id; u32 vendor =3D device & 0xffff; =20 - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return false; =20 if (cpu_feature_enabled(X86_FEATURE_ZEN)) @@ -147,8 +146,7 @@ struct resource *amd_get_mmconfig_range(struct resource= *res) u64 base, msr; unsigned int segn_busn_bits; =20 - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return NULL; =20 /* assume all cpus from fam10h have mmconfig */ @@ -320,8 +318,7 @@ static __init void fix_erratum_688(void) =20 static __init int init_amd_nbs(void) { - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return 0; =20 amd_cache_northbridges(); diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index a5d0998d7604..b0dc4e96f4bc 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1081,8 +1081,7 @@ static void __init retbleed_select_mitigation(void) =20 do_cmd_auto: case RETBLEED_CMD_AUTO: - if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) { + if (x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) { if (IS_ENABLED(CONFIG_MITIGATION_UNRET_ENTRY)) retbleed_mitigation =3D RETBLEED_MITIGATION_UNRET; else if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY) && @@ -1106,8 +1105,7 @@ static void __init retbleed_select_mitigation(void) =20 x86_return_thunk =3D retbleed_return_thunk; =20 - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) pr_err(RETBLEED_UNTRAIN_MSG); =20 mitigate_smt =3D true; @@ -1872,8 +1870,7 @@ static void __init spectre_v2_select_mitigation(void) */ if (boot_cpu_has_bug(X86_BUG_RETBLEED) && boot_cpu_has(X86_FEATURE_IBPB) && - (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON)) { + x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) { =20 if (retbleed_cmd !=3D RETBLEED_CMD_IBPB) { setup_force_cpu_cap(X86_FEATURE_USE_IBPB_FW); @@ -2903,8 +2900,7 @@ static ssize_t retbleed_show_state(char *buf) { if (retbleed_mitigation =3D=3D RETBLEED_MITIGATION_UNRET || retbleed_mitigation =3D=3D RETBLEED_MITIGATION_IBPB) { - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return sysfs_emit(buf, "Vulnerable: untrained return thunk / IBPB on no= n-AMD based uarch\n"); =20 return sysfs_emit(buf, "%s; SMT %s\n", retbleed_strings[retbleed_mitigat= ion], diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 74a2949ff872..0024d126c385 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -633,8 +633,7 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *c) union _cpuid4_leaf_eax cache_eax; int i =3D -1; =20 - if (c->x86_vendor =3D=3D X86_VENDOR_AMD || - c->x86_vendor =3D=3D X86_VENDOR_HYGON) + if (x86_vendor_amd_or_hygon(c->x86_vendor)) op =3D 0x8000001d; else op =3D 4; @@ -907,11 +906,9 @@ static void __cache_cpumap_setup(unsigned int cpu, int= index, int index_msb, i; struct cpuinfo_x86 *c =3D &cpu_data(cpu); =20 - if (c->x86_vendor =3D=3D X86_VENDOR_AMD || - c->x86_vendor =3D=3D X86_VENDOR_HYGON) { + if (x86_vendor_amd_or_hygon(c->x86_vendor)) if (__cache_amd_cpumap_setup(cpu, index, id4)) return; - } =20 ci =3D this_cpu_ci->info_list + index; num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 0dc00c9894c7..135d7b8f3e55 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -227,7 +227,7 @@ static void print_mce(struct mce_hw_err *err) =20 __print_mce(err); =20 - if (m->cpuvendor !=3D X86_VENDOR_AMD && m->cpuvendor !=3D X86_VENDOR_HYGO= N) + if (!x86_vendor_amd_or_hygon(m->cpuvendor)) pr_emerg_ratelimited(HW_ERR "Run the above through 'mcelog --ascii'\n"); } =20 @@ -2060,7 +2060,7 @@ static bool __mcheck_cpu_ancient_init(struct cpuinfo_= x86 *c) */ static void __mcheck_cpu_init_early(struct cpuinfo_x86 *c) { - if (c->x86_vendor =3D=3D X86_VENDOR_AMD || c->x86_vendor =3D=3D X86_VENDO= R_HYGON) { + if (x86_vendor_amd_or_hygon(c->x86_vendor)) { mce_flags.overflow_recov =3D !!cpu_has(c, X86_FEATURE_OVERFLOW_RECOV); mce_flags.succor =3D !!cpu_has(c, X86_FEATURE_SUCCOR); mce_flags.smca =3D !!cpu_has(c, X86_FEATURE_SMCA); diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/s= everity.c index dac4d64dfb2a..a3f2f1c236bc 100644 --- a/arch/x86/kernel/cpu/mce/severity.c +++ b/arch/x86/kernel/cpu/mce/severity.c @@ -413,8 +413,7 @@ static noinstr int mce_severity_intel(struct mce *m, st= ruct pt_regs *regs, char =20 int noinstr mce_severity(struct mce *m, struct pt_regs *regs, char **msg, = bool is_excp) { - if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) + if (x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return mce_severity_amd(m, regs, msg, is_excp); else return mce_severity_intel(m, regs, msg, is_excp); diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/= cleanup.c index 18cf79d6e2c5..236d7e3b4e55 100644 --- a/arch/x86/kernel/cpu/mtrr/cleanup.c +++ b/arch/x86/kernel/cpu/mtrr/cleanup.c @@ -820,8 +820,7 @@ int __init amd_special_default_mtrr(void) { u32 l, h; =20 - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return 0; if (boot_cpu_data.x86 < 0xf) return 0; diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index e199465dc9e1..5ba8424cf4e6 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1250,8 +1250,7 @@ static inline void mwait_play_dead(void) unsigned int highest_subcstate =3D 0; int i; =20 - if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) + if (x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return; if (!this_cpu_has(X86_FEATURE_MWAIT)) return; diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index a713c803a3a3..8c88f3c0c2cd 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -523,8 +523,7 @@ static bool __kvm_is_svm_supported(void) int cpu =3D smp_processor_id(); struct cpuinfo_x86 *c =3D &cpu_data(cpu); =20 - if (c->x86_vendor !=3D X86_VENDOR_AMD && - c->x86_vendor !=3D X86_VENDOR_HYGON) { + if (!x86_vendor_amd_or_hygon(c->x86_vendor)) { pr_err("CPU %d isn't AMD or Hygon\n", cpu); return false; } diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c index 631512f7ec85..43033d54080a 100644 --- a/arch/x86/pci/amd_bus.c +++ b/arch/x86/pci/amd_bus.c @@ -399,8 +399,7 @@ static int __init pci_io_ecs_init(void) =20 static int __init amd_postcore_init(void) { - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return 0; =20 early_root_info_init(); diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index 43dcd8c7badc..13df4917d7d8 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -82,11 +82,9 @@ void xen_hypercall_setfunc(void) if (static_call_query(xen_hypercall) !=3D xen_hypercall_hvm) return; =20 - if ((boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON)) - static_call_update(xen_hypercall, xen_hypercall_amd); - else - static_call_update(xen_hypercall, xen_hypercall_intel); + static_call_update(xen_hypercall, + x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor) ? + xen_hypercall_amd : xen_hypercall_intel); } =20 /* @@ -118,11 +116,8 @@ noinstr void *__xen_hypercall_setfunc(void) if (!boot_cpu_has(X86_FEATURE_CPUID)) xen_get_vendor(); =20 - if ((boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON)) - func =3D xen_hypercall_amd; - else - func =3D xen_hypercall_intel; + func =3D x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor) ? + xen_hypercall_amd : xen_hypercall_intel; =20 static_call_update_early(xen_hypercall, func); =20 diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c index f06987b0efc3..af5cb19b5990 100644 --- a/arch/x86/xen/pmu.c +++ b/arch/x86/xen/pmu.c @@ -130,8 +130,7 @@ static inline uint32_t get_fam15h_addr(u32 addr) =20 static inline bool is_amd_pmu_msr(unsigned int msr) { - if (boot_cpu_data.x86_vendor !=3D X86_VENDOR_AMD && - boot_cpu_data.x86_vendor !=3D X86_VENDOR_HYGON) + if (!x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) return false; =20 if ((msr >=3D MSR_F15H_PERF_CTL && --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 3BFD61FFC7D for ; Tue, 4 Mar 2025 08:53: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=1741078399; cv=none; b=nkmW+eZ+iUCVbrl5mBUsUFigcs9ZCL0l/HX65bszHqnhXXKyTbHDMZRzr4pP9tT25DFLltekMFz0SOc4dAoEiD6syylhKpdHGym8xw5mJbb2GzQfOJbEeFfU4CJ0WsltNxJlBEtjNJZyNSqLBvpMWzVD7O3lxLNmH1rZjr/HVVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078399; c=relaxed/simple; bh=DSPQqfoV/n6tHzAVZaK7QIZDoZqS2S2XEA1CHVRVB38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RGdPGlzQM5bKfbbXkmXAMmwuwsCrk5bazKj5ipMxe27wm4kwQk5Lr4h4KPQM4T3iwfC1qYLupaX7TfzirByh4IOfVbERkxA7gceuuarCr3s1eVLHFtcuqKrOHMWzOIr0Gfi+Wr9BZE7RPCyRiu+4CuJys/IdkvnmEq1YPFPsleY= 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/gdyDWF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=m1j4DIei; 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/gdyDWF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="m1j4DIei" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078396; 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=cCxUUPYdIi4eq4csvJ6zzf6QHEMekx2axM9W90pgfbE=; b=D/gdyDWFKuU+Jv6fljXzL40nf8l2AwStfhlDdKP8eTfyT8uRWnuLAT5qP5WSsSz9TECYl8 8dRgcWLjMU/+yziQvt4SPS/hCyRqlHG1GPz9JV3lNQZUH5aFqD0COJGj+Q2Lkzkawm3KHH P/dFtPfotHYmqWk7RTAHnaKDwyyGHXeh6M+0YUzYGJmoMbGOyxMYqf4oaju1/ccYu2O1lM 1xtkTGM2IkuzHKk2EqbbFnT9liNXsnIxR0m6B6JplNKEfh5VSSyXTzZU418AXSVUUUNziv 0OjU9g9uceLOcg1KBm1HMavNUMW1ncwmlunexawraq1FBXi2O5IAriliiLgB+Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078396; 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=cCxUUPYdIi4eq4csvJ6zzf6QHEMekx2axM9W90pgfbE=; b=m1j4DIeiTMWMqhsN/ZBsxcBadr4kYWKBZLPkEoGDh8Nkv7QeanEm9sAc7XUe9rcAMPN5R4 jjrtneQYLxD21CAA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 21/40] x86/cacheinfo: Consolidate AMD/Hygon leaf 0x8000001d calls Date: Tue, 4 Mar 2025 09:51:32 +0100 Message-ID: <20250304085152.51092-22-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" While gathering CPU cache info, cpuid leaf 0x8000001d is invoked in two separate if blocks: one for Hygon CPUs and one for AMDs with topology extensions. After each invocation, amd_init_l3_cache() is called. Merge the two if blocks into a single condition, thus removing the duplicated code. Future commits will expand these if blocks, so combining them now is both cleaner and more maintainable. Note, while at it, remove a useless "better error?" comment that was within the same function since the 2005 commit e2cac78935ff ("[PATCH] x86_64: When running cpuid4 need to run on the correct CPU"). Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 0024d126c385..6aeabbd94997 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -598,23 +598,24 @@ cpuid4_cache_lookup_regs(int index, struct _cpuid4_in= fo_regs *id4) union _cpuid4_leaf_ecx ecx; unsigned edx; =20 - if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_AMD) { - if (boot_cpu_has(X86_FEATURE_TOPOEXT)) + if (x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) { + if (boot_cpu_has(X86_FEATURE_TOPOEXT) || + boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) { + /* AMD with TOPOEXT, or HYGON */ cpuid_count(0x8000001d, index, &eax.full, &ebx.full, &ecx.full, &edx); - else + } else { + /* Legacy AMD fallback */ amd_cpuid4(index, &eax, &ebx, &ecx); - amd_init_l3_cache(id4, index); - } else if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) { - cpuid_count(0x8000001d, index, &eax.full, - &ebx.full, &ecx.full, &edx); + } amd_init_l3_cache(id4, index); } else { + /* Intel */ cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); } =20 if (eax.split.type =3D=3D CTYPE_NULL) - return -EIO; /* better error ? */ + return -EIO; =20 id4->eax =3D eax; id4->ebx =3D ebx; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 A874C200130 for ; Tue, 4 Mar 2025 08:53: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=1741078403; cv=none; b=Cb7B/+tMPArqcpWd4B8k8lXPb66Ug7EesaTWDgkZsAkPlDrDTTYPvN2vkh0giyfvtgzcO5Jaegy0i4ch+GfN1TLjwy8cgnRORdsOACUh+NgipIvah/yOB65HmLzu6bm+syHWKqy8h/nTR8k9vbLjV26AqXuLsRqXa4EFn59ogIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078403; c=relaxed/simple; bh=Ol/Et/TBYJWmcfag2qO/uanvP2pT7byOM/gEyvpusfw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kcc/UFoXZlxmAr3cUf4tcu3Mz0UN6OWNaSPdCSSGqvIIJ6UVckfgUqGTjc7uD2LiNMXr27on7pbKpmC1ElKZW9usQr/INkgUXQeQ56ZjMRf5hk2CJ99B54Bjdq3In6cqLkPW7EAuIXczNaMH6odZisIGzDEBYJJw6ZFjtYQlZHM= 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=sHZPYetF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UPo8pp1Q; 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="sHZPYetF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UPo8pp1Q" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078399; 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=H36zecaZUTad0CS+C/0cOZo8dyDDwXF4r/drrx9Rm0E=; b=sHZPYetFhk38K88PP50FRVZB2H9G8qt3lqtnV9PHjEMIIO7azdnXPz0eGTd9x29z8zRLDH 6Uc+zAwfixcfr4xBMbHmdtxOO0s69L32vOWiJWqiwmsm9TadkQkY3kSXnbPyEJbocPvuGe w+jElJJ8MJ5qwy+Tjm/dnvkFfuXgdKAIjjUAzLjyLZ7VUG44Phr/GMyoPLXFmSyOioRKdN jsgI50Qb2GKpvhhN/iADuRo0V2QNOvkYW69DnBON91QaDJuFENQquYz5KySDvkLZ1uwi1A qnMyK//GXWTvUMPHkEEmorN9iVtVXtreBnwMr+iz+911CwmEI2LAyYA2tBsVJg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078399; 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=H36zecaZUTad0CS+C/0cOZo8dyDDwXF4r/drrx9Rm0E=; b=UPo8pp1Qwk3xOMlfhkIqW+s7oPGNGge9FdDm9uPeNGGoe3ieYpcLAr6jVyArVs4jx2R6BY 0Fe3hMs5QpRdqmDQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 22/40] x86/cacheinfo: Separate amd_northbridge from _cpuid4_info_regs Date: Tue, 4 Mar 2025 09:51:33 +0100 Message-ID: <20250304085152.51092-23-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 _cpuid4_info_regs structure is meant to hold the cpuid leaf 0x4 output registers (EAX, EBX, and ECX), as well as derived information such as the cache node ID and size. It also contains a reference to amd_northbridge, which is there only to be "parked" until ci_info_init() can store it in the priv pointer of the linux/cacheinfo.h API. That priv pointer is then used by AMD-specific L3 cache_disable_0/1 sysfs attributes. Decouple amd_northbridge from _cpuid4_info_regs and pass it explicitly through the functions at x86/cacheinfo. Doing so clarifies when amd_northbridge is actually needed (AMD-only code) and when it is not (Intel-specific code). It also prepares for moving the AMD-specific L3 cache_disable_0/1 sysfs code into its own file in next commit. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 45 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 6aeabbd94997..2a56c7cc3c2d 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -168,7 +168,6 @@ struct _cpuid4_info_regs { union _cpuid4_leaf_ecx ecx; unsigned int id; unsigned long size; - struct amd_northbridge *nb; }; =20 /* AMD doesn't have CPUID4. Emulate it here to report the same @@ -573,25 +572,36 @@ cache_get_priv_group(struct cacheinfo *ci) return &cache_private_group; } =20 -static void amd_init_l3_cache(struct _cpuid4_info_regs *id4, int index) +static struct amd_northbridge *amd_init_l3_cache(int index) { + struct amd_northbridge *nb; int node; =20 /* only for L3, and not in virtualized environments */ if (index < 3) - return; + return NULL; =20 node =3D topology_amd_node_id(smp_processor_id()); - id4->nb =3D node_to_amd_nb(node); - if (id4->nb && !id4->nb->l3_cache.indices) - amd_calc_l3_indices(id4->nb); + nb =3D node_to_amd_nb(node); + if (nb && !nb->l3_cache.indices) + amd_calc_l3_indices(nb); + + return nb; } #else -#define amd_init_l3_cache(x, y) +static struct amd_northbridge *amd_init_l3_cache(int index) +{ + return NULL; +} #endif /* CONFIG_AMD_NB && CONFIG_SYSFS */ =20 -static int -cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *id4) +/* + * Fill passed _cpuid4_info_regs structure. + * Intel-only code paths should pass NULL for the amd_northbridge + * return pointer. + */ +static int cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *i= d4, + struct amd_northbridge **nb) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; @@ -608,7 +618,9 @@ cpuid4_cache_lookup_regs(int index, struct _cpuid4_info= _regs *id4) /* Legacy AMD fallback */ amd_cpuid4(index, &eax, &ebx, &ecx); } - amd_init_l3_cache(id4, index); + + if (nb) + *nb =3D amd_init_l3_cache(index); } else { /* Intel */ cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); @@ -758,7 +770,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) struct _cpuid4_info_regs id4 =3D {}; int retval; =20 - retval =3D cpuid4_cache_lookup_regs(i, &id4); + retval =3D cpuid4_cache_lookup_regs(i, &id4, NULL); if (retval < 0) continue; =20 @@ -932,8 +944,8 @@ static void __cache_cpumap_setup(unsigned int cpu, int = index, } } =20 -static void ci_info_init(struct cacheinfo *ci, - const struct _cpuid4_info_regs *id4) +static void ci_info_init(struct cacheinfo *ci, const struct _cpuid4_info_r= egs *id4, + struct amd_northbridge *nb) { ci->id =3D id4->id; ci->attributes =3D CACHE_ID; @@ -944,7 +956,7 @@ static void ci_info_init(struct cacheinfo *ci, 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->priv =3D id4->nb; + ci->priv =3D nb; } =20 int init_cache_level(unsigned int cpu) @@ -980,13 +992,14 @@ 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; struct _cpuid4_info_regs id4 =3D {}; + struct amd_northbridge *nb; =20 for (idx =3D 0; idx < this_cpu_ci->num_leaves; idx++) { - ret =3D cpuid4_cache_lookup_regs(idx, &id4); + ret =3D cpuid4_cache_lookup_regs(idx, &id4, &nb); if (ret) return ret; get_cache_id(cpu, &id4); - ci_info_init(ci++, &id4); + ci_info_init(ci++, &id4, nb); __cache_cpumap_setup(cpu, idx, &id4); } this_cpu_ci->cpu_map_populated =3D true; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 C6AD51FFC62 for ; Tue, 4 Mar 2025 08:53: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=1741078407; cv=none; b=QcGNV/3JEIldoWy1Y89Ptm2kSf+xyZj9/3SSoLn1SVaQV0h2DaWak1W4FMY3GoDO5BeQVC/xOePwbdN034EuprSoH65zJvI8P4NSeGIc6eZlppRZKjsiejXrx5AWypQVaeOFWjHAAyB9GYC4lJBHsdknA66In2uAJzTRnF18P4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078407; c=relaxed/simple; bh=S9n5Uxbkb9tkKocmV0n5rofb9brQ1W+BlY5KzhiqdWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TrTlhFULbgYDFJIBZUAfCD29bm+sCd8gT82JSzOtrW8zfwBWWBLl1J2caoVyaizC+P2f1S/FragbNFVObMo2pzqNMY1iNsBim9mb9sTqvItZJBSA5SIpX9pTehCeamxfOeW8Js2bTCnUGr21TuDQEr94c1c5vRyg4KtrbD0POiQ= 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=SvpJnidM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gk/joHi9; 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="SvpJnidM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gk/joHi9" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078403; 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=IGPiw/y1VXFkz0VmEPAcv/TPFcSMGZnJR96c5iQBRwo=; b=SvpJnidMv8GRt8q7C+lCNjc8NdmTVEy9GfL5rpkEggDuU6h59Pd4FZiQpknVoeDSGAyezL IFTM7zVMkGYptd2KvCefuHiduTO2ZI3K3UZprkYdE/VlUxf2eeXzMKnuzy2JOi7ta2WF4P JCZSLz+8xrgDCBKgncSprcgC4JoG0FyXA//KMLlXPurDepbyhfXJ3nYFd47usdWG35sJrJ B0Z2KoAOxroidytq0EpAfJHAeUYepewRJflxNmJt/NhZ2LvrPqoIqUMBRTnWUEZltKUEZB y+aEBPbDuVUuufqgDp5BKg2TLa7c0UIk/q+t15enyJhq5RdhqdqdgcVDIH4Vcw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078403; 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=IGPiw/y1VXFkz0VmEPAcv/TPFcSMGZnJR96c5iQBRwo=; b=gk/joHi9AAvj9c6Wzf/uFWrQGKI62bqlji7wkSVELph9+ZROq2GJJJhsUKUnEfSDKS45rr NCpIymjeE4EnydDg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 23/40] x86/cacheinfo: Move AMD cache_disable_0/1 handling to separate file Date: Tue, 4 Mar 2025 09:51:34 +0100 Message-ID: <20250304085152.51092-24-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Parent commit decoupled amd_northbridge out of _cpuid4_info_regs, where it was merely "parked" there until ci_info_init() can store it in the priv pointer of the linux/cacheinfo.h API. Given that decoupling, move the AMD-specific L3 cache_disable_0/1 sysfs code from the generic (and already extremely convoluted) x86/cacheinfo code into its own file. Compile the file only if CONFIG_AMD_NB and CONFIG_SYSFS are both enabled, which mirrors the existing logic. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/Makefile | 3 + arch/x86/kernel/cpu/amd_cache_disable.c | 301 ++++++++++++++++++++++++ arch/x86/kernel/cpu/cacheinfo.c | 298 ----------------------- arch/x86/kernel/cpu/cpu.h | 9 + 4 files changed, 313 insertions(+), 298 deletions(-) create mode 100644 arch/x86/kernel/cpu/amd_cache_disable.c diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 4efdf5c2efc8..3a39396d422d 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -38,6 +38,9 @@ obj-y +=3D intel.o tsx.o obj-$(CONFIG_PM) +=3D intel_epb.o endif obj-$(CONFIG_CPU_SUP_AMD) +=3D amd.o +ifeq ($(CONFIG_AMD_NB)$(CONFIG_SYSFS),yy) +obj-y +=3D amd_cache_disable.o +endif obj-$(CONFIG_CPU_SUP_HYGON) +=3D hygon.o obj-$(CONFIG_CPU_SUP_CYRIX_32) +=3D cyrix.o obj-$(CONFIG_CPU_SUP_CENTAUR) +=3D centaur.o diff --git a/arch/x86/kernel/cpu/amd_cache_disable.c b/arch/x86/kernel/cpu/= amd_cache_disable.c new file mode 100644 index 000000000000..6d53aee0d869 --- /dev/null +++ b/arch/x86/kernel/cpu/amd_cache_disable.c @@ -0,0 +1,301 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD L3 cache_disable_{0,1} sysfs handling + * Documentation/ABI/testing/sysfs-devices-system-cpu + */ + +#include +#include +#include +#include + +#include + +#include "cpu.h" + +/* + * L3 cache descriptors + */ +static void amd_calc_l3_indices(struct amd_northbridge *nb) +{ + struct amd_l3_cache *l3 =3D &nb->l3_cache; + unsigned int sc0, sc1, sc2, sc3; + u32 val =3D 0; + + pci_read_config_dword(nb->misc, 0x1C4, &val); + + /* calculate subcache sizes */ + l3->subcaches[0] =3D sc0 =3D !(val & BIT(0)); + l3->subcaches[1] =3D sc1 =3D !(val & BIT(4)); + + if (boot_cpu_data.x86 =3D=3D 0x15) { + l3->subcaches[0] =3D sc0 +=3D !(val & BIT(1)); + l3->subcaches[1] =3D sc1 +=3D !(val & BIT(5)); + } + + l3->subcaches[2] =3D sc2 =3D !(val & BIT(8)) + !(val & BIT(9)); + l3->subcaches[3] =3D sc3 =3D !(val & BIT(12)) + !(val & BIT(13)); + + l3->indices =3D (max(max3(sc0, sc1, sc2), sc3) << 10) - 1; +} + +/* + * check whether a slot used for disabling an L3 index is occupied. + * @l3: L3 cache descriptor + * @slot: slot number (0..1) + * + * @returns: the disabled index if used or negative value if slot free. + */ +static int amd_get_l3_disable_slot(struct amd_northbridge *nb, unsigned in= t slot) +{ + unsigned int reg =3D 0; + + pci_read_config_dword(nb->misc, 0x1BC + slot * 4, ®); + + /* check whether this slot is activated already */ + if (reg & (3UL << 30)) + return reg & 0xfff; + + return -1; +} + +static ssize_t show_cache_disable(struct cacheinfo *ci, char *buf, unsigne= d int slot) +{ + int index; + struct amd_northbridge *nb =3D ci->priv; + + index =3D amd_get_l3_disable_slot(nb, slot); + if (index >=3D 0) + return sprintf(buf, "%d\n", index); + + return sprintf(buf, "FREE\n"); +} + +#define SHOW_CACHE_DISABLE(slot) \ +static ssize_t \ +cache_disable_##slot##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct cacheinfo *ci =3D dev_get_drvdata(dev); \ + return show_cache_disable(ci, buf, slot); \ +} + +SHOW_CACHE_DISABLE(0) +SHOW_CACHE_DISABLE(1) + +static void amd_l3_disable_index(struct amd_northbridge *nb, int cpu, + unsigned int slot, unsigned long idx) +{ + int i; + + idx |=3D BIT(30); + + /* + * disable index in all 4 subcaches + */ + for (i =3D 0; i < 4; i++) { + u32 reg =3D idx | (i << 20); + + if (!nb->l3_cache.subcaches[i]) + continue; + + pci_write_config_dword(nb->misc, 0x1BC + slot * 4, reg); + + /* + * We need to WBINVD on a core on the node containing the L3 + * cache which indices we disable therefore a simple wbinvd() + * is not sufficient. + */ + wbinvd_on_cpu(cpu); + + reg |=3D BIT(31); + pci_write_config_dword(nb->misc, 0x1BC + slot * 4, reg); + } +} + +/* + * disable a L3 cache index by using a disable-slot + * + * @l3: L3 cache descriptor + * @cpu: A CPU on the node containing the L3 cache + * @slot: slot number (0..1) + * @index: index to disable + * + * @return: 0 on success, error status on failure + */ +static int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, + unsigned int slot, unsigned long index) +{ + int ret =3D 0; + + /* check if @slot is already used or the index is already disabled */ + ret =3D amd_get_l3_disable_slot(nb, slot); + if (ret >=3D 0) + return -EEXIST; + + if (index > nb->l3_cache.indices) + return -EINVAL; + + /* check whether the other slot has disabled the same index already */ + if (index =3D=3D amd_get_l3_disable_slot(nb, !slot)) + return -EEXIST; + + amd_l3_disable_index(nb, cpu, slot, index); + + return 0; +} + +static ssize_t store_cache_disable(struct cacheinfo *ci, const char *buf, + size_t count, unsigned int slot) +{ + struct amd_northbridge *nb =3D ci->priv; + unsigned long val =3D 0; + int cpu, err =3D 0; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + cpu =3D cpumask_first(&ci->shared_cpu_map); + + if (kstrtoul(buf, 10, &val) < 0) + return -EINVAL; + + err =3D amd_set_l3_disable_slot(nb, cpu, slot, val); + if (err) { + if (err =3D=3D -EEXIST) + pr_warn("L3 slot %d in use/index already disabled!\n", + slot); + return err; + } + return count; +} + +#define STORE_CACHE_DISABLE(slot) \ +static ssize_t \ +cache_disable_##slot##_store(struct device *dev, \ + struct device_attribute *attr, \ + const char *buf, size_t count) \ +{ \ + struct cacheinfo *ci =3D dev_get_drvdata(dev); \ + return store_cache_disable(ci, buf, count, slot); \ +} + +STORE_CACHE_DISABLE(0) +STORE_CACHE_DISABLE(1) + +static ssize_t subcaches_show(struct device *dev, struct device_attribute = *attr, + char *buf) +{ + struct cacheinfo *ci =3D dev_get_drvdata(dev); + int cpu =3D cpumask_first(&ci->shared_cpu_map); + + return sprintf(buf, "%x\n", amd_get_subcaches(cpu)); +} + +static ssize_t subcaches_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct cacheinfo *ci =3D dev_get_drvdata(dev); + int cpu =3D cpumask_first(&ci->shared_cpu_map); + unsigned long val; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (kstrtoul(buf, 16, &val) < 0) + return -EINVAL; + + if (amd_set_subcaches(cpu, val)) + return -EINVAL; + + return count; +} + +static DEVICE_ATTR_RW(cache_disable_0); +static DEVICE_ATTR_RW(cache_disable_1); +static DEVICE_ATTR_RW(subcaches); + +static umode_t cache_private_attrs_is_visible(struct kobject *kobj, + struct attribute *attr, int unused) +{ + struct device *dev =3D kobj_to_dev(kobj); + struct cacheinfo *ci =3D dev_get_drvdata(dev); + umode_t mode =3D attr->mode; + + if (!ci->priv) + return 0; + + if ((attr =3D=3D &dev_attr_subcaches.attr) && + amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) + return mode; + + if ((attr =3D=3D &dev_attr_cache_disable_0.attr || + attr =3D=3D &dev_attr_cache_disable_1.attr) && + amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) + return mode; + + return 0; +} + +static struct attribute_group cache_private_group =3D { + .is_visible =3D cache_private_attrs_is_visible, +}; + +static void init_amd_l3_attrs(void) +{ + static struct attribute **amd_l3_attrs; + int n =3D 1; + + if (amd_l3_attrs) /* already initialized */ + return; + + if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) + n +=3D 2; + if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) + n +=3D 1; + + amd_l3_attrs =3D kcalloc(n, sizeof(*amd_l3_attrs), GFP_KERNEL); + if (!amd_l3_attrs) + return; + + n =3D 0; + if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) { + amd_l3_attrs[n++] =3D &dev_attr_cache_disable_0.attr; + amd_l3_attrs[n++] =3D &dev_attr_cache_disable_1.attr; + } + if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) + amd_l3_attrs[n++] =3D &dev_attr_subcaches.attr; + + cache_private_group.attrs =3D amd_l3_attrs; +} + +const struct attribute_group *cache_get_priv_group(struct cacheinfo *ci) +{ + struct amd_northbridge *nb =3D ci->priv; + + if (ci->level < 3 || !nb) + return NULL; + + if (nb && nb->l3_cache.indices) + init_amd_l3_attrs(); + + return &cache_private_group; +} + +struct amd_northbridge *amd_init_l3_cache(int index) +{ + struct amd_northbridge *nb; + int node; + + /* only for L3, and not in virtualized environments */ + if (index < 3) + return NULL; + + node =3D topology_amd_node_id(smp_processor_id()); + nb =3D node_to_amd_nb(node); + if (nb && !nb->l3_cache.indices) + amd_calc_l3_indices(nb); + + return nb; +} diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 2a56c7cc3c2d..eadd117c05e1 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -9,12 +9,9 @@ */ =20 #include -#include #include #include -#include #include -#include =20 #include #include @@ -300,301 +297,6 @@ amd_cpuid4(int index, union _cpuid4_leaf_eax *eax, (ebx->split.ways_of_associativity + 1) - 1; } =20 -#if defined(CONFIG_AMD_NB) && defined(CONFIG_SYSFS) - -/* - * L3 cache descriptors - */ -static void amd_calc_l3_indices(struct amd_northbridge *nb) -{ - struct amd_l3_cache *l3 =3D &nb->l3_cache; - unsigned int sc0, sc1, sc2, sc3; - u32 val =3D 0; - - pci_read_config_dword(nb->misc, 0x1C4, &val); - - /* calculate subcache sizes */ - l3->subcaches[0] =3D sc0 =3D !(val & BIT(0)); - l3->subcaches[1] =3D sc1 =3D !(val & BIT(4)); - - if (boot_cpu_data.x86 =3D=3D 0x15) { - l3->subcaches[0] =3D sc0 +=3D !(val & BIT(1)); - l3->subcaches[1] =3D sc1 +=3D !(val & BIT(5)); - } - - l3->subcaches[2] =3D sc2 =3D !(val & BIT(8)) + !(val & BIT(9)); - l3->subcaches[3] =3D sc3 =3D !(val & BIT(12)) + !(val & BIT(13)); - - l3->indices =3D (max(max3(sc0, sc1, sc2), sc3) << 10) - 1; -} - -/* - * check whether a slot used for disabling an L3 index is occupied. - * @l3: L3 cache descriptor - * @slot: slot number (0..1) - * - * @returns: the disabled index if used or negative value if slot free. - */ -static int amd_get_l3_disable_slot(struct amd_northbridge *nb, unsigned sl= ot) -{ - unsigned int reg =3D 0; - - pci_read_config_dword(nb->misc, 0x1BC + slot * 4, ®); - - /* check whether this slot is activated already */ - if (reg & (3UL << 30)) - return reg & 0xfff; - - return -1; -} - -static ssize_t show_cache_disable(struct cacheinfo *ci, char *buf, unsigne= d int slot) -{ - int index; - struct amd_northbridge *nb =3D ci->priv; - - index =3D amd_get_l3_disable_slot(nb, slot); - if (index >=3D 0) - return sprintf(buf, "%d\n", index); - - return sprintf(buf, "FREE\n"); -} - -#define SHOW_CACHE_DISABLE(slot) \ -static ssize_t \ -cache_disable_##slot##_show(struct device *dev, \ - struct device_attribute *attr, char *buf) \ -{ \ - struct cacheinfo *ci =3D dev_get_drvdata(dev); \ - return show_cache_disable(ci, buf, slot); \ -} -SHOW_CACHE_DISABLE(0) -SHOW_CACHE_DISABLE(1) - -static void amd_l3_disable_index(struct amd_northbridge *nb, int cpu, - unsigned slot, unsigned long idx) -{ - int i; - - idx |=3D BIT(30); - - /* - * disable index in all 4 subcaches - */ - for (i =3D 0; i < 4; i++) { - u32 reg =3D idx | (i << 20); - - if (!nb->l3_cache.subcaches[i]) - continue; - - pci_write_config_dword(nb->misc, 0x1BC + slot * 4, reg); - - /* - * We need to WBINVD on a core on the node containing the L3 - * cache which indices we disable therefore a simple wbinvd() - * is not sufficient. - */ - wbinvd_on_cpu(cpu); - - reg |=3D BIT(31); - pci_write_config_dword(nb->misc, 0x1BC + slot * 4, reg); - } -} - -/* - * disable a L3 cache index by using a disable-slot - * - * @l3: L3 cache descriptor - * @cpu: A CPU on the node containing the L3 cache - * @slot: slot number (0..1) - * @index: index to disable - * - * @return: 0 on success, error status on failure - */ -static int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, - unsigned slot, unsigned long index) -{ - int ret =3D 0; - - /* check if @slot is already used or the index is already disabled */ - ret =3D amd_get_l3_disable_slot(nb, slot); - if (ret >=3D 0) - return -EEXIST; - - if (index > nb->l3_cache.indices) - return -EINVAL; - - /* check whether the other slot has disabled the same index already */ - if (index =3D=3D amd_get_l3_disable_slot(nb, !slot)) - return -EEXIST; - - amd_l3_disable_index(nb, cpu, slot, index); - - return 0; -} - -static ssize_t store_cache_disable(struct cacheinfo *ci, const char *buf, - size_t count, unsigned int slot) -{ - unsigned long val =3D 0; - int cpu, err =3D 0; - struct amd_northbridge *nb =3D ci->priv; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - cpu =3D cpumask_first(&ci->shared_cpu_map); - - if (kstrtoul(buf, 10, &val) < 0) - return -EINVAL; - - err =3D amd_set_l3_disable_slot(nb, cpu, slot, val); - if (err) { - if (err =3D=3D -EEXIST) - pr_warn("L3 slot %d in use/index already disabled!\n", - slot); - return err; - } - return count; -} - -#define STORE_CACHE_DISABLE(slot) \ -static ssize_t \ -cache_disable_##slot##_store(struct device *dev, \ - struct device_attribute *attr, \ - const char *buf, size_t count) \ -{ \ - struct cacheinfo *ci =3D dev_get_drvdata(dev); \ - return store_cache_disable(ci, buf, count, slot); \ -} -STORE_CACHE_DISABLE(0) -STORE_CACHE_DISABLE(1) - -static ssize_t subcaches_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct cacheinfo *ci =3D dev_get_drvdata(dev); - int cpu =3D cpumask_first(&ci->shared_cpu_map); - - return sprintf(buf, "%x\n", amd_get_subcaches(cpu)); -} - -static ssize_t subcaches_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct cacheinfo *ci =3D dev_get_drvdata(dev); - int cpu =3D cpumask_first(&ci->shared_cpu_map); - unsigned long val; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - if (kstrtoul(buf, 16, &val) < 0) - return -EINVAL; - - if (amd_set_subcaches(cpu, val)) - return -EINVAL; - - return count; -} - -static DEVICE_ATTR_RW(cache_disable_0); -static DEVICE_ATTR_RW(cache_disable_1); -static DEVICE_ATTR_RW(subcaches); - -static umode_t -cache_private_attrs_is_visible(struct kobject *kobj, - struct attribute *attr, int unused) -{ - struct device *dev =3D kobj_to_dev(kobj); - struct cacheinfo *ci =3D dev_get_drvdata(dev); - umode_t mode =3D attr->mode; - - if (!ci->priv) - return 0; - - if ((attr =3D=3D &dev_attr_subcaches.attr) && - amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) - return mode; - - if ((attr =3D=3D &dev_attr_cache_disable_0.attr || - attr =3D=3D &dev_attr_cache_disable_1.attr) && - amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) - return mode; - - return 0; -} - -static struct attribute_group cache_private_group =3D { - .is_visible =3D cache_private_attrs_is_visible, -}; - -static void init_amd_l3_attrs(void) -{ - int n =3D 1; - static struct attribute **amd_l3_attrs; - - if (amd_l3_attrs) /* already initialized */ - return; - - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) - n +=3D 2; - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) - n +=3D 1; - - amd_l3_attrs =3D kcalloc(n, sizeof(*amd_l3_attrs), GFP_KERNEL); - if (!amd_l3_attrs) - return; - - n =3D 0; - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) { - amd_l3_attrs[n++] =3D &dev_attr_cache_disable_0.attr; - amd_l3_attrs[n++] =3D &dev_attr_cache_disable_1.attr; - } - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) - amd_l3_attrs[n++] =3D &dev_attr_subcaches.attr; - - cache_private_group.attrs =3D amd_l3_attrs; -} - -const struct attribute_group * -cache_get_priv_group(struct cacheinfo *ci) -{ - struct amd_northbridge *nb =3D ci->priv; - - if (ci->level < 3 || !nb) - return NULL; - - if (nb && nb->l3_cache.indices) - init_amd_l3_attrs(); - - return &cache_private_group; -} - -static struct amd_northbridge *amd_init_l3_cache(int index) -{ - struct amd_northbridge *nb; - int node; - - /* only for L3, and not in virtualized environments */ - if (index < 3) - return NULL; - - node =3D topology_amd_node_id(smp_processor_id()); - nb =3D node_to_amd_nb(node); - if (nb && !nb->l3_cache.indices) - amd_calc_l3_indices(nb); - - return nb; -} -#else -static struct amd_northbridge *amd_init_l3_cache(int index) -{ - return NULL; -} -#endif /* CONFIG_AMD_NB && CONFIG_SYSFS */ - /* * Fill passed _cpuid4_info_regs structure. * Intel-only code paths should pass NULL for the amd_northbridge diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index 51deb60a9d26..bc38b2d56f26 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -75,6 +75,15 @@ extern void check_null_seg_clears_base(struct cpuinfo_x8= 6 *c); void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id); void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c); =20 +#if defined(CONFIG_AMD_NB) && defined(CONFIG_SYSFS) +struct amd_northbridge *amd_init_l3_cache(int index); +#else +static inline struct amd_northbridge *amd_init_l3_cache(int index) +{ + return NULL; +} +#endif + unsigned int aperfmperf_get_khz(int cpu); void cpu_select_mitigations(void); =20 --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 76148200BAA for ; Tue, 4 Mar 2025 08:53: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=1741078409; cv=none; b=t+oUkWULHV9r4Yd0Ap0MoXGcIG3SaHKSvN7+uysXYC3VZeoHVUEHLbjy3IwKMOMVWbUHw5nH/0Tp1Wx5S+LzsQ1q3Ow3gK4PjAHM7awoEmXIHvTc94GRq51diw5XXMBWzGHqBqCqoDO/k7kbacyNhZ04b3TQL+/gFgwc0h1K69U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078409; c=relaxed/simple; bh=wEw51A1Z/Kflsa07gSPSJJT92gdgpGM02PW8kbXEZCQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J0QGgibqJq5QkpixhSCS74TfVjLpfJkd9669M5teZKT5NCcsakSs8ySF2Cz+LGFfqrggpFkRPaARkrvz2UNlnVv3/1KIuS/GeCvAwlhRieCIY1H08TquazpMphrBHJhsTmCP+l88PFiwdh2OWvWIFiq6QYGEu6PF8rV5UxijnIk= 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=lPip/Dkm; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NGDaIqpQ; 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="lPip/Dkm"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NGDaIqpQ" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078406; 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=wIM1/UO/olTqtQhk58W5MQceA/7wLYg5WiO97m4eSsc=; b=lPip/DkmB/92v94JErAiQC8uoeqSeACnN0hnnmFf/NjeSvpyu3JqGZLRP6IZnqrk+9vmu8 3YrsWd2YHkEzmbPzzxTiWjPR04qWXYz2rIYLjWogwjcPrqfRUboM7ne5qOZpd8/cwMFHuw q8OX9UMAJAH6xxhKuJA82cZ1L8WBPbLZU/f2lmo7pY75KyIo7XDHpXp5BbYOWYWczMqmQT HA5SoKjZoUR0uFWcGz95grWMyunQKUkXNsqBKcHmJyZSzwPn6APIcDNZjZBXhMpblJZnYg KbqcG1vIn5eV2z/fTiQsWKJ+9UC4dpmMgVxuKXIVkMi3FvyUsZvoVH/UFQoPNw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078406; 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=wIM1/UO/olTqtQhk58W5MQceA/7wLYg5WiO97m4eSsc=; b=NGDaIqpQoulPol6XwoMZ+RfcrywgcdCTrVTSr31eYie65gsHTkoc6CpPulQqLJn0h1IEyL p+H239vMB5hS0oDQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 24/40] x86/cacheinfo: Use sysfs_emit() for sysfs attributes show() Date: Tue, 4 Mar 2025 09:51:35 +0100 Message-ID: <20250304085152.51092-25-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Per Documentation/filesystems/sysfs.rst, a sysfs attribute's show() method should only use sysfs_emit() or sysfs_emit_at() when returning values to user space. Use sysfs_emit() for the AMD L3 cache sysfs attributes cache_disable_0, cache_disable_1, and subcaches. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/amd_cache_disable.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/cpu/amd_cache_disable.c b/arch/x86/kernel/cpu/= amd_cache_disable.c index 6d53aee0d869..d860ad3f8a5a 100644 --- a/arch/x86/kernel/cpu/amd_cache_disable.c +++ b/arch/x86/kernel/cpu/amd_cache_disable.c @@ -66,9 +66,9 @@ static ssize_t show_cache_disable(struct cacheinfo *ci, c= har *buf, unsigned int =20 index =3D amd_get_l3_disable_slot(nb, slot); if (index >=3D 0) - return sprintf(buf, "%d\n", index); + return sysfs_emit(buf, "%d\n", index); =20 - return sprintf(buf, "FREE\n"); + return sysfs_emit(buf, "FREE\n"); } =20 #define SHOW_CACHE_DISABLE(slot) \ @@ -189,7 +189,7 @@ static ssize_t subcaches_show(struct device *dev, struc= t device_attribute *attr, struct cacheinfo *ci =3D dev_get_drvdata(dev); int cpu =3D cpumask_first(&ci->shared_cpu_map); =20 - return sprintf(buf, "%x\n", amd_get_subcaches(cpu)); + return sysfs_emit(buf, "%x\n", amd_get_subcaches(cpu)); } =20 static ssize_t subcaches_store(struct device *dev, --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 796C4201113 for ; Tue, 4 Mar 2025 08:53: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=1741078412; cv=none; b=N2og6Wx6YlpSdD7TKKiYwXwi1xt3IPvMbtMmSq6iWTaeiJVNm3/AGAGKS4YgPQZlEpmQhKIBGtx3MAkvF8eeYDJVwxpLcdVhyKGTNHz49wEkdbwgga+nx7BSsckRChMfFZN+jYmEnl6/35CNHxpEB0R9yHhDChxlH2zNcVdojlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078412; c=relaxed/simple; bh=K1hPwdgJoPejrVvcCPX6kdTs0OYpck9lAIlrDpNss8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=coYT6QflQi0MNLVu4r592YqeupEnwk7/RvXIVi3RJEJF5D7cEoOP0rx8qB0S88baMHi5KgMbFnxuGnWiPRcjEFxg/zoHa12hdGsFMZO61bY7jQYZRLSQ83ajI0cJK764wkgFamqq+lDSLz3t6vvmE7mbuTXFFQgVyG5UJrzoxRg= 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=nhlZ2jxe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BZ1Foueq; 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="nhlZ2jxe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BZ1Foueq" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078409; 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=Gwov3ONbr2OPdQ03jCxI51Xzj9Lk7s4sEUU22jCJ/XU=; b=nhlZ2jxeo2dtSgci28OEKBWavHRzOq2SScz99xEl0nqtV6kCKv6V6dPE+j5xTaIvzk+6Lv zcshjRZdeQfiik0G6ma0WMSOesxYB1EY0VCJA4EgEE16DQL6kJxxGYIDjtu8a7dWhXMe5h PRjA8NDbKpxEBalnzTDEuID4aMpQpadETC8hjVZWfKhJaCokksYDai4AFnLsheS6aieceO 36fvZPDm9OVyVuhf54N5DiL4eAuxUU5NxQItc4PrYAesc1oEbUNp6mK4JDTAxSrkhTZ7PT 1ZEO9AbLvK1uKMJnfSh6arJLTeVDdGi13yaEf908axfm/ome5BxWnf3wITj/XQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078409; 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=Gwov3ONbr2OPdQ03jCxI51Xzj9Lk7s4sEUU22jCJ/XU=; b=BZ1FoueqMetQNEaTNLG37qPNDqsDfUBJXE7Wdqptf9q7JVJRrfeKCHlprtAEHh1iHp6oSa K7iS+0k4nJ30+vDA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 25/40] x86/cacheinfo: Separate Intel and AMD leaf 0x4 code paths Date: Tue, 4 Mar 2025 09:51:36 +0100 Message-ID: <20250304085152.51092-26-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x4 parsing code at cpuid4_cache_lookup_regs() is ugly and convoluted. It's tangled with multiple nested conditions to handle: - AMD with TOPEXT, or Hygon CPUs via leaf 0x8000001d - Legacy AMD fallback via leaf 0x4 emulation - Intel CPUs via the actual cpuid leaf 0x4 AMD L3 northbridge initialization is also awkwardly placed alongside the cpuid calls of the first two scenarios. Refactor all of that as follows: - Update AMD's leaf 0x4 emulation comment to represent current state. - Clearly label the AMD leaf 0x4 emulation function as a fallback. - Split AMD/Hygon and Intel code paths into separate functions. - Move AMD L3 northbridge initialization out of leaf 0x4 code, and into populate_cache_leaves() where it belongs. There, ci_info_init() can directly store the initialized object in the priv pointer of the linux/cacheinfo.h API. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 93 ++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index eadd117c05e1..cc320817cfc3 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -167,12 +167,11 @@ struct _cpuid4_info_regs { unsigned long size; }; =20 -/* AMD doesn't have CPUID4. Emulate it here to report the same - information to the user. This makes some assumptions about the machine: - L2 not shared, no SMT etc. that is currently true on AMD CPUs. +/* + * Fallback AMD CPUID(4) emulation + * AMD CPUs with TOPOEXT can just use CPUID(0x8000001d) + */ =20 - In theory the TLBs could be reported as fake type (they are in "dummy"). - Maybe later */ union l1_cache { struct { unsigned line_size:8; @@ -228,9 +227,8 @@ static const enum cache_type cache_type_map[] =3D { [CTYPE_UNIFIED] =3D CACHE_TYPE_UNIFIED, }; =20 -static void -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, union _cpuid4_leaf_eax *eax, + union _cpuid4_leaf_ebx *ebx, union _cpuid4_leaf_ecx *ecx) { unsigned int dummy, line_size, lines_per_tag, assoc, size_in_kb; union l1_cache l1i, l1d; @@ -297,37 +295,9 @@ amd_cpuid4(int index, union _cpuid4_leaf_eax *eax, (ebx->split.ways_of_associativity + 1) - 1; } =20 -/* - * Fill passed _cpuid4_info_regs structure. - * Intel-only code paths should pass NULL for the amd_northbridge - * return pointer. - */ -static int cpuid4_cache_lookup_regs(int index, struct _cpuid4_info_regs *i= d4, - struct amd_northbridge **nb) +static int cpuid4_info_fill_done(struct _cpuid4_info_regs *id4, union _cpu= id4_leaf_eax eax, + union _cpuid4_leaf_ebx ebx, union _cpuid4_leaf_ecx ecx) { - union _cpuid4_leaf_eax eax; - union _cpuid4_leaf_ebx ebx; - union _cpuid4_leaf_ecx ecx; - unsigned edx; - - if (x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) { - if (boot_cpu_has(X86_FEATURE_TOPOEXT) || - boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_HYGON) { - /* AMD with TOPOEXT, or HYGON */ - cpuid_count(0x8000001d, index, &eax.full, - &ebx.full, &ecx.full, &edx); - } else { - /* Legacy AMD fallback */ - amd_cpuid4(index, &eax, &ebx, &ecx); - } - - if (nb) - *nb =3D amd_init_l3_cache(index); - } else { - /* Intel */ - cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx); - } - if (eax.split.type =3D=3D CTYPE_NULL) return -EIO; =20 @@ -342,6 +312,40 @@ static int cpuid4_cache_lookup_regs(int index, struct = _cpuid4_info_regs *id4, return 0; } =20 +static int amd_fill_cpuid4_info(int index, struct _cpuid4_info_regs *id4) +{ + union _cpuid4_leaf_eax eax; + union _cpuid4_leaf_ebx ebx; + union _cpuid4_leaf_ecx ecx; + unsigned int ignored; + + 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 + legacy_amd_cpuid4(index, &eax, &ebx, &ecx); + + return cpuid4_info_fill_done(id4, eax, ebx, ecx); +} + +static int intel_fill_cpuid4_info(int index, struct _cpuid4_info_regs *id4) +{ + union _cpuid4_leaf_eax eax; + union _cpuid4_leaf_ebx ebx; + union _cpuid4_leaf_ecx ecx; + unsigned int ignored; + + cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &ignored); + + return cpuid4_info_fill_done(id4, eax, ebx, ecx); +} + +static int fill_cpuid4_info(int index, struct _cpuid4_info_regs *id4) +{ + return x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor) ? + amd_fill_cpuid4_info(index, id4) : + intel_fill_cpuid4_info(index, id4); +} + static int find_num_cache_leaves(struct cpuinfo_x86 *c) { unsigned int eax, ebx, ecx, edx, op; @@ -472,7 +476,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) struct _cpuid4_info_regs id4 =3D {}; int retval; =20 - retval =3D cpuid4_cache_lookup_regs(i, &id4, NULL); + retval =3D intel_fill_cpuid4_info(i, &id4); if (retval < 0) continue; =20 @@ -690,17 +694,22 @@ static void get_cache_id(int cpu, struct _cpuid4_info= _regs *id4) =20 int populate_cache_leaves(unsigned int cpu) { - unsigned int idx, ret; struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci =3D this_cpu_ci->info_list; struct _cpuid4_info_regs id4 =3D {}; - struct amd_northbridge *nb; + struct amd_northbridge *nb =3D NULL; + int idx, ret; =20 for (idx =3D 0; idx < this_cpu_ci->num_leaves; idx++) { - ret =3D cpuid4_cache_lookup_regs(idx, &id4, &nb); + ret =3D fill_cpuid4_info(idx, &id4); if (ret) return ret; + get_cache_id(cpu, &id4); + + if (x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor)) + nb =3D amd_init_l3_cache(idx); + ci_info_init(ci++, &id4, nb); __cache_cpumap_setup(cpu, idx, &id4); } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 8683C201035 for ; Tue, 4 Mar 2025 08:53: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=1741078415; cv=none; b=PvJgKjLTBcfVtoURJE4qtQ/9zlNXjKrmUCRkHqH+ngR3UQYCJ4FeGdZVHQhBhauEfMC+y7gME61z2SfmNSon6NAxA5W8gTwMMkT1zwilWYtJMxA++JHclHRtpZhh3dKMWvQ0wH7rUhQgtRlQ7vUAylGq7UGsks1/XatK0oMo+po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078415; c=relaxed/simple; bh=xfuli/6Bk10AYSMF8dE3nvNxHUUUcl16U1XYIU9Ak9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qFiOU4fwUE682jqMxILlRjmpsMSek3JDSI4p63kA2X42Q+lxwMcvFf1/iv8mHoWEJ61V3NyclowgzzNhJ39Te0r041U7xjdKn+JtN8SVhrdR2O+hVr5bVfl3fTj5x4dGD/l4w4sY7aqSFBg7fx09GuFFt8doEUo7mJ04f5fkeP0= 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=SKgQ6yWz; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=F/01IoSI; 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="SKgQ6yWz"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="F/01IoSI" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078412; 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=ErUogKnyYbOrLN500X12sFjQxofXjma3yuw+5jvrHP8=; b=SKgQ6yWzJnXAITRXZ5hkbQ1Kq745/NFuNAVmh/AGdVoWqYqlnDKNbn4R6uhO/zIaG1FtUH G8AGV8q+gweSiAQhzTyyxWHm2NB9QFHOmElQu8XT5w9HES6cRCpuWdxD8eKacaYaZqB13n qqQEgDxGwxv4WCooad3A4Xy+9S0L6REYzeOTetzITDeYDs8ZO03vwHS+yMCcROzCluMesG INtCtCNrX2P8yTbJ1h5aQPWBgvDIH+80JTEjD8bZ++OmWpoqaUjDD173aaKwLNGTeYRlMa WoaJM5Usmfn6nyymtA/UcR+W2WdGe9sZu7be7nrJNv+nwf/mIWtvkZuyUqdpcg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078412; 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=ErUogKnyYbOrLN500X12sFjQxofXjma3yuw+5jvrHP8=; b=F/01IoSIH1XiN02Rr7sqGN9XDD6blIlsTbIfWHKlC8NrVWVeRr9SedilrUOHyOmuLbtdKt K5CAhWaq073u3/Aw== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 26/40] x86/cacheinfo: Rename _cpuid4_info_regs to _cpuid4_info Date: Tue, 4 Mar 2025 09:51:37 +0100 Message-ID: <20250304085152.51092-27-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Parent commits decoupled amd_northbridge from _cpuid4_info_regs, moved AMD L3 northbridge cache_disable_0/1 sysfs code to its own file, and splitted AMD vs. Intel leaf 0x4 handling into: amd_fill_cpuid4_info() intel_fill_cpuid4_info() fill_cpuid4_info() After doing all that, the "_cpuid4_info_regs" name becomes a mouthful. It is also not totally accurate, as the structure holds cpuid4 derived information like cache node ID and size -- not just regs. Rename struct _cpuid4_info_regs to _cpuid4_info. That new name also better matches the AMD/Intel leaf 0x4 functions mentioned above. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index cc320817cfc3..2d4180b961f4 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -159,7 +159,7 @@ union _cpuid4_leaf_ecx { u32 full; }; =20 -struct _cpuid4_info_regs { +struct _cpuid4_info { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; union _cpuid4_leaf_ecx ecx; @@ -295,7 +295,7 @@ static void legacy_amd_cpuid4(int index, union _cpuid4_= leaf_eax *eax, (ebx->split.ways_of_associativity + 1) - 1; } =20 -static int cpuid4_info_fill_done(struct _cpuid4_info_regs *id4, union _cpu= id4_leaf_eax eax, +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) { if (eax.split.type =3D=3D CTYPE_NULL) @@ -312,7 +312,7 @@ static int cpuid4_info_fill_done(struct _cpuid4_info_re= gs *id4, union _cpuid4_le return 0; } =20 -static int amd_fill_cpuid4_info(int index, struct _cpuid4_info_regs *id4) +static int amd_fill_cpuid4_info(int index, struct _cpuid4_info *id4) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; @@ -327,7 +327,7 @@ static int amd_fill_cpuid4_info(int index, struct _cpui= d4_info_regs *id4) return cpuid4_info_fill_done(id4, eax, ebx, ecx); } =20 -static int intel_fill_cpuid4_info(int index, struct _cpuid4_info_regs *id4) +static int intel_fill_cpuid4_info(int index, struct _cpuid4_info *id4) { union _cpuid4_leaf_eax eax; union _cpuid4_leaf_ebx ebx; @@ -339,7 +339,7 @@ static int intel_fill_cpuid4_info(int index, struct _cp= uid4_info_regs *id4) return cpuid4_info_fill_done(id4, eax, ebx, ecx); } =20 -static int fill_cpuid4_info(int index, struct _cpuid4_info_regs *id4) +static int fill_cpuid4_info(int index, struct _cpuid4_info *id4) { return x86_vendor_amd_or_hygon(boot_cpu_data.x86_vendor) ? amd_fill_cpuid4_info(index, id4) : @@ -473,7 +473,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) * parameters cpuid leaf to find the cache details */ for (i =3D 0; i < ci->num_leaves; i++) { - struct _cpuid4_info_regs id4 =3D {}; + struct _cpuid4_info id4 =3D {}; int retval; =20 retval =3D intel_fill_cpuid4_info(i, &id4); @@ -560,7 +560,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) } =20 static int __cache_amd_cpumap_setup(unsigned int cpu, int index, - const struct _cpuid4_info_regs *id4) + const struct _cpuid4_info *id4) { struct cpu_cacheinfo *this_cpu_ci; struct cacheinfo *ci; @@ -617,7 +617,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, } =20 static void __cache_cpumap_setup(unsigned int cpu, int index, - const struct _cpuid4_info_regs *id4) + const struct _cpuid4_info *id4) { struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); struct cacheinfo *ci, *sibling_ci; @@ -650,7 +650,7 @@ static void __cache_cpumap_setup(unsigned int cpu, int = index, } } =20 -static void ci_info_init(struct cacheinfo *ci, const struct _cpuid4_info_r= egs *id4, +static void ci_info_init(struct cacheinfo *ci, const struct _cpuid4_info *= id4, struct amd_northbridge *nb) { ci->id =3D id4->id; @@ -681,7 +681,7 @@ int init_cache_level(unsigned int cpu) * ECX as cache index. Then right shift apicid by the number's order to get * cache id for this cache node. */ -static void get_cache_id(int cpu, struct _cpuid4_info_regs *id4) +static void get_cache_id(int cpu, struct _cpuid4_info *id4) { struct cpuinfo_x86 *c =3D &cpu_data(cpu); unsigned long num_threads_sharing; @@ -696,8 +696,8 @@ 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; - struct _cpuid4_info_regs id4 =3D {}; 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++) { --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 B575B202974 for ; Tue, 4 Mar 2025 08:53: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=1741078418; cv=none; b=d06Fw0UYNWuAHbuebzu+36C+2ntuJRwDmlIEFU1TmsztZ9CvGXXpueY+F8c8f1eo1G3HZH98rRs2dKkEojl7yghuAEbeeglWqcBz1ookSw4Tuu8IclYwbI0koMC3cYwY7DpLr5np2C9MJoTYVq8uP7IHsoDsBSk0k1IccngO5pE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078418; c=relaxed/simple; bh=Xf6TMQaIsyJCUu2qh2Sto6zALHdaoZ30+dLgDhZ0Q/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ambGhpwC2lkLcOFl7gtS9Nj68e9Dm8FUrLW8wT05c2BXimd73yHuiMNArhmSiZOkyNX/wJt3XYPgATnEw1Sp9h1uk0olmdV+LEI62Laj4bV5Zt8429XOzRcnPnkhGgsceFAyRvfY+FHP0e6fFNb//Vyyc6ej56FdvawNBNWs/gY= 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=dMH/AlDY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=O6vqJRVD; 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="dMH/AlDY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="O6vqJRVD" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078415; 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=wyVJW/uhOsel/N7suYlz5Goimcr1uKn+zKWoOmAy3e0=; b=dMH/AlDYkIoauy1pKXP7R0bTrEzZwjK/cbGyAVEc0LjKH9GXape/c8Pw3ANohlnJuRxZPy xnHDIYn6B4AYU3VE99Y+DQ8FIKaH0ou2Qw+x/UokjDnCPYZwVnNJl+Jk/oc4M2B3usHeVa 2VCdp7eX6COZXe32GAFI2ldHEeV1XdV4XHFbL6vBI/m8pMUY32KQx36vsv2AIsgBmZ5jwk r5HkaW3T/TXKZnJQ5Qh9odhIL6gXxCDnbkznd9CAEgkvilPrmmahuBbGFI0cG615z8uiUv O6aMM89j+xoA2K8EROniUxnD9k5CK/ZJcKlIi6D1y6v79rZ8jyuGJ84uv40zhA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078415; 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=wyVJW/uhOsel/N7suYlz5Goimcr1uKn+zKWoOmAy3e0=; b=O6vqJRVDPFxwR09Le1eQFicXsbeG3wA0ORX0hRoh14eLZAeVDEykPOoibQEQvNir/6FYAy 90d3jGBmKMgxcvBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 27/40] x86/cacheinfo: Clarify type markers for leaf 0x2 cache descriptors Date: Tue, 4 Mar 2025 09:51:38 +0100 Message-ID: <20250304085152.51092-28-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 output is a stream of one-byte descriptors, each implying certain details about the CPU's cache and TLB entries. Two separate tables exist for interpreting these descriptors: one for TLBs at intel.c and one for caches at cacheinfo.c. These mapping tables will be merged in further commits, among other improvements to their model. In preparation for this, use more descriptive type names for the leaf 0x2 descriptors associated with cpu caches. Namely: LVL_1_INST =3D> CACHE_L1_INST LVL_1_DATA =3D> CACHE_L1_DATA LVL_2 =3D> CACHE_L2 LVL_3 =3D> CACHE_L3 After the TLB and cache descriptors mapping tables are merged, this will make it clear that such descriptors correspond to cpu caches. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 152 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 2d4180b961f4..9e87321466fe 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -23,10 +23,10 @@ =20 #include "cpu.h" =20 -#define LVL_1_INST 1 -#define LVL_1_DATA 2 -#define LVL_2 3 -#define LVL_3 4 +#define CACHE_L1_INST 1 +#define CACHE_L1_DATA 2 +#define CACHE_L2 3 +#define CACHE_L3 4 =20 /* Shared last level cache maps */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); @@ -52,74 +52,74 @@ struct _cache_table { =20 static const struct _cache_table cache_table[] =3D { - { 0x06, LVL_1_INST, 8 }, /* 4-way set assoc, 32 byte line size */ - { 0x08, LVL_1_INST, 16 }, /* 4-way set assoc, 32 byte line size */ - { 0x09, LVL_1_INST, 32 }, /* 4-way set assoc, 64 byte line size */ - { 0x0a, LVL_1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */ - { 0x0c, LVL_1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */ - { 0x0d, LVL_1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */ - { 0x0e, LVL_1_DATA, 24 }, /* 6-way set assoc, 64 byte line size */ - { 0x21, LVL_2, 256 }, /* 8-way set assoc, 64 byte line size */ - { 0x22, LVL_3, 512 }, /* 4-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x23, LVL_3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte = line size */ - { 0x25, LVL_3, MB(2) }, /* 8-way set assoc, sectored cache, 64 byte = line size */ - { 0x29, LVL_3, MB(4) }, /* 8-way set assoc, sectored cache, 64 byte = line size */ - { 0x2c, LVL_1_DATA, 32 }, /* 8-way set assoc, 64 byte line size */ - { 0x30, LVL_1_INST, 32 }, /* 8-way set assoc, 64 byte line size */ - { 0x39, LVL_2, 128 }, /* 4-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x3a, LVL_2, 192 }, /* 6-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x3b, LVL_2, 128 }, /* 2-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x3c, LVL_2, 256 }, /* 4-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x3d, LVL_2, 384 }, /* 6-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x3e, LVL_2, 512 }, /* 4-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x3f, LVL_2, 256 }, /* 2-way set assoc, 64 byte line size */ - { 0x41, LVL_2, 128 }, /* 4-way set assoc, 32 byte line size */ - { 0x42, LVL_2, 256 }, /* 4-way set assoc, 32 byte line size */ - { 0x43, LVL_2, 512 }, /* 4-way set assoc, 32 byte line size */ - { 0x44, LVL_2, MB(1) }, /* 4-way set assoc, 32 byte line size */ - { 0x45, LVL_2, MB(2) }, /* 4-way set assoc, 32 byte line size */ - { 0x46, LVL_3, MB(4) }, /* 4-way set assoc, 64 byte line size */ - { 0x47, LVL_3, MB(8) }, /* 8-way set assoc, 64 byte line size */ - { 0x48, LVL_2, MB(3) }, /* 12-way set assoc, 64 byte line size */ - { 0x49, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */ - { 0x4a, LVL_3, MB(6) }, /* 12-way set assoc, 64 byte line size */ - { 0x4b, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */ - { 0x4c, LVL_3, MB(12) }, /* 12-way set assoc, 64 byte line size */ - { 0x4d, LVL_3, MB(16) }, /* 16-way set assoc, 64 byte line size */ - { 0x4e, LVL_2, MB(6) }, /* 24-way set assoc, 64 byte line size */ - { 0x60, LVL_1_DATA, 16 }, /* 8-way set assoc, sectored cache, 64 byte lin= e size */ - { 0x66, LVL_1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ - { 0x67, LVL_1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte lin= e size */ - { 0x68, LVL_1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte lin= e size */ - { 0x78, LVL_2, MB(1) }, /* 4-way set assoc, 64 byte line size */ - { 0x79, LVL_2, 128 }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x7a, LVL_2, 256 }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x7b, LVL_2, 512 }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x7c, LVL_2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte = line size */ - { 0x7d, LVL_2, MB(2) }, /* 8-way set assoc, 64 byte line size */ - { 0x7f, LVL_2, 512 }, /* 2-way set assoc, 64 byte line size */ - { 0x80, LVL_2, 512 }, /* 8-way set assoc, 64 byte line size */ - { 0x82, LVL_2, 256 }, /* 8-way set assoc, 32 byte line size */ - { 0x83, LVL_2, 512 }, /* 8-way set assoc, 32 byte line size */ - { 0x84, LVL_2, MB(1) }, /* 8-way set assoc, 32 byte line size */ - { 0x85, LVL_2, MB(2) }, /* 8-way set assoc, 32 byte line size */ - { 0x86, LVL_2, 512 }, /* 4-way set assoc, 64 byte line size */ - { 0x87, LVL_2, MB(1) }, /* 8-way set assoc, 64 byte line size */ - { 0xd0, LVL_3, 512 }, /* 4-way set assoc, 64 byte line size */ - { 0xd1, LVL_3, MB(1) }, /* 4-way set assoc, 64 byte line size */ - { 0xd2, LVL_3, MB(2) }, /* 4-way set assoc, 64 byte line size */ - { 0xd6, LVL_3, MB(1) }, /* 8-way set assoc, 64 byte line size */ - { 0xd7, LVL_3, MB(2) }, /* 8-way set assoc, 64 byte line size */ - { 0xd8, LVL_3, MB(4) }, /* 12-way set assoc, 64 byte line size */ - { 0xdc, LVL_3, MB(2) }, /* 12-way set assoc, 64 byte line size */ - { 0xdd, LVL_3, MB(4) }, /* 12-way set assoc, 64 byte line size */ - { 0xde, LVL_3, MB(8) }, /* 12-way set assoc, 64 byte line size */ - { 0xe2, LVL_3, MB(2) }, /* 16-way set assoc, 64 byte line size */ - { 0xe3, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */ - { 0xe4, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */ - { 0xea, LVL_3, MB(12) }, /* 24-way set assoc, 64 byte line size */ - { 0xeb, LVL_3, MB(18) }, /* 24-way set assoc, 64 byte line size */ - { 0xec, LVL_3, MB(24) }, /* 24-way set assoc, 64 byte line size */ + { 0x06, CACHE_L1_INST, 8 }, /* 4-way set assoc, 32 byte line size */ + { 0x08, CACHE_L1_INST, 16 }, /* 4-way set assoc, 32 byte line size */ + { 0x09, CACHE_L1_INST, 32 }, /* 4-way set assoc, 64 byte line size */ + { 0x0a, CACHE_L1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */ + { 0x0c, CACHE_L1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */ + { 0x0d, CACHE_L1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */ + { 0x0e, CACHE_L1_DATA, 24 }, /* 6-way set assoc, 64 byte line size */ + { 0x21, CACHE_L2, 256 }, /* 8-way set assoc, 64 byte line size */ + { 0x22, CACHE_L3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ + { 0x23, CACHE_L3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ + { 0x25, CACHE_L3, MB(2) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ + { 0x29, CACHE_L3, MB(4) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ + { 0x2c, CACHE_L1_DATA, 32 }, /* 8-way set assoc, 64 byte line size */ + { 0x30, CACHE_L1_INST, 32 }, /* 8-way set assoc, 64 byte line size */ + { 0x39, CACHE_L2, 128 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ + { 0x3a, CACHE_L2, 192 }, /* 6-way set assoc, sectored cache, 64 byte line= size */ + { 0x3b, CACHE_L2, 128 }, /* 2-way set assoc, sectored cache, 64 byte line= size */ + { 0x3c, CACHE_L2, 256 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ + { 0x3d, CACHE_L2, 384 }, /* 6-way set assoc, sectored cache, 64 byte line= size */ + { 0x3e, CACHE_L2, 512 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ + { 0x3f, CACHE_L2, 256 }, /* 2-way set assoc, 64 byte line size */ + { 0x41, CACHE_L2, 128 }, /* 4-way set assoc, 32 byte line size */ + { 0x42, CACHE_L2, 256 }, /* 4-way set assoc, 32 byte line size */ + { 0x43, CACHE_L2, 512 }, /* 4-way set assoc, 32 byte line size */ + { 0x44, CACHE_L2, MB(1) }, /* 4-way set assoc, 32 byte line size */ + { 0x45, CACHE_L2, MB(2) }, /* 4-way set assoc, 32 byte line size */ + { 0x46, CACHE_L3, MB(4) }, /* 4-way set assoc, 64 byte line size */ + { 0x47, CACHE_L3, MB(8) }, /* 8-way set assoc, 64 byte line size */ + { 0x48, CACHE_L2, MB(3) }, /* 12-way set assoc, 64 byte line size */ + { 0x49, CACHE_L3, MB(4) }, /* 16-way set assoc, 64 byte line size */ + { 0x4a, CACHE_L3, MB(6) }, /* 12-way set assoc, 64 byte line size */ + { 0x4b, CACHE_L3, MB(8) }, /* 16-way set assoc, 64 byte line size */ + { 0x4c, CACHE_L3, MB(12) }, /* 12-way set assoc, 64 byte line size */ + { 0x4d, CACHE_L3, MB(16) }, /* 16-way set assoc, 64 byte line size */ + { 0x4e, CACHE_L2, MB(6) }, /* 24-way set assoc, 64 byte line size */ + { 0x60, CACHE_L1_DATA, 16 }, /* 8-way set assoc, sectored cache, 64 byte = line size */ + { 0x66, CACHE_L1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte l= ine size */ + { 0x67, CACHE_L1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte = line size */ + { 0x68, CACHE_L1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte = line size */ + { 0x78, CACHE_L2, MB(1) }, /* 4-way set assoc, 64 byte line size */ + { 0x79, CACHE_L2, 128 }, /* 8-way set assoc, sectored cache, 64 byte line= size */ + { 0x7a, CACHE_L2, 256 }, /* 8-way set assoc, sectored cache, 64 byte line= size */ + { 0x7b, CACHE_L2, 512 }, /* 8-way set assoc, sectored cache, 64 byte line= size */ + { 0x7c, CACHE_L2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ + { 0x7d, CACHE_L2, MB(2) }, /* 8-way set assoc, 64 byte line size */ + { 0x7f, CACHE_L2, 512 }, /* 2-way set assoc, 64 byte line size */ + { 0x80, CACHE_L2, 512 }, /* 8-way set assoc, 64 byte line size */ + { 0x82, CACHE_L2, 256 }, /* 8-way set assoc, 32 byte line size */ + { 0x83, CACHE_L2, 512 }, /* 8-way set assoc, 32 byte line size */ + { 0x84, CACHE_L2, MB(1) }, /* 8-way set assoc, 32 byte line size */ + { 0x85, CACHE_L2, MB(2) }, /* 8-way set assoc, 32 byte line size */ + { 0x86, CACHE_L2, 512 }, /* 4-way set assoc, 64 byte line size */ + { 0x87, CACHE_L2, MB(1) }, /* 8-way set assoc, 64 byte line size */ + { 0xd0, CACHE_L3, 512 }, /* 4-way set assoc, 64 byte line size */ + { 0xd1, CACHE_L3, MB(1) }, /* 4-way set assoc, 64 byte line size */ + { 0xd2, CACHE_L3, MB(2) }, /* 4-way set assoc, 64 byte line size */ + { 0xd6, CACHE_L3, MB(1) }, /* 8-way set assoc, 64 byte line size */ + { 0xd7, CACHE_L3, MB(2) }, /* 8-way set assoc, 64 byte line size */ + { 0xd8, CACHE_L3, MB(4) }, /* 12-way set assoc, 64 byte line size */ + { 0xdc, CACHE_L3, MB(2) }, /* 12-way set assoc, 64 byte line size */ + { 0xdd, CACHE_L3, MB(4) }, /* 12-way set assoc, 64 byte line size */ + { 0xde, CACHE_L3, MB(8) }, /* 12-way set assoc, 64 byte line size */ + { 0xe2, CACHE_L3, MB(2) }, /* 16-way set assoc, 64 byte line size */ + { 0xe3, CACHE_L3, MB(4) }, /* 16-way set assoc, 64 byte line size */ + { 0xe4, CACHE_L3, MB(8) }, /* 16-way set assoc, 64 byte line size */ + { 0xea, CACHE_L3, MB(12) }, /* 24-way set assoc, 64 byte line size */ + { 0xeb, CACHE_L3, MB(18) }, /* 24-way set assoc, 64 byte line size */ + { 0xec, CACHE_L3, MB(24) }, /* 24-way set assoc, 64 byte line size */ }; =20 =20 @@ -518,10 +518,10 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) continue; =20 switch (entry->cache_type) { - case LVL_1_INST: l1i +=3D entry->size; break; - case LVL_1_DATA: l1d +=3D entry->size; break; - case LVL_2: l2 +=3D entry->size; break; - case LVL_3: l3 +=3D entry->size; break; + case CACHE_L1_INST: l1i +=3D entry->size; break; + case CACHE_L1_DATA: l1d +=3D entry->size; break; + case CACHE_L2: l2 +=3D entry->size; break; + case CACHE_L3: l3 +=3D entry->size; break; } } } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 6EA2120298B for ; Tue, 4 Mar 2025 08:53: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=1741078421; cv=none; b=fHYr+jjw7kaMDxbmT00zNG1PoahZL6DLB4Gns5iVOwUMNqQ31DQ/wE3G33tYmDF85ZpVed9zPRZLWtkOKX/CINZYmTtHtG/zBbXf8l7H9YxQfKI6L+BWanqbJF7GSWlW46QEW1eyR1gluN7pMI1MGWvSwRX/BC8Xc2zE+rd+spg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078421; c=relaxed/simple; bh=lsxhQurcmM196BSH+oL0A4Qd/q/w2Y/kWtlldc1NdRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lut/Y2xk93bwaa8jP2dtwhSnY0wAOpR5Fh7pV2exbiSeIX1ah1XI+/IjCjzVyLvyiSQciROPSt6yDDwSRYTOp9VvmTBBHwp+z6t3aE4C2DNO4Pon8TenGspRvmLAKhP9AwJl0o7FhXKV27GohTcHGT0/jMorlXAoI8a2nIVtPOw= 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=4BvT2ZQd; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ELXvKaq8; 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="4BvT2ZQd"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ELXvKaq8" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078418; 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=PyaqtxIU8m3/v0+B5MpQxFjLCTwaJUXCAgCjkjGIBQA=; b=4BvT2ZQd2KaFEG7/j9csj17Alf0lhmx2odBQSwdFeK9hawBS6P5gjI9I9ShDY8OqgnSSY5 vWzk+CvQzRJPEKjXeLPBK8uGF5j3dW2tR6dUMXx/1SmE5i6RnOPgrwAiwrUdokohGhkruD tfGSoe7+9YOpLxlRdnXqpruJAhWYyHdtuzh7a+ZC6T5tH06EtDBG44sGIATY5OhY5IeDyN Jv0+/urrJLVk4MmVUGYxAlTXUGGKpNASGQGhNE5W3VrvDBaD3f3817uetXF7B/7WCZqr3Y IURLNFeKzRJqS+jkUoe+Dafy7urnwlV+QIOSMwUXZz1C6hIx5P49fA6bNTE2oA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078418; 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=PyaqtxIU8m3/v0+B5MpQxFjLCTwaJUXCAgCjkjGIBQA=; b=ELXvKaq8NQK7kDQF5xX5aub9QbzKZcGzVntck5qec7Q9LUVmDVT4NDshL729mCp5gHHJdB NKDnjivtKPkLV7CQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 28/40] x86/cacheinfo: Use enums for cache descriptor types Date: Tue, 4 Mar 2025 09:51:39 +0100 Message-ID: <20250304085152.51092-29-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 one-byte cache descriptor types: CACHE_L1_INST CACHE_L1_DATA CACHE_L2 CACHE_L3 are just discriminators to be used within the cache_table[] mapping. Their specific values are irrelevant. Use enums for such types. Make the enum packed and static assert that its values remain within a single byte so that the cache_table[] array size do not go out of hand. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 14 ++++++++++++++ arch/x86/kernel/cpu/cacheinfo.c | 9 ++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 50f6046a57b9..0051d8c2b9ee 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -2,6 +2,8 @@ #ifndef _ASM_X86_CPUID_TYPES_H #define _ASM_X86_CPUID_TYPES_H =20 +#include +#include #include =20 #include @@ -76,4 +78,16 @@ static inline void get_leaf_0x2_regs(union leaf_0x2_regs= *regs) /* Skip the first byte as it is not a descriptor */ \ for (desc =3D &(regs).desc[1]; desc < &(regs).desc[16]; desc++) =20 +/* + * Leaf 0x2 1-byte descriptors' cache types + * To be used for their mappings at cache_table[] + */ +enum _cache_table_type { + CACHE_L1_INST, + CACHE_L1_DATA, + CACHE_L2, + CACHE_L3, +} __packed; +static_assert(sizeof(enum _cache_table_type) =3D=3D 1); + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 9e87321466fe..a7fccbab268d 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -23,11 +23,6 @@ =20 #include "cpu.h" =20 -#define CACHE_L1_INST 1 -#define CACHE_L1_DATA 2 -#define CACHE_L2 3 -#define CACHE_L3 4 - /* Shared last level cache maps */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map); =20 @@ -41,7 +36,7 @@ unsigned int memory_caching_control __ro_after_init; =20 struct _cache_table { unsigned char descriptor; - char cache_type; + enum _cache_table_type type; short size; }; =20 @@ -517,7 +512,7 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) if (!entry) continue; =20 - switch (entry->cache_type) { + switch (entry->type) { case CACHE_L1_INST: l1i +=3D entry->size; break; case CACHE_L1_DATA: l1d +=3D entry->size; break; case CACHE_L2: l2 +=3D entry->size; break; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 7043E20299B for ; Tue, 4 Mar 2025 08:53: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=1741078424; cv=none; b=bl1uG+4e6XSmT7+u/UEa8JCmN25SG0P2qubGrteavYjeLb0q8diCP3/NSLwPQgizCvmOMY/gTwgwjHBbPG605xvBjfkT2n/z7IKoHNbEwxLTOBZ8GXKfIqjG9zEW7Pv5OVpZYtAMnrCjuXb/8wbw9GKPa42PZU1woTIXRWXAgPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078424; c=relaxed/simple; bh=jQG2vJwletYh/YmRc/akLKRggomuDVR/3lDBbg5HsJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UFftPUDfETZ6RtuEijYmXmwzTE0S+Mi02TuJEMQnqEE1eV1M4OfAARv2/rQCZ3JvcJb3E2GfkK7xibhRVpbdFv/gYYDvSBXuDiFfmdqBzkrp2NWtLwfAE2cao9zAIwWpj4PT1egawZ5/pDD38F8TqGw610k0e+YxDsnhHQLW1GA= 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=R/Z3HA4e; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bQeQsp4j; 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="R/Z3HA4e"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bQeQsp4j" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078421; 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=Hb6teOml12m9BN6gMTZxK6kbam1cyV9ClzejVYMjaJU=; b=R/Z3HA4e7Drq/q7dj2tcYf+HJho2mxb+2xdZ7pRwVAdKMT2yzt37aewTKarwqHI9m5w2pR BJj+mh7DXOgExCebJ+hFn/LbWdu6K5uuWqSGOlVU22t8MZsaxCVfsV3Gv9YdIaYxieyeST L1DwzHfgEVLoO2zgvLBVskYit3wCZGC1lQTt4odEb07F5/8iJYWXoGW80uMBZx1CvTkLJq 8eKYCPSG87Hx341Hfh+O7s4DR65QTKfBq4MQl9AKYgs73M6idwLL7peUXm/ubRwT5bXn1O GDgiX9Ew953TIkAN00kGP9Wb8zTLLFTQXzYEAIMeYSbYm7tCi2rKwnXJpZDoEw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078421; 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=Hb6teOml12m9BN6gMTZxK6kbam1cyV9ClzejVYMjaJU=; b=bQeQsp4jnrBujqCNCkSubATgyit6WtTwlzd7J/0rhjCKExMKMG5vOXl0FhNTNhvdGNj7Kk Gduws+4hLK9RGUCQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 29/40] x86/cpu: Use enums for TLB descriptor types Date: Tue, 4 Mar 2025 09:51:40 +0100 Message-ID: <20250304085152.51092-30-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 one-byte TLB descriptor types: TLB_INST_4K TLB_INST_4M TLB_INST_2M_4M ... are just discriminators to be used within the intel_tlb_table[] mapping. Their specific values are irrelevant. Use enums for such types. Make the enum packed and static assert that its values remain within a single byte so that the intel_tlb_table[] size do not go out of hand. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 26 ++++++++++++++++++++++++++ arch/x86/kernel/cpu/intel.c | 28 +++------------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 0051d8c2b9ee..2a4653af2ba2 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -90,4 +90,30 @@ enum _cache_table_type { } __packed; static_assert(sizeof(enum _cache_table_type) =3D=3D 1); =20 +/* + * Leaf 0x2 1-byte descriptors' TLB types + * To be used for their mappings at intel_tlb_table[] + */ +enum _tlb_table_type { + TLB_INST_4K, + TLB_INST_4M, + TLB_INST_2M_4M, + TLB_INST_ALL, + + TLB_DATA_4K, + TLB_DATA_4M, + TLB_DATA_2M_4M, + TLB_DATA_4K_4M, + TLB_DATA_1G, + TLB_DATA_1G_2M_4M, + + TLB_DATA0_4K, + TLB_DATA0_4M, + TLB_DATA0_2M_4M, + + STLB_4K, + STLB_4K_2M, +} __packed; +static_assert(sizeof(enum _tlb_table_type) =3D=3D 1); + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 57e170ffe3ba..884cd1b1e4ff 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -626,28 +626,6 @@ static unsigned int intel_size_cache(struct cpuinfo_x8= 6 *c, unsigned int size) } #endif =20 -#define TLB_INST_4K 0x01 -#define TLB_INST_4M 0x02 -#define TLB_INST_2M_4M 0x03 - -#define TLB_INST_ALL 0x05 -#define TLB_INST_1G 0x06 - -#define TLB_DATA_4K 0x11 -#define TLB_DATA_4M 0x12 -#define TLB_DATA_2M_4M 0x13 -#define TLB_DATA_4K_4M 0x14 - -#define TLB_DATA_1G 0x16 -#define TLB_DATA_1G_2M_4M 0x17 - -#define TLB_DATA0_4K 0x21 -#define TLB_DATA0_4M 0x22 -#define TLB_DATA0_2M_4M 0x23 - -#define STLB_4K 0x41 -#define STLB_4K_2M 0x42 - /* * All of leaf 0x2's one-byte TLB descriptors implies the same number of * entries for their respective TLB types. The 0x63 descriptor is an @@ -660,7 +638,7 @@ static unsigned int intel_size_cache(struct cpuinfo_x86= *c, unsigned int size) =20 struct _tlb_table { unsigned char descriptor; - char tlb_type; + enum _tlb_table_type type; unsigned int entries; }; =20 @@ -718,11 +696,11 @@ static void intel_tlb_lookup(const unsigned char desc) intel_tlb_table[k].descriptor !=3D 0; k++) ; =20 - if (intel_tlb_table[k].tlb_type =3D=3D 0) + if (intel_tlb_table[k].type =3D=3D 0) return; =20 entries =3D intel_tlb_table[k].entries; - switch (intel_tlb_table[k].tlb_type) { + switch (intel_tlb_table[k].type) { case STLB_4K: tlb_lli_4k =3D max(tlb_lli_4k, entries); tlb_lld_4k =3D max(tlb_lld_4k, entries); --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 69ED7202F64 for ; Tue, 4 Mar 2025 08:53: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=1741078426; cv=none; b=S2d9dXlNnzSHKINrkkNbYGcWf2qMj4z60Vj0WHNbxNbvM0RnBM0yON2kj8g+Pfsb/wqyHM9KF7fz4kCGUbwiX4F2CFs2/rC+ngddlRgf0K0/HOkQ7nAJ1NMWz2KPgvAQlq+4muZsXnR/q7yZEKJcph9xdGQTX1o7SgfxsQIyoGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078426; c=relaxed/simple; bh=jlK56uSiHS9HBiPQ7ODfCHJCe9/AMX6Ji6trtnXXyO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WYBie4d4OEpZqGARlB+PGvcUky3J9aaY+h2BUQpuRe3c9dAJ18gQOXwhJIGo/AbZlKyQ3YysSziIuBzuL03Oo0Fdd16cL/gekqotXpebUliylcciJIZmnGKYzG33aw0Q2gBi5U8NzrHk4DlggaReE0eVJCusL/U/p/1EpCDqAgk= 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=ihgPZ+//; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Frhz47KO; 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="ihgPZ+//"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Frhz47KO" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078424; 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=JlUDYlBqaGiI3XiQxvwaaxz0o8oND0xT5D79MoyB0UQ=; b=ihgPZ+//NFxQQg32Iui3xrYE+mJMMc54Q2gwm8kHqUCkL4zvmNywc+QyANT2OMt+G/vL5l bCpidOsbAd1p62YwktbZL5EktjtKt3lXRIO6r242Ib5mkC7Nim3pn+8aom1ruoIBlvx/rH SqcQ+rCn833VrJwQQwM3tVNgq3TQ2b7lrj3/5QSsDJr6MNPRZv1t0KMK8nScVK9/aYz1q9 +eH+sZuCYFaglVGz2GsjNHQV6k/iH5Xg1e6SjWD3M4Z5Pu+9/0JmHbbq/bXeu5HMyBO+9a ccW80HCgyHb2NxedNh9C+eAfZJ7M29tJPQjIhcQbCUkAjMgQDM01sjEayOkptA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078424; 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=JlUDYlBqaGiI3XiQxvwaaxz0o8oND0xT5D79MoyB0UQ=; b=Frhz47KOn/UINqHzCJL1m45jlK2RZLnPu5LqYPli+xaNkNQsQrlEw9GgqeShlISUCmP7Rx 83JYwpQmvejMkADw== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 30/40] sizes.h: Cover all possible x86 cpu cache sizes Date: Tue, 4 Mar 2025 09:51:41 +0100 Message-ID: <20250304085152.51092-31-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 size macros for 24/192/384 Kilobyes and 3/6/12/18/24 Megabytes. With that, the x86 subsystem can avoid locally defining its own macros for CPU cache sizs. Signed-off-by: Ahmed S. Darwish --- include/linux/sizes.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/sizes.h b/include/linux/sizes.h index c3a00b967d18..49039494076f 100644 --- a/include/linux/sizes.h +++ b/include/linux/sizes.h @@ -23,17 +23,25 @@ #define SZ_4K 0x00001000 #define SZ_8K 0x00002000 #define SZ_16K 0x00004000 +#define SZ_24K 0x00006000 #define SZ_32K 0x00008000 #define SZ_64K 0x00010000 #define SZ_128K 0x00020000 +#define SZ_192K 0x00030000 #define SZ_256K 0x00040000 +#define SZ_384K 0x00060000 #define SZ_512K 0x00080000 =20 #define SZ_1M 0x00100000 #define SZ_2M 0x00200000 +#define SZ_3M 0x00300000 #define SZ_4M 0x00400000 +#define SZ_6M 0x00600000 #define SZ_8M 0x00800000 +#define SZ_12M 0x00c00000 #define SZ_16M 0x01000000 +#define SZ_18M 0x01200000 +#define SZ_24M 0x01800000 #define SZ_32M 0x02000000 #define SZ_64M 0x04000000 #define SZ_128M 0x08000000 --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 D9DC82036F3 for ; Tue, 4 Mar 2025 08:53: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=1741078430; cv=none; b=RWfvE/u3+OyS7J1YyRobVimHS7cIn7Wd6DFvLe/yn95Zr1WuCrzEnzjiGCiWx7hbOwkyGm/fhZQnJurVSZeQqrOzsQ/ciqvYlgAoq8yF8dViQ/nN2NHOBV8WJsTUFNIgnDTrKqmSI1ZDHBw/gCAV0Upvt91mE9rKLUFsXMQzjc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078430; c=relaxed/simple; bh=oPFQEapq4177DyuLUeLSeqnGR2ybc73IYFxKKrFsma0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iWzjWa4TFk/YmFXjTzxau8CiGdUAE4Fcc1AI37YwZIRJ8PFzMf+te+jdFyScf4Yfxc9WOegJg3zfSA/UNUN0FTkK7ZY458YiN046K9tdU9saoW2IVjeYiS9o5QJmd942X4jqe3zajp6GzBa81fIUL33S8Au7Ho3cqt20qhEagPM= 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=U5wmWBn6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5jO3dGDo; 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="U5wmWBn6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5jO3dGDo" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078427; 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=ei7lgP4FOrzwvMljyUCKfUc4/l4GuDQ2Bc0oFPTwHIs=; b=U5wmWBn64O1ud8kCYWsZdMphnxVOsI1OUahanfGE+5b9evMJ00DfYeSFp9V5oh/501OxlL yTvBfhekDZ9vJWOxe3A615ks4U72MHVw5JbxJNL+8i5msHAgtlXhKCyzQCbuaM+6ioeyGc DetYmAbcfKFPFDF2d1sfeWMwiUG+CwwnSve1uIjmfJWLY9LBnPq9wcP8l8pDr2TSmNrgAk gukUKQMEASfIM1+daXnAN0l27R83b9iuvPjNaYheymsPi3TJuJNnTWT23mHc9faDMQChiS ADCR7LdLgc82HW2JGE/W8FFLWLe0uXu6gizau+Dft029ig16fAj6r6hYc9piww== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078427; 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=ei7lgP4FOrzwvMljyUCKfUc4/l4GuDQ2Bc0oFPTwHIs=; b=5jO3dGDoLUFpXS4l6DfwQ5u7kPf3ulJRzfrIQQRS2aGTnolcBDiI7ciVllr8h1XjKcSGvx s2wx8dH+cOPJNuAg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 31/40] x86/cpu: Consolidate CPUID leaf 0x2 tables Date: Tue, 4 Mar 2025 09:51:42 +0100 Message-ID: <20250304085152.51092-32-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" From: Thomas Gleixner CPUID leaf 0x2 describes TLBs and caches. So there are two tables with the respective decriptor constants in intel.c and cacheinfo.c. The tables occupy almost 600 byte and require a loop based lookup for each variant. Combining them into one table occupies exactly 1k rodata and allows to get rid of the loop based lookup by just using the descriptor byte provided by CPUID leaf 0x2 as index into the table, which simplifies the code and reduces text size. The conversion of the intel and cacheinfo code is done separately. [darwi: Actually define struct leaf_0x2_table. Tab-align all of cpuid_0x2_table[] mapping entries. Define needed SZ_* macros at linux/sizes.h instead (parent commit.) Use CACHE_L1_{INST,DATA} as names for L1 cache descriptor types. Set descriptor 0x63 type as TLB_DATA_1G_2M_4M and explain why. Use enums for cache and TLB descriptor types (parent commits.) Start enum types at 1 since type 0 is reserved for unknown descriptors. Ensure that cache and TLB enum type values do not intersect. Add leaf 0x2 table accessor for_each_leaf_0x2_entry() + documentation.] Signed-off-by: Thomas Gleixner Co-developed-by: Ahmed S. Darwish Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 66 ++++++++++++- arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/cpuid_0x2_table.c | 128 ++++++++++++++++++++++++++ 3 files changed, 191 insertions(+), 5 deletions(-) create mode 100644 arch/x86/kernel/cpu/cpuid_0x2_table.c diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 2a4653af2ba2..c23f187060aa 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -10,7 +10,7 @@ =20 /* * CPUID(0x2) parsing helpers - * Check for_each_leaf_0x2_desc() documentation. + * Check for_each_leaf_0x2_entry() documentation. */ =20 struct leaf_0x2_reg { @@ -81,21 +81,32 @@ static inline void get_leaf_0x2_regs(union leaf_0x2_reg= s *regs) /* * Leaf 0x2 1-byte descriptors' cache types * To be used for their mappings at cache_table[] + * + * Start at 1 since type 0 is reserved for HW byte descriptors which are + * not recognized by the kernel; i.e., those without an explicit mapping + * entry at cpuid_0x2_table[]. */ enum _cache_table_type { - CACHE_L1_INST, + CACHE_L1_INST =3D 1, CACHE_L1_DATA, CACHE_L2, - CACHE_L3, + CACHE_L3 + /* Adjust __TLB_TABLE_TYPE_BEGIN before adding more types */ } __packed; static_assert(sizeof(enum _cache_table_type) =3D=3D 1); =20 +/* + * Ensure that leaf 0x2 cache and TLB type values do not intersect, + * since they share the same field at struct cpuid_0x2_table. + */ +#define __TLB_TABLE_TYPE_BEGIN (CACHE_L3 + 1) + /* * Leaf 0x2 1-byte descriptors' TLB types * To be used for their mappings at intel_tlb_table[] */ enum _tlb_table_type { - TLB_INST_4K, + TLB_INST_4K =3D __TLB_TABLE_TYPE_BEGIN, TLB_INST_4M, TLB_INST_2M_4M, TLB_INST_ALL, @@ -116,4 +127,51 @@ enum _tlb_table_type { } __packed; static_assert(sizeof(enum _tlb_table_type) =3D=3D 1); =20 +/* + * Combined table for leaf 0x2 cache and TLB descriptors. + */ +struct leaf_0x2_table { + union { + enum _cache_table_type c_type; + enum _tlb_table_type t_type; + }; + union { + short c_size; + short entries; + }; +}; + +extern const struct leaf_0x2_table cpuid_0x2_table[256]; + +/** + * for_each_leaf_0x2_entry() - Iterator for parsed leaf 0x2 descriptors + * @regs: Leaf 0x2 register output, as returned by get_leaf_0x2_regs() + * @__ptr: u8 pointer, for macro internal use only + * @entry: Pointer to parsed descriptor information for each iteration + * + * Loop over the 1-byte descriptors in the passed leaf 0x2 output registers + * @regs. Provide the parsed information for each descriptor through @ent= ry. + * To handle cache specific descriptors, switch on @entry->c_type. For TLB + * specific descriptors, switch on @entry->t_type. + * + * Example usage for cache descriptors:: + * + * const struct leaf_0x2_table *entry; + * union leaf_0x2_regs regs; + * u8 *ptr; + * + * get_leaf_0x2_regs(®s); + * for_each_leaf_0x2_entry(regs, ptr, entry) { + * switch (entry->c_type) { + * ... + * } + * } + * + */ +#define for_each_leaf_0x2_entry(regs, __ptr, entry) \ + /* Skip the first byte as it is not a descriptor */ \ + for (__ptr =3D &(regs).desc[1], entry =3D &cpuid_0x2_table[*__ptr]; \ + __ptr < &(regs).desc[16]; \ + __ptr++, entry =3D &cpuid_0x2_table[*__ptr]) + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile index 3a39396d422d..1e26179ff18c 100644 --- a/arch/x86/kernel/cpu/Makefile +++ b/arch/x86/kernel/cpu/Makefile @@ -24,7 +24,7 @@ obj-y +=3D rdrand.o obj-y +=3D match.o obj-y +=3D bugs.o obj-y +=3D aperfmperf.o -obj-y +=3D cpuid-deps.o +obj-y +=3D cpuid-deps.o cpuid_0x2_table.o obj-y +=3D umwait.o obj-y +=3D capflags.o powerflags.o =20 diff --git a/arch/x86/kernel/cpu/cpuid_0x2_table.c b/arch/x86/kernel/cpu/cp= uid_0x2_table.c new file mode 100644 index 000000000000..487b87b1acd3 --- /dev/null +++ b/arch/x86/kernel/cpu/cpuid_0x2_table.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include + +#include + +#include "cpu.h" + +#define CACHE_ENTRY(_desc, _type, _size) \ + [_desc] =3D { \ + .c_type =3D (_type), \ + .c_size =3D (_size) / SZ_1K, \ + } + +#define TLB_ENTRY(_desc, _type, _entries) \ + [_desc] =3D { \ + .t_type =3D (_type), \ + .entries =3D (_entries), \ + } + +const struct leaf_0x2_table cpuid_0x2_table[256] =3D { + CACHE_ENTRY(0x06, CACHE_L1_INST, SZ_8K ), /* 4-way set assoc, 32 byte lin= e size */ + CACHE_ENTRY(0x08, CACHE_L1_INST, SZ_16K ), /* 4-way set assoc, 32 byte li= ne size */ + CACHE_ENTRY(0x09, CACHE_L1_INST, SZ_32K ), /* 4-way set assoc, 64 byte li= ne size */ + CACHE_ENTRY(0x0a, CACHE_L1_DATA, SZ_8K ), /* 2 way set assoc, 32 byte lin= e size */ + CACHE_ENTRY(0x0c, CACHE_L1_DATA, SZ_16K ), /* 4-way set assoc, 32 byte li= ne size */ + CACHE_ENTRY(0x0d, CACHE_L1_DATA, SZ_16K ), /* 4-way set assoc, 64 byte li= ne size */ + CACHE_ENTRY(0x0e, CACHE_L1_DATA, SZ_24K ), /* 6-way set assoc, 64 byte li= ne size */ + CACHE_ENTRY(0x21, CACHE_L2, SZ_256K ), /* 8-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x22, CACHE_L3, SZ_512K ), /* 4-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x23, CACHE_L3, SZ_1M ), /* 8-way set assoc, sectored cache,= 64 byte line size */ + CACHE_ENTRY(0x25, CACHE_L3, SZ_2M ), /* 8-way set assoc, sectored cache,= 64 byte line size */ + CACHE_ENTRY(0x29, CACHE_L3, SZ_4M ), /* 8-way set assoc, sectored cache,= 64 byte line size */ + CACHE_ENTRY(0x2c, CACHE_L1_DATA, SZ_32K ), /* 8-way set assoc, 64 byte li= ne size */ + CACHE_ENTRY(0x30, CACHE_L1_INST, SZ_32K ), /* 8-way set assoc, 64 byte li= ne size */ + CACHE_ENTRY(0x39, CACHE_L2, SZ_128K ), /* 4-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x3a, CACHE_L2, SZ_192K ), /* 6-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x3b, CACHE_L2, SZ_128K ), /* 2-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x3c, CACHE_L2, SZ_256K ), /* 4-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x3d, CACHE_L2, SZ_384K ), /* 6-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x3e, CACHE_L2, SZ_512K ), /* 4-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x3f, CACHE_L2, SZ_256K ), /* 2-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x41, CACHE_L2, SZ_128K ), /* 4-way set assoc, 32 byte line = size */ + CACHE_ENTRY(0x42, CACHE_L2, SZ_256K ), /* 4-way set assoc, 32 byte line = size */ + CACHE_ENTRY(0x43, CACHE_L2, SZ_512K ), /* 4-way set assoc, 32 byte line = size */ + CACHE_ENTRY(0x44, CACHE_L2, SZ_1M ), /* 4-way set assoc, 32 byte line si= ze */ + CACHE_ENTRY(0x45, CACHE_L2, SZ_2M ), /* 4-way set assoc, 32 byte line si= ze */ + CACHE_ENTRY(0x46, CACHE_L3, SZ_4M ), /* 4-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0x47, CACHE_L3, SZ_8M ), /* 8-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0x48, CACHE_L2, SZ_3M ), /* 12-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0x49, CACHE_L3, SZ_4M ), /* 16-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0x4a, CACHE_L3, SZ_6M ), /* 12-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0x4b, CACHE_L3, SZ_8M ), /* 16-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0x4c, CACHE_L3, SZ_12M ), /* 12-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x4d, CACHE_L3, SZ_16M ), /* 16-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x4e, CACHE_L2, SZ_6M ), /* 24-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0x60, CACHE_L1_DATA, SZ_16K ), /* 8-way set assoc, sectored c= ache, 64 byte line size */ + CACHE_ENTRY(0x66, CACHE_L1_DATA, SZ_8K ), /* 4-way set assoc, sectored ca= che, 64 byte line size */ + CACHE_ENTRY(0x67, CACHE_L1_DATA, SZ_16K ), /* 4-way set assoc, sectored c= ache, 64 byte line size */ + CACHE_ENTRY(0x68, CACHE_L1_DATA, SZ_32K ), /* 4-way set assoc, sectored c= ache, 64 byte line size */ + CACHE_ENTRY(0x78, CACHE_L2, SZ_1M ), /* 4-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0x79, CACHE_L2, SZ_128K ), /* 8-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x7a, CACHE_L2, SZ_256K ), /* 8-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x7b, CACHE_L2, SZ_512K ), /* 8-way set assoc, sectored cach= e, 64 byte line size */ + CACHE_ENTRY(0x7c, CACHE_L2, SZ_1M ), /* 8-way set assoc, sectored cache,= 64 byte line size */ + CACHE_ENTRY(0x7d, CACHE_L2, SZ_2M ), /* 8-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0x7f, CACHE_L2, SZ_512K ), /* 2-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x80, CACHE_L2, SZ_512K ), /* 8-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x82, CACHE_L2, SZ_256K ), /* 8-way set assoc, 32 byte line = size */ + CACHE_ENTRY(0x83, CACHE_L2, SZ_512K ), /* 8-way set assoc, 32 byte line = size */ + CACHE_ENTRY(0x84, CACHE_L2, SZ_1M ), /* 8-way set assoc, 32 byte line si= ze */ + CACHE_ENTRY(0x85, CACHE_L2, SZ_2M ), /* 8-way set assoc, 32 byte line si= ze */ + CACHE_ENTRY(0x86, CACHE_L2, SZ_512K ), /* 4-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0x87, CACHE_L2, SZ_1M ), /* 8-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0xd0, CACHE_L3, SZ_512K ), /* 4-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0xd1, CACHE_L3, SZ_1M ), /* 4-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0xd2, CACHE_L3, SZ_2M ), /* 4-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0xd6, CACHE_L3, SZ_1M ), /* 8-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0xd7, CACHE_L3, SZ_2M ), /* 8-way set assoc, 64 byte line si= ze */ + CACHE_ENTRY(0xd8, CACHE_L3, SZ_4M ), /* 12-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xdc, CACHE_L3, SZ_2M ), /* 12-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xdd, CACHE_L3, SZ_4M ), /* 12-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xde, CACHE_L3, SZ_8M ), /* 12-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xe2, CACHE_L3, SZ_2M ), /* 16-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xe3, CACHE_L3, SZ_4M ), /* 16-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xe4, CACHE_L3, SZ_8M ), /* 16-way set assoc, 64 byte line s= ize */ + CACHE_ENTRY(0xea, CACHE_L3, SZ_12M ), /* 24-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0xeb, CACHE_L3, SZ_18M ), /* 24-way set assoc, 64 byte line = size */ + CACHE_ENTRY(0xec, CACHE_L3, SZ_24M ), /* 24-way set assoc, 64 byte line = size */ + + TLB_ENTRY( 0x01, TLB_INST_4K, 32 ), /* TLB_INST 4 KByte pages, 4-way se= t associative */ + TLB_ENTRY( 0x02, TLB_INST_4M, 2 ), /* TLB_INST 4 MByte pages, full asso= ciative */ + TLB_ENTRY( 0x03, TLB_DATA_4K, 64 ), /* TLB_DATA 4 KByte pages, 4-way se= t associative */ + TLB_ENTRY( 0x04, TLB_DATA_4M, 8 ), /* TLB_DATA 4 MByte pages, 4-way set= associative */ + TLB_ENTRY( 0x05, TLB_DATA_4M, 32 ), /* TLB_DATA 4 MByte pages, 4-way se= t associative */ + TLB_ENTRY( 0x0b, TLB_INST_4M, 4 ), /* TLB_INST 4 MByte pages, 4-way set= associative */ + TLB_ENTRY( 0x4f, TLB_INST_4K, 32 ), /* TLB_INST 4 KByte pages */ + TLB_ENTRY( 0x50, TLB_INST_ALL, 64 ), /* TLB_INST 4 KByte and 2-MByte or= 4-MByte pages */ + TLB_ENTRY( 0x51, TLB_INST_ALL, 128 ), /* TLB_INST 4 KByte and 2-MByte o= r 4-MByte pages */ + TLB_ENTRY( 0x52, TLB_INST_ALL, 256 ), /* TLB_INST 4 KByte and 2-MByte o= r 4-MByte pages */ + TLB_ENTRY( 0x55, TLB_INST_2M_4M, 7 ), /* TLB_INST 2-MByte or 4-MByte pag= es, fully associative */ + TLB_ENTRY( 0x56, TLB_DATA0_4M, 16 ), /* TLB_DATA0 4 MByte pages, 4-way = set associative */ + TLB_ENTRY( 0x57, TLB_DATA0_4K, 16 ), /* TLB_DATA0 4 KByte pages, 4-way = associative */ + TLB_ENTRY( 0x59, TLB_DATA0_4K, 16 ), /* TLB_DATA0 4 KByte pages, fully = associative */ + TLB_ENTRY( 0x5a, TLB_DATA0_2M_4M, 32 ), /* TLB_DATA0 2-MByte or 4 MByte = pages, 4-way set associative */ + TLB_ENTRY( 0x5b, TLB_DATA_4K_4M, 64 ), /* TLB_DATA 4 KByte and 4 MByte p= ages */ + TLB_ENTRY( 0x5c, TLB_DATA_4K_4M, 128 ), /* TLB_DATA 4 KByte and 4 MByte = pages */ + TLB_ENTRY( 0x5d, TLB_DATA_4K_4M, 256 ), /* TLB_DATA 4 KByte and 4 MByte = pages */ + TLB_ENTRY( 0x61, TLB_INST_4K, 48 ), /* TLB_INST 4 KByte pages, full ass= ociative */ + TLB_ENTRY( 0x63, TLB_DATA_1G_2M_4M, 4 ), /* TLB_DATA 1 GByte pages, 4-wa= y set associative + * (plus 32 entries TLB_DATA 2 MByte or 4 MByte pages, not encoded= here) */ + TLB_ENTRY( 0x6b, TLB_DATA_4K, 256 ), /* TLB_DATA 4 KByte pages, 8-way a= ssociative */ + TLB_ENTRY( 0x6c, TLB_DATA_2M_4M, 128 ), /* TLB_DATA 2 MByte or 4 MByte p= ages, 8-way associative */ + TLB_ENTRY( 0x6d, TLB_DATA_1G, 16 ), /* TLB_DATA 1 GByte pages, fully as= sociative */ + TLB_ENTRY( 0x76, TLB_INST_2M_4M, 8 ), /* TLB_INST 2-MByte or 4-MByte pag= es, fully associative */ + TLB_ENTRY( 0xb0, TLB_INST_4K, 128 ), /* TLB_INST 4 KByte pages, 4-way s= et associative */ + TLB_ENTRY( 0xb1, TLB_INST_2M_4M, 4 ), /* TLB_INST 2M pages, 4-way, 8 ent= ries or 4M pages, 4-way entries */ + TLB_ENTRY( 0xb2, TLB_INST_4K, 64 ), /* TLB_INST 4KByte pages, 4-way set= associative */ + TLB_ENTRY( 0xb3, TLB_DATA_4K, 128 ), /* TLB_DATA 4 KByte pages, 4-way s= et associative */ + TLB_ENTRY( 0xb4, TLB_DATA_4K, 256 ), /* TLB_DATA 4 KByte pages, 4-way a= ssociative */ + TLB_ENTRY( 0xb5, TLB_INST_4K, 64 ), /* TLB_INST 4 KByte pages, 8-way se= t associative */ + TLB_ENTRY( 0xb6, TLB_INST_4K, 128 ), /* TLB_INST 4 KByte pages, 8-way s= et associative */ + TLB_ENTRY( 0xba, TLB_DATA_4K, 64 ), /* TLB_DATA 4 KByte pages, 4-way as= sociative */ + TLB_ENTRY( 0xc0, TLB_DATA_4K_4M, 8 ), /* TLB_DATA 4 KByte and 4 MByte pa= ges, 4-way associative */ + TLB_ENTRY( 0xc1, STLB_4K_2M, 1024 ), /* STLB 4 KByte and 2 MByte pages,= 8-way associative */ + TLB_ENTRY( 0xc2, TLB_DATA_2M_4M, 16 ), /* TLB_DATA 2 MByte/4MByte pages,= 4-way associative */ + TLB_ENTRY( 0xca, STLB_4K, 512 ), /* STLB 4 KByte pages, 4-way associati= ve */ +}; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 1F9DE202F7E for ; Tue, 4 Mar 2025 08:53: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=1741078434; cv=none; b=i6a03GP2B6qYblEFuFuSVds8vF8YZc8gKBRuLcmhYtnXtUb5wMmrzALiNepRrwVM9MONi1BzNFQWPhi2+yEZwgoRL5qjU+ni0TTJjV9S9+E527h78hAbLqJHdq6OcrzV2E4Ufb3qqvztxquId9gPxSg49Ttvh4UU4JYh6MFtJ1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078434; c=relaxed/simple; bh=qH9pO1MVGofP87hYfDwPrt24KGohSH28bABYe1e/QB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oPUGoP+VNwAXD+k2xtAT2l+PWh9SKJa0GpYuFFZxd4XRzSqkSM9FKeH50UzMtbH5pS0uq7elcJqYcWufa79lGuZlcuHi3qPj4sj829BnoD6cNsoEXnjn8YVpjoso0Y7yT2f7P1hNFD85Mq/kxeOF3YGsX1ISaBlKQ5P7c70/a60= 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=BnO202Qc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=CkH7nIGK; 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="BnO202Qc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="CkH7nIGK" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078430; 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=4gAlkSE6329WQpXjBpj3Irc9ltsbxG3eus5BNgEDYJ0=; b=BnO202Qc/qPYswn1gBB8CZK3amid1oZfMo4qEIKN2Noq5W5E25frXpNT6KpBWv0Z/0Dned KN1BvwEL6iYjVdBPfVL4ckMyaEK63uUCvuG+DMUfRh3VEZyrhMn4K6pQ5DiEYoo60Wtw6A EJrE/41erKeke0SVIl7y+yPDeTPLyyshtiwE4rKzw2hGehgc2DftalSi9DK6C0CZhgRpW4 7buR3ZGpEP+4HNNWuP6UVf/ihJQorXRtF/3a3rB12x3EjFKHmd99MshsMuj8r18Ttvp+TL ubtnLDlXbqcUoJIXqlGcCUDta427nk9lvsRy74oNni51IQOiVeg7j9bG/+kDdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078430; 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=4gAlkSE6329WQpXjBpj3Irc9ltsbxG3eus5BNgEDYJ0=; b=CkH7nIGK55O2ckmpiu8jkC92GkINpdfoJYkP/tAx/u7OhQZJkZ30318I7KU7gTqgrldfuz U1ay/Z8RkSDqsQDg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 32/40] x86/cacheinfo: Use consolidated leaf 0x2 descriptor table Date: Tue, 4 Mar 2025 09:51:43 +0100 Message-ID: <20250304085152.51092-33-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 output is a stream of one-byte descriptors, each implying certain details about the CPU's cache and TLB entries. At previous commits, the mapping tables for such descriptors were merged into one consolidated table. The mapping was also transformed into a hash lookup instead of a loop-based lookup for each descriptor. Use the new consolidated table and its hash-based lookup through the for_each_leaf_0x2_tlb_entry() accessor. Remove the old cache-specific mapping, cache_table[], as it is no longer used. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 2 +- arch/x86/kernel/cpu/cacheinfo.c | 114 ++--------------------------- 2 files changed, 9 insertions(+), 107 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index c23f187060aa..4af9f6c32895 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -80,7 +80,7 @@ static inline void get_leaf_0x2_regs(union leaf_0x2_regs = *regs) =20 /* * Leaf 0x2 1-byte descriptors' cache types - * To be used for their mappings at cache_table[] + * To be used for their mappings at cpuid_0x2_table[]. * * Start at 1 since type 0 is reserved for HW byte descriptors which are * not recognized by the kernel; i.e., those without an explicit mapping diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index a7fccbab268d..a1cfb6716272 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -34,90 +34,6 @@ static cpumask_var_t cpu_cacheinfo_mask; /* Kernel controls MTRR and/or PAT MSRs. */ unsigned int memory_caching_control __ro_after_init; =20 -struct _cache_table { - unsigned char descriptor; - enum _cache_table_type type; - short size; -}; - -#define MB(x) ((x) * 1024) - -/* All the cache descriptor types we care about (no TLB or - trace cache entries) */ - -static const struct _cache_table cache_table[] =3D -{ - { 0x06, CACHE_L1_INST, 8 }, /* 4-way set assoc, 32 byte line size */ - { 0x08, CACHE_L1_INST, 16 }, /* 4-way set assoc, 32 byte line size */ - { 0x09, CACHE_L1_INST, 32 }, /* 4-way set assoc, 64 byte line size */ - { 0x0a, CACHE_L1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */ - { 0x0c, CACHE_L1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */ - { 0x0d, CACHE_L1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */ - { 0x0e, CACHE_L1_DATA, 24 }, /* 6-way set assoc, 64 byte line size */ - { 0x21, CACHE_L2, 256 }, /* 8-way set assoc, 64 byte line size */ - { 0x22, CACHE_L3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ - { 0x23, CACHE_L3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x25, CACHE_L3, MB(2) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x29, CACHE_L3, MB(4) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x2c, CACHE_L1_DATA, 32 }, /* 8-way set assoc, 64 byte line size */ - { 0x30, CACHE_L1_INST, 32 }, /* 8-way set assoc, 64 byte line size */ - { 0x39, CACHE_L2, 128 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ - { 0x3a, CACHE_L2, 192 }, /* 6-way set assoc, sectored cache, 64 byte line= size */ - { 0x3b, CACHE_L2, 128 }, /* 2-way set assoc, sectored cache, 64 byte line= size */ - { 0x3c, CACHE_L2, 256 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ - { 0x3d, CACHE_L2, 384 }, /* 6-way set assoc, sectored cache, 64 byte line= size */ - { 0x3e, CACHE_L2, 512 }, /* 4-way set assoc, sectored cache, 64 byte line= size */ - { 0x3f, CACHE_L2, 256 }, /* 2-way set assoc, 64 byte line size */ - { 0x41, CACHE_L2, 128 }, /* 4-way set assoc, 32 byte line size */ - { 0x42, CACHE_L2, 256 }, /* 4-way set assoc, 32 byte line size */ - { 0x43, CACHE_L2, 512 }, /* 4-way set assoc, 32 byte line size */ - { 0x44, CACHE_L2, MB(1) }, /* 4-way set assoc, 32 byte line size */ - { 0x45, CACHE_L2, MB(2) }, /* 4-way set assoc, 32 byte line size */ - { 0x46, CACHE_L3, MB(4) }, /* 4-way set assoc, 64 byte line size */ - { 0x47, CACHE_L3, MB(8) }, /* 8-way set assoc, 64 byte line size */ - { 0x48, CACHE_L2, MB(3) }, /* 12-way set assoc, 64 byte line size */ - { 0x49, CACHE_L3, MB(4) }, /* 16-way set assoc, 64 byte line size */ - { 0x4a, CACHE_L3, MB(6) }, /* 12-way set assoc, 64 byte line size */ - { 0x4b, CACHE_L3, MB(8) }, /* 16-way set assoc, 64 byte line size */ - { 0x4c, CACHE_L3, MB(12) }, /* 12-way set assoc, 64 byte line size */ - { 0x4d, CACHE_L3, MB(16) }, /* 16-way set assoc, 64 byte line size */ - { 0x4e, CACHE_L2, MB(6) }, /* 24-way set assoc, 64 byte line size */ - { 0x60, CACHE_L1_DATA, 16 }, /* 8-way set assoc, sectored cache, 64 byte = line size */ - { 0x66, CACHE_L1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte l= ine size */ - { 0x67, CACHE_L1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte = line size */ - { 0x68, CACHE_L1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte = line size */ - { 0x78, CACHE_L2, MB(1) }, /* 4-way set assoc, 64 byte line size */ - { 0x79, CACHE_L2, 128 }, /* 8-way set assoc, sectored cache, 64 byte line= size */ - { 0x7a, CACHE_L2, 256 }, /* 8-way set assoc, sectored cache, 64 byte line= size */ - { 0x7b, CACHE_L2, 512 }, /* 8-way set assoc, sectored cache, 64 byte line= size */ - { 0x7c, CACHE_L2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte li= ne size */ - { 0x7d, CACHE_L2, MB(2) }, /* 8-way set assoc, 64 byte line size */ - { 0x7f, CACHE_L2, 512 }, /* 2-way set assoc, 64 byte line size */ - { 0x80, CACHE_L2, 512 }, /* 8-way set assoc, 64 byte line size */ - { 0x82, CACHE_L2, 256 }, /* 8-way set assoc, 32 byte line size */ - { 0x83, CACHE_L2, 512 }, /* 8-way set assoc, 32 byte line size */ - { 0x84, CACHE_L2, MB(1) }, /* 8-way set assoc, 32 byte line size */ - { 0x85, CACHE_L2, MB(2) }, /* 8-way set assoc, 32 byte line size */ - { 0x86, CACHE_L2, 512 }, /* 4-way set assoc, 64 byte line size */ - { 0x87, CACHE_L2, MB(1) }, /* 8-way set assoc, 64 byte line size */ - { 0xd0, CACHE_L3, 512 }, /* 4-way set assoc, 64 byte line size */ - { 0xd1, CACHE_L3, MB(1) }, /* 4-way set assoc, 64 byte line size */ - { 0xd2, CACHE_L3, MB(2) }, /* 4-way set assoc, 64 byte line size */ - { 0xd6, CACHE_L3, MB(1) }, /* 8-way set assoc, 64 byte line size */ - { 0xd7, CACHE_L3, MB(2) }, /* 8-way set assoc, 64 byte line size */ - { 0xd8, CACHE_L3, MB(4) }, /* 12-way set assoc, 64 byte line size */ - { 0xdc, CACHE_L3, MB(2) }, /* 12-way set assoc, 64 byte line size */ - { 0xdd, CACHE_L3, MB(4) }, /* 12-way set assoc, 64 byte line size */ - { 0xde, CACHE_L3, MB(8) }, /* 12-way set assoc, 64 byte line size */ - { 0xe2, CACHE_L3, MB(2) }, /* 16-way set assoc, 64 byte line size */ - { 0xe3, CACHE_L3, MB(4) }, /* 16-way set assoc, 64 byte line size */ - { 0xe4, CACHE_L3, MB(8) }, /* 16-way set assoc, 64 byte line size */ - { 0xea, CACHE_L3, MB(12) }, /* 24-way set assoc, 64 byte line size */ - { 0xeb, CACHE_L3, MB(18) }, /* 24-way set assoc, 64 byte line size */ - { 0xec, CACHE_L3, MB(24) }, /* 24-way set assoc, 64 byte line size */ -}; - - enum _cache_type { CTYPE_NULL =3D 0, CTYPE_DATA =3D 1, @@ -436,16 +352,6 @@ void init_hygon_cacheinfo(struct cpuinfo_x86 *c) ci->num_leaves =3D find_num_cache_leaves(c); } =20 -static const struct _cache_table *cache_table_get(u8 desc) -{ - for (int i =3D 0; i < ARRAY_SIZE(cache_table); i++) { - if (cache_table[i].descriptor =3D=3D desc) - return &cache_table[i]; - } - - return NULL; -} - void init_intel_cacheinfo(struct cpuinfo_x86 *c) { /* Cache sizes */ @@ -502,21 +408,17 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) =20 /* Don't use CPUID(2) if CPUID(4) is supported. */ if (!ci->num_leaves && c->cpuid_level > 1) { - const struct _cache_table *entry; + const struct leaf_0x2_table *entry; union leaf_0x2_regs regs; - u8 *desc; + u8 *ptr; =20 get_leaf_0x2_regs(®s); - for_each_leaf_0x2_desc(regs, desc) { - entry =3D cache_table_get(*desc); - if (!entry) - continue; - - switch (entry->type) { - case CACHE_L1_INST: l1i +=3D entry->size; break; - case CACHE_L1_DATA: l1d +=3D entry->size; break; - case CACHE_L2: l2 +=3D entry->size; break; - case CACHE_L3: l3 +=3D entry->size; break; + for_each_leaf_0x2_entry(regs, ptr, entry) { + switch (entry->c_type) { + case CACHE_L1_INST: l1i +=3D entry->c_size; break; + case CACHE_L1_DATA: l1d +=3D entry->c_size; break; + case CACHE_L2: l2 +=3D entry->c_size; break; + case CACHE_L3: l3 +=3D entry->c_size; break; } } } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 3168520371B for ; Tue, 4 Mar 2025 08:53: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=1741078437; cv=none; b=eFyPdinLi/M/r2IvXUq25CvkGawdXTbu5AZAzrWYP8LCHytPK2+c19GnTODKwNC8f0sV+4yf4o2Y7+FBpO3hZ6t9RVh2qRyA4MwrrtidCFOkYH0w+egOcsEfqLMNNaVXj47vraxVupyPiE++nWQjVxWwneRb2BMDVmYkNEBzW+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078437; c=relaxed/simple; bh=0zQX//uZaTbQ+G43xlCyNnsVKI4X2Tyu4fpWEIeU6Qo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LsRQ+iD06YNbdpzghd2cHIDYibba/VRnrqHi83FjL1E6l7clT1FfINHsrrl3SiS0IEip76rQ9VtBuQzN8Mo5diE9ZSjz9ECh9ryvPkDJQL5ThXvzuBjtIEHjqm4CJ4p5VKJaaRVg/PdxC6A5uBkotB8N1oJP+yX+zE4b18a8QwY= 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=UuigqRtC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=86LxOivB; 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="UuigqRtC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="86LxOivB" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078433; 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=ji2mdUGlNKAZDUmAmKs5+fhlOipQyk7HkhBqujVvG2A=; b=UuigqRtCGcG54bu7/+XsHeN3U+JQyWnNSBjjLac3ovYZiXHH0CYdHauBaXUQEf1FXQcH1e oZpteS61LAZXz/r6CADIlPCI3fSxmGCwC3u6s/a/59XhqULKXTw6omL+s4KmlwOFxMTzJT nHwpUFnZ+uEFgt2QJzc/cRO+NlsNMTA22cHzWuW0hHw87Ybmw13waco7DTj7oW1db5Estk Xl9l7Tr9K98Qx0wvfORsUCcbMWh4/be/PRlDcPIG6kwdkZ6LO2x2EZY2u58QA6MyRs6K0J UNVyq/hMqowQ97mN5Yzo4FSQl8DXh3k1ctObND3ZNOHa91Hd7Z/yqqZ3i3Gn6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078433; 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=ji2mdUGlNKAZDUmAmKs5+fhlOipQyk7HkhBqujVvG2A=; b=86LxOivBQvNC4p6RhNH+7Vv/hyqDywBI2Wn5GsKbsuTCBLkpus6qsXU/v3ZAnTPuJUMHEx ok7/T312P500MsAg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 33/40] x86/cpu: Use consolidated leaf 0x2 descriptor table Date: Tue, 4 Mar 2025 09:51:44 +0100 Message-ID: <20250304085152.51092-34-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x2 output is a stream of one-byte descriptors, each implying certain details about the CPU's cache and TLB entries. At previous commits, the mapping tables for such descriptors were merged into one consolidated table. The mapping was also transformed into a hash lookup instead of a loop-based lookup for each descriptor. Use the new consolidated table and its hash-based lookup through the for_each_leaf_0x2_tlb_entry() accessor. Remove the TLB-specific mapping, intel_tlb_table[], as it is now no longer used. Remove the cpuid/types.h macro, for_each_leaf_0x2_desc(), since the converted code was its last user. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 33 ++++-------- arch/x86/kernel/cpu/intel.c | 83 +++--------------------------- 2 files changed, 17 insertions(+), 99 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 4af9f6c32895..4d4ab8fc4758 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -56,28 +56,6 @@ static inline void get_leaf_0x2_regs(union leaf_0x2_regs= *regs) } } =20 -/** - * for_each_leaf_0x2_desc() - Iterator for leaf 0x2 descriptors - * @regs: Leaf 0x2 register output, as returned by get_leaf_0x2_regs() - * @desc: Pointer to the returned descriptor for each iteration - * - * Loop over the 1-byte descriptors in the passed leaf 0x2 output registers - * @regs. Provide each descriptor through @desc. - * - * Sample usage:: - * - * union leaf_0x2_regs regs; - * u8 *desc; - * - * get_leaf_0x2_regs(®s); - * for_each_leaf_0x2_desc(regs, desc) { - * // Handle *desc value - * } - */ -#define for_each_leaf_0x2_desc(regs, desc) \ - /* Skip the first byte as it is not a descriptor */ \ - for (desc =3D &(regs).desc[1]; desc < &(regs).desc[16]; desc++) - /* * Leaf 0x2 1-byte descriptors' cache types * To be used for their mappings at cpuid_0x2_table[]. @@ -103,7 +81,7 @@ static_assert(sizeof(enum _cache_table_type) =3D=3D 1); =20 /* * Leaf 0x2 1-byte descriptors' TLB types - * To be used for their mappings at intel_tlb_table[] + * To be used for their mappings at cpuid_0x2_table[] */ enum _tlb_table_type { TLB_INST_4K =3D __TLB_TABLE_TYPE_BEGIN, @@ -174,4 +152,13 @@ extern const struct leaf_0x2_table cpuid_0x2_table[256= ]; __ptr < &(regs).desc[16]; \ __ptr++, entry =3D &cpuid_0x2_table[*__ptr]) =20 +/* + * All of leaf 0x2's one-byte TLB descriptors implies the same number of e= ntries + * for their respective TLB types. TLB descriptor 0x63 is an exception: it + * implies 4 dTLB entries for 1GB pages and 32 dTLB entries for 2MB or 4MB= pages. + * Encode that descriptor's dTLB entry count for 2MB/4MB pages here, as th= e entry + * count for dTLB 1GB pages is already encoded at the cpuid_0x2_table[]'s = mapping. + */ +#define TLB_0x63_2M_4M_ENTRIES 32 + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 884cd1b1e4ff..76be957196ef 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -626,81 +626,11 @@ static unsigned int intel_size_cache(struct cpuinfo_x= 86 *c, unsigned int size) } #endif =20 -/* - * All of leaf 0x2's one-byte TLB descriptors implies the same number of - * entries for their respective TLB types. The 0x63 descriptor is an - * exception: it implies 4 dTLB entries for 1GB pages 32 dTLB entries - * for 2MB or 4MB pages. Encode descriptor 0x63 dTLB entry count for - * 2MB/4MB pages here, as its count for dTLB 1GB pages is already at the - * intel_tlb_table[] mapping. - */ -#define TLB_0x63_2M_4M_ENTRIES 32 - -struct _tlb_table { - unsigned char descriptor; - enum _tlb_table_type type; - unsigned int entries; -}; - -static const struct _tlb_table intel_tlb_table[] =3D { - { 0x01, TLB_INST_4K, 32}, /* TLB_INST 4 KByte pages, 4-way set associati= ve */ - { 0x02, TLB_INST_4M, 2}, /* TLB_INST 4 MByte pages, full associative */ - { 0x03, TLB_DATA_4K, 64}, /* TLB_DATA 4 KByte pages, 4-way set associati= ve */ - { 0x04, TLB_DATA_4M, 8}, /* TLB_DATA 4 MByte pages, 4-way set associativ= e */ - { 0x05, TLB_DATA_4M, 32}, /* TLB_DATA 4 MByte pages, 4-way set associati= ve */ - { 0x0b, TLB_INST_4M, 4}, /* TLB_INST 4 MByte pages, 4-way set associativ= e */ - { 0x4f, TLB_INST_4K, 32}, /* TLB_INST 4 KByte pages */ - { 0x50, TLB_INST_ALL, 64}, /* TLB_INST 4 KByte and 2-MByte or 4-MByte pa= ges */ - { 0x51, TLB_INST_ALL, 128}, /* TLB_INST 4 KByte and 2-MByte or 4-MByte p= ages */ - { 0x52, TLB_INST_ALL, 256}, /* TLB_INST 4 KByte and 2-MByte or 4-MByte p= ages */ - { 0x55, TLB_INST_2M_4M, 7}, /* TLB_INST 2-MByte or 4-MByte pages, fully = associative */ - { 0x56, TLB_DATA0_4M, 16}, /* TLB_DATA0 4 MByte pages, 4-way set associa= tive */ - { 0x57, TLB_DATA0_4K, 16}, /* TLB_DATA0 4 KByte pages, 4-way associative= */ - { 0x59, TLB_DATA0_4K, 16}, /* TLB_DATA0 4 KByte pages, fully associative= */ - { 0x5a, TLB_DATA0_2M_4M, 32}, /* TLB_DATA0 2-MByte or 4 MByte pages, 4-wa= y set associative */ - { 0x5b, TLB_DATA_4K_4M, 64}, /* TLB_DATA 4 KByte and 4 MByte pages */ - { 0x5c, TLB_DATA_4K_4M, 128}, /* TLB_DATA 4 KByte and 4 MByte pages */ - { 0x5d, TLB_DATA_4K_4M, 256}, /* TLB_DATA 4 KByte and 4 MByte pages */ - { 0x61, TLB_INST_4K, 48}, /* TLB_INST 4 KByte pages, full associative */ - { 0x63, TLB_DATA_1G_2M_4M, 4}, /* TLB_DATA 1 GByte pages, 4-way set assoc= iative - * (plus 32 entries TLB_DATA 2 MByte or 4 MByte pages, not encoded h= ere) */ - { 0x6b, TLB_DATA_4K, 256}, /* TLB_DATA 4 KByte pages, 8-way associative = */ - { 0x6c, TLB_DATA_2M_4M, 128}, /* TLB_DATA 2 MByte or 4 MByte pages, 8-wa= y associative */ - { 0x6d, TLB_DATA_1G, 16}, /* TLB_DATA 1 GByte pages, fully associative */ - { 0x76, TLB_INST_2M_4M, 8}, /* TLB_INST 2-MByte or 4-MByte pages, fully = associative */ - { 0xb0, TLB_INST_4K, 128}, /* TLB_INST 4 KByte pages, 4-way set associat= ive */ - { 0xb1, TLB_INST_2M_4M, 4}, /* TLB_INST 2M pages, 4-way, 8 entries or 4M= pages, 4-way entries */ - { 0xb2, TLB_INST_4K, 64}, /* TLB_INST 4KByte pages, 4-way set associativ= e */ - { 0xb3, TLB_DATA_4K, 128}, /* TLB_DATA 4 KByte pages, 4-way set associat= ive */ - { 0xb4, TLB_DATA_4K, 256}, /* TLB_DATA 4 KByte pages, 4-way associative = */ - { 0xb5, TLB_INST_4K, 64}, /* TLB_INST 4 KByte pages, 8-way set associati= ve */ - { 0xb6, TLB_INST_4K, 128}, /* TLB_INST 4 KByte pages, 8-way set associat= ive */ - { 0xba, TLB_DATA_4K, 64}, /* TLB_DATA 4 KByte pages, 4-way associative */ - { 0xc0, TLB_DATA_4K_4M, 8}, /* TLB_DATA 4 KByte and 4 MByte pages, 4-way= associative */ - { 0xc1, STLB_4K_2M, 1024}, /* STLB 4 KByte and 2 MByte pages, 8-way asso= ciative */ - { 0xc2, TLB_DATA_2M_4M, 16}, /* TLB_DATA 2 MByte/4MByte pages, 4-way ass= ociative */ - { 0xca, STLB_4K, 512}, /* STLB 4 KByte pages, 4-way associative */ - { 0x00, 0, 0 } -}; - -static void intel_tlb_lookup(const unsigned char desc) +static void intel_tlb_lookup(const struct leaf_0x2_table *entry) { - unsigned int entries; - unsigned char k; - - if (desc =3D=3D 0) - return; - - /* look up this descriptor in the table */ - for (k =3D 0; intel_tlb_table[k].descriptor !=3D desc && - intel_tlb_table[k].descriptor !=3D 0; k++) - ; - - if (intel_tlb_table[k].type =3D=3D 0) - return; + short entries =3D entry->entries; =20 - entries =3D intel_tlb_table[k].entries; - switch (intel_tlb_table[k].type) { + switch (entry->t_type) { case STLB_4K: tlb_lli_4k =3D max(tlb_lli_4k, entries); tlb_lld_4k =3D max(tlb_lld_4k, entries); @@ -757,15 +687,16 @@ static void intel_tlb_lookup(const unsigned char desc) =20 static void intel_detect_tlb(struct cpuinfo_x86 *c) { + const struct leaf_0x2_table *entry; union leaf_0x2_regs regs; - u8 *desc; + u8 *ptr; =20 if (c->cpuid_level < 2) return; =20 get_leaf_0x2_regs(®s); - for_each_leaf_0x2_desc(regs, desc) - intel_tlb_lookup(*desc); + for_each_leaf_0x2_entry(regs, ptr, entry) + intel_tlb_lookup(entry); } =20 static const struct cpu_dev intel_cpu_dev =3D { --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 32B39204090 for ; Tue, 4 Mar 2025 08:53: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=1741078440; cv=none; b=drNf8+iP2O4IyT/Y8PJnKVJs0+W6XRm+LeBcZfxjd8xIpz5LdEp7U+XJqHvyxxMKhoF5CJ+TW8LlD1NG63jLZ9QeQPSw3g6z65LDM8sW5siT2SN4AWeuBJ4UO4qRto30d/RNYyFDgyE0imM/uCLxk9YGySXbEeDTwP2NFAIgOYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078440; c=relaxed/simple; bh=usRBZ5LwIE2ZR/AkBDSsd+44ddL8FOK66OoAZpd+kNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UjWmg1w+t0b8Y/rytGasoqsIgx1cenuUZpFm7aXsqZEI/A/1xj9MNZ7svoduGD3iGMnoElp5Wk3oZIK2z02YU2OxUFWi0G+jAwMKBJisS6ZAJVGgKwD+GRcpyvV2CM1q0870LZWNKpCr8lFu3zQhgJPeErjt6vQv5TBIURAbTGg= 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=4vuax3yc; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Uk1KjxNW; 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="4vuax3yc"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Uk1KjxNW" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078436; 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=lOsud2F9JoGdnqFP2WrHPfNLNSK6anqaFLxBys6zcuE=; b=4vuax3yciA8gF8TaUYguqS90FgE9F71dF6PiuKdamAXl0ewEY1vHKjAVl6NJNpyt+auJEu nB8SCYHDXj6IfvfOdJF+IJKnkLey58zmMywCqr0dlYCnIMLeXrHKejo3FE2GASV/oqRYJo NiUCUu60DhlW7zrMPfF4o64UdMtrGF3qKafXM6sfXbi1p+YE7T2jVaBpADnLpRTql+IZGj fM19Nj+ReqCv+A53sEOBbhX3oaKw48UVybVRgSxXfxRJXthmjbLLXevv5nW6b0+I+AwFZN D+CdoIgbwXVGLtiCwhsTCi82Bwg+LIm/AyendOBfJdiuw6zC/YPKdCT8WUy2hQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078436; 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=lOsud2F9JoGdnqFP2WrHPfNLNSK6anqaFLxBys6zcuE=; b=Uk1KjxNWKCJ2KWw5jNsgpR2/Ak2iamhQfOVUx9pRDybgF5LOcG/S9IcWnGDlcIDnIAvDrX 38Mv49R1N8QyuGBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 34/40] x86/cacheinfo: Separate leaf 0x2 handling and post-processing logic Date: Tue, 4 Mar 2025 09:51:45 +0100 Message-ID: <20250304085152.51092-35-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 logic of init_intel_cacheinfo() is quite convoluted: it mixes leaf 0x4 parsing, leaf 0x2 parsing, plus some post-processing, in a single place. Begin simplifying its logic by extracting the leaf 0x2 parsing code, and the post-processing logic, into their own functions. While at it, rework the SMT LLC topology ID comment for clarity. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 106 +++++++++++++++++--------------- 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index a1cfb6716272..a15538d72432 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -352,14 +352,56 @@ void init_hygon_cacheinfo(struct cpuinfo_x86 *c) ci->num_leaves =3D find_num_cache_leaves(c); } =20 -void init_intel_cacheinfo(struct cpuinfo_x86 *c) +static void intel_cacheinfo_done(struct cpuinfo_x86 *c, unsigned int l3, + unsigned int l2, unsigned int l1i, unsigned int l1d) +{ + /* + * If llc_id is still unset, then cpuid_level < 4, which implies + * that the only possibility left is SMT. Since CPUID(2) doesn't + * specify any shared caches and SMT shares all caches, we can + * unconditionally set LLC ID to the package ID so that all + * threads share it. + */ + if (c->topo.llc_id =3D=3D BAD_APICID) + c->topo.llc_id =3D c->topo.pkg_id; + + c->x86_cache_size =3D l3 ? l3 : (l2 ? l2 : l1i + l1d); + + if (!l2) + cpu_detect_cache_sizes(c); +} + +/* + * Legacy Intel CPUID(2) path if CPUID(4) is not available. + */ +static void intel_cacheinfo_0x2(struct cpuinfo_x86 *c) { - /* Cache sizes */ unsigned int l1i =3D 0, l1d =3D 0, l2 =3D 0, l3 =3D 0; - unsigned int new_l1d =3D 0, new_l1i =3D 0; /* Cache sizes from cpuid(4) */ - unsigned int new_l2 =3D 0, new_l3 =3D 0, i; /* Cache sizes from cpuid(4) = */ - unsigned int l2_id =3D 0, l3_id =3D 0, num_threads_sharing, index_msb; + const struct leaf_0x2_table *entry; + union leaf_0x2_regs regs; + u8 *ptr; + + if (c->cpuid_level < 2) + return; + + get_leaf_0x2_regs(®s); + for_each_leaf_0x2_entry(regs, ptr, entry) { + switch (entry->c_type) { + case CACHE_L1_INST: l1i +=3D entry->c_size; break; + case CACHE_L1_DATA: l1d +=3D entry->c_size; break; + case CACHE_L2: l2 +=3D entry->c_size; break; + case CACHE_L3: l3 +=3D entry->c_size; break; + } + } + + intel_cacheinfo_done(c, l3, l2, l1i, l1d); +} + +void init_intel_cacheinfo(struct cpuinfo_x86 *c) +{ struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); + unsigned int l1i =3D 0, l1d =3D 0, l2 =3D 0, l3 =3D 0; + unsigned int l2_id =3D 0, l3_id =3D 0; =20 if (c->cpuid_level > 3) { /* @@ -373,7 +415,8 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) * Whenever possible use cpuid(4), deterministic cache * parameters cpuid leaf to find the cache details */ - for (i =3D 0; i < ci->num_leaves; i++) { + for (int i =3D 0; i < ci->num_leaves; i++) { + unsigned int num_threads_sharing, index_msb; struct _cpuid4_info id4 =3D {}; int retval; =20 @@ -384,18 +427,18 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) switch (id4.eax.split.level) { case 1: if (id4.eax.split.type =3D=3D CTYPE_DATA) - new_l1d =3D id4.size/1024; + l1d =3D id4.size / 1024; else if (id4.eax.split.type =3D=3D CTYPE_INST) - new_l1i =3D id4.size/1024; + l1i =3D id4.size / 1024; break; case 2: - new_l2 =3D id4.size/1024; + l2 =3D id4.size / 1024; num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); l2_id =3D c->topo.apicid & ~((1 << index_msb) - 1); break; case 3: - new_l3 =3D id4.size/1024; + l3 =3D id4.size / 1024; num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; index_msb =3D get_count_order(num_threads_sharing); l3_id =3D c->topo.apicid & ~((1 << index_msb) - 1); @@ -408,52 +451,19 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) =20 /* Don't use CPUID(2) if CPUID(4) is supported. */ if (!ci->num_leaves && c->cpuid_level > 1) { - const struct leaf_0x2_table *entry; - union leaf_0x2_regs regs; - u8 *ptr; - - get_leaf_0x2_regs(®s); - for_each_leaf_0x2_entry(regs, ptr, entry) { - switch (entry->c_type) { - case CACHE_L1_INST: l1i +=3D entry->c_size; break; - case CACHE_L1_DATA: l1d +=3D entry->c_size; break; - case CACHE_L2: l2 +=3D entry->c_size; break; - case CACHE_L3: l3 +=3D entry->c_size; break; - } - } + intel_cacheinfo_0x2(c); + return; } =20 - if (new_l1d) - l1d =3D new_l1d; - - if (new_l1i) - l1i =3D new_l1i; - - if (new_l2) { - l2 =3D new_l2; + if (l2) { c->topo.llc_id =3D l2_id; c->topo.l2c_id =3D l2_id; } =20 - if (new_l3) { - l3 =3D new_l3; + if (l3) c->topo.llc_id =3D l3_id; - } =20 - /* - * If llc_id is not yet set, this means cpuid_level < 4 which in - * turns means that the only possibility is SMT (as indicated in - * cpuid1). Since cpuid2 doesn't specify shared caches, and we know - * that SMT shares all caches, we can unconditionally set cpu_llc_id to - * c->topo.pkg_id. - */ - if (c->topo.llc_id =3D=3D BAD_APICID) - c->topo.llc_id =3D c->topo.pkg_id; - - c->x86_cache_size =3D l3 ? l3 : (l2 ? l2 : (l1i+l1d)); - - if (!l2) - cpu_detect_cache_sizes(c); + intel_cacheinfo_done(c, l3, l2, l1i, l1d); } =20 static int __cache_amd_cpumap_setup(unsigned int cpu, int index, --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 2D385204594 for ; Tue, 4 Mar 2025 08:54: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=1741078442; cv=none; b=uSz2/iWkLOQ2NQUkQIdsi9ag/635Y6/1z9+fQ05puIGgacSgapdoej9sfbk28IBmNYFclBisJXbfRTeXfMNfHx2CwWiZ1JFVVqltMqhZOKZSydI1qyS26vpjceuUDqLSKO67Pam1mww7ucxPVMaWpJoRArY6Gdjw/GUGZdasSys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078442; c=relaxed/simple; bh=6KtrpdC5+NUVHd7Ozqev3oC0KaGm949m8rnOyMqGMxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FkjEehecOU30FVbQ12eqZGFuV3Udga+sJu61LupSQ2/yOsN3Ttf7ey/vQUIDWLzz04BL/bfcjbeQZxjRTVmVEeDMNcFwKN36c01CgobH+C5EOxQOSUhYp0V5fYgFufcTeKaQ7yK+RvRBs0U5qULko+f260NfHhVqpizI2gA4kkU= 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=DZ5a53h3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=BPsyyDHh; 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="DZ5a53h3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="BPsyyDHh" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078439; 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=E2ZqNYsTPYK5LhLfCcaC6wx91oUbqwJeh6/BPfMbMFY=; b=DZ5a53h3uVvt1NaC/ytr4tlwDAigKY03QV2o3r+A8UTu2QEI6JV2K6yFnWDxUqTaFZPtly 3Te7w/Kc9lz/+5VZR8mX10VgogzlnWsZwbXJ8pWOXVyFqK+2GIB4onMKmF71vV9etd4idv pwqiILTPYy7eeAWgips+y73X05Wv+D1yxN/5ynyMNX1iToKdgiTKmUg09/aqNwrMrOf4sl XIr7M9WGu44+SIUqpCLJresX6e8UWg/sN10yt+oWAJ7PeUgmP8/Pk2tkD6pOO2Q3bmk2xV KKaEeFdGnw8w6M+BO+GrlzCR0wO7Di/0su3ZqgpD87jw6nM12hQgZMQ2PFZxdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078439; 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=E2ZqNYsTPYK5LhLfCcaC6wx91oUbqwJeh6/BPfMbMFY=; b=BPsyyDHhRmLpCVM+LApPJ4XTwpzpiaEo38ZZwNiUJg5mKZVPK3Uz5kYgSUvAVEmwkBXbBh R4nGecjtlStBc4CQ== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 35/40] x86/cacheinfo: Separate intel leaf 0x4 handling Date: Tue, 4 Mar 2025 09:51:46 +0100 Message-ID: <20250304085152.51092-36-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" init_intel_cacheinfo() was overly complex. It parsed leaf 0x4 data, leaf 0x2 data, and performed post-processing, all within one function. Parent commit moved leaf 0x2 parsing and the post-processing logic into their own functions. Continue the refactoring by extracting leaf 0x4 parsing into its own function. Initialize local L2/L3 topology ID variables to BAD_APICID by default, thus ensuring they can be used unconditionally. Suggested-by: Thomas Gleixner Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 110 ++++++++++++++++---------------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index a15538d72432..7bd3c33b7f04 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -397,73 +397,71 @@ static void intel_cacheinfo_0x2(struct cpuinfo_x86 *c) intel_cacheinfo_done(c, l3, l2, l1i, l1d); } =20 -void init_intel_cacheinfo(struct cpuinfo_x86 *c) +static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) { struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); - unsigned int l1i =3D 0, l1d =3D 0, l2 =3D 0, l3 =3D 0; - unsigned int l2_id =3D 0, l3_id =3D 0; - - if (c->cpuid_level > 3) { - /* - * There should be at least one leaf. A non-zero value means - * that the number of leaves has been initialized. - */ - if (!ci->num_leaves) - ci->num_leaves =3D find_num_cache_leaves(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 - /* - * Whenever possible use cpuid(4), deterministic cache - * parameters cpuid leaf to find the cache details - */ - for (int i =3D 0; i < ci->num_leaves; i++) { - unsigned int num_threads_sharing, index_msb; - struct _cpuid4_info id4 =3D {}; - int retval; + if (c->cpuid_level < 4) + return false; =20 - retval =3D intel_fill_cpuid4_info(i, &id4); - if (retval < 0) - continue; + /* + * There should be at least one leaf. A non-zero value means + * that the number of leaves has been previously initialized. + */ + if (!ci->num_leaves) + ci->num_leaves =3D find_num_cache_leaves(c); =20 - switch (id4.eax.split.level) { - case 1: - if (id4.eax.split.type =3D=3D CTYPE_DATA) - l1d =3D id4.size / 1024; - else if (id4.eax.split.type =3D=3D CTYPE_INST) - l1i =3D id4.size / 1024; - break; - case 2: - l2 =3D id4.size / 1024; - num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; - index_msb =3D get_count_order(num_threads_sharing); - l2_id =3D c->topo.apicid & ~((1 << index_msb) - 1); - break; - case 3: - l3 =3D id4.size / 1024; - num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; - index_msb =3D get_count_order(num_threads_sharing); - l3_id =3D c->topo.apicid & ~((1 << index_msb) - 1); - break; - default: - break; - } + if (!ci->num_leaves) + return false; + + for (int i =3D 0; i < ci->num_leaves; i++) { + unsigned int num_threads_sharing, index_msb; + struct _cpuid4_info id4 =3D {}; + int ret; + + ret =3D intel_fill_cpuid4_info(i, &id4); + if (ret < 0) + continue; + + switch (id4.eax.split.level) { + case 1: + if (id4.eax.split.type =3D=3D CTYPE_DATA) + l1d =3D id4.size / 1024; + else if (id4.eax.split.type =3D=3D CTYPE_INST) + l1i =3D id4.size / 1024; + break; + case 2: + l2 =3D id4.size / 1024; + num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; + index_msb =3D get_count_order(num_threads_sharing); + l2_id =3D c->topo.apicid & ~((1 << index_msb) - 1); + break; + case 3: + l3 =3D id4.size / 1024; + num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; + index_msb =3D get_count_order(num_threads_sharing); + l3_id =3D c->topo.apicid & ~((1 << index_msb) - 1); + break; + default: + break; } } =20 + c->topo.l2c_id =3D l2_id; + c->topo.llc_id =3D (l3_id =3D=3D BAD_APICID) ? l2_id : l3_id; + intel_cacheinfo_done(c, l3, l2, l1i, l1d); + return true; +} + +void init_intel_cacheinfo(struct cpuinfo_x86 *c) +{ /* Don't use CPUID(2) if CPUID(4) is supported. */ - if (!ci->num_leaves && c->cpuid_level > 1) { - intel_cacheinfo_0x2(c); + if (intel_cacheinfo_0x4(c)) return; - } - - if (l2) { - c->topo.llc_id =3D l2_id; - c->topo.l2c_id =3D l2_id; - } - - if (l3) - c->topo.llc_id =3D l3_id; =20 - intel_cacheinfo_done(c, l3, l2, l1i, l1d); + intel_cacheinfo_0x2(c); } =20 static int __cache_amd_cpumap_setup(unsigned int cpu, int index, --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 258FC20459C for ; Tue, 4 Mar 2025 08:54: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=1741078445; cv=none; b=d0oZZ9JLKTdJ+1FZzuB6yKtmKaA9hXlX8IUOY/kF4VmgJhjaZqihxu0xn1I3Qol4NWGatIQOitFQ/lWTU4zyl7sv0hl9P8wQ97QPgpbfH8rYvTJaDDDeO8Mrf6Njp7HWuiv2iHYtS8wr+Ma5O/304PudzAaldMugydXlNdYdOzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078445; c=relaxed/simple; bh=hFL16DLhDtQtcLZvrMYplDpdu0nW4c2wh0/lfU7dn5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jDmMgPhh/DS5XcN+Nn/YaLyYZDcbWjiXPwNqEDwfEa9n3QgijGi9mSpgiB81H9z3vOXUy0Ylp+/NscvpYVUE0C6xy+HTzDKui909/dNHjvUwhQxXCDexVTd06CYQcbioKSHaV7596xnHjJQed8dN2XJPQ2oFggnKEdHOtCAZaFo= 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=qpUIq/bb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=T/D4696s; 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="qpUIq/bb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="T/D4696s" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078442; 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=3+qVD+HyH5QeO/DmxqVT8U0QebtNRgiqMb5NT91qfgs=; b=qpUIq/bbT5nROtYfKMfI5Elqsu6fbjZl+YstH3OmrEiP2q2ekPb2kT8WfC+flOff9pdDgK rhsWq2nVJt8TS60W9g6kB+LaZgaG6ZMNQEcTMFi5bn9y9if0M0MI5c1lGlXlHF2rNwDDI/ Hi/G/XV+3HOfAW+oPKbaFN8hhH2yIyQT7troqoeELCSqX4LAuGjMN9q+4L5R1KoJOtfcyp fv1Z5Pf0r7Y82gZuTa0MR0ngzGkHvgtRUHncmszUGGqr5D4E/xDKbh0ClJeL3SAqVw1zOZ sHl7Skk7xc6DVuTf3Otcp6iMGARGtU3ZS1yD4F8RBGDe25J8Hnub5EsCFBn7lQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078442; 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=3+qVD+HyH5QeO/DmxqVT8U0QebtNRgiqMb5NT91qfgs=; b=T/D4696sD9by54Ii4nDly0TlQTZ35GZJ5IYZdKnV00Z2slG+VA2DvBKaG5EjJuBwxnS489 xnJB367UTwnrKzBA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 36/40] x86/cacheinfo: Extract out cache level topology ID calculation Date: Tue, 4 Mar 2025 09:51:47 +0100 Message-ID: <20250304085152.51092-37-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 leaf 0x4 parsing, refactor the cache level topology ID calculation code into its own method instead of repeating the same logic twice for L2 and L3. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 7bd3c33b7f04..254c0b2e1d72 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -397,6 +397,16 @@ static void intel_cacheinfo_0x2(struct cpuinfo_x86 *c) intel_cacheinfo_done(c, l3, l2, l1i, l1d); } =20 +static unsigned int calc_cache_topo_id(struct cpuinfo_x86 *c, const struct= _cpuid4_info *id4) +{ + unsigned int num_threads_sharing; + int index_msb; + + num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; + index_msb =3D get_count_order(num_threads_sharing); + return c->topo.apicid & ~((1 << index_msb) - 1); +} + static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) { struct cpu_cacheinfo *ci =3D get_cpu_cacheinfo(c->cpu_index); @@ -417,7 +427,6 @@ static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) return false; =20 for (int i =3D 0; i < ci->num_leaves; i++) { - unsigned int num_threads_sharing, index_msb; struct _cpuid4_info id4 =3D {}; int ret; =20 @@ -434,15 +443,11 @@ static bool intel_cacheinfo_0x4(struct cpuinfo_x86 *c) break; case 2: l2 =3D id4.size / 1024; - num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; - index_msb =3D get_count_order(num_threads_sharing); - l2_id =3D c->topo.apicid & ~((1 << index_msb) - 1); + l2_id =3D calc_cache_topo_id(c, &id4); break; case 3: l3 =3D id4.size / 1024; - num_threads_sharing =3D 1 + id4.eax.split.num_threads_sharing; - index_msb =3D get_count_order(num_threads_sharing); - l3_id =3D c->topo.apicid & ~((1 << index_msb) - 1); + l3_id =3D calc_cache_topo_id(c, &id4); break; default: break; --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 18BBC2046AD for ; Tue, 4 Mar 2025 08:54: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=1741078448; cv=none; b=WvXYaoiodF0pzjiXxaL2sGzlTtzltmg0n7+ec48onUtrC9NrtSjCwag3/ZDrnTKvfLDSxsa1CU8YSRIbStvUop0C9/W8KB9MEt7+o17b+aHxCjP1goNL1jmgSXUE7+yFhE1joEyVbAMZfofjH+0RudCJau0P5kaOCHZawL4OeEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078448; c=relaxed/simple; bh=MFQ9K4KEFPnp5Sq8h4bQJXmn/D4w8oxrBMIEnaUKA6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sUZP7zm4a79PrOTeNQm3ldOeP0uO6+uXsBJfQM1CkFynwC5rwxHD3ExfQaXwgY2cCdcclQ9iRFHjhSV7BguFxlJXtc+/cuHWS/yF0rAw0O7KAmFQwLoHPHdFCxhxZYpmzx2NDO5iIoXpjzGBO5PmKNm+bsdvsZSPY4giuim8Vtc= 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=ApQ9UaMQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1qEHzOaB; 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="ApQ9UaMQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1qEHzOaB" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078445; 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=ETFNrcv3Bk/jQxN/QgQApnOhSop3xoTmaHXe1N70U8A=; b=ApQ9UaMQpKSXI7MLCPVN69MhuzzQjdTXDuI7asL/IEiRx5yFDZEGy/bG2+jWnkQmMUK7Kv tT5yLHAr1hY1QHrp84WnbsxQt2U+e7Gp21e+CeyKmOjX3R+LiWiOadYgVYrBFn16tP65JY A2hRoEmcaqIKFhQezfJaM/8RsxuGhTcmGC23CvFoycIKuzuQH4Or+sQwqrr4nk54MzH0Oz BN4jd6Ss3SoqmPb7hIBJwULiwIsS64sZovygRhIiSPNngwjds5aaBko2rdvmjhnJiW1B84 f0gcS0hle2QrCnqYoBTaqSlzyzdUrtGiP9kGfozmueMgKwqaVIiiu2Ow/t9+CA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078445; 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=ETFNrcv3Bk/jQxN/QgQApnOhSop3xoTmaHXe1N70U8A=; b=1qEHzOaBjYxwFegbJ/Xjp/fpDFex3KgSKgG8JJyXSVLLB0g0v8+qNi95Fm+FG86Ca9bbc+ dxcDtg0l+DOM9uCg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 37/40] x86/cacheinfo: Extract out cache self-snoop checks Date: Tue, 4 Mar 2025 09:51:48 +0100 Message-ID: <20250304085152.51092-38-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 logic of not doing a cache flush if the CPU declares cache self snooping support is repeated across the x86/cacheinfo code. Extract it into its own function. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index 254c0b2e1d72..ac47d1b4f775 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -640,6 +640,17 @@ int populate_cache_leaves(unsigned int cpu) static unsigned long saved_cr4; static DEFINE_RAW_SPINLOCK(cache_disable_lock); =20 +/* + * Cache flushing is the most time-consuming step when programming the + * MTRRs. On many Intel CPUs without known erratas, it can be skipped + * if the CPU declares cache self-snooping support. + */ +static void maybe_flush_caches(void) +{ + if (!static_cpu_has(X86_FEATURE_SELFSNOOP)) + wbinvd(); +} + void cache_disable(void) __acquires(cache_disable_lock) { unsigned long cr0; @@ -657,14 +668,7 @@ void cache_disable(void) __acquires(cache_disable_lock) cr0 =3D read_cr0() | X86_CR0_CD; write_cr0(cr0); =20 - /* - * Cache flushing is the most time-consuming step when programming - * the MTRRs. Fortunately, as per the Intel Software Development - * Manual, we can skip it if the processor supports cache self- - * snooping. - */ - if (!static_cpu_has(X86_FEATURE_SELFSNOOP)) - wbinvd(); + maybe_flush_caches(); =20 /* Save value of CR4 and clear Page Global Enable (bit 7) */ if (cpu_feature_enabled(X86_FEATURE_PGE)) { @@ -679,9 +683,7 @@ void cache_disable(void) __acquires(cache_disable_lock) if (cpu_feature_enabled(X86_FEATURE_MTRR)) mtrr_disable(); =20 - /* Again, only flush caches if we have to. */ - if (!static_cpu_has(X86_FEATURE_SELFSNOOP)) - wbinvd(); + maybe_flush_caches(); } =20 void cache_enable(void) __releases(cache_disable_lock) --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 11548204851 for ; Tue, 4 Mar 2025 08:54: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=1741078451; cv=none; b=WLls+kie+IV1diqfWhK4tarypZGSLNcBDnElIed7xlpGtj5HV5mkH10B/tbxnjvRCKjBZGntuRWHtF/dP1123SCmKkLcwyQ7klnoPpYa3ObQ8S540QfCMGqs5s9n9+57w0lrVQ1ImU6GwDRGjH7dCGEI74NltEXxELgPA/Q/W0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078451; c=relaxed/simple; bh=Zfv62AjRdsZsGNmrKpK4CzHMukrCZSEPzzu5WGKhCeI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XcMbwkt6XdlCuf5LY5DJotxMrCbQbGTtGgV1bliYj+yAW3EJjvONHUz3jxm/gcTopsoXv2ExXg7SDGdVxTFa6aATPi2w3a6r+hQgUInuWzU0hW+oHK3sjAX0O9RYqlqBVmhUzzJW73p3qyBvm80fiBXs8PbNDGDdpK7kwBs3P8U= 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=gfSpJ6NY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=J/tQ3cVZ; 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="gfSpJ6NY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="J/tQ3cVZ" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078448; 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=d/CzymNKQDY6/AWVrKNmDCqqiXY5d+DZjg+XGgnzD6Q=; b=gfSpJ6NYsmu4hge65K3r1z++/mTyULiVPqUT1UEH0rI2JVYXAOOgXurJzWKWj/lh0/ioZ5 0DiIULOoARVQGpHpBOCuPCcUHp8YF6VKjlRgw8vcPXwrVlUE3kd8mDKAzvyJIbGo41IcTt aZUuOYR9JKNcUxWgj8jUXRVMF3h7x3xFJ9jLXoPcUiEFfvw5aNNimE7rBHbSUJ4ci8mQ2k eIBNApkNJP7Gj1cfdlFlnsBSYHv0AySAXg4/f1m7GLFXSpnK8Blp7b+L5xZ0QKcYN1YPpi bFLNuYFqM7Ka6gX87DMqHaNgqH6XVT/BgpXHWVOvaGG1rYKK5wrsiOBHyQP/kw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078448; 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=d/CzymNKQDY6/AWVrKNmDCqqiXY5d+DZjg+XGgnzD6Q=; b=J/tQ3cVZPMDDqKuc7c12APp6cpFPp2WhEH/CXSBVdETXCv7NKr7FHs3Dp29i0UgqMkDqTd HqklWTCTO8LM51BA== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 38/40] x86/cacheinfo: Relocate leaf 0x4 cache_type mapping Date: Tue, 4 Mar 2025 09:51:49 +0100 Message-ID: <20250304085152.51092-39-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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 cache_type_map[] array is used to map Intel leaf 0x4 cache_type values to their corresponding types at linux/cacheinfo.h. Move that array's definition after the actual cpuid leaf 0x4 structures, instead of having it in the middle of AMD leaf 0x4 emulation code. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index ac47d1b4f775..bb934f81dcd1 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -78,6 +78,14 @@ struct _cpuid4_info { unsigned long size; }; =20 +/* Map CPUID(4) EAX.cache_type to linux/cacheinfo.h types */ +static const enum cache_type cache_type_map[] =3D { + [CTYPE_NULL] =3D CACHE_TYPE_NOCACHE, + [CTYPE_DATA] =3D CACHE_TYPE_DATA, + [CTYPE_INST] =3D CACHE_TYPE_INST, + [CTYPE_UNIFIED] =3D CACHE_TYPE_UNIFIED, +}; + /* * Fallback AMD CPUID(4) emulation * AMD CPUs with TOPOEXT can just use CPUID(0x8000001d) @@ -131,13 +139,6 @@ 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 const enum cache_type cache_type_map[] =3D { - [CTYPE_NULL] =3D CACHE_TYPE_NOCACHE, - [CTYPE_DATA] =3D CACHE_TYPE_DATA, - [CTYPE_INST] =3D CACHE_TYPE_INST, - [CTYPE_UNIFIED] =3D CACHE_TYPE_UNIFIED, -}; - static void legacy_amd_cpuid4(int index, union _cpuid4_leaf_eax *eax, union _cpuid4_leaf_ebx *ebx, union _cpuid4_leaf_ecx *ecx) { --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 6CFE4204C02 for ; Tue, 4 Mar 2025 08:54: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=1741078455; cv=none; b=GBSRErnbbvMx5hDN7CT8LLClcHbtc5Kp78e5O0sgYXBe8iuLgXR72YGNmi3+7xZE6CGbq+CTL1IpzOmgQMs8lQxGbt4gbfnmrGCG24SWGJqk3M+7WBrUvyW66OZ/SOHotlalGf/jCNv+53w0sKJADO6Pw3nCVztLp2ul4StiiKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078455; c=relaxed/simple; bh=hp6m0qQToWqUG9NcPNoxQ1ym2SFqOwUzAbH23TCilr0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V+CGViOJfHrq857YoGIoOeiIvoc4g+S+s0qPbantTxcm1FoIRF0RdPK10G03L5RlM9ww+P2fW+fUvOYwbhvYqRY20gfoRrSBgHm72NEmkUdUkitLegKWEVFIiMWDaxXmX3aYTYJIi6hMk9C16eEy9FiNAHXj0sFaw3YQBl5nn74= 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=Al11Xq5M; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8yo/IeCa; 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="Al11Xq5M"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8yo/IeCa" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078451; 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=28eD/vgFI5SHsIs8fRQvhuQI5yGryhWDyE2/9tAGKwg=; b=Al11Xq5M6hpj4/9q6SH8n+S8j6mzU2ME8p4BhVlLmfskgmpQIphhR2qLMvytKvssjJSLpB sb8mSptKNUTs5sWbdyqLh1zyHMKkkKNP3fym06OgcKLbtWb9qMKvknKQr9/CC3Kq8XxKsa b3G+xtUNDo2RwLFbE4GrlrSrnYJmas6N+mheAkC6IGib86Em6VsgAsKErcJ0GKKag85uD0 Eu8VK+J1qgJN72zUMRqtCgunDxxacX9QEmwfTeszEzulZTb3g3YCi5TzjBOt7gDc+53ALu bqoTmDrQwXKDjOWiyrhdoTSjwt0loYzJTbSNZLluKZMtqssEC8F/G7vtL32ksw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078451; 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=28eD/vgFI5SHsIs8fRQvhuQI5yGryhWDyE2/9tAGKwg=; b=8yo/IeCan+8dSIaPVs4XU/4PFGezSdmgc+4Z2VTsLmxlNrXrIEzFwkit4p4ubmfL4DzkwP I39k2975W+DOh7Dg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 39/40] x86/cacheinfo: Introduce amd_hygon_cpu_has_l3_cache() Date: Tue, 4 Mar 2025 09:51:50 +0100 Message-ID: <20250304085152.51092-40-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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" Multiple code paths at cacheinfo.c and amd_nb.c check for AMD/Hygon CPUs L3 cache presensce by directly checking leaf 0x80000006 EDX output. Extract that logic into its own function. While at it, rework the AMD/Hygon LLC topology ID caclculation comments for clarity. Signed-off-by: Ahmed S. Darwish --- arch/x86/include/asm/cpuid/types.h | 9 +++++++++ arch/x86/kernel/amd_nb.c | 7 +++---- arch/x86/kernel/cpu/cacheinfo.c | 32 +++++++++++++----------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index 4d4ab8fc4758..a01cea960ea0 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -161,4 +161,13 @@ extern const struct leaf_0x2_table cpuid_0x2_table[256= ]; */ #define TLB_0x63_2M_4M_ENTRIES 32 =20 +/* + * CPUID(0x80000006) parsing helpers + */ + +static inline bool amd_hygon_cpu_has_l3_cache(void) +{ + return cpuid_edx(0x80000006); +} + #endif /* _ASM_X86_CPUID_TYPES_H */ diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c index bac8d3b6f12b..e73697cefa16 100644 --- a/arch/x86/kernel/amd_nb.c +++ b/arch/x86/kernel/amd_nb.c @@ -13,7 +13,9 @@ #include #include #include + #include +#include =20 static u32 *flush_words; =20 @@ -92,10 +94,7 @@ static int amd_cache_northbridges(void) if (amd_gart_present()) amd_northbridges.flags |=3D AMD_NB_GART; =20 - /* - * Check for L3 cache presence. - */ - if (!cpuid_edx(0x80000006)) + if (!amd_hygon_cpu_has_l3_cache()) return 0; =20 /* diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index bb934f81dcd1..f85a3ddfc3cc 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -278,29 +278,29 @@ static int find_num_cache_leaves(struct cpuinfo_x86 *= c) return i; } =20 +/* + * AMD/Hygon CPUs may have multiple LLCs if L3 caches exist. + */ + void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) { - /* - * We may have multiple LLCs if L3 caches exist, so check if we - * have an L3 cache by looking at the L3 cache CPUID leaf. - */ - if (!cpuid_edx(0x80000006)) + if (!amd_hygon_cpu_has_l3_cache()) return; =20 if (c->x86 < 0x17) { - /* LLC is at the node level. */ + /* Pre-Zen: LLC is at the node level */ c->topo.llc_id =3D die_id; } else if (c->x86 =3D=3D 0x17 && c->x86_model <=3D 0x1F) { /* - * LLC is at the core complex level. - * Core complex ID is ApicId[3] for these processors. + * Family 17h up to 1F models: LLC is at the core + * complex level. Core complex ID is ApicId[3]. */ c->topo.llc_id =3D c->topo.apicid >> 3; } else { /* - * LLC ID is calculated from the number of threads sharing the - * cache. - * */ + * Newer families: LLC ID is calculated from the number + * of threads sharing the L3 cache. + */ u32 eax, ebx, ecx, edx, num_sharing_cache =3D 0; u32 llc_index =3D find_num_cache_leaves(c) - 1; =20 @@ -318,16 +318,12 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c,= u16 die_id) =20 void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) { - /* - * We may have multiple LLCs if L3 caches exist, so check if we - * have an L3 cache by looking at the L3 cache CPUID leaf. - */ - if (!cpuid_edx(0x80000006)) + if (!amd_hygon_cpu_has_l3_cache()) return; =20 /* - * LLC is at the core complex level. - * Core complex ID is ApicId[3] for these processors. + * Hygons are similar to AMD Family 17h up to 1F models: LLC is + * at the core complex level. Core complex ID is ApicId[3]. */ c->topo.llc_id =3D c->topo.apicid >> 3; } --=20 2.48.1 From nobody Wed Apr 1 19:57:18 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 0F843204C1A for ; Tue, 4 Mar 2025 08:54: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=1741078458; cv=none; b=q+2JnMsMTvWigf00SUlSwyTS1IkDMVU8OrHEX41BNl38/zfvKgyzAPUaynhMtKXVQiyBiZw198EycMzuqjO2ZISGHn+gyGXtTTG59hAK3foVYeBCmA3g712vcEyzdgE8cLTrF31C6tl7goG6Vz2xvmGwuTRCRqsPSSPXsdApINY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741078458; c=relaxed/simple; bh=zZ1dBTqXrk1OPcXjt472gj9mzp1dgvIBERwFFI/Ke9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gYf+7NMJTFDzWEzaEzHBUoUZkwLSVN7yZck+HcbHR4nP67jwJgYd9jQ7ly+ENJ7GHkzJ+/RFxHcrSkfJmpCbbVLFYHqwkAgi6VJjAsNYvjwdUAufs1u7p2fVk44WEJ8VMJOqZU/s84/eFYcv6kOnA+hv/uaOK8rI7uPyG/mBO7w= 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=3ej8pk35; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=h4Q2t1jN; 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="3ej8pk35"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="h4Q2t1jN" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1741078454; 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=QBz1+1h+KWyvmRpci0P58qwsHMdAY/seRJeS39TUBUU=; b=3ej8pk35KP/ZIXi2bCqjxNMhZKBb7M+EgCCGBfv0uaGMe8eFlRMT7NkQAkvtqYgKx60bc0 ZUm6sjCsMJdHGF9U2+TlBHFQIg9pfpZHD0MsU+9sHQgY1BFGegOIXy+heSQDahFnqn1D/f pBAHR++x1280OJWJa+KKJPsfLt/WoMClhY2AsrwPrX9Hjq9/+M6laZ0gz/9oKWWN8lPOfu cXklS+qFkJuJMamhGgPKstpUgElPm2wJ06q/BDaU4HV6ckHSzAora3pwjKv+kSQN5MjSXD 9trKhif05U3ucgmJ7cWi5l+sOQGjPygytfWc2gCJ2Qg/1JCK9d8pMLPzhNv0UA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1741078454; 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=QBz1+1h+KWyvmRpci0P58qwsHMdAY/seRJeS39TUBUU=; b=h4Q2t1jNqWh28i//pz02CSEsFgAks2opOYeFnzYHfnjwOVzWHiPEVeqRLIM7LI8mOzhc1I 6ZMHPL7FaN1jAHAg== To: Borislav Petkov , Ingo Molnar , Dave Hansen Cc: Thomas Gleixner , John Ogness , "H. Peter Anvin" , Andrew Cooper , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v1 40/40] x86/cacheinfo: Apply maintainer-tip coding style fixes Date: Tue, 4 Mar 2025 09:51:51 +0100 Message-ID: <20250304085152.51092-41-darwi@linutronix.de> In-Reply-To: <20250304085152.51092-1-darwi@linutronix.de> References: <20250304085152.51092-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/cacheinfo code has been heavily refactored and fleshed out at parent commits, where any necessary coding style fixes were also done in place. Apply maintainer-tip.rst coding style fixes to the rest of the code, and align its assignment expressions for readability. At cacheinfo_amd_init_llc_id(), rename variable msb to index_msb as this is how it's called at the rest of cacheinfo.c code. Signed-off-by: Ahmed S. Darwish --- arch/x86/kernel/cpu/cacheinfo.c | 214 ++++++++++++++++---------------- 1 file changed, 108 insertions(+), 106 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinf= o.c index f85a3ddfc3cc..a2359590dde7 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -1,11 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Routines to identify caches on Intel CPU. + * x86 CPU caches detection and configuration * - * Changes: - * Venkatesh Pallipadi : Adding cache identification through cpuid(4) - * Ashok Raj : Work with CPU hotplug infrastructure. - * Andi Kleen / Andreas Herrmann : CPUID4 emulation on AMD. + * Previous changes + * - Venkatesh Pallipadi: Cache identification through CPUID(4) + * - Ashok Raj : Work with CPU hotplug infrastructure + * - Andi Kleen / Andreas Herrmann: CPUID(4) emulation on AMD */ =20 #include @@ -35,37 +35,37 @@ static cpumask_var_t cpu_cacheinfo_mask; unsigned int memory_caching_control __ro_after_init; =20 enum _cache_type { - CTYPE_NULL =3D 0, - CTYPE_DATA =3D 1, - CTYPE_INST =3D 2, - CTYPE_UNIFIED =3D 3 + CTYPE_NULL =3D 0, + CTYPE_DATA =3D 1, + CTYPE_INST =3D 2, + 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; + 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; }; =20 union _cpuid4_leaf_ebx { struct { - unsigned int coherency_line_size:12; - unsigned int physical_line_partition:10; - unsigned int ways_of_associativity:10; + unsigned int coherency_line_size :12; + unsigned int physical_line_partition :10; + unsigned int ways_of_associativity :10; } split; u32 full; }; =20 union _cpuid4_leaf_ecx { struct { - unsigned int number_of_sets:32; + unsigned int number_of_sets :32; } split; u32 full; }; @@ -93,60 +93,59 @@ static const enum cache_type cache_type_map[] =3D { =20 union l1_cache { struct { - unsigned line_size:8; - unsigned lines_per_tag:8; - unsigned assoc:8; - unsigned size_in_kb:8; + unsigned line_size :8; + unsigned lines_per_tag :8; + unsigned assoc :8; + unsigned size_in_kb :8; }; - unsigned val; + unsigned int val; }; =20 union l2_cache { struct { - unsigned line_size:8; - unsigned lines_per_tag:4; - unsigned assoc:4; - unsigned size_in_kb:16; + unsigned line_size :8; + unsigned lines_per_tag :4; + unsigned assoc :4; + unsigned size_in_kb :16; }; - unsigned val; + unsigned int val; }; =20 union l3_cache { struct { - unsigned line_size:8; - unsigned lines_per_tag:4; - unsigned assoc:4; - unsigned res:2; - unsigned size_encoded:14; + unsigned line_size :8; + unsigned lines_per_tag :4; + unsigned assoc :4; + unsigned res :2; + unsigned size_encoded :14; }; - unsigned val; + unsigned int val; }; =20 static const unsigned short assocs[] =3D { - [1] =3D 1, - [2] =3D 2, - [4] =3D 4, - [6] =3D 8, - [8] =3D 16, - [0xa] =3D 32, - [0xb] =3D 48, - [0xc] =3D 64, - [0xd] =3D 96, - [0xe] =3D 128, - [0xf] =3D 0xffff /* fully associative - no way to show this currently */ + [1] =3D 1, + [2] =3D 2, + [4] =3D 4, + [6] =3D 8, + [8] =3D 16, + [0xa] =3D 32, + [0xb] =3D 48, + [0xc] =3D 64, + [0xd] =3D 96, + [0xe] =3D 128, + [0xf] =3D 0xffff /* Fully associative */ }; =20 static const unsigned char levels[] =3D { 1, 1, 2, 3 }; -static const unsigned char types[] =3D { 1, 2, 3, 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) { unsigned int dummy, line_size, lines_per_tag, assoc, size_in_kb; - union l1_cache l1i, l1d; + union l1_cache l1i, l1d, *l1; union l2_cache l2; union l3_cache l3; - union l1_cache *l1 =3D &l1d; =20 eax->full =3D 0; ebx->full =3D 0; @@ -155,6 +154,7 @@ static void legacy_amd_cpuid4(int index, union _cpuid4_= leaf_eax *eax, cpuid(0x80000005, &dummy, &dummy, &l1d.val, &l1i.val); cpuid(0x80000006, &dummy, &dummy, &l2.val, &l3.val); =20 + l1 =3D &l1d; switch (index) { case 1: l1 =3D &l1i; @@ -162,48 +162,52 @@ static void legacy_amd_cpuid4(int index, union _cpuid= 4_leaf_eax *eax, case 0: if (!l1->val) return; - assoc =3D assocs[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 assocs[l1->assoc]; + line_size =3D l1->line_size; + lines_per_tag =3D l1->lines_per_tag; + size_in_kb =3D l1->size_in_kb; break; case 2: if (!l2.val) return; - assoc =3D assocs[l2.assoc]; - line_size =3D l2.line_size; - lines_per_tag =3D l2.lines_per_tag; - /* cpu_data has errata corrections for K7 applied */ - size_in_kb =3D __this_cpu_read(cpu_info.x86_cache_size); + + /* 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; + size_in_kb =3D __this_cpu_read(cpu_info.x86_cache_size); break; case 3: if (!l3.val) return; - 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[l3.assoc]; + line_size =3D l3.line_size; + lines_per_tag =3D l3.lines_per_tag; + size_in_kb =3D l3.size_encoded * 512; if (boot_cpu_has(X86_FEATURE_AMD_DCM)) { - size_in_kb =3D size_in_kb >> 1; - assoc =3D assoc >> 1; + size_in_kb =3D size_in_kb >> 1; + assoc =3D assoc >> 1; } break; default: 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(); + 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(); =20 if (assoc =3D=3D 0xffff) eax->split.is_fully_associative =3D 1; - 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.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; } =20 @@ -260,18 +264,14 @@ static int fill_cpuid4_info(int index, struct _cpuid4= _info *id4) =20 static int find_num_cache_leaves(struct cpuinfo_x86 *c) { - unsigned int eax, ebx, ecx, edx, op; - union _cpuid4_leaf_eax cache_eax; - int i =3D -1; - - if (x86_vendor_amd_or_hygon(c->x86_vendor)) - op =3D 0x8000001d; - else - op =3D 4; + unsigned int eax, ebx, ecx, edx, op; + union _cpuid4_leaf_eax cache_eax; + int i =3D -1; =20 + /* Do a CPUID(op) loop to calculate num_cache_leaves */ + op =3D x86_vendor_amd_or_hygon(c->x86_vendor) ? 0x8000001d : 4; do { ++i; - /* Do cpuid(op) loop to find out num_cache_leaves */ cpuid_count(op, i, &eax, &ebx, &ecx, &edx); cache_eax.full =3D eax; } while (cache_eax.split.type !=3D CTYPE_NULL); @@ -309,9 +309,9 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u= 16 die_id) num_sharing_cache =3D ((eax >> 14) & 0xfff) + 1; =20 if (num_sharing_cache) { - int bits =3D get_count_order(num_sharing_cache); + int index_msb =3D get_count_order(num_sharing_cache); =20 - c->topo.llc_id =3D c->topo.apicid >> bits; + c->topo.llc_id =3D c->topo.apicid >> index_msb; } } } @@ -332,14 +332,10 @@ 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)) { + if (boot_cpu_has(X86_FEATURE_TOPOEXT)) ci->num_leaves =3D find_num_cache_leaves(c); - } else if (c->extended_cpuid_level >=3D 0x80000006) { - if (cpuid_edx(0x80000006) & 0xf000) - ci->num_leaves =3D 4; - else - ci->num_leaves =3D 3; - } + else if (c->extended_cpuid_level >=3D 0x80000006) + ci->num_leaves =3D (cpuid_edx(0x80000006) & 0xf000) ? 4 : 3; } =20 void init_hygon_cacheinfo(struct cpuinfo_x86 *c) @@ -466,6 +462,9 @@ void init_intel_cacheinfo(struct cpuinfo_x86 *c) intel_cacheinfo_0x2(c); } =20 +/* + * linux/cacheinfo.h shared_cpu_map setup, AMD/Hygon + */ static int __cache_amd_cpumap_setup(unsigned int cpu, int index, const struct _cpuid4_info *id4) { @@ -482,12 +481,12 @@ static int __cache_amd_cpumap_setup(unsigned int cpu,= int index, this_cpu_ci =3D get_cpu_cacheinfo(i); if (!this_cpu_ci->info_list) continue; + ci =3D this_cpu_ci->info_list + index; for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) { if (!cpu_online(sibling)) continue; - cpumask_set_cpu(sibling, - &ci->shared_cpu_map); + cpumask_set_cpu(sibling, &ci->shared_cpu_map); } } } else if (boot_cpu_has(X86_FEATURE_TOPOEXT)) { @@ -513,8 +512,7 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, i= nt index, apicid =3D cpu_data(sibling).topo.apicid; if ((apicid < first) || (apicid > last)) continue; - cpumask_set_cpu(sibling, - &ci->shared_cpu_map); + cpumask_set_cpu(sibling, &ci->shared_cpu_map); } } } else @@ -523,18 +521,22 @@ static int __cache_amd_cpumap_setup(unsigned int cpu,= int index, return 1; } =20 +/* + * linux/cacheinfo.h shared_cpu_map setup, Intel + fallback AMD/Hygon + */ static void __cache_cpumap_setup(unsigned int cpu, int index, const struct _cpuid4_info *id4) { struct cpu_cacheinfo *this_cpu_ci =3D get_cpu_cacheinfo(cpu); + struct cpuinfo_x86 *c =3D &cpu_data(cpu); struct cacheinfo *ci, *sibling_ci; unsigned long num_threads_sharing; int index_msb, i; - struct cpuinfo_x86 *c =3D &cpu_data(cpu); =20 - if (x86_vendor_amd_or_hygon(c->x86_vendor)) + if (x86_vendor_amd_or_hygon(c->x86_vendor)) { if (__cache_amd_cpumap_setup(cpu, index, id4)) return; + } =20 ci =3D this_cpu_ci->info_list + index; num_threads_sharing =3D 1 + id4->eax.split.num_threads_sharing; @@ -549,8 +551,10 @@ static void __cache_cpumap_setup(unsigned int cpu, int= index, if (cpu_data(i).topo.apicid >> index_msb =3D=3D c->topo.apicid >> index_= msb) { struct cpu_cacheinfo *sib_cpu_ci =3D get_cpu_cacheinfo(i); =20 + /* Skip if itself or no cacheinfo */ if (i =3D=3D cpu || !sib_cpu_ci->info_list) - continue;/* skip if itself or no cacheinfo */ + continue; + sibling_ci =3D sib_cpu_ci->info_list + index; cpumask_set_cpu(i, &ci->shared_cpu_map); cpumask_set_cpu(cpu, &sibling_ci->shared_cpu_map); @@ -584,7 +588,7 @@ int init_cache_level(unsigned int cpu) } =20 /* - * The max shared threads number comes from CPUID.4:EAX[25-14] with input + * The max shared threads number comes from CPUID(4) EAX[25-14] with input * ECX as cache index. Then right shift apicid by the number's order to get * cache id for this cache node. */ @@ -620,8 +624,8 @@ int populate_cache_leaves(unsigned int cpu) ci_info_init(ci++, &id4, nb); __cache_cpumap_setup(cpu, idx, &id4); } - this_cpu_ci->cpu_map_populated =3D true; =20 + this_cpu_ci->cpu_map_populated =3D true; return 0; } =20 @@ -653,12 +657,10 @@ void cache_disable(void) __acquires(cache_disable_loc= k) unsigned long cr0; =20 /* - * Note that this is not ideal - * since the cache is only flushed/disabled for this CPU while the - * MTRRs are changed, but changing this requires more invasive - * changes to the way the kernel boots + * This is not ideal since the cache is only flushed/disabled + * for this CPU while the MTRRs are changed, but changing this + * requires more invasive changes to the way the kernel boots. */ - raw_spin_lock(&cache_disable_lock); =20 /* Enter the no-fill (CD=3D1, NW=3D0) cache mode and flush caches. */ --=20 2.48.1