Re: [PATCH v10 21/28] KVM: nVMX: Handle FRED VMCS fields in nested VMX context
From: Binbin Wu
Date: Wed Nov 04 2026 - 01:43:19 EST
On 9/12/2026 5:36 AM, Sohil Mehta wrote:
> From: "Xin Li (Intel)" <xin@xxxxxxxxx>
>
> Extend nested VMX context management to include FRED-related VMCS fields,
> enabling proper handling of FRED state during nested virtualization.
No strong preference, but for me this is a bit too thin to describe the
overall change of this patch.
>
> Because KVM always sets SECONDARY_VM_EXIT_SAVE_IA32_FRED, FRED MSRs are
> always saved to vmcs02. However an L1 VMM may choose to clear this bit,
> i.e., not to save FRED MSRs to vmcs12. This is not a problem when the L1
> VMM sets SECONDARY_VM_EXIT_LOAD_IA32_FRED, as KVM then immediately loads
> host FRED MSRs of vmcs12 to guest FRED MSRs of vmcs01. However if the L1
> VMM clears SECONDARY_VM_EXIT_LOAD_IA32_FRED, KVM should retain FRED MSRs
> to run the L1 VMM.
>
> To propagate guest FRED MSRs from vmcs02 to vmcs01, save them in
> sync_vmcs02_to_vmcs12() regardless of whether
> SECONDARY_VM_EXIT_SAVE_IA32_FRED is set in vmcs12. Then, use the saved
> values to set guest FRED MSRs in vmcs01 within load_vmcs12_host_state()
> when !nested_cpu_load_host_fred_state().
>
> Signed-off-by: Xin Li (Intel) <xin@xxxxxxxxx>
> Signed-off-by: Sohil Mehta <sohil.mehta@xxxxxxxxx>
> ---
> v10:
> - Simplify nested FRED MSRs update with read/write helpers (Chao).
> - Add other FRED MSRS to MSR bitmap nested filtering (Chao).
> - Add {ORIGINAL,INJECTED}_EVENT_DATA to shadow fields in a separate
> patch (Sean).
> - Add a new parameter to load_vmcs12_host_state() to indicate the call
> is from a failed VM entry.
> - Update exception status member variable nested to is_nested (Sean).
>
> v9:
> - Rebase to kvm-x86/next.
> - Guard FRED state save/restore with guest_cpu_cap_has(vcpu,
> X86_FEATURE_FRED) (syzbot & Chao).
> ---
[...]
> diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> index 14fd3f57d5c1..cc1e4038cd44 100644
> --- a/arch/x86/kvm/vmx/vmx.h
> +++ b/arch/x86/kvm/vmx/vmx.h
> @@ -182,6 +182,29 @@ struct nested_vmx {
> u64 pre_vmenter_ssp;
> u64 pre_vmenter_ssp_tbl;
>
> + /*
> + * Used to snapshot FRED MSRs that may NOT be saved to vmcs12 as specified
> + * in the VM-Exit controls of vmcs12 configured by L1 VMM.
> + *
> + * FRED MSRs are *always* saved into vmcs02 because KVM always sets
> + * SECONDARY_VM_EXIT_SAVE_IA32_FRED. However an L1 VMM may choose to clear
> + * this bit, resulting in FRED MSRs not being propagated to vmcs12 from
> + * vmcs02. When the L1 VMM sets SECONDARY_VM_EXIT_LOAD_IA32_FRED, this is
> + * not a problem, since KVM then immediately loads the host FRED MSRs of
> + * vmcs12 to the guest FRED MSRs of vmcs01.
> + *
> + * But if the L1 VMM clears SECONDARY_VM_EXIT_LOAD_IA32_FRED, KVM should
> + * retain the FRED MSRs, i.e., propagate the guest FRED MSRs of vmcs02 to
> + * the guest FRED MSRs of vmcs01.
> + *
> + * This structure stores guest FRED MSRs that an L1 VMM opts not to save
> + * during VM-Exits from L2 to L1. These MSRs may still be retained for
> + * running the L1 VMM if SECONDARY_VM_EXIT_LOAD_IA32_FRED is cleared in
> + * vmcs12.
> + */
> + struct vmcs_fred_msrs pre_vmenter_fred_msrs;> + struct vmcs_fred_msrs at_vmexit_fred_msrs;
I understand that the two fields are both belong to FRED, but the comment blocks
are for at_vmexit_fred_msrs, not for pre_vmenter_fred_msrs.
Should pre_vmenter_fred_msrs be put together with the other pre_vmenter_xxx,
since the comments above the pre_vmenter_xxx explains why these fields are
needed.
> +
> u16 vpid02;
> u16 last_vpid;
>