Skip to content

Commit 271544f

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: nVMX: Emulate HLT in L2 if it's not intercepted
JIRA: https://issues.redhat.com/browse/RHEL-95318 commit f43f7a2 Author: Sean Christopherson <seanjc@google.com> Date: Fri Jan 31 17:55:11 2025 -0800 KVM: nVMX: Emulate HLT in L2 if it's not intercepted Extend VMX's nested intercept logic for emulated instructions to handle HLT interception, primarily for testing purposes. Failure to allow emulation of HLT isn't all that interesting, as emulating HLT while L2 is active either requires forced emulation (and no #UD intercept in L1), TLB games in the guest to coerce KVM into emulating the wrong instruction, or a bug elsewhere in KVM. E.g. without commit 47ef3ef ("KVM: VMX: Handle event vectoring error in check_emulate_instruction()"), KVM can end up trying to emulate HLT if RIP happens to point at a HLT when a vectored event arrives with L2's IDT pointing at emulated MMIO. Note, vmx_check_intercept() is still broken when L1 wants to intercept an instruction, as KVM injects a #UD instead of synthesizing a nested VM-Exit. That issue extends far beyond HLT, punt on it for now. Link: https://lore.kernel.org/r/20250201015518.689704-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent d6d0f39 commit 271544f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7995,6 +7995,11 @@ int vmx_check_intercept(struct kvm_vcpu *vcpu,
79957995
/* FIXME: produce nested vmexit and return X86EMUL_INTERCEPTED. */
79967996
break;
79977997

7998+
case x86_intercept_hlt:
7999+
if (!nested_cpu_has(vmcs12, CPU_BASED_HLT_EXITING))
8000+
return X86EMUL_CONTINUE;
8001+
break;
8002+
79988003
case x86_intercept_pause:
79998004
/*
80008005
* PAUSE is a single-byte NOP with a REPE prefix, i.e. collides

0 commit comments

Comments
 (0)