From patchwork Wed Nov 24 07:59:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D96DC4321E for ; Wed, 24 Nov 2021 08:00:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230144.397883 (Exim 4.92) (envelope-from ) id 1mpnC1-0006K0-AA; Wed, 24 Nov 2021 07:59:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230144.397883; Wed, 24 Nov 2021 07:59: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 1mpnC1-0006Jt-6G; Wed, 24 Nov 2021 07:59:49 +0000 Received: by outflank-mailman (input) for mailman id 230144; Wed, 24 Nov 2021 07:59:47 +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 1mpnBz-000641-MT for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:47 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7dcc7a3a-4cfc-11ec-a9d2-d9f7a1cc8784; Wed, 24 Nov 2021 08:59:46 +0100 (CET) Received: by mail-lf1-x12a.google.com with SMTP id t26so4895181lfk.9 for ; Tue, 23 Nov 2021 23:59:46 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:45 -0800 (PST) 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: 7dcc7a3a-4cfc-11ec-a9d2-d9f7a1cc8784 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rH0iLPl/lC8zdfMkSvOZAn1ZGtgBTiLGnIq2zauCwpU=; b=CvHAJ1xE04NRPrR9uFUw3/zuzpPFg3u9wujjKFYXCAW/WtikFS4AZMgWnoVUWp0YU0 WghuxtO9EsC8Apr/X1cAc5gCPxm5sVb7+XgBZRz9IvgQS3XEnRxHo0/9okx8EMxAxI9q ItCDsuuiPjULzGue5LgYRctAbEAl/Nk2rLP5k9OnTJGB0VQJMxKHtAb1AbVe+H2VFqhd XdorHPa8OrhdN58sPA3/4UtEGA4vrK6FHYfSctMS8eDq9LxvMX6ZPeYfN7vE+KrgzyW4 YZ9ww4dByLm2snpsOm/G6MlIVwWOOWMdY1fzGUQWbcAmHikUQGkDXlUH9AMQ440cYec3 /nag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rH0iLPl/lC8zdfMkSvOZAn1ZGtgBTiLGnIq2zauCwpU=; b=GtoXhd+ipb4Dm19umfnOknFJwXOHTd+mQPO7iqCDfVh3gevf0+YOrEYyXpZSGFX+CJ 4k6ZzY/TN3xeBIhRhLwjXeymHWjzJ/PlUyFDTptpMlt45t0ompBaKKfVvBKOZ5n/O0uc T0lJid0lKMTXOy/Q3AFaZ4U0hUU2hAgkzVn53Lh7rIaerrWPU4Z8lBq7NUYsOl55wwWI IprGJpv/BrdYNqnA6ufashwes92rna3ontsYZjERRx4w44lHll+7EeCNd8MBQRfbdriS jBFkpBPHIgYBGY2mQbnVmAQiXio0JVY2VB4hBFG5aq297rFfqlhkHpEBzc85fdkUVzLg nx8g== X-Gm-Message-State: AOAM532BB0BPNGCEE0bE5BI42m4lJeE57KlubL6vbbx4Ev2wIFbqXRPn KrV8v8nKKUbhnhqaxFs9ZIoz5Pbg7ynSMQ== X-Google-Smtp-Source: ABdhPJwaEXhquUg9pSW7bS6CfvB2jhMl4knsYLQ7J3g/8mUX/NuU13lGyedBYurgkmEk6JZwO9+UtQ== X-Received: by 2002:a05:6512:15a2:: with SMTP id bp34mr12389295lfb.65.1637740786174; Tue, 23 Nov 2021 23:59:46 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko , Julien Grall Subject: [PATCH v7 1/7] xen/arm: rename DEVICE_PCI to DEVICE_PCI_HOSTBRIDGE Date: Wed, 24 Nov 2021 09:59:36 +0200 Message-Id: <20211124075942.2645445-2-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko To better reflect the nature of the device type and not to make any confusion rename DEVICE_PCI to DEVICE_PCI_HOSTBRIDGE which it really is. Suggested-by: Julien Grall Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Julien Grall Reviewed-by: Jiamei xie Reviewed-by: Rahul Singh Tested-by: Rahul Singh Reviewed-by: Henry Wang --- New in v6 --- xen/arch/arm/pci/pci-host-generic.c | 2 +- xen/arch/arm/pci/pci-host-zynqmp.c | 2 +- xen/arch/arm/pci/pci.c | 2 +- xen/include/asm-arm/device.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/pci/pci-host-generic.c b/xen/arch/arm/pci/pci-host-generic.c index 33457fbe9615..46de6e43cc72 100644 --- a/xen/arch/arm/pci/pci-host-generic.c +++ b/xen/arch/arm/pci/pci-host-generic.c @@ -32,7 +32,7 @@ static int __init pci_host_generic_probe(struct dt_device_node *dev, return pci_host_common_probe(dev, &pci_generic_ecam_ops); } -DT_DEVICE_START(pci_gen, "PCI HOST GENERIC", DEVICE_PCI) +DT_DEVICE_START(pci_gen, "PCI HOST GENERIC", DEVICE_PCI_HOSTBRIDGE) .dt_match = gen_pci_dt_match, .init = pci_host_generic_probe, DT_DEVICE_END diff --git a/xen/arch/arm/pci/pci-host-zynqmp.c b/xen/arch/arm/pci/pci-host-zynqmp.c index 61a9807d3d58..516982bca833 100644 --- a/xen/arch/arm/pci/pci-host-zynqmp.c +++ b/xen/arch/arm/pci/pci-host-zynqmp.c @@ -49,7 +49,7 @@ static int __init pci_host_generic_probe(struct dt_device_node *dev, return pci_host_common_probe(dev, &nwl_pcie_ops); } -DT_DEVICE_START(pci_gen, "PCI HOST ZYNQMP", DEVICE_PCI) +DT_DEVICE_START(pci_gen, "PCI HOST ZYNQMP", DEVICE_PCI_HOSTBRIDGE) .dt_match = nwl_pcie_dt_match, .init = pci_host_generic_probe, DT_DEVICE_END diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c index 082c14e127a8..78b97beaef12 100644 --- a/xen/arch/arm/pci/pci.c +++ b/xen/arch/arm/pci/pci.c @@ -46,7 +46,7 @@ static int __init dt_pci_init(void) dt_for_each_device_node(dt_host, np) { - rc = device_init(np, DEVICE_PCI, NULL); + rc = device_init(np, DEVICE_PCI_HOSTBRIDGE, NULL); /* * Ignore the following error codes: * - EBADF: Indicate the current device is not a pci device. diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 3782660751b6..086dde13eb6b 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -37,7 +37,7 @@ enum device_class DEVICE_SERIAL, DEVICE_IOMMU, DEVICE_GIC, - DEVICE_PCI, + DEVICE_PCI_HOSTBRIDGE, /* Use for error */ DEVICE_UNKNOWN, }; From patchwork Wed Nov 24 07:59:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4E8AC433EF for ; Wed, 24 Nov 2021 08:00:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230145.397894 (Exim 4.92) (envelope-from ) id 1mpnC2-0006aD-Jk; Wed, 24 Nov 2021 07:59:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230145.397894; Wed, 24 Nov 2021 07:59:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpnC2-0006a4-EY; Wed, 24 Nov 2021 07:59:50 +0000 Received: by outflank-mailman (input) for mailman id 230145; Wed, 24 Nov 2021 07:59: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 1mpnC0-000641-Mm for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:48 +0000 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [2a00:1450:4864:20::236]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7e5b02be-4cfc-11ec-a9d2-d9f7a1cc8784; Wed, 24 Nov 2021 08:59:47 +0100 (CET) Received: by mail-lj1-x236.google.com with SMTP id k23so3673807lje.1 for ; Tue, 23 Nov 2021 23:59:47 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:46 -0800 (PST) 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: 7e5b02be-4cfc-11ec-a9d2-d9f7a1cc8784 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KkHhYh1NWjHxEjAv0HXlf2QneLzqhRUOgxfD/xwWw+c=; b=bzykV/sO60cjghsFXeouZeeZQ2FfzEexc7UGsAx2Ekc2ogaKJgY8/Dty5JjDxgb2IE oVEi9IvxGBkmhMCOjZbPRp0WK8/Yazp0wqiNmonSwZBrRzi3YOO2+lw7MvzvgpdmqWRV JplXAXJ24uWJ1y6m8Ojw36irTyiLdwrLI1EHG9eFDvBLO3kvvjZD+9TM3daq9B69nZ01 b+DvDVJvEk1palt7/m9Xw5eE6ujvvGFDFBCApkI6R6urJrd2qPY5Aic2PuXlX7M+mDHw eK2AeXE7JvIbf1jYQz53QHEAtLlsR0lm3NfPzijHgKevo6WTvF9DnHsq1Ld4e7hYXeye qMaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KkHhYh1NWjHxEjAv0HXlf2QneLzqhRUOgxfD/xwWw+c=; b=Vrjg6N2vszq1K6Gc63horJJlCfirwYZx370qIEi839DsM9/3PV3FF2HVOlE3MuTuy3 D/CPi7vZ1IcH4Fs/Up5v2csfegOihGDZf/vv93h3pHHNbq3elF0s7WzQ4rfAcvZAWhuv RFQ/Mgot35t6us0n1ENmkWufrFPDHtcuKdyXZuROyMkv1HrscH/AsHNzlRv87qdXQTWn jj/1BxP7cokRiJ3ITj78Dz/Nsh6ppKbtQZUlcvYyQLA6IdxDHBg7QPAUIuFg/q6t5oBn LAoWrAEVkJmwOBEzPs+zvRvfhlSh/KpheBCoYIJv+JXwbUUXG1K5IlUzZOlO71+ludBO V+fw== X-Gm-Message-State: AOAM533spHxbXQFLOlU4L7/DJKgha/SbHCbCD2+06yTAiFunWGgDTKnA 28qp5uxRfTYfdvDxLsuTYxhmJXVR+o0vAw== X-Google-Smtp-Source: ABdhPJx9nN49TFsQ5xzG50EnhxC+e1pVOXpjLxq1E6VNokclR+ruBOUEqt3ZGSMOkA3LaBsYV1UyIg== X-Received: by 2002:a05:651c:514:: with SMTP id o20mr13414786ljp.393.1637740787221; Tue, 23 Nov 2021 23:59:47 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH v7 2/7] xen/arm: add pci-domain for disabled devices Date: Wed, 24 Nov 2021 09:59:37 +0200 Message-Id: <20211124075942.2645445-3-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko If a PCI host bridge device is present in the device tree, but is disabled, then its PCI host bridge driver was not instantiated. This results in the failure of the pci_get_host_bridge_segment() and the following panic during Xen start: (XEN) Device tree generation failed (-22). (XEN) (XEN) **************************************** (XEN) Panic on CPU 0: (XEN) Could not set up DOM0 guest OS (XEN) **************************************** Fix this by adding "linux,pci-domain" property for all device tree nodes which have "pci" device type, so we know which segments will be used by the guest for which bridges. Fixes: 4cfab4425d39 ("xen/arm: Add linux,pci-domain property for hwdom if not available.") Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Rahul Singh Tested-by: Rahul Singh Acked-by: Julien Grall --- Since v6: - use use_dt_domains in pci_get_new_domain_nr and return -1 if set - do not set "linux,pci-domain" if parent device is "pci" - move the code to a new helper handle_linux_pci_domain (Julien) New in v6 --- xen/arch/arm/domain_build.c | 66 +++++++++++++++++++++++------- xen/arch/arm/pci/pci-host-common.c | 8 +++- xen/include/asm-arm/pci.h | 8 ++++ 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index e76cee3caccf..c83c02ab8ac6 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -654,6 +654,55 @@ static void __init allocate_static_memory(struct domain *d, } #endif +/* + * When PCI passthrough is available we want to keep the + * "linux,pci-domain" in sync for every host bridge. + * + * Xen may not have a driver for all the host bridges. So we have + * to write an heuristic to detect whether a device node describes + * a host bridge. + * + * The current heuristic assumes that a device is a host bridge + * if the type is "pci" and then parent type is not "pci". + */ +static int handle_linux_pci_domain(struct kernel_info *kinfo, + const struct dt_device_node *node) +{ + uint16_t segment; + int res; + + if ( !is_pci_passthrough_enabled() ) + return 0; + + if ( !dt_device_type_is_equal(node, "pci") ) + return 0; + + if ( node->parent && dt_device_type_is_equal(node->parent, "pci") ) + return 0; + + if ( dt_find_property(node, "linux,pci-domain", NULL) ) + return 0; + + /* Allocate and create the linux,pci-domain */ + res = pci_get_host_bridge_segment(node, &segment); + if ( res < 0 ) + { + res = pci_get_new_domain_nr(); + if ( res < 0 ) + { + printk(XENLOG_DEBUG "Can't assign PCI segment to %s\n", + node->full_name); + return -FDT_ERR_NOTFOUND; + } + + segment = res; + printk(XENLOG_DEBUG "Assigned segment %d to %s\n", + segment, node->full_name); + } + + return fdt_property_cell(kinfo->fdt, "linux,pci-domain", segment); +} + static int __init write_properties(struct domain *d, struct kernel_info *kinfo, const struct dt_device_node *node) { @@ -755,21 +804,10 @@ static int __init write_properties(struct domain *d, struct kernel_info *kinfo, return res; } - if ( is_pci_passthrough_enabled() && dt_device_type_is_equal(node, "pci") ) - { - if ( !dt_find_property(node, "linux,pci-domain", NULL) ) - { - uint16_t segment; - - res = pci_get_host_bridge_segment(node, &segment); - if ( res < 0 ) - return res; + res = handle_linux_pci_domain(kinfo, node); - res = fdt_property_cell(kinfo->fdt, "linux,pci-domain", segment); - if ( res ) - return res; - } - } + if ( res ) + return res; /* * Override the property "status" to disable the device when it's diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c index cdeb3a283a77..9653b92b5b2e 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -30,6 +30,8 @@ static LIST_HEAD(pci_host_bridges); static atomic_t domain_nr = ATOMIC_INIT(-1); +static int use_dt_domains = -1; + static inline void __iomem *pci_remap_cfgspace(paddr_t start, size_t len) { return ioremap_nocache(start, len); @@ -137,14 +139,16 @@ void pci_add_host_bridge(struct pci_host_bridge *bridge) list_add_tail(&bridge->node, &pci_host_bridges); } -static int pci_get_new_domain_nr(void) +int pci_get_new_domain_nr(void) { + if ( use_dt_domains ) + return -1; + return atomic_inc_return(&domain_nr); } static int pci_bus_find_domain_nr(struct dt_device_node *dev) { - static int use_dt_domains = -1; int domain; domain = dt_get_pci_domain_nr(dev); diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index 81273e0d87ac..c20eba643d86 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -108,6 +108,8 @@ static always_inline bool is_pci_passthrough_enabled(void) void arch_pci_init_pdev(struct pci_dev *pdev); +int pci_get_new_domain_nr(void); + #else /*!CONFIG_HAS_PCI*/ struct arch_pci_dev { }; @@ -128,5 +130,11 @@ static inline int pci_get_host_bridge_segment(const struct dt_device_node *node, return -EINVAL; } +static inline int pci_get_new_domain_nr(void) +{ + ASSERT_UNREACHABLE(); + return -1; +} + #endif /*!CONFIG_HAS_PCI*/ #endif /* __ARM_PCI_H__ */ From patchwork Wed Nov 24 07:59:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92AF9C433F5 for ; Wed, 24 Nov 2021 08:00:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230147.397910 (Exim 4.92) (envelope-from ) id 1mpnC5-0006yd-H4; Wed, 24 Nov 2021 07:59:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230147.397910; Wed, 24 Nov 2021 07:59:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpnC5-0006xc-9Z; Wed, 24 Nov 2021 07:59:53 +0000 Received: by outflank-mailman (input) for mailman id 230147; Wed, 24 Nov 2021 07:59:51 +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 1mpnC3-0006a3-JY for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:51 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7f257fce-4cfc-11ec-9787-a32c541c8605; Wed, 24 Nov 2021 08:59:49 +0100 (CET) Received: by mail-lf1-x129.google.com with SMTP id c32so4982386lfv.4 for ; Tue, 23 Nov 2021 23:59:49 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:48 -0800 (PST) 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: 7f257fce-4cfc-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TEnw6Tbi8uyQhbNNHVX1/5nrpb6E6EbDTdN5JDsqHGk=; b=by2F/bIANGRUvvStIBUaqd7BodO++zeMWWnZlFlu5DUN6M6rH6qCLWRUxBZKz4/AXG RsTr4I1VVYaMM/xaXP/07o54/b2a6PjkBSbJKqJgBpamfkKJm9zReQlQFfNwe51SvNOL dPbEflhZbm5VgqImC488kclu9yfnt1gO9KelDXDaAPcEgh65uSSKAg83qGdVcXUvHIgy AsagpG2j6GVS7C4KDeoA8CtEl9Ud+dZOmscgwTKNKyMBHKWDIz5nxmgrsUiGWRYbZMn3 k2PC+uIpnR9Lp9zSo+SlgsFJ7a4EOt27NjEiBuPtbqGPOcgWRXnxJe7JGgVXaqZXexJy lgtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TEnw6Tbi8uyQhbNNHVX1/5nrpb6E6EbDTdN5JDsqHGk=; b=w8Dxv0/tO+/H3H5TJINUfC5DxA/lIdCTVuRAoVp2ZwBtxb8MLPqiMM+WwYIY7Gusor 6G1EkjxT9lyNZHp6blDBHhw02BxsPYFbqPye2Nxjgp4zwvQYf2Ap54PlkHwoDRpxnnQ7 NOHc0jsMnwx1iwKAtumuZQTrQOweQZU4yKkkSjarHB4zto0w7k/VEQjVPGSFCCCUtOzU v8Oq8fF9RlgDB1frQvPDvKSlhgtT95ZdnncecVnLFLhTMLkx0W3TWBLfzdLiz1J1wGhk yPuH2w4naSS+D3y1sZSDaOpyjyJ7tM0vr1NY4970H8T26L8rCEKWYrQbkcbcal2KhH7H 7gQg== X-Gm-Message-State: AOAM531SKjyFg09uh1f7rUQSsm1fUXwh8A4Se9bN5RGxWppk6c4NHX3g YpcYj4eIdQzEki0lNuefowmSc6bv6dVimA== X-Google-Smtp-Source: ABdhPJy+GvMQW9KqqejEYd/gYEIrhD225h+RXwB+gNhrTl1r8Gx0oPe/QnhW/ua+Q2LUKzW+ypYgKw== X-Received: by 2002:a05:6512:3056:: with SMTP id b22mr12540254lfb.316.1637740788381; Tue, 23 Nov 2021 23:59:48 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH v7 3/7] xen/arm: setup MMIO range trap handlers for hardware domain Date: Wed, 24 Nov 2021 09:59:38 +0200 Message-Id: <20211124075942.2645445-4-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko In order for vPCI to work it needs to maintain guest and hardware domain's views of the configuration space. For example, BARs and COMMAND registers require emulation for guests and the guest view of the registers needs to be in sync with the real contents of the relevant registers. For that ECAM address space needs to also be trapped for the hardware domain, so we need to implement PCI host bridge specific callbacks to properly setup MMIO handlers for those ranges depending on particular host bridge implementation. Signed-off-by: Oleksandr Andrushchenko --- Since v6: - eliminate pci_host_get_num_bridges and make pci_host_iterate_bridges return the count - extend comment in domain_vpci_init - remove not yet relevant code for num MMIOs and virtual bus topology - add extra check for has_vpci in domain_vpci_get_num_mmio_handlers - remove code that fixes num MMIOs for guest domain as it doesn't belong to this patch Since v5: - add vpci_sbdf_from_gpa helper for gpa to SBDF translation - take bridge's bus start into account while calculating SBDF Since v4: - unsigned int for functions working with count - gate number of MMIO handlers needed for CONFIG_HAS_PCI_MSI and fix their number, e.g. single handler for PBA and MSI-X tables (Roger) - re-work code for assigning MMIO handlers to be simpler and account on the fact that there could multiple host bridges exist for the hwdom Since v3: - fixed comment formatting Since v2: - removed unneeded assignment (count = 0) - removed unneeded header inclusion - update commit message Since v1: - Dynamically calculate the number of MMIO handlers required for vPCI and update the total number accordingly - s/clb/cb - Do not introduce a new callback for MMIO handler setup --- xen/arch/arm/domain.c | 2 + xen/arch/arm/pci/pci-host-common.c | 17 +++++++ xen/arch/arm/vpci.c | 79 +++++++++++++++++++++++++++--- xen/arch/arm/vpci.h | 6 +++ xen/include/asm-arm/pci.h | 4 ++ 5 files changed, 100 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 96e1b235501d..92a6c509e5c5 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -739,6 +739,8 @@ int arch_domain_create(struct domain *d, if ( (rc = domain_vgic_register(d, &count)) != 0 ) goto fail; + count += domain_vpci_get_num_mmio_handlers(d); + if ( (rc = domain_io_init(d, count + MAX_IO_HANDLER)) != 0 ) goto fail; diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c index 9653b92b5b2e..18b09d5e6f10 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -296,6 +296,23 @@ int pci_get_host_bridge_segment(const struct dt_device_node *node, return -EINVAL; } +int pci_host_iterate_bridges_and_count(struct domain *d, + int (*cb)(struct domain *d, + struct pci_host_bridge *bridge)) +{ + struct pci_host_bridge *bridge; + int err, count = 0; + + list_for_each_entry( bridge, &pci_host_bridges, node ) + { + err = cb(d, bridge); + if ( err ) + return err; + count += err; + } + return count; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index 23f45386f4b3..ccd998d8dba2 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -16,16 +16,31 @@ #include +static pci_sbdf_t vpci_sbdf_from_gpa(const struct pci_host_bridge *bridge, + paddr_t gpa) +{ + pci_sbdf_t sbdf; + + if ( bridge ) + { + sbdf.sbdf = VPCI_ECAM_BDF(gpa - bridge->cfg->phys_addr); + sbdf.seg = bridge->segment; + sbdf.bus += bridge->cfg->busn_start; + } + else + sbdf.sbdf = VPCI_ECAM_BDF(gpa - GUEST_VPCI_ECAM_BASE); + + return sbdf; +} + static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, register_t *r, void *p) { - pci_sbdf_t sbdf; + struct pci_host_bridge *bridge = p; + pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); /* data is needed to prevent a pointer cast on 32bit */ unsigned long data; - /* We ignore segment part and always handle segment 0 */ - sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE); - if ( vpci_ecam_read(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, &data) ) { @@ -41,10 +56,8 @@ static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info, register_t r, void *p) { - pci_sbdf_t sbdf; - - /* We ignore segment part and always handle segment 0 */ - sbdf.sbdf = VPCI_ECAM_BDF(info->gpa - GUEST_VPCI_ECAM_BASE); + struct pci_host_bridge *bridge = p; + pci_sbdf_t sbdf = vpci_sbdf_from_gpa(bridge, info->gpa); return vpci_ecam_write(sbdf, ECAM_REG_OFFSET(info->gpa), 1U << info->dabt.size, r); @@ -55,17 +68,67 @@ static const struct mmio_handler_ops vpci_mmio_handler = { .write = vpci_mmio_write, }; +static int vpci_setup_mmio_handler_cb(struct domain *d, + struct pci_host_bridge *bridge) +{ + struct pci_config_window *cfg = bridge->cfg; + + register_mmio_handler(d, &vpci_mmio_handler, + cfg->phys_addr, cfg->size, bridge); + + /* We have registered a single MMIO handler. */ + return 1; +} + int domain_vpci_init(struct domain *d) { if ( !has_vpci(d) ) return 0; + /* + * The hardware domain gets as many MMIOs as required by the + * physical host bridge. + * Guests get the virtual platform layout: one virtual host bridge for now. + */ + if ( is_hardware_domain(d) ) + { + int count; + + count = pci_host_iterate_bridges_and_count(d, vpci_setup_mmio_handler_cb); + if ( count < 0 ) + return count; + + return 0; + } + register_mmio_handler(d, &vpci_mmio_handler, GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL); return 0; } +static int vpci_get_num_handlers_cb(struct domain *d, + struct pci_host_bridge *bridge) +{ + /* Each bridge has a single MMIO handler for the configuration space. */ + return 1; +} + +unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) +{ + if ( !has_vpci(d) ) + return 0; + + if ( is_hardware_domain(d) ) + { + int ret = pci_host_iterate_bridges_and_count(d, vpci_get_num_handlers_cb); + + return ret < 0 ? 0 : ret; + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vpci.h b/xen/arch/arm/vpci.h index d8a7b0e3e802..3c713f3fcdb5 100644 --- a/xen/arch/arm/vpci.h +++ b/xen/arch/arm/vpci.h @@ -17,11 +17,17 @@ #ifdef CONFIG_HAS_VPCI int domain_vpci_init(struct domain *d); +unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d); #else static inline int domain_vpci_init(struct domain *d) { return 0; } + +static inline unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) +{ + return 0; +} #endif #endif /* __ARCH_ARM_VPCI_H__ */ diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index c20eba643d86..4278d66e5eb9 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -110,6 +110,10 @@ void arch_pci_init_pdev(struct pci_dev *pdev); int pci_get_new_domain_nr(void); +int pci_host_iterate_bridges_and_count(struct domain *d, + int (*cb)(struct domain *d, + struct pci_host_bridge *bridge)); + #else /*!CONFIG_HAS_PCI*/ struct arch_pci_dev { }; From patchwork Wed Nov 24 07:59:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34F71C433FE for ; Wed, 24 Nov 2021 08:00:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230146.397905 (Exim 4.92) (envelope-from ) id 1mpnC4-0006uK-WE; Wed, 24 Nov 2021 07:59:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230146.397905; Wed, 24 Nov 2021 07:59:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpnC4-0006u7-So; Wed, 24 Nov 2021 07:59:52 +0000 Received: by outflank-mailman (input) for mailman id 230146; Wed, 24 Nov 2021 07:59:50 +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 1mpnC2-0006a3-Qy for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:50 +0000 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [2a00:1450:4864:20::12f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7fabd428-4cfc-11ec-9787-a32c541c8605; Wed, 24 Nov 2021 08:59:50 +0100 (CET) Received: by mail-lf1-x12f.google.com with SMTP id c32so4982497lfv.4 for ; Tue, 23 Nov 2021 23:59:49 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:49 -0800 (PST) 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: 7fabd428-4cfc-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NtLazSat9apxux+5yyxbOkPmv89tR4XWYJTOoTreBMc=; b=MbPbydd08IszozKtXB23iEi80MXIftRDzIuvnQIitsp27FmVYxqB1d+gnQDZePIqLE FIgXdx/u1BXkOHDbLQUol2vYaerLrB56zRhlsyBQXdOHuRV/I5KgEjFfM9M2KFzyoH7A as6pVIjYNBcEkQ5jYHjFqdEXHZjt9kR+WD4PLSd6KIm/bYYIIfJOVyCiaFe04slbFTOj asCWuOS0KLjiQ9cUpD8dEpnuMJh/dQzxyha7JJ/PaYFEjE0/s7Vx8uM0c/PDsIIfZbOy 1mIwuRWh4KZo1dA3NqXczSQYCSGfbYGcMv6EF0+BZAlphnT5XAX91UyUmCqWyQMa5S3p CgCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NtLazSat9apxux+5yyxbOkPmv89tR4XWYJTOoTreBMc=; b=LvY9f09Y0MiplaIq5rxOZ3q2smcpkkYMvTgPiuuFs8dboY5TyRjDhz3d0+Ixd3v9oH zuzWydWw11oEXZxjA2fGv5L5t/McUYBlEtfKPiohbV1CaDzqaFt3NBYPga5/C8Aouk4z sSlJiO2k6WJtZTUQOK79cUHjXQ31483CunzRojOLNmh+TfTMljDBZwC4UFxxnOAtq9G4 sbZt2LcIV8gZ8NwdoVLamqKfZN+8bIrMkbIoWOhY/5vlf8EQ5ee6TKLELpIRsuFz5UWE MB16S5XZbz1YI+lcqj4Gh7Wnrp31WnXfFU+Hfo+7EIHi7TFLR1sXIcWW1R5xQLMbJSzW 3Mcw== X-Gm-Message-State: AOAM530OuLuyOtWsr2wZ8046xVSpjoshe/NSPyyMtqo/z2H45HlN6waG J2HGv5KDtyfLjOdQn3Ns0rHScOmmK4kOxg== X-Google-Smtp-Source: ABdhPJxJvBRGULlAB79krxpx2pd/sSPt0RtA66daRKicCVK9MHazHG557XsZg0SUYIuzBhUCn/HNGw== X-Received: by 2002:a05:6512:ac9:: with SMTP id n9mr12022679lfu.59.1637740789446; Tue, 23 Nov 2021 23:59:49 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH v7 4/7] xen/arm: account IO handler for emulated PCI host bridge Date: Wed, 24 Nov 2021 09:59:39 +0200 Message-Id: <20211124075942.2645445-5-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko At the moment, we always allocate an extra 16 slots for IO handlers (see MAX_IO_HANDLER). So while adding an IO trap handler for the emulated PCI host bridge we are not breaking anything, but we have a latent bug as the maximum number of IOs may be exceeded. Fix this by explicitly telling that we have an additional IO handler, so it is accounted. Fixes: d59168dc05a5 ("xen/arm: Enable the existing x86 virtual PCI support for ARM") Signed-off-by: Oleksandr Andrushchenko Acked-by: Julien Grall --- New in v7 --- xen/arch/arm/vpci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c index ccd998d8dba2..8e801f275879 100644 --- a/xen/arch/arm/vpci.c +++ b/xen/arch/arm/vpci.c @@ -126,7 +126,8 @@ unsigned int domain_vpci_get_num_mmio_handlers(struct domain *d) return ret < 0 ? 0 : ret; } - return 0; + /* For a single emulated host bridge's configuration space. */ + return 1; } /* From patchwork Wed Nov 24 07:59:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68107C4332F for ; Wed, 24 Nov 2021 08:00:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230148.397917 (Exim 4.92) (envelope-from ) id 1mpnC6-00072v-3n; Wed, 24 Nov 2021 07:59:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230148.397917; Wed, 24 Nov 2021 07:59:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpnC5-000715-Jc; Wed, 24 Nov 2021 07:59:53 +0000 Received: by outflank-mailman (input) for mailman id 230148; Wed, 24 Nov 2021 07:59:52 +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 1mpnC4-000641-CN for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:52 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 805dce8a-4cfc-11ec-a9d2-d9f7a1cc8784; Wed, 24 Nov 2021 08:59:51 +0100 (CET) Received: by mail-lf1-x136.google.com with SMTP id t26so4895732lfk.9 for ; Tue, 23 Nov 2021 23:59:51 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:50 -0800 (PST) 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: 805dce8a-4cfc-11ec-a9d2-d9f7a1cc8784 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UTFAcfDVj5boS18sBATp/O7+L/F9qrCvn3jbQ1Onsrg=; b=hbTmKJcmSNf2UsvgYlzNV1mjKdhPBVzXW1CrogUsjsWBMICC7Fi/4mQYdZOS3JTPG/ XE4TRnyWh4FSvLxJfVXVsWPdP96vCCnUfKrAVq09yr0hj2vZmw5nifMTUZkyoqcBly66 qurp2dcHVvM90bDKkC3498zBqG52cmJyzZ0rOBZTkcg9znwq4zfETr1gw/aaeb0KdCHw 0tMJKd64qPIqD0vLizHamJ937jMh3ISQdN1AJsk+KaERJsJyZ0BOceSl6gPO0d1KQJ/F zUSWVmdZB8o393VlXOw/DsWxr9zirsLuMSPkUEj5woVW+ymGBC7Pxpg1OErytHTIaD06 tQhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UTFAcfDVj5boS18sBATp/O7+L/F9qrCvn3jbQ1Onsrg=; b=IO9So4/WXDiXT/e56lSwgrU2m96IZ+tWtv4ph50nkXpCVGCNSZv9kSKP5Sli5cy2g+ YtHNhydxwJDsJHo3ks/aEgCXqz9LPKnXQW8rZa4LzYESBHSRkog/NOHWDIRB5RDwaYZY sn8V1xNXwzNBavMuitAoqEQeXDCmzU5HyPk8BGM6IQ+SwbFDfJp2vB4y1oTTzEEyb1n3 ptY3afqsVv6+Yi0JUiBkY9nz6Rm1NtLCMAJLcFzE/Aj5tbZoMmpRm0A9Gcmh/wqCBkIp KfQY33iJsGVE1SBpl5mfYGJqZ2y79Z0s+Euejw/hgyHdeSHplJYIDw1Blu+j53bLeMCH fGzg== X-Gm-Message-State: AOAM5325iUJFTk8SV2UTHkrwt304krYV3uoojymy1GrMOFnWDRNjksEy DhnUZFifjHKhMlpymuyR3evesnO9ZpLgeQ== X-Google-Smtp-Source: ABdhPJzeqEo/7ODLalZpn/uWhQuf+BtXcg5hOYe6wx3UTVLwqgqziXEf+6k13p0TWzdhk0aoZkvNeg== X-Received: by 2002:a05:6512:2101:: with SMTP id q1mr12118307lfr.663.1637740790512; Tue, 23 Nov 2021 23:59:50 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko Subject: [PATCH v7 5/7] xen/arm: do not map PCI ECAM and MMIO space to Domain-0's p2m Date: Wed, 24 Nov 2021 09:59:40 +0200 Message-Id: <20211124075942.2645445-6-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko PCI host bridges are special devices in terms of implementing PCI passthrough. According to [1] the current implementation depends on Domain-0 to perform the initialization of the relevant PCI host bridge hardware and perform PCI device enumeration. In order to achieve that one of the required changes is to not map all the memory ranges in map_range_to_domain as we traverse the device tree on startup and perform some additional checks if the range needs to be mapped to Domain-0. The generic PCI host controller device tree binding says [2]: - ranges: As described in IEEE Std 1275-1994, but must provide at least a definition of non-prefetchable memory. One or both of prefetchable Memory and IO Space may also be provided. - reg : The Configuration Space base address and size, as accessed from the parent bus. The base address corresponds to the first bus in the "bus-range" property. If no "bus-range" is specified, this will be bus 0 (the default). From the above none of the memory ranges from the "ranges" property needs to be mapped to Domain-0 at startup as MMIO mapping is going to be handled dynamically by vPCI as we assign PCI devices, e.g. each device assigned to Domain-0/guest will have its MMIOs mapped/unmapped as needed by Xen. The "reg" property covers not only ECAM space, but may also have other then the configuration memory ranges described, for example [3]: - reg: Should contain rc_dbi, config registers location and length. - reg-names: Must include the following entries: "rc_dbi": controller configuration registers; "config": PCIe configuration space registers. This patch makes it possible to not map all the ranges from the "ranges" property and also ECAM from the "reg". All the rest from the "reg" property still needs to be mapped to Domain-0, so the PCI host bridge remains functional in Domain-0. This is done by first skipping the mappings while traversing the device tree as it is done for usual devices and then by calling a dedicated pci_host_bridge_mappings function which only maps MMIOs required by the host bridges leaving the regions, needed for vPCI traps, unmapped. [1] https://lists.xenproject.org/archives/html/xen-devel/2020-07/msg00777.html [2] https://www.kernel.org/doc/Documentation/devicetree/bindings/pci/host-generic-pci.txt [3] https://www.kernel.org/doc/Documentation/devicetree/bindings/pci/hisilicon-pcie.txt Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Julien Grall --- Since v7: - updates in comments and commit message Since v5: - remove some need_mapping local variables - use own_device in handle_device - add __init for pci_ecam_need_p2m_hwdom_mapping - make pci_host_bridge_mappings use p2m_mmio_direct_dev directly Since v4: - update skip_mapping comment - add comment why we need to map interrupts to Dom0 Since v3: - pass struct map_range_data to map_dt_irq_to_domain - remove redundant check from map_range_to_domain - fix handle_device's .skip_mapping Since v2: - removed check in map_range_to_domain for PCI_DEV and moved it to handle_device, so the code is simpler - s/map_pci_bridge/skip_mapping - extended comment in pci_host_bridge_mappings - minor code restructure in construct_dom0 - s/.need_p2m_mapping/.need_p2m_hwdom_mapping and related callbacks - unsigned int i; in pci_host_bridge_mappings Since v1: - Added better description of why and what needs to be mapped into Domain-0's p2m and what doesn't - Do not do any mappings for PCI devices while traversing the DT - Walk all the bridges and make required mappings in one go --- xen/arch/arm/domain_build.c | 66 +++++++++++++++++------------- xen/arch/arm/pci/ecam.c | 14 +++++++ xen/arch/arm/pci/pci-host-common.c | 50 ++++++++++++++++++++++ xen/arch/arm/pci/pci-host-zynqmp.c | 1 + xen/include/asm-arm/pci.h | 10 +++++ xen/include/asm-arm/setup.h | 13 ++++++ 6 files changed, 126 insertions(+), 28 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index c83c02ab8ac6..47c884cca2c3 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -51,12 +51,6 @@ static int __init parse_dom0_mem(const char *s) } custom_param("dom0_mem", parse_dom0_mem); -struct map_range_data -{ - struct domain *d; - p2m_type_t p2mt; -}; - /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn #define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) @@ -1720,10 +1714,10 @@ static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, const struct dt_irq *dt_irq, void *data) { - struct domain *d = data; + struct map_range_data *mr_data = data; + struct domain *d = mr_data->d; unsigned int irq = dt_irq->irq; int res; - bool need_mapping = !dt_device_for_passthrough(dev); if ( irq < NR_LOCAL_IRQS ) { @@ -1742,18 +1736,16 @@ static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, return res; } - res = map_irq_to_domain(d, irq, need_mapping, dt_node_name(dev)); + res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev)); return 0; } -static int __init map_range_to_domain(const struct dt_device_node *dev, - u64 addr, u64 len, - void *data) +int __init map_range_to_domain(const struct dt_device_node *dev, + u64 addr, u64 len, void *data) { struct map_range_data *mr_data = data; struct domain *d = mr_data->d; - bool need_mapping = !dt_device_for_passthrough(dev); int res; res = iomem_permit_access(d, paddr_to_pfn(addr), @@ -1767,7 +1759,7 @@ static int __init map_range_to_domain(const struct dt_device_node *dev, return res; } - if ( need_mapping ) + if ( !mr_data->skip_mapping ) { res = map_regions_p2mt(d, gaddr_to_gfn(addr), @@ -1796,23 +1788,21 @@ static int __init map_range_to_domain(const struct dt_device_node *dev, * then we may need to perform additional mappings in order to make * the child resources available to domain 0. */ -static int __init map_device_children(struct domain *d, - const struct dt_device_node *dev, - p2m_type_t p2mt) +static int __init map_device_children(const struct dt_device_node *dev, + struct map_range_data *mr_data) { - struct map_range_data mr_data = { .d = d, .p2mt = p2mt }; - int ret; - if ( dt_device_type_is_equal(dev, "pci") ) { + int ret; + dt_dprintk("Mapping children of %s to guest\n", dt_node_full_name(dev)); - ret = dt_for_each_irq_map(dev, &map_dt_irq_to_domain, d); + ret = dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); if ( ret < 0 ) return ret; - ret = dt_for_each_range(dev, &map_range_to_domain, &mr_data); + ret = dt_for_each_range(dev, &map_range_to_domain, mr_data); if ( ret < 0 ) return ret; } @@ -1892,14 +1882,28 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, unsigned int i; int res; u64 addr, size; - bool need_mapping = !dt_device_for_passthrough(dev); + bool own_device = !dt_device_for_passthrough(dev); + /* + * We want to avoid mapping the MMIO in dom0 for the following cases: + * - The device is owned by dom0 (i.e. it has been flagged for + * passthrough). + * - PCI host bridges with driver in Xen. They will later be mapped by + * pci_host_bridge_mappings(). + */ + struct map_range_data mr_data = { + .d = d, + .p2mt = p2mt, + .skip_mapping = !own_device || + (is_pci_passthrough_enabled() && + (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) + }; naddr = dt_number_of_address(dev); dt_dprintk("%s passthrough = %d naddr = %u\n", - dt_node_full_name(dev), need_mapping, naddr); + dt_node_full_name(dev), own_device, naddr); - if ( need_mapping ) + if ( own_device ) { dt_dprintk("Check if %s is behind the IOMMU and add it\n", dt_node_full_name(dev)); @@ -1925,14 +1929,13 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, } } - res = handle_device_interrupts(d, dev, need_mapping); + res = handle_device_interrupts(d, dev, own_device); if ( res < 0 ) return res; /* Give permission and map MMIOs */ for ( i = 0; i < naddr; i++ ) { - struct map_range_data mr_data = { .d = d, .p2mt = p2mt }; res = dt_device_get_address(dev, i, &addr, &size); if ( res ) { @@ -1946,7 +1949,7 @@ static int __init handle_device(struct domain *d, struct dt_device_node *dev, return res; } - res = map_device_children(d, dev, p2mt); + res = map_device_children(dev, &mr_data); if ( res ) return res; @@ -3105,7 +3108,14 @@ static int __init construct_dom0(struct domain *d) return rc; if ( acpi_disabled ) + { rc = prepare_dtb_hwdom(d, &kinfo); + if ( rc < 0 ) + return rc; +#ifdef CONFIG_HAS_PCI + rc = pci_host_bridge_mappings(d); +#endif + } else rc = prepare_acpi(d, &kinfo); diff --git a/xen/arch/arm/pci/ecam.c b/xen/arch/arm/pci/ecam.c index 602d00799c8d..4f71b11c3057 100644 --- a/xen/arch/arm/pci/ecam.c +++ b/xen/arch/arm/pci/ecam.c @@ -40,6 +40,19 @@ void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, return base + (PCI_DEVFN2(sbdf.bdf) << devfn_shift) + where; } +bool __init pci_ecam_need_p2m_hwdom_mapping(struct domain *d, + struct pci_host_bridge *bridge, + uint64_t addr) +{ + struct pci_config_window *cfg = bridge->cfg; + + /* + * We do not want ECAM address space to be mapped in Domain-0's p2m, + * so we can trap access to it. + */ + return cfg->phys_addr != addr; +} + /* ECAM ops */ const struct pci_ecam_ops pci_generic_ecam_ops = { .bus_shift = 20, @@ -47,6 +60,7 @@ const struct pci_ecam_ops pci_generic_ecam_ops = { .map_bus = pci_ecam_map_bus, .read = pci_generic_config_read, .write = pci_generic_config_write, + .need_p2m_hwdom_mapping = pci_ecam_need_p2m_hwdom_mapping, } }; diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c index 18b09d5e6f10..1b18480adf02 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -22,6 +22,8 @@ #include #include +#include + /* * List for all the pci host bridges. */ @@ -313,6 +315,54 @@ int pci_host_iterate_bridges_and_count(struct domain *d, return count; } +/* + * For each PCI host bridge we need to only map those ranges + * which are used by Domain-0 to properly initialize the bridge, + * e.g. we do not want to map ECAM configuration space which lives in + * "reg" device tree property, but we want to map other regions of + * the host bridge. The PCI aperture defined by the "ranges" device + * tree property should also be skipped. + */ +int __init pci_host_bridge_mappings(struct domain *d) +{ + struct pci_host_bridge *bridge; + struct map_range_data mr_data = { + .d = d, + .p2mt = p2m_mmio_direct_dev, + .skip_mapping = false + }; + + list_for_each_entry( bridge, &pci_host_bridges, node ) + { + const struct dt_device_node *dev = bridge->dt_node; + unsigned int i; + + for ( i = 0; i < dt_number_of_address(dev); i++ ) + { + uint64_t addr, size; + int err; + + err = dt_device_get_address(dev, i, &addr, &size); + if ( err ) + { + printk(XENLOG_ERR + "Unable to retrieve address range index=%u for %s\n", + i, dt_node_full_name(dev)); + return err; + } + + if ( bridge->ops->need_p2m_hwdom_mapping(d, bridge, addr) ) + { + err = map_range_to_domain(dev, addr, size, &mr_data); + if ( err ) + return err; + } + } + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/pci/pci-host-zynqmp.c b/xen/arch/arm/pci/pci-host-zynqmp.c index 516982bca833..101edb8593c1 100644 --- a/xen/arch/arm/pci/pci-host-zynqmp.c +++ b/xen/arch/arm/pci/pci-host-zynqmp.c @@ -34,6 +34,7 @@ const struct pci_ecam_ops nwl_pcie_ops = { .map_bus = pci_ecam_map_bus, .read = pci_generic_config_read, .write = pci_generic_config_write, + .need_p2m_hwdom_mapping = pci_ecam_need_p2m_hwdom_mapping, } }; diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index 4278d66e5eb9..679fc83f713b 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -17,6 +17,8 @@ #ifdef CONFIG_HAS_PCI +#include + #define pci_to_dev(pcidev) (&(pcidev)->arch.dev) extern bool pci_passthrough_enabled; @@ -73,6 +75,9 @@ struct pci_ops { uint32_t reg, uint32_t len, uint32_t *value); int (*write)(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t reg, uint32_t len, uint32_t value); + bool (*need_p2m_hwdom_mapping)(struct domain *d, + struct pci_host_bridge *bridge, + uint64_t addr); }; /* @@ -96,6 +101,9 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t reg, uint32_t len, uint32_t value); void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t where); +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); int pci_get_host_bridge_segment(const struct dt_device_node *node, @@ -114,6 +122,8 @@ int pci_host_iterate_bridges_and_count(struct domain *d, int (*cb)(struct domain *d, struct pci_host_bridge *bridge)); +int pci_host_bridge_mappings(struct domain *d); + #else /*!CONFIG_HAS_PCI*/ struct arch_pci_dev { }; diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index 95da0b7ab9cd..88d9673db817 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -2,6 +2,8 @@ #define __ARM_SETUP_H_ #include +#include +#include #define MIN_FDT_ALIGN 8 #define MAX_FDT_SIZE SZ_2M @@ -77,6 +79,14 @@ struct bootinfo { #endif }; +struct map_range_data +{ + struct domain *d; + p2m_type_t p2mt; + /* Set if mapping of the memory ranges must be skipped. */ + bool skip_mapping; +}; + extern struct bootinfo bootinfo; extern domid_t max_init_domid; @@ -124,6 +134,9 @@ void device_tree_get_reg(const __be32 **cell, u32 address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); +int map_range_to_domain(const struct dt_device_node *dev, + u64 addr, u64 len, void *data); + #endif /* * Local variables: From patchwork Wed Nov 24 07:59:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31E27C4167B for ; Wed, 24 Nov 2021 08:00:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230149.397922 (Exim 4.92) (envelope-from ) id 1mpnC6-0007Ex-OK; Wed, 24 Nov 2021 07:59:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230149.397922; Wed, 24 Nov 2021 07:59:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpnC6-0007B5-F0; Wed, 24 Nov 2021 07:59:54 +0000 Received: by outflank-mailman (input) for mailman id 230149; Wed, 24 Nov 2021 07:59:53 +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 1mpnC5-0006a3-0s for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:53 +0000 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [2a00:1450:4864:20::235]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 80fc7e82-4cfc-11ec-9787-a32c541c8605; Wed, 24 Nov 2021 08:59:52 +0100 (CET) Received: by mail-lj1-x235.google.com with SMTP id 207so3571506ljf.10 for ; Tue, 23 Nov 2021 23:59:52 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:51 -0800 (PST) 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: 80fc7e82-4cfc-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bjFZpW48zi8kzMV1Qalht/WLcDbP0OlhtteqBSVp5Go=; b=o9w9CKOl5vt2YPplpPGhxiD6QtvA0G30Yn3IsLXwoPEBfB2WV9r7Ec8mEVY3vJDMFB UUinnnxrNOOZ+baitvt4EWvoHFtqz9KQ3ob8Ak7lRGjpGTQTcvzVJRPSRO2/SwADczE0 zlLCk+f4el2PplaQ/PvHY6GNm812jti1cwjCd7+P/z6Ifi/9N5IPzP9mRbbKmCxehh30 IC2061KUkFdYApXcMf0Ffsj0KOEUqnrFHsg/nKsEiNTyQq7zQ7KBnnfV1O4Fx03A6KEc 5z59SqTLN4YuF/7OOWI0UfohgXgSubDs2Z5Z0kLLxF8zVjFCdvEw1tWHB0gFCMknY77/ PMIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bjFZpW48zi8kzMV1Qalht/WLcDbP0OlhtteqBSVp5Go=; b=fa5BdvbFxDFgOoUCnxDMvGbSlRY1Ku7LDHyjI/YHlPUpkXvRhyg6RL87ZmCEO78uhM 17f71EAxLyaJbAu0CsZufw/i8K349Ca2y7rVFVIjGx3vxDWNB+uAVgxhNeh+4mwfy9vE cqdDsyz/SeMmNwLp3ROLr6xrjxiW+PbYjiK1r/6UXzWW+DgJMZvGD068ASBNuysR2aDD g7nHt44iLoKUBeQoWV2WvwS/hW791D/EgbdqaAbz+GZTX7+OcPpEK3FLBlg5YdGak37L QlAyInPh/0HfMuEyMab+StsIJ9dhXdDtGXPP5grzQWHsKvR8f6gu0R1RI5LnTFkZQT/7 ZGzg== X-Gm-Message-State: AOAM5304qVxvSC0TKWLUCby19eoFYbylt2BL+C918houulNJtTwijkpe 39JI+H3ks/oTDOfY6c/I61NtlR9puQ+elw== X-Google-Smtp-Source: ABdhPJyX2l/icfyS9QZFeP5bbqeK5COGfFR6aGciFju2+RQ8jtec3iR+467q9jAbwxflHePDSqKNJQ== X-Received: by 2002:a2e:870b:: with SMTP id m11mr12691327lji.20.1637740791614; Tue, 23 Nov 2021 23:59:51 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko , Julien Grall Subject: [PATCH v7 6/7] xen/arm: process pending vPCI map/unmap operations Date: Wed, 24 Nov 2021 09:59:41 +0200 Message-Id: <20211124075942.2645445-7-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko vPCI may map and unmap PCI device memory (BARs) being passed through which may take a lot of time. For this those operations may be deferred to be performed later, so that they can be safely preempted. Currently this deferred processing is happening in common IOREQ code which doesn't seem to be the right place for x86 and is even more doubtful because IOREQ may not be enabled for Arm at all. So, for Arm the pending vPCI work may have no chance to be executed if the processing is left as is in the common IOREQ code only. For that reason make vPCI processing happen in arch specific code. Please be aware that there are a few outstanding TODOs affecting this code path, see xen/drivers/vpci/header.c:map_range and xen/drivers/vpci/header.c:vpci_process_pending. Signed-off-by: Oleksandr Andrushchenko [x86 part] Acked-by: Jan Beulich Reviewed-by: Julien Grall Reviewed-by: Rahul Singh Tested-by: Rahul Singh Reviewed-by: Paul Durrant --- Cc: Andrew Cooper Cc: Paul Durrant Since v5: - check_for_vcpu_work: vPCI addition is moved before the vcpu_ioreq__handle_completion(v). This is to avoid differences with the x86 version. (Julien) Since v2: - update commit message with more insight on x86, IOREQ and Arm - restored order of invocation for IOREQ and vPCI processing (Jan) Since v1: - Moved the check for pending vpci work from the common IOREQ code to hvm_do_resume on x86 - Re-worked the code for Arm to ensure we don't miss pending vPCI work --- xen/arch/arm/traps.c | 13 +++++++++++++ xen/arch/x86/hvm/hvm.c | 6 ++++++ xen/common/ioreq.c | 9 --------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 219ab3c3fbde..8757210a798b 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -2290,6 +2291,18 @@ static bool check_for_vcpu_work(void) { struct vcpu *v = current; + if ( has_vpci(v->domain) ) + { + bool pending; + + local_irq_enable(); + pending = vpci_process_pending(v); + local_irq_disable(); + + if ( pending ) + return true; + } + #ifdef CONFIG_IOREQ_SERVER if ( domain_has_ioreq_server(v->domain) ) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index eee365711d63..096a61b7ea02 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -546,6 +546,12 @@ void hvm_do_resume(struct vcpu *v) pt_restore_timer(v); + if ( has_vpci(v->domain) && vpci_process_pending(v) ) + { + raise_softirq(SCHEDULE_SOFTIRQ); + return; + } + if ( !vcpu_ioreq_handle_completion(v) ) return; diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index d732dc045df9..689d256544c8 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -25,9 +25,7 @@ #include #include #include -#include #include -#include #include #include @@ -212,19 +210,12 @@ static bool wait_for_io(struct ioreq_vcpu *sv, ioreq_t *p) bool vcpu_ioreq_handle_completion(struct vcpu *v) { - struct domain *d = v->domain; struct vcpu_io *vio = &v->io; struct ioreq_server *s; struct ioreq_vcpu *sv; enum vio_completion completion; bool res = true; - if ( has_vpci(d) && vpci_process_pending(v) ) - { - raise_softirq(SCHEDULE_SOFTIRQ); - return false; - } - while ( (sv = get_pending_vcpu(v, &s)) != NULL ) if ( !wait_for_io(sv, get_ioreq(s, v)) ) return false; From patchwork Wed Nov 24 07:59:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 12636319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75AB3C43217 for ; Wed, 24 Nov 2021 08:00:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.230150.397940 (Exim 4.92) (envelope-from ) id 1mpnC8-0007hc-6x; Wed, 24 Nov 2021 07:59:56 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 230150.397940; Wed, 24 Nov 2021 07:59:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpnC7-0007g9-ST; Wed, 24 Nov 2021 07:59:55 +0000 Received: by outflank-mailman (input) for mailman id 230150; Wed, 24 Nov 2021 07:59:54 +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 1mpnC5-000641-To for xen-devel@lists.xenproject.org; Wed, 24 Nov 2021 07:59:54 +0000 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [2a00:1450:4864:20::133]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8199097e-4cfc-11ec-a9d2-d9f7a1cc8784; Wed, 24 Nov 2021 08:59:53 +0100 (CET) Received: by mail-lf1-x133.google.com with SMTP id l22so4951015lfg.7 for ; Tue, 23 Nov 2021 23:59:53 -0800 (PST) Received: from localhost.localdomain ([185.199.97.5]) by smtp.gmail.com with ESMTPSA id i24sm1750358ljm.135.2021.11.23.23.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 23:59:52 -0800 (PST) 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: 8199097e-4cfc-11ec-a9d2-d9f7a1cc8784 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MOZs5e3kpEpL+b+deAV/zwFnsBBkhNnhQEIpK1qMuJ0=; b=RIJUOX3nHwSi2SR6buZMi5SQHDAQreoujMtCVvw4wVMs5Oc/LmzuHHJhOGAM0sfwwG 7X9RXZhD/MEsLRjSkiZM16h17sG6FnVWrvw+Rtlv0sBZOAkj9uPa1VZ17riqXoT8u0Wh ki4KPsEPLTtLthMTZzZ/sXpNmz/wb5vhHgYlYbp6wDW2RU5FxIDK86y9YDWBmcsp4q5M 42p6bJNsdWhFZxX72dDLH5KyYs+g+/7CU3+rPTPjDE0DJ6oFY4fC0URsrvpCRtRa/kxw /9pFL/SiB39tlqQnm54ecZSC5u5KePTqlTDFmVkuES4qJjXZW66c905CDlhLZbUcy8YL EmCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MOZs5e3kpEpL+b+deAV/zwFnsBBkhNnhQEIpK1qMuJ0=; b=Ritzh5t+FgpLKvcarBSHzCsuoRZp5NMpfe8AIqvMKqQLJS0xopYJ7P5j2VFaxa+Uyq y9cXnseZtC9jr+IfgjdqFyglgb5htf6+0E8+69XXQ+m2im7dZ0y3pure1urmRfC3OcK/ Loypq2CGn+QEaVn9TTOhoLR6cMY2WOPyVWiD1xec05cch/4WiSAsPz7fsB737UROMVHQ 8sWOwYO6/bvN8Bdv7ltXJbgjdeVb+D5IxpVaTVcgnKwbmYwCwYQXf8j3CCcieuojY8a4 1KP9PxOdx5KFKRNDPB4M2Ma35mAqiW3rR8262mr9bXsJXochpVH3dc+1Syt9cQ466tTm yMkQ== X-Gm-Message-State: AOAM530OJ47mkyIJKhwRnkOsgijdQAoiTHFxU57v7U6bMmma+e/RZ5+U SaAvh67tzA2ef/N8pRomK40i7RbM3g9dxg== X-Google-Smtp-Source: ABdhPJx+u46xX+7n/0n6dnGmme9l1Kx67ttIOWgvMxAk+0FuvAplKaRIkj3mbLKrtDkacbpLOzy3TQ== X-Received: by 2002:a19:3844:: with SMTP id d4mr11647104lfj.64.1637740792674; Tue, 23 Nov 2021 23:59:52 -0800 (PST) From: Oleksandr Andrushchenko To: xen-devel@lists.xenproject.org Cc: julien@xen.org, sstabellini@kernel.org, oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com, Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com, andrew.cooper3@citrix.com, george.dunlap@citrix.com, paul@xen.org, bertrand.marquis@arm.com, rahul.singh@arm.com, Oleksandr Andrushchenko , Julien Grall Subject: [PATCH v7 7/7] xen/arm: do not use void pointer in pci_host_common_probe Date: Wed, 24 Nov 2021 09:59:42 +0200 Message-Id: <20211124075942.2645445-8-andr2000@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211124075942.2645445-1-andr2000@gmail.com> References: <20211124075942.2645445-1-andr2000@gmail.com> MIME-Version: 1.0 From: Oleksandr Andrushchenko There is no reason to use void pointer while passing ECAM ops to the pci_host_common_probe function as it is anyway casted to struct pci_ecam_ops inside. For that reason remove the void pointer and pass struct pci_ecam_ops pointer as is. Signed-off-by: Oleksandr Andrushchenko Acked-by: Julien Grall Reviewed-by: Rahul Singh Tested-by: Rahul Singh --- New in v4 --- xen/arch/arm/pci/ecam.c | 4 ++-- xen/arch/arm/pci/pci-host-common.c | 6 ++---- xen/include/asm-arm/pci.h | 5 +++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/pci/ecam.c b/xen/arch/arm/pci/ecam.c index 4f71b11c3057..6aeea12a68bf 100644 --- a/xen/arch/arm/pci/ecam.c +++ b/xen/arch/arm/pci/ecam.c @@ -24,8 +24,8 @@ void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t where) { const struct pci_config_window *cfg = bridge->cfg; - struct pci_ecam_ops *ops = - container_of(bridge->ops, struct pci_ecam_ops, pci_ops); + const struct pci_ecam_ops *ops = + container_of(bridge->ops, const struct pci_ecam_ops, pci_ops); unsigned int devfn_shift = ops->bus_shift - 8; void __iomem *base; diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c index 1b18480adf02..b1a26eb840ab 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -198,18 +198,16 @@ static int pci_bus_find_domain_nr(struct dt_device_node *dev) return domain; } -int pci_host_common_probe(struct dt_device_node *dev, const void *data) +int pci_host_common_probe(struct dt_device_node *dev, + const struct pci_ecam_ops *ops) { struct pci_host_bridge *bridge; struct pci_config_window *cfg; - struct pci_ecam_ops *ops; int err; if ( dt_device_for_passthrough(dev) ) return 0; - ops = (struct pci_ecam_ops *) data; - bridge = pci_alloc_host_bridge(); if ( !bridge ) return -ENOMEM; diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index 679fc83f713b..7c7449d64fca 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -65,7 +65,7 @@ struct pci_host_bridge { struct list_head node; /* Node in list of host bridges */ uint16_t segment; /* Segment number */ struct pci_config_window* cfg; /* Pointer to the bridge config window */ - struct pci_ops *ops; + const struct pci_ops *ops; }; struct pci_ops { @@ -94,7 +94,8 @@ struct pci_ecam_ops { /* Default ECAM ops */ extern const struct pci_ecam_ops pci_generic_ecam_ops; -int pci_host_common_probe(struct dt_device_node *dev, const void *data); +int pci_host_common_probe(struct dt_device_node *dev, + const struct pci_ecam_ops *ops); int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t reg, uint32_t len, uint32_t *value); int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,