[Devel] [PATCH hci-8.1 03/14] ms/KVM: nVMX: Process each host MSR entry at most once when unwinding failed VM-Entry
Konstantin Khorenko
khorenko at virtuozzo.com
Thu Nov 26 17:30:16 MSK 2026
From: Sean Christopherson <seanjc at google.com>
[ Upstream commit c33ef9d334059f7cb167569ed7b4779752fe4425 ]
Add a missing "break" in the inner for-loop of the open coded mess that
unwinds MSRs back to the pre-VM-Enter state when VMLAUNCH/VMRESUME VM-Fails
due to a consistency check that is caught by hardware but missed by KVM.
I.e. move on to the next MSR in the VM-Entry load list after performing a
write using a value found in the VM-Exit load list. Processing *every*
matching entry in the VM-Exit load list makes the processing quadratic,
which is problematic if the load lists are full of MSRs that are expensive
to emulate. E.g. writing APIC_BASE triggers kvm_recalculate_apic_map() and
a whole pile of unnecessary work.
Functionally, arbitrarily restoring the value of the first matching entry
is "fine", because none of this is architecturally correct: the load lists
are never supposed to have been used in the first place. In practice, it's
likely a moot point as no well-behaved VMM will have multiple, diverging
entries in the load lists.
Fixes: bd18bffca353 ("KVM: nVMX: restore host state in nested_vmx_vmexit for VMFail")
Cc: stable at vger.kernel.org
Cc: David Woodhouse <dwmw2 at infradead.org>
Reported-by: Stefan Teodorescu <fane at google.com>
Suggested-by: Stefan Teodorescu <fane at google.com>
Signed-off-by: Sean Christopherson <seanjc at google.com>
Message-ID: <20261027185917.1478906-1-seanjc at google.com>
Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
Signed-off-by: Sasha Levin <sashal at kernel.org>
(cherry picked from commit 05fae367c6878d08f54a7c5bb6986a5e57e9bd1c)
https://virtuozzo.atlassian.net/browse/VSTOR-157287
Feature: fix ms/kvm
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
arch/x86/kvm/vmx/nested.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 1e34dc5313246..94facc1a2f2e7 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -4956,6 +4956,7 @@ static void nested_vmx_restore_host_state(struct kvm_vcpu *vcpu)
__func__, j, h.index, h.value);
goto vmabort;
}
+ break;
}
}
--
2.43.0
More information about the Devel
mailing list