[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3] x86/nsvm: Fix L2 VINTR intercept merging when only Xen intercepts L1



When nesting SVM, if the L1 hypervisor has not requested a virtual interrupt
(VINTR) intercept for L2 while enabling the V_INTR_MASKING for the L2, Xen
should not force one. In such configuration, L2 execution should remain
isolated from the L1 VINTR state, and there should be no expectation that L2
execution results in an L1 VINTR becoming deliverable.

Currently, if Xen intercepts the VINTR for its own L1 management, this
intercept may unexpectedly cause an intercept during L2 execution under this
configuration. This breaks the expected transparency of L1 configuration and
introduces unnecessary VMEXIT. Later, when Xen handles this forced
VMEXIT_VINTR, it can result in losing L1's pending virtual interrupt for L2.
This occurs because when the intercept is determined to be requested solely by
the host (returning NESTEDHVM_VMEXIT_HOST), svm_vmexit_handler clears the
executing L2 VMCB's fields, in particular clearing the L1 set V_IRQ.

There is still an edge case where L1 might pend receiving IRQ and still expects
L2 to receive the L1 IRQ (i.e., when L1 clears the V_INTR_MASKING while its
EFLAGS.IF is not set).

Fix this by ensuring the L2 VINTR intercept bit in the L2 execution VMCB
correctly reflects the L1's configuration for its guest.

Signed-off-by: Abdelkareem Abdelsaamad <abdelkareem.abdelsaamad@xxxxxxxxxx>
---
Changes in v3:
- Fix the commit message description.
- Add a comment explaining the check.

Changes in v2:
- Rephrased the commit message description.
- Adjusted the condition to account for cleared L2 V_INTR_MASKING.
- Rebased on master.
---
Testing:
 - Setup (using a custom XTF nested virtualization test), on top of the series
   
https://lore.kernel.org/xen-devel/cover.1790146987.git.chunjie.zhu@xxxxxxxxxx/
   
https://lore.kernel.org/xen-devel/cover.1794482561.git.chunjie.zhu@xxxxxxxxxx/
   1. An L1 maskable interrupt is triggered while L1 has physical interrupts
      disabled (via the CLI), leaving the interrupt pending.
   2. Xen enables L1's VINTR_INTERCEPT to catch the next available VINTR
      window.
   3. L2 is launched via VMRUN and configured with
      * An injected virtual interrupt on a distinct vector from
        the pending L1 interrupt.(i.e., L1 sets L2's VMCB V_INTR_VECTOR, V_IRQ
        and V_INTR_PRIO).
      * L1 clears L2 VMCB VINTR_INTERCEPT.
      * L1 also configures L2 with L2 EFLAGS.IF = 0 or 1, L2 vGIF unmasked, and
        L2 V_INTR_MASKING enabled.
      * L2 is executing (sti;nop;hlt;)

   Results:
     - Current Behaviour: The L2 injected vector is not triggered. L1 sees
       L2's VMCB V_IRQ_PENDING is cleared upon VMEXIT_HLT.
     - New Behaviour: The L2 injected vector is triggered in the L2 and no
       unnecessary VMEXIT_VINTR occurs in Xen while executing L2.

 - CI tests:
https://gitlab.com/xen-project/people/aabdelsa/xen/-/pipelines/3074834879
---
 xen/arch/x86/hvm/svm/nestedsvm.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 81cae929dd..b40a6b56ce 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -403,6 +403,15 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct 
cpu_user_regs *regs)
     n2vmcb->_general2_intercepts =
         n1vmcb->_general2_intercepts | ns_vmcb->_general2_intercepts;
 
+    /*
+     * Xen's VINTR intercept only works together with its dummy V_IRQ, which
+     * remains set in the L1 VMCB.  With V_INTR_MASKING set, L2 cannot unmask
+     * L1's interrupts, so the intercept is not needed here.
+     */
+    if ( ns_vmcb->_vintr.vintr_masking &&
+         !(ns_vmcb->_general1_intercepts & GENERAL1_INTERCEPT_VINTR) )
+        n2vmcb->_general1_intercepts &= ~GENERAL1_INTERCEPT_VINTR;
+
     /* Nested Pause Filter */
     if ( ns_vmcb->_general1_intercepts & GENERAL1_INTERCEPT_PAUSE )
         n2vmcb->_pause_filter_count =
-- 
2.53.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.