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

[PATCH v3 2/3] x86/nestedsvm: honour L2's EFLAGS.IF when L1 clears V_INTR_MASKING


  • To: ross.lagerwall@xxxxxxxxxx
  • From: chunjie.zhu@xxxxxxxxxx
  • Date: Thu, 12 Nov 2026 19:35:24 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cvQyzHtfHuw5YwzIwbOty2rLf4ntuJzRbidOWxJhk/g=; b=DYVbYWq735lNPmMaD9ehtlAh87QOW1gnB++LHnc5F9rTLaeOzoopS7K44Tq4AmkWbV6f55DeyQOy+A/KZHUref921QhWRe/kcXzaiFNnUcoA3ZLNjptCb/+VmYwrCJ9X1bZ3kKfWQSdJQh9fHQdtohqaDoYP+XTqtbqBA0Jf15dioauOOJeSAqUqhXRjznsOyrkG0ISTpRZ866tv/qp9IHvuaVbwXmyg5lQI9CsQklcaAWB/DToLTw+pp2pY23nK+hJ3GcqCU5OQPO5dusgrp/D2f87A3qZf5l6V7Q8DUtNcLXOK5P7voLPp9zmZEwMx3xAQb8as4k1bcDOjCKhmYQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GLrjm0PLK00r0Io/OWDDYAqbVim62tJNa1iGTy3Sv6/+6cAIVtrqksf+1sqUaAAzh3dS0OGQi9FG3Npk1eebBOYavWVDysVTeedfXLIiokTNoPDVw5/INTxq8xJ2IiVP6k+Lmi8r5fTfyemoPffMDw+LCIjUVAKeA1MKxXWcK1oxmZnEfWQGi58nH8ph8r34neuWQlCnIRNEW6SsGxhkvLU41Yu0WT+4did+hSKRW/QgDWl7cGnNgHFhe3a0eTWEzCEOWbF01imgo9by89G3hNxx+v9tIr4TCt9hmukqWopfi50dyIFULXAbpcqtuRpT1rEDYdzLBSnyA0PSKO28vw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: andrew.cooper3@xxxxxxxxxx, chunjie.zhu@xxxxxxxxxx, jason.andryuk@xxxxxxx, jbeulich@xxxxxxxx, roger@xxxxxxxxxxxxxx, teddy.astie@xxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Thu, 12 Nov 2026 11:36:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>

L0 always runs L2 with V_INTR_MASKING set, so a physical interrupt exits to
L0 regardless of L2's EFLAGS.IF.  nsvm_intr_blocked() only blocks when L1
requested V_INTR_MASKING=1 and L1's IF was clear.  With V_INTR_MASKING=0
and L2's IF clear, nestedsvm_vcpu_interrupt() would still inject
VMEXIT(INTR) into L1.

Per the APM (vol.2 rev 3.44 "Physical Interrupt Masking in EFLAGS"), with
V_INTR_MASKING=0 L2's IF masks physical interrupts, and a masked interrupt
must stay pending.  Return NSVM_INTR_MASKED for external interrupts in
that case.

Signed-off-by: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
---
v3:
 * Add ASSERT(v == current), as suggested by Ross.
 * Rebased on staging.

 xen/arch/x86/hvm/svm/nestedsvm.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 40c7717c5572..706aed8ed026 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -1150,6 +1150,7 @@ enum hvm_intblk cf_check nsvm_intr_blocked(struct vcpu *v)
     struct nestedsvm *svm = &vcpu_nestedsvm(v);
     struct nestedvcpu *nv = &vcpu_nestedhvm(v);
 
+    ASSERT(v == current);
     ASSERT(nestedhvm_enabled(v->domain));
 
     if ( !nestedsvm_gif_isset(v) )
@@ -1159,7 +1160,16 @@ enum hvm_intblk cf_check nsvm_intr_blocked(struct vcpu 
*v)
     {
         struct vmcb_struct *n2vmcb = nv->nv_n2vmcx;
 
-        if ( svm->ns_hostflags.vintrmask && !svm->ns_hostflags.rflagsif )
+        /*
+         * With V_INTR_MASKING, L1's EFLAGS.IF masks physical interrupts.
+         * Without it, L2's EFLAGS.IF does (APM vol.2 rev 3.44 "Physical
+         * Interrupt Masking in EFLAGS"); L0 always runs L2 with
+         * V_INTR_MASKING set, so the interrupt would otherwise exit to L0
+         * and be forwarded to L1 even with L2's IF clear.
+         */
+        if ( svm->ns_hostflags.vintrmask
+             ? !svm->ns_hostflags.rflagsif
+             : !(guest_cpu_user_regs()->eflags & X86_EFLAGS_IF) )
             return hvm_intblk_rflags_ie;
 
         /* when l1 guest passes its devices through to the l2 guest
-- 
2.34.1




 


Rackspace

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