x86/cpu, kvm: Support AMD Automatic IBRS
Subsystems (5)
v6 cover x86/cpu, kvm: Support AMD Automatic IBRS
The AMD Zen4 core supports a new feature called Automatic IBRS (Indirect Branch Restricted Speculation).
Enable Automatic IBRS by default if the CPU feature is present. It typically provides greater performance over the incumbent generic retpolines mitigation.
Patch 1 adds support for the whole leaf that contains the AutoIBRS feature bit.
Patches 2-5 mainly move the existing features over from scattered / open-coded in KVM into the new shared leaf, where they match hardware.
Patch 6 Adds support for AutoIBRS by turning its EFER enablement bit on at startup if the feature is available.
Patch 7 Adds support for propagating AutoIBRS to the guest.
v6: Address v5 comment from Boris:
- Move CPUID leaf 0x8000021 EAX feature bits from scattered to the new whole leaf since the majority of the features will be used in the kernel and thus a separate leaf is appropriate.
v5: https://lore.kernel.org/lkml/[email protected]/
Address v4 comments from Dave Hansen, Pawan Gupta, and Boris:
- Don't add new user-visible 'autoibrs' command line
options that we have to document: reuse 'eibrs'
- Update Documentation/admin-guide/hw-vuln/spectre.rst
- Add NO_EIBRS_PBRSB to Hygon as well
- Re-word commit texts to not use words like 'us'
v4: https://lore.kernel.org/lkml/[email protected]/
Moved some kvm bits that had crept into patch 6/7 back into 7/7, and addressed v3 comments:
- Don't put ", kvm" in titles of patches that don't touch kvm. [SeanC]
- () after function names, i.e. kvm_set_cpu_caps(). [SeanC]
- follow the established kvm_cpu_cap_init_scattered() style [SeanC]
- Add using cpu_feature_enabled() instead of static_cpu_has() to commit text [SeanC]
- Pawan Gupta mentioned that the ordering of enabling the Intel feature bit past Intel EIBRS bug detection could be avoided by setting NO_EIBRS_PBRSB to cpu_vuln_whitelist, so did that which allowed regrouping all EIBRS related code to one place in cpu_set_bug_bits().
v3: https://lore.kernel.org/lkml/[email protected]/
- Remove Co-developed-bys. They require signed-off-bys,
so co-developers need to add them themselves.
- update check_null_seg_clears_base() [Boris]
- Made the feature bit additions separate patches
because v2 patch was clearly doing too many things at once.
v2: https://lore.kernel.org/lkml/[email protected]/
https://lkml.org/lkml/2022/11/23/1690
- Use synthetic/scattered bits instead of introducing new leaf [Boris]
- Combine the rest of the leaf's bits being used [Paolo]
Note: Bits not used by the host can be moved to kvm/cpuid.c if maintainers do not want them in cpufeatures.h.
- Hoist bitsetting code to kvm_set_cpu_caps(), and use cpuid_entry_override() in __do_cpuid_func() [Paolo]
- Reuse SPECTRE_V2_EIBRS spectre_v2_mitigation enum [Boris, PeterZ, D.Hansen]
- Change from Boris' diff:
Moved setting X86_FEATURE_IBRS_ENHANCED to after BUG_EIBRS_PBRSB so PBRSB mitigations wouldn't be enabled.
- Allow for users to specify "autoibrs,lfence/retpoline" instead of actively preventing the extra protections. AutoIBRS doesn't require the extra protection, but we allow it anyway.
v1: https://lore.kernel.org/lkml/[email protected]/
Kim Phillips (7):
x86/cpu, kvm: Add support for cpuid leaf 80000021/EAX (FeatureExt2Eax) x86/cpu, kvm: Add the NO_NESTED_DATA_BP feature
x86/cpu, kvm: Move the LFENCE_RDTSC / LFENCE always serializing
feature
x86/cpu, kvm: Add the Null Selector Clears Base feature x86/cpu, kvm: Add the SMM_CTL MSR not present feature x86/cpu: Support AMD Automatic IBRS
x86/cpu, kvm: Propagate the AMD Automatic IBRS feature to the guest
Documentation/admin-guide/hw-vuln/spectre.rst | 6 ++-- .../admin-guide/kernel-parameters.txt | 6 ++-- arch/x86/include/asm/cpufeature.h | 7 +++-- arch/x86/include/asm/cpufeatures.h | 11 +++++-- arch/x86/include/asm/disabled-features.h | 3 +- arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/include/asm/required-features.h | 3 +- arch/x86/kernel/cpu/bugs.c | 20 ++++++++----- arch/x86/kernel/cpu/common.c | 22 +++++++++----- arch/x86/kvm/cpuid.c | 30 +++++++------------ arch/x86/kvm/reverse_cpuid.h | 1 + arch/x86/kvm/svm/svm.c | 3 ++ arch/x86/kvm/x86.c | 3 ++ 13 files changed, 70 insertions(+), 47 deletions(-)
Signature · 1 line
2.34.1
PATCH v6 1/7 x86/cpufeatures: Add support for cpuid leaf 80000021/EAX (FeatureExt2Eax)
Add the 80000021/EAX leaf that advertises features for modern Zen processors . The majority of the features will be used in the kernel and thus a separate leaf is appropriate. Include KVM's reverse_cpuid entry because features are used by VM guests, too.
--- arch/x86/include/asm/cpufeature.h | 7 +++++-- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/disabled-features.h | 3 ++- arch/x86/include/asm/required-features.h | 3 ++- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kvm/reverse_cpuid.h | 1 + 6 files changed, 14 insertions(+), 5 deletions(-)
arch/x86/include/asm/cpufeature.h +5 -2
@@ -32,6 +32,7 @@ enum cpuid_leafsCPUID_8000_0007_EBX ,CPUID_7_EDX ,CPUID_8000_001F_EAX , + CPUID_8000_0021_EAX, };#define X86_CAP_FMT_NUM "%d:%d"
@@ -94,8 +95,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) || \ + CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 20, feature_bit) || \ REQUIRED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 20)) + BUILD_BUG_ON_ZERO(NCAPINTS != 21))#define DISABLED_MASK_BIT_SET (feature_bit) \ ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
@@ -118,8 +120,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) || \ + CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 20, feature_bit) || \ DISABLED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 20)) + BUILD_BUG_ON_ZERO(NCAPINTS != 21))#define cpu_has (c, bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -13,7 +13,7 @@/* * Defines x86 CPU feature bits */ -#define NCAPINTS 20/* N 32-bit words worth of info */ +#define NCAPINTS 21/* N 32-bit words worth of info */ #define NBUGINTS 1/* N 32-bit bug flags */ /*
arch/x86/include/asm/disabled-features.h +2 -1
@@ -124,6 +124,7 @@#define DISABLED_MASK17 0#define DISABLED_MASK18 0#define DISABLED_MASK19 0 -#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) +#define DISABLED_MASK20 0 +#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)#endif /* _ASM_X86_DISABLED_FEATURES_H */
arch/x86/include/asm/required-features.h +2 -1
@@ -98,6 +98,7 @@#define REQUIRED_MASK17 0#define REQUIRED_MASK18 0#define REQUIRED_MASK19 0 -#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) +#define REQUIRED_MASK20 0 +#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)#endif /* _ASM_X86_REQUIRED_FEATURES_H */
arch/x86/kernel/cpu/common.c +3 -0
@@ -1093,6 +1093,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)if (c->extended_cpuid_level >=0x8000001f ) c->x86_capability[CPUID_8000_001F_EAX ] =cpuid_eax (0x8000001f ); +if (c->extended_cpuid_level >=0x80000021 ) + c->x86_capability[CPUID_8000_0021_EAX ] =cpuid_eax (0x80000021 ); +init_scattered_cpuid_features (c);init_speculation_control (c);
arch/x86/kvm/reverse_cpuid.h +1 -0
@@ -68,6 +68,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, [CPUID_7_1_EDX] = { 7, 1, CPUID_EDX}, + [CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX}, };/*
Signature · 1 line
2.34.1
PATCH v6 1/7 x86/cpu, kvm: Add support for cpuid leaf 80000021/EAX (FeatureExt2Eax)
In reply to Kim PhillipsAdd the 80000021/EAX leaf that advertises features in later Zen processors. The majority of the features will be used in the kernel and thus a separate leaf is appropriate.
Include KVM's reverse_cpuid entry because features are used by VM guests, too.
--- arch/x86/include/asm/cpufeature.h | 7 +++++-- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/disabled-features.h | 3 ++- arch/x86/include/asm/required-features.h | 3 ++- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kvm/reverse_cpuid.h | 1 + 6 files changed, 14 insertions(+), 5 deletions(-)
arch/x86/include/asm/cpufeature.h +5 -2
@@ -32,6 +32,7 @@ enum cpuid_leafsCPUID_8000_0007_EBX ,CPUID_7_EDX ,CPUID_8000_001F_EAX , + CPUID_8000_0021_EAX, };#define X86_CAP_FMT_NUM "%d:%d"
@@ -94,8 +95,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) || \ + CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 20, feature_bit) || \ REQUIRED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 20)) + BUILD_BUG_ON_ZERO(NCAPINTS != 21))#define DISABLED_MASK_BIT_SET (feature_bit) \ ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
@@ -118,8 +120,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) || \ + CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 20, feature_bit) || \ DISABLED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 20)) + BUILD_BUG_ON_ZERO(NCAPINTS != 21))#define cpu_has (c, bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -13,7 +13,7 @@/* * Defines x86 CPU feature bits */ -#define NCAPINTS 20/* N 32-bit words worth of info */ +#define NCAPINTS 21/* N 32-bit words worth of info */ #define NBUGINTS 1/* N 32-bit bug flags */ /*
arch/x86/include/asm/disabled-features.h +2 -1
@@ -124,6 +124,7 @@#define DISABLED_MASK17 0#define DISABLED_MASK18 0#define DISABLED_MASK19 0 -#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) +#define DISABLED_MASK20 0 +#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)#endif /* _ASM_X86_DISABLED_FEATURES_H */
arch/x86/include/asm/required-features.h +2 -1
@@ -98,6 +98,7 @@#define REQUIRED_MASK17 0#define REQUIRED_MASK18 0#define REQUIRED_MASK19 0 -#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) +#define REQUIRED_MASK20 0 +#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)#endif /* _ASM_X86_REQUIRED_FEATURES_H */
arch/x86/kernel/cpu/common.c +3 -0
@@ -1093,6 +1093,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)if (c->extended_cpuid_level >=0x8000001f ) c->x86_capability[CPUID_8000_001F_EAX ] =cpuid_eax (0x8000001f ); +if (c->extended_cpuid_level >=0x80000021 ) + c->x86_capability[CPUID_8000_0021_EAX ] =cpuid_eax (0x80000021 ); +init_scattered_cpuid_features (c);init_speculation_control (c);
arch/x86/kvm/reverse_cpuid.h +1 -0
@@ -68,6 +68,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, [CPUID_7_1_EDX] = { 7, 1, CPUID_EDX}, + [CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX}, };/*
Signature · 1 line
2.34.1
[tip: x86/cpu] x86/cpu, kvm: Add support for CPUID_80000021_EAX
The following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 15fea09b029d43fd1f3069f5e957ce9dc282f052 Gitweb: https://git.kernel.org/tip/15fea09b029d43fd1f3069f5e957ce9dc282f052 Author: Kim Phillips <[email protected]> AuthorDate: Tue, 10 Jan 2023 16:46:37 -06:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 17 Jan 2023 13:00:12 +01:00
x86/cpu, kvm: Add support for CPUID_80000021_EAX
Add support for CPUID leaf 80000021, EAX. The majority of the features will be used in the kernel and thus a separate leaf is appropriate.
Include KVM's reverse_cpuid entry because features are used by VM guests, too.
[ bp: Massage commit message. ]
--- arch/x86/include/asm/cpufeature.h | 7 +++++-- arch/x86/include/asm/cpufeatures.h | 2 +- arch/x86/include/asm/disabled-features.h | 3 ++- arch/x86/include/asm/required-features.h | 3 ++- arch/x86/kernel/cpu/common.c | 3 +++ arch/x86/kvm/reverse_cpuid.h | 1 + 6 files changed, 14 insertions(+), 5 deletions(-)
arch/x86/include/asm/cpufeature.h +5 -2
@@ -32,6 +32,7 @@ enum cpuid_leafsCPUID_8000_0007_EBX ,CPUID_7_EDX ,CPUID_8000_001F_EAX , + CPUID_8000_0021_EAX, };#define X86_CAP_FMT_NUM "%d:%d"
@@ -94,8 +95,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 17, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 18, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 19, feature_bit) || \ + CHECK_BIT_IN_MASK_WORD(REQUIRED_MASK, 20, feature_bit) || \ REQUIRED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 20)) + BUILD_BUG_ON_ZERO(NCAPINTS != 21))#define DISABLED_MASK_BIT_SET (feature_bit) \ ( CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 0, feature_bit) || \
@@ -118,8 +120,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32]; CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 17, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 18, feature_bit) || \ CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 19, feature_bit) || \ + CHECK_BIT_IN_MASK_WORD(DISABLED_MASK, 20, feature_bit) || \ DISABLED_MASK_CHECK || \ - BUILD_BUG_ON_ZERO(NCAPINTS != 20)) + BUILD_BUG_ON_ZERO(NCAPINTS != 21))#define cpu_has (c, bit) \ (__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
arch/x86/include/asm/cpufeatures.h +1 -1
@@ -13,7 +13,7 @@/* * Defines x86 CPU feature bits */ -#define NCAPINTS 20/* N 32-bit words worth of info */ +#define NCAPINTS 21/* N 32-bit words worth of info */ #define NBUGINTS 1/* N 32-bit bug flags */ /*
arch/x86/include/asm/disabled-features.h +2 -1
@@ -124,6 +124,7 @@#define DISABLED_MASK17 0#define DISABLED_MASK18 0#define DISABLED_MASK19 0 -#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) +#define DISABLED_MASK20 0 +#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)#endif /* _ASM_X86_DISABLED_FEATURES_H */
arch/x86/include/asm/required-features.h +2 -1
@@ -98,6 +98,7 @@#define REQUIRED_MASK17 0#define REQUIRED_MASK18 0#define REQUIRED_MASK19 0 -#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) +#define REQUIRED_MASK20 0 +#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 21)#endif /* _ASM_X86_REQUIRED_FEATURES_H */
arch/x86/kernel/cpu/common.c +3 -0
@@ -1093,6 +1093,9 @@ void get_cpu_cap(struct cpuinfo_x86 *c)if (c->extended_cpuid_level >=0x8000001f ) c->x86_capability[CPUID_8000_001F_EAX ] =cpuid_eax (0x8000001f ); +if (c->extended_cpuid_level >=0x80000021 ) + c->x86_capability[CPUID_8000_0021_EAX ] =cpuid_eax (0x80000021 ); +init_scattered_cpuid_features (c);init_speculation_control (c);
arch/x86/kvm/reverse_cpuid.h +1 -0
@@ -68,6 +68,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, [CPUID_7_1_EDX] = { 7, 1, CPUID_EDX}, + [CPUID_8000_0021_EAX] = {0x80000021, 0, CPUID_EAX}, };/*
PATCH v6 2/7 x86/cpu, kvm: Add the NO_NESTED_DATA_BP feature
In reply to Kim PhillipsThe "Processor ignores nested data breakpoints" feature was being open-coded for KVM in __do_cpuid_func(). Add it to its newly added CPUID leaf 0x80000021 EAX proper, and propagate it in kvm_set_cpu_caps() instead.
Also drop the bit description comments now it's more self-describing.
--- arch/x86/include/asm/cpufeatures.h | 3 +++ arch/x86/kvm/cpuid.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeatures.h +3 -0
@@ -426,6 +426,9 @@#define X86_FEATURE_V_TSC_AUX (19*32+ 9)/* "" Virtual TSC_AUX */ #define X86_FEATURE_SME_COHERENT (19*32+10)/* "" AMD hardware-enforced cache coherency */ +/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ +#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ +/* * BUG word(s) */
arch/x86/kvm/cpuid.c +6 -2
@@ -741,6 +741,10 @@ void kvm_set_cpu_caps(void)0 /* SME */ |F (SEV ) |0 /* VM_PAGE_FLUSH */ |F (SEV_ES ) | F(SME_COHERENT)); +kvm_cpu_cap_mask (CPUID_8000_0021_EAX , +F (NO_NESTED_DATA_BP ) + ); + kvm_cpu_cap_mask(CPUID_C000_0001_EDX, F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) | F(ACE2) | F(ACE2_EN) | F(PHE) | F(PHE_EN) |
@@ -1222,9 +1226,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)break ;case 0x80000021 : entry->ebx = entry->ecx = entry->edx =0 ; +cpuid_entry_override (entry,CPUID_8000_0021_EAX );/* * Pass down these bits: -* EAX 0 NNDBP, Processor ignores nested data breakpoints * EAX 2 LAS, LFENCE always serializing * EAX 6 NSCB, Null selector clear base *
@@ -1235,7 +1239,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)* KVM doesn't support SMM_CTL. * EAX 9 SMM_CTL MSR is not supported */ - entry->eax &=BIT (0 ) |BIT (2 ) |BIT (6 ); + entry->eax &=BIT (2 ) |BIT (6 ); entry->eax |=BIT (9 );if (static_cpu_has (X86_FEATURE_LFENCE_RDTSC )) entry->eax |=BIT (2 );
Signature · 1 line
2.34.1
[tip: x86/cpu] x86/cpu, kvm: Add the NO_NESTED_DATA_BP feature
The following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: dcf67f724b8ada6aa73b77733243024519c35a71 Gitweb: https://git.kernel.org/tip/dcf67f724b8ada6aa73b77733243024519c35a71 Author: Kim Phillips <[email protected]> AuthorDate: Tue, 10 Jan 2023 16:46:38 -06:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Tue, 17 Jan 2023 13:00:12 +01:00
x86/cpu, kvm: Add the NO_NESTED_DATA_BP feature
The "Processor ignores nested data breakpoints" feature was being open-coded for KVM in __do_cpuid_func(). Add it to its newly added CPUID leaf 0x80000021 EAX proper, and propagate it in kvm_set_cpu_caps() instead.
Also drop the bit description comments now it's more self-describing.
--- arch/x86/include/asm/cpufeatures.h | 3 +++ arch/x86/kvm/cpuid.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeatures.h +3 -0
@@ -427,6 +427,9 @@#define X86_FEATURE_V_TSC_AUX (19*32+ 9)/* "" Virtual TSC_AUX */ #define X86_FEATURE_SME_COHERENT (19*32+10)/* "" AMD hardware-enforced cache coherency */ +/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ +#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" No Nested Data Breakpoints */ +/* * BUG word(s) */
arch/x86/kvm/cpuid.c +6 -2
@@ -741,6 +741,10 @@ void kvm_set_cpu_caps(void)0 /* SME */ |F (SEV ) |0 /* VM_PAGE_FLUSH */ |F (SEV_ES ) | F(SME_COHERENT)); +kvm_cpu_cap_mask (CPUID_8000_0021_EAX , +F (NO_NESTED_DATA_BP ) + ); + kvm_cpu_cap_mask(CPUID_C000_0001_EDX, F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) | F(ACE2) | F(ACE2_EN) | F(PHE) | F(PHE_EN) |
@@ -1222,9 +1226,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)break ;case 0x80000021 : entry->ebx = entry->ecx = entry->edx =0 ; +cpuid_entry_override (entry,CPUID_8000_0021_EAX );/* * Pass down these bits: -* EAX 0 NNDBP, Processor ignores nested data breakpoints * EAX 2 LAS, LFENCE always serializing * EAX 6 NSCB, Null selector clear base *
@@ -1235,7 +1239,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)* KVM doesn't support SMM_CTL. * EAX 9 SMM_CTL MSR is not supported */ - entry->eax &=BIT (0 ) |BIT (2 ) |BIT (6 ); + entry->eax &=BIT (2 ) |BIT (6 ); entry->eax |=BIT (9 );if (static_cpu_has (X86_FEATURE_LFENCE_RDTSC )) entry->eax |=BIT (2 );
Sean Christopherson
maintainerRe: [PATCH v6 2/7] x86/cpu, kvm: Add the NO_NESTED_DATA_BP feature
In reply to Kim PhillipsQuoted 54 lines · Kim Phillips
The "Processor ignores nested data breakpoints" feature was being open-coded for KVM in
__do_cpuid_func(). Add it to its newly added CPUID leaf0x80000021EAX proper, and propagate it inkvm_set_cpu_caps()instead.Also drop the bit description comments now it's more self-describing.
Signed-off-by Kim Phillips <[email protected]>--- arch/x86/include/asm/cpufeatures.h | 3 +++ arch/x86/kvm/cpuid.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-)arch/x86/include/asm/cpufeatures.h +3
-0@@ -426,6 +426,9 @@#define X86_FEATURE_V_TSC_AUX (19*32+ 9)/* "" Virtual TSC_AUX */ #define X86_FEATURE_SME_COHERENT (19*32+10)/* "" AMD hardware-enforced cache coherency */ +/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ +#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ +/* * BUG word(s) */ arch/x86/kvm/cpuid.c +5
-1@@ -741,6 +741,10 @@ void kvm_set_cpu_caps(void)0 /* SME */ |F (SEV ) |0 /* VM_PAGE_FLUSH */ |F (SEV_ES ) | F(SME_COHERENT)); +kvm_cpu_cap_mask (CPUID_8000_0021_EAX , +F (NO_NESTED_DATA_BP ) + ); + kvm_cpu_cap_mask(CPUID_C000_0001_EDX, F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) | F(ACE2) | F(ACE2_EN) | F(PHE) | F(PHE_EN) |@@ -1222,9 +1226,9 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)break ;case 0x80000021 : entry->ebx = entry->ecx = entry->edx =0 ; +cpuid_entry_override (entry,CPUID_8000_0021_EAX );/* * Pass down these bits: -* EAX 0 NNDBP, Processor ignores nested data breakpoints * EAX 2 LAS, LFENCE always serializing * EAX 6 NSCB, Null selector clear base *
arch/x86/kvm/cpuid.c static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) · line 1242
Quoted 5 lines
arch/x86/kvm/cpuid.c +1
-1@@ -1235,7 +1239,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)* KVM doesn't support SMM_CTL. * EAX 9 SMM_CTL MSR is not supported */ - entry->eax &=BIT (0 ) |BIT (2 ) |BIT (6 ); + entry->eax &=BIT (2 ) |BIT (6 );
This is broken. It gets fixed by the end of the series, but between here and commit b1366f515fd6 ("x86/cpu, kvm: Add the Null Selector Clears Base feature"), the AND with open coded bits means any bits preserved/set by cpuid_entry_override() are wiped out. E.g. NO_NESTED_DATA_BP will never be advertised as of this patch.
The proper way to do this is to first convert all supported bits away from magic numbers in a single patch, and then introduce newly supported bits one by one. That one patch will be larger, but I don't see a better approach.
Is it too late to back this out? Not a huge deal, but it seems easy enough to clean up.
Borislav Petkov
maintainerRe: [PATCH v6 2/7] x86/cpu, kvm: Add the NO_NESTED_DATA_BP feature
Quoted 2 lines · Sean Christopherson
Is it too late to back this out? Not a huge deal, but it seems easy enough to clean up.
No, not at all. Lemme zap them from the lineup.
Kim, please send a new set like Sean suggests.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v6 3/7 x86/cpu, kvm: Move the LFENCE_RDTSC / LFENCE always serializing feature
In reply to Kim PhillipsThe LFENCE_RDTSC / LFENCE always serializing feature was a scattered bit and open-coded for KVM in __do_cpuid_func(). Add it to its newly added CPUID leaf 0x80000021 EAX proper, and propagate it in kvm_set_cpu_caps() instead.
Also drop the bit description comments now it's more self-describing.
Whilst there, switch to using the more efficient cpu_feature_enabled() instead of static_cpu_has().
--- arch/x86/include/asm/cpufeatures.h | 3 ++- arch/x86/kvm/cpuid.c | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/cpufeatures.h +2 -1
@@ -97,7 +97,7 @@#define X86_FEATURE_SYSENTER32 ( 3*32+15)/* "" sysenter in IA32 userspace */ #define X86_FEATURE_REP_GOOD ( 3*32+16)/* REP microcode works well */ #define X86_FEATURE_AMD_LBR_V2 ( 3*32+17)/* AMD Last Branch Record Extension Version 2 */ -#define X86_FEATURE_LFENCE_RDTSC ( 3*32+18)/* "" LFENCE synchronizes RDTSC */ +/* FREE, was #define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) "" LFENCE synchronizes RDTSC */ #define X86_FEATURE_ACC_POWER ( 3*32+19)/* AMD Accumulated Power Mechanism */ #define X86_FEATURE_NOPL ( 3*32+20)/* The NOPL (0F 1F) instructions */ #define X86_FEATURE_ALWAYS ( 3*32+21)/* "" Always-present feature */
@@ -428,6 +428,7 @@/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ +#define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* "" LFENCE always serializing / synchronizes RDTSC */ /* * BUG word(s)
arch/x86/kvm/cpuid.c +4 -5
@@ -742,8 +742,10 @@ void kvm_set_cpu_caps(void) F(SME_COHERENT));kvm_cpu_cap_mask (CPUID_8000_0021_EAX , -F (NO_NESTED_DATA_BP ) +F (NO_NESTED_DATA_BP ) |F (LFENCE_RDTSC ) ); +if (cpu_feature_enabled (X86_FEATURE_LFENCE_RDTSC )) +kvm_cpu_cap_set (X86_FEATURE_LFENCE_RDTSC ); kvm_cpu_cap_mask(CPUID_C000_0001_EDX, F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) |
@@ -1229,7 +1231,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)cpuid_entry_override (entry,CPUID_8000_0021_EAX );/* * Pass down these bits: -* EAX 2 LAS, LFENCE always serializing * EAX 6 NSCB, Null selector clear base * * Other defined bits are for MSRs that KVM does not expose:
@@ -1239,10 +1240,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)* KVM doesn't support SMM_CTL. * EAX 9 SMM_CTL MSR is not supported */ - entry->eax &=BIT (2 ) |BIT (6 ); + entry->eax &=BIT (6 ); entry->eax |=BIT (9 ); -if (static_cpu_has (X86_FEATURE_LFENCE_RDTSC )) - entry->eax |=BIT (2 );if (!static_cpu_has_bug (X86_BUG_NULL_SEG )) entry->eax |=BIT (6 );break ;
Signature · 1 line
2.34.1
Borislav Petkov
maintainerRe: [PATCH v6 3/7] x86/cpu, kvm: Move the LFENCE_RDTSC / LFENCE always serializing feature
Quoted 30 lines · Kim Phillips
The
LFENCE_RDTSC/ LFENCE always serializing feature was a scattered bit and open-coded for KVM in__do_cpuid_func(). Add it to its newly added CPUID leaf0x80000021EAX proper, and propagate it inkvm_set_cpu_caps()instead.Also drop the bit description comments now it's more self-describing.
Whilst there, switch to using the more efficient
cpu_feature_enabled()instead ofstatic_cpu_has().Signed-off-by Kim Phillips <[email protected]>--- arch/x86/include/asm/cpufeatures.h | 3 ++- arch/x86/kvm/cpuid.c | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-)arch/x86/include/asm/cpufeatures.h +1
-1@@ -97,7 +97,7 @@#define X86_FEATURE_SYSENTER32 ( 3*32+15)/* "" sysenter in IA32 userspace */ #define X86_FEATURE_REP_GOOD ( 3*32+16)/* REP microcode works well */ #define X86_FEATURE_AMD_LBR_V2 ( 3*32+17)/* AMD Last Branch Record Extension Version 2 */ -#define X86_FEATURE_LFENCE_RDTSC ( 3*32+18)/* "" LFENCE synchronizes RDTSC */ +/* FREE, was #define X86_FEATURE_LFENCE_RDTSC ( 3*32+18) "" LFENCE synchronizes RDTSC */ #define X86_FEATURE_ACC_POWER ( 3*32+19)/* AMD Accumulated Power Mechanism */ #define X86_FEATURE_NOPL ( 3*32+20)/* The NOPL (0F 1F) instructions */ #define X86_FEATURE_ALWAYS ( 3*32+21)/* "" Always-present feature */
arch/x86/include/asm/cpufeatures.h line 431
Quoted 4 lines
arch/x86/include/asm/cpufeatures.h +1
-0@@ -428,6 +428,7 @@/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ +#define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* "" LFENCE always serializing / synchronizes RDTSC */
Hmm, a synthetic bit which gets replaced with a vendor one and then the other vendors set it too. I don't see why that cannot work but we probably should be careful here.
dhansen, am I missing an angle?
Also, X86_FEATURE_LFENCE_RDTSC gets set in init_amd() along with setting DE_CFG[1]. I think you should check the new flag here first and avoid the setting if that flag is set. Just for good measure - not that it changes anything but still, it is cheap to do.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH v6 3/7] x86/cpu, kvm: Move the LFENCE_RDTSC / LFENCE always serializing feature
Quoted 8 lines · Borislav Petkov
Quoted 3 lines
/* AMD-defined Extended Feature 2 EAX, CPUID level
0x80000021(EAX), word 20 */
#defineX86_FEATURE_NO_NESTED_DATA_BP(20*32+ 0) /* "" AMD No Nested Data Breakpoints */
+#defineX86_FEATURE_LFENCE_RDTSC(20*32+ 2) /* "" LFENCE always serializing / synchronizes RDTSC */Hmm, a synthetic bit which gets replaced with a vendor one and then the other vendors set it too. I don't see why that cannot work but we probably should be careful here.
dhansen, am I missing an angle?
I don't think so.
I'd be surprised if we don't have a _few_ other cases like this around, but nothing is coming to mind. Either way, it doesn't seem problematic.
Borislav Petkov
maintainerRe: [PATCH v6 3/7] x86/cpu, kvm: Move the LFENCE_RDTSC / LFENCE always serializing feature
Quoted 4 lines · Dave Hansen
I don't think so.
I'd be surprised if we don't have a _few_ other cases like this around, but nothing is coming to mind. Either way, it doesn't seem problematic.
Yeah, probably. The cases I remember are the other way around - we map vendor-specific flags to synthetic ones...
Anyway, thanks for checking!
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePATCH v6 4/7 x86/cpu, kvm: Add the Null Selector Clears Base feature
In reply to Kim PhillipsThe Null Selector Clears Base feature was being open-coded for KVM in __do_cpuid_func(). Add it to its newly added CPUID leaf 0x80000021 EAX proper, and propagate it in kvm_set_cpu_caps() instead.
Also drop the bit description comments now it's more self-describing.
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kvm/cpuid.c | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -429,6 +429,7 @@/* AMD-defined Extended Feature 2 EAX, CPUID level 0x80000021 (EAX), word 20 */ #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* "" LFENCE always serializing / synchronizes RDTSC */ +#define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6)/* "" AMD Null Selector Clears Base */ /* * BUG word(s)
arch/x86/kvm/cpuid.c +3 -7
@@ -742,10 +742,12 @@ void kvm_set_cpu_caps(void) F(SME_COHERENT));kvm_cpu_cap_mask (CPUID_8000_0021_EAX , -F (NO_NESTED_DATA_BP ) |F (LFENCE_RDTSC ) +F (NO_NESTED_DATA_BP ) |F (LFENCE_RDTSC ) |F (NULL_SEL_CLR_BASE ) );if (cpu_feature_enabled (X86_FEATURE_LFENCE_RDTSC ))kvm_cpu_cap_set (X86_FEATURE_LFENCE_RDTSC ); +if (!static_cpu_has_bug (X86_BUG_NULL_SEG )) +kvm_cpu_cap_set (X86_FEATURE_NULL_SEL_CLR_BASE ); kvm_cpu_cap_mask(CPUID_C000_0001_EDX, F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) |
@@ -1230,9 +1232,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->ebx = entry->ecx = entry->edx =0 ;cpuid_entry_override (entry,CPUID_8000_0021_EAX );/* -* Pass down these bits: -* EAX 6 NSCB, Null selector clear base -* * Other defined bits are for MSRs that KVM does not expose: * EAX 3 SPCL, SMM page configuration lock * EAX 13 PCMSR, Prefetch control MSR
@@ -1240,10 +1239,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)* KVM doesn't support SMM_CTL. * EAX 9 SMM_CTL MSR is not supported */ - entry->eax &=BIT (6 ); entry->eax |=BIT (9 ); -if (!static_cpu_has_bug (X86_BUG_NULL_SEG )) - entry->eax |=BIT (6 );break ;/*Add support for Centaur's CPUID instruction*/ case 0xC0000000 :
Signature · 1 line
2.34.1
PATCH v6 5/7 x86/cpu, kvm: Add the SMM_CTL MSR not present feature
In reply to Kim PhillipsThe SMM_CTL MSR not present feature was being open-coded for KVM in __do_cpuid_func(). Add it to its newly added CPUID leaf 0x80000021 EAX proper, and propagate it in kvm_set_cpu_caps() instead.
Also drop the bit description comments now the code is more self-describing, and retain the SmmPgCfgLock and PrefetchCtlMsr feature bit comments at the kvm_cpu_cap_mask() callsite.
--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kvm/cpuid.c | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-)
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -430,6 +430,7 @@#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* "" LFENCE always serializing / synchronizes RDTSC */ #define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6)/* "" AMD Null Selector Clears Base */ +#define X86_FEATURE_NO_SMM_CTL_MSR (20*32+ 9)/* "" AMD SMM_CTL MSR is not present */ /* * BUG word(s)
arch/x86/kvm/cpuid.c +3 -10
@@ -742,12 +742,14 @@ void kvm_set_cpu_caps(void) F(SME_COHERENT));kvm_cpu_cap_mask (CPUID_8000_0021_EAX , -F (NO_NESTED_DATA_BP ) |F (LFENCE_RDTSC ) |F (NULL_SEL_CLR_BASE ) +F (NO_NESTED_DATA_BP ) |F (LFENCE_RDTSC ) |0 /* SmmPgCfgLock */ | +F (NULL_SEL_CLR_BASE ) |0 /* PrefetchCtlMsr */ );if (cpu_feature_enabled (X86_FEATURE_LFENCE_RDTSC ))kvm_cpu_cap_set (X86_FEATURE_LFENCE_RDTSC );if (!static_cpu_has_bug (X86_BUG_NULL_SEG ))kvm_cpu_cap_set (X86_FEATURE_NULL_SEL_CLR_BASE ); +kvm_cpu_cap_set (X86_FEATURE_NO_SMM_CTL_MSR ); kvm_cpu_cap_mask(CPUID_C000_0001_EDX, F(XSTORE) | F(XSTORE_EN) | F(XCRYPT) | F(XCRYPT_EN) |
@@ -1231,15 +1233,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)case 0x80000021 : entry->ebx = entry->ecx = entry->edx =0 ;cpuid_entry_override (entry,CPUID_8000_0021_EAX ); -/* -* Other defined bits are for MSRs that KVM does not expose: -* EAX 3 SPCL, SMM page configuration lock -* EAX 13 PCMSR, Prefetch control MSR -* -* KVM doesn't support SMM_CTL. -* EAX 9 SMM_CTL MSR is not supported -*/ - entry->eax |=BIT (9 );break ;/*Add support for Centaur's CPUID instruction*/ case 0xC0000000 :
Signature · 1 line
2.34.1
PATCH v6 6/7 x86/cpu: Support AMD Automatic IBRS
In reply to Kim PhillipsThe AMD Zen4 core supports a new feature called Automatic IBRS.
It is a "set-and-forget" feature that means that, like Intel's Enhanced IBRS, h/w manages its IBRS mitigation resources automatically across CPL transitions.
The feature is advertised by CPUID_Fn80000021_EAX bit 8 and is enabled by setting MSR C000_0080 (EFER) bit 21.
Enable Automatic IBRS by default if the CPU feature is present. It typically provides greater performance over the incumbent generic retpolines mitigation.
Reuse the SPECTRE_V2_EIBRS spectre_v2_mitigation enum. AMD Automatic IBRS and Intel Enhanced IBRS have similar bugs.c enablement. Add NO_EIBRS_PBRSB to cpu_vuln_whitelist, since AMD Automatic IBRS isn't affected by PBRSB-eIBRS.
The kernel command line option spectre_v2=eibrs is used to select AMD Automatic IBRS, if available.
--- Documentation/admin-guide/hw-vuln/spectre.rst | 6 +++--- .../admin-guide/kernel-parameters.txt | 6 +++--- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/msr-index.h | 2 ++ arch/x86/kernel/cpu/bugs.c | 20 +++++++++++-------- arch/x86/kernel/cpu/common.c | 19 ++++++++++-------- 6 files changed, 32 insertions(+), 22 deletions(-)
Documentation/admin-guide/hw-vuln/spectre.rst +3 -3
@@ -610,9 +610,9 @@ kernel command line. retpoline,generic Retpolines retpoline,lfence LFENCE; indirect branch retpoline,amd alias for retpoline,lfence - eibrs enhanced IBRS - eibrs,retpoline enhanced IBRS + Retpolines - eibrs,lfence enhanced IBRS + LFENCE + eibrs Enhanced/Auto IBRS + eibrs,retpoline Enhanced/Auto IBRS + Retpolines + eibrs,lfence Enhanced/Auto IBRS + LFENCE ibrs use IBRS to protect kernel Not specifying this option is equivalent to
Documentation/admin-guide/kernel-parameters.txt +3 -3
@@ -5729,9 +5729,9 @@ retpoline,generic - Retpolines retpoline,lfence - LFENCE; indirect branch retpoline,amd - alias for retpoline,lfence - eibrs - enhanced IBRS - eibrs,retpoline - enhanced IBRS + Retpolines - eibrs,lfence - enhanced IBRS + LFENCE + eibrs - Enhanced/Auto IBRS + eibrs,retpoline - Enhanced/Auto IBRS + Retpolines + eibrs,lfence - Enhanced/Auto IBRS + LFENCE ibrs - use IBRS to protect kernel Not specifying this option is equivalent to
arch/x86/include/asm/cpufeatures.h +1 -0
@@ -430,6 +430,7 @@#define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0)/* "" AMD No Nested Data Breakpoints */ #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2)/* "" LFENCE always serializing / synchronizes RDTSC */ #define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6)/* "" AMD Null Selector Clears Base */ +#define X86_FEATURE_AUTOIBRS (20*32+ 8)/* "" AMD Automatic IBRS */ #define X86_FEATURE_NO_SMM_CTL_MSR (20*32+ 9)/* "" AMD SMM_CTL MSR is not present */ /*
arch/x86/include/asm/msr-index.h +2 -0
@@ -25,6 +25,7 @@#define _EFER_SVME 12/* Enable virtualization */ #define _EFER_LMSLE 13/* Long Mode Segment Limit Enable */ #define _EFER_FFXSR 14/* Enable Fast FXSAVE/FXRSTOR */ +#define _EFER_AUTOIBRS 21/* Enable Automatic IBRS */ #define EFER_SCE (1<<_EFER_SCE)#define EFER_LME (1<<_EFER_LME)
@@ -33,6 +34,7 @@#define EFER_SVME (1<<_EFER_SVME)#define EFER_LMSLE (1<<_EFER_LMSLE)#define EFER_FFXSR (1<<_EFER_FFXSR) +#define EFER_AUTOIBRS (1<<_EFER_AUTOIBRS)/* Intel MSRs. Some also available on other CPUs */
arch/x86/kernel/cpu/bugs.c +12 -8
@@ -1229,9 +1229,9 @@ static const char * const spectre_v2_strings[] = { [SPECTRE_V2_NONE] = "Vulnerable", [SPECTRE_V2_RETPOLINE] = "Mitigation: Retpolines", [SPECTRE_V2_LFENCE] = "Mitigation: LFENCE", - [SPECTRE_V2_EIBRS] = "Mitigation: Enhanced IBRS", - [SPECTRE_V2_EIBRS_LFENCE] = "Mitigation: Enhanced IBRS + LFENCE", - [SPECTRE_V2_EIBRS_RETPOLINE] = "Mitigation: Enhanced IBRS + Retpolines", + [SPECTRE_V2_EIBRS] = "Mitigation: Enhanced / Automatic IBRS", + [SPECTRE_V2_EIBRS_LFENCE] = "Mitigation: Enhanced / Automatic IBRS + LFENCE", + [SPECTRE_V2_EIBRS_RETPOLINE] = "Mitigation: Enhanced / Automatic IBRS + Retpolines", [SPECTRE_V2_IBRS] = "Mitigation: IBRS", };
@@ -1300,7 +1300,7 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void) cmd == SPECTRE_V2_CMD_EIBRS_LFENCE || cmd == SPECTRE_V2_CMD_EIBRS_RETPOLINE) && !boot_cpu_has(X86_FEATURE_IBRS_ENHANCED)) { -pr_err ("%s selected but CPU doesn't have eIBRS. Switching to AUTO select\n" , +pr_err ("%s selected but CPU doesn't have Enhanced or Automatic IBRS. Switching to AUTO select\n" , mitigation_options[i].option);return SPECTRE_V2_CMD_AUTO ; }
@@ -1486,8 +1486,12 @@ static void __init spectre_v2_select_mitigation(void)pr_err (SPECTRE_V2_EIBRS_EBPF_MSG );if (spectre_v2_in_ibrs_mode (mode)) { - x86_spec_ctrl_base |=SPEC_CTRL_IBRS ; -update_spec_ctrl (x86_spec_ctrl_base); +if (boot_cpu_has (X86_FEATURE_AUTOIBRS )) { +msr_set_bit (MSR_EFER , _EFER_AUTOIBRS); + }else { + x86_spec_ctrl_base |=SPEC_CTRL_IBRS ; +update_spec_ctrl (x86_spec_ctrl_base); + } }switch (mode) {
@@ -1571,8 +1575,8 @@ static void __init spectre_v2_select_mitigation(void)/* * Retpoline protects the kernel, but doesn't protect firmware. IBRS * and Enhanced IBRS protect firmware too, so enable IBRS around -* firmware calls only when IBRS / Enhanced IBRS aren't otherwise -* enabled. +* firmware calls only when IBRS / Enhanced / Automatic IBRS aren't +* otherwise enabled. * * Use "mode" to check Enhanced IBRS instead of boot_cpu_has(), because * the user might select retpoline on the kernel command line and if
arch/x86/kernel/cpu/common.c +11 -8
@@ -1229,8 +1229,8 @@ static const __initconst struct x86_cpu_id cpu_vuln_whitelist[] = {VULNWL_AMD (0x12 ,NO_MELTDOWN |NO_SSB |NO_L1TF |NO_MDS |NO_SWAPGS |NO_ITLB_MULTIHIT |NO_MMIO ),/* FAMILY_ANY must be last, otherwise 0x0f - 0x12 matches won't work */ -VULNWL_AMD (X86_FAMILY_ANY ,NO_MELTDOWN |NO_L1TF |NO_MDS |NO_SWAPGS |NO_ITLB_MULTIHIT |NO_MMIO ), -VULNWL_HYGON (X86_FAMILY_ANY ,NO_MELTDOWN |NO_L1TF |NO_MDS |NO_SWAPGS |NO_ITLB_MULTIHIT |NO_MMIO ), +VULNWL_AMD (X86_FAMILY_ANY ,NO_MELTDOWN |NO_L1TF |NO_MDS |NO_SWAPGS |NO_ITLB_MULTIHIT |NO_MMIO |NO_EIBRS_PBRSB ), +VULNWL_HYGON (X86_FAMILY_ANY ,NO_MELTDOWN |NO_L1TF |NO_MDS |NO_SWAPGS |NO_ITLB_MULTIHIT |NO_MMIO |NO_EIBRS_PBRSB ),/* Zhaoxin Family 7 */ VULNWL(CENTAUR, 7, X86_MODEL_ANY, NO_SPECTRE_V2 | NO_SWAPGS | NO_MMIO),
@@ -1341,8 +1341,16 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c) !cpu_has(c, X86_FEATURE_AMD_SSB_NO))setup_force_cpu_bug (X86_BUG_SPEC_STORE_BYPASS ); -if (ia32_cap &ARCH_CAP_IBRS_ALL ) +/* +* AMD's AutoIBRS is equivalent to Intel's eIBRS - use the Intel feature +* flag and protect from vendor-specific bugs via the whitelist. +*/ +if ((ia32_cap &ARCH_CAP_IBRS_ALL ) ||cpu_has (c,X86_FEATURE_AUTOIBRS )) {setup_force_cpu_cap (X86_FEATURE_IBRS_ENHANCED ); +if (!cpu_matches (cpu_vuln_whitelist,NO_EIBRS_PBRSB ) && + !(ia32_cap &ARCH_CAP_PBRSB_NO )) +setup_force_cpu_bug (X86_BUG_EIBRS_PBRSB ); + }if (!cpu_matches (cpu_vuln_whitelist,NO_MDS ) && !(ia32_cap &ARCH_CAP_MDS_NO )) {
@@ -1404,11 +1412,6 @@ static void __init cpu_set_bug_bits(struct cpuinfo_x86 *c)setup_force_cpu_bug (X86_BUG_RETBLEED ); } -if (cpu_has (c,X86_FEATURE_IBRS_ENHANCED ) && - !cpu_matches (cpu_vuln_whitelist,NO_EIBRS_PBRSB ) && - !(ia32_cap &ARCH_CAP_PBRSB_NO )) -setup_force_cpu_bug (X86_BUG_EIBRS_PBRSB ); -if (cpu_matches (cpu_vuln_whitelist,NO_MELTDOWN ))return ;
Signature · 1 line
2.34.1
Re: [PATCH v6 6/7] x86/cpu: Support AMD Automatic IBRS
Quoted 5 lines · Kim Phillips
The AMD Zen4 core supports a new feature called Automatic IBRS.
It is a "set-and-forget" feature that means that, like Intel's Enhanced IBRS, h/w manages its IBRS mitigation resources automatically across CPL transitions.
This looks a *LOT* better than what was here before. Sharing the eibrs boot options looks great. Thanks,
PATCH v6 7/7 x86/cpu, kvm: Propagate the AMD Automatic IBRS feature to the guest
In reply to Kim PhillipsAdd the AMD Automatic IBRS feature bit to those being propagated to the guest, and enable the guest EFER bit.
--- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/svm/svm.c | 3 +++ arch/x86/kvm/x86.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +1 -1
@@ -743,7 +743,7 @@ void kvm_set_cpu_caps(void)kvm_cpu_cap_mask (CPUID_8000_0021_EAX ,F (NO_NESTED_DATA_BP ) |F (LFENCE_RDTSC ) |0 /* SmmPgCfgLock */ | -F (NULL_SEL_CLR_BASE ) |0 /* PrefetchCtlMsr */ +F (NULL_SEL_CLR_BASE ) |F (AUTOIBRS ) |0 /* PrefetchCtlMsr */ );if (cpu_feature_enabled (X86_FEATURE_LFENCE_RDTSC ))kvm_cpu_cap_set (X86_FEATURE_LFENCE_RDTSC );
arch/x86/kvm/svm/svm.c +3 -0
@@ -4969,6 +4969,9 @@ static __init int svm_hardware_setup(void) tsc_aux_uret_slot =kvm_add_user_return_msr (MSR_TSC_AUX ); +if (boot_cpu_has (X86_FEATURE_AUTOIBRS )) +kvm_enable_efer_bits (EFER_AUTOIBRS ); +/* Check for pause filtering support */ if (!boot_cpu_has (X86_FEATURE_PAUSEFILTER )) { pause_filter_count =0 ;
arch/x86/kvm/x86.c +3 -0
@@ -1685,6 +1685,9 @@ static int do_get_msr_feature(struct kvm_vcpu *vcpu, unsigned index, u64 *data)static bool __kvm_valid_efer (struct kvm_vcpu *vcpu,u64 efer) { +if (efer &EFER_AUTOIBRS && !guest_cpuid_has (vcpu,X86_FEATURE_AUTOIBRS )) +return false; +if (efer &EFER_FFXSR && !guest_cpuid_has (vcpu,X86_FEATURE_FXSR_OPT ))return false;
Signature · 1 line
2.34.1