From nobody Fri May 17 06:43:22 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 1662637806168179.51705556202023; Thu, 8 Sep 2022 04:50:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.403224.645291 (Exim 4.92) (envelope-from ) id 1oWG2X-0003uG-EU; Thu, 08 Sep 2022 11:49:49 +0000 Received: by outflank-mailman (output) from mailman id 403224.645291; Thu, 08 Sep 2022 11:49:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oWG2X-0003u5-BM; Thu, 08 Sep 2022 11:49:49 +0000 Received: by outflank-mailman (input) for mailman id 403224; Thu, 08 Sep 2022 11:49:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oWG2W-000373-3q for xen-devel@lists.xenproject.org; Thu, 08 Sep 2022 11:49:48 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 566b27ae-2f6c-11ed-9760-273f2230c3a0; Thu, 08 Sep 2022 13:49:47 +0200 (CEST) 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 0336B14BF; Thu, 8 Sep 2022 04:49:53 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CA3C53F71A; Thu, 8 Sep 2022 04:49:45 -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: 566b27ae-2f6c-11ed-9760-273f2230c3a0 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Oleksandr Tyshchenko Subject: [PATCH v5 1/2] xen/arm: pci: modify pci_find_host_bridge_node argument to const pdev Date: Thu, 8 Sep 2022 12:49:01 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1662637806476100001 Content-Type: text/plain; charset="utf-8" Modify pci_find_host_bridge_node argument to const pdev to avoid converting the dev to pdev in pci_find_host_bridge_node and also constify the return. Signed-off-by: Rahul Singh Acked-by: Stefano Stabellini Reviewed-by: Oleksandr Tyshchenko --- Changes in v5: - no changes Changes in v4: - no changes Changes in v3: - no changes --- xen/arch/arm/include/asm/pci.h | 3 ++- xen/arch/arm/pci/pci-host-common.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h index 7c7449d64f..80a2431804 100644 --- a/xen/arch/arm/include/asm/pci.h +++ b/xen/arch/arm/include/asm/pci.h @@ -106,7 +106,8 @@ bool pci_ecam_need_p2m_hwdom_mapping(struct domain *d, struct pci_host_bridge *bridge, uint64_t addr); struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus= ); -struct dt_device_node *pci_find_host_bridge_node(struct device *dev); +const struct dt_device_node * +pci_find_host_bridge_node(const struct pci_dev *pdev); int pci_get_host_bridge_segment(const struct dt_device_node *node, uint16_t *segment); =20 diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index fd8c0f837a..89ef30028e 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -243,10 +243,10 @@ err_exit: /* * Get host bridge node given a device attached to it. */ -struct dt_device_node *pci_find_host_bridge_node(struct device *dev) +const struct dt_device_node * +pci_find_host_bridge_node(const struct pci_dev *pdev) { struct pci_host_bridge *bridge; - struct pci_dev *pdev =3D dev_to_pci(dev); =20 bridge =3D pci_find_host_bridge(pdev->seg, pdev->bus); if ( unlikely(!bridge) ) --=20 2.25.1 From nobody Fri May 17 06:43:22 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 1662638364280470.1609085497837; Thu, 8 Sep 2022 04:59:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.403250.645312 (Exim 4.92) (envelope-from ) id 1oWGBU-0006Y1-PN; Thu, 08 Sep 2022 11:59:04 +0000 Received: by outflank-mailman (output) from mailman id 403250.645312; Thu, 08 Sep 2022 11:59:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oWGBU-0006Xu-Mf; Thu, 08 Sep 2022 11:59:04 +0000 Received: by outflank-mailman (input) for mailman id 403250; Thu, 08 Sep 2022 11:59:03 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oWG3V-000373-JO for xen-devel@lists.xenproject.org; Thu, 08 Sep 2022 11:50:49 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 7adaee4b-2f6c-11ed-9760-273f2230c3a0; Thu, 08 Sep 2022 13:50:48 +0200 (CEST) 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 301A114BF; Thu, 8 Sep 2022 04:50:54 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A3783F71A; Thu, 8 Sep 2022 04:50:46 -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: 7adaee4b-2f6c-11ed-9760-273f2230c3a0 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Paul Durrant Subject: [PATCH v5 2/2] xen/pci: replace call to is_memory_hole to pci_check_bar Date: Thu, 8 Sep 2022 12:49:02 +0100 Message-Id: <63a0010c1e0f6ffb86fce35e188d66bf4c0d57e7.1662637415.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1662638365988100001 Content-Type: text/plain; charset="utf-8" is_memory_hole was implemented for x86 and not for ARM when introduced. Replace is_memory_hole call to pci_check_bar as function should check if device BAR is in defined memory range. Also, add an implementation for ARM which is required for PCI passthrough. On x86, pci_check_bar will call is_memory_hole which will check if BAR is not overlapping with any memory region defined in the memory map. On ARM, pci_check_bar will go through the host bridge ranges and check if the BAR is in the range of defined ranges. Signed-off-by: Rahul Singh Acked-by: Jan Beulich # x86, common acked-by would also cover the Arm. I agree this would be uncommon but=20 --- Changes in v5: - drop use of PFN_UP and PF_DOWN in case addresses are not aligned. - As we drop the PFN_UP and PFN_DOWN we need to use the mfn_to_maddr() to get the BAR address without page shift. - Add TODO comment for address alignment check for ranges. - Added Jan Acked-by for x86 and common code. Changes in v4: - check "s <=3D e" before callback - Add TODO comment for revisiting the function pci_check_bar() when ACPI PCI passthrough support is added. - Not Added the Jan Acked-by as patch is modified. Changes in v3: - fix minor comments --- xen/arch/arm/include/asm/pci.h | 2 ++ xen/arch/arm/pci/pci-host-common.c | 54 ++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/pci.h | 10 ++++++ xen/drivers/passthrough/pci.c | 8 ++--- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h index 80a2431804..8cb46f6b71 100644 --- a/xen/arch/arm/include/asm/pci.h +++ b/xen/arch/arm/include/asm/pci.h @@ -126,6 +126,8 @@ int pci_host_iterate_bridges_and_count(struct domain *d, =20 int pci_host_bridge_mappings(struct domain *d); =20 +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end); + #else /*!CONFIG_HAS_PCI*/ =20 struct arch_pci_dev { }; diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index 89ef30028e..d51cfdf352 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -24,6 +24,16 @@ =20 #include =20 +/* + * struct to hold pci device bar. + */ +struct pdev_bar_check +{ + unsigned long start; + unsigned long end; + bool is_valid; +}; + /* * List for all the pci host bridges. */ @@ -363,6 +373,50 @@ int __init pci_host_bridge_mappings(struct domain *d) return 0; } =20 +/* + * TODO: BAR addresses and Root Complex window addresses are not guaranteed + * to be page aligned. We should check for alignment but this is not the + * right place for alignment check. + */ +static int is_bar_valid(const struct dt_device_node *dev, + uint64_t addr, uint64_t len, void *data) +{ + struct pdev_bar_check *bar_data =3D data; + unsigned long s =3D bar_data->start; + unsigned long e =3D bar_data->end; + + if ( (s >=3D addr) && (e <=3D (addr + len - 1)) ) + bar_data->is_valid =3D true; + + return 0; +} + +/* TODO: Revisit this function when ACPI PCI passthrough support is added.= */ +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end) +{ + int ret; + const struct dt_device_node *dt_node; + unsigned long s =3D mfn_to_maddr(start); + unsigned long e =3D mfn_to_maddr(end); + struct pdev_bar_check bar_data =3D { + .start =3D s, + .end =3D e, + .is_valid =3D false + }; + + if ( s >=3D e ) + return false; + + dt_node =3D pci_find_host_bridge_node(pdev); + if ( !dt_node ) + return false; + + ret =3D dt_for_each_range(dt_node, &is_bar_valid, &bar_data); + if ( ret < 0 ) + return false; + + return bar_data.is_valid; +} /* * Local variables: * mode: C diff --git a/xen/arch/x86/include/asm/pci.h b/xen/arch/x86/include/asm/pci.h index c8e1a9ecdb..f4a58c8acf 100644 --- a/xen/arch/x86/include/asm/pci.h +++ b/xen/arch/x86/include/asm/pci.h @@ -57,4 +57,14 @@ static always_inline bool is_pci_passthrough_enabled(voi= d) =20 void arch_pci_init_pdev(struct pci_dev *pdev); =20 +static inline bool pci_check_bar(const struct pci_dev *pdev, + mfn_t start, mfn_t end) +{ + /* + * Check if BAR is not overlapping with any memory region defined + * in the memory map. + */ + return is_memory_hole(start, end); +} + #endif /* __X86_PCI_H__ */ diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index cdaf5c247f..149f68bb6e 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -304,8 +304,8 @@ static void check_pdev(const struct pci_dev *pdev) if ( rc < 0 ) /* Unable to size, better leave memory decoding disabled. */ return; - if ( size && !is_memory_hole(maddr_to_mfn(addr), - maddr_to_mfn(addr + size - 1)) ) + if ( size && !pci_check_bar(pdev, maddr_to_mfn(addr), + maddr_to_mfn(addr + size - 1)) ) { /* * Return without enabling memory decoding if BAR position is = not @@ -331,8 +331,8 @@ static void check_pdev(const struct pci_dev *pdev) =20 if ( rc < 0 ) return; - if ( size && !is_memory_hole(maddr_to_mfn(addr), - maddr_to_mfn(addr + size - 1)) ) + if ( size && !pci_check_bar(pdev, maddr_to_mfn(addr), + maddr_to_mfn(addr + size - 1)) ) { printk(warn, &pdev->sbdf, "ROM ", PFN_DOWN(addr), PFN_DOWN(addr + size - 1)); --=20 2.25.1