Skip to content

Commit f402ecd

Browse files
committed
KVM: nSVM: Set exit_code_hi to -1 when synthesizing SVM_EXIT_ERR (failed VMRUN)
Set exit_code_hi to -1u as a temporary band-aid to fix a long-standing (effectively since KVM's inception) bug where KVM treats the exit code as a 32-bit value, when in reality it's a 64-bit value. Per the APM, offset 0x70 is a single 64-bit value: 070h 63:0 EXITCODE And a sane reading of the error values defined in "Table C-1. SVM Intercept Codes" is that negative values use the full 64 bits: –1 VMEXIT_INVALID Invalid guest state in VMCB. –2 VMEXIT_BUSYBUSY bit was set in the VMSA –3 VMEXIT_IDLE_REQUIREDThe sibling thread is not in an idle state -4 VMEXIT_INVALID_PMC Invalid PMC state And that interpretation is confirmed by testing on Milan and Turin (by setting bits in CR0[63:32] to generate VMEXIT_INVALID on VMRUN). Furthermore, Xen has treated exitcode as a 64-bit value since HVM support was adding in 2006 (see Xen commit d1bd157fbc ("Big merge the HVM full-virtualisation abstractions.")). Cc: Jim Mattson <jmattson@google.com> Cc: Yosry Ahmed <yosry.ahmed@linux.dev> Cc: stable@vger.kernel.org Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev> Link: https://patch.msgid.link/20251113225621.1688428-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent da01f64 commit f402ecd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kvm/svm/nested.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
983983
if (!nested_vmcb_check_save(vcpu) ||
984984
!nested_vmcb_check_controls(vcpu)) {
985985
vmcb12->control.exit_code = SVM_EXIT_ERR;
986-
vmcb12->control.exit_code_hi = 0;
986+
vmcb12->control.exit_code_hi = -1u;
987987
vmcb12->control.exit_info_1 = 0;
988988
vmcb12->control.exit_info_2 = 0;
989989
goto out;
@@ -1016,7 +1016,7 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
10161016
svm->soft_int_injected = false;
10171017

10181018
svm->vmcb->control.exit_code = SVM_EXIT_ERR;
1019-
svm->vmcb->control.exit_code_hi = 0;
1019+
svm->vmcb->control.exit_code_hi = -1u;
10201020
svm->vmcb->control.exit_info_1 = 0;
10211021
svm->vmcb->control.exit_info_2 = 0;
10221022

0 commit comments

Comments
 (0)