From nobody Wed Dec 17 15:43:06 2025 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 60847204C17 for ; Mon, 17 Mar 2025 16:53: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=1742230411; cv=none; b=GsevwiTp/dtmMcasBpHI6yzEpNw+/2wwtwmUwt64W2QVe1d9YUR2liuCi2SPRXa+L5BXNl6CUSbyHRhggKpvbf87L35vfO9YwLmYbu6L2Wm9Wh5N4o54uqs3Px00voOhNneHg8Ybr0fW3BRyAXO/357S6+d56bL5Pr+nIBD5SP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742230411; c=relaxed/simple; bh=Ov55wJG3wWXFMOwRiEGGppPVkQD1V+AnG6DXjOTj5MQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h2PzDWp9NDrj3UtJryo4oQA4t5ZowOopoveiyKNeb+htO8UKuDX4BQ/PFIA6SZnBeQFyBW3jNIY6GatYmYXQM3WtB6xMjTiPSgCr2huY6W4r6mVOuz13MNESjEuFIAU2uODwuCCA32GVd5NIcoHV8W7T7Ac3swV8nwChcGxyDyk= 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=yhA4vqJ/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=A+yo5uj3; 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="yhA4vqJ/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="A+yo5uj3" From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742230408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=berqG2fpKlMsNlGfVcaW8VLOHN9lCWfZiqDuAfHkeEc=; b=yhA4vqJ/amhenOR77sNQNJAs1QXv44PvwKzL+fQfI7FXiuM/ZgxH4PviZ6x/SLboST48Df RzspOoDXBYpYbSdSjJLI45r1KiPMZchjBX1jmYVqFeJS7nFtEZRQMrDq1KC1PHZhHBvQE/ 7VIrkGCvagLKOPFILf8HcIWUIvDcQfgHEoUf1CQRz9edU8R5R5S5xy/smGTQUo55/OqxFc QORRE4h7UvRmreZODnLSeJhe0MNZKtoR9a2CcjYxcdPw5p9uE3KH4K0auaPjxMB/Clw2qe CFXXJ/xEFtCyq//hm+i0sGFRLVp491odCvUTn8o1OZmP1Kct1zccY4iTxhGtiw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742230408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=berqG2fpKlMsNlGfVcaW8VLOHN9lCWfZiqDuAfHkeEc=; b=A+yo5uj3VjgtavtSvC2i27TL5nEIS5CdbgWPrANIqIOJKkO/NsRC2//MJICgQpU5rey1zi 9oRoL0uzFJnXKMBw== To: Ingo Molnar , Dave Hansen , Borislav Petkov Cc: Thomas Gleixner , Andrew Cooper , "H. Peter Anvin" , John Ogness , x86@kernel.org, x86-cpuid@lists.linux.dev, LKML , "Ahmed S. Darwish" Subject: [PATCH v2 19/29] x86/cpu: Use enums for TLB descriptor types Date: Mon, 17 Mar 2025 17:47:35 +0100 Message-ID: <20250317164745.4754-20-darwi@linutronix.de> In-Reply-To: <20250317164745.4754-1-darwi@linutronix.de> References: <20250317164745.4754-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 | 29 +++++++++++++++++++++++++++++ arch/x86/kernel/cpu/intel.c | 28 +++------------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpui= d/types.h index a66192f9df4c..39b6577987bf 100644 --- a/arch/x86/include/asm/cpuid/types.h +++ b/arch/x86/include/asm/cpuid/types.h @@ -55,4 +55,33 @@ 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[] + * + * 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. + */ +enum _tlb_table_type { + TLB_INST_4K =3D 1, + 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 bf735cee9e76..fbdc91bd1da6 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -627,28 +627,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 @@ -661,7 +639,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 @@ -719,11 +697,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