Message ID | 20240207172646.3981-5-xin3.li@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Enable FRED with KVM VMX | expand |
On Wed, Feb 07, 2024 at 09:26:24AM -0800, Xin Li wrote: >The CR4.FRED bit, i.e., CR4[32], is no longer a reserved bit when a guest >enumerates FRED, otherwise it is still a reserved bit. > >Signed-off-by: Xin Li <xin3.li@intel.com> >Tested-by: Shan Kang <shan.kang@intel.com> Reviewed-by: Chao Gao <chao.gao@intel.com>
On Wed, Feb 07, 2024, Xin Li wrote: > The CR4.FRED bit, i.e., CR4[32], is no longer a reserved bit when a guest > enumerates FRED, otherwise it is still a reserved bit. This isn't quite correct, as __cr4_reserved_bits() is used with kvm_cpu_caps too, i.e. to compute CR4 bits that are reserved from the host's perspective. And that matters, because if this check was done _only_ on guest CPUID, then KVM would allow CR4.FRED=1 before all of KVM support is in place. > Signed-off-by: Xin Li <xin3.li@intel.com> > Tested-by: Shan Kang <shan.kang@intel.com> > --- > arch/x86/include/asm/kvm_host.h | 2 +- > arch/x86/kvm/x86.h | 2 ++ > 2 files changed, 3 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index b5b2d0fde579..0d88873eba63 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -134,7 +134,7 @@ > | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \ > | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_VMXE \ > | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP \ > - | X86_CR4_LAM_SUP)) > + | X86_CR4_LAM_SUP | X86_CR4_FRED)) > > #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 2f7e19166658..9a52016ebf5a 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -532,6 +532,8 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type); > __reserved_bits |= X86_CR4_PCIDE; \ > if (!__cpu_has(__c, X86_FEATURE_LAM)) \ > __reserved_bits |= X86_CR4_LAM_SUP; \ > + if (!__cpu_has(__c, X86_FEATURE_FRED)) \ > + __reserved_bits |= X86_CR4_FRED; \ > __reserved_bits; \ > }) > > -- > 2.43.0 >
> On Wed, Feb 07, 2024, Xin Li wrote: > > The CR4.FRED bit, i.e., CR4[32], is no longer a reserved bit when a guest > > enumerates FRED, otherwise it is still a reserved bit. > > This isn't quite correct, as __cr4_reserved_bits() is used with kvm_cpu_caps too, > i.e. to compute CR4 bits that are reserved from the host's perspective. And that > matters, because if this check was done _only_ on guest CPUID, then KVM would > allow CR4.FRED=1 before all of KVM support is in place. Ah, that means I didn't dig deep enough. Thanks! Xin
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index b5b2d0fde579..0d88873eba63 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -134,7 +134,7 @@ | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \ | X86_CR4_OSXMMEXCPT | X86_CR4_LA57 | X86_CR4_VMXE \ | X86_CR4_SMAP | X86_CR4_PKE | X86_CR4_UMIP \ - | X86_CR4_LAM_SUP)) + | X86_CR4_LAM_SUP | X86_CR4_FRED)) #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index 2f7e19166658..9a52016ebf5a 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -532,6 +532,8 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type); __reserved_bits |= X86_CR4_PCIDE; \ if (!__cpu_has(__c, X86_FEATURE_LAM)) \ __reserved_bits |= X86_CR4_LAM_SUP; \ + if (!__cpu_has(__c, X86_FEATURE_FRED)) \ + __reserved_bits |= X86_CR4_FRED; \ __reserved_bits; \ })