x86: Feature check cleanup
cover x86: Feature check cleanup
This builds on the work from "[PATCH 0/6] x86: Introduce MSR_ARCH_CAPS into featuresets" and is just cleanup to feature handling.
No functional change.
Andrew Cooper (4):
x86/cpufeature: Rework {boot_,}cpu_has() x86/vtx: Remove opencoded MSR_ARCH_CAPS check x86/tsx: Remove opencoded MSR_ARCH_CAPS check x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
xen/arch/x86/hvm/vmx/vmx.c | 8 +--- xen/arch/x86/include/asm/cpufeature.h | 24 ++++++++++-- xen/arch/x86/include/asm/processor.h | 2 +- xen/arch/x86/spec_ctrl.c | 56 +++++++++++++-------------- xen/arch/x86/tsx.c | 13 ++++--- 5 files changed, 58 insertions(+), 45 deletions(-)
base-commit: 8f9c8274a4e3e860bd777269cb2c91971e9fa69e
prerequisite-patch-id: ceeba7d5ab9498cb188e5012953c7e8c9a86347d
prerequisite-patch-id: c0957b9e1157ae6eb8de973c96716fd02587c486
prerequisite-patch-id: d2574bba15748cd021e5b33fa50e6cadc38863b6
prerequisite-patch-id: 0f66cd4287ffdc06f24dc01c7d26fb428f3e8c09
prerequisite-patch-id: a585f61b546ff96be3624ff253f8100b2f465de6
prerequisite-patch-id: 54551cdefaca083b4a4b97528d27d0f3dc9753ee
prerequisite-patch-id: 051423463e4a34728ab524f03e801e7103777684
Signature · 1 line
2.30.2
PATCH 1/4 x86/cpufeature: Rework {boot_,}cpu_has()
One area where Xen deviates from Linux is that test_bit() forces a volatile read. This leads to poor code generation, because the optimiser cannot merge bit operations on the same word.
Drop the use of test_bit(), and write the expressions in regular C. This removes the include of bitops.h (which is a frequent source of header tangles), and it offers the optimiser far more flexibility.
Bloat-o-meter reports a net change of:
add/remove: 0/0 grow/shrink: 21/87 up/down: 641/-2751 (-2110)
with half of that in x86_emulate() alone. vmx_ctxt_switch_to() seems to be the fastpath with the greatest delta at -24, where the optimiser has successfully removed the branch hidden in cpu_has_msr_tsc_aux.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/cpufeature.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/cpufeature.h +10 -3
@@ -7,6 +7,7 @@#define __ASM_I386_CPUFEATURE_H#include <xen/const.h> +#include <xen/stdbool.h> #include <asm/cpuid.h> #define cpufeat_word (idx) ((idx) / 32)
@@ -17,7 +18,6 @@#define X86_FEATURE_ALWAYS X86_FEATURE_LM #ifndef __ASSEMBLY__ -#include <xen/bitops.h> struct cpuinfo_x86 { unsigned char x86; /* CPU family */
@@ -43,8 +43,15 @@ struct cpuinfo_x86 {extern struct cpuinfo_x86 boot_cpu_data; -#define cpu_has (c, bit) test_bit(bit, (c)->x86_capability) -#define boot_cpu_has (bit) test_bit(bit, boot_cpu_data.x86_capability) +static inline bool cpu_has (const struct cpuinfo_x86 *info,unsigned int feat) +{ +return info->x86_capability[cpufeat_word (feat)] &cpufeat_mask (feat); +} + +static inline bool boot_cpu_has (unsigned int feat) +{ +return cpu_has (&boot_cpu_data, feat); +}#define CPUID_PM_LEAF 6#define CPUID6_ECX_APERFMPERF_CAPABILITY 0x1
base-commit: 8f9c8274a4e3e860bd777269cb2c91971e9fa69e
prerequisite-patch-id: ceeba7d5ab9498cb188e5012953c7e8c9a86347d
prerequisite-patch-id: c0957b9e1157ae6eb8de973c96716fd02587c486
prerequisite-patch-id: d2574bba15748cd021e5b33fa50e6cadc38863b6
prerequisite-patch-id: 0f66cd4287ffdc06f24dc01c7d26fb428f3e8c09
prerequisite-patch-id: a585f61b546ff96be3624ff253f8100b2f465de6
prerequisite-patch-id: 54551cdefaca083b4a4b97528d27d0f3dc9753ee
prerequisite-patch-id: 051423463e4a34728ab524f03e801e7103777684
Signature · 1 line
2.30.2
Re: [PATCH 1/4] x86/cpufeature: Rework {boot_,}cpu_has()
xen/arch/x86/include/asm/cpufeature.h line 11
Quoted 8 lines · Andrew Cooper
xen/arch/x86/include/asm/cpufeature.h +1
-0@@ -7,6 +7,7 @@#define __ASM_I386_CPUFEATURE_H#include <xen/const.h> +#include <xen/stdbool.h> #include <asm/cpuid.h>
This isn't needed up here, and ...
xen/arch/x86/include/asm/cpufeature.h line 20
Quoted 5 lines
xen/arch/x86/include/asm/cpufeature.h +0
-1@@ -17,7 +18,6 @@#define X86_FEATURE_ALWAYS X86_FEATURE_LM#ifndef __ASSEMBLY__ -#include <xen/bitops.h>
... putting it here would (a) eliminate a header dependency for assembly sources including this file (perhaps indirectly) and (b) eliminate the risk of a build breakage if something was added to that header which isn't valid assembly.
Preferably with the adjustment
Jan
Re: [PATCH 1/4] x86/cpufeature: Rework {boot_,}cpu_has()
Quoted 14 lines · Jan Beulich
xen/arch/x86/include/asm/cpufeature.h line 11
Quoted 8 lines · Andrew Cooper
xen/arch/x86/include/asm/cpufeature.h +1
-0@@ -7,6 +7,7 @@#define __ASM_I386_CPUFEATURE_H#include <xen/const.h> +#include <xen/stdbool.h> #include <asm/cpuid.h> This isn't needed up here, and ...
Quoted 3 lines
xen/arch/x86/include/asm/cpufeature.h +0
-0@@ -17,7 +18,6 @@#define X86_FEATURE_ALWAYS X86_FEATURE_LM
Quoted 6 lines
xen/arch/x86/include/asm/cpufeature.h line 20
Quoted 2 lines
xen/arch/x86/include/asm/cpufeature.h +0
-1#ifndef __ASSEMBLY__ -#include <xen/bitops.h> ... putting it here would (a) eliminate a header dependency for assembly sources including this file (perhaps indirectly) and (b) eliminate the risk of a build breakage if something was added to that header which isn't valid assembly.
b) That's a weak argument for headers in general, but you're saying it about our copy of stdbool.h which probably the least likely header for that ever to be true.
a) Not really, because cpuid.h pulls in a reasonable chunk of the world, including types.h and therefore stdbool.h. cpuid.h is necessary to make the X86_FEATURE_ALWAYS -> X86_FEATURE_LM, which is used by asm for alternatives.
I'm tempted to just omit it. cpufeature.h has one of the most tangled set of headers we've got, and I can't find any reasonable way to make it less bad.
Quoted 2 lines
Preferably with the adjustment
Reviewed-by Jan Beulich <[email protected]>
Thanks,
~Andrew
Re: [PATCH 1/4] x86/cpufeature: Rework {boot_,}cpu_has()
Quoted 26 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
xen/arch/x86/include/asm/cpufeature.h line 11
Quoted 8 lines · Andrew Cooper
xen/arch/x86/include/asm/cpufeature.h +1
-0@@ -7,6 +7,7 @@#define __ASM_I386_CPUFEATURE_H#include <xen/const.h> +#include <xen/stdbool.h> #include <asm/cpuid.h> This isn't needed up here, and ...
Quoted 3 lines
xen/arch/x86/include/asm/cpufeature.h +0
-0@@ -17,7 +18,6 @@#define X86_FEATURE_ALWAYS X86_FEATURE_LMQuoted 6 lines
xen/arch/x86/include/asm/cpufeature.h line 20
Quoted 2 lines
xen/arch/x86/include/asm/cpufeature.h +0
-1#ifndef __ASSEMBLY__ -#include <xen/bitops.h> ... putting it here would (a) eliminate a header dependency for assembly sources including this file (perhaps indirectly) and (b) eliminate the risk of a build breakage if something was added to that header which isn't valid assembly.
b) That's a weak argument for headers in general, but you're saying it about our copy of
stdbool.hwhich probably the least likely header for that ever to be true.
Quoted 8 lines
a) Not really, because
cpuid.hpulls in a reasonable chunk of the world, includingtypes.hand therefore stdbool.h.cpuid.his necessary to make theX86_FEATURE_ALWAYS->X86_FEATURE_LM, which is used by asm for alternatives.I'm tempted to just omit it.
cpufeature.hhas one of the most tangled set of headers we've got, and I can't find any reasonable way to make it less bad.
Yeah, omitting would certainly be fine with me.
Jan
PATCH 2/4 x86/vtx: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperMSR_ARCH_CAPS data is now included in featureset information.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>
--- xen/arch/x86/hvm/vmx/vmx.c | 8 ++------ xen/arch/x86/include/asm/cpufeature.h | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +2 -6
@@ -2849,8 +2849,6 @@ static void __init ler_to_fixup_check(void);*/ static bool __init has_if_pschange_mc (void ) { -uint64_t caps =0 ; -/* * If we are virtualised, there is nothing we can do. Our EPT tables are * shadowed by our hypervisor, and not walked by hardware.
@@ -2858,10 +2856,8 @@ static bool __init has_if_pschange_mc(void)if ( cpu_has_hypervisor )return false; -if ( cpu_has_arch_caps ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps); - -if ( caps &ARCH_CAPS_IF_PSCHANGE_MC_NO ) +/* Hardware reports itself as fixed. */ +if ( cpu_has_if_pschange_mc_no )return false;/*
xen/arch/x86/include/asm/cpufeature.h +3 -0
@@ -183,6 +183,9 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx_vnni_int8 boot_cpu_has(X86_FEATURE_AVX_VNNI_INT8)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT) +/* MSR_ARCH_CAPS 10A */ +#define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO) +/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)#define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING)
Signature · 1 line
2.30.2
Re: [PATCH 2/4] x86/vtx: Remove opencoded MSR_ARCH_CAPS check
Quoted 3 lines · Andrew Cooper
MSR_ARCH_CAPSdata is now included in featureset information.Signed-off-by Andrew Cooper <[email protected]>
albeit, like in one of the patches in the earlier series, ...
xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned int feat) · line 187
Quoted 8 lines
xen/arch/x86/include/asm/cpufeature.h +2
-0@@ -183,6 +183,9 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx_vnni_int8 boot_cpu_has(X86_FEATURE_AVX_VNNI_INT8)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT) +/* MSR_ARCH_CAPS 10A */ +#define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO)
... I'm not convinced that having the (unadorned) MSR index here is really helpful. In particular to people not knowing the indexes by heart (possibly most except you) the number may actually look odd / misplaced there.
Jan
Jan Beulich
Reviewed-byRe: [PATCH 2/4] x86/vtx: Remove opencoded MSR_ARCH_CAPS check
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Andrew Cooper
MSR_ARCH_CAPSdata is now included in featureset information.Signed-off-by Andrew Cooper <[email protected]>Acked-by Jan Beulich <[email protected]>
Oops - this was really meant to be
Jan
Quoted 18 lines
albeit, like in one of the patches in the earlier series, ...
xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned int feat) · line 187
Quoted 8 lines
xen/arch/x86/include/asm/cpufeature.h +2
-0@@ -183,6 +183,9 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx_vnni_int8 boot_cpu_has(X86_FEATURE_AVX_VNNI_INT8)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT) +/* MSR_ARCH_CAPS 10A */ +#define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO)... I'm not convinced that having the (unadorned) MSR index here is really helpful. In particular to people not knowing the indexes by heart (possibly most except you) the number may actually look odd / misplaced there.
Jan
RE: [PATCH 2/4] x86/vtx: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperQuoted 6 lines
From: Andrew Cooper <[email protected]>
Sent: Tuesday, May 16, 2023 10:54 PM
MSR_ARCH_CAPSdata is now included in featureset information.Signed-off-by Andrew Cooper <[email protected]>
PATCH 3/4 x86/tsx: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperThe current cpu_has_tsx_ctrl tristate is serving double pupose; to signal the first pass through tsx_init(), and the availability of MSR_TSX_CTRL.
Drop the variable, replacing it with a once boolean, and altering cpu_has_tsx_ctrl to come out of the feature information.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/processor.h | 2 +- xen/arch/x86/tsx.c | 13 ++++++++----- 3 files changed, 10 insertions(+), 6 deletions(-)
xen/arch/x86/include/asm/cpufeature.h +1 -0
@@ -185,6 +185,7 @@ static inline bool boot_cpu_has(unsigned int feat)/* MSR_ARCH_CAPS 10A */ #define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO) +#define cpu_has_tsx_ctrl boot_cpu_has(X86_FEATURE_TSX_CTRL)/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
xen/arch/x86/include/asm/processor.h +1 -1
@@ -535,7 +535,7 @@ static inline uint8_t get_cpu_family(uint32_t raw, uint8_t *model,return fam; } -extern int8_t opt_tsx, cpu_has_tsx_ctrl; +extern int8_t opt_tsx;extern bool rtm_disabled;void tsx_init (void );
xen/arch/x86/tsx.c +8 -5
@@ -19,7 +19,6 @@* controlling TSX behaviour, and where TSX isn't force-disabled by firmware. */ int8_t __read_mostly opt_tsx =-1 ; -int8_t __read_mostly cpu_has_tsx_ctrl =-1 ;bool __read_mostly rtm_disabled; static int __init cf_check parse_tsx(const char *s)
@@ -37,24 +36,28 @@ custom_param("tsx", parse_tsx);void tsx_init (void ) { +static bool __read_mostly once; +/* * This function is first called between microcode being loaded, and CPUID * being scanned generally. Read into boot_cpu_data.x86_capability[] for * the cpu_has_* bits we care about using here. */ -if (unlikely (cpu_has_tsx_ctrl <0 ) ) +if (unlikely (!once) ) { -uint64_t caps =0 ;bool has_rtm_always_abort; + once = true; +if ( boot_cpu_data.cpuid_level >=7 ) boot_cpu_data.x86_capability[FEATURESET_7d0] =cpuid_count_edx (7 ,0 );if ( cpu_has_arch_caps ) -rdmsrl (MSR_ARCH_CAPABILITIES , caps); +rdmsr (MSR_ARCH_CAPABILITIES , + boot_cpu_data.x86_capability[FEATURESET_10Al], + boot_cpu_data.x86_capability[FEATURESET_10Ah]); - cpu_has_tsx_ctrl = !!(caps &ARCH_CAPS_TSX_CTRL ); has_rtm_always_abort = cpu_has_rtm_always_abort;if ( cpu_has_tsx_ctrl && cpu_has_srbds_ctrl )
Signature · 1 line
2.30.2
Re: [PATCH 3/4] x86/tsx: Remove opencoded MSR_ARCH_CAPS check
Quoted 9 lines · Andrew Cooper
The current
cpu_has_tsx_ctrltristate is serving double pupose; to signal the first pass throughtsx_init(), and the availability ofMSR_TSX_CTRL.Drop the variable, replacing it with a once boolean, and altering
cpu_has_tsx_ctrlto come out of the feature information.No functional change.
Signed-off-by Andrew Cooper <[email protected]>
PATCH 4/4 x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
In reply to Andrew CooperMSR_ARCH_CAPS data is now included in featureset information. Replace opencoded checks with regular feature ones.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/arch/x86/include/asm/cpufeature.h | 7 ++++ xen/arch/x86/spec_ctrl.c | 56 +++++++++++++-------------- 2 files changed, 33 insertions(+), 30 deletions(-)
xen/arch/x86/include/asm/cpufeature.h +7 -0
@@ -184,8 +184,15 @@ static inline bool boot_cpu_has(unsigned int feat)#define cpu_has_avx_ne_convert boot_cpu_has(X86_FEATURE_AVX_NE_CONVERT)/* MSR_ARCH_CAPS 10A */ +#define cpu_has_rdcl_no boot_cpu_has(X86_FEATURE_RDCL_NO) +#define cpu_has_eibrs boot_cpu_has(X86_FEATURE_EIBRS) +#define cpu_has_rsba boot_cpu_has(X86_FEATURE_RSBA) +#define cpu_has_skip_l1dfl boot_cpu_has(X86_FEATURE_SKIP_L1DFL) +#define cpu_has_mds_no boot_cpu_has(X86_FEATURE_MDS_NO)#define cpu_has_if_pschange_mc_no boot_cpu_has(X86_FEATURE_IF_PSCHANGE_MC_NO)#define cpu_has_tsx_ctrl boot_cpu_has(X86_FEATURE_TSX_CTRL) +#define cpu_has_taa_no boot_cpu_has(X86_FEATURE_TAA_NO) +#define cpu_has_fb_clear boot_cpu_has(X86_FEATURE_FB_CLEAR)/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)
xen/arch/x86/spec_ctrl.c +26 -30
183 lines not on this page · raw message
Signature · 1 line
2.30.2
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); +if ( cpu_has_arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);
Why do you read the MSR again? I would have expected this to come out of raw_cpu_policy now (and incrementally the CPUID pieces as well, later on).
Apart from this, with all the uses further down gone, perhaps there's not even a need for the raw value, if you used the bitfields in the printk(). Which in turn raises the question whether the #define-s in msr-index.h are of much use then anymore.
Jan
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 10 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); +if ( cpu_has_arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);Why do you read the MSR again? I would have expected this to come out of
raw_cpu_policynow (and incrementally the CPUID pieces as well, later on).
Consistency with the surrounding logic.
Also because the raw and host policies don't get sorted until much later in boot.
Quoted 4 lines
Apart from this, with all the uses further down gone, perhaps there's not even a need for the raw value, if you used the bitfields in the
printk(). Which in turn raises the question whether the #define-s inmsr-index.hare of much use then anymore.
One of the next phases of work is synthesizing these in the host policy for CPUs which didn't receive microcode updates (for whatever reason).
There is a valid discussion for whether we ought to render the raw or host info here (currently we do raw), but I'm not adjusting that in this patch.
~Andrew
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 12 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); +if ( cpu_has_arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);Why do you read the MSR again? I would have expected this to come out of
raw_cpu_policynow (and incrementally the CPUID pieces as well, later on).
Quoted 1 line
Consistency with the surrounding logic.
I view this as relevant only when the code invoking CPUID directly is intended to stay.
Quoted 2 lines
Also because the raw and host policies don't get sorted until much later in boot.
identify_cpu(), which invokes init_host_cpu_policies(), is called ahead of init_speculation_mitigations(), isn't it?
Quoted 11 lines
Quoted 4 lines
Apart from this, with all the uses further down gone, perhaps there's not even a need for the raw value, if you used the bitfields in the
printk(). Which in turn raises the question whether the #define-s inmsr-index.hare of much use then anymore.One of the next phases of work is synthesizing these in the host policy for CPUs which didn't receive microcode updates (for whatever reason).
There is a valid discussion for whether we ought to render the raw or host info here (currently we do raw), but I'm not adjusting that in this patch.
In the end I think both have their merits to log. So far it was my assumption that "Hardware {hints,features}:" was intended to cover raw, while "Xen settings:" was meaning to be close to "host" (but of course there's quite a bit of a delta).
Jan
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); +if ( cpu_has_arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);Why do you read the MSR again? I would have expected this to come out of
raw_cpu_policynow (and incrementally the CPUID pieces as well, later on).
Quoted 3 lines
Quoted 1 line
Consistency with the surrounding logic.
I view this as relevant only when the code invoking CPUID directly is intended to stay.
Quite the contrary. It stays because this patch, and changing the semantics of the print block are unrelated things and should not be mixed together.
Quoted 4 lines
Quoted 2 lines
Also because the raw and host policies don't get sorted until much later in boot.
identify_cpu(), which invokesinit_host_cpu_policies(), is called ahead ofinit_speculation_mitigations(), isn't it?
What is init_host_cpu_policies() ?
I have a plan for what it's going to be if prior MSR work hadn't ground to a halt, but it's a bit too late for that now.
(To answer the question properly, no the policies aren't set up until just before building dom0, and that's not something that is trivial to change.)
~Andrew
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); +if ( cpu_has_arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);Why do you read the MSR again? I would have expected this to come out of
raw_cpu_policynow (and incrementally the CPUID pieces as well, later on).
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Consistency with the surrounding logic.
I view this as relevant only when the code invoking CPUID directly is intended to stay.
Quite the contrary. It stays because this patch, and changing the semantics of the print block are unrelated things and should not be mixed together.
Hmm. On one hand I can see your point, yet otoh we move things in a longer term intended direction in other cases where we need to touch code anyway. While I'm not going to refuse to ack this change just because of this, I don't fell like you've answered the original question. In particular I don't see how taking the value from a memory location we've already cached it in is changing any semantics here. While some masking may apply even to the raw policy (to zap unknown bits), this should be meaningless here. No bit used here should be unmentioned in the policy.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Also because the raw and host policies don't get sorted until much later in boot.
identify_cpu(), which invokesinit_host_cpu_policies(), is called ahead ofinit_speculation_mitigations(), isn't it?What is
init_host_cpu_policies()?
Oops. I did use my own tree as reference during review. See the long pending "x86/xstate: drop xstate_offsets[] and xstate_sizes[]" [1]. Maybe you simply didn't tell me yet ...
Quoted 6 lines
I have a plan for what it's going to be if prior MSR work hadn't ground to a halt, but it's a bit too late for that now.
(To answer the question properly, no the policies aren't set up until just before building dom0, and that's not something that is trivial to change.)
... that what I'm doing there is too simplistic?
Jan
[1] https://lists.xen.org/archives/html/xen-devel/2021-04/msg01335.html
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 20 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
xen/arch/x86/spec_ctrl.c static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
xen/arch/x86/spec_ctrl.c +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps)cpuid_count (7 ,2 , &tmp, &tmp, &tmp, &_7d2);if ( boot_cpu_data.extended_cpuid_level >=0x80000008 )cpuid (0x80000008 , &tmp, &e8b, &tmp, &tmp); +if ( cpu_has_arch_caps ) +rdmsrl (MSR_ARCH_CAPABILITIES , caps);Why do you read the MSR again? I would have expected this to come out of
raw_cpu_policynow (and incrementally the CPUID pieces as well, later on).Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Consistency with the surrounding logic.
I view this as relevant only when the code invoking CPUID directly is intended to stay.
Quite the contrary. It stays because this patch, and changing the semantics of the print block are unrelated things and should not be mixed together.
Quoted 8 lines
Hmm. On one hand I can see your point, yet otoh we move things in a longer term intended direction in other cases where we need to touch code anyway. While I'm not going to refuse to ack this change just because of this, I don't fell like you've answered the original question. In particular I don't see how taking the value from a memory location we've already cached it in is changing any semantics here. While some masking may apply even to the raw policy (to zap unknown bits), this should be meaningless here. No bit used here should be unmentioned in the policy.
The very next thing I'm going to need to do is start synthesizing arch caps bits for the hardware with known properties but without appropriate enumerations. This is necessary to make migration work.
Because we have not taken a decision about the what printed block means, it needs to not change when I start using setup_force_cpu_cap().
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
Also because the raw and host policies don't get sorted until much later in boot.
identify_cpu(), which invokesinit_host_cpu_policies(), is called ahead ofinit_speculation_mitigations(), isn't it?What is
init_host_cpu_policies()?Oops. I did use my own tree as reference during review. See the long pending "x86/xstate: drop xstate_offsets[] and xstate_sizes[]" [1]. Maybe you simply didn't tell me yet ...
Quoted 7 lines
Quoted 6 lines
I have a plan for what it's going to be if prior MSR work hadn't ground to a halt, but it's a bit too late for that now.
(To answer the question properly, no the policies aren't set up until just before building dom0, and that's not something that is trivial to change.)
... that what I'm doing there is too simplistic?
Raw is fine. I found complexities with Host when doing that.
~Andrew
Re: [PATCH 4/4] x86/spec-ctrl: Remove opencoded MSR_ARCH_CAPS check
Quoted 30 lines · Andrew Cooper
Quoted 20 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Jan Beulich
Review static void __init print_details(enum ind_thunk thunk, uint64_t caps) · line 404
Quoted 6 lines · Andrew Cooper
(quoted diff) +2
-0@@ -401,6 +400,8 @@ static void __init print_details(enum ind_thunk thunk, uint64_t caps) cpuid_count(7, 2, &tmp, &tmp, &tmp, &_7d2); if ( boot_cpu_data.extended_cpuid_level >= 0x80000008 ) cpuid(0x80000008, &tmp, &e8b, &tmp, &tmp); + if ( cpu_has_arch_caps ) + rdmsrl(MSR_ARCH_CAPABILITIES, caps);Why do you read the MSR again? I would have expected this to come out of
raw_cpu_policynow (and incrementally the CPUID pieces as well, later on).Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Consistency with the surrounding logic.
I view this as relevant only when the code invoking CPUID directly is intended to stay.
Quite the contrary. It stays because this patch, and changing the semantics of the print block are unrelated things and should not be mixed together.
Quoted 8 lines
Hmm. On one hand I can see your point, yet otoh we move things in a longer term intended direction in other cases where we need to touch code anyway. While I'm not going to refuse to ack this change just because of this, I don't fell like you've answered the original question. In particular I don't see how taking the value from a memory location we've already cached it in is changing any semantics here. While some masking may apply even to the raw policy (to zap unknown bits), this should be meaningless here. No bit used here should be unmentioned in the policy.
Quoted 3 lines
The very next thing I'm going to need to do is start synthesizing arch caps bits for the hardware with known properties but without appropriate enumerations. This is necessary to make migration work.
But you wouldn't alter the raw featureset, would you? As much as ...
Quoted 2 lines
Because we have not taken a decision about the what printed block means, it needs to not change when I start using
setup_force_cpu_cap().
... setup_force_cpu_cap() doesn't affect raw.
Jan