From patchwork Wed Sep 6 01:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375214 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 E50F0CCF9F5 for ; Wed, 6 Sep 2023 01:17:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595989.929700 (Exim 4.92) (envelope-from ) id 1qdh9v-0006u4-39; Wed, 06 Sep 2023 01:16:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595989.929700; Wed, 06 Sep 2023 01:16:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9u-0006tx-Uf; Wed, 06 Sep 2023 01:16:42 +0000 Received: by outflank-mailman (input) for mailman id 595989; Wed, 06 Sep 2023 01:16:42 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9u-0006tr-8F for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:42 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20620.outbound.protection.outlook.com [2a01:111:f400:fe59::620]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 082fd43b-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:41 +0200 (CEST) Received: from CY5PR15CA0125.namprd15.prod.outlook.com (2603:10b6:930:68::28) by DS7PR12MB6237.namprd12.prod.outlook.com (2603:10b6:8:97::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.28; Wed, 6 Sep 2023 01:16:36 +0000 Received: from CY4PEPF0000E9DC.namprd05.prod.outlook.com (2603:10b6:930:68:cafe::28) by CY5PR15CA0125.outlook.office365.com (2603:10b6:930:68::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:36 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DC.mail.protection.outlook.com (10.167.241.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:35 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:34 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:34 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:34 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 082fd43b-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cjkzRChznUFsL/Kb4ezMYaOVqHLLgwX8VivHXQTbxdPuksUtLcGHtpYaONAcfrNmLFAk8OIrsn7Zkan9vjH0Xj2cEKu9T0VWvnFsQWVQj+lNQjxiVT15QbaKySHyKEtSsRCZMSuqH5P62r3EkNbC2EBPOOuzRusxVHS2fv/RTpJliKFlHO6/kWSxS61b1D4xNffDRkciO/qoyzKREq8TH5BlAAU8hYhIR+zGlMVaozesk9nyTw4XFECOeO3H9SXU6lL+8NM30NCCjVRS7VC7rE6luPimKTNAurrL0Vbv84wUtOi4TDxjBxTVnL/15sL0Rb1ddliajkwl3luDkUm4GQ== 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=551FbITUy/lX+UFAVwLYLGK11TzVaHOhuLFDvzMcrP0=; b=bHnf0id+X79G0TkY80EYj9riKNuFeUQDAhuo5XE34GTtGxWD1aSTa7t5H1PiCBJ1gNsxt5ANp3OsuMFy+s8IDgsve+LtftUSSJdzB37rigHogZOPE3vYgpcD+cphMtKIMLAIf+/Ysk25aSQicBqNiTgYvM1W1s8FL5NhUOnFWZyzFufOCMthqHEArZGTEo9CnXm3FJuqOcAKhOafxyhCMaPE53jVpiopPSSA6dOEF/3+Wac4CoF5VXpFcsofctkbxzxtqW3JVlpWn1MMfQJ/P8YKWEFWJ1Rbn4+rqUhiscyfYEH66PzhfcnKSkgO3F74P7GTKggnFxDax2tkNIqa9Q== 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=551FbITUy/lX+UFAVwLYLGK11TzVaHOhuLFDvzMcrP0=; b=2mStBXeiExRDjGr89TFfTiTBbP2C3BpqTOAcHceDOw6rSPuH6Tvz0PeW74t5QkIrsEVFdNCu1PFndvCA4ZU9v0wNsHkKla97MdjhPBtfn48dfIbhIb9yxd81FcltA7ijOoeLswP/jRqaw7K5BfPGkPtZGy7saElcm/12pGnGc1g= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 01/20] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Date: Tue, 5 Sep 2023 18:16:11 -0700 Message-ID: <20230906011631.30310-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DC:EE_|DS7PR12MB6237:EE_ X-MS-Office365-Filtering-Correlation-Id: e08b7899-7037-46fd-e334-08dbae76e9e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wC/e+H7Gv3Aj63UAEApYCrfbJCTghyZDKBvaUE1PGN64/fVJr73Sl1EIQQMVdthUQ2UN/wLdllDqKNKBldarPu8NJMtF/wKZk8xW9kP4G3XlqcYdAZalMuA/WUpIAx9aWtURG4SUCXiW0wUhmz8J9uPThuZiOFszkIMO4aC6C1Tk+Gqn85NnPnaLtIg65xlq7w/WpKDOw56vJz1/qYnReZD8mGpqjVI3c5Rpiv6EWq21UWh5i+xxrWG9TZK2GfoJvdUb63zx+EPOoKpE/R3TVtmg7KgfW/viNjU5QIWBEp1eJqsMEVyfohPS+9IZbhKKzBwyWAA/pwOJj5Rsgc6jxAY6lrxBnoNQHCvlkFBUWUkRsJyNsxBq0eqcnNlz2wMo5vliE7IzOA3zTxPIQskC6N9161vMYMVmJyKBHQF7reoAyGLpe9Eq/lM4jRl4/pM7LdBk2QaX0k4nVY7//1OJZeh6xPMa2bkk8LpUFXXcJ0DVUHhYThfXd41zm1HRF2SSNe8fFHE/w4/Ru21vFclfeeZl37Uw5KQefnHx9YmncgNHerICktk/vEQE5WCwmvIBwbrB0ltH+vi998LmnXa/fEHX0bbYNB9BQpYFtd+plqTwqTxk3A11eKe0ONBKY2Z8zfLr5rcuE7V6BezKRZHzu4GiQMjuujmLb0HyMe7B9DFxJmzKb6E81dI0/bylPQyWNRf01AFwwtnZ208zBjzgowbpHuZ29frhuCKPtuORnXJNwUuqN+nuatYSS7mLdztAZGm5tSyvznHiidf7qMp6aQ== 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:(13230031)(4636009)(39860400002)(346002)(136003)(376002)(396003)(451199024)(1800799009)(186009)(82310400011)(40470700004)(36840700001)(46966006)(41300700001)(8936002)(40480700001)(83380400001)(44832011)(478600001)(6916009)(6666004)(2906002)(5660300002)(70206006)(8676002)(316002)(54906003)(4326008)(70586007)(1076003)(40460700003)(26005)(2616005)(36860700001)(336012)(426003)(356005)(36756003)(47076005)(82740400003)(81166007)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:35.5232 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e08b7899-7037-46fd-e334-08dbae76e9e1 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: CY4PEPF0000E9DC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6237 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 --- Changes from v9: Update comment regarding return value of unflatten_device_tree(). --- --- xen/common/device_tree.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 0522fdf976..7c6b41c3b4 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2091,9 +2091,11 @@ static unsigned long __init unflatten_dt_node(const void *fdt, * can be used. * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call + * + * Returns 0 on success and a negative number on error */ -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 +2116,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(0xdeadbeefU); @@ -2131,6 +2135,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 +2221,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 Wed Sep 6 01:16:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375209 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 BF3ABCCF9F6 for ; Wed, 6 Sep 2023 01:17:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595992.929726 (Exim 4.92) (envelope-from ) id 1qdh9x-0007Rv-V2; Wed, 06 Sep 2023 01:16:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595992.929726; Wed, 06 Sep 2023 01:16:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9x-0007Rd-Mf; Wed, 06 Sep 2023 01:16:45 +0000 Received: by outflank-mailman (input) for mailman id 595992; Wed, 06 Sep 2023 01:16:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9w-00079K-JO for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:44 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20622.outbound.protection.outlook.com [2a01:111:f400:7e8b::622]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 084ec877-4c53-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 03:16:40 +0200 (CEST) Received: from BL1PR13CA0247.namprd13.prod.outlook.com (2603:10b6:208:2ba::12) by DM6PR12MB4106.namprd12.prod.outlook.com (2603:10b6:5:221::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:36 +0000 Received: from BL02EPF0001A106.namprd05.prod.outlook.com (2603:10b6:208:2ba:cafe::9a) by BL1PR13CA0247.outlook.office365.com (2603:10b6:208:2ba::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:36 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A106.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:36 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:35 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:35 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:35 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 084ec877-4c53-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OLR2embtpmdoUiozsCHGJZh+jIIsbnREkrK8eI3Z5EKx8FjsfXgnbpql4XNUVb/M18mU83UXMlPa6mYSJG2CvzOlxLy6Uf1pSl73OdxJ4ViGBdhCcy48qrAHLdTSJwrdTTWGNriqcsUAIeM2oz49a6MLettbCB8f4TqFzB8coRrj7M/0yivuv1qIzDHjNX3TYVdbysLkVcP8nWd7D6ba0s4/byUXqzLCkg4mYSFFLEG4Qj/73euJHIWxgPLgYkTH4WQbz9ta3HmEauZHgOy4fAJo62oRNpAAPY0kfXooIOTLfpvbR8QsljsiSXgeAAJ1YUVk3G1GtgyS3ZC34I4yvQ== 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=cro8idbWK6/j9Apeo95KJGwjFsR6k97QUgTNDxCH+H8=; b=H6WVFilQd4o0lho5Ejcru7/2NbI2L2QGziCT0eOw7VQ5ktuz6cEG09a2YakRzIGDO8TqyZHRdWR1JWbpVk3F6u6uk9rVQX0W9taMoJhfujkOW4nhEnSWtxFhcUiazTyU7u6kfq8RrotRkRWckFc7OJ374+WbGSbia5SKXeFHMIOalhHvpyiL/obavXoxiRXij2L0RXHg3a8LMhnx0df9Xrbp4gttCMXHBurlbBX+4Ktn7CrPL+SPhASy4A/0w/63ty0w5rD8SidYkInErhu/yEf1j25c8GXgUOLWxXOcj2I6wBa2BglGAFnJqi9DZkaevYtJMO1DkJIstYIRaM6jsA== 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=cro8idbWK6/j9Apeo95KJGwjFsR6k97QUgTNDxCH+H8=; b=aJx+zwGQYyF0BkSbDrE83uUW8Wdih6afDgfCegG+gHUHA9o7ZF1PCSD538tP1XV1OsRVT8KfgDXDWbP80O6d3eAYc6M/ilZUOT32kXmxiLeBUh2tWNkQsfA2yG5Fta0zfi4/pNbB6v3nh7eHYvkYqgM42kju4UOrz4DD3rhm/kI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 02/20] common/device_tree.c: unflatten_device_tree() propagate errors Date: Tue, 5 Sep 2023 18:16:12 -0700 Message-ID: <20230906011631.30310-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A106:EE_|DM6PR12MB4106:EE_ X-MS-Office365-Filtering-Correlation-Id: 716502bd-0a27-4d3a-873a-08dbae76ea24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1K+rXODlw3AOuVPQXHJlvvD0fqz2SfwcqwmzgnNZJvtNCnBQ8HwaXUZF/yoj3qxUFHMAW4D42jJEWWx/I4ziZKMy2SbYPdyUAwl4FW+Oen+zzJ28e3Aq2ja7TRu6ZbeX/ezM6ObJxuM72wrnDUm0wHyYLxXR0GO831iJWtO92saLdhJTY0uFMaT4c70B05nIszPpp/0l21RoJCKD0paNCK4GNy4laEBZzluz8c2EMRoRZjQYa3Ei/MK8Bl8cctgyXrDK10RzulUBW5Lng4QHHGHWx9OM1imfQZHGjtELw1VAIL5sYYQF+ESLkhUTycyBkFvAkM3fyKkSWaHQ1bGuxUQsYunH2QVjYcu5E2a5jRAWxICE+kTKEyZ2U8rjNOgtHW3bxVG/xvSy1g70mVkODxpAuXHTgbFWf4hNELr1IV/BueZxG2LTePrjOXFsLgYkVDiqyQnoJmjqFxMx+Dnl7v70d+AtHSXG16Nz496rYlHXH648PgPb2FgPkbcPi9u7J2jjE9ikftMf6f5TcudKw0jEu0++H4x6lCL0bmVFjRb36+qv4naXhoUTLPM93/ic31hB/KGUSgHfDYHTKBD74S6tmvcVAROgzip1npXrmpX1hMJAgjWSGCdrGo0nxeKB5dM5gzfeX/Yg40BMw3FvcjxiUtzoMVXKBi9rOfFYuzkxI4nRZe1TTvyyEYQDETWum0Ty5k8yKhISb4WYLNVLDlXs4JzC86U/7GZTS5qCjecjuFKJmgf+3Hu85vfHHqhigyb5HgnIC3ggmp4RXg1fLw== 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:(13230031)(4636009)(376002)(39860400002)(396003)(346002)(136003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(46966006)(40470700004)(6916009)(6666004)(70586007)(54906003)(70206006)(40480700001)(316002)(41300700001)(478600001)(44832011)(1076003)(4326008)(8676002)(40460700003)(2616005)(26005)(5660300002)(36860700001)(426003)(36756003)(82740400003)(356005)(81166007)(8936002)(336012)(2906002)(86362001)(83380400001)(47076005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:36.0224 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 716502bd-0a27-4d3a-873a-08dbae76ea24 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: BL02EPF0001A106.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4106 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: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v9: Replace __be64 with void. Changes from v7: Free allocated memory in case of errors when calling unflatten_dt_node. --- --- xen/common/device_tree.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 7c6b41c3b4..b6d9f018c6 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2110,6 +2110,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); @@ -2127,11 +2130,21 @@ 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)); + xfree((void *)mem); + return -EINVAL; + } + if ( be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeefU ) - 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])); + xfree((void *)mem); + return -EINVAL; + } + *allnextp = NULL; dt_dprintk(" <- unflatten_device_tree()\n"); From patchwork Wed Sep 6 01:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375218 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 48E7ACCF9F7 for ; Wed, 6 Sep 2023 01:17:09 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595991.929719 (Exim 4.92) (envelope-from ) id 1qdh9x-0007OS-GZ; Wed, 06 Sep 2023 01:16:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595991.929719; Wed, 06 Sep 2023 01:16:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9x-0007OJ-DO; Wed, 06 Sep 2023 01:16:45 +0000 Received: by outflank-mailman (input) for mailman id 595991; Wed, 06 Sep 2023 01:16:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9v-0006tr-Tp for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:44 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20624.outbound.protection.outlook.com [2a01:111:f400:7e8a::624]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0953fbca-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:41 +0200 (CEST) Received: from CYXPR02CA0080.namprd02.prod.outlook.com (2603:10b6:930:ce::8) by MN0PR12MB6199.namprd12.prod.outlook.com (2603:10b6:208:3c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:38 +0000 Received: from CY4PEPF0000E9D8.namprd05.prod.outlook.com (2603:10b6:930:ce:cafe::e9) by CYXPR02CA0080.outlook.office365.com (2603:10b6:930:ce::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:37 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D8.mail.protection.outlook.com (10.167.241.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:37 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:36 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:36 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:35 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0953fbca-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eZK62RNbfq7YXQsP22HxaDGHeRcLmcLIcBROF1LHy/cRaoYGpXbarK5UaTuzXNeKzRHyWspWWZM5ZYja48BRORWL3fVfCLeWusRRrSL2GuQHwBAV6mhLBwrD0VAdN/OBMMTfzNc4g8J1Uq3H4TNNK77QZPo/kY3baqqBG0ZDFZM1Ho3kXE/Tw2cGsyNwA6OaXRqzzQHImDJGuQD3CJjcV89IPbp2tW0+HxQJj8b9sT8ejSvVEEVW2fdM0hp66O/L8mSazNNyU07VEk2PjxxhLqi5Ud77YG/dPYEw66TACTsNa+GoY5BBPmI2tbXIPKRx57SIxgXaQghMGmI30W62EA== 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=2+pQ3ebYYcNFbMgc60KnoBaf8TeMmZbz4zbbyGRSvFk=; b=mckzlKQLSv8lKJ4wGfjW3XLsdznjo1ieEYnQBzgQCn1M2h3oGGYFgW+bz6jKL3TtvXDkjtsFVVLBEHcC6i3R3+VGYzYrkLN8XBcbJdkKP6q6GAveLGwxBCidATTJpMHSioVZ9Iiayq1LuFn9cjN/qYfAgU7YBsSW4ajwlrSoQJZ1+GMdMSZ88jvhe2eHY/nMxnORCQuIEi6zR8dw2fowOwm8p1O1Di5YIjzl8935OFuH7++CQMSFNL+FkpOPLSaEUJzDZaZgUUz8QeZjtQu44Qx3U8RnGrLZb8JyGqbk0vy08Vw1qqOXPucV1srP1UXXi5UA5y4II7keCnOQ7J41ag== 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=2+pQ3ebYYcNFbMgc60KnoBaf8TeMmZbz4zbbyGRSvFk=; b=o+cQ04d6ExGnf9JnB0WiQxPBqxLrKoXu8tEPKADj8JNKIh79jIzn7H0FEmBQ2FEsTocp+jw5M3u1ZbD1U9ov2KAVcTMq127ytQWLUEb2NU5ZGr8ETOykuyc1YTXORSvsk6yoazsyihKQyZkf1R5Lu2SYBMf0Zj0AHXojHCmEA2o= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v12 03/20] xen/arm/device: Remove __init from function type Date: Tue, 5 Sep 2023 18:16:13 -0700 Message-ID: <20230906011631.30310-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D8:EE_|MN0PR12MB6199:EE_ X-MS-Office365-Filtering-Correlation-Id: 94a50eb7-6f75-4314-ff46-08dbae76eae7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KzSFc35eC0z2LSk2p7rVWwJctcnWs8namLfd95BVivFze1yrUHd6x2yJd1/PiFRyFnCe/0XGY3c5owtfPUx+zJ83okQxzaE0/p4Ney3nmMvPrz5I7V8N7Qczv517Q0PpI18uxKY+OYYZB+pi63fhIXEemDZ28NLRcTAEkwKWij0l/yOtnOSa4rw0u9uLWbP3S90mn2UKG2FO0nPyr+VDyfFGwVnRkDO1AA9JgLEgapq87GtVDWLsqYCmKkQukSLMw8lUv1QNVIfdgzMsTbv/K1Wf1QWZk5hVxGn2U94cjxHs+MO/fJthctUx6gcb0rjFedJArK9rVWMoiYY6lER8ZXPM8Eiv1gIfQ6iPapz1la7t6cOwCn2uFysA7bkhSW+rSmYasYHC5Z6pA38DQ6ERwWMb1BRJbsvIsKK2ha3Fe0DFSe/4Xy9q6ckTsHqLXFveKaPx4TwQ/c81hoAAcsgdS356HUBR1fhrM568NlQWrfOaCuzqOhJSBjWXu93J1bi2zcPZ/hTzhRNaebNDldoSnerCRYYYDHPvakqugvwP1+bWAm3X/j2uk9DC0uzhZAphohe2VvYCC6pZegLIQQ7182p5WTxNoRaj7h8IX06Cwc+tVfDwzwm4qFP/+X9enJr+bfSGnhxjvqlPu0tv0s1zVeUnwZu4PIHlYGjTpOvEb6UBMsCuQuYTU/9fA/wBN40eWOOk6wLVI0KupG/XazG9IpuwE5wcYq2kmoCf81JB6s5mRTVDHPDTEQCfKswk7cyS+rJNO0WLV0ia6zcejZWf7g== 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:(13230031)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(40470700004)(46966006)(2616005)(1076003)(54906003)(316002)(4326008)(8676002)(70206006)(70586007)(8936002)(6916009)(40480700001)(82740400003)(81166007)(356005)(41300700001)(426003)(336012)(83380400001)(5660300002)(26005)(44832011)(6666004)(478600001)(30864003)(2906002)(47076005)(36860700001)(40460700003)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:37.2566 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94a50eb7-6f75-4314-ff46-08dbae76eae7 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: CY4PEPF0000E9D8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6199 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() 5. handle_device() 6. map_device_children() 7. map_dt_irq_to_domain() Move map_irq_to_domain() prototype from domain_build.h to setup.h. Above changes will create an error on build as non-init function are still in domain_build.c file. So, to avoid build fails, following changes are done: 1. Move map_irq_to_domain(), handle_device_interrupts(), map_range_to_domain(), handle_device(), map_device_children() and map_dt_irq_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_interrupts(). Also, renamed handle_device_interrupts() to map_device_irqs_to_domain(). 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 Acked-by: Stefano Stabellini --- Changes from v10: Remove unnecessary rangeset variables from handle_device() declaration. Rename handle_device_interrupts() to map_device_irqs_to_domain(). Fix code styles. Changes from v9: Move handle_device(), map_device_children() and map_dt_irq_to_domain() out of domain_build.c --- --- xen/arch/arm/device.c | 294 +++++++++++++++++++++++ xen/arch/arm/domain_build.c | 295 +----------------------- xen/arch/arm/include/asm/domain_build.h | 2 - xen/arch/arm/include/asm/setup.h | 9 + xen/common/device_tree.c | 12 +- 5 files changed, 310 insertions(+), 302 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..327e4d24fb 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,298 @@ 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; +} + +/* + * map_device_irqs_to_domain retrieves the interrupts configuration from + * a device tree node and maps those interrupts to the target domain. + * + * Returns: + * < 0 error + * 0 success + */ +int map_device_irqs_to_domain(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; +} + +static int map_dt_irq_to_domain(const struct dt_device_node *dev, + const struct dt_irq *dt_irq, + void *data) +{ + struct map_range_data *mr_data = data; + struct domain *d = mr_data->d; + unsigned int irq = dt_irq->irq; + int res; + + if ( irq < NR_LOCAL_IRQS ) + { + printk(XENLOG_ERR "%s: IRQ%u is not a SPI\n", dt_node_name(dev), irq); + return -EINVAL; + } + + /* Setup the IRQ type */ + res = irq_set_spi_type(irq, dt_irq->type); + if ( res ) + { + printk(XENLOG_ERR "%s: Unable to setup IRQ%u to %pd\n", + dt_node_name(dev), irq, d); + return res; + } + + res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev)); + + return res; +} + +/* + * 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 + * the child resources available to domain 0. + */ +static int map_device_children(const struct dt_device_node *dev, + struct map_range_data *mr_data) +{ + if ( dt_device_type_is_equal(dev, "pci") ) + { + int ret; + + dt_dprintk("Mapping children of %s to guest\n", + dt_node_full_name(dev)); + + ret = dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); + if ( ret < 0 ) + return ret; + + ret = dt_for_each_range(dev, &map_range_to_domain, mr_data); + if ( ret < 0 ) + return ret; + } + + return 0; +} + +/* + * For a given device node: + * - Give permission to the guest to manage IRQ and MMIO range + * - Retrieve the IRQ configuration (i.e edge/level) from device tree + * When the device is not marked for guest passthrough: + * - Try to call iommu_add_dt_device to protect the device by an IOMMU + * - Assign the device to the guest if it's protected by an IOMMU + * - Map the IRQs and iomem regions to DOM0 + */ +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) +{ + unsigned int naddr; + unsigned int i; + int res; + paddr_t addr, size; + bool own_device = !dt_device_for_passthrough(dev); + /* + * We want to avoid mapping the MMIO in dom0 for the following cases: + * - The device is owned by dom0 (i.e. it has been flagged for + * passthrough). + * - PCI host bridges with driver in Xen. They will later be mapped by + * pci_host_bridge_mappings(). + */ + struct map_range_data mr_data = { + .d = d, + .p2mt = p2mt, + .skip_mapping = !own_device || + (is_pci_passthrough_enabled() && + (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) + }; + + naddr = dt_number_of_address(dev); + + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(dev), own_device, naddr); + + if ( own_device ) + { + dt_dprintk("Check if %s is behind the IOMMU and add it\n", + dt_node_full_name(dev)); + + res = iommu_add_dt_device(dev); + if ( res < 0 ) + { + printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(dev)); + return res; + } + + if ( dt_device_is_protected(dev) ) + { + dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); + res = iommu_assign_dt_device(d, dev); + if ( res ) + { + printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", + dt_node_full_name(dev)); + return res; + } + } + } + + res = map_device_irqs_to_domain(d, dev, own_device); + if ( res < 0 ) + return res; + + /* Give permission and map MMIOs */ + for ( i = 0; i < naddr; i++ ) + { + res = dt_device_get_paddr(dev, i, &addr, &size); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + res = map_range_to_domain(dev, addr, size, &mr_data); + if ( res ) + return res; + } + + res = map_device_children(dev, &mr_data); + 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 54bf5623c8..ff4fc30769 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2293,299 +2293,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) -{ - struct map_range_data *mr_data = data; - struct domain *d = mr_data->d; - unsigned int irq = dt_irq->irq; - int res; - - if ( irq < NR_LOCAL_IRQS ) - { - printk(XENLOG_ERR "%s: IRQ%u is not a SPI\n", dt_node_name(dev), irq); - return -EINVAL; - } - - /* Setup the IRQ type */ - res = irq_set_spi_type(irq, dt_irq->type); - if ( res ) - { - printk(XENLOG_ERR "%s: Unable to setup IRQ%u to %pd\n", - dt_node_name(dev), irq, d); - return res; - } - - res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(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 - * the child resources available to domain 0. - */ -static int __init map_device_children(const struct dt_device_node *dev, - struct map_range_data *mr_data) -{ - if ( dt_device_type_is_equal(dev, "pci") ) - { - int ret; - - dt_dprintk("Mapping children of %s to guest\n", - dt_node_full_name(dev)); - - ret = dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); - if ( ret < 0 ) - return ret; - - ret = dt_for_each_range(dev, &map_range_to_domain, mr_data); - if ( ret < 0 ) - return ret; - } - - 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 - * - Retrieve the IRQ configuration (i.e edge/level) from device tree - * When the device is not marked for guest passthrough: - * - Try to call iommu_add_dt_device to protect the device by an IOMMU - * - Assign the device to the guest if it's protected by an IOMMU - * - Map the IRQs and iomem regions to DOM0 - */ -static int __init handle_device(struct domain *d, struct dt_device_node *dev, - p2m_type_t p2mt) -{ - unsigned int naddr; - unsigned int i; - int res; - paddr_t addr, size; - bool own_device = !dt_device_for_passthrough(dev); - /* - * We want to avoid mapping the MMIO in dom0 for the following cases: - * - The device is owned by dom0 (i.e. it has been flagged for - * passthrough). - * - PCI host bridges with driver in Xen. They will later be mapped by - * pci_host_bridge_mappings(). - */ - struct map_range_data mr_data = { - .d = d, - .p2mt = p2mt, - .skip_mapping = !own_device || - (is_pci_passthrough_enabled() && - (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) - }; - - naddr = dt_number_of_address(dev); - - dt_dprintk("%s passthrough = %d naddr = %u\n", - dt_node_full_name(dev), own_device, naddr); - - if ( own_device ) - { - dt_dprintk("Check if %s is behind the IOMMU and add it\n", - dt_node_full_name(dev)); - - res = iommu_add_dt_device(dev); - if ( res < 0 ) - { - printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", - dt_node_full_name(dev)); - return res; - } - - if ( dt_device_is_protected(dev) ) - { - dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); - res = iommu_assign_dt_device(d, dev); - if ( res ) - { - printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", - dt_node_full_name(dev)); - return res; - } - } - } - - res = handle_device_interrupts(d, dev, own_device); - if ( res < 0 ) - return res; - - /* Give permission and map MMIOs */ - for ( i = 0; i < naddr; i++ ) - { - res = dt_device_get_paddr(dev, i, &addr, &size); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_range_to_domain(dev, addr, size, &mr_data); - if ( res ) - return res; - } - - res = map_device_children(dev, &mr_data); - if ( res ) - return res; - - return 0; -} - static int __init handle_node(struct domain *d, struct kernel_info *kinfo, struct dt_device_node *node, p2m_type_t p2mt) @@ -3038,7 +2745,7 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo, return -EINVAL; } - res = handle_device_interrupts(kinfo->d, node, true); + res = map_device_irqs_to_domain(kinfo->d, node, true); if ( res < 0 ) return res; 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..6cda3e4039 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -165,6 +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(struct domain *d, struct dt_device_node *dev, + p2m_type_t p2mt); + +int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, + bool need_mapping); + +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname); + int map_range_to_domain(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data); diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index b6d9f018c6..fccf98f94e 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 Wed Sep 6 01:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375210 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 B9865CCF9F2 for ; Wed, 6 Sep 2023 01:17:00 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595994.929748 (Exim 4.92) (envelope-from ) id 1qdh9z-00086L-Oz; Wed, 06 Sep 2023 01:16:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595994.929748; Wed, 06 Sep 2023 01:16:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9z-00085A-Kv; Wed, 06 Sep 2023 01:16:47 +0000 Received: by outflank-mailman (input) for mailman id 595994; Wed, 06 Sep 2023 01:16:46 +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 1qdh9x-0006tr-UF for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:45 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061e.outbound.protection.outlook.com [2a01:111:f400:fe5b::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0ab2a3b0-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:44 +0200 (CEST) Received: from BL0PR0102CA0019.prod.exchangelabs.com (2603:10b6:207:18::32) by PH7PR12MB6977.namprd12.prod.outlook.com (2603:10b6:510:1b7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Wed, 6 Sep 2023 01:16:39 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:207:18:cafe::a4) by BL0PR0102CA0019.outlook.office365.com (2603:10b6:207:18::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.30 via Frontend Transport; Wed, 6 Sep 2023 01:16:38 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:38 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:37 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:37 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:36 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0ab2a3b0-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fldq++7/Oe8Bk8QQTy24bj8wmNJnukw7JGYG3EJ4sDbp94f81UjbKy/CjBYlEpH5dMFj3XIOw2SYl3jRo3wXLYwgJpsq+lkWoF8dImRtyeib3HvB/4Y+v00Mvox6BPOTN63CGh1Pk+n2HsIkVzsBeS6JvZrU1aAGc8DDwO5IthAisQxX4eIDq9KptwCanaLFb0yOw1ZtMNYszxNCryCRBXaDVnYltp9sTrD44OvSKI8DpP+7iQYXP3MaLC36YvvBGIIZN8OJiVDdE5HUN6Pd2BDmsSse29M3lWVNMmSzbaZ2au1wldOeTYL1cl2Ofj/6b3sp2TCtDX7MQvCf7QWqAg== 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=N48gpSlC0ul9Dgr5X4IgXaGnFeuJhzDtng9Ayqa//1E=; b=hDJg47iSvsg+IRLSvQJ8i13lBe4K2A3uXfBGyCA02CG7psq8WLfeog+mmszNdzamSCz6F5zs0aPhECWFSpeTR2PpGQR5tfj5E0/4tSa2gWS7we8sJnlfJlpT6utWfBWIim3ZM1T2GE1XjbsRrE8VvqJWfUJjT4D9J/34xLRHjIqaAZ73hij7qzyJSyVCs6BYcKr9WRaok6B/XVWgYIf3vTZY2w4XIk9U7a9hfmuxwoeEitOldBRYFV0SRRFgrN7gDK1sGo7V3EcJPMItT/oOqCcPRo1YXPOnzrk6Hfp0k9q4yHcl6jbiGGdjC4wOY+dHiIpmgqsJ5Hpylg9ixpx6TA== 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=N48gpSlC0ul9Dgr5X4IgXaGnFeuJhzDtng9Ayqa//1E=; b=3Ozu8m7HW/fHwu5SlGsge3V8Uigk+jree6lfqjc3BA/ms4BZnXhDOCBztwuYufko4afLp2O1KrM4ZWkvE8BlRM7UXysnfriD/tl5Ts1L7LWvLbXqpg7tUX0jS3ogHDk0sQ+l1dWUQbwg2nW2aZJhciWC+JVM1VUQ9vvsofNQsdk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 04/20] common/device_tree: Export __unflatten_device_tree() Date: Tue, 5 Sep 2023 18:16:14 -0700 Message-ID: <20230906011631.30310-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A101:EE_|PH7PR12MB6977:EE_ X-MS-Office365-Filtering-Correlation-Id: 174c8e84-ed8e-4e23-eb6f-08dbae76eb74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /UM5K77t4AdsTCHzHs9b8dGRd0PqzZSZbYvjhNbDtWkCsuejBD3/3xKycSgHZAarTTv+pKla1Kak/6PVpDbf2ayv6MSqrVvDbhAfytf+uU0rQ+MQ9Z2O8NSWqtb6JxpfA3SQHzjyvrarKuAwlrdcjuthb5eui9aBjN0kjYKgU/jhJnOrmKuk5Rlh4+vKljaPEv/a9KXpXAryqYdc5qvdJyJBIGAL0D5YH4ui6EbCoV4fuiUX6bpvabr2SzR5ZWmVCICprhR2TgE7tjuT428WA5JBTEODck/cSml7TlEIxITke/M+koxLGzYSwoGzfaWhSWLzZfc7qG+HhJO66q/PL6gF4QO5dqIp6oXTxoYOi4nNCOSpmwpX5R+AdfRG0tIt6hSPpXbX6CNjvtmbkQnpQ9gJwEkMm62E74Vfal5gq/BgHckB8WT4MxnQE4yyFAF5MAeNxOAt+/9R9yj/bUCBwZJdY8jv11eblfvN1bVdKL41zZcN9XDAttGeYyGyVXTHRU6d0tSQ4Ksnifz0Ow7dl2r18vwkwuiTg493m8fxjwbytK6ZMl0/0ZvjZyDxsMNWN0E0JbUhVJLYvfna8dmENTwfulp+OuiJpPwtn8mjXKl+ldVwz2cE/H7d602jVBqrZW9QJpbxUBisdgwkIl0n0GsSGnESXGYjs7be6jzXRYhO8hvjV9MIZaMilcGVXJT7iZFJAnSsUYsu0uPvC3hCSOBbgWH7cyHufEItjZJF46CpK1mVYKowhwpQV90DXys3DfX1UaMKP+u4iBJV4eEBFw== 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:(13230031)(4636009)(376002)(136003)(39860400002)(396003)(346002)(451199024)(1800799009)(186009)(82310400011)(46966006)(40470700004)(36840700001)(5660300002)(41300700001)(40480700001)(8676002)(8936002)(316002)(6916009)(54906003)(44832011)(70206006)(70586007)(4326008)(2906002)(40460700003)(356005)(81166007)(83380400001)(47076005)(82740400003)(26005)(2616005)(336012)(426003)(1076003)(86362001)(36756003)(36860700001)(478600001)(6666004)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:38.2270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 174c8e84-ed8e-4e23-eb6f-08dbae76eb74 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6977 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. The changes are done to make this function useable for dynamic node programming where new device tree overlay nodes are added to fdt and further unflattend to update xen device tree during runtime. Signed-off-by: Vikram Garhwal Acked-by: Julien Grall --- Changes from v7: Update the commit with why unflatten_device_tree() is changed. Move function documentation to device_tree.h --- --- xen/common/device_tree.c | 19 +++---------------- xen/include/xen/device_tree.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index fccf98f94e..b8ef1c7ae2 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2082,20 +2082,7 @@ static unsigned long unflatten_dt_node(const void *fdt, return mem; } -/** - * __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" - * pointers of the nodes so the normal device-tree walking functions - * can be used. - * @fdt: The fdt to expand - * @mynodes: The device_node tree created by the call - * - * Returns 0 on success and a negative number on error - */ -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; @@ -2234,10 +2221,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 1d79e23b28..a518310a62 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -178,6 +178,20 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/** + * 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" + * pointers of the nodes so the normal device-tree walking functions + * can be used. + * @fdt: The fdt to expand + * @mynodes: The device_node tree created by the call + * + * Returns 0 on success and a negative number on error + */ +int unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes); + /** * IRQ translation callback * TODO: For the moment we assume that we only have ONE From patchwork Wed Sep 6 01:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375217 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 F02CECCF9F6 for ; Wed, 6 Sep 2023 01:17:07 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595993.929734 (Exim 4.92) (envelope-from ) id 1qdh9y-0007f5-KN; Wed, 06 Sep 2023 01:16:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595993.929734; Wed, 06 Sep 2023 01:16:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9y-0007c1-AL; Wed, 06 Sep 2023 01:16:46 +0000 Received: by outflank-mailman (input) for mailman id 595993; Wed, 06 Sep 2023 01:16:44 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9w-0006tr-U3 for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:44 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20611.outbound.protection.outlook.com [2a01:111:f400:7e88::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0a09f55d-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:43 +0200 (CEST) Received: from DM6PR05CA0058.namprd05.prod.outlook.com (2603:10b6:5:335::27) by DS0PR12MB6488.namprd12.prod.outlook.com (2603:10b6:8:c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:39 +0000 Received: from CY4PEPF0000E9DA.namprd05.prod.outlook.com (2603:10b6:5:335:cafe::ed) by DM6PR05CA0058.outlook.office365.com (2603:10b6:5:335::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:39 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DA.mail.protection.outlook.com (10.167.241.79) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:39 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:38 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:38 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:37 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0a09f55d-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ISgq3ucjE6nwy4Na3bB2U3gRvs9AUlL5cRXBO8XDuy3fovcT+xoAv7ootYyAZ60D5OxYRrIK4XhAwRmSqkgyJfxz9w+eEoXaYuKRC1bkNZFS+yPO/L7bh2xiPq9bEpvvt7kBmjCYL7rqgzyXkX2VAayJctjcCYK8eoNH+2t0eIKBiCyBeqGn8hyD8FKHpg65oWe3BCbSV4GiamdjkN+54ETNBaFmZlNz+OnUb4hHQrge9NiBrNSOiclh72ts0QXAyS8wtoc/5sgGWL/F6jAHWyKLJ6DULhitqHcPG8Ee+yAulnGQMIsPEUj56fT0GyHE8ZDJLx3Gora191aWxrMgKw== 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=zEyT6DqrQYXvE2hVcLijFdcrNkFKPw4yo+BSRds+BLE=; b=dsUfaodB6bQBNBKhzKeDF3bPKyZlAtYQAlOi4TOfkGmgV28E7ZhcGaiwGHSv2sbEp6+YNL43Zly9HlaMBhr37ItLx/wV+zL1DoBI8RsWOcXrr1940dPLO8u/zeXxLNGwTF97Zpy+I1FmnoGVPIyUO786FRk9rm4H5lVm2C8hGRi9dkAB2ZMcqNnNF+AMVE3ISE4uhRDjfod/TawquemCljIhUVgBbzpCVcNGoL3kh4gcGrY9XdwMsOLDb8/LcxSJjTPHbFPq7KXMVNr09yYM1LFjkK+xXzVkFFvzZEmk42D8vxeJoYO7oLAm/ls0tHS64JKYwkNe30FFZzSVzuroRA== 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=zEyT6DqrQYXvE2hVcLijFdcrNkFKPw4yo+BSRds+BLE=; b=b434QoaA5AZdoaMJckTk8xzwcuSLsVklwCYNUB+SA3ZP1Ah2jDShQdv2Y2z1b42Jb3lVYirttPXo9x85x2Ir4lgLtfd97nE5cuOo2/4YgNNjk1Wyq0HVNUa7iTy4zNT0sHdz8ZxNBmXNJdhLgWx/MW1TTkoP0NcM/VbK+L1fWi8= 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: , , , , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v12 05/20] xen/arm: Add CONFIG_OVERLAY_DTB Date: Tue, 5 Sep 2023 18:16:15 -0700 Message-ID: <20230906011631.30310-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DA:EE_|DS0PR12MB6488:EE_ X-MS-Office365-Filtering-Correlation-Id: 55283776-035f-4223-5323-08dbae76ec16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pfYRW0zossqfKJDCwYxz+uejvsObbvsQWOHhBzDiC4e62KolhKaDFolxEjiDaUBnO6uz3NR1x/tP7Zqvaw3jk0qYwjonyP4FB7d8gu/7mZQFBUNLno6CpUCAMnXAqXApG5oZu8MGWPDYgnjagDRy9qRV5DIKPnyBr622B1m6Gh+r9lD6WZ186jo6h1hQiG1jtzE1TJCMhoyHl6kOUHg3Mrtbm/o457QBroSPiluMXtO5wfUNMCNzU+QzgmhjbUHInFurzz6OiJiYKKWIt0UGG5y28EoDVUo1Bk1e5FzoFdnCU9/4Q98s/wls3WiOwxcx9lub/0Np4OkUvWgnKwTpUpGx47bg1hVdAp/uLuh3ckRlWrUB+64pOm3+kHLLhnsmT+bcjBgC/AW6KaRNOhSAyg4dY2VaMQZh9dHREEXCtUbT83aez0Euu7Y/uJNdtk4WCdDwhcx70h+9XF5vwG7gY0XrfdhlAXZ262mUkfo1FulBE2rqiVDUsGBVVlt8RwuLWLlWA6J2KknH2x8gkJjvDjpwQp2goi4+477CXYVu9a1VQWbDftqlZO5WEOfxouw1vMfdBOST/0FZZNGT6a3e9RjOOt3yWlN31Ze6z6WHmSPU+rOGgSWuW5U+Ybm6ifv0IwNeam8acebSwJZRHB6dfcm8Pt/o9XJ5OjtsmKoJ/WpcYD6TEwlbiQnilvyONh+GzQOjfS3HzeUb7/v1slhv3patVv0+fOHTIzQf4C6lVMLgttjl46ZzSdfgIc9ip6kta8lrxEAgS3H5Z086MzVk3g== 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:(13230031)(4636009)(346002)(376002)(39860400002)(396003)(136003)(451199024)(1800799009)(186009)(82310400011)(40470700004)(36840700001)(46966006)(26005)(5660300002)(44832011)(54906003)(70586007)(316002)(6916009)(70206006)(41300700001)(40480700001)(82740400003)(81166007)(356005)(1076003)(6666004)(4326008)(8936002)(8676002)(2616005)(426003)(478600001)(83380400001)(7416002)(336012)(2906002)(47076005)(40460700003)(36860700001)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:39.2223 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55283776-035f-4223-5323-08dbae76ec16 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: CY4PEPF0000E9DA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6488 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 Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v9: Fix style. Changes from v7: Add this feature as "experimental support" in CHANGELOG.md --- --- 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 2516526589..24636b8eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - On Arm, add suport for Firmware Framework for Arm A-profile (FF-A) Mediator (Tech Preview) - Add Intel Hardware P-States (HWP) cpufreq driver. + - On Arm, experimental support for dynamic addition/removal of Xen device tree + nodes using a device tree overlay binary (.dtbo). ### Removed - On x86, the "pku" command line option has been removed. It has never diff --git a/SUPPORT.md b/SUPPORT.md index 6ce0ec29b0..3461f5cf2f 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -855,6 +855,12 @@ xen/arch/arm/tee/ffa.c for limitations. 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 57bd1d01d7..650aca99ac 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -92,6 +92,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 Wed Sep 6 01:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375207 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 4BC6ECCF9E9 for ; Wed, 6 Sep 2023 01:16:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595996.929762 (Exim 4.92) (envelope-from ) id 1qdhA1-0008MB-06; Wed, 06 Sep 2023 01:16:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595996.929762; Wed, 06 Sep 2023 01:16:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA0-0008JC-La; Wed, 06 Sep 2023 01:16:48 +0000 Received: by outflank-mailman (input) for mailman id 595996; Wed, 06 Sep 2023 01:16:47 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdh9y-00079K-Vb for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:46 +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 0aecb4fa-4c53-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 03:16:45 +0200 (CEST) Received: from BL0PR0102CA0035.prod.exchangelabs.com (2603:10b6:207:18::48) by LV2PR12MB6015.namprd12.prod.outlook.com (2603:10b6:408:14f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:39 +0000 Received: from BL02EPF0001A101.namprd05.prod.outlook.com (2603:10b6:207:18:cafe::61) by BL0PR0102CA0035.outlook.office365.com (2603:10b6:207:18::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.32 via Frontend Transport; Wed, 6 Sep 2023 01:16:39 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A101.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:39 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:39 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:39 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:38 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0aecb4fa-4c53-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gYfPCUou6Me5bAHdo0fdbji6sGCqTVaXWC+WNm4mk8YggFzkQ6c9P0AlGbmM5o2bVM+eQwDjTPlHJmhUtGsubDT9Mv5+fhQ/w41PnrnSrQImxouAP4JBmcVim50ABA4Zuq+kgapIrn3YZmNHeC/SjBkh8uFBfvCfpFbSs5QgXqvYznDgejRF6l/6ZWFNU4r9CvFX5l2OnaiC6uimgtrYzAAdLeK7iuvwAVMTlxXFSouqrDevHFQePm61hejtdIs2kQyf9rAGUNjs/buPlk21u4Vg7kInFAkReG667VRD4Awv/HTCugCWxCkvhJWSfYQ2F8RpX+A3PxUwoE9I151QxQ== 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=Owyo5CSr9/6ZX2Z+joewg8Saxrid9UartnNb0urqnEuQ+09XTVzXGwxxR0LrTgvcwIeZfRmDaXFq4vIVJfLfODlp0skuC457XNnYr+PuzzCtNoWGI0uttMKwJSfD0I/8jea7aLpk1QU3jaeYGrpvEyF3pBgr6bLLtaJDjhjLUUrav+twp9GXX7PN9U8F/lmUgOKsNXC+lIX2ksemqbeip9pTc073U1VhfA5LG5WWXrVUE+xjUMe283NQhIVP7n8mqF5G5RVc9ig1xjZfxqYhg6ayUOy6QjtcYBaKAxgkO57PfxGwv7+hVIBTGZcQuQWEtdW05L7+NATbnIyEEwHXww== 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=S4mSZ7BAbOHs0azHtNS8K3t3ynHo2A1O/Osx61WsSS7LJGmmpPGncXMb8xMq3f3jW01ZY7Gsyi2L94sJDDKxtYSg+iJn1wS+ob9T9tpqDBA2MYsB+c+kypsvBqMRD1aDemdtPt/lMl2VfbJWmoZDfGwx3T5QWZ8vxuAcw3Pcuws= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 06/20] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Tue, 5 Sep 2023 18:16:16 -0700 Message-ID: <20230906011631.30310-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A101:EE_|LV2PR12MB6015:EE_ X-MS-Office365-Filtering-Correlation-Id: 966adf19-d251-4134-e266-08dbae76ec4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J9JVl4o4VWjcHtLoBQny51ZptNiZDs0vz3P3veBdganJRFCOHSfBR13ObDkwulEW4sS6X2VT9lOJR+OanQIVi0HyN9yeQKV/RQKu4gc4y0UMOJStrUnaYRbSzfOXUvoFTGMjfnjQbeOBlV0y38kvQhvTQbz9TYi3iFgjNL3aARCEGQ2JW3AQ07pOoYirRUEdydNq57QWj/8FOeeawYlEbQ514yEGM2289VTEdJwd5TsppHcYnY0g7Vu5obuxwTCzYryfi4XpF6DwaW0wBzH0ZmyiSKIgL5MWeWjJletFj4on5O3jXZg/Xn6eHWpLvM9YLapP1AU/J2z3Q57VDkgz7cOwhGSdD/sgU1fz/RcTS9oO99+PMVnD52HpVlxuNggeh9+AHZh5ezSUCqhgk9PQEdkHFqiYvQSumXlyRigDW4lSdKDoSTUMpV2O1KY4hMSX4CNB4vKImDUwlqajps+J0dFUr/d5fKjwypdMnguTO2gyWSezGpHcfhvwygyAYXVGLyrI1lqNtGE9Esr+ijjak5ik8w/qDTRB/+TNgI92coa6Xx+W35K5xn9fPaPE9p8ototkwOsP+S69eMCllXsIh0yocF7YkSblmxG1OjPZ8oYTtk6g7OcjWF7iHMrnzHRki1bbujIPIwVxzO2UZUN/fXWxL2E3HqqqmKq9NQUludNtrRuflNzzmkeTIHq+NC5idc7GB3BTjbtkHr2e4WrLklUoFUBQ3BQUU3fD7kaIXfWpeRolVKMaJ33NkPqn8E29f8t6VfTYQ6p0MlyUnREP/w== 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:(13230031)(4636009)(136003)(346002)(396003)(39860400002)(376002)(186009)(1800799009)(82310400011)(451199024)(46966006)(36840700001)(40470700004)(36860700001)(6666004)(40460700003)(44832011)(5660300002)(83380400001)(86362001)(1076003)(2616005)(426003)(336012)(2906002)(4744005)(47076005)(36756003)(26005)(40480700001)(356005)(82740400003)(316002)(41300700001)(70206006)(6916009)(54906003)(81166007)(8936002)(8676002)(70586007)(4326008)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:39.6489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 966adf19-d251-4134-e266-08dbae76ec4d 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: BL02EPF0001A101.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB6015 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 Wed Sep 6 01:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375220 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 80AA3CCF9F2 for ; Wed, 6 Sep 2023 01:17:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596001.929807 (Exim 4.92) (envelope-from ) id 1qdhA6-0001Ph-Mz; Wed, 06 Sep 2023 01:16:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596001.929807; Wed, 06 Sep 2023 01:16: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 1qdhA6-0001MT-Dg; Wed, 06 Sep 2023 01:16:54 +0000 Received: by outflank-mailman (input) for mailman id 596001; Wed, 06 Sep 2023 01:16:52 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA3-00079K-TF for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:51 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061d.outbound.protection.outlook.com [2a01:111:f400:7e8a::61d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0da21748-4c53-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 03:16:49 +0200 (CEST) Received: from DM6PR02CA0046.namprd02.prod.outlook.com (2603:10b6:5:177::23) by CH0PR12MB8580.namprd12.prod.outlook.com (2603:10b6:610:192::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Wed, 6 Sep 2023 01:16:41 +0000 Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2603:10b6:5:177:cafe::fc) by DM6PR02CA0046.outlook.office365.com (2603:10b6:5:177::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:41 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:40 +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.2507.27; Tue, 5 Sep 2023 20:16:40 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 18:16:39 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:39 -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: 0da21748-4c53-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F1eCggap940r3PjRkSvnfz0QJhFg8LUifFyWCbFNN1gV1nL8CbUq8ihRAJjoWGZyU5nHYurQbavX/MEC+YY+CbtVn3qNMuaKUwJKQNiGw8ADsIYhfVqxMrTN3g22TmsNI3ffiGaIjjyUkPvlCHc+8zvdR2sEpaySOJS0dK3ClCP7A62TdAYJ/1NlhS/iPy9DI6RQI40WnU11qbepxj5Tr/HJYMWkv6rp6Pp7hXEqIYxjdP01jZand/K120tPQwlUWQ3ZPh0e0SW3H0U1OPVew2RccF6QcBdw+hk6JDJOrLXDpIj+8tLylswimqUwfSLG7u/sGMtWZYp8Dm9aPhTHHg== 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=653u6xWPNriUED+G4weH7ZKsZbL2O1CzT4XNOpC6uN4=; b=hIdkQwz/vWZLb8REj8ZgK31pJlOCQXNBIIO0mzDnm/ywrt7NhZsmqZmPEDQQhvVex67Rlk8cXsPpvKTdg+78Ku7uXvUTcqJBh16IMPtvFWLZnRUPknZm+gq4ItZiUgCMazmH2miyYYY30NNjWcM3voVlBsXvuZXopTZXtN9FPSQdPzEGnJw1jDs4gipmYb3vViTSwEUhExM6VxDKmOzgs00bsxQM3MY5iRWYBOoWQjehIJHFi/9cPJ1dttKgf+ttfnQfftxIuvLRxzZaglatrJU1yzbs6lxg6eilWMSLt33oQtLlOiMeXdq03TmvASakAnZt1bQMV6P+DebBWqaeCQ== 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=653u6xWPNriUED+G4weH7ZKsZbL2O1CzT4XNOpC6uN4=; b=C7zsaAVDELHUanqZlKqck1kQYvI8frMhnSouQ808KExjIUqFWf3JHqrsy22fZssAExYmagSL3VJ/dlNDTw00zumeEV2PvHvtq4EZ6T53MosGfGUNAEM/QttazpvYcER5OwhV9jpBn6/Q8ya/8LBPf7xBaBPx2o62sIX7jOmRvOs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , "David Gibson" Subject: [XEN][PATCH v12 07/20] libfdt: overlay: change overlay_get_target() Date: Tue, 5 Sep 2023 18:16:17 -0700 Message-ID: <20230906011631.30310-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|CH0PR12MB8580:EE_ X-MS-Office365-Filtering-Correlation-Id: cf8bc73d-abf6-4521-0439-08dbae76ed13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ddskFYipucxe6RKqCM9alvr+E1ETLk0WMdE9yPF2xaa1u/Os4oSV22P8PACsIrpi84WNdE71HBT4pzXJg0y9HJsaAZHEtCRd+jkBljUC+IgWxyoXW1u3xT2qL3XTrycs+cGAJPzh1f2+rirnO/AJPjJncVqnBlas6FredmrGfKycpoUlZqrQ0HTwxcA6F0zUd9ud2TKCP9huvz10Dc63+vSI6kNB2XlY5u4duyzDZ0JH4wHIQbIYcCuxMTXx2lY4D5Mms13mbPb9zojSf/dt7jGYvFLrLV1jdEWLcFqVXplQZ3n6WAFOnNy+zAgIEZAo3wrQiVmleasAcOqOpRzIAjFyTrMA4cPBpwMryj/P06G4An04C+vhOe5u+hXbGRGQbTo30PyUsSeRM6ULEsP56KBu6n2dOjSkTuShHAKks+xYciwSeqT4H6RqTsNKod+vWLFvJkt8DPOlTn0nxLoRCI3vkfzP27lBXW9JCdtMBOKlIOIOOGpxFmWDoKgmvB1+WmmaMdAY5xoZshbl9FDDf1dDSjbcdeowSBAxK/b2SyQECZ8/D/rmB29AbWRnUqYCM+fpER0etcuAL3vKa15+jiGNlqrHm1TBIp+sBTaNZsTPTyxSAwQnYkBpX+uJwKRbCIhssh2GpTI2FcI/BzawDRRVZN2fuRqpUCC/azPdnMvq4SOhPMn8D/GJG5NravcMNL8RBT1Su1unWAoicMMrq4w6dRhEuyA4Dsiqos72V+TbducK4JEZyloh8Qj2ZJijWBtBt+yUP7brmcwSE0ikAw== 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:(13230031)(4636009)(376002)(396003)(39860400002)(346002)(136003)(451199024)(186009)(82310400011)(1800799009)(40470700004)(36840700001)(46966006)(81166007)(356005)(82740400003)(6666004)(40460700003)(36860700001)(86362001)(40480700001)(36756003)(47076005)(1076003)(2616005)(2906002)(426003)(336012)(26005)(83380400001)(478600001)(70206006)(316002)(70586007)(8936002)(8676002)(5660300002)(4326008)(6916009)(44832011)(41300700001)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:40.8783 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf8bc73d-abf6-4521-0439-08dbae76ed13 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: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8580 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 Wed Sep 6 01:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375208 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 E9D84CCF9F3 for ; Wed, 6 Sep 2023 01:16:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595998.929781 (Exim 4.92) (envelope-from ) id 1qdhA3-0000W3-2p; Wed, 06 Sep 2023 01:16:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595998.929781; Wed, 06 Sep 2023 01:16:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA2-0000Ub-N1; Wed, 06 Sep 2023 01:16:50 +0000 Received: by outflank-mailman (input) for mailman id 595998; Wed, 06 Sep 2023 01:16:49 +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 1qdhA1-0006tr-74 for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:49 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060b.outbound.protection.outlook.com [2a01:111:f400:7e89::60b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0c76908c-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:48 +0200 (CEST) Received: from DM6PR02CA0047.namprd02.prod.outlook.com (2603:10b6:5:177::24) by PH8PR12MB7326.namprd12.prod.outlook.com (2603:10b6:510:216::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Wed, 6 Sep 2023 01:16:42 +0000 Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2603:10b6:5:177::4) by DM6PR02CA0047.outlook.office365.com (2603:10b6:5:177::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:41 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:41 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:40 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:40 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:40 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0c76908c-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bma/VP8gAET5qymQzVqSBwBwPI2pCwhUDxs/W0zwksb/wIfp7NaBkIStIFkDT013HKHTkjOuXq6Z5bgcj+duTqgdDsTwxw1YryEEMIoV68BK2xaW58vGgZfuREVpj9TdmddXctkuoWQSo1n3nY/KO7Fw+waTtuI/awzuNYWtmdiZrtnN6/ujGPk+IchToQGE35e2rNBxbC/gZ1aQPiVfjp5UG7rQSu54VoOYblk3rqaZzjwhvU8xQ4HLhkIiK0kXDzIghcP+72lBRzW+CETAG9DpQFW3a87gPbFbGW8IVlcdkbIxjX2MCXgsuFL5RWBSqjWQPmigglYqg911VYA0nw== 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=JIgawtLTJDYclMTRziV6+ukrPXqF+ozH3iEpHoQmI6c=; b=dzTsvZc9PcP6ZIbBY8Oou2Y4Wdr1Nm5Nhmt6klWU0E50DCTbYcUn5RdrndOOY524q16g6NeJNZccW5RBypV4ZEk2WxWNdfYsFx15geAmgkAWQfbj9PdXziFl7lwVvqxEOeanTWWEWOjvpIGhJZSFNpWmx+1YOrm0EkXO+J78NM6OYYF8RPRdGdEztVJHoPJEHfjMmjpJkaSbm59qoAofGy/GoE0+FKDAhJXFtGj1L9x1bms4srnyOmzu9YD+YdyD6cg6KEIZULlxlK1Mr2KBXqdDbNd6+6Mt6CeRSVQOQBi4EoGiGRbcgoBviOgmQK+hs7RJyQPlTiyXgxrtB65uCw== 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=JIgawtLTJDYclMTRziV6+ukrPXqF+ozH3iEpHoQmI6c=; b=xVPaTsQNoxjMoIYYP2l1jzMsJqXVymBNeiUHKtqIMm4h3TTiTy0VvrnrbfvwLAw/dj7Q9vMaJ+rSWrXS0Fzy+CE8OtlIJl+de2lPxpzQk1OB8jZYF4Jx/UKKVXbD0d9xOHuLn2ZZZlzIdVEgHiEMZRDfOYIY/M4F94374alq/Ks= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 08/20] xen/device-tree: Add dt_find_node_by_path_from() to find nodes in device tree Date: Tue, 5 Sep 2023 18:16:18 -0700 Message-ID: <20230906011631.30310-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|PH8PR12MB7326:EE_ X-MS-Office365-Filtering-Correlation-Id: 34fcf7f5-4b5c-4d16-eae0-08dbae76ed9a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V3Os/i7+i9psodDWzfHA4FGaduAWPW6D5+NjZ+AYzqZGdvPaG0XTP0cwbvUGywYLTUMFpsTcj6jdLdIrfyhjJluhDelyNnxKZAngnMnDokD+0A4SsWqLI7cQMOjUWS0KEX+PA1Cq9YL9hxACusGAX3C30UtrpEijAPrW2flZpOicQ6plTwspSPKrGyOfmQeTXzH9IwoK+f/Hpku9vPif+2IqG9HVBGZ6i5hNKyLyG0XoyrMEqUVGrJHPdbERMFPsJiwJ4/xUzSrx2TaTjOVeyOyBCnbmRvaq37IjuIIWhy1E20I2356yHIJgYQ/X0h/r3WonNE64fvWehQKkEXaPk0aLl9OjcLGkc0b2MWkup6DMCoEulyXcLddBCAL7hkkO0c0rjq8cdqXQMqhAbrBfaEnNxqLRntDlXMZoKWyKUdDZOWKXwif6N9NUNc5V/XIsHOaYsLhqMAnYJeP7RnSCPBFhvFjhqDhbtBExDZOneEJxhPs/N6Hzr36gE/qG2HWEb0cDl+I/GLJDCwxxdovmLH4AdTB/k/6KORHqOoI4Pvn+mhUWYupUgauxrSyrL8vDfWpfpyainD1P0lASDL+GRCSjqZqgxM2n74PYB464XeupmF6F7XjTHwQZaexT/VKpkrfA4VJD+HnZLmFwgy9osuMYlIUevMGflcERHt2oGT8RH38k/aTlJXb8r38RXl7LWxUVmLNHN6GEkhOfP28RkcxFQtbeFVoEWqo55m0fD9RACFJZUac7PjnagBo+NfKm/1Xk5boXjeieO0xaSeQOmJnHo8t+SrIT2+rcrKhjxQ8= 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:(13230031)(4636009)(39860400002)(136003)(376002)(346002)(396003)(451199024)(82310400011)(186009)(1800799009)(40470700004)(46966006)(36840700001)(478600001)(6666004)(316002)(6916009)(8676002)(2616005)(4326008)(8936002)(44832011)(26005)(5660300002)(41300700001)(336012)(426003)(2906002)(83380400001)(36860700001)(1076003)(47076005)(356005)(82740400003)(81166007)(36756003)(54906003)(70586007)(70206006)(86362001)(40460700003)(40480700001)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:41.7690 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34fcf7f5-4b5c-4d16-eae0-08dbae76ed9a 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: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7326 Add dt_find_node_by_path_from() 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: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Fix commit message with right function name. Changes from v9: Fix indentation issues. Changes from v7: Rename device_tree_find_node_by_path() to dt_find_node_by_path_from(). Fix indentation. --- --- xen/common/device_tree.c | 5 +++-- xen/include/xen/device_tree.h | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index b8ef1c7ae2..f38f51ec0b 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -358,11 +358,12 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, return np; } -struct dt_device_node *dt_find_node_by_path(const char *path) +struct dt_device_node *dt_find_node_by_path_from(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 a518310a62..44d315c8ba 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -570,13 +570,26 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, struct dt_device_node *dt_find_node_by_alias(const char *alias); /** - * dt_find_node_by_path - Find a node matching a full DT path + * dt_find_node_by_path_from - 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 *dt_find_node_by_path_from(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 dt_find_node_by_path_from(dt_host, path); +} /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the From patchwork Wed Sep 6 01:16: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: 13375216 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 0F3DFCCF9F3 for ; Wed, 6 Sep 2023 01:17:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595995.929755 (Exim 4.92) (envelope-from ) id 1qdhA0-0008HM-HP; Wed, 06 Sep 2023 01:16:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595995.929755; Wed, 06 Sep 2023 01:16:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA0-0008Fa-9f; Wed, 06 Sep 2023 01:16:48 +0000 Received: by outflank-mailman (input) for mailman id 595995; Wed, 06 Sep 2023 01:16:47 +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 1qdh9y-0006tr-UU for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:46 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2060a.outbound.protection.outlook.com [2a01:111:f400:7e8a::60a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0b4ed898-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:46 +0200 (CEST) Received: from MN2PR19CA0030.namprd19.prod.outlook.com (2603:10b6:208:178::43) by MW4PR12MB7312.namprd12.prod.outlook.com (2603:10b6:303:21a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:43 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::8c) by MN2PR19CA0030.outlook.office365.com (2603:10b6:208:178::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33 via Frontend Transport; Wed, 6 Sep 2023 01:16:42 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:41 +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.2507.27; Tue, 5 Sep 2023 20:16:41 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 18:16:41 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:40 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0b4ed898-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PqCLErCrKH3HAn/mkGie6vzVVS+mAZA8E27XmjeCvxNdEuWR+UbucMNz9AXJeIwpti+QIIhGpHH9LeHCZsh3+QPnE9J0kgO/9xWzBZPbOa4wcmtQKJ2TEWcI2TpbrjRdxYDnDH3O8ILgeGtbB9WUGEy59UveIqSe3uJ2mPXSe+zOFz/3A098jIWcuy0oOjHlvJMQ/jcw+4Ph5hIo5MqHEgR0Bo3VsNM07SVGI9boDGRGfHS6OgVQPlc+MvxQG+xQZkyYFXEzHrzjv7pT3PUtbbUr/0K/85tfWuePo3uO9eM9R2AmfSx/CjHSmWLYUDDUlw1iaoC5GKBYquH5lXaesQ== 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=6x0JurAquc6KiyXO0EZH+9rHRs3E5f2UzTo4cnlYiAw=; b=NvlREKPyw5e9WZCwTDCbZhekBIEGuWqza8lNIl1Nnk3Unjcw2TU7/R5zrDG29wSkV3N8ZPByOLXxuuCnLoDMOhRZ5SdHI9iA/3Yb410FNsGsgKHb8JCvhp9bYwWqN17BWuBfoEFKs9PILOWFQuKvcGNhCSOx+yzC+/S8+4gIet+UtadLjrZyq8AzHaKYrsCdLXJ+u+Q1++9ukJ538huEFPGy80tX9OdhuzTfhY4OzTq8q84UjPLomvd0K3Gv1fajifTA5ro05Nwhz8RlKbiALQBib0Ghg7V3lGRxe0WXGqSspr3WMs31JtFB/YrZ3TDObGGhFc/AoVycNpQfNUI15w== 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=6x0JurAquc6KiyXO0EZH+9rHRs3E5f2UzTo4cnlYiAw=; b=pJkf2FBJCEVGMHUFYIRrzJs1GeoENxcA9SpTHNBBhLK0IChal3RgyH8FdbgG1l2GFiUIdrKl5gwW3fpCBl9C/yfgFBAEh8/a/9MlEB2QJfxNbcZizUOpl2vuGBjUYt9fogS/pPJBY7fhCTFUSoMgJMEja+UHIbKESh+8SgW1gKk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Tue, 5 Sep 2023 18:16:19 -0700 Message-ID: <20230906011631.30310-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|MW4PR12MB7312:EE_ X-MS-Office365-Filtering-Correlation-Id: 081765bc-8498-4c87-6047-08dbae76edb0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rHIVzBjxG2ppYS7SqA+2Z5CIVzg4UnsD316X5fE3naZLfheza85XgEwzT/QODQWXUBRfyyKAiTK7BmxZWN7AQQsCeRcG6p06zjI/8OeMGqtk8xaoDkwPLTAm0E/IEHDle1peO83TN0pYVJzX4cU0daNORuzLwF4CXU2EziFlGimsbP/exfqhST62d8Cx23aEbdFKhAo322Cl9vVySaH9NxBQo8O3VvqejF+4QLbG9TF+dlUn3Mo2DJbRJl2zI2yv+4dzg2m4t+jWa2DB/YW0JjFomMP/LJ94r+zgVX4qjfofCyNwFOYm2kqI0qf5gsSPyxhEXVuEtnTQtjWVepHLQhIy68QOaNzC+NhNDy2fm+vLQAyIDXwX9JML3XcpqHvBzb5p3BJtoZ7W4Jp3aj/Fvn6gMqAonpXZBX+7+ZPdrR9pjKJzoLoxdcubEVHxmnRYlonGjd+73NTckuZ0hhbFU+Co0mPvuQRMM6BVxc6sCRV/+8VUKVLG9Mz2aSO9wzRIK00gmF8cmJ44U5JhATlrA2xi9J/9zBr8oK9yI+AWIKXeVlCc/C8uhY5iRE4xwl/0cT71orBJRdymkcs1xtJgI6P+wE4Il+hm1AILnvFnjH05TxPX7Kimb6WeXRQHxOntdGt3c0H7Q5rJD8YuTC9JPELdwyeBLB9hTHhk38eI//DHFa/rWE4/ZdvM9lsxkXT2snyxJzo3O6Uu5YbvprCNjWq0JGshL8SyAc4s3300lajpeoHqWSEs1FiaqC2s3+/o+j0L07MCWNs2otCs8lxhqw== 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:(13230031)(4636009)(39860400002)(136003)(396003)(346002)(376002)(82310400011)(1800799009)(451199024)(186009)(40470700004)(46966006)(36840700001)(8936002)(5660300002)(2906002)(6916009)(316002)(36756003)(54906003)(70586007)(70206006)(8676002)(44832011)(4326008)(41300700001)(36860700001)(1076003)(40460700003)(40480700001)(426003)(47076005)(6666004)(336012)(82740400003)(81166007)(26005)(356005)(478600001)(83380400001)(2616005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:41.9721 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 081765bc-8498-4c87-6047-08dbae76edb0 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7312 Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_locked(). Moving spin_lock to caller was done to prevent the concurrent access to iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Follow-up patches in this series introduces node add/remove feature. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Move spin_lock before iommu_dt_device_is_assigned_locked() call. Rebase the patch with latest Xen. Changes from v9: Make iommu_dt_device_is_assigned_locked() static and delete header. Move dtdevs_lock before iommu_dt_device_is_assigned_locked(). Changes from v7: Update commit message. Add ASSERT(). --- --- xen/drivers/passthrough/device_tree.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 3c0322c797..a7d86a20a0 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -83,16 +83,16 @@ fail: return rc; } -static bool iommu_dt_device_is_assigned(const struct dt_device_node *dev) +static bool iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev) { bool assigned = false; + ASSERT(spin_is_locked(&dtdevs_lock)); + if ( !dt_device_is_protected(dev) ) return 0; - spin_lock(&dtdevs_lock); assigned = !list_empty(&dev->domain_list); - spin_unlock(&dtdevs_lock); return assigned; } @@ -225,12 +225,16 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, if ( domctl->cmd == XEN_DOMCTL_test_assign_device ) { - if ( iommu_dt_device_is_assigned(dev) ) + spin_lock(&dtdevs_lock); + + 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; } From patchwork Wed Sep 6 01:16: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: 13375215 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 2D54ECCF9E9 for ; Wed, 6 Sep 2023 01:17:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595997.929775 (Exim 4.92) (envelope-from ) id 1qdhA2-0000OY-CJ; Wed, 06 Sep 2023 01:16:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595997.929775; Wed, 06 Sep 2023 01:16:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA2-0000NX-4Z; Wed, 06 Sep 2023 01:16:50 +0000 Received: by outflank-mailman (input) for mailman id 595997; Wed, 06 Sep 2023 01:16:48 +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 1qdhA0-0006tr-8D for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:48 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20611.outbound.protection.outlook.com [2a01:111:f400:7e8a::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0ccc862b-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:47 +0200 (CEST) Received: from MN2PR19CA0019.namprd19.prod.outlook.com (2603:10b6:208:178::32) by BL3PR12MB9052.namprd12.prod.outlook.com (2603:10b6:208:3bb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.32; Wed, 6 Sep 2023 01:16:45 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::c1) by MN2PR19CA0019.outlook.office365.com (2603:10b6:208:178::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:45 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:42 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:41 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0ccc862b-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBg1DDNhP8qXdAIAGp4WVRdfKNF/Vhc1E2Ef4e/v7RtotSiVJn6SCq6luUbAwTXNYukBzUTzieXkoTcgpGI4sZYaY2K/zNmrHKJVxOd1oNu7otn+udHaOeTptmdZtGJVLfSy8W2RIYSpfaI7OJwHcsMtAbWXdgq/mZkP7z1E6jVYiEqDzZYNgTG9k0uAjjn1s9tHNXf4I6UTMq8A8zAXJWWbecjUm/IJrJy4RRjy0Rn60LvRS1Thwz6xMkgEFoDLCG3GaMcVHUtixKYWZdZUebtPL9mfsIle/d+mhalC+I1hT8PwyAI7wcsgOhBPHtS6vpF8b3OkAm8t+TDWt62NTg== 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=FrgEsWcwxI+fxIg7Dz5RugaxhcdPFLlME4+MrASnUSw=; b=AT2m9zaG7bjnMwOj/ZSaCea/fUOtdSk/P8DL9tZ1/S4CrtblrjG6RqPaP1VPQi5XZO2+WkDGxe+e4OYC3y0IhLQjnN3VLNkB6x9Q49i2O+ugqmHzr6YntFBLS7FNK+JNr6yOs/AiWE1Jkh+uhyqeAcNzbTLlMQtsJx3Tk6sxzzyEo8Ci0yyV7wB6Br2wGi+y5F9v8EnQ134k5G3oCuwful5C0rM9U6KM3WIdQfBRtYlGtIGQQb7G9yFK1N8AElW76UqzBCiBuWLb1oO74OD7VI20sh/4Fm/nKIl1tQeqFvTGjS21NilSq5uoDOfFnBRMmxI/CPYUC7t7v429jWWO7w== 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=FrgEsWcwxI+fxIg7Dz5RugaxhcdPFLlME4+MrASnUSw=; b=VcCRaChZJ1TFoLFO2pa8VsdCc5MqBjoaKV7gnUWjvc/v1Y979diX+XohwpyTJKF5nPF9/dxhcuCfazh6Y/8tnejj1SSqt+w6y8ossDYfpWYzD0oZvTBWHzixAD5jG17I24iLSjeJ/hZKM6PcFuzcnArUVBBWmg6DNMZr0vpP4GA= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 10/20] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Tue, 5 Sep 2023 18:16:20 -0700 Message-ID: <20230906011631.30310-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|BL3PR12MB9052:EE_ X-MS-Office365-Filtering-Correlation-Id: b10a6c5c-a22b-4109-c291-08dbae76ef96 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5VxtcJgTRbn5Qmw74uvCbkM7DCwaEVZuMfNOCGcCKsJfPfxnC5O353Cs8sArJNuUACmnMaCKulPJqurjKOdnNt6VUCtZFVqMjU9LsN7575y/pONWSg1gv8CcCrnV7KuBJuVTVeRnZr/5VfwMpyEaSYO3jNeVG2CYxXtZho2ZzuSfJNucHZAJNYFgGwyIyrOm/lzFxcgJzFoGVtkOjKx2KHRGTzgq8282dy4C4YVHCqrl5+DNPyYo2lIILSeD3BRG1Jj+kcqsoMAgWQuZZ/HCePaCw5E91My6lEyeYUwpQGh+7njxFk4f4dYdGwu3uZtB0ZPA5e4dvFbmBPRJ6rGYJkJTR+oBqcDC3wlUkRVA/KztdTTNgB5sC0f32+TiBgkz2tIQQYFuKn65K7a8aGDaGHoCFp4dTs3/THkcwjFNxZiN5+01gtHFiQt06HFA0rkUhTZ5SR05XldtHhwtGlKAjhNrWHeWVAzFHoZcgtVdfL9wptMYKLN9KZf3uJ57N6pVSRC+0OsSJ+VFtGm1JfKA/YYokp6YlZhZCoxTpZr0dZkIqULXtp4XQ5RetF2CeAmQPfqzsQ4xHYVncD+Dyy7P/udHkQacR/FBpNQvbqdFEgw2D2kGpoO7K9FWP7aFRSCLRM7DmG4tC8Sk3JFRU8WnNRvtm5D/3no6IUkQV22A37pVGL6bNYSiRv/2T4FYCUKxhAmQZ2L2DhCtBiRyy13EhOo89BwN3bvoDqdzm9Aaj994zSpRK2aA+/pI+n2dsHoimHkt+MDi7FdO7jVirYy7hg== 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:(13230031)(4636009)(136003)(39860400002)(396003)(346002)(376002)(186009)(1800799009)(82310400011)(451199024)(40470700004)(36840700001)(46966006)(8676002)(8936002)(5660300002)(6916009)(316002)(2906002)(54906003)(36756003)(70206006)(70586007)(44832011)(4326008)(36860700001)(41300700001)(40460700003)(426003)(1076003)(26005)(40480700001)(47076005)(336012)(82740400003)(6666004)(81166007)(356005)(478600001)(83380400001)(2616005)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:45.1597 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b10a6c5c-a22b-4109-c291-08dbae76ef96 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB9052 Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access to add/remove/assign/deassign. With addition of dynamic programming feature(follow-up patches in this series), this function can be concurrently accessed by dynamic node add/remove using device tree overlays. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v7: Update commit message and fix indent. --- --- 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 a7d86a20a0..687c61e7da 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -147,6 +147,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. @@ -159,7 +161,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; @@ -190,6 +195,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); + fail: + spin_unlock(&dtdevs_lock); return rc; } From patchwork Wed Sep 6 01:16: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: 13375219 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 2DE0ECCF9E9 for ; Wed, 6 Sep 2023 01:17:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.595999.929799 (Exim 4.92) (envelope-from ) id 1qdhA5-0001EV-MW; Wed, 06 Sep 2023 01:16:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 595999.929799; Wed, 06 Sep 2023 01:16:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA5-0001Dh-ID; Wed, 06 Sep 2023 01:16:53 +0000 Received: by outflank-mailman (input) for mailman id 595999; Wed, 06 Sep 2023 01:16:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA3-0006tr-5n for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:51 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20601.outbound.protection.outlook.com [2a01:111:f400:7ea9::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0dd521f1-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:50 +0200 (CEST) Received: from MN2PR19CA0023.namprd19.prod.outlook.com (2603:10b6:208:178::36) by PH7PR12MB8121.namprd12.prod.outlook.com (2603:10b6:510:2b5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Wed, 6 Sep 2023 01:16:46 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::58) by MN2PR19CA0023.outlook.office365.com (2603:10b6:208:178::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33 via Frontend Transport; Wed, 6 Sep 2023 01:16:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:45 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:43 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:42 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0dd521f1-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=labp9xYICQHkakEdDLSrjb9llPcSUyeYrLqGh3XOgUj24Fu8VStNtoCrMWUSd8in373Qggb9m9MnzsWbGHALkuo1VYMZrK0wgdyVhCDdVFKujdx1j8lKQa6333+/vqdATbFA3fB46Es3jtim5Bf6vPe+noZektzTz+1CyKl4OdKREj6ECjrpUFGaUqY5spP8moxAOtx0FL9hRUvLsZccIqEC0fv9f7yVDgtRpKU40u4VhOE0prLj+MMcGY/iKKMwGlCYnjTG2ydX9EXadevxiMAeTJ623b66TD+FLaoA4S1QsHiGvweyZGd14aqtxY62Iba6B7vIScZqxYXkv8VWQw== 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=XiT/RwOVy6mwEmWSqI/dWGYlfQVkf5SstjJbmGxz3sM=; b=Ow9jDr2XLZ3vRVhvHAAgOq0q13pOVMt8Sl8ZLGiy3rcJh0RwdT4bP8NQgB40t/9VJdr4DblLoLs3FtiFSDGys7IM2DOzX1UwWVYIAl+xn1bnUIgO99QffFldnE/8rOE1wSHPeCSuZNmQ4g9wFPEThMEelfJMTIbvpCpnjSjEtkcu3Q/iUto1L48KeBS/RLKtXNXK5ntYnNOnrqZEEoW/ws2UMGUvnw2v4LPiK2K+VH5KQr9W0W71R3K96ZCwR2rBGjRrFKVAX7UqZy6AcQyOPX+5yN6jB0df5ZcldcLK6XVpP56gXMu2HvrR/leLNmnNR/yRxz+PCDztYmryXUYQjA== 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=XiT/RwOVy6mwEmWSqI/dWGYlfQVkf5SstjJbmGxz3sM=; b=3Cjhf2owuTWkYxyH0N4ZHKbk1BEh3GCFYnmYX+aczJD1gxGOPh3wHghLYUZPdb3bMFk7sXsa1sbK9hrwa6GyYZWxlqMPlOjrC7MRVUME2X+j0APt8ukqrZZqVSdUlGNfvTQgPjphvnqo9fIWaHvSQHr4naVUWk7zklmlijVwv1Y= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Jan Beulich , Paul Durrant , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [XEN][PATCH v12 11/20] xen/iommu: Introduce iommu_remove_dt_device() Date: Tue, 5 Sep 2023 18:16:21 -0700 Message-ID: <20230906011631.30310-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|PH7PR12MB8121:EE_ X-MS-Office365-Filtering-Correlation-Id: b2edb5c1-aebf-4288-36a3-08dbae76efcb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v3/TOB9lhW9kXRBUR6VdN6SE76ShL9TKb8yIAvY9517DHLbWSLjdyLxjNwyzlwrFCtywYdYUMzZz0pITl/jRk+P7SB3JeM1+SC8Kq8aRaetTqrdWBHWaKDGxtHIhhbt/PliPzVImMPDEGiNCbhAj85r2zsZLGZcg3u6mp3sAhO8ZHomXNu4W8FGyamzHg0VuDatvkGUpRodrztRPAc1CE2mvgjVxRH8j8M03+alFOADIjPqorlux//frxdlYB2Cbf1A75duTJaP5atsETjc8YswGgB7SL/MUNNdM/nm34I7ALIXNE/1By/kADYdawW1OGj1nJwtEQifBS4mYRsIOmH28F91WUBUsNTQqLb20DyOzBTi9U1nHIEY+OyPYYgpM9uxkCdldj24+o4b0JvKABWS6gOlw4IPawGs+KW1UcbVj62OTJLsIzA4aXtGcSyYjpp/8SUMYd7JElsMwRRsc/qXUub0nB3rNk1fBPFq+tzO1q+SNCju293snDMYGOBXQh0z4sIx34OGa5sGez2XXM0Zrt6vOUErdXvWTUTUsO0uam4SRKXA9cK7OvLnZwkCWI3bNpFALN9/WHIdEVTfTAdj2mRmqYo+1/VoG2HCOi3R72LoP6MB9Zx4buygL8CftCSgBQxOzBImgZlZZfOPZzlke5G6Y9qzkD/AdohudVxvdcIeHTm/YWSyLiqhXbzK8YMyR3uV0LPDu4pOxBTwio7RsikRMshurTbwSbe00WbGZXats8+seLHMXLJzmPWSvY0yfNHb7aYQ9ezUVloB8Rg== 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:(13230031)(4636009)(396003)(136003)(346002)(39860400002)(376002)(82310400011)(451199024)(186009)(1800799009)(46966006)(40470700004)(36840700001)(44832011)(8936002)(356005)(6666004)(81166007)(83380400001)(54906003)(2906002)(40480700001)(36756003)(47076005)(82740400003)(86362001)(40460700003)(26005)(478600001)(2616005)(36860700001)(426003)(70586007)(1076003)(41300700001)(4326008)(5660300002)(70206006)(6916009)(316002)(336012)(8676002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:45.5034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2edb5c1-aebf-4288-36a3-08dbae76efcb 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8121 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: Stefano Stabellini Acked-by: Jan Beulich --- Changes from v10: Add comment regarding return values of iommu_remove_dt_device(). Add ASSERT to check if is_protected is removed or not. Changes from v7: Add check if IOMMU is enabled. Fix indentation of fail. --- --- xen/drivers/passthrough/device_tree.c | 43 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 10 +++++++ 2 files changed, 53 insertions(+) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 687c61e7da..80f6efc606 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -127,6 +127,49 @@ 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 ( !iommu_enabled ) + return 1; + + if ( !ops ) + return -EOPNOTSUPP; + + spin_lock(&dtdevs_lock); + + if ( iommu_dt_device_is_assigned_locked(np) ) + { + rc = -EBUSY; + goto fail; + } + + if ( !ops->remove_device ) + { + rc = -EOPNOTSUPP; + goto fail; + } + + /* + * De-register the device from the IOMMU driver. + * The driver is responsible for removing is_protected flag. + */ + rc = ops->remove_device(0, dev); + + if ( !rc ) + { + ASSERT(!dt_device_is_protected(np)); + 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 a18b68e247..0e747b0bbc 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -235,6 +235,16 @@ int iommu_add_dt_device(struct dt_device_node *np); int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl); +/* + * Helper to remove master device from the IOMMU. + * + * Return values: + * 0 : device is de-registered from IOMMU. + * <0 : error while removing the device from IOMMU. + * >0 : IOMMU is not enabled/present. + */ +int iommu_remove_dt_device(struct dt_device_node *np); + #endif /* HAS_DEVICE_TREE */ struct page_info; From patchwork Wed Sep 6 01:16: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: 13375226 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 B27B0CCF9FC for ; Wed, 6 Sep 2023 01:28:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596109.929879 (Exim 4.92) (envelope-from ) id 1qdhLS-0003OD-No; Wed, 06 Sep 2023 01:28:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596109.929879; Wed, 06 Sep 2023 01:28:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhLS-0003O6-Ko; Wed, 06 Sep 2023 01:28:38 +0000 Received: by outflank-mailman (input) for mailman id 596109; Wed, 06 Sep 2023 01:28:37 +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 1qdhA4-0006tr-5s for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:52 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061b.outbound.protection.outlook.com [2a01:111:f400:7e89::61b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0dedf5bb-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:51 +0200 (CEST) Received: from MN2PR19CA0007.namprd19.prod.outlook.com (2603:10b6:208:178::20) by BL1PR12MB5031.namprd12.prod.outlook.com (2603:10b6:208:31a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Wed, 6 Sep 2023 01:16:46 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::35) by MN2PR19CA0007.outlook.office365.com (2603:10b6:208:178::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:46 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:46 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:43 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16:43 -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: 0dedf5bb-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MTS5niPUpI3bBgY1brrkFz1jq7XueygLFpQStz/ob76cPRWBr4zwC0nBZBxD6D1bcnD1G8Fpp4l+UFiI1NkDeek9khatGgmWbbZtbyDZhRKTmZ1u89/YYtS3VaRROHSXrTNjCiEOTqIt0Nt4I1eake+4fDOPnSUZETZ32k+ozVaLCco6mfP36I6q5o8hgjYOokJzlrGAxY7Qf7w5tciwMBzJEDB+N59LBgU84+tH9GlfNcz6RIVt2tpS27T04xTgbMGdKMCpJeyimbcHXiuTwIOWI0/5pdkkuOO7QMhW1SeFDHL9N8Bnl0yP6Ymd6QVyw9i+93lVH8WzSNdmq10Jew== 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=1SW4wKXQYKIhPbVrs0COOCkOCwqWA0YoU6tRZStnLaY=; b=K8xgQEPwiBp28p44BBLFce4Gmu555Noe+My3/9s/md9FUenqQWBKIx0m2E8Hz5MOEDnCnX4gceVMg7aToZpfFR3auaKvwsZzOVWyDzPY29c8eQA2jOo8W0WkaryI4cfYP4aJK7snLfls5HBm6sm7NGpV7UHRpEdt392n2j1Nba6hK3Z74fkxz6RUKKQ1ORoj6KKvjfqibIHCZseX8rZ6PZCeiTo3BpYy5VNfFLIf5tOhb7YlKKqqYykb+cQfzWY2MkVBsNBL6nrujEliYhGOGBNl/+HDXtj/M2L9ImUjz21mr45pZksmgqwh+9Iqbd8L+eP2hCavEq7Z6l+JVVJukA== 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=1SW4wKXQYKIhPbVrs0COOCkOCwqWA0YoU6tRZStnLaY=; b=2lgEjYy7zmTz1+PT5azLMf6CcCJibpCQ0JYd+cvG/s3tLtEZQ5KZ1KlT69WSRPSt71Lvsc3kL2aImBbsSKVhiTHXMKL1XnPvJxnuAaZ9eFs5dD4ldmZXZZ19VgXV1KiJ5wObHh9/h3uKIUXXzdSxA5+ZljqoHegOqBLKEovnt7s= 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: , , , , Rahul Singh , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v12 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Tue, 5 Sep 2023 18:16:22 -0700 Message-ID: <20230906011631.30310-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|BL1PR12MB5031:EE_ X-MS-Office365-Filtering-Correlation-Id: 180f8bdd-565d-401a-a82a-08dbae76f03d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4WPy7IofN+szBGIbDlPd+HYyenDo108xNcupNYuj0V7v+J8Wtqsg0DzvNEdBbxNgAVQxQf1JsWR/793BpxWa++7DS09X+qw6i4bIMa2jhPJ/Ymg9bQEs8doLOdMvttVCmALXliiCjNBVSJ+KeNqL/8dS38pUBQnefWAP2ETflWeDCp43obdnPO1Yw3kCge0qaHiRB1a6rFeoTF5ugWBUjmnEZI+KWwYaBBRO3FfL4CXHbWJQuNEmVHRZ4JqdkkS2CiGRfEj/0S30KJtEpQSk5LZOnodKFVF+tv44lFSHLCPUwrvNL+nESdgBZbtXsc6EBO5BVYP9rPEtWFic0m3AEhWD2yXHitlYkp707cj0rdB1jINs7pnknGkWwGodH7cKoztzWMkdNj1u/zS4a1FxzScTsBieWUK/Mhhm5w+OJ/fLC/2aJ8FkniGYTc1EZlat8KX1ao1lk6ORO8o1SV6OdJbH2okZHfi/ucr2v3I2zCkMemgXf8rSJFGFfx6hbZrp+xZjMtRyNd0HsdzVbwRsYAh4cn2iiwvQyw1molBu/FxZ2xc0f51MUMc2h6yTFRCV2X4WiO7Nh/swN2WnvTTSwy9Rh5XmyqXllcLEGWH5DZLmzNdTxQ6Q/KdQm4htydVEEnitc7tnJy5rgd6eW1IQ6TmUG/QWD/KYxgqkgZ7djhuwYcQhljTWmIWTQjasYlllXWoNNf6pSLpqJRnU8xbbZPEbFGIjyczslAJcYcl8O82uoS4OhRYFkOl3yuWJDNg1NQSKb9D+FKGl8IZtBfQJ9w== 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:(13230031)(4636009)(39860400002)(376002)(346002)(136003)(396003)(451199024)(1800799009)(186009)(82310400011)(46966006)(36840700001)(40470700004)(82740400003)(81166007)(356005)(6666004)(36756003)(40460700003)(86362001)(36860700001)(40480700001)(47076005)(2616005)(1076003)(2906002)(26005)(426003)(336012)(83380400001)(478600001)(70206006)(316002)(70586007)(8936002)(8676002)(5660300002)(4326008)(44832011)(6916009)(41300700001)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:46.2534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 180f8bdd-565d-401a-a82a-08dbae76f03d 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5031 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 Acked-by: Stefano Stabellini --- Changes from v9: Remove iommu_dt_device_is_assigned_locked(). Add comment regarding caller holding the locks to protect concurrent access. Changes from v7: Added comments on arm_smmu_dt_remove_device_generic(). --- --- xen/drivers/passthrough/arm/smmu.c | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index c37fa9af13..71799064f8 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -815,6 +815,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 +865,32 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, return insert_smmu_master(smmu, master); } +static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu, + struct device *dev) +{ + struct arm_smmu_master *master; + struct device_node *dev_node = dev_get_dev_node(dev); + int ret; + + master = find_smmu_master(smmu, dev_node); + if (master == NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret = remove_smmu_master(smmu, master); + if (ret) + return ret; + + /* Protected by dt_host_lock and dtdevs_lock as caller holds these locks. */ + 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 +914,26 @@ static int register_smmu_master(struct arm_smmu_device *smmu, fwspec); } +/* + * The driver which supports generic IOMMU DT bindings must have this + * callback implemented. + */ +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 +2918,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arch_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, + .remove_device = arm_smmu_dt_remove_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .assign_device = arm_smmu_assign_dev, From patchwork Wed Sep 6 01:16: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: 13375212 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 A5DD5CCF9E9 for ; Wed, 6 Sep 2023 01:17:05 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596000.929804 (Exim 4.92) (envelope-from ) id 1qdhA6-0001Io-9f; Wed, 06 Sep 2023 01:16:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596000.929804; Wed, 06 Sep 2023 01:16: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 1qdhA6-0001Hk-0L; Wed, 06 Sep 2023 01:16:54 +0000 Received: by outflank-mailman (input) for mailman id 596000; Wed, 06 Sep 2023 01:16:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA3-0006tr-Cz for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:51 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2061c.outbound.protection.outlook.com [2a01:111:f400:fe5a::61c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0dce3f77-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:50 +0200 (CEST) Received: from MN2PR19CA0018.namprd19.prod.outlook.com (2603:10b6:208:178::31) by SA3PR12MB8801.namprd12.prod.outlook.com (2603:10b6:806:312::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:47 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::c1) by MN2PR19CA0018.outlook.office365.com (2603:10b6:208:178::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:46 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:46 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:44 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 0dce3f77-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iSHKIwGspQXOTfuBnwXgt81U/y1Xkxln/KC8SFmYaH4dCLeiFYCcFdeCnf1BmTJojs35qQVbhNQKCbNHauV6d53JOU21H1pYzWZBTUMritldT8tm3ttvCnlHLw3DkGIs4+khj5u8LckugZ1W4wN1pIiMtuyem/ziVUMKQ2yCwB6hnLHmO2/cEwhaO4GxuKb4JJSsMQpjBCCotYjxxzJnqBcOmcMWFsCeFAcF+/e02XdDh+de2/bYvCzO+p71uwF7F7vJe9Rv5HCBv68GMGZQ/qg5MmiHIjIYKfgSytl/T2AUf8EQydkJITAr+G3A9qI78FaKqpBQda2JByO1GWRB2A== 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=TDhW7f5w3p+/XHERjQf4wWurMSkKNLV2sxdzRwRCMQk=; b=AlkowZMcvEXae2WRO3RPyZ4+byRyjMFoBsVfrwBwyLW2l2qG8ORKOfc6vhXagnIwG9K8cZgGl9UNdHtoQGLeOqP3rW0dAygvianAFFEft7CHlCHFq8Jpz3XxOGtTuEtHhRHsAXLQ9ErVFpS1iKHcZK0Ojh/fHS5fH7RTbJSAcqCQMmqbhZpz9PO2d33FSLFA1GY1XwNOjF0Gw7fpilqk8l1B8ltXnGeOqkb4ZM/EPoBzZNzuqSfVtq0SOPOXnyYg/nbNGFDDGp21JHkz2pdBkQt6+NGABsmjHDGbFA7plBal1ggUBviONbsQfX/oQS42hScX02FrWRRm6o1GEOGEkA== 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=TDhW7f5w3p+/XHERjQf4wWurMSkKNLV2sxdzRwRCMQk=; b=FHJIDGMQivtrOJNQf3EoTY2yIBr3+/TuJaEoTMdXC7kbjX/HVXxt89iTWs5k6Xn7m3iiOrqEtBcLCptmIiJKINpjysQOi4pRWmxYYPVhwveJZWFIQSkHkMh7AsLRzyWbTw2niAlJ2NXN0J6khnOLVNwCVS9+04hfn3zR6SIG/Dc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v12 13/20] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Tue, 5 Sep 2023 18:16:23 -0700 Message-ID: <20230906011631.30310-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|SA3PR12MB8801:EE_ X-MS-Office365-Filtering-Correlation-Id: 13a7f2e9-d0b7-43ad-575a-08dbae76f06d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eAw1lGrWNbpFKg2anXnZHunWRlUJNLm3O9vtyZNJaSZT6kXSasoYY12uh9IC9wNQ7xg9giNCc5OzHBaP6pz6ZyX81B9Mxqb1dd4ZUSjKB+bVj+/Kg33Awoi5yhVNWWvamhrOM3pJS34LSYHGCCN0cwR0Xl5GVlJQOuCsS9FdfGIJmKeGfnXk8mxEKTCFAf7nLcXwKmf56ppLUqjVtnip1M83m37OWM4M2ePe0SDgqLPq7WjqPmUOyQUMKwUnbGieOaRA0nf/BImSPLPa8tD/3oNaB69Cl7+5h0BdrggY3FHw+W0BhzIXnqawBe2ODk2M8PrywqddPE/l6WTkmKGDYAc0/LZLDwZeoNnF5yaIxUglLIzRk+7Ouda9RKjnbIZpgj+fP7PGrzXnk4a3GR1k7Rb1/1Y/1d00lPkbckdZWqUdKvJXefW01h1S+AOxsU0oD7NRE3xyNDP7i9Hv4EJUbuWsaoGOGtdl4x3GttAl4HbE+YC8oQw38XxOFoJFftwPdy0ebd64ItemPm3i5lN51xQZmcry9i3puibLTgT+jz98MY1nYDkSbyoD+thuNCPhkiiL3m5HVhImHkXeh7jS0I5wTSht3ZN0sKV813qvGrCNSLzdAgTjEHAVtu3H4LvsIZ3WrOHMi5OphpnTO7qVuQDxrWnMLBIpm74u8vTIuQ1pKAKr7n+35pHYLV4imbQRQW5smD7E9AOSzYEX2sHt6soEloESAofutylDMCG9QOv9uXksIUVUb4+CeO4azihiRYVpqJsjgOnFzdlszVVd2Q== 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:(13230031)(4636009)(346002)(376002)(136003)(396003)(39860400002)(451199024)(1800799009)(82310400011)(186009)(46966006)(36840700001)(40470700004)(8676002)(4326008)(426003)(26005)(44832011)(336012)(40480700001)(6666004)(8936002)(36860700001)(47076005)(83380400001)(2616005)(5660300002)(1076003)(40460700003)(41300700001)(54906003)(70586007)(70206006)(6916009)(316002)(86362001)(478600001)(356005)(82740400003)(36756003)(2906002)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:46.5660 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 13a7f2e9-d0b7-43ad-575a-08dbae76f06d 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB8801 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, we will need to add a rwlock to protect access to the dt_host. However, 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 Acked-by: Julien Grall --- Changes from v7: Move struct dt_device_node declaration just above arch_cpu_init(). --- --- xen/arch/arm/include/asm/smp.h | 4 +++- xen/arch/arm/smpboot.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index a37ca55bff..4fabdf5310 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -3,7 +3,6 @@ #ifndef __ASSEMBLY__ #include -#include #include #endif @@ -23,6 +22,9 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); extern void noreturn stop_cpu(void); extern int arch_smp_init(void); + +struct dt_device_node; + extern int arch_cpu_init(int cpu, struct dt_device_node *dn); extern int arch_cpu_up(int cpu); extern void arch_cpu_up_finish(void); 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 Wed Sep 6 01:16: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: 13375213 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 8AD30CCF9F2 for ; Wed, 6 Sep 2023 01:17:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596002.929816 (Exim 4.92) (envelope-from ) id 1qdhA7-0001dq-Tk; Wed, 06 Sep 2023 01:16:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596002.929816; Wed, 06 Sep 2023 01:16:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA7-0001bR-F5; Wed, 06 Sep 2023 01:16:55 +0000 Received: by outflank-mailman (input) for mailman id 596002; Wed, 06 Sep 2023 01:16:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA5-00079K-2y for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:53 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20614.outbound.protection.outlook.com [2a01:111:f400:7e88::614]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0eeae674-4c53-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 03:16:51 +0200 (CEST) Received: from MN2PR19CA0007.namprd19.prod.outlook.com (2603:10b6:208:178::20) by DS0PR12MB6534.namprd12.prod.outlook.com (2603:10b6:8:c1::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:48 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::5e) by MN2PR19CA0007.outlook.office365.com (2603:10b6:208:178::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:47 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:47 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:45 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 0eeae674-4c53-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jjq62g6wiENr6dvlbk1lgsrMkn3idpyQylg2gaWbMrlsFmt9uaqOv0d+oNJpG3BfyGKVL62GotCHpuMshPW/iaWZ8zFIc3UGgHhc0sXmBoFI6CG+zl+N1W2BKURoG6eTc5lnGvu1eYal7sMAnW41uJ5ccSuMYdIP9FFGm/YP/T3mLkSGnxliMQBWCDhcimTdwGXuzHIyAZsHs6MEdEFV5apLdORcOUdstayZyJu5OnWzxM0ojUG2EosyigXGOJ6dvH7lDFBwycJKWEe7uHJgFy6o9htaz57TU18wgLUMqGFiCAQgOc2AgD1DpTYEg6uFnmytZTB6D2gQeXHwjOYaug== 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=QUEVYKXF5gyGWM9LJIJFFbZLDptuiHcthAk8QZxHgHI=; b=MHn1QGy0lsG2IqtvB4m/BFc6fuQCBGgWi4TxpfimSUYr6qJ3tb5No6ouRlf+23f11Ru6/EBG3QqMRKb1dfGJXDIJVDytUN4gm83KAb0Pc9cQzumfXPfnjkvrateQh3AvQ2zzfp8RE914MxbCIT4V5WaYpj/Yd4NA1BzwWr1cENesiPIsQxYwKbZG/+578npL+Pjxsh8rHlgOHQpn6ggx6xkmICrlzsco4L+shrb+CLDDDWnbiJ8izRJCTntWdJFDoyDW2UmUkjnNuTI/Dqv5TmnGoKTVI4gu5QGfROlMoLPidEwRHXKETXcovGYdBEXbgbjlyI7plYebxeCE09q0Hg== 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=QUEVYKXF5gyGWM9LJIJFFbZLDptuiHcthAk8QZxHgHI=; b=Dn8JDe3aw+JfSt1AHbzFgMlurP1U+fRmg3CZNcG0z+hw34zMcc4xrEGzIbbDmSEsqoj1lNk2gRbsZ/AgL9HuKrdIpFAR0g6UZrzE4qH7v3q2iYFOt9Yh96pqw9EOHNw6V3ei8psKOUb3HzUdCwYl9doCIlh5XK6YMSGdzz5mOJs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 14/20] common/device_tree: Add rwlock for dt_host Date: Tue, 5 Sep 2023 18:16:24 -0700 Message-ID: <20230906011631.30310-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|DS0PR12MB6534:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b72af36-97d0-4b52-0054-08dbae76f138 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fj7k17JM76pkQz7LTYOUtBk41o2BpO0xvF/BjofovlgrRo3LkDVU3x7qON9Xz9U7sUMoMDJQxWo2/62DZX9/G+2KgwdJ6N42fMmd9Ecf7ffSvXO525e6qn/prAch39h21IHea2zdL0/1OsZAMr1cQfq9WTUuhRBpJ8YynGqa+vLFGbI6DCemx8gguOVioPUskWgSD1vmVkgNlrhIz+LEw6laLDuJU5oyGATMs422qY64H9uVNYI8v+t4Vkk2VKgQfVe0hw9iuDqALCXe0jTtf0SeHvXxnXbI68PNEJW4+McjVcVzUUOO/9AgyR5/iZESa5OAL17TTs5pUchu89UBfuEf/IG5rG8pqW1cZAWX7DNDVBVvva5A42wxv85M3pVjH0DkHHkgcF+3AHyrsgaLHd4pe/ZI3+Zceod7PPTazwit9fuTDjEvRM84gVuMfzQ5nbKHWvD3vH2Zmvf7wxXBcuYYyeWTb5Mvrq/vf+ssijfW2lJySrBbWuR9z4dtElym8LC5xDEdclRvHDjgaQiswfKdSMx4nzQSDW9bWevz6HdjmxIzNhaXtle0MlpC1Siv3+0SVKRHUwiL5nrYk3VrbGjbn/6SBweRrkP1Z8wWV8j2ddQXSpvzN9tRYAtF9YXe9O6ILEPMLnUyl4EZvJm6QZbIqcAFWssXHKPumpDUiVrRnnDy5oDHs7VWChsIVWxtU7L/x0MJbjfg/VoMOWa806H9rqccBNnqk2rmT59DjPVcwgfSLJ+e11lqWf1FhkBHEPOhut5S+tDj1Y2GSCGeMw== 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:(13230031)(4636009)(396003)(346002)(39860400002)(136003)(376002)(82310400011)(1800799009)(186009)(451199024)(36840700001)(46966006)(40470700004)(83380400001)(40460700003)(336012)(426003)(36756003)(81166007)(356005)(2906002)(36860700001)(70206006)(47076005)(82740400003)(40480700001)(54906003)(41300700001)(316002)(6916009)(70586007)(86362001)(6666004)(478600001)(8936002)(8676002)(4326008)(5660300002)(2616005)(1076003)(44832011)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:47.8785 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b72af36-97d0-4b52-0054-08dbae76f138 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6534 Dynamic programming ops will modify the dt_host and there might be other functions which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host during runtime. dt_host writer will be added in the follow-up patch for device tree overlay functionalities. 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: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v11: Update check state >= active for checking dt_host_lock to be locked Changes from v10: Add ASSERT for iommu_assign_dt_device() and iommu_add_dt_device(). Changes from v9: Update commit message and fix indentation. Add ASSERT() for iommu_deassign_dt_device() and iommu_remove_dt_device(). Fix code styles. Remove rwlock_init in unflatten_device_tree() and do DEFINE_RWLOCK in device-tree.c Changes from v7: Keep one lock for dt_host instead of lock for each node under dt_host. --- --- xen/common/device_tree.c | 1 + xen/drivers/passthrough/device_tree.c | 28 +++++++++++++++++++++++++-- xen/include/xen/device_tree.h | 7 +++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index f38f51ec0b..b1c2952951 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -31,6 +31,7 @@ dt_irq_xlate_func dt_irq_xlate; struct dt_device_node *dt_host; /* Interrupt controller node*/ const struct dt_device_node *dt_interrupt_controller; +DEFINE_RWLOCK(dt_host_lock); /** * struct dt_alias_prop - Alias property in 'aliases' node diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 80f6efc606..075fb25a37 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -31,6 +31,8 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) int rc = -EBUSY; struct domain_iommu *hd = dom_iommu(d); + ASSERT(system_state < SYS_STATE_active || rw_is_locked(&dt_host_lock)); + if ( !is_iommu_enabled(d) ) return -EINVAL; @@ -62,6 +64,8 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev) const struct domain_iommu *hd = dom_iommu(d); int rc; + ASSERT(rw_is_locked(&dt_host_lock)); + if ( !is_iommu_enabled(d) ) return -EINVAL; @@ -113,6 +117,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); @@ -120,10 +126,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; } @@ -133,6 +143,8 @@ int iommu_remove_dt_device(struct dt_device_node *np) struct device *dev = dt_to_dev(np); int rc; + ASSERT(rw_is_locked(&dt_host_lock)); + if ( !iommu_enabled ) return 1; @@ -177,6 +189,8 @@ int iommu_add_dt_device(struct dt_device_node *np) struct device *dev = dt_to_dev(np); int rc = 1, index = 0; + ASSERT(system_state < SYS_STATE_active || rw_is_locked(&dt_host_lock)); + if ( !iommu_enabled ) return 1; @@ -249,6 +263,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: @@ -289,7 +305,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, } if ( d == dom_io ) - return -EINVAL; + { + ret = -EINVAL; + break; + } ret = iommu_add_dt_device(dev); if ( ret < 0 ) @@ -327,7 +346,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, break; if ( d == dom_io ) - return -EINVAL; + { + ret = -EINVAL; + break; + } ret = iommu_deassign_dt_device(d, dev); @@ -342,5 +364,7 @@ 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 44d315c8ba..a262bba2ed 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 @@ -218,6 +219,12 @@ extern struct dt_device_node *dt_host; */ extern const struct dt_device_node *dt_interrupt_controller; +/* + * Lock that protects r/w updates to unflattened device tree i.e. dt_host during + * runtime. Lock may not be taken for boot only code. + */ +extern rwlock_t dt_host_lock; + /** * Find the interrupt controller * For the moment we handle only one interrupt controller: the first From patchwork Wed Sep 6 01:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375228 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 584DDCCF9FC for ; Wed, 6 Sep 2023 01:29:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596119.929899 (Exim 4.92) (envelope-from ) id 1qdhM4-0004MS-CE; Wed, 06 Sep 2023 01:29:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596119.929899; Wed, 06 Sep 2023 01:29: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 1qdhM4-0004MJ-83; Wed, 06 Sep 2023 01:29:16 +0000 Received: by outflank-mailman (input) for mailman id 596119; Wed, 06 Sep 2023 01:29:15 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA7-0006tr-HC for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:55 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20615.outbound.protection.outlook.com [2a01:111:f400:7ea9::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1065a1e5-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:54 +0200 (CEST) Received: from MN2PR19CA0018.namprd19.prod.outlook.com (2603:10b6:208:178::31) by DM6PR12MB4353.namprd12.prod.outlook.com (2603:10b6:5:2a6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Wed, 6 Sep 2023 01:16:50 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::b8) by MN2PR19CA0018.outlook.office365.com (2603:10b6:208:178::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:50 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:50 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:46 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 1065a1e5-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BXt5SUSwssXIp8tIHllnOsBvYQPAwvCwWH82uXfET8Uzpk31nU+Gqq04mV972bipR49aszBx27Y2X/B+p2Fn3YEN6zXCV+Nsdh7C+N9WNFXv3T+29NWw7LYzsd4ZW+QCyCHoP8tnAgN1srIA/0bMGRglOPzE+4DR1lu/PnxBVa/zc0aS/A0lqmKViqC+oZalTYE0LdaMBM+E3+lyUDnTlQVuTZIvDcrzIpOmXJi/JGD1sAJwnjgGxsJLo7LHYiURogJuskau9Xyeb+QlxIiwIZLbpIKDRt/wdjQCnyKBp7/xFeLZwic+Xbzs4U65UL+xb5geiPDWEG6i8PynPK67dw== 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=stho6rkmy8rK1oECb+GLo4R5AalHWAkc6H9ty4aMTD0=; b=Dka0VPYq/EzD/G2y4GfxRcFI+3837lkPUsVs/oPMH131ZMKa6f7HBXxsjLlh12ZJ6ot9ecqurEVw9v3q1QqSe1YJiOzYloaPdqhNCXSo2I5PkuaM/6h9jQaIgGtvPqAs4PkpoEwh2LIum3ECwsJN/sFKaDhpMLl1FC6QpOZ9jNYcFrXnyCqDY5E1bCI1RfiFMKWGRik9UOdXC2qRu7z2OLQ4pPOs8H3MLAdt4ArcFfR1bKsMIN8njM2t7Z48qC7Tv6I7c6uX8UjGLMLczrOaF3uwUQW7BOUwDycsJ3XFa68TdOY7dXWXbhUVx8UVsOZzLRWtw5nGxV7npwuuC1fSZw== 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=stho6rkmy8rK1oECb+GLo4R5AalHWAkc6H9ty4aMTD0=; b=1F4SU6rl2ubSDbP3yT/NCUHgWy9x5bIHPKnMmMEcP3DsQY2fWXCdBPkTRmP9xFfLwcYxWbbiKhTEwVjIigr1MxqybFc5tusz+mmu6Brtrs3pygvrUogK2fO3PIGt80gQUod5D2vtnUVZkJ5CeMKWyAIaktsb+CK1sJeWAxklD3Y= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v12 15/20] arm/asm/setup.h: Update struct map_range_data to add rangeset. Date: Tue, 5 Sep 2023 18:16:25 -0700 Message-ID: <20230906011631.30310-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|DM6PR12MB4353:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a799134-2e38-4d71-a30b-08dbae76f29d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1CUM1Nxp7aG+Ebhf1czbVBk6GNv7gSznYVfOfFmE6xq2024ayKXslt69KEFjgkIsBRl6dBNrSeffQYjirGz601mBVBzjVw3nHqIP+jjMUJFRAo28oAFJOll7fU7cAvdzjp2RCz5tqT8Uc6iMS4Ev2JqSBsVM8YZBQrh9yhoLZ19g9H5Qp0MhnztB4v4xNsMFpjO4HuPCCyadC6oNcFEnA1LrSbHd+ItxvISvsvDL63/YEMUMAasD29y2mQHU89N60hZvC1D4UYOdLu5incfhso0qwjqupanLuoMSNFZvGDRAcycciH7pPIXUGHr1J6/huAKIpjNJLjtH+fjxYdZNw++yDb+mZp70IpYjUOVSdy/B66v5nc1RcTEuvGqejqVr2sdUJYSnUGtGAgpTdxRhwX6GPtx6rLfrrPiNeNbZ+Ba7k+k/cpR2ODSCGEH1HX/DS/DkfPJDuIH7x/K0oPG6Vn2gG5M4R8VzBhyLg4iVuU+P4RhCY32Z8FJbPQqm49lKHdJ+mw1o3lLi/Mm4fXo9saHYTSViq6C4IWm+vTafMoC1i2yazm66fjolVwQpzmtUApsB0git7voLcnait6VNOlSgLfGTZrP1rWqiL5lP5JFsJKZUb8Ck+/0+WowJ//zQ+8avozkhebPcXjUEcXi2A89km0bMj7pNEYLN54Ln8pSLMM/7jkBoFkERteYeP0OaSIQSeBMMrQt68SNnjgg46aRWq6v9vTulZHYX35SkJtWEaphb8JnHeGklWBF03O7bBS4/XNhi0SV90bIgiK0CcA== 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:(13230031)(4636009)(136003)(346002)(39860400002)(396003)(376002)(82310400011)(186009)(1800799009)(451199024)(46966006)(40470700004)(36840700001)(6666004)(478600001)(83380400001)(1076003)(2616005)(26005)(336012)(426003)(2906002)(44832011)(6916009)(54906003)(41300700001)(316002)(70206006)(70586007)(5660300002)(4326008)(8676002)(8936002)(40460700003)(36756003)(40480700001)(47076005)(36860700001)(86362001)(81166007)(356005)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:50.2379 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a799134-2e38-4d71-a30b-08dbae76f29d 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4353 Add rangesets for IRQs and IOMEMs. This was done to accommodate dynamic overlay node addition/removal operations. With overlay operations, new IRQs and IOMEMs are added in dt_host and routed. While removing overlay nodes, nodes are removed from dt_host and their IRQs and IOMEMs routing is also removed. Storing IRQs and IOMEMs in the rangeset will avoid re-parsing the device tree nodes to get the IOMEM and IRQ ranges for overlay remove ops. Dynamic overlay node add/remove will be introduced in follow-up patches. Signed-off-by: Vikram Garhwal Acked-by: Stefano Stabellini --- Changes from v10: Replace paddr_to_pfn(PAGE_ALIGN()) with paddr_to_pfn_aligned(). Change data type of irq. fix function change for handle_device(). Remove unnecessary change .d = d in mr_data. --- --- xen/arch/arm/device.c | 43 +++++++++++++++++++++++++------- xen/arch/arm/domain_build.c | 4 +-- xen/arch/arm/include/asm/setup.h | 9 ++++--- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 327e4d24fb..1f631d3274 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -165,6 +165,15 @@ int map_range_to_domain(const struct dt_device_node *dev, dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", addr, addr + len, mr_data->p2mt); + if ( mr_data->iomem_ranges ) + { + res = rangeset_add_range(mr_data->iomem_ranges, + paddr_to_pfn(addr), + paddr_to_pfn_aligned(addr + len - 1)); + if ( res ) + return res; + } + return 0; } @@ -178,10 +187,11 @@ int map_range_to_domain(const struct dt_device_node *dev, */ int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, - bool need_mapping) + bool need_mapping, + struct rangeset *irq_ranges) { unsigned int i, nirq; - int res; + int res, irq; struct dt_raw_irq rirq; nirq = dt_number_of_irq(dev); @@ -208,17 +218,24 @@ int map_device_irqs_to_domain(struct domain *d, continue; } - res = platform_get_irq(dev, i); - if ( res < 0 ) + irq = platform_get_irq(dev, i); + if ( irq < 0 ) { printk(XENLOG_ERR "Unable to get irq %u for %s\n", i, dt_node_full_name(dev)); - return res; + return irq; } - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + res = map_irq_to_domain(d, irq, need_mapping, dt_node_name(dev)); if ( res ) return res; + + if ( irq_ranges ) + { + res = rangeset_add_singleton(irq_ranges, irq); + if ( res ) + return res; + } } return 0; @@ -249,6 +266,11 @@ static int map_dt_irq_to_domain(const struct dt_device_node *dev, } res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev)); + if ( res ) + return res; + + if ( mr_data->irq_ranges ) + res = rangeset_add_singleton(mr_data->irq_ranges, irq); return res; } @@ -289,7 +311,8 @@ static int map_device_children(const struct dt_device_node *dev, * - Assign the device to the guest if it's protected by an IOMMU * - Map the IRQs and iomem regions to DOM0 */ -int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt, + struct rangeset *iomem_ranges, struct rangeset *irq_ranges) { unsigned int naddr; unsigned int i; @@ -308,7 +331,9 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) .p2mt = p2mt, .skip_mapping = !own_device || (is_pci_passthrough_enabled() && - (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) + (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)), + .iomem_ranges = iomem_ranges, + .irq_ranges = irq_ranges }; naddr = dt_number_of_address(dev); @@ -342,7 +367,7 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) } } - res = map_device_irqs_to_domain(d, dev, own_device); + res = map_device_irqs_to_domain(d, dev, own_device, irq_ranges); if ( res < 0 ) return res; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index ff4fc30769..29dcbb8a2e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2402,7 +2402,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, "WARNING: Path %s is reserved, skip the node as we may re-use the path.\n", path); - res = handle_device(d, node, p2mt); + res = handle_device(d, node, p2mt, NULL, NULL); if ( res) return res; @@ -2745,7 +2745,7 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo, return -EINVAL; } - res = map_device_irqs_to_domain(kinfo->d, node, true); + res = map_device_irqs_to_domain(kinfo->d, node, true, NULL); if ( res < 0 ) return res; diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 6cda3e4039..b8866c20f4 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -113,6 +113,9 @@ struct map_range_data p2m_type_t p2mt; /* Set if mapping of the memory ranges must be skipped. */ bool skip_mapping; + /* Rangeset to store IRQs and IOMEM for overlay nodes. */ + struct rangeset *iomem_ranges; + struct rangeset *irq_ranges; }; extern struct bootinfo bootinfo; @@ -165,11 +168,11 @@ 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(struct domain *d, struct dt_device_node *dev, - p2m_type_t p2mt); +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt, + struct rangeset *iomem_ranges, struct rangeset *irq_ranges); int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, - bool need_mapping); + bool need_mapping, struct rangeset *irq_ranges); int map_irq_to_domain(struct domain *d, unsigned int irq, bool need_mapping, const char *devname); From patchwork Wed Sep 6 01:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375221 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 74FD6CCF9F5 for ; Wed, 6 Sep 2023 01:17:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596004.929845 (Exim 4.92) (envelope-from ) id 1qdhAF-00032N-U3; Wed, 06 Sep 2023 01:17:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596004.929845; Wed, 06 Sep 2023 01:17:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhAE-0002zS-Bz; Wed, 06 Sep 2023 01:17:02 +0000 Received: by outflank-mailman (input) for mailman id 596004; Wed, 06 Sep 2023 01:17: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 1qdhAC-00079K-CG for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:17:00 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20625.outbound.protection.outlook.com [2a01:111:f400:7eab::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 11dc9176-4c53-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 03:16:57 +0200 (CEST) Received: from MN2PR19CA0004.namprd19.prod.outlook.com (2603:10b6:208:178::17) by MN0PR12MB6173.namprd12.prod.outlook.com (2603:10b6:208:3c6::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:52 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::50) by MN2PR19CA0004.outlook.office365.com (2603:10b6:208:178::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Tue, 5 Sep 2023 20:16:47 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 11dc9176-4c53-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RpYXkIVdtxM+f5Bq8tKFdm0rU32Oq6xCG/dX2+ppnLRRA1mmHGULOpagioMbdA54EdVvGsi065xoR/XDn+AIm2gbhYcmz8cI9rB28mVwcVMrnvaV+9XqN/WAFsuEIlszIG/Q9AOr+k5fHW7213pbnxxw7K3rv4X9QTkrinbAG1nFanVXSuZ1jD1dm8QoeXhJQUjK0Qtgt/StbpOLJKGuK1oBYI5oG0UJwbSIPTIi65Xhu5QB1nYzsjQRjCS3kmNVDLYgkNr59VuWH65s5MMRlVLKllDXjpOQGcORDbvfvkC+kC9H5A+7Bnoj2X81NWbCSfkP53pw9TQLvfC6gyEVvA== 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=BzU2V5UhlhCONkwcboNamsl2T4uX8forSiEa0laE+KA=; b=bT+SqQp3y/nAaO7ZRZFLB6MnQKlFDMhbIogNlfzy7kpb3g8tkw0Eha0cxvxqmXu4rXg5h4NpAOapL0gIfBIdwh69XUGj2l7GjLDdV1DyTOgt9//UfoxImEn1Hd1eQeEH9RUGyvhHzW1lhZjKn9uXpfaF8voORc0D94YNhhepgxAZJn+ZkuhYtYC9mLZSCHM8iwTKUNFK8r5qfeHxKWLVYI5ZzLsGP07321nSDhttWCs38ogKIjZ1K7rVRTVefV5d8Q8jGTwLTK4DxAIDfjN2/zH8gMIxbSm2KldVgi9UsdDYxNeMDzxE8reAVx6JBFhrtxznTbjM2wEEfXQCfYgE8Q== 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=BzU2V5UhlhCONkwcboNamsl2T4uX8forSiEa0laE+KA=; b=imq+Z6paJtrAC27+AePkkoe1BswpSPZRj73dNw5JLjHdC6SEIHyO02xZ8S/ykjPKstN2c9JruMnBsIQPHp5Ssyx9HmEKOkBy1g8UgLTW8ZbitjI/IidzKwYC1gCffbLhsADcLEBN7hlzPU5FskzX/LB8lmTWNE+nwe1riPOiMGQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Andrew Cooper , "George Dunlap" , Jan Beulich , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v12 16/20] xen/arm: Implement device tree node removal functionalities Date: Tue, 5 Sep 2023 18:16:26 -0700 Message-ID: <20230906011631.30310-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|MN0PR12MB6173:EE_ X-MS-Office365-Filtering-Correlation-Id: dd3e6e9d-59e5-4008-d2f3-08dbae76f3af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2V57KMeZkfIB4yQxYIK7sG+DkX8C+Rq1ubbTXLe3wh3H5qzIkIp4Wc0VfLcye+1HmOgHnnYL8MrstzlElcXnpg+lQL6GW27RbCJCqZMAjtTl195Vfm4hUno1jGX2MgTN61mPzz7take+kpk902dKmTicpof6end7p9gfAzhoYylXLdVp1/HJCNO4eDpQl+o2y5U8rPe3sQ87cdU3bv85uyNywkaG7l19c0DLhJEvjQ6jgdh7HhZpLFjuodnZ0ZP7y6/Trk1O3PnfIV9dQgpffkXM7Ht5q21RQUK+cMuWsu25cPejlpx/8AhB51np9aDfwI5RScjF18Hj6uwApPoJJw/b9+IQvpChjRFMF6lMBAK4Ym+8i6bZZOKblTPYRACyF64RHtsE9eq4DO7jJv2PhnRXUEqUDXbyKSS8kzrqOGQC3e16TJBufgYnvYeqVl5ApDU1nPkxLyHaDq6S0rKXGmrQemWZwsdbH2U5meApPvgAQ4BQ+zDcbMSQ2aOBe8BPaf/zcS89b81nt0PGV7TOzm7H0pVg8x/gBVxRfDtyLbu0tuxh0r9b+JNMd/sQ4VlNqwgBhhDvS/uyUbnYwYXUORHbV491LDXlUvnyFd6AT1mKHjTvJkgGr6EhZclirnXyS+KGRunwDiVI1ZQPUdYuYZY65AbTMH6Mla0qQxgV+W3vxzb9DiFjL5OHRBwTdyHQB938orJIHS0YnumNyXWmns4Jm+UgW3sWLIIYOEkiOGpzLNgiRavtfcHeJ7VFDnY5LHjZVQVPBKMA+Nezd2n2oSfQA5HUFbDMG5JV12PABzxCDPK5nLZeln3Y4VNMMSPa 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:(13230031)(4636009)(136003)(396003)(39860400002)(346002)(376002)(451199024)(1800799009)(82310400011)(186009)(46966006)(36840700001)(40470700004)(5660300002)(8936002)(6916009)(36756003)(30864003)(54906003)(316002)(2906002)(70206006)(70586007)(4326008)(44832011)(8676002)(40460700003)(41300700001)(36860700001)(336012)(26005)(1076003)(47076005)(40480700001)(426003)(82740400003)(81166007)(356005)(478600001)(83380400001)(2616005)(86362001)(6666004)(333604002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:52.0036 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd3e6e9d-59e5-4008-d2f3-08dbae76f3af 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6173 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. Also, this is an experimental feature so it is expected from user to make sure correct device tree overlays are used when adding nodes and making sure devices are not being used by other domain before removing them from Xen tree. Partially added/removed i.e. failures while removing the overlay may cause other failures and might need a system reboot. Signed-off-by: Vikram Garhwal Acked-by: Stefano Stabellini --- Changes from v10: Add iommu_remove_dt_device if device has IOMMU added. Changes from v9: Remove iommu and IRQ routing as this will not be done while adding the nodes. Changes from v8: Remove IRQs and IOMMU entries using rangesets instead of parsing each node. Changes from v7: Add dt-overlay.c in MAINTAINERS. Add comments for dt_overlay_remove_node. Rename handle_remove_irq_iommu() to remove_resources(). Add comment regarding false mapping flag for reason behind not removing the mapping.. Remove irq_access_premitted() check. Add error handling for remove_all_descendant_nodes Change read_lock with write_lock. Remove check_overlay_fdt() call from handle_remove_overlay_nodes(). Re-organize dt_sysctl and reutnr -EOPNOSTSUPP for error cases. Also, renamed this function to dt_overlay_sysctl. Remove unnecessary header includes in dt-overlay.h Correct indentation and make func tion inputs const wherever possible. Make overlay_fdt const_void inside xen_sysctl_dt_overlay{}. Add comment regarding why we not removing IRQ and MMIO mappings. Move overlay_node_count() out of this patch as it's not being used here anymore. 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. --- --- MAINTAINERS | 1 + xen/arch/arm/sysctl.c | 16 +- xen/common/Makefile | 1 + xen/common/dt-overlay.c | 406 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 24 +++ xen/include/xen/dt-overlay.h | 63 ++++++ 6 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 xen/common/dt-overlay.c create mode 100644 xen/include/xen/dt-overlay.h diff --git a/MAINTAINERS b/MAINTAINERS index 59103dbac0..0e1d1b7655 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -301,6 +301,7 @@ M: Julien Grall S: Supported F: xen/common/libfdt/ F: xen/common/device_tree.c +F: xen/common/dt-overlay.c F: xen/include/xen/libfdt/ F: xen/include/xen/device_tree.h F: xen/drivers/passthrough/device_tree.c diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c index e9a0661146..5cda0dc674 100644 --- a/xen/arch/arm/sysctl.c +++ b/xen/arch/arm/sysctl.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -25,7 +26,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_overlay_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..7b7224c29a --- /dev/null +++ b/xen/common/dt-overlay.c @@ -0,0 +1,406 @@ +/* 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 +#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(const 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 *last_descendant = device_node->child; + + parent_node = device_node->parent; + + /* Check if we are trying to remove "/" i.e. root node. */ + if ( parent_node == NULL ) + { + dt_dprintk("%s's parent node not found\n", device_node->name); + return -EFAULT; + } + + /* Sanity check for linking between parent and child node. */ + 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 a node, we need to remove all it's descendants too. + * Reason behind finding last_descendant: + * If device_node has multiple children, device_node->allnext will point + * to first_child and first_child->allnext will be a sibling. When the + * device_node and it's all children are removed, parent_node->allnext + * should point to node next to last children. + */ + if ( last_descendant ) + { + last_descendant = find_last_descendants_node(device_node); + parent_node->allnext = 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 ( last_descendant ) + last_descendant = find_last_descendants_node(device_node); + + if ( last_descendant ) + np->allnext = 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; +} + +static int irq_remove_cb(unsigned long s, unsigned long e, void *dom, + unsigned long *c) +{ + int rc; + struct domain *d = dom; + + /* + * TODO: We don't handle shared IRQs for now. So, it is assumed that + * the IRQs was not shared with another devices. + * TODO: Undo the IRQ routing. + */ + rc = irq_deny_access(d, s); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %lu\n", s); + } + else + *c += e - s + 1; + + return rc; + +} + +static int iomem_remove_cb(unsigned long s, unsigned long e, void *dom, + unsigned long *c) +{ + int rc; + struct domain *d = dom; + + /* + * Remove mmio access. + * TODO: Support for remove/add the mapping in P2M. + */ + rc = iomem_deny_access(d, s, e); + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + s & PAGE_MASK, PAGE_ALIGN(e) - 1); + } + else + *c += e - s + 1; + + return rc; +} + +/* Check if node itself can be removed and remove node from IOMMU. */ +static int remove_node_resources(struct dt_device_node *device_node) +{ + int rc = 0; + unsigned int len; + domid_t domid; + + 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 hardware domain or domain io. */ + if ( domid != hardware_domain->domain_id && 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; + } + + /* Check if iommu property exists. */ + if ( dt_get_property(device_node, "iommus", &len) ) + { + if ( dt_device_is_protected(device_node) ) + { + rc = iommu_remove_dt_device(device_node); + if ( rc < 0 ) + return rc; + } + } + + return rc; +} + +/* Remove all descendants from IOMMU. */ +static int +remove_descendant_nodes_resources(const 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 ) + { + rc = remove_descendant_nodes_resources(child_node); + if ( rc ) + return rc; + } + + rc = remove_node_resources(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; + struct domain *d = hardware_domain; + + 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_descendant_nodes_resources(overlay_node); + if ( rc ) + return rc; + + rc = remove_node_resources(overlay_node); + if ( rc ) + return rc; + + dt_dprintk("Removing node: %s\n", overlay_node->full_name); + + write_lock(&dt_host_lock); + + rc = dt_overlay_remove_node(overlay_node); + if ( rc ) + { + write_unlock(&dt_host_lock); + return rc; + } + + write_unlock(&dt_host_lock); + } + + /* Remove IRQ access. */ + if ( tracker->irq_ranges ) + { + rc = rangeset_consume_ranges(tracker->irq_ranges, irq_remove_cb, d); + if ( rc ) + return rc; + } + + /* Remove mmio access. */ + if ( tracker->iomem_ranges ) + { + rc = rangeset_consume_ranges(tracker->iomem_ranges, iomem_remove_cb, d); + if ( rc ) + return rc; + } + + 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(const 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; + + 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 ) + { + 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); + + rangeset_destroy(entry->irq_ranges); + rangeset_destroy(entry->iomem_ranges); + + xfree(entry); + + out: + spin_unlock(&overlay_lock); + return rc; +} + +long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) +{ + long ret; + void *overlay_fdt; + + if ( op->overlay_op != XEN_SYSCTL_DT_OVERLAY_ADD && + op->overlay_op != XEN_SYSCTL_DT_OVERLAY_REMOVE ) + return -EOPNOTSUPP; + + 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; + } + + if ( op->overlay_op == XEN_SYSCTL_DT_OVERLAY_REMOVE ) + ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + + 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 3975050248..f1eba78405 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1185,6 +1185,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(const_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 @@ -1215,6 +1234,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; @@ -1245,6 +1265,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..c0567741ee --- /dev/null +++ b/xen/include/xen/dt-overlay.h @@ -0,0 +1,63 @@ + /* 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 + +/* + * 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. + * @iomem_ranges: Range set to keep track of all IOMEMs. + * @irq_ranges: Range set to keep track of all added IRQs. + */ +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 rangeset *iomem_ranges; + struct rangeset *irq_ranges; +}; + +struct xen_sysctl_dt_overlay; + +#ifdef CONFIG_OVERLAY_DTB +long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op); +#else +#include +static inline long dt_overlay_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 Wed Sep 6 01:16:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375222 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 7A8C2CCF9E9 for ; Wed, 6 Sep 2023 01:17:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596003.929839 (Exim 4.92) (envelope-from ) id 1qdhAC-0002ic-Lj; Wed, 06 Sep 2023 01:17:00 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596003.929839; Wed, 06 Sep 2023 01:17:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhAC-0002hx-9K; Wed, 06 Sep 2023 01:17:00 +0000 Received: by outflank-mailman (input) for mailman id 596003; Wed, 06 Sep 2023 01:16: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 1qdhAB-00079K-C3 for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:59 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20619.outbound.protection.outlook.com [2a01:111:f400:7eb2::619]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 11d49cb7-4c53-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 03:16:56 +0200 (CEST) Received: from CY5PR19CA0013.namprd19.prod.outlook.com (2603:10b6:930:15::32) by DM4PR12MB6496.namprd12.prod.outlook.com (2603:10b6:8:bd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:52 +0000 Received: from CY4PEPF0000E9DB.namprd05.prod.outlook.com (2603:10b6:930:15:cafe::4) by CY5PR19CA0013.outlook.office365.com (2603:10b6:930:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DB.mail.protection.outlook.com (10.167.241.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:51 +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.2507.27; Tue, 5 Sep 2023 20:16:48 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 18:16:48 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 11d49cb7-4c53-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O5kaXHWALsQ+FoipwxpxVEaWAc0LrtWdM8OpJvFud7JciadjvFPr5XkMikEf1up7/0EcZNsIaXR3ncPkBTRTs9h2ZrN/beiMyngosYONXgehzo1krkzhFBaEUxy4QdyWE33cTzNSwtutI2vlDrCDTaCOwWWNrCIzp+UyhKySn2ReHEZVBoNwKxlij5Qvsi4Lwz9qRs/knCsnKiDAYQF7wMjVo2T2f3LiqLp6JLCYMK3apKaSGyArVQx/V7OhuC6LfmC1lVVMtQ7HPEHAIKPqBJQmQO5M9fC9mTV54iy/s6HUlS1fqH84lLMBOI+3FtqDAB1V0LgAm604qTatpRwrew== 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=x7T2p5a2Ff/HAq+v2RKRNl+IMs8XMzp5B2xd5/wlRh0=; b=eShWP/nIm9Ak9vNzON7i8BqDlG3yYBo+Y8x45h0QSU2Vx8K02NOAnYewjNV0kAOLhmMzIbmOkfmjIyfPtAQOadOskzaNS5ewyhUHcvEKuYHKGi7vv0avDnkLo70M00hfuLYUjsjKlFSd2zhsCmNXDhFyZO5Ox6DdB9Bd0Q3dCYUHKLEao3n9975drf7pol4CWnQqIsnx96DgUQy5Kj1jbKUUkh94kFu0wugqJYC0ADOPxwEgtZB50fMvL24YF90XUAzJr2eTwQ353dz+PjsP3jXViidb2DMO4sIYHsppTlSC87rDCqLHYguzqte+n16VHuQ4KFfuGajZ6OHY9yjrPw== 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=x7T2p5a2Ff/HAq+v2RKRNl+IMs8XMzp5B2xd5/wlRh0=; b=ZJnznf+V/xy/1gnhDPQe+xBo4ALdLAWPxyO0CCAkjATHyQOw9nQYOzExi42s8SWFn5Kp3txS/yytbl1JEJ3aEi+x44ioLmb1GX2mlNmRU8DrhIf6QwLKsZIq2U3ooJgWRwBNCDl9btNVhY1bFFFWpxCeeBE82m6Kf2JhjAxu9vY= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v12 17/20] xen/arm: Implement device tree node addition functionalities Date: Tue, 5 Sep 2023 18:16:27 -0700 Message-ID: <20230906011631.30310-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DB:EE_|DM4PR12MB6496:EE_ X-MS-Office365-Filtering-Correlation-Id: 81dcb88c-7b9c-4350-10d3-08dbae76f375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Ivz7wLxg7ke7jdxoL46u5PsuwSP/CCwfREfS/etRgoGSqCsmDPz+rqg5ITmk1XZMAo3h5v6ImUrcSzuliiNO6R1ug1FUi0V8a8i5SRmN/03mX3Y4SeFFgs5xQpGaJ++GqlvqN7t4D9xNwvt20u42HlCpv2cf1iae5e6UIE/EKf29VWgBw30FXkeD4w9JhU7PxZL1pr+4de54Qkx8xTiDaIvobpULA/7zEl2LrkxtK1Sp5U/EF1SbBzPvio2qwsqf6fgWFFIHhhyMyS1DmWgvlup9+fudGbjll+Zpbue8Gnm3YGxuL0SnAhEV59++XliPzfKWlYOf06nbiNoENXWERu9CiEDCxOSzggdqvjXPEmXsByV6kfyfHk+H2vCAK6AZKJDqst3Ei+rUnfzclBcmvGd/zvo+mi216CEMFJnx8ItJHgb03yiv2cGqYh6Kg9aYXGcBIAB74QdWlm2w1PX6Ag5RVaeyg1P8uj/rZhAuw5fZVtbvuo4YcoFVv09MV/1ONBUJptE0UGR5kN9CO/rTnRy2TvHhupelnvlfUqnXox2yFica374jnJbLCmMc0u+LdCt6eVuzsIq9A3iky12sQcTmqbwAzmik3rSlUfs4rsmRqGyCy7db7NgTlmT3aZAVGuAWcekQzCdWwU+LUI58pXUR4r/GOn7wu7w/TI2DXNH4mJJv3owsohOFzVqHwlt/XaBq7Gmu+OubV0C4Edj8ZJCLET0kTQkAq0Ri9qK6Us0q2G7XfzVvbaKgcZvy6gXYUVl8tROtoh7m8RTgQBJpA== 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:(13230031)(4636009)(346002)(376002)(39860400002)(396003)(136003)(451199024)(1800799009)(186009)(82310400011)(40470700004)(36840700001)(46966006)(26005)(5660300002)(44832011)(54906003)(70586007)(316002)(6916009)(70206006)(41300700001)(40480700001)(82740400003)(81166007)(356005)(1076003)(6666004)(4326008)(8936002)(8676002)(2616005)(426003)(478600001)(83380400001)(336012)(2906002)(47076005)(40460700003)(36860700001)(30864003)(66899024)(86362001)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:51.5717 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 81dcb88c-7b9c-4350-10d3-08dbae76f375 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: CY4PEPF0000E9DB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6496 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 Reviewed-by: Stefano Stabellini --- Changes from v10: Change int to unsigned int for accessing node_nums. Re-organize free_nodes_full_path(). Change order of calling xfree for err cases. Changes from v9: Remove add_resources() and use handle_device(). Changes from v8: Add rangeset to keep IRQs and IOMEM information. Changes from v7: Move overlay_node_count() in this patch. Fix indent with goto statements. Rename handle_add_irq_iommu() to add_resources(). 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 | 495 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 495 insertions(+) diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index 7b7224c29a..b07a6128dc 100644 --- a/xen/common/dt-overlay.c +++ b/xen/common/dt-overlay.c @@ -34,6 +34,25 @@ find_last_descendants_node(const struct dt_device_node *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; @@ -111,6 +130,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) { @@ -171,6 +262,102 @@ static int iomem_remove_cb(unsigned long s, unsigned long e, void *dom, return rc; } +/* 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; +} + +/* + * 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; +} + /* Check if node itself can be removed and remove node from IOMMU. */ static int remove_node_resources(struct dt_device_node *device_node) { @@ -359,6 +546,312 @@ static long handle_remove_overlay_nodes(const void *overlay_fdt, return rc; } +static void free_nodes_full_path(unsigned int num_nodes, char **nodes_full_path) +{ + unsigned int i; + + if ( nodes_full_path == NULL ) + return; + + for ( i = 0; i < num_nodes && nodes_full_path[i] != NULL; i++ ) + { + xfree(nodes_full_path[i]); + } + + xfree(nodes_full_path); +} + +static long add_nodes(struct overlay_track *tr, char **nodes_full_path) + +{ + int rc; + unsigned int j; + 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 = dt_find_node_by_path_from(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); + + write_lock(&dt_host_lock); + + /* Add the node to dt_host. */ + rc = dt_overlay_add_node(overlay_node, overlay_node->parent->full_name); + if ( rc ) + { + write_unlock(&dt_host_lock); + + /* Node not added in dt_host. */ + return rc; + } + + write_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_device(hardware_domain, overlay_node, p2m_mmio_direct_c, + tr->iomem_ranges, + tr->irq_ranges); + 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; + unsigned int 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. + * TODO: Check and add alias_scan() if it's needed for overlay in future. + */ + 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; + } + + tr->irq_ranges = rangeset_new(hardware_domain, "Overlays: Interrupts", 0); + if (tr->irq_ranges == NULL) + { + printk(XENLOG_ERR "Creating IRQ rangeset failed"); + goto err; + } + + tr->iomem_ranges = rangeset_new(hardware_domain, "Overlay: I/O Memory", 0); + if (tr->iomem_ranges == NULL) + { + printk(XENLOG_ERR "Creating IOMMU rangeset failed"); + 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); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + xfree(tr->overlay_fdt); + xfree(tr->nodes_address); + xfree(tr->fdt); + + rangeset_destroy(tr->irq_ranges); + rangeset_destroy(tr->iomem_ranges); + + xfree(tr); + + return rc; +} + long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) { long ret; @@ -390,6 +883,8 @@ long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) if ( op->overlay_op == XEN_SYSCTL_DT_OVERLAY_REMOVE ) ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + else + ret = handle_add_overlay_nodes(overlay_fdt, op->overlay_fdt_size); xfree(overlay_fdt); From patchwork Wed Sep 6 01:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375223 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 4E2E1CCF9F3 for ; Wed, 6 Sep 2023 01:20:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596058.929858 (Exim 4.92) (envelope-from ) id 1qdhDi-00009d-Jq; Wed, 06 Sep 2023 01:20:38 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596058.929858; Wed, 06 Sep 2023 01:20:38 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhDi-00009V-HC; Wed, 06 Sep 2023 01:20:38 +0000 Received: by outflank-mailman (input) for mailman id 596058; Wed, 06 Sep 2023 01:20:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhA8-0006tr-Mw for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:16:56 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on20623.outbound.protection.outlook.com [2a01:111:f400:7ea9::623]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 11306e33-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:16:56 +0200 (CEST) Received: from MN2PR19CA0014.namprd19.prod.outlook.com (2603:10b6:208:178::27) by DM4PR12MB5216.namprd12.prod.outlook.com (2603:10b6:5:398::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:52 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:208:178:cafe::6d) by MN2PR19CA0014.outlook.office365.com (2603:10b6:208:178::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +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.2507.27; Tue, 5 Sep 2023 20:16:49 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 18:16:49 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 11306e33-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yq4mhoS3LAABD9NmKBUaIFKOTq7SLsBeTC8uhAWCvLljbwCFTDnh77nChkC1XOMuLOm1sBiKVEaketWHHthJ4cYlmNs/42UPV6yew2GYFVNTRjr5Sst5UiEkxonhR9yj4YvA0ViMzXVRjSqJNv36/weTAKXXlcjTynRbFxTAIoY0yBccyFS7Kezw136w3CSVElzteGfIpdzSp4/4beFynfQvSgSBMd6nqvvtqmyLsb6K2dhBY+XubdRBBjShncSstdheoNgzySHCbgY4QF9vCYPchHTkNR6f0aK9GztbLoEl7gE9vlcpDFcobApsI0z/lPstztE9ztKhfQkN8G6Sgw== 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=f3CXFnL+4aLIWZtU9p5mMJcpke4wuyPy6FqvOY6YZ1o=; b=RIPBciSjncsw7YeHrzTWt61p0BsB9wLoO6aGsWsnNdAzk1rETwl68AuggqHKjRRBJlZgQQFS3ltPeVK1uoveJbH6aYC4p8FjBp1mqLDQLBFW7Of7RvJ5EsZQBIbe/qYqJnNCMLu+vegC8f8Ryt7wRERrV5j1LpU0J08AbyZ/LX5EIvOpnt5BLYKstKrZ3Epooyn+AfXnep5o2WzdbgNHd0ExM5rzJfv0U7tqhrhjwqfRvcn0Ooe/MbNOyU6HKyNTe/4CxNRqnMQ0rW2fFu4CNW6SCEylpnrszm+TjWAhIlClMAGK34cfgVtnWrD0rmZAr9HYKp3BrVAqjZnvNIlThw== 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=f3CXFnL+4aLIWZtU9p5mMJcpke4wuyPy6FqvOY6YZ1o=; b=0tNn2rCiudBygV+H1xPMR7qt7toR0jUKsmtxgxZEUf1X08ZvobL8xM40NZGyRE7gRVVhHpDgzcu0BStoAZDzVKecinn139vHPRfRbj1DWmOYsnpsDSS+sDvhfeMlTB81iY/jBGZB7kxqszB6c1bv9rpCQEQ5FPx9k2OyMBtFtvA= 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 v12 18/20] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Tue, 5 Sep 2023 18:16:28 -0700 Message-ID: <20230906011631.30310-19-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|DM4PR12MB5216:EE_ X-MS-Office365-Filtering-Correlation-Id: f60b614e-9acb-4e7b-a949-08dbae76f3e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9sgS/T4Zdd8wWUnKjUTNt/qFjZCgspRdV+wXJhCxxUfETelrMECuLbCDhnHW7FZ7AapEURPNk5HpW7YO3tV1ChaQ9BBrUGEyQ4Rp+zdsCxUJF7PYMTa7/HI/gaqgUlj7ejND435NTiE5k7sAvGGwUFEGfd2auSdx/35s5/5ahry4hrhqkhQXHH231HzIIqmF9dtnF1jHX8Bb7sNOCzvMUGvMPIdyBZVFe1eeFINU0n+dUjANG0III5NHIssN64WNhRgTE58iEK4EqxUt7HkfvwdbWGQxxCRwzqXo6wg89ObjvGWCKQTEzW5jZDJ57ZvA195GDGg+IWwsK0xH3hki8sEG6GJtdoN2fdL9MsaaI1dLmwJo/0XpdrWI/HGmjEhk02UYkHUPzKitg4o0hfGDi1mVdOUNl6pn4OaWw9qJY0hAVBKZ8URxjaB5c8acIO6k2pUo1meg0s3QdblGDSHYPcd2vbAk/nliBbWJwRyRYw5UgRGtAV1WkigsDo5OcudkuDX8KFEfvMb4JpQtqDi9AC7sCNFL+ZrfTXctYUkFSekpEs6q6yDkua4PofvTif3LPnHpbJiSEFAW9ofLuqFi1uvbtjPe+u5eCZsd/S1lEW5CQ2ygucs1Qp1lCGUi88ccNwbzlZLlStdSo4m1YRPZkrvOxVj0D8/npCQkM9qiZHG16XTSVpW0Ibm39qzEktS3daRJBzX+1U7VM02ucCqS0NhzPRrshE5Uha3mAJluSYbPFwL5nvS9WUCyT3iqGFv8nU+0Uam5dw2o9+CPQ1gWnc6+4ofkCwZQqJl+hULy6f0= 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:(13230031)(4636009)(396003)(346002)(39860400002)(136003)(376002)(82310400011)(1800799009)(186009)(451199024)(36840700001)(46966006)(40470700004)(40460700003)(336012)(426003)(36756003)(81166007)(356005)(2906002)(36860700001)(70206006)(47076005)(82740400003)(40480700001)(54906003)(41300700001)(316002)(6916009)(70586007)(86362001)(6666004)(478600001)(8936002)(8676002)(4326008)(5660300002)(2616005)(1076003)(44832011)(26005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:52.3942 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f60b614e-9acb-4e7b-a949-08dbae76f3e6 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5216 xc_dt_overlay() sends the device tree binary overlay, size of .dtbo and overlay operation type i.e. add or remove to xen. Signed-off-by: Vikram Garhwal Reviewed-by: Anthony PERARD --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 12dca13b69..2ef8b4e054 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2653,6 +2653,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..c2224c4d15 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,50 @@ +/* + * + * 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; + struct xen_sysctl sysctl = { + .cmd = XEN_SYSCTL_dt_overlay, + .u.dt_overlay = { + .overlay_op = overlay_op, + .overlay_fdt_size = overlay_fdt_size, + } + }; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err = do_sysctl(xch, &sysctl)) != 0 ) + PERROR("%s failed", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} From patchwork Wed Sep 6 01:16:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375225 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 914BECCF9E9 for ; Wed, 6 Sep 2023 01:25:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596086.929868 (Exim 4.92) (envelope-from ) id 1qdhIA-0001pD-9k; Wed, 06 Sep 2023 01:25:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596086.929868; Wed, 06 Sep 2023 01:25: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 1qdhIA-0001p6-6r; Wed, 06 Sep 2023 01:25:14 +0000 Received: by outflank-mailman (input) for mailman id 596086; Wed, 06 Sep 2023 01:25:12 +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 1qdhAD-0006tr-MT for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:17:01 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20623.outbound.protection.outlook.com [2a01:111:f400:7eab::623]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 13ef21dd-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:17:01 +0200 (CEST) Received: from CY5PR19CA0010.namprd19.prod.outlook.com (2603:10b6:930:15::14) by DM4PR12MB5261.namprd12.prod.outlook.com (2603:10b6:5:398::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:57 +0000 Received: from CY4PEPF0000E9DB.namprd05.prod.outlook.com (2603:10b6:930:15:cafe::c0) by CY5PR19CA0010.outlook.office365.com (2603:10b6:930:15::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DB.mail.protection.outlook.com (10.167.241.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:52 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:50 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:50 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 13ef21dd-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d56YR/rPBMe5MbfmAWrkXHY2mM3cXK/a3Z7Vh6oW8KP942Sh/Lw20hBz4Z3/Cf0JQWs6+wYI0VpOOwZAZQoKc2MpjwwUCmYRlfu0EuqQu9gwYOyq/4EYUsjq6KNcF9cTJ/6eAutC/EGNwryD/FfRPMOXVLS6c9UiZhRXkdmTtxEhx3CcEbCrzdHZW5pe+ANzzWIUKJWYB07He4T2z0AwkhcWWptVB6mITxxxUSCzB4DlBlHjYf5U2hspSaIVeKGRwr6OpCjUO/aI5sq7i5VgxeDHnQAh3/+g9RQdsDLUIgAFW7Ewas16Cg9dzDyU51o7Ubvihuf3fMEw46dwPPVAqQ== 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=mTCPtQBNjoIyHEJsEb7hqin0hShKQ1om1xTixiBsYZA=; b=eb2dABpz0S361YurgN8F+wNB+bewaZZ5H46s1nAbIJ6X7wG1RxvGJ3ms/T2x/foJ4SfwfyUrkHkFlvq+qSuhFYln4qoPt48dOh6LGH9PW7IjrAupS3PAwCQnc7+FzLWnfT9+ZQ4BLHrFISQuWZB9C0AsSDQr6sliy821QKBD/5KQgwe78xe+Bh5iDsT5BXXidUFlhUn/4HGApLhoC6ex+gdoXISWsH/pTBrJgwApHClLzD55ppUHaXorC3y3WcRuZFNpsJKdG7ax3fsFoswYObD8uXYzPNJzsOkV6H85AnijMIXIYgzu3VRFWiaAGFhYJr2ywJYgziLO9gz5d2dyZw== 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=mTCPtQBNjoIyHEJsEb7hqin0hShKQ1om1xTixiBsYZA=; b=07fn0GtN05eajXibiOW8XkRaruJ5S9U/bUVjyVUc7XaIoRG56BHdjWtZvoxDTeXIqIE7BzZ7gkDyAwiFb17fbezJ6aa1UxAV6mIjYhBDztgFiC2q/sDltRIQPYa3jbDivl+EKGSfh3ZYaOz5VaNRcs0FNlQuHhVtXuxSkRQpxGE= 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 v12 19/20] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Tue, 5 Sep 2023 18:16:29 -0700 Message-ID: <20230906011631.30310-20-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DB:EE_|DM4PR12MB5261:EE_ X-MS-Office365-Filtering-Correlation-Id: b982ab02-2f3e-43f7-599f-08dbae76f3ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3NduXH4F4IyJR2KnHtwwAc9IZcsZ7EYbXNUubsLkwawdQRTPEdxs9YrVgs+ZIFqufVMsvA5n45/yD1hcytq3YjP16IhMJz7lhNb1hmlxFaeh2V7PvyxcgApQEuqxGHBe1CBF9qQ3ZdW1x0a7L1OhGccuxJAa51ViZe6o9imGK6JtGu4IkKLCfn9YhVRhD9BHo7DCthckoacr9ot624f5+4EDBwNOp5fqWkO63V6BclCtuUcjZWczYBrUOqm5bQm86XQ9sdncBQcXl8JIW6DO9sPtd6RMtgD5tkqXv3xqmzSrlgew/FShp1WgfnZX4aBrKqUyUi0jQGMxpGSefV0IYc7KRsdLNtNeD4BKxPVHjrsF7CvzUEFuAW1lG7U+VQze91XKN+5dB12bnLQB1+zGkMICVjlJU4gEaXg4G07b6YgJQtnN5D7I4Vn7K1XliRG7lrJb76FI7JHs2+sVKzC/4FWS7vQCuPRIP7mdqzs8Y1Fnnz2bhtvUDES99VNY40DJj+MGuECmSCvxVwVGFsSH/SJAYPqtJLXsVuJrfpAQMZ7G7BiilvYRM9+NOuCY2Bbyy5mJXHJP4AwUIOSHqNYddWk8frFWFdarxP2Mo1BlMpDeir5QyiQARaVIgleDaqoMZPbQA4jOFY1iuPXJAl4ejShvAbx+bpnyTGBDl0dvclTv6AM7WDhsXmyA4DCXVlrmyKH9IyDeZ2FUh5+EP4QtX1ydPppSi0H/qOH9ZwhPK2HwK83bG5raFdQ0WIbhSGrqlrKenkbWBQQ4wE+bCz9WnySDkqbiU/uPKwjtDxB4TKc= 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:(13230031)(4636009)(39860400002)(136003)(396003)(346002)(376002)(451199024)(82310400011)(186009)(1800799009)(46966006)(36840700001)(40470700004)(2906002)(40460700003)(54906003)(70586007)(70206006)(6916009)(40480700001)(316002)(44832011)(41300700001)(8936002)(4326008)(36756003)(8676002)(5660300002)(86362001)(6666004)(2616005)(1076003)(336012)(81166007)(426003)(26005)(36860700001)(478600001)(356005)(82740400003)(47076005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:52.4935 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b982ab02-2f3e-43f7-599f-08dbae76f3ff 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: CY4PEPF0000E9DB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5261 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 82b764ff57..abc5fd52da 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -259,6 +259,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. @@ -2498,6 +2504,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 Wed Sep 6 01:16:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13375229 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 2548ECCF9F9 for ; Wed, 6 Sep 2023 01:29:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.596126.929909 (Exim 4.92) (envelope-from ) id 1qdhMJ-0004zG-Kd; Wed, 06 Sep 2023 01:29:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 596126.929909; Wed, 06 Sep 2023 01:29:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhMJ-0004z9-HK; Wed, 06 Sep 2023 01:29:31 +0000 Received: by outflank-mailman (input) for mailman id 596126; Wed, 06 Sep 2023 01:29:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdhAH-0006tr-GT for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 01:17:05 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20605.outbound.protection.outlook.com [2a01:111:f400:7eaa::605]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1673d7aa-4c53-11ee-8783-cb3800f73035; Wed, 06 Sep 2023 03:17:04 +0200 (CEST) Received: from CY5PR19CA0013.namprd19.prod.outlook.com (2603:10b6:930:15::32) by CY8PR12MB8065.namprd12.prod.outlook.com (2603:10b6:930:73::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Wed, 6 Sep 2023 01:16:58 +0000 Received: from CY4PEPF0000E9DB.namprd05.prod.outlook.com (2603:10b6:930:15:cafe::f4) by CY5PR19CA0013.outlook.office365.com (2603:10b6:930:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34 via Frontend Transport; Wed, 6 Sep 2023 01:16:58 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9DB.mail.protection.outlook.com (10.167.241.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.25 via Frontend Transport; Wed, 6 Sep 2023 01:16:57 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:51 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Sep 2023 20:16:51 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Tue, 5 Sep 2023 20:16: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: 1673d7aa-4c53-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hb1YC71dWmYwfb1a3xolxxMDYaeNezVKWgfuxWbClIF2IFlUenHyuTW+zKe8MtmkVgVcJIXhUyNR5W/iXrvPZFyXoUCvXCQoZtiA6fiifUvQhrIlN0vVJFh6mBGa2Q7XAAceVMPRh1zoMTiinVUEDcbztpF9rjsgn9OLdOvtaIWC1yIJnQs/0F95vJQdBdNtn3LYga+/zzSaa0qu57jGA4DGEnDsNi0NEzmw/gtLJg2wye5DVUQOyFo5R/NMi47aMPIIM7Y5hTajN77Xh0wM8WxPCKw1ViFtcwXa7hpd6RXb7udIuUuKyDGc7+nnstvNU4pMI/+LSKe6iEkai1ACsQ== 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=0SOh4yXnAAqd95uGtVLNuRN1JoH4/9uDY70TgG5n3FU=; b=kAyIhe93y9ueci/hvUwQB/OarFTCkbKKRZ0VopB7v4VDN9uDOAac9+B9ZePmJ6WBRE1Yw9++XkmK7LOL3dWhlu3hVVoDj5EA7T0HRbwFYPy3csBj7Awp9SXDcK59M8VPqi+KqvlV82aIEziXfnmXHjJwC+pBsnyRamTYmtwjp+pdweSdMMyUf+3ZjvptLWP3wd0dmV+/TpCOJ14f9WYsTznO1G+KvoN0SAm37cVZn+barniUYB/D1IZu4ZpC7E8IqURBDaPh/rbCqBLDIwMoYJw2c17A2UCs+fcHDXifHUwCaCWIHklyMe9rX0FHKIQgBHFOTLgTlzwyEfNixTSAwg== 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=0SOh4yXnAAqd95uGtVLNuRN1JoH4/9uDY70TgG5n3FU=; b=PgNFZPcvkOTjdzwI22qm6s1v/KD6JMWl3BqAoupfdUeCgb4kmydIcSsB+xyiqZ4p6UYHSExZRa5XfOQ4yBRwmvzjhG63OcAiIOrRGEFocypQ9wFFO8dnf12eTLe0VrGpESWbrHkhBMs8OD+Eb4Qd6YGonVcdpFsSIVNCp3HVG3E= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Wei Liu , Anthony PERARD Subject: [XEN][PATCH v12 20/20] tools/xl: Add new xl command overlay for device tree overlay support Date: Tue, 5 Sep 2023 18:16:30 -0700 Message-ID: <20230906011631.30310-21-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230906011631.30310-1-vikram.garhwal@amd.com> References: <20230906011631.30310-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DB:EE_|CY8PR12MB8065:EE_ X-MS-Office365-Filtering-Correlation-Id: 9de38f9f-df21-41d5-e750-08dbae76f735 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OwAUQkkbGzQMyrvIUy0Mbn/RhRsaxwiQ/3OyEGRxrc1x55Rxr/mR6ch2OAIlGm7EUMpLdWXZeFUw6MNnmyRnqORA4pw6e1EPHPUrdLLSA+EmejkMGKGStrbIHr/+18LHlYaJH4Dku1pEQtDlEakifqmyv8JkhF4JWyLhco7HxnbhggAUjAX2u9Bbfwa9Yev2mg48koIAncmCqqMWo7uk8dQjVHjbCuAjsevV2nylSKDQ+OB8H/HwaYaFS6//m4+2MRlWRrjQz8uBSniAQ/ZdPtoMefvR5R+oYgXODUk+8AYWsRfLqQgyH7o/yt1lVs+wy9IpDzrCHQChSK1LnIzkJ8686WoG3gZFsfiibL+a2MvE4JYA0Zp3EotHBP8N1pgZ7NjZhweKP1PxxfLh1fzJM0/oL6rxa5cENvtckw4/ikIK34eWupIy9cZacKjqDF5CZ+5n0g+hAvuhhP0/AAmk1dwU8x+CPO35hNY4xt5pNPZzfNjC+RXSZ+UjwQ7sVtBQPcAMQ0Qp4E8ABJIFDlaaSeTMtIEhWShE7zfD8UYxNpi5pT428u3uf3p9Uv9T9NpkXKyo7uMKhoECV7YQ2J7HymxtsgUk9yT249obfI2LA6iQWoBRfrFkFbAUSnhBuqJAeNtBFt314txtzpPsFSDSg2lReI8Ayjbz9gyQgdmWdqAIUsGyV4PExQdybq9L3qm6g+4Z1bbWbkrfHF7i4AXbbX7KFJJ64xxCLGpdwWVdRbRCauaOHHVFcnSPEn+IfGnlc8xwvna6uE8gd8skOQUmsA== 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:(13230031)(4636009)(39860400002)(136003)(396003)(346002)(376002)(82310400011)(1800799009)(186009)(451199024)(46966006)(40470700004)(36840700001)(40460700003)(36756003)(40480700001)(6666004)(81166007)(478600001)(356005)(82740400003)(2616005)(1076003)(6916009)(316002)(41300700001)(54906003)(70586007)(70206006)(36860700001)(47076005)(426003)(26005)(336012)(83380400001)(2906002)(86362001)(5660300002)(8676002)(4326008)(8936002)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2023 01:16:57.8842 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9de38f9f-df21-41d5-e750-08dbae76f735 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: CY4PEPF0000E9DB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8065 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 67604e9536..2463521156 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -631,6 +631,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 03971927e9..cea5b4a88e 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