Re: [PATCH 2/4] KVM: nVMX: Don't drop an L1-injected INT1 whose delivery is interrupted
From: Chao Gao
Date: Fri Dec 04 2026 - 04:41:31 EST
On Wed, Dec 02, 2026 at 04:02:22PM +0800, Sohil Mehta wrote:
>diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
>index 1a98f28651f7..6cb07873998d 100644
>--- a/arch/x86/kvm/vmx/nested.c
>+++ b/arch/x86/kvm/vmx/nested.c
>@@ -3970,12 +3970,17 @@ static void vmcs12_save_pending_event(struct kvm_vcpu *vcpu,
> nr = vcpu->arch.exception.vector;
> idt_vectoring = nr | VECTORING_INFO_VALID_MASK;
>
>- if (kvm_exception_is_soft(nr)) {
>+ if (vcpu->arch.exception.event_type == EVENT_TYPE_PRIV_SWEXC) {
>+ vmcs12->vm_exit_instruction_len =
>+ vcpu->arch.event_exit_inst_len;
>+ idt_vectoring |= INTR_TYPE_PRIV_SW_EXCEPTION;
>+ } else if (kvm_exception_is_soft(nr)) {
> vmcs12->vm_exit_instruction_len =
> vcpu->arch.event_exit_inst_len;
> idt_vectoring |= INTR_TYPE_SOFT_EXCEPTION;
>- } else
>+ } else {
> idt_vectoring |= INTR_TYPE_HARD_EXCEPTION;
>+ }
Can we derive the type in idt_vectoring from the event type?
idt_vectoring |= vcpu->arch.exception.event_type << 8;
And then set vm_exit_instruction_len only if the event is a software
exception or a privileged software exception.
if (vcpu->arch.exception.event_type == EVENT_TYPE_PRIV_SWEXC ||
vcpu->arch.exception.event_type == EVENT_TYPE_SWEXC)
vmcs12->vm_exit_instruction_len =
vcpu->arch.event_exit_inst_len;
This is much more readable than the if/else chain. The same applies to
nested_vmx_inject_exception_vmexit() and vmx_inject_exception() below.
>diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>index a6c0e8ccdfad..fdc531a61fd3 100644
>--- a/arch/x86/kvm/vmx/vmx.c
>+++ b/arch/x86/kvm/vmx/vmx.c
>@@ -1973,12 +1973,18 @@ void vmx_inject_exception(struct kvm_vcpu *vcpu)
>
> WARN_ON_ONCE(vmx->vt.emulation_required);
>
>- if (kvm_exception_is_soft(ex->vector)) {
>+ /* L1 can inject a privileged software exception with any vector. */
If the event type is the only source of the type here, you don't need
to worry about the order of the event type and vector checks, and this
comment can go.
>+ if (ex->event_type == EVENT_TYPE_PRIV_SWEXC) {
>+ vmcs_write32(VM_ENTRY_INSTRUCTION_LEN,
>+ vmx->vcpu.arch.event_exit_inst_len);
>+ intr_info |= INTR_TYPE_PRIV_SW_EXCEPTION;
>+ } else if (kvm_exception_is_soft(ex->vector)) {
>diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>index c27813bde407..b58518a777de 100644
>--- a/arch/x86/kvm/x86.c
>+++ b/arch/x86/kvm/x86.c
>@@ -3010,12 +3010,13 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
> */
>- if (!kvm_exception_is_soft(ex->vector)) {
>+ if (!kvm_exception_is_soft(ex->vector) &&
>+ ex->event_type != EVENT_TYPE_PRIV_SWEXC) {
With the event type, this becomes a check for a software exception or
a privileged software exception.
ex->event_type == EVENT_TYPE_PRIV_SWEXC ||
ex->event_type == EVENT_TYPE_SWEXC
That check then occurs in a few places, so we can probably add a helper
for it.