From nobody Mon May 13 19:04:48 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=1692232831; cv=pass; d=zohomail.com; s=zohoarc; b=hiz0lwZ2092BV5hhA7kYbW/T3dH+4dfxYIE2R3452qdDvRCLTJSfO8u/QTu5WJhw4KKtxdxASx57QKX7VzSysaFe4yWR8pNXD9jytVi3tTHCE00eQb7rmT2unYFFekUnBjNK/j7IPYWGnKDmdtg0lMCRuJjbcKXNXie/eIkUYYA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232831; 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=OnAkiyK51E8/9hbpYvNOl4Id3yZ+E95/wfBvKWMf7tM=; b=L+8BGywv3t2L45du+yB+Am8YJ4kCBoDciOM3z5Hg3UdI54+7C4fsjhgGYdmOcZLcViEmN+jFZEMgKfyhYnP7s7bXEmlIZcUy9HTXPFlkRs3LVxcR0fi+999W0jSHLWDHrc726D080UWOdWF+2nNu5evPMTOWBYSYgL+ggQd1jSQ= 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 169223283162235.767957672019975; Wed, 16 Aug 2023 17:40:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.584985.915925 (Exim 4.92) (envelope-from ) id 1qWR3b-0002ZY-LS; Thu, 17 Aug 2023 00:40:11 +0000 Received: by outflank-mailman (output) from mailman id 584985.915925; Thu, 17 Aug 2023 00:40: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 1qWR3b-0002ZP-Hw; Thu, 17 Aug 2023 00:40:11 +0000 Received: by outflank-mailman (input) for mailman id 584985; Thu, 17 Aug 2023 00:40: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 1qWR3Z-0002YP-Qy for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:09 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eae::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9d39ac63-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:08 +0200 (CEST) Received: from CY8PR12CA0032.namprd12.prod.outlook.com (2603:10b6:930:49::23) by DM4PR12MB6064.namprd12.prod.outlook.com (2603:10b6:8:af::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:04 +0000 Received: from CY4PEPF0000E9D6.namprd05.prod.outlook.com (2603:10b6:930:49:cafe::9d) by CY8PR12CA0032.outlook.office365.com (2603:10b6:930:49::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Thu, 17 Aug 2023 00:40:03 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000E9D6.mail.protection.outlook.com (10.167.241.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:03 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:02 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40: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: 9d39ac63-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h6OPvYaVjUlHMn+GZEX3Iei4gYKFoXzi02+bDj4TDStNneoavNHrEjNn/EyOcbQAOmo0wuMiSOQTdT++kas3I1e7d/w+RqV7EXRjbCAR4gTbTgmv5Fn6GCKVsX8YDzf4Uu1w3M0cb4nWuzACBVpPcJZfu3MxjWJF69YeyZSkfXqhrhPI1VyCLqHkqyVFb9jtQmT9m5l7rU0MFhW/qvyrrzI7WwY9SwsJapS0UqCIaAdVgmYNfxSCfm/WODpk9aDLX7oQ5FMzuaCpaU/hI3aJILSG4w9VQhUpr7KwvF9g2isaZt7bAEDnr//PzmySXtjbwvGLiuH1lOm+3+7DoqGCKQ== 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=OnAkiyK51E8/9hbpYvNOl4Id3yZ+E95/wfBvKWMf7tM=; b=c/GWQZSVwjrUABqCorwLgvNh1Zd2MhHcfeW2yX9mK4Guor2D6UH5ylt8lql1jntXjKP4dCSQDSjVHq2CEr2jWqEYt6/qs2eGYS+FU6Yo1CyAYTrhKAKq0SKC6fnAuRzB6iaSWAbae6nb2yLiUB2F5ZLrJzbpB7zFArJHJijhnX58KkWEtXmuNlBSLPziZZR4frdWdsx6yjwg2UY2kX3890IYZiHx6SV//4XuyjSkdUddyVGxxaBIN6VSYYUWVOXjNCBXsrYF1q4q00T4Ir7zPY+YsTJHYSbciMA/42+zWdff+Im8bnDFsDqM575Bukje/zZn1t97hjS35Bh1Sduh5w== 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=OnAkiyK51E8/9hbpYvNOl4Id3yZ+E95/wfBvKWMf7tM=; b=Euo3ehfi8tuIew08vfTp5Y2cbUd4saxlGJJzCR9I1H4E+b/db0iF3J2C6yEQFZsYA/TRmns4Ekg9OgqcugqgGxtRqDMaBcsilmr4aW8pqYYpFdfxSx62La9s3SwOtCUoNf+aFxeersNyMsi1NoOowUCD57H3KBhndj5h5VGMtVk= 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: , , , Julien Grall Subject: [XEN][PATCH v8 01/19] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Date: Wed, 16 Aug 2023 17:39:29 -0700 Message-ID: <20230817003947.3849-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D6:EE_|DM4PR12MB6064:EE_ X-MS-Office365-Filtering-Correlation-Id: 82c6b25e-8d2e-4114-6089-08db9eba7ef8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y8uTqncCMMjb2a2oi/Epjvcc3PW+Qeem3wiE2p5bssEbbHM8apxzbveUPmJ5oFhSFzvVWf4WoPhoMMPcbSzEqF+lpnzq0YCsPgzDRnz9SCgyi9pPjUD7ec51RbMyfvzRxSfBCAU/j31P1xzAAsyLfqMeXYNqEL9OzmKNBnIah67yXh1EG4pgYBiJXVPFQuUufbtTGYeJLQ1npzniyKiDtht7MX0miazfE6FJCjLLH3X5kBJ3Y7b+Wyh2/HhhAvERobmVBCcZewTkhobjdmkwPn2SbQ0HqVegR71opGnrWNmmJ76Pcv5IXFUFGwiKDPjMIdirXpehekxp7j662FhZ7RrisDnbrfhtGYS7ttYF2HaGU6RM1rk9PRetwCbGEBobq6BczXl0RDPE10it8fhRGu2IoMJdEBkKtvuYZ7viiMGOVzUZtazlHcDojUbMiug1Rt5Sz1WcRX+v9tBedQzdyGd1yeb3LSo8zKamlD8BZ7ts98/YPnI2XPeY5y3aMlVlum0/HMwE/twwE0m4URiJ+IA7TDVnBrXiWpD18iC8nu+7Lb26z7o32lCs7KLS6eLPqgK2D4gElegA7eIruoXtEIt14Qpyz8ka+k6Y4dr32S1hq9GC6+xQVB6vwdqGVvbOEmqzHGE5N+MQQvz2Eh/Gr3kgzycu/toauhhpDDkBP//PMLxz9d/T+yo9o4yPPwRN0Edy6MPW6HfI3IxuDwLTjcLBsR+NEljGKRTURWPmKs/oaeK6sXTNr3WRfyfsylYHVcmVY6lHH8Ipjp6FDP+/zA== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:03.3275 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82c6b25e-8d2e-4114-6089-08db9eba7ef8 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: CY4PEPF0000E9D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6064 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232832853100001 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 --- xen/common/device_tree.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 0522fdf976..c91d54c493 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2092,8 +2092,8 @@ static unsigned long __init unflatten_dt_node(const v= oid *fdt, * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call */ -static void __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +static int __init __unflatten_device_tree(const void *fdt, + struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp =3D mynodes; @@ -2114,6 +2114,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 +2133,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 +2219,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 Mon May 13 19:04:48 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=1692232841; cv=pass; d=zohomail.com; s=zohoarc; b=ltC7JdaCHPNBz3xhuc937KsGRfdiWP0j3IYeuIHoZv4rHK38rjUJpDGg67FmaJxD12QUYWRw0BaVgYJP7ufbeShCgpOAkZ7iXxkD/Fmrf4w+d/AuHJK9ZsWVcnWU+KX35o4TAz7N++jgAYg2rwACN3a6MPdkdkFIF0Sc9GiKhZU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232841; 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=zNJuXj7ZBUQRHz29zlrzeHOa0+tHLK1DzkscWEXkjVw=; b=HD58scVQvBtO1TnRUeh89rXtn5vG/w238BHiTmWovbEho9sjHBiA39bJ1D64bm1Gay94P+zkvDceO16ScfztW/buyCEKVajXKlYaRPUEjh5tCOlbbNrZYqnRleTJyFbllzmTrehlZYNZPPGYoTFZFclXt/HEF0bI9RTEFgcwmNU= 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 1692232841261105.31132207213807; Wed, 16 Aug 2023 17:40:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.584986.915935 (Exim 4.92) (envelope-from ) id 1qWR3f-0002rR-TO; Thu, 17 Aug 2023 00:40:15 +0000 Received: by outflank-mailman (output) from mailman id 584986.915935; Thu, 17 Aug 2023 00:40: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 1qWR3f-0002rK-Pn; Thu, 17 Aug 2023 00:40:15 +0000 Received: by outflank-mailman (input) for mailman id 584986; Thu, 17 Aug 2023 00:40: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 1qWR3e-0002YP-73 for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:14 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060e.outbound.protection.outlook.com [2a01:111:f400:fe5a::60e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a0abbf1c-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:13 +0200 (CEST) Received: from CY8PR11CA0035.namprd11.prod.outlook.com (2603:10b6:930:4a::21) by CH0PR12MB5076.namprd12.prod.outlook.com (2603:10b6:610:e3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.30; Thu, 17 Aug 2023 00:40:07 +0000 Received: from CY4PEPF0000E9DB.namprd05.prod.outlook.com (2603:10b6:930:4a:cafe::1f) by CY8PR11CA0035.outlook.office365.com (2603:10b6:930:4a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Thu, 17 Aug 2023 00:40:07 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000E9DB.mail.protection.outlook.com (10.167.241.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:07 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:06 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40: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: a0abbf1c-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Lf9Mj3Io8VeqRps2D5PsKJ8PgrKlRx6PhFoJt6Pazdm2rM1fBdHf3WPU2oGkObjPSz97wsP5NBAzojpqb5mr5P1r7AqM9PR8DucYGyHkfkQ2Wc66HLV71dKNfSv7yniJWSLeyWu3R5wa/oFaFEc9Ef95xs2GOPhTHJklSA15ROpT3Ma43Qj6wvXO+3FRd97fJRJTpdW0sjn3EkMtlhx02OJkETnSeH1cU5pUoJ3kvx0AJUdmbH5mG0F/5QkkQlWNe0rgyenRTCOEQNM9JhCtBPUf9waBY3yKH9MeoplZ5kuevxt2Gpg49YbYdKKzK3KSGt7i+IucVpaX3fyel4OVtw== 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=zNJuXj7ZBUQRHz29zlrzeHOa0+tHLK1DzkscWEXkjVw=; b=ZwU47WiDLVyJHGgHGAfPew5vkZTbO7QEMqSLccakl4Q2kdL1OrE5kLDWqR1uuc4k9WNlYXry/aCB5E/GC6bnfVru8aBYrfDoRpkIxYS8GiUuzAYVACARISFMRi5tlgkShysrHxq7qv6QKDoQ7tjzU60c5/mQp+ZDubv2Uas+cvW0tXw5mpJO8GDzZP1f2sv9kM8IVjAWLtehpiN8c/P7vj39GIK5vC/OYkDaVLyH7w/iOpW5lUm4nWux+mCmjv3K11xC4Op7u8M0uhn+ujF4KhKVnfByl5mNCOORr+WVUc4JrNFMbo+YsTQ7C+7V+S1sQ97grAO77EDpkLBEZ6L73w== 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=zNJuXj7ZBUQRHz29zlrzeHOa0+tHLK1DzkscWEXkjVw=; b=bPasNlpaADE6LiHFviJ0vV120hFxOL5zS+vrMCUwsJD+L5sxOXUNq9QW8FXl6xA9a+cAs4wc9n90MeZDCSXYYnZsYJH8xv/zZ/Z8AL8HOBr4aOXOOlAJKNKGE0UTgM2lgLuR593ECn+5dvwe/Xw6gtxLVbTx6dST7nnoCkvuUmI= 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: , , , Julien Grall Subject: [XEN][PATCH v8 02/19] common/device_tree.c: unflatten_device_tree() propagate errors Date: Wed, 16 Aug 2023 17:39:30 -0700 Message-ID: <20230817003947.3849-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DB:EE_|CH0PR12MB5076:EE_ X-MS-Office365-Filtering-Correlation-Id: fd9fde22-5bb5-40bc-ebb3-08db9eba812a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zK6FcWf8Uaa2AACUTMiEogXy8LUyJZ6Y4W3VbBZwAr5TRJcIl17aGmkL8szfqx5FiI8ESMGgdptUHl0rArpbbyo37M2i5cOF+Gf+ETBbURnM1H+0EVGgxpwCMelEmAQV6XRnJTC7v7mX9leo9R5WFun/B9uS20SJa7q9mdQvCVrAjpLQWLFUNDttSi+q3h2n3hC/J7HCUDbg7pWo/cwwIyPb7vrU374kxz9OsyzJx4nHZPd/Q6vOFGYsF4mwT4RSQ0EW8xIxUZzd/3eplmY3RaU2mafHmv/yTQYxl8rtlKXv0NCoWEIo137YVl08keXiLfCBys7oR8lB4bmyb5BbJ6JnjlfXhnqOdLna/X3g1e3nVPd/mjySno4cMZrqa42A52AZWjpfOtKcovk5NGXEFsPg23V3AtmIIhvthS9Exjba08ShAu2x5vPtgTqXN9OW1SFMxbYI8mXaPFWvjdzjnE02zJ2hc0su4pLxV0KUvm+cbHfiAEkwinUTM+GGZL2apTwgWSY++ieFXIXlXO8vAzH3YOQBqJy7h+J8LFgr7zLb2mlyIVLHRLBqoeFPtJqWwD9s02oR/AatwUrclmM1jrivwKMJwWS8JV2tv1H61l1Bt+C22AoQuO94oGKUnJge21xyevAifPQ+zn97FK7hO5h4QUk4wXeYKgQvHv8S+ALRBp1dpj0nbF/nmXO/Q51dWcgdMWUKppfesrwqTgFHzikug2jO9DWI15WdPN5at3N4fZQQp48g/ULqa9vVkd1vJunhtZ3J3KpznHpPi8gO/A== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:07.0142 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fd9fde22-5bb5-40bc-ebb3-08db9eba812a 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: CY4PEPF0000E9DB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5076 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232841639100001 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 --- 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 c91d54c493..cd9a6a5c93 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2108,6 +2108,9 @@ static int __init __unflatten_device_tree(const void = *fdt, /* First pass, scan for size */ start =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); @@ -2125,11 +2128,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((__be64 *)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((__be64 *)mem); + return -EINVAL; + } + *allnextp =3D NULL; =20 dt_dprintk(" <- unflatten_device_tree()\n"); --=20 2.17.1 From nobody Mon May 13 19:04:48 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=1692232843; cv=pass; d=zohomail.com; s=zohoarc; b=IfYuBkx+w/rr/wBjdPRs598BHoLMOIU9kXUR4o6n8KMmaVEh1LoD/rlVPHG8L3IkgT50zCiyHgi2Zt+4ZsNUs0QwO5Y6YU0IHyRmvHxAtKuvNauIJHao3NSBOAkH/cXoAWcmbHI6h+N5oq8Xw4A5N06AsyLJ0sAuwwy8jvZq4xc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232843; 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=ueRoAwRMX84PvKHly0/7xJCC6WZWwr2cF/eTQww9BPQ=; b=RyXqLK+dWuGHE402ciyS5ybWK1LsmP39zt1dcNp8Ew3BO5c5NFF3DOxHxIcThaK20guoQe5XXhKgMMQXs2PIr/TBy1Yd3bpjWapjQr1uMg/1Muh2sV/jk4B1/GjAYcTFsI5uRiqTjPaf8VWpgYkR/B8JZavAbp43mGzlulyXgr4= 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 1692232843201802.3112981006162; Wed, 16 Aug 2023 17:40:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.584987.915945 (Exim 4.92) (envelope-from ) id 1qWR3p-0003Iq-9m; Thu, 17 Aug 2023 00:40:25 +0000 Received: by outflank-mailman (output) from mailman id 584987.915945; Thu, 17 Aug 2023 00:40:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR3p-0003Ig-6U; Thu, 17 Aug 2023 00:40:25 +0000 Received: by outflank-mailman (input) for mailman id 584987; Thu, 17 Aug 2023 00:40:24 +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 1qWR3o-0002YP-0Q for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:24 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20611.outbound.protection.outlook.com [2a01:111:f400:fe59::611]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a633f20d-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:22 +0200 (CEST) Received: from SN7P222CA0002.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::14) by IA1PR12MB6164.namprd12.prod.outlook.com (2603:10b6:208:3e8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Thu, 17 Aug 2023 00:40:19 +0000 Received: from SA2PEPF000015C6.namprd03.prod.outlook.com (2603:10b6:806:124:cafe::19) by SN7P222CA0002.outlook.office365.com (2603:10b6:806:124::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Thu, 17 Aug 2023 00:40:18 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015C6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Thu, 17 Aug 2023 00:40:18 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:17 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:08 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:08 -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: a633f20d-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fhVdhPWGizSjESHFtxIaD9mxnfSYVUkDNrR2cvHZ73ZCPl8M+xqHdzm67dXjj3ckJAGyHeZ6/raf1A/rV1pf8I0KbYHcxjj6o4g0zvY8ngid7jNqJ47kgvrZQD5N+CBvqNNCcWYB7rjbkXtujTLBkKWyozEGW0+j0wTyrrfaxktEAmkPs38pns85CP5+X3RhxttUApDvVYFKvQMFXxCRXMfFPnVE7PhnVZM7KREW15jGIN70wfX4GGjMtiGwUYkY/U+U77rWp5W8uMmlI/L9V89mUoQ8E1BdmP1oStXt1yuZqjki3mVXiqez6gzgkMYkv5mYtc/O8oZXj62NgmHh2Q== 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=ueRoAwRMX84PvKHly0/7xJCC6WZWwr2cF/eTQww9BPQ=; b=NJBJlKa/o429G8xBXSxPi33yaXupFKdXJ0JI6q/bnRadAK4+A25Nm/UteCnsLsdWgnewZXs1hNg0EAWb+OAeIUYc4ufEpAGNSV6tWH4thAR/1de5N6Vrxt90QpcEAQGvIbBeTD+oDQ4tRGZMEroexV5oJiDeKNidhAF2psOYukLpU9r+Obq0bHZBnMJr3cSq1CuHqvEs6v4RAeBiMFxcGGvRnSnmghwfuy4f9i1b8TytHFLW1V5GErbi2gV5m0VvZ7ONqpz4AHqvTwoNZ8OjG1eiU7IfMKdVIoHPhfriDyjxXsCROGkdDwlBBnASfXXsI8elzM+Zm0hzIQjYDAq+zQ== 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=ueRoAwRMX84PvKHly0/7xJCC6WZWwr2cF/eTQww9BPQ=; b=teu6M/leebTn/d5lTHlN3T47BF3DDQXwH0gCS3LGJKtQk/LiWldAoUFSO7XmdCEf0R76iR22QYVPA1V/0k5ytMKhzgDNYNj8yuFrDhrzOBASQB2QBWHOEqqex6PJIqk6xZ1IO5kQPk8Im/vnWyE4gfZ98kMPjrn+uk1Nfw6Ovg4= 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: , , , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v8 03/19] xen/arm/device: Remove __init from function type Date: Wed, 16 Aug 2023 17:39:31 -0700 Message-ID: <20230817003947.3849-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C6:EE_|IA1PR12MB6164:EE_ X-MS-Office365-Filtering-Correlation-Id: e2e7184c-9096-4785-6dc0-08db9eba87e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f4yyjVBXLaTvlSMoY90dCB7JGZGeZjZTugWuw2GMz2mPDZmC19GlXXZWaPfwGjeIUpS7+mxoziPZDHr1myoBvaod041UpjVJo5qe1Xs9tLrWNMFL9tgRKCyutXGpMbDFOjnN9UPS8ys/XPEhrG+bU49Mc9kanOaD1UKmmVouPf1iQhd4qJ66eLQI30EUyKRmdE7FVwyEqii/fqFX/DrR8YV7IDIwBJ3bQTQmFcSXvjaIyiMSeGafzhETOvyj05xX1Rl2/6MYGMzSKWWaMOPl73MI3wlw2p2u+CtwBtd6qE+3LLENsx1PFmmmeato1YbwUGEUS5oom58KFBJtHKxk1t3tJ8H6g69cxfWaw3fuFt3vQM77NMN8haYN/AP1QenDGixbrJzSH9rHDPIAdqadZJFtt64C8mk5xjFQMxFfdeiTIctQCwqTP7K3W05wustZjj8vW591JgwarzUql7Rlq0x+/rmtAq9kpekcMi3L9naA6bpCDj01m39nk2gOBPeoBGQkuCy3vk07I7aBLxtNeqPGQpcfGiATX8LKZ4eDVrkLOG+gfflEzfijsSCGt0qMWW8ThvhAt6Ya6u5T4gBWoJsecKK7wJ6wgkQiJMJTvMVWqc+aTUl2oKNSC7lWsoAwBB2xo2nEaXnZlyCRiSY1Kkb5u5Ldtft/fhBAUUHJ+jeoBcu4+A7g3smKvIMyAkrD+7JKU0JltUkSfUe2M5rCwRgniSmZlsTgREgpq50rntlcrzb4SR1f86cA4r5vtiebD8qt/ScNjibOrcQ60s9T1Q== 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)(396003)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(30864003)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:18.3235 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e2e7184c-9096-4785-6dc0-08db9eba87e1 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: SA2PEPF000015C6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6164 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232843604100003 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() Move map_irq_to_domain() prototype from domain_build.h to setup.h. To avoid breaking the build, following changes are also done: 1. Move map_irq_to_domain(), handle_device_interrupts() and map_range_to_do= main() 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_interrupt(). 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 --- xen/arch/arm/device.c | 149 ++++++++++++++++++++++++ xen/arch/arm/domain_build.c | 147 ----------------------- xen/arch/arm/include/asm/domain_build.h | 2 - xen/arch/arm/include/asm/setup.h | 6 + xen/common/device_tree.c | 12 +- 5 files changed, 161 insertions(+), 155 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..1652d765bd 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -9,8 +9,10 @@ */ =20 #include +#include #include #include +#include #include =20 extern const struct device_desc _sdevice[], _edevice[]; @@ -75,6 +77,153 @@ 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; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 39b4ee03a5..57b6a43314 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2293,39 +2293,6 @@ int __init make_chosen_node(const struct kernel_info= *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) @@ -2355,64 +2322,6 @@ static int __init map_dt_irq_to_domain(const struct = dt_device_node *dev, return res; } =20 -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 @@ -2440,62 +2349,6 @@ static int __init map_device_children(const struct d= t_device_node *dev, return 0; } =20 -/* - * 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 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..f532332d6c 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -165,9 +165,15 @@ void device_tree_get_reg(const __be32 **cell, uint32_t= address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); =20 +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 cd9a6a5c93..d70b6a7ac9 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 Mon May 13 19:04:48 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=1692232854; cv=pass; d=zohomail.com; s=zohoarc; b=lBVIL7fqzOFOKKvpR5f8dW+ATPGNn4AQY11ySfEWBQTXvCL5JIVJAC5UTWgR5dGveFxdbKlk19+q0DsyrkDvJz25NNwv8zYmZ+7d4aBfuN0qmKBXbGKu1i7Zc64bXxNAPSNNxB7Xe7zQcMblMPYNnFQ0Ubiv+x+pWoNZBQigJrM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232854; 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=07WMr1ZLM39ba2ZtlvUhJ2PaUuqZrZEmQIHsuGgAwEE=; b=XCpYWn/UocxE+YO49mqKZD03pAgIV7ahj33GDoAw4jxDtAzthQ5eEZ9F2Zx97RK/C3aVhRZDKMhtssjX8qEBUxV0qQrYLBEIJJmTPOvRguWbAO2+eCZJA9sp4tn2b65FZ3UiMQxKMdTLmTXZ0Cr572WWJP+TnAqp2/VRaPxuRMk= 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 1692232854167960.4507609239572; Wed, 16 Aug 2023 17:40:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.584990.915955 (Exim 4.92) (envelope-from ) id 1qWR3x-0003uP-J1; Thu, 17 Aug 2023 00:40:33 +0000 Received: by outflank-mailman (output) from mailman id 584990.915955; Thu, 17 Aug 2023 00:40:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR3x-0003uF-FZ; Thu, 17 Aug 2023 00:40:33 +0000 Received: by outflank-mailman (input) for mailman id 584990; Thu, 17 Aug 2023 00:40:32 +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 1qWR3w-000280-3N for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:32 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2061e.outbound.protection.outlook.com [2a01:111:f400:7ea9::61e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a9f20774-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:30 +0200 (CEST) Received: from SA1P222CA0186.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c4::18) by IA1PR12MB8407.namprd12.prod.outlook.com (2603:10b6:208:3d9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:25 +0000 Received: from SN1PEPF0002636B.namprd02.prod.outlook.com (2603:10b6:806:3c4:cafe::9) by SA1P222CA0186.outlook.office365.com (2603:10b6:806:3c4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Thu, 17 Aug 2023 00:40:24 +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; Thu, 17 Aug 2023 00:40:24 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:20 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:20 -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: a9f20774-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HUgeQqtLKpqUMaKcUUVK/m5G0qLHdHb5hCyoh/MSPm7uOgRMx0dTjwIcoswZfOz6GknHbNXoWajTl7L4b9IIQGqdwoHS0UMMxYIjMburJnNc+YUd0iN5U58X6lMCE48pYXgpv7eZEHc46VX/00etPcuiaBK/iYs8ndnsfIvJPO2pO43aLhdiQmtc3+z8ucjeuCdAWhISNaAwKo7yFBEa7QPR3hjAq5WbiWQdWzjZ98QpO+7S/Dn8MTU36HYNS06se+qHUC3NumtUWuCagDv+YVKvj7petjtKdye6+NxzLzEB054ZqNTkf9Vqmti68ZAvtbrsINGxFBNQfPpoVlXBSw== 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=07WMr1ZLM39ba2ZtlvUhJ2PaUuqZrZEmQIHsuGgAwEE=; b=YW59k8W/p75EAsT/UUQCpfugnj+/IRCXAnPGJR8DSJ8nEOqczccL3w67AYu0UP9OJlUNvT/e3wgbRcu5ZlAMvHCyi81JJxVJzCjSD6GElInAt0QeX570qt1ZSXM2K53WknFS96GymmTKlQo9pDwGeoS9LxRkLYlfaOZBioYev++iHxCGFYH9/kVTWMhtefNsE/m4BRVCTaPZOzrWAv0CQY122ONPntiMegjPG3aE0HtTi8+l+s2zBn1Ibt/3j/GepEZpCPCDAPw+pc/YI21bvoH7BEO6GmBNc12KFpHqTI2u753fs3Nk3Z+M0skcdU88FWqYlCdSvdqebDj/KnaIvg== 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=07WMr1ZLM39ba2ZtlvUhJ2PaUuqZrZEmQIHsuGgAwEE=; b=mgIaYGgf0NJ4g7TM5j45oR1uKGumw0RjW/FpwPGE+u1115UTbo+jbRQF3IwQEgbM2FLhqQujkdTGx5JCpfXa4m6YBn6vki+We5cbb0n1pd9sgFS/YoF4MdL4u+RjSk9xgjgrv0xK6QLdFLGacaapWsa0sWP5fFkFOFO8AbaHd4k= 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: , , , Julien Grall Subject: [XEN][PATCH v8 04/19] common/device_tree: Export __unflatten_device_tree() Date: Wed, 16 Aug 2023 17:39:32 -0700 Message-ID: <20230817003947.3849-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636B:EE_|IA1PR12MB8407:EE_ X-MS-Office365-Filtering-Correlation-Id: 90022943-74ea-4a2d-3de1-08db9eba8b61 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q2zIDsyaueX1fclWx8qy6u/491zXb3HMKtyyJUb7MsBawcu48J3EwlIT23QwV11OZ1M2VRICP1AGrFh0Z8jjgVA6XNR7D5zWDzxQj+daXWuFE7ZSjYff9sj3zuNR6pell1kgMqc/Rq541XYEW16KrYv/VnMwRi2w2Tw4peTDuCc0h3Ml3AHNGTkMStumcJ/bKDIud07ouyk3/hwaf1sDIvRm/+pIozFmQwIoW5SHF+Ag8enr3hcnrCYmvY7R2OwqKWuZ6IfDyr6m4DLQfVvtEAkH0gzWcetlEBEZqVESLIw+sCdj/+1VzEoZ7SbWlx2BsFyf50lhC2zUAhh60OrHdFGxHhCpgVmvev+USQrzYt71kV6YdDhFUtFThvj03MpGosA0iwsHuMVhYQ7zgacUQ3ctBa1RDY8V0eyPZBT/71u2Ew/WYFJY/GIgnnXqSSQrmeTJ17v+XXmwmNrrJR9fw9/6ngwM4t5VTa6dYOhjL1rxR3vGrx5ohUG/znvJ/vnJXERdxFLb1jxnD/dCmEaPT0Bwdt5mczcXddfnXs6lrpUyseCYJJMJQYr3Ccy/Tizty5ZtvR5jDYpsXVaI0yO6Nw9ELvYV9+tsXtuRH7pF8eoLGp9vaKsMhRemuBaEZ7ZxM2Zlbn3R9mvHliRqQKs5t4Xjf4/nIibvtVdB0loDkYpeXoS6UbDhmdWOn5ZnFOgIt1Nje/U7USfWkX9V4/LyFClz5rXq4gyCwWhmKQbpR4hvWiLopuoC4QLnkHRrAT1//NRnkUvJ6+riZbPxRYNCqw== 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)(396003)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:24.1943 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90022943-74ea-4a2d-3de1-08db9eba8b61 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: IA1PR12MB8407 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232854876100002 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 --- 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 | 17 +++-------------- xen/include/xen/device_tree.h | 12 ++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index d70b6a7ac9..67e9b6de3e 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2082,18 +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 - */ -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; @@ -2232,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..5941599eff 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -178,6 +178,18 @@ 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 + */ +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 Mon May 13 19:04:48 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=1692232874; cv=pass; d=zohomail.com; s=zohoarc; b=Cv2/uxH1s/IKQIG1dmBd1NR5U8pQpCyDQDKRyYf19XnEqqQJDzTfRegah/kMHgfrepT/HteunGoxpR7/UyhAiyo0fKYk2rZLDu8svfFTwTgHo0Y01dEkCSz1omD05FItmi2MQMele1mPYyljkMscC6K5ZG1BCAUV3xGqNf2cUGE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232874; 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=eGVNShdnG/aIBZ1qd0+shXMehlt+J631oNOuesBuA1Q=; b=AigPeIBrFZLOD7hZukIslb3H+x8VkQm/9M8H6BHm8F573DzyuGdyUopeMWx8kQpxgnQljB1+yV53JVst1oAKqLziHsvCjwb9rvQNA4gFMMll2Y1z2NvEbtPuO4jBn+XWl9lg2lwGQUv4yxzf+1zKxEZD6/pOCVeOz/8vR8p7dPY= 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 1692232874435914.4810387482011; Wed, 16 Aug 2023 17:41:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585006.915995 (Exim 4.92) (envelope-from ) id 1qWR4E-0005fh-VS; Thu, 17 Aug 2023 00:40:50 +0000 Received: by outflank-mailman (output) from mailman id 585006.915995; Thu, 17 Aug 2023 00:40:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4E-0005em-Po; Thu, 17 Aug 2023 00:40:50 +0000 Received: by outflank-mailman (input) for mailman id 585006; Thu, 17 Aug 2023 00:40:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4D-0002YP-Jc for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:49 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20601.outbound.protection.outlook.com [2a01:111:f400:7eae::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b5c47200-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:48 +0200 (CEST) Received: from SA0PR11CA0095.namprd11.prod.outlook.com (2603:10b6:806:d1::10) by SN7PR12MB8129.namprd12.prod.outlook.com (2603:10b6:806:323::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Thu, 17 Aug 2023 00:40:43 +0000 Received: from SA2PEPF000015C8.namprd03.prod.outlook.com (2603:10b6:806:d1:cafe::2) by SA0PR11CA0095.outlook.office365.com (2603:10b6:806:d1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:43 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015C8.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:43 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:42 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:25 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:24 -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: b5c47200-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JnwaWOEJ7yNKLN+L9Ybsu9XGVjH2uxQPQF0yT3amZiwXbl8xef6/wi3D4PzvFPChwEKG/OMcCeQnuxMxgE2oOhDMsgcaBrXw0A40EG2qKTK3HtXjq+qNcXW8mQQst+heZUugdshTLJyosRCQ6griZPIusLzNvWFTSz9oD9Cq+NBIN1YK45aPC/j+pYt3b3V0inHP48qaN6v1Uy3Vae6M85F/RBWkBJG0cwRsHpiXjG0JqPJEUw/f+4TfvU5lePCvCpHMm72f7562m6fV5RQQEY0qktRQRUWw6BAv4aE0DVQSttiuR/bc9SbdhHoEQHKLzZakTKPJGXTFYTCbaxJfcg== 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=eGVNShdnG/aIBZ1qd0+shXMehlt+J631oNOuesBuA1Q=; b=eIKwi5DPgFWacIw83htMjFa9MLuWNIKPJVRFCg+qj/pTcZtvp6hQiPY5sAulDzz08qtljeR56xDOOZa6sX/YZG66Qo9xmR1GrZMGUlGAMs+3W9Nxe3W/SGOJ+tfcKY8uHeUlftBaI+5ZKBdo1meui20N6ieZcpstvq6cFGaYndEUYRti/SDuzCTlFrYfagaWCpLh96ExYUuqYIp0chuQUBGq/DQ/L6pqaLz31rr/EkO6c4rHxjKZAv0NCGINGKLsB75swsI3eMzLcVRXDUflcC+yOgcQLROK1YVMZdyOUhrRTfsyFs+csTRFLEyNWtr3Tncr+HdQY9KPrUzIBnAVwA== 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=eGVNShdnG/aIBZ1qd0+shXMehlt+J631oNOuesBuA1Q=; b=i91laATEWyd6D60JM8/H57huPqXJoaVOeJGcZqNcKK/H4v81s0z4O+s1qUn6YyWVQ9fPdBGu9Y07prXYuvuRoVEkahK+bfhusjoPAGnhP0qlEu68jGLx/V86lISyfIoPU/V0Z6bu1SUswFtuhOac9KaQSGso7Fd6BETGN0e1cgI= 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: , , , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , "Jan Beulich" , Julien Grall , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v8 05/19] xen/arm: Add CONFIG_OVERLAY_DTB Date: Wed, 16 Aug 2023 17:39:33 -0700 Message-ID: <20230817003947.3849-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C8:EE_|SN7PR12MB8129:EE_ X-MS-Office365-Filtering-Correlation-Id: 38266f72-d326-4833-68fa-08db9eba96fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FF2DsZW1M7oVyFbl8A2lvQZO1dijxqQ5dEGN8qpMutVWzclSgiozMQMcajZuUZRe3GVS7Gel3FGmrS74wjRZCVZPJJhpkFi+8dBHCrES+IYdjoC6yy6Kfme+oyigvBIQQ+RUhzSQ2R8hB/XmYP3umsM/A2qAM72lHjtR+ROr5ofNRnfz9t2UaG9YEeB+d3tdY7K4BAFd6Q4cu81nr7yNdUHzL0PRkq9pCCmI3uR5YxYCzulYW3k04iSi1MZEsGklmS8QfoB4ukhuaASn9LZxEoD4oUIFzgCV3plhr+5w1qodc1F/HL4yWOIc7hAPVNedD9yE5+aZPC9ogVRsFMndBwZpPShumhDoAT+O0kmWo7Em90BAWxhd2mvZMgmRHH9dADkshu9TmyaKBuA1fbYYzl8SszUxAZ21EsNt+KTkqqoh0qXpMdSvHLeqvxlt2Q61PkFfCnU5YV8pLmlT1ufSAzZz0OMfnOzVkK5Ch9uqefqboH9Wb8L7z9yiQ+ygr0YLCnHXe0oEOCbTbQFg3dPkWW8kgxXfQRftqcpLqggyRgwGiRnOZ9y6xfvf4YxHYR74IOz/IpyX3T8n4chqy6Dhm61X9yY03rTtgq34qR4qhtIhHUDKtN3RgQGUqJo2aUtMHnbagHbZnQubajyZGPNX9/5uZbUBhgNr3/BeweaTGpBAoJhuNWicnsRjoBACmApj8OJ42Qd2Y+dQWSzMNcoWgQ6E16ox68f7Xb4snzLEkSKSjjVyWSEbqy8WhpF7w7Ir6vuq1za+aFU4sUpOvfgkzQ== 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)(396003)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(4001150100001)(336012)(478600001)(7416002)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:43.6531 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38266f72-d326-4833-68fa-08db9eba96fa 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: SA2PEPF000015C8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8129 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232876590100003 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 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..47098dbfca 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..8eb006565c 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 Mon May 13 19:04:48 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=1692232854; cv=pass; d=zohomail.com; s=zohoarc; b=hqFgdotsKiSSGGysNqUm8ccJLo43P3GskSxP1DI++huYc0sM1ijrFwdi3JTvfGnad+7IqTCxrcsaVetAWKwfI75U6uQZdN+rQ9C909bY+TIQNrUeJDJSAVKDkyIDuSZAL56TTU1Xe1uVs5zPphTIMccBi3/zEv1nRhgr5Rv8rdU= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232854; 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=DstsIso8yMGYv+dUFcikv6HG6EfK5RLYqEysHDvzU5SeUcK7gXFhPoQpBQ62mMgfaTNgMEl+Fnv7IvTkOxZ+NxykKvwNb4Em8B62XW8wuSi6hINAYSI3B67/WMBtvgHrBa40XAtK7mL3TmWJA/2/ZQKoSh9QnZSz9TFkqHUDZSY= 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 1692232854264810.5705421488486; Wed, 16 Aug 2023 17:40:54 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.584993.915965 (Exim 4.92) (envelope-from ) id 1qWR41-0004Lu-Vq; Thu, 17 Aug 2023 00:40:37 +0000 Received: by outflank-mailman (output) from mailman id 584993.915965; Thu, 17 Aug 2023 00:40:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR41-0004LJ-R2; Thu, 17 Aug 2023 00:40:37 +0000 Received: by outflank-mailman (input) for mailman id 584993; Thu, 17 Aug 2023 00:40:37 +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 1qWR40-000280-UW for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:36 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20613.outbound.protection.outlook.com [2a01:111:f400:fe5a::613]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id acffca5d-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:35 +0200 (CEST) Received: from SN7P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::17) by MW4PR12MB7000.namprd12.prod.outlook.com (2603:10b6:303:20a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:31 +0000 Received: from SA2PEPF000015C6.namprd03.prod.outlook.com (2603:10b6:806:124:cafe::42) by SN7P222CA0007.outlook.office365.com (2603:10b6:806:124::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.17 via Frontend Transport; Thu, 17 Aug 2023 00:40:30 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015C6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Thu, 17 Aug 2023 00:40:30 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:30 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:29 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:29 -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: acffca5d-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R46mwtsd7g9ad2DvXmRzahH0CgVKF20SRv2NsReGcW43HlL0enmUf7s8sJWgFl6USdthOw8CbaZ7BfVW0hkIA1UiEFuG0tEvIM9q0rkBw+C6PhJxu1G2dCk0/7vh40M+voWPFDzHXbcj5B6o/zxTgItkZdKE/sgedoKNklY9eRLGsPyEiAjeY8GCe5yqUtVFQ7X0QkiS8G+U7nz3BMcgwOQb5LKSIJh0h33snVIsuvc8vpl+BLcKftJTpx00BiLz67eLLDVTSXMNWDvJLjdplsD2avk937N1a6vjEkbq9EdoC8d55RohGW2n3MwWCLUgp6NX+SODcWysCv+/lR+UUA== 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=dPPIHmttSvXNsuHIXUyM03DukL2zOU6wGYrK9Tu1N8Vf/AEU0/x5yO49nT8Uc+1UOOFP2608Q+f76/Az79WAHe1fvkwMU+lnirbQ24DyVv+C+IeUYb1DnbPT88bzfRDsa4Rq/CIYtFW8wBzx3EkM0AGYgt6AB/50i7NeiG4ZKMnHtbWhV+4K9VFqKnhQpvYQVrp/2FUuXd3EBa9r2eK7aayhSFLFBlRHNmY0pv3HmQIhzrdm6Xd9IFQpqzhSiDHBM4SRaWvJDDJH83H52+JccIrer+lG1d5Xlj/d6jaeptymFSlyfDd0nIdShO/u/faDnTfuZLxiWcz9iy7gVhB/hA== 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=YKeBxZcym/0TplfZz7+TiM9RNF8mIcIyYvWX5AKvJOLPdcQ2CXoQSgVwGgZyHEG9+MgfLbLYMdQyB2QOiY6J5RqmcGGgFDdqmIuJ+mXw8BYfmtYeVrBHD4YZjpda5m9BNZoRG2HCAhgkcoKK2g5NM7GB5nx7vJM/7En6ChdIPZ8= 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: , , , Julien Grall Subject: [XEN][PATCH v8 06/19] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Wed, 16 Aug 2023 17:39:34 -0700 Message-ID: <20230817003947.3849-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C6:EE_|MW4PR12MB7000:EE_ X-MS-Office365-Filtering-Correlation-Id: 70737f81-6639-47b8-c9eb-08db9eba8f35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JQhCZw3myDdNiDzBWvYyoh82FHDXAR4PCAw9Yee4KVqhdQglWWCENt3n6d+zH+uXSsytL0lUv53urY6vHThwzlmr/y/VfnviSMx8PE8DqLbBDFFgix304ph1amUkrxyijFMajNYkAr8bFfccBWAq50Cizngol5zzMzJryUOiRmbE0yKkEXPXxhzARJyr3uSyOelJWUZQDg7Bk+8HBlVQFR/QCriqBQI60AohMvdS7hb+Q9r9w6+vNaEqlwkGXsNIVvskOCRThx5gvKt5uzGaRitzBkzJBL+m9s+9ZJpHS2FWOb/AujEpi0ev3vhA6B1faNRu3Btybf32GFWROiQLHYduYi18Mlf98zJXa1hqv0i1BUN3wm1Y56QAr5fKO7X4JUlNQib1TPObVcfYKbWZ5TEGGKlmwHDdZdV4Ka3APywjyhfq14Y36cOtDQQTebuPmTXnGIKIEUD0LQLuCAzmThiy2Lv2Mmqpn0CHgfK7xSFSSH/fzrewJX0S9tqtX+uCPxYkWc8ym6JE1wNvlIn0XpXWuiR+qWyH/24i6rLAmP60MItDr/MUWl31q12FqQdjWWsqOaCTFEjedw4WdeLnlvgdE6VFwUkjbv54Dp3Q9GcModqbsk33b4HdqKMhs4rkaI62cx89R0ABmwHikAVsZ8C3yzgXeM30ep6KxkxBTAX5S/OKhpdIGxcuug/u96g1TCQ2fYdpIBmYmnetteReraM1bq52aGg1w8zF9SEIB+0oRKrVELgXXcvWRniWnMbPOzg5lR/ZJiwcq156kudWoA== 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)(396003)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(4744005)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:30.6204 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 70737f81-6639-47b8-c9eb-08db9eba8f35 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: SA2PEPF000015C6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7000 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232854866100001 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 Mon May 13 19:04:48 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=1692232865; cv=pass; d=zohomail.com; s=zohoarc; b=ZXmb/OxmqqrSOZSufEcnohVOhX1bKXRX4Oi+Y7SvoHLvls9sRmlasBbQZYj8I3CJqJ3Fguik3qrYuh9HRCbOLk5JJYWg5l1UXeDPw2KY+psEHTYTfoWFmLhJ74fU7VCElSYIzlg2FWRoD3OraIB3GMi9b+AKYVLKIK1u8I/3jCc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232865; 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=BphZ2yKoveqs0ZNqF5xYbXTbecBLk6881/Q3Jd9YoRs6/90LXyA8ikkcRLWfTFehPzoLQmJRGJgUiNz87aOjgXBgo3XU/Ny2sBWfTIzbi6Nl80r/RO1atquAT6scGezZSweTUWxJyRNRdS0YI7X4MH7YvDswxsztC8+nUWtiptw= 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 1692232865620113.07421047536627; Wed, 16 Aug 2023 17:41:05 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585005.915979 (Exim 4.92) (envelope-from ) id 1qWR4D-0005Do-IB; Thu, 17 Aug 2023 00:40:49 +0000 Received: by outflank-mailman (output) from mailman id 585005.915979; Thu, 17 Aug 2023 00:40:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4D-0005Bq-C8; Thu, 17 Aug 2023 00:40:49 +0000 Received: by outflank-mailman (input) for mailman id 585005; Thu, 17 Aug 2023 00:40:49 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4C-000280-VC for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:48 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2060f.outbound.protection.outlook.com [2a01:111:f400:fe5a::60f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b4347f6a-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:46 +0200 (CEST) Received: from SN4PR0501CA0067.namprd05.prod.outlook.com (2603:10b6:803:41::44) by IA1PR12MB6163.namprd12.prod.outlook.com (2603:10b6:208:3e9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Thu, 17 Aug 2023 00:40:42 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::26) by SN4PR0501CA0067.outlook.office365.com (2603:10b6:803:41::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:42 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:42 +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; Wed, 16 Aug 2023 19:40:41 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:32 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:31 -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: b4347f6a-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R1DNHNjKschm42ddVL0ZVGTYb5/bl0VT8SdAxJTm58gK0+6mDzLTL1Bse00XHKHvBtkOrboDOjPr+EiIl/+K7JnF4eHYp2OFZEPMx3C1zKsq4LbadMK5QV5xnRfIdKsjdBHHWy/gCNhwJq0z4+5B2c7BphNXkN4II2/ouUp3M/zRLPduQZ320Q/ovP1VsVcseKCcak/qLpXc/Wvy+YwDBkeLTlq//GictCPa92bwmFuxtssa1srLUHG+quYtKfjc6aVVFlvZXrRKlMYteDAJQIRqCdMH8VDIpO56ub+ll32TycrYOHy5T0kNoXxGSxrpWIfgB0JW29pfdOgtuV+Jxw== 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=airvZLNpv/LTKJWyHNH6o5bdGfyrOB1lT1ReA9XDQ/Ma7OG/DveWL71HSwKwzxcFufTljNel5YZzFiKYirU5y74nBOiEnmUdlny6CXQYZk3KTutmidO2r1qd0Qq0hXgEbdgduQnltxf9gCt8AMUQYGPm0T2oAFoe0wOfXLGMeqGly/0xJHszBG55pgePnhD9rEITv4ES1yQNOe0OqPzZQha0DWs7i8pMF5vLTK9N+3QAATN9Y6kLAehP7GrzPoFLG5c05i4M/JdB9hduTeAVvvNfpADbzjdDdHDk+hZIe0JWeT+cnF72mcnWVopvEOjGM9j6c0XuE7JgEKzRhU5AVg== 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=25GgB+Fu9H4FBgJq9ryhEPZoUtfukulkqFvz9I7tms4qiZ6ftP2bLSyQX3Dj5bG0MiLs4F0a6cGjkRGoDfZX9WdAAQsI6eqjDG7QwHxJKRMPNae7xgt9tXm/w32X2390aeTY5/4VXvDnjx3UJMgi+iDH/gIjP4XEhezeGi1aILg= 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: , , , Julien Grall , Vikram Garhwal , David Gibson Subject: [XEN][PATCH v8 07/19] libfdt: overlay: change overlay_get_target() Date: Wed, 16 Aug 2023 17:39:35 -0700 Message-ID: <20230817003947.3849-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|IA1PR12MB6163:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b46e1f3-184e-4099-ba9d-08db9eba961d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ggw+gDu86BHVrakbD4OWK7iPMXKN6nHKRcjEQahuZXumIsZwSw5VGQQcD9ldlrsQZveOtV1WwXx8LA3wVeDh9nBebYcjn4kpkf4n/5ZRkCX1CPpcSb4VJJN0XjONeYUgVqQLshOqanJBJH1Jsa44ZrtM6r5zcXSUsf/xlbE+VjoUyDDmFCPhtB5HImyEQepl4rOlOklSfR5/VkUegBBSbqJe/LQWsPFXhXoWdVvfFqvj/yr7krcozndy7WqWppI50Wc6masycFRBv9zADS8PdrRSJzMiO1xvTJ2uyVCRO74ThxCG3+ICCl3ZrZZNwj/sq/w6kIkYM+/yZo9FolyBkCI8GHZIziA7/StPvn5hFf5Jbl/Ym3+OzYAT9DkSkiyViRNRWCq3e5jA2P/ryLru25hLH+Ky8QfoSAu1pcH7Z2ToN43ppCzHASuEmS0W6baHwzBOqiz1yqD2dr2RAoWDz9srHac+cvUcyH3rGoiHlXl4mPX1CzNVWsN2egBlRESjmTmZeK3PdMtteqvJOv4xX88xbWhT95mvOQbCjq5lhYCPW8Tu9X7VRB8jYRbBghpcGiI1oU8j/AJn56L20VGLSaDNx7M5J62G7RPIVnWqorqzsAFuiJlwSkaRUOSltxUT2gcR60A6kmPbi2Dc+jGMF03/BXvjtHA9tuFjrlF57p1pWnV969rieir6o9V7dK1hWaAHrMZnOPlRt053hgl2QAaVfGA96UKANGllWloHJ2DF4lFDHCbBYjDuEEiBfwEpXQ7TyMLsaAHCWTFhGYjFCg== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:42.2068 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b46e1f3-184e-4099-ba9d-08db9eba961d 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6163 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232867860100001 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 Mon May 13 19:04:48 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=1692232870; cv=pass; d=zohomail.com; s=zohoarc; b=Ij632YEaaxiehI2j13cFnRHzVzDsJuuk8dqznI4HSW3XCf6xEkl4NZxZxcIOpg3aCNo9rHgkIsAk/wPzvpuP0OcqXCDd5ig4FAkni/WQE3KvTTpPfFiVw0vPyjKgp4ugFeHRXBIl6NmRGK4NjjL47RfZ+Myre754xP5NYnEHmAc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232870; 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=/xHkFrH8SopbUhm47gT/XcnanhxswGsDSx0kdqePZ4A=; b=KLkkA9YRTuE8Ld36kk8KM6fhKCKPrZ7upV0RvLyfWpAlO8fChZGVeLgiO6q7EBA1idE93MptmDfhhc6qJmEsbVDDn7tq4ctSg6jNMXF5gdfn5j2vwT3k/HTc6ihh4vMz7CZFwy32OGd9+XtaRMZ82/tQQKgb2QMj4v/PBoMtENI= 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 169223287026826.49775549947651; Wed, 16 Aug 2023 17:41:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585003.915975 (Exim 4.92) (envelope-from ) id 1qWR4D-0005AD-6p; Thu, 17 Aug 2023 00:40:49 +0000 Received: by outflank-mailman (output) from mailman id 585003.915975; Thu, 17 Aug 2023 00:40:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4D-0005A1-3K; Thu, 17 Aug 2023 00:40:49 +0000 Received: by outflank-mailman (input) for mailman id 585003; Thu, 17 Aug 2023 00:40:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4B-0002YP-Jl for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:47 +0000 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on20603.outbound.protection.outlook.com [2a01:111:f400:7eb2::603]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b3fa0aa7-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:46 +0200 (CEST) Received: from SN4PR0501CA0047.namprd05.prod.outlook.com (2603:10b6:803:41::24) by SJ0PR12MB5486.namprd12.prod.outlook.com (2603:10b6:a03:3bb::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:43 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::91) by SN4PR0501CA0047.outlook.office365.com (2603:10b6:803:41::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:43 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:43 +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; Wed, 16 Aug 2023 19:40:41 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:34 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:33 -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: b3fa0aa7-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LMOMkF3u8iNMs/AxnqzdM0ki90BrG7yvrFn3FZrl3kRfvYZUBb7rXu7LnuVxUO/sBD9N44CJfKk6MB9WVEeWASw1wdFJi7c6EnzQKyKlhMtTqnre7F6/nTYYjLJaVKJsxN3YxI7P9d3dXjDyEOwH3LNQqGZRd8delLJq9RAOPZDwzzbD6P9nAce2O9TCyCpW+YNSeqGT3u61XPl3TQJgikiKbp6CmS6nJLye1/rncGFFWwi9Z0I05IBXgEZWW02OxDxz/ZiT1zN3R5IRrPyJdx2LMZYVdDUM2Rh6uHzLA0MLUFAA/W89HxEwAUJIoNqNar2d1nSmkW/L3wqnXJQdOg== 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=/xHkFrH8SopbUhm47gT/XcnanhxswGsDSx0kdqePZ4A=; b=RUpp9T/tjRar/MHOyjlLEpa2eB4WG+2Y0ezJDr5jSm5C3XyOUAJzASbNIU7ZpdT3M9Iwj+Iz2AutWyduGs6sAow+1IFN4eeFsX3FU/tYJeHosUA2BfLa+7uoTbNBJk6EW5lzAUbzmuizWmpuHFvpDukBht2bzz9J9IgNvmciGO1Md1x4HPQyN0cLJbRHt1M2IEOMAuzRKms4wqim9eR/AMAm9DM2rkm6ct5OP0rNvaaJF45cJpRVSqXSKsup+PaTuW0eY62vfSbFEqlPp0Wdkzxi/OPu4l1LHmMqA1WKs2QnlCxLeBtuiA0hIFmkIvA/dOgSqXLnM3AGIHROc0djAg== 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=/xHkFrH8SopbUhm47gT/XcnanhxswGsDSx0kdqePZ4A=; b=xtLsPwRJJvcU+9egjU6pb6yq4KzOUCq89OdZZ6uBPCzEysGk60w7nnURf4lTQagejFtlvidt5c4MyMBITBu/Pn+wnCAkYh7xzV063aXTigVDVCpltzX+GW93sA0yjL1BJDhFSQxOr2c6O2HBhNxYbsq+N+evPK49GbSCSvdtnQo= 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: , , , Julien Grall Subject: [XEN][PATCH v8 08/19] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Date: Wed, 16 Aug 2023 17:39:36 -0700 Message-ID: <20230817003947.3849-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|SJ0PR12MB5486:EE_ X-MS-Office365-Filtering-Correlation-Id: 69ffabb1-e155-4aa2-b24e-08db9eba96d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nhZKrBkO7vSxbYiiS4hI1UbXGhVakjLNyykXah3E5PI7tZTNMf67/0kDom8+lXBAA+6plm1P8aRFwz4wPfTpicbTeIq4FEeB4oqiR9ief55sEbpyZbp5SAhY+0BHG2PrX6Fj6QTDUpLu4dQQbHnYnDWK0Jy81X2olBGfP6s7AfEdHfXYtN19vdhVnq5rqxFf/JKP023lcCwzKkTXvMIh9wVKuDNvULPxVO3X2K0DhFMEsLIr8DtSCyXjDLCiuKTHcgElZQ52Cx9Xzpq+/jTxiE9QGo2cP4WjUxFVD7B72cbKycjLlr2BqI9+/BVTj50NGxGueQbH7PVqWBkgvLpXEc8TTV8dks8trHaKBwfB9BLhHJADSdeFR5/g3yx/Shq1wNDYVFO6b3Be2rigG+miV/nwGfeVsgAWudYFjSC2Gr68Axy9yKKY4d43hMHyFxZSdhYXYOWrGswr67q9EmKfJP6SKSsElAi7Z95hBhEw05wnz2Lo5IJZORZN/dRTsqZM7cnk04sdVk15z6QrsRl9dYSAh5V8wTPE0FL0HNm+0GFUdTHYah0I1cHu4olYvTjiWMt5U9I/bhdI5x88tA6EK6ol/TUT/0s5KoF9thyhI3it6kFRid4s2Oi/plnezyFNGxfNov1fQREOI1SVWpJCSRMNoAf5bmWNp6aZ6qR+1cpc9hUqH2tYfR14FmHSkJQfK0irpyGH5P1uDZcp1+h50I68L48shoymR0dwRNxJ/q3tD0TPXw6baht8ub/jAlMn4gh1ajJgJTOGV/4lSN6EVZ2a1JHWpIbQjnNPIBl2yA4= 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(1076003)(2616005)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:43.4256 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69ffabb1-e155-4aa2-b24e-08db9eba96d7 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5486 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232871670100001 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 --- 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 | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 67e9b6de3e..0f10037745 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 5941599eff..e507658b23 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -568,13 +568,27 @@ struct dt_device_node *dt_find_node_by_type(struct dt= _device_node *from, struct dt_device_node *dt_find_node_by_alias(const char *alias); =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 *from, + 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 Mon May 13 19:04:48 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=1692233470; cv=pass; d=zohomail.com; s=zohoarc; b=NFePbK9pvTM8FWzCicMon0PqVH85IZUv6vtYe3Hl5FRgDj7dz2+habVm8MNsaUy6h3rYinBAwK1d6CdVT4+wjIs7/Nx+L7A5JXe1K9A1h2LJhQmTDe443hY1LUcd+INxQLPvUmgkLOONuruFMbw/qT5xrbsjS6LFXkv10TBbi4c= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233470; 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=qIyUzT1AUXykQrgYpXKigDmIsrdrXXxfGP25yLD3dds=; b=MAWvFi0t4lxDtfZCtQKRQb+8e/UBYz7ELOLtSyCbScsJ/DmVIF5Z3Zds4gv/A7KwgHjR2JaG6Z3C9SUJX5SLZ3KBBu+PqpSF10LcepBEMIZwZNyuLzNC2ZTC/n/HtAH6PPuHrDuBetB05gRZ69igacPxN8LdZyRXGXBrHutldyc= 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 1692233469950654.2939197765287; Wed, 16 Aug 2023 17:51:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585062.916090 (Exim 4.92) (envelope-from ) id 1qWRDs-0004P4-5T; Thu, 17 Aug 2023 00:50:48 +0000 Received: by outflank-mailman (output) from mailman id 585062.916090; Thu, 17 Aug 2023 00:50:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDr-0004NO-TK; Thu, 17 Aug 2023 00:50:47 +0000 Received: by outflank-mailman (input) for mailman id 585062; Thu, 17 Aug 2023 00:50:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4H-0002YP-FC for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:53 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2061e.outbound.protection.outlook.com [2a01:111:f400:fe5b::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b6afca5e-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:51 +0200 (CEST) Received: from SN4PR0501CA0057.namprd05.prod.outlook.com (2603:10b6:803:41::34) by DM4PR12MB7645.namprd12.prod.outlook.com (2603:10b6:8:107::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.31; Thu, 17 Aug 2023 00:40:44 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::a2) by SN4PR0501CA0057.outlook.office365.com (2603:10b6:803:41::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:44 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:44 +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; Wed, 16 Aug 2023 19:40:41 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:36 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:35 -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: b6afca5e-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hevRedi/HuvpbuYXgNJq0iGgLB1N99aAi0qJASATrvYuRLURGh5seYbaA2/yeFHaXQBJ684jwKmBgsAIB9EO0auzOfy1/k0mIk3BgEMLURg36wB10VSJQiTrHxUPNgAgp2vvoapdeV22BhzJadkiiurK5Yy5Naq7HL9hioWUHE3B6hpxun9/+7MlP9LPrQDMxiRfOMuMuYCs6vSf5JCD5SC1cZX+uh/aj5o1FNd1iNzhinA6S2CAjCrJm3++cI9iypOEioFC44KbmDxlGXUzE9M3AWzkbX9c8RTNE9r3bivIpxW5bAi4zVvLysXZqpeCxUWq7sAy3vD3cUK5svxVhw== 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=qIyUzT1AUXykQrgYpXKigDmIsrdrXXxfGP25yLD3dds=; b=WOICDTJwv/fZMYQxINixdg/BUBvxrQYkXgdT55+G5EQ9OAcw4qMoNAZS9zbaCN0w3H+4pVb3daKNmFJidyWxiTEku8Wxg1Wd/I+sLDwZKfrHQK8yxLU7XN28wPgEJj8w89QC33Qvj+TCxg5c0LJ8rX6qaxVvn1sT96J6UAxqAp/A+VvZdWAfBvDi1JgxSJFrh2NbUdks6Njfpj67Z2GElzw6Mmn1KBuP2zwDx+vvPJfQyGBWnt3L9e2XkoCBoI9Tvb+Rym/h1Sdy25G+/JiwPqHmjrXXjio80+dm6BUKoRaJPmYlq6saQ9YVf2zEl0/WsxHcV5TS7q79ZTkGu+DOzw== 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=qIyUzT1AUXykQrgYpXKigDmIsrdrXXxfGP25yLD3dds=; b=paG7YLbAUw504iHfl0J0G0REvjLbDVozU0hidGz5m89Oq70R0lx9JSsnPhbzYwuBEpKOApbSWYmjSgjssqCv97Rcb8Ob3xAeNZtb5Me1AsCYShWwgvjZX6lULnDls/dU+zspZUNLSMjgS3fwevOZvwQE2DgH7DHjxRyA76QudV0= 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: , , , Julien Grall , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu Subject: [XEN][PATCH v8 09/19] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Wed, 16 Aug 2023 17:39:37 -0700 Message-ID: <20230817003947.3849-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|DM4PR12MB7645:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d2e4355-fa3c-4628-e975-08db9eba972f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ukkm6xQFFEApv6YtCS8yz6S4udYrNG/qxgK+562VGWvF2L3ykL2CoXSBninxVBxr8JU7RM0J4QFCOG0jr4tpOpY9JMtXEPpNoAF2aBheUzFQHl+6o6OVfjg0YphmiBJk/Dd20IHw3fAq64sOT0lO/1mvBWvjKZt2dq+riS2NAMfKaEKML85dT/FMCX0RAY60g0gIbqdi1WzSmbC8kMADQ6Wr+NsEn6TmwZDwfr+Yum9otlKk//5LBiybkjxj6/00v2Uet0IXJ9rUUjvV9SBZO1Bzuoti6CpPYogQ3ZDGAnw5u+Afrqm5bg3/rswJIU0eJ3+uuyUVTW7TsNfN0+1nmvoCbZcGJlcZYQoQsjY8Vw+H9A434/vczA7Q3otNMD48ov9/C6Zsdr8cU4gA/oANEnSF/F+T0rEZY7vQ16eLlo4Zob3ucKqCCZ78Mj6UoODEHmYw2uQKbQv19pWAGhEDv+dldMz24mo0uploEVEsn0oqKfKMF+HjNHhcR2tekdb49xlMpKaZDGp7INF0OXsxTB4JaxEVbksnYFMkLw0ekeSdSwW8JXS3oOf7Qms/fCus4swszJzqdkfjLR/gjXDp3Y6dQEbSla39H4hp7MhUaZ6wz3IC4yMUunZJuBqlWBpk2sGy2NQwFbiPQNs2tJaYSQWV6I+AWkSRnVCHnZr7Bk/yDf42eC9M/Pq3QLeWxHuZMopVxpP8Bs+dKB/4bqrIQB/IbAKme6KtPcsV11siDhOOyAI4Ud46JuBfh0dg0ftvq74fcDeUP1AHe64d1/aS2w== 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)(82310400011)(1800799009)(186009)(451199024)(36840700001)(46966006)(40470700004)(40480700001)(40460700003)(47076005)(336012)(426003)(83380400001)(2906002)(36860700001)(70586007)(70206006)(54906003)(6916009)(316002)(478600001)(44832011)(2616005)(5660300002)(26005)(1076003)(41300700001)(4326008)(8936002)(8676002)(36756003)(86362001)(82740400003)(356005)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:44.0037 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d2e4355-fa3c-4628-e975-08db9eba972f 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7645 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233470877100001 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(= ). Remove static type so this can also be used by SMMU drivers to check if the device is being used before removing. Moving spin_lock to caller was done to prevent the concurrent access to iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Follow-= up patches in this series introduces node add/remove feature. Also, caller is required hold the correct lock so moved the function protot= ype to a private header. Signed-off-by: Vikram Garhwal --- Changes from v7: Update commit message. Add ASSERT(). --- --- xen/drivers/passthrough/device_tree.c | 26 +++++++++++++++++++++---- xen/include/xen/iommu-private.h | 28 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 xen/include/xen/iommu-private.h diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 1c32d7b50c..5796ee1f93 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -83,16 +84,16 @@ fail: return rc; } =20 -static bool_t iommu_dt_device_is_assigned(const struct dt_device_node *dev) +bool_t iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev) { bool_t assigned =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; } @@ -213,27 +214,44 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, str= uct domain *d, if ( (d && d->is_dying) || domctl->u.assign_device.flags ) break; =20 + /* + * To ensure that the dev doesn't disappear between the time we lo= ok it + * up with dt_find_node_by_gpath() and we check the assignment lat= er. + */ + spin_lock(&dtdevs_lock); + ret =3D dt_find_node_by_gpath(domctl->u.assign_device.u.dt.path, domctl->u.assign_device.u.dt.size, &dev); if ( ret ) + { + spin_unlock(&dtdevs_lock); break; + } =20 ret =3D xsm_assign_dtdevice(XSM_HOOK, d, dt_node_full_name(dev)); if ( ret ) + { + spin_unlock(&dtdevs_lock); break; + } =20 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 diff --git a/xen/include/xen/iommu-private.h b/xen/include/xen/iommu-privat= e.h new file mode 100644 index 0000000000..bb5c94e7a6 --- /dev/null +++ b/xen/include/xen/iommu-private.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * xen/iommu-private.h + */ +#ifndef __XEN_IOMMU_PRIVATE_H__ +#define __XEN_IOMMU_PRIVATE_H__ + +#ifdef CONFIG_HAS_DEVICE_TREE +#include + +/* + * Checks if dt_device_node is assigned to a domain or not. This function + * expects to be called with dtdevs_lock acquired by caller. + */ +bool_t iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev= ); +#endif + +#endif /* __XEN_IOMMU_PRIVATE_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.17.1 From nobody Mon May 13 19:04:48 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=1692233447; cv=pass; d=zohomail.com; s=zohoarc; b=M1LBgn5SrUCncZwRJRHtJqx0kh7st2GwYidOIjgG+SOHMs+lnpRRligM0vUlzxjT+yZkfP5l0+kObD9OcLo1XYqzLv75TwHB9M5RK1OjRW0bT7SCuCLvdAj3VV4UmNniJbTu7HfYgXXFF2H2RAs9nKNEMK/5K2jSWmKZf/+zJXQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233447; 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=YKa7svLG+XqwpbOJFC3IlsmtdaRP7xcFFG8yBKHlK2o=; b=JMcVLEyhPkPNJEIILvxQUvR4/M6DMXFXQP1pOyBiKrX2vlIwR6q3oX1N4M9UCCh27hvDFAhXzDsCAUvdlkHkJvCphVyyZjFK6hLaEJJRDiaKxnFXGqdpbbsZ9XZUCnSeUzzXccAt2urO3u7DgGMaG91s0HbYFTSAjknUkgwA0/M= 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 1692233447222753.4800147683635; Wed, 16 Aug 2023 17:50:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585035.916045 (Exim 4.92) (envelope-from ) id 1qWRDN-0001p2-Dn; Thu, 17 Aug 2023 00:50:17 +0000 Received: by outflank-mailman (output) from mailman id 585035.916045; Thu, 17 Aug 2023 00:50: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 1qWRDN-0001ov-As; Thu, 17 Aug 2023 00:50:17 +0000 Received: by outflank-mailman (input) for mailman id 585035; Thu, 17 Aug 2023 00:50:16 +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 1qWR4G-000280-Vb for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:52 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20626.outbound.protection.outlook.com [2a01:111:f400:7eaa::626]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b658278d-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:51 +0200 (CEST) Received: from SN4PR0501CA0046.namprd05.prod.outlook.com (2603:10b6:803:41::23) by PH0PR12MB5468.namprd12.prod.outlook.com (2603:10b6:510:ea::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.30; Thu, 17 Aug 2023 00:40:44 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::60) by SN4PR0501CA0046.outlook.office365.com (2603:10b6:803:41::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:44 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:44 +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; Wed, 16 Aug 2023 19:40:42 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:37 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:37 -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: b658278d-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T/J2kOAhk46W6QbyYtpcJ+1nY6rR7+pkglNypNUOaCrbFm5XUcxiyeQaoGz83560/wCR9s4JDJqdkiE/MjpkpLwPJ2N9vN8CSJHUAqdIBYN3s1nvp+7yzV59FJBIZ7zjrTpi+i1PUtBSXxuAeWm/nLK8EH7nhWIiCeg5tHF/Q/29QRfZMnXtcM7hYIBe6UR3Z2XiwMlEaWpr3D7qLGlQszUHWr7DvHX+Hh05qu96z9Q3ZxdKsDF54otLVt1FfMrnGFVTFWn2vzCoFkUzumtN7m3ALH8x1OlDVF1BKQbnLBfqpW/+q6VJEZNOvSz1BLoqNFBoIbWHvwSlKYH9+VS5jw== 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=YKa7svLG+XqwpbOJFC3IlsmtdaRP7xcFFG8yBKHlK2o=; b=LXSJ08Plb3EAmpJMYbOy3OFZ21H9p+FaEcIFT1W1INl+8tqZlJxnjpkMjqc1fR/2LBucxX1BWG5dq+25PHowWilq4mx6VNlrDEU7N9BzJzf7AoJrDGZorIIFkJ2k15d6ugwPT5YGIgYHhZxk5S1ReEVoflLJ65E+LF7j4s7W+2VZ2TdSOuvpMkyA86dQJBuXnyvbIaGLuinhjvrg/+dnZu9sZzyXJOR4FoeGWQGdm7E2mGGfISoC0NbNUBGa7LZpUgbP56KTBWcW2bcSIyKXNY59GE4VShrx5SDNlF2rfTS/g7or4g260baHGJDVhHEsLLEVtdXRd/+Tz1XJj6HFZg== 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=YKa7svLG+XqwpbOJFC3IlsmtdaRP7xcFFG8yBKHlK2o=; b=blsIGMF/msahoLBZj/NYzCTBLqXhZ1KxGWi854bVr9ciI74l8G+PmwBSuYwJV2svbgb5cXQQvRfcnjujkDm8MhkXCVHoA97T8/18oj8OvtBV7OeQcpGMBII+Ts8UUmriJEb4j5U6dhlOlROepildEcV/eJg4tpTQ4+ThwCFOCZo= 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: , , , Julien Grall Subject: [XEN][PATCH v8 10/19] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Wed, 16 Aug 2023 17:39:38 -0700 Message-ID: <20230817003947.3849-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|PH0PR12MB5468:EE_ X-MS-Office365-Filtering-Correlation-Id: 20262333-23a5-4846-e541-08db9eba978c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7CQm6EFisSNZimRQ6JoUKPjbIWnN7ZT44Nu57FXM7YhTZQRWHGfmDzXExWx+9yqPbZ6993RJ4HHGQZSr9L5Y0mXvIj1Q1ef+7SSolb7YjMHwIuRAhweJeemk91JoYnadewaq7QxOBHGgnIbChiUrG4toxcPBzamL2EkDDsDwZkEBLYonBqfTVAfmKJay15WOkaj0biqpFtHGNhekMow/kuW9YZxkxYqP8H7bbTLXaqU9pIDRaQuJJxtyPQh/mRpQVFUZExNw2+f0wzKZmFMdFIIRkX/vOZ0pcOG10qwlKs7ao1MHzygG2QCQ+0y8gyNkza9vQ7iE2yDJfFZOjONzbL4wFu5w85mSzQz5ZD28bM/CjTSYib2RhSDlaIjgAP6OM21QYxQOTdFR2PsqY1s+uN6Uo5j+ugAgvpSzehwDrT8llZcVbE5CagRdG6vPQ8Qxw2BgcqB1pl9NyuxLLoMwCa7WLCXRAXYdabEazdd7uehjfwZX7SWiRuB/FSCoVL0Dy1CFTf0atWniChMFZtr4myFc1Q7dcMzL6sa1+8iNXFuIQHfuG3YCIpWDqKjgtfEFy1J5IeQoPr8MFcR3X42mUaZMD28KzNeWPBLX0Zd8F+ohDzhPSh0l1/SqCgyyu2J7zlCy89B39Qu2xxvplxSRBNLYvd7dYyZ4aow+/UxPjv8EQWyZT0fDNMaaaKosJC1p5M0SHwh5a2ow1wbY7FC4Ci7SnOpoNkHTgLyapHcbWeUrGpEEsAfInKRmWivqN66GEGDJnI30lLM4eJbeuQyk0g== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:44.6131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 20262333-23a5-4846-e541-08db9eba978c 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5468 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233448200100001 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 access by pci device assign/deassign and = also 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 5796ee1f93..096ef2dd68 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 Mon May 13 19:04:48 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=1692232889; cv=pass; d=zohomail.com; s=zohoarc; b=hmzmTery9yi2Adp+FohdiUWBu30Q5BSeLVbkkXg8aqKzKaonSJwEUbDdkNiQfn0cs8ZonnPBv6S7MZ9Plr1FP+pz7wtYzMKCvSSI8denyuI75DNoL6Ko1iliWDcOCdASIKxoafZV4LFEsKkEvVEPSYaTBTceVHLYcVVifbRGvwE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232889; 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=umzmBwETsxaXneMYshLnsO55s0EVvWX81Jc1LOTJ0Nk=; b=l87RquuqIAsf5AGGvuLPUdcCicztLZNtTJ+3cpSV1ePKJEBlwLSTz3GCC4rnQwJv+9FQ+zeqMcWAC/bKiV/yZBqhhVoXVBeF6RyurRjeFak6Y3Om4XS2hScAervDsTp1tAxOsR9o5OzmKv55xRiPp3ZrMDFy03KoUL10V0mybwE= 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 1692232889359200.41822630823162; Wed, 16 Aug 2023 17:41:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585008.916011 (Exim 4.92) (envelope-from ) id 1qWR4H-00068W-Pa; Thu, 17 Aug 2023 00:40:53 +0000 Received: by outflank-mailman (output) from mailman id 585008.916011; Thu, 17 Aug 2023 00:40:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4H-00067a-Ex; Thu, 17 Aug 2023 00:40:53 +0000 Received: by outflank-mailman (input) for mailman id 585008; Thu, 17 Aug 2023 00:40:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4F-0002YP-RX for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:51 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20618.outbound.protection.outlook.com [2a01:111:f400:7eab::618]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b63fafcf-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:51 +0200 (CEST) Received: from SN4PR0501CA0038.namprd05.prod.outlook.com (2603:10b6:803:41::15) by DM4PR12MB5342.namprd12.prod.outlook.com (2603:10b6:5:39f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.30; Thu, 17 Aug 2023 00:40:45 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::ad) by SN4PR0501CA0038.outlook.office365.com (2603:10b6:803:41::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:45 +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; Wed, 16 Aug 2023 19:40:42 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:39 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:38 -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: b63fafcf-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DbwwDRYMB7jKx1IE8X+OAIPS2u5ztJ8uyQd/qLPWHQPJA5JHkvXzIBAovceYRSCoXURwc0u3RYgW0xPPONLJ/q6cRGY8DWvKN7mPDe+FA96lRgjvR06b3WM9GUIv4T4YhOGPADIbpYM0OB6Hh4Mkbv+DJpMuM4CsiWji/g1Sk+tqOLi1cRVJwh/uuG/wJcsQDcCnRAzIxvsY4m8hN8b/rcS1sg2mzhLaABZMdOy0HPA+dbR8qTwDYg995kkrn/85jTcsu9OKgm8Z1HG5cdZ+/6QlWXSsV1Dn34FpBXUsN3VifojUFszNs3wVV3ebTv7UeCWMGrQvqX1I+/p+HATaZA== 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=umzmBwETsxaXneMYshLnsO55s0EVvWX81Jc1LOTJ0Nk=; b=mijolHuY58UYTL2imLiMQIpVVVuhP9uUoFLDHg1M756Dh8cyyFLuwyzUWK6/VmQwuUNSexOdD5xpoBEKCbxzH4LTRrInTLSR483KQw8QKymcS7OZL2zrgYQNKWVYG6EnjmmN4zvxdDLU7ouZ8HuXmkTryMJL138dzsqOt8JHpWkzuH0bARk/UhTfWZZbT1XJentcwbeC73DkuYZyMawZm0ouE/JxsoGNtuLe2FXUA3ve4iGdfnnwVZxBU010aE9FisWg8c5eYAw8BYpjJAerdla+O4oFiak48bJKvv5gryo4r/8HCl0LUONEBceajWfQcWj7+4FR92SPl0vFxyuUlQ== 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=umzmBwETsxaXneMYshLnsO55s0EVvWX81Jc1LOTJ0Nk=; b=L5uR+qyDIxtjXS0mO64+QEm2td0/Hrvqh4sjZ7qNHFlYQE5u8hXiKCEIT8DXT+llL9yYAxHAIyeorm4OKUsm+NgC0FrTxFlBi6vvK9M35C4VfTg67dK3Wg1G7K/oPGWAXdfGEGo2q6VX0/dCgfN+4eYadOIzi41I4rofZPNK1bw= 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: , , , Julien Grall , Jan Beulich , Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [XEN][PATCH v8 11/19] xen/iommu: Introduce iommu_remove_dt_device() Date: Wed, 16 Aug 2023 17:39:39 -0700 Message-ID: <20230817003947.3849-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|DM4PR12MB5342:EE_ X-MS-Office365-Filtering-Correlation-Id: 017010e9-a2aa-4511-ba25-08db9eba97e2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Hgfa5qlBXpYW4u97Y06Wj3pnQy7ZN3AI9i+ZMBYWTgD3yV3cC6mziKcAkKi9j2UKTesdH9MKnXmvTYPJ7Ddg06+lTy+xSJFetNtH5OnOM7YvtYWi0x8nlYaJ0KLKONyKdufN9O0yMBWfbEYGBAeJgrJEhMiKGgKEQ188ukbBwaTPrNl6k4eJWMnibCxG85yUyu9YRWPl6tZR1U1PnoHZ5z+Ska4dkAYIBN9o/Aq0tytPMa1l/85q4MgvLFHuCx4wh0eP/1xTalcNLaJmY/g1JWu7sdJ99HaPK5lzN9t7SUJ9+o8xuyG5GaLWTDylzEpgQYsoBJLw7srnFg03sobe9CrIlO38IPlBY/Sy4AK6rTVg3H0gzFiAmvVYTJIm4lrE05DivxWVolPPd8RRUc/vsMnycGAa/zteBaBZXKIIYi3J+NUwBSAT/xEL/gDZJYlVrYir4MOpgV2eNym+Ou9bKCO4LJCNaeLnY5JTmZjfapOA+6BF3uXVK+8dQw1ezmwygL8YipnggLhhfc5tE9EoUeZ2zppAJ+lpBxvuFjtE+zoJ5sU7y5mPYYJNv5ITZGQUuqc0UD9HfSX0X5SX7kxTbe+xpIRmPXdP13yjWI8gsYb4sMVhaww47MJbVsTFWee0evVuEQvPJAY5jak77PDmLEm0hJy1aRvu/biJ68MCu7DW4fILR+DVr2RrdYIwOVLejC9za25e5wzjjPQbQBpnMI4eo7nfjf1dijaVm+JQFy5uY78cCdzsXj+Zfcf7h+MZY7kKQpiVFQykxPtmwGwdDg== 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)(396003)(136003)(376002)(39860400002)(186009)(451199024)(82310400011)(1800799009)(40470700004)(36840700001)(46966006)(36756003)(86362001)(40480700001)(40460700003)(83380400001)(8936002)(4326008)(8676002)(5660300002)(2906002)(41300700001)(1076003)(26005)(2616005)(44832011)(426003)(36860700001)(336012)(47076005)(478600001)(316002)(82740400003)(356005)(81166007)(70586007)(54906003)(6916009)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:45.1599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 017010e9-a2aa-4511-ba25-08db9eba97e2 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5342 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232890610100001 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 --- 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 096ef2dd68..4cb32dc0b3 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 Mon May 13 19:04:48 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=1692233443; cv=pass; d=zohomail.com; s=zohoarc; b=Xc/f8JHXk5N5GnHr2MqrpBnvdOf42x+g+tOQeXEFdXIDFMAVgYXI0BZvhPdBqwn2d92I49kGtzrrdEw7NY+GsDehcSOPnvWvkwurAsnfh5DLUheJrm+fwTZ/WTXRWkMPgRzVGYvusLu220p5cULtFR3fQD157wPrW4YLvbHVhK0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233443; 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=0z4VnR/rjV3DabEuQM1jMT4AHTgihliMWcytUKhZcwU=; b=j0F+hkBwtO05Ew6EHqSia3V+RJ/z83zDAq9zdWsEl3Igdn/PQeGfbuMAa+9CAL0zEn7LQQN6d8Ng6vmb62U595JUyBFB0F3uSuXczXWf2AkWhIJruuIPXgi1PCJoSzFrGftwzFa5ikSDDlpaH21KaXpBAwPnQGnGhn3mFDyBhvU= 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 1692233443433715.3044634002476; Wed, 16 Aug 2023 17:50:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585029.916034 (Exim 4.92) (envelope-from ) id 1qWRDM-0001YQ-0X; Thu, 17 Aug 2023 00:50:16 +0000 Received: by outflank-mailman (output) from mailman id 585029.916034; Thu, 17 Aug 2023 00:50: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 1qWRDL-0001Xk-Tz; Thu, 17 Aug 2023 00:50:15 +0000 Received: by outflank-mailman (input) for mailman id 585029; Thu, 17 Aug 2023 00:50:14 +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 1qWR4E-000280-Ve for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:50 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2062a.outbound.protection.outlook.com [2a01:111:f400:7eab::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b46852f0-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:48 +0200 (CEST) Received: from SN4PR0501CA0042.namprd05.prod.outlook.com (2603:10b6:803:41::19) by BL1PR12MB5349.namprd12.prod.outlook.com (2603:10b6:208:31f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:43 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::53) by SN4PR0501CA0042.outlook.office365.com (2603:10b6:803:41::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:42 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:42 +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; Wed, 16 Aug 2023 19:40:41 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 17:40:40 -0700 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:40 -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: b46852f0-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TgTCA2de+NpS+wd3G61FK/f8pxKqqXSgBZ6CgAnI/hpNulyfwG5/aIYIO+KcqU9LPmXqKURJ/LP5d8fjlF1GXlLK07pizA6APGmevJqy5muqm8iSMmf+0Z6nOivcXM46PR8KLvunIc04ztflOAJ5MDdIhR/by6V5onoxvSH1Y8SBspXMnU0ZegLftwTvWqt2Df99z/TZZBfW6/kx6FdsF4KipWBIXjmm459nZpgmu0ePaLoUi0tKtHYCf+/1bOflaSPv0X86bh1bHUrDd8hsTjNZ7DZrnMxxXQmLg2pYpV1Qe2b88D+6Enzbd1WbUcyoVMKlJmUY+qjQwgt0S3G4Eg== 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=0z4VnR/rjV3DabEuQM1jMT4AHTgihliMWcytUKhZcwU=; b=ThjSag0gEqt1ftICsa75BCvJahEAW/ChTH6U7punLvP7FUQoFg2gncclM23ubDd8VoITzeX7iJy06CfQqU7gzcg9HFNi+BIFiQTynj6PTv2N7gEgaUo5KKef267B4JdFjt8BOVOo6vdFoEFSjcp/JUQ0X9CDQYBaGvmA8EVjcRvEi/jTQpoPOHNUKStCvmmuZLKn9GZlk+NFElk7it8FC8W+7y1Vh1FBDbnae9ioqLXKFvmXl5Iwrd85Z8t+ZBnbPNsY1oa9nsgHmg9EiAIc0qbLNJHqrFFzY6DZzTcQ5NT7OPSUC/HjkJuj90T+cxC8KojRwwuitRcIkkfIeAO3XA== 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=0z4VnR/rjV3DabEuQM1jMT4AHTgihliMWcytUKhZcwU=; b=0YSUyW366VbAXgOBqDATVjgrcnEACRqNzdqVv9+L4VfogMs6sBKCBD8SbZSOqUobg2xcRnvsZH4Fl/h/iWIJpgMdrhxBANXqcUQVaQay8gggncBJOlEKuvd+3S5qkC+2zKgwJcYXIbq5Hz4D4SBzBS7glNvKOgpBfLuD1L5vmuE= 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: , , , Julien Grall , Rahul Singh , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v8 12/19] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Wed, 16 Aug 2023 17:39:40 -0700 Message-ID: <20230817003947.3849-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|BL1PR12MB5349:EE_ X-MS-Office365-Filtering-Correlation-Id: 694f989c-78b3-417e-b675-08db9eba967a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ud7G8hdjYNzPMatuEF8jSmymlV8iWjiBEgWTwPzP5KIrTRAepwqloSFl1o8MINTuZKk2nANgfD+YG5xSEru9EaKWnssMHNQPRYJPgRRgiqEaK8fFwHFwu+zpEMo++We3IaVIB1YDpD03RaOU1uyPaN9Bi+wczHEaMazeFOlBOmWUy4WQ5fZ6BYHx20iOKfLeoijus2YkD89ors9zahxuTmvtSdHNc9LlXaQ8zKaNq5C7DYfL+HEYJwoTXX3ooSGU0o2FptSK0ZxH7kRHFr/KrKt2073lsfjQuu820/YmeO1HS7i+HfmR7NZBdh5YSlH91GVxzbpSujzGX2Dd6ZUR9A5oXm2V3OkdI6XpYllwn2NH6iI+b/74jERc4Iluehixe20ztXnMEDPLnAzcGYmHWDLdkol2GxA5IuwijgSIhu8kGVsot7u1yWodXmAtxaTfeRIlluTzxkXyxfvXjz/sowfgpURI+2xGNGCRJOSaZRt5gWywSyFPa88VEkYLRY7rN5gixop85FMXUHU4uBev5B+eGOFBQMntuxtScyZ9IkbVEnbmc/m0J1gRpmwzY6r/d0n3Ht0/Zf92K0Yvww9S2n0m3Pw3dpEdUjIk0R6YdARfEY6DmtItmzhIKBI9xn4wE7UytPILpMbaJlmr+Xv145o8sHvIy6MLxVLS7BShjSwrwxdvmPqCJni9QxrgbcMOV0048b2EV+e67V+FCPsiROFgMchs4b3DyJusj+4aN4ksH+1TAlCgJ0Tzrzx5ENAPKj7E25R3TYDQXor2DS25pQ== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:42.8162 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 694f989c-78b3-417e-b675-08db9eba967a 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5349 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233445145100001 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 Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel --- Changes from v7: Added comments on arm_smmu_dt_remove_device_generic(). --- --- xen/drivers/passthrough/arm/smmu.c | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index c37fa9af13..e1e8e4528d 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -815,6 +816,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 +866,34 @@ 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; + } + + if (iommu_dt_device_is_assigned_locked(dev_to_dt(dev))) + return -EBUSY; + + ret =3D remove_smmu_master(smmu, master); + if (ret) + return ret; + + 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 +917,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 +2921,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 Mon May 13 19:04:48 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=1692233451; cv=pass; d=zohomail.com; s=zohoarc; b=NchyoXU1L/u8Bk5n81cbxJdMzXW88yC0+3F2beKzGy+x2DyuFM+kkaB1nYVtAROmj/ovqQE/G4DcOahmkEd3qGVPYmT9m3T3j3pmnuAjFOM4MEStRFborAkLP1aJJPGnJAKXom5QwGSX+SgYqwl/jRqwxPQoneG7Epbm+BIsoFM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233451; 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=zbvEFTy0SN7hLXU1211NeYzv59Rers6Gren3/qiNJHg=; b=CAQ8ZyRsUitShrLKbHNyJ+q6UkLhzbPZWLwWe51rAS76KpBjkTvH9iyLf5jvyEjjy11feWM8doleJ/W2l+XO6kC/+xAx0qiUEZo7JL6jZhG088NFJeITIMr27MhHwbMC5b7nDXI5Jez9tpApUYGZP43ztXlMgvjJoRKeWD2Q5m4= 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 1692233451002807.1958068510786; Wed, 16 Aug 2023 17:50:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585042.916055 (Exim 4.92) (envelope-from ) id 1qWRDa-0002R0-NN; Thu, 17 Aug 2023 00:50:30 +0000 Received: by outflank-mailman (output) from mailman id 585042.916055; Thu, 17 Aug 2023 00:50:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDa-0002Qq-KC; Thu, 17 Aug 2023 00:50:30 +0000 Received: by outflank-mailman (input) for mailman id 585042; Thu, 17 Aug 2023 00:50:29 +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 1qWR4G-000280-6h for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:52 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2060f.outbound.protection.outlook.com [2a01:111:f400:7eab::60f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b6134fda-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:50 +0200 (CEST) Received: from SN4PR0501CA0041.namprd05.prod.outlook.com (2603:10b6:803:41::18) by CYYPR12MB8964.namprd12.prod.outlook.com (2603:10b6:930:bc::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.30; Thu, 17 Aug 2023 00:40:45 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::9f) by SN4PR0501CA0041.outlook.office365.com (2603:10b6:803:41::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:45 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:45 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:42 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:41 -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: b6134fda-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iOOUjvCMsKxWmuQ+eP0zb4yRO8q30D0X2fubeaLSsvNHDe8Qls2gd11lpbI6WioB1NVDDn59Yb5/HYBgfp65i04hEMZX0MZwoNzEp+hwnvD0iqw5ambYYAb1GD2pgmcJC3+yi0uHnB1ZRzBTC0nrnI69Une+hH3KvYA/x/bGIoOF00ZLuY1e/e9TgT9nQHqwnozIbqivy+MjCATN0fy9ZHONVEk+A6P9w/wN2jb4tFZJpJTEH6BGmmvOZvHgHph22QVz2SWWHHHDXDh48yJN7sPdI0leOVgMJSN9Yx2wj7bKlM69AlsBwXVklJWansRiy+zA5QyBCpDL8dS6Y1FnqQ== 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=zbvEFTy0SN7hLXU1211NeYzv59Rers6Gren3/qiNJHg=; b=kr0/WPGXrWX+5troHsezseknnebqb++eWnynezqYXcuHy45cyEivUfZ6PVV97dTZkoGureKLf1PXjUnFUebfwsNDgyc6d5UTAC/5dVRsoO29n7K478AGAt1cD+fjo+fhQxF3XY9zHS45fTDD06j4FHRKeJWw0X9IXimzowGVGkt4bgH7fbA0o+HWdtdkPPSLmB88zkWM9UjbrH1mlyFeELrt7+z9IUadc5MsFNeSEznFG8b+1x94Kx/YqAOooQenOkK2DESNpw5mSPUXXwAN/f0/Wd9BylyI5HTziaSPJ8/tLJ24/73usm/NrjVSu3HGI1iRud/SDMiteLaU9vgSPA== 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=zbvEFTy0SN7hLXU1211NeYzv59Rers6Gren3/qiNJHg=; b=C5Oj9mlb6W80Ic7nE6j7i0Ssp9XF++qMzoe3nqp8v395KXIPnv3GukmL1OgjXuSVxniHBsFVGm28qiz2/6rBZ2ZHMQ6VMcKK+j2L6Et0/0dGubzbgl38QH7bsQwQS8wktE4VFX8Mg7KOW38RAkWa0ZJI6n1YS4mgmd7/w8Nj5m0= 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: , , , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v8 13/19] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Wed, 16 Aug 2023 17:39:41 -0700 Message-ID: <20230817003947.3849-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|CYYPR12MB8964:EE_ X-MS-Office365-Filtering-Correlation-Id: 62a1ac86-896c-4af2-67ec-08db9eba9831 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RojMygBGOAwZgBK/+KBo6vKmdWBnWv/KUrzXLLdO05lQCe3Cr8wsa0rVJAHg3Ja28gcJCYpUK7xKcGqlNv9Op2xwofiVJrxUo2Yl3+LsYmio1EExo2vW23EATJ41GbxCQQ67xq4yubQhmMa7ieb/hGHj2R5eTVWkAM5SM3D4gUtvp+t/PMYlU1PtgK6zjgQTdVec2kZH2UsKv9syL421zjYEBvdLx/x4YlLEC4U71zsvOMeEQPcipU5LC8ENnm8YTP5gmB/pk1JrBUbf3I+q57nUlu3oo0GkgjbCddU/LKZ7YWxUAL6493Wd9aIJSAkMhmnE7AyXqCtmDUa+fgUJfDyPH64k73nW+rCkGvcY5Xocm1DolPbHzfsaq37Txf42SApHTJfeRiRls/Rp1fpSa7tsJ19LlefPQP6oSzc5lzMYMLbtSfbnJISsi88KaSCFyqewmNe9iOVInwDwF/HjfcR6qKJk/X/9WJoYk4HIntklRbQlh6PVgODkkgyiHpOT+VrKAjkV7rpUtJcVshYJlZK5pOp6aozNoOlHdiFO+N9kavVOFJnhYJtpt2FXKntIPfrA4MJ6o2wLaQKWSCFAlVJobFNqKH1HA9uAshdzS5YhYwl0Xzqa+lHanEG2k4RJ3MZwVUBlT6/Gw2/mqi8X0rlaLPMuiOkTq+Vm2tmah3/XdEU2qzEYFznhHL0uSPiaDgVIKW7OufXPC3wFCmLu6bpVbRdHVjwEaD8awKbZx25bRTzB3MdYsbgQGIZ1BTKUR0Re0iiBusSWyCCL3Z9xcQ== 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)(396003)(136003)(376002)(39860400002)(186009)(451199024)(82310400011)(1800799009)(40470700004)(36840700001)(46966006)(36756003)(86362001)(40480700001)(40460700003)(83380400001)(8936002)(4326008)(8676002)(5660300002)(2906002)(41300700001)(1076003)(26005)(2616005)(44832011)(426003)(36860700001)(336012)(47076005)(478600001)(316002)(82740400003)(356005)(81166007)(70586007)(54906003)(6916009)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:45.6912 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62a1ac86-896c-4af2-67ec-08db9eba9831 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8964 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233451951100001 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 --- 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 Mon May 13 19:04:48 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=1692232873; cv=pass; d=zohomail.com; s=zohoarc; b=eK3KGQfyjxOUniCHvulN73vxjjFei0SksKP1kL7XXpAWfHinIEl5rfOOwct4GYZCdmHwhlIGrfOlTFzGlb67uBplotOBmkP26m/rVr6ra3B2tlJxLwZCI7gl4oluA4a7tQBW0GUmFPQE2yhFB9ddMVzFQV6eczEMH2SYRvuf1C8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692232873; 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=nCyL0+8MSIKb4AwqqY4xSHJp57PvTVSjc1PRQ5LvHww=; b=U+Rur/aIek9RkU2RGOS1YfixqHOCaFwsZclz9Klr0PLSseH69s1i8TcHag3Vyfq9KsLbZS84KXt8BuTrhaEZyMFZMHbBIkgfkblNZ/AtMyszyhzvMITDaWNl6ZuK3bSI54GvLSjP7dEe20DP9jaCwjv0OO7atwn98vfp7ZrK9ok= 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 1692232873246889.580723146901; Wed, 16 Aug 2023 17:41:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585007.916005 (Exim 4.92) (envelope-from ) id 1qWR4H-00063f-7M; Thu, 17 Aug 2023 00:40:53 +0000 Received: by outflank-mailman (output) from mailman id 585007.916005; Thu, 17 Aug 2023 00:40:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4H-00063S-2R; Thu, 17 Aug 2023 00:40:53 +0000 Received: by outflank-mailman (input) for mailman id 585007; Thu, 17 Aug 2023 00:40:51 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4F-0002YP-Et for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:51 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20600.outbound.protection.outlook.com [2a01:111:f400:7eab::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b5e3c048-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:50 +0200 (CEST) Received: from SN4PR0501CA0042.namprd05.prod.outlook.com (2603:10b6:803:41::19) by BL1PR12MB5048.namprd12.prod.outlook.com (2603:10b6:208:30a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:46 +0000 Received: from SA2PEPF000015CB.namprd03.prod.outlook.com (2603:10b6:803:41:cafe::13) by SN4PR0501CA0042.outlook.office365.com (2603:10b6:803:41::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:46 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SA2PEPF000015CB.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.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:46 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:43 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:43 -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: b5e3c048-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DF9z7OL7L1u6+rdVuEJscwipiXCcUltnvETwhAYU0AcP/CdsL4+j8W0FlRQtFvkLWlB7nJH5Q7eYmEnVVCAiijkO3I5rBe+lUByFRcsCuqJ8M662FRy+3xHGjw++MEe/f129bDC6El74oAG0vVfqXDFjHM9/LVM1u7eglI2kbuZdJIYGXIgf6e0Q3ppk6eIAgX0ltAeHtvHs7fuSLgqwcig3VXJNpFPGlH0/1eLbdiovtl4qBc5t4xrAoLs2lkyULkWYIMqxMC7zN19e4Yd4omohs8gh+WGxoUjQfuwwuxOKHiw2QyQMEad7FHQ1fxMfseOpuza47pcG9QydapPKGQ== 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=nCyL0+8MSIKb4AwqqY4xSHJp57PvTVSjc1PRQ5LvHww=; b=JzsWHgrC5bH+bojZpjhTxGnY4suYZxCp2dCU64CiUX8rMRl4wAqPXLiT9yjeGnEO15uWSaN8wIeE0Y5Vj4oWYyrVBV9CIK2VunEXtUBWwvBxkwu4/JQeKUzC1bfFAUKRFRy+sq0mRBOhLumms08aueRtKA3pdmvqdQb75xkRhp39CAzfhaHD+2ldxuhgAeZL0tHq+cVRHYoMmAj7mbgyTvKT2hDfqo4BketH8R0kTwoZdgO96DO8P6w8KHOCNWfhYHrv13iVQ/3PZA07APuSrRzQaEP5IDZGp/wRI6fckkgwbGFVsu/erFA8oAsNIyQ0GkG7KdSKr/abUiySH4a4FA== 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=nCyL0+8MSIKb4AwqqY4xSHJp57PvTVSjc1PRQ5LvHww=; b=iHmFigOKOR9df1lNP7F/SInjWf7HTgV8g7uFAVzTGHvdkFttxE5nGbbg/kYKgsX0y9ltgfkwDiQ43LCC3mm2XixItoYYrSGsZA8dv479Fjb/3bswT+MhieiDhwxM31c2r2HaKWoiKCELNr16ySGa4Ub/rL8UVcfDPWGO/WMofBU= 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: , , , Julien Grall Subject: [XEN][PATCH v8 14/19] common/device_tree: Add rwlock for dt_host Date: Wed, 16 Aug 2023 17:39:42 -0700 Message-ID: <20230817003947.3849-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CB:EE_|BL1PR12MB5048:EE_ X-MS-Office365-Filtering-Correlation-Id: 18031cb1-2604-4d4b-c763-08db9eba9871 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fjPNH5ONl/f6GPp6tFsxWpVEoL/a7ajQOnYN3o/k3ZoqOSAiHrVRFwRjT3bJ9O8/9DmFN9wAr4Z6StCbmiuIvW2OvU8axqKZDchwzzbM3NZr8qJtxqPcvvO99UlTUPovK5DMrqU+K1OPT/9zRbiXNGki2/9yR838K57yPgfThVHueMwlouTKDgIzTNvU0lugn3Tt20XkgFZgzB6tX76AvULgjYa07C6qAQXHieivN2G20IrwHB04NMMY6qwi3DkgmKZgsjbLOnI8EvgbggGxe989K+hGaj+2TcLjQmgwoEaqvZwi5atEEFoB5Yc/dGQG2vN2P/lzP8SD4Ab3vK7PO7t5pYB/uEQI3jGmYnoYeiU20D7F0wbtRGDqNK2z55LryGghwditQuToj1n7YKoKrwMaXLKY0PAN/+oOylFWNtNv99DXbSWFb8juXL8Nu0fsFFq3IWHpmzXoXrgj/bnPVxkCrcKFZIM3s50Vo1EmyaXtIKp8nGW5Uejjjor503U36THp28dNs3MjymcF+MB8UR/TKRIpIps/AQ3ETth5nkS7bdYqJTtsjo43gf6yD87YJYMTkYa2BpTwFMzH6fCvqm5oPHthzX9/y1WMTQPQL3nG504Rv8V5MzR06cMFg0xG6YHUvDbMZdHNqfiVGydJXl0ErJ8fHvGabBHtKw12eKWnzCQI8tmznk8DDP+hxEIe75XJizRABbq1M9ifKUP7JDEthUPuwDlFqnsSkxe7m8Wo24yhGNAF5x9dPkUMBc85RSiAxVxeAm6f9L+bBOcppQ== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:46.1131 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18031cb1-2604-4d4b-c763-08db9eba9871 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: SA2PEPF000015CB.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5048 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692232874768100001 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, adding rwlock for browsing the dt_host during runtime. dt_host writer will be added in the follow-up patch titled "xen/arm: Implement dev= ice tree node addition functionalities." Reason behind adding rwlock instead of spinlock: For now, dynamic programming is the sole modifier of dt_host in Xen dur= ing 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 pr= otect others from browsing the dt_host while dynamic programming is modif= ying it. rwlock is better suitable for this task as spinlock won't be ab= le to differentiate between read and write access. Signed-off-by: Vikram Garhwal --- Changes from v7: Keep one lock for dt_host instead of lock for each node under dt_host. --- --- xen/common/device_tree.c | 5 +++++ xen/drivers/passthrough/device_tree.c | 15 +++++++++++++++ xen/include/xen/device_tree.h | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 0f10037745..6b934fe036 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; +rwlock_t dt_host_lock; =20 /** * struct dt_alias_prop - Alias property in 'aliases' node @@ -2137,7 +2138,11 @@ int unflatten_device_tree(const void *fdt, struct dt= _device_node **mynodes) =20 dt_dprintk(" <- unflatten_device_tree()\n"); =20 + /* Init r/w lock for host device tree. */ + rwlock_init(&dt_host_lock); + return 0; + } =20 static void dt_alias_add(struct dt_alias_prop *ap, diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthroug= h/device_tree.c index 4cb32dc0b3..31815d2b60 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -114,6 +114,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 +123,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 @@ -251,6 +257,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: @@ -304,7 +312,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 ) + { + read_unlock(&dt_host_lock); return -EINVAL; + } =20 ret =3D iommu_add_dt_device(dev); if ( ret < 0 ) @@ -342,7 +353,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, stru= ct domain *d, break; =20 if ( d =3D=3D dom_io ) + { + read_unlock(&dt_host_lock); return -EINVAL; + } =20 ret =3D iommu_deassign_dt_device(d, dev); =20 @@ -357,5 +371,6 @@ 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 e507658b23..8191f30197 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 @@ -216,6 +217,11 @@ 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. + */ +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 Mon May 13 19:04:48 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=1692233481; cv=pass; d=zohomail.com; s=zohoarc; b=BY5tIjaAoPizrT9OqvfiuLH3aAleRogGGubhDDK1/wv7wY/oRbExG/qXTeB5tpuWPa/xhCm6MjgyrGhaTKIMttpn+P478tgm220Z23zIIHb7F/bgEWghI3yllNdgt8G4osLC14MVDa2XUQK+hRpQq3nO52n3BdKXfuDQgaNMRto= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233481; 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=oazS5Pakz+arpr5BvXrP3KLf+0uUtUUB2wXc4d5nSBM=; b=fFtZwc1FBAgqw9oDrcnFK5BAzMTaVOZKZZ9HgmxdiLO1281vCfBDyoPATjNPm9k2dVVzIfYAxITqgZvpEx13MnuQq2ykTst+idTHL+G09JWn8SUBd+KW2Q4X+JF42TAkzhX0PZG8We2Ked8ZhPQdx8fXCdzBhUh01mrXj5a3/MI= 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 1692233481802800.6678418223447; Wed, 16 Aug 2023 17:51:21 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585073.916105 (Exim 4.92) (envelope-from ) id 1qWRDz-0005HF-Nz; Thu, 17 Aug 2023 00:50:55 +0000 Received: by outflank-mailman (output) from mailman id 585073.916105; Thu, 17 Aug 2023 00:50:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDz-0005H6-Kg; Thu, 17 Aug 2023 00:50:55 +0000 Received: by outflank-mailman (input) for mailman id 585073; Thu, 17 Aug 2023 00:50:55 +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 1qWR4I-0002YP-FG for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:54 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062d.outbound.protection.outlook.com [2a01:111:f400:7eaa::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b73829e8-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:52 +0200 (CEST) Received: from PH0PR07CA0069.namprd07.prod.outlook.com (2603:10b6:510:f::14) by DS0PR12MB7874.namprd12.prod.outlook.com (2603:10b6:8:141::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:47 +0000 Received: from SA2PEPF000015CD.namprd03.prod.outlook.com (2603:10b6:510:f:cafe::3e) by PH0PR07CA0069.outlook.office365.com (2603:10b6:510:f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.33 via Frontend Transport; Thu, 17 Aug 2023 00:40:47 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF000015CD.mail.protection.outlook.com (10.167.241.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.15 via Frontend Transport; Thu, 17 Aug 2023 00:40:46 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:46 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:45 -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: b73829e8-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U7I85eWVrLalqd9AK2nwo3NPSi1ZA+d3gSJLayhsc5t+4r2MB1APzKmoULrOvsxItumOBVOmpOwtSGzib8uZKW6doshYaPPH6WGZnV8W43ZMsG//x4YjHU1Vu3IHosdJjTSVBD31yjio70g+ll8MK4gKqkmDaxQA2t/I6D67YlbOeVFGKMnHEGr3RYtCfR1Bw2qMcvDTybWqszqg1nSHW1aYBq8UqIX9rbnaFByqcjmFIHjYwf2/4ZUFIwXDY27UBLOJPnlPymhQPIEX2YtvNkYZkawWe3KGuUIs9vfeuG0GDlSNwcvFmYNONOYQlIUZrGC9C1mvpZU6SkHNDa35ZQ== 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=oazS5Pakz+arpr5BvXrP3KLf+0uUtUUB2wXc4d5nSBM=; b=nRJ+mjpIyKUeCc7nPCrs/9FHi2X/FqjYy5S/DVXepSaOZUMVqHbseluB5MY00JVs4K2nNZIpohYeqTQCFiLFqlpM7VpV+pf160xdg9d9oqzA7nwUfwpXsyhbDZqVVoGZ92RQQjU9VZSaDFkuQkn0Av3YfXCRX0Him2wypnVnnH7FSbCebyQ5iJsGDofzGfpwOUm5EtME0uMue+yghXmTXVYfmazjGlUQ2JN1q8LhcJ1D5whE7izgskyO6VRnjEF7qhMcLnKK7hABpQE5smS9b6eTEW6Z4Tl14fWrJEeIg4XWoA1VwYZMGoewCsZQmj2CESlISplyZloJuzUwYJWgkA== 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=oazS5Pakz+arpr5BvXrP3KLf+0uUtUUB2wXc4d5nSBM=; b=MUhD65+GDOyvaQt0bM3+myPetKM24u0ON/W8Flww5/n9/q2oCpOUO4gInyEfXeYwvV8HI4wb+4q359Zq8gNqwaI8wlZH04GM7Jlvz9nsiWERrYZDCuuQXn05yHRhOa49k6+8omtjgH+3v+kYHL5rPNb3r0SXvQdQPhh7XDFA1nQ= 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 , "Julien Grall" , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v8 15/19] xen/arm: Implement device tree node removal functionalities Date: Wed, 16 Aug 2023 17:39:43 -0700 Message-ID: <20230817003947.3849-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015CD:EE_|DS0PR12MB7874:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c16b509-4682-4b20-4caa-08db9eba98c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TcFuFxZonsSeQI5slbJgbfbrW1gr6tdw8WYtCsiTnqbu7Dab1arbxCVQvucane7uKXzVHhjUOwQy5gTUqHxT6u63+98eckkhaaSGoeG89hO0Qd+PgBW26snVr6Ocu5Xqkaapc4OtOAjAP2CWSFcSXS+xgIH6GBd0MO5SeqxhwhnJk26of14ozYnF6qk8ibY3E0Hj9LVFBdWPIRtnEpEyJ66gqQmxZ68ZbaIS6xRkUEyWgEFXm5lSZvTFcSV8w6LDeJ9CJ50BmcmH6ON39q9aaU0RRtBbVceeOPCRnlJo9FtcdO6hCP1gcoKH6Ch8VgjykBbNBdlOZ0I7G6HC+9B2HNCewHzSLlp9I99p3rOyE32eTnq00kOUzF6CP0/4sCyaqp9u/Nq3ewYKIHu1v3x+JZdRSs/cUtUn55KgP8oTNWnMoQaxhdYroh5YgjL1+/HAw5bzyDedPehOr/+fW38iWFivkkvQBorcQXv/6DyZliZqfx9URRkNhkkoyKfEcuifyElzaRGPXvNsKCvaurWXv9TfM4D5vValczvPRegeF435CtyRp0cvMLGg+KNHAZEjgf4eLfazoAhzrdvhr3huGariNqIOc5KANcohp9I/JwH0NyZAYAh7IUlTr4m6z2jcRSBu3f4q6Gg9vsHLU4kSh1NzSZjS5wrp4V6lkAmRsiUdICrG5Lf6hJmGrAxqCoZZk1x5IrSFFGyRywiZjxtieF05pajg9tJoWvszkyYihOTxi8RgcZu1a9HhIqpdzfbs0/Sbh+raL/82mpKpVoTouTH+b3DM+0zLl0ID7UYDvN/dgI/GvaLRZ+Tcx8R5e1Lp X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(376002)(39860400002)(136003)(396003)(186009)(1800799009)(451199024)(82310400011)(36840700001)(40470700004)(46966006)(2616005)(426003)(336012)(83380400001)(6916009)(54906003)(40480700001)(5660300002)(70206006)(70586007)(316002)(26005)(47076005)(36756003)(2906002)(44832011)(1076003)(30864003)(36860700001)(478600001)(82740400003)(81166007)(40460700003)(356005)(86362001)(4326008)(8676002)(8936002)(41300700001)(333604002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:46.6408 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c16b509-4682-4b20-4caa-08db9eba98c2 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: SA2PEPF000015CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7874 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233482969100001 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 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 | 395 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 24 +++ xen/include/xen/dt-overlay.h | 58 +++++ 6 files changed, 494 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..ac104964b1 --- /dev/null +++ b/xen/common/dt-overlay.c @@ -0,0 +1,395 @@ +/* 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 remove_resources(struct dt_device_node *device_node) +{ + int rc =3D 0; + struct domain *d =3D hardware_domain; + domid_t domid; + unsigned int naddr, len; + unsigned int i, nirq; + + 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 -EINVAL; + } + + dt_dprintk("Removing node: %s\n", device_node->full_name); + + nirq =3D dt_number_of_irq(device_node); + + /* Remove IRQ permission */ + for ( i =3D 0; i < nirq; i++ ) + { + rc =3D platform_get_irq(device_node, i); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to get IRQ num for device node %s\n", + device_node->full_name); + return -EINVAL; + } + + /* + * TODO: We don't handle shared IRQs for now. So, it is assumed th= at + * the IRQs was not shared with another devices. + * TODO: Undo the IRQ routing. + */ + rc =3D irq_deny_access(d, rc); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %u for %s\n= ", + i, device_node->full_name); + return rc; + } + } + + /* Check if iommu property exists. */ + if ( dt_get_property(device_node, "iommus", &len) ) + { + rc =3D iommu_remove_dt_device(device_node); + if ( rc ) + return rc; + } + + naddr =3D dt_number_of_address(device_node); + + /* + * Remove mmio access. + * TODO: Support for remove/add the mapping in P2M. + */ + for ( i =3D 0; i < naddr; i++ ) + { + uint64_t addr, size; + + rc =3D dt_device_get_address(device_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(device_node)); + return rc; + } + + rc =3D iomem_deny_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + size - 1))); + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); + return rc; + } + + } + + return rc; +} + +/* Removes all descendants of the given node. */ +static int remove_all_descendant_nodes(const struct dt_device_node *device= _node) +{ + int rc =3D 0; + 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 remove_all_descendant_nodes(child_node); + if ( rc ) + return rc; + } + + rc =3D remove_resources(child_node); + if ( rc ) + return rc; + } + + return rc; +} + +/* Remove nodes from dt_host. */ +static int remove_nodes(const struct overlay_track *tracker) +{ + int rc =3D 0; + struct dt_device_node *overlay_node; + unsigned int j; + + 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; + } + + rc =3D remove_all_descendant_nodes(overlay_node); + if ( rc ) + return rc; + + /* All children nodes are unmapped. Now remove the node itself. */ + rc =3D remove_resources(overlay_node); + if ( rc ) + return rc; + + 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); + } + + 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); + + 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..9cf36d7db0 --- /dev/null +++ b/xen/include/xen/dt-overlay.h @@ -0,0 +1,58 @@ + /* 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 + +/* + * 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. + */ +struct overlay_track { + struct list_head entry; + struct dt_device_node *dt_host_new; + void *fdt; + void *overlay_fdt; + unsigned long *nodes_address; + unsigned int num_nodes; +}; + +struct xen_sysctl_dt_overlay; + +#ifdef CONFIG_OVERLAY_DTB +long dt_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 Mon May 13 19:04:48 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=1692233450; cv=pass; d=zohomail.com; s=zohoarc; b=S9KfyI6SuG8JZ1hNZrOumnCxufYzdBRG64CziFt5p7vPojiZNzpbnWSvBg2aKSbFrtQfVoy2ci5nY9xXPcfgXoTV/EyjlgnsxmxGeN9ZuQE+O9Mx92frumUh+cEVJy//8BIkb1f6TaV8smS8GrqUXW21Oj+LVelFHvEWQf6CIm4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233450; 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=JPpQyIsbQQm551WyZIbVYkVkl2lQHIpUSyitSnytScg=; b=NPel/Ig46tNAROiVupj6nmkiZ13CGyIYFSSsPMmE6LIN+QvGMVTwCtVeflXYa0vfoqn2mUHDmYdCQb9bixA33x/QD87z4VZAV52lsmItQ5hH9d87Z5g9xgE7F8IovD2ebDnIQDDXDJ/2oOTv5i7IBYtuuUK7Kl3IWDeZm3ouPUY= 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 1692233450890787.9972463510773; Wed, 16 Aug 2023 17:50:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585028.916024 (Exim 4.92) (envelope-from ) id 1qWRDJ-0001HX-Pz; Thu, 17 Aug 2023 00:50:13 +0000 Received: by outflank-mailman (output) from mailman id 585028.916024; Thu, 17 Aug 2023 00:50:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDJ-0001HQ-NB; Thu, 17 Aug 2023 00:50:13 +0000 Received: by outflank-mailman (input) for mailman id 585028; Thu, 17 Aug 2023 00:50:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4J-0002YP-Ot for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:55 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20601.outbound.protection.outlook.com [2a01:111:f400:7e8d::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b86a9530-3c96-11ee-8779-cb3800f73035; Thu, 17 Aug 2023 02:40:54 +0200 (CEST) Received: from CY5PR22CA0102.namprd22.prod.outlook.com (2603:10b6:930:65::29) by DS7PR12MB8419.namprd12.prod.outlook.com (2603:10b6:8:e9::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Thu, 17 Aug 2023 00:40:48 +0000 Received: from CY4PEPF0000E9D9.namprd05.prod.outlook.com (2603:10b6:930:65:cafe::56) by CY5PR22CA0102.outlook.office365.com (2603:10b6:930:65::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.17 via Frontend Transport; Thu, 17 Aug 2023 00:40:48 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000E9D9.mail.protection.outlook.com (10.167.241.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:48 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:47 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40: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: b86a9530-3c96-11ee-8779-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NuAfk2uwb1/J5a9cEN4i4gaa/wDjzr1vql7fuP/3L2K6waJU6N7DMNGSiwIYwDfVgVRBOoVjg1K8FqKweCKE+qUJyPMpwyHCM8hc3q88sHgirFVgQM9orSSTlXQ8c3Rm8dnzbIFRlgxEJhcwWT7JTybM+wAqZxmj2K5KXB2Mxowp44WGx/Nw5FhEQjbIb9R8EF+efjE5KQ0qr4SV26fn/LEAd9Q3Ip+OP32B+lyHmN/Cal8IvgFctA0fCo0N9kNXE/WTtZdjnRp7SeS/qBcuXN0jDPCWSS60m0R5JlFJifbZctkrc07Z0p1Sw6sEbqjQq8gc8N3ca6tL4t+IQ0Bruw== 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=JPpQyIsbQQm551WyZIbVYkVkl2lQHIpUSyitSnytScg=; b=XOUc7/3tTnAHG/2abXyVmO+3ml9eEf0eT7nkextsL4WU6L5YcWYRX+5m9AFJsgvoWCgowmxIsFPtpO4Av4B10ih7tydi2S4Xoq72coAYA4auU6bdYomnum0v/vgdiPG0D/L7umgk3+e8vUT6Xsbxwz3mXVUjbHWpd6S/XZJEfyQFiLEXTzR7fW6fEqaViUz9B0DXisi9xNJtXjL+7KzMZvEx8UlPtFQlyaaL2A/0OQMIilmuPvWNn750RX2+skTPArzn9ZYKzg+QeWVt2LR03rpojhBxynCs6mTgBaYiXFjGohhRAvmreUIFfvtSKjEkKtG6EDPtKbkE9Mg3D/Ak6Q== 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=JPpQyIsbQQm551WyZIbVYkVkl2lQHIpUSyitSnytScg=; b=a0i42WX65OflptOfbYBNZq4Qk5iztZBDZbFQii/jEpCE5F4V16L/s7pIG95p896Tq1MgajWYUyozLMKQyGN77KxtdXSA7De/6/FJbn2Letsl5cBYUJNBj7UAHTLhY/p0L6xk8f2AkRNO7Dse+3okCfEI212XVFNdbtRgSKrx31Y= 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: , , , Julien Grall Subject: [XEN][PATCH v8 16/19] xen/arm: Implement device tree node addition functionalities Date: Wed, 16 Aug 2023 17:39:44 -0700 Message-ID: <20230817003947.3849-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D9:EE_|DS7PR12MB8419:EE_ X-MS-Office365-Filtering-Correlation-Id: 76faa5e1-0f98-46c6-37e9-08db9eba99de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0lYaIoGNK/ZaS6QQ83mMWBv6UpXeo7uEnIgik6P119UyHUjM0HWJqIg0tmGow70H5tnFZJvHPwunnO6OYxT+aZZE/q4m8Erqp0xedwWPTndAl3asO5zjlFFwlKXKPHZNfJdlQMXcl1snsdF7SRyb4JCa2YB6AYOaP7ThlFtJO+dbPFxW+6+SvmlRsKvCqoKwmbHagKojgGNjaIthiidyfI4D0ma+y+V7fITAHzH8cdIRh29JLzroiWTPhkrk2cNgOjp4vaSvJDQhnHc9/8r90s9k4pQ/VNgFtEorw837VoV2frEHulYmDsLx0gy+jmpa4U52IQbWDVfQwA+nI7rmj04mM0YPKB0flpzroUjcB79XLgqi/IaSCgfRCyif4oV7kzjiMnki6ryz28/kcQ3OMKo9WYzV4I1hlJFFr31/oAf4nsLLwS3DweF5qtJApxCIC706s7YId1R086/GN4lB63dkXYTPBe/PQYiWRnWzYc6gwn8js3vv+uwbKvMT1BnKUR6dOkzhUHWh34VBq67+fYB8rUy30PGd5NTA4c33GHRQ/0ax9riHviwPsWKBWRGj3QoWJ8EET+9ec5wILxmg1PdZCpPySE7Quj6IK56SHNNZD6NIMQUH8Itw+qUavl0qYpxVUnor4gDupVjnEF71uvQTWix2/fig1Cr6o+NCWPWKUcwUqOciS/aBFLQ0AMof6grJcdUR4QqKGClFoXyKjOS+ARCwwVxQkiSHNy5WIhK0K82mx/lnJ9rn7Ds2469my5NR/7sgFb0YuXvknKG22Q== 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(66899024)(26005)(30864003)(2906002)(40460700003)(83380400001)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:48.4233 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76faa5e1-0f98-46c6-37e9-08db9eba99de 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: CY4PEPF0000E9D9.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8419 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233453049100003 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 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 | 559 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 559 insertions(+) diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index ac104964b1..480ccd5a23 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) { @@ -124,6 +215,102 @@ static int check_overlay_fdt(const void *overlay_fdt,= uint32_t overlay_fdt_size) return 0; } =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; +} + static int remove_resources(struct dt_device_node *device_node) { int rc =3D 0; @@ -348,6 +535,376 @@ static long handle_remove_overlay_nodes(const void *o= verlay_fdt, return rc; } =20 +/* + * Handles IRQ and IOMMU mapping for the overlay_node and all descendants = of the + * overlay_node. + */ +static int add_resources(struct dt_device_node *overlay_node) +{ + int rc; + unsigned int naddr, i, len; + struct dt_device_node *np; + + /* + * First let's handle the interrupts. + * For now, need_mapping is set to false which means it will only perm= it IRQ + * access to hardware_domain using irq_permit_access() but will never = route + * as route_irq_to_guest() will not be called with false flag. + */ + rc =3D handle_device_interrupts(hardware_domain, overlay_node, false); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to retrieve interrupts configuration\n"); + return rc; + } + + /* Check if iommu property exists. */ + if ( dt_get_property(overlay_node, "iommus", &len) ) + { + /* Add device to IOMMUs. */ + rc =3D iommu_add_dt_device(overlay_node); + if ( rc < 0 ) + { + printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(overlay_node)); + return rc; + } + } + + /* Set permissions. */ + naddr =3D dt_number_of_address(overlay_node); + + dt_dprintk("%s naddr =3D %u\n", dt_node_full_name(overlay_node), naddr= ); + + /* Give permission to map MMIOs */ + for ( i =3D 0; i < naddr; i++ ) + { + uint64_t addr, size; + + /* + * For now, we skip_mapping which means it will only permit iomem = access + * to hardware_domain using iomem_permit_access() but will never m= ap as + * map_range_p2mt() will not be called. + */ + struct map_range_data mr_data =3D { .d =3D hardware_domain, + .p2mt =3D p2m_mmio_direct_c, + .skip_mapping =3D true + }; + + rc =3D dt_device_get_address(overlay_node, i, &addr, &size); + if ( rc ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(overlay_node)); + return rc; + } + + rc =3D map_range_to_domain(overlay_node, addr, size, &mr_data); + if ( rc ) + return rc; + } + + /* Map IRQ and IOMMU for overlay_node's children. */ + for ( np =3D overlay_node->child; np !=3D NULL; np =3D np->sibling ) + { + rc =3D add_resources(np); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + } + + return rc; +} + +static void free_nodes_full_path(int num_nodes, char **nodes_full_path) +{ + int i; + + if ( nodes_full_path !=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 add_resources(overlay_node); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + + /* Keep overlay_node address in tracker. */ + tr->nodes_address[j] =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; + } + + 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); + + xfree(tr); + + return rc; +} + long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) { long ret; @@ -379,6 +936,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 Mon May 13 19:04:48 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=1692233462; cv=pass; d=zohomail.com; s=zohoarc; b=MGYbN6Co6WruT3ldklbnZEeEWF5yMuIizPngxt36yhkgT0Bk/nujdlQDGE1UaMP2GgusdGb9Thmto52GfztQfbjr6INEqhe7Uh+oxzngAsbMPRHw9rDDnIwtx0knLiezqSJ6YTOuoqXvw99OjzzUMZ+nCpnNcSPNUHDUmegh9EE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233462; 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=TSMRF97QlKBb4iu384YTAKHEZ9yf+f7ss37J2EfX8aY=; b=CrvqAD/xGifxyx6NWJyx11Tc3YtTJ7okGVvFlB6/9bkGNVlIHmQaa0O+Vh1J8/lK7gg4/88I5Qa+L5769/Viek9jL+SIh9zmczJB2/aj+sn4a4WwQAyO2+DbHFRBVZs2PhnSd78c1ixRo0gG0u+oGRCFmfIos51Xafohjav/Vyw= 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 169223346259290.78349732847937; Wed, 16 Aug 2023 17:51:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585044.916061 (Exim 4.92) (envelope-from ) id 1qWRDb-0002VD-6O; Thu, 17 Aug 2023 00:50:31 +0000 Received: by outflank-mailman (output) from mailman id 585044.916061; Thu, 17 Aug 2023 00:50:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDa-0002Uj-Uu; Thu, 17 Aug 2023 00:50:30 +0000 Received: by outflank-mailman (input) for mailman id 585044; Thu, 17 Aug 2023 00:50:29 +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 1qWR4L-000280-GD for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:57 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2060c.outbound.protection.outlook.com [2a01:111:f400:7eaa::60c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b8fed452-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:55 +0200 (CEST) Received: from CY8PR12CA0040.namprd12.prod.outlook.com (2603:10b6:930:49::7) by SJ2PR12MB8009.namprd12.prod.outlook.com (2603:10b6:a03:4c7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Thu, 17 Aug 2023 00:40:50 +0000 Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2603:10b6:930:49:cafe::ac) by CY8PR12CA0040.outlook.office365.com (2603:10b6:930:49::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:50 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:49 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:49 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40: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: b8fed452-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qcm+y2pTwXs8njTbMNWCgMDWcrsZSWJ68nlqxEpFtmiQyCDhZvfcPBd3Vf4dgGZ5fuz7eMMPaLX3Pj9VF0qDwQ1kc55lpfC8TFJpyPcbM/lRJFFP8DW+xpUhavlPcyd02rLpOaZbC72giheCSgOxy/3+u5VtuEcSrE9iFtKHNtscNt0Vn8PQxV+ppYorEFxQZgUjkh4tufAKU2LUruYX2uvOdjX1IGVA6gCLstG59WxUJIJhqfpS/b7R2I0oljmsBRfatXaY4UFJn8QAy9qjiCLClAnW0vyIe1zn6QQRaf7YhoYDEJBnc7S8gfOJ/DGerws9+mqTWrP+NQsFgkHP9g== 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=TSMRF97QlKBb4iu384YTAKHEZ9yf+f7ss37J2EfX8aY=; b=VTitIQwA7optyatii0KSWzgghiSyBOOHKAV70dV1xGvj6pDRIH6/Er4PN+zmjO4xyqVxQAimkIoZavzYGQXAt0Z8QUbDJ22EUcvvNJo2H3esbhX6Lmam/ZOopzbWir52zCtgvHeF6EijujXAndc2kpy6vGM/HHSP8V0IkGiwclvFCRWAPK2JbFYjn2u38jhuhVX5S2wYfeZbs9ZBYA8VBiKi9OpNW4Z+6jH2BT7a4FnQNwtmF94Y21xQ2ScLlsl+a0QZT/sZ90w6vAp8RrCu2JjaZEDN0C44iiLDSMsx3pk1RR+z8RMj9G81d346rbhOcx87sRxx+ZGx+iWX+07PBw== 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=TSMRF97QlKBb4iu384YTAKHEZ9yf+f7ss37J2EfX8aY=; b=qYD4FlY9c8V5d4r/8ALnxd92D/0nVvvW6Q6/pAPaVONq2TWj0gi4dtyzrrW97YcShigEvshMAS4lnfYQjmiOqsOssxpc4OyeRe0u2u81Z9G5Kk3Hf1F3u02Uo3QYL8CXYibu0psmTY5bEId2iErAFij8tY680vsO1Tucj/y2iF8= 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 v8 17/19] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Wed, 16 Aug 2023 17:39:45 -0700 Message-ID: <20230817003947.3849-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|SJ2PR12MB8009:EE_ X-MS-Office365-Filtering-Correlation-Id: 24576dce-386b-4089-7b14-08db9eba9abd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 33KCuYqF4YXXGidB2WHCu5XhWP6P5YuNPAjg+CCWSw82AplDLAlHERu1vaNIGErKjyCSIyV54jhBzh3lSErgNK8zeeWyVsaQaXIydG6VtjLk+VZpthFjiDRm3hvfZ7VcMyi4tHGgS1cMxAnZlyVkpMX84Ip8hdoz179fUGPQfYsCLpLxyZcHl5QSOiT97x5FEqqB/QzbQKwCqTlbCGqU6PU2Tqw0kqqj0m/oGmhKl9A7hcOQ08R2EyKWTZSaygxF8XUoxV4VyoeFNOChn63TiadEegqKtYd+5vphEJgngcCnw+ZzmslURFOkKACZZnc3rhv+mQrM3dBSXvUt/FoHTt0ePdeCwkpNq2FTB1djptFrGuacY0yUue6OK4T7QIZYxCVyPM1sN/635aPPjIt7H8wecmVOXZM6iYNVqUjaO613+O4rBkN0QX9iGI+gU+HCF+rZXWTyMFVTFZbiWkgpyddGiGgQ7YIDu7AKYEUwk00cN6wNZ5JeijdMUVv3RfJN3nPHmdC+m0xNxaXGocxeONnGd+WC8uJglpSF8l4sJwVr9SdijnJZxuIsemn6qjnZecEZll0hVhbYtmkvOdGcBQara2u6G9HTR+61tw5dJaBnIO0H36Qrpdb3Z17fpl5WT9iH7JIwPaaSXNLcTJLw4wApdMnZu5rPBxNNIg6WiWYm6XbuO2x1b1vF7jU5cF6Cl/D9n1WfLfLO/HBS4siBi83exEihoiEhn1w/NvsA/dMUADlhVUyG0mbLoN0pYYdLECgh+8Un2dtypse3HdiZMItDWLfOfv9mi4YOF2wJMVk= 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:49.9334 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24576dce-386b-4089-7b14-08db9eba9abd 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: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8009 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233464022100001 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 --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 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..58283b9ef6 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,51 @@ +/* + * + * Device Tree Overlay functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op) +{ + int err; + DECLARE_SYSCTL; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err =3D xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + sysctl.cmd =3D XEN_SYSCTL_dt_overlay; + sysctl.u.dt_overlay.overlay_op =3D overlay_op; + sysctl.u.dt_overlay.overlay_fdt_size =3D overlay_fdt_size; + sysctl.u.dt_overlay.pad[0]=3D 0; + sysctl.u.dt_overlay.pad[1]=3D 0; + sysctl.u.dt_overlay.pad[2]=3D 0; + + 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 Mon May 13 19:04:48 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=1692233457; cv=pass; d=zohomail.com; s=zohoarc; b=P/X/z/tv08IAk0RaqcXvQ0KRkWjdxUlrupQtZdxbXngEhIqT1tNrndn5i0FjIRojW4Qul7KqAV5Zx3ibN61AnhF2nm4WjgM5eRkDXluo3F/uRC6zslCd3w/9kNiiQDdi2Ptocy/gp0v6tOUQha8rHCKmjvvkU0SzMe8IY93WN4o= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233457; 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=l7tzaVSJKhTeWW5Eqb6U88dsvEF7+RhixUCMMHLFQBA1WdQ174WlLn/bo2+U/hAr6sTeaLYVVkQfgsokn5nWLCUHbYjzNaNguBJkUSpOcGoV7rDJ9pymHycM71gDkrQZwfr47xGe7yEJiu1qXp2ucg049myUIKaSllmm5rN640g= 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 1692233457621406.4998885391565; Wed, 16 Aug 2023 17:50:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585045.916075 (Exim 4.92) (envelope-from ) id 1qWRDd-00038A-Dq; Thu, 17 Aug 2023 00:50:33 +0000 Received: by outflank-mailman (output) from mailman id 585045.916075; Thu, 17 Aug 2023 00:50:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDd-00037x-AA; Thu, 17 Aug 2023 00:50:33 +0000 Received: by outflank-mailman (input) for mailman id 585045; Thu, 17 Aug 2023 00:50:31 +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 1qWR4N-000280-V4 for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:40:59 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20616.outbound.protection.outlook.com [2a01:111:f400:7e88::616]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ba26f191-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:57 +0200 (CEST) Received: from CY5PR22CA0095.namprd22.prod.outlook.com (2603:10b6:930:65::13) by CH3PR12MB8972.namprd12.prod.outlook.com (2603:10b6:610:169::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.29; Thu, 17 Aug 2023 00:40:51 +0000 Received: from CY4PEPF0000E9D9.namprd05.prod.outlook.com (2603:10b6:930:65:cafe::9e) by CY5PR22CA0095.outlook.office365.com (2603:10b6:930:65::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.15 via Frontend Transport; Thu, 17 Aug 2023 00:40:51 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000E9D9.mail.protection.outlook.com (10.167.241.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:51 +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; Wed, 16 Aug 2023 19:40:50 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:50 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:50 -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: ba26f191-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OF/nv3PDUb/ecNR6tMXNfToo18rNqv80My1N3evK8wV5hJtxJuK3Tacthb9k0COZvcazUtTWyEr818J+VD6eouhVmCicz01TyH+lo8/LcbJz+Vws8QJimVW4eWx8uPHTP7rVjinUE45/TpnVnSYaqlg7dd6gda5oHgVXi3uW/1a4BU9hH7NKZyNFJpFcuccfPW9vLVLefaCj/jVt+Ge4+M84+zjIsn9BFwvFncrblqyx8VBvN+XKJBXPWB3vHKcmsRK/l1fqsRHoG3iOQjgvJ/9aGWxnkW4sMZKZ6622NJ6kNgAS7GgN8lA22vS3ugl3JOQFMsde37Md9r9A6ttLWA== 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=bXurwo8Q1hRorkclsgGurF/NCAWEGQILwBsMm6VQE2nSh3790WVT7prN190Wo4OXtDqJwLGZlbOtwk4WOWLRSpuRltS7GQB6CGaSP4Vbbd4WMCjqe792mKZHjyN9WdjkFYtgOaz8L8KM0xhmgfohKcojvPRN/s76fg8usWezM6FpxCokV7Qoh9T4kq73rltoR2Bn9lw7HGxiD7Fk0a/6PLPYSz8KmZu08goYkhLuhVsb331FH8X1YuOlDbqW2tfoxXzi/4+2kpLDki9QZ8JGl0FEvkvVJSD2u76NSmC6WOa0PUDt2QaBo7tm7w2kvGUcx/uGVcy3zldWRaMqbMLjGg== 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=MFE9jO5mwevqGUnAnP3Pn1XvS00/YzXJP6uxtWZX8Hh7WOytXpmyNHjDPBc63Z2O7rnaA7Pr4fThmRFVfaPraidEaM7/cCPYjftnM1rdt7rPwZX+Hu+sKdn+vyKvWqymg+qM1eb98pJ2H3RyS9rzlY588CW/03svIdU/DRkqb4A= 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 v8 18/19] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Wed, 16 Aug 2023 17:39:46 -0700 Message-ID: <20230817003947.3849-19-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D9:EE_|CH3PR12MB8972:EE_ X-MS-Office365-Filtering-Correlation-Id: c92ee712-76bf-45cc-850d-08db9eba9bb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tnEDntm4nuvJ4sJ6D2gyBlHfPVbxMl0I0gZV9Ud7J3UpaEt5nGd0xakWuVlo1TQCKnb5nMvyPE2jaOo8ayqCMSe5HaSxDEGEKo3Tgw3kUpmR7tLsrRAe4SvkA5gkQBQhqP3NI6KgWJzFCXAKSroFz5zHnBmhZzcR31GYcW93vNwVQnXPu0Tvtw6K2YqQIFe6YumDLQYvb+9InV8ihP+l0EGCqMtpU++r09HeR7mN2ILRMMOKpf22S2KuyDa0JSQCYdiGcrUgRur66I6WqdUDwUYhtYP7sfRR+QenAS8frfRLh88f/1D8rj8GYudZV5XFJIT4ANBnDdGT5s3p3SKRz93anXFaqPz42ElY0eiSfi2DhjGa4n5nKWaxBJlp+7Y3ZGDSO3GjkNkpK1XjE33r9z1hYcJ2aTjDUeTz9P7CDjKqNGFY9CFTSvKBt1yrxQs3bs6BrnLKTlzKXVeXX/NNDxtueiFsgnPFcdfBb/pXuZDCCRqymBs8rqy0IlCyRcXOIbwG8AgJCHyAt0R+bukR10QGjICLCqLzwy+CPwaKVMkVuL7QVIN1E/g0RKqbFvZqEszzNUrbtJDfensoGTKFm5d8Zh8UIrZxYPG+BpmHYshYFSwu3HRuGebY5gXsVx/acCk/n+ZAsL7e3L62VKoD8QEn0k8KXQFpYisIHQFb93HjrktTo5uHORTAiLRRMh1Cpo1gHvbanZaDDDgwImnPjUYyxJftstSVOb+qzDyoTPlo6wZAjkzLbaZAcdhHeai6tEw6EMT6Z6KDEOibiR9jmuRjC+O2z9Wto9K3Nhmre7A= 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)(39860400002)(346002)(136003)(376002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(316002)(54906003)(356005)(82740400003)(6916009)(81166007)(70586007)(70206006)(5660300002)(41300700001)(36860700001)(44832011)(47076005)(4326008)(8936002)(8676002)(26005)(2906002)(40460700003)(40480700001)(426003)(336012)(478600001)(86362001)(36756003)(6666004)(1076003)(2616005)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:51.5171 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c92ee712-76bf-45cc-850d-08db9eba9bb1 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: CY4PEPF0000E9D9.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8972 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233458803100001 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 Mon May 13 19:04:48 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=1692233472; cv=pass; d=zohomail.com; s=zohoarc; b=nmbAX5SNu3rPF7cnOcixsPHIK2iOduS3Vfu3ntkAKxcTfkYAE5kPpiIYuGUVgc4LXyn/udZ++qGDJFk5PqHpyVNdvvE8w9a820Kbzs7sd1faGWF7kEkTnnGbS+Lm0xiyn8xOAQg4OAjTE1l4OMU4PvGLPV7VIX5CwrgEdx+A9/E= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1692233472; 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=KF3W0v6CIwAbk/hgUP6FgC55mJrscfGGeqOy4zzyb+MbnuLAh40clgwRnKFaSs2MzPDAAJcLYdozqBQZ946fE92dvB3SpUxUNuZUaDm9bSM3vy5yGmbOJRHCbZLvzYcmImG61QvTLsavi1IPjBNt+AjhthwaDY+YSFM7sK2OwZ4= 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 1692233472121490.63917099792513; Wed, 16 Aug 2023 17:51:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.585060.916085 (Exim 4.92) (envelope-from ) id 1qWRDr-0004IF-Lb; Thu, 17 Aug 2023 00:50:47 +0000 Received: by outflank-mailman (output) from mailman id 585060.916085; Thu, 17 Aug 2023 00:50:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWRDr-0004I6-Hz; Thu, 17 Aug 2023 00:50:47 +0000 Received: by outflank-mailman (input) for mailman id 585060; Thu, 17 Aug 2023 00:50:46 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qWR4O-000280-GO for xen-devel@lists.xenproject.org; Thu, 17 Aug 2023 00:41:00 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20630.outbound.protection.outlook.com [2a01:111:f400:7e89::630]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id baa59e11-3c96-11ee-9b0c-b553b5be7939; Thu, 17 Aug 2023 02:40:58 +0200 (CEST) Received: from SA1P222CA0134.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c2::7) by DS0PR12MB8293.namprd12.prod.outlook.com (2603:10b6:8:f3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.30; Thu, 17 Aug 2023 00:40:55 +0000 Received: from SN1PEPF00026367.namprd02.prod.outlook.com (2603:10b6:806:3c2:cafe::5e) by SA1P222CA0134.outlook.office365.com (2603:10b6:806:3c2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:54 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF00026367.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6699.14 via Frontend Transport; Thu, 17 Aug 2023 00:40:54 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 16 Aug 2023 19:40:51 -0500 Received: from xsjfnuv50.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Wed, 16 Aug 2023 19:40:51 -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: baa59e11-3c96-11ee-9b0c-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PLUiWpf1KFzkONzyhdcjkurYXUX3NrUZ0EKZIcIMQ1MmsJWnF/xndv6J5uAXyxOF3VLjOv1EZ+0QccjNSaAb4Fx4+yC3RR3Op+lsmQooi7E1R5EQAf8IpEng5t6olohlrB7gmxz07QGDQqbhyyEVT0d8h+T+T2OCLnYSXR4/2t92YOD+46X6MLBDiTYxent2awHbQyVFubyfk+OOMxGWAvFE8pRkjT5EBT00d+XPBlhOXJoC6MQBC4ct2Pkt+rbnA18Qlp0l+3Ve4W0mT9CeRp4khLA6h1gFU1/OVPQexSjV4W20X8GhqndDWb1Hvz7eK3VgASRi8VV05glC8VTfGQ== 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=J0efkVb81dfCiGmyHFvtqEttvYSgRd+9yqcrucgfDdIhClMyzxHAos3P14iQNGt9ZFXPJvdu91GVGltRHbLugNDPMm2J4n4OBMIa9iyYi4OPmw+xWm2jjyhCMnoYS7OvNKTHwr9zRZFtCa4TwyPBB64+ZnJvwtmqg0SjWDUcMsH+feEf3yr7cP1a9N0+eH7PTsHMFg769/f8wMwlNpook40X+n0E3dV89cCa9iVYLbVDkJNd9m+DUjXqkECmGb/G9J0zMgtVQhCt5G9avsP3K0WUX7lEMXbDY3JwifU01HerdceNUztBAo/t8CVPbmD+I1al4ruLS+eRKctisxLqmQ== 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=w1PyhOqZuBAU/VTPctXsYQKQuqpUTdT/wzKtHVLYm6yKth8S5iebaSG7Uml/A9Jk7Vbi7L1cnz0SSvuDj0agGJ/zOPVhJe2f69WNp9gW/6EgaakHUa5tWXmksiO2udRFVr9iJ4SFm36QkBPwZXA4pP29BL44LRo/5JTaE3rtauk= 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 v8 19/19] tools/xl: Add new xl command overlay for device tree overlay support Date: Wed, 16 Aug 2023 17:39:47 -0700 Message-ID: <20230817003947.3849-20-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817003947.3849-1-vikram.garhwal@amd.com> References: <20230817003947.3849-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026367:EE_|DS0PR12MB8293:EE_ X-MS-Office365-Filtering-Correlation-Id: 06d9c245-2573-40da-99f0-08db9eba9d57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zb3344ncoCOPPWQLtON0jvilShop9lFI5o5WZE74JxdqEuiakoyBYcY1qF64jHdfBBpM+6tG3fhtU4kOurPPC2DvWQWsQ3OQmN976oor63lmeoWBeVL1CbvHpjZpm0xuGhEKZx+651rAkuciFkV9zsxj6Vtqq74mktBzrCUBfhW798Q8GbtvFGyKvrK6nCJYNQbziR5nrMbV4C+gNekUDTI0WY1hIWpcio+uoSX3qyMV7ZU75xxI3lZN7KI9uSB4dy1ELRrflQTe+oDubnYA06W0gfSGYOkdS00pKNg3pCHqUAPvfHcCL1ulwpQoW4/FfyusADnK0yaqydcvPO55h0huBhZmlrqVWAkKr2EPy044uWsA0Rq7DGZmWk+4bDsAzpGaCaCmiR3tq/GNQaijkSsPE1EnVIG7RhXiDdOzRP2QjxamppGnq/hx5cWiMv8AjFqqDvonyS88i4MVCxk1N5L54/DGxpnluaxYTjuhAbThdobcEI81AojZHO74RD3W/dWjyzKX0NF87s8GAjYn2SS7hIENycFBvMbF8QOmjX4dwWRwdFOfl54vwLri95ZTnzvmHwYJRYjnADZRRqM2H4DglADcR+txEFNDQG5wE2mC4/ckszfhGj3sozoGDln+0EjTAKWmw92Zn/wiYWVV/g0arKK3dYfW/HnzUQj21iIy8YaO/U4YkUPTYld9u3bANi81XZEuy1V8U7epr/pDQk+Fdajr7UV1avK4b+nVgCYbrSwUzyXwx6dRhjq3IBESPKyBb7QXThAIp/ugdIcqEw== 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)(396003)(136003)(376002)(39860400002)(186009)(451199024)(82310400011)(1800799009)(40470700004)(36840700001)(46966006)(36756003)(86362001)(40480700001)(40460700003)(83380400001)(8936002)(4326008)(8676002)(5660300002)(2906002)(41300700001)(1076003)(26005)(6666004)(2616005)(44832011)(426003)(36860700001)(336012)(47076005)(478600001)(316002)(82740400003)(356005)(81166007)(70586007)(54906003)(6916009)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 00:40:54.3301 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06d9c245-2573-40da-99f0-08db9eba9d57 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: SN1PEPF00026367.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8293 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1692233474041100001 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