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

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


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: chunjie.zhu@xxxxxxxxxx
  • Date: Fri, 27 Nov 2026 11:49:46 +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=3/WbUQZAbDDicdPQE0kH2ARjTx0M+ZDVHr3waq35m+w=; b=Nde7/Axz2sdWg741NOziyvJhC8+MTrV0/zQVTiokVDO0T/zjjUiUhCVpLO1rv3YkEHaE+n/qSYSl6Xzdl3mdMiD1pKT70Qjd73AqPHRgBeVRoUDG8lLwYcZ1cj4uK8zaF75HMcwD5krlhGkX34kHHPdimTSrsVbBBWxi1kwhidDp+tuNqL54QtiKyQWZnod5qQJk01p5MWsDXmS0oJpYCyAcWBQtITBXTUfZ0H2aAN/QkPNY3H1Cpfm9ZqiQxWi/5/YwgDnSTnOR69MR9x+AuHTrMRhMVDe+NnKe3r6FlCCpqQtzZeR+nw/LCZUkcSu+QyVo7otuDNeyWj3RpZFtDg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=R2mTVSFx+ksiZpynuL1XdRMGUxswWR7bo9ERSaCfeByOs1VqVxfXtEBG3IwsDJJdT2y9mXsQA692FLfuj7RWEJeqSSXP2fqDEC74qvtUX7MnYc41frg0HXdt7lMiZr+FRFgFKYyY6QgAsi+z3WVt/WGjqHpyJwevH9D0N/WoiNHaU4a9S0BojqNqiefwIOBywthpDgPsCAvRa2002boNb/xBnHiZilBLJ1j6nyJfDuPEVRW3m2pJgEUb8FQtgJiLqDlmqj2qlp+/9oJg9uiC4QhnFQ612OPr/adzaeJ5xi5NovP68bS5bh+7AjqcPjEyEdBUHxrYlXRCUxpM9L3XCw==
  • 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: ross.lagerwall@xxxxxxxxxx, jbeulich@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger@xxxxxxxxxxxxxx, jason.andryuk@xxxxxxx, teddy.astie@xxxxxxxxxx, Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
  • Delivery-date: Fri, 27 Nov 2026 03:50:52 +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.

Fixes: 3a1ef3c33fa7 ("Implement SVM specific interrupt handling")
Signed-off-by: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
Reviewed-by: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
---
v3->v4: add Fixes: tag(s), collect Reviewed-by (Ross)
 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 f366d9b92be3..c75fb8efbac9 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -1146,6 +1146,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) )
@@ -1155,7 +1156,16 @@ enum hvm_intblk cf_check nsvm_intr_blocked(struct vcpu 
*v)
     {
         struct vmcb *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®.