x86/amd: Fixes for levelling setup
cover x86/amd: Fixes for levelling setup
More fixes for AMD setup.
Andrew Cooper (3):
x86/amd: Fold another DE_CFG edit into amd_init_de_cfg() x86/amd: Exclude K8 RevD and earlier from levelling x86/amd: Delay amd_init_levelling() until after fixes to the CPUID
MSRs
xen/arch/x86/cpu/amd.c | 40 ++++++++++++++++++---------------------- xen/arch/x86/cpu/cpu.h | 2 +- xen/arch/x86/cpu/hygon.c | 6 +++++- 3 files changed, 24 insertions(+), 24 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/3 x86/amd: Fold another DE_CFG edit into amd_init_de_cfg()
Fam12h processors aren't SMT-capable so there are no race condition worries with this path. Nevertheless, group it together with the other DE_CFG modifications.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
I apparently couldn't count how many examples we had editing DE_CFG...
--- xen/arch/x86/cpu/amd.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
xen/arch/x86/cpu/amd.c +7 -9
@@ -920,6 +920,13 @@ void amd_init_de_cfg(const struct cpuinfo_x86 *c)if (zenbleed_use_chickenbit () ) new |= (1 <<9 ); +/* +* Erratum #665, doc 44739. Integer divide instructions may cause +* unpredictable behaviour. +*/ +if ( c->family ==0x12 ) + new |=1U <<31 ; +/* Avoid reading DE_CFG if we don't intend to change anything. */ if ( !new )return ;
@@ -1201,15 +1208,6 @@ static void cf_check init_amd(struct cpuinfo_x86 *c) smp_processor_id());wrmsrl (MSR_AMD64_LS_CFG , value | (1 <<15 )); } - }else if (c->x86 ==0x12 ) { -rdmsrl (MSR_AMD64_DE_CFG , value); -if (!(value & (1U <<31 ))) { -if (c == &boot_cpu_data || opt_cpu_info) -printk_once (XENLOG_WARNING -"CPU%u: Applying workaround for erratum 665\n" , -smp_processor_id ()); -wrmsrl (MSR_AMD64_DE_CFG , value | (1U <<31 )); - } }/* AMD CPUs do not support SYSENTER outside of legacy mode. */
Signature · 1 line
2.39.5
Re: [PATCH 1/3] x86/amd: Fold another DE_CFG edit into amd_init_de_cfg()
Quoted 3 lines · Andrew Cooper
Fam12h processors aren't SMT-capable so there are no race condition worries with this path. Nevertheless, group it together with the other
DE_CFGmodifications.
With this, ...
Quoted 1 line
Fixes d0c75dc4c028 ("x86/amd: Fix race editing DE_CFG")
... isn't this more like Amends:? Aiui this wouldn't need backporting.
Quoted 20 lines
xen/arch/x86/cpu/amd.c +7
-0@@ -920,6 +920,13 @@ void amd_init_de_cfg(const struct cpuinfo_x86 *c)if (zenbleed_use_chickenbit () ) new |= (1 <<9 ); +/* +* Erratum #665, doc 44739. Integer divide instructions may cause +* unpredictable behaviour. +*/ +if ( c->family ==0x12 ) + new |=1U <<31 ; +/* Avoid reading DE_CFG if we don't intend to change anything. */ if ( !new )return ;@@ -1201,15 +1208,6 @@ static void cf_check init_amd(struct cpuinfo_x86 *c) smp_processor_id());wrmsrl (MSR_AMD64_LS_CFG , value | (1 <<15 )); }
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1211
Quoted 10 lines
xen/arch/x86/cpu/amd.c +0
-9- }else if (c->x86 ==0x12 ) { -rdmsrl (MSR_AMD64_DE_CFG , value); -if (!(value & (1U <<31 ))) { -if (c == &boot_cpu_data || opt_cpu_info) -printk_once (XENLOG_WARNING -"CPU%u: Applying workaround for erratum 665\n" , -smp_processor_id ()); -wrmsrl (MSR_AMD64_DE_CFG , value | (1U <<31 )); - } }
Are you deliberately getting rid of the log message?
And I assume it is deliberate that the adjustment no longer is done when we're running virtualized ourselves?
Both imo want making explicit in the description.
Jan
Re: [PATCH 1/3] x86/amd: Fold another DE_CFG edit into amd_init_de_cfg()
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
Fam12h processors aren't SMT-capable so there are no race condition worries with this path. Nevertheless, group it together with the other
DE_CFGmodifications.With this, ...
Quoted 1 line
Fixes d0c75dc4c028 ("x86/amd: Fix race editing DE_CFG")... isn't this more like Amends:? Aiui this wouldn't need backporting.
This does want backporting.
d0c75dc4c028 explains how it's buggy to have multiple pieces of logic writing to DE_CFG, and here's yet another one.
It's only a latent bug because Fam12 doesn't have CMT/SMT, and this property is not discussed, meaning that the logic as-is comes across as unsafe.
Quoted 24 lines
Quoted 24 lines
xen/arch/x86/cpu/amd.c +7
-3@@ -920,6 +920,13 @@ void amd_init_de_cfg(const struct cpuinfo_x86 *c)if (zenbleed_use_chickenbit () ) new |= (1 <<9 ); +/* +* Erratum #665, doc 44739. Integer divide instructions may cause +* unpredictable behaviour. +*/ +if ( c->family ==0x12 ) + new |=1U <<31 ; +/* Avoid reading DE_CFG if we don't intend to change anything. */ if ( !new )return ;@@ -1201,15 +1208,6 @@ static void cf_check init_amd(struct cpuinfo_x86 *c) smp_processor_id());wrmsrl (MSR_AMD64_LS_CFG , value | (1 <<15 )); } - }else if (c->x86 ==0x12 ) { -rdmsrl (MSR_AMD64_DE_CFG , value); -if (!(value & (1U <<31 ))) {
Quoted 8 lines
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1211
Quoted 7 lines
xen/arch/x86/cpu/amd.c +0
-6-if (c == &boot_cpu_data || opt_cpu_info) -printk_once (XENLOG_WARNING -"CPU%u: Applying workaround for erratum 665\n" , -smp_processor_id ()); -wrmsrl (MSR_AMD64_DE_CFG , value | (1U <<31 )); - } }Are you deliberately getting rid of the log message?
Yes, it's basically line noise.
Most errata like this are not handled at all, and this is not overly noteworthy. If it were at debug level then maybe, but certainly not at warning.
Fam12h were rare in the first place and are museum pieces these days.
Quoted 2 lines
And I assume it is deliberate that the adjustment no longer is done when we're running virtualized ourselves?
Of course. It's pointless, and a readback would show that the write had had no effect.
Quoted 2 lines
Both imo want making explicit in the description.
I've updated the commit message to:
x86/amd: Fold another DE_CFG edit into amd_init_de_cfg()
As amd_init_de_cfg() states, it's only safe for there to be one location writing to DE_CFG. This happens to be a latent bug rather than a real one because Fam12h CPUs aren't SMT-capable. Nevertheless, group it together with
the other DE_CFG modifications.
This removes a printk() which is not noteworthy, and skips the adjustment entirely under virt, where the attempted write wouldn't have stuck anyway.
Jan Beulich
Acked-byRe: [PATCH 1/3] x86/amd: Fold another DE_CFG edit into amd_init_de_cfg()
Quoted 10 lines · Andrew Cooper
Quoted 8 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
Fam12h processors aren't SMT-capable so there are no race condition worries with this path. Nevertheless, group it together with the other
DE_CFGmodifications.With this, ...
Quoted 1 line
Fixes d0c75dc4c028 ("x86/amd: Fix race editing DE_CFG")... isn't this more like Amends:? Aiui this wouldn't need backporting.
Quoted 8 lines
This does want backporting.
d0c75dc4c028explains how it's buggy to have multiple pieces of logic writing toDE_CFG, and here's yet another one.It's only a latent bug because Fam12 doesn't have CMT/SMT, and this property is not discussed, meaning that the logic as-is comes across as unsafe.
Hmm, this last part again leaves me with the impression that backport isn't strictly needed. (We often don't when addressing only a latent issue.)
Quoted 62 lines
Quoted 23 lines
Quoted 23 lines
xen/arch/x86/cpu/amd.c +7
-3@@ -920,6 +920,13 @@ void amd_init_de_cfg(const struct cpuinfo_x86 *c)if (zenbleed_use_chickenbit () ) new |= (1 <<9 ); +/* +* Erratum #665, doc 44739. Integer divide instructions may cause +* unpredictable behaviour. +*/ +if ( c->family ==0x12 ) + new |=1U <<31 ; +/* Avoid reading DE_CFG if we don't intend to change anything. */ if ( !new )return ;@@ -1201,15 +1208,6 @@ static void cf_check init_amd(struct cpuinfo_x86 *c) smp_processor_id());wrmsrl (MSR_AMD64_LS_CFG , value | (1 <<15 )); } - }else if (c->x86 ==0x12 ) { -rdmsrl (MSR_AMD64_DE_CFG , value); -if (!(value & (1U <<31 ))) {Quoted 8 lines
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1211
Quoted 7 lines
xen/arch/x86/cpu/amd.c +0
-6-if (c == &boot_cpu_data || opt_cpu_info) -printk_once (XENLOG_WARNING -"CPU%u: Applying workaround for erratum 665\n" , -smp_processor_id ()); -wrmsrl (MSR_AMD64_DE_CFG , value | (1U <<31 )); - } }Are you deliberately getting rid of the log message?
Yes, it's basically line noise.
Most errata like this are not handled at all, and this is not overly noteworthy. If it were at debug level then maybe, but certainly not at warning.
Fam12h were rare in the first place and are museum pieces these days.
Quoted 2 lines
And I assume it is deliberate that the adjustment no longer is done when we're running virtualized ourselves?
Of course. It's pointless, and a readback would show that the write had had no effect.
Quoted 2 lines
Both imo want making explicit in the description.
I've updated the commit message to:
x86/amd: Fold another
DE_CFGedit intoamd_init_de_cfg()
Asamd_init_de_cfg()states, it's only safe for there to be one location writing to DE_CFG. This happens to be a latent bug rather than a real one because Fam12h CPUs aren't SMT-capable. Nevertheless, group it together with
the otherDE_CFGmodifications.
This removes aprintk()which is not noteworthy, and skips the adjustment entirely under virt, where the attempted write wouldn't have stuck anyway.
Quoted 2 lines
Fixes d0c75dc4c028 ("x86/amd: Fix race editing DE_CFG")Signed-off-by Andrew Cooper <[email protected]>
Thanks, this reads good to me:
I'd like to understand the backporting (or not) aspect, though, in order to properly know whether to pick this up once you put it in.
Jan
PATCH 2/3 x86/amd: Exclude K8 RevD and earlier from levelling
In reply to Andrew CooperBetween RevD and RevE silicon, the feature MSRs moved location. This property is highlighted by the suggested workaround for Erratum #110 which gives the two different MSRs for the extended feature leaf.
The other feature MSRs are not given and while they're easy enough to figure out I don't have any K8's to test the result with.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/cpu/amd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
xen/arch/x86/cpu/amd.c +5 -3
@@ -117,10 +117,12 @@ static void __init noinline probe_masking_msrs(void)/* * First, work out which masking MSRs we should have, based on * revision and cpuid. +* +* Fam11h doesn't support masking at all. FamFh RevD and earlier had +* the feature MSRs in different locations, as can be seen by the +* suggested workaround for Erratum #110, docID 25759. */ - -/* Fam11 doesn't support masking at all. */ -if (c->x86 ==0x11 ) +if (c->family ==0x11 || (c->family ==0xf && c->model <0x20 ))return ; cpuidmask_defaults._1cd =
Signature · 1 line
2.39.5
Re: [PATCH 2/3] x86/amd: Exclude K8 RevD and earlier from levelling
Quoted 6 lines · Andrew Cooper
Between RevD and RevE silicon, the feature MSRs moved location. This property is highlighted by the suggested workaround for Erratum #110 which gives the two different MSRs for the extended feature leaf.
The other feature MSRs are not given and while they're easy enough to figure out I don't have any K8's to test the result with.
I can see where you're coming from, but shouldn't we then first document those extremely old models as unsupported in SUPPORT.md?
Jan
Re: [PATCH 2/3] x86/amd: Exclude K8 RevD and earlier from levelling
Quoted 9 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Between RevD and RevE silicon, the feature MSRs moved location. This property is highlighted by the suggested workaround for Erratum #110 which gives the two different MSRs for the extended feature leaf.
The other feature MSRs are not given and while they're easy enough to figure out I don't have any K8's to test the result with.
I can see where you're coming from, but shouldn't we then first document those extremely old models as unsupported in SUPPORT.md?
Not especially, no.
There are Intel CPUs with no levelling capabilities at all, that have no (non)support statement. The levelling on most AMD CPUs is incomplete too.
PV Guest Kernels are required to use FEP to get the Xen-approved version; it's only userspace which ends up adversely affected.
~Andrew
Jan Beulich
Acked-byRe: [PATCH 2/3] x86/amd: Exclude K8 RevD and earlier from levelling
Quoted 8 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Between RevD and RevE silicon, the feature MSRs moved location. This property is highlighted by the suggested workaround for Erratum #110 which gives the two different MSRs for the extended feature leaf.
The other feature MSRs are not given and while they're easy enough to figure out I don't have any K8's to test the result with.
Quoted 7 lines
Quoted 2 lines
I can see where you're coming from, but shouldn't we then first document those extremely old models as unsupported in SUPPORT.md?
Not especially, no.
There are Intel CPUs with no levelling capabilities at all, that have no (non)support statement. The levelling on most AMD CPUs is incomplete too.
Hmm, true.
Jan
PATCH 3/3 x86/amd: Delay amd_init_levelling() until after fixes to the CPUID MSRs
In reply to Andrew CooperThere's no need for amd_init_levelling() to be specifically early. In fact, it must be after init_amd() edits the feature MSRs, e.g. enabling TOPOEXT on Fam15h, or we revert the change on the next context switch.
As the only action in early_init_amd(), drop the function entirely.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/cpu/amd.c | 16 ++++++---------- xen/arch/x86/cpu/cpu.h | 2 +- xen/arch/x86/cpu/hygon.c | 6 +++++- 3 files changed, 12 insertions(+), 12 deletions(-)
xen/arch/x86/cpu/amd.c +6 -10
@@ -224,7 +224,7 @@ static const typeof(ctxt_switch_masking) __initconst_cf_clobber __used csm =* avoid this, as the accidentally-advertised features will not actually * function. */ -static void __init noinline amd_init_levelling(void) +void __init amd_init_levelling (void ) {/* * If there's support for CpuidUserDis or CPUID faulting then
@@ -617,14 +617,6 @@ void amd_process_freq(const struct cpuinfo_x86 *c, *low_mhz =amd_parse_freq (c->x86, lo); } -void cf_check early_init_amd(struct cpuinfo_x86 *c) -{ -if (c == &boot_cpu_data) -amd_init_levelling (); - -ctxt_switch_levelling (NULL ); -} -void amd_log_freq (const struct cpuinfo_x86 *c) {unsigned int low_mhz =0 , nom_mhz =0 , hi_mhz =0 ;
@@ -1270,10 +1262,14 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)check_syscfg_dram_mod_en ();amd_log_freq (c); + +if (c == &boot_cpu_data) +amd_init_levelling ();/* After CPUID MSR adjustments. */ + +ctxt_switch_levelling (NULL ); } const struct cpu_dev __initconst_cf_clobber amd_cpu_dev = { - .c_early_init = early_init_amd, .c_init = init_amd, };
xen/arch/x86/cpu/cpu.h +1 -1
@@ -22,9 +22,9 @@ extern void display_cacheinfo(struct cpuinfo_x86 *c);extern void detect_ht (struct cpuinfo_x86 *c);extern bool detect_extended_topology (struct cpuinfo_x86 *c); -void cf_check early_init_amd(struct cpuinfo_x86 *c);void amd_log_freq (const struct cpuinfo_x86 *c);void amd_init_de_cfg (const struct cpuinfo_x86 *c); +void amd_init_levelling (void );void amd_init_lfence_dispatch (void );void amd_init_ssbd (const struct cpuinfo_x86 *c);void amd_init_spectral_chicken (void );
xen/arch/x86/cpu/hygon.c +5 -1
@@ -90,9 +90,13 @@ static void cf_check init_hygon(struct cpuinfo_x86 *c) }amd_log_freq (c); + +if (c == &boot_cpu_data) +amd_init_levelling ();/* After CPUID MSR adjustments. */ + +ctxt_switch_levelling (NULL ); } const struct cpu_dev __initconst_cf_clobber hygon_cpu_dev = { - .c_early_init = early_init_amd, .c_init = init_hygon, };
Signature · 1 line
2.39.5
Re: [PATCH 3/3] x86/amd: Delay amd_init_levelling() until after fixes to the CPUID MSRs
Quoted 3 lines · Andrew Cooper
There's no need for
amd_init_levelling()to be specifically early. In fact, it must be afterinit_amd()edits the feature MSRs, e.g. enabling TOPOEXT on Fam15h, or we revert the change on the next context switch.
However, ...
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1270
Quoted 10 lines
xen/arch/x86/cpu/amd.c +5
-0@@ -1270,10 +1262,14 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)check_syscfg_dram_mod_en ();amd_log_freq (c); + +if (c == &boot_cpu_data) +amd_init_levelling ();/* After CPUID MSR adjustments. */ + +ctxt_switch_levelling (NULL ); }
... this new placement conflicts with the two RDSEED patches which have been pending for a while / too long. Even moving up wouldn't help, as the TOPOEXT re-enabling is after the switch() that the RDSEED changes are being fit into. Surely I could re-base accordingly, but it kind of feels that the older changes should go in first, with whatever adjustments necessary done either here, or (in a preparatory and agreed upon manner) right there, or entirely independently.
Looks like it would be possible to move the TOPOEXT re-enabling ahead of that very switch(), for the code above then to be inserted between that and said switch().
Jan
Re: [PATCH 3/3] x86/amd: Delay amd_init_levelling() until after fixes to the CPUID MSRs
Quoted 24 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
There's no need for
amd_init_levelling()to be specifically early. In fact, it must be afterinit_amd()edits the feature MSRs, e.g. enabling TOPOEXT on Fam15h, or we revert the change on the next context switch.However, ...
xen/arch/x86/cpu/amd.c static void cf_check init_amd(struct cpuinfo_x86 *c) · line 1270
Quoted 10 lines
xen/arch/x86/cpu/amd.c +5
-0@@ -1270,10 +1262,14 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)check_syscfg_dram_mod_en ();amd_log_freq (c); + +if (c == &boot_cpu_data) +amd_init_levelling ();/* After CPUID MSR adjustments. */ + +ctxt_switch_levelling (NULL ); }... this new placement conflicts with the two RDSEED patches which have been pending for a while / too long. Even moving up wouldn't help, as the TOPOEXT re-enabling is after the
switch()that the RDSEED changes are being fit into. Surely I could re-base accordingly, but it kind of feels that the older changes should go in first, with whatever adjustments necessary done either here, or (in a preparatory and agreed upon manner) right there, or entirely independently.
Quoted 3 lines
Looks like it would be possible to move the TOPOEXT re-enabling ahead of that very
switch(), for the code above then to be inserted between that and saidswitch().
The NX fixes also need to re-activate a CPUID bit, so I'm going to have to rework this all differently anyway.
~Andrew