From patchwork Fri Jun 2 00:48:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264611 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 9B00CC7EE29 for ; Fri, 2 Jun 2023 00:49:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542796.847142 (Exim 4.92) (envelope-from ) id 1q4syV-0002hW-Bn; Fri, 02 Jun 2023 00:49:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542796.847142; Fri, 02 Jun 2023 00:49:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syU-0002ei-UM; Fri, 02 Jun 2023 00:49:02 +0000 Received: by outflank-mailman (input) for mailman id 542796; Fri, 02 Jun 2023 00:49:00 +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 1q4syS-00018B-9x for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:00 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20612.outbound.protection.outlook.com [2a01:111:f400:fe5a::612]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4128b33c-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:57 +0200 (CEST) Received: from MW4P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::12) by SJ0PR12MB6880.namprd12.prod.outlook.com (2603:10b6:a03:485::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.21; Fri, 2 Jun 2023 00:48:47 +0000 Received: from CO1NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::5) by MW4P222CA0007.outlook.office365.com (2603:10b6:303:114::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:47 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT003.mail.protection.outlook.com (10.13.175.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:46 +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; Thu, 1 Jun 2023 19:48:45 -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; Thu, 1 Jun 2023 17:48:45 -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; Thu, 1 Jun 2023 19:48:44 -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: 4128b33c-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffYa3WlRtU+77/+yYuUP2S74YLoZuE8mEMXM+IXw8bPddd8ImRkWXyfWbAe3aNN9L6I4PexpRj17EHTUzuY7d0F8aiu7RK12Al3inyeeewhJY1ebzkhxTY/9TEgpabZARe6zztPpZcBiq4xG2miQm7Oz7lioYdPZ08/gzNgz6U99JtlNw/spIq7azqqAZVpiQarZPjKlokGDv/l9IDnuBuEtHHUyY6QzOzZtocFlBGBDHEcSeK0akDtm+U7IPdl7JI7JOppmo4TJQW4yM/R7fol1YZpr+pDtaF37NhgGCKNADHXmxweWInwp8rEFIwqsV7axH9PhhUSIFVLieT2ZeA== 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=+hpi4GzxVUT91hfToDu51Ag2FWYqgV+Aa/GRAQWx9hg=; b=iMeH+0XM4CGz+aHOiSj2X4e7RBbyP2pePNksY01+JMXX6WLlLeXgEqmoxka8JCJXrvIWFSxMECW08q4+REY65aHKi0+2hqo4f5hCc2X4IN/THgkfd6HmJd8QBo3Ornc3stGDBRC0HxBBGeK8eb7sMxo2pxvkzYIoyxMLcNV1NYfAhdVtPG5FgTUGy86F//azeCzpx4m7rm3xQGpJh1u+tAKKPeSKImj8Q6ykwfeJ3it04q/ebFXr3gJ9RAmrtqM8DasMF+9PSnf9PkOJZGpbf0q3rz+9ET8SMXrjnMo8zrGyD8bgwC6y4S0pbu+NSw3yzrPgJxCVoMCnS4RhK74hEQ== 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=+hpi4GzxVUT91hfToDu51Ag2FWYqgV+Aa/GRAQWx9hg=; b=48YdkSEqLfOouJKojlJK7vDW4Rd5DKXsv9l5G2opAsGMpNyny41aBPzDzGBr43g4aQEbWCI5paiqdSX1YEUnFq6SdXGkxAIo1n/ULCvbIwzM7IMd08AbNkyG3LPNTGBrHUIqVfSeTJqWAlMBqRdMp3mjn0hDKsjjZWJ+LmjwR+E= 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 v7 01/19] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Date: Thu, 1 Jun 2023 17:48:06 -0700 Message-ID: <20230602004824.20731-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT003:EE_|SJ0PR12MB6880:EE_ X-MS-Office365-Filtering-Correlation-Id: f652c363-7d88-42dc-6e5e-08db63031f31 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nchpwUSPMqgyCLreph5U2KdLnH3dAzIASVUpvDdJEVm/3yG5+r3iDMG3H+qqQl4PRZiAWFcr3xIo+EdfSt4xv2W8Rb5Ou9zvxhVHl3+elirurJm3v69rJk+VELW5/zpD589TnrW8a6a1JqJg0ZfAPi0g1BzhoGB6d6j7DOoSRLuOQ88Xv4Uzg1EJmIdEYYObuvfw9sLof83DZOGlNj9VhiKUtkbRMk3qNH3f+Ceaf7B1JROYLa1jkbbTdcWSJVyYPbI1RFjzC+NXIDZotPw3X7ft/aaQaul+Q0yxuKnRB2VtA6efwQF2HVjZSNzitnBhRO49Yh/5sXSKwfn3UD0EQhXC2QbNOEOW3aCYp2oei4rx0B33J5SFT0VNE8EgEzVq/C53oUQttA+W+h4wifeBgS+2o27zkiwX5QB/49u+2DHcG334TxuJ9Xbg5OEVqaNJ5C0VTdaDLomFk2EgtgGXmcVkm6335GGE+Zm3AweQkgXgBiqqs++Ai1dC3aSrspp3hTgifD4JqUeAhtp9w/KljVZ72sDR5xC1dvaNa13eJEFdl6Idnmmn4Xzj3wnXQsaQFDGaW+CK6SVHe9lnh/Le0+xN5D/QfC14rQaQutCS1L24+IMkGejOo+6GLcXmiUccOonhn1SXEtr6xFM+S5T4y5eANlCq/Yb+nDHpcu+OpeO1CHKocp4eeCx7TDNXqRFpVHIBDsn6Vrrvn89BpXMHmfFQlzrn6poMf843skxQVJZulJoU2+wjjk5EKzXfKht6umV3OSfwfKy2Ww5VaUqoFA== 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)(376002)(39860400002)(396003)(136003)(451199021)(36840700001)(40470700004)(46966006)(40460700003)(26005)(1076003)(186003)(6666004)(36860700001)(2616005)(83380400001)(336012)(47076005)(426003)(41300700001)(316002)(2906002)(44832011)(8936002)(5660300002)(8676002)(478600001)(6916009)(4326008)(70586007)(70206006)(54906003)(36756003)(40480700001)(86362001)(82740400003)(356005)(81166007)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:46.1035 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f652c363-7d88-42dc-6e5e-08db63031f31 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: CO1NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6880 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. Fixes: fb97eb614acf ("xen/arm: Create a hierarchical device tree") Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang Reviewed-by: Michal Orzel Acked-by: Julien Grall --- xen/common/device_tree.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 8da1052911..dfdb10e488 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2092,8 +2092,8 @@ static unsigned long __init unflatten_dt_node(const void *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +static int __init __unflatten_device_tree(const void *fdt, + struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; @@ -2114,6 +2114,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); @@ -2131,6 +2133,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, @@ -2215,7 +2219,11 @@ 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 Fri Jun 2 00:48:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264605 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 3D5CBC77B7A for ; Fri, 2 Jun 2023 00:49:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542791.847092 (Exim 4.92) (envelope-from ) id 1q4syQ-0001PJ-TB; Fri, 02 Jun 2023 00:48:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542791.847092; Fri, 02 Jun 2023 00:48:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syQ-0001Nm-MA; Fri, 02 Jun 2023 00:48:58 +0000 Received: by outflank-mailman (input) for mailman id 542791; Fri, 02 Jun 2023 00:48:56 +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 1q4syO-00018B-Pq for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:56 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on20613.outbound.protection.outlook.com [2a01:111:f400:7e8c::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3e421de4-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:53 +0200 (CEST) Received: from DS7PR07CA0008.namprd07.prod.outlook.com (2603:10b6:5:3af::21) by DM6PR12MB4861.namprd12.prod.outlook.com (2603:10b6:5:1bd::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22; Fri, 2 Jun 2023 00:48:47 +0000 Received: from DM6NAM11FT089.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3af:cafe::e8) by DS7PR07CA0008.outlook.office365.com (2603:10b6:5:3af::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:47 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT089.mail.protection.outlook.com (10.13.173.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:46 +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; Thu, 1 Jun 2023 19:48:46 -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; Thu, 1 Jun 2023 17:48:45 -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; Thu, 1 Jun 2023 19:48:45 -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: 3e421de4-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MmNZcbMqkH/CWS7pVUpCKUcF3m+Kgx3L3ZW+5Fqyiv2DrlDTfpwHPOkvixRzSfgADWqbpL+GaIlrI79Drkjx6aZVg8PYFJClR6JgDXHPSMDeDLizOj0zf5Sm+6vXTXMYNjxn2DBaTmPN0Z6XfKGFjvCftd53hmD0k7CbbAI7VvaTwrsvRJdgzkggTQQqrvKUtQwb/OnjfHjslu1Ky/0CGE25UcYSf6dU2Z/NtvhmtEqxOjMS0VdAHHLwZhL3I8IY29cQNZHhJdplQC9vtOeWKFZzXMhYgzB+wOShF8CpaNhir/RNaU1YVNd9pEDQx2UWUJ5Q7U8ZTpLnIODAJ8PylA== 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=DQpG5gl8tjfgQA0nY9ZK0fMXg1D/2bl66ZjFs1Y7jAg=; b=oU1oT1hMDMGW2m3OhQevwgtA3gFKvtsABteio/dWRBnSKR4x2QYsNmKYZaHvwDgUyIvVPFoqzvoyLfsSg48U0VQ74NvMGwEH04J3RmiPTslSvxwcoYaLLN8z1EwXsROnQEOT177m6V1yT0Nbx3+Y0aiO1/9yOSg4bnDnVvx8QqVJbd8kU3vgAFwJsb4l1GbRiA7UQwesapHsUsrMY2NLd9fViZVCeR2dJTfOdPlwxtcAX7z1WSYD9l0bUwMwZPLCZSwqmIaDyJieWY0DNy2vrNbDydMBZJLDBQONYE6K4SRwlaVSwtpEBMXp23PV5y7iQzP4yoh52ABeN/ryKusuJw== 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=DQpG5gl8tjfgQA0nY9ZK0fMXg1D/2bl66ZjFs1Y7jAg=; b=mphWWZLOegKaL+lfl3uUFuLCgZB5TsT1zHsnh9Tbb7DvUo9QqXVtntQl7+c3DiZmzB9VLXmqKxNlLkAF4zY4SEoV2ZpoklhrONrzbW/yeJQezo4t0ZzCRPZ+ikvFEPsjGWWCLT95QpYao7VRasy+VI3RW3rooL2NWIBd9AsrUD4= 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 v7 02/19] common/device_tree.c: unflatten_device_tree() propagate errors Date: Thu, 1 Jun 2023 17:48:07 -0700 Message-ID: <20230602004824.20731-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT089:EE_|DM6PR12MB4861:EE_ X-MS-Office365-Filtering-Correlation-Id: 2536a6fc-905d-4c67-2595-08db63031f86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l0kEec3x1PBIRSkp6AIwnBj5sR377grKmkNuMDHsyyOUoNtt/x2Mu2B1lFiww80KkfpMmryFMPM4cwVoMH52iI50vPJJQ0xcpiJZVYqF4/a0eu9k3CL3yWnxn+F5+PXckjSvNj0jFcACxBxpFS7bgmA1kMxFNXhXwQ1XuF5MgWk8xEmR/rw2YGKy2tvTmapmDuIzPPG4gFL3SCyWnDbcokdUnJChM7yL3LozEdIsiYrtjUgGrqdmO/tCXm101AlhfUNZ2lfK68bdPvZmzcFPDDY2IBntmsCl6QRIqBmMtFnco32QLdsY4UtH9JOqjTilVMu5NHb/LGBKoodHkUCQp1N2wRNWZHxJSQtVIzAKIy53IBvp0MWmzes3UrV1sy5+EdjKq0taY6MwfCJgDZ4oRNZmTXWWQcn3htHLAOg+EfSDLeY4J0QsYDlqdtkIJOt/kE+HudgWw1Y9XOHjeOhEMM7vkXFJfD5MFO5C8ZFSanZkKoYgu9L+7ZqWDLk06Kjr9KNm6FTtX3PAeFneiWXoT1WjDNLuHqaAjrIK3ZUZUYnWS0O5+S5RnM59+Jsr34Lq8/zqkmsMXNnGTsNyCMtBG1y7j8I6HLFg55MXZy1Vo35j2eFSbl4h0IG46TPvIgZxNkwfmmxYyVZkdMf/Z+VCz+UgH8DpvHCcdizuTtvyKWcdp3e6i/y2j4RBcuTT0l9ctbSlSYmIcJYE6o82ZIYBvLYx9BWtKOrK4gJziDLVG+g0gEPN1s0lk+WiCytMXfu+etwf5CuRwOwOQDw6ak7tCQ== 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)(39860400002)(346002)(396003)(376002)(451199021)(40470700004)(36840700001)(46966006)(186003)(40480700001)(6666004)(40460700003)(26005)(1076003)(316002)(478600001)(70206006)(70586007)(4326008)(6916009)(82310400005)(86362001)(8676002)(8936002)(82740400003)(5660300002)(356005)(41300700001)(81166007)(44832011)(47076005)(2906002)(36756003)(54906003)(36860700001)(426003)(2616005)(336012)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:46.7212 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2536a6fc-905d-4c67-2595-08db63031f86 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: DM6NAM11FT089.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4861 This will be useful in dynamic node programming when new dt nodes are unflattend 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 dfdb10e488..117ccccb09 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2108,6 +2108,9 @@ static int __init __unflatten_device_tree(const void *fdt, /* 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); @@ -2125,11 +2128,19 @@ static int __init __unflatten_device_tree(const void *fdt, 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 Fri Jun 2 00:48:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264607 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 10F7AC7EE29 for ; Fri, 2 Jun 2023 00:49:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542790.847087 (Exim 4.92) (envelope-from ) id 1q4syQ-0001KM-Gb; Fri, 02 Jun 2023 00:48:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542790.847087; Fri, 02 Jun 2023 00:48:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syQ-0001Jl-Ak; Fri, 02 Jun 2023 00:48:58 +0000 Received: by outflank-mailman (input) for mailman id 542790; Fri, 02 Jun 2023 00:48:56 +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 1q4syO-00018B-FQ for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:56 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2061b.outbound.protection.outlook.com [2a01:111:f400:fe59::61b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3e527222-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:52 +0200 (CEST) Received: from MW4P222CA0021.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::26) by IA1PR12MB6138.namprd12.prod.outlook.com (2603:10b6:208:3ea::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:48:48 +0000 Received: from CO1NAM11FT003.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::9c) by MW4P222CA0021.outlook.office365.com (2603:10b6:303:114::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:47 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT003.mail.protection.outlook.com (10.13.175.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:47 +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; Thu, 1 Jun 2023 19:48:47 -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; Thu, 1 Jun 2023 17:48:46 -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; Thu, 1 Jun 2023 19:48:46 -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: 3e527222-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lyEmD+3iU4MWJbXUNb41RHbbwjQK17goTU4yO56nF84wYsaxIaFsmXIr4f07uJTGOtFuCSKnjEg1okwCLqg5MgsjriprcuzAGB3NY60Ve5EC5bEzUohWgImLf+9QVwLvLEU7e0N7KB4CIwOuFaH+bOg4ssWS6id/6UgElVaKz7JOLGRyZ4XzQxvmd2Qv4RkWA3IKSxHhZ+ad5IIGm5b0UjEkY5DP/YU1butMYBGgmx2SDK8hC6r/fUWOSIxvWURJF7tFv3eByXJKkZEsmwSOZ98+qZn2gkHAty4jeuTU7/+LJdPD8MTjo8cXCJl+FZPsoWOGpcAUDtPyLaVLwHtm2Q== 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=CQRwLgkTtNFvjNjXMq1Mf9/HDNmOjTI+SOtwexM1tMs=; b=TuaIC6HRWCaMM4dq19wY3Pu0zKG8AH4cLyjGPbUYXEyuBmQP3W1Si9jbNU932RJvWfn4p9vJK+dk4dOCXS9m4qMub4whAPVlON4KLVIKpjJCJlD3U3G9Mgqbpt4VPo+SIL+pL7Tm84+14cHrJnao8AVh5CfF8CNXz/uDerAvlYEsQDjhwHT6lno8kG7S8Dhqq0Yuz3LNwNhbhWbLjq8I/NUqZ3D9ySo2mL5vLpnpUju2DkuoACsDcTFQqEm/3hS93T9UXDaudloE4xI9xYc4RuDWNAveCM4Lg9qKXW1vW5eqVGFCc1ykhzK+E/9jf24XiAt3q+UIAFfxq4u2C0ANHw== 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=CQRwLgkTtNFvjNjXMq1Mf9/HDNmOjTI+SOtwexM1tMs=; b=mn5vfITVaXuTx1JZMnWLoHCMrJQmV7RgV5kMXBzyuApOQs0b1N6x+G0io8q8qs8hu2V6ln868BR1mQ7EUW0dGV4cHY04O47sHZIvbiZ/ErUnzyptaNv6H0m2IzZYyNFkwqF0vZeiHqJriw4DX6o5UaKz0hWvxxBCD046ufAMMN8= 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 v7 03/19] xen/arm/device: Remove __init from function type Date: Thu, 1 Jun 2023 17:48:08 -0700 Message-ID: <20230602004824.20731-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT003:EE_|IA1PR12MB6138:EE_ X-MS-Office365-Filtering-Correlation-Id: d0e4d7fd-cc80-429b-ac43-08db63032037 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4hVx4MuVlxyQLt6wFHSaBFd3TqN2I0IRWS38cPdBjXh5MiDNzrn7FfXn5tkenY0ehW/Z86rDvuMW6JNtlD8z9k32g8md74vtKMxRtSt8mXYfkO2zfjAhpUIVvNEq/03NCF6IuVvKJGHdXgfqPK1DwOKkK3ZWXsb3MfSJFF6ZtvIj/uS8EF+5BIBtU8insb7NnbCiMAHG6mfBi5Y1BYvTJLw5SA3pIVO3Zz1zK9YRkzmrZ09iuJBSvWXO78/jU8FFX9dmeubqbmALfwkK2VKg9Ehnpax+S0gGpFiObUmDK0g30vVmlV3Fs9hvWGMS8vJqtJOwkY7AuPaPEZ/cMy+OXWcw7YRyUVKVkKRsS+ATeBrLIbqUvQkEO3JiqVYakh01z5NYMHZXgoUjgONUgutZTiFenU6cx/t1VTjrIa64FzsNii4SojJbWz+OaFSREkEPHvTNy1eBPlPK2an4KV4IEZk+Ei4T3UA2/47lYcldL71VJ3zd2LdhDdKH/tUTTdNzgQeIyN8QBckh6fijpYPfyM1d8eLsbuRzuuqTtlkeg6FeiO+yGvn0qcJjaWiHAQEPJcPeVX+FTUeFvAFqd/S999FnYSZsXh+bRrfNZu+pog/VFcOZ4J/KwqjRd8u6uAnx0nxpIhUnTFuqeKxgTr5cPl8z3FodWphZ7HeBEURxSQf6AT//cF8cgJ2ZBh4fcd/Lr4Rr1qsfr1YxDjFLcNNidyRYEW53lBRqLtD0ZNKln6Yl9CUe0AIKG4HPRy2AruJHhYaxCPeEaqXeXyYUulxkuA== 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)(136003)(376002)(346002)(451199021)(40470700004)(46966006)(36840700001)(356005)(40460700003)(2616005)(6916009)(4326008)(70586007)(70206006)(81166007)(26005)(1076003)(54906003)(186003)(82740400003)(40480700001)(2906002)(41300700001)(30864003)(5660300002)(478600001)(82310400005)(44832011)(36860700001)(47076005)(6666004)(36756003)(83380400001)(8676002)(316002)(8936002)(86362001)(426003)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:47.8222 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0e4d7fd-cc80-429b-ac43-08db63032037 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: CO1NAM11FT003.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6138 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 | 149 ++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 147 ----------------------- 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, 161 insertions(+), 155 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..1652d765bd 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,153 @@ 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 %pd access to IRQ %u\n", d, 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%u to %pd\n", irq, d); + return res; + } + } + + dt_dprintk(" - IRQ: %u\n", irq); + return 0; +} + +int map_range_to_domain(const struct dt_device_node *dev, + uint64_t addr, uint64_t len, void *data) +{ + struct map_range_data *mr_data = data; + struct domain *d = mr_data->d; + int res; + + if ( (addr != (paddr_t)addr) || (((paddr_t)~0 - addr) < len) ) + { + printk(XENLOG_ERR "%s: [0x%"PRIx64", 0x%"PRIx64"] exceeds the maximum allowed PA width (%u bits)", + dt_node_full_name(dev), addr, (addr + len), PADDR_BITS); + return -ERANGE; + } + + /* + * 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 3f4558ade6..8bcd73dfcf 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2271,39 +2271,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 %pd access to IRQ %u\n", d, 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%u to %pd\n", irq, d); - 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) @@ -2333,64 +2300,6 @@ static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, return res; } -int __init map_range_to_domain(const struct dt_device_node *dev, - uint64_t addr, uint64_t len, void *data) -{ - struct map_range_data *mr_data = data; - struct domain *d = mr_data->d; - int res; - - if ( (addr != (paddr_t)addr) || (((paddr_t)~0 - addr) < len) ) - { - printk(XENLOG_ERR "%s: [0x%"PRIx64", 0x%"PRIx64"] exceeds the maximum allowed PA width (%u bits)", - dt_node_full_name(dev), addr, (addr + len), PADDR_BITS); - return -ERANGE; - } - - /* - * 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 @@ -2418,62 +2327,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 19dc637d55..f532332d6c 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, uint32_t 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, uint64_t addr, uint64_t len, void *data); +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname); + extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES]; #ifdef CONFIG_ARM_64 diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 117ccccb09..bbdab07596 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1847,12 +1847,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 Fri Jun 2 00:48:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264604 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 8BF90C7EE23 for ; Fri, 2 Jun 2023 00:49:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542788.847072 (Exim 4.92) (envelope-from ) id 1q4syM-0000zj-Tl; Fri, 02 Jun 2023 00:48:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542788.847072; Fri, 02 Jun 2023 00:48:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syM-0000zc-Qd; Fri, 02 Jun 2023 00:48:54 +0000 Received: by outflank-mailman (input) for mailman id 542788; Fri, 02 Jun 2023 00:48:54 +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 1q4syM-0000if-1a for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:54 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20628.outbound.protection.outlook.com [2a01:111:f400:7e8d::628]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3ee731f0-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:48:53 +0200 (CEST) Received: from DS7PR03CA0085.namprd03.prod.outlook.com (2603:10b6:5:3bb::30) by PH8PR12MB6889.namprd12.prod.outlook.com (2603:10b6:510:1c9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:48:49 +0000 Received: from DM6NAM11FT061.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3bb:cafe::82) by DS7PR03CA0085.outlook.office365.com (2603:10b6:5:3bb::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:49 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT061.mail.protection.outlook.com (10.13.173.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:48 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:48 -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; Thu, 1 Jun 2023 17:48:47 -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; Thu, 1 Jun 2023 19:48:47 -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: 3ee731f0-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kDp8mpEodeIBrQv5uBUhgQQwxa/WVdkpPbP8B1ILsrMpnzTN56rC1O3W5wJOt+zKji2JgUce1Io0Jl2aL/mGusxvfTdHBT9+fclvMIp/1ml1WwDiB8njpYXtC3RLdXHlk8qnSnpQM0PxDvVSmuoFgv+llilZZOXyAtLynbNcG3lq2mpddIdxfsWY2rIiAT6IXjkSel6EyJ8T8lIVLvMfE5aOiS25i1Ik6NiOurFUw74jEnY01bbdgtt4Coy+rdpW9rU3DVJTzJtAjy2YWCDmTbo+Dwt0zedoHR9JkznDuX3JPcbHTWyG/2kE9LNCQfyYE51Rd5hnvpAWbmA49y1wYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W+0OsyLFwBeugffTn17WHc7QEkMtS0NECm0n9tJPKNc=; b=YVO01YQOamasTgM5JrGSkpf5v6s6Re8T0F09UxQKN6WE+IpuDZyAgD9Ju6RsU1F8T+DHjjros9PYDySFJPiquiz1e8G+kRcwGrwKNE+OvvJL2WSttqSY6yCqIFGAKV6As6nSuFcTvwf1bo06KjRhWjYKW+2wvh6J2pkErtb2U1KAkL4kUh6IdpTuydGPDhMmR7/aKUYqLi/cwAMYpARCCbAvPrGqIOIVJR9idACUAL379dwkcOXgQ+Lh0Amubt0AtSz/kqIfj8oFnj5pLVb/3ybF4NS0M2ltJwFJjPzfYbQsyAPzpgAQbUyX/LMd0pXjxh8jxqAsWGdm/krJNXPwOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W+0OsyLFwBeugffTn17WHc7QEkMtS0NECm0n9tJPKNc=; b=bSqu9jRShA3zWj6FbDpSgQ3NPP0Tcpw/x+kQhL/xFseZlZc+3tleitDn4hhe9NvQs32IKQM9FT3So5a5DGq8pVDDYSfl3y62t0S5VbSxQNFGxKR7Kl8JwY2Kcfem8YYjMJQhr/CD1w47ZgyLxnOn1MStIF/PKKX3lgkhZ1pBuYw= 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 v7 04/19] common/device_tree: change __unflatten_device_tree() type Date: Thu, 1 Jun 2023 17:48:09 -0700 Message-ID: <20230602004824.20731-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT061:EE_|PH8PR12MB6889:EE_ X-MS-Office365-Filtering-Correlation-Id: b56a2613-955e-4a5f-50b5-08db63032091 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9xnPtvt7yJGOkewHJbN0eNRxrBjfq0XMuUvtmLtpixNcLupZRE4LYdidNbWhylYmuNAsfJf6asnb56picysXjYsCHkK/k9bmrIWwGJsto0dXiIUZ0gNV7Loe94qRZ2k99dqhYhOXDt01HIQMHUXOl8CcTawB58mB34f3w9122DWKrf2RbHMlkOmNH8xsSTpF4I3uflVP/pT27Gwqf8Ak7tGfWopw5AmKJSCvF8O5jbiWuRnwwzDRp1hOTeqMjSn6t0BdODvUoFIB2WXKVRRxyCA1kzgqa5/vJgdcMK3/t1omiAXwHANnOSef2MQVLmJ9CVJxfs4GkzbeG2T1B89f53P+ppffR3hpDwgdbLQ3BVQBtXjW/YClMZiMzscsy1VlG9h2xvpTKxDFBBKI15O2dg7KRtozHEE5pB2jGX6boNXj8T0XkPZ5Bpz+eAWD9nJJglS7rguDWqvw8ptpUhlLp4KpPuCkeoIQ823pxThMnwMcYwjKzaq5UH9Xl+jJmsvwLwx0I5o0P0mtg24xNoh1L6K9xwL+GVfldTIxwFBoUGBA9opps4dsZktVXiY3bW8KGqyifKiESew2zcKM05173oLllT9wRJAW/GzEbPYcPGGWUl7IFhCbYqeVqHaCvZk711/6LbGc1XQu//DJz1/bOtwr3YiD0Ixa05C90S2TrF/Knwpw1yR1cZWQdVLyH7VOjSdByWVfBYc9ksE7U6aYVU35iCCkFfyt815RxpfK58da9O2FvaRWKNe5vJ4OvCC2Y74KvHntCMj4Lg+kh6YIdw== 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)(396003)(39860400002)(136003)(376002)(346002)(451199021)(40470700004)(46966006)(36840700001)(356005)(40460700003)(2616005)(6916009)(4326008)(70586007)(70206006)(81166007)(26005)(1076003)(54906003)(186003)(82740400003)(40480700001)(2906002)(41300700001)(5660300002)(478600001)(82310400005)(44832011)(36860700001)(47076005)(6666004)(36756003)(83380400001)(8676002)(316002)(8936002)(86362001)(426003)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:48.4721 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b56a2613-955e-4a5f-50b5-08db63032091 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: DM6NAM11FT061.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6889 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 Reviewed-by: Michal Orzel --- 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 bbdab07596..16b4b4e946 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2083,7 +2083,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" @@ -2092,8 +2092,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; @@ -2230,10 +2229,10 @@ 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 c2eada7489..2c35c0d391 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 Fri Jun 2 00:48:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264609 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 666A1C77B7A for ; Fri, 2 Jun 2023 00:49:11 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542793.847109 (Exim 4.92) (envelope-from ) id 1q4syS-0001oU-1o; Fri, 02 Jun 2023 00:49:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542793.847109; Fri, 02 Jun 2023 00:48: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 1q4syR-0001ik-Pv; Fri, 02 Jun 2023 00:48:59 +0000 Received: by outflank-mailman (input) for mailman id 542793; Fri, 02 Jun 2023 00:48:58 +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 1q4syQ-00018B-9Y for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:58 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20615.outbound.protection.outlook.com [2a01:111:f400:7e89::615]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3fd8da53-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:55 +0200 (CEST) Received: from MW4PR04CA0042.namprd04.prod.outlook.com (2603:10b6:303:6a::17) by SN7PR12MB7836.namprd12.prod.outlook.com (2603:10b6:806:34e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.24; Fri, 2 Jun 2023 00:48:51 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::25) by MW4PR04CA0042.outlook.office365.com (2603:10b6:303:6a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:51 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:50 +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; Thu, 1 Jun 2023 19:48:49 -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; Thu, 1 Jun 2023 17:48:49 -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; Thu, 1 Jun 2023 19:48:48 -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: 3fd8da53-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h6M1iwZcMfs60vHw8iRltTEBq2AlhOPemegq9OS4h/++GVDODLGB4zwPPxR43uKFG+5oMZfW1nXYWKtm37L/FPVGkzl+Bn6UrrBTyWm02K9og7omzsl5Nmlg9qxXkKnRIewa2U4Rydu7cXPqPlgvJS6e9tce8biSdsKYa8SFimT/mLPU3bwliYfVa2GmdL8jFljQX46R9tUbt15NIgfJMqG28wdRoUSHrRhcH4aiXrwx1kdU+TLZJUinrPhRjqF5V0q6vh/foG2ugGxmsNd8Oe4rnrVv+hq7rVjStCQ5wOSUdzOS94zjZtwpw5Y79y+eBm+Hq1Nc/TcsqjLbftnMnQ== 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=zCSUaAfJqaOws8smne3UwBpw/ZTPHQ6ZelbN3iVgJI8=; b=SJbpg/wD3mlB3YSPIOzHR3Uq+Y57pWyOqpfoMLsITk15DwEkhrMyQBYitt7HCiCPmtQBsGAp9K13xPTN1lE2P2TP5Fmg6JMmtdUxxER72iydmzkxf6dkOXNEp1+F4dPwb63bvbzg7LVFgEmQZA+zB+g8bv838lNZGAmfnOUbrSXU3BdQhcNvvmcnKbEgQeokc8ZcErhQJaAEVtz1f5wR2KtVVyCZ0UmiOWTgB/wdgRS+31A1d2enMoKGyuH24xJSbgzJZfWMpGTRjhpJ0CEGmegA5uZm0sqddkVHFwmZxXK55AgiRU9Zjl80i8rE5/xZ3Ea1B40OITEmAFI6ebWEfw== 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=zCSUaAfJqaOws8smne3UwBpw/ZTPHQ6ZelbN3iVgJI8=; b=T/ua7MgIubMBmjH1nls8jPH1KTSqI1O+AwYe6PMuyuky8X2uiDfS/tW24Mm6CHDR2DFojq4n2DWUZEVSAzfnYgrzH0HtPQy8+gjByKamY2k6pUUIU3V7nkxCKyQwY1XNsg4z0DS5NVILESvKnu+FIHlurrWWysW97/caqJCK2E8= 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: , , , , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , Julien Grall , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v7 05/19] xen/arm: Add CONFIG_OVERLAY_DTB Date: Thu, 1 Jun 2023 17:48:10 -0700 Message-ID: <20230602004824.20731-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|SN7PR12MB7836:EE_ X-MS-Office365-Filtering-Correlation-Id: a2c66782-6ae8-47bb-41d7-08db63032189 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7Ox87FTOGBLOjSDuH+KjMkkBMIG0cPwYI8KDCQTcP1eS4wWzQAs5sVEGz66QPwA9erkUwv+VwlVRVRhtSGHP+HSRMPUSme77gGIBxjDAnRqHLuqDALD7tfTHoOlhIddPjBp1pqDrPpNXWemO3zO9+Vcr6fn2DjbH9dxmMjgSQ5OBH/IYpqM27tXOr3zmZtcFVKJ683skTtYpsEjJCs1zJN21VuqndLTLv+Ys7C4d8BoPeH1p9p35fvk1hkFD37MD7uOT+5d7BkW9xK4b4mhmhryuaCFn8UwtohRO6b4OvCVIVXTuLvBE6+y7jD//wxBahStPOMicTrzdIJVYhpk3aUy4dOwN6aDwr3Gg2L8PmE/39bZqRcrD7d++1lHh3v3UBAeGaOJ5kFzeEMewMBbOkOybkM0vkIPLuC1a8K/PYaJeVUxEQ0ERmiQvA1gG5tCTVnl6DThKmUBDMmo3q448TPD+RiHHLvY7JbZLNhohREAytIA9JCEl2XV15nwbrhCE4BriJBLbxpDM+hepxYtmW3uMj2UNVpP1wurydEjhFQYadJYG+wFLh3zxCaqSaLlxO7NEBhj3ZQ4OMQiCcGs6W33QkYJKRHZuV/IslNLOUHzCZ1K3dw2qnGQOqhen1kJz+z+2LBVnojqWPzW70E0SckRX74YoZlTGjgJQCGXE5zAS06w4UCeHmUqaFPHB1JapABpSm+9Fk04yiQs+fXt58t2URGL2pp96OeJZ4/aYj01Ds+pdS3Ok/xQCtUo8nJzZ 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)(346002)(376002)(136003)(451199021)(40470700004)(46966006)(36840700001)(82740400003)(356005)(81166007)(36756003)(82310400005)(86362001)(40480700001)(40460700003)(41300700001)(7416002)(8936002)(44832011)(26005)(1076003)(5660300002)(4001150100001)(186003)(426003)(2616005)(6666004)(336012)(47076005)(8676002)(83380400001)(54906003)(70206006)(316002)(478600001)(36860700001)(4326008)(6916009)(2906002)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:50.0346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2c66782-6ae8-47bb-41d7-08db63032189 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7836 Introduce a config option where the user can enable support for adding/removing device tree nodes using a device tree binary overlay. Update SUPPORT.md and CHANGELOG.md to state the Device Tree Overlays support for Arm. Signed-off-by: Vikram Garhwal Acked-by: Henry Wang # CHANGELOG Reviewed-by: Michal Orzel --- Changes from v6: Add CHANGELOG and SUPPORT.md entries. --- CHANGELOG.md | 2 ++ SUPPORT.md | 6 ++++++ xen/arch/arm/Kconfig | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bfd3aa5c0..a137fce576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Bus-lock detection, used by Xen to mitigate (by rate-limiting) the system wide impact of a guest misusing atomic instructions. - xl/libxl can customize SMBIOS strings for HVM guests. + - On Arm, support for dynamic addition/removal of Xen device tree nodes using + a device tree overlay binary(.dtbo). ## [4.17.0](https://xenbits.xen.org/gitweb/?p=xen.git;a=shortlog;h=RELEASE-4.17.0) - 2022-12-12 diff --git a/SUPPORT.md b/SUPPORT.md index 6dbed9d5d0..6b27d43cc6 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -832,6 +832,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 Fri Jun 2 00:48:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264606 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 CC602C7EE23 for ; Fri, 2 Jun 2023 00:49:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542792.847101 (Exim 4.92) (envelope-from ) id 1q4syR-0001ae-FW; Fri, 02 Jun 2023 00:48:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542792.847101; Fri, 02 Jun 2023 00:48: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 1q4syR-0001Zj-4v; Fri, 02 Jun 2023 00:48:59 +0000 Received: by outflank-mailman (input) for mailman id 542792; Fri, 02 Jun 2023 00:48:57 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syP-00018B-9F for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:57 +0000 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2062b.outbound.protection.outlook.com [2a01:111:f400:7e8c::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 40307ee2-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:55 +0200 (CEST) Received: from DM6PR12CA0018.namprd12.prod.outlook.com (2603:10b6:5:1c0::31) by BN9PR12MB5163.namprd12.prod.outlook.com (2603:10b6:408:11c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.26; Fri, 2 Jun 2023 00:48:51 +0000 Received: from DM6NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1c0:cafe::3e) by DM6PR12CA0018.outlook.office365.com (2603:10b6:5:1c0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:50 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT058.mail.protection.outlook.com (10.13.172.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:50 +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; Thu, 1 Jun 2023 19:48:50 -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; Thu, 1 Jun 2023 17:48:49 -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; Thu, 1 Jun 2023 19:48:49 -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: 40307ee2-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBgdIyNx1lErEsqHUSihRG7XOhpgomU+O0DXYoEyE3UAjpE38BXonyk4/vzFUe4uXRRpMLabQKok/vU69nswDKAwdACmp6rquxo2INI6EbpMp6qSoGSdOKBeKnksGKKZooXGriS5N/ze8efLJRoqjTZBdEPyriiI1INEr51K59yqK4AKgZDeqxioV5VnwLMnmQvnqwgSBmVy1TRV6GjBxklVIsb2Ijylt3WIRF2O+1IjoHuExpBDVIM+w3U3smmKZzavz49Sa3XBxHK0ofIbXJzJx4xCWetCWJ6/lPxxt+347hWwZV5ACzApyfLSvKHF3DGeiAhTnMSBXIvS0Q9qJQ== 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=P4kPavBZ8MkGS1uEWTtSnvjYtqV3Eu6zW4EZDm5kfv8Tv9ZwYkHlrUPF6tYubk7ZnJi4Swg8ruzLfnO9abM0lKTWl8FZEdptrgd2wxZ3b3qng1xWDBJ/+ouNquSaClcKPKweIuP7JC56Jwni010TvQS1tcnOJFjr+xJVsfVW2pSWeNeODfEhEgPhJard/QM0HIsGY26MY3Jnclmjd04azp1QQ+eLsNKLrQ7ouBpGSQlz7oz9HeIjFgCerRdU3lVw5Hj/9GW+ASXpp/WAvx/gOFtFEOWk3V4chlAZ3HAXFfmODzTUBNkb68zxqf68/JfDKvZ7gLpW7MgLEgmSxy5MYg== 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=L8kfweqG9wzxNi+4XwPRAqKBDHJ0GjmPGlf34fxd0YTmHQQyIXeBIlRdA4dZsuX21CZQIxh1qgi9yqEi8qHqjDcdIKrfvFzmqXpk+R2ghJyY4ZNhJBuiCFhE5/PaPFq7xYigyXq4D2gatC7iGiPwdvqXuGDeGp66lSQHt8jjkVE= 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 v7 06/19] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Thu, 1 Jun 2023 17:48:11 -0700 Message-ID: <20230602004824.20731-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT058:EE_|BN9PR12MB5163:EE_ X-MS-Office365-Filtering-Correlation-Id: cbdab297-8486-4c84-ed80-08db630321ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bQdRVhgx3JNVKksLG2YJ0P5KsJp+9nt/MgflSR3ZxkNC5wCn1Lszc4GB/IBo0iZ5Wa9MgdZZZbv7HUTN1FPYqFStWFK4M5Ty5l6D0K2F6Q1YWPDEuAf38Eb+LR+QH3VJvk1a8DSIM9FmTIF9ca7vdzTThX5ySGVleL0vAb0GzbOiN9R+vadbICwNN5s0yxVo9ISLA6hQync7FhcclnYFQ7+dwt+/aIP/EwyWXorlRiO16eM7Klvij/p9Vmeb0rbu/bpcudcMBTiRR+xbKEOl6r/tz85mlv9Ry2VUZwzYOH0/LbiWIwd5j5qYg6GgWonxJrTmL1DDGe+YUmXCvvQkdYhh2hEMUa+Z33eC5wv3WPDr13CKXJtmazzzNOYB+FuzkVsLDCCFnHMQbVchLiayz02HqI7vvdv0q4TyrYe2t5JwXBPnSLj9KYfkl7gYtVtvgFm6SG+cZtHxI3JZcY7JDVlv/qc1FzUeFegqNATuXcCqXZOQp/Qw5p2ofOZZGe3ZiNfICsbSfgyrIxeMOwGFiLmwNCgp5VsFEQmSUvNvJf19d/KgjdKTtUds2sXQcGR5zzth/UlkkJ6mHqboTQakI9qO8DFG5jvv9J66jHPJOvHgNEjAbRt+uFa9jCAA6tXJeiPEx9Ko46KihHPnznneBZIghmjhTvt6BZIttbmM/a09GoA/2U8Q+xo4A2iG71rLq+cFsb/PnWXUdVLJPzkygq0iFqEPGI1bxikynCZMaedaoRp66+H867xhICeobwQH/W0lLOBWTFQbLPaO+aPWxA== 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)(136003)(39860400002)(396003)(451199021)(36840700001)(46966006)(40470700004)(40460700003)(36860700001)(82740400003)(5660300002)(81166007)(356005)(8676002)(8936002)(1076003)(426003)(336012)(83380400001)(2906002)(26005)(2616005)(4744005)(47076005)(44832011)(40480700001)(6916009)(6666004)(316002)(70206006)(4326008)(41300700001)(70586007)(86362001)(82310400005)(36756003)(186003)(478600001)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:50.5537 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbdab297-8486-4c84-ed80-08db630321ce 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: DM6NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5163 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 Fri Jun 2 00:48:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264610 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 961FBC7EE23 for ; Fri, 2 Jun 2023 00:49:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542794.847125 (Exim 4.92) (envelope-from ) id 1q4syT-0002Lv-LS; Fri, 02 Jun 2023 00:49:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542794.847125; Fri, 02 Jun 2023 00:49:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syT-0002J8-EN; Fri, 02 Jun 2023 00:49:01 +0000 Received: by outflank-mailman (input) for mailman id 542794; Fri, 02 Jun 2023 00:48: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 1q4syR-00018B-9d for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:59 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [2a01:111:f400:7eae::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 40de3d1e-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:56 +0200 (CEST) Received: from MW4PR04CA0046.namprd04.prod.outlook.com (2603:10b6:303:6a::21) by BL1PR12MB5048.namprd12.prod.outlook.com (2603:10b6:208:30a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.24; Fri, 2 Jun 2023 00:48:52 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::7) by MW4PR04CA0046.outlook.office365.com (2603:10b6:303:6a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:51 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:51 +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; Thu, 1 Jun 2023 19:48:51 -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; Thu, 1 Jun 2023 17:48:50 -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; Thu, 1 Jun 2023 19:48:50 -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: 40de3d1e-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LRK7g040+o5EeNmwfU8zGctYOKf+0NpEsP704MJtF8O7rYZbyehfnsuWNlM8F7M3IrrnJytSHhw4qtP5Eorqjk+kALUXZbLItt3JgKWE3gpo/+70hrPeJdwFfFbbs24/TLaZ/B7izUsbSz/y0yczxzTuSwVzX+RhBbMxTNkNO3S0t5TCQshp/h23WLWem+vzf0O2r9bjE/HGNJ9aC/PypYNBj3FrKveUNyjArA1RlUWgQvL/DKyLqcWWYzz4/K3GoyDpPxKpvEno4qnKiz6IRb4ySAWc5IpO29cR8dMDcPXo/fzjCDILeKDWoItBg4EBzvVB0N0IipUOfTQ1u6p6/w== 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=lx/xCOBK4s/DsWiUaFjcYyQMa2MfFrJ7M3OaqU88+qU=; b=DeuCeUfRocQ18g3TwpqBvo118j/teYKqroeuy4P9x+s56cpRQAbdRr8c99OGgTeBOiHyGRjh/K/2cNqKIQrHeXGfbKjy9YXh08LbJ0C44GWQWh5uAu9+prpMVF9B6NPmIcouL+rQy5mKMVERz8fdEgDxU6SUgQGkRsZ4T7+INNfOUSy5e7wAGwmoAX6w/bCgQB56b80USk9/jYEYFGTqlZw/dJRWjcKM9d4OSZipyPFKI9/UeyAQaseX3Goh94dMVa9utFGXVjRCe+N9iuNcWWUtnQq+b3+GuvW/Vg25vTQ02BsnmPe9W0+p723Bwra9tJn/jQJyx8voj+aQSb1gLg== 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=lx/xCOBK4s/DsWiUaFjcYyQMa2MfFrJ7M3OaqU88+qU=; b=jhL0v8sRcRT300kpM1qA+B7d2QwiITmtWT1eSUdVqtNe7ojBkPHplQrqyTApRvAUrEhputZKrWw6Z/69Q7yAjlx3zpK2CkFAH8I1+aPLAsB3WXUHHWMio0yx+BcfkLiVIL/PaGcJ/Uy4O60vkeah0ZUJJcbhuwG82en/7h+RMGo= 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 , Vikram Garhwal , David Gibson Subject: [XEN][PATCH v7 07/19] libfdt: overlay: change overlay_get_target() Date: Thu, 1 Jun 2023 17:48:12 -0700 Message-ID: <20230602004824.20731-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|BL1PR12MB5048:EE_ X-MS-Office365-Filtering-Correlation-Id: d0e45d44-01cc-41c5-81d0-08db63032270 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XLhfVHHsk1dZomPCzVBzcsOlnXv47QzSsnZVfCnXKuJYktuIz4oOBmkd5LlApvxCcQCZZpiC0NKza/vbcZtPLRB9o/W8PnYT6D8NmIAUV2Ht6QRnvLeFZJFJ1h2C/La2IMSYONlvHA/Itub2LG5g6EGMcPF+izOA6c8OhgZecQGG2c309OhKdZcLB95WCSRPVbCIPtQQXJaEflbMmlqrF7WjYV7Bk2eD9v6VwEhzOlUx/ji/+kPiJavmmaZHl4+4W4EwxdJpw10dw9Ae45/9+dzPWeboipBjkvegxgzc2I2Jl9eteb+hzmsx70utAinCXbtLeflQbVfT/gfjzjp6Z3AzlAVelik56fwX4zAP1QRGAYRyUZPUiYjyjzRWQ1R6CUH50uQ2ucMA0fD/ylQzw5XnU4xAVgyJEunCRjYUPpoSgyhyHVle2rrK6t04NW2NRc3CruD2tluiX4lmQQJSxu2U3xV+nhzZ3R42GrRKlkXZowPfzlDl2g2jlAFqbuy0R5vp2/Cu7SRquPfPbm1mgCqpRcP2BAqh78HcMUNblBcON8DD+YV3kViVHyaM/2K82OKAlqngg4sk4fHYCiVnYms0n8OS98H2yf6/0l5ApPOJGJ5se2D1TnDrSAhTGzxpQBd0nsWO3tyExkE6VoeXhtEDsXglxl9xFR4a3V6ZVuq1Kih6p2GYinoWmiUiKRwKRXkz8vz4U9ePTCTUAVVrU66+AFJB3dclS/YkVw7UVdm4J5Hi/xG5X35H5FPd/stKku32C64cnmcTsfSXmjv6xQ== 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)(376002)(39860400002)(136003)(451199021)(40470700004)(46966006)(36840700001)(82740400003)(356005)(82310400005)(81166007)(40460700003)(86362001)(54906003)(478600001)(70586007)(70206006)(6916009)(36756003)(40480700001)(4326008)(6666004)(186003)(26005)(1076003)(8676002)(8936002)(5660300002)(44832011)(36860700001)(47076005)(316002)(2616005)(426003)(336012)(41300700001)(83380400001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:51.5345 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0e45d44-01cc-41c5-81d0-08db63032270 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5048 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 Acked-by: Juline Grall --- 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 Fri Jun 2 00:48:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264608 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 24567C7EE2F for ; Fri, 2 Jun 2023 00:49:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542789.847082 (Exim 4.92) (envelope-from ) id 1q4syQ-0001HR-5O; Fri, 02 Jun 2023 00:48:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542789.847082; Fri, 02 Jun 2023 00:48:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syQ-0001HE-2U; Fri, 02 Jun 2023 00:48:58 +0000 Received: by outflank-mailman (input) for mailman id 542789; Fri, 02 Jun 2023 00:48:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syO-0000if-FO for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:56 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20615.outbound.protection.outlook.com [2a01:111:f400:fe5b::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 40386ace-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:48:55 +0200 (CEST) Received: from MW4PR04CA0053.namprd04.prod.outlook.com (2603:10b6:303:6a::28) by IA0PR12MB8352.namprd12.prod.outlook.com (2603:10b6:208:3dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.24; Fri, 2 Jun 2023 00:48:52 +0000 Received: from CO1NAM11FT088.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6a:cafe::69) by MW4PR04CA0053.outlook.office365.com (2603:10b6:303:6a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:52 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT088.mail.protection.outlook.com (10.13.175.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:52 +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; Thu, 1 Jun 2023 19:48:51 -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; Thu, 1 Jun 2023 17:48:51 -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; Thu, 1 Jun 2023 19:48:51 -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: 40386ace-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U11Fk2KsMWo+2lPhDY3uk8uCFVOius0ag6npTVCUO6xaQlpIMA16caiJetPB6TWUJW4QuMSRHD+JixfLjGkJ3P7l0keSvCEfC7HrJ3TEYgV/CsL+MlaT7vJnh/OULoeMxlhAucPDT151OT9lE1GfXbb1vt0HpTkliKVuw9N1NHqF4JL+M4x4MJLuKQG013wrO/N14IlVpAp9CK5WxQZug8LBYK0l5eX2sdXA9oMAm+ZgSRNehZSYqWmSWcStmEjv0JhtHsg8nvtM2c4fZzGnxVX7j4x43+280/wLJfEodtlT5ronu8Ff1jFoCxqBPzoGSWJbFi+MD2un+74mce5/mA== 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=KBFUC7bBO53GfeOJbg8EGgk2RkSd5j7Jb685AIjqUEE=; b=Rz8eoGSljynJbzelfqgzuA+n6xhqXDeeSYxNXAl43vLNBE19ZrHsPqnn1on7CtRoAAwGb9CDXsrBsPs1BVRArnxjelRbnWGHEcb0u0c0Xf0hhG7Sin+6I8HszWgUM81H7o5P6G4Iyw/1X7WSF9B85IOSXqjyCWi003++i+ftV6pn9QmJw4FZyTAZ8hIGOr8dXmwLZ3c0KIYhT1QQKY4bDnQ3CFo00h8jp1IbsC2DCkaROBq4wuCvaNFBJmC2TnpS/jzT5n6nJhDvU3lsU+EMzpvml6E9O4wz0wfq/zlYwifUE5wJdYS0+tEThIwtr3AM54GVnB6VRWiJ3pjJe3Bn9A== 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=KBFUC7bBO53GfeOJbg8EGgk2RkSd5j7Jb685AIjqUEE=; b=lihDbixGeS3gsx7i09AqY2b5fcCJeEStvF9p+8oqaa1kWratGo//P8rPjRbx9UPcfBkpuuQLwFT5gndSrRGB5/L1eWijftnnomxnwTLDVp5+B6hMNcDfqJWj1HU1IZri1f97ywNIPTV33BBxRPTskVJDIMjIjWNfq647LGPorp4= 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 v7 08/19] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Date: Thu, 1 Jun 2023 17:48:13 -0700 Message-ID: <20230602004824.20731-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT088:EE_|IA0PR12MB8352:EE_ X-MS-Office365-Filtering-Correlation-Id: bb67910d-c2c0-4766-9edc-08db63032312 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Efkh05TJGh+0BR4M5S+17dbeAuR5r3XtOlHBXKsDvg2DvwMC8IvjkpjQk0wIu+vougJTc8/68n+2cc5QjJo7TElMae578b5LN0j1WYpqCAz6SrOlKERD9YFayQ9PJnu9NALcYuEJF4XJOKIHvw7pKeoeZ3v75WV6e2GNkY15xvorsELUJG4E4v21hNPnYTAtAqcJc3sPjK1GsCD69LeJUal3fjYjvQT0xZrQkgwUWB9CKoZCFsfEHVGaP4Xa4ITo6E/YCZESUdtrR5KPheOHWCnmIUdmSwmpdzSN9CNSS09Mw5y7AODrs3lNLotIyeS+q3EG1PhElf4TQN/YVv2OKO3r+zVViSdz82VDSSjmI1+v6GvzroBVIS1O0Ud7YaFSyUKm3L2jcB1cR2DOnkYMCcSyT58xPuwmdPiwF1nR+/tEfEBqdKeRTsrJdUwyJF9pSuU/XCb6LhBKwU7I0FC2jNprV/zpXdGVyzWOjb4iTv6TEoRU/ZFEK05A/Wr07yg3lEbsigH5wECdUqygymng3MU3KY8aC6y7A4LxlDRsy2l8Ui+bmkpUzFi8PWgjk2fctmAoGlfUd7SBqSUVV2ObpdcTwGH0qbrphk6Bh/wruZDy3RyjKqo9HIt6ILVRSCmYxeExu4ODooFfAFjGzMGORBPFSWkyX1YljI1L8muu73p4+KIZJfosrtmqc7/Y918v1eBYzc5p3Ev8yXgihprGMXWY3tE84S8T3HAUWPsu/LrdozJWzY0bOPz18o3mWZyAJPWSRAG0ZWh5+fGYxvP7eL2zgANC8IkF/9vEoLMJHVU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(396003)(136003)(376002)(346002)(451199021)(46966006)(40470700004)(36840700001)(40460700003)(1076003)(186003)(26005)(6666004)(47076005)(36860700001)(2616005)(83380400001)(41300700001)(336012)(426003)(316002)(2906002)(44832011)(5660300002)(8936002)(8676002)(478600001)(70206006)(70586007)(6916009)(54906003)(86362001)(40480700001)(36756003)(4326008)(82740400003)(81166007)(82310400005)(356005)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:52.5969 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb67910d-c2c0-4766-9edc-08db63032312 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT088.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8352 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 Reviewed-by: Michal Orzel --- Changes from v6: Rename "dt_node" to "from" --- xen/common/device_tree.c | 6 ++++-- xen/include/xen/device_tree.h | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 16b4b4e946..c5250a1644 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -358,11 +358,13 @@ 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 *from, + const char *path) { struct dt_device_node *np; - dt_for_each_device_node(dt_host, np) + dt_for_each_device_node(from, 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 2c35c0d391..e239f7de26 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -561,13 +561,27 @@ 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 + * @from: The device tree node to start searching from * @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 *from, + 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 Fri Jun 2 00:48:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264615 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 E8899C7EE23 for ; Fri, 2 Jun 2023 00:49:18 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542799.847170 (Exim 4.92) (envelope-from ) id 1q4syZ-0003cF-PK; Fri, 02 Jun 2023 00:49:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542799.847170; Fri, 02 Jun 2023 00:49:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syY-0003Z8-V8; Fri, 02 Jun 2023 00:49:06 +0000 Received: by outflank-mailman (input) for mailman id 542799; Fri, 02 Jun 2023 00:49:02 +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 1q4syU-00018B-AB for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:02 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2061e.outbound.protection.outlook.com [2a01:111:f400:7eaa::61e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 42edd0b9-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:59 +0200 (CEST) Received: from DM6PR06CA0028.namprd06.prod.outlook.com (2603:10b6:5:120::41) by DS0PR12MB6439.namprd12.prod.outlook.com (2603:10b6:8:c9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:48:54 +0000 Received: from DM6NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:5:120:cafe::16) by DM6PR06CA0028.outlook.office365.com (2603:10b6:5:120::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:54 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT052.mail.protection.outlook.com (10.13.172.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:54 +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; Thu, 1 Jun 2023 19:48:52 -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; Thu, 1 Jun 2023 17:48:52 -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; Thu, 1 Jun 2023 19:48:51 -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: 42edd0b9-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G1dreupGVujvSg/z+Wqao6TRb24z6Eo5sPR42CqhbGe2reI8sJ9DUnie7v4Jp/Vk3coLPf7VWT941Vj+GoCvX9VuOlUfBzWbOLJD2EeN+bMpDWF6xfB/1kFeVYNVj6kb3Y952Oqc4VRfbfpXHFtUEqoaOq4pTNV4EoJl6/QbyAhvmiK5FHdoSHAKO6slyV135DRYpy7NTxKSvYcHan2vjeDoUaffcCy+BZ/MKGpoPWaXDCzC/GclrnEKmKr8Sd7F49z+havEQ85ZCrB55efaQKDs+Pxhu0t50RIsE3iDJlOn8i2eYYaknkqcATt7A4W99EfGYpeD/u1jMyYTWhg9pg== 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=vBab6IziVUb8VqAgLKyxqLfCTUlQNBsFeFHWzmZz53Q=; b=lUCbA0cVQvu+JGz77SuhGKpUuFxm0vMmT1xi+oLSf7TwkcbrOSZpRZZ/YiR/7apFYlKRPmbHMzFOoC5ETcLzwvlTnFQJ90ipKWBDDUJjQAhUiEA61+dn/IJyJV7qRhrFwVLkuomcDCoyJ+wEzyIgHwzVASSKWcOABvJK4eLjueJUU+VoqECDrIPIEmoxPwjEOHestXj7K9DvIt4ZiFTOtwFACnJV/xKxyD06J9YlyWNgClxcLIRaURXZ9lLvZ2ugxJ+em9+LMKGQunLreVuaux3hcv/VSwjKpbIdRtMdkenkv+1aCOKl6f/MHzFl1j7HsIUNQow+iNukm3yvR+yIyA== 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=vBab6IziVUb8VqAgLKyxqLfCTUlQNBsFeFHWzmZz53Q=; b=4uc+/KsJhACoD8vcNwCd5CEbLUxco53XCTLFNFkQIxIoXwo6amGGz9fYYpZcxGvxXC+lpNHfw61koA3Mouf7DBHO2w06GGFLfRDBaHdFVciIVCqYIJ+eUMS0PONUa7Vy49uJFdKp0M+Xw0lcDBF4FnrwdjbPijfdJxlaVuskeR8= 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 , Andrew Cooper , George Dunlap , Wei Liu Subject: [XEN][PATCH v7 09/19] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Thu, 1 Jun 2023 17:48:14 -0700 Message-ID: <20230602004824.20731-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT052:EE_|DS0PR12MB6439:EE_ X-MS-Office365-Filtering-Correlation-Id: c22cd97e-2869-4017-2b83-08db630323f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2figlig/kEBWEXIlqMT7DFbL03nzTvTlqiYQPY3FY3AWx0nTwM6Y8NcETmvUuHbj3bVC6obAdyaYdJhzDX5dFDkdApkZ2+PZn7sInpguOK+EmBCB7mXPW4H3YuPGUJDmX89+vDBKGPDLt2ZfPFngDO2XMy2blHWKWIcm64k/wbohEXN0MxTpPZ7uzbTOfwqBElb/bobXYsaTqlrUqbNpmBUhxXigbh6jkWu1B4fdw8/f3DW98vmbBcLjFnpl2QlCej3utnOCFWNKit1G2oZWs1LbNQsM3QNdx3ceIX0JBImiGvM1DFuYbEBDTu73fho80uWrqqEJ/ivbeRgPytvN78J1jqtloHPwoOcsvf3OlaeF22Uft3lSYjbJbSnu9f7RTNBua7MXDzEttMvAr8vAgv/5UKcsB38MFSmiwjtGDwSc48MOdXVPQCYgiwjfaXnfBCwZStaTf6dXzCi/y9k+LFFjSqR8adJwKNGiqai7burq7LV/L5bru9ZnkXQzfYFonehQdH992ErjzWC7iRA/MySpBc2JPe317SdRlPvJy4sieeZZaP6QxAXP3x7xeDvaLF14tp/1wQo7hL7RpJlPkIAw/nGHzAzLMfqrwZBqj5raTsvuX7tz21cxlK1jAUQTR6ewPT9bPgiY7A/YeXHHHuw+lDtujOUOyeVc11x7e53cVJrZa4WVgJHJlwn8uAt07Yg1Gr+mibnkNaq7GCvZjtxPbvCw/h+gBXQBxTe5DjLFk1rvvkxKSYsWlf43YWIeYHZsA4PiKCWye431AXK9Rg== 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)(346002)(136003)(396003)(376002)(451199021)(36840700001)(46966006)(40470700004)(54906003)(40460700003)(478600001)(44832011)(8676002)(8936002)(5660300002)(36756003)(86362001)(2906002)(81166007)(4326008)(6916009)(356005)(70586007)(70206006)(82310400005)(316002)(40480700001)(82740400003)(41300700001)(426003)(336012)(83380400001)(1076003)(26005)(2616005)(36860700001)(186003)(6666004)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:54.1270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c22cd97e-2869-4017-2b83-08db630323f0 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: DM6NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6439 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 --- Changes from v6: Created a private header and moved iommu_dt_device_is_assigned() to header. --- xen/drivers/passthrough/device_tree.c | 20 ++++++++++++++++---- xen/include/xen/iommu-private.h | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 xen/include/xen/iommu-private.h diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 1c32d7b50c..52e370db01 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -83,16 +84,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 +212,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-private.h b/xen/include/xen/iommu-private.h new file mode 100644 index 0000000000..5615decaff --- /dev/null +++ b/xen/include/xen/iommu-private.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + /* + * xen/iommu-private.h + * + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + * Written by Vikram Garhwal + * + */ +#ifndef __XEN_IOMMU_PRIVATE_H__ +#define __XEN_IOMMU_PRIVATE_H__ + +#ifdef CONFIG_HAS_DEVICE_TREE +#include +bool_t iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev); +#endif + +#endif /* __XEN_IOMMU_PRIVATE_H__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Fri Jun 2 00:48:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264612 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 B7C2BC77B7A for ; Fri, 2 Jun 2023 00:49:15 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542795.847134 (Exim 4.92) (envelope-from ) id 1q4syU-0002U5-HJ; Fri, 02 Jun 2023 00:49:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542795.847134; Fri, 02 Jun 2023 00:49:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syU-0002SL-09; Fri, 02 Jun 2023 00:49:02 +0000 Received: by outflank-mailman (input) for mailman id 542795; Fri, 02 Jun 2023 00:49:00 +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 1q4syR-0000if-Vm for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:48:59 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [2a01:111:f400:7eae::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 42a065cc-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:48:59 +0200 (CEST) Received: from MW4PR04CA0100.namprd04.prod.outlook.com (2603:10b6:303:83::15) by CY5PR12MB6348.namprd12.prod.outlook.com (2603:10b6:930:f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.26; Fri, 2 Jun 2023 00:48:55 +0000 Received: from CO1NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:303:83:cafe::18) by MW4PR04CA0100.outlook.office365.com (2603:10b6:303:83::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:55 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT112.mail.protection.outlook.com (10.13.174.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:54 +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; Thu, 1 Jun 2023 19:48:53 -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; Thu, 1 Jun 2023 17:48:53 -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; Thu, 1 Jun 2023 19:48:52 -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: 42a065cc-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A4cBnT6q+KCIPafdlLM5CP4yDXsWNCLlnwOUHQi838ItqG4KKEXYEfgUwxiQOg4ncgn+82spxRpBw1a52c0+815CHq6MzPswm541Ue5BY+tBhuHQwte0o/xWeGleIBxx/AAjsO0fKkJxE2ekt5Xugst+uuymCivEbsLOWhxKeI05lPBiZmujsWUkmN2LEkgQ4vOmupnPh1VsycMA7QZzYk9bArRqodbWtKpuHoJIUQvq5+4ahRAtor/wcA5kutsiBnD7y+scQpn1xwORAC2qYkrIFaVscx3aP8DZmpzLVzZm0gq7CrVAqghdDCfc38bx8IQXSjirxYs1KyUU05IUUQ== 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=BBHXZIlMJGJe8+ipovZgPxAdAwa+jzzdQSk6DYH6FhU=; b=GUO4jqSsFNN/hMrXISeoCBViXMnlvRDzIBg54qDYOJbbWGY6jPwZpXX+g2ZWCf9wGg4zfzLok8jsvQe9ownirPa7yUS9Z95GzupKXz21UvSXYxXQA6q7wN9R2fuUHCFdyNMqtGZeooZ+0Jtf4aghHTww1/EkbUA6U33t/zq0I4JIQ153s2G64PJgUTMAggCa21ptExsOj88kRzbYLeXTMedH6mgbj86Qs9xuGAIfSTiKazFBzztO1QOSjqv9xZmI0VVW5z4x2e/Qnde/8KRp3/16rJ1wU6MaCmZqdakMAIaTR5X/7LHYLKDZ3vjQMBLfDs+8C5LuAPWO6Wsl+Fo6yw== 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=BBHXZIlMJGJe8+ipovZgPxAdAwa+jzzdQSk6DYH6FhU=; b=PFFvMVYnFBE+piBZe+QnuwfdMwW910NdGfoo1Mbo/yiuqYe5lCNG25zkZ94j9C9WD1a8OA2TxYMQSQXXeiAeILwl1kNWa13Uc0AEsJzcA7Bz3kou4fqb2XQJv6jKH7s7NfWibGrGok/Y35YbCyWI/4WRTjyZHoLLVhmStkYo62E= 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 v7 10/19] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Thu, 1 Jun 2023 17:48:15 -0700 Message-ID: <20230602004824.20731-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT112:EE_|CY5PR12MB6348:EE_ X-MS-Office365-Filtering-Correlation-Id: c0e6cfb0-1bda-4842-c504-08db6303240f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eIH0Ww/uRi8IVsPEDXrW4RM+t/vLeRT/ogEO/LQTmYuCZqt0zuW2METsp8k5sTNcmDW9Pj3qmCVKFRfxapzsc2/bbqnXLl7i9q2n9ao3mdB6Qg2o79+zH4/L7NalXqgF8OzezalyAjN+Z94K8gEBDoIy/Hhy53XFkuFaoNkYI8KtuHtc26gStAU4bLEd8UTcEl1KXFnS2dthZcg/fGmbbRGLr9J5ibS004Po9mDjimET35CZSy4hIBxycH1zq1GJAm/f+LUblJVQ2I3UTHT/KobLYpn2X38ZyvF5zN/ZdkbRrQ2+HctZCvobF+w5VcU7UzHWzbRuV545M4QM1WyeK1iCXdMrLviBAFuUY38DKnMQPeOBL8SCfwjQ2wiIBUypX9ArFXecnyeua+OPYssowo1F5fHLvWbj9ulbEclZ8xytoi9kHb0S+4fZhf9x2wF6y8uHEjLEXNQnzPI+T23k2+wDtzB1d8vamVYxuCG2p0b3k3v7KXNjKvHXg7FQpzT8bhokrbg8BVEyjOv2xqT3KcTr9Ov6nDFFEPetf9yf4rWclTWL+J5UcVmYBnuG2eWhKumns8TtmrZP+28eK/bx0cOI4V8TaXkBhvEegm51zNNdWcCx3O8uCpjher3O3GhtMyy2P9e/Lapv5CzBTygFZ6mxNVjoluxrOey5f2Ga0JkxoSsZM/KqdeCazjyRejjvAogzy9wy1EoAQ54QWj/2GDZWch4tHytbCGahfGE3FTOA6O0BUa91VH3QQeMyKtou0vUzwtlCntUGFXbEeGtHEg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(396003)(346002)(376002)(451199021)(40470700004)(36840700001)(46966006)(83380400001)(186003)(41300700001)(336012)(426003)(6666004)(36860700001)(2616005)(47076005)(1076003)(26005)(40460700003)(478600001)(54906003)(6916009)(70586007)(81166007)(356005)(70206006)(4326008)(40480700001)(82310400005)(82740400003)(316002)(44832011)(8676002)(8936002)(5660300002)(86362001)(2906002)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:54.2715 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0e6cfb0-1bda-4842-c504-08db6303240f 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: CO1NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6348 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 52e370db01..8cc413f867 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -146,6 +146,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( dev_iommu_fwspec_get(dev) ) return 0; + spin_lock(&dtdevs_lock); + /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt * from Linux. @@ -158,7 +160,10 @@ int iommu_add_dt_device(struct dt_device_node *np) * these callback implemented. */ if ( !ops->add_device || !ops->dt_xlate ) - return -EINVAL; + { + rc = -EINVAL; + goto fail; + } if ( !dt_device_is_available(iommu_spec.np) ) break; @@ -189,6 +194,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); +fail: + spin_unlock(&dtdevs_lock); return rc; } From patchwork Fri Jun 2 00:48:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264614 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 3AEBAC7EE2E for ; Fri, 2 Jun 2023 00:49:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542798.847158 (Exim 4.92) (envelope-from ) id 1q4syX-0003EC-Ll; Fri, 02 Jun 2023 00:49:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542798.847158; Fri, 02 Jun 2023 00:49:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syX-0003C0-5p; Fri, 02 Jun 2023 00:49:05 +0000 Received: by outflank-mailman (input) for mailman id 542798; Fri, 02 Jun 2023 00:49:01 +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 1q4syT-00018B-9y for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:01 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20619.outbound.protection.outlook.com [2a01:111:f400:fe5b::619]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 42925077-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:48:59 +0200 (CEST) Received: from MW4PR04CA0097.namprd04.prod.outlook.com (2603:10b6:303:83::12) by MN2PR12MB4582.namprd12.prod.outlook.com (2603:10b6:208:26b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.26; Fri, 2 Jun 2023 00:48:56 +0000 Received: from CO1NAM11FT112.eop-nam11.prod.protection.outlook.com (2603:10b6:303:83:cafe::ca) by MW4PR04CA0097.outlook.office365.com (2603:10b6:303:83::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:55 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT112.mail.protection.outlook.com (10.13.174.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:55 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:54 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:48:54 -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; Thu, 1 Jun 2023 19:48:53 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 42925077-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LbdfTIhNv4OLVWrNP5mYWLnmWofmDkgClqNefvtthr79xyZ28ZsxXCnY4kcldDZEf8yM1qq89z3IbzJ+X3y+XUVuLHaL1RotX8X1wpROsprrFEHwRPA5Gr0yq2fyRUjmFQvhGWnqRWwyHQcqVxxti4dRiG7WR4SxXp1bmBek0AdGSFk4aMKhSgkm8Z6V0bK307l82o4rN0f239mWUx8oHwJhJGLOrrlr1cFOVF1HuNnsAGc52FQcgulF3KPzWdnwlzWjPCIBC7Omo8Lfk88N6WGe5IagPqiw7sdEm7SvyZvKomJS3AFtjp5cbiqgzeqvQj/Mk1nAwbC+kQfdMXUDHg== 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=SyXqOAFxYRECrwE1b2BNmdAgZBkIMTgn0iP+i+1WDJY=; b=mzxWwgBMuYOdSW4Nhj0pGETvue30ztZlHlSdBVGkmzn1M1unGKnb7WweFKCErXnwWMyXu/et2ZXRsik8tVwp2ZQIkHaxtxSHmmvTF7XAGpZxaq4Ay5G8eDLvPy59XZhgc8n/Pda2lKoonToqPu/GaeLtnhZ5CxknKMAH0raojAfKYVqfmbPA4/OvrVzn7tGkm6RgUGQ910HnqVOSWOfo9HX289x1vUpxwjr4RSOkpC/vCvI9Ab/5I5m1jVqMV0Kx+r37JYFYsyW6diWNO89faeg5colfidl2gFVVfp5eUbJjP1Qm1VxhUSrERHi7x+wyd6xDCFjgbX4m/EiJrrdf0g== 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=SyXqOAFxYRECrwE1b2BNmdAgZBkIMTgn0iP+i+1WDJY=; b=UOO0h68uhzaEulaqDNYowPGBsD6CpGzSxt/9iZSUiuoWY1fH9w6QcEMpsauG/uEev2Q5Dff9tza128cHgm+mH8kTd/HP10oFyEFgUf2F4gzFARvk5grBsUKMwYwbeUMWK4xDltoueHOn0uNHDc0/blZaZAftBvaqNCA4Ilae+Cw= 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 , Paul Durrant , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [XEN][PATCH v7 11/19] xen/iommu: Introduce iommu_remove_dt_device() Date: Thu, 1 Jun 2023 17:48:16 -0700 Message-ID: <20230602004824.20731-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT112:EE_|MN2PR12MB4582:EE_ X-MS-Office365-Filtering-Correlation-Id: 68f3fd61-e29e-416e-f561-08db630324c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RAFsIcHVmsqwTvrA2ibNNgBwwG/WvKLzhRa6ZoKASaEMTgwCHMuY559yXcLx7LLzzx+juoWkHXpnZuFVp60Ui7yRaPX+OVtHSh4+qCCfzobnm/KABYZ8arMzbLdDCFi+IHL7uDVzWDR7ObN7A2wJ9Vc2Znt3HtWYLp6wQ0QYQV6s9B97GV6sHc043YT6gSaWO0ant9mtHfMo5zNpCRRt5hyK/H2Vq7LZ8RS8Duo3NilpRhqsCliGExSsEClnID76Ia7rhMnkbxpp3DY97mWZ00w+r8jDItIXzN1Tz7MCZg5IzdCLlA1zukhDQ3ENIgoio+uz+SRXSkhq2SNHNn7y3ZjEsLf7G4L+GRdA9BALrzLG3m0Lp5XfWVwLwsV5xpHFifrKPgBqmAT2zEKfb+1S+LKt0Ano0ZQlUTTmg/rZFXJnu1UtF6YwXKMgbruqGw6TPh7zxeLyZjFmjVajRGozgCY2dQQXMzMi4lFFAAkrY/3rlkeLW5SRHeWbT4yBEpj6Xvk1/s0ffux7zlV96AwFmeEzMGWl1q2L3qdUI/6qnIn+KqKcEzBUUYN4xL0sTWP+om3q5ORCSmRt1cWsgc8RLTwGDNQfQ0yQULtGmI4C8BVzdx4Y/n8dsxCBbg55ah6VZ9ZvTcrNi48t4F4T4ody8uX1Z6XS55E8vHzGQdX03c6FNxOU5kwNUbEWseLkveeUHo+7GA7uS8zSVYE0kZcbmXURVFaGL0WqQyX0k/W+S75V445h/yELsF5OES7LqOzYdaGMA9lfPKlOQzFgn/zvzw== 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)(136003)(39860400002)(396003)(451199021)(36840700001)(46966006)(40470700004)(40460700003)(36860700001)(82740400003)(5660300002)(81166007)(356005)(8676002)(8936002)(1076003)(426003)(336012)(83380400001)(2906002)(26005)(2616005)(47076005)(44832011)(40480700001)(6916009)(6666004)(316002)(70206006)(4326008)(41300700001)(70586007)(86362001)(82310400005)(36756003)(186003)(478600001)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:55.4590 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68f3fd61-e29e-416e-f561-08db630324c4 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: CO1NAM11FT112.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4582 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 8cc413f867..301a5bcd97 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -126,6 +126,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 405db59971..0d7924821b 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -229,6 +229,8 @@ int iommu_release_dt_devices(struct domain *d); */ int iommu_add_dt_device(struct dt_device_node *np); +int iommu_remove_dt_device(struct dt_device_node *np); + int iommu_do_dt_domctl(struct xen_domctl *, struct domain *, XEN_GUEST_HANDLE_PARAM(xen_domctl_t)); From patchwork Fri Jun 2 00:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264613 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 30103C7EE23 for ; Fri, 2 Jun 2023 00:49:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542797.847151 (Exim 4.92) (envelope-from ) id 1q4syW-000350-Th; Fri, 02 Jun 2023 00:49:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542797.847151; Fri, 02 Jun 2023 00:49:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syW-0002zU-B4; Fri, 02 Jun 2023 00:49:04 +0000 Received: by outflank-mailman (input) for mailman id 542797; Fri, 02 Jun 2023 00:49:01 +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 1q4syS-0000if-Vw for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:00 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eae::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4316075a-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:48:59 +0200 (CEST) Received: from DM6PR03CA0074.namprd03.prod.outlook.com (2603:10b6:5:333::7) by BL1PR12MB5753.namprd12.prod.outlook.com (2603:10b6:208:390::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Fri, 2 Jun 2023 00:48:56 +0000 Received: from DM6NAM11FT053.eop-nam11.prod.protection.outlook.com (2603:10b6:5:333:cafe::95) by DM6PR03CA0074.outlook.office365.com (2603:10b6:5:333::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:48:56 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT053.mail.protection.outlook.com (10.13.173.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:56 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:55 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:48:55 -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; Thu, 1 Jun 2023 19:48:54 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4316075a-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L26MiYxe1R9ZduPra0t4svbywQKYqhNTWmixJ5taaF5zewdJjHqDAmfKKl6aNoU71q70S4kEoRx5yKFaYKobDBkELfOQzPBePb9dIGNIF3klLyCPcJO6oCyWrTMGmiUSj0B1LBuOUYuRuXFvc0HC/+TNGBek4HamH4uDB/qdy/GAo/EbkxcRy66txfU3BX92X4qIzLqxAZfZAaBTZYMek9gq+UnRRJ4d+nVXVjmedtvNt3+v0mVFnsdoe7QAEQ6YzGA6uCH4K+AOlJ9w6HQ4BqqUisM7LLTR4vOKNP6yDEgymtYuQiKcIHrAS3a+yt1Aokx7bTixiq7UmSTY2+MtrQ== 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=x8f6Wjw45ONksBxgsuuhCKdaU9dyqrhh4lFwNBN7Yrs=; b=I4Q7k9x+ahBWBVj3K0eqhewn44sxhfRHxqvLBiaQsn7/4u9Sp0Zd87He1Zh+lTIVWaccV6zbPVA9TookyuWKgWyx3UDOBN5rPyP4e9dkPiwM293R8whvDNdHFlqZdH0UlOjSZG3hck45Qao1HV0MzaZ47xdBz9dKJ25z6kIeejmm9MllWFn5rjGqpyzBbye9wIutvKwkjg9MqaHx3/Pw3D9vtEMbFv3uj5DmU58yt8LEd94KqaCF2BLUKZ1wKkyU6Gvvqov8xh0x4hsPPzPA9jbiHP/29o0v76mEbxgfwkwIsi0w4ua0fBGJHRLZSEcpVMUJ9h9okfa+r29UKFfxCw== 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=x8f6Wjw45ONksBxgsuuhCKdaU9dyqrhh4lFwNBN7Yrs=; b=I1HKJHIsQVNgT4GI25U2DhS0jmwfhJmgHWR4o9Db05sRqcz+fmfzAwM9ykDv0geCRtfAW/UM7F8nFQ5mWTZ8GyWa7XM/p/elv7q8KfYwdC++gLrET43/jgWkExh82zjb+LerGc3TTtvsii3p18C/AaigZ28Mb2jcETEL19ZyAeA= 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 , Rahul Singh , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v7 12/19] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Thu, 1 Jun 2023 17:48:17 -0700 Message-ID: <20230602004824.20731-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT053:EE_|BL1PR12MB5753:EE_ X-MS-Office365-Filtering-Correlation-Id: ceb94667-5c61-4736-1876-08db63032518 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VnnBptogcLG1GiuYNmXTDIatpv8PWVsbLqJ8+bSGaCJ4QllWDPJSmP1N7QIhBShCDg2EBJ27+3gSU58y1pPesmXd4WU34uR/OBhT4TFLpYCUlDRjqQUyoeLZvgB8Qfp0lVXtU1fPbEIL+Qk5cO1cmQuKHrSldQbYo35JwrsFS74mvssy5ObM7f6JKHFcJAkm5uq4JoXnn5bJhGrO+fDoxUY5J6NC3+z77vNDojapMoerNB7En7rcPHVNmF84DH21JP56kBtqDdd7Z62oFRQnJyE0q3n060aJDwW6sETUvO1ZsL2hIz5f3DpNufLgzBWhwzUXILi9ZtuO9EKdK4sAHtZlILBWoS0qefligC04y0fqTd8qU6ifQbxqqsMnHuhcpPiddDMQMtYQd2Nt12ABM68ifjno++7QNDaT9Hpxaqed94Qbr7MUWVYHHzG4rd5Tjq8WYEXH0V4u02+9u1B2wO8MrLdsY0hMn2OaEYVpASftTig8yLrxVojyDtYUkW6GwLmUyua1uktPz3Y7thLtWp4OcrtPdS15n/qw39zs1lzju+vtn1x0gofV2YTBzeKwMGyIbjIb4C8FGoNdz3eRgwoTrpF0nq+987vzrmBGFbokWG25NoZwY9Xg82/XZFMUUmsPe/JHKX+iX3CDsQALsvs50gy991YwqtQ/BQzZou9hE7/GtR+zNNiYSDJkp8RzKC31fsuRFY95l42O1FZ824l5WlaV10pv/G3pM7BWYNIMkpFS6DXeRVxZrFFLAMpYi/uDXsJvqYP7Fr3GM7boyQ== 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)(136003)(346002)(396003)(451199021)(46966006)(40470700004)(36840700001)(1076003)(186003)(2906002)(36860700001)(36756003)(2616005)(336012)(83380400001)(40480700001)(40460700003)(426003)(4326008)(47076005)(316002)(6916009)(6666004)(70586007)(70206006)(41300700001)(54906003)(82740400003)(81166007)(356005)(478600001)(44832011)(8936002)(26005)(82310400005)(86362001)(5660300002)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:56.0663 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ceb94667-5c61-4736-1876-08db63032518 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: DM6NAM11FT053.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5753 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 | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index c37fa9af13..fdef6e7a7d 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -815,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) @@ -852,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) @@ -875,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; @@ -2859,6 +2917,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 Fri Jun 2 00:48:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264618 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 69F19C7EE23 for ; Fri, 2 Jun 2023 00:49:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542803.847198 (Exim 4.92) (envelope-from ) id 1q4syg-00051j-E0; Fri, 02 Jun 2023 00:49:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542803.847198; Fri, 02 Jun 2023 00:49:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syf-0004u3-77; Fri, 02 Jun 2023 00:49:13 +0000 Received: by outflank-mailman (input) for mailman id 542803; Fri, 02 Jun 2023 00:49:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syY-00018B-26 for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:06 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20616.outbound.protection.outlook.com [2a01:111:f400:fe59::616]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 450f7372-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:49:04 +0200 (CEST) Received: from MW2PR2101CA0034.namprd21.prod.outlook.com (2603:10b6:302:1::47) by SA0PR12MB4461.namprd12.prod.outlook.com (2603:10b6:806:9c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.24; Fri, 2 Jun 2023 00:48:58 +0000 Received: from CO1NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::1e) by MW2PR2101CA0034.outlook.office365.com (2603:10b6:302:1::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.9 via Frontend Transport; Fri, 2 Jun 2023 00:48:58 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT033.mail.protection.outlook.com (10.13.174.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:57 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:56 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:48:56 -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; Thu, 1 Jun 2023 19:48:55 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 450f7372-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YP37zK1MTTnTIgBCY2xm9N1z2hnqLOVeWBQM1RnZhlDCKqm7YLOUoMJhQqDtKJ+oeoVU6UaidbwiqIeNkx73m7sBSp0v7mKYjSoArwukXZTyq9Q4I8+W4VOC7NQP1HbR3RKMS3BPhNrnnXWTkgH2lNFiL16DMCfyUcXbyCduLT6ocZsxZSQ+hngFKs6eO/tLC+LkzFLNYWGagsPYvm4IrEb/otucI4jrpwTdX0KzhaacwNKLflfk46s0lCsDHmqMqXMTxp9QHV22/+2VccM6ZXmrymxet/D0vAqKMlqRFPbwRP3F8yN+2yozDyNC56adV3qF93LZRLmgznhNRYlgEQ== 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=cw3ZgAJufScS/YkBvxCBzP/nR/M5kVzAUuLpS4HefHs=; b=KscL3NRo1r76NTawraKYvZ8y8qLHIA8/tZAqJFqGCTuIs2vZR+BmHd8KYJt0npWP2ti+pmG2O/h4dU7QnRaJQzdrZb/VSsoZSHI2f7/BRNV0PG3mowPorYfj5s1XEOfAgvycMFwB9kKgARBY0SYREIsai9PfM+BNWXKCYvEn2qyL3TwT23ZY0n65vXxz+oi5M/+1QWBPtarY8L5qYtJ6YotKNcHj/jpjy4uFn8/RezFPlERGYCvMJ4HT/rV8N+PpDyBHjyPJD9sEBQ4him02LEarHIgGO4jB+xBJ/YzgZprJHfkNkAhtyaGmdYyt0eTWHaOuLriqVWaHNtbuYzd2kw== 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=cw3ZgAJufScS/YkBvxCBzP/nR/M5kVzAUuLpS4HefHs=; b=e2PvS7RH3KA7nkhzhc8PiQrZBFUyBR8V9z3ZBsBTyK3RlLP05B5frXOrxE5UZzneXKBDaM8QzlJamqkpgKq6qegiEGKW7QyPcbJKVXQmls/LJZnz2QUIAYF9HJFp47Z1uVodYbFVgMNMuCKXv+Zvy6S3iy3I6Io/9cCyOsPyUGg= 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 v7 13/19] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Thu, 1 Jun 2023 17:48:18 -0700 Message-ID: <20230602004824.20731-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT033:EE_|SA0PR12MB4461:EE_ X-MS-Office365-Filtering-Correlation-Id: 4631094a-a250-4563-8928-08db63032614 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zxbrzXF9KkBZyucInPXuc2bP+Ix2YLZuSl02O98SMb0XzVjacZ/vkAiHgEvtU4zmg5Om/101L6PAqNtEOeNxcTAalr8ds/hoYnQBKPvBX5hl5i2V5T3S7WmW1jyO0vuwQRgPR7eQ8f1p4zvtbMnE6cH4wuGYggkFtqx7kcXQdaocUC4IaIsYWTbfKR002kWQKqzJ6rg9i2TLbtRQenbhm4vGe0fQ5pAe9tY3TkGfNu9TyivdO61s47dvqKbZD18GY8/l6LXdVjTKUkZ2Tr/qpQpyt2uvpSpksTNiILL6AIaoYIPVIrzgfEuqRE3Ru/UMHd95uqxEANVRDul/G2auGy7DBDrUFVh7uyQgMZPFTE6//7o68oF0yd/xsf1vu8EdNlWNUNMAT6YUWZUrhsp1Z1dJANYwxbUXsdWwsJOhoO1djSuOCYLS5mn5ExbC+QTgWtOQqbFKpC0OucZudvwb0Ng8H7C7xOTT4WcF/ktOWOKvy+yDfQYXp6+uYQGCBjTOXIlRliuETh+5l5SgRHkCruK93VYd/dSGfaAEaoFbpfHUPYqh1PO9EruEEW6rwd85R4KOqC2XLrxrNo4PB/6eeWsnHhC3Tr4h6e5a8DY0HRgoNiaChn1TCRW9Vyo6hEpfGz/kwuzsFsbqKHtQM1ZBPtv3e3ntRUUJpcp+uHykWWVk5olRcbpqVgF4RtlKA6aK/LGGeHGfttR6gS+Wcxo56SSfwsVBjdX+JIwOg28h9KwENrIBBLbxSNo+1xU3Bwa1T7sOYZNuzIcBYOP/xHFXEg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(346002)(39860400002)(396003)(451199021)(46966006)(40470700004)(36840700001)(47076005)(36860700001)(336012)(426003)(83380400001)(40480700001)(356005)(70586007)(70206006)(26005)(6666004)(1076003)(6916009)(478600001)(2616005)(54906003)(186003)(86362001)(2906002)(44832011)(8936002)(40460700003)(5660300002)(8676002)(36756003)(41300700001)(81166007)(4326008)(82740400003)(316002)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:57.6114 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4631094a-a250-4563-8928-08db63032614 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: CO1NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4461 Dynamic programming ops will modify the dt_host and there might be other function which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host. But adding rwlock in device_tree.h causes following circular dependency: device_tree.h->rwlock.h->smp.h->asm/smp.h->device_tree.h To fix this, removed the "#include and forward declared "struct dt_device_node". Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang Reviewed-by: Michal Orzel --- xen/arch/arm/include/asm/smp.h | 3 ++- xen/arch/arm/smpboot.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index 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 e107b86b7b..eeb76cd551 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 Fri Jun 2 00:48:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264616 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 17786C7EE29 for ; Fri, 2 Jun 2023 00:49:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542800.847175 (Exim 4.92) (envelope-from ) id 1q4sya-0003nh-TK; Fri, 02 Jun 2023 00:49:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542800.847175; Fri, 02 Jun 2023 00:49:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4sya-0003it-1H; Fri, 02 Jun 2023 00:49:08 +0000 Received: by outflank-mailman (input) for mailman id 542800; Fri, 02 Jun 2023 00:49:03 +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 1q4syV-00018B-AF for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:03 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eae::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 441e66ef-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:49:01 +0200 (CEST) Received: from BYAPR21CA0022.namprd21.prod.outlook.com (2603:10b6:a03:114::32) by IA1PR12MB8237.namprd12.prod.outlook.com (2603:10b6:208:3f3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22; Fri, 2 Jun 2023 00:48:58 +0000 Received: from DM6NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:a03:114:cafe::82) by BYAPR21CA0022.outlook.office365.com (2603:10b6:a03:114::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.9 via Frontend Transport; Fri, 2 Jun 2023 00:48:58 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT027.mail.protection.outlook.com (10.13.172.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:57 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:57 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:48:57 -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; Thu, 1 Jun 2023 19:48:56 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 441e66ef-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PT6FhhSe+0SPWpD+oZ4JGLeC5eTPAnQNRAJ+QKCbTp/C8LHo6MmOOPyJP+cSkSDvk4IkFfVU750ONdrkyMMpR3pJMQGx5pP05M3ZdAN6HXomdSqGHJaGuTdvK32IpqVy/0DUVsjQO8Mx/HBd1ZOjgRTwJkMkxv7HIfnPH+4Jct6Jr+yVLGgkVN8hY88WhbV1IQ8aDgOE9LAJoGGHsW8AkCFpmOHNTlzPTvTZ0q+P4pjVqAnjKfu1AqoGfCyG4j8koSRVGJKR5tRTZQrQJIrXSTiEpAJiFmkwMv0Y+6BfG3SyYyHu9aORlnRmUMN+a/k4wOOJWUMaon0F13SIiIqMvQ== 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=uZPtY0Lq1veAssh7dnLe/7/35DwjQ+2mSJmqdDyTing=; b=IZc/P8PKYmkZBYBtCot8IEE0Yy02aUVyg4ly4RhaIgLe3qI9s2vXx8S7AkB+5/btbmu6hhXSzLyiad16ocn9iYprRisMVbkYqUlQaAH9xYx/H8Bv1LnduoRG4FCgpxi6KB5MQS+Y5B30EBCCQP4PsTsFxtBRBNITpmmBEd4IJQz9J4DgHO8hK/9hqUBfZw8Z2pmt/rEH6Gu9WsEbkHbaVPHXeCfXCX8A8kGK2/Vc58Y6+Z/GP9NfeYMsU4/hSBNHYSG3F8l+V/cr18kofwpln5Hkip2aagHFfxGQXbzzWQbsV6fH8qI40lJ+ZCAEW7X7NkePAmymNUb/VVwIzTx+QQ== 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=uZPtY0Lq1veAssh7dnLe/7/35DwjQ+2mSJmqdDyTing=; b=egWQzMpwD0j5E+Z7jzXk2aaI9yhVGYNL9D/lFqFyhiGJo3zrjLn2clUKFQiw3/bVSAsnpy7YY7d9eU2cHA2Z5XFy3ajpDFyOmhM0f5cEUTXSdvHLvwyxczdWW6PzYj6Za/tg5vPcc0P9ycxfYzYxJSNpRJ1VTlFfyq1Z/AtIhJI= 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 v7 14/19] common/device_tree: Add rwlock for dt_host Date: Thu, 1 Jun 2023 17:48:19 -0700 Message-ID: <20230602004824.20731-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT027:EE_|IA1PR12MB8237:EE_ X-MS-Office365-Filtering-Correlation-Id: bc50556f-839f-4c2f-19bb-08db6303262f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 06MA3nPPPXxc9L1rv4PGzDhESbrLTwpWtC3d3855GTpgJI5pDuwskJJerPp1zjcg7z6/xQW1wVHqXxzWJEnDtgHmWCMu2uf+EWIgzOYYZUSJ35Dq1E8sRVaLWFGIqt4JikmuvL/M5up6zZeia2AAMvyByUj9VrHvWHsPa+CMucuLOmHbBv31voHu9Hligd3oUK5rMZoAoduLPecHSYlzDDPXLY7zPTJT2ZNbYCShdUUYBfPse0rFOATpOsCgkOsN1McLjFPqwkzZht7CeUaT6qhpY0NpIUFYOktaskB6LDLM17/cXbmG+9M9cxV2hXA3JjP/iN5ktJzeENFwTGrIar2kRBsAupVFKlshD9YHLBxXT82i0DFFgaml4g377oP/4JhZBkhHMXq6wsrx3r2ot2EAf7WO/qchIcypxgAQwBj3f8psOGv7dyHK11bOQZMLKFy30UVnQP2J8s23bcCHN5TqHWurrse1EBStB4bfx6EXX/BesFBtWEFSvq58cEKB41L3EhnXG5JejXTZ3+vuk9YgRVv5gLXFPGs+1CiiMsVPY9e4YQzFd8jwK0Q7dJu4fV+H1jirR8IVPzuJ+MMRtSls3JY0d4G9Y0WK97K0EsMp4tCyzXfLoW7sbl1NmWK++l44PMVDKuDcn6hi/q8f6V9W/TdyGTyZ4ia+Yn4N4qdmVTUUX/Jem8oljdDKdKvdk3dXzYwehdM/c3Zz22xAqtsf3TFVAnOBlE6JOOmyOnGqbP47m+e/iVQ1uolbs5l+Ef7otiRI95v7O9OHKHF0HA== 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)(396003)(346002)(136003)(39860400002)(376002)(451199021)(36840700001)(40470700004)(46966006)(44832011)(4326008)(6916009)(70586007)(70206006)(8676002)(41300700001)(316002)(54906003)(8936002)(2906002)(5660300002)(36860700001)(40460700003)(82310400005)(6666004)(478600001)(40480700001)(1076003)(356005)(26005)(36756003)(83380400001)(186003)(426003)(47076005)(336012)(81166007)(82740400003)(2616005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:57.8792 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bc50556f-839f-4c2f-19bb-08db6303262f 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: DM6NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8237 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. Reason behind adding rwlock instead of spinlock: For now, dynamic programming is the sole modifier of dt_host in Xen during run time. All other access functions like iommu_release_dt_device() are just reading the dt_host during run-time. So, there is a need to protect others from browsing the dt_host while dynamic programming is modifying it. rwlock is better suitable for this task as spinlock won't be able to differentiate between read and write access. Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang --- Changes from v6: Remove redundant "read_unlock(&dt_host->lock);" in the following case: XEN_DOMCTL_deassign_device --- xen/common/device_tree.c | 4 ++++ xen/drivers/passthrough/device_tree.c | 15 +++++++++++++++ xen/include/xen/device_tree.h | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index c5250a1644..c8fcdf8fa1 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2146,7 +2146,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 301a5bcd97..f4d9deb624 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -112,6 +112,8 @@ int iommu_release_dt_devices(struct domain *d) if ( !is_iommu_enabled(d) ) return 0; + read_lock(&dt_host->lock); + list_for_each_entry_safe(dev, _dev, &hd->dt_devices, domain_list) { rc = iommu_deassign_dt_device(d, dev); @@ -119,10 +121,14 @@ int iommu_release_dt_devices(struct domain *d) { dprintk(XENLOG_ERR, "Failed to deassign %s in domain %u\n", dt_node_full_name(dev), d->domain_id); + + read_unlock(&dt_host->lock); return rc; } } + read_unlock(&dt_host->lock); + return 0; } @@ -246,6 +252,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: @@ -295,7 +303,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 ) @@ -333,7 +344,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, break; if ( d == dom_io ) + { + read_unlock(&dt_host->lock); return -EINVAL; + } ret = iommu_deassign_dt_device(d, dev); @@ -348,5 +362,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 e239f7de26..dee40d2ea3 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 Fri Jun 2 00:48:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264617 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 5F2CFC7EE23 for ; Fri, 2 Jun 2023 00:49:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542801.847182 (Exim 4.92) (envelope-from ) id 1q4syc-00041z-3X; Fri, 02 Jun 2023 00:49:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542801.847182; Fri, 02 Jun 2023 00:49: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 1q4syb-0003xM-0d; Fri, 02 Jun 2023 00:49:09 +0000 Received: by outflank-mailman (input) for mailman id 542801; Fri, 02 Jun 2023 00:49:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syW-0000if-K3 for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:04 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20609.outbound.protection.outlook.com [2a01:111:f400:7e8d::609]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 44930436-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:49:03 +0200 (CEST) Received: from MW2PR2101CA0010.namprd21.prod.outlook.com (2603:10b6:302:1::23) by PH0PR12MB5433.namprd12.prod.outlook.com (2603:10b6:510:e1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:48:59 +0000 Received: from CO1NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::93) by MW2PR2101CA0010.outlook.office365.com (2603:10b6:302:1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.9 via Frontend Transport; Fri, 2 Jun 2023 00:48:59 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT033.mail.protection.outlook.com (10.13.174.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:48:59 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:58 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:48:58 -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; Thu, 1 Jun 2023 19:48:57 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 44930436-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L5tDJtalXFdupYiYrMBWweqUS9scpUpkFpMuYVhJcslL6NEbaxL5pqj2/u9voM3sfM4gL3dOcih9uKlbL6hHoFPw7WJXMEMGqR+uwwZoIS5IYvHqZTln7GckWG/TB8juc/daOkt9EWUf6kIUR6jOmJJwTf/FRNS0QiQksxUQoOfK21I14Yz2J1hOY/X5WVUasVF0dAVGiPrJG3Ixx1SEfOCMk6yOAVRWEWoNtukiFNlhk9YKk3Y8SLUDO32QJ3vxSKSezAc7S3G4pQ9kd9OqqjgN+PMZb/xJ1FulJcFFImYDw8VDorub0e3lhMDsVxqPPXAcQ+5NKJJsRHO10z74vw== 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=ZACCJSYeVg7JvgHrjij92Ypwo4mpte2CHes014k364Q=; b=iosJ7SXAHnjgSJb33btxlHwqyBRzGUjEI8yniwfnrbz1IR5ZWMck9CcbWR4EigCcuQALeZDcZOe362uDQJLAfv5bqmO9eDLhIizyL+EZ2FIjBKdGePDJ13SuV+mejATRFgXGf6GxA7lErfhnMvC9IDRObNWYJq2cI7eKUDPaa/j2Gwt1XP0RwXdqlbG2x9lPVr8L3hHa2L8AYAs0OgIUnmIK89ZWhLRaadBXy8540MBqKtnZcwBTJ57+gTpZAe09+bztu4Yq1zzX+UqVOis4Qu5d7AUk5urkS45nDm8NB/cRz9X6SaRlxlCBKIlZ7QvZnRusOHWLZV7R8Jg6127FdQ== 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=ZACCJSYeVg7JvgHrjij92Ypwo4mpte2CHes014k364Q=; b=5ROhODmnHeX6JV9CZLRkiff9I8EFy+PWEJPuhYvuyrofT3JfGCDXcCCkN/bkMvYt2R7J4kvMwU55PaeYOcmSg4tMI2Z1WQmjT2K6agYYyFFVamJ1DXiD+9UA7NmJEC+JBrUjjDkqA9gFifdeTd1FnGe5AXfzVrXrQ2D7GtjuCQo= 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 , Wei Liu Subject: [XEN][PATCH v7 15/19] xen/arm: Implement device tree node removal functionalities Date: Thu, 1 Jun 2023 17:48:20 -0700 Message-ID: <20230602004824.20731-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT033:EE_|PH0PR12MB5433:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e8cf8c8-b245-4d92-51d3-08db63032705 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QN5LlC3kSI0d5+U3zWOKZke362Z+VGzIyUl6YXHNnO23MOkQcOMYEeBLZCKMgAGquC5fDdXnGQj3aitoVZzLtIbiY9aRkZg9JL9a/FO4oCcZOB3N+8gP+Jd5h9eC2mK59tkt5SFaVyvTTdJxN0nJvyW1+W+vnwkmH4ANrJO1Xf4YbrBp+0etdZr1sIaMTeXq4lqedqLGAJdKrNUe+26ytJIgOIToxpucXANEpF8s/jfRfSQwSqOwc+vaDVGczLfPpobpfMXqWjrxdZw/2NPfv4A6f1do/s6o02NyQf30jAmYe14L38SekIbXa6x3KFDy4L1dKVCdfTIy0g3qyxJp8FLY6IigwnNJGnqGULWWdea3VbFXc/ByOrAWMwoy2kNQzIfMEJlxW5zAWCarOCuKcK02Df/yyclM8VFWTs8d3zFFj5ae4RJVKNg/oe7DucFCXATjXPfhhNaylR6VUY7snTO2wN55Mr3NTfJFVroBUUqCoT9woVnNo/oqzBZkMdi4SiT0gmn9dsJYeRtYqXdnfy8D0D8ofjSFvWWnWVYL+Ig2iiAaksGhqz+nkbYLXYG5Cno1L0ohBxwGtKXrkaYNhe9mfb0B3MzoqPWWxkOFeGJjNMdUgMumaa9uY5MgHKKKUCx7dauPzRez4YTZJhj6n9N1pUsy3WJPCi47D6wJfI/XsPDOKsXyCY2m1RcVvjyDCHHfLyC7CRciDe1EnvnN2uv2Kk6qI6DlNzFcVkEtk2YaPIHElWOz1DiSF11kpmceukKLn5YNO2+F5u4P7ri0YA== 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)(46966006)(36840700001)(40470700004)(40460700003)(336012)(426003)(47076005)(83380400001)(30864003)(2616005)(186003)(36860700001)(6916009)(4326008)(70206006)(70586007)(316002)(54906003)(478600001)(6666004)(8676002)(2906002)(1076003)(44832011)(5660300002)(26005)(41300700001)(8936002)(40480700001)(356005)(81166007)(36756003)(82740400003)(82310400005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:48:59.2362 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e8cf8c8-b245-4d92-51d3-08db63032705 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: CO1NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5433 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 --- Changes from v6: Add explicit padding for xen_system_dt_overlay{} Update license. Rearrange xfree in dt_sysctl() Update overlay_track struct comment with relevant message. Fix missing xen/errno.h for builds without CONFIG_OVERLAY_DTB cases. Fix header formatting. --- xen/arch/arm/sysctl.c | 16 +- xen/common/Makefile | 1 + xen/common/dt-overlay.c | 420 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 24 ++ xen/include/xen/dt-overlay.h | 59 +++++ 5 files changed, 519 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..8b813c970f 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; + + 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..b2a7e441df --- /dev/null +++ b/xen/common/dt-overlay.c @@ -0,0 +1,420 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * 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; + 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 only for prior added dtbo.\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; + + if ( op->pad[0] || op->pad[1] || op->pad[2] ) + 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); + + break; + + default: + break; + } + + xfree(overlay_fdt); + + 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..ff54607617 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1057,6 +1057,25 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#if defined(__arm__) || defined (__aarch64__) +/* + * 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. */ + uint8_t pad[3]; /* IN: Must be zero. */ +}; +#endif + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1087,6 +1106,7 @@ struct xen_sysctl { #define XEN_SYSCTL_livepatch_op 27 /* #define XEN_SYSCTL_set_parameter 28 */ #define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_dt_overlay 30 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -1117,6 +1137,10 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + +#if defined(__arm__) || defined (__aarch64__) + struct xen_sysctl_dt_overlay dt_overlay; +#endif uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/dt-overlay.h b/xen/include/xen/dt-overlay.h new file mode 100644 index 0000000000..43fa5a02a0 --- /dev/null +++ b/xen/include/xen/dt-overlay.h @@ -0,0 +1,59 @@ + /* SPDX-License-Identifier: GPL-2.0-only */ + /* + * 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_track describes information about added nodes through dtbo. + * @entry: List pointer. + * @dt_host_new: Pointer to the updated dt_host_new which is unflattened from + the 'updated fdt'. + * @fdt: Stores the fdt. + * @overlay_fdt: Stores a copy of input overlay_fdt. + * @nodes_address: Stores each overlay_node's address. + * @num_nodes: 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 +#include +static inline long dt_sysctl(struct xen_sysctl_dt_overlay *op) +{ + return -EOPNOTSUPP; +} +#endif + +#endif /* __XEN_DT_OVERLAY_H__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Fri Jun 2 00:48:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264619 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 BEE30C77B7A for ; Fri, 2 Jun 2023 00:49:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542802.847192 (Exim 4.92) (envelope-from ) id 1q4sye-0004WK-K4; Fri, 02 Jun 2023 00:49:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542802.847192; Fri, 02 Jun 2023 00:49:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syd-0004Q4-73; Fri, 02 Jun 2023 00:49:11 +0000 Received: by outflank-mailman (input) for mailman id 542802; Fri, 02 Jun 2023 00:49:06 +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 1q4syX-0000if-KF for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:05 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2062b.outbound.protection.outlook.com [2a01:111:f400:7e88::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 44b714f6-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:49:03 +0200 (CEST) Received: from DM6PR06CA0076.namprd06.prod.outlook.com (2603:10b6:5:336::9) by DS0PR12MB8815.namprd12.prod.outlook.com (2603:10b6:8:14f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:49:00 +0000 Received: from DM6NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:5:336:cafe::c9) by DM6PR06CA0076.outlook.office365.com (2603:10b6:5:336::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:49:00 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT028.mail.protection.outlook.com (10.13.173.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:49:00 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:48:59 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:48:59 -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; Thu, 1 Jun 2023 19:48:58 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 44b714f6-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LBt9/TAmfGby1GHLGSdfMnmlFxbUXILygyrDIj0wSdeTaVLu9jLRp+G3aC8vqq5TOE8Cmtc8e1kyS6nUpygVUbtQs8bDMaTR9ifH1VMZwuDBxihlKrPZtjmauAMohmCILPhin5IFAuUqmyy8J57tkmMyr/7imirS1FEBYvW7EMipERkIFblmKfb7zpRVeWM+VHSAFYTUy6tvnv/zFCCgIF2NuUatjwrTM63YOVPyeSlafzhbtSUQNmQ9Mdzm36pdQ8qS2BghnmcptOGVoCDmeuUAN+yPCPws77apGLzhKRSw3aztRsHtPcYAYJWgnsJsF0P6GWO0Tu7rUo5IbCCL1g== 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=d1CA76xInbIr4hE8UWeQAMGW5FdBn6s0KkNux42XsEg=; b=UMIKE3Xr1I8kljc6mwrFLKsZJ+yE77EPkRIyCAv/SshEmzIlXR/J7NcKCgNTIs0IefJRc2J820G3kvDwqSPECSUZh2NgqWBT92bCaXrvfMT5WFFQT4GhjBx01+lEYWyTIy8J47OD4p0Hl6oqYmFT2d/a2+G4atdevHmY8KiS6BKg+RKv/noE+MsUhCGc7ZsS5FWZG88j5uA0e0ys7gmkuDtOek/m5rwvo0DAK6hvwd0zc0RkqqD6SM7iVlf266hztWYvZgwBbCKMkXkdYA3F0Dc/au0zEPZ24lnka2wMfNocZFQieEuisOD7NDjH65HSU4U5tjTY/hjP/UIvaVSFbg== 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=d1CA76xInbIr4hE8UWeQAMGW5FdBn6s0KkNux42XsEg=; b=5YZCiXEcIcc/skE2I50ZcFa3pZBPn7CnrdRetwiyhQSK4SK5yrMBVqwAjMwA0IuoCwbyR3AIETWfD5psAGS5BKX6+MggWSGyf8hWKTi2gZBmdfxq5cm/+AJxSE9l349ualBqe4fxSijbAjL9cfSxXZYlihGmEDCuSVMF4fVAsdY= 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: , , , , Andrew Cooper , George Dunlap , Julien Grall , Wei Liu Subject: [XEN][PATCH v7 16/19] xen/arm: Implement device tree node addition functionalities Date: Thu, 1 Jun 2023 17:48:21 -0700 Message-ID: <20230602004824.20731-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT028:EE_|DS0PR12MB8815:EE_ X-MS-Office365-Filtering-Correlation-Id: 61ed6f1f-2a60-4eda-f4e0-08db63032788 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IAI3SYTR8xwIBtHmoRBc97aECGtJ0Fo+9VBEvDeJGf8O309xMa34AIKIyY7PS+X5yOvizcsSRZ6i/8E6Ap8EuFq7jG62k4duADsHRckJOItCQ6kMRt0agBOuDLcMTTVCuQ4jfkCQqT9E/G/BFyT7UvBH9IaI9EdRTPfDTx4myvtmbgsOy0LF/aw72RIrL3Lu6rYYk4R06wdgDqfKG2sB9U2DbHizwDfgsyknXPw8Ml+g9/5j6sIcgMv0NXSpkwkuAorvrsH5POnYn96IvdsRfcUa11uQTeymgE3YWqfxNUSG5CpjsYE5w1/HG7oweiH29vVcpDrsd9MfCOc04/k2HzZJQZQXhhKTuQ5HqGZqn619echqiz+6+7vlcIKGiBgxPCMGucoXb5HqPmKwkvfyW/Ecp176zjELQiwVqNcqbUtBLqKWeNaKpkSTcV5/8tBIL0yrvOpDzk3O+awwdVeeLi7HDO27abI/BkBkgO314w6u/PzMpO7/XI3KseB6QlftuUQb2gEFrdxKM9WnyN2zSUGETWuvK+TsjG/naZ843YpaFtTebxCNrIXK0FGiWAqlkDWWFgJAkMIW3pz40DssGxHHG/IwAYmV8DoNCnGw/ODXN9s2vwtxQLlQe9+dtBVMR/d7TNgMIWH6GmqQU0Zmfc/dVUZWtucgooxhhL8EiEF37Oik99qoylIIqF7YEKArCjvVb10TgsK6RxDJPTyAVXhdCzozsYmyjoYIwArsjxnbc1CV7dOi2syWCIH6gRCckOpsuAaA+PBp24maZ9MrNw== 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)(136003)(39860400002)(396003)(451199021)(36840700001)(40470700004)(46966006)(186003)(426003)(336012)(44832011)(2616005)(1076003)(5660300002)(83380400001)(26005)(8676002)(30864003)(47076005)(8936002)(2906002)(66899021)(36860700001)(40460700003)(4326008)(54906003)(40480700001)(6916009)(41300700001)(6666004)(356005)(36756003)(82310400005)(82740400003)(81166007)(316002)(478600001)(70586007)(86362001)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:49:00.1614 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 61ed6f1f-2a60-4eda-f4e0-08db63032788 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: DM6NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8815 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 --- Changes from v6: Fix comment style and add comment regarding false flag in irq mapping. Move malloc for nodes_full_path to handle_add_overlay_nodes. Move node_num define to start of overlay_get_nodes_info(). Remove "domain *d" from handle_add_irq_iommu(). Fix error handling for handle_add_irq_iommu(). Split handle_add_overlay_nodes to two functions. Create a separate function for freeing nodes_full_path. Fix xfree for dt_sysctl. --- xen/common/dt-overlay.c | 533 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 533 insertions(+) diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index b2a7e441df..12b6b010ef 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,78 @@ 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 +236,76 @@ 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) +{ + int fragment; + unsigned int node_num = 0; + + 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; + + 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; @@ -369,6 +530,373 @@ 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 dt_device_node *overlay_node) +{ + int rc; + unsigned int naddr, i, len; + struct dt_device_node *np; + + /* + * First let's handle the interrupts. + * For now, need_mapping is set to false which means it will only permit IRQ + * access to hardware_domain using irq_permit_access() but will never route + * as route_irq_to_guest() will not be called with false flag. + */ + rc = handle_device_interrupts(hardware_domain, 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 = hardware_domain, + .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(np); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + } + + return rc; +} + +static void free_nodes_full_path(int num_nodes, char **nodes_full_path) +{ + int i; + + if ( nodes_full_path != NULL ) + { + for ( i = 0; i < num_nodes && nodes_full_path[i] != NULL; + i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + return; +} + +static long add_nodes(struct overlay_track *tr, char **nodes_full_path) + +{ + int j, rc; + struct dt_device_node *overlay_node; + + 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(); + return -EFAULT; + } + + /* + * 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. */ + return rc; + } + + 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(); + return -EFAULT; + } + + rc = handle_add_irq_iommu(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; + } + + return 0; +} +/* + * 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; + 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 fdt size to accommodate overlay_fdt failed with error %d\n", + rc); + goto err; + } + + nodes_full_path = xzalloc_bytes(tr->num_nodes * sizeof(char *)); + if ( nodes_full_path == NULL ) + { + rc = -ENOMEM; + 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); + 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; + } + + rc = add_nodes(tr, nodes_full_path); + if ( rc ) + { + printk(XENLOG_ERR "Adding nodes failed. Removing the partially added nodes.\n"); + goto remove_node; + } + + INIT_LIST_HEAD(&tr->entry); + list_add_tail(&tr->entry, &overlay_tracker); + + spin_unlock(&overlay_lock); + + free_nodes_full_path(tr->num_nodes, 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); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + 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); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + xfree(tr); + + return rc; +} + long dt_sysctl(struct xen_sysctl_dt_overlay *op) { long ret; @@ -396,6 +924,11 @@ 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); + + break; + case XEN_SYSCTL_DT_OVERLAY_REMOVE: ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); From patchwork Fri Jun 2 00:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264634 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 6970BC7EE29 for ; Fri, 2 Jun 2023 00:57:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542853.847262 (Exim 4.92) (envelope-from ) id 1q4t6m-0004JR-Ss; Fri, 02 Jun 2023 00:57:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542853.847262; Fri, 02 Jun 2023 00:57:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4t6m-0004JG-PS; Fri, 02 Jun 2023 00:57:36 +0000 Received: by outflank-mailman (input) for mailman id 542853; Fri, 02 Jun 2023 00:57:35 +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 1q4syZ-00018B-8O for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:07 +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 4675de5e-00df-11ee-8611-37d641c3527e; Fri, 02 Jun 2023 02:49:05 +0200 (CEST) Received: from MW4P222CA0025.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::30) by DM4PR12MB5358.namprd12.prod.outlook.com (2603:10b6:5:39c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:49:02 +0000 Received: from CO1NAM11FT110.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::8b) by MW4P222CA0025.outlook.office365.com (2603:10b6:303:114::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:49:02 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT110.mail.protection.outlook.com (10.13.175.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:49:01 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 19:49:00 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 1 Jun 2023 17:49:00 -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; Thu, 1 Jun 2023 19:48:59 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4675de5e-00df-11ee-8611-37d641c3527e ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TauGtZi1ivIHOeFQ3l6inG9iV6k3zV2VA73TNg8zza5eqMjxBMKpz8tWk/qS+CHi+t/mM9vLOTcv7qszMss/jdEuAiU41BZwEOkd0IEFSGLfscIY+YpIGabZJoI5xfnNJCX2N3OdMrb/72m7z5ONJsd4d5/t106i/S80ueEXS7knnMEaiEdrhRQCz7YBTGWWWHmfeRvG7rsPoO+m29YISiXuhAbMJ7950kAYsdWpXRLC1Kik096HZWpdElGJ3+gdmcSEP8QitNwumWPfB7Hc+dXV/b6O4dxf+9VLyPFCjcQ7v2V4jESkUxvBzZfWLSChhClTBdp/Z0Xqe/j9q4RWGw== 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=KZGk9VcPBJGLjL1ph26BvCEzkwM9dKWSwelsy6V24KU=; b=hX+H4m41p2e34ujKPSZ+Doykr3pOBI5eJCK3C5/6z9GLoESDWwZEsGEAeO+OSu0ljqMP7C/z1eZSc17WEcQlKFR2XiCjYocyC54wV8GazCj4qUMl4oZb3KkUzTWzSWX3pgPnMcO3VwzPzupepM9aJSwGgVIeFVQSaexjPx9abHj8GYxm/D8JjCct3Mnv22oR1RVj/zjKUETxvTEwFOSlJTBKUWjAo6zgIbTfoTcuqea1NBMOFTsyAft9DNXtHvRh/Tzf6EqlZx73QfkFFaWBO7nM48mq/ZxKCWapuewCJFtFcvq7zfCyPzsyeN+CX5+7MVkfWDs3maPvs7VGFz3AXw== 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=KZGk9VcPBJGLjL1ph26BvCEzkwM9dKWSwelsy6V24KU=; b=dWPT2bYrFbENwMIvJLlkzUxMzkDFfe1dRX9sM6f2uFLctJKFhNj3Coc2cK6+OGhl5nR152wiRnShIY92V1EZsAQBDW7Arc9eDz6C4uryNwZTUNrRfDyYOAC+ylOSMbgUYwp0pyJy9rqHJ/AJ0e2yZV0mm6l3xsOfTk24nKvknmo= 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 v7 17/19] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Thu, 1 Jun 2023 17:48:22 -0700 Message-ID: <20230602004824.20731-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT110:EE_|DM4PR12MB5358:EE_ X-MS-Office365-Filtering-Correlation-Id: 90157362-c37e-483b-0007-08db63032845 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9PpV3p1v7aloBea8/vLI+nUSwJj4tWOT8cxE2OWrNSrDEnA++NiYzMzM1G0flPrEGa47ybWsz98DFhiLykZw0myxcTbOmBguo4V6NbDO6nc3WE6doXt7HP1RJNZN8fVAQ/yk80EojmVUGUpXzYXrSrWRCaqE1KOkKEsLf9f/RUbGOv4IJmQozDvzlcScJPnoGBbzx6Gj/lOPcQwjQ9x4Ez+v85TI4g56lbTxTR8Xtg1hatd/1MK+scqJS7kcuaO4MJBFgt4Zc0erDQkCaxr5GttkQTivPO0QhfjBXIMMrT8SDY0pR6mJKb19Lf+UeGkMA+w7vdgVL2SoqCTqVw73HYICNDAjoKSGzrolLCC135+J88lR7/MsQ7V0fNG7rQmsQfWxudG+2bsTVagePKCr/vdqrEv4h5ntdbUSJVKmT7FuV3pdvs+sNsuLwYU9aqp9yBYzqi+2T6bm5K99ZJrWJCXOpO5E6/4Md70TJ8nbLf6xw+XFAJ+G+x16TxTFCw/LsqcXm8wBZ9vSjNhzu8IiXdhh6aKl4PYMprhKjN4wL82h21om9hsdPgRwlq1OCbq0p6f4YRejte5yo1ONi3eSLCNrtfdEhSAr6I9kRxiidNyNIU5kQU8oWH5cY3D04YTj+iJJRP8X+J1hMLeEhUiHyS1GyuvHngT4i9xdLbs3ptZO4UGsxa9C5OZb33tVZChAu7Ouk8EGK6RsHDcLpe3Hxzk5pKb8gSW1Y7bJ+/jo1m4SnZlZo4JNzIlkFmKJQvv8xR4qShXmM66UCKVH35P9tQ== 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)(46966006)(36840700001)(81166007)(82740400003)(36756003)(356005)(86362001)(82310400005)(40460700003)(41300700001)(8676002)(8936002)(2906002)(1076003)(44832011)(5660300002)(26005)(40480700001)(186003)(2616005)(336012)(426003)(47076005)(70586007)(478600001)(70206006)(54906003)(316002)(36860700001)(4326008)(6916009)(6666004)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:49:01.3157 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90157362-c37e-483b-0007-08db63032845 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: CO1NAM11FT110.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5358 xc_dt_overlay() sends the device tree binary overlay, size of .dtbo and overlay operation type i.e. add or remove to xen. Signed-off-by: Vikram Garhwal --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index dba33d5d0f..411f7ef04b 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2626,6 +2626,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..58283b9ef6 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,51 @@ +/* + * + * Device Tree Overlay functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_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; + sysctl.u.dt_overlay.pad[0]= 0; + sysctl.u.dt_overlay.pad[1]= 0; + sysctl.u.dt_overlay.pad[2]= 0; + + 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 Fri Jun 2 00:48:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264621 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 2176DC7EE23 for ; Fri, 2 Jun 2023 00:49:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542806.847219 (Exim 4.92) (envelope-from ) id 1q4syk-0005rp-8i; Fri, 02 Jun 2023 00:49:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542806.847219; Fri, 02 Jun 2023 00:49:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syj-0005im-30; Fri, 02 Jun 2023 00:49:17 +0000 Received: by outflank-mailman (input) for mailman id 542806; Fri, 02 Jun 2023 00:49:09 +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 1q4sya-0000if-LA for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:08 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061f.outbound.protection.outlook.com [2a01:111:f400:7e89::61f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4672f294-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:49:07 +0200 (CEST) Received: from DM6PR06CA0073.namprd06.prod.outlook.com (2603:10b6:5:336::6) by DS7PR12MB6216.namprd12.prod.outlook.com (2603:10b6:8:94::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23; Fri, 2 Jun 2023 00:49:03 +0000 Received: from DM6NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:5:336:cafe::8) by DM6PR06CA0073.outlook.office365.com (2603:10b6:5:336::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:49:03 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT028.mail.protection.outlook.com (10.13.173.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:49:03 +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; Thu, 1 Jun 2023 19:49:01 -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; Thu, 1 Jun 2023 17:49:01 -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; Thu, 1 Jun 2023 19:49:00 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4672f294-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QtkySiu92kbpUP5+5t4mKoHZjPr8zWEEIAy1VXBmeRb0Wy4ypXck61NzGoCCM0Fojjgz2kifPC6u38dI0fMpfE28OXLCaRfLcd80hfUNWqqmKFM9ENdyZYYtNpgv5Gb0Eb3AUFNzcr6dNdxdakxjQggQpeLcXvKa8pwyHKl0DndWBlGrSuAtAfV601rgm54k4vpVPzYzO5OZtj4lUlDVAs0UPfMvMuUE6CbCeYMnxgOANNrQVWB+Z1qWqvNyT+aPXf6Pve4gcBtP31cqrc84tmx0JjVizhOPKu6A2giRfc8gKUzXuwm46uSADddIXg+NgS6Yc/KDQQyHnUbdvBkWkw== 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=COSto2fMoVPbrVEP8xV0305ulVdAAdS/6g5EZut49Do=; b=j2v3qN7cor5hAuiOEbLvboSVUfsDnqnqraL/G0XrqiTWV9IGRQnVmByckraNVwJrx9HBUsbMlNkMhRgQf1E1/AKZtkT+KYCRvY1N2GGhOpKfHy4a7Ufq4IZvsY+Wf+mTxbFJrBrtTsMdp0Dg3a95S0IAlkaeJjHZpWLhnlRX8T6pq3sEVZI4IOEUx6FXr5PF+1ArVqz6ftDBcS/bec3otrcwftw8nSMVU7dMAprvTdAiCv13frmnsM28gDY/aRrfNyNxkteLRqLn34U4bFX0i5LDCwuEdhWgEuLJ7q2+L+3AzHALr6RR43eqSx0dg+smfbgfEGv8jFg+b1EuMJ8uoQ== 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=COSto2fMoVPbrVEP8xV0305ulVdAAdS/6g5EZut49Do=; b=t1Xf7E+3jv0LytBWnyx+7CZCGHBOWwontdnoRTv0TWtANlyMv6Etb4jkurgQaomJjQ7z+3NKqQu/D4hoAtJ9SfemNhXgEbBxrxCHBA0lk1FBruKvqGO0HJIuBSCbKdHhSVYZPGpd/E4XRc2AM8iDid5ZUlbC6lw55qoKJMgvIjY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Wei Liu , "Anthony PERARD" , Juergen Gross Subject: [XEN][PATCH v7 18/19] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Thu, 1 Jun 2023 17:48:23 -0700 Message-ID: <20230602004824.20731-19-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT028:EE_|DS7PR12MB6216:EE_ X-MS-Office365-Filtering-Correlation-Id: d698fe06-80c2-4ea7-8868-08db6303294b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xtvCz6rMCYb/uOeBt29yv/HDcJ0NqicELGOsT3V13EoNcQAIy9JHi1+7/1RAp6kRxHIGoOT6nW8l9f0BtzrCSxQ5Eze21OeoVHV1wKecOaoTujqFRaR1/8gQXRgPMsayBlV9t1J0/WDXovM7HkbT7R90I7Vit4Te1UMRif3nfTictj9wLdAjq1RpNDcqH/1L8PAvpfTjBSnvExabByaw+j7SsN+VOf7XdXycC3f4d0EHgpyWFPJYQEtHvBUg+r9sxJCVhTa6+myzXLc+npr9QgDjZGouJPAXpEn1ZmpOEoBnS84I8dkoOHi/oCd2i6XwgTdRjrugbs5xkvVLt2r+ZGoRKJikqFGOFOMe4kMF3LD50WriSTnjKk2hZKMewHtR8EuWNadMEzCI0iLo1XYR4kYriekUhNPjy84/rj9OeUO7UY1O9YfWef5XPHfkI7dG49NYet6djoLnvNrO3nhmIHNI3c8DrJ/deQT3lB/yAbHuqiBkcVZTjsBxd2vnynt8xPxW0Q6YG9nFZ4eFZJqEMh9hKs24tHW9xrSgxTUJTLFbR/6IPdQD3taBK/OBpwuFi0Fy0xpf6YjC3Wkb47zu65fWeCAbSyOr9S67XUlNbpKHai/j/ceOH22j1hnaRyJ7WeDbRAPEC9rJ64CqiWnWFwKNrXHxYzZ982eq89ucow1OK4fc1yPaIiUp1IiFtbMTlDVDCVHgwKxK8dM3+VaWUx0eIe7QLRZyJ0H2RInPDB60TZIKT6FsjXSnruk8Fw2UkodgPptSlqqwVO/wUtd1UMh9XGcGurXsLdwCvaoJAAI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(136003)(346002)(376002)(396003)(451199021)(40470700004)(46966006)(36840700001)(41300700001)(316002)(44832011)(5660300002)(2906002)(54906003)(478600001)(70586007)(8676002)(70206006)(6916009)(4326008)(8936002)(6666004)(40460700003)(82740400003)(356005)(81166007)(40480700001)(1076003)(186003)(26005)(336012)(47076005)(426003)(36860700001)(36756003)(86362001)(82310400005)(2616005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:49:03.0987 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d698fe06-80c2-4ea7-8868-08db6303294b 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: DM6NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6216 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 5d7ff94b05..ba4c1b7933 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 Fri Jun 2 00:48:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13264620 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 A332BC7EE2E for ; Fri, 2 Jun 2023 00:49:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.542805.847210 (Exim 4.92) (envelope-from ) id 1q4syi-0005Nq-PW; Fri, 02 Jun 2023 00:49:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 542805.847210; Fri, 02 Jun 2023 00:49:16 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syh-0005Im-Dw; Fri, 02 Jun 2023 00:49:15 +0000 Received: by outflank-mailman (input) for mailman id 542805; Fri, 02 Jun 2023 00:49:07 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q4syZ-0000if-L4 for xen-devel@lists.xenproject.org; Fri, 02 Jun 2023 00:49:07 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20630.outbound.protection.outlook.com [2a01:111:f400:7ea9::630]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4647b034-00df-11ee-b231-6b7b168915f2; Fri, 02 Jun 2023 02:49:06 +0200 (CEST) Received: from MW4P222CA0008.NAMP222.PROD.OUTLOOK.COM (2603:10b6:303:114::13) by CH0PR12MB5187.namprd12.prod.outlook.com (2603:10b6:610:ba::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.22; Fri, 2 Jun 2023 00:49:03 +0000 Received: from CO1NAM11FT110.eop-nam11.prod.protection.outlook.com (2603:10b6:303:114:cafe::aa) by MW4P222CA0008.outlook.office365.com (2603:10b6:303:114::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.23 via Frontend Transport; Fri, 2 Jun 2023 00:49:03 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT110.mail.protection.outlook.com (10.13.175.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.24 via Frontend Transport; Fri, 2 Jun 2023 00:49:03 +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; Thu, 1 Jun 2023 19:49:02 -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; Thu, 1 Jun 2023 17:49:02 -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; Thu, 1 Jun 2023 19:49:01 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4647b034-00df-11ee-b231-6b7b168915f2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rp8pHoRg8ed/ajxYTfWD92SqZMZrLCBcZN3UWy+ptnHfLsDX+ICStJkKoY/yryHXNMDHBTJkJ3WmKtnn/NsT6U4wZFCq5Pg8WZGriDRMI/CWejHLmGXbr9ElkA80o5bt3aQVXe7NXLuNfdJr6NrtTs5aCLz/05yQv/v6I+/tRFDNxIn69gkoEThqmRJ+wsztuXZudgJ8fLnnKJ9jlUb7oPZow2xtJ2IZwy4JMvBcR7btU+TMviyQlAMUdhaRk0v1q/KX5h6nSJl5rfH3jbMDiHzamSyhJFdGd+y8iPMZthqVDpWwkGR82NhzoVQZhB5L1boI9mPgP/M80FiC6L4OWQ== 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=82cXKCd9pIjt4k7d+0pxA09Bfm65PUipqTwwDD6EGDA=; b=Pn2x5FXILpdvqOf2hmUNCzmraeWDHN64/T51cK0kPKh/JmWsLHo4wfwxp8ONazBlYnG9LNYm01Dj5j7AqUvRup8AW6/cC8I9jHts+OcYMmsFvzfUh2qJTScHaUgFMwWGYDXWMtwZceFnk5iR9AMdSDchFXsLpmwmtR/u1mjumWQhToKPS1NtVlodD5wtmoHWh8RmdWO5OVc8Eml/BknEQoU0SAG+6JOVcdDUP+3H+86cZTzBnP1ShBh/ZYLU0CyOSqIN+kq4rRMgmRWgka0PvAZGH4RzhtVJozQVPMvMVN7jlQeFgCzH0N7DmxK+BplBhRfMGTSWeF21t6bIDwjiGQ== 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=82cXKCd9pIjt4k7d+0pxA09Bfm65PUipqTwwDD6EGDA=; b=2jU3mT6+M6dDk79F9dnowrh5R/zXyXisroar1oIaklo5yJoPayg7i7I+5vuCqcO1b5PX5yIaJkBdyP0rNEIZyeDD27AOohgfCm7xA+k64rgkijryZHZcoQUVqC6HwIRiH1r4SQk5QkPTVbW6GkLtaFJurqEulU8xAf6JkZ7G3PA= 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 v7 19/19] tools/xl: Add new xl command overlay for device tree overlay support Date: Thu, 1 Jun 2023 17:48:24 -0700 Message-ID: <20230602004824.20731-20-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230602004824.20731-1-vikram.garhwal@amd.com> References: <20230602004824.20731-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT110:EE_|CH0PR12MB5187:EE_ X-MS-Office365-Filtering-Correlation-Id: a087ca27-b981-4a87-a051-08db6303294d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vemutuTFnXRVmPffSDPBvLSvxxFt9Ce10+r2J5sVaRJ4LgzzAfBykLUDJOyJdvWa7P5ldy21TcqJ9MTYqvDdrsyDXu638qCl8yVPifuaMmtdD5fCe/C/LMoGvC9VhiqAdq6fPLAUoiAqph2WHA7ZfRV7guLGcxoxbqA5uuFBMwfmLymK2AZEKr1tGMKtyphiB+w3LURsqyt0SvIr8GLFSoZjYWAWPniseoDdC0ySePzxeWvQq3gPmVa7ifYOtAKCvgngutohGzp+Z+RYzba0OpHtW181sb6pNQSlwuT0qFJqRXj4msRH7adENLZIgtmriYTRwJ9KlenGRTiQZNPbpLeBzxoZq1JsVV/a12BAwUr4m25basXfOA8qvWPQgWN05JV1rbh3+tkG5geZVBNSIZWpW0mwL5qN09ZrmPmE2+HRIwXAPDq+JbTFsbdmTXdACJOc6iKDHerS105eYnshgVCUMvlgFZjKdv2qVSbXtCpciPzTtlAuxUFHWAYwwloLwT2WQ4JB3ukKRsjPNcJ+kuMUpZ6aBbsUNmwx/aXcRZKpAvK2/PD72dJS+61KEUHpL16qS8dy4qHKlKRlwZPuTV3kaKGj4eIaROPdPjze/50XnznDbEuGuLOjiUgITsOFnSM4Bn6vBsWyWKqb8ziz66uEShgFzj6WesNhY8GZScon1YoiSP1gXBLWljlW/zmWUj4yfwMPpnkwGL21VoXT0MFnC5qHXJkQMaR4Swyi+YcqYc158CO5DYrZieMih9xvvRdcprWt8t9SAz2gZ1FQBg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(136003)(346002)(376002)(39860400002)(396003)(451199021)(40470700004)(46966006)(36840700001)(54906003)(8936002)(8676002)(2906002)(4326008)(6916009)(70206006)(70586007)(316002)(41300700001)(44832011)(5660300002)(478600001)(6666004)(40460700003)(82740400003)(81166007)(1076003)(40480700001)(186003)(26005)(426003)(47076005)(36860700001)(356005)(86362001)(83380400001)(336012)(2616005)(36756003)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2023 00:49:03.0499 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a087ca27-b981-4a87-a051-08db6303294d 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: CO1NAM11FT110.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5187 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