Split lock enumeration cleanup and fixes
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
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().
--- arch/x86/kernel/cpu/intel.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel.c +2 -4
@@ -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
PATCH 2/3 x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Tony LuckThe 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
--- arch/x86/kernel/cpu/intel.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-)
arch/x86/kernel/cpu/intel.c +18 -14
@@ -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
PATCH 3/3 x86/split_lock: Add Tremont family CPU models
In reply to Tony LuckTremont CPUs support IA32_CORE_CAPABILITIES bits to indicate whether speciifc 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
@@ -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
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_INTELstuff from v5.7 doesn't get backported.
Why stable? The split lock stuff got merged post 5.6.
Thanks,
tglx
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
Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Tony LuckQuoted 3 lines · Tony Luck
The Intel Software Developers' Manual erroneously listed bit 5 of the
IA32_CORE_CAPABILITIESregister 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_CAPABILITIESare 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
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_CAPABILITIESare 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_CAPABILITIEScheck if we need a model match to figure out whetherIA32_CORE_CAPABILITIESbit 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
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_CAPABILITIESare 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_CAPABILITIEScheck if we need a model match to figure out whetherIA32_CORE_CAPABILITIESbit 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
Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Tony LuckQuoted 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
[tip: x86/urgent] x86/split_lock: Update to use X86_MATCH_INTEL_FAM6_MODEL()
In reply to Tony LuckThe 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().
--- arch/x86/kernel/cpu/intel.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/intel.c +2 -4
@@ -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 ), {} };
Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Thomas GleixnerQuoted 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_dataMSR_CORE_CAPSMSR_CORE_CAPS_SLDSLD available1 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
--- arch/x86/kernel/cpu/intel.c | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
arch/x86/kernel/cpu/intel.c +22 -16
@@ -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
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?
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
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.
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
--- 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_locvoid __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 (); }
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
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 aswitch()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
Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Thomas GleixnerQuoted 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 inIA32_CORE_CAPABILITIESare not architectural
Date: Thu, 16 Apr 2020 13:57:53 -0700From: Tony Luck <[email protected]>
The Intel Software Developers' Manual erroneously listed bit 5 of the
IA32_CORE_CAPABILITIESregister as an architectural feature. It is not.Features enumerated by
IA32_CORE_CAPABILITIESare 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_CAPABILITIESFixes 6650cdd9a8cc ("x86/split_lock: Enable split lock detection by kernel")Signed-off-by Tony Luck <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>--- 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_locvoid __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 (); }
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.
Re: [PATCH 2/3] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Xiaoyao LiXiaoyao,
can you please trim your replies?
Quoted 13 lines · Xiaoyao Li
Quoted 11 lines · Thomas Gleixner
+ * Bits in the
IA32_CORE_CAPABILITIESare 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 enumerateIA32_CORE_CAPABILITIES.
+ *
+ * - 1: CPU models which may enumerateIA32_CORE_CAPABILITIESand 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
[tip: x86/urgent] x86/split_lock: Add Tremont family CPU models
In reply to Tony LuckThe 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
@@ -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 ), {} };
[tip: x86/urgent] x86/split_lock: Bits in IA32_CORE_CAPABILITIES are not architectural
In reply to Tony LuckThe 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 ]
--- 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_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 (); }