From nobody Mon Apr 29 05:18:47 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 1659714372072296.0901702506508; Fri, 5 Aug 2022 08:46:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.381368.616026 (Exim 4.92) (envelope-from ) id 1oJzWD-00018w-Am; Fri, 05 Aug 2022 15:45:45 +0000 Received: by outflank-mailman (output) from mailman id 381368.616026; Fri, 05 Aug 2022 15:45: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 1oJzWD-00018n-7a; Fri, 05 Aug 2022 15:45:45 +0000 Received: by outflank-mailman (input) for mailman id 381368; Fri, 05 Aug 2022 15:45:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oJzWC-00017n-B6 for xen-devel@lists.xenproject.org; Fri, 05 Aug 2022 15:45:44 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id a9cbb75a-14d5-11ed-bd2e-47488cf2e6aa; Fri, 05 Aug 2022 17:45:43 +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 19251113E; Fri, 5 Aug 2022 08:45:43 -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 D38B63F73B; Fri, 5 Aug 2022 08:45: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: a9cbb75a-14d5-11ed-bd2e-47488cf2e6aa From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Paul Durrant Subject: [PATCH] xen/pci: replace call to is_memory_hole to pci_check_bar Date: Fri, 5 Aug 2022 16:43:45 +0100 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: <5650ddce1de4fd5471823bde44a12a03f157bc11.1659713913.git.rahul.singh@arm.com> References: <5650ddce1de4fd5471823bde44a12a03f157bc11.1659713913.git.rahul.singh@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1659714373322100001 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko 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 --- xen/arch/arm/include/asm/pci.h | 12 ++++++++++ xen/arch/arm/pci/pci-host-common.c | 35 ++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/pci.h | 10 +++++++++ xen/drivers/passthrough/pci.c | 8 +++---- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/include/asm/pci.h b/xen/arch/arm/include/asm/pci.h index 7c7449d64f..5c4ab2c4dc 100644 --- a/xen/arch/arm/include/asm/pci.h +++ b/xen/arch/arm/include/asm/pci.h @@ -91,6 +91,16 @@ struct pci_ecam_ops { int (*init)(struct pci_config_window *); }; =20 +/* + * struct to hold pci device bar. + */ +struct pdev_bar +{ + mfn_t start; + mfn_t end; + bool is_valid; +}; + /* Default ECAM ops */ extern const struct pci_ecam_ops pci_generic_ecam_ops; =20 @@ -125,6 +135,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 fd8c0f837a..8ea1aaeece 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -363,6 +363,41 @@ int __init pci_host_bridge_mappings(struct domain *d) return 0; } =20 +static int is_bar_valid(const struct dt_device_node *dev, + u64 addr, u64 len, void *data) +{ + struct pdev_bar *bar_data =3D data; + unsigned long s =3D mfn_x(bar_data->start); + unsigned long e =3D mfn_x(bar_data->end); + + if ( (s < e) && (s >=3D PFN_DOWN(addr)) && (e<=3D PFN_DOWN(addr + len = - 1)) ) + bar_data->is_valid =3D true; + + return 0; +} + +bool pci_check_bar(const struct pci_dev *pdev, mfn_t start, mfn_t end) +{ + int ret; + struct dt_device_node *dt_node; + struct device *dev =3D (struct device *)pci_to_dev(pdev); + struct pdev_bar bar_data =3D { + .start =3D start, + .end =3D end, + .is_valid =3D false + }; + + dt_node =3D pci_find_host_bridge_node(dev); + + ret =3D dt_for_each_range(dt_node, &is_bar_valid, &bar_data); + if ( ret < 0 ) + return ret; + + if ( !bar_data.is_valid ) + return false; + + return true; +} /* * 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 29356d59a7..52453a05fe 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