From nobody Fri Nov 29 18:28:25 2024 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1632853183914744.5630823479803; Tue, 28 Sep 2021 11:19:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198197.351563 (Exim 4.92) (envelope-from ) id 1mVHhR-0005qX-9r; Tue, 28 Sep 2021 18:19:29 +0000 Received: by outflank-mailman (output) from mailman id 198197.351563; Tue, 28 Sep 2021 18:19:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHhR-0005qQ-71; Tue, 28 Sep 2021 18:19:29 +0000 Received: by outflank-mailman (input) for mailman id 198197; Tue, 28 Sep 2021 18:19:28 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHhQ-0005qD-DE for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:19:28 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 9cc18f95-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:19:26 +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 B05B36D; Tue, 28 Sep 2021 11:19:25 -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 B4F903F793; Tue, 28 Sep 2021 11:19:23 -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: 9cc18f95-2088-11ec-bcc4-12813bfff9fa From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andre.Przywara@arm.com, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Paul Durrant , Daniel De Graaf , "Daniel P. Smith" Subject: [PATCH v3 01/17] xen/pci: Refactor MSI code that implements MSI functionality within XEN Date: Tue, 28 Sep 2021 19:18:10 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853184757100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On Arm, the initial plan is to only support GICv3 ITS which doesn't require us to manage the MSIs because the HW will protect against spoofing. Move the code under CONFIG_HAS_PCI_MSI flag to gate the code for ARM. No functional change intended. Signed-off-by: Rahul Singh Reviewed-by: Daniel P. Smith Acked-by: Jan Beulich Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: none=20 Change in v2: Fixed minor comments --- xen/arch/x86/Kconfig | 1 + xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/msi.c | 83 ++++++++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 54 +++++---------------- xen/drivers/pci/Kconfig | 4 ++ xen/include/xen/msi.h | 43 +++++++++++++++++ xen/xsm/flask/hooks.c | 8 +-- 7 files changed, 149 insertions(+), 45 deletions(-) create mode 100644 xen/drivers/passthrough/msi.c create mode 100644 xen/include/xen/msi.h diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 1f83518ee0..b4abfca46f 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -20,6 +20,7 @@ config X86 select HAS_NS16550 select HAS_PASSTHROUGH select HAS_PCI + select HAS_PCI_MSI select HAS_PDX select HAS_SCHED_GRANULARITY select HAS_UBSAN diff --git a/xen/drivers/passthrough/Makefile b/xen/drivers/passthrough/Mak= efile index 445690e3e5..a5efa22714 100644 --- a/xen/drivers/passthrough/Makefile +++ b/xen/drivers/passthrough/Makefile @@ -7,3 +7,4 @@ obj-y +=3D iommu.o obj-$(CONFIG_HAS_PCI) +=3D pci.o obj-$(CONFIG_HAS_DEVICE_TREE) +=3D device_tree.o obj-$(CONFIG_HAS_PCI) +=3D ats.o +obj-$(CONFIG_HAS_PCI_MSI) +=3D msi.o diff --git a/xen/drivers/passthrough/msi.c b/xen/drivers/passthrough/msi.c new file mode 100644 index 0000000000..ce1a450f6f --- /dev/null +++ b/xen/drivers/passthrough/msi.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) +{ + int rc; + + if ( pdev->msix ) + { + rc =3D pci_reset_msix_state(pdev); + if ( rc ) + return rc; + msixtbl_init(d); + } + + return 0; +} + +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); +} + +void pdev_dump_msi(const struct pci_dev *pdev) +{ + const struct msi_desc *msi; + + if ( list_empty(&pdev->msi_list) ) + return; + + printk(" - MSIs < "); + list_for_each_entry ( msi, &pdev->msi_list, list ) + printk("%d ", msi->irq); + printk(">"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index fc4fa2e5c3..8996403161 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -32,8 +32,8 @@ #include #include #include +#include #include -#include #include "ats.h" =20 struct pci_seg { @@ -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)= ); - - pdev->msi_maxvec =3D multi_msi_capable(ctrl); - } =20 - 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 @@ -1271,18 +1249,16 @@ bool_t pcie_aer_get_firmware_first(const struct pci= _dev *pdev) static int _dump_pci_devices(struct pci_seg *pseg, void *arg) { struct pci_dev *pdev; - struct msi_desc *msi; =20 printk("=3D=3D=3D=3D segment %04x =3D=3D=3D=3D\n", pseg->nr); =20 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) { - printk("%pp - %pd - node %-3d - MSIs < ", + printk("%pp - %pd - node %-3d", &pdev->sbdf, pdev->domain, (pdev->node !=3D NUMA_NO_NODE) ? pdev->node : -1); - list_for_each_entry ( msi, &pdev->msi_list, list ) - printk("%d ", msi->irq); - printk(">\n"); + pdev_dump_msi(pdev); + printk("\n"); } =20 return 0; @@ -1422,13 +1398,9 @@ static int assign_device(struct domain *d, u16 seg, = u8 bus, u8 devfn, u32 flag) ASSERT(pdev && (pdev->domain =3D=3D hardware_domain || pdev->domain =3D=3D dom_io)); =20 - if ( pdev->msix ) - { - rc =3D pci_reset_msix_state(pdev); - if ( rc ) - goto done; - msixtbl_init(d); - } + rc =3D pdev_msix_assign(d, pdev); + if ( rc ) + goto done; =20 pdev->fault.count =3D 0; =20 diff --git a/xen/drivers/pci/Kconfig b/xen/drivers/pci/Kconfig index 7da03fa13b..c6a7bc8007 100644 --- a/xen/drivers/pci/Kconfig +++ b/xen/drivers/pci/Kconfig @@ -1,3 +1,7 @@ =20 config HAS_PCI bool + +config HAS_PCI_MSI + bool + depends on HAS_PCI diff --git a/xen/include/xen/msi.h b/xen/include/xen/msi.h new file mode 100644 index 0000000000..c903d0050c --- /dev/null +++ b/xen/include/xen/msi.h @@ -0,0 +1,43 @@ +#ifndef __XEN_MSI_H_ +#define __XEN_MSI_H_ + +#include + +#ifdef CONFIG_HAS_PCI_MSI + +#include + +int pdev_msix_assign(struct domain *d, struct pci_dev *pdev); +int pdev_msi_init(struct pci_dev *pdev); +void pdev_msi_deinit(struct pci_dev *pdev); +void pdev_dump_msi(const struct pci_dev *pdev); + +#else /* !CONFIG_HAS_PCI_MSI */ + +static inline int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) +{ + return 0; +} + +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) {} +static inline void pdev_dump_msi(const struct pci_dev *pdev) {} + +#endif /* CONFIG_HAS_PCI_MSI */ + +#endif /* __XEN_MSI_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 25e87180b4..ea9a12bd71 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 #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 { 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 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 const struct pci_dev *pdev =3D data; u32 machine_bdf =3D (pdev->seg << 16) | (pdev->bus << 8) | pdev->devfn; =20 --=20 2.17.1