From nobody Tue Feb 10 00:24:26 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=1619454175; cv=none; d=zohomail.com; s=zohoarc; b=UiS1fBZHSjs5moVWTuIfM7OrDApeUfVVYdmuSdNWzNuFSX2zmIXidO7ohyiv7bf1iHKTnY768+G+0yktOVaaa+JriuEa5r+zH3RAEfrMFzUWh1YqsT1xh3QRod1ZAgfEp60TI2sTpkwqWJlWyMtsfWj8aSjlRZy+SfgP1Uj+//U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619454175; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=eZetcenLYrCJ55OxRDfu31M5UnqnHpGyjJpIVD5yx4A=; b=Xs8f5Y9D3zEtDnHegKyVP5QS0363A93dUd6lgmiAL8Fy1btEpdMNNUFtxTIo196L0qWUShNaVDJq8LF4M9JUZwDYStik/+rJr/uLm6iR75R37jSTFd2Ot+zW9JlCTWtSqzMEbti2+4anXAwMwGEuI+pZI5DSGN7JVO3iw3BeRBE= 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 1619454175062649.9063194276843; Mon, 26 Apr 2021 09:22:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.117774.223668 (Exim 4.92) (envelope-from ) id 1lb40M-00057j-MY; Mon, 26 Apr 2021 16:22:38 +0000 Received: by outflank-mailman (output) from mailman id 117774.223668; Mon, 26 Apr 2021 16:22:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lb40M-00057b-Ja; Mon, 26 Apr 2021 16:22:38 +0000 Received: by outflank-mailman (input) for mailman id 117774; Mon, 26 Apr 2021 16:22:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lb40L-00057T-El for xen-devel@lists.xenproject.org; Mon, 26 Apr 2021 16:22:37 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id e5fc57fb-0d70-4b38-88ec-a8275d962832; Mon, 26 Apr 2021 16:22:35 +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 3F4061FB; Mon, 26 Apr 2021 09:22:35 -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 667A13F73B; Mon, 26 Apr 2021 09:22:33 -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: e5fc57fb-0d70-4b38-88ec-a8275d962832 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@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 Subject: [PATCH v3 2/3] xen/pci: Refactor PCI MSI intercept related code Date: Mon, 26 Apr 2021 17:21:26 +0100 Message-Id: <480947d549c46270fccc4c6d83ae8beca3c0fce6.1619453100.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 intercept related code is not useful for ARM when MSI interrupts are injected via GICv3 ITS. Therefore introducing the new flag CONFIG_PCI_MSI_INTERCEPT to gate the MSI code for ARM in common code and also implemented the stub version for the unused code for ARM to avoid compilation error when HAS_PCI is enabled for ARM. No functional change intended. Signed-off-by: Rahul Singh --- Changes since v1: - Rename CONFIG_HAS_PCI_MSI to CONFIG_PCI_MSI_INTERCEPT - Implement stub version of the unused function for ARM. - Move unneeded function to x86 file. Changes since v2: - Rename function name as per the comments. - Created a separate non-arch specific file msi-intercept.c. --- xen/arch/x86/Kconfig | 1 + xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/msi-intercept.c | 52 +++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 16 +++----- xen/drivers/pci/Kconfig | 4 ++ xen/drivers/vpci/Makefile | 3 +- xen/drivers/vpci/header.c | 19 ++------- xen/drivers/vpci/msix.c | 25 ++++++++++++ xen/drivers/vpci/vpci.c | 3 +- xen/include/xen/msi-intercept.h | 48 +++++++++++++++++++++++ xen/include/xen/vpci.h | 23 +++++++++++ xen/xsm/flask/hooks.c | 8 ++-- 12 files changed, 170 insertions(+), 33 deletions(-) create mode 100644 xen/drivers/passthrough/msi-intercept.c create mode 100644 xen/include/xen/msi-intercept.h diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 32b9f23a20..4d72798f00 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 PCI_MSI_INTERCEPT 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..3c707706b0 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_PCI_MSI_INTERCEPT) +=3D msi-intercept.o diff --git a/xen/drivers/passthrough/msi-intercept.c b/xen/drivers/passthro= ugh/msi-intercept.c new file mode 100644 index 0000000000..1edae6d4e8 --- /dev/null +++ b/xen/drivers/passthrough/msi-intercept.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2021 Arm Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#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; +} + +void pdev_dump_msi(const struct pci_dev *pdev) +{ + const struct msi_desc *msi; + + list_for_each_entry ( msi, &pdev->msi_list, list ) + printk("%d ", msi->irq); +} +/* + * 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 199ce08612..298be21b5b 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 { @@ -1271,7 +1271,6 @@ bool_t pcie_aer_get_firmware_first(const struct pci_d= ev *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 @@ -1280,8 +1279,7 @@ static int _dump_pci_devices(struct pci_seg *pseg, vo= id *arg) printk("%pp - %pd - node %-3d - MSIs < ", &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); + pdev_dump_msi(pdev); printk(">\n"); } =20 @@ -1422,13 +1420,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..e6bf0b7441 100644 --- a/xen/drivers/pci/Kconfig +++ b/xen/drivers/pci/Kconfig @@ -1,3 +1,7 @@ =20 config HAS_PCI bool + +config PCI_MSI_INTERCEPT + bool + depends on HAS_PCI diff --git a/xen/drivers/vpci/Makefile b/xen/drivers/vpci/Makefile index 55d1bdfda0..f91fa71a40 100644 --- a/xen/drivers/vpci/Makefile +++ b/xen/drivers/vpci/Makefile @@ -1 +1,2 @@ -obj-y +=3D vpci.o header.o msi.o msix.o +obj-y +=3D vpci.o header.o +obj-$(CONFIG_PCI_MSI_INTERCEPT) +=3D msi.o msix.o diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index ba9a036202..ec735c5b4b 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -206,7 +206,6 @@ static int modify_bars(const struct pci_dev *pdev, uint= 16_t cmd, bool rom_only) struct vpci_header *header =3D &pdev->vpci->header; struct rangeset *mem =3D rangeset_new(NULL, NULL, 0); struct pci_dev *tmp, *dev =3D NULL; - const struct vpci_msix *msix =3D pdev->vpci->msix; unsigned int i; int rc; =20 @@ -244,21 +243,11 @@ static int modify_bars(const struct pci_dev *pdev, ui= nt16_t cmd, bool rom_only) } =20 /* Remove any MSIX regions if present. */ - for ( i =3D 0; msix && i < ARRAY_SIZE(msix->tables); i++ ) + rc =3D vpci_remove_msix_regions(pdev, mem); + if ( rc ) { - unsigned long start =3D PFN_DOWN(vmsix_table_addr(pdev->vpci, i)); - unsigned long end =3D PFN_DOWN(vmsix_table_addr(pdev->vpci, i) + - vmsix_table_size(pdev->vpci, i) - 1); - - rc =3D rangeset_remove_range(mem, start, end); - if ( rc ) - { - printk(XENLOG_G_WARNING - "Failed to remove MSIX table [%lx, %lx]: %d\n", - start, end, rc); - rangeset_destroy(mem); - return rc; - } + rangeset_destroy(mem); + return rc; } =20 /* diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c index 846f1b8d70..3efbaebc92 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -428,6 +428,31 @@ int vpci_make_msix_hole(const struct pci_dev *pdev) return 0; } =20 +int vpci_remove_msix_regions(const struct pci_dev *pdev, struct rangeset *= mem) +{ + const struct vpci_msix *msix =3D pdev->vpci->msix; + unsigned int i; + int rc; + + for ( i =3D 0; msix && i < ARRAY_SIZE(msix->tables); i++ ) + { + unsigned long start =3D PFN_DOWN(vmsix_table_addr(pdev->vpci, i)); + unsigned long end =3D PFN_DOWN(vmsix_table_addr(pdev->vpci, i) + + vmsix_table_size(pdev->vpci, i) - 1); + + rc =3D rangeset_remove_range(mem, start, end); + if ( rc ) + { + printk(XENLOG_G_WARNING + "Failed to remove MSIX table [%lx, %lx]: %d\n", + start, end, rc); + return rc; + } + } + + return 0; +} + static int init_msix(struct pci_dev *pdev) { struct domain *d =3D pdev->domain; diff --git a/xen/drivers/vpci/vpci.c b/xen/drivers/vpci/vpci.c index cbd1bac7fc..85084dd924 100644 --- a/xen/drivers/vpci/vpci.c +++ b/xen/drivers/vpci/vpci.c @@ -48,8 +48,7 @@ void vpci_remove_device(struct pci_dev *pdev) xfree(r); } spin_unlock(&pdev->vpci->lock); - xfree(pdev->vpci->msix); - xfree(pdev->vpci->msi); + vpci_msi_free(pdev->vpci); xfree(pdev->vpci); pdev->vpci =3D NULL; } diff --git a/xen/include/xen/msi-intercept.h b/xen/include/xen/msi-intercep= t.h new file mode 100644 index 0000000000..77c105e286 --- /dev/null +++ b/xen/include/xen/msi-intercept.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2021 Arm Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __XEN_MSI_INTERCEPT_H_ +#define __XEN_MSI_INTERCEPT_H_ + +#ifdef CONFIG_PCI_MSI_INTERCEPT + +#include + +int pdev_msix_assign(struct domain *d, struct pci_dev *pdev); +void pdev_dump_msi(const struct pci_dev *pdev); + +#else /* !CONFIG_PCI_MSI_INTERCEPT */ + +static inline int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) +{ + return 0; +} + +static inline void pdev_dump_msi(const struct pci_dev *pdev) {} +static inline void pci_cleanup_msi(struct pci_dev *pdev) {} + +#endif /* CONFIG_PCI_MSI_INTERCEPT */ + +#endif /* __XEN_MSI_INTERCEPT_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/include/xen/vpci.h b/xen/include/xen/vpci.h index 9f5b5d52e1..2cd3647305 100644 --- a/xen/include/xen/vpci.h +++ b/xen/include/xen/vpci.h @@ -91,6 +91,7 @@ struct vpci { /* FIXME: currently there's no support for SR-IOV. */ } header; =20 +#ifdef CONFIG_PCI_MSI_INTERCEPT /* MSI data. */ struct vpci_msi { /* Address. */ @@ -136,6 +137,7 @@ struct vpci { struct vpci_arch_msix_entry arch; } entries[]; } *msix; +#endif /* CONFIG_PCI_MSI_INTERCEPT */ #endif }; =20 @@ -148,6 +150,7 @@ struct vpci_vcpu { }; =20 #ifdef __XEN__ +#ifdef CONFIG_PCI_MSI_INTERCEPT void vpci_dump_msi(void); =20 /* Make sure there's a hole in the p2m for the MSIX mmio areas. */ @@ -174,6 +177,7 @@ int __must_check vpci_msix_arch_disable_entry(struct vp= ci_msix_entry *entry, const struct pci_dev *pdev); void vpci_msix_arch_init_entry(struct vpci_msix_entry *entry); int vpci_msix_arch_print(const struct vpci_msix *msix); +int vpci_remove_msix_regions(const struct pci_dev *pdev, struct rangeset *= mem); =20 /* * Helper functions to fetch MSIX related data. They are used by both the @@ -208,6 +212,25 @@ static inline unsigned int vmsix_entry_nr(const struct= vpci_msix *msix, { return entry - msix->entries; } + +static inline void vpci_msi_free(struct vpci *vpci) +{ + XFREE(vpci->msix); + XFREE(vpci->msi); +} +#else /* !CONFIG_PCI_MSI_INTERCEPT */ +static inline int vpci_make_msix_hole(const struct pci_dev *pdev) +{ + return 0; +} + +static inline int vpci_remove_msix_regions(const struct pci_dev *pdev, + struct rangeset *mem) +{ + return 0; +} +static inline void vpci_msi_free(struct vpci *vpci) {} +#endif /* CONFIG_PCI_MSI_INTERCEPT */ #endif /* __XEN__ */ =20 #else /* !CONFIG_HAS_VPCI */ diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 5a24d01f04..d87f56fc95 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_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_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_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_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