Skip to content

Commit 2bf889a

Browse files
committed
KVM: nVMX: Switch to vmcs01 to refresh APICv controls on-demand if L2 is active
If APICv is (un)inhibited while L2 is running, temporarily load vmcs01 and immediately refresh the APICv controls in vmcs01 instead of deferring the update until the next nested VM-Exit. This all but eliminates potential ordering issues due to vmcs01 not being synchronized with kvm_lapic.apicv_active, e.g. where KVM _thinks_ it refreshed APICv, but vmcs01 still contains stale state. Reviewed-by: Chao Gao <chao.gao@intel.com> Link: https://patch.msgid.link/20260109034532.1012993-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f004442 commit 2bf889a

3 files changed

Lines changed: 1 addition & 10 deletions

File tree

arch/x86/kvm/vmx/nested.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5134,11 +5134,6 @@ void __nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 vm_exit_reason,
51345134
kvm_make_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu);
51355135
}
51365136

5137-
if (vmx->nested.update_vmcs01_apicv_status) {
5138-
vmx->nested.update_vmcs01_apicv_status = false;
5139-
vmx_refresh_apicv_exec_ctrl(vcpu);
5140-
}
5141-
51425137
if ((vm_exit_reason != -1) &&
51435138
(enable_shadow_vmcs || nested_vmx_is_evmptr12_valid(vmx)))
51445139
vmx->nested.need_vmcs12_to_shadow_sync = true;

arch/x86/kvm/vmx/vmx.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4578,10 +4578,7 @@ void vmx_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu)
45784578
{
45794579
struct vcpu_vmx *vmx = to_vmx(vcpu);
45804580

4581-
if (is_guest_mode(vcpu)) {
4582-
vmx->nested.update_vmcs01_apicv_status = true;
4583-
return;
4584-
}
4581+
guard(vmx_vmcs01)(vcpu);
45854582

45864583
pin_controls_set(vmx, vmx_pin_based_exec_ctrl(vmx));
45874584

arch/x86/kvm/vmx/vmx.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ struct nested_vmx {
133133

134134
bool change_vmcs01_virtual_apic_mode;
135135
bool reload_vmcs01_apic_access_page;
136-
bool update_vmcs01_apicv_status;
137136

138137
/*
139138
* Enlightened VMCS has been enabled. It does not mean that L1 has to

0 commit comments

Comments
 (0)