mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Ahmed S. Darwish" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Ahmed S. Darwish" <darwi@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/cpu] x86/cpu: Use enums for TLB descriptor types
Date: Tue, 25 Mar 2025 09:36:22 -0000	[thread overview]
Message-ID: <174289538275.14745.15529363240425062884.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20250324133324.23458-20-darwi@linutronix.de>

The following commit has been merged into the x86/cpu branch of tip:

Commit-ID:     543904cdfe1eb53ff4267f561a4d59cb1fe6ceb7
Gitweb:        https://git.kernel.org/tip/543904cdfe1eb53ff4267f561a4d59cb1fe6ceb7
Author:        Ahmed S. Darwish <darwi@linutronix.de>
AuthorDate:    Mon, 24 Mar 2025 14:33:14 +01:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 25 Mar 2025 10:23:00 +01:00

x86/cpu: Use enums for TLB descriptor types

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.

Use a __CHECKER__ guard for the static_assert(sizeof(enum) == 1) line as
sparse ignores the __packed annotation on enums.

This is similar to:

  fe3944fb245a ("fs: Move enum rw_hint into a new header file")

for the core SCSI code.

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/Z9rsTirs9lLfEPD9@lx-t490
Link: https://lore.kernel.org/r/20250324133324.23458-20-darwi@linutronix.de
---
 arch/x86/include/asm/cpuid/types.h | 31 +++++++++++++++++++++++++++++-
 arch/x86/kernel/cpu/intel.c        | 28 ++------------------------
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/arch/x86/include/asm/cpuid/types.h b/arch/x86/include/asm/cpuid/types.h
index 39c3c79..e756327 100644
--- a/arch/x86/include/asm/cpuid/types.h
+++ b/arch/x86/include/asm/cpuid/types.h
@@ -60,4 +60,35 @@ enum _cache_table_type {
 static_assert(sizeof(enum _cache_table_type) == 1);
 #endif
 
+/*
+ * 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		= 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;
+#ifndef __CHECKER__
+static_assert(sizeof(enum _tlb_table_type) == 1);
+#endif
+
 #endif /* _ASM_X86_CPUID_TYPES_H */
diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index aeb7d6d..def433e 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_x86 *c, unsigned int size)
 }
 #endif
 
-#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)
 
 struct _tlb_table {
 	unsigned char descriptor;
-	char tlb_type;
+	enum _tlb_table_type type;
 	unsigned int entries;
 };
 
@@ -718,11 +696,11 @@ static void intel_tlb_lookup(const unsigned char desc)
 	     intel_tlb_table[k].descriptor != 0; k++)
 		;
 
-	if (intel_tlb_table[k].tlb_type == 0)
+	if (intel_tlb_table[k].type == 0)
 		return;
 
 	entries = intel_tlb_table[k].entries;
-	switch (intel_tlb_table[k].tlb_type) {
+	switch (intel_tlb_table[k].type) {
 	case STLB_4K:
 		tlb_lli_4k = max(tlb_lli_4k, entries);
 		tlb_lld_4k = max(tlb_lld_4k, entries);

  reply	other threads:[~2025-03-25  9:36 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 13:32 [PATCH v4 00/29] x86: Leaf 0x2 and leaf 0x4 refactorings Ahmed S. Darwish
2025-03-24 13:32 ` [PATCH v4 01/29] x86/cpu: Remove leaf 0x2 parsing loop Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cpu: Remove CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:32 ` [PATCH v4 02/29] x86/cacheinfo: Remove " Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Remove CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:32 ` [PATCH v4 03/29] x86/cpu: Introduce and use leaf 0x2 parsing helpers Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cpu: Introduce and use CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:32 ` [PATCH v4 04/29] x86/cacheinfo: Use " Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Use CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 05/29] x86/cacheinfo: Refactor leaf 0x2 cache descriptor lookup Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Refactor CPUID " tip-bot2 for Thomas Gleixner
2025-03-24 13:33 ` [PATCH v4 06/29] x86/cacheinfo: Properly name amd_cpuid4()'s first parameter Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Thomas Gleixner
2025-03-24 13:33 ` [PATCH v4 07/29] x86/cacheinfo: Use proper name for cacheinfo instances Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Thomas Gleixner
2025-03-24 13:33 ` [PATCH v4 08/29] x86/cacheinfo: Constify _cpuid4_info_regs instances Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 09/29] x86/cacheinfo: Align ci_info_init() assignment expressions Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 10/29] x86/cacheinfo: Standardize _cpuid4_info_regs instance naming Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 11/29] x86/cacheinfo: Consolidate AMD/Hygon leaf 0x8000001d calls Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 12/29] x86/cacheinfo: Separate amd_northbridge from _cpuid4_info_regs Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 13/29] x86/cacheinfo: Move AMD cache_disable_0/1 handling to separate file Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 14/29] x86/cacheinfo: Use sysfs_emit() for sysfs attributes show() Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 15/29] x86/cacheinfo: Separate Intel and AMD leaf 0x4 code paths Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Separate Intel and AMD CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 16/29] x86/cacheinfo: Rename _cpuid4_info_regs to _cpuid4_info Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Rename 'struct _cpuid4_info_regs' to 'struct _cpuid4_info' tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 17/29] x86/cacheinfo: Clarify type markers for leaf 0x2 cache descriptors Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Clarify type markers for CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 18/29] x86/cacheinfo: Use enums for cache descriptor types Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 19/29] x86/cpu: Use enums for TLB " Ahmed S. Darwish
2025-03-25  9:36   ` tip-bot2 for Ahmed S. Darwish [this message]
2025-03-24 13:33 ` [PATCH v4 20/29] x86/cpu: Consolidate CPUID leaf 0x2 tables Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Thomas Gleixner
2025-03-24 13:33 ` [PATCH v4 21/29] x86/cacheinfo: Use consolidated leaf 0x2 descriptor table Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Use consolidated CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 22/29] x86/cpu: Use consolidated " Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cpu: Use consolidated CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 23/29] x86/cacheinfo: Separate leaf 0x2 handling and post-processing logic Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Separate CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 24/29] x86/cacheinfo: Separate Intel leaf 0x4 handling Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Separate Intel CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 25/29] x86/cacheinfo: Extract out cache level topology ID calculation Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 26/29] x86/cacheinfo: Extract out cache self-snoop checks Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 27/29] x86/cacheinfo: Relocate leaf 0x4 cache_type mapping Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] x86/cacheinfo: Relocate CPUID " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 28/29] x86/cacheinfo: Introduce cpuid_amd_hygon_has_l3_cache() Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish
2025-03-24 13:33 ` [PATCH v4 29/29] x86/cacheinfo: Apply maintainer-tip coding style fixes Ahmed S. Darwish
2025-03-25  9:36   ` [tip: x86/cpu] " tip-bot2 for Ahmed S. Darwish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=174289538275.14745.15529363240425062884.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=darwi@linutronix.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®