From patchwork Tue Apr 11 19:16:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208100 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 7AA03C77B73 for ; Tue, 11 Apr 2023 19:17:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519770.806750 (Exim 4.92) (envelope-from ) id 1pmJUK-0005JE-Lj; Tue, 11 Apr 2023 19:17:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519770.806750; Tue, 11 Apr 2023 19:17:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUK-0005J7-I8; Tue, 11 Apr 2023 19:17:08 +0000 Received: by outflank-mailman (input) for mailman id 519770; Tue, 11 Apr 2023 19:17:05 +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 1pmJUH-0004Ta-Dk for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:05 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061e.outbound.protection.outlook.com [2a01:111:f400:7e8a::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7003e71b-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:03 +0200 (CEST) Received: from MW3PR05CA0004.namprd05.prod.outlook.com (2603:10b6:303:2b::9) by MW6PR12MB8734.namprd12.prod.outlook.com (2603:10b6:303:249::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31; Tue, 11 Apr 2023 19:17:00 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::33) by MW3PR05CA0004.outlook.office365.com (2603:10b6:303:2b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:16:59 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:16:59 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:54 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:54 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:53 -0500 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: 7003e71b-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZoaxB4bFLbZgS5WHHZcc7Q2JNIUjaW6J+JCxA2fmYTW3nBQ2j9coBWisKiCfCXFOcjrFMTstSF0xWUGWtuCyep3JhovZ1XV5inwtQLmZy8uO+FYvx5mDwiBdcL6PLqd7EtB0GLquF5Pl5Hc3LXu3CAC5oEyM2rZxbBCL/58jxvE9aoxo740ZUVX9Rc6bvUJF38XrQzk2NUYrPSrAhccYEYaOVr9n8MtwIG5hYV9tJIj4yvzsJtJrwbmEeS+fC6IHFmMm/bvOdHFwjnL2/nqmODQhBwPEuwI8zon1FpL9EZrM/5fHWNQdLAd2OCFdQc3h07QoCzui9AlPZ6uYGsIPRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z2clB4UixcJGvwOZJ+XN0wD+kcnhi2QU+8ofkZ5Co48=; b=RoZApb5D1WrOD7o9t5X9invczFFpM8bXTIFK1x6yv+3TUxNKFSmB3f68ySJc6moMrpmguITRrb8G1Z9Eg3iya5EzPRP+eX5XFexXisbGVyF8um0COhhoJ5Q60FEdFev7CbsZfo3Nt8rZxN01+IMhyockuz+HdWmLRaKZdG4XyuUd3nXoC0wL1cp5ZFD9k6A+Pj9kMr4J53LXAoFI4P4+WvAlcgIhu8ZwmNwQ1Jx2+AwSIRnLemwiCNYf5EGvOu9TFG08pVt9Vk2KQWMx6GV0rO1D1qq7YnJGeh4MRQV91Cifi3JAZig53CQDi60kteeemQDfNSWCOjT/oK5dr/GgKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z2clB4UixcJGvwOZJ+XN0wD+kcnhi2QU+8ofkZ5Co48=; b=uG3yZ2q5CylqwilEN0w1lucY3u1hCuIw3gAflcKN2wFvTGJlsbJOVoocZsN62RVXs8md4ynK/i2EJD4Kd9n+L3YDixHpgt81Xdc+yDJdzoZagvx0OA/iP3eR6k6AmI+5qyCX8MgdbB80bE5ShP9n6Sk9LC4s8FzM/+ovwThwI8I= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v5 01/17] xen/arm/device: Remove __init from function type Date: Tue, 11 Apr 2023 12:16:02 -0700 Message-ID: <20230411191636.26926-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|MW6PR12MB8734:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ccc9639-ecdb-4de5-16fc-08db3ac152be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1nZdWlJL/siybVTnbTI1lAmr6TWeqSDLIc0m/tAf95v6A7UuW3OoeXSDRffUjaQ+5Y85O6S+9kI0qym75WjJBPFA7AizyTun88WjRujaWDHA08ihv7jXoXXTPfhDLoBmI1EgY09qrTQh7zlyBDJsJ2mnCieg7+TsGy668oLevSG4Hy2X76p+WPkuFVS0dJKrgQI3EGrduQCHwm160dyE/AUQmh60Ov4ohYORM3d6at/H+cokq0m+Lut5JFcFaeCMFqhv76PNthhld8VWHra1d3Wm9/WPWNdhH9HJklCuH7vg/nN6dzeua6f8bxzkardLfOQkV4xdccn9O7fop9mjDuIcnpKxZHls2hluVbFRGyv0c6xkcdni+fp5RlOq+mZzOS1YS5CfHNdfJHm63D1qY+qNCPo9OC3w+NI3qV+0ZRTPmF06wtM0tgBwmb3RN1D+jSL9QTlkGKZdgnSzntFKK0thEzDeObN3TdVFALa/KUNOdgEI2Ztmvhm1BGjBE93tWwGQk2Dy9C65WddhIJiWDP3SDLeQqrdt16CQQsvfp1flbBKBDKvx27Cs79UCsdWff/SMB7cUTwE6HvubGxEoi07+jeM8O+omQnrsvEzn6RuYUXjJOOIR4XvRy4wWhVMGGEM1r4O+H3y1MkVStWMMpexk67WObCUn+G3Zv84x+DcDNYbYuISH1tZWs8pZ1cPhATNDJY4+mD6sj31xuWqyuPbN6UsLH5H0ZsDIQh294sE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(39860400002)(396003)(346002)(451199021)(40470700004)(36840700001)(46966006)(30864003)(8936002)(8676002)(41300700001)(47076005)(81166007)(2616005)(2906002)(5660300002)(44832011)(356005)(4326008)(83380400001)(70586007)(6916009)(336012)(36860700001)(40460700003)(426003)(70206006)(6666004)(478600001)(316002)(36756003)(86362001)(40480700001)(82310400005)(1076003)(54906003)(186003)(82740400003)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:16:59.2939 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ccc9639-ecdb-4de5-16fc-08db3ac152be X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8734 Remove __init from following function to access during runtime: 1. map_irq_to_domain() 2. handle_device_interrupt() 3. map_range_to_domain() 4. unflatten_dt_node() 5. unflatten_device_tree() Move map_irq_to_domain() prototype from domain_build.h to setup.h. To avoid the breaking the build, following changes are also done: 1. Move map_irq_to_domain(), handle_device_interrupt() and map_range_to_domain() to device.c. After removing __init type, these functions are not specific to domain building, so moving them out of domain_build.c to device.c. 2. Remove static type from handle_device_interrupt(). Overall, these changes are done to support the dynamic programming of a nodes where an overlay node will be added to fdt and unflattened node will be added to dt_host. Furthermore, IRQ and mmio mapping will be done for the added node. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- xen/arch/arm/device.c | 145 ++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 142 ----------------------- xen/arch/arm/include/asm/domain_build.h | 2 - xen/arch/arm/include/asm/setup.h | 6 + xen/common/device_tree.c | 16 +-- 5 files changed, 159 insertions(+), 152 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..fec6e29c42 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include extern const struct device_desc _sdevice[], _edevice[]; extern const struct acpi_device_desc _asdevice[], _aedevice[]; @@ -75,6 +78,148 @@ enum device_class device_get_class(const struct dt_device_node *dev) return DEVICE_UNKNOWN; } +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname) +{ + int res; + + res = irq_permit_access(d, irq); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n", + d->domain_id, irq); + return res; + } + + if ( need_mapping ) + { + /* + * Checking the return of vgic_reserve_virq is not + * necessary. It should not fail except when we try to map + * the IRQ twice. This can legitimately happen if the IRQ is shared + */ + vgic_reserve_virq(d, irq); + + res = route_irq_to_guest(d, irq, irq, devname); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map IRQ%"PRId32" to dom%d\n", + irq, d->domain_id); + return res; + } + } + + dt_dprintk(" - IRQ: %u\n", irq); + return 0; +} + +int 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; + int res; + + /* + * reserved-memory regions are RAM carved out for a special purpose. + * They are not MMIO and therefore a domain should not be able to + * manage them via the IOMEM interface. + */ + if ( strncasecmp(dt_node_full_name(dev), "/reserved-memory/", + strlen("/reserved-memory/")) != 0 ) + { + res = iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); + return res; + } + } + + if ( !mr_data->skip_mapping ) + { + res = map_regions_p2mt(d, + gaddr_to_gfn(addr), + PFN_UP(len), + maddr_to_mfn(addr), + mr_data->p2mt); + + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map 0x%"PRIx64 + " - 0x%"PRIx64" in domain %d\n", + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, + d->domain_id); + return res; + } + } + + dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", + addr, addr + len, mr_data->p2mt); + + return 0; +} + +/* + * handle_device_interrupts retrieves the interrupts configuration from + * a device tree node and maps those interrupts to the target domain. + * + * Returns: + * < 0 error + * 0 success + */ +int handle_device_interrupts(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) +{ + unsigned int i, nirq; + int res; + struct dt_raw_irq rirq; + + nirq = dt_number_of_irq(dev); + + /* Give permission and map IRQs */ + for ( i = 0; i < nirq; i++ ) + { + res = dt_device_get_raw_irq(dev, i, &rirq); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + /* + * Don't map IRQ that have no physical meaning + * ie: IRQ whose controller is not the GIC + */ + if ( rirq.controller != dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", + i, dt_node_full_name(rirq.controller)); + continue; + } + + res = platform_get_irq(dev, i); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to get irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + if ( res ) + return res; + } + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 4f9d4f9d88..6ab18c53ab 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2256,41 +2256,6 @@ int __init make_chosen_node(const struct kernel_info *kinfo) return res; } -int __init map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname) -{ - int res; - - res = irq_permit_access(d, irq); - if ( res ) - { - printk(XENLOG_ERR "Unable to permit to dom%u access to IRQ %u\n", - d->domain_id, irq); - return res; - } - - if ( need_mapping ) - { - /* - * Checking the return of vgic_reserve_virq is not - * necessary. It should not fail except when we try to map - * the IRQ twice. This can legitimately happen if the IRQ is shared - */ - vgic_reserve_virq(d, irq); - - res = route_irq_to_guest(d, irq, irq, devname); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to map IRQ%"PRId32" to dom%d\n", - irq, d->domain_id); - return res; - } - } - - dt_dprintk(" - IRQ: %u\n", irq); - return 0; -} - static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, const struct dt_irq *dt_irq, void *data) @@ -2322,57 +2287,6 @@ static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, return 0; } -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; - int res; - - /* - * reserved-memory regions are RAM carved out for a special purpose. - * They are not MMIO and therefore a domain should not be able to - * manage them via the IOMEM interface. - */ - if ( strncasecmp(dt_node_full_name(dev), "/reserved-memory/", - strlen("/reserved-memory/")) != 0 ) - { - res = iomem_permit_access(d, paddr_to_pfn(addr), - paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); - if ( res ) - { - printk(XENLOG_ERR "Unable to permit to dom%d access to" - " 0x%"PRIx64" - 0x%"PRIx64"\n", - d->domain_id, - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); - return res; - } - } - - if ( !mr_data->skip_mapping ) - { - res = map_regions_p2mt(d, - gaddr_to_gfn(addr), - PFN_UP(len), - maddr_to_mfn(addr), - mr_data->p2mt); - - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to map 0x%"PRIx64 - " - 0x%"PRIx64" in domain %d\n", - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, - d->domain_id); - return res; - } - } - - dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", - addr, addr + len, mr_data->p2mt); - - return 0; -} - /* * For a node which describes a discoverable bus (such as a PCI bus) * then we may need to perform additional mappings in order to make @@ -2400,62 +2314,6 @@ static int __init map_device_children(const struct dt_device_node *dev, return 0; } -/* - * handle_device_interrupts retrieves the interrupts configuration from - * a device tree node and maps those interrupts to the target domain. - * - * Returns: - * < 0 error - * 0 success - */ -static int __init handle_device_interrupts(struct domain *d, - struct dt_device_node *dev, - bool need_mapping) -{ - unsigned int i, nirq; - int res; - struct dt_raw_irq rirq; - - nirq = dt_number_of_irq(dev); - - /* Give permission and map IRQs */ - for ( i = 0; i < nirq; i++ ) - { - res = dt_device_get_raw_irq(dev, i, &rirq); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - /* - * Don't map IRQ that have no physical meaning - * ie: IRQ whose controller is not the GIC - */ - if ( rirq.controller != dt_interrupt_controller ) - { - dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", - i, dt_node_full_name(rirq.controller)); - continue; - } - - res = platform_get_irq(dev, i); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to get irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); - if ( res ) - return res; - } - - return 0; -} - /* * For a given device node: * - Give permission to the guest to manage IRQ and MMIO range diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include/asm/domain_build.h index 34ceddc995..b9329c9ee0 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -4,8 +4,6 @@ #include #include -int map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname); int make_chosen_node(const struct kernel_info *kinfo); void evtchn_allocate(struct domain *d); diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index a926f30a2b..1d636e8a4a 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -163,9 +163,15 @@ 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 handle_device_interrupts(struct domain *d, struct dt_device_node *dev, + bool need_mapping); + int map_range_to_domain(const struct dt_device_node *dev, u64 addr, u64 len, void *data); +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname); + extern const char __ro_after_init_start[], __ro_after_init_end[]; struct init_info diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 6c9712ab7b..aed38ff63c 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1811,12 +1811,12 @@ int dt_count_phandle_with_args(const struct dt_device_node *np, * @allnextpp: pointer to ->allnext from last allocated device_node * @fpsize: Size of the node path up at the current depth. */ -static unsigned long __init unflatten_dt_node(const void *fdt, - unsigned long mem, - unsigned long *p, - struct dt_device_node *dad, - struct dt_device_node ***allnextpp, - unsigned long fpsize) +static unsigned long unflatten_dt_node(const void *fdt, + unsigned long mem, + unsigned long *p, + struct dt_device_node *dad, + struct dt_device_node ***allnextpp, + unsigned long fpsize) { struct dt_device_node *np; struct dt_property *pp, **prev_pp = NULL; @@ -2056,8 +2056,8 @@ static unsigned long __init unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +static void __unflatten_device_tree(const void *fdt, + struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; From patchwork Tue Apr 11 19:16:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208097 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 571C7C77B72 for ; Tue, 11 Apr 2023 19:17:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519767.806720 (Exim 4.92) (envelope-from ) id 1pmJUF-0004U6-Lt; Tue, 11 Apr 2023 19:17:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519767.806720; Tue, 11 Apr 2023 19:17:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUF-0004Tx-Hx; Tue, 11 Apr 2023 19:17:03 +0000 Received: by outflank-mailman (input) for mailman id 519767; Tue, 11 Apr 2023 19:17:02 +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 1pmJUE-0004Ta-U4 for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:02 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20623.outbound.protection.outlook.com [2a01:111:f400:7e83::623]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6e0c351d-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:00 +0200 (CEST) Received: from BN9PR03CA0604.namprd03.prod.outlook.com (2603:10b6:408:106::9) by MW4PR12MB5601.namprd12.prod.outlook.com (2603:10b6:303:168::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:16:56 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:408:106:cafe::3) by BN9PR03CA0604.outlook.office365.com (2603:10b6:408:106::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.40 via Frontend Transport; Tue, 11 Apr 2023 19:16:56 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.29 via Frontend Transport; Tue, 11 Apr 2023 19:16:55 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:55 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:55 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:54 -0500 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: 6e0c351d-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R5odVlwbleoZs5wA2Fen6R9qmt+TiYhz/GpyppkIzbqswKQkuXyCbkxlQkjB8nSBOC20onufEscuNKm8vNm/j8yfswu3WLAnPgPOmNfR0T9GpLsMwbeW08oSzC1XnlUtEyHEDQlWFwA0VgmbcWHu+8ImpdPqQNNPYJVB9kGOgqahApezPnCwhGAVm6Fk/gJlRBBaxRQU2dbVZQlrSGqFNw5ze+hpUvgkOqmrl0qa67NkZZzimM2in0Ulk6CErHvk43d48O/zoqDAx/6h/d2jN/HJ5cMTC0cdC4wsTytksf5KinwvIQS5rOH9t2nsVXBKrTq1ZGqTcEvHCDNupHfXYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0odwSwlZEbTJvdLLf27PaAsLK4pjjIm+Jsb7s8Lqv7g=; b=fR7WKLv54LP01SNa8MUepB3sId6Q718wi+GEOAuTATUVrbm5NmItXz521gJfoVce67ZdtDj3uDs+G6apBoBxTE+lCnDL+cIRrkpbDo+X29siGtAjog02PguifLjPmmhd8qYgMAvhHaDsn8UsmECzWKFzzUOhiLt4WhPPrKmffXvzcNBvFlzv6jZzite09ifNwof4EuwxN2kq2I3KKwQJaK/2yK/LxpPm5tIOOFf7NE7Y3kRp1BxBnxe34Tr9Stx0nbskob0ru6CJZf1I/vEDbXoZTHIrcEC4b542tPSX1IKI1PJ3H4zpeOLcL8feazxofP/zOOuTgyJ/MLkR38YXNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0odwSwlZEbTJvdLLf27PaAsLK4pjjIm+Jsb7s8Lqv7g=; b=Md5NgPnF/dZc6LSjpF9zQvCHu3SnY1fZQYKEa4Ctv2VO6o6TW+wqH6xsxLNdN88/nIjeb8ZQwPcGMwej8/143x3pPhkp5fPtJvG1Ou/G/K/OCJj1pfKEpnGaKFb417l4ClhSo/MkCvoC3HbxphnPRiypyMP4AOyNZm/zoYvzbgI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" Subject: [XEN][PATCH v5 02/17] common/device_tree: change __unflatten_device_tree() Date: Tue, 11 Apr 2023 12:16:03 -0700 Message-ID: <20230411191636.26926-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT052:EE_|MW4PR12MB5601:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a55ab8b-09ca-432d-daf6-08db3ac15098 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tRF8rJuNDr5YAn1IKIgQmYgV4Xg3sb4+bNUMt0OUvk/7+9ZimF1PYMvu+V9AR319u1kO/w+2FZjcOha9YM1YSyz8nG5g9SE5swyVF/F+bEKokoJeyZlCGBUMjnmu0lJE4JbCc3xzHtHKY5Ms/JgGqNJAt5aPewk/of/WaAL4Lj20+TsmvONcyw99ZcJdonUU5JqIXalTOBeCU6LUDFk2QU1Asw0Vm304GjCHVxWrqTSHrYN0E/jLVwB3f/+YW/1sPJuZeQNFvstg22Jw0OXhnltLLL2MXutboZ3A2s/JUu4+O14c7+3ikq0T0o1Vkeysarod4OYoIVZJaexZXZcmgJ3HapzUw5MVMbTil7/FvNupjYSq4qin63K9Xg/L/zSZqk5ZbWdqZTUCGXxCmlsIme6PMcpMpTSb1rJ73dYjHhzrz0da2vQtGwplOitZCAQm608CDDedenQ66kEZ+Bp31uBouNN4Ysj1zBuMIbCjBzgWSF5zGisvcxfBdidoqHKji3INiI+kzIbrWYl1yUso8UkOxMe+3AwCpH1jx0nxOTOxLi2WV3jUmxGgFs1fCcABD+iXeskYnd9CSFppMreCQiqmZixCd0zBtyd4oMmPL992mXabbPY4c872k51Exb4Q5U+9QvpVvdNU8vuDKrQsP4jufjckzAgiCd21astDPcag/QPqJbpZI2BGHExZBL57fhM9FJWIEbmXcPSsn+fF9vs/Emc8/qMF2RqBHC2Wlhc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199021)(40470700004)(46966006)(36840700001)(36860700001)(54906003)(2616005)(47076005)(478600001)(26005)(1076003)(6666004)(81166007)(82740400003)(356005)(41300700001)(316002)(4326008)(6916009)(186003)(336012)(83380400001)(426003)(70206006)(70586007)(2906002)(5660300002)(44832011)(36756003)(82310400005)(40460700003)(86362001)(40480700001)(8676002)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:16:55.7882 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a55ab8b-09ca-432d-daf6-08db3ac15098 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5601 Following changes are done to __unflatten_device_tree(): 1. __unflatten_device_tree() is renamed to unflatten_device_tree(). 2. Remove static function type. 3. Add handling of memory allocation. This will be useful in dynamic node programming when we unflatten the dt during runtime memory allocation can fail. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- xen/common/device_tree.c | 10 ++++++---- xen/include/xen/device_tree.h | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index aed38ff63c..bf847b2584 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2047,7 +2047,7 @@ static unsigned long unflatten_dt_node(const void *fdt, } /** - * __unflatten_device_tree - create tree of device_nodes from flat blob + * unflatten_device_tree - create tree of device_nodes from flat blob * * unflattens a device-tree, creating the * tree of struct device_node. It also fills the "name" and "type" @@ -2056,8 +2056,7 @@ static unsigned long unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +void unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; @@ -2079,6 +2078,9 @@ static void __unflatten_device_tree(const void *fdt, /* Allocate memory for the expanded device tree */ mem = (unsigned long)_xmalloc (size + 4, __alignof__(struct dt_device_node)); + if ( !mem ) + panic("Cannot allocate memory for unflatten device tree\n"); + ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef); dt_dprintk(" unflattening %lx...\n", mem); @@ -2179,7 +2181,7 @@ dt_find_interrupt_controller(const struct dt_device_match *matches) void __init dt_unflatten_host_device_tree(void) { - __unflatten_device_tree(device_tree_flattened, &dt_host); + unflatten_device_tree(device_tree_flattened, &dt_host); dt_alias_scan(); } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 19a74909ce..58ac12abe3 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -178,6 +178,11 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/** + * unflatten any device tree. + */ +void unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes); + /** * IRQ translation callback * TODO: For the moment we assume that we only have ONE From patchwork Tue Apr 11 19:16:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208096 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 6743FC77B6F for ; Tue, 11 Apr 2023 19:17:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519771.806754 (Exim 4.92) (envelope-from ) id 1pmJUL-0005OG-0z; Tue, 11 Apr 2023 19:17:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519771.806754; Tue, 11 Apr 2023 19:17:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUK-0005MU-SE; Tue, 11 Apr 2023 19:17:08 +0000 Received: by outflank-mailman (input) for mailman id 519771; Tue, 11 Apr 2023 19:17:06 +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 1pmJUI-0004DR-7o for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:06 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062b.outbound.protection.outlook.com [2a01:111:f400:fe59::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 70c37f42-d89d-11ed-8611-37d641c3527e; Tue, 11 Apr 2023 21:17:04 +0200 (CEST) Received: from MW3PR05CA0004.namprd05.prod.outlook.com (2603:10b6:303:2b::9) by SJ2PR12MB7962.namprd12.prod.outlook.com (2603:10b6:a03:4c2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:01 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::87) by MW3PR05CA0004.outlook.office365.com (2603:10b6:303:2b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:01 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:01 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:56 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:56 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:55 -0500 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: 70c37f42-d89d-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UxpCf3u8aQhuKKrQ0T4SThXXP1/7rOEjefrnQSrBSTFBH+2vet0/BkN9/96BSOh7BRc29yBAuGPfWBrzsmO+z5fnIfCwZv+/W19BY/NV8YANilCikYT1V6SYpNidRCML6foQhvXzNpSPdoWeuYsSgXeXBoRcw30A9hLweGC05laY3bfZd0nKDfZygI2pHhb+DVTBGxMKHmbwxn5ZVbZ7WJk6S5aqZRc1vjlpRsq2ZVXjC8+8eeuht7v/iiIdbRQyVVxOlmpJIwUjwPmg0cum0s/L0CtRf+4gtmJkTKc71Q13em4p8IVwFzZY2HoSwbOnofwG8X+xRU252Zq5wh0tew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=y5jE5w9tUBXYNb4GkaW66AGdvE8156w4aHYPgYkE7PU=; b=J8chaI68GCgVd6yiVlsCc2D6W9f8W6rt3VGRxdijG5QkKl4XmOHnBv8yIOYI/Rgw6Klo5ZQhcfIdeK4P15dtOyfRXRvLNo/MftvzVHrbSeH/vaYcM9RFyEJ7NUhxXpfNqKRi+aR0qwKnJVPtlrB7QQh00GsQM9m0Rodu36ZTFZeAjjD47Mx2VrRjvv9dtW52pf3kcqkolch+iGosTYvrcT784CYrbxufSy0xOdAiTpXV1A0iS3ImLKKJp6281qCGzbhF9c9Xln6UIHd4NKB3CWweckTiIqaye45CAj0ZJkXf6BnGjxwtBMmifjilgQ5RjO+UazrA0bzcIwYk090FzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y5jE5w9tUBXYNb4GkaW66AGdvE8156w4aHYPgYkE7PU=; b=wxWB/BWXY2CO32y5vRS7236kub8VwKV+uQFpF+1OL7L0gNQP0NFpjSVE+5iJrM4LMKSlT0XcPeLcswieKsQ8nTGed5rjuOLbVuJXYhTiPU4/xfe0O9OCoYPR1oCufxMZ35hDCStB3gc6PZlfTqyQ9vA0Q0yoWaW96zC54AlnEGs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Andrew Cooper" , George Dunlap , Jan Beulich , Julien Grall , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v5 03/17] xen/arm: Add CONFIG_OVERLAY_DTB Date: Tue, 11 Apr 2023 12:16:04 -0700 Message-ID: <20230411191636.26926-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|SJ2PR12MB7962:EE_ X-MS-Office365-Filtering-Correlation-Id: 93a1cd42-a56c-4eb5-c800-08db3ac153f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XWH3oXWHqcZD9sTbyewkrsWBFCMU89fDJmR4pzMiPZW5pze/IlzoIeNqgMO+onWgXaj7kkAxDBoDLNVOcSQsC8idNUm+ugK7ePoigLJoBTkuI4LPtr6TpF1Hu96MhwTrlzVFaMa8sY/LwPPV4Jv9pxEySrnK4eUpkPnpbZIFmvfQwFd2u2XDDj5UI2KTlnkYAVF8I4WaxTvn1RsWJ01pNp1scH91N4EH6kjSdx9cp9nn4MhQKQyquijx0FvB96sd8lhRvXqKnGN4ej9l87xkd6gaBZFF2QDaWi/bx8h82ONNlZbn/6Bdf9FCl4EgW9/S3afztXOAIZr0zPtDkxpYUmdBxecv9dJ0AWU5e18XbD9auKVMJm/1NlaTK8CnG5SPzNnfl840lBkZdlL1otUt/ycx6XbjnQ8Pg18BFGRMa54ksmJgSg7RBkpYZ0ebggriUDOCaJTYHTG1iDX7k35EY/ACLzaqqPtlL8QkBkYeLj32xs5mlb5IuZUXzwgAMxGmvvp6TOPOE+EMrXpxYCmby1nAHtZ6i/vJHIVuc8xH9wvDpCtCcA1gw/nFOXZ0eiJaWGH/JmKExlvCImja4S1yoLikS/kf61uDhiWCluec1ISqzh7nToVQZBqAlEykzumK+3IM04rzaalN6zkN/upDRJ+JUwM+HvF/xC7nLvPig/jILnqLMs5OG7+4ucnYho7ogyInqZSxFbkoEr5V6l8vHITm7LFWVa+3ZtQdrpW0ie8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(36860700001)(70206006)(70586007)(8676002)(4326008)(6916009)(5660300002)(86362001)(186003)(426003)(336012)(40480700001)(41300700001)(6666004)(82310400005)(316002)(8936002)(478600001)(54906003)(2906002)(36756003)(40460700003)(26005)(44832011)(82740400003)(1076003)(2616005)(47076005)(356005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:01.3563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 93a1cd42-a56c-4eb5-c800-08db3ac153f8 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7962 Introduce a config option where the user can enable support for adding/removing device tree nodes using a device tree binary overlay. Signed-off-by: Vikram Garhwal --- SUPPORT.md | 6 ++++++ xen/arch/arm/Kconfig | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index aa1940e55f..0a31f40af4 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -822,6 +822,12 @@ No support for QEMU backends in a 16K or 64K domain. Status: Supported +### Device Tree Overlays + +Add/Remove device tree nodes using a device tree overlay binary(.dtbo). + + Status: Supported for ARM + ### ARM: Guest ACPI support Status: Supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 239d3aed3c..1fe3d698a5 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -53,6 +53,11 @@ config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC && !ARM_32 +config OVERLAY_DTB + bool "DTB overlay support (UNSUPPORTED)" if UNSUPPORTED + help + Dynamic addition/removal of Xen device tree nodes using a dtbo. + config HVM def_bool y From patchwork Tue Apr 11 19:16:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208099 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 F25FFC77B75 for ; Tue, 11 Apr 2023 19:17:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519768.806730 (Exim 4.92) (envelope-from ) id 1pmJUG-0004ji-Ui; Tue, 11 Apr 2023 19:17:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519768.806730; Tue, 11 Apr 2023 19:17: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 1pmJUG-0004jb-QV; Tue, 11 Apr 2023 19:17:04 +0000 Received: by outflank-mailman (input) for mailman id 519768; Tue, 11 Apr 2023 19:17:03 +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 1pmJUF-0004Ta-KC for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:03 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [2a01:111:f400:fe5a::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6f89fd80-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:02 +0200 (CEST) Received: from BN9PR03CA0077.namprd03.prod.outlook.com (2603:10b6:408:fc::22) by DM6PR12MB4282.namprd12.prod.outlook.com (2603:10b6:5:223::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.35; Tue, 11 Apr 2023 19:16:59 +0000 Received: from BN8NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::5b) by BN9PR03CA0077.outlook.office365.com (2603:10b6:408:fc::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:16:58 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT066.mail.protection.outlook.com (10.13.177.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:16:58 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:57 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:57 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:56 -0500 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: 6f89fd80-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dqfHvUQkKRI+G1Rz6oofnKIRzyCknyLcK0EUyws71WyuEo6e0kx4wVRS09qucjTXA9EqkU8e+z63bCu/YkL+kfC8GOSrj7rwUj/hevwvj9CRfVNBXfSRMd26MnOj3P8VppZyJsbOp7oN9ULsAUdBY38gE9097qaUlMR1paZy56dBemNS5UHDTkVZOl1r3tGL1yoFI1mzVv0ozo9bM9zVFJZ/DRtGpVz1Qx60rijmc4vA9vapQqD+RSk23+p1T2rJWJbUrSzG8xgrWNwYoabwKn3Zx7YQvsbVjj6T73nkM0AEDfvtaOEkS0oh/1/GuMZ4JZyfsyyma955nur+H1rWYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+aOH8wbfxJ3CDB9n8z4otIPVVDXaY3ZnHxlpPeTlbO8=; b=XVfer5z5EHUilHhV+QpewCTkSOCiPTyjg/flVMZDEAzRK7xS4U90MmLS2j6XCxJadMrTyfIFtqZgoV8tE5knDGCt9Oy0pJnHl/YgFH12ggxAV7MMV8Fr+WG99/NQCfuORKTWXweHXckRRu6Ghyd9EzVd+cdZhZgDEOTfJrOaND763U12ywlONjxb2o0xNbsw08P4nJPuYUvA34TqM5tdqXE4UKXbylbIoJu4mMYx3dg+VOB48TH9m8UNMBnMYOUnFMnaNJhPMSzo+GyHnp1zexnQxanpVOmx8/4ez4aN6AvQjfluvkCvSi4wU3+b/2iwK54aukTqwBjwLwEyLBAb8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+aOH8wbfxJ3CDB9n8z4otIPVVDXaY3ZnHxlpPeTlbO8=; b=rl/f+0LCUCpB609QADltQg+rTxdAOrQiu8YujzkFf1OQB3AAg5ivux1ExrlGxmgNX4gA13RYWWZLejjd2CoSI8Y6BCICQIu+vn/vyCh/BDlKvHSYiFlDmHWaQLT2ceA64UDpUA/XJ+8ZOo+WqDeTLlbQI3mUA4YsgiIRfgsyJ2A= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" Subject: [XEN][PATCH v5 04/17] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Tue, 11 Apr 2023 12:16:05 -0700 Message-ID: <20230411191636.26926-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT066:EE_|DM6PR12MB4282:EE_ X-MS-Office365-Filtering-Correlation-Id: a9c843cc-4c85-4c96-a8c6-08db3ac15246 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E5mZY9arVfIz4R/AVfjqkQGX6I4NgpAdkIvjkuVZqz5BKhyPZEDL6b5Xq8b3aZ8yk9JU+rCdeveWZbPStUFbHz4rOiSVlz3wiAZwUYR0jRVcmHdSCANP2OdgfJgacMgBX58liZjifMHUHzC/32dEBes0dT/X0sVh0V0ClZ/pmvVNF2vnoktMpqFl7WQQ6/bzuXUT8t6RLcCdF1n/3N0pUtC3AMR9H2HHoI73W91MU1zSRQ9p3o//hEvudGpbf1Q/O9EyfgJP5cn6D5Wa+pOcUC+a0wuMf94oRCG6cfHd5p9GA/HhF+Rw7SezASSeL6IA6UysRg+9vzAPtm0ZN/6sMk48bGE1upLmFIspEKzE5Xx6I6Oa3iUBQemvUG0GRGf4bdhWntvbrDNu30WquTcxt+EoHMzvNBdW59Z2Q54ECfZK69MyfO0N3SILS823JJrSKR2I444zyf/CPE3tEfFHX91CO9QOXC+5ALFlZGMr2X28jaiAhNzEM19Os8Ea7kh5ySxKv0vuydLq5lJtnjoAQwr5BCuUnxCWZO7KKKfDzxM4jLQXG2exYJ7Yc61JwrHEHD0D39MpQ1pWsM0R7MGeR2RyYy8cukIRVhn2m5REcOmNb6w6YBFsOkQbj9rXjK4kFARvTQo2T2N1Y9AaR02BFnvB9oY1v1UmFgnOGiR1+Qql+LFy4XNhSrlWdx9PgLB67O/ky0Ps9USxEUlIXO9dY9kMQK7XS1nWTKovgA0R31I= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(346002)(396003)(376002)(39860400002)(451199021)(46966006)(40470700004)(36840700001)(36756003)(54906003)(86362001)(41300700001)(83380400001)(316002)(70586007)(4326008)(478600001)(70206006)(6916009)(8676002)(82310400005)(5660300002)(40480700001)(8936002)(2906002)(4744005)(44832011)(36860700001)(356005)(186003)(82740400003)(81166007)(6666004)(26005)(1076003)(426003)(336012)(2616005)(47076005)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:16:58.6206 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a9c843cc-4c85-4c96-a8c6-08db3ac15246 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4282 This is done to access fdt library function which are required for adding device tree overlay nodes for dynamic programming of nodes. Signed-off-by: Vikram Garhwal Acked-by: Julien Grall --- xen/common/libfdt/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile index 75aaefa2e3..d50487aa6e 100644 --- a/xen/common/libfdt/Makefile +++ b/xen/common/libfdt/Makefile @@ -1,7 +1,11 @@ include $(src)/Makefile.libfdt SECTIONS := text data $(SPECIAL_DATA_SECTIONS) + +# For CONFIG_OVERLAY_DTB, libfdt functionalities will be needed during runtime. +ifneq ($(CONFIG_OVERLAY_DTB),y) OBJCOPYFLAGS := $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) +endif obj-y += libfdt.o nocov-y += libfdt.o From patchwork Tue Apr 11 19:16:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208095 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 DC6DCC7619A for ; Tue, 11 Apr 2023 19:17:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519769.806740 (Exim 4.92) (envelope-from ) id 1pmJUI-0004zv-8U; Tue, 11 Apr 2023 19:17:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519769.806740; Tue, 11 Apr 2023 19:17:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUI-0004zo-5D; Tue, 11 Apr 2023 19:17:06 +0000 Received: by outflank-mailman (input) for mailman id 519769; Tue, 11 Apr 2023 19:17:04 +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 1pmJUG-0004Ta-DQ for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:04 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062a.outbound.protection.outlook.com [2a01:111:f400:fe5b::62a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6f9ec66c-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:02 +0200 (CEST) Received: from BN9PR03CA0074.namprd03.prod.outlook.com (2603:10b6:408:fc::19) by DS0PR12MB7927.namprd12.prod.outlook.com (2603:10b6:8:147::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31; Tue, 11 Apr 2023 19:16:59 +0000 Received: from BN8NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::4b) by BN9PR03CA0074.outlook.office365.com (2603:10b6:408:fc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:16:59 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT066.mail.protection.outlook.com (10.13.177.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:16:59 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:58 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:57 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:57 -0500 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: 6f9ec66c-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hsnvahqefEJcrGbq8TaKoxKIRcJ8k6g3h4CnC8ViW6gsJNOkIj7iYXQL9Ii413JsBQybdidGJ6LrYp4fbkQfkCB+uk9G8JtQNGWQEg7I2zZVvPT0EekScDapJsrHJ2zroYwVXqobef3b6SibjN1W95m4XVNV8awgAgRxS+ctdQe76N96+hxiTZeE6koUtR3VImFtKbEN7dLGN9hrSzfE8pxKNgYKtUkx5df4BxHctIT+EYRqjZiKki1Ixz3dScKqCfPRWYYBMY/C9zXeYJx1kov8c46c5urOiOJlWKEhQzyGMoDaeydbYpyedbXcu8qGhtYFZ2jrveqP13TX74XUSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aXlXQRcv7U/T/rRXFeXTNVQL0ZVDEHTt5u8gFMIkdTA=; b=L19PP9YIoz2ENayQ10udRQtImwhc0jGVL9fhd/yJy3oG4NYnKeU5Uo7S9PfQ9S8C1q+F4AwS7Y77NS815xEiRFBaNIOjsCyiACllRlkf8xpQYjufEogNI1/VWI9eg7Am75r3yQL14wxPA0vDfIwf8/6m9kPfVD1Vqw1QEzg7RC+e1UwfTZBxCjLz0wKU3mIcfVUrw0bJmuGMsNCCKlVGcwz2mvlqPpWHMLSxVYXyT6DuugcjRPXS2YanxJLXxvxMB+b8bGYlUNFrk6RRU3hRJjZHjJkQnbf1S2sz5s3uYyet8zguNevVPntPXjgvfXEy9umt/iGpNr6PZusNGspcJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aXlXQRcv7U/T/rRXFeXTNVQL0ZVDEHTt5u8gFMIkdTA=; b=WEz5Ij5Kp8boEyjMUb91XSI7OHDNJpWmshSsP8z3y16orb5bMbZYN4Ifo6hwDNVLqS9pcLJn7M7tz6Hpl6WM6nVl3T2uL2+3WmAzWkPtgLlRVYNE7KBVjbwOq/kRR34spEH0g+H7ltXDphzhcRAXoKFJL30lTxKV8Cm8wEzuk5w= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" , Vikram Garhwal , David Gibson Subject: [XEN][PATCH v5 05/17] libfdt: overlay: change overlay_get_target() Date: Tue, 11 Apr 2023 12:16:06 -0700 Message-ID: <20230411191636.26926-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT066:EE_|DS0PR12MB7927:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f074106-fed4-47f9-7c35-08db3ac1529c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oC7YWE9imiHPDPvyBdq1PTLkB0ISDaGkF+VlhetZPVZnrzr6qM7i8dNDmV+QzgsOCOuzwqrGgKNhT6Gc22W0h6Jl/VO52RYpH5NKqj6nuXeOvhDgl5n1sZfailtvZQ88ra2YqPqoWwMRZ/ranbQZks7SlxvR9ZlSLAbrSFWtdAI34AOBnT71936i+XeHyBYcVEF/jOWTxjkh/+G45mkAZLAGk32lNWO7+a0YoA55yRJDH5xXnogPn3Oqx1XIFtciV347wsEzKAHR/q5xdxufvwgEuBDl0xOC5mxRQ+FOxXjsenAxKvYFPe5qgzV08T1nisxhvhRijfLnun7V25nvhtfCXFCf+A2UTc1DtYM6oe2k0vbMOqhnAYKnwVMNkHszSH897j6urVNiCCXBv+SeywRIahq1UOkE9rHubtMSbGU7Bgh3uczPNvtnDxuc9yjluZZ/3UFlw9ymuEWobZgLUULm812dpGF2tKKTCu7rUz6qRg0clEn/C4NfeKoeGw2eQnPQRcGNOBdoc38sFsycpXmByMev6cjJxEVKXcaLXzH48i3nRDdI57qPVYuvkt3zWy/ri3F6DbdkhSXIIX6EWE+EbF4BziXbNg/ovhq0lb891h54Gpe7MePtoE+87lj72BOYskDuhcpNVoO/NCN7u9vRlpXEi/C5sECMSM31b4uyhfDxhXHIaU8+69B/HAcsq73Pb+ALVezM4Jeq7j1OBL8v9Evy9xODkhsWbiLMfmw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(376002)(346002)(136003)(451199021)(46966006)(40470700004)(36840700001)(47076005)(82740400003)(36860700001)(40480700001)(2616005)(426003)(316002)(966005)(26005)(478600001)(6666004)(186003)(1076003)(54906003)(83380400001)(2906002)(336012)(81166007)(8676002)(5660300002)(4326008)(36756003)(356005)(40460700003)(44832011)(6916009)(41300700001)(70586007)(8936002)(82310400005)(70206006)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:16:59.1674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f074106-fed4-47f9-7c35-08db3ac1529c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7927 Rename overlay_get_target() to fdt_overlay_target_offset() and remove static function type. This is done to get the target path for the overlay nodes which is very useful in many cases. For example, Xen hypervisor needs it when applying overlays because Xen needs to do further processing of the overlay nodes, e.g. mapping of resources(IRQs and IOMMUs) to other VMs, creation of SMMU pagetables, etc. Signed-off-by: Vikram Garhwal Message-Id: <1637204036-382159-2-git-send-email-fnu.vikram@xilinx.com> Signed-off-by: David Gibson Origin: https://github.com/dgibson/dtc 45f3d1a095dd Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- xen/common/libfdt/fdt_overlay.c | 29 +++++++---------------------- xen/common/libfdt/version.lds | 1 + xen/include/xen/libfdt/libfdt.h | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c index 7b95e2b639..acf0c4c2a6 100644 --- a/xen/common/libfdt/fdt_overlay.c +++ b/xen/common/libfdt/fdt_overlay.c @@ -41,37 +41,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) return fdt32_to_cpu(*val); } -/** - * overlay_get_target - retrieves the offset of a fragment's target - * @fdt: Base device tree blob - * @fdto: Device tree overlay blob - * @fragment: node offset of the fragment in the overlay - * @pathp: pointer which receives the path of the target (or NULL) - * - * overlay_get_target() retrieves the target offset in the base - * device tree of a fragment, no matter how the actual targeting is - * done (through a phandle or a path) - * - * returns: - * the targeted node offset in the base device tree - * Negative error code on error - */ -static int overlay_get_target(const void *fdt, const void *fdto, - int fragment, char const **pathp) +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp) { uint32_t phandle; const char *path = NULL; int path_len = 0, ret; /* Try first to do a phandle based lookup */ - phandle = overlay_get_target_phandle(fdto, fragment); + phandle = overlay_get_target_phandle(fdto, fragment_offset); if (phandle == (uint32_t)-1) return -FDT_ERR_BADPHANDLE; /* no phandle, try path */ if (!phandle) { /* And then a path based lookup */ - path = fdt_getprop(fdto, fragment, "target-path", &path_len); + path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len); if (path) ret = fdt_path_offset(fdt, path); else @@ -638,7 +623,7 @@ static int overlay_merge(void *fdt, void *fdto) if (overlay < 0) return overlay; - target = overlay_get_target(fdt, fdto, fragment, NULL); + target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); if (target < 0) return target; @@ -781,7 +766,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) return -FDT_ERR_BADOVERLAY; /* get the target of the fragment */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; @@ -803,7 +788,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) if (!target_path) { /* again in case setprop_placeholder changed it */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; diff --git a/xen/common/libfdt/version.lds b/xen/common/libfdt/version.lds index 7ab85f1d9d..cbce5d4a8b 100644 --- a/xen/common/libfdt/version.lds +++ b/xen/common/libfdt/version.lds @@ -77,6 +77,7 @@ LIBFDT_1.2 { fdt_appendprop_addrrange; fdt_setprop_inplace_namelen_partial; fdt_create_with_flags; + fdt_overlay_target_offset; local: *; }; diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h index c71689e2be..fabddbee8c 100644 --- a/xen/include/xen/libfdt/libfdt.h +++ b/xen/include/xen/libfdt/libfdt.h @@ -2109,6 +2109,24 @@ int fdt_del_node(void *fdt, int nodeoffset); */ int fdt_overlay_apply(void *fdt, void *fdto); +/** + * fdt_overlay_target_offset - retrieves the offset of a fragment's target + * @fdt: Base device tree blob + * @fdto: Device tree overlay blob + * @fragment_offset: node offset of the fragment in the overlay + * @pathp: pointer which receives the path of the target (or NULL) + * + * fdt_overlay_target_offset() retrieves the target offset in the base + * device tree of a fragment, no matter how the actual targeting is + * done (through a phandle or a path) + * + * returns: + * the targeted node offset in the base device tree + * Negative error code on error + */ +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ From patchwork Tue Apr 11 19:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208094 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 438B9C76196 for ; Tue, 11 Apr 2023 19:17:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519772.806761 (Exim 4.92) (envelope-from ) id 1pmJUL-0005Uc-Hg; Tue, 11 Apr 2023 19:17:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519772.806761; Tue, 11 Apr 2023 19:17:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUL-0005Si-A6; Tue, 11 Apr 2023 19:17:09 +0000 Received: by outflank-mailman (input) for mailman id 519772; Tue, 11 Apr 2023 19:17:07 +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 1pmJUJ-0004Ta-L8 for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:07 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20613.outbound.protection.outlook.com [2a01:111:f400:7eab::613]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7205330f-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:06 +0200 (CEST) Received: from MW3PR05CA0006.namprd05.prod.outlook.com (2603:10b6:303:2b::11) by DM4PR12MB5357.namprd12.prod.outlook.com (2603:10b6:5:39b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:03 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::94) by MW3PR05CA0006.outlook.office365.com (2603:10b6:303:2b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:02 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:02 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:58 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:58 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:58 -0500 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: 7205330f-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WSIe8IWtkogZDuJROEuyEa4L5qtz0r0ub7oLaSfO1oYNN6uZkXy/AYkEa3PeoOYonr9wYRQt+vHxHp+g/sYWlxHPL5FypP2L333pRjkvdOHBFru51nKqqPmtHjUq8o8GrG5y8yDBLzH8tnluod1ewfCDKM4wcoGOPGGStdCZjVWAwUNmZr5A9t2PuUIYrZjRaoSZUWNZTqyMP+OYSaGEH1hCgOgsJ3vJs2EyLcRAlUvGXsMRB0pozooPmglFCVbN34KWvZrvQUmwLSVu0nZ1ELhtlGW0nNHvKq6OCci9womzrMTovnYOKR2qZWd8RrqKtlTmvon+x8XhFJpGe+Fl9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IPRvr0PydrbevxDRuC5bBe8hAAj8BLWppbzz+G6AD20=; b=Q6QuNO/MJsxQ0Mfgmqv9Fc2TTQvDV0zliZG80oSqKGwzzpfT9J7UZ2FuPaiYfXU/qiOYHT7fHQP1t/QBxkf012+VIOerMfB3Dt6nDxwpI6myg11MXW+FBGeex1p/gIZzfUq33QTMvrNskEHqisXKNHnCX7jcmrseAw5RwEvaEafIOJ2EThr5w/RXlVXFLxiGBqOtb8NJBRHVXwuxBkFFg/2byl1vVO1ABs4TYzz0/3GqkGZZEFmVOoH2X8bA4bhzAOBAwZicx47pyOkjCng0OPhHTyoKK5D2zLgqyQj2e2lwqaorRkw+Gg9QI3UT3rfGtJroT25tHoWNkBIhp7696Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IPRvr0PydrbevxDRuC5bBe8hAAj8BLWppbzz+G6AD20=; b=KDu9AlO4fQb4RnMxIBoAkLNp+pI1dLaayOR4hzEGfRdnkwnBMysAjR/rLTC3LnlSxfeTfOoBcgV7J2cmTTfYIMihNqqMdDt0ekAxFiY2Rvo00w9cwKWP85ONIYg9S2Q4lQM+yFt67X9yvcEUyhncpYclWgTkKAv6Gp/j6YjnUoc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" Subject: [XEN][PATCH v5 06/17] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Date: Tue, 11 Apr 2023 12:16:07 -0700 Message-ID: <20230411191636.26926-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|DM4PR12MB5357:EE_ X-MS-Office365-Filtering-Correlation-Id: 92748e6e-4e36-4f2d-f5b0-08db3ac154cc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: POXz1WG1hmvtmv5RRF+iVjz+L8Z++hE0T36YgoND+tvNfXU/Rd6SPUicT57Mcps7aDrp6/TmvJJRrlH6FadTG1hn4VFTdykLIM4JnRdvcd1mf/i1lRmcPBSrHMP+Im8G8qLaN7BXyrxnrrH/yOOwAzOpRDrG8IOa12/TZkyjJadsajlTtO4WDHpR8O+nVF+NkYSTWfDzv7AqcPsvh9r3KCDIzHfBFurWQ6Kz3waGiXRtZtGZ8BDRDJ+Ehde4oNdx/Jhh5iuIEPauPu6juAmCzj6Jw07AJ4Bo6qvTPRfHt7AM6yIxi7U6+vVNDzyVZGYtuxhRP/MyQKl5wdkGY3Y/U/dGmoxFNMyNVRvKaL69tpU+m9J7iGTxkbbs+O/EIboBocgQrs2YE6q3MMpNR0pAw3av7s45/S2QnBRJgvfcYOxuvoT31hUUewjypoQ2OI+Ce+RbA6xziFmiOaE0XOWv5buUBnwRohqZZkALRJRtuUKYsDDDKs539xqAA86hV2ihzXiQzSAkL7GWAaMm5RBxEH96prsa3Ha9XE4D67wF6GK6vkDkzuLGzurXbz4rw7Q2wMTZdaihTT04kxLSPbswtunugHmQQB/eKBcU1LZr2dwByFx+JEfIIXiRF3SOmnEwaDeqK6nwrGqe0tmJoYnQ+rsI+rCoLcosJVnzaOchF7EnmLYwRMMP9ENiQhoAfopd2dzm2C63Ud1EGkJKAnjkzZXwSKT5coSqN2lJ962XuiXWU7p/NRVEOg94z+CrKbPrKEUI1p+5Ot9Zk6tZkaCHLg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(39860400002)(396003)(346002)(136003)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(4326008)(478600001)(6916009)(54906003)(8676002)(70206006)(41300700001)(70586007)(316002)(86362001)(36756003)(83380400001)(426003)(2616005)(336012)(26005)(1076003)(6666004)(2906002)(8936002)(44832011)(40480700001)(5660300002)(82310400005)(36860700001)(82740400003)(356005)(186003)(81166007)(47076005)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:02.7468 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92748e6e-4e36-4f2d-f5b0-08db3ac154cc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5357 Add device_tree_find_node_by_path() to find a matching node with path for a dt_device_node. Reason behind this function: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, we need to find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. Thus we need this function to search for node in different unflattened device trees. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 5 +++-- xen/include/xen/device_tree.h | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index bf847b2584..507b4ac5b6 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -358,11 +358,12 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, return np; } -struct dt_device_node *dt_find_node_by_path(const char *path) +struct dt_device_node *device_tree_find_node_by_path(struct dt_device_node *dt, + const char *path) { struct dt_device_node *np; - dt_for_each_device_node(dt_host, np) + dt_for_each_device_node(dt, np) if ( np->full_name && (dt_node_cmp(np->full_name, path) == 0) ) break; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 58ac12abe3..998f972ebc 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -534,13 +534,26 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, struct dt_device_node *dt_find_node_by_alias(const char *alias); /** - * dt_find_node_by_path - Find a node matching a full DT path + * device_tree_find_node_by_path - Generic function to find a node matching the + * full DT path for any given unflatten device tree + * @dt_node: The device tree to search * @path: The full path to match * * Returns a node pointer. */ -struct dt_device_node *dt_find_node_by_path(const char *path); +struct dt_device_node *device_tree_find_node_by_path(struct dt_device_node *dt, + const char *path); +/** + * dt_find_node_by_path - Find a node matching a full DT path in dt_host + * @path: The full path to match + * + * Returns a node pointer. + */ +static inline struct dt_device_node *dt_find_node_by_path(const char *path) +{ + return device_tree_find_node_by_path(dt_host, path); +} /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the From patchwork Tue Apr 11 19:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208102 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 883F6C7619A for ; Tue, 11 Apr 2023 19:17:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519774.806777 (Exim 4.92) (envelope-from ) id 1pmJUN-0005rE-2i; Tue, 11 Apr 2023 19:17:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519774.806777; Tue, 11 Apr 2023 19:17:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUM-0005nZ-Kb; Tue, 11 Apr 2023 19:17:10 +0000 Received: by outflank-mailman (input) for mailman id 519774; Tue, 11 Apr 2023 19:17:09 +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 1pmJUL-0004DR-4f for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:09 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20600.outbound.protection.outlook.com [2a01:111:f400:7e89::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 727aca3a-d89d-11ed-8611-37d641c3527e; Tue, 11 Apr 2023 21:17:07 +0200 (CEST) Received: from MW3PR05CA0015.namprd05.prod.outlook.com (2603:10b6:303:2b::20) by SA3PR12MB7975.namprd12.prod.outlook.com (2603:10b6:806:320::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.35; Tue, 11 Apr 2023 19:17:03 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::98) by MW3PR05CA0015.outlook.office365.com (2603:10b6:303:2b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.27 via Frontend Transport; Tue, 11 Apr 2023 19:17:03 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:03 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:16:59 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:16:59 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:16:59 -0500 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: 727aca3a-d89d-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DDZel6WEBGb2aTYAnYAotrmzVbZ3s3kcfUhLpszVA23+8sB6m7eS38UT9bYqoRo6RP23ED4kQur/HOYEtasxuVNCH2OINnUCwHgjJBrrPz/EQEzneYHUaMhiwE6tSOH7ZTDIbyopUVlTXoj1irUeAIHzr0qJa79iKrprkvfH0bGG478A723b3fPn0GdS2JgFHW8dj8i9FwM19w51JAtejG+N24Sw9LsGNC5yJy9IV8OiftA4AyouNKMQhf9HDP23SNhsv7wJqyAC+07IxAtkNBrK0996Ut17FGuOYWMYtSLrVwrJbwiG7C3759csDuFlp7vdsfzDkoqFHwGNTVXo8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SvjprfsFjT2q+G0BBsMISOBPht18qx5Ov6rcUISgUjE=; b=dw5LUMyKeF5kkahMH7yGjNK1hZL2dfKx4esYNnvJI8FmdkkhcX8LaD/tLlW+JYtNFKxonu4qD8NlSbJO9k7b6LEo5QMSpEznWwTFYdC8p/kK9JkcBBv0FPlcWd7M6PN6EdR1nuGk6dCABARmo33RFDXAM4OYiTXk16JNTyg6My8aoS8Im3Yae7e+z3VwdLecvoxpgiMWhUtLotEM8m3Nz7NxyCcrc031cS8qmdxC2SNOr6fGWaEv/VleGwn6A8tOwATNZKIvLo++UhVR8W5Az4qEAa+jS8kt6vu1yl8bi0nblYOPf1hMg3ZR2UXNdVip2ZhsluYEnJZb05efiLzOoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SvjprfsFjT2q+G0BBsMISOBPht18qx5Ov6rcUISgUjE=; b=37Bcs5BNxuIQA4OVW40raq+uSYlN3KhcoUpYSnVGbWlCEJDzDZYDouCqG/QsSbIcef6GSJ6TPWTkiNkRQPAYIrAAWmRrEtsOY9jdJolx4wj10djxsKpGqzim6xKu8aUSgLSfZDP8Av4z2wQDegFm51ZAjcZrZE1XNNQewGfi+1k= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" , Rahul Singh , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v5 07/17] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Tue, 11 Apr 2023 12:16:08 -0700 Message-ID: <20230411191636.26926-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|SA3PR12MB7975:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f9a7f2f-a193-4b53-18b5-08db3ac15512 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DR+ixQxTfr4F1T81YK50UlMuZ859lngTVfX60KdhxnLbhinqY03bYxNAzFU/gcCZ5s6LA5Js9UQZcEl8RamVvLuIvh1Fuy6KKfhr4tsA2xxQrmnR08hnkxfJeGCQaSmDAXvL3eHxqgo1TiQqGaAV1Sf5feOZjPeIM9s0AHubsl1BRLMcTCi538v0w3WLCKKKH21Y9zPDunYZVpx/bkVQpu1bGxi01n8wb+H0DH84qci3sRFtGa7o/ertOi3A2igLGal3mDlIQGedktPkaa1iNb5KYb1iJYEH2FS7UkPknbiL2NV7vp6RMK4PA4czQjI3EgMKg+wM/nW42TYgAs7vbPx+ksJRTeFi2pxLPB7G74Y2ww+IfL8ViFTev06tC9+FGtaP8B+U/BujH+Lm8s6qUEJw6BFL/g6C3onBWcrDDLoObosYP1b7FqPX4DAxQA8jvl6pr94dAw3HavaHiH0nyxwAqpzt+mTUcyd7WUiu/roG43XjG0fPZilSbqr0EWEHdSvhx6L0+Sb+XDj1m6/5KzFkhYF5L/+q1dWSihWClC+4bTJaWvm1S48337U87hTkHZAn5ub1bE7WfIwFS+upjkIZkXWVPEryBw3ftrJKGuP93tx0y7xIebcj1aAyv87qSH5xcEcnMhr/r8Bz9ZTst5YYo21V6teKVAT1TEXOyPgmSE8SV3p1G79jpyQ+GLNHHubHTSA48X6q1d6MJ96hXiLDCfQWy3iPMYV9fhgAoLA= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(376002)(39860400002)(346002)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(70586007)(70206006)(4326008)(478600001)(6916009)(8676002)(41300700001)(316002)(36756003)(54906003)(86362001)(47076005)(426003)(336012)(2616005)(26005)(1076003)(6666004)(8936002)(44832011)(5660300002)(40480700001)(82310400005)(81166007)(2906002)(82740400003)(186003)(36860700001)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:03.1999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f9a7f2f-a193-4b53-18b5-08db3ac15512 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7975 Add remove_device callback for removing the device entry from smmu-master using following steps: 1. Find if SMMU master exists for the device node. 2. Remove the SMMU master Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel --- xen/drivers/passthrough/arm/smmu.c | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index 0a514821b3..14e15f1bc6 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -816,6 +816,19 @@ static int insert_smmu_master(struct arm_smmu_device *smmu, return 0; } +static int remove_smmu_master(struct arm_smmu_device *smmu, + struct arm_smmu_master *master) +{ + if (!smmu->masters.rb_node) { + ASSERT_UNREACHABLE(); + return -ENOENT; + } + + rb_erase(&master->node, &smmu->masters); + + return 0; +} + static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, struct device *dev, struct iommu_fwspec *fwspec) @@ -853,6 +866,32 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, return insert_smmu_master(smmu, master); } +static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu, + struct device *dev) +{ + struct arm_smmu_master *master; + struct device_node *dev_node = dev_get_dev_node(dev); + int ret; + + master = find_smmu_master(smmu, dev_node); + if (master == NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret = remove_smmu_master(smmu, master); + + if (ret) + return ret; + + dev_node->is_protected = false; + + kfree(master); + return 0; +} + static int register_smmu_master(struct arm_smmu_device *smmu, struct device *dev, struct of_phandle_args *masterspec) @@ -876,6 +915,22 @@ static int register_smmu_master(struct arm_smmu_device *smmu, fwspec); } +static int arm_smmu_dt_remove_device_generic(u8 devfn, struct device *dev) +{ + struct arm_smmu_device *smmu; + struct iommu_fwspec *fwspec; + + fwspec = dev_iommu_fwspec_get(dev); + if (fwspec == NULL) + return -ENXIO; + + smmu = find_smmu(fwspec->iommu_dev); + if (smmu == NULL) + return -ENXIO; + + return arm_smmu_dt_remove_device_legacy(smmu, dev); +} + static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev) { struct arm_smmu_device *smmu; @@ -2858,6 +2913,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arch_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, + .remove_device = arm_smmu_dt_remove_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .assign_device = arm_smmu_assign_dev, From patchwork Tue Apr 11 19:16:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208105 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 64F8EC77B6F for ; Tue, 11 Apr 2023 19:17:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519777.806801 (Exim 4.92) (envelope-from ) id 1pmJUP-0006Pl-CE; Tue, 11 Apr 2023 19:17:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519777.806801; Tue, 11 Apr 2023 19:17:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUO-0006LA-OY; Tue, 11 Apr 2023 19:17:12 +0000 Received: by outflank-mailman (input) for mailman id 519777; Tue, 11 Apr 2023 19:17:10 +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 1pmJUM-0004DR-4r for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:10 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20600.outbound.protection.outlook.com [2a01:111:f400:fe59::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7309f7e2-d89d-11ed-8611-37d641c3527e; Tue, 11 Apr 2023 21:17:08 +0200 (CEST) Received: from BN9PR03CA0125.namprd03.prod.outlook.com (2603:10b6:408:fe::10) by BN9PR12MB5084.namprd12.prod.outlook.com (2603:10b6:408:135::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:05 +0000 Received: from BN8NAM11FT107.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::84) by BN9PR03CA0125.outlook.office365.com (2603:10b6:408:fe::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:17:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT107.mail.protection.outlook.com (10.13.176.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.22 via Frontend Transport; Tue, 11 Apr 2023 19:17:04 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:00 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:00 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:00 -0500 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: 7309f7e2-d89d-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f5hwxHDiJ6cPXtGVi0oDhgGm3os2tvfuJk/rvPeOs5IMC2wLTyxhSHPzGdvuuRI/bYz0Ev6Rre1K2rIqyc6Ri59vS16WiVSCQ1l2QfFetjgsYV5Yff3j66E4dGWelns5JVGmuHmyH1IJ/kbG8OD8pCblaMZ0E+AZIamdZgxFL6/rMSeIGdzBgffGT18CcjFfcjPhq0SrSrarKjXWWlLoGAmgksCM4eUYqtYTTyJn79+PXiCL8X26kfGxK59CnhJuMs3jKTv4FM3xgKbn0JR2wtFqYfeAhFWUzF9AQNhkj4t7gwiq4fg9M5y2vc9uwGkqFYIy5rGppra40oH/rnLn+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hbn+9h9tF7QZlww7kr6YoDzwWCRUPyZKofdb3QDs5Ls=; b=QNK9jA3ONnSE1MrYZppf2BKDWAJikpDz/GOU3l1M5GQWpOa3zeWUIQHywMUMYHK0RC5LhxeEzDXtfOIAQM0QmgHUemK4J03w6+oy55pd+1fcryOg5UQwJPlFbpsShvUrxOvN3WuucMqSP7vpnPTswMhoDr+e5riI0lrri1kXnMMExr7tbXY2OIjsGQRMoYLXtR0TaNRsThkS/pCIwVm+3tEDFUWCdgtZB+TMJ0Br/XCmGe3kqYmcHtx8/disPE18Rg/weHlFOUxiy8yaxbv3rxBSTJ1V5a/C6+kS0j+q55PYoyljRW2We6QxUC4N36NIpQdhyaeMVVjcoS/mlftlmg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hbn+9h9tF7QZlww7kr6YoDzwWCRUPyZKofdb3QDs5Ls=; b=auVQJ0UMG/mylausafR6rHAq+f0clyeouWECzrLAe+0FRFpwvUeGm/ek4sst6QIP7jQR4I5kTJUXKwX0yStFdEbrBAO1c2cp3KYtzvbqVOIAn8vSEU5dQerSPjGyH1T2jf7RtpXR85IyJQbGr+k7taprljIZT/DgVkW0Mua+GrE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" Subject: [XEN][PATCH v5 08/17] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Tue, 11 Apr 2023 12:16:09 -0700 Message-ID: <20230411191636.26926-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT107:EE_|BN9PR12MB5084:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bc72af7-9755-4072-ca37-08db3ac155e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aesU9CuNguun7Fu2Zu/Im/OValFm4zDIlA3vKluqIupLhBGOIhKJzL3kOBw9pc+M1uTqxvlV8M2MTLGidHSoQ9QYcZBNx5MMH4dzfVw9fHu7qhFgBOaDdU8yRkB/fpClf7vqVCXPJ1Qxo4cxojToznqjQ/baIHSEtTZfQSWDudyCvjxHCPZFDwqNLaq+Ah60vqJm/EhkmqwcHG9R1XA9y0IpflLQMperCGb1aIxadYWQRdN5a4EH0mC1C8e+dYSNpSaKavZkUiA+V2EX9NmlJ12gA+grRZfQMeksLwPkOQ5FNG+v0wlI22li2TB2cRwLDpz1No5Ao1bKRC7zkV3QaTsndXFhkrek7dVSAIrr8hAAWVzEq9n0xupoLdEtcP9yRez/dnhChpBsKdBbThmlvePtmhEY94uxyHALWIqEehztR9Yg/vkejNFzOw6ZYDzEL+XYrOIS4550vkADN18wNBsXdqTyNbygFJLwD0Iv21Ur58i01+RybNF6VvAKeqE7L9W5hZ/WPTdbA40j54Ab4SO/tSnJEw7LtXld4XERgzT4obmEtWSRllwB7nDL1sHWdinxTBN9pzhsBq6l7qW5ow7vY+9M2nJo5yHXIC3C0zVcOX/O2eqxZCsYvMIV81j7AW3n92+55NFguWetyfdNr2sKQDUo1FM+r7ncCtaDSeoKVob3SxQQosMjKUzuebtDao5PsQKzn0dHOwcXMmUi5flVdoIVD7EJQkivGjwgH4g= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(346002)(376002)(396003)(39860400002)(451199021)(36840700001)(46966006)(40470700004)(36756003)(86362001)(478600001)(41300700001)(316002)(4326008)(6916009)(70586007)(70206006)(8676002)(54906003)(8936002)(40480700001)(82310400005)(44832011)(5660300002)(2906002)(36860700001)(356005)(186003)(82740400003)(81166007)(1076003)(26005)(2616005)(426003)(47076005)(336012)(83380400001)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:04.7072 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bc72af7-9755-4072-ca37-08db3ac155e9 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT107.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5084 Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_lock(). Moving spin_lock to caller was done to prevent the concurrent access to iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- xen/drivers/passthrough/device_tree.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 1c32d7b50c..bb4cf7784d 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -83,16 +83,15 @@ fail: return rc; } -static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev) +static bool_t + iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev) { bool_t assigned = 0; if ( !dt_device_is_protected(dev) ) return 0; - spin_lock(&dtdevs_lock); assigned = !list_empty(&dev->domain_list); - spin_unlock(&dtdevs_lock); return assigned; } @@ -213,27 +212,43 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, if ( (d && d->is_dying) || domctl->u.assign_device.flags ) break; + spin_lock(&dtdevs_lock); + ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path, domctl->u.assign_device.u.dt.size, &dev); if ( ret ) + { + spin_unlock(&dtdevs_lock); + break; + } ret = xsm_assign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev)); if ( ret ) + { + spin_unlock(&dtdevs_lock); + break; + } if ( domctl->cmd == XEN_DOMCTL_test_assign_device ) { - if ( iommu_dt_device_is_assigned(dev) ) + + if ( iommu_dt_device_is_assigned_locked(dev) ) { printk(XENLOG_G_ERR "%s already assigned.\n", dt_node_full_name(dev)); ret = -EINVAL; } + + spin_unlock(&dtdevs_lock); + break; } + spin_unlock(&dtdevs_lock); + if ( d == dom_io ) return -EINVAL; From patchwork Tue Apr 11 19:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208103 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 E4E8DC76196 for ; Tue, 11 Apr 2023 19:17:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519775.806786 (Exim 4.92) (envelope-from ) id 1pmJUN-0005z6-O5; Tue, 11 Apr 2023 19:17:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519775.806786; Tue, 11 Apr 2023 19:17:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUN-0005x3-4z; Tue, 11 Apr 2023 19:17:11 +0000 Received: by outflank-mailman (input) for mailman id 519775; Tue, 11 Apr 2023 19:17:09 +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 1pmJUL-0004DR-DB for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:09 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20606.outbound.protection.outlook.com [2a01:111:f400:7e8d::606]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 72be6fba-d89d-11ed-8611-37d641c3527e; Tue, 11 Apr 2023 21:17:07 +0200 (CEST) Received: from MW3PR05CA0009.namprd05.prod.outlook.com (2603:10b6:303:2b::14) by DS7PR12MB6360.namprd12.prod.outlook.com (2603:10b6:8:93::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:04 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::93) by MW3PR05CA0009.outlook.office365.com (2603:10b6:303:2b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.27 via Frontend Transport; Tue, 11 Apr 2023 19:17:04 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:04 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:01 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:01 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:00 -0500 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: 72be6fba-d89d-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lDNOOUoUQrDMzJfKXlJfbBxfcLNE2ExFDTv865MP0/28SIEbvp9JnZjJDr5LiG2XgsPaddpgjmGypo4MdsgnlyvwAvcH5/tAVyON4tcV29yB5Ax5/rzMW6ngkXaB1UBKGYvq2j+aZVZmhrNwjVcuwB0KKYXqfz/ptE6F65s+mJEjq8G2VLHNZg4X4aI+pQhT+GVYB2esbpZP5Le+4vQaIRdvSESALv92/hOY2ohpeVzIb8GKRKbpFZlCAH/NKZEy8kHh6QD5+Iy7xS7PSL5SGScUzX7Q3pYlRuIDFqeQ8QY0Umpam1vCOps3ut4ieAid0xpteHShUAq767fEik0JzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qd0QFdZvzHUGWrw0BfIrEu3cWkp8jWSV4vPT9FURuHE=; b=BLJ69mgmDOC4R6oelAOdYmiz7bsaXr3tCsp/n9jVQSfNwQkvbwB8mNzPAXedghQGVKl73r9eHZiXnJDEgi6/5PIi785YsAGhLn/NjQVkncwcrUtvIO3Ub6EdFenIHqnvqeDVN+21UtIh+Agwu3sYvQtHLFYcsiEX8fDmQ8SxvaMsHl2nIL8WKgr0dF1fefO9Zd3hLLl1qRtq0ONlThpsSekvWPCjEdCdGe18ABWfwzYnKYzMpFoX/bFTV5a9F1lWAvL7nMGpRo/DHrjB9bZ+Wq0GxePVPj7o0sU+FM9Jnt0wqPJ5dJ0WJKD0FQVylkqF6rg4pG5aaacy8nY5HFtxPQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qd0QFdZvzHUGWrw0BfIrEu3cWkp8jWSV4vPT9FURuHE=; b=ydjZWvY1P/SI3BwD6fN+ts4m/35w6s58norWJb8ajYjmOcxbz3+nrGWMPxgzBAof3asGEfFsqYqJX+24SJKCU0VWnbnkWYCLCKikt1G3NmUzCNGNO6RCVa+N34wH/DUa74ovVoxQDb1Q4ujmxsdoFPr8gxaJg5RL2qb538w68hc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" Subject: [XEN][PATCH v5 09/17] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Tue, 11 Apr 2023 12:16:10 -0700 Message-ID: <20230411191636.26926-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|DS7PR12MB6360:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ab94d90-81ed-4d5a-7551-08db3ac1559c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qApyCw/eRhNKr9aze4U/rylhAkLcEqFW2qkkpLpyGUEdW2AgCK6S44/p2a67w1EuRCOHOm8BHUSpGgB9zXZ/Ac8aWvzxeFHcn+Gh5fQCW7wznN0MXMeYGWOr8xRnW2zrjSd8TadH8++Qaqe9vvGXNJaAcKZ5LNgkE/09f4wCEemxWSE/QVJ9HtFE9r9ehK/pb1HXoFwvHKYWhHgipn/QH/68Cj9kOEaQ9eIcIKU2DzYu/x3NWq8hbgQBJxAVoz1FRURZUtTkhzGZVW/DyKVMYu5NjzEBKekSLWPWvrIpLPAU45Acb1aQ/Q15gRkhEnUnPbe4UTxH3INxGJui8bfLeQ65cibYQCatpgNnCYr/08gyMg7prvQrE+8+41WLV4dXlHGSswThx20toJwjzJu0RaGii9JoQossCFqzOwXj3cNVH44tvvejdre2iIAhssiBRrApAzRdaNkLbd0kytp4OYeit8PRWwCskR4Xr7+qfYx1nPDzot+qTkZ31qz4oF5QYy1/VGAolU1Dh9dQSS7K3kF7fUiF+XrYB6Jjem6uybz2J0GNJQ28hMf6vMjeNx7Qj2S20XUxo7Fv+ofCyrSIBSz2JnN1IJvo7PBotlBZk8siV0EgvqNdK1qqC1eJIo3w4GJJ0m7IGxURagIbwE93lQ0DRC/u33VvRuxQlF48aqlSw0gUYORcOya+QbJs79vSJMyWczmowmgjZfg+dN6orTbpzeYxYKZjKFfO4LE+BQM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(136003)(451199021)(40470700004)(46966006)(36840700001)(1076003)(356005)(82740400003)(8936002)(8676002)(4326008)(86362001)(6666004)(5660300002)(6916009)(41300700001)(44832011)(40460700003)(82310400005)(36756003)(316002)(2906002)(478600001)(54906003)(70586007)(70206006)(40480700001)(47076005)(83380400001)(26005)(81166007)(186003)(36860700001)(2616005)(336012)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:04.1067 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ab94d90-81ed-4d5a-7551-08db3ac1559c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6360 Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access add. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel --- xen/drivers/passthrough/device_tree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index bb4cf7784d..457df333a0 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -146,6 +146,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( dev_iommu_fwspec_get(dev) ) return 0; + spin_lock(&dtdevs_lock); + /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt * from Linux. @@ -158,7 +160,10 @@ int iommu_add_dt_device(struct dt_device_node *np) * these callback implemented. */ if ( !ops->add_device || !ops->dt_xlate ) - return -EINVAL; + { + rc = -EINVAL; + goto fail; + } if ( !dt_device_is_available(iommu_spec.np) ) break; @@ -189,6 +194,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); +fail: + spin_unlock(&dtdevs_lock); return rc; } From patchwork Tue Apr 11 19:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208106 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 B8F3CC77B72 for ; Tue, 11 Apr 2023 19:17:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519778.806807 (Exim 4.92) (envelope-from ) id 1pmJUQ-0006fJ-99; Tue, 11 Apr 2023 19:17:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519778.806807; Tue, 11 Apr 2023 19:17:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUP-0006dJ-LC; Tue, 11 Apr 2023 19:17:13 +0000 Received: by outflank-mailman (input) for mailman id 519778; Tue, 11 Apr 2023 19:17:11 +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 1pmJUN-0004DR-58 for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:11 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20625.outbound.protection.outlook.com [2a01:111:f400:fe5a::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 73919cc7-d89d-11ed-8611-37d641c3527e; Tue, 11 Apr 2023 21:17:09 +0200 (CEST) Received: from BN9PR03CA0142.namprd03.prod.outlook.com (2603:10b6:408:fe::27) by DM4PR12MB7526.namprd12.prod.outlook.com (2603:10b6:8:112::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.34; Tue, 11 Apr 2023 19:17:05 +0000 Received: from BN8NAM11FT107.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::a2) by BN9PR03CA0142.outlook.office365.com (2603:10b6:408:fe::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:17:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT107.mail.protection.outlook.com (10.13.176.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.22 via Frontend Transport; Tue, 11 Apr 2023 19:17:05 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:02 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:02 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:01 -0500 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: 73919cc7-d89d-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nvRZFbWVxaHzD4dC4eg10s+JGeIh41RGjpq+bd3XY0t9hcciIFmAIf/xunvaYze63VcqaP8lDQIBoG0ArOGN3q0ezmZKBrhNS2VJPfRvLgWOtBxvXk3wP/Y5hb2gRua+HQqpFQyZBbhT3GPys5oZctzZiNmO07UsUtWReK6Cg2TnoZSShhAhjMNYMANyre5ctqTUhJ168r8N2bb4rLzUQpDH5ymPpE4a5xQlb6SGLgwEOJ48CAgd5flxzlaA7xH6uelUGpzk4lPdrhLlBwtJRfy529sag0IAv2JGcwAaMlK8rPanjPldyLK9auTZUvD4AY9kEDEfTcPAtisaOwrzdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gLWShZkghSoju5aCTSrHjPTktEFI3gdZrQ2ShX60hx0=; b=KxsI1IgHe4kyjJTYgsFZFWdpdnVOjddPLs48Hx2uUh+5zs2jS8/T0oe6xPIASt4IeeHSuiDMdecDtOM2c7WT0UFmNL2oWFvv3Ifeptc6jTvcwgO7xzganDpzZ3AKixd0P+QFPSA8SQ5lvbGx0E5bM3eQ6c5kZZvKd1mhKIdHtOp1utdCrQjJDiLbtRVo/tw8/cfAQAm9l7W+Nj+aiee3nWIK4QxyTi0SOcGq5aXtKKn3rjqDqpIrtT2tZECCubVI5sByrivWKtBTUXFTBWcJFerV0eQF8yZGMvGwmBdH3hx6kc80uQLYkaQp1XyV12Inde5nQdIAuMlDKkvw42GQUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=gLWShZkghSoju5aCTSrHjPTktEFI3gdZrQ2ShX60hx0=; b=NWggMp+NbZSoS74+iEW/lnwNxS/0+U45dx/xyGra3jRZCZ/dfkfv8fv3DPfx3rxJ7FZc8iSwFmlouf7C98Zy+LTDNBg0U7IISXWuutersEy7dJTx5zPfo0BU9grO+Uy/1sa/8XNWxNOd/BoFskPRKMLnF063zd0vUd3Kc6RMoNs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" , Jan Beulich , Paul Durrant , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [XEN][PATCH v5 10/17] xen/iommu: Introduce iommu_remove_dt_device() Date: Tue, 11 Apr 2023 12:16:11 -0700 Message-ID: <20230411191636.26926-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT107:EE_|DM4PR12MB7526:EE_ X-MS-Office365-Filtering-Correlation-Id: e678d25e-8dd0-4fed-c468-08db3ac15646 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4SMf3AeZxBcqMh+wCIuBWx4KpJmrSvC3Q6Fd/cdWCkn2sVjgyyZjynVpyRRCVplD4p7cX1bmJX8PzrHIYXpPfTZBmYKZFLRIbVNsdcPSiwHAsvtxVPdMUM3rYt0uBAwi3CbZQtanTiEDypOO3bHozVcvs9edN4GDqQayKQwrdlpZwqTUM7Dn3xGqLlQjth+k/NrdL3/fDAT75zeiPZn8Jrrw1aU29UNz+QImHUOTkkhEa2r0uyHUvWdT59Z1M/kyzQwOOJyqOGY4pbrxq6ZMYFAzX7k03In/TlaL+uXrLnDZnZ82Xxbw+g/mtEHlci2wm4JJNySUal8bPXdhEiLRZVDNqiA28f5E3FCAKaTbohv+nRaWhpKe8E3tTKFTC1KAFtngaI+KOaUHNdYMqtmeErZCaWnzMeWVTWhD81JubVi20aQviby1gBWMXZ/YVTAlSn2+ghFDMRKzziSt/jLbRI0sdUpQxNtpe6VHYWGTXv6FTuDmejueMdxSLoobwU01xwNiRaAgBSvoNF3kSyxmrWV3CX/sXLvkFqDPZ7g/uX4vjREiVIhb9XJb8XMnMNyWqNK+Zf4tCGCRxenOxYvbIlc/2jKxVc4sw/ojHVzauZE11kuFcpV1MVUZB7L8aigy5lElgLw7MIX696Bg9wmTK9ASSE9XBvuEaUsBOS8eGAgK1d6KhQJg2qzZqbpOVRPGpAsIA4UWS08+78bJnaCz4M6SNCLP5vfAGm5WdPlqAho= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(396003)(346002)(136003)(451199021)(40470700004)(36840700001)(46966006)(478600001)(40480700001)(47076005)(36756003)(83380400001)(86362001)(40460700003)(81166007)(356005)(82740400003)(426003)(2616005)(2906002)(316002)(1076003)(336012)(36860700001)(54906003)(44832011)(26005)(186003)(8676002)(8936002)(6666004)(6916009)(82310400005)(41300700001)(5660300002)(70586007)(4326008)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:05.3322 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e678d25e-8dd0-4fed-c468-08db3ac15646 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT107.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7526 Remove master device from the IOMMU. This will be helpful when removing the overlay nodes using dynamic programming during run time. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- xen/drivers/passthrough/device_tree.c | 38 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 457df333a0..a77a217f3d 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -126,6 +126,44 @@ int iommu_release_dt_devices(struct domain *d) return 0; } +int iommu_remove_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops = iommu_get_ops(); + struct device *dev = dt_to_dev(np); + int rc; + + if ( !ops ) + return -EOPNOTSUPP; + + spin_lock(&dtdevs_lock); + + if ( iommu_dt_device_is_assigned_locked(np) ) + { + rc = -EBUSY; + goto fail; + } + + /* + * The driver which supports generic IOMMU DT bindings must have + * these callback implemented. + */ + if ( !ops->remove_device ) + { + rc = -EOPNOTSUPP; + goto fail; + } + + /* Remove master device from the IOMMU if latter is present and available. */ + rc = ops->remove_device(0, dev); + + if ( !rc ) + iommu_fwspec_free(dev); + +fail: + spin_unlock(&dtdevs_lock); + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops = iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 405db59971..079c06321e 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -218,6 +218,8 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev); int iommu_dt_domain_init(struct domain *d); int iommu_release_dt_devices(struct domain *d); +int iommu_remove_dt_device(struct dt_device_node *np); + /* * Helper to add master device to the IOMMU using generic IOMMU DT bindings. * From patchwork Tue Apr 11 19:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208104 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 896E0C77B7A for ; Tue, 11 Apr 2023 19:17:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519776.806793 (Exim 4.92) (envelope-from ) id 1pmJUO-0006Fq-JH; Tue, 11 Apr 2023 19:17:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519776.806793; Tue, 11 Apr 2023 19:17:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUO-0006DA-3H; Tue, 11 Apr 2023 19:17:12 +0000 Received: by outflank-mailman (input) for mailman id 519776; Tue, 11 Apr 2023 19:17:10 +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 1pmJUL-0004Ta-UB for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:09 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20611.outbound.protection.outlook.com [2a01:111:f400:fe59::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 73e6f7e9-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:09 +0200 (CEST) Received: from BN9PR03CA0142.namprd03.prod.outlook.com (2603:10b6:408:fe::27) by SA0PR12MB4461.namprd12.prod.outlook.com (2603:10b6:806:9c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:06 +0000 Received: from BN8NAM11FT107.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::68) by BN9PR03CA0142.outlook.office365.com (2603:10b6:408:fe::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:17:06 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT107.mail.protection.outlook.com (10.13.176.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.22 via Frontend Transport; Tue, 11 Apr 2023 19:17:05 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:03 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:02 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:02 -0500 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: 73e6f7e9-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EE2Ctn9GNlCFsItgMw8F9HmYXg17oJOdiP9I9XI4gGGOLXsCtSbDBSqC61H+Dq+MLsM7lxptVaIo+tOpPZPzzMDUlCj/wE4F6cekg2BKBn6/Lo9J9ZDhfqwtpK/9IY1089A9Q867ER7/LITYmQibC71RbKQVmwQGce9+X5tjUYl3mShbhsOu8sRmoCVk/82SwIkHBA0S/pxssD5JCg+BWCV4HX/8NOUZm+GqDJPV/BsZhURrKd9nJXFRya41E9vv9DuOzNDjwYbJ5xo+9I8FY/BzeL3GPEYu4G6QlZSHWIXlZp5tfgNRPLpwRbKvetPtBqkQF/6ytR5INCV8dx6KlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x1PNAnqijXbZmLbaJTz/bnk2u6mRzrBSQaqCUQeSU5s=; b=jaL9+qOMzRad5tarJg4rEj4AKXrLNbMCDZlevdOeN1RNicT0Vj4aGC2TpobcwtvzX7YLo5mFaIpM/8ulm1opSE0QM2dTfcTf+xjX0o/MfWBBCLKrIfMG4b3D39A3YuA0fhCjqtpKPBGsMN/cjpUibFTkyhbO+SToa+IxsW4Vu2rS7dD6RbdMLXSMN3IF1G05npHhRVG9BabpwY7H+D6HQI0DUuznXWTDFXOS2Tx//5JnZtFgOpDe9Ck2R9xUkNMQmOz+Y2p0ORVooRxFOIzonSG/hvi6aJR7+oABL/WNh62YxFEGv7Frl7HiY+NUrkun81OMteRtRID/tKwmaCyugw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x1PNAnqijXbZmLbaJTz/bnk2u6mRzrBSQaqCUQeSU5s=; b=utGqqoXglk4yU5u11TW967K8k1NpxM1j7Bmkllm4Bn7wCTX1ogO1oSrTPEHf13ml2qCcv7EmB00zIOviy+PnFtwWVV26CjjThzvZrLhKh2848DLvyL841LgU937KVR6dXT4JeV+TpyfgP5FucG/R6tH+0XCreVFnWdWGjbUzCDM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v5 11/17] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Tue, 11 Apr 2023 12:16:12 -0700 Message-ID: <20230411191636.26926-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT107:EE_|SA0PR12MB4461:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c464d7b-9522-41af-e4d2-08db3ac156aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T1rYiXDUh4QnttGRazlOfWqjXoFP74k7bGx8YZ1wWb56PmvEsA86NABuo8umFlX5ixEi3YYq+E2xjZP6eBbWnvYB8jxJWUKeG79Av4TW3jJB0aDKOibhxbA8op9ZEslTO2VsDBJsW4puJuLQF7PNsVPhHaCsz5gSEg86dt60nC2ol7cScOcmegiDeOXY+tXSJiIhUvybYfmsyq869lb3lyUcRji4lT2SPZkgGwlhtMALVu5CEvyb4OD12v3OB56KM6iv8RWFhILrbyKWRqnCZ8PzKzi/TvS9SiFw0ahr+L4ptt3IZFsM19tr9C3tZrfGcKox5W6ERt+1bkk5UtbxL53hbKEx4hQyEZ/9oV76ao9yEIiAK6As55jinHTIfSUmYt/NK1WegBul9N/cwFSkVrvI6svGFAWb6w9labchneUXBergLWfB3IMNsYi0urR6/e0DNYLNxyZrf0Oukje6aAbxrhkjmnEDG+zm2iyCshjIIYqYIoQI9aZ/nxZMUfWlQiKtFnaRJj0554loeuyY/TkoOT4sXNZeygfCwwjgY9UgFvt8oxTkAmwMW/Lizz5BqYQSUsCa4r6xDDcLKsHV/YDmBTYJ89hw78Le2RG7Ls5rR68UcuQHYCXuNRbn9NHVB0APiSi70L1uADioPmuqiUCXQ/o8LtHvjZWYSeM5OZ8GxB3fuIZB6BJujSECBgvXC/F8hNVXBAFgT6WhzWUjtt7RdHucICoh2uh3QgMCCbk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(346002)(136003)(396003)(451199021)(40470700004)(36840700001)(46966006)(40460700003)(4326008)(6916009)(8676002)(54906003)(70586007)(70206006)(478600001)(41300700001)(316002)(36756003)(86362001)(336012)(47076005)(2616005)(426003)(6666004)(1076003)(26005)(83380400001)(44832011)(5660300002)(2906002)(36860700001)(8936002)(82310400005)(40480700001)(356005)(186003)(82740400003)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:05.9727 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c464d7b-9522-41af-e4d2-08db3ac156aa X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT107.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4461 Dynamic programming ops will modify the dt_host and there might be other function which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host. But adding rwlock in device_tree.h causes following circular dependency: device_tree.h->rwlock.h->smp.h->asm/smp.h->device_tree.h To fix this, removed the "#include and forward declared "struct dt_device_node". Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang Reviewed-by: Michal Orzel --- xen/arch/arm/include/asm/smp.h | 3 ++- xen/arch/arm/smpboot.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index 8133d5c295..afe6129276 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -3,13 +3,14 @@ #ifndef __ASSEMBLY__ #include -#include #include #endif DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); +struct dt_device_node; + #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) #define smp_processor_id() get_processor_id() diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 412ae22869..336a7d418b 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include From patchwork Tue Apr 11 19:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208101 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 05325C77B77 for ; Tue, 11 Apr 2023 19:17:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519773.806769 (Exim 4.92) (envelope-from ) id 1pmJUM-0005hl-A9; Tue, 11 Apr 2023 19:17:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519773.806769; Tue, 11 Apr 2023 19:17:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUM-0005gq-4P; Tue, 11 Apr 2023 19:17:10 +0000 Received: by outflank-mailman (input) for mailman id 519773; Tue, 11 Apr 2023 19:17:08 +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 1pmJUK-0004Ta-Pp for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:08 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20611.outbound.protection.outlook.com [2a01:111:f400:fe59::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 739189b0-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:08 +0200 (CEST) Received: from MW3PR05CA0017.namprd05.prod.outlook.com (2603:10b6:303:2b::22) by BN9PR12MB5257.namprd12.prod.outlook.com (2603:10b6:408:11e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.35; Tue, 11 Apr 2023 19:17:05 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::4a) by MW3PR05CA0017.outlook.office365.com (2603:10b6:303:2b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.27 via Frontend Transport; Tue, 11 Apr 2023 19:17:05 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:04 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:04 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:03 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:03 -0500 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: 739189b0-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RnOWGfhR+alOXtb1kEbH7mY9GHTUEb4Fh/Fq5W+ejuEBGScgkN+8M1kOzS1mFU4cA3rfTYuCUVidDnhaZwcIb3yH4MUbng3sDhlaGnQNs2bLeLWU+QLALHyOh6CCJhJQ35Fv0tfwvwbfL/RVHk4qdplIJ6NK9iWXfIv59MjOsILUtV/+MaRpY9HuwnDQh1R2S+1WxwGgc2i6+DPVMRL9v6qFUU46v4NtKiUIhGPHgtmRxH0AoZsyJEY9Kjj3m1REYDdpCUA4+p4qwj21PDv3c+9WAoLdNmEiTWZ1c2zIcG7SesZD2zVy+jc545NHBmf4mtQzOAGaAOrGiljWyw30fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zOQW4Omju1dTUno8ADGoDg+I28lOLIV01naa3ZWrW1o=; b=AfQz2DOlaIMvQKAfoj502N6k0Jzk3taYs6o6qwigXCHpwW9phuQL1ITtRk4IU4J3E9NW7amG3/ALbGXLT5qtSR/E78kmN0/SGnoIuH3ZklgOvT69Vgiste+lkcBBzOTpqZnmNqJHaI8nvqy9GkgQxNOezhqE18ZkBNOVddwf1TgIaJuwB4/MVqX7ZryKA4OXdowle9i35wq0g55QFrE2CaAXwmnFk7yQ5C72gzfecJg05Z8FViqa9a0TieJdOuPJzwaF3XJoql9riQPR7cpExcFwxk7tSvAArFJhJxJ0qDJhDi7kFBDo9XCjVSBw5u7OLEOkT5yS6dCv/wG+WRmLgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zOQW4Omju1dTUno8ADGoDg+I28lOLIV01naa3ZWrW1o=; b=yxZPsIxPbBZxAQRHbKz6JQv92aqGSLAVhz9iyCR72zNrtSEZDD/8sdBXFUVIUlg8q8cq3Nz60IlR1Gp2e7TcV6+htFinDnkGslGbL1h/edwWvv6KV5dmwrIBDYGlYaMPQ0QtCijJ0IRHkCLQQn4cHAy94E8McblhaOHAsSIB5ng= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" Subject: [XEN][PATCH v5 12/17] common/device_tree: Add rwlock for dt_host Date: Tue, 11 Apr 2023 12:16:13 -0700 Message-ID: <20230411191636.26926-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|BN9PR12MB5257:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c5bf8b1-3ea5-4fb3-321a-08db3ac1561d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QhfFyki35SJbRekBupI7TtH1V3WKYpDwoOfoHKrgY+p0KezPSeQt3siAWShc/QMBXA+1E2Alz5IVPwpto5fOu0pPF3dg1ZSOaysK/53rpx8PXrCDgOKlLGXLzMl8nR5wlJhLoHzmvG5bzi9shRnWClX6oAJRfKsSZqE0A27pLeOMJFcig7YwOd73TTCH37VmFh46V9uY66e3pWOZlm2pVv9ABTpMJaVcnRqtq4BgYqR9JGyCzuZB7H+vxmxoUyKdi97Z+bfAdJJsOVB7yamKBwyS9FLGOG0h8OnvnH8/3VudTqh0TaoRqhhZ/tSALeKw7cxetA1NkG8gKfCuzfpd1NtSfEbHB452W64YVPYrmtr7OrMaw4uga/aqEPeRRmt+eJ6TC1BXum2xBhu0eofYNTIYXg6SROb8t0CxYbPKCVGfqeu9h/XgTaLv5SGd9MTUR/3R8aENWmMrHhHESYCIj9aTFP0KjIV9WgU6hcZ2Ovhx3N6sVjA4W7XY3cwbsif9JTp08qjzIFanvRRZ011vcEKrCxhDKupQ9WbDjejzxoo35ggY0btzTNQDAYe83SgaIc0SH516ef74Kb1MN+zPK+Ozu3pZtoeYCOOPjp4tS+ZqjZjKTs/Pi3VJ7go13Q4q04+vWqTU1Jzarorqoku8E5LYWnFcWulNlnjo1UB6k8qMLAZqBSt3LAjT4QccAqgXz8W3GGqRfz8aLuVruJQvuzgBavv9/PZa4GCONwDeNHg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(396003)(346002)(136003)(451199021)(40470700004)(36840700001)(46966006)(478600001)(40480700001)(47076005)(36756003)(83380400001)(86362001)(40460700003)(81166007)(356005)(82740400003)(426003)(2616005)(2906002)(316002)(1076003)(336012)(36860700001)(54906003)(44832011)(26005)(186003)(8676002)(8936002)(6666004)(6916009)(82310400005)(41300700001)(5660300002)(70586007)(4326008)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:04.9504 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9c5bf8b1-3ea5-4fb3-321a-08db3ac1561d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5257 Dynamic programming ops will modify the dt_host and there might be other function which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host during runtime. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 3 +++ xen/drivers/passthrough/device_tree.c | 39 +++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 6 +++++ 3 files changed, 48 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 507b4ac5b6..b330e6a013 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2098,6 +2098,9 @@ void unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) *allnextp = NULL; dt_dprintk(" <- unflatten_device_tree()\n"); + + /* Init r/w lock for host device tree. */ + rwlock_init(&dt_host->lock); } static void dt_alias_add(struct dt_alias_prop *ap, diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index a77a217f3d..74f994b9da 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -112,6 +112,8 @@ int iommu_release_dt_devices(struct domain *d) if ( !is_iommu_enabled(d) ) return 0; + read_lock(&dt_host->lock); + list_for_each_entry_safe(dev, _dev, &hd->dt_devices, domain_list) { rc = iommu_deassign_dt_device(d, dev); @@ -119,10 +121,14 @@ int iommu_release_dt_devices(struct domain *d) { dprintk(XENLOG_ERR, "Failed to deassign %s in domain %u\n", dt_node_full_name(dev), d->domain_id); + + read_unlock(&dt_host->lock); return rc; } } + read_unlock(&dt_host->lock); + return 0; } @@ -259,11 +265,15 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, spin_lock(&dtdevs_lock); + read_lock(&dt_host->lock); + ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path, domctl->u.assign_device.u.dt.size, &dev); if ( ret ) { + read_unlock(&dt_host->lock); + spin_unlock(&dtdevs_lock); break; @@ -272,6 +282,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, ret = xsm_assign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev)); if ( ret ) { + read_unlock(&dt_host->lock); + spin_unlock(&dtdevs_lock); break; @@ -287,6 +299,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, ret = -EINVAL; } + read_unlock(&dt_host->lock); + spin_unlock(&dtdevs_lock); break; @@ -295,22 +309,31 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, spin_unlock(&dtdevs_lock); if ( d == dom_io ) + { + read_unlock(&dt_host->lock); return -EINVAL; + } ret = iommu_add_dt_device(dev); if ( ret < 0 ) { printk(XENLOG_G_ERR "Failed to add %s to the IOMMU\n", dt_node_full_name(dev)); + + read_unlock(&dt_host->lock); break; } ret = iommu_assign_dt_device(d, dev); if ( ret ) + { printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" " to dom%u failed (%d)\n", dt_node_full_name(dev), d->domain_id, ret); + } + + read_unlock(&dt_host->lock); break; case XEN_DOMCTL_deassign_device: @@ -322,25 +345,41 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, if ( domctl->u.assign_device.flags ) break; + read_lock(&dt_host->lock); + ret = dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path, domctl->u.assign_device.u.dt.size, &dev); if ( ret ) + { + read_unlock(&dt_host->lock); break; + } ret = xsm_deassign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev)); + if ( ret ) + { + read_unlock(&dt_host->lock); break; + } if ( d == dom_io ) + { + read_unlock(&dt_host->lock); return -EINVAL; + } ret = iommu_deassign_dt_device(d, dev); if ( ret ) + { printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" " to dom%u failed (%d)\n", dt_node_full_name(dev), d->domain_id, ret); + } + + read_unlock(&dt_host->lock); break; default: diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 998f972ebc..b7272bbccc 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -18,6 +18,7 @@ #include #include #include +#include #define DEVICE_TREE_MAX_DEPTH 16 @@ -106,6 +107,11 @@ struct dt_device_node { struct list_head domain_list; struct device dev; + + /* + * Lock that protects r/w updates to unflattened device tree i.e. dt_host. + */ + rwlock_t lock; }; #define dt_to_dev(dt_node) (&(dt_node)->dev) From patchwork Tue Apr 11 19:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208107 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 414CEC7619A for ; Tue, 11 Apr 2023 19:17:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519779.806822 (Exim 4.92) (envelope-from ) id 1pmJUS-0007Ds-DN; Tue, 11 Apr 2023 19:17:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519779.806822; Tue, 11 Apr 2023 19:17:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUR-0007Bc-SA; Tue, 11 Apr 2023 19:17:15 +0000 Received: by outflank-mailman (input) for mailman id 519779; Tue, 11 Apr 2023 19:17:13 +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 1pmJUO-0004Ta-VA for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:13 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2060f.outbound.protection.outlook.com [2a01:111:f400:7e8d::60f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 75176950-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:11 +0200 (CEST) Received: from BN9PR03CA0140.namprd03.prod.outlook.com (2603:10b6:408:fe::25) by PH7PR12MB6717.namprd12.prod.outlook.com (2603:10b6:510:1b0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Tue, 11 Apr 2023 19:17:06 +0000 Received: from BN8NAM11FT107.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::d5) by BN9PR03CA0140.outlook.office365.com (2603:10b6:408:fe::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:17:06 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT107.mail.protection.outlook.com (10.13.176.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.22 via Frontend Transport; Tue, 11 Apr 2023 19:17:06 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:05 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:04 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:04 -0500 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: 75176950-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fcX85IqJccCGBe/QojBYX98xNDGdabmYF+Zf31yQxBGDff6mnyC5036RjUc+vNeCVVM9gONrC9zUraMNMVOWRsNICeIxhzmjMi/dltGM84fA19Tq+ErybnmMlSpZje5r2zPQg3lnZazpNhNAdM+5KVJko8GlumURs0aXbNPQtBIFMvc5llhGsEaw/qXzVis6NlV9143xMNg0CpJBVPElRmu+5InH9K9uWE5t3fT9rokREVUnuFNcgMTf6rhWQ1sZl+Wgl+IiZLHkhAGzRErEIbNamxllm2/jsIyFYUc9TstI8SCMkZdJEQaf9wMixXzJSg03SrL2uwj0docX5gDAEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vXy30MDq5H9lVjpDCmPPgeX6WY9DS2JY3kC1QKAn9No=; b=EWdxnXZIHj9Q2jeSvYo16U1pFYbKoWoC2fSjscISmOZTKCjofhAH3otiYoq9EgsrwA7oblZnJxGTiwNVcX7lSLiGc3H5bUurk38eDYFOVRNcRk7s2yR/qbQl81SGxhUArMIPYIdeWuA31izTVpMFixl/s4VNKWmWLoN8XrlIId2tCMZ3YYXv66oiVEsbxVGOBOZGyNLdYFbP228nsgbfOrhFqjA1x1NSea8/ftLR42H7zjNHSoEhUa9th3DOONoNPMYD8eHNrxdwBEKR5PGU5RmRmyaxMxcg/OTlGzyesyf3oK3aSKRwHJB54fTKkTTtiXR5njZTFEy61ILRaFryRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vXy30MDq5H9lVjpDCmPPgeX6WY9DS2JY3kC1QKAn9No=; b=TB5K3tBM/Q6w1B75wjMitVnL7DqvAIonQ11xUEnWZ5E17YXNhU7YqMMxdEGzS9TQHnpD1Vsb/aAYnooiZvtNCkXG0+oiVFCsZAdOExBypXdAzv17r9OuhyxrTvcE1HGe9oEfHchBAULwoNvRClZ0Z0aFDHo7aXHqDF6EFdPgq6c= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Julien Grall" , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu Subject: [XEN][PATCH v5 13/17] xen/arm: Implement device tree node removal functionalities Date: Tue, 11 Apr 2023 12:16:14 -0700 Message-ID: <20230411191636.26926-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT107:EE_|PH7PR12MB6717:EE_ X-MS-Office365-Filtering-Correlation-Id: d0188860-8724-4ff4-1c1e-08db3ac156e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ETK2kqVrnWW6vEg7dU542k+8z7yWzf4PQnFPqlH3d7oKxJwQjx69chGqA9JIEedbE0LNWVxNifNQELyLIY0R87SVx+5b+Oekmwp0ETMWwHohlVZVHARguE611aybKX+R+jSUUm94ojGqd4OjisXeErDBqWU9cjnWHMs8ZmqE04qTAYIwSct1FVKl7eAbAiD6KqKORABiFkLCE3JEYLXTmYu0oO/wqQwEawVhzp+ChRYki4iaCE5Q+hT+CfgMn9hi1UMmMD2o+vAETEXv4HFthHlQdZnAxJZ3oYbNLBys9BR5EdWL/O1pHfmKHkEjbTkTC1WnwGcoMFW47DKP14ZDFdl1UFeeQvIsZ8m1ClthAer+yEdf1Tzbh8aspHgjfCjXXztApP3NSNvl6dYhPWR6AV6lW27C7NojPCzisjvsjn2N4w2sjdSBA046RzSXi+2/27ifxkgUhNY1e0BpghcuKuWjbzJ6aWcmMrE8aZwaRgudGzYCk4AqgX7UJLZK+MckPdx6fhtFQUh/S4GpSwWu3IyPapi78woFVIV1YtKesRTEXsU4Vsne6hSVkeHxVjxzPFeAu3a4KoC/52Gfp3FX3rDQfvFHRCeypuyHDGuGz2vFL8kNzTGr0udzCArpmC5/f1I7nv4L6MATLHOP0vh6LoKz7jGorLGWUfg4xhGSs7/+V2keNPsO/X/Pm8OAeUeBDpwO1SFBuOnpkpbwD+kI5rCbxUgdQF0zX+F4ENiuFksxwEUAkCEgwhX8byXjH3Ne5bDJoK6qJZdmMjhZQbgnCw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(136003)(346002)(376002)(451199021)(36840700001)(46966006)(40470700004)(86362001)(30864003)(186003)(5660300002)(44832011)(426003)(336012)(82310400005)(47076005)(356005)(1076003)(26005)(83380400001)(82740400003)(36860700001)(81166007)(316002)(8936002)(8676002)(54906003)(6666004)(40480700001)(478600001)(40460700003)(2616005)(70586007)(6916009)(70206006)(36756003)(41300700001)(4326008)(2906002)(403724002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:06.3633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0188860-8724-4ff4-1c1e-08db3ac156e4 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT107.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6717 Introduce sysctl XEN_SYSCTL_dt_overlay to remove device-tree nodes added using device tree overlay. xl dt-overlay remove file.dtbo: Removes all the nodes in a given dtbo. First, removes IRQ permissions and MMIO accesses. Next, it finds the nodes in dt_host and delete the device node entries from dt_host. The nodes get removed only if it is not used by any of dom0 or domio. Also, added overlay_track struct to keep the track of added node through device tree overlay. overlay_track has dt_host_new which is unflattened form of updated fdt and name of overlay nodes. When a node is removed, we also free the memory used by overlay_track for the particular overlay node. Nested overlay removal is supported in sequential manner only i.e. if overlay_child nests under overlay_parent, it is assumed that user first removes overlay_child and then removes overlay_parent. Signed-off-by: Vikram Garhwal --- xen/arch/arm/sysctl.c | 16 +- xen/common/Makefile | 1 + xen/common/dt_overlay.c | 415 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 24 ++ xen/include/xen/dt_overlay.h | 59 +++++ 5 files changed, 514 insertions(+), 1 deletion(-) create mode 100644 xen/common/dt_overlay.c create mode 100644 xen/include/xen/dt_overlay.h diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c index b0a78a8b10..672db61650 100644 --- a/xen/arch/arm/sysctl.c +++ b/xen/arch/arm/sysctl.c @@ -12,6 +12,7 @@ #include #include #include +#include void arch_do_physinfo(struct xen_sysctl_physinfo *pi) { @@ -21,7 +22,20 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi) long arch_do_sysctl(struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { - return -ENOSYS; + long ret = 0; + + switch ( sysctl->cmd ) + { + case XEN_SYSCTL_dt_overlay: + ret = dt_sysctl(&sysctl->u.dt_overlay); + break; + + default: + ret = -ENOSYS; + break; + } + + return ret; } /* diff --git a/xen/common/Makefile b/xen/common/Makefile index 46049eac35..be78c9a8c2 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o +obj-$(CONFIG_OVERLAY_DTB) += dt_overlay.o obj-y += event_2l.o obj-y += event_channel.o obj-y += event_fifo.o diff --git a/xen/common/dt_overlay.c b/xen/common/dt_overlay.c new file mode 100644 index 0000000000..516e8010c5 --- /dev/null +++ b/xen/common/dt_overlay.c @@ -0,0 +1,415 @@ +/* + * SPDX-License-Identifier: GPL-2.0 + * + * xen/common/dt_overlay.c + * + * Device tree overlay support in Xen. + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + * Written by Vikram Garhwal + * + */ +#include +#include +#include +#include +#include + +static LIST_HEAD(overlay_tracker); +static DEFINE_SPINLOCK(overlay_lock); + +/* Find last descendants of the device_node. */ +static struct dt_device_node *find_last_descendants_node( + struct dt_device_node *device_node) +{ + struct dt_device_node *child_node; + + for ( child_node = device_node->child; child_node->sibling != NULL; + child_node = child_node->sibling ) + { + } + + /* If last child_node also have children. */ + if ( child_node->child ) + child_node = find_last_descendants_node(child_node); + + return child_node; +} + +static int dt_overlay_remove_node(struct dt_device_node *device_node) +{ + struct dt_device_node *np; + struct dt_device_node *parent_node; + struct dt_device_node *device_node_last_descendant = device_node->child; + + parent_node = device_node->parent; + + if ( parent_node == NULL ) + { + dt_dprintk("%s's parent node not found\n", device_node->name); + return -EFAULT; + } + + np = parent_node->child; + + if ( np == NULL ) + { + dt_dprintk("parent node %s's not found\n", parent_node->name); + return -EFAULT; + } + + /* If node to be removed is only child node or first child. */ + if ( !dt_node_cmp(np->full_name, device_node->full_name) ) + { + parent_node->child = np->sibling; + + /* + * Iterate over all child nodes of device_node. Given that we are + * removing parent node, we need to remove all it's descendants too. + */ + if ( device_node_last_descendant ) + { + device_node_last_descendant = + find_last_descendants_node(device_node); + parent_node->allnext = device_node_last_descendant->allnext; + } + else + parent_node->allnext = np->allnext; + + return 0; + } + + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + if ( !dt_node_cmp(np->sibling->full_name, device_node->full_name) ) + { + /* Found the node. Now we remove it. */ + np->sibling = np->sibling->sibling; + + if ( np->child ) + np = find_last_descendants_node(np); + + /* + * Iterate over all child nodes of device_node. Given that we are + * removing parent node, we need to remove all it's descendants too. + */ + if ( device_node_last_descendant ) + device_node_last_descendant = + find_last_descendants_node(device_node); + + if ( device_node_last_descendant ) + np->allnext = device_node_last_descendant->allnext; + else + np->allnext = np->allnext->allnext; + + break; + } + } + + return 0; +} + +/* Basic sanity check for the dtbo tool stack provided to Xen. */ +static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) +{ + if ( (fdt_totalsize(overlay_fdt) != overlay_fdt_size) || + fdt_check_header(overlay_fdt) ) + { + printk(XENLOG_ERR "The overlay FDT is not a valid Flat Device Tree\n"); + return -EINVAL; + } + + return 0; +} + +/* Count number of nodes till one level of __overlay__ tag. */ +static unsigned int overlay_node_count(void *fdto) +{ + unsigned int num_overlay_nodes = 0; + int fragment; + + fdt_for_each_subnode(fragment, fdto, 0) + { + int subnode; + int overlay; + + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + fdt_for_each_subnode(subnode, fdto, overlay) + { + num_overlay_nodes++; + } + } + + return num_overlay_nodes; +} + +static int handle_remove_irq_iommu(struct dt_device_node *device_node) +{ + int rc = 0; + struct domain *d = hardware_domain; + domid_t domid; + unsigned int naddr, len; + unsigned int i, nirq; + uint64_t addr, size; + + domid = dt_device_used_by(device_node); + + dt_dprintk("Checking if node %s is used by any domain\n", + device_node->full_name); + + /* Remove the node iff it's assigned to domain 0 or domain io. */ + if ( domid != 0 && domid != DOMID_IO ) + { + printk(XENLOG_ERR "Device %s as it is being used by domain %d. Removing nodes failed\n", + device_node->full_name, domid); + return -EINVAL; + } + + dt_dprintk("Removing node: %s\n", device_node->full_name); + + nirq = dt_number_of_irq(device_node); + + /* Remove IRQ permission */ + for ( i = 0; i < nirq; i++ ) + { + rc = platform_get_irq(device_node, i);; + + if ( irq_access_permitted(d, rc) == false ) + { + printk(XENLOG_ERR "IRQ %d is not routed to domain %d\n", rc, + domid); + return -EINVAL; + } + /* + * TODO: We don't handle shared IRQs for now. So, it is assumed that + * the IRQs was not shared with another devices. + */ + rc = irq_deny_access(d, rc); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %u for %s\n", + i, device_node->full_name); + return rc; + } + } + + /* Check if iommu property exists. */ + if ( dt_get_property(device_node, "iommus", &len) ) + { + rc = iommu_remove_dt_device(device_node); + if ( rc != 0 && rc != -ENXIO ) + return rc; + } + + naddr = dt_number_of_address(device_node); + + /* Remove mmio access. */ + for ( i = 0; i < naddr; i++ ) + { + rc = dt_device_get_address(device_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(device_node)); + return rc; + } + + rc = iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + size - 1))); + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); + return rc; + } + + } + + return rc; +} + +/* Removes all descendants of the given node. */ +static int remove_all_descendant_nodes(struct dt_device_node *device_node) +{ + int rc = 0; + struct dt_device_node *child_node; + + for ( child_node = device_node->child; child_node != NULL; + child_node = child_node->sibling ) + { + if ( child_node->child ) + remove_all_descendant_nodes(child_node); + + rc = handle_remove_irq_iommu(child_node); + if ( rc ) + return rc; + } + + return rc; +} + +/* Remove nodes from dt_host. */ +static int remove_nodes(const struct overlay_track *tracker) +{ + int rc = 0; + struct dt_device_node *overlay_node; + unsigned int j; + + for ( j = 0; j < tracker->num_nodes; j++ ) + { + overlay_node = (struct dt_device_node *)tracker->nodes_address[j]; + if ( overlay_node == NULL ) + { + printk(XENLOG_ERR "Device %s is not present in the tree. Removing nodes failed\n", + overlay_node->full_name); + return -EINVAL; + } + + rc = remove_all_descendant_nodes(overlay_node); + + /* All children nodes are unmapped. Now remove the node itself. */ + rc = handle_remove_irq_iommu(overlay_node); + if ( rc ) + return rc; + + read_lock(&dt_host->lock); + + rc = dt_overlay_remove_node(overlay_node); + if ( rc ) + { + read_unlock(&dt_host->lock); + + return rc; + } + + read_unlock(&dt_host->lock); + } + + return rc; +} + +/* + * First finds the device node to remove. Check if the device is being used by + * any dom and finally remove it from dt_host. IOMMU is already being taken care + * while destroying the domain. + */ +static long handle_remove_overlay_nodes(void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc = 0; + struct overlay_track *entry, *temp, *track; + bool found_entry = false; + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + return rc; + + if ( overlay_node_count(overlay_fdt) == 0 ) + return -ENOMEM; + + spin_lock(&overlay_lock); + + /* + * First check if dtbo is correct i.e. it should one of the dtbo which was + * used when dynamically adding the node. + * Limitation: Cases with same node names but different property are not + * supported currently. We are relying on user to provide the same dtbo + * as it was used when adding the nodes. + */ + list_for_each_entry_safe( entry, temp, &overlay_tracker, entry ) + { + if ( memcmp(entry->overlay_fdt, overlay_fdt, overlay_fdt_size) == 0 ) + { + track = entry; + found_entry = true; + break; + } + } + + if ( found_entry == false ) + { + rc = -EINVAL; + + printk(XENLOG_ERR "Cannot find any matching tracker with input dtbo." + " Removing nodes is supported for only prior added dtbo. Please" + " provide a valid dtbo which was used to add the nodes.\n"); + goto out; + + } + + rc = remove_nodes(entry); + + if ( rc ) + { + printk(XENLOG_ERR "Removing node failed\n"); + goto out; + } + + list_del(&entry->entry); + + xfree(entry->dt_host_new); + xfree(entry->fdt); + xfree(entry->overlay_fdt); + + xfree(entry->nodes_address); + + xfree(entry); + +out: + spin_unlock(&overlay_lock); + return rc; +} + +long dt_sysctl(struct xen_sysctl_dt_overlay *op) +{ + long ret; + void *overlay_fdt; + + if ( op->overlay_fdt_size <= 0 || op->overlay_fdt_size > KB(500) ) + return -EINVAL; + + overlay_fdt = xmalloc_bytes(op->overlay_fdt_size); + + if ( overlay_fdt == NULL ) + return -ENOMEM; + + ret = copy_from_guest(overlay_fdt, op->overlay_fdt, op->overlay_fdt_size); + if ( ret ) + { + gprintk(XENLOG_ERR, "copy from guest failed\n"); + xfree(overlay_fdt); + + return -EFAULT; + } + + switch ( op->overlay_op ) + { + case XEN_SYSCTL_DT_OVERLAY_REMOVE: + ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + xfree(overlay_fdt); + + break; + + default: + xfree(overlay_fdt); + break; + } + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 2b24d6bfd0..1158c1efb3 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1057,6 +1057,25 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#if defined(__arm__) || defined (__aarch64__) +#define XEN_SYSCTL_DT_OVERLAY_ADD 1 +#define XEN_SYSCTL_DT_OVERLAY_REMOVE 2 + +/* + * XEN_SYSCTL_dt_overlay + * Performs addition/removal of device tree nodes under parent node using dtbo. + * This does in three steps: + * - Adds/Removes the nodes from dt_host. + * - Adds/Removes IRQ permission for the nodes. + * - Adds/Removes MMIO accesses. + */ +struct xen_sysctl_dt_overlay { + XEN_GUEST_HANDLE_64(void) overlay_fdt; /* IN: overlay fdt. */ + uint32_t overlay_fdt_size; /* IN: Overlay dtb size. */ + uint8_t overlay_op; /* IN: Add or remove. */ +}; +#endif + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1087,6 +1106,7 @@ struct xen_sysctl { #define XEN_SYSCTL_livepatch_op 27 /* #define XEN_SYSCTL_set_parameter 28 */ #define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_dt_overlay 30 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -1117,6 +1137,10 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + +#if defined(__arm__) || defined (__aarch64__) + struct xen_sysctl_dt_overlay dt_overlay; +#endif uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/dt_overlay.h b/xen/include/xen/dt_overlay.h new file mode 100644 index 0000000000..2cd975a070 --- /dev/null +++ b/xen/include/xen/dt_overlay.h @@ -0,0 +1,59 @@ +/* + * SPDX-License-Identifier: GPL-2.0 + * + * xen/dt_overlay.h + * + * Device tree overlay support in Xen. + * + * Copyright (c) 2022 AMD Inc. + * Written by Vikram Garhwal + * + */ +#ifndef __XEN_DT_SYSCTL_H__ +#define __XEN_DT_SYSCTL_H__ + +#include +#include +#include +#include + +/* + * overlay_node_track describes information about added nodes through dtbo. + * @entry: List pointer. + * @dt_host_new: Pointer to the updated dt_host_new unflattened 'updated fdt'. + * @fdt: Stores the fdt. + * @nodes_fullname: Stores the full name of nodes. + * @nodes_irq: Stores the IRQ added from overlay dtb. + * @node_num_irq: Stores num of IRQ for each node in overlay dtb. + * @num_nodes: Stores total number of nodes in overlay dtb. + */ +struct overlay_track { + struct list_head entry; + struct dt_device_node *dt_host_new; + void *fdt; + void *overlay_fdt; + unsigned long *nodes_address; + unsigned int num_nodes; +}; + +struct xen_sysctl_dt_overlay; + +#ifdef CONFIG_OVERLAY_DTB +long dt_sysctl(struct xen_sysctl_dt_overlay *op); +#else +static inline long dt_sysctl(struct xen_sysctl_dt_overlay *op) +{ + return -ENOSYS; +} +#endif +#endif + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Tue Apr 11 19:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208108 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 36223C76196 for ; Tue, 11 Apr 2023 19:17:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519780.806829 (Exim 4.92) (envelope-from ) id 1pmJUT-0007Qi-98; Tue, 11 Apr 2023 19:17:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519780.806829; Tue, 11 Apr 2023 19:17:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUS-0007Lm-LY; Tue, 11 Apr 2023 19:17:16 +0000 Received: by outflank-mailman (input) for mailman id 519780; Tue, 11 Apr 2023 19:17:14 +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 1pmJUP-0004Ta-VN for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:14 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20616.outbound.protection.outlook.com [2a01:111:f400:7e89::616]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 75148f5c-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:12 +0200 (CEST) Received: from MW4PR04CA0047.namprd04.prod.outlook.com (2603:10b6:303:6a::22) by MN2PR12MB4502.namprd12.prod.outlook.com (2603:10b6:208:263::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:07 +0000 Received: from CO1NAM11FT085.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::73) by MW4PR04CA0047.outlook.office365.com (2603:10b6:303:6a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.39 via Frontend Transport; Tue, 11 Apr 2023 19:17:07 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT085.mail.protection.outlook.com (10.13.174.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.29 via Frontend Transport; Tue, 11 Apr 2023 19:17:06 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:06 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:05 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:05 -0500 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: 75148f5c-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RZdxqLJLgKXDWMojKmWYYz9UnYELtxncFWW4wx0bV5HcVbaJrpZBh04U5pSoVFPsQkFcKZDIq1Cg8njnRsZo6At6d4z/W7Zb556MDP3/UZ4X1Wb5wU8M5Er5sE3aE8e8e1aOyEtOXb76xht+yVKRN7MYBlIlizy+KTpDxKe4zd1CmkCF4sn+uCQ0yjObeHk7/SE6yLnGUgnlu68frNEVqHXGYkKu5drI0ZpXtqvO3qVhNk/rpBs+02yeuqTefgfStDVLs8Nuc0LaUnIWCzCro0vRIkBdCAavv7c2RUSxDWRs+0RhhYHkJuRPKWQPVvsr5gpIkF3+fZ5oLOfEcn4RWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3+cCBf3g6fBI4ES7DG61XJTRWpPAgPp5V0YvFzOd6Q8=; b=KJK2ygR2wbBhuVxFyoZFLe+hjdtRm5koMDZd9Oeof9o6Aryt6qAPXH4LSXA53BlJtoWTl7/QMpPB3rE1/jgDjcVx6BzJS2qm1j1Nzza7P1YhA10GSS0bJNqHNjNK7+g9BV0KMtvFYvDXV4I+yVf5/9R1o0iETEgk5CSteU9Iuq8c1w26r9xNQoxbwSH7Xf31WwyiYOFDY1Z8BWsfLWkNm4M35eIeZSkN2Px0Y9WJI6r1y6CaciDRh+ALhIi+01A2xtV+iMUUCCug8h1kLS0BerTPjTmiuO8KQzFu4jVy1oFWzmC8mSZ7Prz+LFeloL+VwtbV04/T7J/jbrAjQpbNMA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3+cCBf3g6fBI4ES7DG61XJTRWpPAgPp5V0YvFzOd6Q8=; b=brYbKaGU8Q72lJSgTQfQSW8LmLDO7PvXt2hCa4KPGUB8MerKituz4Z9o0vpiMd3zauNzeTF9tRf/OkKJfza8PRinChP0AN4UqPhRxE7AF4B7Ohpaal8qYF6xk+4HuIFn2jQ6lgAMkQS8ir7ykY4Ws1ZcEeHGCpeoyIoCKF37Z+I= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , "Andrew Cooper" , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN][PATCH v5 14/17] xen/arm: Implement device tree node addition functionalities Date: Tue, 11 Apr 2023 12:16:15 -0700 Message-ID: <20230411191636.26926-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT085:EE_|MN2PR12MB4502:EE_ X-MS-Office365-Filtering-Correlation-Id: c6a6d862-d820-4db3-7343-08db3ac15750 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MmAyEa5oVIVl3CtWWYgdlvLVK6ewQoub2983E5bimxekYFO5Peb8HJsCasTmDKy/FzyLzXzOVomWOv2EFfH7ERRVTuHUGIYfKq54yrOp0jb8L+OG6ab/c/7eSpMtPAQeyXF1dyw7OlLUZV7gMQCeGsE2wKS6BmaFmzlBR80+wO7Z/IMmuca/CSfj4rCyJBtwSBtlAjnDlaJ6+5ulPhbbNEeddu0NNyXLzXtnhQgQo/sPjTEdQIlHQVC5wrJt+Q2dHRPbcLz90zCboCsQl5U+OcqJlPg6sZ0RLrXEdmqnEN7Ox3+7UupKtwwqmjgb34j4AyBqYsr1ZO7FWUP84f44ybjswyvoIlbJkiYcx5pyYDjerN7W4GaXoctw5xFMzz7eNNlzlGuTtURm1KSrhOEqnnnm1s9NU6n53DJuPYQL3njtUgGoQhYtMqFiXhYMXTKWLyBiaV8k5ew7WeCfLAFAR6y+YAc0EwCQYAcCemvz7YJKA1XGh7ygvZ6b+qrUXSH3W1iyKgQLTBD3h5gd+NdUHWzsVWQR9HfOajVGzAivWRoRRYkj2GMll49MUooNSHSWL5C5TAi7sj6hYuXl324GMIYIdayWJn4emzVeGGRfVyRYQZsXtk4BhqaF9SselyMrRpSuMC62XFvr1Q6AcaoQc5IZhXJXLs3UU5cTaVUeSB/uJgnQHukVeTC9TL4ycINQumm2Kk0n0lrIEEZJb8+WMESo8HpBytE9R4oFUgdIvk8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(36840700001)(46966006)(40470700004)(316002)(82310400005)(54906003)(82740400003)(36860700001)(356005)(81166007)(70586007)(8676002)(70206006)(4326008)(86362001)(6916009)(478600001)(426003)(336012)(47076005)(186003)(2616005)(26005)(41300700001)(36756003)(1076003)(2906002)(83380400001)(30864003)(40460700003)(44832011)(40480700001)(8936002)(6666004)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:06.9640 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6a6d862-d820-4db3-7343-08db3ac15750 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT085.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4502 Update sysctl XEN_SYSCTL_dt_overlay to enable support for dtbo nodes addition using device tree overlay. xl dt-overlay add file.dtbo: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, it checks if any of the overlay nodes already exists in the dt_host. If overlay nodes doesn't exist then find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. The node is attached as the last node under target parent. Finally, add IRQs, add device to IOMMUs, set permissions and map MMIO for the overlay node. When a node is added using overlay, a new entry is allocated in the overlay_track to keep the track of memory allocation due to addition of overlay node. This is helpful for freeing the memory allocated when a device tree node is removed. The main purpose of this to address first part of dynamic programming i.e. making xen aware of new device tree node which means updating the dt_host with overlay node information. Here we are adding/removing node from dt_host, and checking/setting IOMMU and IRQ permission but never mapping them to any domain. Right now, mapping/Un-mapping will happen only when a new domU is created/destroyed using "xl create". Signed-off-by: Vikram Garhwal --- xen/common/dt_overlay.c | 482 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 482 insertions(+) diff --git a/xen/common/dt_overlay.c b/xen/common/dt_overlay.c index 516e8010c5..3344bad313 100644 --- a/xen/common/dt_overlay.c +++ b/xen/common/dt_overlay.c @@ -36,6 +36,25 @@ static struct dt_device_node *find_last_descendants_node( return child_node; } +/* + * Returns next node to the input node. If node has children then return + * last descendant's next node. +*/ +static struct dt_device_node *dt_find_next_node(struct dt_device_node *dt, + const struct dt_device_node *node) +{ + struct dt_device_node *np; + + dt_for_each_device_node(dt, np) + if ( np == node ) + break; + + if ( np->child ) + np = find_last_descendants_node(np); + + return np->allnext; +} + static int dt_overlay_remove_node(struct dt_device_node *device_node) { struct dt_device_node *np; @@ -109,6 +128,72 @@ static int dt_overlay_remove_node(struct dt_device_node *device_node) return 0; } +static int dt_overlay_add_node(struct dt_device_node *device_node, + const char *parent_node_path) +{ + struct dt_device_node *parent_node; + struct dt_device_node *np, *np_last_descendant; + struct dt_device_node *next_node; + struct dt_device_node *device_node_last_descendant; + + parent_node = dt_find_node_by_path(parent_node_path); + + if ( parent_node == NULL ) + { + dt_dprintk("Node not found. Overlay node will not be added\n"); + return -EINVAL; + } + + /* If parent has no child. */ + if ( parent_node->child == NULL ) + { + next_node = parent_node->allnext; + device_node->parent = parent_node; + parent_node->allnext = device_node; + parent_node->child = device_node; + } + else + { + /* If parent has at least one child node. + * Iterate to the last child node of parent. + */ + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ); + + /* Iterate over all child nodes of np node. */ + if ( np->child ) + { + np_last_descendant = find_last_descendants_node(np); + + next_node = np_last_descendant->allnext; + np_last_descendant->allnext = device_node; + } + else + { + next_node = np->allnext; + np->allnext = device_node; + } + + device_node->parent = parent_node; + np->sibling = device_node; + np->sibling->sibling = NULL; + } + + /* Iterate over all child nodes of device_node to add children too. */ + if ( device_node->child ) + { + device_node_last_descendant = find_last_descendants_node(device_node); + /* Plug next_node at the end of last children of device_node. */ + device_node_last_descendant->allnext = next_node; + } + else + { + /* Now plug next_node at the end of device_node. */ + device_node->allnext = next_node; + } + + return 0; +} + /* Basic sanity check for the dtbo tool stack provided to Xen. */ static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) { @@ -148,6 +233,79 @@ static unsigned int overlay_node_count(void *fdto) return num_overlay_nodes; } +/* + * overlay_get_nodes_info will get full name with path for all the nodes which + * are in one level of __overlay__ tag. This is useful when checking node for + * duplication i.e. dtbo tries to add nodes which already exists in device tree. + */ +static int overlay_get_nodes_info(const void *fdto, char ***nodes_full_path, + unsigned int num_overlay_nodes) +{ + int fragment; + + *nodes_full_path = xzalloc_bytes(num_overlay_nodes * sizeof(char *)); + + if ( *nodes_full_path == NULL ) + return -ENOMEM; + + fdt_for_each_subnode(fragment, fdto, 0) + { + int target; + int overlay; + int subnode; + const char *target_path; + + target = fdt_overlay_target_offset(device_tree_flattened, fdto, + fragment, &target_path); + if ( target < 0 ) + return target; + + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + fdt_for_each_subnode(subnode, fdto, overlay) + { + const char *node_name = NULL; + int node_name_len; + unsigned int target_path_len = strlen(target_path); + unsigned int node_full_name_len; + unsigned int node_num = 0; + + node_name = fdt_get_name(fdto, subnode, &node_name_len); + + if ( node_name == NULL ) + return node_name_len; + + /* + * Magic number 2 is for adding '/'. This is done to keep the + * node_full_name in the correct full node name format. + */ + node_full_name_len = target_path_len + node_name_len + 2; + + (*nodes_full_path)[node_num] = xmalloc_bytes(node_full_name_len); + + if ( (*nodes_full_path)[node_num] == NULL ) + return -ENOMEM; + + memcpy((*nodes_full_path)[node_num], target_path, target_path_len); + + (*nodes_full_path)[node_num][target_path_len] = '/'; + + memcpy((*nodes_full_path)[node_num] + target_path_len + 1, + node_name, node_name_len); + + (*nodes_full_path)[node_num][node_full_name_len - 1] = '\0'; + + node_num++; + } + } + + return 0; +} + static int handle_remove_irq_iommu(struct dt_device_node *device_node) { int rc = 0; @@ -367,6 +525,322 @@ out: return rc; } +/* + * Handles IRQ and IOMMU mapping for the overlay_node and all descendants of the + * overlay_nodes. + */ +static int handle_add_irq_iommu(struct domain *d, + struct dt_device_node *overlay_node) +{ + int rc; + unsigned int naddr, i, len; + uint64_t addr, size; + struct dt_device_node *np; + + /* First let's handle the interrupts. */ + rc = handle_device_interrupts(d, overlay_node, false); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Interrupt failed\n"); + return rc; + } + + /* Check if iommu property exists. */ + if ( dt_get_property(overlay_node, "iommus", &len) ) + { + + /* Add device to IOMMUs. */ + rc = iommu_add_dt_device(overlay_node); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(overlay_node)); + return rc; + } + } + + /* Set permissions. */ + naddr = dt_number_of_address(overlay_node); + + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(overlay_node), false, naddr); + + /* Give permission for map MMIOs */ + for ( i = 0; i < naddr; i++ ) + { + /* + * For now, we skip_mapping which means it will only permit iomem access + * to hardware_domain using iomem_permit_access() but will never map as + * map_range_p2mt() will not be called. + */ + struct map_range_data mr_data = { .d = d, + .p2mt = p2m_mmio_direct_c, + .skip_mapping = true }; + + rc = dt_device_get_address(overlay_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(overlay_node)); + return rc; + } + + rc = map_range_to_domain(overlay_node, addr, size, &mr_data); + if ( rc ) + return rc; + } + + /* Map IRQ and IOMMU for overlay_node's children. */ + for ( np = overlay_node->child; np != NULL; np = np->sibling) + { + rc = handle_add_irq_iommu(d, np); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + } + + return rc; +} + +/* + * Adds device tree nodes under target node. + * We use tr->dt_host_new to unflatten the updated device_tree_flattened. This + * is done to avoid the removal of device_tree generation, iomem regions mapping + * to hardware domain done by handle_node(). + */ +static long handle_add_overlay_nodes(void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc, j, i; + struct dt_device_node *overlay_node, *prev_node, *next_node; + struct domain *d = hardware_domain; + struct overlay_track *tr = NULL; + char **nodes_full_path = NULL; + unsigned int new_fdt_size; + + tr = xzalloc(struct overlay_track); + if ( tr == NULL ) + return -ENOMEM; + + new_fdt_size = fdt_totalsize(device_tree_flattened) + + fdt_totalsize(overlay_fdt); + + tr->fdt = xzalloc_bytes(new_fdt_size); + if ( tr->fdt == NULL ) + { + xfree(tr); + return -ENOMEM; + } + + tr->num_nodes = overlay_node_count(overlay_fdt); + if ( tr->num_nodes == 0 ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + tr->nodes_address = xzalloc_bytes(tr->num_nodes * sizeof(unsigned long)); + if ( tr->nodes_address == NULL ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + { + xfree(tr->nodes_address); + xfree(tr->fdt); + xfree(tr); + return rc; + } + + /* + * Keep a copy of overlay_fdt as fdt_overlay_apply will change the input + * overlay's content(magic) when applying overlay. + */ + tr->overlay_fdt = xzalloc_bytes(overlay_fdt_size); + if ( tr->overlay_fdt == NULL ) + { + xfree(tr->nodes_address); + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + memcpy(tr->overlay_fdt, overlay_fdt, overlay_fdt_size); + + spin_lock(&overlay_lock); + + memcpy(tr->fdt, device_tree_flattened, + fdt_totalsize(device_tree_flattened)); + + /* Open tr->fdt with more space to accommodate the overlay_fdt. */ + fdt_open_into(tr->fdt, tr->fdt, new_fdt_size); + + /* + * overlay_get_nodes_info is called to get the node information from dtbo. + * This is done before fdt_overlay_apply() because the overlay apply will + * erase the magic of overlay_fdt. + */ + rc = overlay_get_nodes_info(overlay_fdt, &nodes_full_path, + tr->num_nodes); + if ( rc ) + { + printk(XENLOG_ERR "Getting nodes information failed with error %d\n", + rc); + goto err; + } + + rc = fdt_overlay_apply(tr->fdt, overlay_fdt); + if ( rc ) + { + printk(XENLOG_ERR "Adding overlay node failed with error %d\n", rc); + goto err; + } + + /* + * Check if any of the node already exists in dt_host. If node already exits + * we can return here as this overlay_fdt is not suitable for overlay ops. + */ + for ( j = 0; j < tr->num_nodes; j++ ) + { + overlay_node = dt_find_node_by_path(nodes_full_path[j]); + if ( overlay_node != NULL ) + { + printk(XENLOG_ERR "node %s exists in device tree\n", + nodes_full_path[j]); + rc = -EINVAL; + goto err; + } + } + + /* Unflatten the tr->fdt into a new dt_host. */ + unflatten_device_tree(tr->fdt, &tr->dt_host_new); + + for ( j = 0; j < tr->num_nodes; j++ ) + { + dt_dprintk("Adding node: %s\n", nodes_full_path[j]); + + /* Find the newly added node in tr->dt_host_new by it's full path. */ + overlay_node = device_tree_find_node_by_path(tr->dt_host_new, + nodes_full_path[j]); + if ( overlay_node == NULL ) + { + dt_dprintk("%s node not found\n", nodes_full_path[j]); + rc = -EFAULT; + goto remove_node; + } + + /* + * Find previous and next node to overlay_node in dt_host_new. We will + * need these nodes to fix the dt_host_new mapping. When overlay_node is + * take out of dt_host_new tree and added to dt_host, link between + * previous node and next_node is broken. We will need to refresh + * dt_host_new with correct linking for any other overlay nodes + * extraction in future. + */ + dt_for_each_device_node(tr->dt_host_new, prev_node) + if ( prev_node->allnext == overlay_node ) + break; + + next_node = dt_find_next_node(tr->dt_host_new, overlay_node); + + read_lock(&dt_host->lock); + + /* Add the node to dt_host. */ + rc = dt_overlay_add_node(overlay_node, overlay_node->parent->full_name); + if ( rc ) + { + read_unlock(&dt_host->lock); + + /* Node not added in dt_host. */ + goto remove_node; + } + + read_unlock(&dt_host->lock); + + prev_node->allnext = next_node; + + overlay_node = dt_find_node_by_path(overlay_node->full_name); + if ( overlay_node == NULL ) + { + /* Sanity check. But code will never come here. */ + ASSERT_UNREACHABLE(); + goto remove_node; + } + + rc = handle_add_irq_iommu(d, overlay_node); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + + /* Keep overlay_node address in tracker. */ + tr->nodes_address[j] = (unsigned long)overlay_node; + } + + INIT_LIST_HEAD(&tr->entry); + list_add_tail(&tr->entry, &overlay_tracker); + + spin_unlock(&overlay_lock); + + if ( nodes_full_path != NULL ) + { + for ( i = 0; i < tr->num_nodes && nodes_full_path[i] != NULL; + i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + return rc; + +/* + * Failure case. We need to remove the nodes, free tracker(if tr exists) and + * tr->dt_host_new. + */ +remove_node: + tr->num_nodes = j; + rc = remove_nodes(tr); + + if ( rc ) + { + /* If removing node fails, this may cause memory leaks. */ + printk(XENLOG_ERR "Removing node failed.\n"); + spin_unlock(&overlay_lock); + return rc; + } + +err: + spin_unlock(&overlay_lock); + + xfree(tr->dt_host_new); + xfree(tr->fdt); + xfree(tr->overlay_fdt); + xfree(tr->nodes_address); + + if ( nodes_full_path != NULL ) + { + for ( i = 0; i < tr->num_nodes && nodes_full_path[i] != NULL; + i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + xfree(tr); + + return rc; +} + long dt_sysctl(struct xen_sysctl_dt_overlay *op) { long ret; @@ -391,6 +865,14 @@ long dt_sysctl(struct xen_sysctl_dt_overlay *op) switch ( op->overlay_op ) { + case XEN_SYSCTL_DT_OVERLAY_ADD: + ret = handle_add_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + + if ( ret ) + xfree(overlay_fdt); + + break; + case XEN_SYSCTL_DT_OVERLAY_REMOVE: ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); xfree(overlay_fdt); From patchwork Tue Apr 11 19:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208109 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 8DD6CC77B72 for ; Tue, 11 Apr 2023 19:17:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519783.806848 (Exim 4.92) (envelope-from ) id 1pmJUV-0007ww-RZ; Tue, 11 Apr 2023 19:17:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519783.806848; Tue, 11 Apr 2023 19:17:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUV-0007uF-01; Tue, 11 Apr 2023 19:17:19 +0000 Received: by outflank-mailman (input) for mailman id 519783; Tue, 11 Apr 2023 19:17:16 +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 1pmJUR-0004DR-Q0 for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:15 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20606.outbound.protection.outlook.com [2a01:111:f400:7e8c::606]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 75bcde91-d89d-11ed-8611-37d641c3527e; Tue, 11 Apr 2023 21:17:13 +0200 (CEST) Received: from MW4PR04CA0041.namprd04.prod.outlook.com (2603:10b6:303:6a::16) by IA1PR12MB6529.namprd12.prod.outlook.com (2603:10b6:208:3a6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.34; Tue, 11 Apr 2023 19:17:08 +0000 Received: from CO1NAM11FT085.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::d0) by MW4PR04CA0041.outlook.office365.com (2603:10b6:303:6a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.40 via Frontend Transport; Tue, 11 Apr 2023 19:17:08 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT085.mail.protection.outlook.com (10.13.174.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.29 via Frontend Transport; Tue, 11 Apr 2023 19:17:08 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:07 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:06 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:06 -0500 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: 75bcde91-d89d-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YpIDKdgdf7yz2eJTAnEtGnIAAnvHfpj3300VLO6iafBOlyg9uKGtWR8AlWLxZXP7jXq9z+MOemUrxotW3ALnTbYqRKLYnv4hTlBU7fOiISFawFTn2sfZGHNIb/LaE9ZO2I+2Qd/HNcuwn5+M8fnxdXlS6Bqmzr3N6eCnwFV/c9YZRm82uhULvb8h7wuS9Mip6Y5DUmuTbpTPaJGax/zVmWaporPWDtZGvPYZXRhakfjvF5Glz2cx6XgfjW78lAGD/6ddcqxVFNiG3vicbmGg0mYIVHVd7jMXYOiGlYnApFw9Vr1UlR226LBQIzbrDZb7A5rL6hhtY7hLB1EWpHlorQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nkwDgQcNvE9UkGiRuGgnKgAIS4K7kLAxiI7Z7Wg7YaY=; b=F5OZE8ajLmHZ/3smvtrG3B3WH5oV4QmrHteG/vHTRllwu508EHSaQPST7gJiFbgHoDWf/e2BCweqleNSWP9MHT+GLdqcgZK5AiBmzlg2os1366qXKVcQlnDk4JdYYrnROOe5Sy2X4NZVgweQrs5LGeNMPwrv8/9f4U0UI7nyceUS39HZ6pA7+XALE0/zSb90fv+KxfUmpme0YPQeuQrPeuVfI61ZaGeJM97fGAA/SZn+rC4m0cvg6C0lUtesgR/EQkCsDqHidnogKC/o+r6wpScV0HDwk2GrA1yn+zaL2Xc7m9py2DDfF9tBZfERXRPetcpYXqwXCxeV7y22lYa4UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nkwDgQcNvE9UkGiRuGgnKgAIS4K7kLAxiI7Z7Wg7YaY=; b=34B69AbRgoSes/U8YltA7jp1SIRw84uuhNt7TRQZNULohAXDZZhsPhgLOiVTgnRk+J/lfOOIctNDhuCdHAaPGqQfAc3uPDMpNjcUypQ3tyfJV2gzFGg9cZP7f0PTD/hRhQXzyre6jKZVAHVEzs9NDOUJMKcbR6jeo+riXyEmy8o= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][PATCH v5 15/17] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Tue, 11 Apr 2023 12:16:16 -0700 Message-ID: <20230411191636.26926-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT085:EE_|IA1PR12MB6529:EE_ X-MS-Office365-Filtering-Correlation-Id: 79fb94b7-2e1f-4cd8-dde2-08db3ac15800 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: osc+4KnrjY/eXHRp/c21nvn18/PBqzgrfrXWovfYXG3QrplR0MgbJ72hALFCiEcxPhk3QCSjzTFO0dTXS6yY9bt/J8GQaZ3WYGZnBX2YGioCcALoBjUowaD5pS+r/sLI+L2YN/4s9DHwAJKZFS2+nLiYjL1EMqTc6AHTqNHVpeHyOcIaMNldU5M5EzDaASxUhO3oCEUMTi96Ba4RbWsjp3sMkNFeeKj7mdIpNg39NVoQtJJrexrczJ3CXJ4N5k3KSt8jbO0kW511tYq5p+Ahe7LLGnRU0SMi7baInhIHt0mb5n2gFKkRFvd0ht9LB96tkW4dWRFp3QKStHnhBh7nZG/l8PXpbqpgzp4viFw2WKasPQ5v0VkIlSn0xAafRSR/qj3De+tPh/fTVyxfhRntQdkTvcpxMSsXaIHjID7Nyxx24+li9JVuGCxeXyewaEMKOsrFzaQ4y+oj7CslTKxiL9D0SR+uWSi/EfyxI8TfNgnalPhnHrEZzPQOsBKxFrh0eaXeS/MW13vx6/MePibxA9oju6iZnUa+Hc80Zf2Dr5VbNvLe7Tl+P13UgrnjzYNyI9vQS+oO0EdP89r4GuGuwIdysUR9FW1yxvmTteTro8D60MVMkOZyS/XwStAp5xf8DPld7jEQcQpzt8I5BHTNI+rEq3SpHSmv7VEwN27rRCI+IUMoActsf1te3hUn69CJxWUpjJw0GHVSd/eNq7wywPqJvAYdGBddDOaD8uiSerCTHaw/TBAANLwczdGUStdu X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(39860400002)(396003)(346002)(451199021)(40470700004)(46966006)(36840700001)(40460700003)(70206006)(4326008)(478600001)(8676002)(54906003)(41300700001)(316002)(70586007)(6916009)(86362001)(36756003)(47076005)(2616005)(336012)(26005)(1076003)(426003)(6666004)(5660300002)(44832011)(2906002)(82310400005)(40480700001)(8936002)(356005)(82740400003)(186003)(81166007)(36860700001)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:08.1201 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79fb94b7-2e1f-4cd8-dde2-08db3ac15800 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT085.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6529 xc_dt_overlay() sends the device tree binary overlay, size of .dtbo and overlay operation type i.e. add or remove to xen. Signed-off-by: Vikram Garhwal --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 05967ecc92..b932589c8d 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2637,6 +2637,11 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +#if defined(__arm__) || defined(__aarch64__) +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op); +#endif + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libs/ctrl/Makefile.common b/tools/libs/ctrl/Makefile.common index 0a09c28fd3..247afbe5f9 100644 --- a/tools/libs/ctrl/Makefile.common +++ b/tools/libs/ctrl/Makefile.common @@ -24,6 +24,7 @@ OBJS-y += xc_hcall_buf.o OBJS-y += xc_foreign_memory.o OBJS-y += xc_kexec.o OBJS-y += xc_resource.o +OBJS-$(CONFIG_ARM) += xc_dt_overlay.o OBJS-$(CONFIG_X86) += xc_psr.o OBJS-$(CONFIG_X86) += xc_pagetab.o OBJS-$(CONFIG_Linux) += xc_linux.o diff --git a/tools/libs/ctrl/xc_dt_overlay.c b/tools/libs/ctrl/xc_dt_overlay.c new file mode 100644 index 0000000000..202fc906f4 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,48 @@ +/* + * + * Device Tree Overlay functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op) +{ + int err; + DECLARE_SYSCTL; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + sysctl.cmd = XEN_SYSCTL_dt_overlay; + sysctl.u.dt_overlay.overlay_op = overlay_op; + sysctl.u.dt_overlay.overlay_fdt_size = overlay_fdt_size; + + set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err = do_sysctl(xch, &sysctl)) != 0 ) + PERROR("%s failed", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} From patchwork Tue Apr 11 19:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208131 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 168CBC77B73 for ; Tue, 11 Apr 2023 19:20:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519861.806993 (Exim 4.92) (envelope-from ) id 1pmJX4-00019e-2w; Tue, 11 Apr 2023 19:19:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519861.806993; Tue, 11 Apr 2023 19:19:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJX3-00017T-Q5; Tue, 11 Apr 2023 19:19:57 +0000 Received: by outflank-mailman (input) for mailman id 519861; Tue, 11 Apr 2023 19:19:56 +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 1pmJUR-0004Ta-Vq for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:15 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20615.outbound.protection.outlook.com [2a01:111:f400:7eaa::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 76edfa86-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:14 +0200 (CEST) Received: from BN9P221CA0020.NAMP221.PROD.OUTLOOK.COM (2603:10b6:408:10a::32) by BY5PR12MB4322.namprd12.prod.outlook.com (2603:10b6:a03:20a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:11 +0000 Received: from BN8NAM11FT113.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10a:cafe::eb) by BN9P221CA0020.outlook.office365.com (2603:10b6:408:10a::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38 via Frontend Transport; Tue, 11 Apr 2023 19:17:10 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT113.mail.protection.outlook.com (10.13.176.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.29 via Frontend Transport; Tue, 11 Apr 2023 19:17:10 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:07 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 12:17:07 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:07 -0500 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: 76edfa86-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E8b/gdsp9EhJpwqEqWnSuieF6eymTrNe7CZCQIhNlXPnI9rbzaQ9wvtKtsjf8kP5i3R8URY/xdnXA4z5xpo6gHBEMWaxZykiVSxkS5IX9GPzCVHxrsWjarIu4i2Gai1OZW1LhqjKfQ3613hbwJtVwcHRkvsqrjZQMhmB1zr+3fL7NYtkYjn/O/lE3EtnFmvqnRpqZjW2HhvCO8FLrJFTjXGgjdfpCxF+iPM1wo6kyd6vUyRKgOAiYIQGCBzoEf0Qa6jDfyC4ZMVRSiSGssuo3vgTR2fcrzTK+5aDDiUAsT2QnfwW7VVz06WpZOzG8MrZh1Rzisa1hHvAHTmyd6+Ukw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=91E2KEtRfiC4xks88DcPT08G46pT034ykx3UwRRlezk=; b=nxIqwyEEBoGjZ2Kuiet6/zxQ1rXzFTD9+Tb8gozYJ/K69DjIujomDliSsWjN6KFcbMnN2aGkwTczNRgYS6wjhAw1GVWvCHbB877FDdlw/Z7ryiq0f0E0TkFr6zwbr6c+9/31vEwBGNPKAdGpMRl/1MRnkUrrkz2ExOW5z/Z0zUwocZDZe/bCYvRT+gZkSJQEFXS9Co2Di9Fi9PdJNEPQh4Q9FWsxvw/v6dOeJyMpOK92Qi76t4Up2UXXyPumbKQtuUsjFySgj4hkfiGchNgMjtqJzNIDEQ6BlcddYezacJLktwxN2ZYOhv3OVqVhnjwCzVsVvyy5irVapGD5gnheKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=91E2KEtRfiC4xks88DcPT08G46pT034ykx3UwRRlezk=; b=Mlr/+9OeakKs1WY2xZ18xA0mf8IJHjFeJSeRCQ20Q0zD8LVeRq1TGn30xKGU8oa4JxImKkmgn4JGZaMnjvON9eZpaV/sVxo6PY/uIkYeMQfwhCSOKw8PW/xN+uEztqYsTT2xIFp0708WEh0TgXAcyESUMJ/qgIrlxY3WqsNsi6o= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][PATCH v5 16/17] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Tue, 11 Apr 2023 12:16:17 -0700 Message-ID: <20230411191636.26926-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT113:EE_|BY5PR12MB4322:EE_ X-MS-Office365-Filtering-Correlation-Id: f399bca7-e537-444f-ca75-08db3ac15925 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K+t5V2+TAUOZSEpGSwWXK//7mVQ+/eyBcdLVEKdtEN4WY/OiGfcf1/gyhYIYcIO+xc2Z7SKl80+536Xeh5lp8rzwgmEG+EG1jTi+Dc0f7A5bykEp6HZNuGr4lWbKv/EtVCJdoFEo8wFwiEixU7By7P0fVXx77hwcPYNUCbnNTvhi4G3SB0PBW/wO19rtokte+XM11+gBEn3zZLSuFoIrdn97DHMFYsLdHHXCNCittTwO1WBOKmJPPZWZG6KA7wHnG8RYBi22flUwZQtwFON5Hv6xc2GS+LmOAlQsq3MSkv6Et51WAhgS6vECFMCqK+g7NSO5gvOm5emZJmtZTbipCt/XJ/VfOBh4Oa0djPeXy7z7gAgQqYxYVbz7N0Nuv3zzlGhZGDoQHxYkDAj4MNPHjlLD2z2CO2u/I8yj5k9ensKm4kjHEvBsvwLu2yiDG2oOYcvP7DfwpkT3fzXLKr1X6wKEXFe6tZv9rv5pz9WAzKXzusNAXLtYbtLK98MfTMptlzToh300Tn8FXSC3hHdECNcZfnPYVizzo/ogVgkdudl1bnIT1gI2jcjL7rKGZEXwY6i1IcLpLD37kdpYHv8szq26znZyba7r1Ca3/pdwXujCrw2C6froyU9xQXa4UdpI7Fh86Axdin70rTa6Hnd/Uv7KoVvjilC8Mzrj+v/lshuDw2ue+66wdjmcpghqxa2/+reQkMaVbByvXO+5tG6+1jiyC12STT/1S0UlEImC/76aPg8EpW7OH3jfEVSOg3NG X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(376002)(346002)(39860400002)(396003)(451199021)(36840700001)(46966006)(40470700004)(8936002)(5660300002)(44832011)(82310400005)(41300700001)(70206006)(70586007)(40460700003)(4326008)(8676002)(6916009)(316002)(2906002)(478600001)(54906003)(6666004)(36756003)(86362001)(40480700001)(1076003)(26005)(2616005)(336012)(426003)(186003)(356005)(81166007)(82740400003)(47076005)(36860700001)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:10.1336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f399bca7-e537-444f-ca75-08db3ac15925 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT113.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4322 Signed-off-by: Vikram Garhwal --- tools/include/libxl.h | 11 +++++ tools/libs/light/Makefile | 3 ++ tools/libs/light/libxl_dt_overlay.c | 71 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tools/libs/light/libxl_dt_overlay.c diff --git a/tools/include/libxl.h b/tools/include/libxl.h index cfa1a19131..1c5e8abaae 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -250,6 +250,12 @@ */ #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 +#if defined(__arm__) || defined(__aarch64__) +/** + * This means Device Tree Overlay is supported. + */ +#define LIBXL_HAVE_DT_OVERLAY 1 +#endif /* * libxl_domain_build_info has device_model_user to specify the user to * run the device model with. See docs/misc/qemu-deprivilege.txt. @@ -2453,6 +2459,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); void libxl_device_pci_list_free(libxl_device_pci* list, int num); +#if defined(__arm__) || defined(__aarch64__) +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay, + uint32_t overlay_size, uint8_t overlay_op); +#endif + /* * Turns the current process into a backend device service daemon * for a driver domain. diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 96daeabc47..563a1e8d0a 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -112,6 +112,9 @@ OBJS-y += _libxl_types.o OBJS-y += libxl_flask.o OBJS-y += _libxl_types_internal.o +# Device tree overlay is enabled only for ARM architecture. +OBJS-$(CONFIG_ARM) += libxl_dt_overlay.o + ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL += $(LIBNL3_CFLAGS) endif diff --git a/tools/libs/light/libxl_dt_overlay.c b/tools/libs/light/libxl_dt_overlay.c new file mode 100644 index 0000000000..a6c709a6dc --- /dev/null +++ b/tools/libs/light/libxl_dt_overlay.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" +#include +#include + +static int check_overlay_fdt(libxl__gc *gc, void *fdt, size_t size) +{ + int r; + + if (fdt_magic(fdt) != FDT_MAGIC) { + LOG(ERROR, "Overlay FDT is not a valid Flat Device Tree"); + return ERROR_FAIL; + } + + r = fdt_check_header(fdt); + if (r) { + LOG(ERROR, "Failed to check the overlay FDT (%d)", r); + return ERROR_FAIL; + } + + if (fdt_totalsize(fdt) > size) { + LOG(ERROR, "Overlay FDT totalsize is too big"); + return ERROR_FAIL; + } + + return 0; +} + +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay_dt, uint32_t overlay_dt_size, + uint8_t overlay_op) +{ + int rc; + int r; + GC_INIT(ctx); + + if (check_overlay_fdt(gc, overlay_dt, overlay_dt_size)) { + LOG(ERROR, "Overlay DTB check failed"); + rc = ERROR_FAIL; + goto out; + } else { + LOG(DEBUG, "Overlay DTB check passed"); + rc = 0; + } + + r = xc_dt_overlay(ctx->xch, overlay_dt, overlay_dt_size, overlay_op); + + if (r) { + LOG(ERROR, "%s: Adding/Removing overlay dtb failed.", __func__); + rc = ERROR_FAIL; + } + +out: + GC_FREE; + return rc; +} + From patchwork Tue Apr 11 19:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13208110 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 ACC3AC77B6F for ; Tue, 11 Apr 2023 19:17:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.519782.806842 (Exim 4.92) (envelope-from ) id 1pmJUV-0007pa-9l; Tue, 11 Apr 2023 19:17:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 519782.806842; Tue, 11 Apr 2023 19:17:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pmJUU-0007iE-Ba; Tue, 11 Apr 2023 19:17:18 +0000 Received: by outflank-mailman (input) for mailman id 519782; Tue, 11 Apr 2023 19:17:15 +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 1pmJUQ-0004Ta-Vc for xen-devel@lists.xenproject.org; Tue, 11 Apr 2023 19:17:14 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eae::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 75d4f138-d89d-11ed-b21e-6b7b168915f2; Tue, 11 Apr 2023 21:17:13 +0200 (CEST) Received: from MW4PR04CA0033.namprd04.prod.outlook.com (2603:10b6:303:6a::8) by SA0PR12MB4559.namprd12.prod.outlook.com (2603:10b6:806:9e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.38; Tue, 11 Apr 2023 19:17:09 +0000 Received: from CO1NAM11FT085.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::c1) by MW4PR04CA0033.outlook.office365.com (2603:10b6:303:6a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.28 via Frontend Transport; Tue, 11 Apr 2023 19:17:09 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT085.mail.protection.outlook.com (10.13.174.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6298.29 via Frontend Transport; Tue, 11 Apr 2023 19:17:09 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:08 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 11 Apr 2023 14:17:08 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 11 Apr 2023 14:17:08 -0500 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: 75d4f138-d89d-11ed-b21e-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DTml8cnkj84ksqDvwmgLUZtR0xNNi8j8gmyZZ50NnJf6XmYk4HgUz7aoClfr4FK1jkfk4g7plQg+djTV75FFKMdPB0MHeFeu0W4d0eHgep/Ape8kzIMtibQyKSlQ2HcwCfkhZzQ61cG3MKquXcpIboKoRpvhINdRYEs+179ympYaKf2fbqF8cKSx9vE423zovjpRNHKf8rT7ooFcREz351MXGRmnGy6V3YM6zUOi5R2bLLuPmsJUV1ZOd6WLqzdMTidyptnQAZ1a+SAT06XcG4KIgsiHhXXdlILV4juyOxujiRVVO0R3sE+nX8flJHmSfRO67haMXeHYRNxVuNkp7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W8ANf04rvVBwwTVoSmk1wMh7BnV4jbgpw3PgliDnkIY=; b=HnPfgKNaLFifYRiXm89CjxS4F6TXWN/XgNhsUBNeY+VHE1YVDqBxhjNCQQL9rrOaT2XRtjgRmxCcikoVKx8LaB9Nq4VyTfo4SF/u9kg79qz3XWzXcmnK15+nx4p9iJf2zR5U/9VawbiiPi4Z5SGyGvtbLAqpw0w0GhF0M6caGbWoLlFL5cc9AGmrKvApx63v4pC5aQMtmIDvV66olDZ6NDoOZSfW/jgb4Xt+R4ldKtWAwvLbNW+VuVEhubTNm4sw1xwK+i4JH+RcZC1LwUr+euvvnhE8w4TQmOoN4wA6g1Bup0r8nhtRTHJ4UaCYiJ8oJsInS9QTJaAyt/2IDafrXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W8ANf04rvVBwwTVoSmk1wMh7BnV4jbgpw3PgliDnkIY=; b=rkrcfNVyCeJcZHMV3Mza5hd29yd4W4yc4A3VEwlix84TV47Qvdg/J/YD/UzPLoW9asNTunX/Xp1eeCtMc+rad/aRjHlgyONX5dtS7Tsk6n5H+vz4iSpN/C0apzzGMBWgTn55O00uFgxIx77ez6Pq5BTvsFNeOEPLg5z4cgq0ftM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , Vikram Garhwal , Wei Liu , Anthony PERARD Subject: [XEN][PATCH v5 17/17] tools/xl: Add new xl command overlay for device tree overlay support Date: Tue, 11 Apr 2023 12:16:18 -0700 Message-ID: <20230411191636.26926-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230411191636.26926-1-vikram.garhwal@amd.com> References: <20230411191636.26926-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT085:EE_|SA0PR12MB4559:EE_ X-MS-Office365-Filtering-Correlation-Id: e028d683-9b8b-4468-33f4-08db3ac158bd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: acc5R9HxREvMwAXUxJDUDLP/yKj+S5WJ6zRQIH7J2xdWmf3Jqiu7x0lcP9LSJvCgCr61Qk9r2NXH5f2ToI2cyrpaUf67UPfRtH+cqDrbkgcuvmndpY8kp99iOxQzTV1MwgCXPdcXVFz8AqacI55kDNTUEpxempIAws7UXihOK5HmtDyLJfKyUMrlGm+W+kSv9q7RCCboOcVU2zwbraBLJ/0S+2kv0PIBQQZK8YFeNFVBOaJipQSAHQvdYRdtf5rXVjWEGhawFasc9dkrtYACET2+YgH6HTx3qyGDJU78m1Hu94wiaswrAQl1PdxBrodzHvqioimRUT8hz7VWmUOM9gA5iHF17CLEjxD9XDCeES0fvA4ZGBxWwI3uRoHYiCw0hniX07Rpwu7kM9Ce0cZyFL0a22B/DWq2394y70mdK5twYuNIKSb5TrZHA9bsEcOq6xrTzbrZPDSXEDTL33u6+yH5VG6Ut3qdKkOPbeNxkSY2S7bVPMPWJ0QsunegqlGFmg1GXz3QMTj+7WHEEJ4Ycwp96sfqQnX0a3b3xCSimkkQe3OwPzn5xpQtaFKyW8zg9UykK3EN/efvjcUGcsr6qxgLBnSjYk0k/XXVX8TqWHZAafajz+PAMfJc+aRFCDzRABFLsJdzfmHz+XhqKWdWA1DifLmYYxeIF5IRWUthWjHyOK6pCs9V561lQJMWq3rmDuoT29l5fO/6WKMwB/z54sksBswB4M1iehdjS67IFk8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199021)(46966006)(40470700004)(36840700001)(478600001)(40460700003)(40480700001)(47076005)(83380400001)(36756003)(82740400003)(356005)(81166007)(426003)(86362001)(2616005)(336012)(36860700001)(6666004)(44832011)(2906002)(316002)(1076003)(186003)(5660300002)(26005)(54906003)(41300700001)(8936002)(6916009)(82310400005)(8676002)(70206006)(70586007)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 19:17:09.3544 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e028d683-9b8b-4468-33f4-08db3ac158bd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT085.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4559 Signed-off-by: Vikram Garhwal --- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 6 +++++ tools/xl/xl_vmcontrol.c | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 72538d6a81..a923daccd3 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -138,6 +138,7 @@ int main_shutdown(int argc, char **argv); int main_reboot(int argc, char **argv); int main_list(int argc, char **argv); int main_vm_list(int argc, char **argv); +int main_dt_overlay(int argc, char **argv); int main_create(int argc, char **argv); int main_config_update(int argc, char **argv); int main_button_press(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index ccf4d83584..db0acff62a 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -630,6 +630,12 @@ const struct cmd_spec cmd_table[] = { "Issue a qemu monitor command to the device model of a domain", " ", }, + { "dt-overlay", + &main_dt_overlay, 0, 1, + "Add/Remove a device tree overlay", + "add/remove <.dtbo>" + "-h print this help\n" + }, }; const int cmdtable_len = ARRAY_SIZE(cmd_table); diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 5518c78dc6..de56e00d8b 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1265,6 +1265,58 @@ int main_create(int argc, char **argv) return 0; } +int main_dt_overlay(int argc, char **argv) +{ + const char *overlay_ops = NULL; + const char *overlay_config_file = NULL; + void *overlay_dtb = NULL; + int rc; + uint8_t op; + int overlay_dtb_size = 0; + const int overlay_add_op = 1; + const int overlay_remove_op = 2; + + if (argc < 2) { + help("dt_overlay"); + return EXIT_FAILURE; + } + + overlay_ops = argv[1]; + overlay_config_file = argv[2]; + + if (strcmp(overlay_ops, "add") == 0) + op = overlay_add_op; + else if (strcmp(overlay_ops, "remove") == 0) + op = overlay_remove_op; + else { + fprintf(stderr, "Invalid dt overlay operation\n"); + return EXIT_FAILURE; + } + + if (overlay_config_file) { + rc = libxl_read_file_contents(ctx, overlay_config_file, + &overlay_dtb, &overlay_dtb_size); + + if (rc) { + fprintf(stderr, "failed to read the overlay device tree file %s\n", + overlay_config_file); + free(overlay_dtb); + return ERROR_FAIL; + } + } else { + fprintf(stderr, "overlay dtbo file not provided\n"); + return ERROR_FAIL; + } + + rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + + free(overlay_dtb); + + if (rc) + return EXIT_FAILURE; + + return rc; +} /* * Local variables: * mode: C