From nobody Fri Mar 29 00:44:57 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 ARC-Seal: i=1; a=rsa-sha256; t=1619707664; cv=none; d=zohomail.com; s=zohoarc; b=Vx09l+81t8MIfq84V5yXdl7KfnmgSLOeBLyDPeHWTw66D5mZzc1F2iZmbhSRu4qiv+kFmgZ5AA8Xnb1ZLjANf8uyEF/ap1nayxr66t7JRHity+brVTDhnCZqJeM2r4JrH2bhx8TpsPJbgX0KFOBYTu4P++hk7enVnk7T3W/6c1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619707664; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=9zCfigqrsi9cYlNrs26ddDBV9gNFR73YdG73F1pFvs4=; b=BuMy8MDypg02h2MfisfpGh9orklaOTzt/XdBE1WlECgkbd+WaMs7XdtfW5ovxGHB8JcGCQhx2rI+LaztbzgFeCZr30VkhnGzRNMj6RwsNuDI21ugNlYD5DRioyB0HB/HETA+ir4fVSWtLTCKJVOd9HvxKR5wEk2KFZSMA92kNmI= 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 1619707664919600.2757767912733; Thu, 29 Apr 2021 07:47:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.120080.227069 (Exim 4.92) (envelope-from ) id 1lc7wy-00021D-1A; Thu, 29 Apr 2021 14:47:32 +0000 Received: by outflank-mailman (output) from mailman id 120080.227069; Thu, 29 Apr 2021 14:47:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lc7wx-000216-UO; Thu, 29 Apr 2021 14:47:31 +0000 Received: by outflank-mailman (input) for mailman id 120080; Thu, 29 Apr 2021 14:47:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lc7ww-00020q-GK for xen-devel@lists.xenproject.org; Thu, 29 Apr 2021 14:47:30 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 4d73e45a-6464-43d6-aaa6-87f0b1fb6232; Thu, 29 Apr 2021 14:47:29 +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 051091FB; Thu, 29 Apr 2021 07:47:29 -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 387803F73B; Thu, 29 Apr 2021 07:47:28 -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: 4d73e45a-6464-43d6-aaa6-87f0b1fb6232 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Jan Beulich , Paul Durrant Subject: [PATCH v4 1/3] xen/iommu: Move iommu_update_ire_from_msi(..) to xen/iommu.h Date: Thu, 29 Apr 2021 15:46:51 +0100 Message-Id: <3dd255f5715eee3f359a6187d83c57a262065830.1619707144.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" Move iommu_update_ire_from_msi(..) from passthrough/pci.c to xen/iommu.h and wrap it under CONFIG_X86 as it is referenced in x86 code only to avoid compilation error for other architecture when HAS_PCI is enabled. No functional change intended. Signed-off-by: Rahul Singh Acked-by: Jan Beulich --- xen/drivers/passthrough/pci.c | 7 ------- xen/include/xen/iommu.h | 13 ++++++++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 705137f8be..199ce08612 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1303,13 +1303,6 @@ static int __init setup_dump_pcidevs(void) } __initcall(setup_dump_pcidevs); =20 -int iommu_update_ire_from_msi( - struct msi_desc *msi_desc, struct msi_msg *msg) -{ - return iommu_intremap - ? iommu_call(&iommu_ops, update_ire_from_msi, msi_desc, msg) : = 0; -} - static int iommu_add_device(struct pci_dev *pdev) { const struct domain_iommu *hd; diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 4f0e5ac622..460755df29 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -187,8 +187,6 @@ void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci); struct msi_desc; struct msi_msg; =20 -int iommu_update_ire_from_msi(struct msi_desc *msi_desc, struct msi_msg *m= sg); - #define PT_IRQ_TIME_OUT MILLISECS(8) #endif /* HAS_PCI */ =20 @@ -238,7 +236,6 @@ struct iommu_ops { u8 devfn, device_t *dev); #ifdef CONFIG_HAS_PCI int (*get_device_group_id)(u16 seg, u8 bus, u8 devfn); - int (*update_ire_from_msi)(struct msi_desc *msi_desc, struct msi_msg *= msg); #endif /* HAS_PCI */ =20 void (*teardown)(struct domain *d); @@ -267,6 +264,7 @@ struct iommu_ops { int (*adjust_irq_affinities)(void); void (*sync_cache)(const void *addr, unsigned int size); void (*clear_root_pgtable)(struct domain *d); + int (*update_ire_from_msi)(struct msi_desc *msi_desc, struct msi_msg *= msg); #endif /* CONFIG_X86 */ =20 int __must_check (*suspend)(void); @@ -374,6 +372,15 @@ extern struct page_list_head iommu_pt_cleanup_list; =20 bool arch_iommu_use_permitted(const struct domain *d); =20 +#ifdef CONFIG_X86 +static inline int iommu_update_ire_from_msi( + struct msi_desc *msi_desc, struct msi_msg *msg) +{ + return iommu_intremap + ? iommu_call(&iommu_ops, update_ire_from_msi, msi_desc, msg) : = 0; +} +#endif + #endif /* _IOMMU_H_ */ =20 /* --=20 2.17.1 From nobody Fri Mar 29 00:44:57 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 ARC-Seal: i=1; a=rsa-sha256; t=1619707679; cv=none; d=zohomail.com; s=zohoarc; b=ktwwY6iWIkImSBnFuNK/1PIia365owJAcHlWNnSlATR9K/FkaQRG76lOVDn3yn9W4V59vIS7jb/sKSxyIc5uG23gu+pmqIpr90q73vdeWNWdq4ennDlDh+/E5KRwYRdpRThJmyhBFJwQP5ToHztvaFrPdTrVQutNSadk/tCR+5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619707679; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Gk30QduyHAKoQnJtQU+YxtmoF6be/V0E1oSp8Gc4DFE=; b=arBA0fNvetu4gah165qnt/10Xz9dhrPyw3HysdWQZfKEisJbnvgu4wMMfhI4Dm7rAsGrmj9NFFShZ164KCUi2q15exkYC3hE1oqOUgI0b4rbTY0cD1YPW5vJ9Q2Zm/AGMzoEaeatVHNN/K/k0rU/8iLvxuHp0DS4mjZVp/hWl2Y= 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 1619707679954769.0592904448123; Thu, 29 Apr 2021 07:47:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.120083.227081 (Exim 4.92) (envelope-from ) id 1lc7xB-00026M-An; Thu, 29 Apr 2021 14:47:45 +0000 Received: by outflank-mailman (output) from mailman id 120083.227081; Thu, 29 Apr 2021 14:47:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lc7xB-00026E-6d; Thu, 29 Apr 2021 14:47:45 +0000 Received: by outflank-mailman (input) for mailman id 120083; Thu, 29 Apr 2021 14:47:44 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lc7xA-000265-Cm for xen-devel@lists.xenproject.org; Thu, 29 Apr 2021 14:47:44 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 53b275d3-9361-444c-98a8-0deddf254de2; Thu, 29 Apr 2021 14:47:42 +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 D94411FB; Thu, 29 Apr 2021 07:47:41 -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 30D5F3F73B; Thu, 29 Apr 2021 07:47:40 -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: 53b275d3-9361-444c-98a8-0deddf254de2 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 Subject: [PATCH v4 2/3] xen/pci: Refactor PCI MSI intercept related code Date: Thu, 29 Apr 2021 15:46:52 +0100 Message-Id: <07cb9f45a91a283af1991c42266555bb0bfe3b71.1619707144.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_HAS_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 --- xen/arch/x86/Kconfig | 1 + xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/msi-intercept.c | 53 ++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 20 ++++----- xen/drivers/pci/Kconfig | 4 ++ xen/drivers/vpci/Makefile | 3 +- xen/drivers/vpci/header.c | 19 ++------- xen/drivers/vpci/msix.c | 55 +++++++++++++++++++++++++ xen/drivers/vpci/vpci.c | 3 +- xen/include/xen/msi-intercept.h | 49 ++++++++++++++++++++++ xen/include/xen/vpci.h | 41 ++++++++---------- 11 files changed, 195 insertions(+), 54 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..a822687c2e 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_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..eb27d10f5a 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_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..ed3ec38003 --- /dev/null +++ b/xen/drivers/passthrough/msi-intercept.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008, Netronome Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 f= or + * 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("- MSIs < %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..237461b4ab 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,18 +1271,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 +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..295731a3f4 100644 --- a/xen/drivers/pci/Kconfig +++ b/xen/drivers/pci/Kconfig @@ -1,3 +1,7 @@ =20 config HAS_PCI bool + +config HAS_PCI_MSI_INTERCEPT + bool + depends on HAS_PCI diff --git a/xen/drivers/vpci/Makefile b/xen/drivers/vpci/Makefile index 55d1bdfda0..a95e6c2ca0 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_HAS_PCI_MSI_INTERCEPT) +=3D msi.o msix.o diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index ba9a036202..81d3d2d17f 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->vpci, 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..b62106ddf9 100644 --- a/xen/drivers/vpci/msix.c +++ b/xen/drivers/vpci/msix.c @@ -27,6 +27,36 @@ ((addr) >=3D vmsix_table_addr(vpci, nr) && = \ (addr) < vmsix_table_addr(vpci, nr) + vmsix_table_size(vpci, nr)) =20 +/* + * Helper functions to fetch MSIX related data. They are used by both the + * emulated MSIX code and the BAR handlers. + */ +static inline paddr_t vmsix_table_base(const struct vpci *vpci, + unsigned int nr) +{ + return vpci->header.bars[vpci->msix->tables[nr] & PCI_MSIX_BIRMASK].ad= dr; +} + +static inline paddr_t vmsix_table_addr(const struct vpci *vpci, + unsigned int nr) +{ + return vmsix_table_base(vpci, nr) + + (vpci->msix->tables[nr] & ~PCI_MSIX_BIRMASK); +} + +/* + * Note regarding the size calculation of the PBA: the spec mentions "The = last + * QWORD will not necessarily be fully populated", so it implies that the = PBA + * size is 64-bit aligned. + */ +static inline size_t vmsix_table_size(const struct vpci *vpci, unsigned in= t nr) +{ + return + (nr =3D=3D VPCI_MSIX_TABLE) ? vpci->msix->max_entries * PCI_MSIX_E= NTRY_SIZE + : ROUNDUP(DIV_ROUND_UP(vpci->msix->max_ent= ries, + 8), 8); +} + static uint32_t control_read(const struct pci_dev *pdev, unsigned int reg, void *data) { @@ -428,6 +458,31 @@ int vpci_make_msix_hole(const struct pci_dev *pdev) return 0; } =20 +int vpci_remove_msix_regions(const struct vpci *vpci, struct rangeset *mem) +{ + const struct vpci_msix *msix =3D 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(vpci, i)); + unsigned long end =3D PFN_DOWN(vmsix_table_addr(vpci, i) + + vmsix_table_size(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..1bf9fc4465 --- /dev/null +++ b/xen/include/xen/msi-intercept.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2008, Netronome Systems, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 f= or + * 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_HAS_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_HAS_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_HAS_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..4197407464 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_HAS_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_HAS_PCI_MSI_INTERCEPT */ #endif }; =20 @@ -148,6 +150,7 @@ struct vpci_vcpu { }; =20 #ifdef __XEN__ +#ifdef CONFIG_HAS_PCI_MSI_INTERCEPT void vpci_dump_msi(void); =20 /* Make sure there's a hole in the p2m for the MSIX mmio areas. */ @@ -174,40 +177,32 @@ int __must_check vpci_msix_arch_disable_entry(struct = vpci_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 vpci *vpci, struct rangeset *mem= ); =20 -/* - * Helper functions to fetch MSIX related data. They are used by both the - * emulated MSIX code and the BAR handlers. - */ -static inline paddr_t vmsix_table_base(const struct vpci *vpci, unsigned i= nt nr) +static inline unsigned int vmsix_entry_nr(const struct vpci_msix *msix, + const struct vpci_msix_entry *en= try) { - return vpci->header.bars[vpci->msix->tables[nr] & PCI_MSIX_BIRMASK].ad= dr; + return entry - msix->entries; } =20 -static inline paddr_t vmsix_table_addr(const struct vpci *vpci, unsigned i= nt nr) +static inline void vpci_msi_free(struct vpci *vpci) { - return vmsix_table_base(vpci, nr) + - (vpci->msix->tables[nr] & ~PCI_MSIX_BIRMASK); + XFREE(vpci->msix); + XFREE(vpci->msi); } - -/* - * Note regarding the size calculation of the PBA: the spec mentions "The = last - * QWORD will not necessarily be fully populated", so it implies that the = PBA - * size is 64-bit aligned. - */ -static inline size_t vmsix_table_size(const struct vpci *vpci, unsigned in= t nr) +#else /* !CONFIG_HAS_PCI_MSI_INTERCEPT */ +static inline int vpci_make_msix_hole(const struct pci_dev *pdev) { - return - (nr =3D=3D VPCI_MSIX_TABLE) ? vpci->msix->max_entries * PCI_MSIX_E= NTRY_SIZE - : ROUNDUP(DIV_ROUND_UP(vpci->msix->max_ent= ries, - 8), 8); + return 0; } =20 -static inline unsigned int vmsix_entry_nr(const struct vpci_msix *msix, - const struct vpci_msix_entry *en= try) +static inline int vpci_remove_msix_regions(const struct vpci *vpci, + struct rangeset *mem) { - return entry - msix->entries; + return 0; } +static inline void vpci_msi_free(struct vpci *vpci) {} +#endif /* CONFIG_HAS_PCI_MSI_INTERCEPT */ #endif /* __XEN__ */ =20 #else /* !CONFIG_HAS_VPCI */ --=20 2.17.1 From nobody Fri Mar 29 00:44:57 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 ARC-Seal: i=1; a=rsa-sha256; t=1619707707; cv=none; d=zohomail.com; s=zohoarc; b=bSgcfOBuA177pauy8yS0fjmIcynBn1udquMobV9Pn88e4VKmEjq0biDhkLrqWH1O+CzUv2Cl+cHexUl5EGOkmBXyH/B/iD7USOfj82P9CQXepGPayu00uh42OFuYDS+XprIQ5PpocSFiGrHaMNHRD72PrUTFJfVh2eqg2/ig77Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619707707; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6KcPZh8SxVEJeed0PpT4wkWKN+/+0ThQAa5faHx9CPo=; b=VY9/RF6gT6gcHrcTTbOVzU+luat6DMNaHWy7HiVzcfShBow3r9kx480ON62f26YaKQcVGQbj+1GL2DHQTxdI7BM4RfVCd1M07PM+EH8U1ZKOiOYAmfNBskT03sEMPvPkxXDQSpCOvzLsbgRTWgig0XH9OxWAt7/SLAa2QXTjJ2w= 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 1619707707909349.6897942397244; Thu, 29 Apr 2021 07:48:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.120092.227093 (Exim 4.92) (envelope-from ) id 1lc7xf-0002EI-Kr; Thu, 29 Apr 2021 14:48:15 +0000 Received: by outflank-mailman (output) from mailman id 120092.227093; Thu, 29 Apr 2021 14:48:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lc7xf-0002EB-HH; Thu, 29 Apr 2021 14:48:15 +0000 Received: by outflank-mailman (input) for mailman id 120092; Thu, 29 Apr 2021 14:48:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lc7xe-0002Dy-Fk for xen-devel@lists.xenproject.org; Thu, 29 Apr 2021 14:48:14 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id ee86eacc-7629-43de-987d-0fb95e68d49e; Thu, 29 Apr 2021 14:48:13 +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 B5E1D1FB; Thu, 29 Apr 2021 07:48:12 -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 2F0723F73B; Thu, 29 Apr 2021 07:48:11 -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: ee86eacc-7629-43de-987d-0fb95e68d49e 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 v4 3/3] xen/pci: Refactor MSI code that implements MSI functionality within XEN Date: Thu, 29 Apr 2021 15:46:53 +0100 Message-Id: <60b4c33fdcc2f7ad68d383ffae191e22b0b32f1c.1619707144.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 | 7 +++++ xen/include/xen/pci.h | 11 ++++--- xen/xsm/flask/hooks.c | 8 ++--- 5 files changed, 65 insertions(+), 36 deletions(-) diff --git a/xen/drivers/passthrough/msi-intercept.c b/xen/drivers/passthro= ugh/msi-intercept.c index ed3ec38003..12187bc9b9 100644 --- a/xen/drivers/passthrough/msi-intercept.c +++ b/xen/drivers/passthrough/msi-intercept.c @@ -19,6 +19,47 @@ #include #include =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); +} + int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) { int rc; 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 1bf9fc4465..7b094e08f7 100644 --- a/xen/include/xen/msi-intercept.h +++ b/xen/include/xen/msi-intercept.h @@ -21,16 +21,23 @@ =20 #include =20 +int pdev_msi_init(struct pci_dev *pdev); +void pdev_msi_deinit(struct pci_dev *pdev); int pdev_msix_assign(struct domain *d, struct pci_dev *pdev); void pdev_dump_msi(const struct pci_dev *pdev); =20 #else /* !CONFIG_HAS_PCI_MSI_INTERCEPT */ +static inline int pdev_msi_init(struct pci_dev *pdev) +{ + return 0; +} =20 static inline int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) { return 0; } =20 +static inline void pdev_msi_deinit(struct pci_dev *pdev) {} static inline void pdev_dump_msi(const struct pci_dev *pdev) {} static inline void pci_cleanup_msi(struct pci_dev *pdev) {} =20 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 5a24d01f04..394455cc42 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