From patchwork Fri Sep 1 04:59:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4FC0BCA0FE1 for ; Fri, 1 Sep 2023 05:00:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594214.927466 (Exim 4.92) (envelope-from ) id 1qbwGR-000385-0e; Fri, 01 Sep 2023 05:00:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594214.927466; Fri, 01 Sep 2023 05:00:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGQ-00037y-U2; Fri, 01 Sep 2023 05:00:10 +0000 Received: by outflank-mailman (input) for mailman id 594214; Fri, 01 Sep 2023 05:00:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGQ-0001Hn-08 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:10 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2061f.outbound.protection.outlook.com [2a01:111:f400:7e88::61f]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6c09cb3d-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:08 +0200 (CEST) Received: from DM6PR11CA0016.namprd11.prod.outlook.com (2603:10b6:5:190::29) 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.6745.20; Fri, 1 Sep 2023 05:00:04 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:5:190:cafe::24) by DM6PR11CA0016.outlook.office365.com (2603:10b6:5:190::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 05:00:04 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:04 +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; Fri, 1 Sep 2023 00:00:03 -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; Fri, 1 Sep 2023 00:00:03 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6c09cb3d-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KZ7eUmJhLV9Zxs35H71ghReW7zKM3PMZaGQ31dBlYxhotVP1SyBSNUem9/8zuUD8F4MJERvT+kl01V13ue00j7pc7Ubo6I54Syis0rS5IxfA0nMothl9rOvB6wxQkV4sWT09yvEsCh9hdtzEQzlwFEC+KMP308xsqGd7BJuCu8pw3JjgX+wTIRciQ2bHl1eO7I139vzNLRHQ4qYMsHmmkLwIb0CaY0QGZWOquEO6YjgD8HI6feZeIGVb076jdspCUtqpqMtgh2LQoMqzc/L3yAqmJs0MwAatrCQmb2RevYRWc7kXbmsrn2I3j8SaJZdRqob+1nNsecCT0ZXyN85YNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=551FbITUy/lX+UFAVwLYLGK11TzVaHOhuLFDvzMcrP0=; b=IjMnoH0+FMUUzhk2mcdrZBwuWupsgFYFUg7o/9fDrH5plLQOy5hauhMPcq7QfB5s7vVoIt6m4J583jcwki5Uo2UHPr2SsW4yG3tP9fj4tu0sAX1YP3F3OUB/MDYSZSJAZDE3x9E7rCfcp8Oitu1Kp1Ipj55iOUnIceEO/gSkA0fyZLfJ1S21fXa3lp8LeDra68G5Jc4vGEIn6uQOVsjoSjMRceLGvGitRcosbVuuUXsVUpkWlneFksngJ0Qr0YIArVBhcQPk0o/Flc4lR6hlzrMZn0KZPdjo5mtM0a+omURe7rHx42f5VRSccAm6AjYZ4iwasetHOj618CflUFcfOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=551FbITUy/lX+UFAVwLYLGK11TzVaHOhuLFDvzMcrP0=; b=HXhYuYW9DFa/TIK6N1FgUZywh1VekL1ZiaI3OcxISmueGGFHBXS97LtMhP40tY4uGgxVmUy0SgkUqaeUvGGTVB4sAZL1U1crXQPtOkdjRMHZtCWkVrSMXl/Lk+41lBlfFnhGCVuYyaFN7oHgr71GJ+Yh19aWs3jk5cAaHqAE9CA= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 01/20] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Date: Thu, 31 Aug 2023 21:59:28 -0700 Message-ID: <20230901045947.32351-2-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|IA1PR12MB6164:EE_ X-MS-Office365-Filtering-Correlation-Id: 737e6e59-95ad-4346-96f3-08dbaaa84e05 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2SHxBrHydjnE4JcjMZxmv8H2Os82vmIaRa7cYQNKuR297uZ/BhnoCbM+Zzxu0mG6l8K0hATRPQFtPHqx6s2rHZKgisTU+tGmxYpvZlc4xRuGf0tjvEfUPuue80AWKJA82hPIC/bRHJckbNLIzsObxFoWvd6c0SfD5ErTZC8mY2DHZGmtwvX4PcahRWB2b+M4cuedShlttyxI9APhJXIRe3KzWifr7olg95PXxL7S4EQ0lchAQZ7ANZUbj4ww75uD4zmGRCpt00xM+3POlD2kXTRg8pNxql0dsN3B7KzsUVzSS8/9KRFpdWh6BzmzC6AwwKMRFJLakQJnXJYrYTnjeO9siOgv0epCNSbTxeWntbt0JLNrbWyVMYPVcsjQDUzpYZzoyMw4RgkQmociArChtqIfqwBElm9SAhHWYeg1f5NJyWWIuqIngr0x3HnlUD+UMLOasBFQGRYXHUziWpXhIRNq+Wuwd/3qnVEYpr3f50zn1mPGw2UtvAM1tDdKnsJSOfFANcN1X55FCgrwDKPOFmEOTfDq2VGXevKh0L+I/f4PMIbluRhqh2k5Jh2pYGxwiTFTrQvTr9Xytst7jvwqQIZmmCBEzaLX6f3knWCkOoteWhyGlg4MjUfQQVIjUV8WEkaKVb/fY8wEsEClVzmgF/hBN+LKBNSm68eV33evg7JSmM4XvjSnFGHjtXaPVVD/7FeEQYnm6b4CrjP3kLV/y4qNJnkYRwCMeHRfRVhdqbHSqoBi3YwPuy7tOWLtiUH/60hkw5hfBZMJ8r37ZfVTZA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(376002)(396003)(136003)(451199024)(82310400011)(1800799009)(186009)(40470700004)(36840700001)(46966006)(82740400003)(426003)(356005)(478600001)(1076003)(26005)(336012)(36756003)(81166007)(70586007)(70206006)(47076005)(36860700001)(41300700001)(6666004)(83380400001)(2616005)(54906003)(6916009)(316002)(44832011)(5660300002)(40460700003)(4326008)(8676002)(8936002)(86362001)(40480700001)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:04.2180 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 737e6e59-95ad-4346-96f3-08dbaaa84e05 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: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6164 Change __unflatten_device_tree() return type to integer so it can propagate memory allocation failure. Add panic() in dt_unflatten_host_device_tree() for memory allocation failure during boot. Fixes: fb97eb614acf ("xen/arm: Create a hierarchical device tree") Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang Reviewed-by: Michal Orzel Acked-by: Julien Grall --- Changes from v9: Update comment regarding return value of unflatten_device_tree(). --- --- xen/common/device_tree.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 0522fdf976..7c6b41c3b4 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2091,9 +2091,11 @@ static unsigned long __init unflatten_dt_node(const void *fdt, * can be used. * @fdt: The fdt to expand * @mynodes: The device_node tree created by the call + * + * Returns 0 on success and a negative number on error */ -static void __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +static int __init __unflatten_device_tree(const void *fdt, + struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; @@ -2114,6 +2116,8 @@ static void __init __unflatten_device_tree(const void *fdt, /* Allocate memory for the expanded device tree */ mem = (unsigned long)_xmalloc (size + 4, __alignof__(struct dt_device_node)); + if ( !mem ) + return -ENOMEM; ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeefU); @@ -2131,6 +2135,8 @@ static void __init __unflatten_device_tree(const void *fdt, *allnextp = NULL; dt_dprintk(" <- unflatten_device_tree()\n"); + + return 0; } static void dt_alias_add(struct dt_alias_prop *ap, @@ -2215,7 +2221,11 @@ dt_find_interrupt_controller(const struct dt_device_match *matches) void __init dt_unflatten_host_device_tree(void) { - __unflatten_device_tree(device_tree_flattened, &dt_host); + int error = __unflatten_device_tree(device_tree_flattened, &dt_host); + + if ( error ) + panic("__unflatten_device_tree failed with error %d\n", error); + dt_alias_scan(); } From patchwork Fri Sep 1 04:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 49678CA0FE6 for ; Fri, 1 Sep 2023 05:00:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594217.927481 (Exim 4.92) (envelope-from ) id 1qbwGU-0003U4-Sx; Fri, 01 Sep 2023 05:00:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594217.927481; Fri, 01 Sep 2023 05:00:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGU-0003TB-LD; Fri, 01 Sep 2023 05:00:14 +0000 Received: by outflank-mailman (input) for mailman id 594217; Fri, 01 Sep 2023 05:00:13 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGT-0001Hn-EX for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:13 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20618.outbound.protection.outlook.com [2a01:111:f400:7e8b::618]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6df55f76-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:11 +0200 (CEST) Received: from CY8PR10CA0029.namprd10.prod.outlook.com (2603:10b6:930:4b::10) by BL1PR12MB5729.namprd12.prod.outlook.com (2603:10b6:208:384::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 05:00:06 +0000 Received: from CY4PEPF0000EE35.namprd05.prod.outlook.com (2603:10b6:930:4b:cafe::7e) by CY8PR10CA0029.outlook.office365.com (2603:10b6:930:4b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.26 via Frontend Transport; Fri, 1 Sep 2023 05:00:05 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE35.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:04 +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; Fri, 1 Sep 2023 00:00:04 -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; Thu, 31 Aug 2023 22:00:04 -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; Fri, 1 Sep 2023 00:00:03 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6df55f76-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cxtIzzVeUDUjkTHCNTKOPrS4P+7I1RAtfBIkHmElRsSicW1JcoIKnQVajirH6i5FWcliRVf2jEmnEk3M58j00FWMjppggT6vI59yvhZQxuzXJwMRtMh6Ql9tmoJrXtDSEyq04QGUBouP/Clb4bx+I6wEgkbNSfPZGrn+2lh8eTEVqsFVN7Td8z2lXBZEbtTgml674qjtdVIlDyfgRddSkCbMl/WZhh/8JMbOoTW4lf+tANmhtpW2V2/7Mp3tlFLtCx04UgOGVsMiTJf898w+Thb0PpK8q2NDwQHfTJ5tK/PSWVwJmGx1yFdG1DqryRBcSkiZTYs+ZcT9DEqB7xEy9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cro8idbWK6/j9Apeo95KJGwjFsR6k97QUgTNDxCH+H8=; b=XLlDgpRWF3Wx5s+0rQY1Z6Bj8ImZaVj1ic5goFQ2666XbARlznpBZun9TUyFE4Y6/C9earruSe32CQnXoiuxe8Q9yFU4Dubb5DvUjJuqSruJl6evCWnVMieE2jRthoNgVBfSo5ZWCPsIdSM2MjlEAAsTBqBQoSNypzJ1pBiyvPs39WGX4nh2tEfp2+rkGCG9GGp66sJOATdhb7NDQ4pMBmGNBxx05LMk6xyN/LYrBL+OfkiSriOkp15A9+6z4JEBw6Nk8dlDUDc2xR/ECwkrJfG9nnH+vvb1EN57GN9rlofZ/TFgy1WYTXMVHGk9PEwTwPROeJ74rNI+dKyEzm8ZDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cro8idbWK6/j9Apeo95KJGwjFsR6k97QUgTNDxCH+H8=; b=E0gJYxDNBmIJ3MpQo3frVtGKgCSKC4ks1W9t/aHi/vfz9vpcJ5n4oq/z906XkL2iDv/YE+D+jpO+M8oVpzedkG1QKXUCCdI1gIvheJBoy8qBeqQkAzW/Tot7dQjA8N50R95E4pEzU4E1rnDh1FWQfpw616z/iuHPVZc+8tEkp94= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 02/20] common/device_tree.c: unflatten_device_tree() propagate errors Date: Thu, 31 Aug 2023 21:59:29 -0700 Message-ID: <20230901045947.32351-3-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE35:EE_|BL1PR12MB5729:EE_ X-MS-Office365-Filtering-Correlation-Id: aa597767-0471-4327-40ba-08dbaaa84e58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZrjKqd9zzJW/BMOvGBlpbW4RV50y2cVvRDendDY/FAsH85VfLDveKeuj1TjEZMmNKaNRjeBmhl5P8hcQgZ/i8snpYhZ6kozocsBOA+O1yLAqxf6lbZeXSSu6aGdf3tWNK5I1co1yyuY3kVfdIfrTv7rCDgeKXRVxq1T/OzqL9+rDo1ChLH6krWypaEMJBCY+Wy1TZUcN8IpmKEF8+xgMFWjbdB8xllB2AuYlUvyLGWKPzhXtm/zlC5spWE0vSjngMn+FKJW56qt7Zm3cS+E8E2RDCF3+fp4irUCCoFdjTfHeIDn1039guZrh0A9L6xjMwuSw2yAuoyK/Rqrrxh3SU8dc7qWKxAPcUQX0WXJhiE9O+tpvS3W9zFjiICjW+d17Oq06svxB1N/woSIxRHQfUQB7v5LDYG/euigw4PoHEA/Yi8z6SLwV0FgrLXo42lxLVLwfT6fI4A33vIIvwM+AEEya4WoJmJXIqSpLW8w2RquGL/WW+YYf5cfG8bUJf8LDx70hal6dq5VkBah4b3rtBj11gVOjKy38N056D9bTaFbRT8KJbd/TeFxBLFgYP0JVyGo9H++u8BFPFK5i6dOLjezn72p2lmReleze9qpa/QTAC947Vj8lt0pWGx74XpvbVQlHozhzIDxJlW3+xiasWjabLzVmAdNDt9FbX7tLU/4mIWQZXH17oyRCE8U2AkWWA1wb10ghgGj8y8bJf13VdrDRHzxDYrZFpbGPyWYq2zx6BrQ9ydVU313Jh8MGDxV424VWGdcVojhja2EVjOrWVg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(39860400002)(396003)(346002)(376002)(451199024)(1800799009)(82310400011)(186009)(40470700004)(46966006)(36840700001)(6666004)(2906002)(5660300002)(86362001)(316002)(6916009)(478600001)(2616005)(4326008)(47076005)(8676002)(36860700001)(44832011)(8936002)(26005)(40460700003)(1076003)(82740400003)(40480700001)(41300700001)(426003)(336012)(36756003)(356005)(83380400001)(81166007)(54906003)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:04.7597 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa597767-0471-4327-40ba-08dbaaa84e58 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: CY4PEPF0000EE35.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5729 This will be useful in dynamic node programming when new dt nodes are unflattend during runtime. Invalid device tree node related errors should be propagated back to the caller. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v9: Replace __be64 with void. Changes from v7: Free allocated memory in case of errors when calling unflatten_dt_node. --- --- xen/common/device_tree.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 7c6b41c3b4..b6d9f018c6 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2110,6 +2110,9 @@ static int __init __unflatten_device_tree(const void *fdt, /* First pass, scan for size */ start = ((unsigned long)fdt) + fdt_off_dt_struct(fdt); size = unflatten_dt_node(fdt, 0, &start, NULL, NULL, 0); + if ( !size ) + return -EINVAL; + size = (size | 3) + 1; dt_dprintk(" size is %#lx allocating...\n", size); @@ -2127,11 +2130,21 @@ static int __init __unflatten_device_tree(const void *fdt, start = ((unsigned long)fdt) + fdt_off_dt_struct(fdt); unflatten_dt_node(fdt, mem, &start, NULL, &allnextp, 0); if ( be32_to_cpup((__be32 *)start) != FDT_END ) - printk(XENLOG_WARNING "Weird tag at end of tree: %08x\n", + { + printk(XENLOG_ERR "Weird tag at end of tree: %08x\n", *((u32 *)start)); + xfree((void *)mem); + return -EINVAL; + } + if ( be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeefU ) - printk(XENLOG_WARNING "End of tree marker overwritten: %08x\n", + { + printk(XENLOG_ERR "End of tree marker overwritten: %08x\n", be32_to_cpu(((__be32 *)mem)[size / 4])); + xfree((void *)mem); + return -EINVAL; + } + *allnextp = NULL; dt_dprintk(" <- unflatten_device_tree()\n"); From patchwork Fri Sep 1 04:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DA29CA0FE9 for ; Fri, 1 Sep 2023 05:00:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594218.927488 (Exim 4.92) (envelope-from ) id 1qbwGV-0003bD-AM; Fri, 01 Sep 2023 05:00:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594218.927488; Fri, 01 Sep 2023 05:00: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 1qbwGV-0003Zj-15; Fri, 01 Sep 2023 05:00:15 +0000 Received: by outflank-mailman (input) for mailman id 594218; Fri, 01 Sep 2023 05:00:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGT-0000Nr-HO for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:13 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20601.outbound.protection.outlook.com [2a01:111:f400:fe5a::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6e1fd67f-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:11 +0200 (CEST) Received: from CYZPR10CA0016.namprd10.prod.outlook.com (2603:10b6:930:8a::19) by SA1PR12MB7176.namprd12.prod.outlook.com (2603:10b6:806:2bd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.23; Fri, 1 Sep 2023 05:00:06 +0000 Received: from CY4PEPF0000EE39.namprd03.prod.outlook.com (2603:10b6:930:8a:cafe::35) by CYZPR10CA0016.outlook.office365.com (2603:10b6:930:8a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:06 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE39.mail.protection.outlook.com (10.167.242.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:05 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:00:05 -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; Thu, 31 Aug 2023 22:00:05 -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; Fri, 1 Sep 2023 00:00:04 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6e1fd67f-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eR29bI8FAsy9ByvUnBkGBKqnyF6RNK0rB8n0zKjjgv4nCNmmyaqwlacR5Cpl0gRv3T+wEZvkde92OuG0NXdnRZ2g+yUuVHdGVIT1TLLwbJ8pc6esXRIrnquSif5M3QiwPJIHaXutn540GDgIZnDk/ppeF4A+MJgUgB2FalOlv4qotLVoM/y1hMDufMLzol35dEpGGeXe5VD+5pUOTBxgjL6Ki6uueocsUvssgrFM/aWtTLvayXZtLhltNQFKjdJaP3if/Cu7UITX8i+ZjtbLmXH+Alm+o+UtV0tS+y6GYMHLasrER0etFskjmF6magxP4VyVeLQOupOGKSd/nJPb4Q== 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=FDrA8kyZcppqpVb5vdK9SGxL7ekN3/cHqigiQ/O+H7M=; b=eXgBe/deS+Qb+HVzx48IgJtiTciz36fQT8p+b5LI0SeuRIfNeAAM0bmq7n/gJCuhr977Xd2wPARwegmLPae7wkHd1Rg1KkDU4/tYrcKok9kSOTQYI3H44JY55PkKDOjco40BaXKSLJTFUfl/hHafjn+F8/5UI5dfRo2GKcPsLyK+mNIhTBhsWGVwvK/SXDwMan+Xo+r5/T7NOM19YyIMMEePtz6Ffu9XE1Nvq0+y94kR7R9evVicRAdvL0SZBFQcWLI1qOohL0SjEsrPiMaBnSTIWOT35a+laM2jSs7sBmTlkapYQXpfB1rLybozgOnuICpg9es6k6HB/pcJCh3SBw== 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=FDrA8kyZcppqpVb5vdK9SGxL7ekN3/cHqigiQ/O+H7M=; b=oTPw1n2/1wtIyUxxd/oHOZ7hGmsQ+wRd+FTm24nHWYfcI7sf5XJv76Mb7vLTbgaJ6lbnYKIZrgjARJKPxemKdVdBAzDgVOwQUIavrd6B6Ufjk8FcckXBIFguBDruy2TK3usCbgv8aYHbVV7di0sdYhGVuvlXoay4TOwbaa1DSio= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v11 03/20] xen/arm/device: Remove __init from function type Date: Thu, 31 Aug 2023 21:59:30 -0700 Message-ID: <20230901045947.32351-4-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE39:EE_|SA1PR12MB7176:EE_ X-MS-Office365-Filtering-Correlation-Id: 10f503ac-a65e-49ba-3e31-08dbaaa84f0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +MWJhJXIdlOJptjSulo38oTtTQRR04+DITU7Bc31XEhloai67ourAYq+2LRdsdSPzqPnuWs1936vKXnn+CRLKmHDDhizxA6ET5cwakZYWIefCUtWiB6eOdpQFzfv4KpsSXs60pve7CZtgpvAX6CKKmUDzhhWZYKmU+lVT+vCcUzcmjbqG3wuWCFmADXun2nvluIqvetS7SuYPVNnxZEg3x0lU0yvWn1Ct0qRDRJufCx3OmNg17lk5fhCfGtPc1DO2/kBqIdSTJnV57xYfY1s+FMjuWHvSccaRrAtwAOdLo0eeQhU2YQQXQhUljT5mV+7l6t04Y+FC/8sMxMNZ00Q4VLud7K1IwmL8uqJbAoKsetQDaKlBaahtnVy6OpzVd4VHnxa7AMgnWFDEedS6O/aDB8OoIyHA2241AuKX2nipbqISacCABZFlxfFdAvQ2hgNNwUWbHWOUW8p2NdpO/K6ROv+n2ezdyA5+1GSXJTHU0+LcNBPfc9gsmfozT/kycWV+z2IphPm4mGFDVNne4GHw/gHY33s/i7AURF6Mdi0FZQdgWZhDU2nYqlDk2VPNiTNv+TANZeaPmQ/ERxpN02fOJSwxNhVey6MaDiJAyCuKUT4bQU8Zpcu4RDOKdlMNP2QlE41W+Dg5GmkSptJgVXQVcB3I1GXXVYeAP/BphuFtcptcWCngjEz/k7ft698C7dwILkwPAPMzjZ2dNPZovre6QV8/A3yX/qvyXD+cdq5BbnV44y7piYiyYhKgZ7FsaKJyTAUw/KKFeOLQ8SO9sFM2g== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(396003)(346002)(376002)(39860400002)(451199024)(82310400011)(1800799009)(186009)(40470700004)(36840700001)(46966006)(41300700001)(70586007)(70206006)(2906002)(30864003)(1076003)(2616005)(5660300002)(478600001)(316002)(4326008)(54906003)(6916009)(8936002)(8676002)(44832011)(6666004)(40460700003)(36756003)(36860700001)(47076005)(26005)(40480700001)(83380400001)(81166007)(86362001)(336012)(426003)(82740400003)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:05.9590 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10f503ac-a65e-49ba-3e31-08dbaaa84f0f 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: CY4PEPF0000EE39.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7176 Remove __init from following function to access during runtime: 1. map_irq_to_domain() 2. handle_device_interrupts() 3. map_range_to_domain() 4. unflatten_dt_node() 5. handle_device() 6. map_device_children() 7. map_dt_irq_to_domain() Move map_irq_to_domain() prototype from domain_build.h to setup.h. Above changes will create an error on build as non-init function are still in domain_build.c file. So, to avoid build fails, following changes are done: 1. Move map_irq_to_domain(), handle_device_interrupts(), map_range_to_domain(), handle_device(), map_device_children() and map_dt_irq_to_domain() to device.c. After removing __init type, these functions are not specific to domain building, so moving them out of domain_build.c to device.c. 2. Remove static type from handle_device_interrupts(). Also, renamed handle_device_interrupts() to map_device_irqs_to_domain(). Overall, these changes are done to support the dynamic programming of a nodes where an overlay node will be added to fdt and unflattened node will be added to dt_host. Furthermore, IRQ and mmio mapping will be done for the added node. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Remove unnecessary rangeset variables from handle_device() declaration. Rename handle_device_interrupts() to map_device_irqs_to_domain(). Fix code styles. Changes from v9: Move handle_device(), map_device_children() and map_dt_irq_to_domain() out of domain_build.c --- --- xen/arch/arm/device.c | 294 +++++++++++++++++++++++ xen/arch/arm/domain_build.c | 295 +----------------------- xen/arch/arm/include/asm/domain_build.h | 2 - xen/arch/arm/include/asm/setup.h | 9 + xen/common/device_tree.c | 12 +- 5 files changed, 310 insertions(+), 302 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index ca8539dee5..327e4d24fb 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -9,8 +9,10 @@ */ #include +#include #include #include +#include #include extern const struct device_desc _sdevice[], _edevice[]; @@ -75,6 +77,298 @@ enum device_class device_get_class(const struct dt_device_node *dev) return DEVICE_UNKNOWN; } +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname) +{ + int res; + + res = irq_permit_access(d, irq); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to %pd access to IRQ %u\n", d, irq); + return res; + } + + if ( need_mapping ) + { + /* + * Checking the return of vgic_reserve_virq is not + * necessary. It should not fail except when we try to map + * the IRQ twice. This can legitimately happen if the IRQ is shared + */ + vgic_reserve_virq(d, irq); + + res = route_irq_to_guest(d, irq, irq, devname); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map IRQ%u to %pd\n", irq, d); + return res; + } + } + + dt_dprintk(" - IRQ: %u\n", irq); + return 0; +} + +int map_range_to_domain(const struct dt_device_node *dev, + uint64_t addr, uint64_t len, void *data) +{ + struct map_range_data *mr_data = data; + struct domain *d = mr_data->d; + int res; + + if ( (addr != (paddr_t)addr) || (((paddr_t)~0 - addr) < len) ) + { + printk(XENLOG_ERR "%s: [0x%"PRIx64", 0x%"PRIx64"] exceeds the maximum allowed PA width (%u bits)", + dt_node_full_name(dev), addr, (addr + len), PADDR_BITS); + return -ERANGE; + } + + /* + * reserved-memory regions are RAM carved out for a special purpose. + * They are not MMIO and therefore a domain should not be able to + * manage them via the IOMEM interface. + */ + if ( strncasecmp(dt_node_full_name(dev), "/reserved-memory/", + strlen("/reserved-memory/")) != 0 ) + { + res = iomem_permit_access(d, paddr_to_pfn(addr), + paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); + if ( res ) + { + printk(XENLOG_ERR "Unable to permit to dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); + return res; + } + } + + if ( !mr_data->skip_mapping ) + { + res = map_regions_p2mt(d, + gaddr_to_gfn(addr), + PFN_UP(len), + maddr_to_mfn(addr), + mr_data->p2mt); + + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to map 0x%"PRIx64 + " - 0x%"PRIx64" in domain %d\n", + addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, + d->domain_id); + return res; + } + } + + dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", + addr, addr + len, mr_data->p2mt); + + return 0; +} + +/* + * map_device_irqs_to_domain retrieves the interrupts configuration from + * a device tree node and maps those interrupts to the target domain. + * + * Returns: + * < 0 error + * 0 success + */ +int map_device_irqs_to_domain(struct domain *d, + struct dt_device_node *dev, + bool need_mapping) +{ + unsigned int i, nirq; + int res; + struct dt_raw_irq rirq; + + nirq = dt_number_of_irq(dev); + + /* Give permission and map IRQs */ + for ( i = 0; i < nirq; i++ ) + { + res = dt_device_get_raw_irq(dev, i, &rirq); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + /* + * Don't map IRQ that have no physical meaning + * ie: IRQ whose controller is not the GIC + */ + if ( rirq.controller != dt_interrupt_controller ) + { + dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", + i, dt_node_full_name(rirq.controller)); + continue; + } + + res = platform_get_irq(dev, i); + if ( res < 0 ) + { + printk(XENLOG_ERR "Unable to get irq %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + if ( res ) + return res; + } + + return 0; +} + +static int map_dt_irq_to_domain(const struct dt_device_node *dev, + const struct dt_irq *dt_irq, + void *data) +{ + struct map_range_data *mr_data = data; + struct domain *d = mr_data->d; + unsigned int irq = dt_irq->irq; + int res; + + if ( irq < NR_LOCAL_IRQS ) + { + printk(XENLOG_ERR "%s: IRQ%u is not a SPI\n", dt_node_name(dev), irq); + return -EINVAL; + } + + /* Setup the IRQ type */ + res = irq_set_spi_type(irq, dt_irq->type); + if ( res ) + { + printk(XENLOG_ERR "%s: Unable to setup IRQ%u to %pd\n", + dt_node_name(dev), irq, d); + return res; + } + + res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev)); + + return res; +} + +/* + * For a node which describes a discoverable bus (such as a PCI bus) + * then we may need to perform additional mappings in order to make + * the child resources available to domain 0. + */ +static int map_device_children(const struct dt_device_node *dev, + struct map_range_data *mr_data) +{ + if ( dt_device_type_is_equal(dev, "pci") ) + { + int ret; + + dt_dprintk("Mapping children of %s to guest\n", + dt_node_full_name(dev)); + + ret = dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); + if ( ret < 0 ) + return ret; + + ret = dt_for_each_range(dev, &map_range_to_domain, mr_data); + if ( ret < 0 ) + return ret; + } + + return 0; +} + +/* + * For a given device node: + * - Give permission to the guest to manage IRQ and MMIO range + * - Retrieve the IRQ configuration (i.e edge/level) from device tree + * When the device is not marked for guest passthrough: + * - Try to call iommu_add_dt_device to protect the device by an IOMMU + * - Assign the device to the guest if it's protected by an IOMMU + * - Map the IRQs and iomem regions to DOM0 + */ +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) +{ + unsigned int naddr; + unsigned int i; + int res; + paddr_t addr, size; + bool own_device = !dt_device_for_passthrough(dev); + /* + * We want to avoid mapping the MMIO in dom0 for the following cases: + * - The device is owned by dom0 (i.e. it has been flagged for + * passthrough). + * - PCI host bridges with driver in Xen. They will later be mapped by + * pci_host_bridge_mappings(). + */ + struct map_range_data mr_data = { + .d = d, + .p2mt = p2mt, + .skip_mapping = !own_device || + (is_pci_passthrough_enabled() && + (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) + }; + + naddr = dt_number_of_address(dev); + + dt_dprintk("%s passthrough = %d naddr = %u\n", + dt_node_full_name(dev), own_device, naddr); + + if ( own_device ) + { + dt_dprintk("Check if %s is behind the IOMMU and add it\n", + dt_node_full_name(dev)); + + res = iommu_add_dt_device(dev); + if ( res < 0 ) + { + printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", + dt_node_full_name(dev)); + return res; + } + + if ( dt_device_is_protected(dev) ) + { + dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); + res = iommu_assign_dt_device(d, dev); + if ( res ) + { + printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", + dt_node_full_name(dev)); + return res; + } + } + } + + res = map_device_irqs_to_domain(d, dev, own_device); + if ( res < 0 ) + return res; + + /* Give permission and map MMIOs */ + for ( i = 0; i < naddr; i++ ) + { + res = dt_device_get_paddr(dev, i, &addr, &size); + if ( res ) + { + printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", + i, dt_node_full_name(dev)); + return res; + } + + res = map_range_to_domain(dev, addr, size, &mr_data); + if ( res ) + return res; + } + + res = map_device_children(dev, &mr_data); + if ( res ) + return res; + + return 0; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 54bf5623c8..ff4fc30769 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2293,299 +2293,6 @@ int __init make_chosen_node(const struct kernel_info *kinfo) return res; } -int __init map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname) -{ - int res; - - res = irq_permit_access(d, irq); - if ( res ) - { - printk(XENLOG_ERR "Unable to permit to %pd access to IRQ %u\n", d, irq); - return res; - } - - if ( need_mapping ) - { - /* - * Checking the return of vgic_reserve_virq is not - * necessary. It should not fail except when we try to map - * the IRQ twice. This can legitimately happen if the IRQ is shared - */ - vgic_reserve_virq(d, irq); - - res = route_irq_to_guest(d, irq, irq, devname); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to map IRQ%u to %pd\n", irq, d); - return res; - } - } - - dt_dprintk(" - IRQ: %u\n", irq); - return 0; -} - -static int __init map_dt_irq_to_domain(const struct dt_device_node *dev, - const struct dt_irq *dt_irq, - void *data) -{ - struct map_range_data *mr_data = data; - struct domain *d = mr_data->d; - unsigned int irq = dt_irq->irq; - int res; - - if ( irq < NR_LOCAL_IRQS ) - { - printk(XENLOG_ERR "%s: IRQ%u is not a SPI\n", dt_node_name(dev), irq); - return -EINVAL; - } - - /* Setup the IRQ type */ - res = irq_set_spi_type(irq, dt_irq->type); - if ( res ) - { - printk(XENLOG_ERR "%s: Unable to setup IRQ%u to %pd\n", - dt_node_name(dev), irq, d); - return res; - } - - res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev)); - - return res; -} - -int __init map_range_to_domain(const struct dt_device_node *dev, - uint64_t addr, uint64_t len, void *data) -{ - struct map_range_data *mr_data = data; - struct domain *d = mr_data->d; - int res; - - if ( (addr != (paddr_t)addr) || (((paddr_t)~0 - addr) < len) ) - { - printk(XENLOG_ERR "%s: [0x%"PRIx64", 0x%"PRIx64"] exceeds the maximum allowed PA width (%u bits)", - dt_node_full_name(dev), addr, (addr + len), PADDR_BITS); - return -ERANGE; - } - - /* - * reserved-memory regions are RAM carved out for a special purpose. - * They are not MMIO and therefore a domain should not be able to - * manage them via the IOMEM interface. - */ - if ( strncasecmp(dt_node_full_name(dev), "/reserved-memory/", - strlen("/reserved-memory/")) != 0 ) - { - res = iomem_permit_access(d, paddr_to_pfn(addr), - paddr_to_pfn(PAGE_ALIGN(addr + len - 1))); - if ( res ) - { - printk(XENLOG_ERR "Unable to permit to dom%d access to" - " 0x%"PRIx64" - 0x%"PRIx64"\n", - d->domain_id, - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1); - return res; - } - } - - if ( !mr_data->skip_mapping ) - { - res = map_regions_p2mt(d, - gaddr_to_gfn(addr), - PFN_UP(len), - maddr_to_mfn(addr), - mr_data->p2mt); - - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to map 0x%"PRIx64 - " - 0x%"PRIx64" in domain %d\n", - addr & PAGE_MASK, PAGE_ALIGN(addr + len) - 1, - d->domain_id); - return res; - } - } - - dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", - addr, addr + len, mr_data->p2mt); - - return 0; -} - -/* - * For a node which describes a discoverable bus (such as a PCI bus) - * then we may need to perform additional mappings in order to make - * the child resources available to domain 0. - */ -static int __init map_device_children(const struct dt_device_node *dev, - struct map_range_data *mr_data) -{ - if ( dt_device_type_is_equal(dev, "pci") ) - { - int ret; - - dt_dprintk("Mapping children of %s to guest\n", - dt_node_full_name(dev)); - - ret = dt_for_each_irq_map(dev, &map_dt_irq_to_domain, mr_data); - if ( ret < 0 ) - return ret; - - ret = dt_for_each_range(dev, &map_range_to_domain, mr_data); - if ( ret < 0 ) - return ret; - } - - return 0; -} - -/* - * handle_device_interrupts retrieves the interrupts configuration from - * a device tree node and maps those interrupts to the target domain. - * - * Returns: - * < 0 error - * 0 success - */ -static int __init handle_device_interrupts(struct domain *d, - struct dt_device_node *dev, - bool need_mapping) -{ - unsigned int i, nirq; - int res; - struct dt_raw_irq rirq; - - nirq = dt_number_of_irq(dev); - - /* Give permission and map IRQs */ - for ( i = 0; i < nirq; i++ ) - { - res = dt_device_get_raw_irq(dev, i, &rirq); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - /* - * Don't map IRQ that have no physical meaning - * ie: IRQ whose controller is not the GIC - */ - if ( rirq.controller != dt_interrupt_controller ) - { - dt_dprintk("irq %u not connected to primary controller. Connected to %s\n", - i, dt_node_full_name(rirq.controller)); - continue; - } - - res = platform_get_irq(dev, i); - if ( res < 0 ) - { - printk(XENLOG_ERR "Unable to get irq %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); - if ( res ) - return res; - } - - return 0; -} - -/* - * For a given device node: - * - Give permission to the guest to manage IRQ and MMIO range - * - Retrieve the IRQ configuration (i.e edge/level) from device tree - * When the device is not marked for guest passthrough: - * - Try to call iommu_add_dt_device to protect the device by an IOMMU - * - Assign the device to the guest if it's protected by an IOMMU - * - Map the IRQs and iomem regions to DOM0 - */ -static int __init handle_device(struct domain *d, struct dt_device_node *dev, - p2m_type_t p2mt) -{ - unsigned int naddr; - unsigned int i; - int res; - paddr_t addr, size; - bool own_device = !dt_device_for_passthrough(dev); - /* - * We want to avoid mapping the MMIO in dom0 for the following cases: - * - The device is owned by dom0 (i.e. it has been flagged for - * passthrough). - * - PCI host bridges with driver in Xen. They will later be mapped by - * pci_host_bridge_mappings(). - */ - struct map_range_data mr_data = { - .d = d, - .p2mt = p2mt, - .skip_mapping = !own_device || - (is_pci_passthrough_enabled() && - (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) - }; - - naddr = dt_number_of_address(dev); - - dt_dprintk("%s passthrough = %d naddr = %u\n", - dt_node_full_name(dev), own_device, naddr); - - if ( own_device ) - { - dt_dprintk("Check if %s is behind the IOMMU and add it\n", - dt_node_full_name(dev)); - - res = iommu_add_dt_device(dev); - if ( res < 0 ) - { - printk(XENLOG_ERR "Failed to add %s to the IOMMU\n", - dt_node_full_name(dev)); - return res; - } - - if ( dt_device_is_protected(dev) ) - { - dt_dprintk("%s setup iommu\n", dt_node_full_name(dev)); - res = iommu_assign_dt_device(d, dev); - if ( res ) - { - printk(XENLOG_ERR "Failed to setup the IOMMU for %s\n", - dt_node_full_name(dev)); - return res; - } - } - } - - res = handle_device_interrupts(d, dev, own_device); - if ( res < 0 ) - return res; - - /* Give permission and map MMIOs */ - for ( i = 0; i < naddr; i++ ) - { - res = dt_device_get_paddr(dev, i, &addr, &size); - if ( res ) - { - printk(XENLOG_ERR "Unable to retrieve address %u for %s\n", - i, dt_node_full_name(dev)); - return res; - } - - res = map_range_to_domain(dev, addr, size, &mr_data); - if ( res ) - return res; - } - - res = map_device_children(dev, &mr_data); - if ( res ) - return res; - - return 0; -} - static int __init handle_node(struct domain *d, struct kernel_info *kinfo, struct dt_device_node *node, p2m_type_t p2mt) @@ -3038,7 +2745,7 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo, return -EINVAL; } - res = handle_device_interrupts(kinfo->d, node, true); + res = map_device_irqs_to_domain(kinfo->d, node, true); if ( res < 0 ) return res; diff --git a/xen/arch/arm/include/asm/domain_build.h b/xen/arch/arm/include/asm/domain_build.h index 34ceddc995..b9329c9ee0 100644 --- a/xen/arch/arm/include/asm/domain_build.h +++ b/xen/arch/arm/include/asm/domain_build.h @@ -4,8 +4,6 @@ #include #include -int map_irq_to_domain(struct domain *d, unsigned int irq, - bool need_mapping, const char *devname); int make_chosen_node(const struct kernel_info *kinfo); void evtchn_allocate(struct domain *d); diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 19dc637d55..6cda3e4039 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -165,6 +165,15 @@ void device_tree_get_reg(const __be32 **cell, uint32_t address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); +int handle_device(struct domain *d, struct dt_device_node *dev, + p2m_type_t p2mt); + +int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, + bool need_mapping); + +int map_irq_to_domain(struct domain *d, unsigned int irq, + bool need_mapping, const char *devname); + int map_range_to_domain(const struct dt_device_node *dev, uint64_t addr, uint64_t len, void *data); diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index b6d9f018c6..fccf98f94e 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -1847,12 +1847,12 @@ int dt_count_phandle_with_args(const struct dt_device_node *np, * @allnextpp: pointer to ->allnext from last allocated device_node * @fpsize: Size of the node path up at the current depth. */ -static unsigned long __init unflatten_dt_node(const void *fdt, - unsigned long mem, - unsigned long *p, - struct dt_device_node *dad, - struct dt_device_node ***allnextpp, - unsigned long fpsize) +static unsigned long unflatten_dt_node(const void *fdt, + unsigned long mem, + unsigned long *p, + struct dt_device_node *dad, + struct dt_device_node ***allnextpp, + unsigned long fpsize) { struct dt_device_node *np; struct dt_property *pp, **prev_pp = NULL; From patchwork Fri Sep 1 04:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 47711CA0FE6 for ; Fri, 1 Sep 2023 05:00:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594216.927476 (Exim 4.92) (envelope-from ) id 1qbwGU-0003Qq-Ce; Fri, 01 Sep 2023 05:00:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594216.927476; Fri, 01 Sep 2023 05:00:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGU-0003Qf-9a; Fri, 01 Sep 2023 05:00:14 +0000 Received: by outflank-mailman (input) for mailman id 594216; Fri, 01 Sep 2023 05:00:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGS-0001Hn-ES for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:12 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20606.outbound.protection.outlook.com [2a01:111:f400:7e88::606]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 6cde6eb5-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:10 +0200 (CEST) Received: from CY8PR10CA0035.namprd10.prod.outlook.com (2603:10b6:930:4b::20) by PH7PR12MB8425.namprd12.prod.outlook.com (2603:10b6:510:240::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21; Fri, 1 Sep 2023 05:00:07 +0000 Received: from CY4PEPF0000EE35.namprd05.prod.outlook.com (2603:10b6:930:4b:cafe::27) by CY8PR10CA0035.outlook.office365.com (2603:10b6:930:4b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE35.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:07 +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; Fri, 1 Sep 2023 00:00:06 -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; Thu, 31 Aug 2023 22:00:05 -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; Fri, 1 Sep 2023 00:00:05 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6cde6eb5-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=khGLwmFWZ7/CYopEgb7toFEB4nDktaUmMbocRTHbVkAdv06dcDeM9GF7Hjh1G/cnCXaCFr0EdFbbEFzrZ4gmVq4s16LQAfNOLJ0GzfjNs6olwbhNdYiXAWa/JPRuWs+d5ZCbbkRw9UpZC/f7WXpRO/nWi2xW4CIhL6xW9plm+bubcpzPvsM0vUKjQV3C5ZdrWxYCBbAunpE5KQfLX8niAT1957HyDC2vzrpN4pmAUEscx1H1QXAjhvaOcPSAKKXlf79PAWrfmDeLnt8WrpWRVGMeuSAnz6mSKozRWXrl2R4lOh8eaEs1kiRp1upEyrG31COj6Q8P+s8h+mk72wCRag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N48gpSlC0ul9Dgr5X4IgXaGnFeuJhzDtng9Ayqa//1E=; b=Abc+rUFK2fnnFV6CGoiXJe5fSKWVPnWhTqWzod/O6n3m7/PcE45wnYpoSn0Y/qPmTXZgwOHX1QRtMaG8co2zcjf2qR16kjkIJpnIvy0lNveScXfHD3OMKduM7mT6EIRgSZW7Fc+ILEsDWDO88JQ2b4dbJuL0IAYfpdduTmxKKucqVQ+TnpLWak+xJJO+pm9uTctQmieRLLZVEEBdaNN3GkAPoPQZ9rRdRrr+0vEzQRsR/+nZsfRki4o1WX7oiv3M17nqAIxawU/QmRKTk0iSYIGKrpXhSvxnPBhDEOcKUyEDUferbBrUL8RlVxjMxp9pblR57/CJIIkZSOyVfay3ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N48gpSlC0ul9Dgr5X4IgXaGnFeuJhzDtng9Ayqa//1E=; b=MYmmcPeLu+hSFXuMqC7KptfLXacjjBlenjK8/D7dzEileYMcRJ4q7FI56uKtC4XZdwuh15vvVZUSMWwpyj3oIZAz6TyYgcN+GkrNYPnSQhk4ECpJLzRjUMFbbgFxkMhw8R8PgsEUVManZWpmRGuOws/Q5tWKwdrZ0MHoU+cMqcc= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 04/20] common/device_tree: Export __unflatten_device_tree() Date: Thu, 31 Aug 2023 21:59:31 -0700 Message-ID: <20230901045947.32351-5-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE35:EE_|PH7PR12MB8425:EE_ X-MS-Office365-Filtering-Correlation-Id: c7213844-8e55-40ef-7f25-08dbaaa84fbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rNjol1fFpIq8bEXkGh1N1j41ypf469TxtlaxMskCR+47C45Kbd61wVPj/dWUcnK/y5XZ1eflRemPqQcWKO0ERU3AQDbKOfzsNM34m9nBIHzmuuzFfn1bw7tBEZZBCgZBAA/hjVeorxukW/7wiUtvfDPe74kRd3048Rt0XMSfJlvEVgyPjkidgF0NpbpeQNsA9DWjfFYgD1W4LQT7gYUKoRnqYXqX3ySfE/HyqvrQkaGUSf53nFYYPXowjLoxInl07Cd4GMd0e4IaBmW53ZUhfLj6H5mRdVgBlQVVM8qeUdwht6JsmxoMCNCF1u1f0q99cRsdVcVIDUjNSOXnQ2O0p/GogYphrOupo9jZVptagRqaHf4LLFI8qCQHyY6QM4ZGeegKzZVPsCSz9ygAcNyZ5uuD4s6FTwwcgEyhpPrS4FzrtubV87MNCCI9nljBVG/H8YlD7YCEmgpGZFrCHqbGppXbMHPcU2sT/Frevpqwzk1oRlBOGeJOm9vLz2yezjxLjsFHv366diC+FCxC5B3xXf1UqA8RGr4kZtVCv/pL2Jo/dcQgpkxYpLZCfzBr+/0OQyRK6pp4fsaBdVWKN/rFSDixWhWxKj+vA7EEoXf02fpc0OGlTiAozU1+ifyq7AxBed5QIjTBc8B/ssAjIXqVpnC0tlRENGk5chTCWsWAvxfEOiH/OwDBpPH+nuGqacpp75dbdcE4cA+5V2zKIYGLwV0q4JLHOv4Bu16FPUzSeZCdcToXi5MFlDw7JxyKDR4N5qFxgCOPWNkwA4uDcMH9Fw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(346002)(39860400002)(396003)(376002)(136003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(40470700004)(46966006)(82740400003)(356005)(6666004)(40460700003)(36756003)(86362001)(81166007)(36860700001)(40480700001)(47076005)(2616005)(1076003)(2906002)(426003)(336012)(26005)(83380400001)(478600001)(8936002)(70586007)(70206006)(54906003)(8676002)(4326008)(44832011)(5660300002)(41300700001)(6916009)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:07.0878 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c7213844-8e55-40ef-7f25-08dbaaa84fbb 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: CY4PEPF0000EE35.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8425 Following changes are done to __unflatten_device_tree(): 1. __unflatten_device_tree() is renamed to unflatten_device_tree(). 2. Remove __init and static function type. The changes are done to make this function useable for dynamic node programming where new device tree overlay nodes are added to fdt and further unflattend to update xen device tree during runtime. Signed-off-by: Vikram Garhwal Acked-by: Julien Grall --- Changes from v7: Update the commit with why unflatten_device_tree() is changed. Move function documentation to device_tree.h --- --- xen/common/device_tree.c | 19 +++---------------- xen/include/xen/device_tree.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index fccf98f94e..b8ef1c7ae2 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2082,20 +2082,7 @@ static unsigned long unflatten_dt_node(const void *fdt, return mem; } -/** - * __unflatten_device_tree - create tree of device_nodes from flat blob - * - * unflattens a device-tree, creating the - * tree of struct device_node. It also fills the "name" and "type" - * pointers of the nodes so the normal device-tree walking functions - * can be used. - * @fdt: The fdt to expand - * @mynodes: The device_node tree created by the call - * - * Returns 0 on success and a negative number on error - */ -static int __init __unflatten_device_tree(const void *fdt, - struct dt_device_node **mynodes) +int unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes) { unsigned long start, mem, size; struct dt_device_node **allnextp = mynodes; @@ -2234,10 +2221,10 @@ dt_find_interrupt_controller(const struct dt_device_match *matches) void __init dt_unflatten_host_device_tree(void) { - int error = __unflatten_device_tree(device_tree_flattened, &dt_host); + int error = unflatten_device_tree(device_tree_flattened, &dt_host); if ( error ) - panic("__unflatten_device_tree failed with error %d\n", error); + panic("unflatten_device_tree failed with error %d\n", error); dt_alias_scan(); } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 1d79e23b28..a518310a62 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -178,6 +178,20 @@ int device_tree_for_each_node(const void *fdt, int node, */ void dt_unflatten_host_device_tree(void); +/** + * unflatten_device_tree - create tree of device_nodes from flat blob + * + * unflattens a device-tree, creating the + * tree of struct device_node. It also fills the "name" and "type" + * pointers of the nodes so the normal device-tree walking functions + * can be used. + * @fdt: The fdt to expand + * @mynodes: The device_node tree created by the call + * + * Returns 0 on success and a negative number on error + */ +int unflatten_device_tree(const void *fdt, struct dt_device_node **mynodes); + /** * IRQ translation callback * TODO: For the moment we assume that we only have ONE From patchwork Fri Sep 1 04:59:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DFD80CA0FE1 for ; Fri, 1 Sep 2023 05:00:34 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594219.927492 (Exim 4.92) (envelope-from ) id 1qbwGV-0003jP-Ld; Fri, 01 Sep 2023 05:00:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594219.927492; Fri, 01 Sep 2023 05:00: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 1qbwGV-0003fK-D6; Fri, 01 Sep 2023 05:00:15 +0000 Received: by outflank-mailman (input) for mailman id 594219; Fri, 01 Sep 2023 05:00:13 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGT-0000Nr-S6 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:13 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20623.outbound.protection.outlook.com [2a01:111:f400:7e8b::623]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6ee03a18-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:13 +0200 (CEST) Received: from CY8PR10CA0035.namprd10.prod.outlook.com (2603:10b6:930:4b::20) by PH0PR12MB7960.namprd12.prod.outlook.com (2603:10b6:510:287::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.23; Fri, 1 Sep 2023 05:00:08 +0000 Received: from CY4PEPF0000EE35.namprd05.prod.outlook.com (2603:10b6:930:4b:cafe::f8) by CY8PR10CA0035.outlook.office365.com (2603:10b6:930:4b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:08 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE35.mail.protection.outlook.com (10.167.242.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:08 +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; Fri, 1 Sep 2023 00:00:07 -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; Fri, 1 Sep 2023 00:00:06 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6ee03a18-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fer7V9bgsZezmk7sLvUNhLb2F5rHjZWEIodmeTyFRqLQFsa0Xgnub3lKFNS1p0Cr+qBmkDPXKi9I72vzwcOJXsG/6dgNQIsWq15mlbjQcseTwBim11Pmi0cqpAm8ZSsuUFfO1nN/HsW3kTPq94E/6GrPytMM8ZhNmXZEjWp+PQQv0rMydsEuptI9Kt7LxracVohpECy+5BkyrPEpCd/SVcSQERLYgPiEVWxoWdtUXOJx3xCA/I/KvWJVLxcQlhrl7y/jVcrsoN7qS8YiIbIAS+2RxVcJVJ//9QZYC2w0OZ/dF2W1czc8LGaRRs4K8T4wY3mQLIfh64GQ9yyYiMa7FA== 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=WEDXsWkF8KTl41RuBhMPUNVpLR2NQqTU90/MTcE+TTg=; b=R/4Z7WAaxAOtorxN0qm9Aj1EdheOveY8ml1avt+hPhWkYSete4xqQZWieozQ8l8m+E6yQKyZfDJXjIstpoZyp2ZgrVbcQJBmWWotBdQEYA4XOTvwlVyHFiF1l4fZ6N+6cYW9ORFo3dfe1h4AYoTkl/bs+bM3Pg4gHRkBRRW2CW83uysEt9zh2VZ+51Glk49o8G9lFy4NpOnQ1cVr27W4mklYXmHTppnKy2YRiAtoQ2fHxuSjY6LnzY4hrJ797Z5s/bgIcbdH7Gz99mDXLKyc2c4z6Y+CpOlhh3E8nTmXooBhT42g3ynkQJiUWZEAMzghBFtNiIOJcPbYZ4W6cDjW3A== 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=WEDXsWkF8KTl41RuBhMPUNVpLR2NQqTU90/MTcE+TTg=; b=rD+TE4z2LQoLK2QcgfhUy68fXEYEfptN48CcIUoAuzxOa3YV+SO52NVonEWxkKxoAtAIszgjfuEXUWpyFcHB7+NjcbpoEi8KCtpYrwqlMHE8VUIeCw/JSj6dkMnS10oD10HFQ0vW9AezzyEMmVCKdvebRMoI976/tbR77NE3QM4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Henry Wang , Community Manager , Andrew Cooper , George Dunlap , "Jan Beulich" , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v11 05/20] xen/arm: Add CONFIG_OVERLAY_DTB Date: Thu, 31 Aug 2023 21:59:32 -0700 Message-ID: <20230901045947.32351-6-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE35:EE_|PH0PR12MB7960:EE_ X-MS-Office365-Filtering-Correlation-Id: cf7d6b30-57f5-4933-74e3-08dbaaa85094 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fjvd3bTZ0iBsyKsEHnsSmd0ddGLKFm4IbbHonWpt8EYuyQUgSuJSBOiiYqLWwbJB0Njhw5tK08f+a4TRM6FfTtPAbIe7iQD+1MUpueojxo5Wwgbp3oOxFRKf/yoz6IzWZbfu5uNtZk0kKAj9sEu3n2+vd+KYPuDBhyzc1yW3vf9tSPlrEjh9vMAMmsOvuUzX88qzeeL8h+Hp5C+tlrIYAJv6gm3UP25bStSr3dcCRCQvkxcVDBLapsSSVQ2A92aOIWwK/nBivOw7g+QxpisbolvNoQRDYGCKXU1LgBK0mzPI4Im5AtlJK/PUCi6ocOLBMY7VvEyUGV7sw37m9cIgm82QXRCKizeSOHcbmhOf1dJ6gY5T+1GvMf6LPcSGrQEFpXdMjwf3P1bqqP7rOkYEJ36xprwE/M73j6JRb75tgn8De6ffbFl0zDD4d/xDOnN6Xs35lT+TIb2+h++CiUnMxX+ZY/z6DT+xUgRvmDsksLMkgnGq2sccLQbYGC7+YcUFOHsF48ZG4T0wibGWVdSHy9mE40yWD5ZeS5gmMnkhy5XFb2nAUih+QaNNGWKzGQWebTjbTlm+aShYWRXE1Mvt8aBUdNR3TqFdMDq8p+BQ+HruqnNpjszp9MDWpnhFPYqASfBsW9ryiZG6c6n9dXy+gHhJWnXAgRSV+fDizuYaYpcOFzK8PjkdDDNYO0traVYuRbZaf732SxuZv2jZ0kks8azBC48gWgoOzDYvCbNNnmyL/yOq67SD3bH/iqIQ7HtBmVRwZf496t0REJMEJ7FZ/A== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(346002)(376002)(39860400002)(396003)(82310400011)(451199024)(1800799009)(186009)(36840700001)(46966006)(40470700004)(81166007)(478600001)(6666004)(2616005)(1076003)(82740400003)(356005)(36860700001)(54906003)(47076005)(336012)(426003)(83380400001)(26005)(70586007)(70206006)(6916009)(2906002)(44832011)(5660300002)(8676002)(40460700003)(41300700001)(316002)(7416002)(40480700001)(8936002)(36756003)(86362001)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:08.5097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf7d6b30-57f5-4933-74e3-08dbaaa85094 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: CY4PEPF0000EE35.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7960 Introduce a config option where the user can enable support for adding/removing device tree nodes using a device tree binary overlay. Update SUPPORT.md and CHANGELOG.md to state the Device Tree Overlays support for Arm. Signed-off-by: Vikram Garhwal Acked-by: Henry Wang Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v9: Fix style. Changes from v7: Add this feature as "experimental support" in CHANGELOG.md --- --- CHANGELOG.md | 2 ++ SUPPORT.md | 6 ++++++ xen/arch/arm/Kconfig | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2516526589..24636b8eaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - On Arm, add suport for Firmware Framework for Arm A-profile (FF-A) Mediator (Tech Preview) - Add Intel Hardware P-States (HWP) cpufreq driver. + - On Arm, experimental support for dynamic addition/removal of Xen device tree + nodes using a device tree overlay binary (.dtbo). ### Removed - On x86, the "pku" command line option has been removed. It has never diff --git a/SUPPORT.md b/SUPPORT.md index 6ce0ec29b0..3461f5cf2f 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -855,6 +855,12 @@ xen/arch/arm/tee/ffa.c for limitations. Status: Supported +### Device Tree Overlays + +Add/Remove device tree nodes using a device tree overlay binary (.dtbo). + + Status, ARM: Experimental + ### ARM: Guest ACPI support Status: Supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 57bd1d01d7..650aca99ac 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -92,6 +92,11 @@ config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC && !ARM_32 +config OVERLAY_DTB + bool "DTB overlay support (UNSUPPORTED)" if UNSUPPORTED + help + Dynamic addition/removal of Xen device tree nodes using a dtbo. + config HVM def_bool y From patchwork Fri Sep 1 04:59:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9D778CA0FE6 for ; Fri, 1 Sep 2023 05:11:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594265.927586 (Exim 4.92) (envelope-from ) id 1qbwRB-0002Fy-C4; Fri, 01 Sep 2023 05:11:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594265.927586; Fri, 01 Sep 2023 05:11: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 1qbwRB-0002Fn-9D; Fri, 01 Sep 2023 05:11:17 +0000 Received: by outflank-mailman (input) for mailman id 594265; Fri, 01 Sep 2023 05:11: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 1qbwGZ-0001Hn-Nl for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:19 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2062a.outbound.protection.outlook.com [2a01:111:f400:fe5a::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 711858fd-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:18 +0200 (CEST) Received: from CYZPR12CA0021.namprd12.prod.outlook.com (2603:10b6:930:8b::28) by SA1PR12MB8095.namprd12.prod.outlook.com (2603:10b6:806:33f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Fri, 1 Sep 2023 05:00:14 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:8b:cafe::c5) by CYZPR12CA0021.outlook.office365.com (2603:10b6:930:8b::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:00:08 -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; Thu, 31 Aug 2023 22:00:07 -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; Fri, 1 Sep 2023 00:00:07 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 711858fd-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dccIBgjs7bq4UBoNXojMJajOOXWXcHlEyTdhA3hVTib0XBKFCIVs4pxWDfeSi8+QjFNvftDnvueKA2qiY/yi6MxhGsWEzfaOssQVev0CnZ1YMyxAU8J8aNUZbc/RQqVpRKATE8Q6TVxiPOXxZWelaHhVNCDZ1g06sRnG9ke9qpLNp2zyo/ZVfO51NGz0PWYO5x3Lfh1dvB7hgIGE9xBdKh6waeUNVEAg1yDjoHbIk4UCks2kYfH1qBjBU0UccmRcUfwpmzm/eVzJ+O6UBcmUWUgoRq+ct2tLetoN6ETHr3Iub1P5QbK1sYWnWUG58psjqMYNNelksEsEzl+sMcHeCQ== 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=CsdQVgIk8lVXC89MYuh1VnOveoGXyF73E8F+D6Hyd5QFEZzR4ZVXyVl+Hqtm8pLirV24+Xm2mS714GLY8rI7obimhTGjUaHQul8GjarEXcyTW/2ZfTPftCSeOMZRSjoUS9/SCqk9TamXAvjRg8xZrIA37jgEKaAuDJvsNCwptZIzZqcbZyn2qqcacS6zpvNWa/QtJSw8fRHvmjoPhCiBTzj95NjSxPQrfvogSuqL/lErU9/tt56kTs5lyzhNUBT5499uN7Xck5wi2ZreZ2oXkyyDgyUmkfCnqAzdhY41oc+YIK0NY07xaQFJK3oQHQFFPZryxaNnZ/J5gEZuUM0D0A== 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=W2atpgT1FseznPwSfTMWMqm7HLlAHsEsuWu3PrHxODHX8pzoU5i7j/zfmE4vYipMHtG1lHq38++uI7bxS6YfxA80PYLa0tHv4plCgJePRCmGx7mTO3CY7OysGH4vbM3dHwFlSN42jXEVzdTsWtzDGFiDvjXrEZhyMNVpRt4egv8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 06/20] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB. Date: Thu, 31 Aug 2023 21:59:33 -0700 Message-ID: <20230901045947.32351-7-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|SA1PR12MB8095:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e215ad4-03cb-439f-5fd8-08dbaaa853ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SjM3TMUhecCY3pwIcpuRuDVYJmZ8YlmU12LwyewhTk7vAUYAO4tZLlb5HCSgxjMwAjCWweDV1Z3q08QmvwuR1Ykj835122qwEIbki9wzmiMQ3zlbQgw/cZsZvj+fpZ7Su5keY2Cgr66c2VhDwfbDI7pmRexvpezyQdd4iSr703OjChpUeOFgt6DInctulVHztG2NO1Ek8Sj8wtROn7lzu3mzkl/xYoa6Kiw35ecqankbznAQwbjQKjtiqPxzuT1QnVWbfwi5ytTNlAVb7lS/Kq+laoetKKUq5XahTx+KwHZZQP6mJlFqnqi+TeqqMdRXjxRkFl2+uYHRjvll42vMFVRHW0mGB0bmkrRJKGNCqAtHVthk9oiYA4wdLea2plrF4M7BMIyYnEHVe1DQbaGL8npvXeqtgaDqaKSEgCc9PHqm3/CNM3MIN938DMrzls/CA+ZObJb3SijSw+MZksEhYlVTGO6ocUTOUHWN0Ebk/ZMnNdyyO7HX7gxi1FgmdAY/80QPYn+qlOnKza9XWpdidT7dVxegpbuEDF0YRCfHCDm4nDERelY5tt+PASqFHmsYnuW8vAV9DB7P0njFoVEv5Frgpuj6maeWQzGF0qL5AYEN2cDmx6QR9rcTyCnYvwhialFI1DTA5PFu5sPtHZCggUJrC3btZOw8lN0T/gWU/t1/8ikVDs1M9EFEHchQXQAkVrurmXZt/6AbGCavWYW87kECSyP5W6Z4mPVHlyMIS3oNqWbAILiU4B75eCoSiHXv+nAD3XlqIeeirSu8uiMsPg== 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)(136003)(376002)(396003)(39860400002)(1800799009)(186009)(82310400011)(451199024)(36840700001)(40470700004)(46966006)(356005)(81166007)(82740400003)(8936002)(6666004)(70206006)(70586007)(54906003)(478600001)(316002)(41300700001)(426003)(40460700003)(44832011)(86362001)(8676002)(1076003)(36756003)(26005)(2616005)(83380400001)(47076005)(6916009)(4744005)(40480700001)(36860700001)(2906002)(336012)(5660300002)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:13.6996 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e215ad4-03cb-439f-5fd8-08dbaaa853ac 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: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8095 This is done to access fdt library function which are required for adding device tree overlay nodes for dynamic programming of nodes. Signed-off-by: Vikram Garhwal Acked-by: Julien Grall --- xen/common/libfdt/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xen/common/libfdt/Makefile b/xen/common/libfdt/Makefile index 75aaefa2e3..d50487aa6e 100644 --- a/xen/common/libfdt/Makefile +++ b/xen/common/libfdt/Makefile @@ -1,7 +1,11 @@ include $(src)/Makefile.libfdt SECTIONS := text data $(SPECIAL_DATA_SECTIONS) + +# For CONFIG_OVERLAY_DTB, libfdt functionalities will be needed during runtime. +ifneq ($(CONFIG_OVERLAY_DTB),y) OBJCOPYFLAGS := $(foreach s,$(SECTIONS),--rename-section .$(s)=.init.$(s)) +endif obj-y += libfdt.o nocov-y += libfdt.o From patchwork Fri Sep 1 04:59:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C198CA0FE1 for ; Fri, 1 Sep 2023 05:00:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594221.927520 (Exim 4.92) (envelope-from ) id 1qbwGY-0004fd-Jl; Fri, 01 Sep 2023 05:00:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594221.927520; Fri, 01 Sep 2023 05:00:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGY-0004ed-BX; Fri, 01 Sep 2023 05:00:18 +0000 Received: by outflank-mailman (input) for mailman id 594221; Fri, 01 Sep 2023 05:00:16 +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 1qbwGW-0000Nr-J3 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:16 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20609.outbound.protection.outlook.com [2a01:111:f400:fe59::609]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 705d405d-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:15 +0200 (CEST) Received: from DM6PR17CA0012.namprd17.prod.outlook.com (2603:10b6:5:1b3::25) by IA1PR12MB8335.namprd12.prod.outlook.com (2603:10b6:208:3fa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 05:00:12 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:5:1b3:cafe::af) by DM6PR17CA0012.outlook.office365.com (2603:10b6:5:1b3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21 via Frontend Transport; Fri, 1 Sep 2023 05:00:12 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:12 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:00:09 -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; Thu, 31 Aug 2023 22:00: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; Fri, 1 Sep 2023 00:00:08 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 705d405d-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KCl9i6TtPsq/DJI5XK9ViXY58FauOFMr3COHviRussWdhIYG3dxLlw/Ml5k6CVXPLv13gxZAMwgKhd9jS1F2Gn3ynQQOVUh0CUeiUehFLiAaCtuZiR+oXEs7Kn25W52IFRLyNLkI3ewoyG8mgTW1KQBRgvLuJrY62a7JiQtSSIhh3F0WwVCkxVd+MUlsmj9b/ySao8lG3gqvVhfJrZdPp0etuP40qJ9/OJCwDoR+n4dNUa+H/hGZvX+1u/JZbjfC4qpdE9keiITz8FSMogMQ8A/vuxrCeNUfW0PzlYfs7z44QXuXdnlTKmrqkMGK/70/O5QMrPZhQyXOnRcqc26S+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=653u6xWPNriUED+G4weH7ZKsZbL2O1CzT4XNOpC6uN4=; b=DNO5DspXD8xqALCd8PD9NjZbjozw4TAfdZRh6/8Kdyi5c78HKFuYzEL6Wo0TrtoeIBhs2KNyQGBxsx15bC7Pc8SxWt+1scQeHfL4DBzyBjBu6xcI2zCpgWxaFuL/1RdL98zYD7Peuned7qClQd8/qjPv5w2wrFsoZztLfCr4SGmrvFZ2Cf4GybSNQfp4/wmJdV14MJtJWSjR1yznB+keClSA9TmgrxNSOcvgOsOV4GMhan6ROn/hfptqNi7h1fv5bkHHc5LJtRN4xypQiZ7Co/nuxfJD0VpPXKESJzkZi6rPnhFw9r0JnzaNoV0fVIzjbz2eSIMjmBWY3ch+YMFX5A== 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=rnPAmua7d6KsHdyvHeK68uuH73Yp+VA1p/96eBgTQsN1So9VvOzqrqDHS7VKhAb+++V7UjoL27uqaBnqzLr1WSbQoR7EXVhjduBOcVnIHTMAPQFJ82DjyWYQGYKxrPjBeF7YZI29TXvTxxmOz70HE99j8X6uKY78oR3WD//DBSQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Vikram Garhwal , "David Gibson" Subject: [XEN][PATCH v11 07/20] libfdt: overlay: change overlay_get_target() Date: Thu, 31 Aug 2023 21:59:34 -0700 Message-ID: <20230901045947.32351-8-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|IA1PR12MB8335:EE_ X-MS-Office365-Filtering-Correlation-Id: eca93473-b53b-4023-7f57-08dbaaa852c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dRa8JPLYr9vTsXeECeb0xUrVHRGndnqunTidwwZ/98vY0aNtOsuxmoq0KUXfq7hGc+x0mDCuWh02j0UyVjnjVu9RYfMEnElREBzqMeazD4VUWes2SMKYx42SUKcfOLz3DE8wFNIy+Ckrxg5Ss7C5Ww9SNuK2/zYKZQ92ZRqiI21d4zEUOsjoLxtG5IoGB5TXyssy1RiaItIRFXtY89mBYcc7f+bnDe+JUHXZAq321vvsZGrMq3MUQDpsUS7IXYtDcH531egc3sd2uegHUs5ChdE8a+6ghZmESWYp2Sp20uH0SGRoislITKC/8PVTJVkMPsU2t6hlXcegluetV+qqKcu1qoNE+gF2opaxWkGDwSzU9ogwN4UzB1rXAZGrTXK+R28kPr8XBgqHjcs4QtISHFcjL88eddr2Xw4FTSOvRWjulKy+5utlYFY1anF9Sn1v898MSjt9tM6XT8IciazqFzw/Zuy4/azR/kfgNdkmfJbEY0Yfbx3Kv6zbPZfU9c6AOH5s0Im7j6ybOSf6PCrxcj6FB2Eat7KFCgmMr38VGE0mWaoCim6TQSDSVxESp08FGPKAtTOCoHecbVUm2Y98p3BF9tb/kjy9g4JpcQBGEJg5+z4Q3tv3g8iUIXwwKlf4P6inzCzS+xxM9HhemcNRGdJcQeZ+WImzkGxXRvu8G66AOJyCaNfOUbjhjV3SmJ/MKPmtwiiHkjmxeQ3PNHZNhUj9gXSGYDKnRN4C6B1u/Z8YNRy1x4HnbJkUW16zVuck2tig2fra2DjK3ElLUKPkJw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(39860400002)(136003)(396003)(82310400011)(186009)(1800799009)(451199024)(40470700004)(46966006)(36840700001)(40480700001)(82740400003)(36756003)(41300700001)(336012)(426003)(26005)(1076003)(40460700003)(54906003)(356005)(70586007)(70206006)(81166007)(83380400001)(316002)(6916009)(478600001)(6666004)(2906002)(5660300002)(86362001)(44832011)(8936002)(2616005)(36860700001)(8676002)(47076005)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:12.2128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eca93473-b53b-4023-7f57-08dbaaa852c9 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: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8335 Rename overlay_get_target() to fdt_overlay_target_offset() and remove static function type. This is done to get the target path for the overlay nodes which is very useful in many cases. For example, Xen hypervisor needs it when applying overlays because Xen needs to do further processing of the overlay nodes, e.g. mapping of resources(IRQs and IOMMUs) to other VMs, creation of SMMU pagetables, etc. Signed-off-by: Vikram Garhwal Message-Id: <1637204036-382159-2-git-send-email-fnu.vikram@xilinx.com> Signed-off-by: David Gibson Origin: git://git.kernel.org/pub/scm/utils/dtc/dtc.git 45f3d1a095dd Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Reviewed-by: Henry Wang Acked-by: Juline Grall --- xen/common/libfdt/fdt_overlay.c | 29 +++++++---------------------- xen/common/libfdt/version.lds | 1 + xen/include/xen/libfdt/libfdt.h | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/xen/common/libfdt/fdt_overlay.c b/xen/common/libfdt/fdt_overlay.c index 7b95e2b639..acf0c4c2a6 100644 --- a/xen/common/libfdt/fdt_overlay.c +++ b/xen/common/libfdt/fdt_overlay.c @@ -41,37 +41,22 @@ static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) return fdt32_to_cpu(*val); } -/** - * overlay_get_target - retrieves the offset of a fragment's target - * @fdt: Base device tree blob - * @fdto: Device tree overlay blob - * @fragment: node offset of the fragment in the overlay - * @pathp: pointer which receives the path of the target (or NULL) - * - * overlay_get_target() retrieves the target offset in the base - * device tree of a fragment, no matter how the actual targeting is - * done (through a phandle or a path) - * - * returns: - * the targeted node offset in the base device tree - * Negative error code on error - */ -static int overlay_get_target(const void *fdt, const void *fdto, - int fragment, char const **pathp) +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp) { uint32_t phandle; const char *path = NULL; int path_len = 0, ret; /* Try first to do a phandle based lookup */ - phandle = overlay_get_target_phandle(fdto, fragment); + phandle = overlay_get_target_phandle(fdto, fragment_offset); if (phandle == (uint32_t)-1) return -FDT_ERR_BADPHANDLE; /* no phandle, try path */ if (!phandle) { /* And then a path based lookup */ - path = fdt_getprop(fdto, fragment, "target-path", &path_len); + path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len); if (path) ret = fdt_path_offset(fdt, path); else @@ -638,7 +623,7 @@ static int overlay_merge(void *fdt, void *fdto) if (overlay < 0) return overlay; - target = overlay_get_target(fdt, fdto, fragment, NULL); + target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); if (target < 0) return target; @@ -781,7 +766,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) return -FDT_ERR_BADOVERLAY; /* get the target of the fragment */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; @@ -803,7 +788,7 @@ static int overlay_symbol_update(void *fdt, void *fdto) if (!target_path) { /* again in case setprop_placeholder changed it */ - ret = overlay_get_target(fdt, fdto, fragment, &target_path); + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); if (ret < 0) return ret; target = ret; diff --git a/xen/common/libfdt/version.lds b/xen/common/libfdt/version.lds index 7ab85f1d9d..cbce5d4a8b 100644 --- a/xen/common/libfdt/version.lds +++ b/xen/common/libfdt/version.lds @@ -77,6 +77,7 @@ LIBFDT_1.2 { fdt_appendprop_addrrange; fdt_setprop_inplace_namelen_partial; fdt_create_with_flags; + fdt_overlay_target_offset; local: *; }; diff --git a/xen/include/xen/libfdt/libfdt.h b/xen/include/xen/libfdt/libfdt.h index c71689e2be..fabddbee8c 100644 --- a/xen/include/xen/libfdt/libfdt.h +++ b/xen/include/xen/libfdt/libfdt.h @@ -2109,6 +2109,24 @@ int fdt_del_node(void *fdt, int nodeoffset); */ int fdt_overlay_apply(void *fdt, void *fdto); +/** + * fdt_overlay_target_offset - retrieves the offset of a fragment's target + * @fdt: Base device tree blob + * @fdto: Device tree overlay blob + * @fragment_offset: node offset of the fragment in the overlay + * @pathp: pointer which receives the path of the target (or NULL) + * + * fdt_overlay_target_offset() retrieves the target offset in the base + * device tree of a fragment, no matter how the actual targeting is + * done (through a phandle or a path) + * + * returns: + * the targeted node offset in the base device tree + * Negative error code on error + */ +int fdt_overlay_target_offset(const void *fdt, const void *fdto, + int fragment_offset, char const **pathp); + /**********************************************************************/ /* Debugging / informational functions */ /**********************************************************************/ From patchwork Fri Sep 1 04:59:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D681CA0FE6 for ; Fri, 1 Sep 2023 05:11:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594260.927546 (Exim 4.92) (envelope-from ) id 1qbwR3-00016u-2P; Fri, 01 Sep 2023 05:11:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594260.927546; Fri, 01 Sep 2023 05:11:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwR2-00016n-UE; Fri, 01 Sep 2023 05:11:08 +0000 Received: by outflank-mailman (input) for mailman id 594260; Fri, 01 Sep 2023 05:11:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGY-0001Hn-6H for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:18 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on20602.outbound.protection.outlook.com [2a01:111:f400:7eab::602]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7032be93-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:16 +0200 (CEST) Received: from CY5PR15CA0006.namprd15.prod.outlook.com (2603:10b6:930:14::9) by DM4PR12MB7719.namprd12.prod.outlook.com (2603:10b6:8:101::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 05:00:13 +0000 Received: from CY4PEPF0000EE32.namprd05.prod.outlook.com (2603:10b6:930:14:cafe::fb) by CY5PR15CA0006.outlook.office365.com (2603:10b6:930:14::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE32.mail.protection.outlook.com (10.167.242.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:12 +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; Fri, 1 Sep 2023 00:00:09 -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; Fri, 1 Sep 2023 00:00:09 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7032be93-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K89iQoFiEFSf0bqsEWd6uzDbDH/mfon3zokUzk7FcE5tydUT7CV2KTJCCNIoRxdh+biJMEworTi+m6W8DMbAuPmvOqyzTu0dUFssyIDTseJEoxNXoOBNfj5N4KQaNnpWGRkl57bGjDR6EDUI94FHEw5xc4ZPyB9ZxQDz/mOLD4nF+tw596aYs+vOE0g8ufwuky6IMGkSPLco6pIrH+JQ0wkV3eVpoFESilzvVKf5L7a1AklSyk/1Zb4CaF8SXCRrcQIS665uj2TDW6JfpbZaeoVDAEeeErRs7xC7bIT0T0YYGs69HqLe4f/82bFxf6ykuLJdiqnvTJ5KZMMM+bPmLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JIgawtLTJDYclMTRziV6+ukrPXqF+ozH3iEpHoQmI6c=; b=Z/w6AMB1A8+3B8OzZy71juf5K2/KzMsJm9oYqLZ8O+L/oDZlG/7sShD2Wly+C+W7nuVyrJB3wAnVKTLGwTS++aETrA5w3qsgPV1/iRSEPpHX1u7kKXGxWmnyoAaNiREsnRaXNibnbvsYr9CjmQoItBgHvGD9O/DMvR6X4gGAdanfxCsAgmsULkopBmuhGAqBR4CgFtSkSZ1KSMGc7LLKN6Ink75Zni3RQt2gpptQs5dutGrgkX3nSfV3BINO1VmBhC6dDPvlcPrvFAIW05+lTJKyjNs1eI0zyT7WkzPNFYLGaqWfzve/0iQLLUM3Rd/kImKWRxAQyIFPfAYc99K1kQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JIgawtLTJDYclMTRziV6+ukrPXqF+ozH3iEpHoQmI6c=; b=27/PiAWhzMgPwauVdDVn7zfLiIo9Cv5Q9YNhIqBX4P8uZFZFKP7QtkREDNRvBidQewuifvZ8K75ZbhALEWJp0tQ8pw/n4s7SzIt6layvuNh6MxijnTSjGpjP6IBy5OedqvPGnSl2WBPQDdTiRhpDFgkiIuZY94Ns+0/OlkcpsYI= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 08/20] xen/device-tree: Add dt_find_node_by_path_from() to find nodes in device tree Date: Thu, 31 Aug 2023 21:59:35 -0700 Message-ID: <20230901045947.32351-9-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE32:EE_|DM4PR12MB7719:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b0c34c5-a605-4f58-26ca-08dbaaa85346 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zc79sxi8OJuMpM/rX1j8GrYByhB1hj7WWoCMsp3RbOOX+bXhThN4pjrApz2IjjympqCdghaJxB0egtrbY71LAWbka010sSJXdvckhG3Fo+XMXUTeaUOJR4ukFPXRrlGR4Bzzb7WL+5cknsH1imujtNJZnQHZceqd9eoK1Yzg1+rw1Cppiw6FGYE/PTfDOvpeLFDNZimyDTmqbqDLjWQvyYqV01MEyhpAcmw16FwazGgcWWwrt314tp+MNhkaX1L0INyw5PVYV78QyOoyHJKvppO3JlND9pWsO3ISLg23ojUPlpkTIogTbct2apIMBaalntVxNa2YM2SJ/d4eAcbT5wcgDPpkZ73PkWXjcFfsoySxNBJfTsVXaJFXluk9Vt9QmptG+NTmzZ0PR+IsWicRnfrW1yf3wpYVhdkccPaIom2I8LQVJmJ7anaCJqy49jmB6BFX0P3WTBB61Mlgi5Kr5XvPHqXFgn1TYI+SPdyUeXa2QJ5gb+0d/yDprTN7fg6X9LJTQ9P27r60Sw4U0HGDnI7EfEKQYG4tMAN+3eiG4RSDkBdRG3LlaX7+SzjLwwV2OKcVSAMuJeye5SPp24o59TeWIqYjcOlmKCGgxGolzGfCUvM4F53Mkulri+3ufp44wpmAm4MpDCAuehb+FA5DGYcBr8mBv0vXam7F5gZ9Jt+jvyfkioKcvNZyr02k0S3aWSr3+naRLSrYW4ahcETsjlKUIzkzX/1jwMWINYHFtqu98+AjGafcVxwB+QFQQwmVVe37imDXkDI8vmp43vfPlvRhLOxUMVujO+YFm9TEkMk= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(39860400002)(136003)(396003)(82310400011)(186009)(1800799009)(451199024)(40470700004)(46966006)(36840700001)(40480700001)(82740400003)(36756003)(41300700001)(336012)(426003)(26005)(1076003)(40460700003)(54906003)(356005)(70586007)(70206006)(81166007)(83380400001)(316002)(6916009)(478600001)(6666004)(2906002)(5660300002)(86362001)(44832011)(8936002)(2616005)(36860700001)(8676002)(47076005)(4326008)(37363002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:12.9672 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b0c34c5-a605-4f58-26ca-08dbaaa85346 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: CY4PEPF0000EE32.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7719 Add dt_find_node_by_path_from() to find a matching node with path for a dt_device_node. Reason behind this function: Each time overlay nodes are added using .dtbo, a new fdt (memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, we need to find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. Thus we need this function to search for node in different unflattened device trees. Also, make dt_find_node_by_path() static inline. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Fix commit message with right function name. Changes from v9: Fix indentation issues. Changes from v7: Rename device_tree_find_node_by_path() to dt_find_node_by_path_from(). Fix indentation. --- --- xen/common/device_tree.c | 5 +++-- xen/include/xen/device_tree.h | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index b8ef1c7ae2..f38f51ec0b 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -358,11 +358,12 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, return np; } -struct dt_device_node *dt_find_node_by_path(const char *path) +struct dt_device_node *dt_find_node_by_path_from(struct dt_device_node *from, + const char *path) { struct dt_device_node *np; - dt_for_each_device_node(dt_host, np) + dt_for_each_device_node(from, np) if ( np->full_name && (dt_node_cmp(np->full_name, path) == 0) ) break; diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index a518310a62..44d315c8ba 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -570,13 +570,26 @@ struct dt_device_node *dt_find_node_by_type(struct dt_device_node *from, struct dt_device_node *dt_find_node_by_alias(const char *alias); /** - * dt_find_node_by_path - Find a node matching a full DT path + * dt_find_node_by_path_from - Generic function to find a node matching the + * full DT path for any given unflatten device tree + * @from: The device tree node to start searching from * @path: The full path to match * * Returns a node pointer. */ -struct dt_device_node *dt_find_node_by_path(const char *path); +struct dt_device_node *dt_find_node_by_path_from(struct dt_device_node *from, + const char *path); +/** + * dt_find_node_by_path - Find a node matching a full DT path in dt_host + * @path: The full path to match + * + * Returns a node pointer. + */ +static inline struct dt_device_node *dt_find_node_by_path(const char *path) +{ + return dt_find_node_by_path_from(dt_host, path); +} /** * dt_find_node_by_gpath - Same as dt_find_node_by_path but retrieve the From patchwork Fri Sep 1 04:59:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E478CA0FE8 for ; Fri, 1 Sep 2023 05:11:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594263.927569 (Exim 4.92) (envelope-from ) id 1qbwR9-0001ai-2Q; Fri, 01 Sep 2023 05:11:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594263.927569; Fri, 01 Sep 2023 05:11: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 1qbwR8-0001YZ-O7; Fri, 01 Sep 2023 05:11:14 +0000 Received: by outflank-mailman (input) for mailman id 594263; Fri, 01 Sep 2023 05:11: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 1qbwGZ-0000Nr-Q1 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:19 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20619.outbound.protection.outlook.com [2a01:111:f400:7e83::619]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 71b98988-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:19 +0200 (CEST) Received: from CYZPR12CA0006.namprd12.prod.outlook.com (2603:10b6:930:8b::22) by SJ2PR12MB9114.namprd12.prod.outlook.com (2603:10b6:a03:567::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Fri, 1 Sep 2023 05:00:13 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:8b:cafe::8) by CYZPR12CA0006.outlook.office365.com (2603:10b6:930:8b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.27 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:12 +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; Fri, 1 Sep 2023 00:00:10 -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; Fri, 1 Sep 2023 00:00:09 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 71b98988-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dr5mBEqYlmHRjj1Im62kymab8EtDJgUc9wueBAxgJggdavG6pukTli+nCzSbI5Q6FA2GLnPQUIot67oWzOQpZwVpReDHGeIvb4K/GEzz1q14g0q4Twn6YiJQTDF06s/otON5Ln3qwkecY+sNOS04BHyRbUS5UFBP1w43USpHQWfqkGIyV96bDOTvE5X6AIpqatYps9eoJwk4hPs5P5hVAfsiTYE3LAfEpjEbKAyuhHoxpPq+DMZOUqxOoTd0lrqYBuE6vV6hRmALEjJS2yVv7oF0TbQUw49zOp025yUlllJX+uGKXZY5iP1J40K/JsgubDXQMRj7AvLADlTTbiLAgg== 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=WEOO1lNx/ONa1/nR//BBauJgW25xq4jXfGIfpWrsOLc=; b=k7b2W91nzQFMU6ESbBF1UvA30Fkm9sybCmpyb5lFZ80KKO1HwtFI1E9VnUMwHzy50A6GTMU38YAyCeT71hP+gB9ILxXcnk+3iziYcucEvLJpAD+0Wl6xXRWgAmbQpF3QPcP+YQ/mW1eA+QsKcaE3RTyoLeHR2sFw/gqqCl4Ag1FTGeqb9pdcp5FrAZv6ugeRAEKhrsd3tc7vP6+/ynEPhsH02lHJPFSakDNKycu8jNCdHE/NpBJ1AokSX/3NdmvFxbBzgHhPBHY6P1gfnisbJBvMcmYoWt8GgcQ+bl5Uyny2BWlw6dl/o6LkNQJCQPgAu06wNqYmy0TmGiEaJXygqw== 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=WEOO1lNx/ONa1/nR//BBauJgW25xq4jXfGIfpWrsOLc=; b=ARAI2mK0eudpSwKfxdvwb45RpyJcgH1O3rmFk9pR2uXMUVvTZvlQ01qJOJlgchFyAWvrjf443iWb5wEVbaM1//LH9jTc+BMkP5iYT9qu51uf1HjbXlQANPf9ddHW3CTwSlx/q+GmyAfU6wdnHKZQK5QvnItW389ysmoekB00zpM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Date: Thu, 31 Aug 2023 21:59:36 -0700 Message-ID: <20230901045947.32351-10-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|SJ2PR12MB9114:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c03ea69-01cf-4958-6586-08dbaaa85330 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7Kd2SX98lWwPVNPqKtEGuM59PRkBCGCpq4TclAqNXgwR3DoBSVEJk+9CQKAsxvrg5w9cciVfOX2E9U6gOdVZtI2HoizZL2anUJKo4pD4fuBvc4seBDuCZC8YMNiwgwQiDZEzBDK8h6J6Xt1E3hwmOBQGp4h5tvva/cE1Tk12hCpvbzV3mF6jQ70XUkX/8eSVs5kk2o/Iyo/VsSwl/piXi97ec4sq+0BClfARgnudKkaVolxyv+J1afcAoFLrI1uIFxmee734KSuKwJfuwTITY+GbCDuyQzebnMTBj6YDqG5G+ooxDM8Y3KKkYoPJXxlxeIeblmrgXUjUVTWMant222Y3Ce8j0nqGVn+ffPl8qx1sqXuMx5xRGwe7cMp9xcT3WZ0RhRkbfw0SC04wxl1iu3P4zFH44ETpxkmYW/L1m6QwKMVb46C5p7KhhGXASfg45GESOr59Lbk+C/LQl36ufayEbPA3conJ0O+1kw+tBcEXhxo+YGRLRKkYlFx7ELxpzjtm0TuWCQl8tGwL5hupL5uMICeLURrSf74RJoj/b6wMHhoJBvGSFNG5Fb4nX3k6FAZ9JbXgqZY83CUWvVmb7QgYez37++xuTrKQ2Sy791WYhyBAkL2XOov5D/o10o03AeUch+nDQ616a4g5142CvaNTE8zQ80UfuXsviP2KNJp2iaDiyrB2EaEZsqjlhiNMwHxOxzYwdyGp4Bqmlh3bRXU+xl+2heuYrh4nUUhDnUyRWVvmOtSHD6ZRn/2ipKf6dgu31oECYJeyKVVvbmCBXA== 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)(82310400011)(451199024)(1800799009)(46966006)(40470700004)(36840700001)(36756003)(2616005)(40460700003)(40480700001)(83380400001)(4326008)(44832011)(86362001)(5660300002)(41300700001)(36860700001)(8936002)(8676002)(6666004)(426003)(336012)(1076003)(26005)(47076005)(478600001)(82740400003)(2906002)(356005)(81166007)(70206006)(70586007)(6916009)(316002)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:12.8871 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c03ea69-01cf-4958-6586-08dbaaa85330 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: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9114 Rename iommu_dt_device_is_assigned() to iommu_dt_device_is_assigned_locked(). Moving spin_lock to caller was done to prevent the concurrent access to iommu_dt_device_is_assigned while doing add/remove/assign/deassign. Follow-up patches in this series introduces node add/remove feature. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Move spin_lock before iommu_dt_device_is_assigned_locked() call. Rebase the patch with latest Xen. Changes from v9: Make iommu_dt_device_is_assigned_locked() static and delete header. Move dtdevs_lock before iommu_dt_device_is_assigned_locked(). Changes from v7: Update commit message. Add ASSERT(). --- --- xen/drivers/passthrough/device_tree.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 3c0322c797..a7d86a20a0 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -83,16 +83,16 @@ fail: return rc; } -static bool iommu_dt_device_is_assigned(const struct dt_device_node *dev) +static bool iommu_dt_device_is_assigned_locked(const struct dt_device_node *dev) { bool assigned = false; + ASSERT(spin_is_locked(&dtdevs_lock)); + if ( !dt_device_is_protected(dev) ) return 0; - spin_lock(&dtdevs_lock); assigned = !list_empty(&dev->domain_list); - spin_unlock(&dtdevs_lock); return assigned; } @@ -225,12 +225,16 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, if ( domctl->cmd == XEN_DOMCTL_test_assign_device ) { - if ( iommu_dt_device_is_assigned(dev) ) + spin_lock(&dtdevs_lock); + + if ( iommu_dt_device_is_assigned_locked(dev) ) { printk(XENLOG_G_ERR "%s already assigned.\n", dt_node_full_name(dev)); ret = -EINVAL; } + + spin_unlock(&dtdevs_lock); break; } From patchwork Fri Sep 1 04:59:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372032 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C127ACA0FE6 for ; Fri, 1 Sep 2023 05:11:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594297.927626 (Exim 4.92) (envelope-from ) id 1qbwRd-0004zo-1j; Fri, 01 Sep 2023 05:11:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594297.927626; Fri, 01 Sep 2023 05:11:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwRc-0004zh-Tw; Fri, 01 Sep 2023 05:11:44 +0000 Received: by outflank-mailman (input) for mailman id 594297; Fri, 01 Sep 2023 05:11:43 +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 1qbwGY-0000Nr-8t for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:18 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061b.outbound.protection.outlook.com [2a01:111:f400:7e8a::61b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 70f13c05-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:17 +0200 (CEST) Received: from DM6PR17CA0006.namprd17.prod.outlook.com (2603:10b6:5:1b3::19) by CY5PR12MB6406.namprd12.prod.outlook.com (2603:10b6:930:3d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.18; Fri, 1 Sep 2023 05:00:13 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:5:1b3:cafe::f1) by DM6PR17CA0006.outlook.office365.com (2603:10b6:5:1b3::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +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; Fri, 1 Sep 2023 00:00:10 -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; Fri, 1 Sep 2023 00:00:10 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 70f13c05-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mS19cTSXN6/r9Wq3MHKmemP8Tf3XLbO8epJyRe/JM/bn4MPKghtxY5uxoVant/2cdUitBSYM2k3RVQxMI8bea1xSd5o/FV/7xo34JBZsQshikFtgwjcxanxgENtuS3LcJKO4iHiGdI1+N1sPIjA4dGZpMbZLROyrasekLDhslAc6i3qzyXR6rgmH8YdhvzxwzpceRNAxMas0EbR6/bOLP8BOZqkeqCmFSHP8gIr4g0TcqL+rGePv6Sedg6seSEn5zR4QS1Zt81Jxkn+nbclNq7yVMjGM1KUF8R2WtRgeriAPvr2myVq1FaWWaJRfWaIJPMB0riNAxJAAaB0ICcXp5Q== 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=fgeWijtmTwTyogLk6WxOUL3kuOmYaDdqs1e6E0a1fkw=; b=PzOsEMnUeFs40RoROJpd2htayQ5BKj0MQK7aqXRM9PLi+71jSxFpknXr1/XyaUrbhJHZaCw3aDrGUIx0sE1Mcc1VOTkvTCCKZxUEer33cjz/uRxb06nuBwSW2C3PHJPR+0rNcCidvEUPfPAX86t+pV2kWWXdeUI7vUwYN/geRECC/xSix8E0D0E2R+tK8XHuWkNNFPuyArBu57DRwo0OWSpNmrSvvEGhwZiRP7WOApQntn/tg+9ijJsSiEOc/Wa3FRdFqm8GqhQAfapTFZO6hB0fjwY9UwUp92mbp7iS5hPD2/oZLPXEx3chTrxsBhi24ELf9BCQcE48AwNep5APQA== 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=fgeWijtmTwTyogLk6WxOUL3kuOmYaDdqs1e6E0a1fkw=; b=jynGNOCY0JLwrjcg1JHg53n+o3xNSiMrb61xmuBS6oqmm5yu247IEfAW6OyMul2zGVwzrK1FGkyCKraC8zm+rhVAsAYN7Q0qRr2muT9I8XtgqnooFwC4XM2soUINLnq/LMe8KDZT3L7qI1ff/GDS3aiVm1fb4JC4yYEkeQyvUp8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 10/20] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Date: Thu, 31 Aug 2023 21:59:37 -0700 Message-ID: <20230901045947.32351-11-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|CY5PR12MB6406:EE_ X-MS-Office365-Filtering-Correlation-Id: 2dbcc140-53e8-4f26-2881-08dbaaa85375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gTFr8QeWxDS82+Ho5lf8reBbi/hfAhBcY4PLg3H/SN78p2cJePkvXwU2vurlPEFj5ICOTQIVsYC7xfXQCiozyyL107I0JyjNL0JaedTbpe4sYmprnociFobA9k2eVUOsfSHjOxlCtqz7rAkbac3PMtTH27UIRVmn9gUYXY92ZBl3+5gbCEbPqKFlvNpYvahtUK4IB+TqAqQ2a95Nhgoi34fhh8aPlEmTXnArIO44rxlx7agFNNHPFrc/BxC74A1POKX87MITN4ZqMJWYLTBdkJp+Xdo6kZ4I4jBRRuU88d86/PBExlvxtu1+vPgM6rF06T+7M2i2yPiNGoO22bn3qdNhUNBytBfiQl0DnU0gooypR+gIAWQTzduGMswwTIoiFoPJGThdmOxZoiqp4kFcvk9zp0NQnuTA9oN9YcfHaVoGVYK7xld8UUQN2OSgJslUh7QKTIfiABTYTv5xN+Q2LJ2OCEitBYT2lqAeJAHw9E91qD1vVApVp9VZxyT5B5CE0VxMHargVqOZGESG9Eez9IOmkRZvoUEOK5aLgc9TNVI2J1FBQ+sta/+F+Jt2Q2IeiUFLo+GuOB2MHY1sgKGrj6jRVWbbef15OuFAQ0Y+XcIGmhz2PiK+biJW/fCnHEf9TIErecRA03BlyOAPVVrpuB7uB9Zl3a6+ICQMAlXlurjTRxOnTAice1keAY2MSB1X6sV6R0rpgq5+/nceecdBJyyx/Lvg7HNxpacic3CMsn8QW95PPnzTqmT4CHCzbizBXoHezALiFCYwlwVcBsdxiA== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(376002)(396003)(346002)(39860400002)(1800799009)(186009)(82310400011)(451199024)(40470700004)(46966006)(36840700001)(81166007)(356005)(82740400003)(8936002)(6666004)(70206006)(478600001)(70586007)(54906003)(316002)(41300700001)(40460700003)(44832011)(1076003)(26005)(83380400001)(5660300002)(36756003)(2616005)(2906002)(86362001)(47076005)(8676002)(36860700001)(40480700001)(6916009)(426003)(336012)(4326008)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:13.3379 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2dbcc140-53e8-4f26-2881-08dbaaa85375 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: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6406 Protect iommu_add_dt_device() with dtdevs_lock to prevent concurrent access to add/remove/assign/deassign. With addition of dynamic programming feature(follow-up patches in this series), this function can be concurrently accessed by dynamic node add/remove using device tree overlays. Signed-off-by: Vikram Garhwal Reviewed-by: Luca Fancellu Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v7: Update commit message and fix indent. --- --- xen/drivers/passthrough/device_tree.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index a7d86a20a0..687c61e7da 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -147,6 +147,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( dev_iommu_fwspec_get(dev) ) return 0; + spin_lock(&dtdevs_lock); + /* * According to the Documentation/devicetree/bindings/iommu/iommu.txt * from Linux. @@ -159,7 +161,10 @@ int iommu_add_dt_device(struct dt_device_node *np) * these callback implemented. */ if ( !ops->add_device || !ops->dt_xlate ) - return -EINVAL; + { + rc = -EINVAL; + goto fail; + } if ( !dt_device_is_available(iommu_spec.np) ) break; @@ -190,6 +195,8 @@ int iommu_add_dt_device(struct dt_device_node *np) if ( rc < 0 ) iommu_fwspec_free(dev); + fail: + spin_unlock(&dtdevs_lock); return rc; } From patchwork Fri Sep 1 04:59:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66AF4CA0FE1 for ; Fri, 1 Sep 2023 05:12:08 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594317.927635 (Exim 4.92) (envelope-from ) id 1qbwRt-000660-EP; Fri, 01 Sep 2023 05:12:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594317.927635; Fri, 01 Sep 2023 05:12:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwRt-00065t-BW; Fri, 01 Sep 2023 05:12:01 +0000 Received: by outflank-mailman (input) for mailman id 594317; Fri, 01 Sep 2023 05:11:59 +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 1qbwGZ-0000Nr-4x for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:19 +0000 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2062f.outbound.protection.outlook.com [2a01:111:f400:7eab::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7155dada-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:18 +0200 (CEST) Received: from MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) by CH3PR12MB9024.namprd12.prod.outlook.com (2603:10b6:610:176::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22; Fri, 1 Sep 2023 05:00:14 +0000 Received: from CO1PEPF000044FA.namprd21.prod.outlook.com (2603:10b6:303:8f:cafe::2) by MW4PR03CA0013.outlook.office365.com (2603:10b6:303:8f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.23 via Frontend Transport; Fri, 1 Sep 2023 05:00:14 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000044FA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6768.2 via Frontend Transport; Fri, 1 Sep 2023 05:00:13 +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; Fri, 1 Sep 2023 00:00:12 -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; Thu, 31 Aug 2023 22:00:11 -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; Fri, 1 Sep 2023 00:00:11 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7155dada-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNO8iPyieYQEIv4Pb0LITNx5IHz7P6nm5Ez1dA+zn8SRTuRbGxYAGdyEh4ICZJGvF+w/tYsKr1eCp1I2qyL1HQ3pnjTxazYaxIHvNzXiOLrcJiZZYq58tAqFIoZuh9usv1C+ZwaHqa2g7xU1v6ikFvMBprsn8APMtDoN2h/V4SAYyQnmyaK3J31vQHuqiAjQ7Xw5ZB9HXhToI4M9C/CxuHrw3QFuymFQm+1AedNWcbr7/i+iplMUVaU89YYzA6t8GI4iTBteWLcRysrAUxdMEZf2orA58UvmHrqDSFX/Q1AIa6mp8elGjzexgipT/1JNfFiVs3TSeFw4lSsB5Q8Dng== 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=xshnPL3bDlSXz1SSqrZ2OojIbY+USaVA9VSd3/Ty7gY=; b=Gz3v70KIQfqQT43Am88qqO9mc8Nvl8+3g47znZtYLbQ5okhw3ybDNTAqtTlPpC/NPl+xWTIADyFH/mTwcTTcT8qQOH93btctB0D5fEP7ePWrf7aVFaONzQr762AmB0yeW+IsmTER6NRUJKdwcboslT5xJhHJOgOROsW80Si4QIGul63TWPLuNWqDGCHABl/eUU/pFlUEuw+yH7JV2Tq3iAD19gte1w9zCi8Djd4KR/6QZizVDwefLG+dtrLZGx6wWOHV3SYBxKslt5rjNaGt7a9/pTeKhTLN9hODXDmkt0+d1XWog60C693FkdyXVsQ8VNd/F8MllqwuEVSUsOIFQQ== 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=xshnPL3bDlSXz1SSqrZ2OojIbY+USaVA9VSd3/Ty7gY=; b=4AQy9kWpqTd07rF7thjwCaFi52OgeB8G2KLr9eMxLyhYQivjDIgJssvff50f9IzqhhOcZWwejp35WpBggtKZSthES5HPkey2hPajLegvk++RzSPxQ3MjHf48BdiPJRGZyIWcQD81gYb0jqnSd4iWKE2+vb6Z4jQ1aI4DHbGTtD0= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Jan Beulich , Paul Durrant , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [XEN][PATCH v11 11/20] xen/iommu: Introduce iommu_remove_dt_device() Date: Thu, 31 Aug 2023 21:59:38 -0700 Message-ID: <20230901045947.32351-12-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FA:EE_|CH3PR12MB9024:EE_ X-MS-Office365-Filtering-Correlation-Id: b50ebd9f-22f2-41de-2318-08dbaaa853d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v5cnateb2uNiAYBoNDWZyKBwTnTHdfPsjbJn3MYnsZfArk/CbLhxQIuEXQr1RJ9w+V+POdMwrXj53o8BTVaoVYmO1lIAQ1+LjJ699VzyrLkubZ7VhRB8dWJ8dG3UC5ODid1jVHgd+4TmlZ67otkEeeZR98arF7eTe3C+iYMitgTSbDE7iArb1yb0kOlH8SZlt+g9BGmeJ7HnKRkhVrH+9pOHMWeiamo3ftJxWouBsPqnni8X6F73sJk0DhJJUwac9c5hGT2q7mxNz8pLS0/t41KFF6brGIFOdSxWWwWicCGSPCsNb9NFSkjlqzMicgO/uOdZebDe7WFvi0RFdvGT7myfl3kXaX5rx3PovLfufKEtewhSh1sNdo7+r9JYpP3ULBKHAhWOQM1yJwYjxT3hHbMy50KQVD9Q6/dCTZ4JbA1GiEqKfb/vDBvJT3aNTUPjs1pCILxgiFMv4Yb5CXn9XAAnVS7UnpNlqqj8DYYoXiuDOU2H4rPFz6vLigJHTF4g/JeCZ3gBipPwTgR9bCIkPxE2CRvx9UfeDHRg6JW9L1u8oZ0yN6RwhhwHTwaz+ZmINcWdj581GRpjENaDHLq/f8pfJkDdIssAgWBmreg6HxagjUdtA9WfS+M4iOx9TuTNJSAxkXQNzRHXoL+2uM4zlCtB9OHL3Q5V7A+8C0fifQX819cKsrims8Ietf6qjlUd49xet/9OfbXocymoI62TzphPgV8iXv2NP+9Che6UjsGHz4WB3nsZw+hKti/ey6Nfd1CCmOAshUVz2ZN+fsmfZw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(39860400002)(396003)(346002)(376002)(451199024)(1800799009)(82310400011)(186009)(40470700004)(46966006)(36840700001)(6666004)(2906002)(5660300002)(86362001)(316002)(6916009)(478600001)(2616005)(4326008)(47076005)(8676002)(36860700001)(44832011)(8936002)(26005)(40460700003)(1076003)(82740400003)(40480700001)(41300700001)(426003)(336012)(36756003)(356005)(83380400001)(81166007)(54906003)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:13.8418 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b50ebd9f-22f2-41de-2318-08dbaaa853d5 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: CO1PEPF000044FA.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9024 Remove master device from the IOMMU. This will be helpful when removing the overlay nodes using dynamic programming during run time. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Add comment regarding return values of iommu_remove_dt_device(). Add ASSERT to check if is_protected is removed or not. Changes from v7: Add check if IOMMU is enabled. Fix indentation of fail. --- --- xen/drivers/passthrough/device_tree.c | 43 +++++++++++++++++++++++++++ xen/include/xen/iommu.h | 10 +++++++ 2 files changed, 53 insertions(+) diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 687c61e7da..80f6efc606 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -127,6 +127,49 @@ int iommu_release_dt_devices(struct domain *d) return 0; } +int iommu_remove_dt_device(struct dt_device_node *np) +{ + const struct iommu_ops *ops = iommu_get_ops(); + struct device *dev = dt_to_dev(np); + int rc; + + if ( !iommu_enabled ) + return 1; + + if ( !ops ) + return -EOPNOTSUPP; + + spin_lock(&dtdevs_lock); + + if ( iommu_dt_device_is_assigned_locked(np) ) + { + rc = -EBUSY; + goto fail; + } + + if ( !ops->remove_device ) + { + rc = -EOPNOTSUPP; + goto fail; + } + + /* + * De-register the device from the IOMMU driver. + * The driver is responsible for removing is_protected flag. + */ + rc = ops->remove_device(0, dev); + + if ( !rc ) + { + ASSERT(!dt_device_is_protected(np)); + iommu_fwspec_free(dev); + } + + fail: + spin_unlock(&dtdevs_lock); + return rc; +} + int iommu_add_dt_device(struct dt_device_node *np) { const struct iommu_ops *ops = iommu_get_ops(); diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index a18b68e247..84bd77395e 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -235,6 +235,16 @@ int iommu_add_dt_device(struct dt_device_node *np); int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl); +/* + * Helper to remove master device from the IOMMU. + * + * Return values: + * 0 : device is de-registerd from IOMMU. + * <0 : error while removing the device from IOMMU. + * >0 : IOMMU is not enabled/present or device is not connected to it. + */ +int iommu_remove_dt_device(struct dt_device_node *np); + #endif /* HAS_DEVICE_TREE */ struct page_info; From patchwork Fri Sep 1 04:59:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB479CA0FE6 for ; Fri, 1 Sep 2023 05:10:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594252.927536 (Exim 4.92) (envelope-from ) id 1qbwQP-0000N6-Pz; Fri, 01 Sep 2023 05:10:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594252.927536; Fri, 01 Sep 2023 05:10:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwQP-0000Mz-Ly; Fri, 01 Sep 2023 05:10:29 +0000 Received: by outflank-mailman (input) for mailman id 594252; Fri, 01 Sep 2023 05:10:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGc-0001Hn-KV for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:22 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20624.outbound.protection.outlook.com [2a01:111:f400:fe5a::624]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 72e360b3-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:20 +0200 (CEST) Received: from DM6PR17CA0009.namprd17.prod.outlook.com (2603:10b6:5:1b3::22) by CH0PR12MB5330.namprd12.prod.outlook.com (2603:10b6:610:d5::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.23; Fri, 1 Sep 2023 05:00:14 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:5:1b3:cafe::21) by DM6PR17CA0009.outlook.office365.com (2603:10b6:5:1b3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 05:00:14 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.16 via Frontend Transport; Fri, 1 Sep 2023 05:00:14 +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; Fri, 1 Sep 2023 00:00:12 -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; Fri, 1 Sep 2023 00:00:12 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 72e360b3-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bTSZxqIGX6QUklP7E+2bT/V1IuikQIE7ptoo+pjO/hd1Go0+JvZiGOqh2QD11Qeq9To5cOfeLioLO/L2WEPvabHLtcOhC8fX+JENV1xPYwU9Ls1r9sF3H9YCQtVtSfC5Lgca4oHRzEzDj+nDlL0ChVqnXVddqi9FqmRSk0HhjMppx+A8Qn0u+eYR9K2gbLFVLCUkB15oAiT24/+3MYiNd4S/28D94MZQi7c/ak6zzMS6vVtqlLES7yCtRXiyM6m40N7gQeLodYTBE8ltFTP1zCdFXd6Us5Pa59LCIjTJ5zXVHoKxXPWMG2uj33pF9MkQ8RodIsR9lvJLV9ox20Q7yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=N5Ad07nFyqe3yvUSTljKoScg3IAugPfBscvADFFb2TQ=; b=cfoERg+tJmlDINXCzok+2CY0OCeCSEjzptvM96kFfbMXaRJjGM7zr3+kp03HRbf/5XfXN5TJDkqOF3a80bcPxnEt5+cBOiT2NKhBmjhBe6SbMgK+PD3w4SxofdoD8gpO0+1udy5dn+ilQMG8zlRFavKi84lii1al8V1NKOW1Srt3t6WAB9jXuMpg7tf+0kepteck8tUwmRhVFbxStlRzPso2CqcapRc7VbYlAZOO+QWa7Qta0qDBKNdRcs3Cgxeek78CjkSBLIXaDdfgSIa8BtmkWwmM1HV0K3hahzf2bpWWHy99ir2/D66GNi1WIxQoSso4Zfx0D61REXPj1SLuFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=N5Ad07nFyqe3yvUSTljKoScg3IAugPfBscvADFFb2TQ=; b=qwxtyOjyiw0it9jprvyaGDAx8fvVBChsAjAVNbo9CrfC9gDmtKH0EcHVwKZX+7BEwQNh/uWTu4oWpgeOB8owMRn2ld0ViOfeV26L6ipx1fxE3yDFgr0ff/wltqKEd/svN2gQfPJUS6JZLfC85X2h4w9h1FtPbeLVXgKeZEvhsGM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Rahul Singh , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v11 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops Date: Thu, 31 Aug 2023 21:59:39 -0700 Message-ID: <20230901045947.32351-13-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|CH0PR12MB5330:EE_ X-MS-Office365-Filtering-Correlation-Id: f501a0e5-1e22-4433-c043-08dbaaa853ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L0RiqoHbUAXBiQXKngOBAEYk8huoJjUHKDssVxDMWg0j6Hrilp0n+HYctAR4gw42huHltIQ1EPXD6zZEWCsJyfywkyfSaMbnzz5plYB772Yjm1BRDEeC1CQ56ms3o7b8NQ86vZYp0CjIIj6Lq7py0b0ziSLRp2FXF44y5f9miA6P7AHmgPJYaZzTts3rTfLUJkFyV8+9t+85YRzIiYNGVFt7BRO68qzwQ1uSaFElvDP2HsBb+Ubg4qcBSh6zE/RKXd1NmraABJYOjCYGzIAdwOZxH97WVlIPO3414q5qYu0HWvfFFD6b7mlmjBNt9g48uSCCA/O1iDZ/S7QThuyAn9QeewHf5WvEy7HacT6EI4SfpzdZXINIwXsrPirg+fLTOrKVAhsETfw+CCrauoxqgHmtDeibvSOBbv82EMrFeWgCi6UwmoiqnQaIPkfX3dtrVCqFol6Izn45l2GgdEg52LrT8SvAirtXDu/PZ7Xoq29MzDyZQqDqP2IIy8ygb0zZAYdxPGcxGoS6vt8InsYhFtxTnMi5RIXfMzUs3HeAJb4JMNKkOAQ9azPqLKIuT0J28PoLtpDsLbOfNQa8/QEfiL29Qp0HcJHMpkn51dQg6Qg3zQbTqt9pNxszfTWphoKq5ht3NDH+Wpx9JZew60enARBs7CsIJ8K/QcUAEWzc4vr/DG7Mv2IFIjHLRlZ+Jzv7OTWYXZbmp5LVXFlPb1BG5LxbuyS+L70xudCTvGG/8cQ2llQ4/0qFGRBt/p1H3K/2pnrD8VYaxXb4q67kongdag== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(136003)(346002)(376002)(39860400002)(82310400011)(451199024)(186009)(1800799009)(40470700004)(46966006)(36840700001)(6666004)(478600001)(83380400001)(1076003)(2616005)(336012)(426003)(26005)(2906002)(44832011)(6916009)(54906003)(316002)(41300700001)(70586007)(70206006)(5660300002)(8936002)(8676002)(4326008)(40460700003)(36756003)(40480700001)(47076005)(36860700001)(86362001)(81166007)(356005)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:14.1503 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f501a0e5-1e22-4433-c043-08dbaaa853ee 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: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5330 Add remove_device callback for removing the device entry from smmu-master using following steps: 1. Find if SMMU master exists for the device node. 2. Check if device is currently in use. 3. Remove the SMMU master. Signed-off-by: Vikram Garhwal Acked-by: Stefano Stabellini --- Changes from v9: Remove iommu_dt_device_is_assigned_locked(). Add comment regarding caller holding the locks to protect concurrent access. Changes from v7: Added comments on arm_smmu_dt_remove_device_generic(). --- --- xen/drivers/passthrough/arm/smmu.c | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c index c37fa9af13..71799064f8 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -815,6 +815,19 @@ static int insert_smmu_master(struct arm_smmu_device *smmu, return 0; } +static int remove_smmu_master(struct arm_smmu_device *smmu, + struct arm_smmu_master *master) +{ + if (!smmu->masters.rb_node) { + ASSERT_UNREACHABLE(); + return -ENOENT; + } + + rb_erase(&master->node, &smmu->masters); + + return 0; +} + static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, struct device *dev, struct iommu_fwspec *fwspec) @@ -852,6 +865,32 @@ static int arm_smmu_dt_add_device_legacy(struct arm_smmu_device *smmu, return insert_smmu_master(smmu, master); } +static int arm_smmu_dt_remove_device_legacy(struct arm_smmu_device *smmu, + struct device *dev) +{ + struct arm_smmu_master *master; + struct device_node *dev_node = dev_get_dev_node(dev); + int ret; + + master = find_smmu_master(smmu, dev_node); + if (master == NULL) { + dev_err(dev, + "No registrations found for master device %s\n", + dev_node->name); + return -EINVAL; + } + + ret = remove_smmu_master(smmu, master); + if (ret) + return ret; + + /* Protected by dt_host_lock and dtdevs_lock as caller holds these locks. */ + dev_node->is_protected = false; + + kfree(master); + return 0; +} + static int register_smmu_master(struct arm_smmu_device *smmu, struct device *dev, struct of_phandle_args *masterspec) @@ -875,6 +914,26 @@ static int register_smmu_master(struct arm_smmu_device *smmu, fwspec); } +/* + * The driver which supports generic IOMMU DT bindings must have this + * callback implemented. + */ +static int arm_smmu_dt_remove_device_generic(u8 devfn, struct device *dev) +{ + struct arm_smmu_device *smmu; + struct iommu_fwspec *fwspec; + + fwspec = dev_iommu_fwspec_get(dev); + if (fwspec == NULL) + return -ENXIO; + + smmu = find_smmu(fwspec->iommu_dev); + if (smmu == NULL) + return -ENXIO; + + return arm_smmu_dt_remove_device_legacy(smmu, dev); +} + static int arm_smmu_dt_add_device_generic(u8 devfn, struct device *dev) { struct arm_smmu_device *smmu; @@ -2859,6 +2918,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = { .init = arm_smmu_iommu_domain_init, .hwdom_init = arch_iommu_hwdom_init, .add_device = arm_smmu_dt_add_device_generic, + .remove_device = arm_smmu_dt_remove_device_generic, .teardown = arm_smmu_iommu_domain_teardown, .iotlb_flush = arm_smmu_iotlb_flush, .assign_device = arm_smmu_assign_dev, From patchwork Fri Sep 1 04:59:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52E1FCA0FE6 for ; Fri, 1 Sep 2023 05:12:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594324.927646 (Exim 4.92) (envelope-from ) id 1qbwS1-0006hi-Og; Fri, 01 Sep 2023 05:12:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594324.927646; Fri, 01 Sep 2023 05:12:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwS1-0006hX-Ky; Fri, 01 Sep 2023 05:12:09 +0000 Received: by outflank-mailman (input) for mailman id 594324; Fri, 01 Sep 2023 05:12:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGo-0001Hn-E4 for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:34 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20602.outbound.protection.outlook.com [2a01:111:f400:fe5b::602]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 796f3ef0-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:31 +0200 (CEST) Received: from DM6PR11CA0013.namprd11.prod.outlook.com (2603:10b6:5:190::26) by SJ2PR12MB8010.namprd12.prod.outlook.com (2603:10b6:a03:4c7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Fri, 1 Sep 2023 05:00:27 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:5:190:cafe::eb) by DM6PR11CA0013.outlook.office365.com (2603:10b6:5:190::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:27 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:26 +0000 Received: from SATLEXMB05.amd.com (10.181.40.146) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 1 Sep 2023 00:00:14 -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; Fri, 1 Sep 2023 00:00:13 -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; Fri, 1 Sep 2023 00:00:13 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 796f3ef0-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ABMb5caoFTHdGE90hdcC1LS27NfKX+6tsf9efu9pI6wnqLuVE1Kv7tvadcp7dvGKxttrBSeLVDdHTE5Dv1hbmwMo0DrsTIrGwQNfqRb2NOi8tBB5eifh1UDX/HPRnaQGy4n7ZOOV73s9ULVQ45Nvvhy33JC8pH4yvZKUWEcdaCsxd9NSaJZmYfi/gWWvZ9JTrBwUdmjIJUfZoB+TyuE+tUnM3wgvOi91U1bv2FTZAiAiCS220vSkTWFeO8Yi5h+OioHeCwy/oR+kaPQQ1DxR3KMVSijmHJOpBrLKzkub2yBk/VWsVnzdQolGmnXkdBuIJWzTb8ddXCuJc25umnFB4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=TDhW7f5w3p+/XHERjQf4wWurMSkKNLV2sxdzRwRCMQk=; b=WGEDvkUmdOMpVH14woCHDpQF7a55A2xKmXLfqMGsqtLgXgoaNfryumvI7E4CA1m7vPA+aV23stgIFD/VJ8wJx83SXWnitZbnlrByjrSvhBhU9cQYCLA5hHBxs7ZZ1rUdV7GlkVsCah9W37IVIX4RM+HKEOI9sK98yQVi/MEWHoNwKV21fpRSwd8F5ILX8m8qQDsKo4aKoGNU4kprvheh2vOT3yHJKYi+G1QOu22PsyEd31nb4n9U4edXQPGKlJg9cOb2Z3nq1EcsJwBYJ8dOzg2/Lxk7J1AguufP8zTjcbRwkl2ByNaqhQ7gHvGHWAnNAjZSI32KLPMp300JVdYxew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TDhW7f5w3p+/XHERjQf4wWurMSkKNLV2sxdzRwRCMQk=; b=lmcDpSLY/D7Ar+F1Vtnkm+MbuYRjkAJzvO6MAAUbPAQeBZBkTDsaeo4WgFO/BNvykh/nQyEIVWMfiq2DI/I/+ckPtLux5LhT99QY1h8krn1AUmS8OiaD7ILzDeQMQKMFcxUfagf6eunTEWpGsaQZYGOAsKg9MzSkpPPrOG8E0Cs= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v11 13/20] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Date: Thu, 31 Aug 2023 21:59:40 -0700 Message-ID: <20230901045947.32351-14-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|SJ2PR12MB8010:EE_ X-MS-Office365-Filtering-Correlation-Id: c4adddf8-0b03-43df-a3c5-08dbaaa85b86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PH23t3earyBwOkWZYWC9RGyr/2+0hhZ6KnZIVNcCGvmiKJhUjmWi5sOFrLu1Utue0z5NlwmAZL1MCyXwCTdnUZ6W3ODJcXUPPdQGqMD9AaXhRkUPANgJfRdJ2yP41+U5N6lNzTeQnPefVSf4lY+DB68JfRHuCh0Sv0sFPjKyKKCr8wy96jhKVeFIt+TJhAf9i+pSu0STzYl3dmCd+jRKFDsVQQPSXLt2ZENtz2zT8rzIWrI28RdlkH13vqzqr5g1MljehlOmQI08x1LqaiupkTYOhgKXI/jaYwsXkenOYgUpnUbNQnHCzz7FrWN//ZLRUkbuOC12wWPj8G5l/3bdC2rR9jDsls0hNzLFx3wU9o73qW5IFZrjWbWnUUjpnK0P1iWa+S5V/C3Npq7m6KKW9jKNnOo4hG9vc6YcbZhDQbh4k1kMbAHzyuti2+nzII37zznzdigYWoscd6PTxNgMCwuJ5UUDF+9JFJngr03St9HdySowbWMElVnVfNvDa5ihZH87Fd5X/I8Ra4DPgKlmSCpqm3/ZDQaMjRIdCqi3jRoKB8ISkSPrFbbwlX7OQ+Vb4pQDkW5ylkEJVqA+PIdidHcDbbig1+zbGPxNWhjHRiiuyemsJ43iAUFk1vs+nbh+A9D/Y0dFq2VgE7ex7MMMjpmvjdqW77468+TutfDROzMPtC4yDdehYTfkWxJADEWd+v5IbqIIA5Rs5WH+bG4I4t2sUqly7HWodLhilL2H1j6ouCSVU1hwghFNXGALc9Zgiy7Mp4B1ZGDe/M5g3a61Lw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(136003)(396003)(346002)(1800799009)(451199024)(82310400011)(186009)(36840700001)(40470700004)(46966006)(40480700001)(40460700003)(2906002)(316002)(6916009)(70586007)(70206006)(356005)(82740400003)(81166007)(478600001)(54906003)(5660300002)(8936002)(86362001)(8676002)(4326008)(83380400001)(41300700001)(44832011)(2616005)(36860700001)(47076005)(6666004)(336012)(26005)(1076003)(426003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:26.8741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4adddf8-0b03-43df-a3c5-08dbaaa85b86 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: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8010 Dynamic programming ops will modify the dt_host and there might be other function which are browsing the dt_host at the same time. To avoid the race conditions, we will need to add a rwlock to protect access to the dt_host. However, adding rwlock in device_tree.h causes following circular dependency: device_tree.h->rwlock.h->smp.h->asm/smp.h->device_tree.h To fix this, removed the "#include and forward declared "struct dt_device_node". Signed-off-by: Vikram Garhwal Reviewed-by: Henry Wang Reviewed-by: Michal Orzel Acked-by: Julien Grall --- Changes from v7: Move struct dt_device_node declaration just above arch_cpu_init(). --- --- xen/arch/arm/include/asm/smp.h | 4 +++- xen/arch/arm/smpboot.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index a37ca55bff..4fabdf5310 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -3,7 +3,6 @@ #ifndef __ASSEMBLY__ #include -#include #include #endif @@ -23,6 +22,9 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); extern void noreturn stop_cpu(void); extern int arch_smp_init(void); + +struct dt_device_node; + extern int arch_cpu_init(int cpu, struct dt_device_node *dn); extern int arch_cpu_up(int cpu); extern void arch_cpu_up_finish(void); diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index e107b86b7b..eeb76cd551 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include From patchwork Fri Sep 1 04:59:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BA1DCA0FE1 for ; Fri, 1 Sep 2023 05:11:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594272.927602 (Exim 4.92) (envelope-from ) id 1qbwRM-00033b-9I; Fri, 01 Sep 2023 05:11:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594272.927602; Fri, 01 Sep 2023 05:11:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwRM-00032s-37; Fri, 01 Sep 2023 05:11:28 +0000 Received: by outflank-mailman (input) for mailman id 594272; Fri, 01 Sep 2023 05:11:26 +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 1qbwGn-0001Hn-Ds for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:33 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20612.outbound.protection.outlook.com [2a01:111:f400:fe5b::612]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 79449440-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:31 +0200 (CEST) Received: from CY5PR19CA0085.namprd19.prod.outlook.com (2603:10b6:930:83::9) by IA0PR12MB9010.namprd12.prod.outlook.com (2603:10b6:208:48e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Fri, 1 Sep 2023 05:00:28 +0000 Received: from CY4PEPF0000EE34.namprd05.prod.outlook.com (2603:10b6:930:83:cafe::d5) by CY5PR19CA0085.outlook.office365.com (2603:10b6:930:83::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.36 via Frontend Transport; Fri, 1 Sep 2023 05:00:27 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE34.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:27 +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; Fri, 1 Sep 2023 00:00:26 -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; Thu, 31 Aug 2023 22:00:14 -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; Fri, 1 Sep 2023 00:00:14 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 79449440-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gfZo7KZhLvVDthkBZjr4z6Is4q0UFGKOKCsNb7xrK4Fwae0YZVdxoxMLJfLpo8ZJGLS1mh5Li4Pg9uScT1XDX6lncr8SKwR4W97xjcDX8h9C4Ye4iZVv+IBmyGFk1fiCnYXbBDIIhGrKaSZOxzJy3BQB6dlwDX7GuYVSYBgSSF+WdYoZFLyvPURP1DS2zHUHK0uGOeDQ+WTf+Dg7sxxsPZAYPy0WMccra136hmHqTTRmnRYY7CTjidR0Kxgyhvw2a6Xj1mgfzaFal+bsf8z5SEihMhps2x7HoWP70dD0Fx3/TJSLovsHbMuethM4SnFQErbB+nO0fSxwOIVnOZYsCg== 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=jHjqTJ1UaUiiJx0UNTFIv0uoiG+uui8ndyNCkHPJ/Yg=; b=hllnZopp2EQJWo2615T2uaFsDmL5eLMT7FrWXxWQBt6ZoTrTtsGT5LVIqhF2BqBfKHrY449+NnU6mvt9fdKIcsvhHLRo5hInDiHyHpZJJ9tY7wJxxwaijyj3DOHe025XUcJSrs1rNKyCCWJXYsatK+n4hwGh4B7kDXVti+1XXoMZOCOLmXLG5H9hX40VkAFWXszhElZ723hNwRFbf3hxyScVI/lUrXREaN2zo0BRJGd8M8v7k7C3LXqAH/RW23JwXVc+4k/ZVpauemyVyf5vkw9pd1KgLodOPKW0TQPpNIseslpMtovYFfsjwZDDBp35KtZBZ1ld7SkXSuo4QxPt/w== 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=jHjqTJ1UaUiiJx0UNTFIv0uoiG+uui8ndyNCkHPJ/Yg=; b=lIhXTlYpnCmkiAq4Ev2XrDZ4zRP/KDrT9XzxToTYNam+PHW44FerL77yKXwpqEvf4udMSj8jGO8wwNpZR05TNcsYf7NCITR6ZDG2w2yD4K/jBrSa7oWE8+gulHRuRsMHrQtjevnEyEVP6WKR3NRfCL6PsrkSQQl2TLbRMlIlhsQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 14/20] common/device_tree: Add rwlock for dt_host Date: Thu, 31 Aug 2023 21:59:41 -0700 Message-ID: <20230901045947.32351-15-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE34:EE_|IA0PR12MB9010:EE_ X-MS-Office365-Filtering-Correlation-Id: 27587e69-0acf-4bcb-d40b-08dbaaa85be7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q7xsWm37SwrKiJXG/zuGJxpK9OucMlZD9lbw8WhXjfBSQlOXraC6Kw4ZSRnhb1HEZZTvWzRmNYnmc8yj0mwEMWqFzoq1h7PKpuq9EXaNt3WhJPzLH2T5Tyt6NoJ2QkE+SXgylBCEArLWBO+K7IfwwZLQe74j6L90CfjGWseXaR9dSEvVTIqgIH8Qz+EiXekFdT+RgczF34dnWpLlCilQLxmZy4MfwR4Q186iV09W2kVivILohrLDTzRo0orZky8SZnBouyYAAwCvMDnHhWSKvljO4358RR3+ywLFdi84RaWLNiQ7apYaUlm/7oYRcw8TGlULciZiurqXlaQKwydgsnFZTVad5LJr/cquATsNhpsYXSwrteWaaeeGTnNbhlqILiEGyjmE2/5AqEB3mmH66oKsCb6MV9CuX4CTIBxvdGnux8CvmuTc2CS6a4ci/ToCJH6QfMzVzlH1FMy8lk00iKHpBbzs+9EWhBFZqYQhQAgqgZSqyeiEKysQ+VRd/vVv3OuvoyOa2z4X0Ta2AFWNCoVrxN/vbRVXOdNh3U5Dx7lyYyw9QN+PM7xsg9JstxzYH88nbFg7fODZjmvduUhmbo9Tsv0Ay+EHRnptM3bWBkIHcz3BS5F7xvPymB7wxzQPoFFUN9x+4g3beqRi+WTzilnGcrrZDiiA3UZdRFWRPEN+fOaN5WTQWTAf/BtbYxzNYsrLSgGPnVkUP6J45zRQVwxeo2reoRcZFhjc6QJa6I+nieMz+2PZzx3GZoDritwhWt1u4F67M7sNhOn4x8n4vQ== 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)(376002)(39860400002)(136003)(451199024)(1800799009)(186009)(82310400011)(40470700004)(46966006)(36840700001)(70206006)(2906002)(36756003)(5660300002)(86362001)(44832011)(40460700003)(82740400003)(356005)(81166007)(40480700001)(36860700001)(47076005)(4326008)(8676002)(336012)(41300700001)(8936002)(83380400001)(426003)(1076003)(2616005)(26005)(316002)(54906003)(6666004)(478600001)(70586007)(6916009)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:27.5267 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27587e69-0acf-4bcb-d40b-08dbaaa85be7 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: CY4PEPF0000EE34.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB9010 Dynamic programming ops will modify the dt_host and there might be other functions which are browsing the dt_host at the same time. To avoid the race conditions, adding rwlock for browsing the dt_host during runtime. dt_host writer will be added in the follow-up patch for device tree overlay functionalities. Reason behind adding rwlock instead of spinlock: For now, dynamic programming is the sole modifier of dt_host in Xen during run time. All other access functions like iommu_release_dt_device() are just reading the dt_host during run-time. So, there is a need to protect others from browsing the dt_host while dynamic programming is modifying it. rwlock is better suitable for this task as spinlock won't be able to differentiate between read and write access. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel --- Changes from v10: Add ASSERT for iommu_assign_dt_device() and iommu_add_dt_device(). Changes from v9: Update commit message and fix indentation. Add ASSERT() for iommu_deassign_dt_device() and iommu_remove_dt_device(). Fix code styles. Remove rwlock_init in unflatten_device_tree() and do DEFINE_RWLOCK in device-tree.c Changes from v7: Keep one lock for dt_host instead of lock for each node under dt_host. --- --- xen/common/device_tree.c | 1 + xen/drivers/passthrough/device_tree.c | 28 +++++++++++++++++++++++++-- xen/include/xen/device_tree.h | 7 +++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index f38f51ec0b..b1c2952951 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -31,6 +31,7 @@ dt_irq_xlate_func dt_irq_xlate; struct dt_device_node *dt_host; /* Interrupt controller node*/ const struct dt_device_node *dt_interrupt_controller; +DEFINE_RWLOCK(dt_host_lock); /** * struct dt_alias_prop - Alias property in 'aliases' node diff --git a/xen/drivers/passthrough/device_tree.c b/xen/drivers/passthrough/device_tree.c index 80f6efc606..1f9cfccf95 100644 --- a/xen/drivers/passthrough/device_tree.c +++ b/xen/drivers/passthrough/device_tree.c @@ -31,6 +31,8 @@ int iommu_assign_dt_device(struct domain *d, struct dt_device_node *dev) int rc = -EBUSY; struct domain_iommu *hd = dom_iommu(d); + ASSERT(system_state <= SYS_STATE_active || rw_is_locked(&dt_host_lock)); + if ( !is_iommu_enabled(d) ) return -EINVAL; @@ -62,6 +64,8 @@ int iommu_deassign_dt_device(struct domain *d, struct dt_device_node *dev) const struct domain_iommu *hd = dom_iommu(d); int rc; + ASSERT(rw_is_locked(&dt_host_lock)); + if ( !is_iommu_enabled(d) ) return -EINVAL; @@ -113,6 +117,8 @@ int iommu_release_dt_devices(struct domain *d) if ( !is_iommu_enabled(d) ) return 0; + read_lock(&dt_host_lock); + list_for_each_entry_safe(dev, _dev, &hd->dt_devices, domain_list) { rc = iommu_deassign_dt_device(d, dev); @@ -120,10 +126,14 @@ int iommu_release_dt_devices(struct domain *d) { dprintk(XENLOG_ERR, "Failed to deassign %s in domain %u\n", dt_node_full_name(dev), d->domain_id); + read_unlock(&dt_host_lock); + return rc; } } + read_unlock(&dt_host_lock); + return 0; } @@ -133,6 +143,8 @@ int iommu_remove_dt_device(struct dt_device_node *np) struct device *dev = dt_to_dev(np); int rc; + ASSERT(rw_is_locked(&dt_host_lock)); + if ( !iommu_enabled ) return 1; @@ -177,6 +189,8 @@ int iommu_add_dt_device(struct dt_device_node *np) struct device *dev = dt_to_dev(np); int rc = 1, index = 0; + ASSERT(system_state <= SYS_STATE_active || rw_is_locked(&dt_host_lock)); + if ( !iommu_enabled ) return 1; @@ -249,6 +263,8 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, int ret; struct dt_device_node *dev; + read_lock(&dt_host_lock); + switch ( domctl->cmd ) { case XEN_DOMCTL_assign_device: @@ -289,7 +305,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, } if ( d == dom_io ) - return -EINVAL; + { + ret = -EINVAL; + break; + } ret = iommu_add_dt_device(dev); if ( ret < 0 ) @@ -327,7 +346,10 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, break; if ( d == dom_io ) - return -EINVAL; + { + ret = -EINVAL; + break; + } ret = iommu_deassign_dt_device(d, dev); @@ -342,5 +364,7 @@ int iommu_do_dt_domctl(struct xen_domctl *domctl, struct domain *d, break; } + read_unlock(&dt_host_lock); + return ret; } diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 44d315c8ba..a262bba2ed 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -18,6 +18,7 @@ #include #include #include +#include #define DEVICE_TREE_MAX_DEPTH 16 @@ -218,6 +219,12 @@ extern struct dt_device_node *dt_host; */ extern const struct dt_device_node *dt_interrupt_controller; +/* + * Lock that protects r/w updates to unflattened device tree i.e. dt_host during + * runtime. Lock may not be taken for boot only code. + */ +extern rwlock_t dt_host_lock; + /** * Find the interrupt controller * For the moment we handle only one interrupt controller: the first From patchwork Fri Sep 1 04:59:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED339CA0FE1 for ; Fri, 1 Sep 2023 05:12:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594328.927666 (Exim 4.92) (envelope-from ) id 1qbwS5-0007Mp-Gw; Fri, 01 Sep 2023 05:12:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594328.927666; Fri, 01 Sep 2023 05:12: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 1qbwS5-0007Mc-CI; Fri, 01 Sep 2023 05:12:13 +0000 Received: by outflank-mailman (input) for mailman id 594328; Fri, 01 Sep 2023 05:12:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGr-0001Hn-Er for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:37 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062c.outbound.protection.outlook.com [2a01:111:f400:7e8a::62c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7afcc685-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:33 +0200 (CEST) Received: from DM6PR11CA0005.namprd11.prod.outlook.com (2603:10b6:5:190::18) by PH7PR12MB6740.namprd12.prod.outlook.com (2603:10b6:510:1ab::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.18; Fri, 1 Sep 2023 05:00:28 +0000 Received: from CY4PEPF0000EE3D.namprd03.prod.outlook.com (2603:10b6:5:190:cafe::25) by DM6PR11CA0005.outlook.office365.com (2603:10b6:5:190::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 05:00:28 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3D.mail.protection.outlook.com (10.167.242.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:28 +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; Fri, 1 Sep 2023 00:00:27 -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; Fri, 1 Sep 2023 00:00:26 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7afcc685-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eimMht/BIbCOaf4Ab03L1N9il/aUNePqR6JzU/ebpvo5l3ZqoHsY6GBTzE5LwUS7a8tZnpH7AC/dEfu6J6gREhdBHncIlIXyNq6cfhlKpKQSTDMw/BFcLLiPXm+E3cTyC3YPVHctmyeITnHB50DY1C3vAnYxiea98uI/+60kH6AknCm9ETcvSojiVTN5AwR0yibyG2UNk0fe9Q/whb0PIv277QYw+CmSjaCWKjBtjrh8AA0hwUGm2t5jYcqbTSdrHrAO4wiRrvPTx1IBXghBM47oXU9Buo7u8XCt5bX2nD47i/6wjnfLzRFidg0wP/sh4CCakrrRt7KnLHrRdxEsgQ== 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=y81wVIygGPJh0Ydvh/80eu9K2SfjYwEv+GVsIT2ZkAI=; b=WscnBkmj25k8sndAXPLH4wTyEd6XndZui0vF8E8+RY9LaOQYpwfVU+/N1lVo9D3AG9bOxyaUrLZzNyecRt8JDVK6rZTVx9nswzwiC8DVHebHGzdMqNJl9j9q/ZJYnDDRv15TUQTo/3RB3Zbmo3wDJsXF2boWYdIJQotjcq8wtHvsyPUc/Y5jgfmtRus9shNy6SKMr4CJK4e7xQ5J2JRiEk48FGHFVZvKoPovKdLtQMweCuuRxrfMi+/a243g3INwIFqfRal35G+5fiF5xkN2lYAJ3R7J2pZEfmIdouTwVwXnfCeRWRMCUK6kEi/4bg4JvlnOj0BPXvNyZ0Iid9DKcQ== 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=y81wVIygGPJh0Ydvh/80eu9K2SfjYwEv+GVsIT2ZkAI=; b=NBpNAVxSMHznO3GuBJYlw/rXwu2ca+1x8hBrDZMr19ZHjkZDur6kVO5EtkPcT0TYlXFeDzZDnOPwFtOkUaTZCT9phnnLEFX5noDDWreS4Tqn/zo2RgFaOUWLhjOOgVjL6apXkvxWcTqvKkvhk/JlIcFXyTvMzZvvf9F4/092qRM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v11 15/20] arm/asm/setup.h: Update struct map_range_data to add rangeset. Date: Thu, 31 Aug 2023 21:59:42 -0700 Message-ID: <20230901045947.32351-16-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3D:EE_|PH7PR12MB6740:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a558305-c284-4366-c0af-08dbaaa85c66 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xQ5sVp8HbXryancRsEbIf5Q07n0zB/qU6d56xod1I0uBQmu84z0MyC21x5lkWgfFUYyfp0xypEGfQZBiUU/eGUy6k+TD3ss4Xf74PfpR+OGq/ybXGYgyjU0ik0ukD6fHLh1iRiliyHxF2SAfrZvXBD20TBDumszO9YDBN0HXbCW+MIgNx3pm9fWfAV4FWMpU5xXpIDviDwKXgGwCf++EOExbJCzlnkBQ8yzAGh9Ozso16sAZpLEcPYhm+uHu2Lp0iQruMvOUhNO2Nnyz7a0bvqKTMq9VUp2fooKwNEKUVI8VUZmtXsgcw/pkHdWT0XBx8m/zOe5XRCYZMUINZbwnwdHWftEZftqNV76/QGXi+oRdy5AHX/zlQzG4eTor5kqZHVHqs2a/AfiekLxCVsD8fgC/myF5SDctlWadz1yGhkgRvW7COIXNiaCqAU0iXcPLGr8KJF17EdjQrzwQxdVmRpW9jBcivIMsyNkhBT2OfzQqlnvQP29bVH7sa5tlp2AMwR/+ZepyGEoSMUQWbiWpKjBUftWMtkZNshymH0hb8qHgNWiatvTpb2T//w8MXk5q63tALNDEb1+mZNOj7PTx6S7uTCeaHGKJG0Se2SEKZqJpwJf7lKaGRWOQbjAuHYtTmYyd+BhfI7jjcZUJLz4pPrri0+KMwVkof54sN6iOyEOHFsrdFiw2QBQ+daFxjbJfyyKEOyTtjhLVLeiQ8MiSSsdT85QdTbqGwTn7IuQMPivCfzReP9rRFqfiGYkBkVAcNI+GfMQZHYeXjY9Jx3aTRw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(376002)(346002)(136003)(186009)(82310400011)(451199024)(1800799009)(36840700001)(46966006)(40470700004)(26005)(1076003)(426003)(336012)(47076005)(36860700001)(5660300002)(44832011)(6666004)(82740400003)(356005)(478600001)(8936002)(8676002)(81166007)(4326008)(86362001)(2616005)(83380400001)(70586007)(54906003)(2906002)(6916009)(36756003)(316002)(70206006)(41300700001)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:28.3428 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a558305-c284-4366-c0af-08dbaaa85c66 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: CY4PEPF0000EE3D.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6740 Add rangesets for IRQs and IOMEMs. This was done to accommodate dynamic overlay node addition/removal operations. With overlay operations, new IRQs and IOMEMs are added in dt_host and routed. While removing overlay nodes, nodes are removed from dt_host and their IRQs and IOMEMs routing is also removed. Storing IRQs and IOMEMs in the rangeset will avoid re-parsing the device tree nodes to get the IOMEM and IRQ ranges for overlay remove ops. Dynamic overlay node add/remove will be introduced in follow-up patches. Signed-off-by: Vikram Garhwal Reviewed-by: Michal Orzel Acked-by: Stefano Stabellini --- Changes from v10: Replace paddr_to_pfn(PAGE_ALIGN()) with paddr_to_pfn_aligned(). Change data type of irq. fix function change for handle_device(). Remove unnecessary change .d = d in mr_data. --- --- xen/arch/arm/device.c | 43 +++++++++++++++++++++++++------- xen/arch/arm/domain_build.c | 4 +-- xen/arch/arm/include/asm/setup.h | 9 ++++--- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c index 327e4d24fb..1f631d3274 100644 --- a/xen/arch/arm/device.c +++ b/xen/arch/arm/device.c @@ -165,6 +165,15 @@ int map_range_to_domain(const struct dt_device_node *dev, dt_dprintk(" - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n", addr, addr + len, mr_data->p2mt); + if ( mr_data->iomem_ranges ) + { + res = rangeset_add_range(mr_data->iomem_ranges, + paddr_to_pfn(addr), + paddr_to_pfn_aligned(addr + len - 1)); + if ( res ) + return res; + } + return 0; } @@ -178,10 +187,11 @@ int map_range_to_domain(const struct dt_device_node *dev, */ int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, - bool need_mapping) + bool need_mapping, + struct rangeset *irq_ranges) { unsigned int i, nirq; - int res; + int res, irq; struct dt_raw_irq rirq; nirq = dt_number_of_irq(dev); @@ -208,17 +218,24 @@ int map_device_irqs_to_domain(struct domain *d, continue; } - res = platform_get_irq(dev, i); - if ( res < 0 ) + irq = platform_get_irq(dev, i); + if ( irq < 0 ) { printk(XENLOG_ERR "Unable to get irq %u for %s\n", i, dt_node_full_name(dev)); - return res; + return irq; } - res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev)); + res = map_irq_to_domain(d, irq, need_mapping, dt_node_name(dev)); if ( res ) return res; + + if ( irq_ranges ) + { + res = rangeset_add_singleton(irq_ranges, irq); + if ( res ) + return res; + } } return 0; @@ -249,6 +266,11 @@ static int map_dt_irq_to_domain(const struct dt_device_node *dev, } res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev)); + if ( res ) + return res; + + if ( mr_data->irq_ranges ) + res = rangeset_add_singleton(mr_data->irq_ranges, irq); return res; } @@ -289,7 +311,8 @@ static int map_device_children(const struct dt_device_node *dev, * - Assign the device to the guest if it's protected by an IOMMU * - Map the IRQs and iomem regions to DOM0 */ -int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt, + struct rangeset *iomem_ranges, struct rangeset *irq_ranges) { unsigned int naddr; unsigned int i; @@ -308,7 +331,9 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) .p2mt = p2mt, .skip_mapping = !own_device || (is_pci_passthrough_enabled() && - (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)) + (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)), + .iomem_ranges = iomem_ranges, + .irq_ranges = irq_ranges }; naddr = dt_number_of_address(dev); @@ -342,7 +367,7 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt) } } - res = map_device_irqs_to_domain(d, dev, own_device); + res = map_device_irqs_to_domain(d, dev, own_device, irq_ranges); if ( res < 0 ) return res; diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index ff4fc30769..29dcbb8a2e 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2402,7 +2402,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo, "WARNING: Path %s is reserved, skip the node as we may re-use the path.\n", path); - res = handle_device(d, node, p2mt); + res = handle_device(d, node, p2mt, NULL, NULL); if ( res) return res; @@ -2745,7 +2745,7 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo, return -EINVAL; } - res = map_device_irqs_to_domain(kinfo->d, node, true); + res = map_device_irqs_to_domain(kinfo->d, node, true, NULL); if ( res < 0 ) return res; diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h index 6cda3e4039..b8866c20f4 100644 --- a/xen/arch/arm/include/asm/setup.h +++ b/xen/arch/arm/include/asm/setup.h @@ -113,6 +113,9 @@ struct map_range_data p2m_type_t p2mt; /* Set if mapping of the memory ranges must be skipped. */ bool skip_mapping; + /* Rangeset to store IRQs and IOMEM for overlay nodes. */ + struct rangeset *iomem_ranges; + struct rangeset *irq_ranges; }; extern struct bootinfo bootinfo; @@ -165,11 +168,11 @@ void device_tree_get_reg(const __be32 **cell, uint32_t address_cells, u32 device_tree_get_u32(const void *fdt, int node, const char *prop_name, u32 dflt); -int handle_device(struct domain *d, struct dt_device_node *dev, - p2m_type_t p2mt); +int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt, + struct rangeset *iomem_ranges, struct rangeset *irq_ranges); int map_device_irqs_to_domain(struct domain *d, struct dt_device_node *dev, - bool need_mapping); + bool need_mapping, struct rangeset *irq_ranges); int map_irq_to_domain(struct domain *d, unsigned int irq, bool need_mapping, const char *devname); From patchwork Fri Sep 1 04:59:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 677F5CA0FE6 for ; Fri, 1 Sep 2023 05:11:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594283.927616 (Exim 4.92) (envelope-from ) id 1qbwRT-0004Dv-PJ; Fri, 01 Sep 2023 05:11:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594283.927616; Fri, 01 Sep 2023 05:11:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwRT-0004Dd-LL; Fri, 01 Sep 2023 05:11:35 +0000 Received: by outflank-mailman (input) for mailman id 594283; Fri, 01 Sep 2023 05:11:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGo-0000Nr-HJ for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:34 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2061c.outbound.protection.outlook.com [2a01:111:f400:7e8a::61c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7a61ee8d-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:32 +0200 (CEST) Received: from CY5PR19CA0104.namprd19.prod.outlook.com (2603:10b6:930:83::21) by LV3PR12MB9410.namprd12.prod.outlook.com (2603:10b6:408:212::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21; Fri, 1 Sep 2023 05:00:29 +0000 Received: from CY4PEPF0000EE34.namprd05.prod.outlook.com (2603:10b6:930:83:cafe::f8) by CY5PR19CA0104.outlook.office365.com (2603:10b6:930:83::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:29 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE34.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:29 +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; Fri, 1 Sep 2023 00:00:28 -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; Fri, 1 Sep 2023 00:00:28 -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; Fri, 1 Sep 2023 00:00:27 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7a61ee8d-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Px90ePQurEEV1jICaBhJlQVa72gDDNE0vlxzoZIcXhxcFtQJhS3FLPYgWveg/ZZLfYaH42Vf8Faz9b0aogJ98kv2qhMkKgextnvfx0piXAX6NobwxrFP1rbWPpNey00QGnoniwTq5rKNR+12pq32diB0rv8NgIOwHGU4HP22e4DFstuO1S3m6xWDeddw/ljkaha2IDehGClb8llg76R5McFHHOo+fL4Btj1dFrSPnhHfCAe8wM8wvZqr+SX2aq5vIigzToR+acntuZrkLCVxJMoCrcrkmR86PO/ufWkKznAZ6gAS5T06Ur+Z+o+JzGLqXEK2w4Qui1f1GV6a0N1MDQ== 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=zNgVOKlUw7+tkGNpzY9AQb7DzcxioZaMnr7HSCVji8M=; b=YcdeoyjzDi/5GDP3kLPzTr/pR8FQ/D6N75cCN+03FPImDqG0zvUsbbYXCiwXx70/cCFPrxrnDC0JjcOPYQm/bTGPT3b7kZT19Y2rIEQncgV2w6N9IClDUHxJAi4K0yHZeTdLdrWqhl2MyNrqjXv8rGalZFNxYIkMUSzkCeoDSWP/pZWfFpT2ahh42ky+HCbDWOtSLqwcIbP07a8PXGChYRBtBm9vV64oMrqifXcFTRFTM5vwbYoPkH5pttl7Rgl0vNm4FT10wu3NwYcKSe0IOOhnFAAB1Py/815F3AHLmQ2yng20oWzX9PuQwIeFUT3QHaivnM5mWoLh2j3djqANtg== 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=zNgVOKlUw7+tkGNpzY9AQb7DzcxioZaMnr7HSCVji8M=; b=ARzfeZYeaSbwZHvcFJR8btAsjC6azR+aABfQhScBIvT0y+jCYciNjADrSOejKdGPirCWDCr4lxO/ENJZSaqw2CbWXKoH3O6Xm2gfoWDzKIgVMMnIX2MTIJIC/a027PoEzHZbMhnlHMQaaGhXoF2ZvMYqJXGfcEe0tBdRJdVdlOo= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Andrew Cooper , "George Dunlap" , Jan Beulich , Wei Liu , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN][PATCH v11 16/20] xen/arm: Implement device tree node removal functionalities Date: Thu, 31 Aug 2023 21:59:43 -0700 Message-ID: <20230901045947.32351-17-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE34:EE_|LV3PR12MB9410:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c0aac3b-4de8-4fe8-3f86-08dbaaa85cd6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tDsQoRVCny+VBKb4OWE3WEAWZhLVHSazlWQ/uuC/WteowIFhRzL/d99d7l3Wq+irLXI54sNjGPUx/ctKTJ88guJOAHsdNjaeHViqVQBU+TBJMb8IH3dfaH+z50F7DCqviDZKoX3ToD2avwCikgEihhMYhRd3YY5Tpf44dGbjGpTrEmrAiJGfeHKZ8CfjX+se48hfapfgoyeHdXPS0/LWB/YF/bvrK3jfM21/6JUDrcc80iwAPiHN2DvXcdnPSxZmMRIL8nwXVzjImAaoJTu9RRwlGxBO2QIACaWKUG/BGtZRLngce5d/wKtyHhFsukDNchRSqIWd/LuYryBeyZnHqWIlcjro+IOpIJoRhj1YlNtvsMJmg3w9gHg+fB1DNbjQJ1atf7lxbVIEkFVz/F4wpa7RgKwZpxqnwS1x5DbNHF5J3Y8zR0D6DQYAJC0KbSe2eScjCQw1PUfC2+rc9CkHf+6tlPParr2x7YEtGY8cS2zvF6s09SWjfylbDxs/JHSOqMV2E4jAm4cP9jHIBoJ9O7pvh1IzjvpngArAnigmK3E0RtRQqe1k4xSczOBN6HX5g843m0qvTvMWYhTVjv1ixVoRLrXiGjYDdGbvNNobD8yepe/GV5D+OtzV59atN/jjrFJ5U0gfTOAE+in5el/wwIjgyymuSxbNEp92Fx8r0s0Qi8FIxsDXsEK9PSBOdVa7S+yH0GGr8KIW1mbDeyw2KUhIq8fPDbSvXsZMmBJ8kn//ISB7EnaaXPGcaqieKuZJq1ADR6JkpJcNjOglxHL/34YXZTKCZf0zZa1RdntOpCHzVPo8RIW6zVez5EbB0Zjs X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(346002)(376002)(136003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(46966006)(40470700004)(356005)(82740400003)(6666004)(36756003)(40460700003)(36860700001)(86362001)(81166007)(47076005)(40480700001)(2616005)(1076003)(30864003)(2906002)(426003)(336012)(26005)(83380400001)(478600001)(70586007)(70206006)(8936002)(54906003)(8676002)(4326008)(44832011)(5660300002)(41300700001)(6916009)(316002)(333604002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:29.0579 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c0aac3b-4de8-4fe8-3f86-08dbaaa85cd6 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: CY4PEPF0000EE34.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9410 Introduce sysctl XEN_SYSCTL_dt_overlay to remove device-tree nodes added using device tree overlay. xl dt-overlay remove file.dtbo: Removes all the nodes in a given dtbo. First, removes IRQ permissions and MMIO accesses. Next, it finds the nodes in dt_host and delete the device node entries from dt_host. The nodes get removed only if it is not used by any of dom0 or domio. Also, added overlay_track struct to keep the track of added node through device tree overlay. overlay_track has dt_host_new which is unflattened form of updated fdt and name of overlay nodes. When a node is removed, we also free the memory used by overlay_track for the particular overlay node. Nested overlay removal is supported in sequential manner only i.e. if overlay_child nests under overlay_parent, it is assumed that user first removes overlay_child and then removes overlay_parent. Also, this is an experimental feature so it is expected from user to make sure correct device tree overlays are used when adding nodes and making sure devices are not being used by other domain before removing them from Xen tree. Partially added/removed i.e. failures while removing the overlay may cause other failures and might need a system reboot. Signed-off-by: Vikram Garhwal Reviewed-by: Stefano Stabellini --- Changes from v10: Add iommu_remove_dt_device if device has IOMMU added. Changes from v9: Remove iommu and IRQ routing as this will not be done while adding the nodes. Changes from v8: Remove IRQs and IOMMU entries using rangesets instead of parsing each node. Changes from v7: Add dt-overlay.c in MAINTAINERS. Add comments for dt_overlay_remove_node. Rename handle_remove_irq_iommu() to remove_resources(). Add comment regarding false mapping flag for reason behind not removing the mapping.. Remove irq_access_premitted() check. Add error handling for remove_all_descendant_nodes Change read_lock with write_lock. Remove check_overlay_fdt() call from handle_remove_overlay_nodes(). Re-organize dt_sysctl and reutnr -EOPNOSTSUPP for error cases. Also, renamed this function to dt_overlay_sysctl. Remove unnecessary header includes in dt-overlay.h Correct indentation and make func tion inputs const wherever possible. Make overlay_fdt const_void inside xen_sysctl_dt_overlay{}. Add comment regarding why we not removing IRQ and MMIO mappings. Move overlay_node_count() out of this patch as it's not being used here anymore. Changes from v6: Add explicit padding for xen_system_dt_overlay{} Update license. Rearrange xfree in dt_sysctl() Update overlay_track struct comment with relevant message. Fix missing xen/errno.h for builds without CONFIG_OVERLAY_DTB cases. Fix header formatting. --- --- MAINTAINERS | 1 + xen/arch/arm/sysctl.c | 16 +- xen/common/Makefile | 1 + xen/common/dt-overlay.c | 406 +++++++++++++++++++++++++++++++++++ xen/include/public/sysctl.h | 24 +++ xen/include/xen/dt-overlay.h | 63 ++++++ 6 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 xen/common/dt-overlay.c create mode 100644 xen/include/xen/dt-overlay.h diff --git a/MAINTAINERS b/MAINTAINERS index bf71ac144c..d320233538 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -301,6 +301,7 @@ M: Julien Grall S: Supported F: xen/common/libfdt/ F: xen/common/device_tree.c +F: xen/common/dt-overlay.c F: xen/include/xen/libfdt/ F: xen/include/xen/device_tree.h F: xen/drivers/passthrough/device_tree.c diff --git a/xen/arch/arm/sysctl.c b/xen/arch/arm/sysctl.c index e9a0661146..5cda0dc674 100644 --- a/xen/arch/arm/sysctl.c +++ b/xen/arch/arm/sysctl.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -25,7 +26,20 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi) long arch_do_sysctl(struct xen_sysctl *sysctl, XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) { - return -ENOSYS; + long ret; + + switch ( sysctl->cmd ) + { + case XEN_SYSCTL_dt_overlay: + ret = dt_overlay_sysctl(&sysctl->u.dt_overlay); + break; + + default: + ret = -ENOSYS; + break; + } + + return ret; } /* diff --git a/xen/common/Makefile b/xen/common/Makefile index 46049eac35..e7e96b1087 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o obj-$(CONFIG_IOREQ_SERVER) += dm.o obj-y += domain.o +obj-$(CONFIG_OVERLAY_DTB) += dt-overlay.o obj-y += event_2l.o obj-y += event_channel.o obj-y += event_fifo.o diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c new file mode 100644 index 0000000000..7b7224c29a --- /dev/null +++ b/xen/common/dt-overlay.c @@ -0,0 +1,406 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * xen/common/dt-overlay.c + * + * Device tree overlay support in Xen. + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + * Written by Vikram Garhwal + * + */ +#include +#include +#include +#include +#include +#include + +static LIST_HEAD(overlay_tracker); +static DEFINE_SPINLOCK(overlay_lock); + +/* Find last descendants of the device_node. */ +static struct dt_device_node * +find_last_descendants_node(const struct dt_device_node *device_node) +{ + struct dt_device_node *child_node; + + for ( child_node = device_node->child; child_node->sibling != NULL; + child_node = child_node->sibling ); + + /* If last child_node also have children. */ + if ( child_node->child ) + child_node = find_last_descendants_node(child_node); + + return child_node; +} + +static int dt_overlay_remove_node(struct dt_device_node *device_node) +{ + struct dt_device_node *np; + struct dt_device_node *parent_node; + struct dt_device_node *last_descendant = device_node->child; + + parent_node = device_node->parent; + + /* Check if we are trying to remove "/" i.e. root node. */ + if ( parent_node == NULL ) + { + dt_dprintk("%s's parent node not found\n", device_node->name); + return -EFAULT; + } + + /* Sanity check for linking between parent and child node. */ + np = parent_node->child; + if ( np == NULL ) + { + dt_dprintk("parent node %s's not found\n", parent_node->name); + return -EFAULT; + } + + /* If node to be removed is only child node or first child. */ + if ( !dt_node_cmp(np->full_name, device_node->full_name) ) + { + parent_node->child = np->sibling; + + /* + * Iterate over all child nodes of device_node. Given that we are + * removing a node, we need to remove all it's descendants too. + * Reason behind finding last_descendant: + * If device_node has multiple children, device_node->allnext will point + * to first_child and first_child->allnext will be a sibling. When the + * device_node and it's all children are removed, parent_node->allnext + * should point to node next to last children. + */ + if ( last_descendant ) + { + last_descendant = find_last_descendants_node(device_node); + parent_node->allnext = last_descendant->allnext; + } + else + parent_node->allnext = np->allnext; + + return 0; + } + + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ) + { + if ( !dt_node_cmp(np->sibling->full_name, device_node->full_name) ) + { + /* Found the node. Now we remove it. */ + np->sibling = np->sibling->sibling; + + if ( np->child ) + np = find_last_descendants_node(np); + + /* + * Iterate over all child nodes of device_node. Given that we are + * removing parent node, we need to remove all it's descendants too. + */ + if ( last_descendant ) + last_descendant = find_last_descendants_node(device_node); + + if ( last_descendant ) + np->allnext = last_descendant->allnext; + else + np->allnext = np->allnext->allnext; + + break; + } + } + + return 0; +} + +/* Basic sanity check for the dtbo tool stack provided to Xen. */ +static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) +{ + if ( (fdt_totalsize(overlay_fdt) != overlay_fdt_size) || + fdt_check_header(overlay_fdt) ) + { + printk(XENLOG_ERR "The overlay FDT is not a valid Flat Device Tree\n"); + return -EINVAL; + } + + return 0; +} + +static int irq_remove_cb(unsigned long s, unsigned long e, void *dom, + unsigned long *c) +{ + int rc; + struct domain *d = dom; + + /* + * TODO: We don't handle shared IRQs for now. So, it is assumed that + * the IRQs was not shared with another devices. + * TODO: Undo the IRQ routing. + */ + rc = irq_deny_access(d, s); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %lu\n", s); + } + else + *c += e - s + 1; + + return rc; + +} + +static int iomem_remove_cb(unsigned long s, unsigned long e, void *dom, + unsigned long *c) +{ + int rc; + struct domain *d = dom; + + /* + * Remove mmio access. + * TODO: Support for remove/add the mapping in P2M. + */ + rc = iomem_deny_access(d, s, e); + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove dom%d access to" + " 0x%"PRIx64" - 0x%"PRIx64"\n", + d->domain_id, + s & PAGE_MASK, PAGE_ALIGN(e) - 1); + } + else + *c += e - s + 1; + + return rc; +} + +/* Check if node itself can be removed and remove node from IOMMU. */ +static int remove_node_resources(struct dt_device_node *device_node) +{ + int rc = 0; + unsigned int len; + domid_t domid; + + domid = dt_device_used_by(device_node); + + dt_dprintk("Checking if node %s is used by any domain\n", + device_node->full_name); + + /* Remove the node if only it's assigned to hardware domain or domain io. */ + if ( domid != hardware_domain->domain_id && domid != DOMID_IO ) + { + printk(XENLOG_ERR "Device %s is being used by domain %u. Removing nodes failed\n", + device_node->full_name, domid); + return -EINVAL; + } + + /* Check if iommu property exists. */ + if ( dt_get_property(device_node, "iommus", &len) ) + { + if ( dt_device_is_protected(device_node) ) + { + rc = iommu_remove_dt_device(device_node); + if ( rc < 0 ) + return rc; + } + } + + return rc; +} + +/* Remove all descendants from IOMMU. */ +static int +remove_descendant_nodes_resources(const struct dt_device_node *device_node) +{ + int rc = 0; + struct dt_device_node *child_node; + + for ( child_node = device_node->child; child_node != NULL; + child_node = child_node->sibling ) + { + if ( child_node->child ) + { + rc = remove_descendant_nodes_resources(child_node); + if ( rc ) + return rc; + } + + rc = remove_node_resources(child_node); + if ( rc ) + return rc; + } + + return rc; +} + +/* Remove nodes from dt_host. */ +static int remove_nodes(const struct overlay_track *tracker) +{ + int rc = 0; + struct dt_device_node *overlay_node; + unsigned int j; + struct domain *d = hardware_domain; + + for ( j = 0; j < tracker->num_nodes; j++ ) + { + overlay_node = (struct dt_device_node *)tracker->nodes_address[j]; + if ( overlay_node == NULL ) + { + printk(XENLOG_ERR "Device %s is not present in the tree. Removing nodes failed\n", + overlay_node->full_name); + return -EINVAL; + } + + rc = remove_descendant_nodes_resources(overlay_node); + if ( rc ) + return rc; + + rc = remove_node_resources(overlay_node); + if ( rc ) + return rc; + + dt_dprintk("Removing node: %s\n", overlay_node->full_name); + + write_lock(&dt_host_lock); + + rc = dt_overlay_remove_node(overlay_node); + if ( rc ) + { + write_unlock(&dt_host_lock); + return rc; + } + + write_unlock(&dt_host_lock); + } + + /* Remove IRQ access. */ + if ( tracker->irq_ranges ) + { + rc = rangeset_consume_ranges(tracker->irq_ranges, irq_remove_cb, d); + if ( rc ) + return rc; + } + + /* Remove mmio access. */ + if ( tracker->iomem_ranges ) + { + rc = rangeset_consume_ranges(tracker->iomem_ranges, iomem_remove_cb, d); + if ( rc ) + return rc; + } + + return rc; +} + +/* + * First finds the device node to remove. Check if the device is being used by + * any dom and finally remove it from dt_host. IOMMU is already being taken care + * while destroying the domain. + */ +static long handle_remove_overlay_nodes(const void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc; + struct overlay_track *entry, *temp, *track; + bool found_entry = false; + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + return rc; + + spin_lock(&overlay_lock); + + /* + * First check if dtbo is correct i.e. it should one of the dtbo which was + * used when dynamically adding the node. + * Limitation: Cases with same node names but different property are not + * supported currently. We are relying on user to provide the same dtbo + * as it was used when adding the nodes. + */ + list_for_each_entry_safe( entry, temp, &overlay_tracker, entry ) + { + if ( memcmp(entry->overlay_fdt, overlay_fdt, overlay_fdt_size) == 0 ) + { + track = entry; + found_entry = true; + break; + } + } + + if ( !found_entry ) + { + rc = -EINVAL; + + printk(XENLOG_ERR "Cannot find any matching tracker with input dtbo." + " Removing nodes is supported only for prior added dtbo.\n"); + goto out; + + } + + rc = remove_nodes(entry); + if ( rc ) + { + printk(XENLOG_ERR "Removing node failed\n"); + goto out; + } + + list_del(&entry->entry); + + xfree(entry->dt_host_new); + xfree(entry->fdt); + xfree(entry->overlay_fdt); + + xfree(entry->nodes_address); + + rangeset_destroy(entry->irq_ranges); + rangeset_destroy(entry->iomem_ranges); + + xfree(entry); + + out: + spin_unlock(&overlay_lock); + return rc; +} + +long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) +{ + long ret; + void *overlay_fdt; + + if ( op->overlay_op != XEN_SYSCTL_DT_OVERLAY_ADD && + op->overlay_op != XEN_SYSCTL_DT_OVERLAY_REMOVE ) + return -EOPNOTSUPP; + + if ( op->overlay_fdt_size == 0 || op->overlay_fdt_size > KB(500) ) + return -EINVAL; + + if ( op->pad[0] || op->pad[1] || op->pad[2] ) + return -EINVAL; + + overlay_fdt = xmalloc_bytes(op->overlay_fdt_size); + + if ( overlay_fdt == NULL ) + return -ENOMEM; + + ret = copy_from_guest(overlay_fdt, op->overlay_fdt, op->overlay_fdt_size); + if ( ret ) + { + gprintk(XENLOG_ERR, "copy from guest failed\n"); + xfree(overlay_fdt); + + return -EFAULT; + } + + if ( op->overlay_op == XEN_SYSCTL_DT_OVERLAY_REMOVE ) + ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + + xfree(overlay_fdt); + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 3975050248..f1eba78405 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1185,6 +1185,25 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_cpu_policy_t); #endif +#if defined(__arm__) || defined (__aarch64__) +/* + * XEN_SYSCTL_dt_overlay + * Performs addition/removal of device tree nodes under parent node using dtbo. + * This does in three steps: + * - Adds/Removes the nodes from dt_host. + * - Adds/Removes IRQ permission for the nodes. + * - Adds/Removes MMIO accesses. + */ +struct xen_sysctl_dt_overlay { + XEN_GUEST_HANDLE_64(const_void) overlay_fdt; /* IN: overlay fdt. */ + uint32_t overlay_fdt_size; /* IN: Overlay dtb size. */ +#define XEN_SYSCTL_DT_OVERLAY_ADD 1 +#define XEN_SYSCTL_DT_OVERLAY_REMOVE 2 + uint8_t overlay_op; /* IN: Add or remove. */ + uint8_t pad[3]; /* IN: Must be zero. */ +}; +#endif + struct xen_sysctl { uint32_t cmd; #define XEN_SYSCTL_readconsole 1 @@ -1215,6 +1234,7 @@ struct xen_sysctl { #define XEN_SYSCTL_livepatch_op 27 /* #define XEN_SYSCTL_set_parameter 28 */ #define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_dt_overlay 30 uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */ union { struct xen_sysctl_readconsole readconsole; @@ -1245,6 +1265,10 @@ struct xen_sysctl { #if defined(__i386__) || defined(__x86_64__) struct xen_sysctl_cpu_policy cpu_policy; #endif + +#if defined(__arm__) || defined (__aarch64__) + struct xen_sysctl_dt_overlay dt_overlay; +#endif uint8_t pad[128]; } u; }; diff --git a/xen/include/xen/dt-overlay.h b/xen/include/xen/dt-overlay.h new file mode 100644 index 0000000000..c0567741ee --- /dev/null +++ b/xen/include/xen/dt-overlay.h @@ -0,0 +1,63 @@ + /* SPDX-License-Identifier: GPL-2.0-only */ + /* + * xen/dt-overlay.h + * + * Device tree overlay support in Xen. + * + * Copyright (C) 2023, Advanced Micro Devices, Inc. All Rights Reserved. + * Written by Vikram Garhwal + * + */ +#ifndef __XEN_DT_OVERLAY_H__ +#define __XEN_DT_OVERLAY_H__ + +#include +#include +#include + +/* + * overlay_track describes information about added nodes through dtbo. + * @entry: List pointer. + * @dt_host_new: Pointer to the updated dt_host_new which is unflattened from + the 'updated fdt'. + * @fdt: Stores the fdt. + * @overlay_fdt: Stores a copy of input overlay_fdt. + * @nodes_address: Stores each overlay_node's address. + * @num_nodes: Total number of nodes in overlay dtb. + * @iomem_ranges: Range set to keep track of all IOMEMs. + * @irq_ranges: Range set to keep track of all added IRQs. + */ +struct overlay_track { + struct list_head entry; + struct dt_device_node *dt_host_new; + void *fdt; + void *overlay_fdt; + unsigned long *nodes_address; + unsigned int num_nodes; + struct rangeset *iomem_ranges; + struct rangeset *irq_ranges; +}; + +struct xen_sysctl_dt_overlay; + +#ifdef CONFIG_OVERLAY_DTB +long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op); +#else +#include +static inline long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) +{ + return -EOPNOTSUPP; +} +#endif + +#endif /* __XEN_DT_OVERLAY_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Fri Sep 1 04:59:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45F11CA0FE6 for ; Fri, 1 Sep 2023 05:11:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594270.927596 (Exim 4.92) (envelope-from ) id 1qbwRL-0002z5-Rf; Fri, 01 Sep 2023 05:11:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594270.927596; Fri, 01 Sep 2023 05:11:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwRL-0002yn-NH; Fri, 01 Sep 2023 05:11:27 +0000 Received: by outflank-mailman (input) for mailman id 594270; Fri, 01 Sep 2023 05:11:26 +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 1qbwGs-0001Hn-Ex for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:38 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2060b.outbound.protection.outlook.com [2a01:111:f400:7e8b::60b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7a990220-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:33 +0200 (CEST) Received: from CY5P221CA0074.NAMP221.PROD.OUTLOOK.COM (2603:10b6:930:9::11) by CY8PR12MB8216.namprd12.prod.outlook.com (2603:10b6:930:78::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Fri, 1 Sep 2023 05:00:29 +0000 Received: from CY4PEPF0000EE3F.namprd03.prod.outlook.com (2603:10b6:930:9:cafe::d8) by CY5P221CA0074.outlook.office365.com (2603:10b6:930:9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:29 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3F.mail.protection.outlook.com (10.167.242.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:29 +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; Fri, 1 Sep 2023 00:00:28 -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; Fri, 1 Sep 2023 00:00:28 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7a990220-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MHvAyuY+eBCVhlY7JBlkvEGrhh2wRBrldKuOhGTS3MJJIoxQGy4r/golspoYSqMzKs6NmAsp/1IruYsCzaEG0wAOvdPrKCRNK+bZpgzhAQy/x8Ak1aXfkj3m2SkGH2looewjf7oMwojDbsUT2uo9sRWpVYSQdM3WTpeWRT6+bgJCUxpGBjFcKkC4oQIZ5QHiQm+HvgJT3BB593BnPQJzGZXB55K2YZCTvDzxXV5wCHg9ZopahmGBpnnbtdevlzrCzr9CQEY3YtMUyrRhCaARKesY7YyHXqMYgvljkdsleZKghT/ktJ48xnmjMsr+p6dcexvwlGKtCbXrHuhtMZ1M6Q== 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=U07oIExPBdAjjT4LN+M3eFjY0zcOWOucXEwjxMGcDw8=; b=Xrp04w3Z0rkLEzKcCE2DoKztptEWpbjZ1bjaCx7WdkftOSoWeaOLh1TOwDC2yLOQxEVdHR3WXHE4MR36y3JmfHGIqPPToTXja+JKbwBDTg2dOl/wBhKXQ2c03OPG6mursNdaN6EDVyBmXyFTwtV12vhCWRlVPUxQLmun+u5d4vJROYBtHL9kwigYW6dt0Xysed3D3WLum0eDnkcAXcFA+BOlSLLTTxG2D1DKMnWW+QEhnMmT4UIQ4gT/8d9ftcs4glFDDPAEUu2scs87zb18f7S/5+wPTXZM3G2yQQJXMVp/xwKllBUYXVzuWwpBmc8FZKX7//fpn2XPkrHIbbEieA== 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=U07oIExPBdAjjT4LN+M3eFjY0zcOWOucXEwjxMGcDw8=; b=pQBn/YSbgO7Q/NJn8rj3QSDDDUdtvvQCFH2YVMvpjkbIfoxz3bz8RnWhq64d266qT6e1TsDCkHAST5WBxvAUzc7nB+eYmqyPEKj+gjprs4x6DstIpfqnNmyKnKHve/kBID1oFboC1MdULDkLjNh+zV7h4TOWKjGCdYnuZflUV/A= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , Subject: [XEN][PATCH v11 17/20] xen/arm: Implement device tree node addition functionalities Date: Thu, 31 Aug 2023 21:59:44 -0700 Message-ID: <20230901045947.32351-18-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3F:EE_|CY8PR12MB8216:EE_ X-MS-Office365-Filtering-Correlation-Id: 3677762e-9b11-4874-d648-08dbaaa85d2f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HnEQCcJHgwfIAHefEmgkeLsHXM0tSCCwCE0hBQ4RBxr6jfFYO1Usp5thbkyWnzxP6bHp6dXtatVZNX0zaKzfHG4QS6M5wPAxi4IuMsDUJfuWgphu6wyiaAHlTpItp+hT+0PacvgjtSo/AGgLLmM2MTJH1dMkmvptuUTqM12rViPj+xJnVfRTu5AdU709MKLhDjs4LprQ/HRSN7YqFzzwq9FXeB/YiydceaLNsl3G/RqFx9C2ws0/c9/ixPj/9G2KOQCIeD5Flv2Vv5A2gJzU7PkLj4l4lIBIYtPHPHMcs/rZtqUJEtY2m4SWHm5yavxbx3DS42nYuN0JJMeLKzoKzNxLmHbyeGRAO2XoD83grQUKtvWdeygR5QhN5dgmYfFfbVzCoscef75JlHNm//jJ/cUov8pGiL6KmhoY/y8XwOo1R4/UqG6jXeETSxMlmfkQ/BgZJrW1GVH4sJSbQYVumMToGQJBk/BlBr+5CpeEDQ1jkXl2ik3LdGmTVKhzL9Owl9ecxmXgq/L7Ht61klsxKzEtNJ+Vp39RaPsb9lI1xDXekPKFrg3DEYuJOsh8XzuUWQZs581/I1+thXilYwD9f/w0pXnVI3XP52MvHRao0KIXLZ/ru5zpBWMKvjD6rkvfjuS8FLLtsUDUjlTtDkM3LiWEc/uKHNcy0JiqbxnF6eDMqj2SdfhKedRfvWNQhx1YEb10pkjiwzOpHvezAxH0zyBzOWSvW7POroZLXirSZWJwmQ9sbVBcIwTTbwg2z6EvQN6aZMztHfH+6ggmfTZssg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(136003)(376002)(396003)(346002)(82310400011)(1800799009)(186009)(451199024)(40470700004)(36840700001)(46966006)(8936002)(66899024)(82740400003)(4326008)(6666004)(40480700001)(47076005)(356005)(40460700003)(36756003)(2906002)(81166007)(86362001)(36860700001)(426003)(1076003)(478600001)(336012)(30864003)(8676002)(26005)(54906003)(83380400001)(41300700001)(5660300002)(70586007)(44832011)(70206006)(6916009)(2616005)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:29.6607 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3677762e-9b11-4874-d648-08dbaaa85d2f 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: CY4PEPF0000EE3F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8216 Update sysctl XEN_SYSCTL_dt_overlay to enable support for dtbo nodes addition using device tree overlay. xl dt-overlay add file.dtbo: Each time overlay nodes are added using .dtbo, a new fdt(memcpy of device_tree_flattened) is created and updated with overlay nodes. This updated fdt is further unflattened to a dt_host_new. Next, it checks if any of the overlay nodes already exists in the dt_host. If overlay nodes doesn't exist then find the overlay nodes in dt_host_new, find the overlay node's parent in dt_host and add the nodes as child under their parent in the dt_host. The node is attached as the last node under target parent. Finally, add IRQs, add device to IOMMUs, set permissions and map MMIO for the overlay node. When a node is added using overlay, a new entry is allocated in the overlay_track to keep the track of memory allocation due to addition of overlay node. This is helpful for freeing the memory allocated when a device tree node is removed. The main purpose of this to address first part of dynamic programming i.e. making xen aware of new device tree node which means updating the dt_host with overlay node information. Here we are adding/removing node from dt_host, and checking/setting IOMMU and IRQ permission but never mapping them to any domain. Right now, mapping/Un-mapping will happen only when a new domU is created/destroyed using "xl create". Signed-off-by: Vikram Garhwal --- Changes from v10: Change int to unsigned int for accessing node_nums. Re-organize free_nodes_full_path(). Change order of calling xfree for err cases. Changes from v9: Remove add_resources() and use handle_device(). Changes from v8: Add rangeset to keep IRQs and IOMEM information. Changes from v7: Move overlay_node_count() in this patch. Fix indent with goto statements. Rename handle_add_irq_iommu() to add_resources(). Changes from v6: Fix comment style and add comment regarding false flag in irq mapping. Move malloc for nodes_full_path to handle_add_overlay_nodes. Move node_num define to start of overlay_get_nodes_info(). Remove "domain *d" from handle_add_irq_iommu(). Fix error handling for handle_add_irq_iommu(). Split handle_add_overlay_nodes to two functions. Create a separate function for freeing nodes_full_path. Fix xfree for dt_sysctl. --- --- xen/common/dt-overlay.c | 495 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 495 insertions(+) diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index 7b7224c29a..d748ea3df0 100644 --- a/xen/common/dt-overlay.c +++ b/xen/common/dt-overlay.c @@ -34,6 +34,25 @@ find_last_descendants_node(const struct dt_device_node *device_node) return child_node; } +/* + * Returns next node to the input node. If node has children then return + * last descendant's next node. +*/ +static struct dt_device_node * +dt_find_next_node(struct dt_device_node *dt, const struct dt_device_node *node) +{ + struct dt_device_node *np; + + dt_for_each_device_node(dt, np) + if ( np == node ) + break; + + if ( np->child ) + np = find_last_descendants_node(np); + + return np->allnext; +} + static int dt_overlay_remove_node(struct dt_device_node *device_node) { struct dt_device_node *np; @@ -111,6 +130,78 @@ static int dt_overlay_remove_node(struct dt_device_node *device_node) return 0; } +static int dt_overlay_add_node(struct dt_device_node *device_node, + const char *parent_node_path) +{ + struct dt_device_node *parent_node; + struct dt_device_node *next_node; + + parent_node = dt_find_node_by_path(parent_node_path); + + if ( parent_node == NULL ) + { + dt_dprintk("Parent node %s not found. Overlay node will not be added\n", + parent_node_path); + return -EINVAL; + } + + /* If parent has no child. */ + if ( parent_node->child == NULL ) + { + next_node = parent_node->allnext; + device_node->parent = parent_node; + parent_node->allnext = device_node; + parent_node->child = device_node; + } + else + { + struct dt_device_node *np; + /* + * If parent has at least one child node. + * Iterate to the last child node of parent. + */ + for ( np = parent_node->child; np->sibling != NULL; np = np->sibling ); + + /* Iterate over all child nodes of np node. */ + if ( np->child ) + { + struct dt_device_node *np_last_descendant; + + np_last_descendant = find_last_descendants_node(np); + + next_node = np_last_descendant->allnext; + np_last_descendant->allnext = device_node; + } + else + { + next_node = np->allnext; + np->allnext = device_node; + } + + device_node->parent = parent_node; + np->sibling = device_node; + np->sibling->sibling = NULL; + } + + /* Iterate over all child nodes of device_node to add children too. */ + if ( device_node->child ) + { + struct dt_device_node *device_node_last_descendant; + + device_node_last_descendant = find_last_descendants_node(device_node); + + /* Plug next_node at the end of last children of device_node. */ + device_node_last_descendant->allnext = next_node; + } + else + { + /* Now plug next_node at the end of device_node. */ + device_node->allnext = next_node; + } + + return 0; +} + /* Basic sanity check for the dtbo tool stack provided to Xen. */ static int check_overlay_fdt(const void *overlay_fdt, uint32_t overlay_fdt_size) { @@ -171,6 +262,102 @@ static int iomem_remove_cb(unsigned long s, unsigned long e, void *dom, return rc; } +/* Count number of nodes till one level of __overlay__ tag. */ +static unsigned int overlay_node_count(const void *overlay_fdt) +{ + unsigned int num_overlay_nodes = 0; + int fragment; + + fdt_for_each_subnode(fragment, overlay_fdt, 0) + { + int subnode; + int overlay; + + overlay = fdt_subnode_offset(overlay_fdt, fragment, "__overlay__"); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + fdt_for_each_subnode(subnode, overlay_fdt, overlay) + { + num_overlay_nodes++; + } + } + + return num_overlay_nodes; +} + +/* + * overlay_get_nodes_info gets full name with path for all the nodes which + * are in one level of __overlay__ tag. This is useful when checking node for + * duplication i.e. dtbo tries to add nodes which already exists in device tree. + */ +static int overlay_get_nodes_info(const void *fdto, char **nodes_full_path) +{ + int fragment; + unsigned int node_num = 0; + + fdt_for_each_subnode(fragment, fdto, 0) + { + int target; + int overlay; + int subnode; + const char *target_path; + + target = fdt_overlay_target_offset(device_tree_flattened, fdto, + fragment, &target_path); + if ( target < 0 ) + return target; + + if ( target_path == NULL ) + return -EINVAL; + + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + + /* + * overlay value can be < 0. But fdt_for_each_subnode() loop checks for + * overlay >= 0. So, no need for a overlay>=0 check here. + */ + fdt_for_each_subnode(subnode, fdto, overlay) + { + const char *node_name = NULL; + int node_name_len; + unsigned int target_path_len = strlen(target_path); + unsigned int node_full_name_len; + + node_name = fdt_get_name(fdto, subnode, &node_name_len); + + if ( node_name == NULL ) + return node_name_len; + + /* + * Magic number 2 is for adding '/' and '\0'. This is done to keep + * the node_full_path in the correct full node name format. + */ + node_full_name_len = target_path_len + node_name_len + 2; + + nodes_full_path[node_num] = xmalloc_bytes(node_full_name_len); + + if ( nodes_full_path[node_num] == NULL ) + return -ENOMEM; + + memcpy(nodes_full_path[node_num], target_path, target_path_len); + + nodes_full_path[node_num][target_path_len] = '/'; + + memcpy(nodes_full_path[node_num] + target_path_len + 1, + node_name, node_name_len); + + nodes_full_path[node_num][node_full_name_len - 1] = '\0'; + + node_num++; + } + } + + return 0; +} + /* Check if node itself can be removed and remove node from IOMMU. */ static int remove_node_resources(struct dt_device_node *device_node) { @@ -359,6 +546,312 @@ static long handle_remove_overlay_nodes(const void *overlay_fdt, return rc; } +static void free_nodes_full_path(unsigned int num_nodes, char **nodes_full_path) +{ + unsigned int i; + + if ( nodes_full_path != NULL ) + return; + + for ( i = 0; i < num_nodes && nodes_full_path[i] != NULL; i++ ) + { + xfree(nodes_full_path[i]); + } + + xfree(nodes_full_path); +} + +static long add_nodes(struct overlay_track *tr, char **nodes_full_path) + +{ + int rc; + unsigned int j; + struct dt_device_node *overlay_node; + + for ( j = 0; j < tr->num_nodes; j++ ) + { + struct dt_device_node *prev_node, *next_node; + + dt_dprintk("Adding node: %s\n", nodes_full_path[j]); + + /* Find the newly added node in tr->dt_host_new by it's full path. */ + overlay_node = dt_find_node_by_path_from(tr->dt_host_new, + nodes_full_path[j]); + if ( overlay_node == NULL ) + { + /* Sanity check. But code will never come here. */ + ASSERT_UNREACHABLE(); + return -EFAULT; + } + + /* + * Find previous and next node to overlay_node in dt_host_new. We will + * need these nodes to fix the dt_host_new mapping. When overlay_node is + * take out of dt_host_new tree and added to dt_host, link between + * previous node and next_node is broken. We will need to refresh + * dt_host_new with correct linking for any other overlay nodes + * extraction in future. + */ + dt_for_each_device_node(tr->dt_host_new, prev_node) + if ( prev_node->allnext == overlay_node ) + break; + + next_node = dt_find_next_node(tr->dt_host_new, overlay_node); + + write_lock(&dt_host_lock); + + /* Add the node to dt_host. */ + rc = dt_overlay_add_node(overlay_node, overlay_node->parent->full_name); + if ( rc ) + { + write_unlock(&dt_host_lock); + + /* Node not added in dt_host. */ + return rc; + } + + write_unlock(&dt_host_lock); + + prev_node->allnext = next_node; + + overlay_node = dt_find_node_by_path(overlay_node->full_name); + if ( overlay_node == NULL ) + { + /* Sanity check. But code will never come here. */ + ASSERT_UNREACHABLE(); + return -EFAULT; + } + + rc = handle_device(hardware_domain, overlay_node, p2m_mmio_direct_c, + tr->iomem_ranges, + tr->irq_ranges); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + return rc; + } + + /* Keep overlay_node address in tracker. */ + tr->nodes_address[j] = (unsigned long)overlay_node; + } + + return 0; +} +/* + * Adds device tree nodes under target node. + * We use tr->dt_host_new to unflatten the updated device_tree_flattened. This + * is done to avoid the removal of device_tree generation, iomem regions mapping + * to hardware domain done by handle_node(). + */ +static long handle_add_overlay_nodes(void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc; + unsigned int j; + struct dt_device_node *overlay_node; + struct overlay_track *tr = NULL; + char **nodes_full_path = NULL; + unsigned int new_fdt_size; + + tr = xzalloc(struct overlay_track); + if ( tr == NULL ) + return -ENOMEM; + + new_fdt_size = fdt_totalsize(device_tree_flattened) + + fdt_totalsize(overlay_fdt); + + tr->fdt = xzalloc_bytes(new_fdt_size); + if ( tr->fdt == NULL ) + { + xfree(tr); + return -ENOMEM; + } + + tr->num_nodes = overlay_node_count(overlay_fdt); + if ( tr->num_nodes == 0 ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + tr->nodes_address = xzalloc_bytes(tr->num_nodes * sizeof(unsigned long)); + if ( tr->nodes_address == NULL ) + { + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + { + xfree(tr->nodes_address); + xfree(tr->fdt); + xfree(tr); + return rc; + } + + /* + * Keep a copy of overlay_fdt as fdt_overlay_apply will change the input + * overlay's content(magic) when applying overlay. + */ + tr->overlay_fdt = xzalloc_bytes(overlay_fdt_size); + if ( tr->overlay_fdt == NULL ) + { + xfree(tr->nodes_address); + xfree(tr->fdt); + xfree(tr); + return -ENOMEM; + } + + memcpy(tr->overlay_fdt, overlay_fdt, overlay_fdt_size); + + spin_lock(&overlay_lock); + + memcpy(tr->fdt, device_tree_flattened, + fdt_totalsize(device_tree_flattened)); + + /* Open tr->fdt with more space to accommodate the overlay_fdt. */ + rc = fdt_open_into(tr->fdt, tr->fdt, new_fdt_size); + if ( rc ) + { + printk(XENLOG_ERR "Increasing fdt size to accommodate overlay_fdt failed with error %d\n", + rc); + goto err; + } + + nodes_full_path = xzalloc_bytes(tr->num_nodes * sizeof(char *)); + if ( nodes_full_path == NULL ) + { + rc = -ENOMEM; + goto err; + } + + /* + * overlay_get_nodes_info is called to get the node information from dtbo. + * This is done before fdt_overlay_apply() because the overlay apply will + * erase the magic of overlay_fdt. + */ + rc = overlay_get_nodes_info(overlay_fdt, nodes_full_path); + if ( rc ) + { + printk(XENLOG_ERR "Getting nodes information failed with error %d\n", + rc); + goto err; + } + + rc = fdt_overlay_apply(tr->fdt, overlay_fdt); + if ( rc ) + { + printk(XENLOG_ERR "Adding overlay node failed with error %d\n", rc); + goto err; + } + + /* + * Check if any of the node already exists in dt_host. If node already exits + * we can return here as this overlay_fdt is not suitable for overlay ops. + */ + for ( j = 0; j < tr->num_nodes; j++ ) + { + overlay_node = dt_find_node_by_path(nodes_full_path[j]); + if ( overlay_node != NULL ) + { + printk(XENLOG_ERR "node %s exists in device tree\n", + nodes_full_path[j]); + rc = -EINVAL; + goto err; + } + } + + /* + * Unflatten the tr->fdt into a new dt_host. + * TODO: Check and add alias_scan() if it's needed for overlay in future. + */ + rc = unflatten_device_tree(tr->fdt, &tr->dt_host_new); + if ( rc ) + { + printk(XENLOG_ERR "unflatten_device_tree failed with error %d\n", rc); + goto err; + } + + tr->irq_ranges = rangeset_new(hardware_domain, "Overlays: Interrupts", 0); + if (tr->irq_ranges == NULL) + { + printk(XENLOG_ERR "Creating IRQ rangeset failed"); + goto err; + } + + tr->iomem_ranges = rangeset_new(hardware_domain, "Overlay: I/O Memory", 0); + if (tr->iomem_ranges == NULL) + { + printk(XENLOG_ERR "Creating IOMMU rangeset failed"); + goto err; + } + + rc = add_nodes(tr, nodes_full_path); + if ( rc ) + { + printk(XENLOG_ERR "Adding nodes failed. Removing the partially added nodes.\n"); + goto remove_node; + } + + INIT_LIST_HEAD(&tr->entry); + list_add_tail(&tr->entry, &overlay_tracker); + + spin_unlock(&overlay_lock); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + return rc; + +/* + * Failure case. We need to remove the nodes, free tracker(if tr exists) and + * tr->dt_host_new. + */ + remove_node: + tr->num_nodes = j; + rc = remove_nodes(tr); + + if ( rc ) + { + /* + * User needs to provide right overlay. Incorrect node information + * example parent node doesn't exist in dt_host etc can cause memory + * leaks as removing_nodes() will fail and this means nodes memory is + * not freed from tracker. Which may cause memory leaks. Ideally, these + * device tree related mistakes will be caught by fdt_overlay_apply() + * but given that we don't manage that code keeping this warning message + * is better here. + */ + printk(XENLOG_ERR "Removing node failed.\n"); + spin_unlock(&overlay_lock); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + return rc; + } + + err: + spin_unlock(&overlay_lock); + + if ( tr->dt_host_new ) + xfree(tr->dt_host_new); + + free_nodes_full_path(tr->num_nodes, nodes_full_path); + + xfree(tr->overlay_fdt); + xfree(tr->nodes_address); + xfree(tr->fdt); + + rangeset_destroy(tr->irq_ranges); + rangeset_destroy(tr->iomem_ranges); + + xfree(tr); + + return rc; +} + long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) { long ret; @@ -390,6 +883,8 @@ long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) if ( op->overlay_op == XEN_SYSCTL_DT_OVERLAY_REMOVE ) ret = handle_remove_overlay_nodes(overlay_fdt, op->overlay_fdt_size); + else + ret = handle_add_overlay_nodes(overlay_fdt, op->overlay_fdt_size); xfree(overlay_fdt); From patchwork Fri Sep 1 04:59:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372034 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44F38CA0FE6 for ; Fri, 1 Sep 2023 05:12:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594325.927652 (Exim 4.92) (envelope-from ) id 1qbwS2-0006lY-4W; Fri, 01 Sep 2023 05:12:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594325.927652; Fri, 01 Sep 2023 05:12:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwS1-0006jy-TB; Fri, 01 Sep 2023 05:12:09 +0000 Received: by outflank-mailman (input) for mailman id 594325; Fri, 01 Sep 2023 05:12:08 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGt-0001Hn-FD for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:39 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060c.outbound.protection.outlook.com [2a01:111:f400:7e88::60c]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7b152e34-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:34 +0200 (CEST) Received: from DS7PR03CA0168.namprd03.prod.outlook.com (2603:10b6:5:3b2::23) by CYYPR12MB8921.namprd12.prod.outlook.com (2603:10b6:930:c7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.23; Fri, 1 Sep 2023 05:00:30 +0000 Received: from CY4PEPF0000EE3C.namprd03.prod.outlook.com (2603:10b6:5:3b2:cafe::5a) by DS7PR03CA0168.outlook.office365.com (2603:10b6:5:3b2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 05:00:30 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3C.mail.protection.outlook.com (10.167.242.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:30 +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; Fri, 1 Sep 2023 00:00:29 -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; Fri, 1 Sep 2023 00:00:29 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7b152e34-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=br+vnSfFGe89wBRfE1hfe9zveK1u9F1Iq8b0lCb/nbOKksW5AheSyhg0LiOSS+2XPFpA+jBvWSe+jHuMRhxXixc0Ar91uXnO4LU+QU4qmelF0jzb9THMjFxgIOs4GT1glEuuhCpg6B6oiRCkOZxxZRUygyg7VaMH8TGX3141o+IT+Q/NLVSOzNjKhYv0Q8VGzMcJ30CrQgRAaASgdcIT9jZvzquLnMf9uwMPnJDm4CK/Z5ql+MLXejX0gB7GJjm2SFm9g9jrSWC6bEMipEGefpDWMocuGNlBgDSCMOWDLHDsbK4Glgyz7SykFwOdxc6Z8sy+gor8W2DBcLjYkLZTTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f3CXFnL+4aLIWZtU9p5mMJcpke4wuyPy6FqvOY6YZ1o=; b=ZYQ4qbXcuRQ5T2XIbqn4ApBVIoRq9noZWlen+q+VBeIcpoH1xMV9BzdV2rYR1l9yaFJVPTWy+nhd7uxFAccef9c9YB8RjyXZgc35jNa3Q7v0u/Db9Ve1njSuazr0C+uRapfJO5evYLHw3hOC15a70QcI6FUjFT2sj/T6RaryT2m3uULwBwfRe77DEJysIOYTvRow1v15S4w5kYjwFZOa42rhIj+v7UQ58VhEo1Gpznq5b9BFArQqfR1WGITK62+QKiF7tysheZIoR4G1R+5+730Ja7TDyIyGsLLTDto+uE/+qS8C8WajQ1UdqGjfYibaDP8kXmfYhIGBv+uFloZbsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f3CXFnL+4aLIWZtU9p5mMJcpke4wuyPy6FqvOY6YZ1o=; b=GguLGdsVWl7X/nGtZ1nYh0L/CIk92WxYRzCYP5aSrdmUALqURTuiDlvOB58jIZyU+GTaaGOwm0hs5r0iuf7ZTE37dYIuMjCQR54BT3vlqgjvdsNW2xSz1Q4jM/VqF1+OsB941r9rIkGWP7u/uixAvjF5ITz8WRAZzaT1hgtsCkg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][PATCH v11 18/20] tools/libs/ctrl: Implement new xc interfaces for dt overlay Date: Thu, 31 Aug 2023 21:59:45 -0700 Message-ID: <20230901045947.32351-19-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3C:EE_|CYYPR12MB8921:EE_ X-MS-Office365-Filtering-Correlation-Id: ac2dd0b3-e953-4150-3d3d-08dbaaa85db4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MvRa/6J4rDug4nsKud19NijEpszhflc0hexeCt0gli0S3WpmOEdsyImkaLc34KHmeCwABDsDgbfx5qu6cF5/vyskpahSzfuC4BiTIgTqf3iIObGAqhhKdssmcqJeMvbyypW9wcdPSLocspjEDFTpDR3RxYd/EQ3k9Gtx0sBAOHSx+a6UWhQpGwdDsnucdc+8iFlGyaVbTA5n3VIWSQBqu1POSZNLp/2VpApunUqPf5TMvISJ8e+H4lxFlyTbYZWntq3wHnRtYzKijIjSqn4IoTof9vrsIafrsjJLA5/FZk9WA8+R7LnOjmxpYCNxo8boQ6rRSODCfbMKnHPlu0meFea/Sv7HdovP50Xgq4H20KQ8lIhFeiNNNFphcholy684ur02+kuqaK4tNgojJlFvg/x+ATbsyXT4GTY90nUizFgaADsEeU+xHEEmd3NDjoCxAktfAWdvb9IoE7hHnmoN1hR5QKX1V3CtqUwXPcngJNBphG+h8QehK0OpvmF0Y0bki2pEBWR/41rJdxcOXm2BnAA5YeDYPwkCpaBXitwVen+BhJibexgSK+TaYz5eLZ428HghDwWeFdinILpYYbSohKRLJBBUYhVd18ZMUb8Z0WtR2ekNz/i0e2l6vT6RLDb01yWsKAQnLG78cdjAK7xmT05MKJy3xJkPSovU4mg+DStg4exY8xGvz8//6+H0ZAXAGvzVNfi7b9nu5CCBJYuNrEJ+MCzceXK/yRNXR62b6pB/pMWpSfYp36+F0IUIDin6oBXWMn4M7rsA9f66ok1Ia8boTaMmjNx9aUhmBzPEVTQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(396003)(346002)(376002)(136003)(39860400002)(451199024)(186009)(82310400011)(1800799009)(36840700001)(40470700004)(46966006)(356005)(82740400003)(6666004)(36756003)(40460700003)(86362001)(81166007)(40480700001)(47076005)(36860700001)(2616005)(2906002)(426003)(336012)(26005)(1076003)(478600001)(5660300002)(8936002)(70586007)(70206006)(8676002)(4326008)(6916009)(44832011)(41300700001)(316002)(54906003)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:30.5284 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac2dd0b3-e953-4150-3d3d-08dbaaa85db4 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: CY4PEPF0000EE3C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8921 xc_dt_overlay() sends the device tree binary overlay, size of .dtbo and overlay operation type i.e. add or remove to xen. Signed-off-by: Vikram Garhwal Reviewed-by: Anthony PERARD --- tools/include/xenctrl.h | 5 ++++ tools/libs/ctrl/Makefile.common | 1 + tools/libs/ctrl/xc_dt_overlay.c | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tools/libs/ctrl/xc_dt_overlay.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 12dca13b69..2ef8b4e054 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2653,6 +2653,11 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout, uint32 int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, xen_pfn_t start_pfn, xen_pfn_t nr_pfns); +#if defined(__arm__) || defined(__aarch64__) +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op); +#endif + /* Compat shims */ #include "xenctrl_compat.h" diff --git a/tools/libs/ctrl/Makefile.common b/tools/libs/ctrl/Makefile.common index 0a09c28fd3..247afbe5f9 100644 --- a/tools/libs/ctrl/Makefile.common +++ b/tools/libs/ctrl/Makefile.common @@ -24,6 +24,7 @@ OBJS-y += xc_hcall_buf.o OBJS-y += xc_foreign_memory.o OBJS-y += xc_kexec.o OBJS-y += xc_resource.o +OBJS-$(CONFIG_ARM) += xc_dt_overlay.o OBJS-$(CONFIG_X86) += xc_psr.o OBJS-$(CONFIG_X86) += xc_pagetab.o OBJS-$(CONFIG_Linux) += xc_linux.o diff --git a/tools/libs/ctrl/xc_dt_overlay.c b/tools/libs/ctrl/xc_dt_overlay.c new file mode 100644 index 0000000000..c2224c4d15 --- /dev/null +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -0,0 +1,50 @@ +/* + * + * Device Tree Overlay functions. + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op) +{ + int err; + struct xen_sysctl sysctl = { + .cmd = XEN_SYSCTL_dt_overlay, + .u.dt_overlay = { + .overlay_op = overlay_op, + .overlay_fdt_size = overlay_fdt_size, + } + }; + + DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size, + XC_HYPERCALL_BUFFER_BOUNCE_IN); + + if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) ) + goto err; + + set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err = do_sysctl(xch, &sysctl)) != 0 ) + PERROR("%s failed", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} From patchwork Fri Sep 1 04:59:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B5347CA0FE1 for ; Fri, 1 Sep 2023 05:12:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594329.927672 (Exim 4.92) (envelope-from ) id 1qbwS5-0007R9-W9; Fri, 01 Sep 2023 05:12:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594329.927672; Fri, 01 Sep 2023 05:12: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 1qbwS5-0007QV-OG; Fri, 01 Sep 2023 05:12:13 +0000 Received: by outflank-mailman (input) for mailman id 594329; Fri, 01 Sep 2023 05:12: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 1qbwGt-0000Nr-EI for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:39 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20615.outbound.protection.outlook.com [2a01:111:f400:7e83::615]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7e21e25c-4884-11ee-8783-cb3800f73035; Fri, 01 Sep 2023 07:00:38 +0200 (CEST) Received: from DS7PR03CA0162.namprd03.prod.outlook.com (2603:10b6:5:3b2::17) by SJ1PR12MB6338.namprd12.prod.outlook.com (2603:10b6:a03:455::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Fri, 1 Sep 2023 05:00:32 +0000 Received: from CY4PEPF0000EE3C.namprd03.prod.outlook.com (2603:10b6:5:3b2:cafe::f6) by DS7PR03CA0162.outlook.office365.com (2603:10b6:5:3b2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.25 via Frontend Transport; Fri, 1 Sep 2023 05:00:32 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3C.mail.protection.outlook.com (10.167.242.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:32 +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; Fri, 1 Sep 2023 00:00:30 -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; Fri, 1 Sep 2023 00:00:30 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7e21e25c-4884-11ee-8783-cb3800f73035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QqAEX/Aia6VR6eHcLHNQ4K4Bfpc1cFBzh/TycvhH1Ei/DFNzO/ctL2TyOi4DQnhE9dDSrWN10koo5fAx2BMEC5nrBJiPMcfDx1nBJXy0EREG5888qAM1UlF3X/qOg2BRZPMtN0cd1y8VjL6cX1ZMAkMzDvHgko4sp6gZ3T0Pbv+Bzh1TF01DIHLF+tssJLB9dWDh+FReWr2QFtjbxf7/eylOzHCWnZwBLSNjoeZ1iBOxg5M5JRJfg9QSApoAAaPZz04rs8iRiPqf6CNqmDS/6V45mkR0+OMKXPUVL+XRD9Te7L2obMGckqg7zV7WRx/qBl0Q98OMuT/g+/YqYMWsfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mTCPtQBNjoIyHEJsEb7hqin0hShKQ1om1xTixiBsYZA=; b=UL+uajtCXEF8s+UfOdk+0K4L4cfmh2KXdQye6aoagTBiY114zW94lF3vqxOlsK78eWdq7hXFQMOOVp5Em95X/ShHo2tf4l3efJQw09ErXlYo24J2wBeWpuMfdqXXMpWcAbcZ8Gd4SFdAwJAEqYHi9U+BoyQk6MYhu2dY2nOweS46ABlKp4dDJsToIHD1xtiOnBCXbInoJN72JAgaykqdXUSBvBevKiYHxgeZTqfON/SHlF0smIsAFcOlqFsSiLLaoBPvDfCGhpbumTKLfJ4BYZSShhXhmdMI+KN7jr20dZeWJJvhRZbYNGxdrNb0alEQXiiPLSfNWe1xBfKwumU2ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mTCPtQBNjoIyHEJsEb7hqin0hShKQ1om1xTixiBsYZA=; b=C7pNEwTj7YlLGY5iutzDUK9P+6dDmxWvdYcCesM/vhscApPjnyLc9ucAmVYpfasG7uapgb3KAtyUfyVjVps/C1v3YVWjC79ybetYvw+D5hDWK8VVqznGDo0gDc1WtAv0A2jwwSxUQ3E3LyYI2Gf7R17kzlWfNKO83UGnnv0P/CA= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Wei Liu , Anthony PERARD , Juergen Gross Subject: [XEN][PATCH v11 19/20] tools/libs/light: Implement new libxl functions for device tree overlay ops Date: Thu, 31 Aug 2023 21:59:46 -0700 Message-ID: <20230901045947.32351-20-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3C:EE_|SJ1PR12MB6338:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d21bdfd-7d6d-449d-cf04-08dbaaa85ea9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ejNHlH2jMBZEeXTHwY/5N/u3gBFXbpvNSt4TMFbC1SrVDeGjKzKykuFfy8T4l63BBmt5d16BEkeiVUf5oGgywnJ+z5NjCeioeT6G+ONgr0CbrRuEYwy/qg6Q9IThD6x7uXD5bOUCPLz2cNAqv9j0bcJo4pk8CxgDBZO54c9vlIlQLBJWaoJ4uORSEIXas9mmPUPuLDLLfDHdfBarfAV5mb1PjT1Se2k853fBzggaBUCFK+mrXfeME3enYWn5sEszTOc9zDT0tUQHVSXt5Yi3TRej8K5c4bWmh4/H6MyyARlK/uzyOhSxGzbfkOct2MhQ/VZTHri0X/JtgP68Fv0LCoff+YXgr0Etz0hcmRNX5ycQnpOa1/w5/RLgUbshY+6z/dvdW1slrGOHc7Y7AKO5R3wiQgiDCZ/U+ajbTmZFVZEgmAZooEXiM3nnnTK0pcsSsAH4nKG2wraLN2aDEM/tSLYZTAgfCL8+eqZVyTM5EZVjLWdd0W5726ghONR7pTQtoaAmnJ+xM2Zeukr4IYXryj5GjeW1Xbm8qgARpr6c+uWZFhBSKaquYQb9yYULA3KbIRyCAz5Acs1UJxp7b8sGJe8KHLCpS/qs/rS8UdziTbrUk7QmZzBiTSGqqY+cM50WmrW7MU8JgvDnQfgaep6yLc1My1VPkPzKhTMk7KmyRUgP0HSQfFOELScPVHJyksXf9RkOMmMGibb4omAYc2XP6M/HZwEQKNsG1rInX+5PEk1MsTdVrjn8nmlXzgkL2i1RYYHZdbfFbFLh46rpfsjtGFAksABZOc9nxqcAtlHvxIQ= 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)(376002)(39860400002)(136003)(451199024)(1800799009)(186009)(82310400011)(40470700004)(46966006)(36840700001)(70206006)(2906002)(36756003)(5660300002)(86362001)(44832011)(40460700003)(82740400003)(356005)(81166007)(40480700001)(36860700001)(47076005)(4326008)(8676002)(336012)(41300700001)(8936002)(426003)(1076003)(2616005)(26005)(316002)(54906003)(6666004)(478600001)(70586007)(6916009)(2004002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:32.1377 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d21bdfd-7d6d-449d-cf04-08dbaaa85ea9 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: CY4PEPF0000EE3C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6338 Signed-off-by: Vikram Garhwal Reviewed-by: Anthony PERARD --- tools/include/libxl.h | 11 +++++ tools/libs/light/Makefile | 3 ++ tools/libs/light/libxl_dt_overlay.c | 71 +++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 tools/libs/light/libxl_dt_overlay.c diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 82b764ff57..abc5fd52da 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -259,6 +259,12 @@ */ #define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 +#if defined(__arm__) || defined(__aarch64__) +/** + * This means Device Tree Overlay is supported. + */ +#define LIBXL_HAVE_DT_OVERLAY 1 +#endif /* * libxl_domain_build_info has device_model_user to specify the user to * run the device model with. See docs/misc/qemu-deprivilege.txt. @@ -2498,6 +2504,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num); void libxl_device_pci_list_free(libxl_device_pci* list, int num); +#if defined(__arm__) || defined(__aarch64__) +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay, + uint32_t overlay_size, uint8_t overlay_op); +#endif + /* * Turns the current process into a backend device service daemon * for a driver domain. diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile index 5d7ff94b05..ba4c1b7933 100644 --- a/tools/libs/light/Makefile +++ b/tools/libs/light/Makefile @@ -112,6 +112,9 @@ OBJS-y += _libxl_types.o OBJS-y += libxl_flask.o OBJS-y += _libxl_types_internal.o +# Device tree overlay is enabled only for ARM architecture. +OBJS-$(CONFIG_ARM) += libxl_dt_overlay.o + ifeq ($(CONFIG_LIBNL),y) CFLAGS_LIBXL += $(LIBNL3_CFLAGS) endif diff --git a/tools/libs/light/libxl_dt_overlay.c b/tools/libs/light/libxl_dt_overlay.c new file mode 100644 index 0000000000..a6c709a6dc --- /dev/null +++ b/tools/libs/light/libxl_dt_overlay.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 Xilinx Inc. + * Author Vikram Garhwal + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl_osdeps.h" /* must come before any other headers */ +#include "libxl_internal.h" +#include +#include + +static int check_overlay_fdt(libxl__gc *gc, void *fdt, size_t size) +{ + int r; + + if (fdt_magic(fdt) != FDT_MAGIC) { + LOG(ERROR, "Overlay FDT is not a valid Flat Device Tree"); + return ERROR_FAIL; + } + + r = fdt_check_header(fdt); + if (r) { + LOG(ERROR, "Failed to check the overlay FDT (%d)", r); + return ERROR_FAIL; + } + + if (fdt_totalsize(fdt) > size) { + LOG(ERROR, "Overlay FDT totalsize is too big"); + return ERROR_FAIL; + } + + return 0; +} + +int libxl_dt_overlay(libxl_ctx *ctx, void *overlay_dt, uint32_t overlay_dt_size, + uint8_t overlay_op) +{ + int rc; + int r; + GC_INIT(ctx); + + if (check_overlay_fdt(gc, overlay_dt, overlay_dt_size)) { + LOG(ERROR, "Overlay DTB check failed"); + rc = ERROR_FAIL; + goto out; + } else { + LOG(DEBUG, "Overlay DTB check passed"); + rc = 0; + } + + r = xc_dt_overlay(ctx->xch, overlay_dt, overlay_dt_size, overlay_op); + + if (r) { + LOG(ERROR, "%s: Adding/Removing overlay dtb failed.", __func__); + rc = ERROR_FAIL; + } + +out: + GC_FREE; + return rc; +} + From patchwork Fri Sep 1 04:59:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vikram Garhwal X-Patchwork-Id: 13372026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C2768CA0FE6 for ; Fri, 1 Sep 2023 05:11:27 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.594261.927555 (Exim 4.92) (envelope-from ) id 1qbwR8-0001Qk-8g; Fri, 01 Sep 2023 05:11:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 594261.927555; Fri, 01 Sep 2023 05:11:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwR8-0001Qb-5U; Fri, 01 Sep 2023 05:11:14 +0000 Received: by outflank-mailman (input) for mailman id 594261; Fri, 01 Sep 2023 05:11:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qbwGu-0001Hn-FU for xen-devel@lists.xenproject.org; Fri, 01 Sep 2023 05:00:40 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20601.outbound.protection.outlook.com [2a01:111:f400:fe59::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 7bffc160-4884-11ee-9b0d-b553b5be7939; Fri, 01 Sep 2023 07:00:35 +0200 (CEST) Received: from DS7PR03CA0168.namprd03.prod.outlook.com (2603:10b6:5:3b2::23) by MN0PR12MB6126.namprd12.prod.outlook.com (2603:10b6:208:3c6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.21; Fri, 1 Sep 2023 05:00:33 +0000 Received: from CY4PEPF0000EE3C.namprd03.prod.outlook.com (2603:10b6:5:3b2:cafe::5a) by DS7PR03CA0168.outlook.office365.com (2603:10b6:5:3b2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.22 via Frontend Transport; Fri, 1 Sep 2023 05:00:32 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3C.mail.protection.outlook.com (10.167.242.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Fri, 1 Sep 2023 05:00:32 +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; Fri, 1 Sep 2023 00:00:31 -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; Fri, 1 Sep 2023 00:00:31 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7bffc160-4884-11ee-9b0d-b553b5be7939 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nf8WcL3qB/lcjeQrNWjnbCxHRKatLQmfford6ksOpyPUlcqya9+6rqLgYHywlsZblr/XqdHW9+2jg1w9yYp3m8RwUQ8a1IzjUXFe1zpVSNpMDHoyIDfeElnLXLfCRiAdMm711eMUs9deU4JNMIos8c2bjyb8LM1DvgkFjvqHyUXaQNxD7020+jlv/GwYuaF2uevF1YznENf02LOymE+zYjppuOmaLJdBA0jLTDIWY6SMHxSm+hyJg4hdvjCZ+CBAtVvLj7TXlTTGr2dtiuOZum8WYtTq+d/Rc7V69LGfIgzpq1KA/f56iIqHAvuTTczPY2sPwpZSBhrg7btHh6izvA== 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=Y04HI+23rnClaNfPhIzLPu8Fg9wvbrQvhxVZD5/M7f6mLclgN0/1oOS2z1kWJ95H89ulgddenQqeBei8xnjA/A6BL2z4jSmW3tS29lRaLbMADPbvtvYM4GpV91h86rcJsMLEA8v2JYbibWjc8vVhLOa+pV+vCEpvhrrOg+gEK/B5BuWzMd/jdbml1oD9ZT3MrZWW+q9EKL/5JWsvaZoaAuYOyxaiy6G1b382y5uJ9PAX6uxMmW8E8/XFLE5id3H9bGpl331cHP+EYg32yk4h0uEl1qE60p1WjLGf5PaH8/PdR/49zNHcFfoK5/DqDv23d0UZjJTiPWZejhd1AtrqQQ== 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=eRlDvm2fCP5AReW4gx03Pg8Kf2U02BfUUIIQtpSLJe4eQsaud9OM/x7iDki4adYaP9+ZngKDrI/Xvpp3bgiyaF9J27sBtZMS5Hg1xW7jnUk6qZ/33i+IPVzihyk8joOLOW7hPdvbsYKDzP+6EHN6YEsKGisDn50urLG790xYNrU= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Vikram Garhwal To: CC: , , , , Wei Liu , Anthony PERARD Subject: [XEN][PATCH v11 20/20] tools/xl: Add new xl command overlay for device tree overlay support Date: Thu, 31 Aug 2023 21:59:47 -0700 Message-ID: <20230901045947.32351-21-vikram.garhwal@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230901045947.32351-1-vikram.garhwal@amd.com> References: <20230901045947.32351-1-vikram.garhwal@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3C:EE_|MN0PR12MB6126:EE_ X-MS-Office365-Filtering-Correlation-Id: 7a01316f-071a-4814-6833-08dbaaa85f04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IKgAg60HDsnCItKCyZIz3/h3CEXHdWo7f3LshDBSsMpz8sM2j6hvobqqtIcVFQgp64BA6iCqOVXUBSTXjl2s8ZjcxNxdzqAPjWPU4L6qH+ubC2jAs+FwiFgKk5+zAedinFu8K6nMp03lf65E0B25JC/p9nqEwE6LYMlBfUxXpYsN04zGTZwiqDdI3pfdcVnNySNJvEewOD0jy87+k6ohbwi8M0Pvb/0bLxgqWlSOt5U3mDs6bdkLTMuSB5yKeO4M9VGMKPO1I0qEcjmiuBSByYduPreVAuAJr4uAJOgwBpIkpl8iNAdFif1oH6wXx6LynkUGWTctN80dxnkLY3qYitQvmrgjJTiFb+jD5oTH9hxPSJE9EjAxDq9KaTQP3ezctCYR6j5Zgr9KBuP3cMI6BNOs9dmfKW9OmYi1UxxukD9jDrzGx0Yw+R/txXg46/X3UwKR0Y/wEFm5HXISvrpkYDubk/ESh3rSbZdxBdgozJ6D8CvRXgyEUwxB2f1UTsRNfJX4qDcqfacFrQiB7z8ybNXbo9Ans4y066VVmKBn4S59IMfMEeBzRT5t2cDniEexEqiJS64j3zu9RmB4amXQiBKjoYIEHyaTz57Naj4iXYFNkvB1PaAuq/LeN72CuZ+5B2Y7B4l0GvqgMn3F15zh8H9MqFAXZZBVA9ZjGaHvLMRVeA52pDv/rB/Z7phzs9zQrgpq0nfa0mvBltnEZG8UDrdNfqj5K18n5W3zCI3sPKmE0EnKTO2ydX1Dwpxp4Z9E2uFdhtPrElO8PTWw6uj6Yg== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(396003)(346002)(376002)(136003)(1800799009)(186009)(451199024)(82310400011)(36840700001)(46966006)(40470700004)(356005)(82740400003)(6666004)(36756003)(40460700003)(36860700001)(86362001)(81166007)(47076005)(40480700001)(2616005)(1076003)(2906002)(426003)(336012)(26005)(83380400001)(478600001)(70586007)(70206006)(8936002)(54906003)(8676002)(4326008)(44832011)(5660300002)(41300700001)(6916009)(316002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2023 05:00:32.7315 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a01316f-071a-4814-6833-08dbaaa85f04 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: CY4PEPF0000EE3C.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6126 Signed-off-by: Vikram Garhwal Reviewed-by: Anthony PERARD --- tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 6 +++++ tools/xl/xl_vmcontrol.c | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/tools/xl/xl.h b/tools/xl/xl.h index 72538d6a81..a923daccd3 100644 --- a/tools/xl/xl.h +++ b/tools/xl/xl.h @@ -138,6 +138,7 @@ int main_shutdown(int argc, char **argv); int main_reboot(int argc, char **argv); int main_list(int argc, char **argv); int main_vm_list(int argc, char **argv); +int main_dt_overlay(int argc, char **argv); int main_create(int argc, char **argv); int main_config_update(int argc, char **argv); int main_button_press(int argc, char **argv); diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 67604e9536..2463521156 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -631,6 +631,12 @@ const struct cmd_spec cmd_table[] = { "Issue a qemu monitor command to the device model of a domain", " ", }, + { "dt-overlay", + &main_dt_overlay, 0, 1, + "Add/Remove a device tree overlay", + "add/remove <.dtbo>" + "-h print this help\n" + }, }; const int cmdtable_len = ARRAY_SIZE(cmd_table); diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 03971927e9..cea5b4a88e 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1265,6 +1265,58 @@ int main_create(int argc, char **argv) return 0; } +int main_dt_overlay(int argc, char **argv) +{ + const char *overlay_ops = NULL; + const char *overlay_config_file = NULL; + void *overlay_dtb = NULL; + int rc; + uint8_t op; + int overlay_dtb_size = 0; + const int overlay_add_op = 1; + const int overlay_remove_op = 2; + + if (argc < 2) { + help("dt_overlay"); + return EXIT_FAILURE; + } + + overlay_ops = argv[1]; + overlay_config_file = argv[2]; + + if (strcmp(overlay_ops, "add") == 0) + op = overlay_add_op; + else if (strcmp(overlay_ops, "remove") == 0) + op = overlay_remove_op; + else { + fprintf(stderr, "Invalid dt overlay operation\n"); + return EXIT_FAILURE; + } + + if (overlay_config_file) { + rc = libxl_read_file_contents(ctx, overlay_config_file, + &overlay_dtb, &overlay_dtb_size); + + if (rc) { + fprintf(stderr, "failed to read the overlay device tree file %s\n", + overlay_config_file); + free(overlay_dtb); + return ERROR_FAIL; + } + } else { + fprintf(stderr, "overlay dtbo file not provided\n"); + return ERROR_FAIL; + } + + rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + + free(overlay_dtb); + + if (rc) + return EXIT_FAILURE; + + return rc; +} /* * Local variables: * mode: C