Skip to content

Commit da01f64

Browse files
committed
KVM: nSVM: Clear exit_code_hi in VMCB when synthesizing nested VM-Exits
Explicitly clear exit_code_hi in the VMCB when synthesizing "normal" nested VM-Exits, as the full exit code is a 64-bit value (spoiler alert), and all exit codes for non-failing VMRUN use only bits 31:0. 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-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent af62fe2 commit da01f64

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ static bool check_selective_cr0_intercepted(struct kvm_vcpu *vcpu,
24352435

24362436
if (cr0 ^ val) {
24372437
svm->vmcb->control.exit_code = SVM_EXIT_CR0_SEL_WRITE;
2438+
svm->vmcb->control.exit_code_hi = 0;
24382439
ret = (nested_svm_exit_handled(svm) == NESTED_EXIT_DONE);
24392440
}
24402441

@@ -4611,6 +4612,7 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu,
46114612
if (static_cpu_has(X86_FEATURE_NRIPS))
46124613
vmcb->control.next_rip = info->next_rip;
46134614
vmcb->control.exit_code = icpt_info.exit_code;
4615+
vmcb->control.exit_code_hi = 0;
46144616
vmexit = nested_svm_exit_handled(svm);
46154617

46164618
ret = (vmexit == NESTED_EXIT_DONE) ? X86EMUL_INTERCEPTED

arch/x86/kvm/svm/svm.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,10 @@ int nested_svm_vmexit(struct vcpu_svm *svm);
764764

765765
static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_code)
766766
{
767-
svm->vmcb->control.exit_code = exit_code;
768-
svm->vmcb->control.exit_info_1 = 0;
769-
svm->vmcb->control.exit_info_2 = 0;
767+
svm->vmcb->control.exit_code = exit_code;
768+
svm->vmcb->control.exit_code_hi = 0;
769+
svm->vmcb->control.exit_info_1 = 0;
770+
svm->vmcb->control.exit_info_2 = 0;
770771
return nested_svm_vmexit(svm);
771772
}
772773

0 commit comments

Comments
 (0)