KVM: x86: Propagate AMD-specific IBRS bits to guests
v2 cover KVM: x86: Propagate AMD-specific IBRS bits to guests
Changes since v2:
* Move feature bits macros from arch/x86/include/asm/cpufeatures.h to arch/x86/kvm/reverse_cpuid.h.
Takahiro Itazuri (1):
KVM: x86: Propagate AMD-specific IBRS bits to guests
arch/x86/kvm/cpuid.c | 5 +++-- arch/x86/kvm/reverse_cpuid.h | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-)
Signature · 1 line
2.38.0
PATCH v2 1/1 KVM: x86: Propagate AMD-specific IBRS bits to guests
VMMs retrieve supported CPUID features via KVM_GET_SUPPORTED_CPUID to construct CPUID information to be passed to KVM_SET_CPUID2. Most CPUID feature bits related to speculative attacks are propagated from host CPUID. AMD processors have AMD-specific IBRS related bits in CPUID Fn8000_0008_EBX (ref: AMD64 Architecture Programmer's Manual Volume 3:
General-Purpose and System Instructions) and some bits are not propagated to guests.
Enable propagation of these bits to guests, so that guests can see the same security information as the host without VMM action.
--- arch/x86/kvm/cpuid.c | 5 +++-- arch/x86/kvm/reverse_cpuid.h | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-)
arch/x86/kvm/cpuid.c +3 -2
@@ -704,8 +704,9 @@ void kvm_set_cpu_caps(void)kvm_cpu_cap_mask (CPUID_8000_0008_EBX ,F (CLZERO ) |F (XSAVEERPTR ) |F (WBNOINVD ) |F (AMD_IBPB ) |F (AMD_IBRS ) |F (AMD_SSBD ) |F (VIRT_SSBD ) | -F (AMD_SSB_NO ) |F (AMD_STIBP ) |F (AMD_STIBP_ALWAYS_ON ) | -__feature_bit (KVM_X86_FEATURE_AMD_PSFD ) +F (AMD_SSB_NO ) |F (AMD_STIBP ) |F (AMD_IBRS_ALWAYS_ON ) | +F (AMD_STIBP_ALWAYS_ON ) |F (AMD_IBRS_PREFERRED ) | +F (AMD_IBRS_SAME_MODE ) |__feature_bit (KVM_X86_FEATURE_AMD_PSFD ) );/*
arch/x86/kvm/reverse_cpuid.h +5 -0
@@ -43,6 +43,11 @@ enum kvm_only_cpuid_leafs {#define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5)#define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14) +/* AMD-specific IBRS hint bits, CPUID level 0x80000008 (EBX) */ +#define X86_FEATURE_AMD_IBRS_ALWAYS_ON KVM_X86_FEATURE(CPUID_8000_0008_EBX, 16) +#define X86_FEATURE_AMD_IBRS_PREFERRED KVM_X86_FEATURE(CPUID_8000_0008_EBX, 18) +#define X86_FEATURE_AMD_IBRS_SAME_MODE KVM_X86_FEATURE(CPUID_8000_0008_EBX, 19) +struct cpuid_reg {u32 function;u32 index;
Signature · 1 line
2.38.0
Sean Christopherson
maintainerQuoted 10 lines · Takahiro Itazuri
VMMs retrieve supported CPUID features via
KVM_GET_SUPPORTED_CPUIDto construct CPUID information to be passed toKVM_SET_CPUID2. Most CPUID feature bits related to speculative attacks are propagated from host CPUID. AMD processors have AMD-specific IBRS related bits in CPUIDFn8000_0008_EBX(ref: AMD64 Architecture Programmer's Manual Volume 3:
General-Purpose and System Instructions) and some bits are not propagated to guests.Enable propagation of these bits to guests, so that guests can see the same security information as the host without VMM action.
Please provide some description on what these bits do, and more importantly why no action is required to virtualize them in KVM, even if it seems obvious. We've had a few goofs with respect to mitigations across guest domains, I just want to be extra paranoid that we document upfront why it's ok (recommended?) to advertise this information to the guest.
Quoted 27 lines
Signed-off-by Takahiro Itazuri <[email protected]>--- arch/x86/kvm/cpuid.c | 5 +++-- arch/x86/kvm/reverse_cpuid.h | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-)arch/x86/kvm/cpuid.c +3
-2@@ -704,8 +704,9 @@ void kvm_set_cpu_caps(void)kvm_cpu_cap_mask (CPUID_8000_0008_EBX ,F (CLZERO ) |F (XSAVEERPTR ) |F (WBNOINVD ) |F (AMD_IBPB ) |F (AMD_IBRS ) |F (AMD_SSBD ) |F (VIRT_SSBD ) | -F (AMD_SSB_NO ) |F (AMD_STIBP ) |F (AMD_STIBP_ALWAYS_ON ) | -__feature_bit (KVM_X86_FEATURE_AMD_PSFD ) +F (AMD_SSB_NO ) |F (AMD_STIBP ) |F (AMD_IBRS_ALWAYS_ON ) | +F (AMD_STIBP_ALWAYS_ON ) |F (AMD_IBRS_PREFERRED ) | +F (AMD_IBRS_SAME_MODE ) |__feature_bit (KVM_X86_FEATURE_AMD_PSFD ) );/* arch/x86/kvm/reverse_cpuid.h +0
-0
arch/x86/kvm/reverse_cpuid.h enum kvm_only_cpuid_leafs { · line 49
Quoted 7 lines
arch/x86/kvm/reverse_cpuid.h +4
-0@@ -43,6 +43,11 @@ enum kvm_only_cpuid_leafs {#define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5)#define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14) +/* AMD-specific IBRS hint bits, CPUID level 0x80000008 (EBX) */ +#define X86_FEATURE_AMD_IBRS_ALWAYS_ON KVM_X86_FEATURE(CPUID_8000_0008_EBX, 16) +#define X86_FEATURE_AMD_IBRS_PREFERRED KVM_X86_FEATURE(CPUID_8000_0008_EBX, 18) +#define X86_FEATURE_AMD_IBRS_SAME_MODE KVM_X86_FEATURE(CPUID_8000_0008_EBX, 19)
These belong in cpufeatures.h, see the rest of the discussion in v1[*]. Sorry for the runaround :-(
Quoted 10 lines · Sean Christopherson
Quoted 8 lines · Takahiro Itazuri
VMMs retrieve supported CPUID features via
KVM_GET_SUPPORTED_CPUIDto construct CPUID information to be passed toKVM_SET_CPUID2. Most CPUID feature bits related to speculative attacks are propagated from host CPUID. AMD processors have AMD-specific IBRS related bits in CPUIDFn8000_0008_EBX(ref: AMD64 Architecture Programmer's Manual Volume 3:
General-Purpose and System Instructions) and some bits are not propagated to guests.
Quoted 2 lines
Quoted 2 lines
Enable propagation of these bits to guests, so that guests can see the same security information as the host without VMM action.
Usually, I can count on Sean for the semantic nitpick:
This propagates bits only to the userspace VMM. They may make it to the guest. They may not.