On Thu, Feb 08, 2024 at 01:26:31AM +0800, Xin Li wrote:
Add kvm_is_fred_enabled() to get if FRED is enabled on a vCPU.
Signed-off-by: Xin Li xin3.li@intel.com Tested-by: Shan Kang shan.kang@intel.com
Change since v1:
- Explain why it is ok to only check CR4.FRED (Chao Gao).
arch/x86/kvm/kvm_cache_regs.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index 75eae9c4998a..1d431c703fdf 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -187,6 +187,23 @@ static __always_inline bool kvm_is_cr4_bit_set(struct kvm_vcpu *vcpu, return !!kvm_read_cr4_bits(vcpu, cr4_bit); }
+/*
- It's enough to check just CR4.FRED (X86_CR4_FRED) to tell if
- a vCPU is running with FRED enabled, because:
- CR4.FRED can be set to 1 only _after_ IA32_EFER.LMA = 1.
- To leave IA-32e mode, CR4.FRED must be cleared first.
- More details at FRED Spec 6.0 Section 4.2 Enabling in CR4.
- */
I think we can give more context here, e.g.,
Although FRED architecture applies to 64-bit mode only, there is no need to check if the CPU is in 64-bit mode (i.e., IA32_EFER.LMA and CS.L) to tell if FRED is enabled because CR4.FRED=1 implies the CPU is in 64-bit mode. Specifically,
1) .. 2) ..