From nobody Mon Feb 9 14:17:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1620661711; cv=none; d=zohomail.com; s=zohoarc; b=YZMmuELWqrVGBT9JZ5LpljFifXth0LW+8/53J2s5eBnUMVYXkVxxGjFs0xUe2eQAlgQ3OmWG5GLXsgaO8MGdOfnmR2t7haJ3G7aLoIfcnXf2WYxqU621FIjCtfl/COFwemasluW5oGISR8Qar9LCZ9imbcWKAAs9p8mwh0a4NJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620661711; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=rg5tA45C9bjCD1GfjFQJDK0zPPW9wkQF8MR64pCV63Q=; b=KWtFQMwINA/7xlpv6oc0YSHXSRhI8LNeEvGDTHSpWwwgGAIRJgyHEj3elzlDnVAHwJsB9s38zMjxEcDdgbXw67MbOBlPpNigDzdXntBAsmq6UmEK53yzVyvOEFEmNcJUok2iqlCQ+X8ov92Kn/wTF55TZOli/Of1JkkcMUk0MDg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1620661711134418.17289853413706; Mon, 10 May 2021 08:48:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.125348.235954 (Exim 4.92) (envelope-from ) id 1lg88p-0005oI-0t; Mon, 10 May 2021 15:48:19 +0000 Received: by outflank-mailman (output) from mailman id 125348.235954; Mon, 10 May 2021 15:48:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg88o-0005oB-U1; Mon, 10 May 2021 15:48:18 +0000 Received: by outflank-mailman (input) for mailman id 125348; Mon, 10 May 2021 15:48:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lg88n-0005kO-5S for xen-devel@lists.xenproject.org; Mon, 10 May 2021 15:48:17 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 03ff9d8b-7816-49a7-b3dc-18f0d05f1b0d; Mon, 10 May 2021 15:48:15 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6CF0F168F; Mon, 10 May 2021 08:48:15 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DB5433F73B; Mon, 10 May 2021 08:48:13 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 03ff9d8b-7816-49a7-b3dc-18f0d05f1b0d From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Jan Beulich , Paul Durrant , Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu , Daniel De Graaf Subject: [PATCH v5 2/2] xen/pci: Refactor MSI code that implements MSI functionality within XEN Date: Mon, 10 May 2021 16:47:27 +0100 Message-Id: <2843d1c399e8ed81d807e680147cac5cd601d28a.1620661205.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" MSI code that implements MSI functionality to support MSI within XEN is not usable on ARM. Move the code under CONFIG_HAS_PCI_MSI_INTERCEPT flag to gate the code for ARM. Currently, we have no idea how MSI functionality will be supported for other architecture therefore we have decided to move the code under CONFIG_PCI_MSI_INTERCEPT. We know this is not the right flag to gate the code but to avoid an extra flag we decided to use this. No functional change intended. Signed-off-by: Rahul Singh --- xen/drivers/passthrough/msi-intercept.c | 41 +++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 34 ++++---------------- xen/include/xen/msi-intercept.h | 11 ++++++- xen/include/xen/pci.h | 11 ++++--- xen/xsm/flask/hooks.c | 8 ++--- 5 files changed, 68 insertions(+), 37 deletions(-) diff --git a/xen/drivers/passthrough/msi-intercept.c b/xen/drivers/passthro= ugh/msi-intercept.c index 757f3fc236..3f9d4f480b 100644 --- a/xen/drivers/passthrough/msi-intercept.c +++ b/xen/drivers/passthrough/msi-intercept.c @@ -44,6 +44,47 @@ void pdev_dump_msi(const struct pci_dev *pdev) printk(">"); } =20 +int pdev_msi_init(struct pci_dev *pdev) +{ + unsigned int pos; + + INIT_LIST_HEAD(&pdev->msi_list); + + pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn= ), + PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSI); + if ( pos ) + { + uint16_t ctrl =3D pci_conf_read16(pdev->sbdf, msi_control_reg(pos)= ); + + pdev->msi_maxvec =3D multi_msi_capable(ctrl); + } + + pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn= ), + PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSIX); + if ( pos ) + { + struct arch_msix *msix =3D xzalloc(struct arch_msix); + uint16_t ctrl; + + if ( !msix ) + return -ENOMEM; + + spin_lock_init(&msix->table_lock); + + ctrl =3D pci_conf_read16(pdev->sbdf, msix_control_reg(pos)); + msix->nr_entries =3D msix_table_size(ctrl); + + pdev->msix =3D msix; + } + + return 0; +} + +void pdev_msi_deinit(struct pci_dev *pdev) +{ + XFREE(pdev->msix); +} + /* * Local variables: * mode: C diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 237461b4ab..a3ec85c293 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -314,6 +314,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg,= u8 bus, u8 devfn) { struct pci_dev *pdev; unsigned int pos; + int rc; =20 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) if ( pdev->bus =3D=3D bus && pdev->devfn =3D=3D devfn ) @@ -327,35 +328,12 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pse= g, u8 bus, u8 devfn) *((u8*) &pdev->bus) =3D bus; *((u8*) &pdev->devfn) =3D devfn; pdev->domain =3D NULL; - INIT_LIST_HEAD(&pdev->msi_list); - - pos =3D pci_find_cap_offset(pseg->nr, bus, PCI_SLOT(devfn), PCI_FUNC(d= evfn), - PCI_CAP_ID_MSI); - if ( pos ) - { - uint16_t ctrl =3D pci_conf_read16(pdev->sbdf, msi_control_reg(pos)= ); =20 - pdev->msi_maxvec =3D multi_msi_capable(ctrl); - } - - pos =3D pci_find_cap_offset(pseg->nr, bus, PCI_SLOT(devfn), PCI_FUNC(d= evfn), - PCI_CAP_ID_MSIX); - if ( pos ) + rc =3D pdev_msi_init(pdev); + if ( rc ) { - struct arch_msix *msix =3D xzalloc(struct arch_msix); - uint16_t ctrl; - - if ( !msix ) - { - xfree(pdev); - return NULL; - } - spin_lock_init(&msix->table_lock); - - ctrl =3D pci_conf_read16(pdev->sbdf, msix_control_reg(pos)); - msix->nr_entries =3D msix_table_size(ctrl); - - pdev->msix =3D msix; + xfree(pdev); + return NULL; } =20 list_add(&pdev->alldevs_list, &pseg->alldevs_list); @@ -449,7 +427,7 @@ static void free_pdev(struct pci_seg *pseg, struct pci_= dev *pdev) } =20 list_del(&pdev->alldevs_list); - xfree(pdev->msix); + pdev_msi_deinit(pdev); xfree(pdev); } =20 diff --git a/xen/include/xen/msi-intercept.h b/xen/include/xen/msi-intercep= t.h index 5cfc21662c..08e467ff79 100644 --- a/xen/include/xen/msi-intercept.h +++ b/xen/include/xen/msi-intercept.h @@ -23,9 +23,10 @@ =20 int pdev_msix_assign(struct domain *d, struct pci_dev *pdev); void pdev_dump_msi(const struct pci_dev *pdev); +int pdev_msi_init(struct pci_dev *pdev); +void pdev_msi_deinit(struct pci_dev *pdev); =20 #else /* !CONFIG_HAS_PCI_MSI_INTERCEPT */ - static inline int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) { return 0; @@ -33,6 +34,14 @@ static inline int pdev_msix_assign(struct domain *d, str= uct pci_dev *pdev) =20 static inline void pdev_dump_msi(const struct pci_dev *pdev) {} =20 +static inline int pdev_msi_init(struct pci_dev *pdev) +{ + return 0; +} + +static inline void pdev_msi_deinit(struct pci_dev *pdev) {} +static inline void pci_cleanup_msi(struct pci_dev *pdev) {} + #endif /* CONFIG_HAS_PCI_MSI_INTERCEPT */ =20 #endif /* __XEN_MSI_INTERCEPT_H */ diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 8e3d4d9454..01a92ce9e6 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -79,10 +79,6 @@ struct pci_dev { struct list_head alldevs_list; struct list_head domain_list; =20 - struct list_head msi_list; - - struct arch_msix *msix; - struct domain *domain; =20 const union { @@ -94,7 +90,14 @@ struct pci_dev { pci_sbdf_t sbdf; }; =20 +#ifdef CONFIG_HAS_PCI_MSI_INTERCEPT + struct list_head msi_list; + + struct arch_msix *msix; + uint8_t msi_maxvec; +#endif + uint8_t phantom_stride; =20 nodeid_t node; /* NUMA node */ diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index f1a1217c98..024c368fb8 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -21,7 +21,7 @@ #include #include #include -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI_INTERCEPT #include #endif #include @@ -114,7 +114,7 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_au= dit_data *ad) } return security_irq_sid(irq, sid); } -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI_INTERCEPT { struct irq_desc *desc =3D irq_to_desc(irq); if ( desc->msi_desc && desc->msi_desc->dev ) { @@ -874,7 +874,7 @@ static int flask_map_domain_pirq (struct domain *d) static int flask_map_domain_msi (struct domain *d, int irq, const void *da= ta, u32 *sid, struct avc_audit_data *ad) { -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI_INTERCEPT const struct msi_info *msi =3D data; u32 machine_bdf =3D (msi->seg << 16) | (msi->bus << 8) | msi->devfn; =20 @@ -940,7 +940,7 @@ static int flask_unmap_domain_pirq (struct domain *d) static int flask_unmap_domain_msi (struct domain *d, int irq, const void *= data, u32 *sid, struct avc_audit_data *ad) { -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI_INTERCEPT const struct pci_dev *pdev =3D data; u32 machine_bdf =3D (pdev->seg << 16) | (pdev->bus << 8) | pdev->devfn; =20 --=20 2.17.1