From: Sohil Mehta <sohil.mehta@intel.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>, Xin Li <xin@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Nikunj A Dadhania <nikunj@amd.com>,
Shivansh Dhiman <shivansh.dhiman@amd.com>,
Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Chao Gao <chao.gao@intel.com>,
Binbin Wu <binbin.wu@linux.intel.com>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Sohil Mehta <sohil.mehta@intel.com>,
Yosry Ahmed <yosry@kernel.org>,
David Matlack <dmatlack@google.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH 2/4] KVM: nVMX: Don't drop an L1-injected INT1 whose delivery is interrupted
Date: Wed, 2 Dec 2026 00:02:22 -0800 [thread overview]
Message-ID: <20261202080224.4165883-3-sohil.mehta@intel.com> (raw)
In-Reply-To: <20261202080224.4165883-1-sohil.mehta@intel.com>
Currently, KVM doesn't inject a privileged software exception itself,
but L1 can inject an INT1 into L2. If a VM-exit interrupts the delivery
of the INT1, KVM drops it, as it requeues only hardware and software
exceptions. For example, a delivery is interrupted when it touches an
IDT or stack page that isn't mapped yet.
If KVM handles the VM-exit itself, L2 then resumes without the INT1. If
L1 handles it, L1 doesn't find the INT1 in the IDT-vectoring information
and can't re-inject it.
Handle an INT1 the way KVM handles a software exception, which also
needs its instruction length. Requeue it with its length, re-inject it
with its own event type, and report it to L1 with that type and length.
Check the event type before the vector, as L1 can inject a privileged
software exception with any vector.
When the INT1 goes through a task gate, KVM emulates the task switch.
Clear the requeued INT1 there, so that KVM doesn't inject it twice. And
leave a queued INT1 out of the vCPU events, as the uAPI doesn't provide
a mechanism to carry its length.
Signed-off-by: Sohil Mehta <sohil.mehta@intel.com>
---
Patch 3 relies on this patch, as it makes KVM inject an ICEBP's #DB as
a privileged software exception. Without this patch, KVM would inject
that #DB as a hardware exception with RIP still on the ICEBP. The guest
would then execute the ICEBP forever, and patch 4's test would hang.
No Fixes tag, as KVM has dropped this event type ever since nested VMX
started passing L1's injected events through to L2.
---
arch/x86/kvm/vmx/nested.c | 13 ++++++++++---
arch/x86/kvm/vmx/vmx.c | 12 ++++++++++--
arch/x86/kvm/x86.c | 11 ++++++-----
3 files changed, 26 insertions(+), 10 deletions(-)
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;
+ }
if (vcpu->arch.exception.has_error_code) {
idt_vectoring |= VECTORING_INFO_DELIVER_CODE_MASK;
@@ -4085,7 +4090,9 @@ static void nested_vmx_inject_exception_vmexit(struct kvm_vcpu *vcpu)
intr_info |= INTR_INFO_DELIVER_CODE_MASK;
}
- if (kvm_exception_is_soft(ex->vector))
+ if (ex->event_type == EVENT_TYPE_PRIV_SWEXC)
+ intr_info |= INTR_TYPE_PRIV_SW_EXCEPTION;
+ else if (kvm_exception_is_soft(ex->vector))
intr_info |= INTR_TYPE_SOFT_EXCEPTION;
else
intr_info |= INTR_TYPE_HARD_EXCEPTION;
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 (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)) {
vmcs_write32(VM_ENTRY_INSTRUCTION_LEN,
vmx->vcpu.arch.event_exit_inst_len);
intr_info |= INTR_TYPE_SOFT_EXCEPTION;
- } else
+ } else {
intr_info |= INTR_TYPE_HARD_EXCEPTION;
+ }
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info);
@@ -5946,6 +5952,7 @@ static int handle_task_switch(struct kvm_vcpu *vcpu)
vmcs_read32(IDT_VECTORING_ERROR_CODE);
}
fallthrough;
+ case INTR_TYPE_PRIV_SW_EXCEPTION:
case INTR_TYPE_SOFT_EXCEPTION:
kvm_clear_exception_queue(vcpu);
break;
@@ -7185,6 +7192,7 @@ static void __vmx_complete_interrupts(struct kvm_vcpu *vcpu,
*/
vmx_set_nmi_mask(vcpu, false);
break;
+ case INTR_TYPE_PRIV_SW_EXCEPTION:
case INTR_TYPE_SOFT_EXCEPTION:
vcpu->arch.event_exit_inst_len = vmcs_read32(instr_len_field);
fallthrough;
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,
memset(events, 0, sizeof(*events));
/*
- * The API doesn't provide the instruction length for software
- * exceptions, so don't report them. As long as the guest RIP
- * isn't advanced, we should expect to encounter the exception
- * again.
+ * The API doesn't provide the instruction length that software
+ * exceptions and INT1 need, so don't report them. As long as the
+ * guest RIP isn't advanced, we should expect to encounter the
+ * exception again.
*/
- if (!kvm_exception_is_soft(ex->vector)) {
+ if (!kvm_exception_is_soft(ex->vector) &&
+ ex->event_type != EVENT_TYPE_PRIV_SWEXC) {
events->exception.injected = ex->injected;
events->exception.pending = ex->pending;
/*
--
2.43.0
next prev parent reply other threads:[~2026-12-02 8:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 8:02 [PATCH 0/4] KVM: VMX: Handle the #DB of an ICEBP as a privileged software exception Sohil Mehta
2026-12-02 8:02 ` [PATCH 1/4] KVM: x86: Track the event type of a queued exception Sohil Mehta
2026-12-02 8:02 ` Sohil Mehta [this message]
2026-12-02 8:02 ` [PATCH 3/4] KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception Sohil Mehta
2026-12-02 8:02 ` [PATCH 4/4] KVM: selftests: Test how L1 sees the #DB of an ICEBP in L2 Sohil Mehta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202080224.4165883-3-sohil.mehta@intel.com \
--to=sohil.mehta@intel.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=andrew.cooper3@citrix.com \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dmatlack@google.com \
--cc=dwmw@amazon.co.uk \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=shivansh.dhiman@amd.com \
--cc=skhan@linuxfoundation.org \
--cc=tglx@kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
--cc=yosry@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®