From patchwork Tue May 2 23:36:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229355 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 1D312C77B78 for ; Tue, 2 May 2023 23:37:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528854.822515 (Exim 4.92) (envelope-from ) id 1ptzYg-00059l-IB; Tue, 02 May 2023 23:37:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528854.822515; Tue, 02 May 2023 23:37:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzYg-00059e-EG; Tue, 02 May 2023 23:37:22 +0000 Received: by outflank-mailman (input) for mailman id 528854; Tue, 02 May 2023 23:37:20 +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 1ptzYe-0004sC-F0 for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:20 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20625.outbound.protection.outlook.com [2a01:111:f400:7e8a::625]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 474e8439-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:19 +0200 (CEST) Received: from DS7PR03CA0256.namprd03.prod.outlook.com (2603:10b6:5:3b3::21) by PH0PR12MB5404.namprd12.prod.outlook.com (2603:10b6:510:d7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:15 +0000 Received: from DM6NAM11FT072.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b3:cafe::86) by DS7PR03CA0256.outlook.office365.com (2603:10b6:5:3b3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:15 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT072.mail.protection.outlook.com (10.13.173.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:15 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:13 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:13 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 474e8439-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eqY7o3U2kc48o7sQ9kzIP4hsRjay3NTEhCYn6scr9vlx2szGvghJBY7BTqBZ5+ePpX2hGq0WAmuGD0pGkDFsLPsa4viQ73nQ5KnudJ3/1o1WnOAiiM8t0gUGwrhdnaUMx6ULthTR7pskowWxfrm2kZOb52Z3EacSFArS7+f7GJ34ASmTZjjK0YTLjF9R3pp9tLgsi3d1f82bQHE7EvMMte0BvmyQ1blkNla4LmgJhYVLRr3DZBmuEYnl0TluTKmlFH7tk0BdHEkZk9/ZJpTU9qBbzdFhN8Iy4K/jpuuoBBbLPLuZPqhMNSCvytZNDA3pOTBJcIpHUioeafUBrgarcw== 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=z1f/f7bsw24NdyZtZPfyDM5uGc9VQDLG7SJSmTtwvfg=; b=OWKuBhLTe0ujJwlwhEqj05kzwWoUPrsysQTQJ3V+a5n9hZvLwFkBOP8PGgdu7hu5kici3C0bnY22OjLvuhFGvvSa9erk3Cs3ue1k+ijPVkZ3o2wQyGSrRbDP5pwAYagNdBwSIvtKHKj5h14UBJ2cpt6bbV7vipmfFt/V2Ra5TZ6428Z8+b0+QQaB+Mq22qb1Hj1b/Z8X5sGVmHn5nBnYq0DUnX3LusBXuS19Z/CUBbX/OG/FmaSNnWfHBF/kbQyuFV6Qv7hTSNPiQfOYwlnPRLapX2rG3sXShsvSgWLGqxNzkOQZBMVc2jLd7JY+v2G4ICu2jTezlYrvDIrySlqqwQ== 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=z1f/f7bsw24NdyZtZPfyDM5uGc9VQDLG7SJSmTtwvfg=; b=y/JQ2yrTo88/hmwMi8xLbMSEhyKhySLQPOvP75g0ejnrU/llpBn/nzzZGD+Jnwrwyqj+wnCVFIw/yR1PIwBDerq6x7DaOwryVVmOAzX9VyER2w6s1il8SriJbBnJ4pIeLPnUpohQjNSmWzO0L/X5eU+uXdWvV1yrhLuD7szxO4w= 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: , , , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v6 01/19] xen/arm/device: Remove __init from function type Date: Tue, 2 May 2023 16:36:32 -0700 Message-ID: <20230502233650.20121-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT072:EE_|PH0PR12MB5404:EE_ X-MS-Office365-Filtering-Correlation-Id: 02c9cde4-7911-4d95-51bf-08db4b662922 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sIAHOPEjxzjT7v3MKV92z8sKxP+zmf6zc7ms5pdpvVtVtQs6Z2k2XuKcpRcN+ZvrIjO8HETaBTkyleK/7YapDMQNrmCmMUMOeqG0a9f4JDJFJt7HxcCH5JEaOwyGzbEdhcaHXM/lSNohS3xhTdS+/pEIEgf3eKp/WWBNznENr2TxBNCJq8EKqe+U4i5UvBhXhIZZ2+6/LMdM+TtKcc2GNMD1G3hkKG7zida+FFIrngZOe1MOWUJnWf5Qk8hP/Cy8fjZosLPpUrLPcPMeOR2JAI962904PTofp+Z9PItZ+Wbo3ypG76QbWU6i+Sqt1ooa1Auna1sHU20MLlDuJ5/KI/qi2jxOzf2oJdDOi/s3RnorY2bA7KWTdxVmjftYuDhZJpvsC+lR0Um9Q3PHlACk7nCR7FWtkx3lW6+9K1R68bP4R8CaUIEue7KeXN+J5opBoRlPxdQ1h1NehoNYzie4xVbkHr4F71wyXvV9mNcQCPDw50Yq+SVFECj2nXd7NeUkh/Xruv+4Js4dL3UVN0yyEGqop9JpUtTDs3wI8BKxhsWvv734xHYKAYGgtT/JwMkVlmOA8L4Hvd2KSKFjUwoLegDxUXb6lpy1araBni7IheHeXKtIjYEazEf0jitG23RJFC1K1Skk+fqH0Acs0H29sbGFm6G0z+ubs/yWPV7SxI4HFCOgGTH41zwbQQLtjY/iJxZGg1v3lJ0LOp2LDuJBX51bADg5L+QgSJFCxw26nvo= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(39860400002)(136003)(396003)(451199021)(36840700001)(40470700004)(46966006)(26005)(1076003)(86362001)(6666004)(8676002)(8936002)(40460700003)(5660300002)(2906002)(30864003)(70206006)(70586007)(6916009)(4326008)(36860700001)(82740400003)(81166007)(356005)(41300700001)(44832011)(316002)(478600001)(40480700001)(186003)(47076005)(36756003)(426003)(336012)(82310400005)(83380400001)(54906003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:15.1138 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02c9cde4-7911-4d95-51bf-08db4b662922 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: DM6NAM11FT072.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5404 Remove __init from following function to access during runtime: 1. map_irq_to_domain() 2. handle_device_interrupts() 3. map_range_to_domain() 4. unflatten_dt_node() Move map_irq_to_domain() prototype from domain_build.h to setup.h. To avoid breaking the build, following changes are also done: 1. Move map_irq_to_domain(), handle_device_interrupts() and map_range_to_domain() to device.c. After removing __init type, these functions are not specific to domain building, so moving them out of domain_build.c to device.c. 2. Remove static type from handle_device_interrupt(). Overall, these changes are done to support the dynamic programming of a nodes where an overlay node will be added to fdt and unflattened node will be added to dt_host. Furthermore, IRQ and mmio mapping will be done for the added node. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- xen/arch/arm/device.c | 144 ++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 142 ----------------------- xen/arch/arm/include/asm/domain_build.h | 2 - xen/arch/arm/include/asm/setup.h | 6 + xen/common/device_tree.c | 12 +- 5 files changed, 156 insertions(+), 150 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..84197981a0 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -9,8 +9,10 @@ */ #include +#include #include #include +#include #include extern const struct device_desc _sdevice[], _edevice[]; @@ -75,6 +77,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 f80fdd1af2..5e4108a233 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2257,41 +2257,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) @@ -2323,57 +2288,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 @@ -2401,62 +2315,6 @@ static int __init map_device_children(const struct dt_device_node *dev, return 0; } -/* - * handle_device_interrupts retrieves the interrupts configuration from - * a device tree node and maps those interrupts to the target domain. - * - * Returns: - * < 0 error - * 0 success - */ -static int __init handle_device_interrupts(struct domain *d, - struct dt_device_node *dev, - bool need_mapping) -{ - unsigned int i, nirq; - int res; - struct dt_raw_irq rirq; - - nirq = dt_number_of_irq(dev); - - /* Give permission and map IRQs */ - for ( i = 0; i < nirq; i++ ) - { - res = dt_device_get_raw_irq(dev, i, &rirq); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - /* - * Don't map IRQ that have no physical meaning - * ie: IRQ whose controller is not the GIC - */ - if ( rirq.controller != dt_interrupt_controller ) - { - dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", - i, dt_node_full_name(rirq.controller)); - continue; - } - - res = platform_get_irq(dev, i); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to get irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); - if ( res ) - return res; - } - - return 0; -} - /* * For a given device node: * - Give permission to the guest to manage IRQ and MMIO range diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include/asm/domain_build.h index 34ceddc995..b9329c9ee0 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -4,8 +4,6 @@ #include #include -int map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname); int make_chosen_node(const struct kernel_info *kinfo); void evtchn_allocate(struct domain *d); diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 38e2ce255f..40a30c78b7 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -165,9 +165,15 @@ void device_tree_get_reg(const __be32 **cell, u32 address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); +int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, + bool need_mapping); + int map_range_to_domain(const struct dt_device_node *dev, u64 addr, u64 len, void *data); +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname); + extern DEFINE_BOOT_PAGE_TABLE(boot_pgtable); #ifdef CONFIG_ARM_64 diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 6c9712ab7b..5f7ae45304 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; From patchwork Tue May 2 23:36:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229357 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 C374BC77B78 for ; Tue, 2 May 2023 23:37:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528856.822535 (Exim 4.92) (envelope-from ) id 1ptzYp-0005kw-5L; Tue, 02 May 2023 23:37:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528856.822535; Tue, 02 May 2023 23:37:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzYp-0005kp-2Q; Tue, 02 May 2023 23:37:31 +0000 Received: by outflank-mailman (input) for mailman id 528856; Tue, 02 May 2023 23:37:29 +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 1ptzYn-0004sC-M7 for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:29 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2061b.outbound.protection.outlook.com [2a01:111:f400:fe59::61b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4c196cac-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:28 +0200 (CEST) Received: from DS7P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::14) by DS0PR12MB8455.namprd12.prod.outlook.com (2603:10b6:8:158::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 23:37:22 +0000 Received: from DM6NAM11FT102.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::b0) by DS7P222CA0004.outlook.office365.com (2603:10b6:8:2e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:22 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT102.mail.protection.outlook.com (10.13.173.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:22 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:17 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:16 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4c196cac-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U+Jo3aZ/KXfCpID5n2MqwuEg+k/PJWPStk/V7ThEjUdZSxD2n071o+4GiDyi7VQShAVY17IRY7Ygfy2XcBUTIEmJs0AUzAi+Fnktq7MGgARIkko7gEphpqHdWdZ7OE5/VhUK5LRMpnQThG34+rszzv/22fhLnNqzN/+7Pzldq0Muno6B553aa2LvDjmv+IBqyBfCl1PXWMUSqtZY3aOdnS+XotN2TdwdmXXCQ2A+k+3iQcdjgBfnmrm5B4A8n5GKu4s9i6HkjlKMgjDyfb/Jtd6wB+TFceuEhm7elEcPXrJS+G9ICJovNLTohBfS4myaVSYHLTJGDl1hj6QSAnh5jw== 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=vzddX9TV10ndAd/6iE6kCNK/WBOdnTL0B9KxpRRHgRI=; b=j3fsZJ9IS3+TAhj6342U+O5MPJm3D1bTxoachuuFo/r8ed1CYRt4rNRKAn9gD9n0krpTmCoebLydEExor4KfOcxoANBbt3fUieHqEAKR1t0CTUoqzdF80prbHe7a1Txqvz1yGL5JOBlgNKdtAlH1JdFggaU8Fdj3KgGz/OF6ulbE6PMMgPqiVGLQWlcYGv/zOj/KKcwimlVJL+oerHgfQ6rFa5k2ghnpXwHbkoZ80NmtxpJBKJIl2oICsPg0FtlN2TFxS2wgA9bbwe8KB50uqY4ZjyWMxxYOO7DPeZyurt/2WWGFzVwL5Maw0kDemxiYUKBl+FwoL7De839WZvrX1A== 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=vzddX9TV10ndAd/6iE6kCNK/WBOdnTL0B9KxpRRHgRI=; b=zTMm0RzZVvXES+Lc4cafDnZ6fs6J9ghbOAfPJXcrA7fJUAzCobmGtkkaJqH7E2PgoOoihXEnWr+Kh1+BdT7ujmx1hBYb36qg6bhudH5Rk1JZlgBk0IhPz7cJpjqEfzLOA4+xylCoZRhU1X/smL9grrElU3tAmjUoQCPgiexGxic= 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: , , , Julien Grall Subject: [XEN][PATCH v6 02/19] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Date: Tue, 2 May 2023 16:36:33 -0700 Message-ID: <20230502233650.20121-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT102:EE_|DS0PR12MB8455:EE_ X-MS-Office365-Filtering-Correlation-Id: 00c59c3d-252e-446b-6218-08db4b662d61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bXZpaaDpLqpx3roIliDKqmF4bmnR5HXhmhZVM2NqaPcDVBz31GEC/P2lYHnGwskM3ttHDDta60GqtlFtTIBtKvOWiU5BFy3nB0+4yngPumQS6bNottUnxA+rZkIBx4GUOjkWuFzuDkFaapJG8Cha2wE1Rs1l3NZ3Kwl+GD8NAWwjLVK7dExeGwbJww/zmNuRW/1DpZ6S53DTOyWWbEx0cyMxkuD+2GsmLp8U3mvihdVWbrcOCMJJvgBxnqGSPy1eF8+hKrTvyitW9TuJGXIDA0cN83Q8aqbfa+NyW6Q2nzp/5iP7wMe3v5ofIgM+Lvhkkeq7FOAaTObKqS9xEV4GOmF3wDpBT3T19HYOFii1fJcAoxb8lXIgVxrGO982BogbCI3DdjJD2iPUU+Upywx3hAwhcDPcQwmf87l7UJQ3aFkfHQndWb0hw1pNQNvbwBNgAtwUqdDmFPSpzQNnPVhDUpZSNI0sehU2LBu7WKz+a1eUokDVs1L4nVcU5Er1bR03dOcV2gpt6yn4DWC4cJEVjPHb36XXbAdJoQw41qZyl2jteQx9cX3Btr4AiNOIsU7ZKp74sqW4Ns9H7kpvZCG/ZIV/ogC9rEekq7qZesxjsGau3cT+2b/aoImpD/5EKH7t7rLX+WUzX9q3mwdz3udItMPeHZjy5ekkdMXaQSKMeGhGrOPq845wG/bn+LwGKLPWnduD3troODuoJ0ZZDrZTtHtGBYO+Fxg3RikM9XX1iuU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(396003)(39860400002)(346002)(136003)(451199021)(40470700004)(46966006)(36840700001)(82310400005)(83380400001)(47076005)(36860700001)(2616005)(40480700001)(41300700001)(40460700003)(81166007)(356005)(36756003)(70206006)(70586007)(82740400003)(6916009)(316002)(4326008)(186003)(478600001)(1076003)(86362001)(336012)(426003)(54906003)(26005)(5660300002)(8936002)(8676002)(44832011)(2906002)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:22.2380 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00c59c3d-252e-446b-6218-08db4b662d61 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: DM6NAM11FT102.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8455 Change __unflatten_device_tree() return type to integer so it can propagate memory allocation failure. Add panic() in dt_unflatten_host_device_tree() for memory allocation failure during boot. Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang --- xen/common/device_tree.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 5f7ae45304..fc38a0b3dd 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2056,8 +2056,8 @@ static unsigned long unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +static int __init __unflatten_device_tree(const void *fdt, + struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; @@ -2078,6 +2078,8 @@ 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 ) + return -ENOMEM; ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef); @@ -2095,6 +2097,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 +2183,10 @@ 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); + int error = __unflatten_device_tree(device_tree_flattened, &dt_host); + if ( error ) + panic("__unflatten_device_tree failed with error %d\n", error); + dt_alias_scan(); } From patchwork Tue May 2 23:36:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229356 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 3A708C7EE21 for ; Tue, 2 May 2023 23:37:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528855.822525 (Exim 4.92) (envelope-from ) id 1ptzYn-0005Th-U9; Tue, 02 May 2023 23:37:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528855.822525; Tue, 02 May 2023 23:37: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 1ptzYn-0005Ta-QX; Tue, 02 May 2023 23:37:29 +0000 Received: by outflank-mailman (input) for mailman id 528855; Tue, 02 May 2023 23:37: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 1ptzYm-0005Si-Oc for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:28 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20623.outbound.protection.outlook.com [2a01:111:f400:7e88::623]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4ba8dd56-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:26 +0200 (CEST) Received: from BN9PR03CA0740.namprd03.prod.outlook.com (2603:10b6:408:110::25) by MN0PR12MB6128.namprd12.prod.outlook.com (2603:10b6:208:3c4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 23:37:22 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:110:cafe::cb) by BN9PR03CA0740.outlook.office365.com (2603:10b6:408:110::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:22 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.22 via Frontend Transport; Tue, 2 May 2023 23:37:22 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:22 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Tue, 2 May 2023 18:37:21 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:21 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4ba8dd56-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTtkvu0gTNoHijYkh0caIcnZNMVLdlec5IVV1/GIiTyjW8HTmKScMudSqSiA3htV1cZ8vvhz5Bp/iZxudHo6+QUlCAtUcKThf+SRQ50LgjN9tHlngZkudxvpRTONEh2X3jrIQ7j0XDW1jl44qpHXArcZOmLeQibWvf31pSHUv/3Jiov4FyS8ANGHpCEQ16Ebhp3dmYOCLLU3oSD/5GM2sHD9RM0YdolPfIPFvsv5spS352CyEZZBn0DTy/bewuV3hojwbfrFIuT31bYRiCcbai+i86Qs9LrNF5edALt1qcC4S5osQ/yQ3mYm9BwHeuQzP/8yg1iio7VIktsgVQ8pxA== 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=qGBrlYz1MYPx3dVlqExLGnD1JoxqWVU0WGIisylldqw=; b=JGM+vcyC9zcVJ2lePJixNlxjB8OaBGl9kNpIMLOyiWdAyyaFllsWoph8OQu0PUe+WBjm7p5F9YKGVaP3cUkvauBksR2KigrhusO5wEBshJnBuHjtluCBEoW9hm8cgySyGsYiL3VoemRRJ6hSBwbGPxdwMQGh3ZbLsYlXYbIvQ80PiYAL9Ew0KohhuJm5SrL5K3d95bUblb9tydvbEWK3QYC/4R5oG2xOM4CmS58xTI0Rij8YK+/F2Q5JQeZ/kNHRDSOoG/LFQOfloIeFMAjvGBUnSSh8I7BAz7TRS6jIkI1Xv0WuvvQn+tSVfnwWCxj0CN6qgNbSQZpgzWP9jkqn0A== 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=qGBrlYz1MYPx3dVlqExLGnD1JoxqWVU0WGIisylldqw=; b=b0/gi+WxhUSiSWWIvLFFkAUwRqFGs3UEBrAFs07LH6hZ84oI6vK6hqW6holvwjIV3jQiHwobuv5R+dQHHoiqCYsvctQ+e/lOYTIdtXWan8YNF8dBsqGE6UYT4oybDw0v6AyDLHnktDOldilktGJ/5AV4TN9e95H/qWVqiFBbALo= 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: , , , Julien Grall Subject: [XEN][PATCH v6 03/19] common/device_tree: change __unflatten_device_tree() type Date: Tue, 2 May 2023 16:36:34 -0700 Message-ID: <20230502233650.20121-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT063:EE_|MN0PR12MB6128:EE_ X-MS-Office365-Filtering-Correlation-Id: 29ae46b7-ee61-4327-35bc-08db4b662d8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TXciANatIM6/IA9AvojUj9UdWhHKXAjDMGdyeU7y3PB48zQRGYNcagqGIB4G/9pZwjBlr3rKRIB1gvc91DXmfFM/EKpywHX2cc4ldJKyO0WqRdKA1NeVp3RGih4E0Z4auQW29j56ew7JUrTl9LUcmJ+nYoM+V9ULgs6Inyh+Etrm8LLl6Qf/odhshXhPaXXq/L7rZmYz63BSG4HpzeV6clkINLNS3yKBzM/ueQ7YmFvDpLcCMWskCYFXxui12nhmw0urmd4HC3mPMDiWIcigy4idQRczIg9IOq4adYscUamiqrKLVbLEqWkL0UqK3+DKOn56XuSXtrLXuOircKZyjI9Je3gFadHOORoJE/4Jc74qMiK4x+1RoUoHeMV90AKRmbm6yis3hnW8/3zekqawupqsB1wG4KoFW6TQErDNFg82moRqoNZP/NR0hu8QJg6bVDHke/zXNNb6FIYWb3HWAGXlgk1UtOAfs2LgQm7y38qrHh29DZpdwrOKjqhIwfNHStb2q/7ycAHlUnm/4FLUK3sHTvzm5H4Jln/fNq9Pfcad/fF1C6sLNZr759GFEmm17lTzVU4dgHKAizHd8zr0ceqavN6CnDuITP5a+KQUpq6tZqDfhjaoymXCru5MnOyahS7RJaaJBvbrNjt1uFqM8BEuxbHqRrg+f2ZpBZYJCLkmtQwinAqxUpU1ZOH9ZvZ+g22HYi9fqk9I77DriJ/oHFnSw/MgvXuDfu6zLSCAncw= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(376002)(39860400002)(346002)(451199021)(40470700004)(46966006)(36840700001)(41300700001)(8936002)(44832011)(8676002)(5660300002)(86362001)(36860700001)(47076005)(83380400001)(81166007)(82740400003)(356005)(2616005)(426003)(316002)(26005)(40480700001)(478600001)(36756003)(336012)(54906003)(70586007)(4326008)(6666004)(6916009)(70206006)(40460700003)(2906002)(1076003)(186003)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:22.5368 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 29ae46b7-ee61-4327-35bc-08db4b662d8a 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: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6128 Following changes are done to __unflatten_device_tree(): 1. __unflatten_device_tree() is renamed to unflatten_device_tree(). 2. Remove __init and static function type. Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang --- xen/common/device_tree.c | 9 ++++----- xen/include/xen/device_tree.h | 5 +++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index fc38a0b3dd..5daf5197bd 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2047,7 +2047,7 @@ static unsigned long unflatten_dt_node(const void *fdt, } /** - * __unflatten_device_tree - create tree of device_nodes from flat blob + * unflatten_device_tree - create tree of device_nodes from flat blob * * unflattens a device-tree, creating the * tree of struct device_node. It also fills the "name" and "type" @@ -2056,8 +2056,7 @@ static unsigned long unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static int __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; @@ -2183,9 +2182,9 @@ dt_find_interrupt_controller(const struct dt_device_match *matches) void __init dt_unflatten_host_device_tree(void) { - int error = __unflatten_device_tree(device_tree_flattened, &dt_host); + int error = unflatten_device_tree(device_tree_flattened, &dt_host); if ( error ) - panic("__unflatten_device_tree failed with error %d\n", error); + panic("unflatten_device_tree failed with error %d\n", error); dt_alias_scan(); } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 19a74909ce..eef0335b79 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -178,6 +178,11 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/** + * unflatten any device tree. + */ +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 Tue May 2 23:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229358 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 21D85C7EE24 for ; Tue, 2 May 2023 23:37:53 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528857.822545 (Exim 4.92) (envelope-from ) id 1ptzYr-000649-G0; Tue, 02 May 2023 23:37:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528857.822545; Tue, 02 May 2023 23:37:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzYr-000640-C4; Tue, 02 May 2023 23:37:33 +0000 Received: by outflank-mailman (input) for mailman id 528857; Tue, 02 May 2023 23:37:32 +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 1ptzYq-0004sC-9f for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:32 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2061f.outbound.protection.outlook.com [2a01:111:f400:fe5a::61f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4ea29618-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:31 +0200 (CEST) Received: from DS7P222CA0025.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::31) by MN2PR12MB4344.namprd12.prod.outlook.com (2603:10b6:208:26e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:28 +0000 Received: from DM6NAM11FT102.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::f8) by DS7P222CA0025.outlook.office365.com (2603:10b6:8:2e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:27 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT102.mail.protection.outlook.com (10.13.173.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:27 +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; Tue, 2 May 2023 18:37:24 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Tue, 2 May 2023 18:37:24 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:24 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4ea29618-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ya559k3ytzE58QL3KyvkDHWlCou/EpLMtnHz+AfDNesZbJBVQrHCVd9O/X2sfYs05nR0ZAZjqOqgqkRLwnTBn8PpcVmbtU0aopomIApedhGmB/llatC44tqLNBQcHF2dCqtBKIa8XLArx4gGhnW2qK1RbrGhIGqwPHPmb1s2YNb7D9543ZkB9Zlt+sZJv6s+rdx8Wy87BkrDiJD5I7XsjPtr+Vf9b5F8Q+mFGoFu9ICQkq24m3mQrsWcygnqvnH9icSZR8tERgym2WX49BiGJ8FGcasSlWzdsiSdzlJYWPE/lC+KElJ5/0v8NktQghL2FkC3kM2ZyQKZFZYSCqQ5Mw== 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=Rjb1ox/OK8Kv1DTBbQ9Lbk0Z1Hvt88hsPr+KDuGNW5w=; b=Hz+rdkM/wfTd9fxqtd5x1iefsXZ5mWlTJ5i6ondLuEz2ceyHntIcRRSyW2xPHYCNdoO/FphYeMbP+AZcZoJtHp6s9p4jlAWFXTA3fEcpAXjpfvsf5BTEopY8T35mBYsXyruxraWInqxT8jGrWsrSKsWMfA2SKolXZxiEem64KeSU6hGDMIgXP7f3SEEHOnqi2kq9OOcemoTSZZwNjQGWja1kPKIZaa4d2oav8TC96FZr/MuJG7i68c+62fGEoqhrxj5BnLWdRKyWcpqQeS6ptJtAcZNIInrEI9BYFv6vVal2PGQBwa25PVZ2uW/OHC73Khk//DWjUug+5c1c9n8LhA== 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=Rjb1ox/OK8Kv1DTBbQ9Lbk0Z1Hvt88hsPr+KDuGNW5w=; b=ZvkjLJX73yjR4ZHX+wK0pLnIZu3fH6j8wQsc5N42hg8/AmY1r3cFKaB1XlyFRKWL+Oi8LCuu1F0BHRwFcZyTdtns+Lqx4vw1oHrJNhx1kzwEP9wL+1EW0XjNuy1D+bOoh5xsTiu9vgbC7Ov8cG0SeIJ776NQu1jZ1i9n7KM5wkU= 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: , , , Julien Grall Subject: [XEN][PATCH v6 04/19] common/device_tree.c: unflatten_device_tree() propagate errors Date: Tue, 2 May 2023 16:36:35 -0700 Message-ID: <20230502233650.20121-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT102:EE_|MN2PR12MB4344:EE_ X-MS-Office365-Filtering-Correlation-Id: 65cd3dcb-bc7d-4e88-029a-08db4b6630be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /5YqEmdxPxt4isXUmi0aJJ8EK8xbb5p6mWWsxsKih3OJ7jlhYqr0NqHve5493P80TN1pNTDEc1DFblP0Ouzpycrjd+LxkKTEBzbvEtnMN3e0b7KRPMzUypiUo1vK+QbjbHQu8UHfGQM8NKRkzonnvO3DNpIbFFS0Q2vHARa5V8/28bunJXzQWBvd0hF7eHvL5qYHtwBHQfv7GHoTO60+FXPdw52gIbEgSQ6WIYdZzi3QBYV84eZnztPFccpZmoSzu8WlFMg5urAVsfzVEi7cxT7bY58p1ZVfa7j6fvM2TGV5srEiFU+CMjpOgP3oaYNhY5ljK2uilqsJ1IfqqCs0/oahIy8D4bleeMBMspvgbdk2z1x6kn2GVB6SsMRMLa27qzSivp/hx+g851UudOrtAONbpdmXccibs5dRHZnWoC/CDpCTjZKkGwfTnD+X+4XvOTwdvAst1hLtvNA1W5WpR2DkM9VUt9berrNsbMgKu9qnSpfqY8I97Gb0Xpj3RRSyqBF6YGAzlB/81X6dmsZMol/XnQFpbI8Jl3Fpnr+5vAqguHj/viIo1z0gLEXKMpq727MJbJ+7EhcG6ho3W2NDCLaxLfE+2p7vfy+crx/n8ecnpGU0IE3rHw7ZZTiXI6OQo6rd2/cGv6nJyIlL/R65zS1oXPtnok9SYBCJGIQdHge/pqel7XfAsGb4Wy2Wu00lpiWlZigbAN71hL/xve1Ga5PRwfYWRocifoMJu88U9Mc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(376002)(396003)(346002)(451199021)(36840700001)(40470700004)(46966006)(6916009)(70586007)(70206006)(356005)(82740400003)(316002)(4326008)(40460700003)(478600001)(82310400005)(54906003)(36756003)(86362001)(186003)(6666004)(40480700001)(1076003)(26005)(36860700001)(5660300002)(2616005)(44832011)(83380400001)(336012)(426003)(8676002)(8936002)(41300700001)(81166007)(2906002)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:27.8782 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 65cd3dcb-bc7d-4e88-029a-08db4b6630be 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: DM6NAM11FT102.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4344 This will be useful in dynamic node programming when new dt nodes are unflatten during runtime. Invalid device tree node related errors should be propagated back to the caller. Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang --- xen/common/device_tree.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 5daf5197bd..47ab2f7940 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2071,6 +2071,9 @@ int unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) /* First pass, scan for size */ start = ((unsigned long)fdt) + fdt_off_dt_struct(fdt); size = unflatten_dt_node(fdt, 0, &start, NULL, NULL, 0); + if ( !size ) + return -EINVAL; + size = (size | 3) + 1; dt_dprintk(" size is %#lx allocating...\n", size); @@ -2088,11 +2091,19 @@ int unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) start = ((unsigned long)fdt) + fdt_off_dt_struct(fdt); unflatten_dt_node(fdt, mem, &start, NULL, &allnextp, 0); if ( be32_to_cpup((__be32 *)start) != FDT_END ) - printk(XENLOG_WARNING "Weird tag at end of tree: %08x\n", + { + printk(XENLOG_ERR "Weird tag at end of tree: %08x\n", *((u32 *)start)); + return -EINVAL; + } + if ( be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef ) - printk(XENLOG_WARNING "End of tree marker overwritten: %08x\n", + { + printk(XENLOG_ERR "End of tree marker overwritten: %08x\n", be32_to_cpu(((__be32 *)mem)[size / 4])); + return -EINVAL; + } + *allnextp = NULL; dt_dprintk(" <- unflatten_device_tree()\n"); From patchwork Tue May 2 23:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229359 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 DA564C7EE21 for ; Tue, 2 May 2023 23:37:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528858.822555 (Exim 4.92) (envelope-from ) id 1ptzYs-0006LD-PZ; Tue, 02 May 2023 23:37:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528858.822555; Tue, 02 May 2023 23:37:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzYs-0006Ky-LR; Tue, 02 May 2023 23:37:34 +0000 Received: by outflank-mailman (input) for mailman id 528858; Tue, 02 May 2023 23:37:33 +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 1ptzYr-0004sC-JC for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:33 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20620.outbound.protection.outlook.com [2a01:111:f400:7e88::620]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4f841d83-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:33 +0200 (CEST) Received: from BN1PR13CA0006.namprd13.prod.outlook.com (2603:10b6:408:e2::11) by CH3PR12MB8912.namprd12.prod.outlook.com (2603:10b6:610:169::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:30 +0000 Received: from BN8NAM11FT082.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e2:cafe::88) by BN1PR13CA0006.outlook.office365.com (2603:10b6:408:e2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:30 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT082.mail.protection.outlook.com (10.13.176.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:29 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:29 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Tue, 2 May 2023 18:37:29 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:28 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4f841d83-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nQNz5wxnSNHnhF3KsOCS17kfx8SR59b60S+M5rwJS51BB1LlF0e/zbfWbGKAvYUcj3Z6z71tfqp5eKHSE2Q0GuIagR0mTV0KKC9kZXojsXWBZmrKHYjAF5T7YxFddVDBHAPJLNWzJwQz/dL4PsEsLmMBojxcWIwJ5o14t1u8A8X6hNV4Jpy12FrCvfuenKv+BhuCwcVSbnVIQczWNeToQGmsH8VE1N00pU20sz3UIsAe95jOk+MAbaThqojZpzkds5FYpdVm0mhKNmP+2tJbacWdQf7Zxd2O4LKFW8bHU359DPkmwdq8zZR8ua3y1I3daiV+2mu1ydlVQBFlFqtiQg== 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=F0j3i9rO3ndTIMxTYPP/EpeTJUoU0W3bKZrIDhMYirk=; b=LCeMEu8LY7CJcnfW8lVkHrH/Ly9iygD+qYDlGweTDAA7kM4ySyjwLH+W9aLoQ+oysRBimROfg6KAkuTQ6RvetUthIweLOoudGaEnWDlrJ4bb5RFx4R6fOqMVuED4bAGXqN43a0rw9M43c+7bZwCEXTrTM3dx/bF3EiXSBkvcmz/iS2+b6tpr92NaxdcsmZOonL+MGoyXM0tRp76bXvrl3XLyV8IpUzUM5nf24B3uj306m6D78+CkXngZXr8sCUlsNn+Vm10+dQcgO4VxLcHyAvuMqZESXsfdMBWY7wxPI4SCO54UkfyP4ujPMV+tZLXlxAh5ng5/x50ID1wez7LuLg== 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=F0j3i9rO3ndTIMxTYPP/EpeTJUoU0W3bKZrIDhMYirk=; b=wZTm6IKZpqV9BPjt1HFwSMztoYc3VJ1K4NeX2B44LSc0Pqg2I4PClc2ux4dc8Pj+qw/Z7mh3paiX1io9MRxHhFBAoDe5EsIIKPJbT/ZsqQIm2J1yvNKb3kFBCFJduuqlbhQi8s/icZ4jUGexyCSh1RxGGTiWlWx6cF6FvywDrsY= 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 , "Julien Grall" , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v6 05/19] xen/arm: Add CONFIG_OVERLAY_DTB Date: Tue, 2 May 2023 16:36:36 -0700 Message-ID: <20230502233650.20121-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT082:EE_|CH3PR12MB8912:EE_ X-MS-Office365-Filtering-Correlation-Id: eb644b4e-1f72-4a36-9496-08db4b6631d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q7+45602Cr5J7QTaF4ra4FlnfGcVG8zk1+745qMSwgbfzEVWLF1xQNil9Tqpm3jwx99qVNPL71p0iQbUa5/q/alOz9PcI4EzygwQfSRiu2GJk30LShG5kwd0iYvPhPyhutNObrLdQGlSOsnbMEtJZz6FR8X2MWovIPJAZdqUKR+9zYLFyFG4mqGdX5xno1z8yuuaY03D6fQTV7/vszAjI3gyB7ZmJCbW/wYBwbdo+QqSZQneNk5z19FF76HMQzgGG3Jd6JIdtDQhhAcrGw79CgH1gYLkEGHZQRwDJWCjGRateAjHJA0CGVCuNnqNCbsEucFAMf5wZgpspGzpJpsZE6YT4mTBWHj7Eemw8XMYy1ABP5yhlThIUiZd2RCbSwuo9hU4k1dOyEn6y3yx8oAtx4DnRpIrBm5D7x52FoSkihBdDcjZT0q94j2aGtZzaKQGNLZnuU0dM3/Ex2vT7kk7CS2ynsl7t32LBWZ750KFipGUQjGvGpB3WN81oSQxkD5hM501ZVOOmQd2v8A7zg42kjaVq2YXT4P3sBffjYviceUPmU+Ubx4XoY2THoHy7x7/zSQOpdp8Stt4M546mdAQ2hl71xipILnm4h+MYwzkP5H8JHOLwpTgYYXUC4xYY9Sp/XPq5VIDco8dTfq0qBHd2QZ8PzrsL262ARghEZC+b2tqkUK23W2O76fl3JpfJ78OYRT90l+d3gTIZVOu9QZEO1jfAbB1JMAseLJlusMpTu8= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(136003)(39860400002)(346002)(451199021)(46966006)(36840700001)(40470700004)(81166007)(8676002)(8936002)(40480700001)(86362001)(4326008)(82310400005)(478600001)(6916009)(6666004)(316002)(36756003)(41300700001)(70586007)(70206006)(356005)(82740400003)(40460700003)(5660300002)(426003)(336012)(2616005)(54906003)(26005)(186003)(47076005)(1076003)(2906002)(44832011)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:29.7416 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb644b4e-1f72-4a36-9496-08db4b6631d5 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: BN8NAM11FT082.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8912 Introduce a config option where the user can enable support for adding/removing device tree nodes using a device tree binary overlay. Signed-off-by: Vikram Garhwal --- SUPPORT.md | 6 ++++++ xen/arch/arm/Kconfig | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index aa1940e55f..e40ec4fba2 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -822,6 +822,12 @@ No support for QEMU backends in a 16K or 64K domain. Status: Supported +### Device Tree Overlays + +Add/Remove device tree nodes using a device tree overlay binary(.dtbo). + + Status, ARM: Experimental + ### ARM: Guest ACPI support Status: Supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 239d3aed3c..1fe3d698a5 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -53,6 +53,11 @@ config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC && !ARM_32 +config OVERLAY_DTB + bool "DTB overlay support (UNSUPPORTED)" if UNSUPPORTED + help + Dynamic addition/removal of Xen device tree nodes using a dtbo. + config HVM def_bool y From patchwork Tue May 2 23:36:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229360 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 13785C77B78 for ; Tue, 2 May 2023 23:37:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528860.822565 (Exim 4.92) (envelope-from ) id 1ptzYx-0006oD-8c; Tue, 02 May 2023 23:37:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528860.822565; Tue, 02 May 2023 23:37: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 1ptzYx-0006o0-4X; Tue, 02 May 2023 23:37:39 +0000 Received: by outflank-mailman (input) for mailman id 528860; Tue, 02 May 2023 23:37:38 +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 1ptzYw-0005Si-AY for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:38 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20613.outbound.protection.outlook.com [2a01:111:f400:fe5a::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5111dbf2-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:36 +0200 (CEST) Received: from BN9PR03CA0347.namprd03.prod.outlook.com (2603:10b6:408:f6::22) by SJ2PR12MB8651.namprd12.prod.outlook.com (2603:10b6:a03:541::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:33 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::85) by BN9PR03CA0347.outlook.office365.com (2603:10b6:408:f6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:32 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:32 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:32 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 2 May 2023 16:37:31 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:31 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5111dbf2-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dOI3UsBnZi4ADCLNm0yqO8Y/wzh7xghvMpxvyh3MCnsrMZ8Ky7vfl8I+QHrtUg9oCKhturO0n71UZq2frso6yCbXO1lWnREJAYVt+K5dOFXLXE5Olsb5IMzkIZbHWa4MJRTAV1GZoRMPaHHKWNzes1ypE64DR/i3jQ7gjrJcY5nzybAv+sIyq4F4Gqzt1+Ia6DGDpCyQU+Q8oRhQCLv2jb1/xM40c4lntw2shxo6bJlhiOlUKnpXAEmzWOylVL/xqM3BeIbNvIFNoE8fhlxRNvUidpIhPLZddZ5El8GMvLYMreJAs2P8m0paW0cAu204rYjZjQuoXmbvhbnrSu3N2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+aOH8wbfxJ3CDB9n8z4otIPVVDXaY3ZnHxlpPeTlbO8=; b=InGULvt9rlpPWnhP/U/d5fplmSZzkHYKMu7e+WH2tT9AS3c2hL4Dq3egm/4Z1H6DbsJtozSV2+sMFUDHG+33u0THnv4iIJVSczrpgY7e3MUmOsFhuQBs/MDiZvNH+3/RlhpkperW81txoUf/SMeypvyc5tJXtDjhrU2IGucn82LaDOlTpcxtjHoWTMfuYvIJ4OtfcwpEzsyzQv90HuMBoX8PoJZRs2HNYWh1rfhNP3fJv8X9NhchbS6Ctf/JC2J4JXW//d8MP4HgK8OFaxqOe1xA4O+hTnUlmYkBgD/92aHxU79MjgtMLGdwThRLqZ4mUcz1diJP9pAQpI1IcTvd3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+aOH8wbfxJ3CDB9n8z4otIPVVDXaY3ZnHxlpPeTlbO8=; b=28l3iP1mztYxC9ocTLWhJFHIYBjUtI9s7/WBjkQRkkotPrsiTA6R7IZFB8xnjitJVFkqe3/nV5tWzqSh9baKAqazvjCRpAUdxikLGeiUVEJxydzVVZQ4Ew6+wB2PkpqX0uMkY52eQTctpOyzPUjNnkHRb5BI9Ex4esR615JLTX8= 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: , , , Julien Grall Subject: [XEN][PATCH v6 06/19] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Tue, 2 May 2023 16:36:37 -0700 Message-ID: <20230502233650.20121-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|SJ2PR12MB8651:EE_ X-MS-Office365-Filtering-Correlation-Id: 12a6975c-c9e3-4350-bdb8-08db4b663375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EUY32wrrKmUTKyUR8ekT4xiIwr4sbHJVwToDFSGra4BowHtWKoGqIm5p0h6+Qgth+w3gYRYkrKSsfkbvbxKCERjp1e3zRcwEUn7dOU6eYzEBTq7eB7qBPsZwwY25G1YOvy1WuzHlJwnMppbWlmNUVgUwx5LffnAlc89+C8zf5L08ZBorO02pWjexrbqKDRb72CVPYQyariwLzAnJ77dqPILNvtjP21+ADxDE3Z4a07oVMMKyNHzEEcvxSejnQSk25BDNpeLDRhtGgUTljhCgK5xtsllZke95HvqWZdZ5MkUp0w2QrCCKZ9DWlQ07QGGTu+p4wDjVkeRqpQZjtKiliOqcVXedzSi3XwtZsovNCpCrf48k6I5qQNYoYd+PzRyxvvgDWnfAloiTEqCy8MeQcdCyvyfCaGHFAotjM+QWH/B9v0I/bm1IqAWPOMJ5rYA5hRlgDaSyWIJdlzF5GT4b9RPoA1rn43Ls86U6VvzRBhAHoxlpyKFepKIp2ujp+rl4ODmOlUkNX3NT7xD5/BSn2D6qOhiWyR5ROyK8lQ8L6qH9mo1zPnxrOYsuxtd23yqBgqBFJxXcbbt8fWt0dDCU4P5VVeTks4mE05PDqIykKjB55SBT87i2U45dDrN443QULEJ3HL/8wcCFb/02ahhUWVsgWyih0V45Q/95FC/pbPNUqxtX8kAMfV8XuXij+uJfW5ozf9i6kSqajqkauDzcL66ZN0hDofsHjnXnzafeWXI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(396003)(136003)(39860400002)(376002)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(1076003)(26005)(82740400003)(36756003)(2616005)(41300700001)(82310400005)(4326008)(6916009)(36860700001)(336012)(426003)(316002)(478600001)(47076005)(70586007)(70206006)(86362001)(83380400001)(356005)(4744005)(186003)(40480700001)(81166007)(54906003)(44832011)(2906002)(5660300002)(8936002)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:32.4690 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 12a6975c-c9e3-4350-bdb8-08db4b663375 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8651 This is done to access fdt library function which are required for adding device tree overlay nodes for dynamic programming of nodes. Signed-off-by: Vikram Garhwal Acked-by: Julien Grall --- xen/common/libfdt/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile index 75aaefa2e3..d50487aa6e 100644 --- a/xen/common/libfdt/Makefile +++ b/xen/common/libfdt/Makefile @@ -1,7 +1,11 @@ include $(src)/Makefile.libfdt SECTIONS := text data $(SPECIAL_DATA_SECTIONS) + +# For CONFIG_OVERLAY_DTB, libfdt functionalities will be needed during runtime. +ifneq ($(CONFIG_OVERLAY_DTB),y) OBJCOPYFLAGS := $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) +endif obj-y += libfdt.o nocov-y += libfdt.o From patchwork Tue May 2 23:36:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229364 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 30AD3C7EE24 for ; Tue, 2 May 2023 23:38:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528865.822597 (Exim 4.92) (envelope-from ) id 1ptzZ2-0007i9-24; Tue, 02 May 2023 23:37:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528865.822597; Tue, 02 May 2023 23:37:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ1-0007h6-MS; Tue, 02 May 2023 23:37:43 +0000 Received: by outflank-mailman (input) for mailman id 528865; Tue, 02 May 2023 23:37:42 +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 1ptzZ0-0004sC-C1 for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:42 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060e.outbound.protection.outlook.com [2a01:111:f400:7e89::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 547f4a68-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:41 +0200 (CEST) Received: from DS7PR03CA0208.namprd03.prod.outlook.com (2603:10b6:5:3b6::33) by DM4PR12MB5071.namprd12.prod.outlook.com (2603:10b6:5:38a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:36 +0000 Received: from DM6NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b6:cafe::99) by DS7PR03CA0208.outlook.office365.com (2603:10b6:5:3b6::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.32 via Frontend Transport; Tue, 2 May 2023 23:37:36 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT068.mail.protection.outlook.com (10.13.173.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:36 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:32 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 2 May 2023 16:37:32 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:32 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 547f4a68-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SrS7MKU7griNkYaA1QkcHvAz1NT8Pcu0D5BbYbnr/ayE3Ag2TZjEAUJeykBeDaXsA5VusHzafAfq9VJXw3ttMv2CFBiLSJ0z5I7f0vh1BFv9GDdfZpWFzPGSek133i900JsoaYci0E48xxOkP1vEnh4P2N2QEPWI/SFxduijnXRENOkau8cBF9ZrbApazqiLabACxtapl0C+j5BfSa67NWNL3LN84UAQ48hNyQbfigittrGm++/NF3A4fSh5sEQ+UolZsEPgxCkZTwtpDnnCgPWkuAffKFSCQhmPtjtCZztWuem8sZTmwvJvEYaL4Eyb66/3gcL2XV1GjUdCUzQhRw== 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=Izi8iFk0zRF4BRyNOjdDxCvThsPDcczKcmdhMhR/3Sk=; b=KwdI1Z2YIxKavOXDxN7d/J7eEfXh5WYQDKccFRFeEFXolQusimheCwFSdn/y7h3MTVrREeYn2U3ccn+o4HiGQGONPtDZI6ZmYrBYkS7i2z9EuhY32wnsQ+G+QvsEVfvdNKRZx9D3ZHx7c1FgN4Q+9EQieG2qGsQh6FDuUDTBHOlTplJBB7qE8QZ4khYu9Hj1yRAKSj+sf5WFHUitLLhsn7sWoaOWlLahHCnTiDj03VcwJxJ0WA0RJpstYXxRSTwvmM7TaqhTB3C2oh29RKc1dspvpZxorovjxYTwUGWOkIFs8a1SaeZcpwCNdZnbigNbsHvaX7jxLv70qGCwGoqb7g== 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=Izi8iFk0zRF4BRyNOjdDxCvThsPDcczKcmdhMhR/3Sk=; b=VuNvzciNWJ4Lx0/rMEBLsVGEvfM3eIhHYxvb38q6fUaQhmahn2jrDfK13eOT4zO6kuHGYo2lPTbE7BXQUoePeXmsaxTwV8kiZL/Z/DO0z0UHp++qYoBWDSmBDt5+3mUR876gzcBMLQaWKvZ6KAQLrZ8tKHedZ0VE5wcw/d43Z0Q= 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: , , , Julien Grall , Vikram Garhwal , David Gibson Subject: [XEN][PATCH v6 07/19] libfdt: overlay: change overlay_get_target() Date: Tue, 2 May 2023 16:36:38 -0700 Message-ID: <20230502233650.20121-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT068:EE_|DM4PR12MB5071:EE_ X-MS-Office365-Filtering-Correlation-Id: f6d2c9fa-7007-410d-69ba-08db4b6635a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eVMJI7TaxrFA/V7rVr0NqyN0WoPsJmJvpK7gnokNKWc6GU6g0vqSn53EQn8c3sZR+4IlT+SZXnzwOdMGL8hBC27wg9fxzUer8ui8dimykTIZ39M61mFWDrIOkU3MaSYs08NbJBF78SvnQ3Rl/04M5ZQbnm50kYVM+xuuysOjHSwg7ADDjZAFOKudF2RLo345dH7lylPcFnBHCKhj8areY+Awtd+W04IxWTRr5VWlON1qYjC+IwzZbe96lxO/By9yFLCrFaOBIr5a28yf+R8w2Wa9BxsO/v9QrzTRYmuDORLX0yFSPNCG6rnLRUHdJTO2S7cN6vobJXqW7qHGuEAgOo6vVEIQV2Za+BzFLAGFEjWOGfJTiGTf8pVefihRFj7KWqxpVtycFmywKfjkJDdePu2d/vCZ0nuqC0/ogh6BxUZ2YXenwusJuHyul7Mb/PUMGFgOvz1kjU90KxxHT3NPC/l4kpEmmcO/nDaZ8HevIC071FtUTX8DvlZp7LOOLSFhIiSAcXWJWHBsmw3inYsPkoA7DPVySm699o/TNOrps57+iASgLNDV6HnGxdCodGHRL6gtJP8wJRzVbK1k2YNYhvzhlKlO4AXbfPmzYTVUstKBm+eXr9sF5kCCF+0cLWKtJd8dFYTvmWS8R0LCEUzYbHfeL8a8/2xO+eoJGsghtKUwk849j0WhKaQxucynE+dIkj3Z8JtIlmgoMFzrw/rp2rTWFGUIwdP+W+4XR+Qkzqg= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(396003)(346002)(39860400002)(376002)(451199021)(36840700001)(40470700004)(46966006)(26005)(1076003)(40460700003)(316002)(2906002)(70586007)(8936002)(70206006)(6916009)(5660300002)(86362001)(4326008)(8676002)(44832011)(356005)(81166007)(82740400003)(41300700001)(82310400005)(40480700001)(186003)(478600001)(47076005)(36860700001)(2616005)(336012)(426003)(54906003)(36756003)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:36.0859 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6d2c9fa-7007-410d-69ba-08db4b6635a2 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: DM6NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5071 Rename overlay_get_target() to fdt_overlay_target_offset() and remove static function type. This is done to get the target path for the overlay nodes which is very useful in many cases. For example, Xen hypervisor needs it when applying overlays because Xen needs to do further processing of the overlay nodes, e.g. mapping of resources(IRQs and IOMMUs) to other VMs, creation of SMMU pagetables, etc. Signed-off-by: Vikram Garhwal Message-Id: <1637204036-382159-2-git-send-email-fnu.vikram@xilinx.com> Signed-off-by: David Gibson Origin: git://git.kernel.org/pub/scm/utils/dtc/dtc.git 45f3d1a095dd Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Reviewed-by: Henry Wang --- xen/common/libfdt/fdt_overlay.c | 29 +++++++---------------------- xen/common/libfdt/version.lds | 1 + xen/include/xen/libfdt/libfdt.h | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c index 7b95e2b639..acf0c4c2a6 100644 --- a/xen/common/libfdt/fdt_overlay.c +++ b/xen/common/libfdt/fdt_overlay.c @@ -41,37 +41,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) return fdt32_to_cpu(*val); } -/** - * overlay_get_target - retrieves the offset of a fragment's target - * @fdt: Base device tree blob - * @fdto: Device tree overlay blob - * @fragment: node offset of the fragment in the overlay - * @pathp: pointer which receives the path of the target (or NULL) - * - * overlay_get_target() retrieves the target offset in the base - * device tree of a fragment, no matter how the actual targeting is - * done (through a phandle or a path) - * - * returns: - * the targeted node offset in the base device tree - * Negative error code on error - */ -static int overlay_get_target(const void *fdt, const void *fdto, - int fragment, char const **pathp) +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp) { uint32_t phandle; const char *path = NULL; int path_len = 0, ret; /* Try first to do a phandle based lookup */ - phandle = overlay_get_target_phandle(fdto, fragment); + phandle = overlay_get_target_phandle(fdto, fragment_offset); if (phandle == (uint32_t)-1) return -FDT_ERR_BADPHANDLE; /* no phandle, try path */ if (!phandle) { /* And then a path based lookup */ - path = fdt_getprop(fdto, fragment, "target-path", &path_len); + path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len); if (path) ret = fdt_path_offset(fdt, path); else @@ -638,7 +623,7 @@ static int overlay_merge(void *fdt, void *fdto) if (overlay < 0) return overlay; - target = overlay_get_target(fdt, fdto, fragment, NULL); + target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); if (target < 0) return target; @@ -781,7 +766,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) return -FDT_ERR_BADOVERLAY; /* get the target of the fragment */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; @@ -803,7 +788,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) if (!target_path) { /* again in case setprop_placeholder changed it */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; diff --git a/xen/common/libfdt/version.lds b/xen/common/libfdt/version.lds index 7ab85f1d9d..cbce5d4a8b 100644 --- a/xen/common/libfdt/version.lds +++ b/xen/common/libfdt/version.lds @@ -77,6 +77,7 @@ LIBFDT_1.2 { fdt_appendprop_addrrange; fdt_setprop_inplace_namelen_partial; fdt_create_with_flags; + fdt_overlay_target_offset; local: *; }; diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h index c71689e2be..fabddbee8c 100644 --- a/xen/include/xen/libfdt/libfdt.h +++ b/xen/include/xen/libfdt/libfdt.h @@ -2109,6 +2109,24 @@ int fdt_del_node(void *fdt, int nodeoffset); */ int fdt_overlay_apply(void *fdt, void *fdto); +/** + * fdt_overlay_target_offset - retrieves the offset of a fragment's target + * @fdt: Base device tree blob + * @fdto: Device tree overlay blob + * @fragment_offset: node offset of the fragment in the overlay + * @pathp: pointer which receives the path of the target (or NULL) + * + * fdt_overlay_target_offset() retrieves the target offset in the base + * device tree of a fragment, no matter how the actual targeting is + * done (through a phandle or a path) + * + * returns: + * the targeted node offset in the base device tree + * Negative error code on error + */ +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ From patchwork Tue May 2 23:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229362 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 A36E7C77B78 for ; Tue, 2 May 2023 23:38:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528863.822585 (Exim 4.92) (envelope-from ) id 1ptzZ0-0007SI-Sd; Tue, 02 May 2023 23:37:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528863.822585; Tue, 02 May 2023 23:37:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ0-0007Rn-Kt; Tue, 02 May 2023 23:37:42 +0000 Received: by outflank-mailman (input) for mailman id 528863; Tue, 02 May 2023 23:37:41 +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 1ptzYz-0005Si-Hf for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:41 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060f.outbound.protection.outlook.com [2a01:111:f400:7e88::60f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 53775b0b-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:39 +0200 (CEST) Received: from BN9PR03CA0343.namprd03.prod.outlook.com (2603:10b6:408:f6::18) by CH2PR12MB4103.namprd12.prod.outlook.com (2603:10b6:610:7e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:36 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::43) by BN9PR03CA0343.outlook.office365.com (2603:10b6:408:f6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.32 via Frontend Transport; Tue, 2 May 2023 23:37:36 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:36 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:33 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:33 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 53775b0b-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OcuBEpgBv91+CABaEHG+sQ13V2oVko2y7E2qN/5olSnow6SkQ+e+yyDAb836RN70VOUGaV90hYDVSa27niA4ayCVwQoOt02mfu+k4kEobVnj9G2oyeYg/7SpbE/FJ5nqCgNCrElGFrFGstapy/Hv1E2S3FS0PpfNaoX20JkYDudfKiuAQbmrDTeCQ0GFXgD3MVLrFnve3e30AYtjM6fvwTLUqjUjJGgPmLSnke0u+Xl5tJpKoaVfxSNHu2oNXvU6cptQAwbf/bwzAqKNYs9bSCJVF7u3gUVCJWXl4W7SU+Hb8I1YQH0S/+347z2LPlTVkeTIee4hqjLCxgr4JjxWAQ== 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=LptqMUkxHVxrSuaM+i6CgX8fqOqrHiX3/jew+F/gQRs=; b=P5m/nNPtt7VhJ+pgTHeLyfND9vt7eBABWqquZOefh7SK/CVMMtlusCr/PoLJj58WB0KuvT8srAFToGBx7q0WdFPWDilN/rM1EU/BDpEWNF4aYEmXWWXV0ISbMXVTdFoR4kyK7F2U9MPSL1EaFDrQevS9emZT2ed3u1HNE5adJvI6Eg1p6elajde6wJTDH2V0wFBDfACLY70kdeUAxDjss0ykfQKxB7b6PkAhzifjgpq8uPz2DxLOBszkPLL9tnf5I7vzkkC0YmxWvTxbm3T5wirzdnq2VzXslrAXuKKVC0G1jmgLrCrLPdtHXcxefFjeph5C13/vY7UNiVhFcRCyvA== 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=LptqMUkxHVxrSuaM+i6CgX8fqOqrHiX3/jew+F/gQRs=; b=w2IDg1FiVeNBJgY/xOdKhF9kBqNjIivZ1AzFnDhj95o/f++ewR0Mga7GrIvkOIlNU+lo2HVVGRrgAHMnMu5MATjB5JpJl0r9kgOSoB2NsdNcz4S5AKOKazjoFCaOsPgssVMlkhvz1LmlCf47gfcJvXLyWfV94QjW9+lVL0yfoLs= 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: , , , Julien Grall Subject: [XEN][PATCH v6 08/19] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Date: Tue, 2 May 2023 16:36:39 -0700 Message-ID: <20230502233650.20121-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|CH2PR12MB4103:EE_ X-MS-Office365-Filtering-Correlation-Id: ac7d9bfb-95f8-4823-ffc0-08db4b6635c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tnVNrl+EWQRdKhMY7bSFdykTa7BAPjsgesGWpRYzgt3des1TrY6lbV8bTx/RSGE/6bFXXXz3mzRE6kQf+3X2bk5oJnkQRcc7WBBEsrjJxBzR8GUwoN6pgR+S77tDxhBkhbg1Y9pIQEA7Olycq75K+X8MIBVhghJCbdsgsEUulzmI0RhNPr2ZPy18El+vNcYMg9//H7gOWxsFdVlI8ykTjbT/GZNhcEwiNYkE/3ctwXj9LpYUeC50SmZtMayqvbRQz+0iLywP6Gpc3tYTWEQXR4DebiSh0iOMxDPfgSGy3/kmLCLkSiFnQHCSeVlBniI853HZ+/GcIceOU9rXq0EFvYO8nRf2rjlgmZ+TX48Eo9VjFMfihoiPKrtk4Jw/FVX3lUCVMWWwxlHqncYWfA3IBFGOp+LmQMZVJaDXpHQG48p3YPuNZByepSTyp7oFTeEfPlyVPpoyE2Htxd9K8PGPqNNfDqcOm3ulPFH8sFGR73SX+gSS6c0kcd46rvWcncxcVxh174TD2RaGzLpSZ5GJsTsFNrgU7FE2geHXrxs6z5p1S65mYDBasXV2UaoAdWMQ8eLxcu3rVmTD+MEGTYkmg7kaAsVd5RvPXNKvek4fGhqx8uvUc7q8WzX6A0tzAinnYwPNsjvR740o9gjRGJkRT7bZ1xcqEOVx6hciulPNN1kEwjCTJGltj12IrExAQWTy9Q2ZPobgGPsnspKEyjCRqfDLlEc8jrLDm1rqOUwOIy6pZav127Epdm4y4Yvw3p701bFIJu94gKtPWtmgoVcFlA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(346002)(136003)(451199021)(36840700001)(40470700004)(46966006)(81166007)(41300700001)(356005)(5660300002)(8936002)(8676002)(70206006)(70586007)(316002)(82740400003)(2906002)(86362001)(40480700001)(40460700003)(44832011)(6916009)(1076003)(26005)(186003)(4326008)(336012)(83380400001)(36860700001)(426003)(47076005)(36756003)(82310400005)(2616005)(54906003)(478600001)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:36.3595 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac7d9bfb-95f8-4823-ffc0-08db4b6635c4 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4103 Add device_tree_find_node_by_path() to find a matching node with path for a dt_device_node. Reason behind this function: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, we need to find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. Thus we need this function to search for node in different unflattened device trees. Also, make dt_find_node_by_path() static inline. Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang --- xen/common/device_tree.c | 5 +++-- xen/include/xen/device_tree.h | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 47ab2f7940..426a809f42 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 eef0335b79..d6366d3dac 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -534,13 +534,26 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, struct dt_device_node *dt_find_node_by_alias(const char *alias); /** - * dt_find_node_by_path - Find a node matching a full DT path + * device_tree_find_node_by_path - Generic function to find a node matching the + * full DT path for any given unflatten device tree + * @dt_node: The device tree to search * @path: The full path to match * * Returns a node pointer. */ -struct dt_device_node *dt_find_node_by_path(const char *path); +struct dt_device_node *device_tree_find_node_by_path(struct dt_device_node *dt, + const char *path); +/** + * dt_find_node_by_path - Find a node matching a full DT path in dt_host + * @path: The full path to match + * + * Returns a node pointer. + */ +static inline struct dt_device_node *dt_find_node_by_path(const char *path) +{ + return device_tree_find_node_by_path(dt_host, path); +} /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the From patchwork Tue May 2 23:36:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229361 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 07054C7EE21 for ; Tue, 2 May 2023 23:38:02 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528862.822574 (Exim 4.92) (envelope-from ) id 1ptzYz-00079J-G4; Tue, 02 May 2023 23:37:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528862.822574; Tue, 02 May 2023 23:37: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 1ptzYz-00078z-Cp; Tue, 02 May 2023 23:37:41 +0000 Received: by outflank-mailman (input) for mailman id 528862; Tue, 02 May 2023 23:37: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 1ptzYy-0004sC-BZ for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:40 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20622.outbound.protection.outlook.com [2a01:111:f400:7e88::622]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 52edf28a-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:39 +0200 (CEST) Received: from BN9PR03CA0346.namprd03.prod.outlook.com (2603:10b6:408:f6::21) by SA0PR12MB4591.namprd12.prod.outlook.com (2603:10b6:806:9d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 23:37:37 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::97) by BN9PR03CA0346.outlook.office365.com (2603:10b6:408:f6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:36 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:36 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:34 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 2 May 2023 16:37:34 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:33 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 52edf28a-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oU0ePOBiG+WFuk03h0aJuvgatXHo+HtslAsPF8/SjrUbRNz8GXcE6/2YtKyf2A3WNBqM/by7vOzfKMQPzzDyeXALfUbt7/SeNc4I3gJAEiWCEVZ5eOKWK9oviDcLb0JSPdTN0yse3ah6rZMytRmMZhM6PaQtXJg/fszsXPDNQmLVN/OUtJWZyjTKPHoEfSo+i87cYeYVhnDW9R0dupPBdcbaYxu1X5xBCG1Lsmbo6YU/j/rTWYzIdHKNkaoyBmembCoYu2+LKlVCwUnOCY7UoYKNFj2xydv8oaQQSC512dihHORCxXyXCFSngN0q5bM75KMH67vUboctcWB0vEepxQ== 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=A7a8SO//tZf8dnpDvLiol5y8mZo4siOv2JmDmv476O8=; b=VqaAMbUA8W+NWm2MXFVLuvfkaddrdbCs+sVauAxPeDyqqEHIRgL7MJ8bhyh/EEQPXoyNCU3kX2TvQKvx25tQjvMUQnNDBXpx22lvHABtkG/Wvk+Md/sWQTU7Vl+3dqdo7A/wN60WgtkcPw8W3jjzteyRTl+tR0R4r2+MMjiYruO5hdJLH7xlWYh569bXNu01MTUaZUy7Gp1tAmOHNgtra0doncKwGbvqufaZ/qjaewJeeNZzO9vZrjZdAVukKILS8jVlNiZWJKnTSrZtS/x4HiqtKHxmUVBfxFhlt2xH3+Gt9RgbKt5uUZCcjvJdv/Wv/Ep0kg0KWjvwcZAyWKkgkg== 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=A7a8SO//tZf8dnpDvLiol5y8mZo4siOv2JmDmv476O8=; b=Y//I1YxSxs07Ke9XfwSAHsAWj3cIR16fafxzouwyg7k7PxSVdnm/R327CwyfLaFnMIwvGCTaQ5iaEwIhXnlPPsD5xCnQ76ZtuXM3DbJ4ruYvVuu4W2dDGBJpceuYQM6u0e6v5lpEAhlJ/vxyg9E7eLcFNVACK57GfkN7yPy3fU0= 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: , , , Julien Grall , Jan Beulich , Paul Durrant , =?utf-8?q?Rog?= =?utf-8?q?er_Pau_Monn=C3=A9?= Subject: [XEN][PATCH v6 09/19] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Tue, 2 May 2023 16:36:40 -0700 Message-ID: <20230502233650.20121-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|SA0PR12MB4591:EE_ X-MS-Office365-Filtering-Correlation-Id: 86cb0c46-2d1f-4b3b-d4d2-08db4b6635fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r57mn/8nqbzEuAz8S7ebrddM+Jxdwf2cJa/mk60QqgcX+ghGXqbDvH7/hBVwN65/HxegsidKm5aDS+lpeVGcb6F9Z0cJreUAUojCavL7rczSVca3BYtsQKK7ixCyalADViBc2aMjyLILeoA/TINRadND2fd1Hp77IMkkffNScPof4TttK6FiH0/mOospzN8mam1RCAUC9pdeRSQ1+AClmYzPWdQ72O4e+nffDx75VM0yUtL2XwW43Bz6A5olRP5fwDBRTBDE38wAs4iekfeix2VYzysm0RzggOJ7ZVxjLSQ4xDrU7vZAwj4o7hmp2EgPIV7koe5E21v+WsVzT0XpkSqI8ctgGPd822o2osF20PxaeBNug8p2Qdpr8BF7uPcJyXLwUdf/0BFjez4VyanZzn0du8D2iMiBhPdkdQnfNnH6baW2EzFVZx2w4gPGivf73B3MWCYHLyuNticlldp/cHx/aCKI36ldyK8/kTYFZ53DiD1CJi5HVuJc36P1bXMXmBmp/hiDlMFhu72uYkKCpiQ/g8VHXilp5Wdf9AewmIH5Y05OdLhm2038GIe6ImZWMUOso9jrlKSn4eR9EE5yGjp/RnnwEsHL+AfUNYHLzQWLKsYHe7ou3VMroIqwcLj0Yp25sQIlwdZFJqCfZT3Y6fuTyl14bBEysGXBPKJVaGrTEZB+CZkx7mvJb5ZmkLbYlRvz7+J5R+c9gZ3DdRcieIACPBOdFVPtxtbecppjMpE= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(136003)(39860400002)(376002)(451199021)(46966006)(36840700001)(40470700004)(47076005)(40460700003)(2616005)(426003)(186003)(336012)(40480700001)(36756003)(86362001)(82310400005)(356005)(81166007)(82740400003)(83380400001)(36860700001)(8936002)(6666004)(8676002)(316002)(41300700001)(44832011)(5660300002)(54906003)(478600001)(4326008)(6916009)(70206006)(70586007)(26005)(1076003)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:36.7188 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86cb0c46-2d1f-4b3b-d4d2-08db4b6635fb 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4591 Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_locked(). Remove static type so this can also be used by SMMU drivers to check if the device is being used before removing. 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 | 19 +++++++++++++++---- xen/include/xen/iommu.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 1c32d7b50c..c386fda3e4 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -83,16 +83,14 @@ fail: return rc; } -static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev) +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 +211,40 @@ 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; diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 405db59971..76add226ec 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -214,6 +214,7 @@ struct msi_msg; #include int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev); +bool_t iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev); int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev); int iommu_dt_domain_init(struct domain *d); int iommu_release_dt_devices(struct domain *d); From patchwork Tue May 2 23:36:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229366 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 D0C5AC7EE21 for ; Tue, 2 May 2023 23:38:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528868.822614 (Exim 4.92) (envelope-from ) id 1ptzZ4-0008US-L4; Tue, 02 May 2023 23:37:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528868.822614; Tue, 02 May 2023 23:37:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ4-0008Tz-Ew; Tue, 02 May 2023 23:37:46 +0000 Received: by outflank-mailman (input) for mailman id 528868; Tue, 02 May 2023 23:37: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 1ptzZ2-0004sC-Fg for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:44 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062c.outbound.protection.outlook.com [2a01:111:f400:7eaa::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 552ea58e-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:43 +0200 (CEST) Received: from DM6PR10CA0030.namprd10.prod.outlook.com (2603:10b6:5:60::43) by PH8PR12MB6841.namprd12.prod.outlook.com (2603:10b6:510:1c8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:38 +0000 Received: from DM6NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:5:60:cafe::88) by DM6PR10CA0030.outlook.office365.com (2603:10b6:5:60::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:38 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT073.mail.protection.outlook.com (10.13.173.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:37 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:35 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 2 May 2023 16:37:35 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:34 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 552ea58e-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fVNgEAorIrinAzAbFAp1oO37hZXxBb7ekDWjwhWkcemEPGnxRKqcW+m3UToKpPlfVd5OCRi1xKCFrZ5/wejFBIqH3b1Sg/PB2Gch6emWZvgQ8egmSLDJ33AbTJIrCRcn6yeNRSi5YjHKGgW0RvmZYOfrcEVXpXtwKkSabinpq7IdVcbt2VjGlEWFGoNlfIPP7T1S6jkb8Vo0Mo9X6mkX+eE+gQA5ntIefbtpOGhR9OAYBiD/6w84OY6lZSXdK3bZ4TBHKtP4l3CasBIvAKuwRFk9xrXybm5I2RfUkP1tfYo2E051mpKe4JBWuDr6UIg6bxyNST9AcCBfRsgz3JlGXg== 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=45fuJEPfdOT3ElxOeWsri05r41QvJhpC/khBsBhOc+k=; b=ltr4GcawQtiBZOSzhjSlRlnkHepmTmdlewD6rX+IyOnI3Qa0LfkDFdAJL+YFn1zSkzgBVKIl0ZYra/377eGVtKJkDB/QS1G9Gx7cQ7W0OjEhLrtQVq05w0nrfPRtqcJKkocQAfU+tHtORxkrmo0ywS9hFQuhc05Ibiys4Kecv0D3QXRYBmMfDpNhqyZ1A+aNUwrMfA+hpyfeCtQpHSL0iqhcofaTixr4F5QliDttmXUExnqhYAnKj6S77jlubO6+MY3Tp00N1CFECr7kYBf3FrPJQVFXbMwR8saRecwD+Xe3vtR3s7sq4HF3eW9tfZdMPrwGcGMirvRqTe4uD/27SA== 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=45fuJEPfdOT3ElxOeWsri05r41QvJhpC/khBsBhOc+k=; b=f8ysGqbPRFTrPohT1BVu30l4EsRvmo5iN1OZd5jYXU1jJPbaurGryIB/ed7WzKBC8kShyNGm0hocom6HFA2xp3LLHwyDlR21MvM0LDlP8Qbr7lKzzckUhrnSyLtrgeB8JTqcJPoFLPry19PslYAGuGQKRG6I7Xlyu1gCoJ0yiFE= 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: , , , Julien Grall Subject: [XEN][PATCH v6 10/19] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Tue, 2 May 2023 16:36:41 -0700 Message-ID: <20230502233650.20121-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT073:EE_|PH8PR12MB6841:EE_ X-MS-Office365-Filtering-Correlation-Id: 79ad38c7-1516-43e6-acb0-08db4b6636c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NU8RTqxFer0gTDcYCP8jr+YW3AMDAsYu2QvLaiu8yd98kz3m4aPe0bQWQEwgYiIdstnCe19lnOY3Xye7H7DwX7O8UW56F7yM9nwvcy1JQAc6rcNZbOSxR2PG2bdbrJCrkvTvNtHlhP4/M4d+rUoh8jEynp0yVWHXSMGg9uwY8OVHhZIFoOyYXZJiCgxo2CpVU81kWQdvBKJ+9dGL+mjsQQWor5CamdMZROucpMUupXD/bZIVlPAZ57cCYHaqf4W61yqsW8tV/XYcnKESHWvCva67K6QkrokKkyiExt2abTqEECYfekxRmbYg2bV3vuaEl6ZnnfYU7MQ32qxyPHEOTz4mMOQiAPSFnaMLfTh8vSzeelg+lLIfhxH0VYpNjyTHHahFFqXaIdCnBIMmMetWnFdmbOeElN7Q/kH+izWNQSsJIHioRxrKBZx+FzrvQNiOhJ4I6Le3omOpfDUIZXP/QYGpTUcFGVVtjGNZomH5v9QVIpauS3pOMtWTpnYWhH59Ze2ts3dBNAdqRy4zELKma4W2XvNmeVRCzdYT3fUsy4TMe7GaCkrCB3adacu7lAJTQCjA39Fs7PzN7nHMhzdFEMIvxp5WZezlFReFpekc5vT7EhmbuJ1WyntoWf33ocp/766tix0lhGZjAIwpelVWUPKZJOFmQbZDnIUfc6TAsFYYWcus/E24U1PsPwnlRU+rnwNKWIblsuESa/gPXDi3eNKp+UtS4VARwlth7KSQg1s= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(346002)(136003)(396003)(451199021)(36840700001)(40470700004)(46966006)(54906003)(478600001)(2616005)(83380400001)(36860700001)(47076005)(40480700001)(6666004)(26005)(1076003)(336012)(6916009)(4326008)(316002)(356005)(82740400003)(70586007)(70206006)(186003)(426003)(41300700001)(2906002)(81166007)(8676002)(5660300002)(44832011)(8936002)(40460700003)(86362001)(36756003)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:37.9816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 79ad38c7-1516-43e6-acb0-08db4b6636c3 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: DM6NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6841 Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access add. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel --- xen/drivers/passthrough/device_tree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index c386fda3e4..f3867ef1a6 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -145,6 +145,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. @@ -157,7 +159,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; @@ -188,6 +193,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); +fail: + spin_unlock(&dtdevs_lock); return rc; } From patchwork Tue May 2 23:36:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229368 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 7C4C1C77B78 for ; Tue, 2 May 2023 23:38:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528871.822633 (Exim 4.92) (envelope-from ) id 1ptzZ7-0000YY-7U; Tue, 02 May 2023 23:37:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528871.822633; Tue, 02 May 2023 23:37:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ6-0000VP-Im; Tue, 02 May 2023 23:37:48 +0000 Received: by outflank-mailman (input) for mailman id 528871; Tue, 02 May 2023 23:37:46 +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 1ptzZ4-0005Si-IQ for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:46 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20605.outbound.protection.outlook.com [2a01:111:f400:fe5a::605]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 54ed58db-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:43 +0200 (CEST) Received: from BN9PR03CA0357.namprd03.prod.outlook.com (2603:10b6:408:f6::32) by PH8PR12MB7026.namprd12.prod.outlook.com (2603:10b6:510:1bd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 23:37:37 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::c6) by BN9PR03CA0357.outlook.office365.com (2603:10b6:408:f6::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:37 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:37 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:36 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 2 May 2023 16:37:36 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:35 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 54ed58db-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lnzedPcLVf9AgNtKSrsWnxlj8wg/n0b35HQajSB8VeMk4/pP7cndeadLyZowOcl2cp8NM5Php0iB6EEijSr27Gcr6oW5YxBvmLqan8hePFHoBA5z8xdMPfKDTamtWJK6IpxtnoDCI9SeL+WK7LJTuFWhKNAIRL+NdnJ0FBQ/cQyBL8XbJIUfuBHGHgrlwky19/krsIwZ9Skv1eUOqyI1tdoS/SIGj21ZpfUacUZRD4ipLXElLbe4+FHqUPd47hstrCmvywKSfZHcubZ15rpdxhjTXVTD4X5T3SiSuexWs5l5ITZkTiXtg8e+NkVOv6HoD202Y8xKvgoADEnXjVu7kQ== 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=rIRy40Pphy3puPxLyarufMzgZUdXxhJqsOpQVvIQDWY=; b=hUh4Ds6KIjy/4l/tB4nJ3FwOgDFMEgiZmqb4yxVATYO+IOx+kG3xHZS8zilSoIVmBglcIUo6LhW8N0KL+ZE66jVfkv6sI4Ei+3us6nzoco9EAKtcuK3sFkpvZwkdFRncjFHPfWEbAj9dH4fRhCiwmjM+HqHgsDkvQhOl2UFtFm5QxluZsBkNmu9QetIzLlQ77P0p3Tumwv613ZgUCs+gAubxx/yQiYTvYWcXJw3BiYiTM9kHFNkdGJYydGQcTMviMfyfSViCujx29GugZbQ2twaF4jbnYsBIWP84S2dICBi7p7hwqPwN0rt1AoDgDjLDJ1hxf6atjmg9BbgDWeV8Kg== 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=rIRy40Pphy3puPxLyarufMzgZUdXxhJqsOpQVvIQDWY=; b=Q/vuMHZ8fOVxvR+uIcHcM5KH/SxWuak/R7bE8S7aLTxzJu0aA69UCBk4z+RcfrbI/eNljptrJ1S/C/+1SkX5AUO6FUgc6h5GxXXpkyB/cYLkV2Law6ezhiZ6LuNTcuQ/N0Eg9OBAgvy0i+4aQrIdO3C1mjAgdEmVTeHyi1cRViQ= 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: , , , Julien Grall , Jan Beulich , Paul Durrant , =?utf-8?q?Rog?= =?utf-8?q?er_Pau_Monn=C3=A9?= Subject: [XEN][PATCH v6 11/19] xen/iommu: Introduce iommu_remove_dt_device() Date: Tue, 2 May 2023 16:36:42 -0700 Message-ID: <20230502233650.20121-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|PH8PR12MB7026:EE_ X-MS-Office365-Filtering-Correlation-Id: 2bca90a4-d19f-4adf-e3c7-08db4b66364c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Mzjbtg8HLssdAgmmIu3wUMMiNi91uy0HTN5DYlJM0B0ON8jJCxHlcp05X1gONEuw9Oc9aAAkv+VsvX5rXJB+IDtvfdptl0OPABfZkC8hOeVvmaLUJj/uHlvze+znXRGJvmukIUrLfu/0HUmPlImEE9I2g7+JnNZBX0bRZiw9zVDjP1BHgMaMysjnJlSNJE8R2rBETEiD2OthCc7X1SmBVh97APnSTMDBTM96YtBhuWENBFZru89Y31VeMxXbo9PjDO1ZQV5xAU3lNvgXjSDG+r1TclAGDFsRaEgg8Sfs4U3cfCRgubWjassDtP/MY5RbsqS+mTrXHFO7VyLsPZQMDO8xA4CdJ3xZRHayJGBxf1uGpb15h/Rm01w5QJ5v6S2+99dN2sy/n3JDj3er/Adl+xeZd6Kp+sUKAE+xMbUcOuLhvqn9LCegjapwsNzrpWiybDx0SuOkkNLfwWcwjGvdTSe9k0KJpLXmH30clwUls/CAwOMlIV5Gb380W9oMSk0+hysSA2uq7C0APc6XI5pyyej24WoLWviAjsjbITzBwqI8h4+mrZTsWiy/tWaaJPNKC6QEGLZ2SUNpBRvWZSYzluTAXGClYkmSpmyImqPDfHFsQZRGKL/AVXBDTEEryo/lAtTmPHUsjcxD4OGjKX1CSln//eDn2adIOoy9LmYcQPKQQ4U37/jgo3Av3tIChk5j4Z94PV5Nm8WrQ3GkreUCWXNSw6vt3wp/qXUzN2jeerY= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(376002)(39860400002)(396003)(451199021)(46966006)(40470700004)(36840700001)(2616005)(83380400001)(478600001)(36860700001)(186003)(4326008)(54906003)(70586007)(70206006)(6916009)(47076005)(426003)(26005)(6666004)(336012)(1076003)(44832011)(316002)(40460700003)(8676002)(82740400003)(8936002)(5660300002)(356005)(41300700001)(2906002)(40480700001)(81166007)(82310400005)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:37.2500 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2bca90a4-d19f-4adf-e3c7-08db4b66364c 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7026 Remove master device from the IOMMU. This will be helpful when removing the overlay nodes using dynamic programming during run time. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Jan Beulich --- xen/drivers/passthrough/device_tree.c | 41 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index f3867ef1a6..46f9080c8f 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -125,6 +125,47 @@ 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 this + * callback implemented. + */ + if ( !ops->remove_device ) + { + rc = -EOPNOTSUPP; + goto fail; + } + + /* + * Remove master device from the IOMMU if latter is present and available. + * The driver is responsible for removing is_protected flag. + */ + rc = ops->remove_device(0, dev); + + if ( !rc ) + iommu_fwspec_free(dev); + +fail: + spin_unlock(&dtdevs_lock); + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops = iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 76add226ec..6ba8d73966 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -219,6 +219,8 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev); int iommu_dt_domain_init(struct domain *d); int iommu_release_dt_devices(struct domain *d); +int iommu_remove_dt_device(struct dt_device_node *np); + /* * Helper to add master device to the IOMMU using generic IOMMU DT bindings. * From patchwork Tue May 2 23:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229363 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 3E22DC7EE29 for ; Tue, 2 May 2023 23:38:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528864.822590 (Exim 4.92) (envelope-from ) id 1ptzZ1-0007Yx-CL; Tue, 02 May 2023 23:37:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528864.822590; Tue, 02 May 2023 23:37:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ1-0007Wg-5y; Tue, 02 May 2023 23:37:43 +0000 Received: by outflank-mailman (input) for mailman id 528864; Tue, 02 May 2023 23:37:41 +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 1ptzYz-0004sC-Se for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:41 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20600.outbound.protection.outlook.com [2a01:111:f400:fe59::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 53a655d4-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:41 +0200 (CEST) Received: from BN9PR03CA0358.namprd03.prod.outlook.com (2603:10b6:408:f6::33) by PH7PR12MB8180.namprd12.prod.outlook.com (2603:10b6:510:2b6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.28; Tue, 2 May 2023 23:37:38 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::ae) by BN9PR03CA0358.outlook.office365.com (2603:10b6:408:f6::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:38 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:38 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:36 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:36 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 53a655d4-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VMuhiR7OjqK98R6C2Y+i2BwUPlmh/NGw2J8UYvPW8dKGxBa1iV1j5v33lhksmAVKe8fslgYp/p8OyGG+xz6Yr1br6oRqS0Rz0txYazHtUOD3ENh0pOiA/yDPtHWUDAxT7OftAIsG2ievhkgIQippqVQLEZAyw0TONxPYxx5dhumzJUrnPc8mXShxNWcUGBp07e/cxB+hH4Wn7z7+89ipGslY+3JEqTGd5NZbhw+pfEUEdSQbG+ECynalrKb3jBZJbH6kWsKdCQsfTePuf4YAURIh4hT1om4sjnbmzd9krWT5Vowk9s/jFQJqpKnvqgsBtq+LsKKsTsMr2fv5j2Ir0w== 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=o//kziDFlVk7rDkLuyZCz6gXGJUkyhMLecqyMP3X36E=; b=j8RnKyNane9AlUt12z+CtWCP8pOZJ9vwNhFsxN7qgdNLCaOXJqeW5/nstSsVhdlOdS2zpo9RJXTId1o+lgEA6ubGR0qWqV1zxbj6rqkju6O9IWxYmRaWHqIy4uBg+MTBWM3oZ383FjVz1K+kpQCezutbY8mrCbAvdSmXk205liAE5ejIgOHkfzMQk4IIfSICMGnGQpzwhjUopVSdr47z6VNVZmSn3ceddCp20aT/mh6hIS9Oad6BT/m2wrH1msLYYLzy1bmVFZ8U61GkSJ7yWEsZiOfAjB0rGJTiusxx0v3UYqnMd9WWb2wWMghl6/2BxWA8qOYIHKlwEPYgLPd4dA== 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=o//kziDFlVk7rDkLuyZCz6gXGJUkyhMLecqyMP3X36E=; b=K4bFgZs7i4fiQhliTFJ3687gVb/NFX5VZnNbJDYqIW9oAIuSE3IMOJ2I+uhNXIlwU2L3tqpyVuXWv2EaH04PzPmADLC3xQ4laizDvvSdI6KWscP5sqSJy6huRLe+/sYVY0xti30U20nWlkJrdkgcfxaMe8iMNeaLbx39WJb6YJE= 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: , , , Julien Grall , Rahul Singh , Bertrand Marquis , "Volodymyr Babchuk" Subject: [XEN][PATCH v6 12/19] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Tue, 2 May 2023 16:36:43 -0700 Message-ID: <20230502233650.20121-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|PH7PR12MB8180:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a718bd1-80da-4de4-b416-08db4b6636c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NiE6EW8yQhtuk8zLuQOPtsucZA/jm2YfnWqSL444s42WCtwp71ub9OatR2Zk4hEGxH4OiRqh+3BZj9X+/rjfKeubFY/6ciKhQ+1pvi2nyqzdIutUKkIeP5cCziAw1FLWaYZ/5BjtcBdZSMvrGqR+phs+kNQOtnSKM79X8lo+JvdRDsHR5pUBVWELT6C4qLbQj1eP6egOYuThDxG+2aBRWEXWDKel8IV/u+5AfT/ms6OGA0SJd+UEevJoae7OfTnCLkew/JMFZb+7udFcrwlg9sK8S9e3ejXkUBVJ0ANwZjNCzxNQgcmf8LmXHl181MER0Ltc1IIVfHwjut0Ab70W9sSeiFhG58DPmMYnTNEw4QU1kL+9b4MO0pivJgu5RKwWvYJ6vqwjZ1FaPsdVu83bnneVzMsnaLAT7cLGL58Xr9fjMYa9k/+v39LL0LNfGEVhr3QuE9GxBW9zqLFUI0NW33kDXfzlyytuBwJc8X//GWC7s82JEtLWz85zM7/h8YmNqWWRfuVNoxtzfrwLKEhXyQYiCrZn/iOMyPSPAPqSy20XRFmBI3YFoAp2hXPY9b1RVzgACY6Ay5jFdkebh/9l2pJlzKkVR7tG0vdDHxiiBu/+Dgfcd6x2SunGKnGV1QgKPU5xBiuPhY0rEQycKJWWbxvz8XKG03oDxR315qg+C9zAAPokCoHbTOEO24NCu8DfDyo3nmkHoe4R3UVJdaW52lMat4Htl1aQu8T0/HPqF7c= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(39860400002)(136003)(396003)(346002)(451199021)(40470700004)(36840700001)(46966006)(2906002)(478600001)(47076005)(70586007)(70206006)(40480700001)(8936002)(8676002)(83380400001)(5660300002)(44832011)(426003)(336012)(41300700001)(356005)(81166007)(54906003)(82740400003)(4326008)(316002)(6916009)(2616005)(40460700003)(36860700001)(6666004)(86362001)(36756003)(186003)(82310400005)(1076003)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:38.0156 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a718bd1-80da-4de4-b416-08db4b6636c1 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8180 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. Check if device is currently in use. 3. Remove the SMMU master. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel --- xen/drivers/passthrough/arm/smmu.c | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index 0a514821b3..39d3a5c345 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,34 @@ 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; + } + + if (iommu_dt_device_is_assigned_locked(dev_to_dt(dev))) + return -EBUSY; + + 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 +917,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 +2915,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arch_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, + .remove_device = arm_smmu_dt_remove_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .assign_device = arm_smmu_assign_dev, From patchwork Tue May 2 23:36:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229365 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 04431C7EE26 for ; Tue, 2 May 2023 23:38:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528869.822620 (Exim 4.92) (envelope-from ) id 1ptzZ5-000060-6Y; Tue, 02 May 2023 23:37:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528869.822620; Tue, 02 May 2023 23:37: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 1ptzZ4-00004v-UB; Tue, 02 May 2023 23:37:46 +0000 Received: by outflank-mailman (input) for mailman id 528869; Tue, 02 May 2023 23:37:44 +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 1ptzZ2-0005Si-I8 for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:44 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20615.outbound.protection.outlook.com [2a01:111:f400:7eab::615]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 542f6709-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:42 +0200 (CEST) Received: from BN9PR03CA0353.namprd03.prod.outlook.com (2603:10b6:408:f6::28) by DS0PR12MB8017.namprd12.prod.outlook.com (2603:10b6:8:146::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.20; Tue, 2 May 2023 23:37:38 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::79) by BN9PR03CA0353.outlook.office365.com (2603:10b6:408:f6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:38 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:38 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:37 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:37 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 542f6709-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lbLrY0XLfmtX5VteDWmQwhU0kk2Ylnhgds6RZ+kfmVv+oussvigC+N19O6lGs47+KeUblhHXdolMu9LH6xcHSmkRtx+yYjeY2V1qZTGJo7ZCRPwbhTYpVYUHIRmEpJbdX1P2cAHvf3C2RksP+jLk6vMv/ByNntBL78KPO2SNbGAAe3vTB8Q83yTXoKrXtEIAUovJ6/HTXVJPWI7TWQbOck8P7Tae/+L/rUiXDEL6IrRRYNRRWsMS1zYbVMPo9XClfsovvTbbvDeQpLMqEbBnj8eP0igPQb1TU/c4Aww3cmwDbkYqiI/XQcz231ht3T1raBkk6Oz05iiYUq0i7X4mbA== 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=+CZpvoQNw8JQfGrQR7sP9j/mivY1rVi0G0xxugML0N8=; b=OYsyBQ2qtqWf9g4uKUwiBP9H0/uFQGZgVXvKlpP8iP5ZoN4x9aKo/EFMymredk4PiW4oSgu3M5BWjelyXrC5qMVLoKFCLxWVOm2e6lgMhpwnbviHTt3NEhe5ivHhIrqa0bBFHNkqWBZLY8KddIbB6/W4T+vhlFyzWnjk3DQLF8RRYe21RM8so3gX9N1dJW2FzJWV3WanfYdE2DU0DbFmQkL8JKuOyf7L4cAmuDwiuqIZdkV70RS6oVV+bOEA89Y/TWwz/lkHPbQdKw1oLrYKh2rpqYesYyCN5AefVo/vtk/zeWTFbpWNaCK/xHq8t4KkmvMo35sAFYfpLLDpiS29Dw== 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=+CZpvoQNw8JQfGrQR7sP9j/mivY1rVi0G0xxugML0N8=; b=wPIjnURyLlj93gqdi6Z9aCwXcg+joWkR/kkmEM8sFZVJWqiAR9Zzf0gTzm0bh6clUjcfjwg/jMz6JuCxjD1vPxnPWM3Dqpc7cgWJanHT2GKTQ0W6aORAjlFk1ik/ZvSlwGmyUcBI+Ab0WbZQwEutjYwJ9Gj1xFpOVhJ40cnjhUQ= 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: , , , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v6 13/19] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Tue, 2 May 2023 16:36:44 -0700 Message-ID: <20230502233650.20121-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|DS0PR12MB8017:EE_ X-MS-Office365-Filtering-Correlation-Id: 497fbd75-4f3b-410f-3942-08db4b663709 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QDJUL5UEsyw4J3mOZMHxO6MCIzm75A6YFTW2AkkQIcsuLRHs5vWqj64AKqydffx5mFFgPMwILp2KH7S/s2EeVNQYdWveT69oPyb25LzbrtBEY592D+WV68LQ/kx6hV3nBM1JFUIjzLIgJWIyHWGIorDRg4GP1w5RAXulf+7Q61hrJYNXc4Pd9DFyeJqOAFYhXwKMW5c41bI7WgyN/jD4cbQtX4+6oBUuizaN5u4f164CJMLg3DyiDK5/ecex3eh97PyONaJDMjaq4B74FyltkzLDz0YtnSA9VveGUs3Xe1smDdM9pATBCVOIjfVHem1wkh8FFVPBU0N9imnou9JI+jT+CS8rhHl4D860WfrG8ZjIkl+7yY4czOHf95HOZyR8Vf426SllumytAZFP3XhrP7bVD4tfqPGqy/VEe8Zf+HsmgtCyd0wcvYtBxi1VoozpHHUrdNm3mUAvnZ0S8MJ9U2nJnYFSI+mcemuUSkVWFxadpIokx9PaJ4VZQM42dtFk8cCW7QHC+7Jte7kNSJ2b339pKiQiYj70ICIhvNywYHEL7eOzXMUvoUqnKx1IRDGhVu9xeyVIOylmJpw0eQ3sl80hABabLPFDJLRct2aPwDDHF0tYgL2JNPAFDVnzs7ZsO6Zdzxh3A0SeGwDw0nYk4+Bknur1eOWtGSDxHvo/j715/FTzc6LAIlQUoGk3DM9tzpbwNTHw2Ga+YJ/rb/btLKHjzTx9KHbjiGOnco08ufU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(346002)(39860400002)(376002)(451199021)(36840700001)(46966006)(40470700004)(81166007)(356005)(82740400003)(44832011)(41300700001)(8936002)(5660300002)(8676002)(2906002)(40480700001)(86362001)(40460700003)(82310400005)(6666004)(36860700001)(47076005)(54906003)(478600001)(186003)(36756003)(2616005)(70206006)(83380400001)(1076003)(26005)(336012)(6916009)(70586007)(4326008)(426003)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:38.4843 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 497fbd75-4f3b-410f-3942-08db4b663709 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8017 Dynamic programming ops will modify the dt_host and there might be other function which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host. But adding rwlock in device_tree.h causes following circular dependency: device_tree.h->rwlock.h->smp.h->asm/smp.h->device_tree.h To fix this, removed the "#include and forward declared "struct dt_device_node". Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang Reviewed-by: Michal Orzel --- xen/arch/arm/include/asm/smp.h | 3 ++- xen/arch/arm/smpboot.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index a37ca55bff..b12949ba8a 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -3,13 +3,14 @@ #ifndef __ASSEMBLY__ #include -#include #include #endif DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); +struct dt_device_node; + #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) #define smp_processor_id() get_processor_id() diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 4a89b3a834..255bbcc967 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include From patchwork Tue May 2 23:36:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229367 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 8F5CAC7EE24 for ; Tue, 2 May 2023 23:38:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528870.822625 (Exim 4.92) (envelope-from ) id 1ptzZ6-0000Mm-3V; Tue, 02 May 2023 23:37:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528870.822625; Tue, 02 May 2023 23:37:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ5-0000Kd-M3; Tue, 02 May 2023 23:37:47 +0000 Received: by outflank-mailman (input) for mailman id 528870; Tue, 02 May 2023 23:37: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 1ptzZ3-0005Si-IN for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:45 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20624.outbound.protection.outlook.com [2a01:111:f400:7ea9::624]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 55505898-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:42 +0200 (CEST) Received: from BN9PR03CA0343.namprd03.prod.outlook.com (2603:10b6:408:f6::18) by CH0PR12MB5267.namprd12.prod.outlook.com (2603:10b6:610:d2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:39 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::43) by BN9PR03CA0343.outlook.office365.com (2603:10b6:408:f6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.32 via Frontend Transport; Tue, 2 May 2023 23:37:39 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:39 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:38 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:38 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 55505898-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QJGXP6I5DbTWCJd4UPQsUa0et2w6HnKRklEs3Tq0HDyaZjomDSMmOx394jyxoEYWtAH6vCir7FylPFU47fc5cNMSPqak6eMuO60yyiS1EqWOULnwGw6+asuLYM933ih96Mlz4rdVOpmwLYAyPBEP9t8vE5yFsf7bHbV4I/Dchquluyt4YAkiDVcSaV8BpTMtQTWOD10Gins5RVJpjeduZkDKnL3jubsobkU9OAVDcU58UFWtQO8oMrkNifcG8+gQmEa0XZxKFfY3bw7JHWvad/J1pZN6gywslRw3mFs+sy8g5c7DzMxMnnZh4ZUkhYrqSY0rHmnzyMydW8mBwsGjbQ== 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=vIBy8QBowBYZ6c4wTJeiTkeZZ3rBM64WqnXkHigySw8=; b=NR+ALs6okeXu7dtkr7pF8B7BIDy9LXA4clEVyPo7OHLKid4HxwQCPa6HuTiDDxEHk6LT1A9FfYuaNZDF//KamLzgVZnaUUBnezUlWuAH6zBLqG7DQy1KYcNd62eZkEb0CtH7SKWfVJLs1jTqL+vA3jr3TWWrHHeM6SbHyN1lqL+sVexlS2Spqx5JVYVgGFaf6aVbTt6irajHTJpcgjl5DCyoyXCQawyLUGXKgVeuBkdh7QYfOAU8kjH32Z2MPE6ORFCDwVcond62doT2494uDpknItOSiuq3S/LnYgdhmKt7LehAavC9htErHbgv7D1l0XH3IiGVzCBhjc9daIx9pA== 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=vIBy8QBowBYZ6c4wTJeiTkeZZ3rBM64WqnXkHigySw8=; b=FxrmF8KpbY8OMt9twCQcmBtIxQj5cssKdQJWsbfwwjf9LZ6+wqZgxnrMzBXMKkjrx/97XNSxcVTeU9iV1fn8YxDLaXlDFB+NgnzDSeKR8p1cOZ/EAxELUFAnFuguxJt4eaX1z3OTPb9ONhgsB6iCik+9jIrYsV0EUMufMGS4rZE= 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: , , , Julien Grall Subject: [XEN][PATCH v6 14/19] common/device_tree: Add rwlock for dt_host Date: Tue, 2 May 2023 16:36:45 -0700 Message-ID: <20230502233650.20121-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT047:EE_|CH0PR12MB5267:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a7aefba-4bc9-41ea-9579-08db4b663768 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bY3CIOnIcI4X9pEmoRAiF0hbj8IBsn/tdl4KhSa8MyxKKPCRWysPgd+5Su4M60i8YtOI3p0Ob5N0HQGmeayfBYiS1j+xRM1O5UHiP3eVLwM3SB4Xert+T/Ta3TJvAWgRQMAju3f/bxjG975cMuNiwfCsys72Qfquwuc2QTVKY8iH9vAozLUVnqobOJiHJi2yGLIk5Uc73GNtigC7fOSTVU/dDDZn715IDTPsLtwj0f9YWiCBfZShzDp4cfOWCttgnVX7YmXIAIw35g8prowY3mh5dX7a/F6gAtEw+w5Zlg9N7nUY5KGlBINMtKrHyug7jsHHAceFgSKSfPKqhrLf4PsfetJAUldfao/+rkU4USgq+59DcH+RK5FR32N5VV3qNza4glve1w2pUBY4q0dwFuYCX9mb7RQ6FC212GdKc5CWVwGWnXtEvcK93whOoJcwYzlbnjyc1TGvF1DQIVDutwjYLMQgjyExTKPz+YpuxPWbd6+dWxzAmr6e/9gbYBRVEL+avVZOYBcFpS7SG8bE7kG+4h0SrM3RbvEpfrZXsLCNzadFqjC18NLaBVYyFbUh+DDMJRaoBnvU70sxgoqXCcbaM55SVGF1qXxgWB+eSaT7PMuJTw+FS0kTxfaJnkEP2Hr4WPdZP4lENxwUyzA5B+qZoRC2I374aMQUTVrLvVueswPoDjcuhl+HCx7F/QWwFH7COFZnePKschJzE3miL3N+gGL7wabVZMpH+GqMs70= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(346002)(376002)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(81166007)(26005)(356005)(82740400003)(1076003)(186003)(83380400001)(2616005)(336012)(36860700001)(426003)(47076005)(36756003)(44832011)(40460700003)(2906002)(40480700001)(41300700001)(54906003)(5660300002)(82310400005)(478600001)(6666004)(70586007)(6916009)(70206006)(4326008)(8936002)(86362001)(316002)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:39.1092 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a7aefba-4bc9-41ea-9579-08db4b663768 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: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5267 Dynamic programming ops will modify the dt_host and there might be other function which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host during runtime. Signed-off-by: Vikram Garhwal --- xen/common/device_tree.c | 4 ++++ xen/drivers/passthrough/device_tree.c | 18 ++++++++++++++++++ xen/include/xen/device_tree.h | 6 ++++++ 3 files changed, 28 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 426a809f42..48cb68bcd9 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2109,7 +2109,11 @@ 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; + } static void dt_alias_add(struct dt_alias_prop *ap, diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 46f9080c8f..e3be8e3f91 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -111,6 +111,8 @@ int iommu_release_dt_devices(struct domain *d) if ( !is_iommu_enabled(d) ) return 0; + read_lock(&dt_host->lock); + list_for_each_entry_safe(dev, _dev, &hd->dt_devices, domain_list) { rc = iommu_deassign_dt_device(d, dev); @@ -118,10 +120,14 @@ int iommu_release_dt_devices(struct domain *d) { dprintk(XENLOG_ERR, "Failed to deassign %s in domain %u\n", dt_node_full_name(dev), d->domain_id); + + read_unlock(&dt_host->lock); return rc; } } + read_unlock(&dt_host->lock); + return 0; } @@ -245,6 +251,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, int ret; struct dt_device_node *dev; + read_lock(&dt_host->lock); + switch ( domctl->cmd ) { case XEN_DOMCTL_assign_device: @@ -294,7 +302,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, spin_unlock(&dtdevs_lock); if ( d == dom_io ) + { + read_unlock(&dt_host->lock); return -EINVAL; + } ret = iommu_add_dt_device(dev); if ( ret < 0 ) @@ -310,6 +321,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, printk(XENLOG_G_ERR "XEN_DOMCTL_assign_dt_device: assign \"%s\"" " to dom%u failed (%d)\n", dt_node_full_name(dev), d->domain_id, ret); + + read_unlock(&dt_host->lock); break; case XEN_DOMCTL_deassign_device: @@ -328,11 +341,15 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, break; ret = xsm_deassign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev)); + if ( ret ) break; if ( d == dom_io ) + { + read_unlock(&dt_host->lock); return -EINVAL; + } ret = iommu_deassign_dt_device(d, dev); @@ -347,5 +364,6 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, break; } + read_unlock(&dt_host->lock); return ret; } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index d6366d3dac..e616dd7e9c 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -18,6 +18,7 @@ #include #include #include +#include #define DEVICE_TREE_MAX_DEPTH 16 @@ -106,6 +107,11 @@ struct dt_device_node { struct list_head domain_list; struct device dev; + + /* + * Lock that protects r/w updates to unflattened device tree i.e. dt_host. + */ + rwlock_t lock; }; #define dt_to_dev(dt_node) (&(dt_node)->dev) From patchwork Tue May 2 23:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229370 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 D6FB6C7EE24 for ; Tue, 2 May 2023 23:38:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528872.822640 (Exim 4.92) (envelope-from ) id 1ptzZ8-0000vu-EI; Tue, 02 May 2023 23:37:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528872.822640; Tue, 02 May 2023 23:37:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ8-0000ql-12; Tue, 02 May 2023 23:37:50 +0000 Received: by outflank-mailman (input) for mailman id 528872; Tue, 02 May 2023 23:37:48 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ5-0005Si-IX for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:47 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062f.outbound.protection.outlook.com [2a01:111:f400:7eaa::62f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 553c6b0d-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:44 +0200 (CEST) Received: from BN9PR03CA0742.namprd03.prod.outlook.com (2603:10b6:408:110::27) by MN0PR12MB5714.namprd12.prod.outlook.com (2603:10b6:208:371::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 23:37:40 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:408:110:cafe::24) by BN9PR03CA0742.outlook.office365.com (2603:10b6:408:110::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.32 via Frontend Transport; Tue, 2 May 2023 23:37:40 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.22 via Frontend Transport; Tue, 2 May 2023 23:37:40 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:39 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:38 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 553c6b0d-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jf+Pl77K6re/uAAOe5J4d4QO0tluyAQnYENz1B5K2kLmkfK2zC954matqkxE/DTpmsorFJIonpoTDzx7fOFWprJ9S7Bvqll8TlSBiH4BnemvzvPeyso+0rpNmy7MGyKe9KPnttUlKYLAVY/2z3e+s6elSp2vRTD3rB8t2rKpgXyLwAO0SUN8+5T1AjE6mtISgWvX1r6pQ6RuqfvZv2DAmJkAlqlM4YY0cf9Tk9FoYwTlozNsKDQs6j9tM6mYER2uQfX0AebVFv5gdx6amuzpHtDwMbuArX3JLSIkG1n6SLSdKfzjjzU7bJ3iXCm8iSc3RTRVKXJQ+0+aFAH/H26Zhg== 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=6lA6+5GWeGyVJ/eIdTxBUhZWKw1xIAoedVb14517C6o=; b=R6TNLe8+2RrL5HKo7lQY9ChtM6wPoQjqI8QVsU8yacg70PslIwv7gsqU7yDzeNGVO1WSXiUFFloIUrWWvnMlYozfoc8SN5SfQA0GwUFJ5BDkYb1Twasrbq0iNx3vOf7QE7rKjuK3+8jUJEnBaJ5oU3w0i9ZiUE3HRoZ47JfaXOTkDQdhjJMEcpKmY2Sdwgz9BgbM37J63dDvfPx+YoeoIRPYoYjQH5CHPyaQPk8E4aTG1bdELaS2K3smzybPrlYqZOBA4VMScnkxL95NYvLkofVWX5+lHA2D1dkU+gwfYt5e923k9TK46aNuqqBW7vzxT5JbER2Z3W1Y/qhI7QUEUg== 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=6lA6+5GWeGyVJ/eIdTxBUhZWKw1xIAoedVb14517C6o=; b=Qpbpu8+IF1xpezD7wZX6vbBwY7w0HXK28rUpruhu9xKRMEx7yreFz58Lf2T5UN2N+v0m5Horm7pVGooqFKqAXF7r991YNQbfOlfKUIZnUigIKJ+FwxKz9CJyPxMPkOXvR7mfmvE8FrKnYtmjopNVAfQXEAD1uGNQGY3XumDNZmU= 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: , , , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Wei Liu Subject: [XEN][PATCH v6 15/19] xen/arm: Implement device tree node removal functionalities Date: Tue, 2 May 2023 16:36:46 -0700 Message-ID: <20230502233650.20121-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT063:EE_|MN0PR12MB5714:EE_ X-MS-Office365-Filtering-Correlation-Id: a9d8e0b7-d6c2-42a9-5f77-08db4b66380b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ObIVh6nvqFLs+CfF0txS2yj8MSGrx3IkESWWOS7Xihpa/omLs9Z9DE8hsoMksIvtKx0wYkWBMOeby0wVb1AaD2Nxasd/fA4vpgtHlVtsZMIDKnhMRYN5huYQf+vZF6zHJ3uxhxbXhVVcC7wlIavLfsBYoteJ3fgYy1m8lwwt3T7gCyFMT1WAT2VHCzEXFVrX4u/ohnQVHcTDD/yI2MZ+ve9Bj+itFG+yWdtj2FhWLTfpfOQ5K1AwmF5egPx9yHffC7IpiW7dDyrntp34WUZn5zUzu8ivEYK4VMWd4zRsG3198PLBcyIB3k9/WPRIFiV4N5EuHGmIcdcVJlNoREsELzT6iociJr01r+kj6SyCNRoesUFHIQCKD+d3Gz3PEWNGi7Lj1s8OnEvXlIRE1VVfWGRe8sslB4bOswgD8hOkJc029sFq1Ma+flo/M/PmvdF6zyMf5zfmL3+ORytITDp5xsVGsy3bYncKMVn8GbuTXjFxkWFUrpiIhfDNu46TtPkNzBZE1jsQnwGHC+qQgeaCAffvndxLlY54DegzisCl7N2oKgmmxdM/A+oS1PndxHWIwxUFpULO7HJvqEtKkd4ycf5Mp8DbL1rGea1tPF5Obu34rEn0hqKDeOBlbzLC4UaXM9rhs8ZxpQ7WhrJT7sKCUZYjS1ivbWQqzeJTapEjNWsjVuQodkj7QzUZ75wLFgspkTSIxMXmzirTDOlWSN7dA1tprGom/4NNEou1nBB6mWQqv+eqIjDx4j+2DHuZSC3r6RKTLITpQQL6MLc7a52+9g== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(39860400002)(376002)(136003)(451199021)(40470700004)(36840700001)(46966006)(478600001)(36860700001)(36756003)(316002)(5660300002)(2906002)(30864003)(40460700003)(8936002)(8676002)(70206006)(40480700001)(86362001)(4326008)(82310400005)(70586007)(81166007)(6916009)(336012)(356005)(44832011)(41300700001)(82740400003)(83380400001)(426003)(47076005)(54906003)(1076003)(186003)(26005)(2616005)(6666004)(403724002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:40.1605 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a9d8e0b7-d6c2-42a9-5f77-08db4b66380b 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: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5714 Introduce sysctl XEN_SYSCTL_dt_overlay to remove device-tree nodes added using device tree overlay. xl dt-overlay remove file.dtbo: Removes all the nodes in a given dtbo. First, removes IRQ permissions and MMIO accesses. Next, it finds the nodes in dt_host and delete the device node entries from dt_host. The nodes get removed only if it is not used by any of dom0 or domio. Also, added overlay_track struct to keep the track of added node through device tree overlay. overlay_track has dt_host_new which is unflattened form of updated fdt and name of overlay nodes. When a node is removed, we also free the memory used by overlay_track for the particular overlay node. Nested overlay removal is supported in sequential manner only i.e. if overlay_child nests under overlay_parent, it is assumed that user first removes overlay_child and then removes overlay_parent. Signed-off-by: Vikram Garhwal --- xen/arch/arm/sysctl.c | 16 +- xen/common/Makefile | 1 + xen/common/dt-overlay.c | 419 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 23 ++ xen/include/xen/dt-overlay.h | 58 +++++ 5 files changed, 516 insertions(+), 1 deletion(-) create mode 100644 xen/common/dt-overlay.c create mode 100644 xen/include/xen/dt-overlay.h diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c index b0a78a8b10..456358166c 100644 --- a/xen/arch/arm/sysctl.c +++ b/xen/arch/arm/sysctl.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -21,7 +22,20 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi) long arch_do_sysctl(struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { - return -ENOSYS; + long ret = 0; + + switch ( sysctl->cmd ) + { + case XEN_SYSCTL_dt_overlay: + ret = dt_sysctl(&sysctl->u.dt_overlay); + break; + + default: + ret = -ENOSYS; + break; + } + + return ret; } /* diff --git a/xen/common/Makefile b/xen/common/Makefile index 46049eac35..e7e96b1087 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o +obj-$(CONFIG_OVERLAY_DTB) += dt-overlay.o obj-y += event_2l.o obj-y += event_channel.o obj-y += event_fifo.o diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c new file mode 100644 index 0000000000..b89cceab84 --- /dev/null +++ b/xen/common/dt-overlay.c @@ -0,0 +1,419 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * xen/common/dt-overlay.c + * + * Device tree overlay support in Xen. + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + * Written by Vikram Garhwal + * + */ +#include +#include +#include +#include +#include + +static LIST_HEAD(overlay_tracker); +static DEFINE_SPINLOCK(overlay_lock); + +/* Find last descendants of the device_node. */ +static struct dt_device_node * + find_last_descendants_node(struct dt_device_node *device_node) +{ + struct dt_device_node *child_node; + + for ( child_node = device_node->child; child_node->sibling != NULL; + child_node = child_node->sibling ); + + /* If last child_node also have children. */ + if ( child_node->child ) + child_node = find_last_descendants_node(child_node); + + return child_node; +} + +static int dt_overlay_remove_node(struct dt_device_node *device_node) +{ + struct dt_device_node *np; + struct dt_device_node *parent_node; + struct dt_device_node *device_node_last_descendant = device_node->child; + + parent_node = device_node->parent; + + if ( parent_node == NULL ) + { + dt_dprintk("%s's parent node not found\n", device_node->name); + return -EFAULT; + } + + np = parent_node->child; + + if ( np == NULL ) + { + dt_dprintk("parent node %s's not found\n", parent_node->name); + return -EFAULT; + } + + /* If node to be removed is only child node or first child. */ + if ( !dt_node_cmp(np->full_name, device_node->full_name) ) + { + parent_node->child = np->sibling; + + /* + * Iterate over all child nodes of device_node. Given that we are + * removing parent node, we need to remove all it's descendants too. + */ + if ( device_node_last_descendant ) + { + device_node_last_descendant = + find_last_descendants_node(device_node); + parent_node->allnext = device_node_last_descendant->allnext; + } + else + parent_node->allnext = np->allnext; + + return 0; + } + + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + if ( !dt_node_cmp(np->sibling->full_name, device_node->full_name) ) + { + /* Found the node. Now we remove it. */ + np->sibling = np->sibling->sibling; + + if ( np->child ) + np = find_last_descendants_node(np); + + /* + * Iterate over all child nodes of device_node. Given that we are + * removing parent node, we need to remove all it's descendants too. + */ + if ( device_node_last_descendant ) + device_node_last_descendant = + find_last_descendants_node(device_node); + + if ( device_node_last_descendant ) + np->allnext = device_node_last_descendant->allnext; + else + np->allnext = np->allnext->allnext; + + break; + } + } + + return 0; +} + +/* Basic sanity check for the dtbo tool stack provided to Xen. */ +static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) +{ + if ( (fdt_totalsize(overlay_fdt) != overlay_fdt_size) || + fdt_check_header(overlay_fdt) ) + { + printk(XENLOG_ERR "The overlay FDT is not a valid Flat Device Tree\n"); + return -EINVAL; + } + + return 0; +} + +/* Count number of nodes till one level of __overlay__ tag. */ +static unsigned int overlay_node_count(const void *overlay_fdt) +{ + unsigned int num_overlay_nodes = 0; + int fragment; + + fdt_for_each_subnode(fragment, overlay_fdt, 0) + { + int subnode; + int overlay; + + overlay = fdt_subnode_offset(overlay_fdt, 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, overlay_fdt, overlay) + { + num_overlay_nodes++; + } + } + + return num_overlay_nodes; +} + +static int handle_remove_irq_iommu(struct dt_device_node *device_node) +{ + int rc = 0; + struct domain *d = hardware_domain; + domid_t domid; + unsigned int naddr, len; + unsigned int i, nirq; + + 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 if only it's assigned to domain 0 or domain io. */ + if ( domid != 0 && domid != DOMID_IO ) + { + printk(XENLOG_ERR "Device %s is being used by domain %u. 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 ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to get IRQ num for device node %s\n", + device_node->full_name); + return -EINVAL; + } + + if ( irq_access_permitted(d, rc) == false ) + { + printk(XENLOG_ERR "IRQ %d is not routed to domain %u\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++ ) + { + uint64_t addr, size; + + 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 -EINVAL; + + spin_lock(&overlay_lock); + + /* + * First check if dtbo is correct i.e. it should one of the dtbo which was + * used when dynamically adding the node. + * Limitation: Cases with same node names but different property are not + * supported currently. We are relying on user to provide the same dtbo + * as it was used when adding the nodes. + */ + list_for_each_entry_safe( entry, temp, &overlay_tracker, entry ) + { + if ( memcmp(entry->overlay_fdt, overlay_fdt, overlay_fdt_size) == 0 ) + { + track = entry; + found_entry = true; + break; + } + } + + if ( found_entry == false ) + { + rc = -EINVAL; + + printk(XENLOG_ERR "Cannot find any matching tracker with input dtbo." + " Removing nodes is supported for only prior added dtbo. Please" + " provide a valid dtbo which was used to add the nodes.\n"); + goto out; + + } + + rc = remove_nodes(entry); + + if ( rc ) + { + printk(XENLOG_ERR "Removing node failed\n"); + goto out; + } + + list_del(&entry->entry); + + xfree(entry->dt_host_new); + xfree(entry->fdt); + xfree(entry->overlay_fdt); + + xfree(entry->nodes_address); + + xfree(entry); + +out: + spin_unlock(&overlay_lock); + return rc; +} + +long dt_sysctl(struct xen_sysctl_dt_overlay *op) +{ + long ret; + void *overlay_fdt; + + if ( op->overlay_fdt_size == 0 || op->overlay_fdt_size > KB(500) ) + return -EINVAL; + + overlay_fdt = xmalloc_bytes(op->overlay_fdt_size); + + if ( overlay_fdt == NULL ) + return -ENOMEM; + + ret = copy_from_guest(overlay_fdt, op->overlay_fdt, op->overlay_fdt_size); + if ( ret ) + { + gprintk(XENLOG_ERR, "copy from guest failed\n"); + xfree(overlay_fdt); + + return -EFAULT; + } + + switch ( op->overlay_op ) + { + case XEN_SYSCTL_DT_OVERLAY_REMOVE: + ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + xfree(overlay_fdt); + + break; + + default: + xfree(overlay_fdt); + break; + } + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 2b24d6bfd0..28f7fba98b 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1057,6 +1057,24 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#if defined(__arm__) || defined (__aarch64__) +/* + * XEN_SYSCTL_dt_overlay + * Performs addition/removal of device tree nodes under parent node using dtbo. + * This does in three steps: + * - Adds/Removes the nodes from dt_host. + * - Adds/Removes IRQ permission for the nodes. + * - Adds/Removes MMIO accesses. + */ +struct xen_sysctl_dt_overlay { + XEN_GUEST_HANDLE_64(void) overlay_fdt; /* IN: overlay fdt. */ + uint32_t overlay_fdt_size; /* IN: Overlay dtb size. */ +#define XEN_SYSCTL_DT_OVERLAY_ADD 1 +#define XEN_SYSCTL_DT_OVERLAY_REMOVE 2 + uint8_t overlay_op; /* IN: Add or remove. */ +}; +#endif + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1087,6 +1105,7 @@ struct xen_sysctl { #define XEN_SYSCTL_livepatch_op 27 /* #define XEN_SYSCTL_set_parameter 28 */ #define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_dt_overlay 30 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -1117,6 +1136,10 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + +#if defined(__arm__) || defined (__aarch64__) + struct xen_sysctl_dt_overlay dt_overlay; +#endif uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/dt-overlay.h b/xen/include/xen/dt-overlay.h new file mode 100644 index 0000000000..5b369f8eb7 --- /dev/null +++ b/xen/include/xen/dt-overlay.h @@ -0,0 +1,58 @@ + /* SPDX-License-Identifier: GPL-2.0 */ + /* + * xen/dt-overlay.h + * + * Device tree overlay support in Xen. + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + * Written by Vikram Garhwal + * + */ +#ifndef __XEN_DT_OVERLAY_H__ +#define __XEN_DT_OVERLAY_H__ + +#include +#include +#include +#include + +/* + * overlay_node_track describes information about added nodes through dtbo. + * @entry: List pointer. + * @dt_host_new: Pointer to the updated dt_host_new unflattened 'updated fdt'. + * @fdt: Stores the fdt. + * @nodes_fullname: Stores the full name of nodes. + * @nodes_irq: Stores the IRQ added from overlay dtb. + * @node_num_irq: Stores num of IRQ for each node in overlay dtb. + * @num_nodes: Stores total number of nodes in overlay dtb. + */ +struct overlay_track { + struct list_head entry; + struct dt_device_node *dt_host_new; + void *fdt; + void *overlay_fdt; + unsigned long *nodes_address; + unsigned int num_nodes; +}; + +struct xen_sysctl_dt_overlay; + +#ifdef CONFIG_OVERLAY_DTB +long dt_sysctl(struct xen_sysctl_dt_overlay *op); +#else +static inline long dt_sysctl(struct xen_sysctl_dt_overlay *op) +{ + return -ENOSYS; +} +#endif +#endif + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Tue May 2 23:36:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229369 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 9F273C77B78 for ; Tue, 2 May 2023 23:38:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528873.822650 (Exim 4.92) (envelope-from ) id 1ptzZ9-00017l-NO; Tue, 02 May 2023 23:37:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528873.822650; Tue, 02 May 2023 23:37:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzZ8-000150-TA; Tue, 02 May 2023 23:37:50 +0000 Received: by outflank-mailman (input) for mailman id 528873; Tue, 02 May 2023 23:37:49 +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 1ptzZ6-0005Si-Om for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:48 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060f.outbound.protection.outlook.com [2a01:111:f400:7eaa::60f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 56cde790-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:46 +0200 (CEST) Received: from BN9PR03CA0251.namprd03.prod.outlook.com (2603:10b6:408:ff::16) by DM4PR12MB7647.namprd12.prod.outlook.com (2603:10b6:8:105::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.30; Tue, 2 May 2023 23:37:43 +0000 Received: from BN8NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::8) by BN9PR03CA0251.outlook.office365.com (2603:10b6:408:ff::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:43 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT101.mail.protection.outlook.com (10.13.177.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:42 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:40 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:40 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 56cde790-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d+CBlD4/N0WIl6ao3jV5P6Wv5qMbul26Yjh9mI5DwgaymAwiNKw/amRYWmNZGTfp3fzAjzcZxOOTBagXx6zCsqBe2j09bhcCT8qUR9nFYsCw5ayia2K3EzKm9z+c2ipeXZBpcSDGZaAk+Q7d9Htoh0EUxOhPCn8WiKJZle0AQSWfs/zNpnGwjlDif25uhC7XNH/at8OQUtnFaueowFB01OA7/aNKJT3WwUm/LLJNB18XuvNJgtbpVR7w1jn9XY9Cwy5KLHLV0H1Zqu+GVQWthMcMLEouOl0u5z814f1JTb7GIbDRj221ltOVe/YZ5k9dcHhKJhQckzZrLSZSTsW+Qw== 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=DAz4bXIcLBaNxB7D8chHRJkgDHozUzgRvSx6fTSNQTA=; b=F7HyEkG+GLwlElxdZczQOhg9mmuvbLSMRxkaOk6v9qgRuZIvRupd+6El8aa1WkB+eDy78qsDEP3ZWq3PeeHMJQLJipyRtbzeZquFPSrFFX6Sluu8MlD9M0qmYs+DnAvyxS+VsAQOdmD16YNNTobdS6+ts1/DKfElwkd3xjShBt1g/NeA6g/MBd32CvU+IGqF3AIAJimRN1w43GtiBNTx6+wW6GEkS2K4fZvMZ0iogVma8zhuXpje8DyuaG8Rz0XJidZ2t+WVefKlayhCJGOoc+KOcKJsIFuZrfnrHjYUb889soCDbOY1adXtiyNZMmjnaEQxCN9d3Goa8keIakrX3A== 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=DAz4bXIcLBaNxB7D8chHRJkgDHozUzgRvSx6fTSNQTA=; b=tvwnbBv0YwQoW7fIrtmBRyeA/qbvHPPniXYcQF5dZLJDTAj1ggmq3qLLyoBs75aSCqiDKKkW+9E50/THsMvuilQAJP+PSMeUzZ3ge5W9CnBLylvVHGemuCzZceD23O46wQuhIcXpfHg+Lamascd6G4qNHHk0eKi7qeUBaVSKsw4= 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 , "Julien Grall" , Wei Liu Subject: [XEN][PATCH v6 16/19] xen/arm: Implement device tree node addition functionalities Date: Tue, 2 May 2023 16:36:47 -0700 Message-ID: <20230502233650.20121-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT101:EE_|DM4PR12MB7647:EE_ X-MS-Office365-Filtering-Correlation-Id: 70cb53a0-6b2e-4327-0398-08db4b6639b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1hPgD0kpSyOEMfq6/nPxjohfDV4v+5ckgSAvz0uL7Xh2ayAcX333ubGPBXhgr9M4Y8QQuaaD/t26ORibFv3saFNqXXJzWpW27YcQJdXklOyVITQyWTcWkKhkR3LpE0mhAatM2zqzScbsjodCUYigyhO9VYuT3qwbExXOuaLpzLJ7CNFkh/luYDSEqrI7kRig/0gNyKL1EORQcPgfNJ2iVBwGGv7wgoocxgoPLLAH6bhef78rD8caJ98SrFy6ipMK8A8VlCZS/1U4RFbfK+G8zYajluUuBnUHkzIiW6qInYciCaDLQ+lcNuNVhOIJRfstvPRyK265gKVcC/ikmgy2aDGdcHeJ6m2Epq4dW7LTia2pFWwFvLEK3OmZysf8kSMJOqZzE90ajzTSe7mDtva1cjQVKjHDTr72NjqJe9rTfIlj+nkwEuR1mdKe4VOS19YogYQIbEgLtqkvmE1hr1fD+SL6ZqDYAGRxqqvvumQWHkHgf4K8/9+0ujSnQGPZ874SMrUq51dMbv8nfHUUD6uov6aofwBfRMTr5ka2ndauqP6IOFjD9SAazAW2nZrKpzN88d5AkmQwHxFc9kT3XUtfZZZ1n4n+VpoH1gQ5gZsT4K+68kDYlt02Ye4+ocVAQPQdwPzuTQG45f1j81QG/hn8YbhDGyZ5Iodrqxh5Kx++bDNwVaoU9qNmlkLKj/BEPfq/4ztuuMhYPtl6VtGYLrzh9AAy6L/2XEfjheeDrOXE//Y= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(346002)(376002)(136003)(396003)(451199021)(40470700004)(36840700001)(46966006)(30864003)(66899021)(426003)(44832011)(4326008)(82310400005)(36860700001)(336012)(83380400001)(47076005)(2906002)(5660300002)(8936002)(8676002)(41300700001)(36756003)(316002)(186003)(26005)(70586007)(70206006)(6916009)(1076003)(356005)(81166007)(40460700003)(82740400003)(54906003)(86362001)(2616005)(40480700001)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:42.9525 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 70cb53a0-6b2e-4327-0398-08db4b6639b3 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: BN8NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7647 Update sysctl XEN_SYSCTL_dt_overlay to enable support for dtbo nodes addition using device tree overlay. xl dt-overlay add file.dtbo: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, it checks if any of the overlay nodes already exists in the dt_host. If overlay nodes doesn't exist then find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. The node is attached as the last node under target parent. Finally, add IRQs, add device to IOMMUs, set permissions and map MMIO for the overlay node. When a node is added using overlay, a new entry is allocated in the overlay_track to keep the track of memory allocation due to addition of overlay node. This is helpful for freeing the memory allocated when a device tree node is removed. The main purpose of this to address first part of dynamic programming i.e. making xen aware of new device tree node which means updating the dt_host with overlay node information. Here we are adding/removing node from dt_host, and checking/setting IOMMU and IRQ permission but never mapping them to any domain. Right now, mapping/Un-mapping will happen only when a new domU is created/destroyed using "xl create". Signed-off-by: Vikram Garhwal --- xen/common/dt-overlay.c | 510 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 510 insertions(+) diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index b89cceab84..09ea46111b 100644 --- a/xen/common/dt-overlay.c +++ b/xen/common/dt-overlay.c @@ -33,6 +33,25 @@ static struct dt_device_node * return child_node; } +/* + * Returns next node to the input node. If node has children then return + * last descendant's next node. +*/ +static struct dt_device_node * +dt_find_next_node(struct dt_device_node *dt, const struct dt_device_node *node) +{ + struct dt_device_node *np; + + dt_for_each_device_node(dt, np) + if ( np == node ) + break; + + if ( np->child ) + np = find_last_descendants_node(np); + + return np->allnext; +} + static int dt_overlay_remove_node(struct dt_device_node *device_node) { struct dt_device_node *np; @@ -106,6 +125,76 @@ 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 *next_node; + + parent_node = dt_find_node_by_path(parent_node_path); + + if ( parent_node == NULL ) + { + dt_dprintk("Parent node %s not found. Overlay node will not be added\n", + parent_node_path); + 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 + { + struct dt_device_node *np; + /* 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 ) + { + struct dt_device_node *np_last_descendant; + + 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 ) + { + struct dt_device_node *device_node_last_descendant; + + 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) { @@ -145,6 +234,82 @@ static unsigned int overlay_node_count(const void *overlay_fdt) return num_overlay_nodes; } +/* + * overlay_get_nodes_info gets full name with path for all the nodes which + * are in one level of __overlay__ tag. This is useful when checking node for + * duplication i.e. dtbo tries to add nodes which already exists in device tree. + */ +static int overlay_get_nodes_info(const void *fdto, char ***nodes_full_path, + unsigned int num_overlay_nodes) +{ + int fragment; + + *nodes_full_path = xzalloc_bytes(num_overlay_nodes * sizeof(char *)); + + if ( *nodes_full_path == NULL ) + return -ENOMEM; + + fdt_for_each_subnode(fragment, fdto, 0) + { + int target; + int overlay; + int subnode; + const char *target_path; + + target = fdt_overlay_target_offset(device_tree_flattened, fdto, + fragment, &target_path); + if ( target < 0 ) + return target; + + if ( target_path == NULL ) + return -EINVAL; + + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + fdt_for_each_subnode(subnode, fdto, overlay) + { + const char *node_name = NULL; + int node_name_len; + unsigned int target_path_len = strlen(target_path); + unsigned int node_full_name_len; + unsigned int node_num = 0; + + node_name = fdt_get_name(fdto, subnode, &node_name_len); + + if ( node_name == NULL ) + return node_name_len; + + /* + * Magic number 2 is for adding '/' and '\0'. This is done to keep + * the node_full_path 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; @@ -371,6 +536,344 @@ out: return rc; } +/* + * Handles IRQ and IOMMU mapping for the overlay_node and all descendants of the + * overlay_node. + */ +static int handle_add_irq_iommu(struct domain *d, + struct dt_device_node *overlay_node) +{ + int rc; + unsigned int naddr, i, len; + struct dt_device_node *np; + + /* First let's handle the interrupts. */ + rc = handle_device_interrupts(d, overlay_node, false); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to retrieve interrupts configuration\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 naddr = %u\n", dt_node_full_name(overlay_node), naddr); + + /* Give permission to map MMIOs */ + for ( i = 0; i < naddr; i++ ) + { + uint64_t addr, size; + + /* + * For now, we skip_mapping which means it will only permit iomem access + * to hardware_domain using iomem_permit_access() but will never map as + * map_range_p2mt() will not be called. + */ + struct map_range_data mr_data = { .d = d, + .p2mt = p2m_mmio_direct_c, + .skip_mapping = true + }; + + rc = dt_device_get_address(overlay_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(overlay_node)); + return rc; + } + + rc = map_range_to_domain(overlay_node, addr, size, &mr_data); + if ( rc ) + return rc; + } + + /* Map IRQ and IOMMU for overlay_node's children. */ + for ( np = overlay_node->child; np != NULL; np = np->sibling ) + { + rc = handle_add_irq_iommu(d, np); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + } + + return rc; +} + +/* + * Adds device tree nodes under target node. + * We use tr->dt_host_new to unflatten the updated device_tree_flattened. This + * is done to avoid the removal of device_tree generation, iomem regions mapping + * to hardware domain done by handle_node(). + */ +static long handle_add_overlay_nodes(void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc, j, i; + struct dt_device_node *overlay_node; + struct overlay_track *tr = NULL; + char **nodes_full_path = NULL; + unsigned int new_fdt_size; + + tr = xzalloc(struct overlay_track); + if ( tr == NULL ) + return -ENOMEM; + + new_fdt_size = fdt_totalsize(device_tree_flattened) + + fdt_totalsize(overlay_fdt); + + tr->fdt = xzalloc_bytes(new_fdt_size); + if ( tr->fdt == NULL ) + { + xfree(tr); + return -ENOMEM; + } + + tr->num_nodes = overlay_node_count(overlay_fdt); + if ( tr->num_nodes == 0 ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + tr->nodes_address = xzalloc_bytes(tr->num_nodes * sizeof(unsigned long)); + if ( tr->nodes_address == NULL ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + { + xfree(tr->nodes_address); + xfree(tr->fdt); + xfree(tr); + return rc; + } + + /* + * Keep a copy of overlay_fdt as fdt_overlay_apply will change the input + * overlay's content(magic) when applying overlay. + */ + tr->overlay_fdt = xzalloc_bytes(overlay_fdt_size); + if ( tr->overlay_fdt == NULL ) + { + xfree(tr->nodes_address); + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + memcpy(tr->overlay_fdt, overlay_fdt, overlay_fdt_size); + + spin_lock(&overlay_lock); + + memcpy(tr->fdt, device_tree_flattened, + fdt_totalsize(device_tree_flattened)); + + /* Open tr->fdt with more space to accommodate the overlay_fdt. */ + rc = fdt_open_into(tr->fdt, tr->fdt, new_fdt_size); + if ( rc ) + { + printk(XENLOG_ERR "Increasing tr->fdt size failed with error %d\n", + rc); + goto err; + } + + /* + * 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 ) + { + printk(XENLOG_ERR "unflatten_device_tree failed with error %d\n", rc); + goto err; + } + + for ( j = 0; j < tr->num_nodes; j++ ) + { + struct dt_device_node *prev_node, *next_node; + + 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 ) + { + /* Sanity check. But code will never come here. */ + ASSERT_UNREACHABLE(); + 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(hardware_domain, overlay_node); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + + /* Keep overlay_node address in tracker. */ + tr->nodes_address[j] = (unsigned long)overlay_node; + } + + INIT_LIST_HEAD(&tr->entry); + list_add_tail(&tr->entry, &overlay_tracker); + + spin_unlock(&overlay_lock); + + if ( nodes_full_path != NULL ) + { + for ( i = 0; i < tr->num_nodes && nodes_full_path[i] != NULL; + i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + return rc; + +/* + * Failure case. We need to remove the nodes, free tracker(if tr exists) and + * tr->dt_host_new. + */ +remove_node: + tr->num_nodes = j; + rc = remove_nodes(tr); + + if ( rc ) + { + /* + * User needs to provide right overlay. Incorrect node information + * example parent node doesn't exist in dt_host etc can cause memory + * leaks as removing_nodes() will fail and this means nodes memory is + * not freed from tracker. Which may cause memory leaks. Ideally, these + * device tree related mistakes will be caught by fdt_overlay_apply() + * but given that we don't manage that code keeping this warning message + * is better here. + */ + printk(XENLOG_ERR "Removing node failed.\n"); + spin_unlock(&overlay_lock); + return rc; + } + +err: + spin_unlock(&overlay_lock); + + if ( tr->dt_host_new ) + xfree(tr->dt_host_new); + + xfree(tr->overlay_fdt); + xfree(tr->nodes_address); + xfree(tr->fdt); + + 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; @@ -395,6 +898,13 @@ long dt_sysctl(struct xen_sysctl_dt_overlay *op) switch ( op->overlay_op ) { + case XEN_SYSCTL_DT_OVERLAY_ADD: + ret = handle_add_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + if ( ret ) + xfree(overlay_fdt); + + break; + case XEN_SYSCTL_DT_OVERLAY_REMOVE: ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); xfree(overlay_fdt); From patchwork Tue May 2 23:36:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229373 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 C5991C77B78 for ; Tue, 2 May 2023 23:39:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528915.822695 (Exim 4.92) (envelope-from ) id 1ptzaP-0006X2-9G; Tue, 02 May 2023 23:39:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528915.822695; Tue, 02 May 2023 23:39:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzaP-0006Wt-6M; Tue, 02 May 2023 23:39:09 +0000 Received: by outflank-mailman (input) for mailman id 528915; Tue, 02 May 2023 23:39:08 +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 1ptzZ7-0005Si-M1 for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:49 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20600.outbound.protection.outlook.com [2a01:111:f400:7e8c::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 578e1a5d-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:47 +0200 (CEST) Received: from BN9PR03CA0243.namprd03.prod.outlook.com (2603:10b6:408:ff::8) by SN7PR12MB7953.namprd12.prod.outlook.com (2603:10b6:806:345::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.32; Tue, 2 May 2023 23:37:44 +0000 Received: from BN8NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::1a) by BN9PR03CA0243.outlook.office365.com (2603:10b6:408:ff::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:43 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT101.mail.protection.outlook.com (10.13.177.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:43 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:41 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:41 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 578e1a5d-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bERWKi0IoKVO4XW7QmAZRl3xJLDoCyjpHNLhXy2w8KqjDAoMs4NvnCUKsP8Ee2WJwWXgEeCIvj5SsNeRzRSw+O9XGQi3DaHdSauVbrSF6eGvT60gHy4K7VsV3+wh8upOth/TCzae97M7vL0vIZiOeZv2A703E7v+v4lRPiqLWAL6GV1FsYA1cZme8c992f2NDqbHxuiatP1xZhUv+cnRLY5Ex39gbw6PeelY5rR3Pis192NKcDft3LuoL3Z3Z7H0avkqt0ha7trY++XL2wodIBgdKunUOBAMXdaLIgiht7Gw3fTELp02mvA6E4lsnx6/wPNTUdL3GBSzZ3Q5DWSVzA== 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=EQ8GqVc2MExei+u64NzeTvfYwAOuigBIRcvJ0a0ukt4=; b=TBzHrtkDlEDXZ5Lzf5F99GDULi3RK4nBdtOX21n/x9a6YZTpImEBQ5Whmz29A0Tiz+T/NfvGXC9BxqCIcW0uuBppMH5DBdEtl6xQbhis8jFH471u8+Vw3MQtcZ7sxomqGaK55/VekubFpRxbedk/ZxTLrD0XBozo6xETNhqtPzyG+BR4XAp5aX6FhFqXzHFB753uSVxZfMCf7PUUjqo7k3PVLOg/aNitMpHW3gjSYByVl7OlBQjNEbg2q5s3pnzJ6fTUxO2bEh5cQPJb5QaGu1EHX73zFUEqbtpwbrsJCYSpEGnHxPmZEqhlhJus2bhTs7rQBofRbguO4OEu1E8cyQ== 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=EQ8GqVc2MExei+u64NzeTvfYwAOuigBIRcvJ0a0ukt4=; b=r3D+eMzSnKuDoXOsPjZC7VuCLArC/Phzl8Bgg+JYBuvvdMKeWbrwes775Dj3DJ/BPoOms52uOzfZHhKdRhrs271X7kb84qsN9vr2UBcMqa6faF1/ue/6u1R3KLiTepvf4V0PNlgPvOHeAxnfWXaljExWAuCiaw7hFz5g2qNWpQU= 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][PATCH v6 17/19] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Tue, 2 May 2023 16:36:48 -0700 Message-ID: <20230502233650.20121-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT101:EE_|SN7PR12MB7953:EE_ X-MS-Office365-Filtering-Correlation-Id: a4a8e144-13c2-4e46-1033-08db4b663a23 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V8hJH/YlyuhXPweNA4KTn69XI5co255t1TQrBJSBvak61sR9Z3kCIRm5PnYmiv/8VqFuHPWmw23kSZX9Sgkb1NCFN/xGvif9AfKeylD3OvOSJNwhd2tXo0Jma9dFo399P2p40XlneedckLjeWsUFVEm7BNKVYFIjNl8lfhjCPrdSOB593Wr1vI9Wd7xvkCo5n1NopJMXwljxnE23QQVusPVxoAzbYmLh0w86LPSAH93OiSvn2LLcpWfOEeeyNC/bUFw/93dBSLQPXyon8uYIi6bVTtMpWqAXPh9CyRNEwwshjuLmjWx6d/UBUgY2AJFBP4ipLifz4pY65iVwivesH8NYfiqiXMDW4Zk/sOeDyj4K0mjp+znx5UzhcuLhT87RhGxNR3IcnMOLy6NoAsVmZMIJO5VnkHjH0MQbIFsVHDfmeDYziHmTYE+ufpzQkzNnZY+LRCOawJUiStHSrYS5FkzwcWS8sLXjrYUDh6VqFfMSbf2ewn33FRHtTk30RrMBNAGJiSOpRMlJ0pZ+VJlddqBEzd+yUVl4PQYf01N9kA8qgbPmzZdu6yk289xZGJQykT0fIIAgXxBBr+1frpPvXxKB+unoP/6Ad2o+xLMu0kxg7nxtgaqU/3UFHDOXFIw8rqAKt+xEIg5TMRfFUiWKEw5iEiuxBdvGKaSwymKKL42uIU0VmC3zLY6k92kisa9ONiTE9SuDFSZUM+SFTGybctS0pLMx3HwMmy4G43noknm4Di25fqdTgxamn/6aoYA2 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(39860400002)(136003)(396003)(451199021)(46966006)(36840700001)(40470700004)(5660300002)(36860700001)(1076003)(40480700001)(478600001)(356005)(81166007)(26005)(186003)(82740400003)(54906003)(47076005)(426003)(2616005)(336012)(8676002)(41300700001)(8936002)(4326008)(70206006)(2906002)(316002)(6916009)(44832011)(70586007)(86362001)(36756003)(40460700003)(82310400005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:43.6868 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a4a8e144-13c2-4e46-1033-08db4b663a23 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: BN8NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7953 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 Reviewed-by: Anthony PERARD --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 48 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 752fc87580..1a99c06561 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2666,6 +2666,11 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +#if defined(__arm__) || defined(__aarch64__) +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op); +#endif + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libs/ctrl/Makefile.common b/tools/libs/ctrl/Makefile.common index 0a09c28fd3..247afbe5f9 100644 --- a/tools/libs/ctrl/Makefile.common +++ b/tools/libs/ctrl/Makefile.common @@ -24,6 +24,7 @@ OBJS-y += xc_hcall_buf.o OBJS-y += xc_foreign_memory.o OBJS-y += xc_kexec.o OBJS-y += xc_resource.o +OBJS-$(CONFIG_ARM) += xc_dt_overlay.o OBJS-$(CONFIG_X86) += xc_psr.o OBJS-$(CONFIG_X86) += xc_pagetab.o OBJS-$(CONFIG_Linux) += xc_linux.o diff --git a/tools/libs/ctrl/xc_dt_overlay.c b/tools/libs/ctrl/xc_dt_overlay.c new file mode 100644 index 0000000000..202fc906f4 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,48 @@ +/* + * + * Device Tree Overlay functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op) +{ + int err; + DECLARE_SYSCTL; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + sysctl.cmd = XEN_SYSCTL_dt_overlay; + sysctl.u.dt_overlay.overlay_op = overlay_op; + sysctl.u.dt_overlay.overlay_fdt_size = overlay_fdt_size; + + set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err = do_sysctl(xch, &sysctl)) != 0 ) + PERROR("%s failed", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} From patchwork Tue May 2 23:36:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229371 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 1E4EEC77B75 for ; Tue, 2 May 2023 23:39:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528899.822685 (Exim 4.92) (envelope-from ) id 1ptzaH-00065C-10; Tue, 02 May 2023 23:39:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528899.822685; Tue, 02 May 2023 23:39:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzaG-000655-Tg; Tue, 02 May 2023 23:39:00 +0000 Received: by outflank-mailman (input) for mailman id 528899; Tue, 02 May 2023 23:38:59 +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 1ptzZ8-0005Si-KC for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:50 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2061b.outbound.protection.outlook.com [2a01:111:f400:7e88::61b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5852231d-e942-11ed-8611-37d641c3527e; Wed, 03 May 2023 01:37:48 +0200 (CEST) Received: from BN9PR03CA0269.namprd03.prod.outlook.com (2603:10b6:408:ff::34) by MW3PR12MB4441.namprd12.prod.outlook.com (2603:10b6:303:59::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31; Tue, 2 May 2023 23:37:44 +0000 Received: from BN8NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::2c) by BN9PR03CA0269.outlook.office365.com (2603:10b6:408:ff::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:44 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT101.mail.protection.outlook.com (10.13.177.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:44 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:42 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:41 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5852231d-e942-11ed-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O9KJvxaJwC7gSbVT/N0kcaG447n665alx2AFy1uWliqBzkmRVikvSOeO+S5Ubpv9EW2JcueM5Ns+LHYlbYnq2CXHnK42OyJIzo7cngq1FoKWKXJ3DhSjBMhpQvTSt1h8JjgB1LMxOR29g0qrnriJlFI2LRg0QdJfoUhmXr3lvOJNfiENv/A8ZVn1j6l6wS0MSe+xWd16iR84yEJZQVZ0BLIWNbeNxflQqJQEfAJQMO3rgNSl7/Ahsuth0O9lY3N3jqlffV6vvLBmhAyZPh+EmCkQUjfxNQlPSpSdVSFxMF0tpwnim08Frz6HPdZhK9yNmXLFa1ciisrAfJF7SwXm2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=91E2KEtRfiC4xks88DcPT08G46pT034ykx3UwRRlezk=; b=bYPfW6hbwLA+thF6ca7CBjdBIlWJxlk0Sg5jlme6Najiqe+bl2kdfgvb97Lr+ujgZnd4yrJVZ8MdH4XyKgWpUl0bQF3ZjeQp7ijqGU8lsZq/G5g6ZqtRNJ5SRa+s+iWE6vldLb98w9LDhKS/ftkDFxl2DCo1IgquGcvjki0aPp57C1FQ7LFKJB5bPpV7XEfq9cQHjeZElRmjpwb1TwPwZQfQxYjbRMglaBJv79zZqksys65Edxe1mcHZ5cgwqZXR5HksP1Hd6gmEwCjMWkaqqZPmMsUQUdA8KDUKxF9M2s4Y0MUfYrHMMc05ILm+6nBeo0dR+Dv7A190Ox9L3rwaEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=91E2KEtRfiC4xks88DcPT08G46pT034ykx3UwRRlezk=; b=hQeYj5zsHKXYLQ5oZ+X59iJtWrHLjoaauVSb5Tg/5IuQt5Vu2d4Z15FmUy4YWG5JY45jxcV6Mn/UmRM7SLJRVyd+CAWee5mFkcfL/V3wyZtDY/djiKDk9/8z/eZnZ1kvSIodkAC+saLlGRKZJlvyxPvaIRZZizMj6eStxABGNhw= 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][PATCH v6 18/19] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Tue, 2 May 2023 16:36:49 -0700 Message-ID: <20230502233650.20121-19-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT101:EE_|MW3PR12MB4441:EE_ X-MS-Office365-Filtering-Correlation-Id: 5347c826-59cd-4976-0a45-08db4b663a80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WDRiwXSfCM+NKXNP/23ZDrpZh1shJqPjsyD0mxQbTv1llItNW+0F+6gp6h0+uCV715uKpHYCDSt2Y1WQIXGT+iX9roA/pKCce3QTT7lnpTYZHeWQaUB7EhUZlKuyzOczC7fkm0Z0EMqyCmDdZnTkyCDStaEx5cRm6xUxinC9eEINZhxvH8k4LmpdIdPm43on96NUQLxZKmVXGdYop5XVEy6pEO0aXd6ThHiQKO+bQx2gO4JONuKwuJRAR787zGyKibdnysVIlGPXYTQxt3lXGrC2EkXHeac4+0v5VG3pHU0OhvItI14/9ZiEkjUQbfOrt2mC3zAfgS8Gwd4xFzp8avQeXywY6RKxwMcM2fMyg+jvH3Q2fCwWAR+W2RxRXWF4/Lb1OyhPBu7bO5tKawuRrK3/xk/2HubNPyKJN2z++G68x+6cUEtfq+a3VgY5pJwfSPxdvVMxZKA4/SeYJuzurysfof86jlj3PokCw89qmnYZb41pyaknKgQWmL3pRMoYz+rQ2T1G0GEupxlkpxEafGt1IvihjOz5DyEDWHNZvqSEKH+sPw/1j6w3YtClPsbWI5sittpV1abYsn8H//mvN1VMsTdz3VhQ3DUzeh+QmD8EGba7mCL5Wph1X4G34D0Km0niXBTAJniZzNRG13WnybOhoq5ioKU5JABDwClfiAmfPL8n67pGUr8HZEiWhck7uoeR+/0PqNbZltJ7CiPFbW1BpOGEMvOZGSyuqzwix2+9vrylBuO9x+HVXW3RdaNU X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(396003)(39860400002)(136003)(376002)(451199021)(40470700004)(46966006)(36840700001)(478600001)(82310400005)(316002)(2906002)(6916009)(70206006)(70586007)(4326008)(36756003)(40480700001)(86362001)(54906003)(40460700003)(1076003)(8936002)(8676002)(44832011)(2616005)(336012)(426003)(36860700001)(5660300002)(186003)(47076005)(26005)(82740400003)(356005)(81166007)(41300700001)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:44.2961 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5347c826-59cd-4976-0a45-08db4b663a80 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: BN8NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4441 Signed-off-by: Vikram Garhwal Reviewed-by: Anthony PERARD --- tools/include/libxl.h | 11 +++++ tools/libs/light/Makefile | 3 ++ tools/libs/light/libxl_dt_overlay.c | 71 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tools/libs/light/libxl_dt_overlay.c diff --git a/tools/include/libxl.h b/tools/include/libxl.h index cfa1a19131..1c5e8abaae 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -250,6 +250,12 @@ */ #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 +#if defined(__arm__) || defined(__aarch64__) +/** + * This means Device Tree Overlay is supported. + */ +#define LIBXL_HAVE_DT_OVERLAY 1 +#endif /* * libxl_domain_build_info has device_model_user to specify the user to * run the device model with. See docs/misc/qemu-deprivilege.txt. @@ -2453,6 +2459,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); void libxl_device_pci_list_free(libxl_device_pci* list, int num); +#if defined(__arm__) || defined(__aarch64__) +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay, + uint32_t overlay_size, uint8_t overlay_op); +#endif + /* * Turns the current process into a backend device service daemon * for a driver domain. diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 96daeabc47..563a1e8d0a 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -112,6 +112,9 @@ OBJS-y += _libxl_types.o OBJS-y += libxl_flask.o OBJS-y += _libxl_types_internal.o +# Device tree overlay is enabled only for ARM architecture. +OBJS-$(CONFIG_ARM) += libxl_dt_overlay.o + ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL += $(LIBNL3_CFLAGS) endif diff --git a/tools/libs/light/libxl_dt_overlay.c b/tools/libs/light/libxl_dt_overlay.c new file mode 100644 index 0000000000..a6c709a6dc --- /dev/null +++ b/tools/libs/light/libxl_dt_overlay.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" +#include +#include + +static int check_overlay_fdt(libxl__gc *gc, void *fdt, size_t size) +{ + int r; + + if (fdt_magic(fdt) != FDT_MAGIC) { + LOG(ERROR, "Overlay FDT is not a valid Flat Device Tree"); + return ERROR_FAIL; + } + + r = fdt_check_header(fdt); + if (r) { + LOG(ERROR, "Failed to check the overlay FDT (%d)", r); + return ERROR_FAIL; + } + + if (fdt_totalsize(fdt) > size) { + LOG(ERROR, "Overlay FDT totalsize is too big"); + return ERROR_FAIL; + } + + return 0; +} + +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay_dt, uint32_t overlay_dt_size, + uint8_t overlay_op) +{ + int rc; + int r; + GC_INIT(ctx); + + if (check_overlay_fdt(gc, overlay_dt, overlay_dt_size)) { + LOG(ERROR, "Overlay DTB check failed"); + rc = ERROR_FAIL; + goto out; + } else { + LOG(DEBUG, "Overlay DTB check passed"); + rc = 0; + } + + r = xc_dt_overlay(ctx->xch, overlay_dt, overlay_dt_size, overlay_op); + + if (r) { + LOG(ERROR, "%s: Adding/Removing overlay dtb failed.", __func__); + rc = ERROR_FAIL; + } + +out: + GC_FREE; + return rc; +} + From patchwork Tue May 2 23:36:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13229372 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 A1367C77B78 for ; Tue, 2 May 2023 23:39:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.528894.822675 (Exim 4.92) (envelope-from ) id 1ptzaF-0005p9-PG; Tue, 02 May 2023 23:38:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 528894.822675; Tue, 02 May 2023 23:38:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1ptzaF-0005on-LD; Tue, 02 May 2023 23:38:59 +0000 Received: by outflank-mailman (input) for mailman id 528894; Tue, 02 May 2023 23:38:58 +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 1ptzZ7-0004sC-Lr for xen-devel@lists.xenproject.org; Tue, 02 May 2023 23:37:49 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2061e.outbound.protection.outlook.com [2a01:111:f400:7eab::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 582050bd-e942-11ed-b225-6b7b168915f2; Wed, 03 May 2023 01:37:49 +0200 (CEST) Received: from BN9PR03CA0269.namprd03.prod.outlook.com (2603:10b6:408:ff::34) by DS0PR12MB6559.namprd12.prod.outlook.com (2603:10b6:8:d1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.20; Tue, 2 May 2023 23:37:45 +0000 Received: from BN8NAM11FT101.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ff:cafe::2c) by BN9PR03CA0269.outlook.office365.com (2603:10b6:408:ff::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.31 via Frontend Transport; Tue, 2 May 2023 23:37:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BN8NAM11FT101.mail.protection.outlook.com (10.13.177.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6363.21 via Frontend Transport; Tue, 2 May 2023 23:37:45 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 2 May 2023 18:37:43 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 2 May 2023 18:37:42 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 582050bd-e942-11ed-b225-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DROLClaF+aGH7NYS5zydzrPTP4mibpTNPe0ZoUB0bNtEgTnF7SV6zAwcvfmxH3k8vXh0kFr3FltTZ9r851MD1pbZeZ/2Y4GGAoUmC64jqHyT7oieI4BlyMayUPqlbrzPZJn3JKnhqRFvb8RmEVY5yDj3/msJR0MkBMAoZ0c9ubGZvmUG2Yyys/8mVGJEcIl2fVFRZ0TwB9LKsNidCjRYK7wBxEqI/KqTn93UHrmDTqRLM29+5bA1ptTsEN68F3xU7vt02WgfzTenO1Fqst1MWPbqytuWEtf/l5x/iEshJ8RaTYN/OuC0iJ+NEP7qMrT8EHhgWnYhsXIVB9VysQAgow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W8ANf04rvVBwwTVoSmk1wMh7BnV4jbgpw3PgliDnkIY=; b=T9QZoJnBB2xOZ1/jmK/an5wpiebV1ZJURBqpIOADuHLmDou8E6zhHXpMY3idjmzyiHZghWswDPZsaf07fVuWeVaHQIWUTk7wf5jApo5WaBXs5vsBpn/23OUeCky6wA4v7cpeyQnBNkBviXD+oUiosL/uYaYBSwX3kr74lqjs3fszIw8ay97Gyj0sYnAD9I5a7ZBU216h4WztFF72nJ/F/WsAae5RCRNMmXiukDov2K5RinaWmAT9tMRsA1w+sWhZpsfiRDfgCjOvS3RMyaSH9aJuDxdaRb4WN3Vgrq3YmyJRnvCB/ioixZc+VV89Sj1xEsSqh5QWYr6n8Zz5H9EPZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W8ANf04rvVBwwTVoSmk1wMh7BnV4jbgpw3PgliDnkIY=; b=mfMEDx1uFImG7A79WBozqHEF2QaRa5nkflQ1zG9Mp0jlMowT7VOk82LRmrBYQfGZDBCBnpgATlgNfzKix+vIYo4VbAU6H9liO3KEs+CYIjNkz/fSrX4+cOhbflIktTiB+vr4TSuOhNIgM1lMUj28Xv853meqj4V/feAdQPZpnls= 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 Subject: [XEN][PATCH v6 19/19] tools/xl: Add new xl command overlay for device tree overlay support Date: Tue, 2 May 2023 16:36:50 -0700 Message-ID: <20230502233650.20121-20-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230502233650.20121-1-vikram.garhwal@amd.com> References: <20230502233650.20121-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT101:EE_|DS0PR12MB6559:EE_ X-MS-Office365-Filtering-Correlation-Id: 87db793a-0ce9-45e1-14f2-08db4b663b0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Ky0jDQ4nyKCJRDumE86REXWu2MwxLdK/N4E2ZhzE8ccdaSyv3yNRoPZcsBcI9fQGC1FFQ/fuGX/KAekGKo6JCmQo+ouL+BxL123Vhxn60oV76fmKva9JBNBWOfuMEUH9voXJHENWv8N22JPCO26FT0XR1OT9seGW9JnX4p0redjuQ7qAAGFxLsHDhDB0ggjl+HHJeiBhSGfRJhD3ikXu72OwkfaSYS5bWHGKlInr4B1K5p9N5aanBizbmTHGlN1pgUgQX3rSMf2c7l7zFRCvAhjeoC18ebw/S8OwmNrf5aBIYL18q3kKRXSQVqiuAhpxeZAowrLBMCideSLROGISJ06GfSo8FWUxf+jypIXCJPmwGYT0jPWrsR4l8GCCpJjtmi29Jvax1Ed9gInCVCh6JmtKRwhkcRo27MU0oGdbLYkBcoTnvuuFz6mfoA4ndvHW6AUFxWiJA2IsVSsXUdD2FqsPGOcOZXH3bs7/gVpITYaJCTM9nrjVGmLCV24FsGrjawGG+1UM313zXFLcq5GB6MHVQ/0HU6bR7gJDhaFdK9VB/iNnzZbYxSUW8EdZJdsLfbxsnR1v0nlWHtASoCs5KFNuWFnfGe2Ji9uR5nMwjSMt2R9ZCPJw8aOZOi9A8zdLYopXEkBmVdxLdOx+C9ZGJykxd28HM6La4dK1GWl3S3Z7O9C3VRTneCMX0RyorMCAsI/GPgWuT0fl2/RsGRNNEWRPCHSl1V8urf9CMN8nmU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(39860400002)(396003)(136003)(451199021)(40470700004)(46966006)(36840700001)(356005)(2906002)(81166007)(1076003)(82740400003)(186003)(26005)(6666004)(47076005)(36860700001)(2616005)(82310400005)(336012)(426003)(36756003)(44832011)(40460700003)(5660300002)(54906003)(478600001)(86362001)(83380400001)(8936002)(8676002)(41300700001)(6916009)(70206006)(70586007)(316002)(40480700001)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2023 23:37:45.2336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 87db793a-0ce9-45e1-14f2-08db4b663b0f 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: BN8NAM11FT101.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6559 Signed-off-by: Vikram Garhwal Reviewed-by: Anthony PERARD --- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 6 +++++ tools/xl/xl_vmcontrol.c | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 72538d6a81..a923daccd3 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -138,6 +138,7 @@ int main_shutdown(int argc, char **argv); int main_reboot(int argc, char **argv); int main_list(int argc, char **argv); int main_vm_list(int argc, char **argv); +int main_dt_overlay(int argc, char **argv); int main_create(int argc, char **argv); int main_config_update(int argc, char **argv); int main_button_press(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index ccf4d83584..db0acff62a 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -630,6 +630,12 @@ const struct cmd_spec cmd_table[] = { "Issue a qemu monitor command to the device model of a domain", " ", }, + { "dt-overlay", + &main_dt_overlay, 0, 1, + "Add/Remove a device tree overlay", + "add/remove <.dtbo>" + "-h print this help\n" + }, }; const int cmdtable_len = ARRAY_SIZE(cmd_table); diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 5518c78dc6..de56e00d8b 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1265,6 +1265,58 @@ int main_create(int argc, char **argv) return 0; } +int main_dt_overlay(int argc, char **argv) +{ + const char *overlay_ops = NULL; + const char *overlay_config_file = NULL; + void *overlay_dtb = NULL; + int rc; + uint8_t op; + int overlay_dtb_size = 0; + const int overlay_add_op = 1; + const int overlay_remove_op = 2; + + if (argc < 2) { + help("dt_overlay"); + return EXIT_FAILURE; + } + + overlay_ops = argv[1]; + overlay_config_file = argv[2]; + + if (strcmp(overlay_ops, "add") == 0) + op = overlay_add_op; + else if (strcmp(overlay_ops, "remove") == 0) + op = overlay_remove_op; + else { + fprintf(stderr, "Invalid dt overlay operation\n"); + return EXIT_FAILURE; + } + + if (overlay_config_file) { + rc = libxl_read_file_contents(ctx, overlay_config_file, + &overlay_dtb, &overlay_dtb_size); + + if (rc) { + fprintf(stderr, "failed to read the overlay device tree file %s\n", + overlay_config_file); + free(overlay_dtb); + return ERROR_FAIL; + } + } else { + fprintf(stderr, "overlay dtbo file not provided\n"); + return ERROR_FAIL; + } + + rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + + free(overlay_dtb); + + if (rc) + return EXIT_FAILURE; + + return rc; +} /* * Local variables: * mode: C