From patchwork Wed Dec 7 06:15:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066656 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 B87AAC47089 for ; Wed, 7 Dec 2022 06:16:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455824.713414 (Exim 4.92) (envelope-from ) id 1p2niy-0006vt-RS; Wed, 07 Dec 2022 06:16:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455824.713414; Wed, 07 Dec 2022 06:16: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 1p2niy-0006vm-Oa; Wed, 07 Dec 2022 06:16:08 +0000 Received: by outflank-mailman (input) for mailman id 455824; Wed, 07 Dec 2022 06:16: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 1p2nix-0006dw-EH for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:16:07 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [2a01:111:f400:7eae::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a127ef5c-75f6-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:16:05 +0100 (CET) Received: from DM6PR07CA0130.namprd07.prod.outlook.com (2603:10b6:5:330::22) by DM6PR12MB4960.namprd12.prod.outlook.com (2603:10b6:5:1bc::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:16:01 +0000 Received: from DS1PEPF0000E652.namprd02.prod.outlook.com (2603:10b6:5:330:cafe::8) by DM6PR07CA0130.outlook.office365.com (2603:10b6:5:330::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:16:01 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0000E652.mail.protection.outlook.com (10.167.18.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:16:00 +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; Wed, 7 Dec 2022 00:15:58 -0600 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, 6 Dec 2022 22:15:57 -0800 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; Wed, 7 Dec 2022 00:15:57 -0600 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: a127ef5c-75f6-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DYiug1ac1Tf1VuR2CXydiKM2Gk6ZFwmItFObYldMFHZdIfy/X/jfv3+SULDL8jSOkDXDnZ3U8Lnajz7KDD1hlbr+DG4sEjMUhE8/1hoBLZ30ZlvavyFDI4BDx9dZUCfuM9KoWQ7BxiWUsNVyDSipQmwGP0wuBUvyLYdU5SosMgqgTk2BztDy5nW72/KSef3l0Tj7lVLW5NzktGD3+WYl+yd3aEd1UzbC0UCAobEbEZ/2CQaSjHELD8tn5rZFz4WEqHr4O9RDY0GTA3nm75VHoB+NdOovPheNDafwj+5x5kDn4EkvRt+03052SR48WNTkvXU/1M/e9fkBJwRem+9elg== 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=DS/nF2bIfjgp31HI6UzUoMJVBvMsV8pu8GheBmaD6q4=; b=js01XpdZqv0bKHrDrgV7ZmbNTcq15BmxJtiAGII4XkzjTs1tEGziLgM0cfPm+fcRp9S69AE8lPtpo4RVkqf9nnIrghFsn2TGOIXb3QawbhIHF4QfkGCQ8jZkxVS23BlCa4L1Wm/WiliS2l5lbSDdQ3pj0lIdgo+xaP34WGgAebjoab8onwM1+WVFLN8VtWKO3DHXm2ZY2ngDy0LhPOALS486nuwuMZpSC7yZjs1ZJ47fTy1TarJXy1tbXc+fhTSV4nDs7LK28ZtVSGPXna3SPYy22Nnfe6TWYbJfiAfy1FOT9I3T6uQ7B+pne6if/bg8lZYE3TwM0DnGu9jL14ApjQ== 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=DS/nF2bIfjgp31HI6UzUoMJVBvMsV8pu8GheBmaD6q4=; b=WFlRl/7QwMrvV/rE3S7uJTjoqGUj/6QbOs1AudiAzHncPihGizaLhk/6vxOyG/UEMsQss6sKx1EDjNq4alPUXjwdIrAtXhjlWggUrqJJKY8nR+XtFJ8muTVFQPg7YVp3kBY9riME/L5mkJJsEwKSoymZ3PQ9YlHbyRX/gfkz/ZU= 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: , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][RFC PATCH v4 01/16] xen/arm/device: Remove __init from function type Date: Tue, 6 Dec 2022 22:15:22 -0800 Message-ID: <20221207061537.7266-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061537.7266-1-vikram.garhwal@amd.com> References: <20221207061537.7266-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E652:EE_|DM6PR12MB4960:EE_ X-MS-Office365-Filtering-Correlation-Id: 7884a8d5-e52b-445f-f0ec-08dad81a8317 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1iq7w3dl102B2XC1NS3jM5BQ9l6xtCEq/8YSqexstkAmySsAUsSQ8UHUmsc+rqUA2Hyiu9JS2GItmuoN3INeACCT21Fj0wNuGjE0KYAGeheJOzeUMGaQ30NjfvWcQuejjKXN76p2/iMwzYay7B5+fmS5JhEOXYRE+8u3s3MOt99xZE1YiYr1f8RG/cWTUQbwdg3VyBxu5GacqiwIa4hBROCjdY/vivy/pdikOWKsuISi2+/WpvwMlfZSaAdv6e9TZsXW3/7QB24oCZIxgIDG+eg14j1OW359W+Spn6NelM8bQJdc0TW2cdix9MpOGbIguVuiF/vrBQnRHGfkMDhPtExKsUZLOawkrugyDE4EDYKqBa90PuPxZm9NzqMbDLPLij+2wumaI50LuCbm4egoE1Qd19MHVM7Zp/uGQgvZoWLsKdu13K0pfHyihrv3FVNH6GLxmHEfiPp348YXbbq4KgsfPVYY3/HVL03kBqO/ilsVIUbYC1j6Gp4jQBizuO9qQMgvIY7gvk64MtMcT9gDiKGNCejkQGKJg235fPt9j28LoQIKOUeOXMv6ZiJRCHHFKVsd79GO9XciFmlxCIgGMCnl+2lmnIfgyR+XwXKAqcZ4Wp9+q0rMYOVqbOHLIbObXFBJO7t46/3nFwFUmeAkfL1LxEuYS2R0QZ8I1bsexwbgp/QS0i3WZbWfxzBkqWRYm51K4OgEGUKqlShqQJlHQtNGK3h6hc0OC2u1DQ9ZAWI= 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:(13230022)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199015)(46966006)(36840700001)(40470700004)(30864003)(2906002)(44832011)(41300700001)(82740400003)(478600001)(81166007)(40460700003)(356005)(82310400005)(4326008)(8676002)(86362001)(40480700001)(8936002)(5660300002)(47076005)(70206006)(36756003)(70586007)(426003)(54906003)(26005)(186003)(1076003)(336012)(2616005)(6916009)(6666004)(83380400001)(316002)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:16:00.5542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7884a8d5-e52b-445f-f0ec-08dad81a8317 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: DS1PEPF0000E652.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4960 Change function type of 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(), handle_device_interrupt() and map_range_to_domain() to device.c. unflatten_device_tree(): Add handling of memory allocation failure. 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 --- xen/arch/arm/device.c | 145 +++++++++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 142 ------------------------------ xen/arch/arm/include/asm/setup.h | 3 + xen/common/device_tree.c | 27 +++--- xen/include/xen/device_tree.h | 5 ++ 5 files changed, 170 insertions(+), 152 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 70cd6c1a19..d299c04e62 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include extern const struct device_desc _sdevice[], _edevice[]; extern const struct acpi_device_desc _asdevice[], _aedevice[]; @@ -84,6 +87,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 4fb5c20b13..acde8e714e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2229,41 +2229,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) @@ -2295,57 +2260,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 @@ -2373,62 +2287,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/setup.h b/xen/arch/arm/include/asm/setup.h index fdbf68aadc..ec050848aa 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -163,6 +163,9 @@ void device_tree_get_reg(const __be32 **cell, u32 address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); +int 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); diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 6c9712ab7b..6518eff9b0 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; @@ -2047,7 +2047,7 @@ static unsigned long __init 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 __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) +int 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,12 @@ static void __init __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 == 0 ) + { + printk(XENLOG_ERR "Cannot allocate memory for unflatten device tree\n"); + return -ENOMEM; + } + ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef); dt_dprintk(" unflattening %lx...\n", mem); @@ -2095,6 +2100,8 @@ static void __init __unflatten_device_tree(const void *fdt, *allnextp = NULL; dt_dprintk(" <- unflatten_device_tree()\n"); + + return 0; } static void dt_alias_add(struct dt_alias_prop *ap, @@ -2179,7 +2186,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 a28937d12a..bde46d7120 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -181,6 +181,11 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/** + * unflatten any device tree. + */ +int 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 Wed Dec 7 06:15:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066657 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 709C8C352A1 for ; Wed, 7 Dec 2022 06:16:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455827.713436 (Exim 4.92) (envelope-from ) id 1p2njF-0007da-Hh; Wed, 07 Dec 2022 06:16:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455827.713436; Wed, 07 Dec 2022 06:16:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2njF-0007dA-DB; Wed, 07 Dec 2022 06:16:25 +0000 Received: by outflank-mailman (input) for mailman id 455827; Wed, 07 Dec 2022 06:16:23 +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 1p2njD-0007Hl-Qi for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:16:23 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20624.outbound.protection.outlook.com [2a01:111:f400:7eaa::624]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id aaa68031-75f6-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:16:21 +0100 (CET) Received: from BN9PR03CA0760.namprd03.prod.outlook.com (2603:10b6:408:13a::15) by SJ0PR12MB5675.namprd12.prod.outlook.com (2603:10b6:a03:42d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:16:16 +0000 Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13a:cafe::a6) by BN9PR03CA0760.outlook.office365.com (2603:10b6:408:13a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:16:16 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.15 via Frontend Transport; Wed, 7 Dec 2022 06:16:16 +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; Wed, 7 Dec 2022 00:16:14 -0600 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, 6 Dec 2022 22:16:00 -0800 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; Wed, 7 Dec 2022 00:15:59 -0600 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: aaa68031-75f6-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cnTKUcW6EFX7valtywuUlqVjDGeonhx8XKMlsQvckoFrIOac3qVva9f2xA75yGqvekDLeMB+UP5lwaLIzDbgwXkLOguwuSBDDDQ+3ok3oMyX4xSv45ReaqEtMn/Op8Fhw4DYnrKfdqM8dJ/7J+KE3aS5QAmuxlajaU9gzslo95Ry8/iJnn+JBqX9VomHjhJDs9rQ5xqNZf1xyQBmMX5XCHOGuKDT7hvwkbASISjsqDySpILKwqT2wB5J4k0cer4eI37x3JRuX6ClvM6QO+ANW5jLr039vmdpl4zvPD9LfEKrl41v36LEXjX09DVZVupqr57V1JUqU0+djbWyMPySzQ== 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=EfET4ZlUmPQkBgdnYzJx7GKoPrXNKYIDQQVVWcgL9M0=; b=G/O8GechKu+S3MYny45KGB1nddhopjUpD0gyMoP1HfCpzAKR+/atVbwELb3gTGvRIZdGep5nQOIJh1KJAZUWehG/YmQebo7TdIa6v6TotaRcXHAbf4/i2W9/XXDH1mTilhSwOSXUCCvhj7HIoDXBrMxbSnBWvE7dkJV3SsVkT5FG0+zpCAzzCErm1EA2c+ImkSlYu8B6ndVDWAdUksS0RrHlO6U5/HBFBOyOenuKDiK/jum2aS9LWIDmjTfblxiqQqYUqtBmNAmIl5Zc5hU5oPaOoH2v19saek8ERu5Es1yUtIrZf4fbP0eU7aLHHQQvts9HDF5mBuv/sW2fttKUoQ== 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=EfET4ZlUmPQkBgdnYzJx7GKoPrXNKYIDQQVVWcgL9M0=; b=xyVu2ZM2/IeTdwnWMcjUWDwoBpv9RHRN6ZPVnYWJ3/Bz9N7frmFcx/M3M8VOVes0KOwmE8nyuz1Oolv0f3hiLDcgA7zjpjesSVRJg4YKUJArsZj/kIJzvFxre8sg5M/zs9CDusUf1MuaaDsz8qidwD0LDuseAIFj1GOwzJG92is= 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: , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][RFC PATCH v4 02/16] xen/arm: Add CONFIG_OVERLAY_DTB Date: Tue, 6 Dec 2022 22:15:23 -0800 Message-ID: <20221207061537.7266-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061537.7266-1-vikram.garhwal@amd.com> References: <20221207061537.7266-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT050:EE_|SJ0PR12MB5675:EE_ X-MS-Office365-Filtering-Correlation-Id: 76b09ed3-9a35-4e97-1382-08dad81a8c6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HHwkqMXL9Bat02fhRoEPr/Lp1aFUIFU2okWjUFTuiQJjqrxH5vNhOrJx4m8298uLdYlEV4ZPUo0hpWon3igkc9AzMAJAI3enwq/P3LvFB4arTgtrAiFdUgxVmfCbTpGcjpJqoqXQJk7dowX1g97zPuBfZMCPmieioaUOtOVwsmtEowcCfSS2O8OH0fosIgn7kM5se5Fhs9yPXgkT5+d9TnLDhS2AC9zjv380IFViuG04iochp84sp7X6ZCcnO06/m3RBZ8D2nOQsDeoaN+NP3LLDAhnwrHkP2KRrMlz3XPXNzPGE56sihcUFy1KmRSijFjbzsUkVSAmKzXGnvMh3ArIOo9QhJOePvHS5sYVRRU3UKoZWCRosATcKmWezUpKxfnWJLs3lB91hYlLydzIV242jWLKE1iVL9h7+teB7UWoQkZBjPqXlhs18YXKIgrDs6uuFPtYvK9tiOPOC+AAV6tIzLlS4oCATZ2IjwFIX+SLr/Sqjqo7FI7v7xWFuoB731ckVs7X4NCQI5kdSOeptu1VgnQKNbPsSai9tUAoRLVhMfbgygJfW1l98gAro1krSDDvD2uLI4cUpeZS0uiuOmAwTJW1AP7EUiw1BYKYYE6GVu3Fr4f8BQMLP0Rb/ZHVy55OL0gCSypqHG26u4WnG20H8pP7wkfysTxNSuqrKFMpWXbtNyHjST5SBZlzzashyLPrI68yISerj3tadSchm4CMufmXRLlt3lQ6KYtpuEco= 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:(13230022)(4636009)(39860400002)(346002)(376002)(396003)(136003)(451199015)(36840700001)(40470700004)(46966006)(81166007)(86362001)(36756003)(40480700001)(4326008)(40460700003)(478600001)(26005)(8676002)(5660300002)(6666004)(4744005)(41300700001)(8936002)(316002)(70586007)(6916009)(44832011)(70206006)(54906003)(2906002)(36860700001)(426003)(356005)(186003)(47076005)(2616005)(82740400003)(336012)(1076003)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:16:16.2454 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76b09ed3-9a35-4e97-1382-08dad81a8c6b 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: BN8NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5675 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 --- xen/arch/arm/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 1fe5faf847..ae2ebf1697 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -52,6 +52,11 @@ config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC +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 Wed Dec 7 06:15:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066658 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 DC01DC4708E for ; Wed, 7 Dec 2022 06:16:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455826.713424 (Exim 4.92) (envelope-from ) id 1p2njE-0007Ln-3l; Wed, 07 Dec 2022 06:16:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455826.713424; Wed, 07 Dec 2022 06:16:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2njE-0007Lg-12; Wed, 07 Dec 2022 06:16:24 +0000 Received: by outflank-mailman (input) for mailman id 455826; Wed, 07 Dec 2022 06:16:22 +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 1p2njC-0007Hl-Qb for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:16:22 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20614.outbound.protection.outlook.com [2a01:111:f400:7eaa::614]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id aa6642ed-75f6-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:16:21 +0100 (CET) Received: from BN9PR03CA0375.namprd03.prod.outlook.com (2603:10b6:408:f7::20) by SJ0PR12MB5407.namprd12.prod.outlook.com (2603:10b6:a03:3ac::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:16:18 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::a6) by BN9PR03CA0375.outlook.office365.com (2603:10b6:408:f7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:16:18 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.15 via Frontend Transport; Wed, 7 Dec 2022 06:16:17 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Wed, 7 Dec 2022 00:16:14 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 7 Dec 2022 00:16:03 -0600 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; Wed, 7 Dec 2022 00:16:02 -0600 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: aa6642ed-75f6-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RUqnlUKBpcbzFMIwKi5B2qTHIzC89kxejfaLTzD/Wo+c9WtuFob8hbGy5aPVnQj5kLcJ4XhIk9hxoLtfPWUa9DirDHnkvvsQcn03W9C61XPJOYsdInNEl0ivvKNWTeCyBNHDdWD4dty7MoKC7DmObPsiv9jaaGR5nW9PWRwxR4AKlIOwLONgCrizBMAryENGrsP0RgTSlQEq1dfE7ZTNhcYn5OcC8aFct/nbhp/kMlXb/v0yd6rG2ApBPWWe0nwYMdqmcSRKXNUtcQYMYB6PVIQpnFG7ZGpZxGOv31kqFFP9YPCWON70/hi+3vbuej0wA500zxIq+Wuz4YEw2nGyRA== 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=QdobsI7I1s2xg3QPC/xfjvXO6m4sMLz8hqEk31lxd+A=; b=IQqfNuzqbZLvYfoXeHu2BoSww1PPfyvpQx6p3dkSLDXBuBAXH9lObrRxImvcZHYzFNDUQlgM3V4BcFkkBP/yHg3nlyty19AvtFyMSBCR2XRW/p4UdIv1drZRjsxfyxWbWAKk4L9ZMIg6mxvEMQHM8EMQdpuxMYXTWHDMMA77+xfVrs5/JLGj5h4kw8ZZjmqjeEW19Sr8HlpDh016I9Umefb5JFKbWGo6Ux76a312oEUAffmP7l/zj1IdOHAyv5kzqQniQek13jT8TKODORJ9bgpOqLjeJSVjahIXkpWCQTD04Xc2DTsi2407g1VIs2LxXa11dAz9XYgTeRJ9f7RIeg== 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=QdobsI7I1s2xg3QPC/xfjvXO6m4sMLz8hqEk31lxd+A=; b=FORrxHQwYwLQqTiGzkJYtwluLXZM83TMwCoyzMufpf6FZGRAyLMajDaLI/fzhNszlYb5eW35jBPT2U45taOhGuEKjNLy0skbwziUUZWNb9ZisqnFC7t5afDnjjjKfC1pZplDWMWRMqoJ9bbaDg0BGMfEZopFpJAwtdK7L/bs5l4= 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: , , Subject: [XEN][RFC PATCH v4 03/16] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Tue, 6 Dec 2022 22:15:24 -0800 Message-ID: <20221207061537.7266-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061537.7266-1-vikram.garhwal@amd.com> References: <20221207061537.7266-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT009:EE_|SJ0PR12MB5407:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ae02cc4-7871-4517-2525-08dad81a8d2b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sqyht156BaGaeryzYwSQVhGTlUi5YiDKcSO3OF1rAqQOI+9ZXQe4dkw9wF1hGxz6RzQYjeasGTPtnrsljPoZ5WufjhyFBOsP9jX9Nl1gCA53ncRMcNVmYuJZtP7JiokQCMQz87tCK/ZNfId/bm6xn1+r4SzVEME+eoMAdlAegqdsVamUDOZlROtFT8Q2oeur3CwyADXC5m/1fA1PNeeueaYgqFga6i01SehJIuOrDEQuYngd0mu4kDYDUYFpKtaEMU8gOXMQxmO58WcyMYn1DD+3Dfq6Ht2OfGX/oebp+i0laDC//mNkB0SeiGqTx49uA+4cBMUSHqP3YbFhSbqEFvz0dWMpbOpwhw9E6W3J6M0BgBQeNThccZEM53I7ZRpSmhO/6AO3RZi9R6Bc+kaD84o5gQSeZ1FP70H+PLHayqMwJtqKJAieEfBlcjD+1Yt8k/2s0pFC/sesaMa2LEMGRFmcJVTQHzSj24JfZI4F01TeGLR2xz/34xAJq0X30Hg82uVgGVxYgTJ49pzTC0E7fdFsc6Thc4kCfkxPy5bL5cQd87cpymzOjAJibDGrfVUVJqVNjGKz00lLWae1+vfW7Gv53xUkPhqpgyMA9tyBgHzPnUr7o8gWYVuSPApoUI69dcx0mqa7ntgij4DzHiKHk1834WnTvMc4Lz9AWx0r/Yb30ZJaBbFJUkAK8BpyBHdOZw5V5jiq3Cu/tsUJtGALcR9kld/XTNal10vNN99ns9E= 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:(13230022)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199015)(46966006)(40470700004)(36840700001)(86362001)(36756003)(40460700003)(70206006)(82310400005)(40480700001)(186003)(41300700001)(1076003)(70586007)(336012)(44832011)(8676002)(8936002)(47076005)(4744005)(4326008)(426003)(2616005)(5660300002)(6916009)(54906003)(316002)(6666004)(478600001)(26005)(356005)(81166007)(82740400003)(83380400001)(2906002)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:16:17.5042 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ae02cc4-7871-4517-2525-08dad81a8d2b 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: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5407 This is done to access fdt library function which are required for adding device tree overlay nodes for dynamic programming of nodes. Acked-by: Julien Grall Signed-off-by: Vikram Garhwal --- 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 Wed Dec 7 06:15:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066659 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 07597C352A1 for ; Wed, 7 Dec 2022 06:16:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455838.713446 (Exim 4.92) (envelope-from ) id 1p2njZ-0008Tc-PY; Wed, 07 Dec 2022 06:16:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455838.713446; Wed, 07 Dec 2022 06:16:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2njZ-0008TU-Ma; Wed, 07 Dec 2022 06:16:45 +0000 Received: by outflank-mailman (input) for mailman id 455838; Wed, 07 Dec 2022 06:16:45 +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 1p2njY-0007Hl-Ui for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:16:45 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20612.outbound.protection.outlook.com [2a01:111:f400:7e88::612]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7b32493-75f6-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:16:43 +0100 (CET) Received: from DS7PR03CA0024.namprd03.prod.outlook.com (2603:10b6:5:3b8::29) by DM4PR12MB6208.namprd12.prod.outlook.com (2603:10b6:8:a5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:16:40 +0000 Received: from DS1PEPF0000E64E.namprd02.prod.outlook.com (2603:10b6:5:3b8:cafe::2b) by DS7PR03CA0024.outlook.office365.com (2603:10b6:5:3b8::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:16:40 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0000E64E.mail.protection.outlook.com (10.167.18.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:16:39 +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; Wed, 7 Dec 2022 00:16:18 -0600 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, 6 Dec 2022 22:16:17 -0800 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; Wed, 7 Dec 2022 00:16:17 -0600 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: b7b32493-75f6-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DQr3GLA+FDgw6wbm/yN9MUDG2l1ZRJDz3KFWJER+1rrW8BFIYIfBgQuz2trTwvXPjKrUtg4W50N20OHsJolgO2b5kcL5p0WPsVSFM8o0gbT95+yYOFKYmaC5BIJ3VHbeiJlgudJcUG7mUi0tcwtaabKwBqDJtdIbCOe735RimX8ANRmIlolCo9x2Whi3NkDr7Jkk2NNiO04IQ+vvZEzkHNVBqGPtj7ZUbzIR8nAZkrVkF+v/HNwYcesk6jRszFUTD3WjJ38U6XKcVuhLcbU/Ln2MjHC75weEpCPNpmXAwyTvoSnqCo+gp+XOwGsu4IX9SlZjpk9/+w68PuqqyDU1WQ== 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=g6KtYvddfVW+GCdGKl8QzCqK7RXkmTVgJchJNwSNoN4=; b=AzESfRdXMJXQUfcbbVF/Dmr0G/7pO6ABftIMJN/6oFWC2iQFxrPsBEznTAiKjhJXU16aGNTx2JlLKx2ZjYAO5p7fiCPYiMEfXx80hA/0gdV/+V7Sux3c6LLfQ2Dm7ONgZDFj0eSwu+tBurMv3ba066ZXBGVaZnpi4S2JbVlcPqYe1ExkIjoUKithrONFRePIPK17+W4tA+tSMlFZfxNgVeD6xqCMXibIb1SvZj/xcEd1bfACsOu0G1thQ2BktBe6fxDlsdBjXH2YyCNgiLVsRGFTXEkTC9ELYK9PsxRWdkbOMyIL9MofQyj+WtlQCULlc1fPZ9CKZ247hZfyk5I/yA== 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=g6KtYvddfVW+GCdGKl8QzCqK7RXkmTVgJchJNwSNoN4=; b=v5mroyvYtjC6nez3wp+bbTwU45xdgTA4sKGJ2oeB34Q9xOTplHRhwrOeqxzepz08K9o0tPFlIVUDkejw9RxMxHRMwIwPC4IX/MmUR366AnX8lp8YSXwCeJvS1rpgUqhsEPdgZmJSzqU/hh+l9jT/iOzIS93JP3wfgBiTDXiFz40= 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: , , , David Gibson Subject: [XEN][RFC PATCH v4 04/16] libfdt: overlay: change overlay_get_target() Date: Tue, 6 Dec 2022 22:15:25 -0800 Message-ID: <20221207061537.7266-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061537.7266-1-vikram.garhwal@amd.com> References: <20221207061537.7266-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E64E:EE_|DM4PR12MB6208:EE_ X-MS-Office365-Filtering-Correlation-Id: 842a9634-8217-41d8-4022-08dad81a9a63 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZL+pOnjaKC91xIm0LPMLFE9MldlgvHBAXhvMlrmYHbsJ1hXPPwRc+8Yes2K1574P8kVJdUdjPKZTsXOrAG92ykTHtpUCFxDKX41i1FzyBYQ6rYN4pX6ShGAJRwp8wI2ZDW0hwZNRYUCm1nfkmRN6+AUQsTIKF/yI6x5tTrVulWi/4YblcM7xNjTeMtFOOXhaILoAab4y6CUjrYw+hPwhcypS77i4FSpYPo8fWV2/k83bHqCyKWYCaw3EWIHOMjjSNThjH5eGBchr1f/maZv9mf6R5FL/VVxieKc3dqk95cufAb32PLJ+wVMEZwHtzWhUI7Jrs9kdrhSaJPCxACCbBMEUYnQCiIMTN+s5aeruq4LTDPScbj6zbswEIeiAuKxBOt52GmhNBjiixtdCwxg3MASLL7m+x1kE4gb/HCFneutITTiCTtaCAXEaQ5OINMSs5xqTgMFMJJE/vsLxKZnCIBpshEJgXFKIV3IctdsimroCpgT7oAiyGfzu3IfF2sSO1LZBuVmOaGBZDZ/Up6nPKcT9gmCkfxFOHc/VjxPmQOUx15Bf7avDMK9pd2mgXbJ1PKYLKHOhxivHQP5wAoZGOFz7E642TiumG7EBcekjKgOm/hCClZx9HL8KYt77uNdUjpPbhXfZTVFhXnVRAU9JnULBUSJ1NEcj0V4VcrBrkOsEYnbIqzW29wT7tzqqUyrUu1vQejPX/9OvB0Ic95IxIz57RIo1SC1BueQ3gG1K7yX71/cXSzcKV2QFcbgSkYNto1SHX10BIZYJWnzmXqLtnQ== 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:(13230022)(4636009)(136003)(346002)(376002)(396003)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(1076003)(41300700001)(2616005)(186003)(70206006)(70586007)(478600001)(36860700001)(82310400005)(336012)(6666004)(47076005)(356005)(40460700003)(44832011)(81166007)(26005)(966005)(8936002)(5660300002)(316002)(36756003)(2906002)(40480700001)(86362001)(4326008)(8676002)(426003)(83380400001)(82740400003)(54906003)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:16:39.6354 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 842a9634-8217-41d8-4022-08dad81a9a63 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: DS1PEPF0000E64E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6208 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. Origin: https://github.com/dgibson/dtc 45f3d1a095dd Signed-off-by: Vikram Garhwal Message-Id: <1637204036-382159-2-git-send-email-fnu.vikram@xilinx.com> Signed-off-by: David Gibson --- 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 Wed Dec 7 06:15:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066672 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 64DC7C352A1 for ; Wed, 7 Dec 2022 06:22:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455912.713579 (Exim 4.92) (envelope-from ) id 1p2noc-0000Mh-T7; Wed, 07 Dec 2022 06:21:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455912.713579; Wed, 07 Dec 2022 06:21: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 1p2noc-0000Ma-PO; Wed, 07 Dec 2022 06:21:58 +0000 Received: by outflank-mailman (input) for mailman id 455912; Wed, 07 Dec 2022 06:21:57 +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 1p2njr-0007Hl-7e for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:17:03 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20602.outbound.protection.outlook.com [2a01:111:f400:fe5b::602]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c2e756e5-75f6-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:17:02 +0100 (CET) Received: from DS7PR03CA0289.namprd03.prod.outlook.com (2603:10b6:5:3ad::24) by DM4PR12MB5216.namprd12.prod.outlook.com (2603:10b6:5:398::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Wed, 7 Dec 2022 06:16:59 +0000 Received: from DS1PEPF0000E654.namprd02.prod.outlook.com (2603:10b6:5:3ad:cafe::71) by DS7PR03CA0289.outlook.office365.com (2603:10b6:5:3ad::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:16:59 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0000E654.mail.protection.outlook.com (10.167.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:16:58 +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; Wed, 7 Dec 2022 00:16:57 -0600 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; Wed, 7 Dec 2022 00:16:45 -0600 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; Wed, 7 Dec 2022 00:16:45 -0600 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: c2e756e5-75f6-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jpy825VLUYfE4H2lD6b/aQbb32tWiSlUvcJakqRcQOAqQ3Q3AAibepNS38zp9iob2pkpjaDohtZi0EVKcQ5wg5QO69RYpQEpY9TwxXbZH15WR8kz8Q8tF0uNb/FQrfAD4Np8tTmG9L/ki+1RaaQ5LCaZJvYdmOVlURrjyeDUzrxh5bmsdsdjZfyfhsUhWZ7yaCYOwOscqHbX7YS9q4nFBCXUhC4gyy2eDfkd/MjZuviofeqcY+bZaC74Ic+0P9iiJYzQr9c9cVg+H0C9fIQTOa2x+jcJToFoiJTewsms/p+U9cgSNRzE/OBjAOjrng1Wqk8LcGVlRNLU2fCgUW0fmA== 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=XLhSLOJ5pm1JyR9SwI48LW3Gv+ml3wGq6nn4glAMwVw=; b=mZdyUSw+gduU+S4Bmklwp/3OCIq7d1m3l+82Ct/ZJ7QQfyCdyq4uXPytuv5iXdTY4kYsygJVyM+/z8cNRnxsKW//bj/b1Onj9HKTZdGIkrEKO1lkD87El76izF2csDpHZelOE+lSw4vxxHmGx8JOqIljB4hJNjQN82ReTrX1TlieZjvkMWXnWZomciUFGmBVyrMY4t93Z5+O5Q1wfiEGghSpcF69u8RqbozTcP6qPdUayAGhXTsFuvxww4/Tn9WmRDHyEatx9UVmn0WBnIo/zxjLSb6k0hO2WgEkwZUA36tTGvkTweEm45PNnSgmsiwTrxmyY25X2QxmiHdxQmdGpw== 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=XLhSLOJ5pm1JyR9SwI48LW3Gv+ml3wGq6nn4glAMwVw=; b=48DgmdHw/fs9ymW0IwuKa93kAS655+wM/S2taaiOWOQmDvH2JvvTVOomumVONakYO5UrVqblD0q5x6WtROOa2zDs7/Hg9N9LCydJbionWQd0BMHKOMxN0cmG+U/q77XyvxSyDZC8JPxJXKGYwH8u5h4FtVPzSBm22ycP8wRa3Ek= 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: , , Subject: [XEN][RFC PATCH v4 05/16] xen/device-tree: Add _dt_find_node_by_path() to find nodes in device tree Date: Tue, 6 Dec 2022 22:15:26 -0800 Message-ID: <20221207061537.7266-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061537.7266-1-vikram.garhwal@amd.com> References: <20221207061537.7266-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E654:EE_|DM4PR12MB5216:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b5055bc-cb43-4343-a874-08dad81aa5ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MshKseY3RAeYO9mGzT4vjUU/v2dV7DarewLsM++3JkgY60D2EMjI0aZvl6kZlEWkVbyanuozXyiJtBogz8hmFoVgAQYNgcoVvwt0RjY7TNk6SbUZy+GOmfqnMf2Z/6hi30PLacuEO7AQgeWLIlhw4PgZjr17qavT4UHIRdbNWMR2som63cEnqoyEHL4UIRljQLtR90QMqD6YgGXIQs4o151PmJAr3aGCjvGL4scWLdtD9GLbXMZvhRjLjsA/O5fJtEx7/KWga6JiRKKOzrXttTVyy0iNMQwia1DyrsFUwcBNVVenGHGu/N9XmIxM6BKL14ns/s1dTFk5BnKQkBZ0KsWTOob0OMMcG8gSYHqaX8UWTzc3xXtApgdOCPSiRGvdTpU9w4k+OvkYRHVy5GA4Ik6MOMNzBdvSAL/AHDIvrfGa9nLn+UxYWaYYb/YpQCdjyoPBwJDH2PDX8pz59NqxcU1gjyTG68j9CUJzP78JTmKQO5rO5mSwYXLRXX6hgwfhKSGLechjJVIu5HOe/fVbKfIli3Tv8vpb/+jEDaqLdjtflBm0s/60mt6q0XQFVsfis5q91SIx2oSdDBxaRI3ziqe7O3ro+C7yogSo1l72t+Do5KSEaYtboFXyXEWlSlA74ybeBBpFjoeINGMbzdb2ydFFUk9AXmTKzyyXCQLnuY1VtNGFDXIAmL+eWJxUXh66iIbjYW3UEFbZZ5u0YNrrohqEOsqGdKnN2AQ0HCO/Eibr0O8xEEgVB4W0aUSxB9MdSV1MPqO0sQUpRrZ0HMLqMg== 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:(13230022)(4636009)(376002)(346002)(396003)(39860400002)(136003)(451199015)(40470700004)(46966006)(36840700001)(8936002)(4326008)(356005)(82310400005)(8676002)(5660300002)(41300700001)(82740400003)(81166007)(44832011)(6916009)(36756003)(316002)(36860700001)(2906002)(26005)(83380400001)(70586007)(70206006)(40460700003)(6666004)(1076003)(54906003)(40480700001)(478600001)(186003)(2616005)(336012)(47076005)(426003)(86362001)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:16:58.9777 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8b5055bc-cb43-4343-a874-08dad81aa5ea 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: DS1PEPF0000E654.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5216 Add _dt_find_by_path() to find a matching node with path for a dt_device_node. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 5 +++-- xen/include/xen/device_tree.h | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 6518eff9b0..acf26a411d 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 bde46d7120..51e251b0b4 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -537,13 +537,25 @@ 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 - Find a node matching a full DT path + * @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 + * @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 Wed Dec 7 06:15:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066661 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 5FAB6C352A1 for ; Wed, 7 Dec 2022 06:17:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455843.713458 (Exim 4.92) (envelope-from ) id 1p2nk5-0000uT-2o; Wed, 07 Dec 2022 06:17:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455843.713458; Wed, 07 Dec 2022 06: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 1p2nk4-0000uM-VZ; Wed, 07 Dec 2022 06:17:16 +0000 Received: by outflank-mailman (input) for mailman id 455843; Wed, 07 Dec 2022 06: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 1p2nk3-0008Ff-Ku for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:17:15 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062b.outbound.protection.outlook.com [2a01:111:f400:fe5b::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ca88b0cd-75f6-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:17:14 +0100 (CET) Received: from BN9PR03CA0642.namprd03.prod.outlook.com (2603:10b6:408:13b::17) by SA3PR12MB7879.namprd12.prod.outlook.com (2603:10b6:806:306::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:17:11 +0000 Received: from BN8NAM11FT043.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::e6) by BN9PR03CA0642.outlook.office365.com (2603:10b6:408:13b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:17:11 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT043.mail.protection.outlook.com (10.13.177.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:17:11 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Wed, 7 Dec 2022 00:17:10 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 7 Dec 2022 00:17:10 -0600 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; Wed, 7 Dec 2022 00:17:09 -0600 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: ca88b0cd-75f6-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nlh/fb8KJ7GauHf27g/W1ggiylT5IKHq9ctZy/cvm4a9T6X03EeypBBbjXzRIa8NF/9h9MfEaf01leui1z5GZPs3V81p24O9lCsQAEjwRtrQK3bRPda9ibF+V/Y92JdnSkcEKQGjn+148/P9HgdrELY0vDE9yTci4hpg04dV14qIf3xA8MMFsgqEJqUOxnCoeh/NhCQ+wj1jRx9XJTW3QZqFHTQdlJl8gSuMjZDs17stclpGmZ9GmM1tq0LLi7Ia5wZZRX0Fc/nFvml/IAYAAsVULOVQCYMsgxja40e4sji9RkK2n5Ujddznz+LSVxDyC+WwH/MRvXuo4UQIFQTQ9Q== 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=U4/akz42Wqp+igCe0Vw2nCKK4JFqhGrpcVfR2U+G9LN7PtAgq3PIM51tDoKcVSVRHylp+yyoDhCteBs61CpwYs+NkTDPm8lrw4A32tvYa1mdAOvZfjjFTebbJJI28WAGq3Ab0FFdPQllzRUepKFtF26uUQmAlVcAhyvfTS8JGHGpDNybeN26rpqG6THnTpaydJq/5QPC2pDCPFj9Rb0Y5KhnAfy9anktIdAwYIk/0+6/IqyGx6IiFPl43Nw21WjyRqjZNQzu2ijEQyHMDsgHM0fCTEQ7WxGipfuh4F70nuVVNE/eDhM3RGhW+AgTAvSYPZkOZGpn1wE7ex5i1fgLeA== 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=VpRIKaNXuiCO/Ze7iyq6lgsToYXfAIHRY9G0K3CCm3ywkBOdLwdvGzOvBYOP5/c1eKQiJcJjpg6WVYFQxJ/7V1TO70BVJi0c02q0/ZkXov1+BHLqKJ44jH2KQVUhRK2hKuEadTQm3pfK7q+QnL9i6Xj+tumYG9AYwaD9oSW1eFw= 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: , , , Rahul Singh , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][RFC PATCH v4 06/16] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Tue, 6 Dec 2022 22:15:27 -0800 Message-ID: <20221207061537.7266-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061537.7266-1-vikram.garhwal@amd.com> References: <20221207061537.7266-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT043:EE_|SA3PR12MB7879:EE_ X-MS-Office365-Filtering-Correlation-Id: c125e758-315f-4ea2-3bfe-08dad81aad16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t+4o159JBUmQ5ybNeBngZPrEGaNHTGn4PTSSy+sxBIPqXZJh/jLe6bCDa8gS65SVdW8iZCywsAMp5PzftxfX7u6Mq1cM17/4FkpcE78gPBjDhiLzxVSUEMeJyKLoXqLZd8iuHEVRetqJuWpXzYBGeisffw5AQztPnVYc/MxSalap3nosTM+Jbl9EQ/Qb3Klx1ECkgmbebqVgwLdY+kAkVUlz/1hna1I8AezCBtnTYPtD7GlXNHNF4QuGJls6zsYnki+U/iOf/P0AbvvVPwuW5exegdrfYTn3VgmGFS24egwyuEPuofR1S/klMk/QyKrGd/7WcYfKLDY86FxJMPU3EGohuCjvKmJWEju42EJc+9bmoQv2MjW072v6IO3SP/bJ2mGGZ7QVMn/orHp9IoJOEJHGXcgZT71nvepZG466bNNAIaDPafkU6DX0zOA6evGZjRQ98rF3H3yFmf7ZGuQ2G5KptXLtIs7xoTDGS5rd47gH5CvyyXrITS6WQseOZA4A5pT03rOd85QUEggOiMtFfu6m1P8++krT/LWxZPi83WL9jdmzVjKGkUzUhImQD5qhnliq4xzedWbVQbn/n2/4RH8W/qjeTFdOu/n++ZceEGSmr4xftTgd+3DYPPyTtDWA5rT9sWy/T3TUVDsKpbn07GOHGZkt85BkChWLxmQbzRGb9RNvYqqLad0YamiU14HJUuoINqT+XGX56cJv3FDvT3rS7dW3nxVI0Dfh7cvPiZ0= 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:(13230022)(4636009)(39860400002)(346002)(396003)(376002)(136003)(451199015)(36840700001)(46966006)(40470700004)(36860700001)(41300700001)(86362001)(81166007)(356005)(70206006)(44832011)(4326008)(8676002)(8936002)(70586007)(2906002)(478600001)(82310400005)(40480700001)(186003)(5660300002)(26005)(426003)(336012)(47076005)(6666004)(54906003)(40460700003)(2616005)(316002)(1076003)(6916009)(82740400003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:17:11.0542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c125e758-315f-4ea2-3bfe-08dad81aad16 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: BN8NAM11FT043.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7879 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 --- 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 Wed Dec 7 06:18:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066662 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 84F34C352A1 for ; Wed, 7 Dec 2022 06:18:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455848.713469 (Exim 4.92) (envelope-from ) id 1p2nlF-0001eJ-Ih; Wed, 07 Dec 2022 06:18:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455848.713469; Wed, 07 Dec 2022 06:18:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlF-0001eC-Ea; Wed, 07 Dec 2022 06:18:29 +0000 Received: by outflank-mailman (input) for mailman id 455848; Wed, 07 Dec 2022 06:18:28 +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 1p2nlE-0001e0-44 for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:28 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20608.outbound.protection.outlook.com [2a01:111:f400:fe59::608]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f527b47a-75f6-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:18:27 +0100 (CET) Received: from DM6PR07CA0065.namprd07.prod.outlook.com (2603:10b6:5:74::42) by CY5PR12MB6430.namprd12.prod.outlook.com (2603:10b6:930:3a::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:23 +0000 Received: from DS1PEPF0000E651.namprd02.prod.outlook.com (2603:10b6:5:74:cafe::6a) by DM6PR07CA0065.outlook.office365.com (2603:10b6:5:74::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:23 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E651.mail.protection.outlook.com (10.167.18.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:23 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) 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; Wed, 7 Dec 2022 00:18:21 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 7 Dec 2022 00:18:21 -0600 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; Wed, 7 Dec 2022 00:18:20 -0600 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: f527b47a-75f6-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FXpJu77SjgdaGmTxdjRm4pHr2gCN/9RKNqXc4rMU8T4zMjO4fttqrlMZj183kyphRxkX2Q2/RSd3MjvJqNy1oJFmYkT9xVyErQwfsQBtr+dU4BfNOPT7Wj4jNaLeiIxjhDlszkr7Ip3tFHRtZdYVCkiFSJWyyBgDw5l9IwsKGkbKHUdtlQ5LBLZzpFV3/0/VJZgAHcxqjc4VVu8Elswf45wVpLBUtdE33NdkaeUZk22v68KZ7Ku9hC7j8l/YFtOUnM8O64S4rK7MQiqs2FuAAV1tA65G9bVR2HP5dIa0muhoTZkhDkhftPnm9TgkzG4TYZFSsFY1uWSdVjj4qRh+3A== 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=PQ+OzqXXeimtDKzjKu6YYvcKwF5RB8639RurEeEMf3Cas3X5BXtylALYlOcvgofWJMAOwCowLAA0E2/aektL2cgHprSsrDVtxq98CGLB3NLD1K1cUD7ZjH5XvOTFue/n/bO2PCOXeq3k7LnB3oB3lYmSIgTaLJrpBbP0Jot0OMQrjxoxY3UGQkm9QtNinaZKwqUoLzMPXZGvrwDTzGwmCZUeSsaHkvQdNip7RYuGsJ5R0nY5+Da9SuIIC7tJ2GZNPp5Wl2Ldi75SNKxv2wRNHWYDty7zE8JqdFkDeb47XIPkjZMkBbB5ZOk+CFODLywIt1Z1egsDgPE6pHT93xc2jA== 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=dJDKp1Xg2ds0MDYyyUYiLAXURH3O+vH/q+qkI8HUiyoHVFo8RrRE78lOB+ysJQvp79xY85cBPQXh+xKzSOQ6foK7c8QdWzWUWWMrMiJbqFn91sBuf8NlnNs0n70xzUiW1jU6zCrlWxlr46DOxlocjwUdtgOQuwSAlUNOYGqodQI= 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: , , , Subject: [XEN][RFC PATCH v4 07/16] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Tue, 6 Dec 2022 22:18:06 -0800 Message-ID: <20221207061815.7404-1-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E651:EE_|CY5PR12MB6430:EE_ X-MS-Office365-Filtering-Correlation-Id: b7b05a9c-5245-40b5-122c-08dad81ad804 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DvYPUn6sy3wVFri0HvA7SwtWb4o2YBcFtWhH0sEg4tOStYH9k7BUUbOhMve0ddh2ObvkNnBZkwkLerpDi0+A7iu/IAvCMoD8sbOwmWTtyCL3beasb+p2a6wgaRQ3lYAFZ8IzxIvZanFLpZ8CHJgLUysUpR2eMWxIIIY6wgpaRrWL4JWufgz0AlMQqSjIsjiBLQ8Plc50Ww64p4Glh897LSm/ce81l+fm152alsL3yvEc9226qPB/gqkDE06COYIPV5URLl2vEOZnGGIvbxnGK+tsfE8BpquNrGsx4qUVCjc4Y3E5UaWuc0w5MudGpuE/vqPblhDlBaQsfsYQeUs0mQbNQnAATUqMgUQecHOtsZyQTaN0biDVEu0WduHq0AFJL8jPMVYKj+3Mig39cCbf9x6H3ANKLUzi7HNsuuZtFxHBIODVF1lllfSVuJQuzLCSP0XztXx2MW1TL+ZzdoDHpWsaoAx6t4p/N7jIzMzagyXcSduVmEik1jXbazb9/f79mL16xtGUnaO/Yj9zIAplr/Uf9f0gud6WILtApEoKuRtI37ZkV5z8pb4H3fx5uPmL8octoN/3o3Rw17tr4kty7nBWwwC/o/J+WNfCrw8cSNYXQ7FJkoOXUTzgh0kyaXba7bjXMoR4AYcvhI86cG78jlbqRa2h+A4s7W8sc3ucLgiZglcxUUeoywM2YymwpME/y05XwMzqQSEk2yc1VVPnmihUglTdmw8tFGdBOYSTsNM= 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:(13230022)(4636009)(346002)(136003)(396003)(39860400002)(376002)(451199015)(36840700001)(40470700004)(46966006)(70586007)(70206006)(186003)(4326008)(8676002)(41300700001)(1076003)(6666004)(2906002)(82740400003)(478600001)(40460700003)(40480700001)(36756003)(2616005)(81166007)(36860700001)(356005)(47076005)(8936002)(336012)(44832011)(82310400005)(426003)(5660300002)(6916009)(54906003)(316002)(26005)(86362001)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:23.0459 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7b05a9c-5245-40b5-122c-08dad81ad804 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: DS1PEPF0000E651.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6430 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 Wed Dec 7 06:18:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066663 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 DE7AEC47089 for ; Wed, 7 Dec 2022 06:18:40 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455849.713480 (Exim 4.92) (envelope-from ) id 1p2nlI-0001w5-Rw; Wed, 07 Dec 2022 06:18:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455849.713480; Wed, 07 Dec 2022 06:18:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlI-0001vv-NY; Wed, 07 Dec 2022 06:18:32 +0000 Received: by outflank-mailman (input) for mailman id 455849; Wed, 07 Dec 2022 06:18:30 +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 1p2nlG-0001rE-MQ for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:30 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2061d.outbound.protection.outlook.com [2a01:111:f400:fe59::61d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f6d01796-75f6-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:18:29 +0100 (CET) Received: from DM6PR07CA0066.namprd07.prod.outlook.com (2603:10b6:5:74::43) by SJ1PR12MB6241.namprd12.prod.outlook.com (2603:10b6:a03:458::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:26 +0000 Received: from DS1PEPF0000E651.namprd02.prod.outlook.com (2603:10b6:5:74:cafe::6b) by DM6PR07CA0066.outlook.office365.com (2603:10b6:5:74::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:26 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E651.mail.protection.outlook.com (10.167.18.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:26 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Wed, 7 Dec 2022 00:18:24 -0600 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; Wed, 7 Dec 2022 00:18:24 -0600 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: f6d01796-75f6-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=COXahS98tM4FADTgTRdCU6PTsyCqJ90PakUz/8fXKjZw5LsbiM6Wuj+SHG0lWu79gwATRYIpEMMP4lqE4mfNw9juwYBBl69Vv1HdisG1hIiHeVkzER0NKpw/LXALWsX7OI34v/YSLIk7DLQACK1d/FmcU0Ep006hHn67WCxsKWFlG+RFwRtuf2TdwNArnT3c0NSunt0HNKCLXS2ixaWf2p+Bm1LQkcLVp1RF6bCD8vS2Rqj1UoZBNo++Ss/1E6UqoCffmUkg40CnRna3IV/eKBc0VQ3nocsxbHoIhOWXCDPCwLLo6yZgqfweiDHdlgC0+Zpkf3JQZ9tKAOdw5NiFOA== 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=hikzcibQ0nJOOKfCK5FgUvIPTCOdqHLUb/xiWwNXEa1M3jUmktZctPe1ByZF0GVsk/+0BM1XDum5OosYsGUJJEDT5v8w8jubwt+gtuHFiX1QEy1yErWKZWSgC3I23cuXA1u5PB/XJ2I+1eIli5kfzIHRRO+BnSbqvi5v5EVoDJPQ4cPYiKVZA8i/xgpVxAjs7OxbSE2Cq3N1rUW/NdtqaaFquIv1L/C5uvlNIG2Huh/54Bd18dldS8P+MqBwP4wrCJJpNThevjKJqK16/RUm6swkwVxzo8JkFZxxdxNdPhIvMuZq9wtoCDsRUpq0EnYJYH/8g8gk6wDFJdvo0CKZxw== 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=xNiVNLih/dhMiVdLuKF4gDjHAxUTDns4Rxu5GfACJjnCZUis5L7cNKcQM5hrOb8xXC0uiXAWcrm5hgrP5a20sgdSch9aUxu9Je6NCPO/lM+jfaF5n4TTgLG6pAB4k3DVgSJIKLmSfvyoC3k0M/jfjpzFvJ49OZpLp4eyIPL1Nlg= 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: , , , Subject: [XEN][RFC PATCH v4 08/16] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Tue, 6 Dec 2022 22:18:07 -0800 Message-ID: <20221207061815.7404-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E651:EE_|SJ1PR12MB6241:EE_ X-MS-Office365-Filtering-Correlation-Id: c6125904-23d9-4acf-0acd-08dad81ada07 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PFFaUz3KDhfbBWArza2pLzmf/uod3NHSSW+oJFGi1oSmQdGYKaw4EzNrfAJhAeTJXPnp4MXLLV+JzIbjxzE71vevsQw40gbP6YHTJF99EOBg9HcCBbNKXSIN+sXTcfA7QhwDV3vhsrcdj81Tp+Zfy6nGibejsIvilKvQ5ezIgIuvzT0BerP5MBOxNU3rVA9es8dbvMJ8cKVLH3sYKVApNbPoiTGn1MyQVrkFab5SiTwyuuviWouVw+Nobx31J1sntqxOnGfQzHQ1BeKzyqd7pBXOStPtT3l/eWOgbtNQSNdWIwU0TUOXEfDCituQgCMLXpmkyUa5ytZoyDLtXx6uXNfuskMdPsApeGF9phSJPcEudYUDn+dpAxW4FsbJ1trMLVorVP/tXOgTq9loxXTSjq5JNafz5qqRax+n0e2bWCFhVSKwjECPZthLasX2FPQdw87SBavkIJw7SdY5MzS4Ro0eCU419HGk7Fcg3H+wk8yNz3sJvXH7iopq80vRrHGM2k7+Cu4jIhiNR8YAVzJgW9TBSyq73zGTIbEKu5jt8bAaMA2+5cMQA76jvA7p4NFRdEbCYlR0iAO4XyGVeTQtN/aLxK1YViYt1Lh8kFs/9uysJqzzjA1OEism2X1ctIlqTCvkm9vldfiiBrg8erWAGBJtOw38brVBbdBafx+AlEK423g85eg12AOkZ/t5wNm3sxsJ2rCXfL3d6I5xZyopaVXGmthd4uojG91iuZLQ5jc= 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:(13230022)(4636009)(346002)(396003)(136003)(376002)(39860400002)(451199015)(40470700004)(36840700001)(46966006)(40480700001)(356005)(82740400003)(82310400005)(81166007)(36756003)(86362001)(40460700003)(316002)(478600001)(54906003)(6916009)(36860700001)(44832011)(4326008)(2906002)(5660300002)(41300700001)(8676002)(70586007)(8936002)(70206006)(83380400001)(26005)(426003)(6666004)(2616005)(47076005)(336012)(186003)(1076003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:26.4209 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6125904-23d9-4acf-0acd-08dad81ada07 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: DS1PEPF0000E651.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6241 Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access add. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- 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 Wed Dec 7 06:18:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066665 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 D6EDCC352A1 for ; Wed, 7 Dec 2022 06:18:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455853.713502 (Exim 4.92) (envelope-from ) id 1p2nlR-0002a9-FM; Wed, 07 Dec 2022 06:18:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455853.713502; Wed, 07 Dec 2022 06:18:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlR-0002Zz-Bv; Wed, 07 Dec 2022 06:18:41 +0000 Received: by outflank-mailman (input) for mailman id 455853; Wed, 07 Dec 2022 06:18:40 +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 1p2nlP-0001rE-Vb for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:40 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20615.outbound.protection.outlook.com [2a01:111:f400:7e88::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fc63c4cc-75f6-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:18:39 +0100 (CET) Received: from DS7PR03CA0146.namprd03.prod.outlook.com (2603:10b6:5:3b4::31) by MW4PR12MB6924.namprd12.prod.outlook.com (2603:10b6:303:207::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:30 +0000 Received: from DS1PEPF0000E653.namprd02.prod.outlook.com (2603:10b6:5:3b4:cafe::f8) by DS7PR03CA0146.outlook.office365.com (2603:10b6:5:3b4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:30 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0000E653.mail.protection.outlook.com (10.167.18.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:28 +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; Wed, 7 Dec 2022 00:18:28 -0600 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; Wed, 7 Dec 2022 00:18:27 -0600 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; Wed, 7 Dec 2022 00:18:27 -0600 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: fc63c4cc-75f6-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzyVu5um2w5rSj+rvsgptU6As5+M7Tzp/dIcujowhLL8k17tzNCZ42D9oyja8PLzP1u69wMlfAmXXmYx1hzrjLF8xIdiA+xYI64kBz59CB7DG5o+VKgKSzacLivwPJM61vrrhJGmqjGXDZMme4Q3+uxYm/FED+NELi5+MniGL+ZWUjOIcpmwRIn2cjhOPBJTPqlrRbI3Fe5sjCAz+F5uqxv7AVjvsUYhYKbkJujJmx1dN3q54gf6TNx05zmcUWfuTzL51PL36tWuRhD7tq5Z9GkQz14rHJYPvPMD5vgAKZ+2N8jkJHbfpHP6ch7yuEQpvh5RxokCZqru8oFPxwlJcQ== 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=+LUe0w+LpO5tERWdII/zFZViW4K+Jr8pdOMefoNdmlg=; b=JOgLJWRc3AmI2MK9NkKY+TaK9mhNFrQTGJ8DZc6KAgm4nVhB4b96u0EPU/2YiqPmGdOsfVTm0fQRKujUSLBy/TV0PUS3FdHpRDQ48JaZxsH4MVd31c1LvoS1GtyLohkeyaukvDJiLWE4wxD2TMUPnjXrGzWEv+xrvRqB83AbOHu2VjA6sd7nCLEQLexyPzNgHfRjsNoIKLN0RF0Yk10wOABV2tpqrXzh2bgVPuIhGLqcXnCX/y1PkGSyFGsVOY5pl+1ufWmpMN6PAtO4v57qGLg7zxsXXqzIau4wDzNhaRiZjDsJSvejGFdG5xKPP6pSN3bcbQ9AHDjWeJmDKiNx8Q== 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=+LUe0w+LpO5tERWdII/zFZViW4K+Jr8pdOMefoNdmlg=; b=UwOPF03jEgllGUo3PbJeO6MaZbzIiyOJX8Xumxpt6HAUYSVLotbVskRIVK7SBu2sCokYjTbqGCRct/CGrS6QI1ltM+6++qSwXJv5QWBc9blseyItuzjSq0KxPgo2JRrOxj9KHxVG7JBv2JMTdgW2AiMpKcI3gtWNvoDEm7h3Th0= 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: , , , , Jan Beulich , Paul Durrant , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [XEN][RFC PATCH v4 09/16] xen/iommu: Introduce iommu_remove_dt_device() Date: Tue, 6 Dec 2022 22:18:08 -0800 Message-ID: <20221207061815.7404-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E653:EE_|MW4PR12MB6924:EE_ X-MS-Office365-Filtering-Correlation-Id: b0e85081-b8f3-47d8-5bbf-08dad81adb3e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZNEtA9ZYKzx7T+6ftIUAC1dkwZ8SZXZbe68Xlz4pfxOp+OFhrRObrIfLDZq4sWcggZUxuYj6e6rtiW0g0sQ/si5BK/uargVusQYwVbwYlcLKR75D1J6XRTlU4KyuYh0PlHmu+5y3qISXFr0e4DmHhO+n+3PBTjGsKdAYE/dNpTrGhvWFk+baDXzEAAmqz9wed3Cmlp5KsGuVZUahGRiuKYCA87WkWjEHATVs9aevnrJNgow0k20v2zzNHp1R6Ztj/XEQaCCvUpWu/cq3obpy0VnBLkYlULTGwDsBeJZsLf6I+CUQcm7Go8T23Nu+z7aCBACeRds/bvp5SQhWy6pGD+5iy7CV1dJ/b4HVr7bVFzDwkpcsua1WsxPKFscOzUvuUp53vdD9Puxfzk1PtM/T8mX3DMILRDNi7dSCqmWTGRx7FqesUt4jjzEc1mJz6mIGfGlyVG5MxF0/UhPNevQdbwbiXbc589IqoZ/fUH7USYaQ9mU5DEEvYOdG5X5Xx9o9VLD/v/T+IVrlhloVuzduXIsyfDghOrDU0PRw+DU9sI/XznoQG75o0eCW4e59Ojv13CMSqPsa5FgFB1X1lNhFe63vjwWY8CIkFS1SF81B7Bi+gdw/j0zOFXi9syGT0wzTPMYCyP7EYet37HFMFCkQ46DZn6CFe2YVRgBiJf1veesUSdSeN4FOiHNyzhgFw6At45Zu3hLFKYf3ojf4knEDpF86IzdHKDV5vS/M+fta1PI= 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:(13230022)(4636009)(136003)(396003)(346002)(376002)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(70206006)(70586007)(478600001)(8676002)(44832011)(81166007)(4326008)(6666004)(82740400003)(2906002)(40460700003)(356005)(316002)(54906003)(6916009)(36756003)(40480700001)(86362001)(83380400001)(47076005)(426003)(1076003)(8936002)(5660300002)(2616005)(336012)(186003)(41300700001)(26005)(36860700001)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:28.4455 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0e85081-b8f3-47d8-5bbf-08dad81adb3e 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: DS1PEPF0000E653.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6924 Remove master device from the IOMMU. Signed-off-by: Vikram Garhwal --- 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..a8ba0b0d17 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 == 0 ) + 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 4f22fc1bed..1b36c0419d 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -225,6 +225,8 @@ int iommu_release_dt_devices(struct domain *d); */ int iommu_add_dt_device(struct dt_device_node *np); +int iommu_remove_dt_device(struct dt_device_node *np); + int iommu_do_dt_domctl(struct xen_domctl *, struct domain *, XEN_GUEST_HANDLE_PARAM(xen_domctl_t)); From patchwork Wed Dec 7 06:18:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066664 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 56C65C352A1 for ; Wed, 7 Dec 2022 06:18:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455852.713490 (Exim 4.92) (envelope-from ) id 1p2nlP-0002Hb-3o; Wed, 07 Dec 2022 06:18:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455852.713490; Wed, 07 Dec 2022 06:18:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlP-0002HK-0p; Wed, 07 Dec 2022 06:18:39 +0000 Received: by outflank-mailman (input) for mailman id 455852; Wed, 07 Dec 2022 06:18:38 +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 1p2nlN-0001rE-UX for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:38 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2062c.outbound.protection.outlook.com [2a01:111:f400:7e8b::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id faccc05a-75f6-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:18:36 +0100 (CET) Received: from DS7PR03CA0015.namprd03.prod.outlook.com (2603:10b6:5:3b8::20) by SA0PR12MB4557.namprd12.prod.outlook.com (2603:10b6:806:9d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:31 +0000 Received: from DS1PEPF0000E64E.namprd02.prod.outlook.com (2603:10b6:5:3b8:cafe::1a) by DS7PR03CA0015.outlook.office365.com (2603:10b6:5:3b8::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:31 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E64E.mail.protection.outlook.com (10.167.18.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:31 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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; Wed, 7 Dec 2022 00:18:31 -0600 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; Wed, 7 Dec 2022 00:18:30 -0600 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; Wed, 7 Dec 2022 00:18:29 -0600 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: faccc05a-75f6-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mXOzTNpk/5BMKH+TTIPgyuM2zRgpk8eUMR+vB2kT4ztNRkDbpzX0gwX9UCramvCpFcX9In3nH7nuuNVDMFqjWk45KMDjsdglKOSw7dUiPgUK68dxNK5lbObABq4rMP1YiSrAz5r0sLbpsJsZWUULxjfBvm+jHMyI1ZYlHjp5oeB/44CLy/TbTvwbmzbaiDrK63p86ChJoRCHi1yuBTL98MOX+J+BbgHDPOFm6k972WFdaZIF7eKEW2+B/mgnX6WmYgd/3rn/s23/Q/Zl240hTyqQRJ0bZxSEj1CCHKUYtrxZgjpKr9exSM49Liy/R6I7Gi6pSnMyCHaRc6q8Ac6lPQ== 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=w+Sq6+5nUDNMD9hP99qzhfGlSEZu9BK2xepwW4V56QI=; b=Fniblm45wnL1kmFFwur/0YAlBRFG3GPO+PR/zBSKIXi96RP9UjEUMMqAKN3mos5CNCtDNMCIlQc2m5rIjpXIl6D3X3wy88cdYNr2aO6qbSDmKvhvC1tvTCSUblJnSNHymKjmtpRZue0tu/ih+ejlqSDOEzewIbv4zdCeLb/g9AR5Tikk/xiNT6Yv313y8vG4qtpTCkIiUdVW6PAN5ieK+6px3qOIULZT+f0RVF3cf0nlOoWizbZiV3KmyggT/pMLFziT2ctffY33++MFw3nrUl8vhbtX9yMfkODp4LJZvAmKuOBl4IB8BqF+Nh2IPW8LUUCffpivxdeldIvBY1rpvA== 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=w+Sq6+5nUDNMD9hP99qzhfGlSEZu9BK2xepwW4V56QI=; b=glWZSJrpo1cLTqRtVolAKHS4df9fe3+5jGNFmFdcPMoKSCohYXbfDM1ZoehuYxMmKf7eY+ZDfz1ECW52KrCl0K3mW29JT8Jm5VQUYlCzG5s1SpTyztI6IuXXae5EsrtlaR6YGVQUmETHcoQ70O/K5GvycaOa3nDYRWWssqpWhOA= 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: , , , , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu Subject: [XEN][RFC PATCH v4 10/16] asm/smp.h: move cpu related function to asm/cpu.h Date: Tue, 6 Dec 2022 22:18:09 -0800 Message-ID: <20221207061815.7404-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E64E:EE_|SA0PR12MB4557:EE_ X-MS-Office365-Filtering-Correlation-Id: d33989e8-047b-45dd-23ce-08dad81add06 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HB8RbFd9C4NWZvnmbm2ClJBErG2zjMZnocH4Ep/flRhEVjkJawutEtvNXyhHaT0euQLbTpbPqu9b4wisFxSAqKQ5h3qbBdjDBZ8CMfNNbp1xUcSYkomwUmIAUJR8CsBpP8d/ekbiFfwoPvv2Q9ZBqfanvA9vkVORTg0+9nPII6VkNcm3M+51aiHCYdWqNP6Brk9Rf6oInosz0oWWLxHbg/KEa2XGK+4zETiTNk+NcF1/ZZ+YyXkbi/xMtj4uR5tNab/zFN0/c/1Gt307RB3YgZtuNl9AGblg1VCLu/MP4y4dD7ve/OmUNCOwjfsZlm4YT3RswqwnMEPYCVRcBEL4gl3PknXi32WOXKzP22FMBHtVdSoawk+dh4j+VbEv2TbmGXUyaX7G7T420KmQaQiOK0SfnuIn3+BKADudqUcNatH9zSdhWhYGFiZmt7ezYBzmUlPahX6hpuqStTSfwwNbnDtQEC5hJ/RhuEQgd1kjYeAc9pEJeMakiF1KT5qb4okA1zaNVtQqD22VgpQCEkx+ZrPmw/jtK8tUmh6JdoleGVpq/9l/4npDndxyELT/e6CftrHYgT1rancU74E+QBwLzDzbk+bEyx7iMujzUcAkowEWPFiVRGtd0HrWyCCmWQWh7y1g8xkvvurwspCf6uCtZ3+wJ6H5lkY1+r02fSMyK10jD6TXnA3EEtU305owf6TMYoYhrODR2yCQxE3+8Mx9T5/pNRHc6Ep4+7IvYJLJrlg= 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:(13230022)(4636009)(396003)(346002)(136003)(376002)(39860400002)(451199015)(36840700001)(40470700004)(46966006)(41300700001)(36860700001)(86362001)(478600001)(6666004)(1076003)(2616005)(82740400003)(81166007)(83380400001)(6916009)(316002)(40460700003)(54906003)(356005)(4326008)(336012)(8676002)(186003)(7416002)(8936002)(36756003)(2906002)(40480700001)(26005)(47076005)(5660300002)(426003)(44832011)(70586007)(70206006)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:31.4325 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d33989e8-047b-45dd-23ce-08dad81add06 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: DS1PEPF0000E64E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4557 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 Inside arch/arm/include/asm/smp.h, there is one function which needs device_tree.h, moved the cpu related function to a new file: arch/arm/include/asm/cpu.h Signed-off-by: Vikram Garhwal --- xen/arch/arm/efi/efi-boot.h | 1 + xen/arch/arm/include/asm/cpu.h | 35 +++++++++++++++++++++++++++++++ xen/arch/arm/include/asm/domain.h | 1 + xen/arch/arm/include/asm/psci.h | 1 + xen/arch/arm/include/asm/smp.h | 24 --------------------- xen/include/xen/cpu.h | 4 ++++ xen/include/xen/softirq.h | 4 ++++ 7 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 xen/arch/arm/include/asm/cpu.h diff --git a/xen/arch/arm/efi/efi-boot.h b/xen/arch/arm/efi/efi-boot.h index 43a836c3a7..ca40c6f73f 100644 --- a/xen/arch/arm/efi/efi-boot.h +++ b/xen/arch/arm/efi/efi-boot.h @@ -5,6 +5,7 @@ */ #include #include +#include #include #include diff --git a/xen/arch/arm/include/asm/cpu.h b/xen/arch/arm/include/asm/cpu.h new file mode 100644 index 0000000000..4df80ca1b5 --- /dev/null +++ b/xen/arch/arm/include/asm/cpu.h @@ -0,0 +1,35 @@ +#ifndef __ASM_CPU_H +#define __ASM_CPU_H + +#ifndef __ASSEMBLY__ +#include +#include +#include +#endif + +DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); +DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); + +#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) + +/* + * Do we, for platform reasons, need to actually keep CPUs online when we + * would otherwise prefer them to be off? + */ +#define park_offline_cpus false + +extern void noreturn stop_cpu(void); + +extern int arch_cpu_init(int cpu, struct dt_device_node *dn); +extern int arch_cpu_up(int cpu); + +int cpu_up_send_sgi(int cpu); + +/* Secondary CPU entry point */ +extern void init_secondary(void); + +#define cpu_physical_id(cpu) cpu_logical_map(cpu) + +#endif + + diff --git a/xen/arch/arm/include/asm/domain.h b/xen/arch/arm/include/asm/domain.h index 2ce6764322..f9440e5c7e 100644 --- a/xen/arch/arm/include/asm/domain.h +++ b/xen/arch/arm/include/asm/domain.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/xen/arch/arm/include/asm/psci.h b/xen/arch/arm/include/asm/psci.h index 832f77afff..74c1bc6368 100644 --- a/xen/arch/arm/include/asm/psci.h +++ b/xen/arch/arm/include/asm/psci.h @@ -1,6 +1,7 @@ #ifndef __ASM_PSCI_H__ #define __ASM_PSCI_H__ +#include #include /* PSCI return values (inclusive of all PSCI versions) */ diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index 8133d5c295..76944b07f7 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -3,40 +3,16 @@ #ifndef __ASSEMBLY__ #include -#include #include #endif -DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); -DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); - -#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) - #define smp_processor_id() get_processor_id() -/* - * Do we, for platform reasons, need to actually keep CPUs online when we - * would otherwise prefer them to be off? - */ -#define park_offline_cpus false - -extern void noreturn stop_cpu(void); - extern int arch_smp_init(void); -extern int arch_cpu_init(int cpu, struct dt_device_node *dn); -extern int arch_cpu_up(int cpu); - -int cpu_up_send_sgi(int cpu); - -/* Secondary CPU entry point */ -extern void init_secondary(void); extern void smp_init_cpus(void); extern void smp_clear_cpu_maps (void); extern unsigned int smp_get_max_cpus(void); - -#define cpu_physical_id(cpu) cpu_logical_map(cpu) - #endif /* diff --git a/xen/include/xen/cpu.h b/xen/include/xen/cpu.h index e8eeb217a0..ce93eb0003 100644 --- a/xen/include/xen/cpu.h +++ b/xen/include/xen/cpu.h @@ -5,6 +5,10 @@ #include #include +#ifdef CONFIG_ARM +#include +#endif + /* Safely access cpu_online_map, cpu_present_map, etc. */ bool get_cpu_maps(void); void put_cpu_maps(void); diff --git a/xen/include/xen/softirq.h b/xen/include/xen/softirq.h index 1f6c4783da..cc98a65287 100644 --- a/xen/include/xen/softirq.h +++ b/xen/include/xen/softirq.h @@ -19,6 +19,10 @@ enum { #include #include +#ifdef CONFIG_ARM +#include +#endif + #define NR_SOFTIRQS (NR_COMMON_SOFTIRQS + NR_ARCH_SOFTIRQS) typedef void (*softirq_handler)(void); From patchwork Wed Dec 7 06:18:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066666 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 40E5DC352A1 for ; Wed, 7 Dec 2022 06:18:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455855.713513 (Exim 4.92) (envelope-from ) id 1p2nlV-0002yW-RB; Wed, 07 Dec 2022 06:18:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455855.713513; Wed, 07 Dec 2022 06:18:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlV-0002yL-LD; Wed, 07 Dec 2022 06:18:45 +0000 Received: by outflank-mailman (input) for mailman id 455855; Wed, 07 Dec 2022 06:18:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlU-0001rE-AA for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:44 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2061e.outbound.protection.outlook.com [2a01:111:f400:7eb2::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fefb935c-75f6-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:18:43 +0100 (CET) Received: from DS7PR03CA0315.namprd03.prod.outlook.com (2603:10b6:8:2b::10) by LV2PR12MB5941.namprd12.prod.outlook.com (2603:10b6:408:172::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:39 +0000 Received: from DS1PEPF0000E654.namprd02.prod.outlook.com (2603:10b6:8:2b:cafe::8c) by DS7PR03CA0315.outlook.office365.com (2603:10b6:8:2b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:38 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E654.mail.protection.outlook.com (10.167.18.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:38 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Wed, 7 Dec 2022 00:18:34 -0600 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; Wed, 7 Dec 2022 00:18:33 -0600 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: fefb935c-75f6-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jj0Lw93vBrmJv1JDJ/ATBpJAjMfpQBXXfYddtM+oTlePkqhEzM2P2P8vXKHweoVdNyPVrgl5HHpKIvE6oVRcdVdVsUgz75x+KK6yf6nF8IWJf0KUjaa0OeX2xRQfJpPilISnU9vu5XOSIGrUxwrKkHzua3XbyfQDAP6u994zMS4CJoAKMj2yhAR1y76utetYv2ofrQwd7f2vFc0OKqMTxYt3Ov0ovxIAJfPuIDYn7QRRSlPHM/1GIDsBHb8Bx/ap4urSz8WyS40Ve3lAz+L95a2q9+m4Krzm1HAig0ZXY9jMiNrWOCXzCl0oeE9pqCkb98iOrnOmAH71t2gOddXv7A== 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=7ti07e7HwAD9XqBya0RpIypdK+xP18bQKOLyxyXTyac=; b=U2rIoRkqre6KI2ht5G3fjCozSmiXPFkqEqy5Wr2f+/1kcXv/0UAZ6vh99PGoxmLfaVwog7ofstHnM71zyvUrTgJx3Re8OdKRX0/9ZbvlYfhnSYVQr9WvWqS4vUM5oDC4QLygJXcUNjdXokuguEbqmWofbZ1M3MBu8cfqFTS/JDVQ/CkL092GIrtAczQdjlj9UpCleLXIsMJPoGNBaJqgQ136AlCfcMeM1u//zuWX3QCrIEUefM6jMMIxyKIauaiuxIKmV8n/vyECsblLERIx20PJyMZPvd6Miehfnzn4J9POyzFLsKzsTZwAfEOQ/RFLGJEuoSRSSH2LqGWb6bMyAA== 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=7ti07e7HwAD9XqBya0RpIypdK+xP18bQKOLyxyXTyac=; b=ESSXY+RZ/KveE4VcWx/gEfYn3COpB7cOLPvWU+nkj0Q0unBH87gn19VZHvgUiO7+achjTCTKr4zj/w/zdSeHMb10Fmh5X5yiiarRutlceRCi6XKvnZe0D8YAplClYPO1DPNp9ak79cl7aG+mqorfgq8buXpHfgsLF2R8YYeS3Ug= 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: , , , Subject: [XEN][RFC PATCH v4 11/16] common/device_tree: Add rwlock for dt_host Date: Tue, 6 Dec 2022 22:18:10 -0800 Message-ID: <20221207061815.7404-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E654:EE_|LV2PR12MB5941:EE_ X-MS-Office365-Filtering-Correlation-Id: eeb2441c-a59f-48b6-12ab-08dad81ae15d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1qb/anIJYWohn+XfNoKDoVRNnlQcPeXjA2zS5G3QxmRoaWTm/YN+XLcFBgvPNvF6D2ejTzgy76aykf1V7md55uUN473tn/YhVthPHf+VS8Zbyej0wUjhLKX245DriJ+eBFwdS2npHckfcovSnbnYALElUIFxpYod/MiTwIwHSDAZzU9l6yona4I+URQh+q7/KL0oWfioD0KBrYGTm4kHg9mH0c0XkrS2INGzs6v6i5CphmWqgyQu8zRM/ljxWeQR6bU3CQm7gysq8YgSchkDCb3LRD+vweakIRwa0mdGJihRt/aU98P94P00zQCUZXMAf5mqtucKdGE2wm5pxkwrftNX45FLnGU+k8Kt/XccOkaMlGMz7nQBOoos5TyJTZ3D16I4iWgM6XVzCOLBoqKlpwgdbVFPqYolVT+yvn9Ji0656obdTAj36+XWjQdRHgr0OfjUKDwQfy4dJv7QJ4XMyrJkF8vbasXx4zKN5XDG1S1dQ48tah8UzCWlWrkXPLwrPXW16JfBrnKe+BL6UfXZ5CrvsS6rygSBZlv7WDtK8KJvWLAMxdZW4yjDN9hcwxeQDmXmY5/rUwS/AX08VU0Hw5stnUHRUWbsDZTiP3cs3TlE4G0XL5vLI7aR36+HaoZv87VNbrtV5psMijW1t8WAlks8SjeEHumghkHu2a8mVjbtlWmvCL9Ege4Nfk5Y+OmotlTvAgkMDxrMuOx6C7RJ1Vrqi35HjJ8Z/g5SU8o1s7c= 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:(13230022)(4636009)(376002)(39860400002)(346002)(136003)(396003)(451199015)(40470700004)(46966006)(36840700001)(36756003)(86362001)(356005)(81166007)(8676002)(2906002)(70586007)(44832011)(8936002)(36860700001)(83380400001)(70206006)(316002)(4326008)(478600001)(2616005)(40460700003)(47076005)(336012)(426003)(186003)(6916009)(54906003)(1076003)(40480700001)(41300700001)(82740400003)(26005)(6666004)(5660300002)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:38.7131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eeb2441c-a59f-48b6-12ab-08dad81ae15d 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: DS1PEPF0000E654.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5941 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. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 27 +++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index acf26a411d..51ee2a5edf 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -140,6 +140,8 @@ const struct dt_property *dt_find_property(const struct dt_device_node *np, if ( !np ) return NULL; + read_lock(&dt_host->lock); + for ( pp = np->properties; pp; pp = pp->next ) { if ( dt_prop_cmp(pp->name, name) == 0 ) @@ -150,6 +152,7 @@ const struct dt_property *dt_find_property(const struct dt_device_node *np, } } + read_unlock(&dt_host->lock); return pp; } @@ -336,11 +339,14 @@ struct dt_device_node *dt_find_node_by_name(struct dt_device_node *from, struct dt_device_node *np; struct dt_device_node *dt; + read_lock(&dt_host->lock); + dt = from ? from->allnext : dt_host; dt_for_each_device_node(dt, np) if ( np->name && (dt_node_cmp(np->name, name) == 0) ) break; + read_unlock(&dt_host->lock); return np; } @@ -350,11 +356,14 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, struct dt_device_node *np; struct dt_device_node *dt; + read_lock(&dt_host->lock); + dt = from ? from->allnext : dt_host; dt_for_each_device_node(dt, np) if ( np->type && (dt_node_cmp(np->type, type) == 0) ) break; + read_unlock(&dt_host->lock); return np; } @@ -363,10 +372,13 @@ struct dt_device_node *device_tree_find_node_by_path(struct dt_device_node *dt, { struct dt_device_node *np; + read_lock(&dt_host->lock); + dt_for_each_device_node(dt, np) if ( np->full_name && (dt_node_cmp(np->full_name, path) == 0) ) break; + read_unlock(&dt_host->lock); return np; } @@ -450,6 +462,8 @@ dt_find_compatible_node(struct dt_device_node *from, struct dt_device_node *np; struct dt_device_node *dt; + read_lock(&dt_host->lock); + dt = from ? from->allnext : dt_host; dt_for_each_device_node(dt, np) { @@ -460,6 +474,7 @@ dt_find_compatible_node(struct dt_device_node *from, break; } + read_unlock(&dt_host->lock); return np; } @@ -470,13 +485,19 @@ dt_find_matching_node(struct dt_device_node *from, struct dt_device_node *np; struct dt_device_node *dt; + read_lock(&dt_host->lock); + dt = from ? from->allnext : dt_host; dt_for_each_device_node(dt, np) { if ( dt_match_node(matches, np) ) + { + read_unlock(&dt_host->lock); return np; + } } + read_unlock(&dt_host->lock); return NULL; } @@ -1052,10 +1073,13 @@ struct dt_device_node *dt_find_node_by_phandle(dt_phandle handle) { struct dt_device_node *np; + read_lock(&dt_host->lock); + dt_for_each_device_node(dt_host, np) if ( np->phandle == handle ) break; + read_unlock(&dt_host->lock); return np; } @@ -2102,6 +2126,9 @@ int unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) dt_dprintk(" <- unflatten_device_tree()\n"); + /* Init r/w lock for host device tree. */ + rwlock_init(&dt_host->lock); + return 0; } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 51e251b0b4..bafc898f1c 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 Wed Dec 7 06:18:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066667 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 53F7CC4708E for ; Wed, 7 Dec 2022 06:18:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455857.713524 (Exim 4.92) (envelope-from ) id 1p2nlX-0003GU-4p; Wed, 07 Dec 2022 06:18:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455857.713524; Wed, 07 Dec 2022 06:18:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlW-0003FW-Vl; Wed, 07 Dec 2022 06:18:46 +0000 Received: by outflank-mailman (input) for mailman id 455857; Wed, 07 Dec 2022 06:18:45 +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 1p2nlV-0001e0-G8 for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:45 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20616.outbound.protection.outlook.com [2a01:111:f400:fe59::616]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ff479659-75f6-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:18:43 +0100 (CET) Received: from MW4PR03CA0074.namprd03.prod.outlook.com (2603:10b6:303:b6::19) by PH7PR12MB7210.namprd12.prod.outlook.com (2603:10b6:510:205::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:40 +0000 Received: from CO1NAM11FT111.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b6:cafe::c1) by MW4PR03CA0074.outlook.office365.com (2603:10b6:303:b6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:40 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT111.mail.protection.outlook.com (10.13.174.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.15 via Frontend Transport; Wed, 7 Dec 2022 06:18:39 +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; Wed, 7 Dec 2022 00:18:38 -0600 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, 6 Dec 2022 22:18:38 -0800 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; Wed, 7 Dec 2022 00:18:37 -0600 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: ff479659-75f6-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iHjg41A5jbp5+CaLhktJqQGbB/zs2y3zqHDMnW5BDTLEA0THQKch2X+z2V4c54ZYspMBE3I57vBCZ9T/6fDHDurtqCf0bfogUNKU0uQhkve+CCuqk4AU1dXSkYARg2CrJevxm+Ulouh+xdoylcZqxClD/B5W/pkNz5R/rI9jwmHXBVp09krNzzTThpEXypSYjCmhSsIn5rXthuXi/yFX+NzdYNOTXHlQj1BBqcC7nNO0UUQ5iokfuUJgF03sP5RNhQxZgL8P54j3vGigboooLpm6m7CkA6YTdjuKrKt+h1N2AgrhfBTgaohJDGSKg7MuB/0zMHbra5EH9O8PS3gKvw== 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=GshHSMMJR5sgvqnRBFWDW+JaPUeWwgv68C3b1I7NOss=; b=eXwdyU7f6elrVR0jEwglOlpYZbcsrZCQCPPW/BPvAHNFIZPjnSIYlhiDCM4vNRBaxV6i0gXkQvQwII6wpSliEoQa5Oi0hfDSVel1j0MOHospV1jBA/Ifl5lINHKSRf51L0l0MMYFArp5wD1KJlBo6zUr12fQKDjgS1aBV06WKuB/DmxtOWhWYUToAMWju2iNew0DZtIldkNssKQruBIu3zCzCqb7WWoXgHg1jAiV/bJ+6p6+ZlUrQABQt82aRON91R1Y+t4caKlmUJSQUwvXP3cFHVB7ExzCG5IJi869td1eOk5fPKlxKlPdV+WCihcyzJZPyIXlYYbMRsUmNEtYJw== 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=GshHSMMJR5sgvqnRBFWDW+JaPUeWwgv68C3b1I7NOss=; b=ngkRp+p3Eed2Jsl+X5qWDztdyMEHjmBYIr7NVweoLlG0Dvuq093TksJKJP9/M3u1tPljqr4l2XGuNG3onLARgHHxoGk4idfLlmZCU/oYxQEr6yivoDgmFQ9sVnqdvwockB/t0j+krdaKZsPTalCr+nQr7M8TbXuICMpJiJPt++o= 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: , , , , Andrew Cooper , "George Dunlap" , Jan Beulich , Wei Liu Subject: [XEN][RFC PATCH v4 12/16] xen/arm: Implement device tree node removal functionalities Date: Tue, 6 Dec 2022 22:18:11 -0800 Message-ID: <20221207061815.7404-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT111:EE_|PH7PR12MB7210:EE_ X-MS-Office365-Filtering-Correlation-Id: 57cfdc65-127b-439c-cafe-08dad81ae1b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yLZhAjp0lEBRWb5nMY1TRjBi9e9muVFTpyR+75qqg5iX0yHm6dHxdAKPiez1qM2H7tqxUStiLTr3ssPt2ehoC1wtJ7l5UIVe69J8E48STJEhtYz+unFpd2qhsuOtcTZ+8chIR6j3lkRRMz8f01ltcmZizbWMpQEEcjePm4nsMv/XU24tejeTz4Q8zSobaBMFdN+G9o4ggnib7MMQ/RqpYtIDs24nFSgAkVdI7Ek2BXfe/9GwjLLY1KUdtW4/SfceQ5jlOeL9hXuyzpgi8XGIIKP2Q3ySc3Pu3wB3hmRd+Q+doJfVJ6yjGJd/VzhZ34hEHTdEFgnHARPs84rAE345lnO1F0auMhzKGbJpDg87E23+ygYiSh040wkVS8grUGQbA8/zaYt8hcjC11kKZ58GgVIadPbV13N8O7gniM4l4Zf+cSe2nINXraGtamwg0IlZQbOrpgSExNvBWPjejWMufvzogO/Q06XqRaLZyJKC84ZDZgqyJZ0wVah1t8k7MeWe+KU1q0b1UXKI40uH0HQjzQzBTyMP0LJZZ4dgfdmvDj5mUJJc2rTmT5fr48YvG1HqzLVq4LwR8Vzdy9zLVR5kPVw4Hn8aLN9zRwzKuwK6JIWUwjj26BgJZReec9pT8akNAe0+GMwXioUj8SO0KcAa3XvEjocsojyQKqq+ZpCSM1kvMXz/AurNuRbvj/nmaKRlUT01KePm1uuFYGTet2bEaJx9K2aDAjhjEdv9UaDX2SKDNj8jrwHvMnLRrSwNCHkYEAqki29NtvfI7ANbkny5S6tv2u5GC5AFk0cKzYN57xw= 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:(13230022)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199015)(46966006)(40470700004)(36840700001)(47076005)(478600001)(40460700003)(86362001)(26005)(40480700001)(426003)(81166007)(36756003)(356005)(336012)(82740400003)(82310400005)(186003)(1076003)(83380400001)(2616005)(30864003)(44832011)(41300700001)(5660300002)(8676002)(4326008)(36860700001)(70586007)(6666004)(316002)(70206006)(54906003)(6916009)(8936002)(2906002)(403724002)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:39.2477 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57cfdc65-127b-439c-cafe-08dad81ae1b5 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: CO1NAM11FT111.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7210 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/common/Makefile | 1 + xen/common/dt_overlay.c | 411 +++++++++++++++++++++++++++++++++++ xen/common/sysctl.c | 5 + xen/include/public/sysctl.h | 19 ++ xen/include/xen/dt_overlay.h | 55 +++++ 5 files changed, 491 insertions(+) create mode 100644 xen/common/dt_overlay.c create mode 100644 xen/include/xen/dt_overlay.h diff --git a/xen/common/Makefile b/xen/common/Makefile index 3baf83d527..58a35f55b2 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -7,6 +7,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..477341f0aa --- /dev/null +++ b/xen/common/dt_overlay.c @@ -0,0 +1,411 @@ +/* + * xen/common/dt_overlay.c + * + * Device tree overlay support in Xen. + * + * Copyright (c) 2022 AMD Inc. + * Written by Vikram Garhwal + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 General Public License for more details. + */ +#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 = 0; + unsigned int naddr, len; + unsigned int i, nirq; + u64 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 = 0; + void *overlay_fdt; + + if ( op->overlay_fdt_size <= 0 || op->overlay_fdt_size > 500000 ) + 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: + break; + } + + return ret; +} diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index 02505ab044..bb338b7c27 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -28,6 +28,7 @@ #include #include #include +#include long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { @@ -482,6 +483,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) copyback = 1; break; + case XEN_SYSCTL_dt_overlay: + ret = dt_sysctl(&op->u.dt_overlay); + break; + default: ret = arch_do_sysctl(op, u_sysctl); copyback = 0; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 5672906729..4bc76bbe27 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1079,6 +1079,23 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#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; + uint32_t overlay_fdt_size; /* Overlay dtb size. */ + uint8_t overlay_op; /* Add or remove. */ +}; + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1109,6 +1126,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; @@ -1139,6 +1157,7 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + struct xen_sysctl_dt_overlay dt_overlay; 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..30f4b86586 --- /dev/null +++ b/xen/include/xen/dt_overlay.h @@ -0,0 +1,55 @@ +/* + * xen/common/dt_overlay.h + * + * Device tree overlay support in Xen. + * + * Copyright (c) 2022 AMD Inc. + * Written by Vikram Garhwal + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 General Public License for more details. + */ +#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 From patchwork Wed Dec 7 06:18:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066670 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 A09CCC63706 for ; Wed, 7 Dec 2022 06:19:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455864.713551 (Exim 4.92) (envelope-from ) id 1p2nle-0004Gn-CA; Wed, 07 Dec 2022 06:18:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455864.713551; Wed, 07 Dec 2022 06:18:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nle-0004G2-5m; Wed, 07 Dec 2022 06:18:54 +0000 Received: by outflank-mailman (input) for mailman id 455864; Wed, 07 Dec 2022 06:18:53 +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 1p2nld-0001e0-13 for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:53 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20625.outbound.protection.outlook.com [2a01:111:f400:fe5b::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 02ab86e9-75f7-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:18:49 +0100 (CET) Received: from MW4PR03CA0177.namprd03.prod.outlook.com (2603:10b6:303:8d::32) by MW3PR12MB4457.namprd12.prod.outlook.com (2603:10b6:303:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:42 +0000 Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::cd) by MW4PR03CA0177.outlook.office365.com (2603:10b6:303:8d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:42 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:42 +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; Wed, 7 Dec 2022 00:18:41 -0600 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; Wed, 7 Dec 2022 00:18:41 -0600 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; Wed, 7 Dec 2022 00:18:40 -0600 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: 02ab86e9-75f7-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cu9sv2pmwQtVrKGOBIJrtcGkKZSoRjsJUKo0P7TUNLyiksoRIDXbzxMlTPKUTkmrNs6b/sdjBEjGpZKXy2TDeWtl2iY+qOb9qgO1kZTGyQS8RBjjRpALlbyeovW2/rNZok6897MZHy5GsS0NkNBWvU5ra1LIJSrmHvP43VUIJnbg8YD8sFTN3p8K/hmpo1+v8HngaDzaIoG0UhtKtqLH9R3xyk0Yo/ugtDrNup3XMffKMdUryi4jnCxsKvI4v2n5NxaAx8i2kSVp4X0W934hjsKAf8tiYEdRqqbRVjh7i3jd3MPJR+HSzbCCGm/jtNZfhk67LvCCpJE4+ESdLRp/Qg== 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=K37W2xBZWHNKyU8WFAoV3vosjD3ABc6TdacNZiA/BmU=; b=AdWMclY4MWLB7f658pF5WT79TPBJA0VUUekFzr36z4igIKWkFrtrmWkhRjgzAnw4RROD7oMZF17QqBlnFGkrXVrZQ59tb/GWcOXkH458n02K6RBvMEXo45jAT5ScJ8XypEoExFPAz4RCgd1wdGHescx/dpj2ViZlAHmBwGNfiCpmBwFvTAyDq+3svMrlPMCpYI8YEda2kN0r0qJ70i0koYDoDZj3/oHbCUEZaZnYsqbgVPw2OU58vKZk7+5Kwc+21ayN43TC/lHIJvtSGhPhF9sd8riqApd3eMD1tPoxwlwI7zEFBHwFzOneBHnWwKEavEHLwCv6zEQaRs4MEUPj7Q== 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=K37W2xBZWHNKyU8WFAoV3vosjD3ABc6TdacNZiA/BmU=; b=c93feq9udmz5nVUDcb5N3+KMtmkcq+XABN5YcOiojzQgVOar90TelQY2av6FP7UZM1U4ykADqmj2vdpKIAT0GKkYVrFBmjzXv5v6Bqj03trrksV52jzc3C/56qamag7qAAi3vpL8bYyde0TXnX9Io3zTC4VxL6r4Pv6hl3ogNSU= 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: , , , , Andrew Cooper , "George Dunlap" , Jan Beulich , Wei Liu Subject: [XEN][RFC PATCH v4 13/16] xen/arm: Implement device tree node addition functionalities Date: Tue, 6 Dec 2022 22:18:12 -0800 Message-ID: <20221207061815.7404-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT022:EE_|MW3PR12MB4457:EE_ X-MS-Office365-Filtering-Correlation-Id: 921af667-2afa-4fda-e9a9-08dad81ae375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nv50eSh/1et9UdT522j+pt8atIpKrwmbKjPYr2Bymg9CvBY5HceUdeuloI9oq5qcOFNZ1bQngo1nT9Agt4Z6dB2pj2O21SE0WJ7Zq9Jw3edLy+Z35pcqcb5uSZN01QfBRucJb8CjoHlZeEMmlCsA0nFtxPBPr/2RFUEwDAXdaJ+yteCG1rAwscyTuNcfJIhFY5ufoczkZi+XvPbEfF5gb0F3LYQCIb+FRz8OxcSHt0ghMVxsv5RFnMX/oiGBbTcLdcpxJxfoMoGICy8q9SxLDoKafQU+/CxQClg/GNKPf9lpQB3sO8By6pkmiWa+hSKFkQ5FHyn27DUA2BQXy/05yQykDm2gy2y70V5ehJ9EbJ1YTQENIWtgHJmIie+hjwD3wNr9zwBNutw5SxKwD05eFmCLBDBOZnIkia9To21pzrYs8u9NiP5BZT/It92l/pS4NZMpS6cMXbKp5xTRX6TTvntG24x9d2WzI5fAki0Yy3cuEY8YhCrapKJN9qvJWi+/ZeoDmgkQJK2dru259F2QkD4G5/2zay8b1Ugj9PasNs8+mTDNpBImXz8bEa0PUtT4HSMAqOkXiE9PLC8YcgT1CTIoJPpMMpZsM2J6dOJZ0bem9i6A6Mo6A/2FrKuxGyQuQNVP8A1c/QzvP8hx30ZHftlNn+BpE7rrNhNK/kELq8oRcIQjT2rRXdyP2ZkjOPssniBLOrKxqGxKh4F8orM8dlkkjZM2M+VySOJDA2Jc8EM= 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:(13230022)(4636009)(376002)(346002)(396003)(39860400002)(136003)(451199015)(40470700004)(36840700001)(46966006)(426003)(47076005)(83380400001)(186003)(41300700001)(336012)(82310400005)(26005)(36860700001)(1076003)(8936002)(2616005)(5660300002)(82740400003)(30864003)(2906002)(8676002)(44832011)(81166007)(4326008)(6666004)(40460700003)(478600001)(70206006)(70586007)(356005)(86362001)(54906003)(36756003)(6916009)(316002)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:42.1532 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 921af667-2afa-4fda-e9a9-08dad81ae375 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: CO1NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4457 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. Signed-off-by: Vikram Garhwal --- xen/common/dt_overlay.c | 465 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 465 insertions(+) diff --git a/xen/common/dt_overlay.c b/xen/common/dt_overlay.c index 477341f0aa..f5426b9dab 100644 --- a/xen/common/dt_overlay.c +++ b/xen/common/dt_overlay.c @@ -38,9 +38,29 @@ static struct dt_device_node *find_last_descendants_node( /* If last child_node also have children. */ if ( child_node->child ) child_node = find_last_descendants_node(child_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, + 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; @@ -114,6 +134,74 @@ 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) { @@ -153,6 +241,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; + unsigned int node_num = 0; + + *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 = 0; + unsigned int target_path_len = strlen(target_path); + unsigned int node_full_name_len = 0; + + node_name = fdt_get_name(fdto, subnode, &node_name_len); + + if ( node_name == NULL ) + return -EINVAL; + + /* + * 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; @@ -373,6 +534,302 @@ 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 = 0; + unsigned int naddr, i, len; + u64 addr, size; + struct dt_device_node *np; + + /* First let's handle the interrupts. */ + rc = handle_device_interrupts(d, overlay_node, false); + if ( rc ) + { + 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++ ) + { + 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); + } + + 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 = 0, j = 0, 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 ) + return -ENOMEM; + + tr->num_nodes = overlay_node_count(overlay_fdt); + if ( tr->num_nodes == 0 ) + { + xfree(tr->fdt); + return -ENOMEM; + } + + tr->nodes_address = xzalloc_bytes(tr->num_nodes * sizeof(unsigned long)); + if ( tr->nodes_address == NULL ) + { + xfree(tr->fdt); + return -ENOMEM; + } + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + { + xfree(tr->fdt); + 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->fdt); + 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. */ + rc = unflatten_device_tree(tr->fdt, &tr->dt_host_new); + if ( rc < 0 ) + goto err; + + 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); + + /* 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 = 0; @@ -397,6 +854,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 Wed Dec 7 06:18:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066671 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 8F141C352A1 for ; Wed, 7 Dec 2022 06:19:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455865.713555 (Exim 4.92) (envelope-from ) id 1p2nle-0004LB-UI; Wed, 07 Dec 2022 06:18:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455865.713555; Wed, 07 Dec 2022 06:18:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nle-0004KI-IR; Wed, 07 Dec 2022 06:18:54 +0000 Received: by outflank-mailman (input) for mailman id 455865; Wed, 07 Dec 2022 06:18:53 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nld-0001rE-66 for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:53 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [2a01:111:f400:7eae::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 04af1d4a-75f7-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:18:51 +0100 (CET) Received: from MW4PR02CA0013.namprd02.prod.outlook.com (2603:10b6:303:16d::13) by PH7PR12MB6811.namprd12.prod.outlook.com (2603:10b6:510:1b5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:49 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:303:16d:cafe::1) by MW4PR02CA0013.outlook.office365.com (2603:10b6:303:16d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:48 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5901.15 via Frontend Transport; Wed, 7 Dec 2022 06:18:48 +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; Wed, 7 Dec 2022 00:18:43 -0600 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, 6 Dec 2022 22:18:43 -0800 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; Wed, 7 Dec 2022 00:18:42 -0600 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: 04af1d4a-75f7-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b0AdmDvBPLBmoY07TZlWdAedXk4v6Y/sHS2JD/1MXwZRrKWpOCxFJqzXedQdGYNMqCO+Vl7cvdH0hxbGBFm0pDhfWYuRwh60aFGHPr/kEE+tDB+izWrMvlIyZg0m1dgUggx86KjaKqXzZklkt7G/swkX/VA3s6nelWcMaA1xW2emVohVuhfDZDNq5je3nOpxS6cJ4e9k+ME20FGaIFeQB3NlZrGMJx0FykC6t/fMzq7XbeI11Ej4Srom82stNriHe8hBbDI1rtXK9Ca4GVbP3/qM4G7zVvh4oVtJotqFWmLIwOPfbY6lm5qjT86+Kuy80zggSC6wQKIR1Zh7eidGTg== 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=goLWEVa+AtelixIUgdIy7KMIuSqD1uMsMPZgQBv8oUg=; b=nM3rwMsCnVbvHf7SJnSqrtjzYrLS2CvC2p8HzU6MgokKF4B4NBCfzWyM9KxTRAKb3ZqyTLgYhO1bh2cfoosZPixzveJ7Bc5G102nvS8tLgSmXB80CX48NECYGXG2DMuRZQ8YSP9ZuTnLOE1p/wS8BhLgDbwt+j4OeKnBhAkJw+keprw3yjniB67X9oCyoNOj8AcjGWfXpEBVYjzYKdKY0qUG39IVl5c0I05MMsPbQ2tzN0nn/RCZGh51r0NgSEQue2dPyQdzjiAgCCitdQ2uYgGZrS3AF94NsCW950XITassvb3pweScZZwgXNG82/KTp7C7Z6kyXg1rmmBnvlsR5w== 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=goLWEVa+AtelixIUgdIy7KMIuSqD1uMsMPZgQBv8oUg=; b=oAt7mPaMtzFOSb7vNNgL26FZkxX9ERs6kbMdC3/cDpU/ed1DVGnXN4wZ0pgZm0LBG4XHSr0JX9arcVkmrSkX/iwtfVmxkSRbu2kwMV7CH+RFFGL42uj+5HyvLL2lseiyoNx1/Nj3aFTr9ZszdMLp3OyXuoAslJ93MM6J5pZTvmw= 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: , , , , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][RFC PATCH v4 14/16] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Tue, 6 Dec 2022 22:18:13 -0800 Message-ID: <20221207061815.7404-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT018:EE_|PH7PR12MB6811:EE_ X-MS-Office365-Filtering-Correlation-Id: 02b244a0-2337-488b-cff3-08dad81ae6fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: woF9ihQWiczNhFh8OM3ZTckui71eSo9l7wG8mrrycsCFv55BmDqZgpf1QUs2NKZnia8pvXPB4aVSrEQcZKyY5soJmumteRQnSmep54D9bpvrmhPfvikuNIb2lVjs/NNbLNhuX8ys6Wmav1P2JWp0S6cmhUu9Idzr/FszRPDW0AYkpi+yT1br/UthxAbDpAAs9E0gfLqYuKoS2nPnTIKxO6zcEvx1D7Kb1O47plcid6nXiu62mGYAKCPsxm3fTQjvtl9qpiut4bV7Zn5YAOGoT9l8ay2gLohabYD6KMQI5R/BmXfYEiUAxX/EF7ad+kGp/jgMhWLihTtCESIGhnfqh5aVpf1Dgiy6FrDklJ+PbmFNmHRhdhEccSl6+EBbFUSGRnpTw0zJv6RjgsZf6wARZATqwtm67aesF8mlfXbVm9wBFFTS/P0iyNWtsuaj35/XHmltSjvWLIgYEuU/JUegO/aYh1EhkhcYtW8Qsy6k5S8eTLHXbynU259nX7/LJwBBkZmkVbRHpXw2XOdaCN5M2Urf09juLHRFR2glU0OND15w2u4Txeo70qzZSrljT2bYzjyCE+Y6QNTlQJczrv883gceHjqj6ZmN5BgY3yLNY5skdsqq6pG21hKgx6347XU9XjuB9CYTEeGmhtzyvbh83gS76KUsEi8JYlpO3NgxEXmcUaF12iMQDXPyN3qZ9tlj/eEwMHIh/zgVPRWN8XXU1IHUqUY3CtRZ3XpMWE0PBSc+RCPfOJQqW5oUeQ2lTE4cjtUX7nttrr5tviaze4ieFf2xKT5LQ6aiOW5N8xWtAas= 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:(13230022)(4636009)(346002)(136003)(396003)(376002)(39860400002)(451199015)(36840700001)(46966006)(40470700004)(36756003)(70586007)(54906003)(356005)(86362001)(8936002)(41300700001)(81166007)(2906002)(40460700003)(44832011)(4326008)(5660300002)(36860700001)(478600001)(70206006)(316002)(2616005)(6916009)(82740400003)(40480700001)(82310400005)(8676002)(1076003)(47076005)(336012)(426003)(6666004)(186003)(26005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:48.0705 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02b244a0-2337-488b-cff3-08dad81ae6fc 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: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6811 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 | 3 ++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 0c8b4c3aa7..a71bc0bb1d 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2633,6 +2633,9 @@ 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); +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op); + /* 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..325c9ef4c0 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,51 @@ +/* + * + * 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_bitops.h" +#include "xc_private.h" +#include +#include + +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 Wed Dec 7 06:18:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066668 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 B0997C352A1 for ; Wed, 7 Dec 2022 06:19:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455861.713535 (Exim 4.92) (envelope-from ) id 1p2nlc-0003s0-Il; Wed, 07 Dec 2022 06:18:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455861.713535; Wed, 07 Dec 2022 06:18:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nlc-0003rk-FV; Wed, 07 Dec 2022 06:18:52 +0000 Received: by outflank-mailman (input) for mailman id 455861; Wed, 07 Dec 2022 06:18:51 +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 1p2nlb-0001e0-0d for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:51 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20627.outbound.protection.outlook.com [2a01:111:f400:7eb2::627]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 027862e7-75f7-11ed-8fd2-01056ac49cbb; Wed, 07 Dec 2022 07:18:48 +0100 (CET) Received: from DS7PR03CA0154.namprd03.prod.outlook.com (2603:10b6:5:3b2::9) by DM6PR12MB4105.namprd12.prod.outlook.com (2603:10b6:5:217::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.13; Wed, 7 Dec 2022 06:18:45 +0000 Received: from DS1PEPF0000E652.namprd02.prod.outlook.com (2603:10b6:5:3b2:cafe::6e) by DS7PR03CA0154.outlook.office365.com (2603:10b6:5:3b2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:45 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E652.mail.protection.outlook.com (10.167.18.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:45 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Wed, 7 Dec 2022 00:18:45 -0600 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; Wed, 7 Dec 2022 00:18:44 -0600 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: 027862e7-75f7-11ed-8fd2-01056ac49cbb ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gl9zA5Rlw6Z18406/kvz9L6rxskXGoVieYrESwNAT9FGrO17EIYKr3qD5Hh93U7dg3j5OdXrcpNJbMJpwVuchm0bRquWUfFcwyQ/3DVMJHNsyVQ7mChOXovHFqm6E8gwN5INEsnwqQZByDUdTxLOyKUHI5jcP/jQC1fI9F3sAjAh4iOD7dzgbpCRG3XL6moj1+5AwWg3+1B/PPcsYpj2EHopOVG/bqNYT47C+/CKdpK5wIlErHyGaRG1FKTC9EIkYA0t8adMQ2gq19ky6u7mbecqW4UumL2xfCLfwI9sL5wLIlnExdqRC56XwusKShEkDH+5365lX3H5y3iRZ2JL9w== 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=JOPPAvQXWI6mBEMr+gwu+U1QiIWcZR6lM0h0oeP5Sao=; b=ee2Tk4HAwaQ9cqfiAlRY7yeiOnycD83/2kEdWajTm5S5QzdKHktLmrbmdB+QgU06p4CGOMSf07RGFeqYPv3oDCsSimNmyr78i0H0SFtTjT2zjjNKc6owb329vhHggdkuz3bftB8aw997KkQjBEQzrZIuEDu0s6jTUEK2lxjflz/jVAW0YVegjY+brapXq3bMz/oyGHegt1RoUZZ+BC7hzocawqP1ElC4xItHQSeXIUzQWBKqSQKN61CDj3VwnxQFV4Pkn2/fUWFC8MAVI/b8MaFH7Cy1aj5Koxmrizj9Z8IVs62jGV04wFiCnly5PJ6hvFteWiS9k2oJbp32KZkJKg== 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=JOPPAvQXWI6mBEMr+gwu+U1QiIWcZR6lM0h0oeP5Sao=; b=4bvf5nmqnRYkljZdCWjjctvzN4ZMW0P5h23MHs2YnQRWjX18XifbUtrYEjcZq629x1s/CtIs68FWP2CZXFiVtrP/2DlUTpaC0syZdBrnsTvMquElOAnNbRDrFfv86ba9RdMJ5/9GNkXD0OsZJU6UpHERQO4nwrv8Aj8Zs1xPlbw= 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: , , , , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][RFC PATCH v4 15/16] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Tue, 6 Dec 2022 22:18:14 -0800 Message-ID: <20221207061815.7404-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E652:EE_|DM6PR12MB4105:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e5429a2-6bb2-40cc-58cb-08dad81ae590 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uQYnwTJBZzzsIDxJKS00fctYfhKUCWfH+75jtjPY809tsXrPz8uqlvA5YwyId370pOzr2fv9Z7koJuuynbp3cNRsn05b17KgKcOPz6xtoYum66NSw8BNxZ0oG6cJ+E3pgckLdUXR9+lQJV8rcznSW1koAr+meuJsSkXMbqm39MaDePOSAgQLy69nhF97pOimj0c8L3AQh+XTCkKcZ3rBg5rWkJiYqLcNCQFQPY47tmqXezdNAGXUfo19FUYXOMG1I2ZdFcYsRJaCBMd60cHOi9d+9dIvztLX2LugYDLIU9NtRQv8PesleLQ9sBSw6ZFXM9JOgJTpjRsFZdWVZego+LiZjXhY3piruPjzCWUUXrN4VY7L4o3dK/FPWblZXCnL6nPNmmsK9JSzzU0y33X0QAJg2REO8ARh0p6h53sRh13CMmNNGG35bR308b7C7uS/vMwKfWPJBDR/LYpq8BHIBaO8ONAZjph9X3XD/Mu2VSSUHr1myz7h5LYRwNvWf20rIgCsMzvsrQD9/48yV1A2n9lC528zTKRiDP4rPXcGs/olPVhT27SABICQCWvZ9s4PdCR4ZN32OY9irg639t1/AMtdDwcICtfPWsQaHvkoqXgqOAJ1ntwU9h7ZJ1k/wcIt6UcH6K5/+/yJgUQMffrKb2VUekjRmPOy0CiygGdsijP7TOMkk7ygGeB+XvC3sl/BWlHfRd/msrlAI67AVdlfXS95Afxy2tyRkqepRsnlwKksbH12AQJGZSleD/BSIdDo 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:(13230022)(4636009)(136003)(346002)(39860400002)(376002)(396003)(451199015)(46966006)(40470700004)(36840700001)(36756003)(40460700003)(316002)(5660300002)(81166007)(6916009)(54906003)(426003)(336012)(41300700001)(86362001)(2616005)(47076005)(356005)(82310400005)(82740400003)(36860700001)(186003)(6666004)(40480700001)(478600001)(8936002)(26005)(2906002)(8676002)(4326008)(70206006)(1076003)(70586007)(44832011)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:45.7444 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e5429a2-6bb2-40cc-58cb-08dad81ae590 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: DS1PEPF0000E652.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4105 Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu --- tools/include/libxl.h | 8 ++++ tools/libs/light/Makefile | 3 ++ tools/libs/light/libxl_dt_overlay.c | 72 +++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 tools/libs/light/libxl_dt_overlay.c diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 2321a648a5..82fc7ce6b9 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -245,6 +245,11 @@ */ #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 +/** + * This means Device Tree Overlay is supported. + */ +#define LIBXL_HAVE_DT_OVERLAY 1 + /* * libxl_domain_build_info has device_model_user to specify the user to * run the device model with. See docs/misc/qemu-deprivilege.txt. @@ -2448,6 +2453,9 @@ 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); +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay, + uint32_t overlay_size, uint8_t overlay_op); + /* * 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 374be1cfab..2fde58246e 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -111,6 +111,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..38cab880a0 --- /dev/null +++ b/tools/libs/light/libxl_dt_overlay.c @@ -0,0 +1,72 @@ +/* + * 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 +#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 Wed Dec 7 06:18:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13066669 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 E326AC4708E for ; Wed, 7 Dec 2022 06:19:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.455862.713546 (Exim 4.92) (envelope-from ) id 1p2nld-0004CF-Tl; Wed, 07 Dec 2022 06:18:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 455862.713546; Wed, 07 Dec 2022 06:18:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p2nld-0004Bh-Ol; Wed, 07 Dec 2022 06:18:53 +0000 Received: by outflank-mailman (input) for mailman id 455862; Wed, 07 Dec 2022 06:18:52 +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 1p2nlc-0001rE-64 for xen-devel@lists.xenproject.org; Wed, 07 Dec 2022 06:18:52 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20615.outbound.protection.outlook.com [2a01:111:f400:fe59::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 03d11df2-75f7-11ed-91b6-6bf2151ebd3b; Wed, 07 Dec 2022 07:18:51 +0100 (CET) Received: from DS7PR03CA0021.namprd03.prod.outlook.com (2603:10b6:5:3b8::26) by CY8PR12MB8298.namprd12.prod.outlook.com (2603:10b6:930:7c::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 06:18:48 +0000 Received: from DS1PEPF0000E64E.namprd02.prod.outlook.com (2603:10b6:5:3b8:cafe::9b) by DS7PR03CA0021.outlook.office365.com (2603:10b6:5:3b8::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14 via Frontend Transport; Wed, 7 Dec 2022 06:18:48 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E64E.mail.protection.outlook.com (10.167.18.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5880.8 via Frontend Transport; Wed, 7 Dec 2022 06:18:48 +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; Wed, 7 Dec 2022 00:18:47 -0600 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, 6 Dec 2022 22:18:47 -0800 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; Wed, 7 Dec 2022 00:18:46 -0600 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: 03d11df2-75f7-11ed-91b6-6bf2151ebd3b ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e1fb3yvNkfoPTHLSJ5CDiIpmRT84v6oW3L0EN8V6n5/+aFJcM+kzYe+eyeLMBVA8Q6ZbLQAMJGaydUGteV3OmGEdgEi2ngNaDs7fq0UHW1gBy38G0A39tbJh2bX+tp0W+C6WbGx1uiOOLoMRiJcPt9NcHsN5fVyt8NAwcGBy4T12JW78sGaF9rFxvOd/juB5tlIWd9d6EdxyrsThXW4EfoSUEsTziqoEh2HBQT1LXQHIrsqYYR5YnhuHnVSBD/IPZ545YmWEM+jRPBquxtyUzQ2JTguPpM4k09ijoyzNsqYNncDD3lr65M+WBMJErgFb4/LJexsNGy2vWsTwB6HYBg== 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=BuoYa3ejdKptzo6evNtz7S4dZu6LLa77J+UAHvefdHA=; b=duVyDuB00dbJugGCzltfibeIiRVsSX8dLnHMzSHL8lEY4NgYXrBK+T/xM/1cSFdaB/oQpttntjYyQOr5h799RXvDDen+7beAisAugXOWqF/Z97rFnQPVOyUQNOXlEZxXgzfHMomSPqnlwrW2JCjqJ3PpW2WuSQq9kKPKgq/4IbpZHtte3rkVtd8LvJ4DVO9TKWL7nLVez6ohnrHeDAPLrmiCRCN1iu6/gpEftX+g3rNbajY8XmfzTlT45A5UuXcf/Kl1JsbXLRKpjmJIdtVXuzLwR3+y1zLu090VydaaNsbYhMJC1Ix/iK0BsvFpvN2n/db8uskQ97+vbC6WMoGg8g== 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=BuoYa3ejdKptzo6evNtz7S4dZu6LLa77J+UAHvefdHA=; b=eeoiBpzM/bO6s03305AX6O1r1dyJZjR0bHjbd0vO1mOMvpT7RrHVXjHpZwW50VahklK4fJCalDRZe5jIwwsmMPkaxMCtM82BOOKvjkjZ4iK53bxRsF74BAd3nhYMIIyyRvyVauJu2nQKd69YwLP8EVCgGExzPSzTizMxLQGzSYw= 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: , , , , Wei Liu , Anthony PERARD Subject: [XEN][RFC PATCH v4 16/16] tools/xl: Add new xl command overlay for device tree overlay support Date: Tue, 6 Dec 2022 22:18:15 -0800 Message-ID: <20221207061815.7404-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221207061815.7404-1-vikram.garhwal@amd.com> References: <20221207061815.7404-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E64E:EE_|CY8PR12MB8298:EE_ X-MS-Office365-Filtering-Correlation-Id: bbc46c4d-5228-43bc-2a95-08dad81ae6f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +ETeav/QZDjQl6TGBYBcr2zgceIcDIq0XGk29itftJU8gHReJthJsOag8RnuRIjfDIMhNNl9DLnCwDwxiNxHkvCD4jxsDvDcPlxY1pfaiWDrs85E2nSYpd6rK+CxnpTf6Xtq4qsM6kiSXZPRZrBIyZFidWGaaWH1qPeM87xBhCYZTbJTnSllJJwjMUwUkSO8+qX6TQPY80L0oa9ASaCx8W/AzxZOOqIcx0Z2Sk3MokKfq2ggQvADK0vOvTitODxJQUsxsdDg8VZd0nf/erajBXPnAGi90U7Ai1ZTTOVKJcyxj0LX1iEOzeYq7Azxs2cYaqysIdSadahRMXYcBXqK2R+C/1hxakYJrHNK4ot2dYN6NQ5UdeuUTukqDtKo9ks58lvXNY2V+ayRTclPOOe357uzkpDlomUc2igzyJMNzZv4V/t9MfWZ0kKQOBtx8bAiXiziWYy1kYru0aNUmBuYaHt0iSQU/y6EU6mhz4/Gb3ZgWpX/XG/88IE6th0El0lIsHDo8lW2Ps2/x6wTBFvw1X6M4obAWPQSFRggJWBdxlEjXRZ8oczetoPYtFnDcHSTw9fFYhocgy8yy/rZpWgXZaFn+9YJ3SOD1UPmaKIb6bfXe9oTLB28H/Qt9ORO0wPlSVR4C37Hmfx20bcUdnzRCfLd+XgNHs0G/pycFpwJw6M1euYTkwS/FVTvXEf9tfW/rLjD8BBuwx9db5YhzO5Pl+VujUeq5xaHbEadclhlXcA= 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:(13230022)(4636009)(39860400002)(136003)(346002)(396003)(376002)(451199015)(40470700004)(46966006)(36840700001)(36860700001)(83380400001)(356005)(40460700003)(86362001)(81166007)(8936002)(44832011)(5660300002)(2906002)(4326008)(41300700001)(478600001)(186003)(40480700001)(82310400005)(26005)(336012)(1076003)(426003)(6666004)(47076005)(2616005)(6916009)(54906003)(70206006)(70586007)(316002)(8676002)(82740400003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 06:18:48.1050 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbc46c4d-5228-43bc-2a95-08dad81ae6f6 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: DS1PEPF0000E64E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8298 Signed-off-by: Vikram Garhwal --- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 6 ++++++ tools/xl/xl_vmcontrol.c | 48 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 7c9aff6ad7..6e95dfe6ea 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 35182ca196..868364c58d 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..b5f04e2741 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1265,6 +1265,54 @@ 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 ERROR_FAIL; + } + + 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); + return rc; +} /* * Local variables: * mode: C