mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter
       [not found] <sashiko-outbox-247213@kernel.org>
@ 2026-12-03  6:05 ` Zihui Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Zihui Guo @ 2026-12-03  6:05 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

Right. vm_entry_intr_info_field keeps its valid bit until the next
nested VM-Exit, so with this patch KVM_SET_NESTED_STATE rejects the
saved state of an L2 that executed HLT after L1 injected a #PF. v2 will
check the injected event only when a nested run is pending, as is done
for the guest's IA32_EFER.

Thanks,
Zihui

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter
  2026-12-03  5:34 [PATCH 0/3] KVM: nVMX: Add missing guest-state checks " Zihui Guo
@ 2026-12-03  5:34 ` Zihui Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Zihui Guo @ 2026-12-03  5:34 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: Chao Gao, Binbin Wu, kvm, linux-kernel

SDM Vol. 3C 29.3.1.5 allows only these injected events when the
activity state is HLT: an external interrupt, an NMI, a #DB or #MC
hardware exception, and the pending MTF VM exit (other event, vector
0). KVM does not check this, and as with the SS.DPL check the hardware
never sees vmcs12's activity state, so L1 can inject, for example, a #GP
into an L2 that is in the HLT state and get a successful VM-Enter.

Add the check.

Fixes: 6dfacadd5858 ("KVM: nVMX: Add support for activity state HLT")
Signed-off-by: Zihui Guo <youzih27@gmail.com>
---
 arch/x86/kvm/vmx/nested.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 82618f74d4ad..2712648915a9 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3281,6 +3281,24 @@ static int nested_vmx_check_vmcs_link_ptr(struct kvm_vcpu *vcpu,
 /*
  * Checks related to Guest Non-register State
  */
+/* Events that may be injected in the HLT state (SDM 29.3.1.5). */
+static bool nested_hlt_event_allowed(u32 intr_info)
+{
+	u8 vector = intr_info & INTR_INFO_VECTOR_MASK;
+
+	switch (intr_info & INTR_INFO_INTR_TYPE_MASK) {
+	case INTR_TYPE_EXT_INTR:
+	case INTR_TYPE_NMI_INTR:
+		return true;
+	case INTR_TYPE_HARD_EXCEPTION:
+		return vector == DB_VECTOR || vector == MC_VECTOR;
+	case INTR_TYPE_OTHER_EVENT:
+		return vector == 0;
+	default:
+		return false;
+	}
+}
+
 static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
 {
 	if (CC(vmcs12->guest_activity_state != GUEST_ACTIVITY_ACTIVE &&
@@ -3292,6 +3310,11 @@ static int nested_check_guest_non_reg_state(struct vmcs12 *vmcs12)
 	       VMX_AR_DPL(vmcs12->guest_ss_ar_bytes) != 0))
 		return -EINVAL;
 
+	if (CC(vmcs12->guest_activity_state == GUEST_ACTIVITY_HLT &&
+	       (vmcs12->vm_entry_intr_info_field & INTR_INFO_VALID_MASK) &&
+	       !nested_hlt_event_allowed(vmcs12->vm_entry_intr_info_field)))
+		return -EINVAL;
+
 	return 0;
 }
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03  6:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <sashiko-outbox-247213@kernel.org>
2026-12-03  6:05 ` [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state on nested VM-Enter Zihui Guo
2026-12-03  5:34 [PATCH 0/3] KVM: nVMX: Add missing guest-state checks " Zihui Guo
2026-12-03  5:34 ` [PATCH 3/3] KVM: nVMX: Check the event injected into the HLT state " Zihui Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®