All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: "Ross Lagerwall" <ross.lagerwall@citrix.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Jason Andryuk" <jason.andryuk@amd.com>,
	"Teddy Astie" <teddy.astie@vates.tech>
Subject: [PATCH v1 5/6] nestedsvm: Fix deferred event injection
Date: Tue, 26 May 2026 13:40:26 +0100	[thread overview]
Message-ID: <20260526124027.573412-6-ross.lagerwall@citrix.com> (raw)
In-Reply-To: <20260526124027.573412-1-ross.lagerwall@citrix.com>

If an event for L1 occurs while L2 is running, Xen should inject
VMEXIT_INTR and the event into L1.

nestedsvm_vcpu_interrupt() and nestedsvm_vmexit_defer() set this up to
be handled later by nsvm_vcpu_vmexit_inject() after the switch back to
L1. However, the code there appears to be bogus and completely ignores
the source/vector set up in the first place. Fix this by using the
values to properly inject the event.

Fixes: 9a779e4fc161 ("Implement SVM specific part for Nested Virtualization")
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
 xen/arch/x86/hvm/svm/intr.c      |  4 ++--
 xen/arch/x86/hvm/svm/nestedsvm.c | 22 ++++++++++++++++++----
 xen/arch/x86/hvm/svm/svm.h       |  3 +++
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/intr.c b/xen/arch/x86/hvm/svm/intr.c
index cf0621d2f628..8914375b6c21 100644
--- a/xen/arch/x86/hvm/svm/intr.c
+++ b/xen/arch/x86/hvm/svm/intr.c
@@ -55,7 +55,7 @@ static void svm_inject_nmi(struct vcpu *v)
         vmcb, general1_intercepts | GENERAL1_INTERCEPT_IRET);
 }
 
-static void svm_inject_extint(struct vcpu *v, int vector)
+void svm_inject_extint(struct vcpu *v, int vector)
 {
     struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
     intinfo_t event;
@@ -69,7 +69,7 @@ static void svm_inject_extint(struct vcpu *v, int vector)
     vmcb->event_inj = event;
 }
 
-static void svm_enable_intr_window(struct vcpu *v, struct hvm_intack intack)
+void svm_enable_intr_window(struct vcpu *v, struct hvm_intack intack)
 {
     struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
     uint32_t general1_intercepts = vmcb_get_general1_intercepts(vmcb);
diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 9b0bd0358ce4..d4fd838ca0b6 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -733,11 +733,25 @@ nsvm_vcpu_vmexit_inject(struct vcpu *v, struct cpu_user_regs *regs,
         switch ( exitcode )
         {
         case VMEXIT_INTR:
-            if ( unlikely(ns_vmcb->event_inj.v) && nv->nv_vmentry_pending &&
-                 hvm_event_needs_reinjection(ns_vmcb->event_inj.type,
-                                             ns_vmcb->event_inj.vector) )
-                ns_vmcb->exit_int_info = ns_vmcb->event_inj;
+        {
+            struct hvm_intack intack = {
+                .source = svm->ns_vmexit.exitinfo1,
+                .vector = svm->ns_vmexit.exitinfo2
+            };
+
+            /* See the comment in svm_intr_assist() for why this is necessary */
+            if ( unlikely(vmcb->event_inj.v) ||
+                 hvm_interrupt_blocked(v, intack) )
+            {
+                svm_enable_intr_window(v, intack);
+                break;
+            }
+
+            svm_inject_extint(v, intack.vector);
+            pt_intr_post(v, intack);
             break;
+        }
+
         case VMEXIT_EXCEPTION_PF:
             ns_vmcb->_cr2 = ns_vmcb->ei.exc.cr2;
             fallthrough;
diff --git a/xen/arch/x86/hvm/svm/svm.h b/xen/arch/x86/hvm/svm/svm.h
index cfa411ad5ae1..186e0905967c 100644
--- a/xen/arch/x86/hvm/svm/svm.h
+++ b/xen/arch/x86/hvm/svm/svm.h
@@ -95,6 +95,9 @@ enum vmcb_sync_state {
 
 void svm_sync_vmcb(struct vcpu *v, enum vmcb_sync_state new_state);
 
+void svm_inject_extint(struct vcpu *v, int vector);
+void svm_enable_intr_window(struct vcpu *v, struct hvm_intack intack);
+
 #endif /* __X86_HVM_SVM_SVM_PRIV_H__ */
 
 /*
-- 
2.53.0



  parent reply	other threads:[~2026-05-26 12:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 12:40 [PATCH v1 0/6] nestedsvm: Misc fixes Ross Lagerwall
2026-05-26 12:40 ` [PATCH v1 1/6] nestedsvm: Fix CR3 MBZ check Ross Lagerwall
2026-05-26 13:01   ` Andrew Cooper
2026-05-26 13:23     ` Ross Lagerwall
2026-08-06 10:43       ` Ross Lagerwall
2026-06-25 11:58     ` Jan Beulich
2026-05-26 12:40 ` [PATCH v1 2/6] nestedsvm: Adjust L2's DR intercept when adjusting L1 Ross Lagerwall
2026-05-26 13:45   ` Andrew Cooper
2026-05-26 12:40 ` [PATCH v1 3/6] nestedsvm: Use the correct VMCB for vGIF Ross Lagerwall
2026-05-26 12:40 ` [PATCH v1 4/6] nestedsvm: Set GIF during VMRUN if vGIF is enabled Ross Lagerwall
2026-05-26 12:40 ` Ross Lagerwall [this message]
2026-09-11 10:56   ` [PATCH v1 5/6] nestedsvm: Fix deferred event injection Andrew Cooper
2026-09-11 13:37     ` Ross Lagerwall
2026-05-26 12:40 ` [PATCH v1 6/6] nestedsvm: Allow destroying the domain fully Ross Lagerwall
2026-06-25 12:11   ` Jan Beulich
2026-08-06 10:46 ` [PATCH v1 0/6] nestedsvm: Misc fixes Ross Lagerwall

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=20260526124027.573412-6-ross.lagerwall@citrix.com \
    --to=ross.lagerwall@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jason.andryuk@amd.com \
    --cc=jbeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=teddy.astie@vates.tech \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.