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

[PATCH v2] 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 \ overwriting an already injected L2
virtual interrupt. 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 VIRQ_PENDING.

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_MASKIN 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 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):
   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 Vector, VIRQ_PENDING
        and VIRQ_PRIORITY).
      * 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 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 81cae929dd..e09d5f3186 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -403,6 +403,10 @@ static int nsvm_vmcb_prepare4vmrun(struct vcpu *v, struct 
cpu_user_regs *regs)
     n2vmcb->_general2_intercepts =
         n1vmcb->_general2_intercepts | ns_vmcb->_general2_intercepts;
 
+    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®.