From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950620; cv=pass; d=zohomail.com; s=zohoarc; b=SRll+EsdzlbwWuw3TyM4TONQEYRmvMVTARAHBIYYMPiTywHXdAEeCrzTTBp9MZB/ZUzbeOnON+zH1fw9P/AmOAJh3ZM9V4H1c5+3KGkMHJ4hZ0iPqCfvntgOWF53EW9BFFSz5ODSaoCOU1aury3fnr07iMd7wMIxoxDxMZOcpeo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950620; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=551FbITUy/lX+UFAVwLYLGK11TzVaHOhuLFDvzMcrP0=; b=fAwzgdckQTN1GKU1tgfbikRQXRSgTjQw3wcevaYc4U1Z+Gy6ioR8DMF7AZQG90RQlJv7JuOuF+Mb+cBGn69d0oqktw1wRpObeUn2Ar3XDr8fP+vQbnpuR9ngdiw2D+yJUF7946SCp9HWlU0ziHyYw+RMLXkZ5yH088QUvXT5lkM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950620351759.1177118792859; Fri, 25 Aug 2023 01:03:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590553.922920 (Exim 4.92) (envelope-from ) id 1qZRmi-0000RH-Tf; Fri, 25 Aug 2023 08:03:12 +0000 Received: by outflank-mailman (output) from mailman id 590553.922920; Fri, 25 Aug 2023 08:03:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmi-0000Nm-Kw; Fri, 25 Aug 2023 08:03:12 +0000 Received: by outflank-mailman (input) for mailman id 590553; Fri, 25 Aug 2023 08:03:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmg-0007G4-Nj for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:10 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20613.outbound.protection.outlook.com [2a01:111:f400:7e89::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d3910c9e-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:09 +0200 (CEST) Received: from MW2PR2101CA0034.namprd21.prod.outlook.com (2603:10b6:302:1::47) by SN7PR12MB6741.namprd12.prod.outlook.com (2603:10b6:806:26f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:05 +0000 Received: from CO1PEPF000044F4.namprd05.prod.outlook.com (2603:10b6:302:1:cafe::7e) by MW2PR2101CA0034.outlook.office365.com (2603:10b6:302:1::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.7 via Frontend Transport; Fri, 25 Aug 2023 08:03:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F4.mail.protection.outlook.com (10.167.241.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:04 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:02:55 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:02:55 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d3910c9e-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nBCmLBnOjn7lWk/MC1zY2SZOHg+kHDx1OVw70bNVGABBnMb0oN0GhuIKPmR+hMw84KS5m+BUCJ8r5SmctUPxzlumJssQsVTBjvFd3vt/TlkarEz9XP/exJ1tPUM+b+wqvSGlTgC7x4N0TfJqJJ8RFuzGnxYOwuJPKSREXbMopRgrbe6Ojdi91LDJuBfsA82pX6/S17b1F25T/Jsq4I26e/GnG7oJr3tNEwfMUOOL+8Bm4q6QjQCcoidUrBJ6trE8FDdr2yUTjVcthcNUOLuBSJ33MrT9bd1w3Ka48yIRR96j3eYMtERy4TL5heGjNY5L4hKpEnkERV1tFM+L0P4yvA== 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=MDmCxmk7ELWq9ChnVqgxZ0lZlpdingdbmtaimrlP2vnSWO7mt5U7TvglCNOuv1l8k6lWI17pHmYvW1GAsr+IJAp/Nr9U3H9SLfewbRWhn2z6Y/dGs+h+7ZT5ZOgs17KdFCB5Q/X5wCdEonBnAftGRoO4q+AbWIZFqMtwrs6XRM0ez8lkw9sGZy540d4yxBc5ww3hHcHgK+XU1N6CSJuSEZDrqjw7/jEp6IPZyhpE7+IjOFeRN+J8CQtvDoPptfSai8gQG+28ukhVcQHpaagLR+WmKPCRecPdzRPL0KdJHaMPAql+Pvld0B2jvjfugpXjkLBHyX1qFJgs6U2SWOVUgw== 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=qPu4tragayB/zBNjGd+YzlfTi702XXTwdN2BwVUjoIWJsNde2hQPvp19i0sqzH3YAxOiu6rj8K5oFpdSGLXy75hjxuL5UoLfBqpHE7yn+3Bqjw0gojc3O4FP4l6zajOlY8OhZIijqL9q9YhSoFJCRO6zFqm1viFRlABXXjEfSUw= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 01/20] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Date: Fri, 25 Aug 2023 01:02:03 -0700 Message-ID: <20230825080222.14247-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F4:EE_|SN7PR12MB6741:EE_ X-MS-Office365-Filtering-Correlation-Id: 942ffa70-5870-42d2-03be-08dba541b5f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SQ4w+gZ24TKjXHRlyIpg25a/uYFQJlvyBN2NI0xbLubS/nJ8u6TaOxcxQCxyQDnMl7Vms0PCAT+6fR0F+7By/Bp8q4ASxHrnFTPIxBy+Hjp4PSM42wajjt2PDSRgK1j20pxlB4AYM+o+L2yGQoJ2WYjxQdrQVWeawAdaej2ogNztxufkXroj0LeEdtwfXufyWdg/iPiot2Rg857u88GgMqAgKKAVd0DpbRUeSyFynoUFVmx2tQeDetN9W+D79pvWCkYWLD7fmVuugjXI9ZySbabE1+xO6rvQY32APEKHfE4vQmbF0bGSii7XlPyB2lbWoGCooet8fvr7OB2JTUJj/aGGlxtWJnpRTzZPphgi0wwl/o0DP2a4Geh3nxJEdgjtI4+kwzjdUShfX03cxRYDsaDAQlDU4/gosETsF4KBZhryk8Wk/4OB3B3vKdY5055uuoxfKM5cSxM/Fj/gVadAC1Q0xTS60XCMKf/HwF7M8slbt5b5JcUpq6FcYydriOioYr6acfJQrr7Dzl6KV/lJlL8cHk6eCvAE50xGda6qxnGEy+6nDHVTkP9YNXdRZlLeYuRtvSI9Q2dNF6YuzqwURp/qixVVHUTYPgoGYH1zEqP9zftl6kP21sjRGmfoHZLPlZX9zuClCei2NKiZxOODIsK5/O6Af3bZSkOtxW6GDWWEMc3n27Tq8lQmZzr8su8OyOpSbHL0qxYK2aLRDGCgFbUHlinMfHBrFIW8sq31WUvz55OMzkZFOZeJCW6f+bxQTelEUsY5fimn6DaT9ZWIAg== 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)(136003)(396003)(346002)(39860400002)(451199024)(186009)(1800799009)(82310400011)(46966006)(36840700001)(40470700004)(36860700001)(47076005)(40460700003)(44832011)(2616005)(41300700001)(86362001)(36756003)(8936002)(8676002)(4326008)(6666004)(81166007)(316002)(6916009)(54906003)(82740400003)(70206006)(356005)(70586007)(40480700001)(1076003)(5660300002)(2906002)(478600001)(83380400001)(26005)(336012)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:04.5201 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 942ffa70-5870-42d2-03be-08dba541b5f0 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: CO1PEPF000044F4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6741 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950622206100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Change __unflatten_device_tree() return type to integer so it can propagate memory allocation failure. Add panic() in dt_unflatten_host_device_tree() f= or 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 =3D mynodes; @@ -2114,6 +2116,8 @@ static void __init __unflatten_device_tree(const void= *fdt, =20 /* Allocate memory for the expanded device tree */ mem =3D (unsigned long)_xmalloc (size + 4, __alignof__(struct dt_devic= e_node)); + if ( !mem ) + return -ENOMEM; =20 ((__be32 *)mem)[size / 4] =3D cpu_to_be32(0xdeadbeefU); =20 @@ -2131,6 +2135,8 @@ static void __init __unflatten_device_tree(const void= *fdt, *allnextp =3D NULL; =20 dt_dprintk(" <- unflatten_device_tree()\n"); + + return 0; } =20 static void dt_alias_add(struct dt_alias_prop *ap, @@ -2215,7 +2221,11 @@ dt_find_interrupt_controller(const struct dt_device_= match *matches) =20 void __init dt_unflatten_host_device_tree(void) { - __unflatten_device_tree(device_tree_flattened, &dt_host); + int error =3D __unflatten_device_tree(device_tree_flattened, &dt_host); + + if ( error ) + panic("__unflatten_device_tree failed with error %d\n", error); + dt_alias_scan(); } =20 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950605; cv=pass; d=zohomail.com; s=zohoarc; b=b+c2KYB6l/DldbR3vZhJ+1DwcWEJh1N6oA204eyjwpQzWYu7PVxJVPK98Tjc9iwDZdpx/rkENApTEQuqU1wLVtLlFuJG6KpaQhQhdzXSahSVBFPXwLQkVIl3s2Vt1/EGraRlwPxkI+2vtiOOZ3P//g5uePIM+YVGE+/QsaMGW78= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950605; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TvyzZKkKruBh4hcUgS0xB1M/ZVRIznonRnMXhEGKKko=; b=Ob2Mn4MEDFfFRzmU9xcxo25Aw6QCH69PVL8xZxzGY1ahKQHXUBgpOQICeZK67R5oMgtC/vrAbxJQsV4dTSMiBx2m4UiejgVz02F4M7MJ5aP0iSbSHZMMkijfrPxSBYGxD+WGntqvn/aej3HkffMMx/2tTqpmtpHvb/T2zLtbiOE= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 169295060543155.379382429816246; Fri, 25 Aug 2023 01:03:25 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590545.922856 (Exim 4.92) (envelope-from ) id 1qZRmc-0007HF-2h; Fri, 25 Aug 2023 08:03:06 +0000 Received: by outflank-mailman (output) from mailman id 590545.922856; Fri, 25 Aug 2023 08:03:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmb-0007H8-Vx; Fri, 25 Aug 2023 08:03:05 +0000 Received: by outflank-mailman (input) for mailman id 590545; Fri, 25 Aug 2023 08:03:04 +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 1qZRma-0007G4-5E for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:04 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062a.outbound.protection.outlook.com [2a01:111:f400:fe59::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cf165a16-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:01 +0200 (CEST) Received: from MW4PR03CA0055.namprd03.prod.outlook.com (2603:10b6:303:8e::30) by CH0PR12MB8579.namprd12.prod.outlook.com (2603:10b6:610:182::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29; Fri, 25 Aug 2023 08:02:58 +0000 Received: from CO1PEPF000044FB.namprd21.prod.outlook.com (2603:10b6:303:8e:cafe::6b) by MW4PR03CA0055.outlook.office365.com (2603:10b6:303:8e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:02:57 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044FB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:02:56 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:02:56 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:02:56 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: cf165a16-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lBOpXoPbVXKhhA9fvSvRPQDpLfTnQc/j2mT1T1cFfeHMFNpOhP0gJBEntm94K7+WcWQiY5xGcPtem8NS5vIA3gs1BykGxoodMow2z2BZqm6I8MqOPwWQqk2yg+Q4n/f46kVn4rf73LFL848EnclVuL/G8xv/h2LjZ2mCtpaYwckE97dVdPxR0hJKUBTqcu94Upk3iD8CJnchP6HAXs3+G5oGpsziNANxFeDazX5NZEm+VmHeP/EoNOGx2Onh19UFx6FZeOChiNdwEzJEkzB16RPbtsI5AwfHYsNRDE6i4FE2sUgmft00UmQHQNqXguER63rgKu3ZHOJsq71keORTUw== 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=TvyzZKkKruBh4hcUgS0xB1M/ZVRIznonRnMXhEGKKko=; b=D8sIOba4VEYzLXSpBIfSfUF0avv+xNqRjRB5RnMtl83nr1mWQiH+INv5PfB+Ite8LLD3bVD8bQmzjO9kqKqirMs0ft+3rbSccIMKCcOzsSSej+SfiX1LxaAw3/t+vfzBbiWIqVJcV2E/cfbubM3SYKTkrpx+D1cqtP25/VJp0kXXIlKUw9W9gv4ovFvRevQCW5e+WXIVow2XMJELT+syzAmSWVXKtQNj4byBgF1QbwDS+TXyNAVV1oyXcq17HHPLZaSnPCjWwi5sS6bCfJI8j0FaiHDu3eoi8iRvoSMilUgvWVRkIH5GCfUnu7E0eJJDY7tn2SEEVhqh9eJEr2y+kw== 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=TvyzZKkKruBh4hcUgS0xB1M/ZVRIznonRnMXhEGKKko=; b=Mf+rCflavkMxuB6E/HBkt2zLAo/0V4lnxc1DhzZ2InHLW+b/M77HwO1z4BVsB+rZkmsVQsCN0XU1TYXZqciNkmEncR2ctS+X+pjWypAdHQ9lvsANiL+wAyEwSk0ua6xXbf36sBANNPoUl9XuXPJdzw//f2ZSHmFYkbK6no9SZ4c= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 02/20] common/device_tree.c: unflatten_device_tree() propagate errors Date: Fri, 25 Aug 2023 01:02:04 -0700 Message-ID: <20230825080222.14247-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FB:EE_|CH0PR12MB8579:EE_ X-MS-Office365-Filtering-Correlation-Id: 27be0861-6331-4eb8-c6c9-08dba541b161 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7633raw/rY21lrYvW8KiPPfcqYi3gUz/Z2zNyZ5d/SXhDGvYg8amPgPdnKH4keKZCtbkUK7WMewNPSEpZ4FoIYPaoYFNNbz3g6K0jnwqxPmwJKCEdFcyY2qmq3WHKiecJFyG3tUvWCjli3wnuTAFkDgA22DQJwcKjI3LChn5oapa64A8DkJquGgcqXFG1VPozZ3wGUpiJ9Nsqh8ZbvS+4KMw2VtRkymGRf0YB3YI3Nr0cWnRlF/VjzxBQ72fR6KpVbFRvlCJwCTz10cjnIepZoD3fUBQ3MzOEGuTlmIEGSl83fqSZgl3EYauaZH4fPStjeg3fXGgMwt9Y9T9IlVfR9xrTu+VsxgqLNjO0Dm84duNZHw8xemLAi+jeO0sWEypX51x2K5q1hEyY4ju+J4Hwd3FNhGsj1/B4psbCKzdmxnjEkUMkLltxe9y6yCWrkMtNN7dh26Np1DXxyPIsT+vi5Hc9TvzpCcpWHo5/+11uZ62pL4spivnaBjjr5nxXmflFkrsIc5BgZS5jCXCuM7gwYFigVRthXArntCucX7T+HMSEHI6EK4S0/+O5hRBcaiUoUAhiZdmNex7vDKe0So4fAb+L7cwNZu3DqnzxiAgum3q6lb8ua8m4rHA95OaOdIRao3PvguJXJvN0RpDLqVCjz+uNKn6L7ZsprOJeyLQeat+7onKt8FPTd73ZnaT5B+KX5/ZNBJlFzj4Y38rmK58n7LhgCZqj5Pf8ZSbdT4eI3d3T5rhwsX2LXiwysjTHv7cEVNB0Ah2u1Q4jAiitAvkZQ== 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)(186009)(82310400011)(1800799009)(451199024)(40470700004)(36840700001)(46966006)(356005)(82740400003)(81166007)(40460700003)(8676002)(4326008)(8936002)(54906003)(41300700001)(6666004)(316002)(36756003)(6916009)(70586007)(70206006)(86362001)(40480700001)(47076005)(26005)(478600001)(336012)(36860700001)(1076003)(44832011)(83380400001)(2906002)(2616005)(5660300002)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:02:56.9083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27be0861-6331-4eb8-c6c9-08dba541b161 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: CO1PEPF000044FB.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8579 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950606636100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This will be useful in dynamic node programming when new dt nodes are unfla= ttend during runtime. Invalid device tree node related errors should be propagated back to the caller. Signed-off-by: Vikram Garhwal Acked-by: Stefano Stabellini Reviewed-by: Henry Wang Reviewed-by: Michal Orzel --- 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 =3D ((unsigned long)fdt) + fdt_off_dt_struct(fdt); size =3D unflatten_dt_node(fdt, 0, &start, NULL, NULL, 0); + if ( !size ) + return -EINVAL; + size =3D (size | 3) + 1; =20 dt_dprintk(" size is %#lx allocating...\n", size); @@ -2127,11 +2130,21 @@ static int __init __unflatten_device_tree(const voi= d *fdt, start =3D ((unsigned long)fdt) + fdt_off_dt_struct(fdt); unflatten_dt_node(fdt, mem, &start, NULL, &allnextp, 0); if ( be32_to_cpup((__be32 *)start) !=3D 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]) !=3D 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 =3D NULL; =20 dt_dprintk(" <- unflatten_device_tree()\n"); --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950613; cv=pass; d=zohomail.com; s=zohoarc; b=YM9y/KajK/jzMzYHaA8jipL2M6DP9AhR///aS57C53YyuMhcvUvmoeMgAP/xgyPcaIpVrAvtojlmFXBp7dBYpXmDzys/1rargQTMdFLW+Uw/SLGtuNodJqA0ZsCnemMflAo9cbSdSnDUQwy4yga2/5jelp3XMg63nkf9+EaJzGA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950613; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qW7oUZ/uYCJdDraRyDsuGjNHoONAmzK9QOZzGwOjFIY=; b=X2UZphgXd874jRw1TRpkwwyr3Yjvxr8Y6YLJkDcBWCoLYGe/yorT1jqa8p9D1T7q2Kgh8PqauqW/0LZ/sazvG0uwwriJ1uaHndXBy5EOw96ANISqWIfl37DX75O3b8yAM/YvF/pQ8L9/L7QfGuVXp+f1BWxBYWHVbeCO3JiWgto= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950613370881.3744460879044; Fri, 25 Aug 2023 01:03:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590548.922887 (Exim 4.92) (envelope-from ) id 1qZRme-00081H-91; Fri, 25 Aug 2023 08:03:08 +0000 Received: by outflank-mailman (output) from mailman id 590548.922887; Fri, 25 Aug 2023 08:03:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRme-0007zs-40; Fri, 25 Aug 2023 08:03:08 +0000 Received: by outflank-mailman (input) for mailman id 590548; Fri, 25 Aug 2023 08:03:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmc-0007G4-D2 for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:06 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20609.outbound.protection.outlook.com [2a01:111:f400:7e88::609]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d118f5ca-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:03 +0200 (CEST) Received: from MW4PR03CA0243.namprd03.prod.outlook.com (2603:10b6:303:b4::8) by IA0PR12MB7676.namprd12.prod.outlook.com (2603:10b6:208:432::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:02:59 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:b4:cafe::52) by MW4PR03CA0243.outlook.office365.com (2603:10b6:303:b4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:02:59 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:02:58 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:02:57 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:02:56 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d118f5ca-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SFU0voUFblOLV9zXFEP9dMzFaSm7YZljp2RbOATitpIZ/00iIQ0Y4Qq6pDt73gQx1nA5aA86dEf5eaR9i3OMSmsomVYwNOw84OIFv1f75pcl6HcLv+bjTMTjOgbykrzq/AKav3Es2qE9/6dbgTClF7K4X0ZORviGhTPvvYOYVOCpN43xJgd6eFQFVlwSQpfTWctcam5lDrkR5B4nnBqnx83sMeKj/8oEvpLX3UKdV3QnkMGl9lr8U7XnQtyMAD9pB8qalGPgrhSCLwTOezl4Q7JU/O3Yq6QR6xfmkFdx5fCTex6pEorXPIoATcQt1ZaPHnEZvw8fIkr0Bq/6gELF+g== 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=qW7oUZ/uYCJdDraRyDsuGjNHoONAmzK9QOZzGwOjFIY=; b=n7JsMggUSPM8nqKroEecEOVsk3zUx/l5S3q1JeGih4k9L9qwbsgsBfXS18NNED0DHZKAyQz6cNuQ6AMYhhcjD8oJN/ACjc2xVtSTBqGDErp/ShMFgzHaHic1nUocFK93/sHXLskROgyu5zA37wozNCt8CdBs6rCC8Sd16YNHA3XaYdJRCmtsbVKzQ1phZuDSDPrCNbIBiQc9pwcgS2yuQJYThPV54jCykmiErdZQIufBxu0ZWJsUtSb7LnuqNz5YRlxjACcHpQirn/hErzpyCwjtRkXQwsyzzfpGrcN2Wo7KpUWWJ72bKdisa9BEIHSgJCy1pQjWXlTJjUFDoGQEnQ== 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=qW7oUZ/uYCJdDraRyDsuGjNHoONAmzK9QOZzGwOjFIY=; b=uyKxc60diGsNY1u3qd26k+BgThL0jFcAQZD1zapFKEg0WjqGdqL/AirJqEoS9jP1Y1W4wBIOp9VmKNe9Ldf1YTU4Z0bAWgtwT3lu4lkf0iBXrmgmVppJjGzbjAcSGlrf5Wwjj2vxKiDZxhdxTDzW/iQQiPo2xxhZyUO/DLTDunU= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 03/20] xen/arm/device: Remove __init from function type Date: Fri, 25 Aug 2023 01:02:05 -0700 Message-ID: <20230825080222.14247-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|IA0PR12MB7676:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b4c4559-7063-424e-7428-08dba541b27e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QIftDperJGxZJXYMcQSYfEjdEOqH97++2vrqU9wHclyysw+JB3VeaYYIpmieFrHosc855d9l5oWxQC7O496Irf1AEp/vQ2Hs04xu8b8GCf+40v9wX860gyPdzcb/xNXoF1mJ0ZFS1TP6aRRKUrzifTXxKHaPJlqzeSfvvtAM/Pyda8RSjIv7KuSLfWWfznlUEzkaJOtNNORrskXWyjhZtAp0U2wQwNhbRSHlkqJspknVMHZlxtr3PX/GdN4tCRyddgULyR3zDDYC0WzsrhoZqINr6k1AEtxoaYb4CFc+WNU3Uv7umC3racPkIb3RZ8CxnbCZ6H93g+Kg0jHkhEDIFqLiwt8xk9g2Emw7OLsAh/GhbszPykG4kok5H5tMghYPPCFIxG4S6/gSClELJti3lm5/AQLaYH0Sa3XQq3c8fxHAWg3HtofC9dwu0Fcv68APxHHW0jhwlLTAnARFWn6U0glMx1Zqxq+2pxFK6VND1M79HtlMTj8cfrjK6aSYkan+HcCt57K3DcK8VLk2JlMemxO4A/H/9sRMf7AR0NwFs3/AO9ZUAfV7dcs7oEb4z3bpGjWj5Rm9pdn4AsMA3M20OYXz7FUDyR3mUxH2pBejXewKJQhOgyRlWQXoR1VLGqQmO5EtraLDh70gjVth1JzWLqMbnfGVoK+7srJBptEclbpih3EQWfjSQ4YxoAORQRR04dJJphDlVjwjwMbIt37ROV/cZLAUkFtQX7SITAwqMLrO0sF0G7ZU4JUQvV1PCfJGRYj/vtsKLKP7rxzMy9ACTw== 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)(376002)(39860400002)(346002)(136003)(1800799009)(82310400011)(186009)(451199024)(36840700001)(40470700004)(46966006)(2616005)(40460700003)(8936002)(8676002)(83380400001)(4326008)(5660300002)(30864003)(336012)(1076003)(426003)(36756003)(36860700001)(47076005)(44832011)(40480700001)(26005)(82740400003)(6666004)(81166007)(70206006)(70586007)(54906003)(2906002)(6916009)(316002)(478600001)(356005)(41300700001)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:02:58.6802 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b4c4559-7063-424e-7428-08dba541b27e 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: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7676 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950614729100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 don= e: 1. Move map_irq_to_domain(), handle_device_interrupts(), map_range_to_domai= n(), handle_device(), map_device_children() and map_dt_irq_to_domain() to device.c. After removing __init type, these functions are not speci= fic to domain building, so moving them out of domain_build.c to device.c. 2. Remove static type from handle_device_interrupts(). Overall, these changes are done to support the dynamic programming of a nod= es where an overlay node will be added to fdt and unflattened node will be add= ed to dt_host. Furthermore, IRQ and mmio mapping will be done for the added node. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- 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 | 293 ++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 293 ------------------------ 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, 308 insertions(+), 301 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..857f171a27 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -9,8 +9,10 @@ */ =20 #include +#include #include #include +#include #include =20 extern const struct device_desc _sdevice[], _edevice[]; @@ -75,6 +77,297 @@ enum device_class device_get_class(const struct dt_devi= ce_node *dev) return DEVICE_UNKNOWN; } =20 +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname) +{ + int res; + + res =3D 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 =3D 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 =3D data; + struct domain *d =3D mr_data->d; + int res; + + if ( (addr !=3D (paddr_t)addr) || (((paddr_t)~0 - addr) < len) ) + { + printk(XENLOG_ERR "%s: [0x%"PRIx64", 0x%"PRIx64"] exceeds the maxi= mum 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/")) !=3D 0 ) + { + res =3D 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 =3D 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=3D%x\n", + addr, addr + len, mr_data->p2mt); + + return 0; +} + +/* + * handle_device_interrupts retrieves the interrupts configuration from + * a device tree node and maps those interrupts to the target domain. + * + * Returns: + * < 0 error + * 0 success + */ +int handle_device_interrupts(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) +{ + unsigned int i, nirq; + int res; + struct dt_raw_irq rirq; + + nirq =3D dt_number_of_irq(dev); + + /* Give permission and map IRQs */ + for ( i =3D 0; i < nirq; i++ ) + { + res =3D 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 !=3D dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller. Connec= ted to %s\n", + i, dt_node_full_name(rirq.controller)); + continue; + } + + res =3D 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 =3D 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 =3D data; + struct domain *d =3D mr_data->d; + unsigned int irq =3D 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), i= rq); + return -EINVAL; + } + + /* Setup the IRQ type */ + res =3D 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 =3D 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 =3D dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); + if ( ret < 0 ) + return ret; + + ret =3D 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 =3D !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 =3D { + .p2mt =3D p2mt, + .skip_mapping =3D !own_device || + (is_pci_passthrough_enabled() && + (device_get_class(dev) =3D=3D DEVICE_PCI_HOSTBRIDG= E)) + }; + + naddr =3D dt_number_of_address(dev); + + dt_dprintk("%s passthrough =3D %d naddr =3D %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 =3D 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 =3D 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 =3D handle_device_interrupts(d, dev, own_device); + if ( res < 0 ) + return res; + + /* Give permission and map MMIOs */ + for ( i =3D 0; i < naddr; i++ ) + { + res =3D 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 =3D map_range_to_domain(dev, addr, size, &mr_data); + if ( res ) + return res; + } + + res =3D 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 39b4ee03a5..63ca9ea5fe 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_inf= o *kinfo) return res; } =20 -int __init map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname) -{ - int res; - - res =3D 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 =3D 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 =3D data; - struct domain *d =3D mr_data->d; - unsigned int irq =3D 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), i= rq); - return -EINVAL; - } - - /* Setup the IRQ type */ - res =3D 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 =3D 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 =3D data; - struct domain *d =3D mr_data->d; - int res; - - if ( (addr !=3D (paddr_t)addr) || (((paddr_t)~0 - addr) < len) ) - { - printk(XENLOG_ERR "%s: [0x%"PRIx64", 0x%"PRIx64"] exceeds the maxi= mum 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/")) !=3D 0 ) - { - res =3D 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 =3D 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=3D%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 =3D dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); - if ( ret < 0 ) - return ret; - - ret =3D 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 =3D dt_number_of_irq(dev); - - /* Give permission and map IRQs */ - for ( i =3D 0; i < nirq; i++ ) - { - res =3D 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 !=3D dt_interrupt_controller ) - { - dt_dprintk("irq %u not connected to primary controller. Connec= ted to %s\n", - i, dt_node_full_name(rirq.controller)); - continue; - } - - res =3D 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 =3D 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 *d= ev, - p2m_type_t p2mt) -{ - unsigned int naddr; - unsigned int i; - int res; - paddr_t addr, size; - bool own_device =3D !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 =3D { - .d =3D d, - .p2mt =3D p2mt, - .skip_mapping =3D !own_device || - (is_pci_passthrough_enabled() && - (device_get_class(dev) =3D=3D DEVICE_PCI_HOSTBRIDG= E)) - }; - - naddr =3D dt_number_of_address(dev); - - dt_dprintk("%s passthrough =3D %d naddr =3D %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 =3D 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 =3D 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 =3D handle_device_interrupts(d, dev, own_device); - if ( res < 0 ) - return res; - - /* Give permission and map MMIOs */ - for ( i =3D 0; i < naddr; i++ ) - { - res =3D 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 =3D map_range_to_domain(dev, addr, size, &mr_data); - if ( res ) - return res; - } - - res =3D 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) 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 =20 -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); =20 diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 19dc637d55..1a052ed924 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -165,9 +165,18 @@ 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); =20 +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t= p2mt, + struct rangeset *iomem_ranges, struct rangeset *irq_rang= es); + +int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, + bool need_mapping); + int map_range_to_domain(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data); =20 +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname); + extern lpae_t boot_pgtable[XEN_PT_LPAE_ENTRIES]; =20 #ifdef CONFIG_ARM_64 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_devi= ce_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 ***all= nextpp, - 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 =3D NULL; --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950607; cv=pass; d=zohomail.com; s=zohoarc; b=oBnT7l+Um23SFEYA3jR5wV+Qbr/nbVv9ZmHFx2A10qeKrEbgsxHDivt6UUaEXS/du7JLs4WkdoqpoVSu9VHLneIwTLmBHeqK/A3QAOpJYjybOL948Nh8SR+hJOUjaYIX04uJhGiriaxXlxl3oSUixVmLSXIUh31XnEkM+Sb9z5s= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950607; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N48gpSlC0ul9Dgr5X4IgXaGnFeuJhzDtng9Ayqa//1E=; b=BB1eEQOVCCGrCCMrJkVTAWtPfv3x1QeCYR7TjeH9QLe78JToWpDI2lrMO0xPGp/VvH1flV1uD/nBNiz99so8SDyWutRzJJSGvNdls9ZjxjKWB2+H1dUAfY8rm2hnT5gJIXVQ4WResMVTNKJpiP8YSdWJjrvD4kDXXbxPj5cbGlA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950607197784.6105867034071; Fri, 25 Aug 2023 01:03:27 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590547.922869 (Exim 4.92) (envelope-from ) id 1qZRmc-0007Sd-QJ; Fri, 25 Aug 2023 08:03:06 +0000 Received: by outflank-mailman (output) from mailman id 590547.922869; Fri, 25 Aug 2023 08:03:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmc-0007RB-Jv; Fri, 25 Aug 2023 08:03:06 +0000 Received: by outflank-mailman (input) for mailman id 590547; Fri, 25 Aug 2023 08:03:05 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmb-0007GZ-6u for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:05 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060e.outbound.protection.outlook.com [2a01:111:f400:7e88::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d0a40d40-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:04 +0200 (CEST) Received: from MW4PR03CA0037.namprd03.prod.outlook.com (2603:10b6:303:8e::12) by IA1PR12MB8496.namprd12.prod.outlook.com (2603:10b6:208:446::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:02:58 +0000 Received: from CO1PEPF000044FB.namprd21.prod.outlook.com (2603:10b6:303:8e:cafe::f6) by MW4PR03CA0037.outlook.office365.com (2603:10b6:303:8e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:02:58 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044FB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:02:58 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:02:58 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:02:57 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d0a40d40-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CgumGq9aZCLCsioaDumg9l1ra1WH63XNss7bY8kPvTXG22l0TOwp/q3jWnHJbFPD2mG9YdxxxPDyBHmjo74mfU06S7Fz/sdMVOopAYl5UowekfoIYnJCN/9rj7lLB6ZRvXzuAJgcsUfi0HQkOSkhdajfNZepnFGBL8/BHD3ol4TT8nq2mKf7J6NdRJuff8De6DUC/mh+3QPiJeIzZVQ0lqgkeclvekN309O8ryx5y89BoajL47BraBg9NDEE6ctqHo3ePNqFI4gsP7J0d9bfDSMfn5S2CEEjCFVLEdnS3wSqyWE6oJRioVEpjWuRRpYx64Y1x443V9vtxFC97jYvxw== 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=foEjyy0NPEwpDfiwJw/N96j6IlrTtxty8iW7Xb+vfjGZMVLKKLIt90jr0vzSSTXEJP8JRx6g2mo5YnlU9jMg/Z0A8ZFqU5AiciuY+AmZMRdo0S22VLf8+I3Q0J2OAvfJATU+A+kA20rkNCvlM0Ojh+tKR7rEFIHxqqzsTWtnH6s7rryKbFFAfRQpTUC7mzyAK5hR7x3Cg0G1KT4jEGYmdqzj3Rjw3m4Y1iFnqkdbbIMmMZKD/X6p82iwKEKL6RzGmBc4YlwKvcs7Dkt7gOyY07FoxsAMFySSEwOWPZvh8MgHKhanO89GncIP5fZgZoqfTJwi2EwBefxqPpBF26pEKQ== 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=U5lQyWoIPj714eCMMBBWlHCbVtlrHEUTzdlS4upIGEsQfYZPzscuTcRyxZZ6Voin52grovV4qrBKSoE+KvAV2nq0yTaouLUuDFhsWvOX58rktslRLEJuSzLCa8ew4/bImsy5MKOqqoVa6Lu3CrVO3lOMXZOwV3SjrvhcAAQpzcM= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 04/20] common/device_tree: Export __unflatten_device_tree() Date: Fri, 25 Aug 2023 01:02:06 -0700 Message-ID: <20230825080222.14247-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FB:EE_|IA1PR12MB8496:EE_ X-MS-Office365-Filtering-Correlation-Id: 537abbab-683b-413a-1e03-08dba541b25c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QYjgEMkYOgrV7ptUCqmB/PJckNRAgoc8nhwvUqlAwkBtBTTNUCxcq7ZWs1sml+4+rn2C6DdBysmzPaw9gp0uKf0RTBHN1msq3BrJvEFg3uQtYgxsTs6sCDVNlf3YUaU2uCJw002jOLmVnG8yTf16b9ViR8VhhhYAKMv/+kDk7exfaIy0vLmE4LvB0zlOri0cnc6nKhPbpXNeRZz+mruSUFBqpHDiaOLxdtbs4d/fwKnF74++CSIdHEmjQJe9IXaKa2CAd9LKnxusnNAhIgbV/HqiBHSGQfR9SRoZm558a4tWI/u8awthhiIt8GVy4aFGp+m5kKckziXWH3ro7QNqKS5H4wJgWkjS0riBYfnxxAu6ShdHAgpqCWaQmnBc/n92ycf3lV6Z0kzB3SNss5OTyGDaj4MG+U6RECmKd0wcUPP7VBahp6zOLjbukYB2gl4d+bOusLtUSIQrYjHJc3wX+IUT3HgKPTH9HIwIE6m33noYAF3ualORpcJ7pMZ+agJSokx1Dxwv8TZL1MmG/mn4wQqikg3mdH9R6kZaJE1qo0AOX9ig3isaXwvQty4eUZH9g1Q1LYXFF5vIF772eI5ZYJcGPTI89h3DjG2cTjIMMxQbDza3yD3/Sir/8JPu2nRxRm3EKzibQ5UwriYcl8EpG5Qu+FjwHxQujJkI2NR9Xo+lxasjfL8QZ8bk/qRTGi737UvSeIJyntuSiLPRd/CPeOEBhvsHSDnbPUmBtliqbhjgXDMkos/4EA0BIViUm7q/9JZVlf6UxVc7FA2u5BcAlA== 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)(39860400002)(136003)(396003)(376002)(186009)(1800799009)(82310400011)(451199024)(40470700004)(46966006)(36840700001)(54906003)(70586007)(70206006)(316002)(6916009)(81166007)(478600001)(40480700001)(26005)(6666004)(82740400003)(41300700001)(86362001)(2906002)(356005)(4326008)(8676002)(8936002)(83380400001)(2616005)(40460700003)(5660300002)(47076005)(44832011)(1076003)(426003)(336012)(36756003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:02:58.5489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 537abbab-683b-413a-1e03-08dba541b25c 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: CO1PEPF000044FB.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8496 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950609517100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 program= ming 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 *f= dt, return mem; } =20 -/** - * __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 =3D mynodes; @@ -2234,10 +2221,10 @@ dt_find_interrupt_controller(const struct dt_device= _match *matches) =20 void __init dt_unflatten_host_device_tree(void) { - int error =3D __unflatten_device_tree(device_tree_flattened, &dt_host); + int error =3D unflatten_device_tree(device_tree_flattened, &dt_host); =20 if ( error ) - panic("__unflatten_device_tree failed with error %d\n", error); + panic("unflatten_device_tree failed with error %d\n", error); =20 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 nod= e, */ void dt_unflatten_host_device_tree(void); =20 +/** + * 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 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950628; cv=pass; d=zohomail.com; s=zohoarc; b=lq/QykXWfQizHmHKKkfVmlSVlqlpPRuS9ipcnHD/nVxYQu2nBY1Qoar8Ay9nmZ2dsRLz8uFWVJ1QZgz5d7XD/SmJ8ujOwzG1YE59JRttRUdr8kaZYVuFh+LrYijPat31LfnrB6bTZ7ApMsSZ0AtJZ741m3DwtEEV9l7U+Nm6Byk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950628; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nKGY0SzVAnGU2fYrb6mmbdoZbAtWP+ycGZ0v+ZHO7vU=; b=HAgpkUZnOSv16Bgy+YoBywYzWSmCHlRWpQUGr8LX0YYoLd+DEADQylvwqiv9Itev7Pj7sJaHbHUED9ne497SHj/D0dGSzGYtW+i+Llkmj6FMkbXi5jp1D3arYwRp83NxX9FAfyGiVDFwQ+eh8MYcWiCWC8pvxaMvIaLKzsE7AF8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950628804487.80494810278697; Fri, 25 Aug 2023 01:03:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590552.922915 (Exim 4.92) (envelope-from ) id 1qZRmi-0000Ak-97; Fri, 25 Aug 2023 08:03:12 +0000 Received: by outflank-mailman (output) from mailman id 590552.922915; Fri, 25 Aug 2023 08:03:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmh-00008K-Lm; Fri, 25 Aug 2023 08:03:11 +0000 Received: by outflank-mailman (input) for mailman id 590552; Fri, 25 Aug 2023 08:03:10 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmg-0007GZ-F8 for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:10 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2060c.outbound.protection.outlook.com [2a01:111:f400:7e8b::60c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d4a91944-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:09 +0200 (CEST) Received: from MW4PR03CA0264.namprd03.prod.outlook.com (2603:10b6:303:b4::29) by SJ2PR12MB7918.namprd12.prod.outlook.com (2603:10b6:a03:4cc::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:03 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:b4:cafe::f9) by MW4PR03CA0264.outlook.office365.com (2603:10b6:303:b4::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:03:03 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:03:03 +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; Fri, 25 Aug 2023 03:02:59 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:02:59 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:02:58 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d4a91944-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n67aMB/jNGb4O2l3h0DzFCtBu4gaimzVYooU90TY2wRtXYDx/Nu6OFwxwOqFFU4t7QLtr9yiLiTnrQEk6yNYd5qC6ccJTyT6HTmJ9wCnUg69EcS8a1Fn499Erjn7fB/qMbmuo9aSuEZ5XNrUB6jUBTew1vVrVGWVSmBOiq/rV1t34tjsu0kLujgBcKuyATK6MeXiTnsnQG9xp0O8jgmju24upDwQgi9POBF7HRJEJbF7fLZQxO6ePeVsXOwvMaF6gqvuJ8odB19deWMAUFNT1pqwNLzgUTpSu8e53QFg9uFiBiqZpcNEAD7vVxG8chSEQJjGtoHNU7QWgBpAyw34Hg== 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=nKGY0SzVAnGU2fYrb6mmbdoZbAtWP+ycGZ0v+ZHO7vU=; b=iQAoSBrG+qYyXn1vK/AO2zbtU199auRrroGKyi4Wfc9BGn6qt9lV2XBnBd/1uo8UbmOe+k9SyDg/Fr0vfEuBZSIzxqV9gklTMpxpCgBGW3nxUCPAHoeeF8Mp5FijiFkr7nJlIZF5X3oQpO7uMFXp02Dtlzy0MI/wXwXYlzZMZifKdu+h1/R9cKIKDnt3eERTB+CCBui2tAHD7cidncvp4Q8vv3v9VPF8pODc6ZEbVUBaVZeJtcnvnyrwwykOehgNVSl7lhDkTbYCCc9pGIf7INJ9+WFQK66EvSySrPfFYBwbBFACNGY9Oxcurz+FzVeGsFdwUVPnmKUivTTMtLdInQ== 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=nKGY0SzVAnGU2fYrb6mmbdoZbAtWP+ycGZ0v+ZHO7vU=; b=Bp6Sk4PPdkFV1WQA5qAi896aPv2DqeM/+9VFr91IOM4TdpqBJolzelos4R3ZH7f+IRCZ28WdbUsGitThHVYwhf4eGO+gh4vmPIDDOrDwBJoC0zA/HF1Mqjs4nH2b/ylq8BUqgfX1SFvo/bzltdBgh5fBHfqEqIdLqxWTUSRXK84= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v10 05/20] xen/arm: Add CONFIG_OVERLAY_DTB Date: Fri, 25 Aug 2023 01:02:07 -0700 Message-ID: <20230825080222.14247-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|SJ2PR12MB7918:EE_ X-MS-Office365-Filtering-Correlation-Id: 8dae1290-8fb8-4e49-b57b-08dba541b549 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MSoVzKIgJKPR6vfmmJjgA2L07q+ktwg5RO7INS3bLDm11IYK3ji8+jrE5ii/V5bd8XNGkISBDqJExPXC76tQMBxUOBMnUwnAyckUD/6Y6EkwYt//CWP2z40l3Nv8mg5no3uofUAjWmb9X6iQ7g8RFrzfZjBAtRkkCOK5yvBrux53I/bB4YNOj3gTkLOq2eRicvMevrWq1GWymxu3PfdWL/cd0+m7jpNkixkFb2dJEnFoH3Jnvp1RhFIKuVg+m5bJKWQgFQ/FIqvFOPUKwWrz1InVps+NpbOeAXCulbFP2tITxz69LFg1lz6+g+4yChrrdKfS++RJU5rWKfkcHb95BzXSS7Y5cFhS1F2hstuduybOwJ3fQ53Nt5MWD+XTdQTJrek4CAQrHyUM5JUd+wDnQWRdckAvidllsDO837YyHDcTloeQ3rTnEj48QE9hKhtpT/W0YGtMpFO1sJofx/Q1FAss4ixwOm3v0CXcDM29nN5/2B2ste4k1X2mwx6OA5+ruw3/+alnIxPotmR2CpGPi56aWGDlxXjzNRHHE8NfpmA2guw4McYLF0yJR+z16ijxjSkjDw84tTSJG/SnEKmzIYZ524Y6ojl2zAQOn1WsUwWCfEKZRkv/MWEuyfU2InKxvJK5/chsZt0q9niPuAjpqLOFe+cdMRM7HWCTj81FdfqjPmE7ZPcb65/RMMWV89EZgCUJU3WrG6fHTPWMZvIdQQmqk6y61NMegri0vrWB17i9dP2+Xi1Te6tgxXRpv72dhqV1EqFM1MViJQ1nFpQjWkyVECgWgBYOiO0X6E4kUm4= 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)(346002)(136003)(396003)(376002)(451199024)(1800799009)(82310400011)(186009)(40470700004)(46966006)(36840700001)(356005)(82740400003)(86362001)(81166007)(36756003)(40460700003)(478600001)(4001150100001)(5660300002)(70206006)(316002)(6916009)(2906002)(54906003)(4326008)(8676002)(44832011)(6666004)(8936002)(70586007)(40480700001)(426003)(336012)(83380400001)(26005)(36860700001)(47076005)(7416002)(41300700001)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:03.4458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8dae1290-8fb8-4e49-b57b-08dba541b549 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: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7918 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950629297100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a config option where the user can enable support for adding/remo= ving device tree nodes using a device tree binary overlay. Update SUPPORT.md and CHANGELOG.md to state the Device Tree Overlays suppor= t for Arm. Signed-off-by: Vikram Garhwal Acked-by: Henry Wang Reviewed-by: Michal Orzel --- Changes from v9: Fix style. Changes from v7: Add this feature as "experimental support" in CHANGELOG.md --- --- CHANGELOG.md | 3 ++- SUPPORT.md | 6 ++++++ xen/arch/arm/Kconfig | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7e0590f8..f6f4c351c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,8 @@ The format is based on [Keep a Changelog](https://keepach= angelog.com/en/1.0.0/) - xl/libxl can customize SMBIOS strings for HVM guests. - Add support for AVX512-FP16 on x86. - On Arm, Xen supports guests running SVE/SVE2 instructions. (Tech Previe= w) - + - On Arm, experimental support for dynamic addition/removal of Xen device= tree + nodes using a device tree overlay binary (.dtbo). =20 ## [4.17.0](https://xenbits.xen.org/gitweb/?p=3Dxen.git;a=3Dshortlog;h=3DR= ELEASE-4.17.0) - 2022-12-12 =20 diff --git a/SUPPORT.md b/SUPPORT.md index 35a6249e03..8ec272eabd 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -844,6 +844,12 @@ No support for QEMU backends in a 16K or 64K domain. =20 Status: Supported =20 +### Device Tree Overlays + +Add/Remove device tree nodes using a device tree overlay binary (.dtbo). + + Status, ARM: Experimental + ### ARM: Guest ACPI support =20 Status: Supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index fd57a82dd2..02c4796438 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 UNSUPPORT= ED depends on GICV3 && !NEW_VGIC && !ARM_32 =20 +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 =20 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950629; cv=pass; d=zohomail.com; s=zohoarc; b=nF4Hnge0FVBQC/a6PAVh2B09yIFrL3fffCyC6DCKYz1KgfoTPCPdYFLj6PB+ILfNdu832E17l4W4GfaWAwje7aqz7FUIc1/woQ7IiKtiJof088lBUFjzIqHI7Ffn+phwL7ttmLsjq97KfeYtVinXDVImnLz7cR+Tpd/sWGhMJ3k= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950629; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+aOH8wbfxJ3CDB9n8z4otIPVVDXaY3ZnHxlpPeTlbO8=; b=V8qQ2/0H6EhWARpeSGCIXZ1QxvqCybYXY7BcPYcyMQMQeLDkfh2hD9UMJmsNrBGzXDoqFi7Qk4Ksu7AqSB5HFgE+/oQFk81OtB6pnxUJ0vZg/GklCe505g5vSy9IQTwlHQy6cegHYE3CTouOqoBFkptwB69hhOwVHr2dkHDLaUc= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950629097674.1157391756071; Fri, 25 Aug 2023 01:03:49 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590557.922950 (Exim 4.92) (envelope-from ) id 1qZRmm-0001Ff-3v; Fri, 25 Aug 2023 08:03:16 +0000 Received: by outflank-mailman (output) from mailman id 590557.922950; Fri, 25 Aug 2023 08:03: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 1qZRml-0001Dn-LG; Fri, 25 Aug 2023 08:03:15 +0000 Received: by outflank-mailman (input) for mailman id 590557; Fri, 25 Aug 2023 08:03:13 +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 1qZRmi-0007G4-Ua for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:12 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060a.outbound.protection.outlook.com [2a01:111:f400:7ea9::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d58f77b7-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:11 +0200 (CEST) Received: from SJ0PR13CA0207.namprd13.prod.outlook.com (2603:10b6:a03:2c3::32) by DM4PR12MB6206.namprd12.prod.outlook.com (2603:10b6:8:a7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29; Fri, 25 Aug 2023 08:03:05 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:2c3:cafe::aa) by SJ0PR13CA0207.outlook.office365.com (2603:10b6:a03:2c3::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:05 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:00 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:02:59 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d58f77b7-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dKislC23qUUQRL2Vr8JOs7s3LAf0PG1xd6HaS59cjNWzdNT9wGWIQBcrLNTcwnjvgoQqtlGyBTWJEhrxoasHaqVjrxPWDo6ctkULvYAt43JgMUlD7qJkyPkLdiMhzHI7V+6zsaF8JlhffIsWiFo//SfgmhIUPJL/yy6DFdsYviJDj9Wnp9AuzVYgNnF+yDosXSOME1d7YXow8GNOM6N+VKvNl4oEYK6DI9Z9yPtxjHgamDYzJbibdRbEx7UetewkAellAcYg4GCOUYJxp6o97Lu7ZBun/ZOp4Vw4eVEGWzsgZf2UUk8CCt7QENHxFaTJko59d4HXzChwfFCCvw+shw== 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=lKwP13yn/5bUO87KwHcKBlEV84uIV2FapQ9uACFshvhyysF8EdHz/InJeHb2QTs4yHnn3Ns/WrvO9cIZVImF9X1WE4HgPoHTPbGvNnhinOyVmz75OxYwhBlGGIvCatg1i5PIl3NxxFyhdzbusFGdsDEJdo48l9Jq4Rm/Jt1QILDRvy0ZKlUjmeawgqtRgSg15biLdDAhu8G/pTJpKV4oVN9DONJnycPej0ILYNdU+5jYqXIrEjVhdAPrYEGYfvcDzIxplNcyvwcPRblTuRI0x1JpZu+4Sb5eKvoFQ92UsgzCq++3yxfM8/jcaGYZQ0Tc/l1aNH9hw7lG0J6Bj7y7lQ== 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=kTqr/MSGDC2yAdHlqRbyolTivQ3SuOJcvfa3Uh5K85mh8S56vbFPBrpQnYJUHrdajQD1Nt5pQZlobZsZUdXooaGqc/XFgjvjFj3Vjv7LSRWtC+KSUSENs7apuvzwx5CGb2TRJocwsG1+OQQJOhiPwJDTelXGjdJSoG3R79xXmcY= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 06/20] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Fri, 25 Aug 2023 01:02:08 -0700 Message-ID: <20230825080222.14247-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F5:EE_|DM4PR12MB6206:EE_ X-MS-Office365-Filtering-Correlation-Id: fe5d618e-bf27-494e-6d0f-08dba541b660 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JOi6MCIzvT27J7jf3vQElEY2nG7J9611Ixiq2ORkMOyuuV+ucUfyaV/9JcngEacTvQXaZwHQHg/+P4w6MG+uivuJ/CV3EJ5KTr9URIz5RUShm2oZeaczxInxQ9LONrwnL+UbvcBTlQopBwvMLxDEpl3O99E366cqOJ3tah0hXY6T1dLddpf4EO3nbNFioaamNDOo8JObyjwxxCfayKrll+RElqNy/xEBz2+LGW0Q14CrNekbPi2vmodXINy5t0OLwO/tuQF7lrGov/42w7t8Qf6CKDs2OGP94nuDdLCM9mKG9A0ZCcVn+L11LyS4JiQB4xmOJeI4IWsAunlATIxMMYVWJarxXmfTC1mElKmVwrfpPgMcLrCOk81RqQQ9p81uITnwDx/R0t0ecX6COreLAuz4HZAAtRKdYEDXQYgi185oa17DJ69F0eS3KcxiWh6HFwKVZxg82j/NcTcCnJVu/4fMyGftim3zVHxJQ5gtbnQ+7v17ZevOyQuEr7irdsrRZoId/qXTBFL4eo3U96Ws/UFK/cc35McFstLJ6OQhmM+EKcqgjz79FREJErCMBMjmOE/3b8GJmb1vGhfYzejjCiIP27Kwi7p14qq3IWJBQ9f621N1QivRbvgHC5mPxDcJ9oVgJrs1a6SRaDwxuslYP0JvzjEYqBJciOVBqB3fgNdqXWID3BO91z9eeZXbUf6e7yfXIyPbANN8xlcddXji58MVxJ7UnjS66GrsQmmvhmBrXRoBPNRd6urdVTS+g7xJJPJrerh1mRTqRBzt2kdQTA== 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)(82310400011)(451199024)(1800799009)(186009)(46966006)(40470700004)(36840700001)(82740400003)(81166007)(356005)(40460700003)(8676002)(4326008)(8936002)(54906003)(41300700001)(6666004)(316002)(36756003)(6916009)(70586007)(70206006)(86362001)(40480700001)(47076005)(26005)(478600001)(336012)(36860700001)(1076003)(44832011)(83380400001)(2906002)(4744005)(2616005)(426003)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:05.2568 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe5d618e-bf27-494e-6d0f-08dba541b660 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6206 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950629976100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is done to access fdt library function which are required for adding d= evice 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 =20 SECTIONS :=3D text data $(SPECIAL_DATA_SECTIONS) + +# For CONFIG_OVERLAY_DTB, libfdt functionalities will be needed during run= time. +ifneq ($(CONFIG_OVERLAY_DTB),y) OBJCOPYFLAGS :=3D $(foreach s,$(SECTIONS),--rename-section .$(s)=3D.init.$= (s)) +endif =20 obj-y +=3D libfdt.o nocov-y +=3D libfdt.o --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950628; cv=pass; d=zohomail.com; s=zohoarc; b=OiF5HglrztOJ7brbOHBsF8W527jsSMlMDKWJvBVNIu6mZ83h38du5Wb7iRAmfCHXJTstBNag8JyWLBHVL/WzCQA004zEg/VLnb6Yat+b+LgJ4vyxWLxmPfGDLRF1h0JTiLAU7InerO41LnWMC2NtJ09unnnJ5uaEgf1Xl2GxEHU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950628; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=653u6xWPNriUED+G4weH7ZKsZbL2O1CzT4XNOpC6uN4=; b=BgwQ9SyspNlMXtR5WyukVJYvdkyxK1GEdHHdsxhahRSOU/iZsqZGXuKO62m1EpQt4N/6te4F5Idd+w6h1x4/Xz46brxq5WlmWq6ne72AM1pPzTDQffPV6DdO4ClQdKOdtGdhPNTqpsEx7yY6wcBuCNBKub28IQWkxUDXoRuuX3M= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950628968161.18222729061256; Fri, 25 Aug 2023 01:03:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590555.922936 (Exim 4.92) (envelope-from ) id 1qZRmk-0000u5-Gu; Fri, 25 Aug 2023 08:03:14 +0000 Received: by outflank-mailman (output) from mailman id 590555.922936; Fri, 25 Aug 2023 08:03: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 1qZRmk-0000qz-3n; Fri, 25 Aug 2023 08:03:14 +0000 Received: by outflank-mailman (input) for mailman id 590555; Fri, 25 Aug 2023 08:03:12 +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 1qZRmh-0007G4-Mz for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:11 +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 d3cea309-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:09 +0200 (CEST) Received: from SJ0PR13CA0188.namprd13.prod.outlook.com (2603:10b6:a03:2c3::13) by DS0PR12MB7804.namprd12.prod.outlook.com (2603:10b6:8:142::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29; Fri, 25 Aug 2023 08:03:06 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:2c3:cafe::7c) by SJ0PR13CA0188.outlook.office365.com (2603:10b6:a03:2c3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:05 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:01 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:00 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d3cea309-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nMjiC0Nkq7g3Jm2aw9sUlVaeRE74l8OFPLoNaw5QgiMrCEMbb52tyyvplAXwpMB4mUPSbN/4WAFF/ngniJnxSbVJGxQeMwAZf9Wf0C1ukUmcDVZ9Y06JOtmWbK5dJqhPXIHchP82o6ebGddxHNK9vrHrAUdoRVZxXUOCdsTJq6djd1wl+JS5lq4tY5NjzWJSL7rqCuqTGbc8bsrlVdsGcyKN0Jt8YF9ImbW/mV32R/bwpp+3uDZQDEIoR2cKrRSjr/X3Zx3mIbsQHqSUnGsdKWlyaO2Ig1iobVJoRT6Jvv2K20BZDugW4LCTSMlNaHKfBb8H0DCIA7xCAiMPqSjdLw== 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=eI9U8dpioistzfKA+X1FtTjeLC/MrD31yX6n5sDJl6ekswmVVOKKT6C4R5QkqYz831up7e3CStiG7gg4LIS98hcwpobWRaKDZ6HTVD8J+RuYtoxysZJ3noBpBbShz6YyM8xku6JpIFkz4utDlRppiSBWXMHYLA4c/vzp8SnGswqbz6ULy4M07ulRad9WDfapVPmB4+1jOASmrFI6ZWx6hq81rzxVQqCZSiZ5diHYin6Xubljn+2UwU8ii+PDLEAtpFxy62+riyJOskXo3cs25uGyI2xwvyb42MV5e9bYOCcIqyqC1C1DVFyNqZpc8lbc+qAqI1YtLdQXQlCE9DoRwA== 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=TU7uY2SGH39yZGXVbw0AIfjnBgbRs70cMZv7CGtwx8JhpD7itiY25szXkQKC5ZOWK8WPwaXkmUHbZs8Rbbbk48y+EQhlXvRaW1UeXViM70UGy9baZ1h1RxHzK8vCVAVWK78rmRRwaFHQGX/6QXqZUAQ5IaNYVJkoCk3WPf/GvRA= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 07/20] libfdt: overlay: change overlay_get_target() Date: Fri, 25 Aug 2023 01:02:09 -0700 Message-ID: <20230825080222.14247-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F5:EE_|DS0PR12MB7804:EE_ X-MS-Office365-Filtering-Correlation-Id: 438c18e0-22a6-43ae-1da2-08dba541b671 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xb8ndx0ya9H0rFFlbM+u+px5gtawftpjvhtTosdabWRc2xkSWI53697QzRJ5WdkOFJoQEp0aIZvDuFf5mARvzCYsjWQHE8C3uFia0Gs47Siuwb3qpVMyfVwBXSuiDGLHILgkqvWQ4Xkv6VI2+PFFJyjX0k6tPXOnKCvPlj+Ltwy+2lrRmO+1pf+NhVqnYCHKZLxSeFJKLMKnY08yf6ko33J4I3RvfIDUD5274ZI43Jiw00dHFfUuJx2N4Or4Xofk7KuyBwQpbiSXIs+d4KlSk+LWVyLd4GXtI/gKW+khqYipq072EF1dh8JSP3abUkSJSALIZzu+bnf04dl4NFpZOVkiPf1rrMShXcVPBgT6DMTnH7+nXn01IL3cbxpaISQPn4Rd3Eqp26OwUqvCMbe+qtqqTGFQXLcZGi9i67Qoap3x526ywNLROn5CALcsS658DQ8Y0AeeYWnUn0DKbWzhWiQlXVY2ggwPSNAOKsa6TXUFTi71el72CdcbnCZLzurVaRNiWJ5tZ3suTn/LyPRwVPup3z+6J8RTkeLmfj14gh6BWQtbq/2oClZE9PEI+mcZ2utdvAHhtK9rNfCTABCd7J+nNQ2b+YwHqT7CzJ7Z/2webTBZFoPgUD9zQvlj8Wtz5dl+LpOd+jO2W2wk9XyNgn+GBvHsOY84JMX5+SowRq3ZYaDULj/ouYHnWMmDq/3DR5djn3ifoRXYcTmac8DNdRFGLhY9aAkJqYDislJ63BZw3UKoGsGA5mmflcH8KWvEPM6A4fBdq3iDtS+zrUjrPA== 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)(82310400011)(451199024)(1800799009)(186009)(46966006)(40470700004)(36840700001)(82740400003)(81166007)(356005)(40460700003)(8676002)(4326008)(8936002)(54906003)(41300700001)(316002)(36756003)(6916009)(70586007)(70206006)(86362001)(40480700001)(47076005)(26005)(478600001)(336012)(36860700001)(1076003)(44832011)(83380400001)(2906002)(2616005)(426003)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:05.3662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 438c18e0-22a6-43ae-1da2-08dba541b671 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7804 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950630608100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 use= ful 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. mappi= ng 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_overla= y.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); } =20 -/** - * 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 =3D NULL; int path_len =3D 0, ret; =20 /* Try first to do a phandle based lookup */ - phandle =3D overlay_get_target_phandle(fdto, fragment); + phandle =3D overlay_get_target_phandle(fdto, fragment_offset); if (phandle =3D=3D (uint32_t)-1) return -FDT_ERR_BADPHANDLE; =20 /* no phandle, try path */ if (!phandle) { /* And then a path based lookup */ - path =3D fdt_getprop(fdto, fragment, "target-path", &path_len); + path =3D fdt_getprop(fdto, fragment_offset, "target-path", &path_len); if (path) ret =3D fdt_path_offset(fdt, path); else @@ -638,7 +623,7 @@ static int overlay_merge(void *fdt, void *fdto) if (overlay < 0) return overlay; =20 - target =3D overlay_get_target(fdt, fdto, fragment, NULL); + target =3D fdt_overlay_target_offset(fdt, fdto, fragment, NULL); if (target < 0) return target; =20 @@ -781,7 +766,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) return -FDT_ERR_BADOVERLAY; =20 /* get the target of the fragment */ - ret =3D overlay_get_target(fdt, fdto, fragment, &target_path); + ret =3D fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target =3D ret; @@ -803,7 +788,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) =20 if (!target_path) { /* again in case setprop_placeholder changed it */ - ret =3D overlay_get_target(fdt, fdto, fragment, &target_path); + ret =3D fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target =3D 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/libfd= t.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); =20 +/** + * 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 */ /**********************************************************************/ --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950613; cv=pass; d=zohomail.com; s=zohoarc; b=dA/0ru2rQn5LsE5sii6amRWQb0F/gcu7OJwYdylfiVrrxj2stzy6U4uMaYE/Xa5lN+LXf8AEdg+sePPt5iS6CRIzGMF0YASk+zV5g6loJzNlkGNmovB+1wD2J7VkIvv9Ldva/ux/Nc6iW7dH00lHZhlMdJP7cVxGg0rwJSJKDxQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950613; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lPFr75nv1aBnnGpQw+siLMDm3xpzWwYvMbfH1Hl8l3c=; b=UngGLRUC5wal0NGqlsQIgiDP6Vf3ykWxwn/70HA9LI8owhSmn/rleA48tetZGv4I2ejZK3V/NeXIVRgHLjr/bDPIbyLoFtcJYtdbAQ3TXWYFslUejwM2kkWtqaTkf9yq3KB7+O6MsA/k+pmmV0nreIUQR2OsI4O3yErCuSFCBZY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16929506138211005.0484550337528; Fri, 25 Aug 2023 01:03:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590549.922897 (Exim 4.92) (envelope-from ) id 1qZRmg-0008Mx-RM; Fri, 25 Aug 2023 08:03:10 +0000 Received: by outflank-mailman (output) from mailman id 590549.922897; Fri, 25 Aug 2023 08:03:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmg-0008Mi-Jm; Fri, 25 Aug 2023 08:03:10 +0000 Received: by outflank-mailman (input) for mailman id 590549; Fri, 25 Aug 2023 08:03:08 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRme-0007GZ-DN for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:08 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20622.outbound.protection.outlook.com [2a01:111:f400:7e83::622]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d2cb8fba-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:07 +0200 (CEST) Received: from MW4PR03CA0269.namprd03.prod.outlook.com (2603:10b6:303:b4::34) by IA0PR12MB8208.namprd12.prod.outlook.com (2603:10b6:208:409::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:04 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:b4:cafe::9a) by MW4PR03CA0269.outlook.office365.com (2603:10b6:303:b4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:03:03 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:03:03 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:02 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 01:03:01 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:01 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d2cb8fba-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aIK8AW8F5UrujvOMvLRRXkzlSpjoYFH9716GEBkNG8VPl56ms5Viv1bpJtrY19TsgIYxZW05g6YNDkqbkU5VkIiYiR5DWaDH1p6DLSW8YhQobAnlr1+gvGizEttiTmTsxtQl+YVZ/9KhXmh69RmL/Q9yv+SLVClq/gF5GM9WCw/arZyQeY6lqYrbw0fM9JiJESh+Q/Zi+4grBxaGSG0qooS6T+/hlDQlQM2WmeICBazdOW2kn/nvUHp4QSdSaKB3uU0twHo0iG/pQZy4ooUffXUs2wUsF4u2qTSShqbCpj3EBryaZatO2pleO/czm9+bPeIudid16XumCnrJcH3ljg== 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=lPFr75nv1aBnnGpQw+siLMDm3xpzWwYvMbfH1Hl8l3c=; b=PoHkyuAF8IYl6YQiFkJGGIPtdTJOPtLfJ2DcFtlXzSmqy4PrJ+8SIu3A4bLINk+GouyjhsZt0P5CmxNBhRjXKc7wRHGkuLwEmvm1caEPptfbMopAQ1P/sv4TWcIFQWYD21JqJ7eustrS38t3VxcJ056L7OUR0zqCdDA/qSwu18JyoSdV2p96lr6VPXOE1Ex/OTQPtLxHNhYV5jJKgWFfMVbpPNRDClprchlNpRfFJimI4UIKHESQqssUuI57p/F1/j/DKQEKkhr559IkzXE/NvYPOttNSrxLeFyvVela1BY9zh79KfTyt4Whqum11AhzPrA7Q7WmYwKhp0ZWnt24cg== 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=lPFr75nv1aBnnGpQw+siLMDm3xpzWwYvMbfH1Hl8l3c=; b=fmWniqkPSZ2zRJjMXdt4YrMm5zuirBGKoKS3VYkEEq9nYAdctMlJTpiMiXDZEGga2GKrkITI5Yu+C8p/25/H9dqyvEtG2vWon8YwF1u7RD+e5aaheQL6EEfrIbtAgmafFR6vY28MsWVsEvrl0nHZ/CuzILoKANNTSSokZORLpmU= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 08/20] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Date: Fri, 25 Aug 2023 01:02:10 -0700 Message-ID: <20230825080222.14247-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|IA0PR12MB8208:EE_ X-MS-Office365-Filtering-Correlation-Id: 9dcc3098-e987-4c11-5176-08dba541b566 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Gf3wjCDMmpXWahX+UJC54kkPGRLzFolOGP7SOnzlE+Ace2x5Es1//zvTxMVVUrjVO10lZb4qRCkkhVGsUgflRNfBgzZkounRNs0+bwRfmObnf7TNhp3Oa5h2EQh1FJHmGu7v4wFhxvTIZy7oqAHbN6a7UPfL+eVEynqKaFiT2QlLIAFft1XyM8YqmqIi55oPsBvDJAgFyn/PHwNI8aH6pc9YfBqrIqJDLk5O13XPEbl5tQ+D4+mvaCWQ1FA4aqhg2GASgb5dfm0s/MSpz6McwRmL12DFfrXmw9NiCjOSM/q0zwEi/20jeGsTDdl7VB30mQ2RyhvBn0bCl/ceVlpBK570qo+8LXsr8zQTbhBcfFs3MDtRRN5EBbnC1JLVbqY1hkZ4BcY9cHwEdHO3w7DCvIgpru9bik6Lz5F1UHv3PxbDtbZ1KwFFQLkdioXkAce6N8VL8IlnmJLQpQQAjnKC6iqxlS44Txq0Slyms6byWCwJKRTPerqx3Sf0o7ZD+Y9EJLomuE0Pqk9Zog/IQwFx10Re0NUSauJv2QJYd0UOFYNbvL8/f1EEf5A55gIcWUVXKoRJ5Sv5aN3vR/UDWPx+rHOFukJTqc2PKcuvlw/xBOEbQsIBEijDMMn9QN+pMtjUB/qwEcCuz8FcmVVpmOfMU8fit7v/EiF6dpamahJOQk7sgvSgyFgnTlzxEH9dnyVBAG9t1Vsotbg7XpqQQmOm7EE2+wS3V8m96esLLfLzR5Honw0vaZ+EOdArIRY4c5uQVyOCOi8nsItLPU4L1EME1ZO304jhZxabjGE699NHh/0= 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)(136003)(346002)(186009)(451199024)(1800799009)(82310400011)(46966006)(36840700001)(40470700004)(40460700003)(2906002)(336012)(426003)(83380400001)(1076003)(2616005)(47076005)(36860700001)(41300700001)(26005)(316002)(70206006)(6916009)(70586007)(5660300002)(4326008)(44832011)(8936002)(8676002)(6666004)(478600001)(54906003)(40480700001)(86362001)(82740400003)(356005)(81166007)(36756003)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:03.6333 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9dcc3098-e987-4c11-5176-08dba541b566 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: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8208 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950615999100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add device_tree_find_node_by_path() to find a matching node with path for a dt_device_node. Reason behind this function: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, we need to f= ind 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 n= eed 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 Acked-by: Stefano Stabellini Reviewed-by: Henry Wang Reviewed-by: Michal Orzel --- 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; } =20 -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 *fr= om, + const char *path) { struct dt_device_node *np; =20 - 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) =3D=3D 0) ) break; =20 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); =20 /** - * 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 *fr= om, + const char *path); =20 +/** + * 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); +} =20 /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950623; cv=pass; d=zohomail.com; s=zohoarc; b=OJlOyrD0nD31+tWAFyaTy/7axArF2J0Rj0JWM5MjmKoCxh+X7vemaZ8bljJ+yZ7WjovV+ECkA0dtkvRGBPYro41ObgzIPIQaIUP1Wedgmu+Co5VBLfjQByFQ18f4VETN0TBle28PkKkXFypDAROQ4tHxhmnpfoRTRQ2d+LooQ+M= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950623; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bbLjByfblu66od1Vdrl71+ZR1WzFVQiYpHtzjdK7oJE=; b=F2YmJmgYmfjs/V4arfm9hSs1ltF4KXW2wg4GCE261QRK3L1SchnyvQ45uIP7HPIMFuZtBoeJDvnrqE+t0ZpJVLjomKfG1SY7FXFiw7PboHaxraHdlMYiv6sLV0HDKKVLUmaSijnJLsFJyYrLFzk97f0eMGz7wU8Z8SsfLDbEpJM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950623057516.9717775667076; Fri, 25 Aug 2023 01:03:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590561.922979 (Exim 4.92) (envelope-from ) id 1qZRmq-0002IL-7a; Fri, 25 Aug 2023 08:03:20 +0000 Received: by outflank-mailman (output) from mailman id 590561.922979; Fri, 25 Aug 2023 08:03:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmp-0002EI-IO; Fri, 25 Aug 2023 08:03:19 +0000 Received: by outflank-mailman (input) for mailman id 590561; Fri, 25 Aug 2023 08:03:14 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmk-0007GZ-Er for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:14 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20616.outbound.protection.outlook.com [2a01:111:f400:fe5b::616]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d5f05c61-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:11 +0200 (CEST) Received: from SJ0PR13CA0202.namprd13.prod.outlook.com (2603:10b6:a03:2c3::27) by BL1PR12MB5706.namprd12.prod.outlook.com (2603:10b6:208:385::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29; Fri, 25 Aug 2023 08:03:07 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:2c3:cafe::3b) by SJ0PR13CA0202.outlook.office365.com (2603:10b6:a03:2c3::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:06 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:06 +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; Fri, 25 Aug 2023 03:03:02 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Fri, 25 Aug 2023 03:03:02 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:02 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d5f05c61-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AibZfvB1j1eJmcQxa9jPL9SsdKUIKL/J9ZgWdVJa7KcwnVhYskpucGOZe+RQOlvyp0BS/fjbW4ruHwhZO9VCl/WlEZNaEEaVn6huN9UoGbi+2D0rWMMbPdOFbwe+lM24cB7QCzJI7rtvxpN4bVL01sO5Z6MRuRZpx8ti+eW0G5v78UJITyyLFsQlHMzcqOXZAK0Kvwxhx40hFPuwsQ5Q/SOxggG7pd8wRHZHT2GHDzPhmFkCpJ1AEaVn3EXVh8E+2fU3NvWfauKO+DulTq5r1gDUDNEhb0x6SCSYCMThOkeBvWwVz4bDIwsV84dThCYjlPo3SPzSh2TQJHVld4WLag== 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=bbLjByfblu66od1Vdrl71+ZR1WzFVQiYpHtzjdK7oJE=; b=JgZmabtjnrUSQyY139mI246NXEqOR1/m/2UoBHxKatWJL89GUW00VJ3Klx9L/AIPgDVcorP0eE86dyNmruwLPyy0ySnMrqXBmXkeAXdBc2KP8iou0dj25+fQ4jvt7YH4idFgmizqAIcXnct6FjkNRmCFLdRIzSSrnve9OtjH/ocTbrG1l0V3vkPSBE7jYnUOj6Fi0oXY89rKj0J7PuwksTBEguN2kGjm8GhXIzZtqoH71xtib1pk4doILmFEokRVv0Ipebpet7tUyeRZzJ4GY2kuhg7VWqOkPYz3L71/ShjRXFokZh33XY9uqj8wjye2Zs8roOy3aKIm0DsVy4zrEg== 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=bbLjByfblu66od1Vdrl71+ZR1WzFVQiYpHtzjdK7oJE=; b=CFxt1tLjr1yErFOh+K8+rgeOfMdbHPMLh40gwdgP9JWtnqDyo21nmp/dBnbqSUPM1gCOsSnVBZyBSUxlAZ5yMbQWq08E61DOhNBNIMVgT0rftisg+Q9MC7FQVsYTdEouYr9pi1mfst9nHFaf/ps27sdbwySyflFerDXvHwFVV3s= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Fri, 25 Aug 2023 01:02:11 -0700 Message-ID: <20230825080222.14247-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F5:EE_|BL1PR12MB5706:EE_ X-MS-Office365-Filtering-Correlation-Id: 8607ac54-e699-4797-b404-08dba541b709 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4UZi/QuVEXYlI1/AmUrqeTIJ7P+rJWg5nPk1/sqtzFiDNFDHuvOCFoAsYHErYf0db5oSWswGP904QVMCHriN1ptRp5LZ5dU4VS6Xp6izgntc7uaFx400pvWxPHF1b4+MBhzjim9sSkNsPcv2ufdUwbrb+/A1BoUVdVajceUr4oO2j9ZjCRdV7M6XQvpLsI2uJgcz5WBYPHOdlp1grmDra+T/o4UrMAGE+xuHkoWLajsA/9wi3lz7WJJNm64kWa8s6G9eIY9SVx8bNpkK8X+okvU2Tji6n1G6RSDHtF+p3nU5GcnBDWs0+fkORCQ1aFA9tYSmumzeQib67XWFqTbEmzLDgd7ykp81xuzM836CPeDF0QtpFnxCY/CHrPUkLRSVIzMgRHWGr23juYsBGfiynDCnDxRMUuUtgxdT4EAsV8hDVBLG/lG2db+mydp+bACLBd8Iy5yxbH/gPhKh7m0wy3/gTRN0nPALluIPlqmr7I79MKA9dAcpsFABA8PHnMa1dKGhx9kwpRtR/nV6WHKVGIhzsJ76bAdnPFmkSU+6BP4aKabouGPKtKghtbJ2Pgziala9Z3WIVlJ9jl0dTNMFHUbGM4pWuDQMK7RZYyiTJMQ+j07ZC3euvkrp/Vq8p16mW+vhWhAsC2CKQJoq2J9cTZu2PH23kfwxfpoSBCV60PYPximvzoAXF10TyrcyG/E9NhIsfKfduOTlGlgAnI+PUw8BuhnxAGI5D5S3FYpfibhzG2Q8YNjFYASbU9lAHi0aZMSR3iWo4v5r4JPXB1z4qA== 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)(82310400011)(451199024)(1800799009)(186009)(46966006)(40470700004)(36840700001)(82740400003)(81166007)(356005)(40460700003)(8676002)(4326008)(8936002)(54906003)(41300700001)(6666004)(316002)(36756003)(6916009)(70586007)(70206006)(86362001)(40480700001)(47076005)(26005)(478600001)(336012)(36860700001)(1076003)(44832011)(83380400001)(2906002)(2616005)(426003)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:06.3662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8607ac54-e699-4797-b404-08dba541b709 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5706 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950624412100008 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 1c32d7b50c..5d84c07b50 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -83,16 +83,17 @@ fail: return rc; } =20 -static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev) +static bool_t +iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev) { bool_t assigned =3D 0; =20 + ASSERT(spin_is_locked(&dtdevs_lock)); + if ( !dt_device_is_protected(dev) ) return 0; =20 - spin_lock(&dtdevs_lock); assigned =3D !list_empty(&dev->domain_list); - spin_unlock(&dtdevs_lock); =20 return assigned; } @@ -223,17 +224,24 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, str= uct domain *d, if ( ret ) break; =20 + spin_lock(&dtdevs_lock); + if ( domctl->cmd =3D=3D XEN_DOMCTL_test_assign_device ) { - if ( iommu_dt_device_is_assigned(dev) ) + + if ( iommu_dt_device_is_assigned_locked(dev) ) { printk(XENLOG_G_ERR "%s already assigned.\n", dt_node_full_name(dev)); ret =3D -EINVAL; } + + spin_unlock(&dtdevs_lock); break; } =20 + spin_unlock(&dtdevs_lock); + if ( d =3D=3D dom_io ) return -EINVAL; =20 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950617; cv=pass; d=zohomail.com; s=zohoarc; b=MlohqikOld9htkyvS5DlW0fb8g8NYALvvbx5dLcxnlaCmSDtNmHM8lWb24fyPV3VUOoMMiQcK+bCZnsRVZcjOj94qhzgSgJt11pcfYfMlwyOkiupMsPwZcjAMEe8gtoeZnm1bsivpYLTb7d7Lohx7hZ50VGNUCRiZ6eA+wAbvo4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950617; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=46ebdCxwn7EavFAkYu+2lsP3rPq7Dn3Zw3ob+HqOtOg=; b=HsYJNZJOyOhKEFHVSbymcKPA5z93b4nB4S94ZJywfkY3cNeXGXPCYSbGrUnz1EZLwqA9CvW/up+wZY7jE6J1/ZMUD6I+zBARU/56vLX4KmHDbSxZGHtv+qCNxlosneTXctZHaOzIcKHXEowEJYdiPl5JHGwL6xPmQPLIcZ47MUo= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16929506178491011.3998211111224; Fri, 25 Aug 2023 01:03:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590551.922908 (Exim 4.92) (envelope-from ) id 1qZRmh-00006y-MJ; Fri, 25 Aug 2023 08:03:11 +0000 Received: by outflank-mailman (output) from mailman id 590551.922908; Fri, 25 Aug 2023 08:03:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmh-00005p-Bq; Fri, 25 Aug 2023 08:03:11 +0000 Received: by outflank-mailman (input) for mailman id 590551; Fri, 25 Aug 2023 08:03:09 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmf-0007G4-MR for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:09 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20616.outbound.protection.outlook.com [2a01:111:f400:7eab::616]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d2ee0ab7-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:08 +0200 (CEST) Received: from MW4PR03CA0047.namprd03.prod.outlook.com (2603:10b6:303:8e::22) by DS0PR12MB7748.namprd12.prod.outlook.com (2603:10b6:8:130::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:04 +0000 Received: from CO1PEPF000044FB.namprd21.prod.outlook.com (2603:10b6:303:8e:cafe::56) by MW4PR03CA0047.outlook.office365.com (2603:10b6:303:8e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29 via Frontend Transport; Fri, 25 Aug 2023 08:03:04 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044FB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:03:04 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:03 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:02 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d2ee0ab7-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h03teoUtXTEV/W8gpGhhQcH40HUtjrLF15Kg2oY6m5hsrhNUvYFLLCRw3rQyxQCUwv/SMsh3tBJ6JHCVzgsNYI8zxW0DuhNqPBoBfuQO+yfwia4aOBasQio9lPtxytxSBtyAVrZSgqGAh6nFO1ETbIHb+07eaTm4xh07mM0OlzVf76H9VHD9cENPqg+yfYIKZrxV0b1k7xnHh2kcUGJWzn+jbe92XMFjVCiQADCM9MqGSuq4imgf52DjcnlsSCDEunAp24hrajOuEhW9taK42cTA92NqiYXL0NGC/9UY1FwpXtafaxsiHvVqCCQuYHMoZrXC/wwnEYsBkLKep7SU3w== 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=46ebdCxwn7EavFAkYu+2lsP3rPq7Dn3Zw3ob+HqOtOg=; b=JY9doyFZHXaTMqM577rz0iGf8/LkJgA+aAu3dIB76ZHCJKTFmRFDdTwM6H4c5AXSLH45MYgN9T7dDSWHqTQYzdHd5P1EyTRUFT3oGSDHXzjwX55y/mSALyA18BSgFN6IMorg30gjKb1Qa0WNJPlQMbNBQ8ATuepY5XhBRzXp9jiVgj5H9pYsKqYYwGWntc69TzBfpe2SWJauXOkcx+w5yEVTuYgaktCzghh/+U4iHksW7wA22AVJPbrIs08DygqrNBu6D/5IohExTE8MBrELkX+lfJ90y/+0UpQfcXRgqtKBVchayMCjOYj7bjeX/5rFqufb8XpL/uRRHw6VHAvp8Q== 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=46ebdCxwn7EavFAkYu+2lsP3rPq7Dn3Zw3ob+HqOtOg=; b=0z11GyZrE9IDmI33qPbF9JpTL+Y4CBZ6Jgz1ugiSlmfz9KDlsRHR3mL+y1egwSocddlM44HcFobHOnnhxoTMRXFLHTUkZSdbXgvhlpKa8xVwdrTr+wY1PD0SojevrktgQ7GvrVYBm1+MPqATB05n3qXrJ8Ohfv+d7LNzugGOEOA= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 10/20] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Fri, 25 Aug 2023 01:02:12 -0700 Message-ID: <20230825080222.14247-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FB:EE_|DS0PR12MB7748:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d2bb6a4-4657-4993-a52d-08dba541b5ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AMDpI54a7bopD2A3IdXCBMqqrnt//2RJBvEqL/d8tH1oLrLeSYxL9cLHwwUVDkekLULQE8/tNnacjtDMR32YrI2LTPBlMhDhIbbd74F1DkwIRoBKz6Gy4ofkzEKb0vPQmmYe5IAtd1HfwkhuJacpREFVnjj+L8jIHL8Wh9fmfTccgmAhe0mHFx75+2kKIwA/EV1splDCTSy4vglH657XKpH5elO7/SMsFDf++iKppyAL5HVw5gZJEgud8QLKUVBMvEZayrsrpMs4w81OnFwbHBN+KO91E1qGOC4fLMmlraq456leVuDCbqRW2FcMmz5Uyzu62Rr2Ym2tiphbL1gDwYG0QGjFTYalQrL9fmMbhSoNfg1+Dhz6sp5MxKOGFEvdpmtU3a1Vmfw2PJEcMYQLDxEYQzgwwgwXaDqTyX72NWNEbkPy8+XFr99U+ae+OEU4NsYJHgH8f6Hazd5nmUoeNxD8rr7Xer4jUqcGUB9w+KlNXT/wFFs60/Hp8T7aiNV7obyeA7NQ/Jf29DYTH7it8iVWhSRiBjzwlPWsZs8ZJzS00j0/nnaTDWIeLhaY7LCFi8shvcExqKT+iRuvaPtP9e3miR5rYgwPGIFz43u3fmF4l6qvOU62F1CaYuqDgMJRmLFZZnmeM+wIR1/8k2fB2QfgQ9tqkzeqwn2uusFvVgBXzDWK7jtXVpr0YkZhUXPBDDV59AGVvR8iGvdRw4z3o9Uy5+NYJ3pglceXQYvtkCjQK2UO6OUF3VC6Ew8OVKXyEn86D241fvmyhQh9w0nwGQ== 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)(346002)(39860400002)(396003)(136003)(82310400011)(1800799009)(186009)(451199024)(40470700004)(36840700001)(46966006)(1076003)(40460700003)(2616005)(5660300002)(8936002)(4326008)(8676002)(336012)(47076005)(426003)(36756003)(83380400001)(44832011)(36860700001)(26005)(82740400003)(40480700001)(356005)(6666004)(81166007)(6916009)(70206006)(70586007)(54906003)(316002)(478600001)(41300700001)(2906002)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:04.5489 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d2bb6a4-4657-4993-a52d-08dba541b5ef 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: CO1PEPF000044FB.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7748 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950619266100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 seri= es), this function can be concurrently accessed by while making a device assign/deassign for passthrough and by dynamic node add/remove using device= tree overlays. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel --- 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/passthroug= h/device_tree.c index 5d84c07b50..1202eac625 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -148,6 +148,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( dev_iommu_fwspec_get(dev) ) return 0; =20 + spin_lock(&dtdevs_lock); + /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt * from Linux. @@ -160,7 +162,10 @@ int iommu_add_dt_device(struct dt_device_node *np) * these callback implemented. */ if ( !ops->add_device || !ops->dt_xlate ) - return -EINVAL; + { + rc =3D -EINVAL; + goto fail; + } =20 if ( !dt_device_is_available(iommu_spec.np) ) break; @@ -191,6 +196,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); =20 + fail: + spin_unlock(&dtdevs_lock); return rc; } =20 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950623; cv=pass; d=zohomail.com; s=zohoarc; b=DzkssbtUQ/UnCJDbHGS+qnjt2uUTCoES6Ee9V9tnu24fBDlqwV6HzXFOpvz9SaJfsUFGP7uJdNP6NjDxJjMobFUzx41RAWry6afkHde7Mw9SiJCWNRGEsvba+dYLGM8keC8qe0UKN6hERNcizJcPlpQceQJJSVi4O6vNCaVbuNo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950623; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Boh4kb43qvVkEeoNHrUhygxa2MEH5SiaelWzI7PkkUo=; b=LM4WY3g/7vU53Hm9nu+GRHiWNKsswPcGzlKmN4ML5L5a+PpTl/mNyDGLJZkgeH5DCYjs96Aju0x9LMf9QKscE0R9a1siDZvlwx1b/rLhxL6Iq1vJS/81bVNIu6MiPO7zSAZTT6shHdS9gppBC+Bk2gSrajfZY6dDSjCK8tm2Jow= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950623686948.9284930731471; Fri, 25 Aug 2023 01:03:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590550.922902 (Exim 4.92) (envelope-from ) id 1qZRmh-0008SR-6Z; Fri, 25 Aug 2023 08:03:11 +0000 Received: by outflank-mailman (output) from mailman id 590550.922902; Fri, 25 Aug 2023 08:03:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmh-0008PU-0o; Fri, 25 Aug 2023 08:03:11 +0000 Received: by outflank-mailman (input) for mailman id 590550; Fri, 25 Aug 2023 08:03:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmf-0007GZ-Dn for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:09 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20629.outbound.protection.outlook.com [2a01:111:f400:7e8b::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d2ff9b4f-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:07 +0200 (CEST) Received: from MW4PR03CA0249.namprd03.prod.outlook.com (2603:10b6:303:b4::14) by CY8PR12MB7492.namprd12.prod.outlook.com (2603:10b6:930:93::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:05 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:b4:cafe::e5) by MW4PR03CA0249.outlook.office365.com (2603:10b6:303:b4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:03:05 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:03:04 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:04 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 01:03:04 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:03 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d2ff9b4f-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PWNPiWb3YD70wFh53GavZgDDzG+nma8HVHJRYu1ByCAl4B1bBrMGMzepkBg7hjLCDf0irxjwq+/dkjmvwyLh8W9gI/EbpTpZ4KbGe+J4oWKITtnP2ixhK5IFKFNKlfgNB2W4W6yXmmxsrNoGugA972xqKVVk/JkkiJujjfu8Gh6VswvaRr9PoG518vQw9tHfe/p6qoB/ATg7sBBiBISt62P9LBAmLlTJhIsKOWzYAq7C6qO3wACEuJCH03qqFCeUBdK/EX7t2EmQlIn+OjN7xLABgmNr2Zrwn8RSZU1mXw91+GumTbWAbHmJ0x8CDKxQR9onxNWSZ1RD5QsMM/2QlQ== 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=Boh4kb43qvVkEeoNHrUhygxa2MEH5SiaelWzI7PkkUo=; b=jh6ttUYC3O0vrtXPslebnTzN4GQBX808QJtWj4wKYnx0RXrp60baoQgzVBxuRAWx+l4n03XB3s/riQQeqZBYB01BZL6kkUicuIM3A0krXCH42zFol/dQhzcAjgY1dVDVUAWciDWrlKgzK0vxHJEf9rn+URLVo8TxODp2+rVPN5H7fHVnKfu31YbPVzDzA90rBRSSA+o/5S0fpngW5qKzq1qLhAR9aFfWHzC2UVSKwCdcpaAZs++43rDz+UvEpWGcEDVhf0gKHIsDtsMu8xpebto4cmOTOAlWlP6UK9n0K36C42iU8MmTrZ58H745g/2oNjruUCGylcJ6CfASiSb41Q== 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=Boh4kb43qvVkEeoNHrUhygxa2MEH5SiaelWzI7PkkUo=; b=k4pef2kWh9k89xzpQrNYQ3RJjekrvQIdUCqflnCSPoBiGEO4o9hCpf/W0NFINUhE40I49yUJzyPLxZ0iCSFXEEsLpSILGT3coFGUxgTwrYr9fXtL/GiRC6brmiDB+nO8DrpZ6mx9NFkBLdd9NVoqu2wbrAYZTNJx2N6kkQzi0/I= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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=20Pau=20Monn=C3=A9?= Subject: [XEN][PATCH v10 11/20] xen/iommu: Introduce iommu_remove_dt_device() Date: Fri, 25 Aug 2023 01:02:13 -0700 Message-ID: <20230825080222.14247-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|CY8PR12MB7492:EE_ X-MS-Office365-Filtering-Correlation-Id: 9de89e45-9635-45de-48b7-08dba541b620 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gMuMeDQo3wgrhTbne2aKcCyLrCINgDWk+tKpnZoDVvh0DmY816BzoAif3FciHs73+pWBPr+MiVwUpyK1Uy4wldlCm/C8whdLzEbMHAo9HCGSBLAf/lfb+fphV4tRRcYPWGUUaSDyYrMrqoNnbNDUcHBvJZxtkVGQzGvbIQ+SEorVwLovKncigb/rSJRdjp2rETf6dHrRDu5l8lYaZ6ShGYvUKcMY2ehJuypFG+nbKcZ3eQjvpeyCvdLKbJs/qhoXcy42vTOG6WM5PzVUSAwW4qvzoQEjYR8KCMUMqNe4r2njtQA/Ti7PXWkQkxNkFp7xiOxLzjEtbfeIpRBxE9eI77xIBy9fsEyFBFEDXAJqmfqhOGL9tkppvN0ygHgFvE0tDyVtmTUVs3/lL8q5M//upU5hBEpb17ZZwgoQz1CJbBPc4MsVl8LMjaNqWPvCXRLUJsSax1svRPBBnwm3060hf9FfgMGSk2xY3wtxI5TnfCzfj+hbhdIilcryQ5eHjsUiJiTg212c4NfTl96GPhQB8t3VuMCggjbPUk6DDbXd5eGnKWpwy+T5Jq0O5OZVyb8Un987h5AUTytVIFyBJ3aayQK3iLJzSRFmTH48QOMdKmJUAYxsgxYhE3ys5KULjoCJ1QZU+EmCduK7ABiYl7xwicD2rzKLx3WSIZAwAqJLREzJNxihTcFdmNMoA2RKyggPSvsVsBCIDiPXWp+dss2Psg+mSrOIi2SWwK9cBsyYSq4Y/DcEFpceWlX9WuDWC9pYSMLj2kU4ZOI7wL7Jolhy4A== 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)(136003)(346002)(186009)(451199024)(1800799009)(82310400011)(40470700004)(46966006)(36840700001)(40460700003)(2906002)(83380400001)(336012)(426003)(26005)(1076003)(2616005)(47076005)(36860700001)(41300700001)(70206006)(316002)(6916009)(54906003)(5660300002)(8936002)(44832011)(4326008)(40480700001)(8676002)(478600001)(6666004)(70586007)(86362001)(82740400003)(81166007)(356005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:04.8521 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9de89e45-9635-45de-48b7-08dba541b620 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: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7492 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950624367100007 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Jan Beulich --- Changes from v7: Add check if IOMMU is enabled. Fix indentation of fail. --- --- xen/drivers/passthrough/device_tree.c | 44 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 1 + 2 files changed, 45 insertions(+) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 1202eac625..3fad65fb69 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -128,6 +128,50 @@ int iommu_release_dt_devices(struct domain *d) return 0; } =20 +int iommu_remove_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops =3D iommu_get_ops(); + struct device *dev =3D 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 =3D -EBUSY; + goto fail; + } + + /* + * The driver which supports generic IOMMU DT bindings must have this + * callback implemented. + */ + if ( !ops->remove_device ) + { + rc =3D -EOPNOTSUPP; + goto fail; + } + + /* + * Remove master device from the IOMMU if latter is present and availa= ble. + * The driver is responsible for removing is_protected flag. + */ + rc =3D ops->remove_device(0, dev); + + if ( !rc ) + iommu_fwspec_free(dev); + + fail: + spin_unlock(&dtdevs_lock); + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops =3D iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 110693c59f..a8e9bc9a2d 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -233,6 +233,7 @@ int iommu_add_dt_device(struct dt_device_node *np); =20 int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl); +int iommu_remove_dt_device(struct dt_device_node *np); =20 #endif /* HAS_DEVICE_TREE */ =20 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950630; cv=pass; d=zohomail.com; s=zohoarc; b=KvUBL265706OqknUZGCbyQJuSwB3yiTtKTw5AkfhZ/j5/vY3QWpsW8O3nyYeQdNTewmgtvyi85WbTqajmefUA9fSo2iE9TvpevERimRotkb6fU7gesDG8nlQTPj1foiG/DARJXQN1Ha7YRpgxw2XSX8lAydSqQe2HYOUCyQmy2k= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950630; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N5Ad07nFyqe3yvUSTljKoScg3IAugPfBscvADFFb2TQ=; b=Ff/WXF8I3a9etUrxfgsxEpDjOiBWNAB2DSihXv0Vn8jh4/p6APNjsxN8uVztG6CQuosSylBcWhxO2/6g8/kXp4lNnfj6Ppua7PTSUhyMZ4vOUGycZJlwP/OlTyENG9+yYGbJ1HhC8OxTm1JHmXljYyDNpaJmuuO0sKxO9hRoqqs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950630600551.0554071556899; Fri, 25 Aug 2023 01:03:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590559.922973 (Exim 4.92) (envelope-from ) id 1qZRmo-0001yO-VL; Fri, 25 Aug 2023 08:03:18 +0000 Received: by outflank-mailman (output) from mailman id 590559.922973; Fri, 25 Aug 2023 08:03:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmo-0001rm-30; Fri, 25 Aug 2023 08:03:18 +0000 Received: by outflank-mailman (input) for mailman id 590559; Fri, 25 Aug 2023 08:03:13 +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 1qZRmj-0007G4-NN for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:13 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060a.outbound.protection.outlook.com [2a01:111:f400:7eaa::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d49b80d1-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:11 +0200 (CEST) Received: from MW2PR2101CA0020.namprd21.prod.outlook.com (2603:10b6:302:1::33) by DS7PR12MB6093.namprd12.prod.outlook.com (2603:10b6:8:9e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:07 +0000 Received: from CO1PEPF000044F4.namprd05.prod.outlook.com (2603:10b6:302:1:cafe::d5) by MW2PR2101CA0020.outlook.office365.com (2603:10b6:302:1::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.4 via Frontend Transport; Fri, 25 Aug 2023 08:03:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F4.mail.protection.outlook.com (10.167.241.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:06 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:04 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:04 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d49b80d1-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g9fSMHGAn/RPAGfsMrquwkKdth5HwKK8UMp4zpSTHZ1ZPt2qJ4bWOeAvPFBKSpAWmMaSexqfGI/13ti8glfcV3jIaQLr0ZvfHKyjF4vA3h6suRG8bd+boA95031YB/rRSkI2FDP/GZucpEFWWMuBb4up2ejBkTBXGiRmbcSm5pW2h/slKg5HaU1PoLymkbOBOE2UtTnUwMceHOg1iMGYQuyjLRLhp4GF4oXcfgsCRqz/exjXQv2XSEl0Pb/H06yp12wzMGB5roXusJixt6v/fuKayILQb6gXZwPPH8vFgcyM453g+3EsEhZoviTT3EKVzhmoWg+7hfwplyCXjvZqEQ== 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=N5Ad07nFyqe3yvUSTljKoScg3IAugPfBscvADFFb2TQ=; b=hjH87sBgZfsR/bauTspleETzz4qLAKFCGHpCFRUnE0bqtHtJRjQtA7mjD/bDS8hNdRc0636zyMMwMpu25Xd4iEKFOENmPde+JgwipKM/zYkqQlj+yeNBMXlQGR7QGq6mzZ1xzfG5QZ38i0bsAKtWmIzbc83nTPa7w1TRlPbaWjL+MB/PxIzoHu3g4ceszqOHQJJNj99H3i5AYtZ2uMA0qPdNm9AFjzXgil+L4odscufsgOJI1fxhqLFx6Ha6SiGFWgcR3f3MMreL+Ol4EfkNICLN3CTGTKKLd+yFk+TtIIp+u4MFYdRfY16Jfi42gK9nICddJ2SBG085VBmErKpVxQ== 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=N5Ad07nFyqe3yvUSTljKoScg3IAugPfBscvADFFb2TQ=; b=YbPyfTwiIQOPFKBiD+vks2W6K1+eL0tKgHYRF6n8PSxiDIwWl7ChqikcRe2JFUPof8jks7DvWnp9rl7lRWD5s8yx597jnzB4PRcn1qSaS8moJ7IzkO4DRYmyicXFL1+9d4pfN2obxwwJoDE2pa5PkkLgJM4uEJe7X98IRIuxdSw= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Rahul Singh , Bertrand Marquis , "Volodymyr Babchuk" Subject: [XEN][PATCH v10 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Fri, 25 Aug 2023 01:02:14 -0700 Message-ID: <20230825080222.14247-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F4:EE_|DS7PR12MB6093:EE_ X-MS-Office365-Filtering-Correlation-Id: cc7bdd2e-0999-4a0e-cbb4-08dba541b75c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m38KQQdC7AQ7kO6bbLtZ7xwFS/eCXNRwCJpc+5GoKy4EVwzS1whiLFXISCaU0rFyeZWt3TTcphOpzx/X2SL0E3JHPke0SGqLJC6OfSACNEyt9lcM8AR/l0l1Rm+tigN6rGVGT8Bead0JmHCZqJlBf2kgOOZ79JLUSxYj8tHkpX21cS2LioiI9sP4m5tYVGGzaVBWZkae60Oxg+5S6qpLD1vjw3GKSWBNuFRgDDcLCNnffJY8p0hJsqCVCgZtt69qCTWpZaYHt50BKDcFJ1m5vY4SS6+EncXAmDu557AvdbVtCCvdmdz4ZeBJ2+DsNr37aFG5X1atpf1BaT/WqZ51zp35EAmzGHi6Jq97l5pRexlD3TQGuA0qszKgz+b0G33UpHxyVyPK1vegkQJ7zKSj13A23411WW48hnza4TaSlfWKs7Oc8oFTU/4J22Bsd0Pm8saPtO5Ivc1sMTEZT8Qi7Qu+4TdTkQshWUBgyIpacBuZlmuumb+nkQjryiv5or0otjLNqikHhFXqr8bbmsq9LAc03v+t3bfyx/B4Dt0F5SZc2xwPbFRwAXaSPsSTfTBCRMouMYcHlX7tF134YkQJ5Pp73lYY86Jj3FQ3Wn5k24L6uPr7jXXa1QtYFUUFXMCxD0s08hm0uaG4y4XJ/gyxzEgo875YT6GxBAbpQeNLAYrcIouhcvp2lOt6p3M7wiBh1jsKw2VKhdCgyFdi8StOsRYTxNeCzDMi+BPW9kLdPAt3bxpacBiP4RK7hqE6Wy+a23hZclMUfitllmTt+B1oaw== 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)(39860400002)(136003)(396003)(376002)(186009)(1800799009)(82310400011)(451199024)(40470700004)(46966006)(36840700001)(54906003)(70586007)(70206006)(316002)(6916009)(81166007)(478600001)(40480700001)(26005)(6666004)(82740400003)(41300700001)(86362001)(2906002)(356005)(4326008)(8676002)(8936002)(83380400001)(2616005)(40460700003)(5660300002)(47076005)(44832011)(1076003)(426003)(336012)(36756003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:06.9107 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc7bdd2e-0999-4a0e-cbb4-08dba541b75c 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: CO1PEPF000044F4.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6093 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950631630100007 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add remove_device callback for removing the device entry from smmu-master u= sing 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 --- Changes from v9: Remove iommu_dt_device_is_assigned_locked(). Add comment regarding caller holding the locks to protect concurrent ac= cess. 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/a= rm/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; } =20 +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_sm= mu_device *smmu, return insert_smmu_master(smmu, master); } =20 +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 =3D dev_get_dev_node(dev); + int ret; + + master =3D find_smmu_master(smmu, dev_node); + if (master =3D=3D NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret =3D 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 =3D 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); } =20 +/* + * 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 =3D dev_iommu_fwspec_get(dev); + if (fwspec =3D=3D NULL) + return -ENXIO; + + smmu =3D find_smmu(fwspec->iommu_dev); + if (smmu =3D=3D 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 =3D { .init =3D arm_smmu_iommu_domain_init, .hwdom_init =3D arch_iommu_hwdom_init, .add_device =3D arm_smmu_dt_add_device_generic, + .remove_device =3D arm_smmu_dt_remove_device_generic, .teardown =3D arm_smmu_iommu_domain_teardown, .iotlb_flush =3D arm_smmu_iotlb_flush, .assign_device =3D arm_smmu_assign_dev, --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950622; cv=pass; d=zohomail.com; s=zohoarc; b=QcqcmT1VoMv1dW/Q+KVL3ONh4keU3paBaYgmvx1gS7fGAaU6d26e6xtrk3GE7WCTzS2i/dM9B53l9L5LbwxdDsuQUN+w0ATHUceafFJVhJ+bmYMCkQFN/ILZdtJIL6xBbiNIbZFFrNcqaFhunpVCAnrrm8Ry4YuQEo3hLMVm7h8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950622; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TDhW7f5w3p+/XHERjQf4wWurMSkKNLV2sxdzRwRCMQk=; b=JUbsJWYepm8GhJHcMKorhORGudd1TWn3ZoaEsC2DG/sC7bQhPYxFd+2F4zxEAwFGuGZZ5x27qfNb6/sUq+Hq3aTUDvT+nvEon/M68E4XEMhe1m8d8n+wGUNnXIzRT0pDkW43OcOSXagSetrscpsbsHsqk28K5QMWTUsFY6jVlTw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 169295062234410.75104152219319; Fri, 25 Aug 2023 01:03:42 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590558.922958 (Exim 4.92) (envelope-from ) id 1qZRmn-0001aF-8T; Fri, 25 Aug 2023 08:03:17 +0000 Received: by outflank-mailman (output) from mailman id 590558.922958; Fri, 25 Aug 2023 08:03:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmm-0001VS-U7; Fri, 25 Aug 2023 08:03:16 +0000 Received: by outflank-mailman (input) for mailman id 590558; Fri, 25 Aug 2023 08:03:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmj-0007GZ-EY for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:13 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2062e.outbound.protection.outlook.com [2a01:111:f400:7eb2::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d549fb41-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:11 +0200 (CEST) Received: from SJ0PR13CA0187.namprd13.prod.outlook.com (2603:10b6:a03:2c3::12) by PH7PR12MB6468.namprd12.prod.outlook.com (2603:10b6:510:1f4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:08 +0000 Received: from CO1PEPF000044F5.namprd05.prod.outlook.com (2603:10b6:a03:2c3:cafe::30) by SJ0PR13CA0187.outlook.office365.com (2603:10b6:a03:2c3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044F5.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:07 +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; Fri, 25 Aug 2023 03:03:06 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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; Fri, 25 Aug 2023 03:03:05 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:05 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d549fb41-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fs7dRZlvKEOhHv+E6cEfm2fZ0nfh5k3uB4oDbP1q0FRo4BN7Lxgrr78LDaEjI2NN8ppFTDDLHWPzXODJh4YYSl0UScB63mxe6uXeXYp4PmQXWIJi24OQ6vnUN4nTgk7MztMoJEz5wzraVY/wwt8+qqawfZLot180x3MSzccMeCi+mVP2KNaRUNArGAkadCCq8YRj/I94oEg6I/B/oQpD1n9w2xxgvK4xSsph79cLrcAAnWSEzZG1X6IgUOf62G1pkUhs7hOxtIHfh598HmkCXlOvU3rRAQA5s1a2FwlansMAbnfbqavr+QkucSq9iKnWT/Wf0XWeat1l6ebdot9w7Q== 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=DsiBT9jjQhqD0zQRf4D+MByTVTTUTOKSG4a50D9pHVbvY7kaVl4XnyL7sYdnivAj13uEVzdUMeBnqIZ+45BqDYXHKyJaFXUXt/+3qZMwxHx1fHXmC7i1CK814NthhmRbdyfS2kcuWjnMN52EbQbssTq+KAzBo1ohb5gjcFyHxUoNbrE6R3Kgg7suG1oPBzAPBbiMBHIHoy1Zk68ve0vFNDLTpmJQrO4JWo7rAV6AkNqC+ol1j9p8i/sL0DIAquu68dhppSskgIcbuLiFZskhoDJ/lbBMB55mDZh9Awr5hWaLsfU8dW9bmW+4yzzuzXBY6xN4J1NrWBJ+Hzo5QUe2Bw== 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=HJuHfWG/PoC2FQpydKkiVaKhWDeLqd97oamHeUlGLsrRZH2bZhBlwSrWhk3WZpKTqShhi/CPqMuntAmxyw7Ht69/4+CguXJbokRkxfa3U2Q29NQtrbfs1+dvG0rXAZesc5Ft47w8L2e7z6d2D6EeUmbPj5IylZFNsdBQcvkFiEE= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 13/20] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Fri, 25 Aug 2023 01:02:15 -0700 Message-ID: <20230825080222.14247-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F5:EE_|PH7PR12MB6468:EE_ X-MS-Office365-Filtering-Correlation-Id: 3699c4fd-6df1-438d-976e-08dba541b7cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EJmj9JmKq4l8UAVdzucsDdS9wHrBcBZMAyC/L5+leOja8hlGM20/t+tN6Lvfny4Z5qHpynMjmxS9fDMShW6TrWI0q4U6RDuwSUgLa7MXTja3TgNpwVyo4I5x66wicO+/Q14MJLPezuQsBhIkOHx5cOHG8MTi8/lFqJ3TtvK8a/gWD5oLX7U33EuNsuneIbhGQ01ojN8uAPgOPROTByrXXjqPtXlYzxw7mQNkg/ozPRBcXERF2sE68JhiH4p2ZC+yhwsLMGlDeUeD+InpXDkp00UDPqgldo0s9/r2KD3JSo4pW8gGcgu1JCGF2JdQDLOB2QGQICD8R6yttmUns4rFCFcVgyyNGuMkkuZkJzz1OIkT/Y4v1JIoUukF5e02eczFXl1S2DPTMQBJ+pQHWUE8DRJJxjM9ZWDzWRPdhe/TpadVG+5XWyfQjssyzzatFON/Y+4naX+WmgabLTavbZO34w125alfCAOFo309fTYa/7Dxc4SbZvOhDZbvwPJZYjlthHLC0aVAgzu3VYx+Q437R3nEKNtZESY6z3g1AgByDBeDIHsgJ7n4cgX49Qp61GJYks+xQ4/chRSsinsD2Bmq/0alCcf5zpp/4/hObbhHOnGw3uKzlSFIMkQ07QAM0dCpK0XXimuX3SC8MZJF0n7WYztofoVCySZ5IJ94fFvGeHuKqTW1TEvbwUw5iLaMBwyAOEJPKWRoeRzHCdzscmoODxO2mvMJgYlxyLyQjm46Jaa/tVblnZcIEK3lVTD0FZhtZfGeT1NXEvW5hdNJhALrDQ== 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)(136003)(396003)(39860400002)(346002)(376002)(451199024)(1800799009)(82310400011)(186009)(36840700001)(40470700004)(46966006)(356005)(82740400003)(86362001)(81166007)(36756003)(40460700003)(6666004)(478600001)(5660300002)(70586007)(54906003)(316002)(70206006)(6916009)(2906002)(4326008)(8676002)(44832011)(8936002)(40480700001)(426003)(336012)(83380400001)(26005)(36860700001)(47076005)(41300700001)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:07.6631 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3699c4fd-6df1-438d-976e-08dba541b7cf 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: CO1PEPF000044F5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6468 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950623921100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 dependenc= y: 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 @@ =20 #ifndef __ASSEMBLY__ #include -#include #include #endif =20 @@ -23,6 +22,9 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); extern void noreturn stop_cpu(void); =20 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 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950621; cv=pass; d=zohomail.com; s=zohoarc; b=XxBfFsjSt2ec/RzYIHXL3rElTlFZtkgEb9UQUVPbe3nWUB2Kl0Qkpwg23V6Ix877DeXXMWuiY0eeJ+w1RfmRht7Q31z5yrN8haV+gCFbsoCLRlHVa9ASn7VodmUWRscua6HYLOip7SzVrDITKUeTMuUfzXR453yKX8ZD1IgOcW8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950621; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vRgubDfFnAvFwagyB0ghhVyfbsrh9DPQoCEwaYuA3Nk=; b=TX0h4nti4CeUyxJkhfokyTflnjvQt6vKCkvswYcbTBE/5NhxQuEJjlP7KQayHyL3Fce2CpkejKORBiS5cK9L1i4bDQzU3pslSCjOFHwUhL8UuEqECsEiVSYksUtKXzM4g+QlfPVf3N51xiFTzon/LnuCe7n+bm4ldq51D5DGQXE= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950621622354.4984683259612; Fri, 25 Aug 2023 01:03:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590554.922943 (Exim 4.92) (envelope-from ) id 1qZRml-000161-Ep; Fri, 25 Aug 2023 08:03:15 +0000 Received: by outflank-mailman (output) from mailman id 590554.922943; Fri, 25 Aug 2023 08:03:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmk-00012w-T7; Fri, 25 Aug 2023 08:03:14 +0000 Received: by outflank-mailman (input) for mailman id 590554; Fri, 25 Aug 2023 08:03:11 +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 1qZRmh-0007GZ-Ie for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:11 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20619.outbound.protection.outlook.com [2a01:111:f400:7eb2::619]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d4df1a39-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:10 +0200 (CEST) Received: from MW4PR03CA0255.namprd03.prod.outlook.com (2603:10b6:303:b4::20) by SN7PR12MB6813.namprd12.prod.outlook.com (2603:10b6:806:267::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:07 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:b4:cafe::8b) by MW4PR03CA0255.outlook.office365.com (2603:10b6:303:b4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:03:07 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:03:07 +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; Fri, 25 Aug 2023 03:03:06 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 01:03:06 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:06 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d4df1a39-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X0J80O5mkwUxvK9/OtW0ThLME+hmLP4Y2mYSFuQ1I5NpprJFE296CTPc0yHU42GagpAl/F7YLsU/4yR6uXd4TgoPo8PYqLVsXx6cKoq2/muVFDAI+d5/PFMJd/fGHSp8yZPj704R7lBtm62SPihIMIQieExi2B1dCka+AQnQ8+VBC/xtBbvrDjuh0LCnOMmMz6ttM9lmG+Is6bk6tz1/drYmJrYSqK7qlUsWTGLx0zW1Q9k6HTPVYaVeKtCDOmGaYPyjYxzrKfc0QygsMRwfRsLk3Pf1+KInF4LxawDTZ8DiJDWWAyWRQMpyVE8uFKOJ2E+t05NRCC+yyePAhTasnA== 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=vRgubDfFnAvFwagyB0ghhVyfbsrh9DPQoCEwaYuA3Nk=; b=MakoNwa62UL+2x6QFtUHTvtaz7795NG5CWtm7dvh2EcfKySCrmtIZuYNZQDmosooyBcyywOFok8C5g8jnKLeO53r2xapmTDHaCXxPFiuLidWSSp6POpW+65IJSKAg4vZO4uU0rrv40lt9iX+/tjFqPgQCiPs/OhWtSM98ZIB8V7TgJKz5qjVZMSWOohdvAiMc1zVjTV0JuquYiDT+ibs5wAvVVkLiq7/eyhvAm58V4bZMy2qa9sNH2UR7kA3LfAoaCaaD5LUa2OzTlgxhssQxIjq0cFr/9QqCBrk8n38xHnsxC469XF1E32A3tJgspRMj4La+URELhOo2W1i0wC7lA== 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=vRgubDfFnAvFwagyB0ghhVyfbsrh9DPQoCEwaYuA3Nk=; b=vuH3Tf04k3cUtCoYTKDu72U3B5cNMIxNYZA9sujHGKxHwlg1HYx5I+Wke7KMFN+brUzgLVLEiSQf7Ni7K041uFRiyRPeI2pDxvOuOlM3sMLsB9bXmGalMfa327LNORWIlh98fYcKqggJD9LbuNk7o6oJJHpiK66hAy4vMCeZ0YE= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 14/20] common/device_tree: Add rwlock for dt_host Date: Fri, 25 Aug 2023 01:02:16 -0700 Message-ID: <20230825080222.14247-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|SN7PR12MB6813:EE_ X-MS-Office365-Filtering-Correlation-Id: 17ee52d9-2f6c-4647-bf61-08dba541b7bc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e6bRD0fDwtMPzLm2MFmo+Z9Nr8YBtasXxBrf/RaZ/1ATv5O2btgYpTQfI1tVTyvIfkpgm0YiIsSvKsL8jZyeyHPuJzyTgDx9tyJWhj2f8cVGmW7MB8Z3pLrfHQzWIjozZEnV3w3yj7ymSVpv9eoCNKAYG1Z8aLoM43NBB1GVCrQq+cyQyP/MtvBsw2LeIMGFoXFmcB9pE98IJyw+Fx8W7PetVlL/EGayFgRrw8/uw0nADbxIdaubPFl2YgpQoTkCtd2C1NO/yHzmX54sYB0MhQJ4u5pWQbUPVOtcI8sjpCuzpst6SBqyz77WISOiaJh1BcjwzC3zIMvCtTeJnjLT8kpDrHu5FfRVbjm6b3xyhTz4l2MWUpFcDw1uEBJamMMOH4UXGFJY96wDG9/0JBTdJyNXsqQSiEtkKRMJ1pIJDX6yS3wKFx9uAx+NngevcarijtMOfKrsdRpCkiqDespHAo7PkKEn87eEWh5LUo3iMbtIOaBWQuYs68kHOY4Ltb+aqIMYTc90uzSpLO0y/U95mBXUwWMT+S4oTUJDSDv25K2CsjofN4JGWYWrEnbODwpAKQdNTBYR8AI4vBsc80SqL2bLbGDY8amqVOj7DwDc+y+9TaiqYqj5kDFO7yA3Q4S7isIwTYpTjUQJH0BehUm+4XToR3gAzd3bBNw7kllgI89SxQJV43eJzfk/VCGC/XLCezZkK+ypmrjFTYEJwt5j3sJySVpQz1NFkX/P1xik3j3L553kF9nPYaZObotRbZFteX6VfMrrlYDyofab0haq1A== 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)(39860400002)(136003)(396003)(376002)(186009)(1800799009)(82310400011)(451199024)(40470700004)(46966006)(36840700001)(54906003)(70586007)(70206006)(316002)(6916009)(81166007)(478600001)(40480700001)(26005)(6666004)(82740400003)(41300700001)(86362001)(2906002)(356005)(4326008)(8676002)(8936002)(83380400001)(2616005)(40460700003)(5660300002)(47076005)(44832011)(1076003)(426003)(336012)(36756003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:07.5708 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17ee52d9-2f6c-4647-bf61-08dba541b7bc 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: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6813 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950623641100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 duri= ng 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 pro= tect others from browsing the dt_host while dynamic programming is modify= ing it. rwlock is better suitable for this task as spinlock won't be abl= e to differentiate between read and write access. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- 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 | 24 ++++++++++++++++++++++-- xen/include/xen/device_tree.h | 7 +++++++ 3 files changed, 30 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); =20 /** * struct dt_alias_prop - Alias property in 'aliases' node diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 3fad65fb69..b81dab5a48 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -62,6 +62,8 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_= device_node *dev) const struct domain_iommu *hd =3D dom_iommu(d); int rc; =20 + ASSERT(rw_is_locked(&dt_host_lock)); + if ( !is_iommu_enabled(d) ) return -EINVAL; =20 @@ -114,6 +116,8 @@ int iommu_release_dt_devices(struct domain *d) if ( !is_iommu_enabled(d) ) return 0; =20 + read_lock(&dt_host_lock); + list_for_each_entry_safe(dev, _dev, &hd->dt_devices, domain_list) { rc =3D iommu_deassign_dt_device(d, dev); @@ -121,10 +125,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; } } =20 + read_unlock(&dt_host_lock); + return 0; } =20 @@ -134,6 +142,8 @@ int iommu_remove_dt_device(struct dt_device_node *np) struct device *dev =3D dt_to_dev(np); int rc; =20 + ASSERT(rw_is_locked(&dt_host_lock)); + if ( !iommu_enabled ) return 1; =20 @@ -251,6 +261,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struc= t domain *d, int ret; struct dt_device_node *dev; =20 + read_lock(&dt_host_lock); + switch ( domctl->cmd ) { case XEN_DOMCTL_assign_device: @@ -294,7 +306,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, stru= ct domain *d, spin_unlock(&dtdevs_lock); =20 if ( d =3D=3D dom_io ) - return -EINVAL; + { + ret =3D -EINVAL; + break; + } =20 ret =3D iommu_add_dt_device(dev); if ( ret < 0 ) @@ -332,7 +347,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, stru= ct domain *d, break; =20 if ( d =3D=3D dom_io ) - return -EINVAL; + { + ret =3D -EINVAL; + break; + } =20 ret =3D iommu_deassign_dt_device(d, dev); =20 @@ -347,5 +365,7 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struc= t domain *d, break; } =20 + 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 =20 #define DEVICE_TREE_MAX_DEPTH 16 =20 @@ -218,6 +219,12 @@ extern struct dt_device_node *dt_host; */ extern const struct dt_device_node *dt_interrupt_controller; =20 +/* + * 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 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692950632; cv=pass; d=zohomail.com; s=zohoarc; b=Al4qdBsYZ70HFMJn6LbdUuSDKcwFndHKJW/RS7wRq6xZhmbkXjkqzUqBoKLEpUsVoEJ70cW8Dmec73Cn/JGJtVwgAMdkPmUbl6pBSUWrrbMYVBpgIV5UfAmIrAIQxMYtS0jDhALfJ5OIFaUU7hdcgwVIdWFpvGhIDOzKJqchT6Y= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692950632; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xLOhd+eCdzsILcS2OSpdjdN9Er/z7fDSt3+c00KeABo=; b=Z0zQ383tZdubEMapcXaeglXdUXAn6+NzuuQE0vM+3+DC2zftFH+cQPQFXrVmp7nGMZSXgZlyaAl5njvH19KgItEcaR2tqHxSkZbrv36CE7OSp3dbt2wVPp0f0gJiMbcKb+uqA0Wp5/IV8LZZrJuKsIiSasxdrWae2iyUCg424Fk= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692950632165161.0805900647149; Fri, 25 Aug 2023 01:03:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590562.922989 (Exim 4.92) (envelope-from ) id 1qZRmr-0002Xq-Mq; Fri, 25 Aug 2023 08:03:21 +0000 Received: by outflank-mailman (output) from mailman id 590562.922989; Fri, 25 Aug 2023 08:03:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRmq-0002VD-JF; Fri, 25 Aug 2023 08:03:20 +0000 Received: by outflank-mailman (input) for mailman id 590562; Fri, 25 Aug 2023 08:03:15 +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 1qZRmk-0007G4-P1 for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:14 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2061f.outbound.protection.outlook.com [2a01:111:f400:7e89::61f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d5cc5d26-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:13 +0200 (CEST) Received: from MW4PR03CA0296.namprd03.prod.outlook.com (2603:10b6:303:b5::31) by SJ2PR12MB9005.namprd12.prod.outlook.com (2603:10b6:a03:53d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:08 +0000 Received: from CO1PEPF000044EF.namprd05.prod.outlook.com (2603:10b6:303:b5:cafe::42) by MW4PR03CA0296.outlook.office365.com (2603:10b6:303:b5::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.26 via Frontend Transport; Fri, 25 Aug 2023 08:03:08 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044EF.mail.protection.outlook.com (10.167.241.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:07 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:07 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:06 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: d5cc5d26-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eSsOTsv5SYkcalJtf1erOn8A0zxKP7qkGcOMnuhdQEbq2fn8KSO3+B829NqxuGywbWClB/pR8l9hKRimYaqpcdO48Eg+ve+BeblvGDY4vs6WxTtKZvcJ0+odIRV/bMhu0N6liBXZRyPEHqWQ5CODZMwNiQpmvnzXu9v0RsFYcuOmke7tTtX54S3KFYiWBEMi0XUQ7DdkLZks92rpim5gqwFb8K3T0hAEUxoRaGKqkDQGQGVqC0KSaQOh18FheRm05zUzzGpSq6rQFVUQ2VrHEN2srFLVkwiYkt1+u0q344YilNcylTMqPhCDNywS9r1gz7Zun7QlugweZ5CmGsd9JA== 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=xLOhd+eCdzsILcS2OSpdjdN9Er/z7fDSt3+c00KeABo=; b=PKJAFiY0PDzzDqhxfyOKTzrkVgqqOljxXLtiVr2SIpAbZIzvRXrlToN5VaDcjqRHkx31XTL2S9UR/CRR0Nv1o3gJljTIgRO+s4JWedAwqGqcbl7ht1OUFUY5xlJABMJdKo6T7plk/F3znaluSEBGoCap6Z8HTA8Gxs5s7IX9xYKpE80ibDmTZPpaTUyJ2QtuNdmaxA+u1HEsdpywDYC4GnedmHJPfAAvpORPuEeq2b1jglcfKqdxK918dqgu5hSct/H8BJSNU8XA0nDxwdtvtKJrtIrvtdryiVkvYGvFfgX50q7OAnVcsJ/oGO+J+TsBq0hv29ZswHo9wv79xaKHeQ== 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=xLOhd+eCdzsILcS2OSpdjdN9Er/z7fDSt3+c00KeABo=; b=qVKo3AqFfsJZ3Dph5zczmfQOO2xkJQYOuIWWyKPCnYMegxFJpO2G5j4R08/j3+r8wtbGjNOT9rvzqArpgi7RqaMfG+hPQQi5OKeVr0Yu/K6nDeLWu8CAP/hZJO52PsPcdvGRruhw5zzwbSq7fLI5mjru3uiba5tf7tsrHaqsEZI= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 15/20] arm/asm/setup.h: Update struct map_range_data to add rangeset. Date: Fri, 25 Aug 2023 01:02:17 -0700 Message-ID: <20230825080222.14247-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044EF:EE_|SJ2PR12MB9005:EE_ X-MS-Office365-Filtering-Correlation-Id: d63acfd1-83ff-439a-b564-08dba541b7e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g9X/AsVV56MBJoI6K9WkCBJaEb1tkn/mw27WNB3jZleSVN6H52MuzvEeqOTNTAnNCxvsGFsam4+Jg7l31Gs04LylPCzi/fNMdkI/sFbj9clE9QQ0VD5sHnN8TF5TG1vsE9ZKPDpcDzDc60P8yniVpJIWwHRuLV2Hs6P/ZRicbKTlqzedCdhEdNCnzOI8ffUaTnNSKktWnWLo0WpYoNitx2/TVy/BQCED3W+HSC4RtkmTaWEiK0V6EJqbIsNLzGIT4G5E0QXdZxHd5rQu5zz8a+MStUZHSzDvgtx5lq/7egnhp/FsRD1YoGhgKKHTowt+k1myQA6rtq13YLQgl2pT4sULznmr296qonGb4x+dzHEQwHj9Wrp6iWMxSjFbQFCvKGbZ+Qm3vQj2XgJSoAvpp0shQVqYC8lVlameRxVimX7G3ga3jKQTW8hPF9lS7AnxV8CR680Zle5u/oOddVl10tzsMk2uKT319gbvrF27iQFHXpDTIZFxSpo4iFNwoG3TiV7Uwguxy5wLK80Fji2CUX8To/ED5791PqWMFvb40nWFdLGvGo/05DZld4jYrotaor6JP5/E0NePn33wAuD/v1RhRP8D18luCpmhQstSfm2ERCZgk8wi/cAHFC45l62u0QK37SFnVo8o82DSy/vxZGEQudwPsTbrYmpcu9ymttrP1t9BZNXyJOPLodwt/chMG1VlhpeFQkqRr3dm1oGau+jIL5j0SOJlUYcfMZG3ptZYLS9fVJnjiTKMF/0IX0Sb4mfc4nqrw5BJd0JI/MOVaQ== 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)(346002)(376002)(396003)(186009)(82310400011)(451199024)(1800799009)(46966006)(36840700001)(40470700004)(54906003)(70586007)(70206006)(316002)(81166007)(6916009)(478600001)(26005)(40480700001)(6666004)(82740400003)(41300700001)(86362001)(2906002)(356005)(8676002)(8936002)(83380400001)(2616005)(40460700003)(4326008)(5660300002)(47076005)(44832011)(1076003)(426003)(336012)(36756003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:07.8196 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d63acfd1-83ff-439a-b564-08dba541b7e2 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: CO1PEPF000044EF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9005 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692950632609100009 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add rangesets for IRQs and IOMEMs. This was done to accommodate dynamic ove= rlay node addition/removal operations. With overlay operations, new IRQs and IOM= EMs are added in dt_host and routed. While removing overlay nodes, nodes are re= move from dt_host and their IRQs and IOMEMs routing is also removed. Storing IRQ= s and IOMEMs in the rangeset will avoid re-parsing the device tree nodes to get t= he 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 --- xen/arch/arm/device.c | 43 +++++++++++++++++++++++++------- xen/arch/arm/domain_build.c | 4 +-- xen/arch/arm/include/asm/setup.h | 5 +++- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 857f171a27..9df37abac8 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -165,6 +165,14 @@ int map_range_to_domain(const struct dt_device_node *d= ev, dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=3D%x\n", addr, addr + len, mr_data->p2mt); =20 + if ( mr_data->iomem_ranges ) + { + res =3D rangeset_add_range(mr_data->iomem_ranges, paddr_to_pfn(add= r), + paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + if ( res ) + return res; + } + return 0; } =20 @@ -178,9 +186,10 @@ int map_range_to_domain(const struct dt_device_node *d= ev, */ int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, - bool need_mapping) + bool need_mapping, + struct rangeset *irq_ranges) { - unsigned int i, nirq; + unsigned int i, nirq, irq; int res; struct dt_raw_irq rirq; =20 @@ -208,17 +217,24 @@ int handle_device_interrupts(struct domain *d, continue; } =20 - res =3D platform_get_irq(dev, i); - if ( res < 0 ) + irq =3D 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; } =20 - res =3D map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + res =3D map_irq_to_domain(d, irq, need_mapping, dt_node_name(dev)); if ( res ) return res; + + if ( irq_ranges ) + { + res =3D rangeset_add_singleton(irq_ranges, irq); + if ( res ) + return res; + } } =20 return 0; @@ -249,6 +265,11 @@ static int map_dt_irq_to_domain(const struct dt_device= _node *dev, } =20 res =3D map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name= (dev)); + if ( res ) + return res; + + if ( mr_data->irq_ranges ) + res =3D rangeset_add_singleton(mr_data->irq_ranges, irq); =20 return res; } @@ -289,7 +310,8 @@ static int map_device_children(const struct dt_device_n= ode *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_rang= es) { unsigned int naddr; unsigned int i; @@ -304,10 +326,13 @@ int handle_device(struct domain *d, struct dt_device_= node *dev, p2m_type_t p2mt) * pci_host_bridge_mappings(). */ struct map_range_data mr_data =3D { + .d =3D d, .p2mt =3D p2mt, .skip_mapping =3D !own_device || (is_pci_passthrough_enabled() && - (device_get_class(dev) =3D=3D DEVICE_PCI_HOSTBRIDG= E)) + (device_get_class(dev) =3D=3D DEVICE_PCI_HOSTBRIDG= E)), + .iomem_ranges =3D iomem_ranges, + .irq_ranges =3D irq_ranges }; =20 naddr =3D dt_number_of_address(dev); @@ -341,7 +366,7 @@ int handle_device(struct domain *d, struct dt_device_no= de *dev, p2m_type_t p2mt) } } =20 - res =3D handle_device_interrupts(d, dev, own_device); + res =3D handle_device_interrupts(d, dev, own_device, irq_ranges); if ( res < 0 ) return res; =20 diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 63ca9ea5fe..8e9dd0c373 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2401,7 +2401,7 @@ static int __init handle_node(struct domain *d, struc= t kernel_info *kinfo, "WARNING: Path %s is reserved, skip the node as we may re-u= se the path.\n", path); =20 - res =3D handle_device(d, node, p2mt); + res =3D handle_device(d, node, p2mt, NULL, NULL); if ( res) return res; =20 @@ -2744,7 +2744,7 @@ static int __init handle_passthrough_prop(struct kern= el_info *kinfo, return -EINVAL; } =20 - res =3D handle_device_interrupts(kinfo->d, node, true); + res =3D handle_device_interrupts(kinfo->d, node, true, NULL); if ( res < 0 ) return res; =20 diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/se= tup.h index 1a052ed924..2dc6d4c1a6 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; }; =20 extern struct bootinfo bootinfo; @@ -169,7 +172,7 @@ int handle_device(struct domain *d, struct dt_device_no= de *dev, p2m_type_t p2mt, struct rangeset *iomem_ranges, struct rangeset *irq_rang= es); =20 int handle_device_interrupts(struct domain *d, struct dt_device_node *dev, - bool need_mapping); + bool need_mapping, struct rangeset *irq_range= s); =20 int map_range_to_domain(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data); --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692951148; cv=pass; d=zohomail.com; s=zohoarc; b=j7LoPUNOf3oo8CBB7wIJADkBt7hj4bFERCblT5y87i2eXFSKQpUzmtxyOpvjCkOySd0sAtdw6QBKvfMIbUpFiWgx/PEgqOCuxZ5CNFJzfrZLuWLbXVrgGCoIy/0LkAGW9p/pEqXU+uWnwbjF+cqae4tNXXPOMsioBWRAiHer5/4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692951148; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zt/V6Dm8rU3iuQaBnl1b6JyUY5OvDZ99vua8YutGWYU=; b=YtOCqPMUMMQW1WRMDXMoJf6wKVopMm0rUIeKbe5xovnPeKC3DNFaAgGI+QYxCeCeGQ9iQQopw4ERd2Uc2/Ntgfa7WCz9KYDj4Xv7zK1hCtc48MGJQkMHH98vwnU7c1m2O4L42U9nm9PvFS8Bisxd8E9Q9W+zDvJjT7zyvyoWG5U= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692951148784902.0505676194766; Fri, 25 Aug 2023 01:12:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590704.923087 (Exim 4.92) (envelope-from ) id 1qZRvP-0005LG-MX; Fri, 25 Aug 2023 08:12:11 +0000 Received: by outflank-mailman (output) from mailman id 590704.923087; Fri, 25 Aug 2023 08:12:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRvP-0005L9-Jq; Fri, 25 Aug 2023 08:12:11 +0000 Received: by outflank-mailman (input) for mailman id 590704; Fri, 25 Aug 2023 08:12:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRnP-0007G4-V4 for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:56 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20611.outbound.protection.outlook.com [2a01:111:f400:7e89::611]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ecf36cd5-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:53 +0200 (CEST) Received: from DS7PR03CA0122.namprd03.prod.outlook.com (2603:10b6:5:3b4::7) by MN2PR12MB4128.namprd12.prod.outlook.com (2603:10b6:208:1dd::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:47 +0000 Received: from SN1PEPF0002636C.namprd02.prod.outlook.com (2603:10b6:5:3b4:cafe::27) by DS7PR03CA0122.outlook.office365.com (2603:10b6:5:3b4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:03:47 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636C.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:46 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:08 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:07 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: ecf36cd5-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BeTObQ4RvJZOwegyp65K0/kaf9HbX+dksOkw1soA5EMBOiOtbfuT4T3DOcCl60wH8C8C1E0kpj8CHURy0YnGW5lVJVS7RNUBGwJBbMwTmrfHidXmpcC/HBhFsf9l/gjg0tMONYN5KJkVNkxh3JFQflcQdW5B653nuxGziN6LkcNUrnH7L8hcmAlI49kOOJ5oIycqIfJhElLegjxWiCt2g0tZH9D2WajSmZcN9AgXUNirRFNbV16p/+61blkDOyelL1lAQzxsgWicje0QMC9X9C8VDMbJ24Fd+6c4oq6SaRYcZLzWYUZNu9rFOsS1XOYLWdZAy6UZUcDi2FP/P0b/ww== 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=zt/V6Dm8rU3iuQaBnl1b6JyUY5OvDZ99vua8YutGWYU=; b=ne8wK+ZqTPEaMh9GBMpQmhGjLc2j34N1EerAaAsZZZs3VKM8z19kQL/lLpuwgTDbu18wZIBTvl1fjRVzpLh3ppR0U+MYAv7B+sQBKkmxDldmyvlwOcusY63RTK6wrNMEA4Z81cp1rHHGZyExPHD3vowWunfCwWFM+C5QamKmdXoHNzIGnwOKIC38EShCbItv2MUIXM4TNCmo/TJjIcZ/pU6KNjZcRBcPGQNydSn9iwjAtBuYSI+ZNyd63BghOLCL4YFqYRo8Lif01OUBSapa27Pasfzg01vHG7aQuKuZYFuw0u5WUwxzmkVZHlYkumMxUewIodMFO+LZKhSBwP+D4Q== 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=zt/V6Dm8rU3iuQaBnl1b6JyUY5OvDZ99vua8YutGWYU=; b=mBvRBfvYZnwYI5T2uXJc3g098XrHoV8pb1RrQXGmYaz2ePUh9yt1yOHMi7Oks3gPpeYgRK9PFsk3sxs2JFPQURQUGPbvmGoq5GK+UVS61UWm0Zq/Y9qIN76NMgprl5s8aULCA4en4Oa3iY6R3JjgQewR4/iYvcFOqqlurNZMa5g= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v10 16/20] xen/arm: Implement device tree node removal functionalities Date: Fri, 25 Aug 2023 01:02:18 -0700 Message-ID: <20230825080222.14247-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636C:EE_|MN2PR12MB4128:EE_ X-MS-Office365-Filtering-Correlation-Id: af614152-bad7-4e36-3a1d-08dba541cee8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1W4x7UTG/uQjyY1GBJLvwhbR1z9bJN29lWBe/5U/xChxnnkXaV+doWkjEr0gG3qgZ1iXFw/F4J+yu5b5Mw5874mpiU9YCF5hSQpw1fiusnBdF04EI9RIQxesQjgiawMSynh6bJAHHnwYvUG0+Qu6ui3bSZakn4mQs6rKUgJARhSqw1q7FEvweGjXjUkmT2IB6/OheRvxJVbl4j7VRMmRI052MEr0y+cfDDSrsZ7YKiXJHW9ssg175zPEgAzZQjGpLDcapsfenQiHqmXK+emRBXXhbQauUHKpLM1TP+NeiWNXn/eRcY4KpT7S+5Y/nksI7Yk9JzdRAN3LIeSpoeOKQqLR2JOSfl3L4S8eSexmfHn7UlWw+AFn7bMeuGXsjTNT8Ew93IoGeeNO4OnFAvMsS5+SWHO3Kgc7mGLf3dt1fgwyJvDTr+LLjgnauJcr8vUgNHJf4EIq8D1N/oewM5PSqSyHOsLP4f+JOeIR4/8Mj8HBxEnw+0tYjWbXNZs6FVigjC+cw7bLTE/Tg7LCc4O/sxBGXf25qwgMT9V0YMyfOYXvntNYng3YBbDLxcZ0N9Ire5sAOVe86qQoTpbW7HgO5FX4p84lHS8RJssQsecQPBtNVPi6Ff3y71030tb58nOaqeD3ZWP5Q8RBDwlzgAmJXG6LSzNXvUsl9KyvxwIE9aUHbWQRDPhjM2ZA1z3wyT0scArMY4btjhJNtRu0lpTkrOSjxIV2GDY4zPALLlkUIbZnOpLgUhIrgi8ETs+1TMIOr2ZKHFlMDjWXYtcpGlcgZwTmZASTXeb69AL/ZdCRBoPFRScS7oNEqyuXek1nhrxI 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:ErrorRetry;CAT:NONE;SFS:(13230031)(4636009)(136003)(396003)(376002)(39860400002)(346002)(451199024)(82310400011)(186009)(1800799009)(40470700004)(36840700001)(46966006)(54906003)(70206006)(70586007)(316002)(81166007)(40480700001)(6916009)(478600001)(26005)(36860700001)(44832011)(6666004)(356005)(82740400003)(41300700001)(86362001)(2906002)(8936002)(8676002)(4326008)(1076003)(40460700003)(2616005)(5660300002)(83380400001)(36756003)(30864003)(336012)(426003)(47076005)(333604002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:46.5371 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: af614152-bad7-4e36-3a1d-08dba541cee8 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: SN1PEPF0002636C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4128 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692951151161100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce sysctl XEN_SYSCTL_dt_overlay to remove device-tree nodes added us= ing 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 no= des 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 de= vice tree overlay. overlay_track has dt_host_new which is unflattened form of up= dated fdt and name of overlay nodes. When a node is removed, we also free the mem= ory 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 rem= oves overlay_child and then removes overlay_parent. Also, this is an experimental feature so it is expected from user to make s= ure correct device tree overlays are used when adding nodes and making sure dev= ices 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 --- 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 n= ode. 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, re= named 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 | 392 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 24 +++ xen/include/xen/dt-overlay.h | 63 ++++++ 6 files changed, 496 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 a0805d35cd..c41a7c5440 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 @@ =20 #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 =3D dt_overlay_sysctl(&sysctl->u.dt_overlay); + break; + + default: + ret =3D -ENOSYS; + break; + } + + return ret; } =20 /* 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) +=3D debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) +=3D device_tree.o obj-$(CONFIG_IOREQ_SERVER) +=3D dm.o obj-y +=3D domain.o +obj-$(CONFIG_OVERLAY_DTB) +=3D dt-overlay.o obj-y +=3D event_2l.o obj-y +=3D event_channel.o obj-y +=3D event_fifo.o diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c new file mode 100644 index 0000000000..12a3029fee --- /dev/null +++ b/xen/common/dt-overlay.c @@ -0,0 +1,392 @@ +/* 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 =3D device_node->child; child_node->sibling !=3D NULL; + child_node =3D child_node->sibling ); + + /* If last child_node also have children. */ + if ( child_node->child ) + child_node =3D 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 =3D device_node->child; + + parent_node =3D device_node->parent; + + /* Check if we are trying to remove "/" i.e. root node. */ + if ( parent_node =3D=3D 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 =3D parent_node->child; + if ( np =3D=3D 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 =3D 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->all= next + * should point to node next to last children. + */ + if ( last_descendant ) + { + last_descendant =3D find_last_descendants_node(device_node); + parent_node->allnext =3D last_descendant->allnext; + } + else + parent_node->allnext =3D np->allnext; + + return 0; + } + + for ( np =3D parent_node->child; np->sibling !=3D NULL; np =3D np->sib= ling ) + { + if ( !dt_node_cmp(np->sibling->full_name, device_node->full_name) ) + { + /* Found the node. Now we remove it. */ + np->sibling =3D np->sibling->sibling; + + if ( np->child ) + np =3D 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 descendant= s too. + */ + if ( last_descendant ) + last_descendant =3D find_last_descendants_node(device_node= ); + + if ( last_descendant ) + np->allnext =3D last_descendant->allnext; + else + np->allnext =3D 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) !=3D 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 =3D 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 =3D irq_deny_access(d, s); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %lu\n", s); + } + else + *c +=3D 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 =3D dom; + + /* + * Remove mmio access. + * TODO: Support for remove/add the mapping in P2M. + */ + rc =3D 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 +=3D e - s + 1; + + return rc; +} + +/* Check if node itself can be removed. */ +static bool check_node_removable(struct dt_device_node *device_node) +{ + domid_t domid; + + domid =3D 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 !=3D hardware_domain->domain_id && domid !=3D DOMID_IO ) + { + printk(XENLOG_ERR "Device %s is being used by domain %u. Removing = nodes failed\n", + device_node->full_name, domid); + return false; + } + + + return true; +} + +/* Check if all descendants of the given node are removable. */ +static bool +check_descendant_nodes_removable(const struct dt_device_node *device_node) +{ + bool rc =3D true; + struct dt_device_node *child_node; + + for ( child_node =3D device_node->child; child_node !=3D NULL; + child_node =3D child_node->sibling ) + { + if ( child_node->child ) + { + rc =3D check_descendant_nodes_removable(child_node); + if ( !rc ) + return rc; + } + + rc =3D check_node_removable(child_node); + if ( !rc ) + return rc; + } + + return rc; +} + +/* Remove nodes from dt_host. */ +static int remove_nodes(const struct overlay_track *tracker) +{ + int rc =3D 0; + struct dt_device_node *overlay_node; + unsigned int j; + struct domain *d =3D hardware_domain; + + for ( j =3D 0; j < tracker->num_nodes; j++ ) + { + overlay_node =3D (struct dt_device_node *)tracker->nodes_address[j= ]; + if ( overlay_node =3D=3D NULL ) + { + printk(XENLOG_ERR "Device %s is not present in the tree. Remov= ing nodes failed\n", + overlay_node->full_name); + return -EINVAL; + } + + if ( !check_descendant_nodes_removable(overlay_node) ) + return -EINVAL; + + if ( !check_node_removable(overlay_node) ) + return -EINVAL; + + dt_dprintk("Removing node: %s\n", overlay_node->full_name); + + write_lock(&dt_host_lock); + + rc =3D 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 =3D rangeset_consume_ranges(tracker->irq_ranges, irq_remove_cb,= d); + if ( rc ) + return rc; + } + + /* Remove mmio access. */ + if ( tracker->iomem_ranges ) + { + rc =3D 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 use= d by + * any dom and finally remove it from dt_host. IOMMU is already being take= n 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 =3D false; + + rc =3D 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 n= ot + * 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) =3D= =3D 0 ) + { + track =3D entry; + found_entry =3D true; + break; + } + } + + if ( !found_entry ) + { + rc =3D -EINVAL; + + printk(XENLOG_ERR "Cannot find any matching tracker with input dtb= o." + " Removing nodes is supported only for prior added dtbo.\n"= ); + goto out; + + } + + rc =3D 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 !=3D XEN_SYSCTL_DT_OVERLAY_ADD && + op->overlay_op !=3D XEN_SYSCTL_DT_OVERLAY_REMOVE ) + return -EOPNOTSUPP; + + if ( op->overlay_fdt_size =3D=3D 0 || op->overlay_fdt_size > KB(500) ) + return -EINVAL; + + if ( op->pad[0] || op->pad[1] || op->pad[2] ) + return -EINVAL; + + overlay_fdt =3D xmalloc_bytes(op->overlay_fdt_size); + + if ( overlay_fdt =3D=3D NULL ) + return -ENOMEM; + + ret =3D 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 =3D=3D XEN_SYSCTL_DT_OVERLAY_REMOVE ) + ret =3D handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_s= ize); + + 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 fa7147de47..900239133a 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1059,6 +1059,25 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_= policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif =20 +#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 @@ -1089,6 +1108,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; @@ -1119,6 +1139,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 f= rom + 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: + */ --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692951144; cv=pass; d=zohomail.com; s=zohoarc; b=n5c/lk/CfenWAaxvLpThiYkf5NoKqFlxU0PY3ctgQKrIQQp/au5+Pk1Pj0jS6+z0pSEZMnVx8fn0abLQzNwd95b8cBXCZl0aC9YOTQi3Tg55QFaSptF3aK19Jk8sO0mtsNrvdYNl5LywOOQQJZUDaO80nTgPVOgJitg1TrMIZQM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692951144; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=su17ekHBLJzw0hv7K/2ka70d5IT8Mbr5+9d7QLpnNxw=; b=hTagvbtPlmiDO4nPhN29RSbVTSdziXI7RLWUWeBmkl91evTxTRlIBWXF5469pptjHt/SmWFN/eOoGe/p4DUG5pExcsz+cM9lhaXhYjlH+Ng5muv2kHNKAYRJI6Sq4gL5UAuhcN/r2ufHCM9A8bL4vj83IzejDduiSNfodJxUX6E= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692951144598809.9830236483705; Fri, 25 Aug 2023 01:12:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590698.923077 (Exim 4.92) (envelope-from ) id 1qZRvJ-000505-CK; Fri, 25 Aug 2023 08:12:05 +0000 Received: by outflank-mailman (output) from mailman id 590698.923077; Fri, 25 Aug 2023 08:12:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRvJ-0004zy-8h; Fri, 25 Aug 2023 08:12:05 +0000 Received: by outflank-mailman (input) for mailman id 590698; Fri, 25 Aug 2023 08:12:04 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRnR-0007GZ-R8 for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:57 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20625.outbound.protection.outlook.com [2a01:111:f400:fe59::625]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f06efcd3-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:56 +0200 (CEST) Received: from SA9P223CA0019.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::24) by PH7PR12MB8177.namprd12.prod.outlook.com (2603:10b6:510:2b4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SN1PEPF0002636B.namprd02.prod.outlook.com (2603:10b6:806:26:cafe::78) by SA9P223CA0019.outlook.office365.com (2603:10b6:806:26::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.30 via Frontend Transport; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636B.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:51 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:46 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:46 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: f06efcd3-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lmqmKTd+hE+Xko9CJjukWx8rSjOCvWsTmD7mqr9tkDvAos4qmRe6cU1S/yZlSpJYg76LTcSWrR0+a/OoZdokRKju72e3jxgHzBFYKlmqVjNDMdmGZXCuyoi60k/xK8XC+ZZPC5ZVLv98tcf+ob3DqBysxLQJEs6it535AdyWx4tz/dvURyluJbmK9CMzUmJWjKQ4zMnO5Qb+5pSGoZa2b5KrhXr2iV5HcnBkn7T53chx3PMb43vG3Xb0avPHY2qqKnHvhYERQQQO+ljhmNSbNZfUm4NHRLR69br8pW14bQlE6JfpL1lKj35/DZ5W3//dWQH9SPt30rHjsfvZKUeLKA== 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=su17ekHBLJzw0hv7K/2ka70d5IT8Mbr5+9d7QLpnNxw=; b=bcgbO5VsFBZreP7OYF/3vY1Gbw5RD8wpLY69rVRgw8+Fcpjat89NXhuMjC/m1QVmW2DzWQ2qMgyECuYsLOxilG7Q8uv+g8Hp//TFiFrVpQccW6LsyxjQz3aKFHbzKNmkImiUfMxtcaobHRaPuZtS/FGsntJ2k02fA65kv49SCbiW3aqpWNWs+PeDHwaUec2bZFO0pXDx2a4NlgbgJVKIVaEXbJ5nXbMqCNDei2y6YHp3yAt404iLCIhc4wS9fChfo35NXy6adt6+p1Y7xEjdF/gETpaBYLsaOBXtS4sf8ON841BOWD1UADSZns/K3MgxKlf/htzCzb3EXgW+V05k4g== 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=su17ekHBLJzw0hv7K/2ka70d5IT8Mbr5+9d7QLpnNxw=; b=lV1YzYfjyESWL3kHPD2StS2k8MYVorADaShVBuL461f0i/eQr+iFPI1RQzdHaVx3BnFjthY7dso0ktZ35yN5s5sbTPYPKS3aI8ir+vl6QawjDmQKzjTYsIm1viVJtUQPB1CN5A8iG0GTKB+n1EndakcDOoEumRCY18jY40FE3Kg= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 17/20] xen/arm: Implement device tree node addition functionalities Date: Fri, 25 Aug 2023 01:02:19 -0700 Message-ID: <20230825080222.14247-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636B:EE_|PH7PR12MB8177:EE_ X-MS-Office365-Filtering-Correlation-Id: 20d4057b-005e-47fe-b48f-08dba541d21a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cUrYVV5QaC1EaOnVKBYlnxrLZxIWhEIqr/7tOJC9WlR1y07iqd6Vm1CbkSPVN4id0XFMRaLDaH3F3BQC9uAjFUpKO75CUqvjUqPtfIKh8w3Gk7OWDdJp52vaqgwHRXNnmRMyJ8k3S5gMbWN9L43WrN1VVAtFN164sP7HcjTiUIg1FIBfDpaA8z4xx3hRyh2Vjd8Zq3CkNMyyB+PFKt6Gas7O7vdw3HTRS7iXdUXAXW30PCgUXU5gBi+wMs/5EMdm4xnjzzit/CIu5TY6eJbJ5zsYh5htVUaS0tViDOgl2rut26xLpn8LBdwtcNO5lSFe1ioxxCGOoW7duA9DBKVioI+I9Riv6JgeiZH7ZKG0hTWTqNsm5D1F49lQKCK56TxRML3j6+KF2ij2ZoWPzmQSsT1y3Uv8meJ9PRYuCAQskyW71idJ1y91yf/QR/dSx3hbcksnZTpvTfNpECdSblkYNYQqy5CuX50R2uleVn3GqHFIoAqMxt7X6MFZ6vszTwFo5aoMf6YWsgW3ybUbY7LLxsZQGC2ptA+wU+gG3EneZ/za/6MpXIhoXNlwUGTaDwOceWhvyu2IMiL8FcwFMHOo8sSbVvnbiDD1ZFqiw0QcL+To153MWsiCusKx/El3fZlyLZSRVEKN7PW3UDkCi2MdvaG7m1KBhJHDCfh4QiQoCNypPwGZOrTPcM5Q6WuzYSCwVepih78duAWP0Hi4AZ0qO5xRLkf5GxbzFGrCCu0/WWkmH4rD9u6m/9PWJyzu/F5SpvggE+k83dv0sO5J+c9SRQ== 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)(39860400002)(136003)(396003)(376002)(186009)(1800799009)(82310400011)(451199024)(40470700004)(46966006)(36840700001)(54906003)(70586007)(70206006)(316002)(6916009)(81166007)(478600001)(40480700001)(26005)(6666004)(82740400003)(41300700001)(86362001)(2906002)(356005)(30864003)(4326008)(8676002)(8936002)(83380400001)(2616005)(40460700003)(66899024)(5660300002)(47076005)(44832011)(1076003)(426003)(336012)(36756003)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:51.8854 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 20d4057b-005e-47fe-b48f-08dba541d21a 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: SN1PEPF0002636B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8177 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692951145098100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Update sysctl XEN_SYSCTL_dt_overlay to enable support for dtbo nodes additi= on 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 do= esn'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 f= or 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 ove= rlay node. This is helpful for freeing the memory allocated when a device tree n= ode 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 w= ith 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 dom= ain. Right now, mapping/Un-mapping will happen only when a new domU is created/destroyed using "xl create". Signed-off-by: Vikram Garhwal --- Changes from 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 12a3029fee..e7a467f60a 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; } =20 +/* + * 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 =3D=3D node ) + break; + + if ( np->child ) + np =3D 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_nod= e *device_node) return 0; } =20 +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 =3D dt_find_node_by_path(parent_node_path); + + if ( parent_node =3D=3D NULL ) + { + dt_dprintk("Parent node %s not found. Overlay node will not be add= ed\n", + parent_node_path); + return -EINVAL; + } + + /* If parent has no child. */ + if ( parent_node->child =3D=3D NULL ) + { + next_node =3D parent_node->allnext; + device_node->parent =3D parent_node; + parent_node->allnext =3D device_node; + parent_node->child =3D 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 =3D parent_node->child; np->sibling !=3D NULL; np =3D np-= >sibling ); + + /* Iterate over all child nodes of np node. */ + if ( np->child ) + { + struct dt_device_node *np_last_descendant; + + np_last_descendant =3D find_last_descendants_node(np); + + next_node =3D np_last_descendant->allnext; + np_last_descendant->allnext =3D device_node; + } + else + { + next_node =3D np->allnext; + np->allnext =3D device_node; + } + + device_node->parent =3D parent_node; + np->sibling =3D device_node; + np->sibling->sibling =3D 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 =3D find_last_descendants_node(device_= node); + + /* Plug next_node at the end of last children of device_node. */ + device_node_last_descendant->allnext =3D next_node; + } + else + { + /* Now plug next_node at the end of device_node. */ + device_node->allnext =3D 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; } =20 +/* 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 =3D 0; + int fragment; + + fdt_for_each_subnode(fragment, overlay_fdt, 0) + { + int subnode; + int overlay; + + overlay =3D fdt_subnode_offset(overlay_fdt, fragment, "__overlay__= "); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop check= s for + * overlay >=3D 0. So, no need for a overlay>=3D0 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 =3D 0; + + fdt_for_each_subnode(fragment, fdto, 0) + { + int target; + int overlay; + int subnode; + const char *target_path; + + target =3D fdt_overlay_target_offset(device_tree_flattened, fdto, + fragment, &target_path); + if ( target < 0 ) + return target; + + if ( target_path =3D=3D NULL ) + return -EINVAL; + + overlay =3D fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop check= s for + * overlay >=3D 0. So, no need for a overlay>=3D0 check here. + */ + fdt_for_each_subnode(subnode, fdto, overlay) + { + const char *node_name =3D NULL; + int node_name_len; + unsigned int target_path_len =3D strlen(target_path); + unsigned int node_full_name_len; + + node_name =3D fdt_get_name(fdto, subnode, &node_name_len); + + if ( node_name =3D=3D 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 =3D target_path_len + node_name_len + 2; + + nodes_full_path[node_num] =3D xmalloc_bytes(node_full_name_len= ); + + if ( nodes_full_path[node_num] =3D=3D NULL ) + return -ENOMEM; + + memcpy(nodes_full_path[node_num], target_path, target_path_len= ); + + nodes_full_path[node_num][target_path_len] =3D '/'; + + 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] =3D '\0'; + + node_num++; + } + } + + return 0; +} + /* Check if node itself can be removed. */ static bool check_node_removable(struct dt_device_node *device_node) { @@ -345,6 +532,312 @@ static long handle_remove_overlay_nodes(const void *o= verlay_fdt, return rc; } =20 +static void free_nodes_full_path(int num_nodes, char **nodes_full_path) +{ + int i; + + if ( nodes_full_path !=3D NULL ) + { + for ( i =3D 0; i < num_nodes && nodes_full_path[i] !=3D NULL; + i++ ) + { + xfree(nodes_full_path[i]); + } + xfree(nodes_full_path); + } + + return; +} + +static long add_nodes(struct overlay_track *tr, char **nodes_full_path) + +{ + int j, rc; + struct dt_device_node *overlay_node; + + for ( j =3D 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 =3D dt_find_node_by_path_from(tr->dt_host_new, + nodes_full_path[j]); + if ( overlay_node =3D=3D 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_n= ode 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 =3D=3D overlay_node ) + break; + + next_node =3D dt_find_next_node(tr->dt_host_new, overlay_node); + + write_lock(&dt_host_lock); + + /* Add the node to dt_host. */ + rc =3D dt_overlay_add_node(overlay_node, overlay_node->parent->ful= l_name); + if ( rc ) + { + write_unlock(&dt_host_lock); + + /* Node not added in dt_host. */ + return rc; + } + + write_unlock(&dt_host_lock); + + prev_node->allnext =3D next_node; + + overlay_node =3D dt_find_node_by_path(overlay_node->full_name); + if ( overlay_node =3D=3D NULL ) + { + /* Sanity check. But code will never come here. */ + ASSERT_UNREACHABLE(); + return -EFAULT; + } + + rc =3D handle_device(hardware_domain, overlay_node, p2m_mmio_direc= t_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] =3D (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 m= apping + * to hardware domain done by handle_node(). + */ +static long handle_add_overlay_nodes(void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc, j; + struct dt_device_node *overlay_node; + struct overlay_track *tr =3D NULL; + char **nodes_full_path =3D NULL; + unsigned int new_fdt_size; + + tr =3D xzalloc(struct overlay_track); + if ( tr =3D=3D NULL ) + return -ENOMEM; + + new_fdt_size =3D fdt_totalsize(device_tree_flattened) + + fdt_totalsize(overlay_fdt); + + tr->fdt =3D xzalloc_bytes(new_fdt_size); + if ( tr->fdt =3D=3D NULL ) + { + xfree(tr); + return -ENOMEM; + } + + tr->num_nodes =3D overlay_node_count(overlay_fdt); + if ( tr->num_nodes =3D=3D 0 ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + tr->nodes_address =3D xzalloc_bytes(tr->num_nodes * sizeof(unsigned lo= ng)); + if ( tr->nodes_address =3D=3D NULL ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + rc =3D 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 inp= ut + * overlay's content(magic) when applying overlay. + */ + tr->overlay_fdt =3D xzalloc_bytes(overlay_fdt_size); + if ( tr->overlay_fdt =3D=3D 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 =3D 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 =3D xzalloc_bytes(tr->num_nodes * sizeof(char *)); + if ( nodes_full_path =3D=3D NULL ) + { + rc =3D -ENOMEM; + goto err; + } + + /* + * overlay_get_nodes_info is called to get the node information from d= tbo. + * This is done before fdt_overlay_apply() because the overlay apply w= ill + * erase the magic of overlay_fdt. + */ + rc =3D 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 =3D 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 =3D 0; j < tr->num_nodes; j++ ) + { + overlay_node =3D dt_find_node_by_path(nodes_full_path[j]); + if ( overlay_node !=3D NULL ) + { + printk(XENLOG_ERR "node %s exists in device tree\n", + nodes_full_path[j]); + rc =3D -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 futur= e. + */ + rc =3D 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 =3D rangeset_new(hardware_domain, "Overlays: Interrupts= ", 0); + if (tr->irq_ranges =3D=3D NULL) + { + printk(XENLOG_ERR "Creating IRQ rangeset failed"); + goto err; + } + + tr->iomem_ranges =3D rangeset_new(hardware_domain, "Overlay: I/O Memor= y", 0); + if (tr->iomem_ranges =3D=3D NULL) + { + printk(XENLOG_ERR "Creating IOMMU rangeset failed"); + goto err; + } + + rc =3D add_nodes(tr, nodes_full_path); + if ( rc ) + { + printk(XENLOG_ERR "Adding nodes failed. Removing the partially add= ed 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) a= nd + * tr->dt_host_new. + */ + remove_node: + tr->num_nodes =3D j; + rc =3D 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 memo= ry + * 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_appl= y() + * but given that we don't manage that code keeping this warning m= essage + * is better here. + */ + printk(XENLOG_ERR "Removing node failed.\n"); + spin_unlock(&overlay_lock); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + return rc; + } + + err: + spin_unlock(&overlay_lock); + + if ( tr->dt_host_new ) + xfree(tr->dt_host_new); + + xfree(tr->overlay_fdt); + xfree(tr->nodes_address); + xfree(tr->fdt); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + 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; @@ -376,6 +869,8 @@ long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) =20 if ( op->overlay_op =3D=3D XEN_SYSCTL_DT_OVERLAY_REMOVE ) ret =3D handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_s= ize); + else + ret =3D handle_add_overlay_nodes(overlay_fdt, op->overlay_fdt_size= ); =20 xfree(overlay_fdt); =20 --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692951105; cv=pass; d=zohomail.com; s=zohoarc; b=b3+BXQyj1pJN/26/g/j6t8KhXtTJDl8YoMmIb8Hn1ueRfqCEmSSPUI843mgIsdwz8ogarIfNZ20fADComTUNP2OJy5VRcFVV9AJPt/faQsnZ+ytlJPVkLoZicEOmGVf1ulJpqtA/1KKSv7DK6Zju8oNJ/ITskNtZTQ+c9E7ezIo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692951105; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/se936Ujxc8NjdpD2oq8brh4lkajza78rV0iq3rKEiM=; b=FZOOCxUJi84+S5hPGTwp0suEMToyaBd8q1Ue8rWGFIN8itzDSYG8sIJU7iIEktUcfULkTXI0zKpGTLd6Nmxs4cdvsQhSlonIWh3U/x5A2U+fi6x+wMMhhfjH1Ub8J/vHWBlMclNKzFRFQkP+Ws7v2qX74OrCrVu3ykuH7Ro8nO8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692951105077706.198583752254; Fri, 25 Aug 2023 01:11:45 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590677.923067 (Exim 4.92) (envelope-from ) id 1qZRui-00040q-4g; Fri, 25 Aug 2023 08:11:28 +0000 Received: by outflank-mailman (output) from mailman id 590677.923067; Fri, 25 Aug 2023 08:11:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRui-00040j-0D; Fri, 25 Aug 2023 08:11:28 +0000 Received: by outflank-mailman (input) for mailman id 590677; Fri, 25 Aug 2023 08:11:26 +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 1qZRnP-0007GZ-Vf for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:55 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2061d.outbound.protection.outlook.com [2a01:111:f400:7e8b::61d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ee93e141-431d-11ee-8783-cb3800f73035; Fri, 25 Aug 2023 10:03:54 +0200 (CEST) Received: from MW4PR03CA0250.namprd03.prod.outlook.com (2603:10b6:303:b4::15) by DM4PR12MB7741.namprd12.prod.outlook.com (2603:10b6:8:103::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:50 +0000 Received: from CO1PEPF000044F8.namprd21.prod.outlook.com (2603:10b6:303:b4:cafe::6b) by MW4PR03CA0250.outlook.office365.com (2603:10b6:303:b4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27 via Frontend Transport; Fri, 25 Aug 2023 08:03:49 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1PEPF000044F8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.2 via Frontend Transport; Fri, 25 Aug 2023 08:03:49 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:47 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 01:03:47 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:46 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: ee93e141-431d-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HduS80hfQ0RwZJd0/kGyZfPxMKe3oh/7ym6qJXU0D0uXxWrIM8NTXtk7KEfWYgNhPjKz0mTUxNkFLhxN7P5NEtEs2M1SRRm76qB/rR1tlxP7EPlDS3BzM4jjW/IL0+T4VX0RnfNIwbH77FVuJHYt9Rmpq+YH0a0Wk/r+Y412WORSEYVI8IdsU6lgquk3yM1gzrQYE2ZGojQERCtxKfkn7ope9VhmlwjfeJYtaJ3w4txdZ81eoXiMzSWT9betNQJ42mOHS7Vp85nnZhouef7tSozVk1QAJRusVePqQmovP2UoE4OWMG08y2NfmuuEzI/CcO9qicdM1l84Okfmlp+goQ== 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=/se936Ujxc8NjdpD2oq8brh4lkajza78rV0iq3rKEiM=; b=Kk5A+8cuq7YC4VIHwTP/pAc3H45XHLYb4kCqIreJkFE03agFifiwJEgLKMNskc4diGGiry2ehvoP+yMVCo5+xYaSgE9z5yOLokLi2z21km3tT0lnPaFzewLjKZuQmogpzuT2y5R4RgwS3MIA2kLAMvWpmQ5/OsbObONrgTzOP4DPhXn1wU/IeUMBcgAKLd7/DM7/uP0N6drjLo3361w5h3sYV1d1IP5WVfUyRRSOtgsLkKQ+deWdYgTFWgI4Nwdv4dV7vdMIhWBcodHWRwu7tJeiAAp3D9RpAOzLNfwCISOG9kOyMdLQsEPkVlbQEkajTfemPcAB016A6MLKUb1ZlA== 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=/se936Ujxc8NjdpD2oq8brh4lkajza78rV0iq3rKEiM=; b=ndeV2ql1xIc9PaY3udxvRiQw9/KhcDbmHx4PlijIZ1XkZBE1C/X7mPCitbcpoo/Rn3bQO6r3Fp7wuY+uSH39Gzxwk+b6T8W7gTI4ojI+GV9qdXUZ0g/gZ0R0SiyvyBK82SPbwLeZY1oEEi5K0vVU/bdHPn+ScFsLK2ufSnIGUDo= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 18/20] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Fri, 25 Aug 2023 01:02:20 -0700 Message-ID: <20230825080222.14247-19-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F8:EE_|DM4PR12MB7741:EE_ X-MS-Office365-Filtering-Correlation-Id: 271ee5a1-108b-4bd1-6d56-08dba541d0c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gl4nc7i3IzLezFZW3pdIAD0X9FAznfF5Im7s0Ba02g3aMLdXYjkIZx8hgaS2OuaBxaGKv7RasXotEo2gd6kYcJUPsPA+3W/zpWhEmRwj+uzpbVjflf3prk00I38lKi9R7D/z08rBWIir61ll8uDV2zwoDjWHJCljZm/GvhOZb8NoYG0AFgEB2cZld+QHCJd+kgChNxXzSa/uHjcZ7gBCK85FMObyrKBq1L9fjsORzlmowzRMH6IrD+QVX+Z/a2b6qO3fpMI5qnO9vGmO2Pt9FIK+rm4mUjhwi/VYQCbhR6u94fxaXevurCL5r2LjV3C+sS43KyeQiE9hpMhJZOY+A8TNr7X6xgFRd4dWpbHnySUICqapsblUndKJ6BaqZC7XlCMy1YQxHEGIdBzUVwu4ulflAacSJeBD7nNB64yBY49r4XZ4f4aLF+SIK6xek2uG01f5KMCTJdt22YLyOYbhDlChJSg0LJo1/nnDAMHM4KkUQfRA0mRMJJ7osqdAWjcKPySegFG4o86XAf3nFxRV0PR1NrHd/ibSWNSKk+fw91cKUh/4V/sayG7vjLFvnDJxMkPTd6po0T8DCmmuNU2UBn0XAsuRIQI7DC0xfTACGcoApfSTh1l8Yp4cjRD7riU6J3m15p9aEKf0gEYynkmrh55Udiw2F4sCinpNt7B+Zn8NsNvFB3AU6Drpuf6ghEMPrPP885e/3ES7Os4u86ldU6IPmWDeluQQKw9b1AL5n+BSDfDcM5mjxXNiN2we1n+o3Cm25LJal6ObLTgv/J4L61IcuBk1bKGD+f05KX3k5MQ= 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)(346002)(39860400002)(396003)(136003)(82310400011)(186009)(1800799009)(451199024)(46966006)(36840700001)(40470700004)(1076003)(40460700003)(2616005)(5660300002)(4326008)(8676002)(8936002)(336012)(426003)(47076005)(36756003)(44832011)(36860700001)(26005)(40480700001)(82740400003)(356005)(6666004)(81166007)(70586007)(70206006)(54906003)(6916009)(316002)(478600001)(41300700001)(2906002)(86362001)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:49.4770 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 271ee5a1-108b-4bd1-6d56-08dba541d0c5 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: CO1PEPF000044F8.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7741 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692951106882100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" xc_dt_overlay() sends the device tree binary overlay, size of .dtbo and ove= rlay 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 faec1dd824..3da602586c 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2643,6 +2643,11 @@ int xc_livepatch_replace(xc_interface *xch, char *na= me, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); =20 +#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" =20 diff --git a/tools/libs/ctrl/Makefile.common b/tools/libs/ctrl/Makefile.com= mon index 0a09c28fd3..247afbe5f9 100644 --- a/tools/libs/ctrl/Makefile.common +++ b/tools/libs/ctrl/Makefile.common @@ -24,6 +24,7 @@ OBJS-y +=3D xc_hcall_buf.o OBJS-y +=3D xc_foreign_memory.o OBJS-y +=3D xc_kexec.o OBJS-y +=3D xc_resource.o +OBJS-$(CONFIG_ARM) +=3D xc_dt_overlay.o OBJS-$(CONFIG_X86) +=3D xc_psr.o OBJS-$(CONFIG_X86) +=3D xc_pagetab.o OBJS-$(CONFIG_Linux) +=3D xc_linux.o diff --git a/tools/libs/ctrl/xc_dt_overlay.c b/tools/libs/ctrl/xc_dt_overla= y.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 =3D { + .cmd =3D XEN_SYSCTL_dt_overlay, + .u.dt_overlay =3D { + .overlay_op =3D overlay_op, + .overlay_fdt_size =3D overlay_fdt_size, + } + }; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err =3D xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err =3D do_sysctl(xch, &sysctl)) !=3D 0 ) + PERROR("%s failed", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692951086; cv=pass; d=zohomail.com; s=zohoarc; b=R5kDlUIPN6Nayt0hT6BeUvgRq5Dib60isAltYn6wkKH1ryzCkiVqOQ7dJ23sNq7JOl1suyWlA38VQA0wIUPhg1zuZtv1D8nSwb+G18uUNEwBoxd/FP2EDKeufHb+CyZiRl30yqQ+ZQpMJKPISAMqhXCbUxhfIVB1Ou10Pq9iTp4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692951086; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=niCrThl8tSMKvN20vRpMYz3k/B1BccExVBIC4Bh0pr4=; b=aBBdD6++m33bc84xuoVWyLd155RxP43G8x/WxyqPie1cudKm0N2apyumf5WINSQUOiNTqTdkq69gn+4AVVExFQNJUhpu/vUVdyDUQYg0FL/9AoaQOpOJGObHuSoS39v+9yk1wmt5SlIUKjWIdz2xVVCqqik9W9UAwbtk9nfXK3Y= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692951086308540.1432094494586; Fri, 25 Aug 2023 01:11:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590661.923057 (Exim 4.92) (envelope-from ) id 1qZRuM-00031k-Kw; Fri, 25 Aug 2023 08:11:06 +0000 Received: by outflank-mailman (output) from mailman id 590661.923057; Fri, 25 Aug 2023 08:11:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRuM-00031b-I2; Fri, 25 Aug 2023 08:11:06 +0000 Received: by outflank-mailman (input) for mailman id 590661; Fri, 25 Aug 2023 08:11:05 +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 1qZRnR-0007G4-VX for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:57 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20629.outbound.protection.outlook.com [2a01:111:f400:7eaa::629]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ef577e2f-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:55 +0200 (CEST) Received: from DS7PR03CA0121.namprd03.prod.outlook.com (2603:10b6:5:3b4::6) by CYYPR12MB8990.namprd12.prod.outlook.com (2603:10b6:930:ba::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SN1PEPF0002636C.namprd02.prod.outlook.com (2603:10b6:5:3b4:cafe::8c) by DS7PR03CA0121.outlook.office365.com (2603:10b6:5:3b4::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.27 via Frontend Transport; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636C.mail.protection.outlook.com (10.167.241.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:48 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:47 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: ef577e2f-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZLo3fxcaTuBsC2MILQLHZ8lfJJkazX7WWIDvk3pVcit1kuRnQ1B9QYdiuBlySvhQtxKHITcUe8dCfCYbGfW3wnZVcQvp3MpXWbzwnZ5SJxtoWYkQz4xZ/PPotiDgnzdDA0OMHFZ93BZs5zlR68K4Rlgv0wvwThaf5oejjbDpau6Xkq+UdR98hyq6Grm0AKvC17848AnmtBUC5w5c+7nwSBfyUTrPBitxThgBHfRUqwbWNeCqWOudInxsPQhQvd9KvgFOK1rFawXLv0JcQHUwoN2/FwUuXXEWhWonlkEcXOumRxAzRpESDO71sukYKWeK+WZlHhfx8SXIOoZMVsh7/g== 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=niCrThl8tSMKvN20vRpMYz3k/B1BccExVBIC4Bh0pr4=; b=VyfLVwdUlW/FmYMCVSvTFp3JZZYjTCyxSwJiKGtmFEPYo4wdkt/Rc42Td+Wq/EWyPgx04if76thCihq/Y+NgVN05e797aToiR3wfF9f0RIlnm6Yn+ULddNvPPD3HYlkLEPUHn5I2iaT+Tma+PLkZ659mH6ucF7r+8xVMjerz7lzK2DYWl/FADapdMZj3O8D5NF9/jmRtzGLNNppl0VWPt3NBN72pjONCjfV9pOMBguDOa/cIjh/pZO16tgJwOBFO3xsHV1gSjdK7FXW18AxED8dMu7ka3F/JpksG7JUd7UdKgxogw63iwOI1r/ilTR17O7F4GiuL9XeezB5Wta2pJA== 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=niCrThl8tSMKvN20vRpMYz3k/B1BccExVBIC4Bh0pr4=; b=zHsPWq58zZQcfafpKRxauLFgN2q9C4bDCAVAiIMdEySqtrFZlYt2E8D5v4gPZ0U6YWGSPjUJbCKd8WwPDY9Us5wE2vaTuw5FIxQctMxMkT3rkSanYlkvXi5boaHN1D03TojsP7/WdjUYy20aUvvJDIQHnCIxLAoCOB0kb9wwFb0= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 19/20] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Fri, 25 Aug 2023 01:02:21 -0700 Message-ID: <20230825080222.14247-20-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636C:EE_|CYYPR12MB8990:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b4ad94c-00ec-47eb-4ca2-08dba541d266 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pgdUs4g2kYSopWsUhShitsqu0Q48qz1uQ7QrqQdua1D+G4tAPILy+zpvqLYwNN6yy4oPfoX5Y0G26ZqZdR0FR+8QBBXoj3L489hkUfikFxCqA8+NDX28G8nXiCjnk68QfLboXvxq71YDvt2H7kGbWdz2uU75mKh4LiOIqLfjsH2LnjQ7fMaYtJnJgbHYf8rd4knrBa6KwKNbhyURd9fzYk+yhh1oysS18wECbOGYnzJOAMROiOvsg2Nfx2AJSdX33l7ROTeC4W9ubHNltN5EzInpEKzfxlhIEqrcBHYB0obDZyzqfJNqsLYMMpRqgFiUqBMm/hWSJASVzF7vXSWyQG4DDRGEP6PDOtJqIvaAywfhgGkzBeFHy0kX/kXAQBHuvPo/xE9q0tLlK5IWMshK2eTTpE1vM9xpEsdUnpu+GcvaN1JtC2+jUEOy/4PnXyh4CRo0viTCXVW/6p/KSOY60gihLC1voLIem5dRPzBVjOvZpb9itt8x8wcz0AcuG8WDihtvoQH84D5jCZG4QHhKVdt6Xpx7YkYpkZspAb1/DmFYAEktr3sr8lu/dA9PRka5HODA7EtwtMH+IgWu9jeNU2KU38UQrlHrGbYv71LulNDxx7Q06yWhEWlS7luXCrDJ809FF1pULaNhHXZj38VELTrgf3fCNCmR91m0gQriKKNDqXBgcKh+KWxpe+rcIHYYc3XYKEihVT/qwAZuxGLSrH5mbR11MXfg2bhkk4ZPEKs12QKPmqpjYw7aNwQpC5N8SQJtOt/9OktGQlmKHSmm1VtsjYmJUjfhnc9VUfXc4Bo= 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)(39860400002)(396003)(136003)(82310400011)(1800799009)(186009)(451199024)(40470700004)(36840700001)(46966006)(1076003)(40460700003)(2616005)(5660300002)(8936002)(4326008)(8676002)(336012)(47076005)(426003)(36756003)(44832011)(36860700001)(26005)(82740400003)(40480700001)(356005)(6666004)(81166007)(6916009)(70206006)(70586007)(54906003)(316002)(478600001)(41300700001)(2906002)(86362001)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:52.3809 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9b4ad94c-00ec-47eb-4ca2-08dba541d266 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: SN1PEPF0002636C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8990 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692951088605100001 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 aa5b1c98d4..b4f2a69b34 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -259,6 +259,12 @@ */ #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 =20 +#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. @@ -2493,6 +2499,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *c= tx, uint32_t domid, int *num); void libxl_device_pci_list_free(libxl_device_pci* list, int num); =20 +#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 +=3D _libxl_types.o OBJS-y +=3D libxl_flask.o OBJS-y +=3D _libxl_types_internal.o =20 +# Device tree overlay is enabled only for ARM architecture. +OBJS-$(CONFIG_ARM) +=3D libxl_dt_overlay.o + ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL +=3D $(LIBNL3_CFLAGS) endif diff --git a/tools/libs/light/libxl_dt_overlay.c b/tools/libs/light/libxl_d= t_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) !=3D FDT_MAGIC) { + LOG(ERROR, "Overlay FDT is not a valid Flat Device Tree"); + return ERROR_FAIL; + } + + r =3D 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 =3D ERROR_FAIL; + goto out; + } else { + LOG(DEBUG, "Overlay DTB check passed"); + rc =3D 0; + } + + r =3D xc_dt_overlay(ctx->xch, overlay_dt, overlay_dt_size, overlay_op); + + if (r) { + LOG(ERROR, "%s: Adding/Removing overlay dtb failed.", __func__); + rc =3D ERROR_FAIL; + } + +out: + GC_FREE; + return rc; +} + --=20 2.17.1 From nobody Sun May 19 13:54:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1692951080; cv=pass; d=zohomail.com; s=zohoarc; b=LZQdcxTKkD1o0M5Tu6O0W1db/wASli8DSi923aWrNc65sUxz/LQz6ZYrNA4GzJ/53D5kABnoEf+h7+bnHCPlDdJ49hBNooaFZNwmrUlY5Q/WGDH0V+tgzRkN2PBtKyIK5hf0kkm10c73cdYO0QEU8A+sFra5mWLysB+nyNlQRM4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692951080; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0SOh4yXnAAqd95uGtVLNuRN1JoH4/9uDY70TgG5n3FU=; b=M9KleRiYoSiOzorIg4cjZI/EVELts9PpkCokRntiOA27c4cZB4Kwhkowy+VDD7Oe83Ry1j87tyrTppLhUESUV3O0KDJLKfsV6hzO9KA/+SJGpM6DofO3/wigqFEPci+RYU+ES7cnR/LRjtmThlG4GNqjwWH+EGbRe96NWa0on3k= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1692951080716777.706114075069; Fri, 25 Aug 2023 01:11:20 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.590660.923047 (Exim 4.92) (envelope-from ) id 1qZRuJ-0002jL-Dv; Fri, 25 Aug 2023 08:11:03 +0000 Received: by outflank-mailman (output) from mailman id 590660.923047; Fri, 25 Aug 2023 08:11: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 1qZRuJ-0002jC-Au; Fri, 25 Aug 2023 08:11:03 +0000 Received: by outflank-mailman (input) for mailman id 590660; Fri, 25 Aug 2023 08:11:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qZRnT-0007G4-Nj for xen-devel@lists.xenproject.org; Fri, 25 Aug 2023 08:03:59 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20627.outbound.protection.outlook.com [2a01:111:f400:7e8a::627]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f0f866ca-431d-11ee-9b0c-b553b5be7939; Fri, 25 Aug 2023 10:03:58 +0200 (CEST) Received: from SA9P223CA0027.NAMP223.PROD.OUTLOOK.COM (2603:10b6:806:26::32) by CY5PR12MB6081.namprd12.prod.outlook.com (2603:10b6:930:2b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.29; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SN1PEPF0002636B.namprd02.prod.outlook.com (2603:10b6:806:26:cafe::8b) by SA9P223CA0027.outlook.office365.com (2603:10b6:806:26::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20 via Frontend Transport; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF0002636B.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Fri, 25 Aug 2023 08:03:52 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 25 Aug 2023 03:03:49 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Fri, 25 Aug 2023 03:03:48 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: f0f866ca-431d-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WW6AVVrnKdyipkWb2LMak/2n2vr+oSfaz/3ky9grqSHLmk39S9JIcVWHXOk8/+ynVojFDU3jnUACTUVhEXf2kR4varDAMzBX3NAvRKTUM9c/KTOdAgO3idoM0It88BwUcEY564csD23kW+x1bjeJ7Jd9l5F3MczzbPWzbC13qGzzBrv3yrrhZ3pmufencXU8g9uWVYgEWR3gjYXalmixJ6OKv4YNlfTj6M5ObseiC1FrKhFMJ7yPq/idVEzVMN7dV7Pwo98132nUcFaUi3Ilto2dYCUKxNy+fKEAdYM1CyOaW9vqhhpIqpPWNP7FclHc4DdSO5+i/8mFshW5o8wpEg== 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=TIcZzuoyJFBSnK9lvM9tk/UhtBZDrF4tll0jlMcf5JT5MLXlGgfqT7Y8aEgqjsazO4enQlddihFtnXhMB5UYF+bYGWi5Ih7+B2Miu3Tr8/q4yc1vTOXKIWNmYiBl3ydP5OKe+EnPUOiRciSP0okRh5Th54frke1m+1EZvFNKTSuGRkotBXgXJQhcbK6ZlNjgQF6MLqgu95HeOydM2Zb8UAyiLuE2f/MtsarB61LOC/xvoUJ4d2W8uCXt2kTewfzYfQ+8v726X4HsmjnzOibon4rPbnLFkU0mMq/3iwo8BKz3Xx04iFRXJLXQ+dY3PlW2xgeueKmbtc3i5BfMnNQ3dw== 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=fTHdPbffVyCXa+PBA2aZKc7HPrp+7r7Qt7hyW0TOEosMuQgzeIq96aVk1fJL1g3BDoIL2SCRrcDNtfYeTA2zAxEdrof2nmkRNakB9qY5xKJJ0QOt9+/Swp5Py9aVvfDXv33UxNx7itgM8JzCMYHjPPKCiaS/QtXiayueIVp46Yg= 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 (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; 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 v10 20/20] tools/xl: Add new xl command overlay for device tree overlay support Date: Fri, 25 Aug 2023 01:02:22 -0700 Message-ID: <20230825080222.14247-21-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com> References: <20230825080222.14247-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636B:EE_|CY5PR12MB6081:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ee1585e-aab8-4244-73b1-08dba541d29b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gjV7tIifUFa107+ucGl8wEN4osFHEV9lq7BM9BVP8ACk75J3CHh4NyFMAgpdRdSVRQ9HglykEnUiTIlgdMsa0XOUwIpStwzOXhnpLCKiNU4kicc+oCho1h5yBhINtMqt+wy4ST18dBcSTDg4O3j3FAL3A4+uDqILLku5vVmk9yvUPTZGReGSQl1OBVTk/u7NQXGhJM/Iya75z3Q/jPc7FJ3uH4AXPPehTobVQaPVt7YmgF5BQ2sRrElIIIrp4dk3WkvAuZZ9FZQ9l16QG2KKL1B/EO0uXY2Obpezg4SGpg3Djq5bKUBRg5BuV8zm1m2akVaD9Xot4rkn1eaGaPaosv9zNIeMYsRn4okEVxGGWW7cBWSca4svVrpqZdZ1PruZ5R66rLsu9N3561328rR2FYJU/Ljegrr60fs1pd3OgXsy9RNCTA1C6jAysrrmnewnzVXw0nNoCZ3NwHOmX2GHyYYDNtuzXMsyFUEbyCMYPaODadTmULiAEcALa6zXbBLVN406B9nNu1E+Lzx2EYOjZ90c3R4UOtxOXo77ZX9zxPltvQsE1yT1DU41D6Wgtd5LYiEMPXjrwGa74q1lLGnl1GR0XXqZKGM8IQ8YZ7yMoRrz/sL8Hbtzw4rlt2R68EaGKuImk8HUCtpSBnZ8bQsNLL6EbO1677dmjRJ0LRdjIjG+Ikkx1DTpW3GqAIphSEHT1H2FIJMfXFNLdnpPe0XC0A5X49T2Un5y8730jWNgYKxSoD8dB3h9lwNLFswFdU2QxsvNhUiq+ka9Wk+obcrifg== 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)(82310400011)(451199024)(1800799009)(186009)(46966006)(40470700004)(36840700001)(82740400003)(81166007)(356005)(40460700003)(8676002)(4326008)(8936002)(54906003)(41300700001)(6666004)(316002)(36756003)(6916009)(70586007)(70206006)(86362001)(40480700001)(47076005)(26005)(478600001)(336012)(36860700001)(1076003)(44832011)(83380400001)(2906002)(2616005)(426003)(5660300002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2023 08:03:52.7292 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ee1585e-aab8-4244-73b1-08dba541d29b 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: SN1PEPF0002636B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6081 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692951082551100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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[] =3D { "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" + }, }; =20 const int cmdtable_len =3D 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; } =20 +int main_dt_overlay(int argc, char **argv) +{ + const char *overlay_ops =3D NULL; + const char *overlay_config_file =3D NULL; + void *overlay_dtb =3D NULL; + int rc; + uint8_t op; + int overlay_dtb_size =3D 0; + const int overlay_add_op =3D 1; + const int overlay_remove_op =3D 2; + + if (argc < 2) { + help("dt_overlay"); + return EXIT_FAILURE; + } + + overlay_ops =3D argv[1]; + overlay_config_file =3D argv[2]; + + if (strcmp(overlay_ops, "add") =3D=3D 0) + op =3D overlay_add_op; + else if (strcmp(overlay_ops, "remove") =3D=3D 0) + op =3D overlay_remove_op; + else { + fprintf(stderr, "Invalid dt overlay operation\n"); + return EXIT_FAILURE; + } + + if (overlay_config_file) { + rc =3D 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 =3D libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + + free(overlay_dtb); + + if (rc) + return EXIT_FAILURE; + + return rc; +} /* * Local variables: * mode: C --=20 2.17.1