Re: [PATCH v9 07/22] KVM: VMX: Initialize VMCS FRED fields
From: Chao Gao
Date: Tue Nov 18 2025 - 21:45:16 EST
On Sun, Oct 26, 2025 at 01:18:55PM -0700, Xin Li (Intel) wrote:
>From: Xin Li <xin3.li@xxxxxxxxx>
>
>Initialize host VMCS FRED fields with host FRED MSRs' value and
>guest VMCS FRED fields to 0.
>
>FRED CPU state is managed in 9 new FRED MSRs:
> IA32_FRED_CONFIG,
> IA32_FRED_STKLVLS,
> IA32_FRED_RSP0,
> IA32_FRED_RSP1,
> IA32_FRED_RSP2,
> IA32_FRED_RSP3,
> IA32_FRED_SSP1,
> IA32_FRED_SSP2,
> IA32_FRED_SSP3,
>as well as a few existing CPU registers and MSRs:
> CR4.FRED,
> IA32_STAR,
> IA32_KERNEL_GS_BASE,
> IA32_PL0_SSP (also known as IA32_FRED_SSP0).
>
>CR4, IA32_KERNEL_GS_BASE and IA32_STAR are already well managed.
>Except IA32_FRED_RSP0 and IA32_FRED_SSP0, all other FRED CPU state
>MSRs have corresponding VMCS fields in both the host-state and
>guest-state areas. So KVM just needs to initialize them, and with
>proper VM entry/exit FRED controls, a FRED CPU will keep tracking
>host and guest FRED CPU state in VMCS automatically.
>
>Signed-off-by: Xin Li <xin3.li@xxxxxxxxx>
>Signed-off-by: Xin Li (Intel) <xin@xxxxxxxxx>
>Tested-by: Shan Kang <shan.kang@xxxxxxxxx>
>Tested-by: Xuelian Guo <xuelian.guo@xxxxxxxxx>
Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>
one nit below,
>@@ -8717,6 +8748,11 @@ __init int vmx_hardware_setup(void)
>
> kvm_caps.inapplicable_quirks &= ~KVM_X86_QUIRK_IGNORE_GUEST_PAT;
>
>+ if (kvm_cpu_cap_has(X86_FEATURE_FRED)) {
>+ rdmsrl(MSR_IA32_FRED_CONFIG, kvm_host.fred_config);
>+ rdmsrl(MSR_IA32_FRED_STKLVLS, kvm_host.fred_stklvls);
s/rdmsrl/rdmsrq
>+ }
>+
> return r;
> }
>
>diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
>index f3dc77f006f9..0c1fbf75442b 100644
>--- a/arch/x86/kvm/x86.h
>+++ b/arch/x86/kvm/x86.h
>@@ -52,6 +52,9 @@ struct kvm_host_values {
> u64 xss;
> u64 s_cet;
> u64 arch_capabilities;
>+
>+ u64 fred_config;
>+ u64 fred_stklvls;
> };
>
> void kvm_spurious_fault(void);
>--
>2.51.0
>