Skip to contentSkip to conversation

Split lock enumeration cleanup and fixes

PATCH Applied Tony Luck 5 participants 23 messages Apr 16, 2020 – Apr 18, 2020 x86

lore
Share & tools
lore

Tony Luck

author
#0 lore raw

cover Split lock enumeration cleanup and fixes

Need to revisit the sequence of operations when testing for the split lock detect feature. It is model specific, so we must check the model number before looking at CORE_CAPABILITIES.

I marked it all for stable ... some tweaking would be needed if the X86_MATCH_INTEL stuff from v5.7 doesn't get backported.

Tony Luck (3):
x86/split_lock: Update to use X86_MATCH_INTEL_FAM6_MODEL() x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural x86/split_lock: Add Tremont family CPU models

 arch/x86/kernel/cpu/intel.c | 41 +++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 18 deletions(-)
Signature · 1 line
2.21.1
author
#1 lore raw

PATCH 1/3 x86/split_lock: Update to use X86_MATCH_INTEL_FAM6_MODEL()

The SPLIT_LOCK_CPU() macro escaped the tree-wide sweep for old-style initialization. Update to use X86_MATCH_INTEL_FAM6_MODEL().

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel.c +2 -4
index bf08d4508ecb..6119deb32660 100644
@@ -1119,8 +1119,6 @@ void switch_to_sld(unsigned long tifn)
 	sld_update_msr(!(tifn & _TIF_SLD));
 }
 
-#define SPLIT_LOCK_CPU(model) {X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY}
-
 /*
  * The following processors have the split lock detection feature. But
  * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
@@ -1128,8 +1126,8 @@ void switch_to_sld(unsigned long tifn)
  * processors.
  */
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
-	SPLIT_LOCK_CPU(INTEL_FAM6_ICELAKE_X),
-	SPLIT_LOCK_CPU(INTEL_FAM6_ICELAKE_L),
+	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,           0),
+	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L,           0),
 	{}
 };
 
Signature · 1 line
2.21.1
author
#3 lore raw

PATCH 2/3 x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Tony Luck

The Intel Software Developers' Manual erroneously listed bit 5 of the IA32_CORE_CAPABILITIES register as an architectural feature. It is not.

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

Icelake client and server models are known to implement the split lock detect feature even though they don't enumerate IA32_CORE_CAPABILITIES

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/intel.c +18 -14
index 6119deb32660..3b43b2c91054 100644
@@ -1120,10 +1120,12 @@ void switch_to_sld(unsigned long tifn)
 }
 
 /*
- * The following processors have the split lock detection feature. But
- * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
- * be enumerated. Enable it by family and model matching on these
- * processors.
+ * Bits in the IA32_CORE_CAPABILITIES are not architectural, so they
+ * should only be trusted if you know you are on a model that implements
+ * them.
+ * The driver_data field is set to zero to indicate CPU models like
+ * Icelake that are known to have the split-lock feature even though
+ * they do not enumerate IA32_CORE_CAPABILITIES.
  */
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,           0),
@@ -1133,19 +1135,21 @@ static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 
 void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c)
 {
-	u64 ia32_core_caps = 0;
+	const struct x86_cpu_id *m;
+	u64 ia32_core_caps;
 
-	if (c->x86_vendor != X86_VENDOR_INTEL)
+	if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
 		return;
-	if (cpu_has(c, X86_FEATURE_CORE_CAPABILITIES)) {
-		/* Enumerate features reported in IA32_CORE_CAPABILITIES MSR. */
+
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
+		return;
+
+	if (m->driver_data && cpu_has(c, X86_FEATURE_CORE_CAPABILITIES)) {
 		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
-	} else if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
-		/* Enumerate split lock detection by family and model. */
-		if (x86_match_cpu(split_lock_cpu_ids))
-			ia32_core_caps |= MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT;
+		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+			return;
 	}
 
-	if (ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT)
-		split_lock_setup();
+	split_lock_setup();
 }
Signature · 1 line
2.21.1
author
#19 lore raw

PATCH 3/3 x86/split_lock: Add Tremont family CPU models

In reply to Tony Luck

Tremont CPUs support IA32_CORE_CAPABILITIES bits to indicate whether speciifc SKUs have support for split lock detection.

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/intel.c +3 -0
index 3b43b2c91054..d559481b54a6 100644
@@ -1130,6 +1130,9 @@ void switch_to_sld(unsigned long tifn)
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,           0),
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L,           0),
+	X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT,	1),
+	X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D,	1),
+	X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_L,	1),
 	{}
 };
 
Signature · 1 line
2.21.1
#21 lore raw
In reply to Tony Luck
Quoted 6 lines · Tony Luck

Need to revisit the sequence of operations when testing for the split lock detect feature. It is model specific, so we must check the model number before looking at CORE_CAPABILITIES.

I marked it all for stable ... some tweaking would be needed if the X86_MATCH_INTEL stuff from v5.7 doesn't get backported.

Why stable? The split lock stuff got merged post 5.6.

Thanks,

tglx

author
#22 lore raw
Quoted 1 line

Why stable? The split lock stuff got merged post 5.6.

I have no sense of time ... in my memory it went in ages ago. I guess I'm remembering it making it into TIP.

Drop the stable stuff ... obviously no need.

-Tony

#4 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Tony Luck
Quoted 3 lines · Tony Luck

The Intel Software Developers' Manual erroneously listed bit 5 of the IA32_CORE_CAPABILITIES register as an architectural feature. It is not.

TBH. I'm really pissed off by that. We ask Intel for the past 20 years that this non-enumerability and model checking has to stop.

Especially for the split lock festure we got assured that the Icelakes are the only models which need the cpu match because it was too late to add the capability bit.

Quoted 3 lines

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

What's the point of the IA32_CORE_CAPABILITIES check if we need a model match to figure out whether IA32_CORE_CAPABILITIES bit 5 is valid to enumerate split lock detection?

IOW, are we going to see CPUs which end up in the match list and have bit 5 cleared in IA32_CORE_CAPABILITIES?

Thanks,

tglx

author
#5 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Quoted 11 lines · Thomas Gleixner
Quoted 3 lines · Tony Luck

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

What's the point of the IA32_CORE_CAPABILITIES check if we need a model match to figure out whether IA32_CORE_CAPABILITIES bit 5 is valid to enumerate split lock detection?

IOW, are we going to see CPUs which end up in the match list and have bit 5 cleared in IA32_CORE_CAPABILITIES?

There may be low-end SKUs of a model that don't have all the features of the high-end SKUs. So yes, you may find that a specific SKU of a model on the list for a feature doesn't have the feature.

A model specific feature may also have implementation differences on different models. E.g. if Intel were to produce a model that did split lock "right" (with thread-scoped control). That would still use the same bit in IA32_CORE_CAPABILITIES, but the OS would need model specific knowledge to know that this split lock detect worked differently from another model that has split lock detect.

-Tony

#6 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Tony,

Quoted 17 lines · Tony
Quoted 11 lines · Thomas Gleixner
Quoted 3 lines · Tony Luck

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

What's the point of the IA32_CORE_CAPABILITIES check if we need a model match to figure out whether IA32_CORE_CAPABILITIES bit 5 is valid to enumerate split lock detection?

IOW, are we going to see CPUs which end up in the match list and have bit 5 cleared in IA32_CORE_CAPABILITIES?

There may be low-end SKUs of a model that don't have all the features of the high-end SKUs. So yes, you may find that a specific SKU of a model on the list for a feature doesn't have the feature.

Quoted 6 lines

A model specific feature may also have implementation differences on different models. E.g. if Intel were to produce a model that did split lock "right" (with thread-scoped control). That would still use the same bit in IA32_CORE_CAPABILITIES, but the OS would need model specific knowledge to know that this split lock detect worked differently from another model that has split lock detect.

IA32_CORE_CAPABILITIES makes a lot of sense to enumerate per thread functionality because common sense and consistency are overrated.

Can Intel's HW folks please stop their approach of 'let software deal with the mess we create' once and forever?

Thanks,

tglx

#7 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Tony Luck
Quoted 6 lines · Tony Luck
arch/x86/kernel/cpu/intel.c +5 -0
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
+		return;
+
+	if (m->driver_data && cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))

{

This condition results in the following:

driver_data MSR_CORE_CAPS MSR_CORE_CAPS_SLD SLD available

1       0             Don't care          Don't care               Y
2       1                N                Don't care               Y
3       1                Y                    Y                    Y
4       1                Y                    N                    N

#2 does not make any sense to me.

Thanks,

tglx

merge bot Applied
#2 lore raw

[tip: x86/urgent] x86/split_lock: Update to use X86_MATCH_INTEL_FAM6_MODEL()

In reply to Tony Luck
The following commit has been merged into the x86/urgent branch of tip:

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

Commit-ID:     3ab0762d1edfda6ccbc08f636acab42c103c299f
Gitweb:        https://git.kernel.org/tip/3ab0762d1edfda6ccbc08f636acab42c103c299f
Author:        Tony Luck <[email protected]>
AuthorDate:    Thu, 16 Apr 2020 13:57:52 -07:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 17 Apr 2020 12:14:12 +02:00

x86/split_lock: Update to use X86_MATCH_INTEL_FAM6_MODEL()

The SPLIT_LOCK_CPU() macro escaped the tree-wide sweep for old-style initialization. Update to use X86_MATCH_INTEL_FAM6_MODEL().

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel.c +2 -4
index bf08d45..ec0d8c7 100644
@@ -1119,8 +1119,6 @@ void switch_to_sld(unsigned long tifn)
 	sld_update_msr(!(tifn & _TIF_SLD));
 }
 
-#define SPLIT_LOCK_CPU(model) {X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY}
-
 /*
  * The following processors have the split lock detection feature. But
  * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
@@ -1128,8 +1126,8 @@ void switch_to_sld(unsigned long tifn)
  * processors.
  */
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
-	SPLIT_LOCK_CPU(INTEL_FAM6_ICELAKE_X),
-	SPLIT_LOCK_CPU(INTEL_FAM6_ICELAKE_L),
+	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,		0),
+	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L,		0),
 	{}
 };
 
author
#8 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Thomas Gleixner
Quoted 10 lines · Thomas Gleixner
Quoted 6 lines · Tony Luck
(quoted diff) +5 -0
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
+		return;
+
+	if (m->driver_data && cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))

{

This condition results in the following:

Quoted 8 lines

driver_data MSR_CORE_CAPS MSR_CORE_CAPS_SLD SLD available

1       0             Don't care          Don't care               Y
2       1                N                Don't care               Y
3       1                Y                    Y                    Y
4       1                Y                    N                    N

#2 does not make any sense to me.

Nor to me :-(

I got too clever trying to combine tests.

New version taking cases one at a time so my "stuck inside the house for six weeks now" brain can follow the steps.

-Tony

From 8c9d779e358eaa239b9647b7a3fe8ebee9becd63 Mon Sep 17 00:00:00 2001
From: Tony Luck <[email protected]>
Date: Thu, 16 Apr 2020 10:37:42 -0700
Subject: [PATCH v2] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not
architectural

The Intel Software Developers' Manual erroneously listed bit 5 of the IA32_CORE_CAPABILITIES register as an architectural feature. It is not.

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

Icelake client and server models are known to implement the split lock detect feature even though they don't enumerate IA32_CORE_CAPABILITIES

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c | 38 +++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/intel.c +22 -16
index 6119deb32660..0bf0d7e3832a 100644
@@ -1120,10 +1120,12 @@ void switch_to_sld(unsigned long tifn)
 }
 
 /*
- * The following processors have the split lock detection feature. But
- * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
- * be enumerated. Enable it by family and model matching on these
- * processors.
+ * Bits in the IA32_CORE_CAPABILITIES are not architectural, so they
+ * should only be trusted if you know you are on a model that implements
+ * them.
+ * The driver_data field is set to zero to indicate CPU models like
+ * Icelake that are known to have the split-lock feature even though
+ * they do not enumerate IA32_CORE_CAPABILITIES.
  */
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,           0),
@@ -1133,19 +1135,23 @@ static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 
 void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c)
 {
-	u64 ia32_core_caps = 0;
+	const struct x86_cpu_id *m;
+	u64 ia32_core_caps;
 
-	if (c->x86_vendor != X86_VENDOR_INTEL)
+	if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
+		return;
+
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
 		return;
-	if (cpu_has(c, X86_FEATURE_CORE_CAPABILITIES)) {
-		/* Enumerate features reported in IA32_CORE_CAPABILITIES MSR. */
-		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
-	} else if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
-		/* Enumerate split lock detection by family and model. */
-		if (x86_match_cpu(split_lock_cpu_ids))
-			ia32_core_caps |= MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT;
-	}
 
-	if (ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT)
-		split_lock_setup();
+	if (!m->driver_data)
+		goto setup;
+	if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+		return;
+	rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
+	if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+		return;
+setup:
+	split_lock_setup();
 }
Signature · 1 line
2.21.1
#9 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

arch/x86/kernel/cpu/intel.c static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = { · line 1156

Quoted 10 lines · Tony

On Fri, Apr 17, 2020 at 12:04:36PM +0200, Thomas Gleixner wrote:

arch/x86/kernel/cpu/intel.c +9 -0
+	if (!m->driver_data)
+		goto setup;
+	if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+		return;
+	rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
+	if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+		return;
+setup:
+	split_lock_setup();

Which looks nicer w/o the goto:

	if (m->driver_data) {
		if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
			return;
		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
			return;
	}

Hmm?

author
#10 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Quoted 22 lines · Thomas Gleixner

arch/x86/kernel/cpu/intel.c static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = { · line 1156

Quoted 10 lines · Tony

On Fri, Apr 17, 2020 at 12:04:36PM +0200, Thomas Gleixner wrote:

arch/x86/kernel/cpu/intel.c +9 -0
+	if (!m->driver_data)
+		goto setup;
+	if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+		return;
+	rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
+	if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+		return;
+setup:
+	split_lock_setup();

Which looks nicer w/o the goto:

	if (m->driver_data) {
		if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
			return;
		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
			return;
	}
Quoted 1 line

Hmm?

Swings and roundabouts ... getting rid of the goto makes for deeper indentation. But if you really want to get rid of the goto, then your version is fine with me.

Do you want me to spin it into v3?

-Tony

#11 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Quoted 23 lines · Tony
Quoted 22 lines · Thomas Gleixner

arch/x86/kernel/cpu/intel.c static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = { · line 1156

Quoted 10 lines · Tony

On Fri, Apr 17, 2020 at 12:04:36PM +0200, Thomas Gleixner wrote:

arch/x86/kernel/cpu/intel.c +9 -0
+	if (!m->driver_data)
+		goto setup;
+	if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+		return;
+	rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
+	if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+		return;
+setup:
+	split_lock_setup();

Which looks nicer w/o the goto:

	if (m->driver_data) {
		if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
			return;
		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
			return;
	}
Quoted 7 lines
Quoted 1 line

Hmm?

Swings and roundabouts ... getting rid of the goto makes for deeper indentation. But if you really want to get rid of the goto, then your version is fine with me.

Do you want me to spin it into v3?

Nah. I tweak it myself.

#12 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Tony,

Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Tony

Swings and roundabouts ... getting rid of the goto makes for deeper indentation. But if you really want to get rid of the goto, then your version is fine with me.

Do you want me to spin it into v3?

Nah. I tweak it myself.

as I fear that the infinite wisdom of HW folks will add yet another variant in the foreseeable future, I used a switch() right away and tweaked the comments a bit.

Can you have a look, please?

Thanks,

tglx

8<------------------
From: Tony Luck <[email protected]>
Subject: x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
Date: Thu, 16 Apr 2020 13:57:53 -0700

From: Tony Luck <[email protected]>

The Intel Software Developers' Manual erroneously listed bit 5 of the IA32_CORE_CAPABILITIES register as an architectural feature. It is not.

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

Icelake client and server models are known to implement the split lock detect feature even though they don't enumerate IA32_CORE_CAPABILITIES

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c |   45 ++++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/intel.c +31 -14
@@ -1120,10 +1120,17 @@ void switch_to_sld(unsigned long tifn)
 }
 
 /*
- * The following processors have the split lock detection feature. But
- * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
- * be enumerated. Enable it by family and model matching on these
- * processors.
+ * Bits in the IA32_CORE_CAPABILITIES are not architectural, so they should
+ * only be trusted if it is confirmed that a CPU model implements a
+ * specific feature at a particular bit position.
+ *
+ * The possible driver data field values:
+ *
+ * - 0: CPU models that are known to have the per-core split-lock detection
+ *	feature even though they do not enumerate IA32_CORE_CAPABILITIES.
+ *
+ * - 1: CPU models which may enumerate IA32_CORE_CAPABILITIES and if so use
+ *      bit 5 to enumerate the per-core split-lock detection feature.
  */
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,		0),
@@ -1133,19 +1140,29 @@ static const struct x86_cpu_id split_loc
 
 void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c)
 {
-	u64 ia32_core_caps = 0;
+	const struct x86_cpu_id *m;
+	u64 ia32_core_caps;
 
-	if (c->x86_vendor != X86_VENDOR_INTEL)
+	if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
 		return;
-	if (cpu_has(c, X86_FEATURE_CORE_CAPABILITIES)) {
-		/* Enumerate features reported in IA32_CORE_CAPABILITIES MSR. */
+
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
+		return;
+
+	switch (m->driver_data) {
+	case 0:
+		break;
+	case 1:
+		if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+			return;
 		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
-	} else if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
-		/* Enumerate split lock detection by family and model. */
-		if (x86_match_cpu(split_lock_cpu_ids))
-			ia32_core_caps |= MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT;
+		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+			return;
+		break;
+	default:
+		return;
 	}
 
-	if (ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT)
-		split_lock_setup();
+	split_lock_setup();
 }
author
#13 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Quoted 10 lines · Thomas Gleixner

Tony,

Quoted 7 lines · Thomas Gleixner
Quoted 5 lines · Tony

Swings and roundabouts ... getting rid of the goto makes for deeper indentation. But if you really want to get rid of the goto, then your version is fine with me.

Do you want me to spin it into v3?

Quoted 7 lines
Quoted 1 line

Nah. I tweak it myself.

as I fear that the infinite wisdom of HW folks will add yet another variant in the foreseeable future, I used a switch() right away and tweaked the comments a bit.

Can you have a look, please?

Looks like you are all ready for "case 2:" when Intel produces a less sucky implementation of split lock detect. Don't hold your breath waiting for that :-)

Looks good. Should be a useful template for any future bits that show up in CORE_CAPABILITIES.

-Tony

#14 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Quoted 11 lines · Tony
Quoted 6 lines · Thomas Gleixner

Thomas Gleixner <[email protected]> writes:
as I fear that the infinite wisdom of HW folks will add yet another variant in the foreseeable future, I used a switch() right away and tweaked the comments a bit.

Can you have a look, please?

Looks like you are all ready for "case 2:" when Intel produces a less sucky implementation of split lock detect. Don't hold your breath waiting for that :-)

Surely not.

I'm still hoping to see quirkless TSCs and timers, sane IRET semantics and the demise of non-maskable MSIs before my retirement. Not that I believe it will happen, it's just because hope dies last.

Quoted 2 lines

Looks good. Should be a useful template for any future bits that show up in CORE_CAPABILITIES.

Groan. No!

Thanks,

tglx

#15 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Thomas Gleixner
Quoted 59 lines · Thomas Gleixner

Tony,

Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Tony

Swings and roundabouts ... getting rid of the goto makes for deeper indentation. But if you really want to get rid of the goto, then your version is fine with me.

Do you want me to spin it into v3?

Nah. I tweak it myself.

as I fear that the infinite wisdom of HW folks will add yet another variant in the foreseeable future, I used a switch() right away and tweaked the comments a bit.

Can you have a look, please?

Thanks,

tglx

8<------------------
From: Tony Luck <[email protected]>
Subject: x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
Date: Thu, 16 Apr 2020 13:57:53 -0700

From: Tony Luck <[email protected]>

The Intel Software Developers' Manual erroneously listed bit 5 of the IA32_CORE_CAPABILITIES register as an architectural feature. It is not.

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

Icelake client and server models are known to implement the split lock detect feature even though they don't enumerate IA32_CORE_CAPABILITIES

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
  arch/x86/kernel/cpu/intel.c |   45 ++++++++++++++++++++++++++++++--------------
  1 file changed, 31 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/intel.c +1 -4
@@ -1120,10 +1120,17 @@ void switch_to_sld(unsigned long tifn)
  }
 
  /*
- * The following processors have the split lock detection feature. But
- * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
- * be enumerated. Enable it by family and model matching on these
- * processors.
+ * Bits in the IA32_CORE_CAPABILITIES are not architectural, so they should

arch/x86/kernel/cpu/intel.c void switch_to_sld(unsigned long tifn) · line 1133

Quoted 10 lines
arch/x86/kernel/cpu/intel.c +10 -0
+ * only be trusted if it is confirmed that a CPU model implements a
+ * specific feature at a particular bit position.
+ *
+ * The possible driver data field values:
+ *
+ * - 0: CPU models that are known to have the per-core split-lock detection
+ *	feature even though they do not enumerate IA32_CORE_CAPABILITIES.
+ *
+ * - 1: CPU models which may enumerate IA32_CORE_CAPABILITIES and if so use
+ *      bit 5 to enumerate the per-core split-lock detection feature.

So now, it's tightly associated with CPU model, which makes it harder to expose this feature to guest. For guest, the CPU model can be configured to anything.

As suggested by Sean internally, we'd better use a KVM CPUID to expose it to guest, which makes it independent of CPU model.

Paolo, tglx,

What do you think?

Quoted 44 lines
arch/x86/kernel/cpu/intel.c +20 -10
   */
  static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
  	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,		0),
@@ -1133,19 +1140,29 @@ static const struct x86_cpu_id split_loc
 
  void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c)
  {
-	u64 ia32_core_caps = 0;
+	const struct x86_cpu_id *m;
+	u64 ia32_core_caps;
 
-	if (c->x86_vendor != X86_VENDOR_INTEL)
+	if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
  		return;
-	if (cpu_has(c, X86_FEATURE_CORE_CAPABILITIES)) {
-		/* Enumerate features reported in IA32_CORE_CAPABILITIES MSR. */
+
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
+		return;
+
+	switch (m->driver_data) {
+	case 0:
+		break;
+	case 1:
+		if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+			return;
  		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
-	} else if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
-		/* Enumerate split lock detection by family and model. */
-		if (x86_match_cpu(split_lock_cpu_ids))
-			ia32_core_caps |= MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT;
+		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+			return;
+		break;
+	default:
+		return;
  	}
 
-	if (ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT)
-		split_lock_setup();
+	split_lock_setup();
  }
#16 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

Quoted 6 lines · Xiaoyao Li

So now, it's tightly associated with CPU model, which makes it harder to expose this feature to guest. For guest, the CPU model can be configured to anything.

As suggested by Sean internally, we'd better use a KVM CPUID to expose it to guest, which makes it independent of CPU model.

Making this a paravirt feature from a KVM perspective would also let us do the whole STICKY bit thing straight away. I don't like paravirtualizing something that could be emulated as-is, I but dislike it less than exposing features based on CPU model.

#17 lore raw

Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Xiaoyao Li

Xiaoyao,

can you please trim your replies?

Quoted 13 lines · Xiaoyao Li
Quoted 11 lines · Thomas Gleixner

+ * Bits in the IA32_CORE_CAPABILITIES are not architectural, so they should
+ * only be trusted if it is confirmed that a CPU model implements a
+ * specific feature at a particular bit position.
+ *
+ * The possible driver data field values:
+ *
+ * - 0: CPU models that are known to have the per-core split-lock detection
+ * feature even though they do not enumerate IA32_CORE_CAPABILITIES.
+ *
+ * - 1: CPU models which may enumerate IA32_CORE_CAPABILITIES and if so use
+ * bit 5 to enumerate the per-core split-lock detection feature.

Quoted 6 lines

So now, it's tightly associated with CPU model, which makes it harder to expose this feature to guest. For guest, the CPU model can be configured to anything.

As suggested by Sean internally, we'd better use a KVM CPUID to expose it to guest, which makes it independent of CPU model.

Works for me.

Thanks,

tglx

merge bot Applied
#20 lore raw

[tip: x86/urgent] x86/split_lock: Add Tremont family CPU models

In reply to Tony Luck
The following commit has been merged into the x86/urgent branch of tip:

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

Commit-ID:     8b9a18a9f2494144fe23fe630d0734310fa65301
Gitweb:        https://git.kernel.org/tip/8b9a18a9f2494144fe23fe630d0734310fa65301
Author:        Tony Luck <[email protected]>
AuthorDate:    Thu, 16 Apr 2020 13:57:54 -07:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sat, 18 Apr 2020 12:48:44 +02:00

x86/split_lock: Add Tremont family CPU models

Tremont CPUs support IA32_CORE_CAPABILITIES bits to indicate whether specific SKUs have support for split lock detection.

---
 arch/x86/kernel/cpu/intel.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/cpu/intel.c +3 -0
index c23ad48..a19a680 100644
@@ -1135,6 +1135,9 @@ void switch_to_sld(unsigned long tifn)
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,		0),
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L,		0),
+	X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT,	1),
+	X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D,	1),
+	X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_L,	1),
 	{}
 };
 
merge bot Applied
#18 lore raw

[tip: x86/urgent] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

In reply to Tony Luck
The following commit has been merged into the x86/urgent branch of tip:

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

Commit-ID:     48fd5b5ee714714f4cf9f9e1cba3b49b1fd40ed6
Gitweb:        https://git.kernel.org/tip/48fd5b5ee714714f4cf9f9e1cba3b49b1fd40ed6
Author:        Tony Luck <[email protected]>
AuthorDate:    Thu, 16 Apr 2020 13:57:53 -07:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sat, 18 Apr 2020 12:48:44 +02:00

x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural

The Intel Software Developers' Manual erroneously listed bit 5 of the IA32_CORE_CAPABILITIES register as an architectural feature. It is not.

Features enumerated by IA32_CORE_CAPABILITIES are model specific and implementation details may vary in different cpu models. Thus it is only safe to trust features after checking the CPU model.

Icelake client and server models are known to implement the split lock detect feature even though they don't enumerate IA32_CORE_CAPABILITIES

[ tglx: Use switch() for readability and massage comments ]

Fixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")
---
 arch/x86/kernel/cpu/intel.c | 45 ++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/intel.c +31 -14
index ec0d8c7..c23ad48 100644
@@ -1120,10 +1120,17 @@ void switch_to_sld(unsigned long tifn)
 }
 
 /*
- * The following processors have the split lock detection feature. But
- * since they don't have the IA32_CORE_CAPABILITIES MSR, the feature cannot
- * be enumerated. Enable it by family and model matching on these
- * processors.
+ * Bits in the IA32_CORE_CAPABILITIES are not architectural, so they should
+ * only be trusted if it is confirmed that a CPU model implements a
+ * specific feature at a particular bit position.
+ *
+ * The possible driver data field values:
+ *
+ * - 0: CPU models that are known to have the per-core split-lock detection
+ *	feature even though they do not enumerate IA32_CORE_CAPABILITIES.
+ *
+ * - 1: CPU models which may enumerate IA32_CORE_CAPABILITIES and if so use
+ *      bit 5 to enumerate the per-core split-lock detection feature.
  */
 static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 	X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,		0),
@@ -1133,19 +1140,29 @@ static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
 
 void __init cpu_set_core_cap_bits(struct cpuinfo_x86 *c)
 {
-	u64 ia32_core_caps = 0;
+	const struct x86_cpu_id *m;
+	u64 ia32_core_caps;
+
+	if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
+		return;
 
-	if (c->x86_vendor != X86_VENDOR_INTEL)
+	m = x86_match_cpu(split_lock_cpu_ids);
+	if (!m)
 		return;
-	if (cpu_has(c, X86_FEATURE_CORE_CAPABILITIES)) {
-		/* Enumerate features reported in IA32_CORE_CAPABILITIES MSR. */
+
+	switch (m->driver_data) {
+	case 0:
+		break;
+	case 1:
+		if (!cpu_has(c, X86_FEATURE_CORE_CAPABILITIES))
+			return;
 		rdmsrl(MSR_IA32_CORE_CAPS, ia32_core_caps);
-	} else if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
-		/* Enumerate split lock detection by family and model. */
-		if (x86_match_cpu(split_lock_cpu_ids))
-			ia32_core_caps |= MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT;
+		if (!(ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT))
+			return;
+		break;
+	default:
+		return;
 	}
 
-	if (ia32_core_caps & MSR_IA32_CORE_CAPS_SPLIT_LOCK_DETECT)
-		split_lock_setup();
+	split_lock_setup();
 }