lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241120202411.2E4C9595@davehans-spike.ostc.intel.com>
Date: Wed, 20 Nov 2024 12:24:11 -0800
From: Dave Hansen <dave.hansen@...ux.intel.com>
To: linux-kernel@...r.kernel.org
Cc: x86@...nel.org,tglx@...utronix.de,bp@...en8.de,kan.liang@...ux.intel.com,Dave Hansen <dave.hansen@...ux.intel.com>
Subject: [RFC][PATCH 2/4] x86/cpu: Replace 'x86_cpu_desc' use with 'x86_cpu_id'


From: Dave Hansen <dave.hansen@...ux.intel.com>

The 'x86_cpu_desc' and 'x86_cpu_id' structures are very similar.
Reduce duplicate infrastructure by moving the few users of
'x86_cpu_id' to the much more common variant.

The existing X86_MATCH_VFM_STEPPINGS() helper matches ranges of
steppings. Introduce a new helper to match a single stepping to make
the macro use a bit less verbose.

I'm a _bit_ nervous about this because

	X86_MATCH_VFM_STEPPING(INTEL_SANDYBRIDGE_X,  7, 0x0000070c),
and
	X86_MATCH_VFM_STEPPINGS(INTEL_SANDYBRIDGE_X, 7, 0x0000070c),

look very similar but the second one is buggy. Any suggestions for
making this more foolproof would be appreciated.

Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
---

 b/arch/x86/events/intel/core.c         |   72 ++++++++++++++++-----------------
 b/arch/x86/include/asm/cpu_device_id.h |   18 ++++++++
 2 files changed, 54 insertions(+), 36 deletions(-)

diff -puN arch/x86/events/intel/core.c~zap-x86_cpu_desc arch/x86/events/intel/core.c
--- a/arch/x86/events/intel/core.c~zap-x86_cpu_desc	2024-11-20 12:22:05.468400705 -0800
+++ b/arch/x86/events/intel/core.c	2024-11-20 12:22:05.472400858 -0800
@@ -5340,42 +5340,42 @@ static __init void intel_clovertown_quir
 	x86_pmu.pebs_constraints = NULL;
 }
 
-static const struct x86_cpu_desc isolation_ucodes[] = {
-	INTEL_CPU_DESC(INTEL_HASWELL,		 3, 0x0000001f),
-	INTEL_CPU_DESC(INTEL_HASWELL_L,		 1, 0x0000001e),
-	INTEL_CPU_DESC(INTEL_HASWELL_G,		 1, 0x00000015),
-	INTEL_CPU_DESC(INTEL_HASWELL_X,		 2, 0x00000037),
-	INTEL_CPU_DESC(INTEL_HASWELL_X,		 4, 0x0000000a),
-	INTEL_CPU_DESC(INTEL_BROADWELL,		 4, 0x00000023),
-	INTEL_CPU_DESC(INTEL_BROADWELL_G,	 1, 0x00000014),
-	INTEL_CPU_DESC(INTEL_BROADWELL_D,	 2, 0x00000010),
-	INTEL_CPU_DESC(INTEL_BROADWELL_D,	 3, 0x07000009),
-	INTEL_CPU_DESC(INTEL_BROADWELL_D,	 4, 0x0f000009),
-	INTEL_CPU_DESC(INTEL_BROADWELL_D,	 5, 0x0e000002),
-	INTEL_CPU_DESC(INTEL_BROADWELL_X,	 1, 0x0b000014),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_X,		 3, 0x00000021),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_X,		 4, 0x00000000),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_X,		 5, 0x00000000),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_X,		 6, 0x00000000),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_X,		 7, 0x00000000),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_X,		11, 0x00000000),
-	INTEL_CPU_DESC(INTEL_SKYLAKE_L,		 3, 0x0000007c),
-	INTEL_CPU_DESC(INTEL_SKYLAKE,		 3, 0x0000007c),
-	INTEL_CPU_DESC(INTEL_KABYLAKE,		 9, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE_L,	 9, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE_L,	10, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE_L,	11, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE_L,	12, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE,		10, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE,		11, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE,		12, 0x0000004e),
-	INTEL_CPU_DESC(INTEL_KABYLAKE,		13, 0x0000004e),
+static const struct x86_cpu_id isolation_ucodes[] = {
+	X86_MATCH_VFM_STEPPING(INTEL_HASWELL,		 3, 0x0000001f),
+	X86_MATCH_VFM_STEPPING(INTEL_HASWELL_L,		 1, 0x0000001e),
+	X86_MATCH_VFM_STEPPING(INTEL_HASWELL_G,		 1, 0x00000015),
+	X86_MATCH_VFM_STEPPING(INTEL_HASWELL_X,		 2, 0x00000037),
+	X86_MATCH_VFM_STEPPING(INTEL_HASWELL_X,		 4, 0x0000000a),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL,		 4, 0x00000023),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL_G,	 1, 0x00000014),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL_D,	 2, 0x00000010),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL_D,	 3, 0x07000009),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL_D,	 4, 0x0f000009),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL_D,	 5, 0x0e000002),
+	X86_MATCH_VFM_STEPPING(INTEL_BROADWELL_X,	 1, 0x0b000014),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_X,		 3, 0x00000021),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_X,		 4, 0x00000000),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_X,		 5, 0x00000000),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_X,		 6, 0x00000000),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_X,		 7, 0x00000000),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_X,		11, 0x00000000),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE_L,		 3, 0x0000007c),
+	X86_MATCH_VFM_STEPPING(INTEL_SKYLAKE,		 3, 0x0000007c),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE,		 9, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE_L,	 9, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE_L,	10, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE_L,	11, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE_L,	12, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE,		10, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE,		11, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE,		12, 0x0000004e),
+	X86_MATCH_VFM_STEPPING(INTEL_KABYLAKE,		13, 0x0000004e),
 	{}
 };
 
 static void intel_check_pebs_isolation(void)
 {
-	x86_pmu.pebs_no_isolation = !x86_cpu_has_min_microcode_rev(isolation_ucodes);
+	x86_pmu.pebs_no_isolation = !x86_match_min_microcode_rev(isolation_ucodes);
 }
 
 static __init void intel_pebs_isolation_quirk(void)
@@ -5385,16 +5385,16 @@ static __init void intel_pebs_isolation_
 	intel_check_pebs_isolation();
 }
 
-static const struct x86_cpu_desc pebs_ucodes[] = {
-	INTEL_CPU_DESC(INTEL_SANDYBRIDGE,	7, 0x00000028),
-	INTEL_CPU_DESC(INTEL_SANDYBRIDGE_X,	6, 0x00000618),
-	INTEL_CPU_DESC(INTEL_SANDYBRIDGE_X,	7, 0x0000070c),
+static const struct x86_cpu_id pebs_ucodes[] = {
+	X86_MATCH_VFM_STEPPING(INTEL_SANDYBRIDGE,	7, 0x00000028),
+	X86_MATCH_VFM_STEPPING(INTEL_SANDYBRIDGE_X,	6, 0x00000618),
+	X86_MATCH_VFM_STEPPING(INTEL_SANDYBRIDGE_X,	7, 0x0000070c),
 	{}
 };
 
 static bool intel_snb_pebs_broken(void)
 {
-	return !x86_cpu_has_min_microcode_rev(pebs_ucodes);
+	return !x86_match_min_microcode_rev(pebs_ucodes);
 }
 
 static void intel_snb_check_microcode(void)
diff -puN arch/x86/include/asm/cpu_device_id.h~zap-x86_cpu_desc arch/x86/include/asm/cpu_device_id.h
--- a/arch/x86/include/asm/cpu_device_id.h~zap-x86_cpu_desc	2024-11-20 12:22:05.468400705 -0800
+++ b/arch/x86/include/asm/cpu_device_id.h	2024-11-20 12:22:05.472400858 -0800
@@ -226,6 +226,24 @@
 		steppings, X86_FEATURE_ANY, data)
 
 /**
+ * X86_MATCH_VFM_STEPPING - Match encoded vendor/family/model/stepping
+ * @vfm:	Encoded 8-bits each for vendor, family, model
+ * @stepping:	A single integer stepping
+ * @data:	Driver specific data or NULL. The internal storage
+ *		format is unsigned long. The supplied value, pointer
+ *		etc. is cast to unsigned long internally.
+ *
+ * feature is set to wildcard
+ */
+#define X86_MATCH_VFM_STEPPING(vfm, stepping, data)	\
+	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
+		VFM_VENDOR(vfm),			\
+		VFM_FAMILY(vfm),			\
+		VFM_MODEL(vfm),				\
+		X86_STEPPINGS(stepping, stepping), 	\
+		X86_FEATURE_ANY, data)
+
+/**
  * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature
  * @vfm:	Encoded 8-bits each for vendor, family, model
  * @feature:	A X86_FEATURE bit
_

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ