From nobody Tue Apr 30 06:28:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503586552995693.7732376661002; Thu, 24 Aug 2017 07:55:52 -0700 (PDT) Received: from localhost ([::1]:48924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dktXz-0002Jk-Nt for importer@patchew.org; Thu, 24 Aug 2017 10:55:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dktX6-0001b7-U7 for qemu-devel@nongnu.org; Thu, 24 Aug 2017 10:54:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dktX0-0004kr-MP for qemu-devel@nongnu.org; Thu, 24 Aug 2017 10:54:56 -0400 Received: from smtp.citrix.com ([66.165.176.89]:55145) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dktX0-0004jW-FM for qemu-devel@nongnu.org; Thu, 24 Aug 2017 10:54:50 -0400 X-IronPort-AV: E=Sophos;i="5.41,421,1498521600"; d="scan'208";a="436741532" From: Roger Pau Monne To: Date: Thu, 24 Aug 2017 15:54:45 +0100 Message-ID: <20170824145445.79575-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.11.0 (Apple Git-81) In-Reply-To: <20170824145445.79575-1-roger.pau@citrix.com> References: <20170824145445.79575-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.165.176.89 Subject: [Qemu-devel] [PATCH QEMU v3] xen/pt: allow QEMU to request MSI unmasking at bind time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anthony Perard , Stefano Stabellini , qemu-devel@nongnu.org, Jan Beulich , Roger Pau Monne Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 When a MSI interrupt is bound to a guest using xc_domain_update_msi_irq (XEN_DOMCTL_bind_pt_irq) the interrupt is left masked by default. This causes problems with guests that first configure interrupts and clean the per-entry MSIX table mask bit and afterwards enable MSIX globally. In such scenario the Xen internal msixtbl handlers would not detect the unmasking of MSIX entries because vectors are not yet registered since MSIX is not enabled, and vectors would be left masked. Introduce a new flag in the gflags field to signal Xen whether a MSI interrupt should be unmasked after being bound. This also requires to track the mask register for MSI interrupts, so QEMU can also notify to Xen whether the MSI interrupt should be bound masked or unmasked Signed-off-by: Roger Pau Monn=C3=A9 Reviewed-by: Jan Beulich Reported-by: Andreas Kinzler --- Cc: Stefano Stabellini Cc: Anthony Perard Cc: Jan Beulich Cc: qemu-devel@nongnu.org --- Changes since v2: - Fix coding style. Changes since v1: - Track MSI mask bits. - Notify Xen of whether MSI interrupts should be unmasked after binding, instead of hardcoding it. --- hw/xen/xen_pt.h | 1 + hw/xen/xen_pt_config_init.c | 19 +++++++++++++++++-- hw/xen/xen_pt_msi.c | 13 ++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h index 191d9caea1..aa39a9aa5f 100644 --- a/hw/xen/xen_pt.h +++ b/hw/xen/xen_pt.h @@ -180,6 +180,7 @@ typedef struct XenPTMSI { uint32_t addr_hi; /* guest message upper address */ uint16_t data; /* guest message data */ uint32_t ctrl_offset; /* saved control offset */ + uint32_t mask; /* guest mask bits */ int pirq; /* guest pirq corresponding */ bool initialized; /* when guest MSI is initialized */ bool mapped; /* when pirq is mapped */ diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 1f04ec5eec..9c724eeb62 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -1315,6 +1315,21 @@ static int xen_pt_msgdata_reg_write(XenPCIPassthroug= hState *s, return 0; } =20 +static int xen_pt_mask_reg_write(XenPCIPassthroughState *s, XenPTReg *cfg_= entry, + uint32_t *val, uint32_t dev_value, + uint32_t valid_mask) +{ + int rc; + + rc =3D xen_pt_long_reg_write(s, cfg_entry, val, dev_value, valid_mask); + if (rc) + return rc; + + s->msi->mask =3D *val; + + return 0; +} + /* MSI Capability Structure reg static information table */ static XenPTRegInfo xen_pt_emu_reg_msi[] =3D { /* Next Pointer reg */ @@ -1393,7 +1408,7 @@ static XenPTRegInfo xen_pt_emu_reg_msi[] =3D { .emu_mask =3D 0xFFFFFFFF, .init =3D xen_pt_mask_reg_init, .u.dw.read =3D xen_pt_long_reg_read, - .u.dw.write =3D xen_pt_long_reg_write, + .u.dw.write =3D xen_pt_mask_reg_write, }, /* Mask reg (if PCI_MSI_FLAGS_MASKBIT set, for 64-bit devices) */ { @@ -1404,7 +1419,7 @@ static XenPTRegInfo xen_pt_emu_reg_msi[] =3D { .emu_mask =3D 0xFFFFFFFF, .init =3D xen_pt_mask_reg_init, .u.dw.read =3D xen_pt_long_reg_read, - .u.dw.write =3D xen_pt_long_reg_write, + .u.dw.write =3D xen_pt_mask_reg_write, }, /* Pending reg (if PCI_MSI_FLAGS_MASKBIT set, for 32-bit devices) */ { diff --git a/hw/xen/xen_pt_msi.c b/hw/xen/xen_pt_msi.c index ff9a79f5d2..6d1e3bdeb4 100644 --- a/hw/xen/xen_pt_msi.c +++ b/hw/xen/xen_pt_msi.c @@ -24,6 +24,7 @@ #define XEN_PT_GFLAGS_SHIFT_DM 9 #define XEN_PT_GFLAGSSHIFT_DELIV_MODE 12 #define XEN_PT_GFLAGSSHIFT_TRG_MODE 15 +#define XEN_PT_GFLAGSSHIFT_UNMASKED 16 =20 #define latch(fld) latch[PCI_MSIX_ENTRY_##fld / sizeof(uint32_t)] =20 @@ -155,7 +156,8 @@ static int msi_msix_update(XenPCIPassthroughState *s, int pirq, bool is_msix, int msix_entry, - int *old_pirq) + int *old_pirq, + bool masked) { PCIDevice *d =3D &s->dev; uint8_t gvec =3D msi_vector(data); @@ -171,6 +173,8 @@ static int msi_msix_update(XenPCIPassthroughState *s, table_addr =3D s->msix->mmio_base_addr; } =20 + gflags |=3D masked ? 0 : (1u << XEN_PT_GFLAGSSHIFT_UNMASKED); + rc =3D xc_domain_update_msi_irq(xen_xc, xen_domid, gvec, pirq, gflags, table_addr); =20 @@ -273,8 +277,10 @@ int xen_pt_msi_setup(XenPCIPassthroughState *s) int xen_pt_msi_update(XenPCIPassthroughState *s) { XenPTMSI *msi =3D s->msi; + + /* Current MSI emulation in QEMU only supports 1 vector */ return msi_msix_update(s, msi_addr64(msi), msi->data, msi->pirq, - false, 0, &msi->pirq); + false, 0, &msi->pirq, msi->mask & 1); } =20 void xen_pt_msi_disable(XenPCIPassthroughState *s) @@ -355,7 +361,8 @@ static int xen_pt_msix_update_one(XenPCIPassthroughStat= e *s, int entry_nr, } =20 rc =3D msi_msix_update(s, entry->addr, entry->data, pirq, true, - entry_nr, &entry->pirq); + entry_nr, &entry->pirq, + vec_ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT); =20 if (!rc) { entry->updated =3D false; --=20 2.11.0 (Apple Git-81)