From: Xin Li <xin@zytor.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-doc@vger.kernel.org
Cc: pbonzini@redhat.com, seanjc@google.com, corbet@lwn.net,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
luto@kernel.org, peterz@infradead.org, andrew.cooper3@citrix.com,
chao.gao@intel.com, hch@infradead.org
Subject: Re: [PATCH v5A 20/23] KVM: nVMX: Add FRED VMCS fields to nested VMX context handling
Date: Sun, 3 Aug 2025 23:03:16 -0700 [thread overview]
Message-ID: <5ca5d98e-6a3c-48fc-8aa2-7db0980543e6@zytor.com> (raw)
In-Reply-To: <aad3d385-5743-4f81-992a-22d1701c3611@zytor.com>
On 8/2/2025 10:33 AM, Xin Li wrote:
>> @@ -4531,6 +4593,27 @@ static void sync_vmcs02_to_vmcs12_rare(struct
>> kvm_vcpu *vcpu,
>> vmcs12->guest_tr_base = vmcs_readl(GUEST_TR_BASE);
>> vmcs12->guest_gdtr_base = vmcs_readl(GUEST_GDTR_BASE);
>> vmcs12->guest_idtr_base = vmcs_readl(GUEST_IDTR_BASE);
>> +
>> + vmx->nested.pre_vmexit_fred_config =
>> vmcs_read64(GUEST_IA32_FRED_CONFIG);
>> + vmx->nested.pre_vmexit_fred_rsp1 =
>> vmcs_read64(GUEST_IA32_FRED_RSP1);
>> + vmx->nested.pre_vmexit_fred_rsp2 =
>> vmcs_read64(GUEST_IA32_FRED_RSP2);
>> + vmx->nested.pre_vmexit_fred_rsp3 =
>> vmcs_read64(GUEST_IA32_FRED_RSP3);
>> + vmx->nested.pre_vmexit_fred_stklvls =
>> vmcs_read64(GUEST_IA32_FRED_STKLVLS);
>> + vmx->nested.pre_vmexit_fred_ssp1 =
>> vmcs_read64(GUEST_IA32_FRED_SSP1);
>> + vmx->nested.pre_vmexit_fred_ssp2 =
>> vmcs_read64(GUEST_IA32_FRED_SSP2);
>> + vmx->nested.pre_vmexit_fred_ssp3 =
>> vmcs_read64(GUEST_IA32_FRED_SSP3);
>
> This ...
>
>> +
>> + if (nested_cpu_save_guest_fred_state(vmcs12)) {
>> + vmcs12->guest_ia32_fred_config = vmx-
>> >nested.pre_vmexit_fred_config;
>> + vmcs12->guest_ia32_fred_rsp1 = vmx->nested.pre_vmexit_fred_rsp1;
>> + vmcs12->guest_ia32_fred_rsp2 = vmx->nested.pre_vmexit_fred_rsp2;
>> + vmcs12->guest_ia32_fred_rsp3 = vmx->nested.pre_vmexit_fred_rsp3;
>> + vmcs12->guest_ia32_fred_stklvls = vmx-
>> >nested.pre_vmexit_fred_stklvls;
>> + vmcs12->guest_ia32_fred_ssp1 = vmx->nested.pre_vmexit_fred_ssp1;
>> + vmcs12->guest_ia32_fred_ssp2 = vmx->nested.pre_vmexit_fred_ssp2;
>> + vmcs12->guest_ia32_fred_ssp3 = vmx->nested.pre_vmexit_fred_ssp3;
>> + }
>> +
>> vmcs12->guest_pending_dbg_exceptions =
>> vmcs_readl(GUEST_PENDING_DBG_EXCEPTIONS);
>> @@ -4761,6 +4860,26 @@ static void load_vmcs12_host_state(struct
>> kvm_vcpu *vcpu,
>> vmcs_write32(GUEST_IDTR_LIMIT, 0xFFFF);
>> vmcs_write32(GUEST_GDTR_LIMIT, 0xFFFF);
>> + if (nested_cpu_load_host_fred_state(vmcs12)) {
>> + vmcs_write64(GUEST_IA32_FRED_CONFIG, vmcs12-
>> >host_ia32_fred_config);
>> + vmcs_write64(GUEST_IA32_FRED_RSP1, vmcs12->host_ia32_fred_rsp1);
>> + vmcs_write64(GUEST_IA32_FRED_RSP2, vmcs12->host_ia32_fred_rsp2);
>> + vmcs_write64(GUEST_IA32_FRED_RSP3, vmcs12->host_ia32_fred_rsp3);
>> + vmcs_write64(GUEST_IA32_FRED_STKLVLS, vmcs12-
>> >host_ia32_fred_stklvls);
>> + vmcs_write64(GUEST_IA32_FRED_SSP1, vmcs12->host_ia32_fred_ssp1);
>> + vmcs_write64(GUEST_IA32_FRED_SSP2, vmcs12->host_ia32_fred_ssp2);
>> + vmcs_write64(GUEST_IA32_FRED_SSP3, vmcs12->host_ia32_fred_ssp3);
>> + } else {
>> + vmcs_write64(GUEST_IA32_FRED_CONFIG, vmx-
>> >nested.pre_vmexit_fred_config);
>> + vmcs_write64(GUEST_IA32_FRED_RSP1, vmx-
>> >nested.pre_vmexit_fred_rsp1);
>> + vmcs_write64(GUEST_IA32_FRED_RSP2, vmx-
>> >nested.pre_vmexit_fred_rsp2);
>> + vmcs_write64(GUEST_IA32_FRED_RSP3, vmx-
>> >nested.pre_vmexit_fred_rsp3);
>> + vmcs_write64(GUEST_IA32_FRED_STKLVLS, vmx-
>> >nested.pre_vmexit_fred_stklvls);
>> + vmcs_write64(GUEST_IA32_FRED_SSP1, vmx-
>> >nested.pre_vmexit_fred_ssp1);
>> + vmcs_write64(GUEST_IA32_FRED_SSP2, vmx-
>> >nested.pre_vmexit_fred_ssp2);
>> + vmcs_write64(GUEST_IA32_FRED_SSP3, vmx-
>> >nested.pre_vmexit_fred_ssp3);
>
> And this are actually nops. IOW, if I don't add this snippet of code,
> the CPU still retains the guest FRED MSRs, i.e., using guest FRED state
> from vmcs02 as that of vmcs01.
I confused myself. They are NOT nops, because __nested_vmx_vmexit()
switches from vmcs02 to vmcs01. The code should be (as the patch does):
__nested_vmx_vmexit()
{
...
/*
* Save guest FRED state of vmcs02 to nested.pre_vmexit_fred
* no matter if SECONDARY_VM_EXIT_SAVE_IA32_FRED is set.
*/
sync_vmcs02_to_vmcs12();
...
vmx_switch_vmcs();
...
/*
* Load nested.pre_vmexit_fred to guest FRED state of vmcs01
* if SECONDARY_VM_EXIT_LOAD_IA32_FRED is NOT set.
*/
load_vmcs12_host_state();
...
}
As not setting any of the two FRED VM-Exit controls are rare cases, we
need to add KVM tests with L1 that:
1) doesn't set SECONDARY_VM_EXIT_SAVE_IA32_FRED in VM-Exit controls.
2) doesn't set SECONDARY_VM_EXIT_LOAD_IA32_FRED in VM-Exit controls.
3) doesn't set both of the FRED VM-Exit controls.
Looks we need a framework for all VM-Exit controls which control whether
to save/load specific MSRs related to CPU features during VM-Exit?
next prev parent reply other threads:[~2025-08-04 6:04 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-23 17:53 [PATCH v5 00/23] Enable FRED with KVM VMX Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 01/23] KVM: VMX: Add support for the secondary VM exit controls Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 02/23] KVM: VMX: Initialize VM entry/exit FRED controls in vmcs_config Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 03/23] KVM: VMX: Disable FRED if FRED consistency checks fail Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 04/23] x86/cea: Export an API to get per CPU exception stacks for KVM to use Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 05/23] KVM: VMX: Fix an indentation Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 06/23] KVM: VMX: Initialize VMCS FRED fields Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 07/23] KVM: VMX: Set FRED MSR intercepts Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 08/23] KVM: VMX: Save/restore guest FRED RSP0 Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 09/23] KVM: VMX: Add host MSR read/write helpers to streamline preemption logic Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 10/23] KVM: VMX: Add support for FRED context save/restore Xin Li (Intel)
2025-07-24 5:35 ` Chao Gao
2025-07-24 18:01 ` Xin Li
2025-08-02 17:15 ` [PATCH v5A " Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 11/23] KVM: x86: Add a helper to detect if FRED is enabled for a vCPU Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 12/23] KVM: VMX: Virtualize FRED event_data Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 13/23] KVM: VMX: Virtualize FRED nested exception tracking Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 14/23] Documentation: kvm: Fix a section number typo Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 15/23] KVM: x86: Save/restore the nested flag of an exception Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 16/23] KVM: x86: Mark CR4.FRED as not reserved Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 17/23] KVM: VMX: Dump FRED context in dump_vmcs() Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 18/23] KVM: x86: Advertise support for FRED Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 19/23] KVM: nVMX: Add support for the secondary VM exit controls Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 20/23] KVM: nVMX: Add FRED VMCS fields to nested VMX context handling Xin Li (Intel)
2025-07-24 6:50 ` Chao Gao
2025-07-31 7:24 ` Xin Li
2025-08-02 17:17 ` [PATCH v5A " Xin Li (Intel)
2025-08-02 17:33 ` Xin Li
2025-08-04 6:03 ` Xin Li [this message]
2025-07-23 17:53 ` [PATCH v5 21/23] KVM: nVMX: Add FRED-related VMCS field checks Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 22/23] KVM: nVMX: Allow VMX FRED controls Xin Li (Intel)
2025-07-23 17:53 ` [PATCH v5 23/23] KVM: nVMX: Add prerequisites to SHADOW_FIELD_R[OW] macros Xin Li (Intel)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5ca5d98e-6a3c-48fc-8aa2-7db0980543e6@zytor.com \
--to=xin@zytor.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=hch@infradead.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).