[MODERATED] [PATCH 1/3] v4 more sampling fun 1

mark gross <[email protected]> Mon, 16 Mar 2020 17:56:27 -0700
Newsgroups org.kernel.lore.historical-speck
Message-ID <7a8f6bad758eedcbf9d0b3d3eccd3581dacf37b9.158456 [email protected]>
From: mark gross <[email protected]>
Subject: [PATCH 1/3] x86/cpu: Add stepping field to x86_cpu_id structure

Intel uses the same family/model for several CPUs. Sometimes
the stepping must be checked to tell them apart.

Note that to keep this patch simple the new field has been added at the
end to avoid churn with all the pre-C99 initialized uses of this
structure. Such legacy usage will result in a "0" value for the stepping
field, hence X86_STEPPING_ANY is defined as "0".

Signed-off-by: Mark Gross <[email protected]>
Co-developed-by: Tony Luck <[email protected]>
Signed-off-by: Tony Luck <[email protected]>
---
 arch/x86/kernel/cpu/match.c     | 6 +++++-
 include/linux/mod_devicetable.h | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/match.c b/arch/x86/kernel/cpu/match.c
index 6dd78d8235e4..129df1a959e9 100644
--- a/arch/x86/kernel/cpu/match.c
+++ b/arch/x86/kernel/cpu/match.c
@@ -34,7 +34,8 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
 	const struct x86_cpu_id *m;
 	struct cpuinfo_x86 *c = &boot_cpu_data;
 
-	for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
+	for (m = match; m->vendor | m->family | m->model | m->feature |
+							   m->stepping; m++) {
 		if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
 			continue;
 		if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
@@ -43,6 +44,9 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match)
 			continue;
 		if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
 			continue;
+		if (m->stepping != X86_STEPPING_ANY &&
+				!(c->x86_stepping & m->stepping))
+			continue;
 		return m;
 	}
 	return NULL;
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index e3596db077dc..340ad760a47a 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -665,6 +665,7 @@ struct x86_cpu_id {
 	__u16 model;
 	__u16 feature;	/* bit index */
 	kernel_ulong_t driver_data;
+	__u16 stepping;
 };
 
 #define X86_FEATURE_MATCH(x) \
@@ -674,6 +675,7 @@ struct x86_cpu_id {
 #define X86_FAMILY_ANY 0
 #define X86_MODEL_ANY  0
 #define X86_FEATURE_ANY 0	/* Same as FPU, you can't test for that */
+#define X86_STEPPING_ANY 0
 
 /*
  * Generic table type for matching CPU features.
-- 
2.17.1