From patchwork Thu May 23 07:40:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671337 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 9F453C25B7E for ; Thu, 23 May 2024 07:41:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728094.1132869 (Exim 4.92) (envelope-from ) id 1sA34H-0001lE-NG; Thu, 23 May 2024 07:40:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728094.1132869; Thu, 23 May 2024 07:40:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34H-0001l7-KE; Thu, 23 May 2024 07:40:53 +0000 Received: by outflank-mailman (input) for mailman id 728094; Thu, 23 May 2024 07:40:52 +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 1sA34G-0001WY-PD for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:40:52 +0000 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on20601.outbound.protection.outlook.com [2a01:111:f403:2405::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c73155d3-18d7-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 09:40:52 +0200 (CEST) Received: from SJ0PR03CA0272.namprd03.prod.outlook.com (2603:10b6:a03:39e::7) by DS0PR12MB7509.namprd12.prod.outlook.com (2603:10b6:8:137::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19; Thu, 23 May 2024 07:40:47 +0000 Received: from CO1PEPF000066E7.namprd05.prod.outlook.com (2603:10b6:a03:39e:cafe::d0) by SJ0PR03CA0272.outlook.office365.com (2603:10b6:a03:39e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22 via Frontend Transport; Thu, 23 May 2024 07:40:47 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066E7.mail.protection.outlook.com (10.167.249.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:46 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 May 2024 02:40:45 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:44 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c73155d3-18d7-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TXdzLE+kKH46u9Sng84dpWlCTRQJI357cr0AvkengcQnhlsrf5Iwemeh7WjtNCl+oVmvyaOl+qRo056poVrfNWXIYqMuDkUyZNhExvVXeiGUK0NlJ+szO1eTUux0rxa1nrSuFTBhixg8+ls7qMOtkMPs0fkXS2Uny0J19MlrVILVjVAPMI3vp+to+wGDURkbvXSbl3BScWM3vpuOCr7azFdDV7Xg2OBIBeh9x4/93YjS6OKYXFWLAGMMSW8cDIBLF9m7y4KdPa/op6HPrPd+2ni4N4dh2OUfsgNYJHgO179kwWPMfBZR4BtlniN1+bT1AyOFT6Q+UFu6CID2JuMPvA== 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=r/W168QEvQVYTC09iGsQQFU2oTMKOq6gSMJXAiUxem4=; b=NMaeuc0ruls78XaqMFJNAgAvtcN6bNBfxoJjmuiCbICes0/+QLC2obkCdpPQoVBhQL0ENQfje4cRmfZFR9KgqniUMpebFrkOOz3cFsZrqlmcF31v1qWJ5Rs0Ll3JbQypn8xlwTwasDpzPBUxDLNiwvc5y5Yej4wNOlhb9oYIcEuUVTSIlWLDMICcgpBs8uGxpfN2cYo335BptrilvzGoDOBd0yMxzEbWl0MlhPL1GU/fM7VMJviBrWDKUtfm9AtIS01DhceT3L80FxcC2t133Lz6riFYjAbvLyc6LS1EqgJ4WRhMDqh1CvGnwLuuxNo0t5LUrztUNWrKLCEPqUA/mQ== 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 (0) 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=r/W168QEvQVYTC09iGsQQFU2oTMKOq6gSMJXAiUxem4=; b=TXD8tE0v34Mn88tGEFcaqrfSKdZLPHpYn6pij5jvSEULaSUd5NfphWjyhYC4Wk8RFLc6Cjdgs0+Z9W0yFOh1XcOvIvj/168jlMKJmYT9dfPb/Fa6rEtzuSsdLyE+tntQWY84HDSRhDRTpYEVhelkQq3AVSwuDUbD/3tXMgFEHXA= 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: Henry Wang To: CC: Anthony PERARD , Henry Wang , Jason Andryuk Subject: [PATCH v4 1/9] tools/xl: Correct the help information and exit code of the dt-overlay command Date: Thu, 23 May 2024 15:40:32 +0800 Message-ID: <20240523074040.1611264-2-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066E7:EE_|DS0PR12MB7509:EE_ X-MS-Office365-Filtering-Correlation-Id: d377181f-5b2f-445f-d9d5-08dc7afba8e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: aBxdqU1m92P565gZjrLCwUTUZ7iEh2pilmYFgRhCAGqcNpKQ2StZPIxzzdVd96H/MB6e+5lA6zQaY1Ygk0zcz0wvfAuc4PudQL6b7spKqWEZZ84fHVWih+/f76YGFzs14idDEeONJXl8x/+TFsqcViwcVpUoEHIQz4n8qwccKhdCxNPLhmKhqvVaLAC4GEHySL3+qKLA7uAara81nnO+rPGhzJa4kKrTBlWfz6/g8Nz2JsMllz2HLILzJlxEHYGtZyfvoZLF9Z1sb6c91J4jUCy7SmpCRcKF42HkxmISBx0uXDoUkJd3LaHZm3mpQRnQsQVKpb6zNez9gKi2HSLipryEgnyr4sEh802JgkBVwYWnCrGZNF1jozBkvdFXGsZAFPM2duvy8tdWzQluoIfdQw7P7Tr9+njnFoXMaLdlY45m51BjgXsjZAtPBixECkcedvnTfQxuuFgXmRAz+lgnefSYOJ84Se1h477hGdGmXXoocAS4FQTeuoUJ9RxRI3xIbeVPf6oC+weWCzOqfnrH9zjiBqB89rv3I5PkWUJVOuk0jX7c3JyJ2KRvra0s09OGoi6YnTQ/OzWJ0OcHSn31kL9Kq2mzNIM65dbeMa2D2BDvBasOLyjFoKH1bIVFPoYmyK5bCpUaHlALXct3Ck9+8UMfhnixOiX/EpU45+P/NwvqQXjg4/VET6KCcPTpvKtWFOHqVnKiN8E9r3LoprWwb6iuuXQkww4Y2mPmpve4yndQyXNp3IvN6JtFADjGskdtnZraZqmuEAbUw7y6Gwo3QFTpvGVirVQa4ba13obncpsabH/5DEugocn4eyjegc8YB9rk9xRkIhOnIyeOiSI5X1eWxN7mYThjkanxeUadYfqpKSu+99l8tlw+UW+Eci97Yr/L+S+LrCEEdfbAD/a+MW9f4Q9Xe0qYo3LOn8WEG48DbsW3623Bk8y7yVawC5NfVCFGnTlnsC5eNIhqPbCAXxXlqiwVXgDfh9kcJFJWEYijHjJUS8sWG1pZbhiNOH/5e/Sim4eQkCHRWCdmRSRhE89HnvPlnBXVtAbnkr2DAqcyWvjIiZc8WC84gHjbM/ud/tf9RPk5RN8RJ5tOR7mWC+b+DM0O75iYebIuysx6GMv2nSIgQdpARYzFoFkm94etGITtytCUNlhjcU4g1bMqcqRKeYqUnOgtrhhpmfHEP523D9P4nniGe3UZDHH/Pj4tyhKOAnJIl1FSgSZoe/TsnIww0SRQ+WHVwfdwz44P+zvmjaGNIDUiA6+D0923XI/AlDwjBNneGhUhl6XUIUUgR7hvfpci/YNRdvG96VDrma2RNU9wq+unOYC9luT8f9w05OpSDAxXMp0gcpcCywDKtRaLhZ3tAeckhHTcDm5ZfbE= 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)(1800799015)(376005)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:46.6883 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d377181f-5b2f-445f-d9d5-08dc7afba8e7 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: CO1PEPF000066E7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7509 Fix the name mismatch in the xl dt-overlay command, the command name should be "dt-overlay" instead of "dt_overlay". Add the missing "," in the cmdtable. Fix the exit code of the dt-overlay command, use EXIT_FAILURE instead of ERROR_FAIL. Fixes: 61765a07e3d8 ("tools/xl: Add new xl command overlay for device tree overlay support") Suggested-by: Anthony PERARD Signed-off-by: Henry Wang Reviewed-by: Jason Andryuk Reviewed-by: Stefano Stabellini --- v4: - No change. v3: - Add Jason's Reviewed-by tag. v2: - New patch --- tools/xl/xl_cmdtable.c | 2 +- tools/xl/xl_vmcontrol.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 62bdb2aeaa..1f3c6b5897 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -635,7 +635,7 @@ const struct cmd_spec cmd_table[] = { { "dt-overlay", &main_dt_overlay, 0, 1, "Add/Remove a device tree overlay", - "add/remove <.dtbo>" + "add/remove <.dtbo>", "-h print this help\n" }, #endif diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 98f6bd2e76..02575d5d36 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1278,7 +1278,7 @@ int main_dt_overlay(int argc, char **argv) const int overlay_remove_op = 2; if (argc < 2) { - help("dt_overlay"); + help("dt-overlay"); return EXIT_FAILURE; } @@ -1302,11 +1302,11 @@ int main_dt_overlay(int argc, char **argv) fprintf(stderr, "failed to read the overlay device tree file %s\n", overlay_config_file); free(overlay_dtb); - return ERROR_FAIL; + return EXIT_FAILURE; } } else { fprintf(stderr, "overlay dtbo file not provided\n"); - return ERROR_FAIL; + return EXIT_FAILURE; } rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); From patchwork Thu May 23 07:40:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671336 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 DA90AC25B75 for ; Thu, 23 May 2024 07:41:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728095.1132880 (Exim 4.92) (envelope-from ) id 1sA34J-00020W-VF; Thu, 23 May 2024 07:40:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728095.1132880; Thu, 23 May 2024 07:40:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34J-00020L-S1; Thu, 23 May 2024 07:40:55 +0000 Received: by outflank-mailman (input) for mailman id 728095; Thu, 23 May 2024 07:40:55 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34J-0001WY-5o for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:40:55 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2415::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c8a1b593-18d7-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 09:40:54 +0200 (CEST) Received: from CH0PR03CA0317.namprd03.prod.outlook.com (2603:10b6:610:118::12) by DS7PR12MB5718.namprd12.prod.outlook.com (2603:10b6:8:71::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Thu, 23 May 2024 07:40:49 +0000 Received: from CH1PEPF0000AD74.namprd04.prod.outlook.com (2603:10b6:610:118:cafe::9b) by CH0PR03CA0317.outlook.office365.com (2603:10b6:610:118::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20 via Frontend Transport; Thu, 23 May 2024 07:40:49 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH1PEPF0000AD74.mail.protection.outlook.com (10.167.244.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:49 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 May 2024 02:40:47 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:46 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c8a1b593-18d7-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BENyBqWYcm6Pq/xf854269+YaTfuU2GK/+p0Jnp2PKwUYsar2Nz83urLx3jCEj/L5ueXm1O5bTu0EAnIfASZBaRWjtE2RQowQqBMaV2rTC+MxlF38pTt5w9B4FEhhcSuovXgYdg+28i2a5rOLDeYWk3+FlBuQl3MTcGTxEROSFKSp8+ZXMPp42m75LnB4QLA6D1HthnMAWk9sU04CNsrAQgdOJgATTDE0n+D4ARNBfzzLSywBYE7HJp2N6f3jxGEN1+vwteRxZNjy1wxsKuH5k8YyRfIMUVvNXF5Qr6LUFE2ggRGlUQOXEj/6lfKoVBXDNdWFZyOa4GXjnzoTEio9A== 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=1PvDoXhNpQSv0AS8DYv80AMDNw8eCiT+reRuwP+9FhI=; b=hbyVjSNL2HvF+bDJjnSDNSm4BtfimDM57P7OMhiL/VzPvDsYffq1kUjLm0+YOrCnTuEqelgJRq/3sdx8zxpyxxL9irtgAHRD1V6rdRYLNMKQGqwM9pb4dlwTjIlKlUixLKN7fjGa7KfGNKfzZzoR4XYq4Rq1nx/bWwDiLckRgtWmhVNAI1l68rm3ZaxbDVLrN+yTQFKVMByiRgIL0f9Lc8yHsDM7JXVooR71Kxgkf7nz/X03jNeiol6FjpEIOObsQjv9dOQIUbdklfawbNJ/qS/KCqpxx2o+KNOMtuk5GDx7CB6DZcWXpfUDmMJw4DhsDBQoCSnnne6kN8Lc/fqu2g== 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 (0) 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=1PvDoXhNpQSv0AS8DYv80AMDNw8eCiT+reRuwP+9FhI=; b=qC4v2zWovjYwQYxqAG6rfZZkoNEEk79LhoDTTOaW1l/azRRqFDmG2QZ3ISdtF4lKmiQNG5Z6ZKnfq0U0oR/YQjOjCTeIskaCWLoOcabEhsCRE4qOSs2gL7C1YdrhVsdA8PccVZfbR5h+WYKsRq4xcxhKiEwr+/XHJ1fb+HEt4xY= 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: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , "Henry Wang" Subject: [PATCH v4 2/9] xen/arm, doc: Add a DT property to specify IOMMU for Dom0less domUs Date: Thu, 23 May 2024 15:40:33 +0800 Message-ID: <20240523074040.1611264-3-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD74:EE_|DS7PR12MB5718:EE_ X-MS-Office365-Filtering-Correlation-Id: 857a9ee6-1009-4bda-0eb6-08dc7afbaa47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|1800799015|82310400017; X-Microsoft-Antispam-Message-Info: fFIyXY5nh2IaKIY5JtE4otIB+TL2D7QyIMTc6XQhKjU1adF76KFbQXL7Bd4ojsFp1ThFKMlFIh6R2v0cnjhwFNXcfg3UDwgrZdCOwyzyQZszt7HrZpKZ/HKlgTAKwcadTSjEjhRSOzUn7kWQXonrqLdONgNpBoA1SB42vU+uaERhIj41qdMlwc7JCnaXe+Dl65CNAHQQ4EvQAcQxFsaCXenh+AAY3xjDiAgP422tD9te0kdSoCnmhuI5E+vgJlqu3Pqx9ri4waOpeUZW5yi8ymU01Tk8FWTmfv8TrTYOvE9LvmPj2IBZe9y0K+jQfl1e7GNzjt2Pb+iEOFMgIc10hnq1cdHWk/MQoNojL4vfiQlqn7xUwUZ3Gw7964X55sAkGxZvrK+auGL7rjY4F7RJ0AssayHr4v6yH1FysqvNrPSLN2kFm9VB4rVIeSHA4cVlhNBHC8gysgkDAmzkncjEzUzOd+NkOrO3YIVowO/vDEx0qk9ToCA6HRMm5BJOFze/1N63TU8C9qeXwwgdq4sFzhmBFkXNkQIKyu2w/y0nuU/XmiYKXpWi9eLSpCVtFSWr9pphQDfuNRWQbPIZQjexSWYTmYHKOfRPsPKwiRBXxUoYtIeF8QvyOACNuOk9SZ2YLQ5+Fcr1A7Pl9W1FYHeAyP1AfIXKu7fcssmdQQ64QejV7+dicu3iSsgDYwDCaER4oGSNJqBalqix2U7ISn2Wbiqs4KB7xe4X6N1PhyiLNGlZfPGiz6SfPVw85BgHbpb3A88yLoIMAGXNIVY66NYfrh4wUyspjBLCF6cwPVRYPFLwAxGuBc7xIseDZv8yWd2LJTqp0lZK4b8or9EmSQSTAXOAb5EGsZO6bqe1LJ1DT1B/TA0N66jZkXn1i5AMe7+ptH+iwkymHX9jnsp75uKbx9+XAkbLmif3VfjOPeeo70ssCZqgwHGyxtAqEA1BDS665zr0dYiKqhxkiCfmTBsMZTu/CZqVvAVq/nxz0PWNrel1SA61cMvfB+vCtH9ZUgishP6mhlzVUY4qVRIeH9fLag3ZGLld8Ct+gsyHOy4eIOnN6ltKkpmtEiSnm4fs6pxbApFin2gZRF/IJxbFF0dnN5dmd6lQXl2u3dDjU+zk478H36pdXO04b6jBiJJ1GjBClWuJsuUdIbSFOscGXk4NPJHj90xniQ45r1hi2ucuIt7kBYrWM7sBNZ7Je3oFFNGsQuvqOS43+nCe5mKInfdyZ7xLO1o9dZzFPIxC27dZEKZs9OJFydYElttwLsO/MOtwT0RI426znyPFwFWlXlpNHJNTlIw9xSsxeTchdXdL7bsQPQQyeb4Q7q50WHI0s3SZb501MLa3qCmTeTz+Pr0HK2pNXUKPm0JwJzVgr7yISToomKmTX2UNRiuX47stH1FS 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)(376005)(36860700004)(1800799015)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:49.1150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 857a9ee6-1009-4bda-0eb6-08dc7afbaa47 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: CH1PEPF0000AD74.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5718 There are some use cases in which the dom0less domUs need to have the XEN_DOMCTL_CDF_iommu set at the domain construction time. For example, the dynamic dtbo feature allows the domain to be assigned a device that is behind the IOMMU at runtime. For these use cases, we need to have a way to specify the domain will need the IOMMU mapping at domain construction time. Introduce a "passthrough" DT property for Dom0less DomUs following the same entry as the xl.cfg. Currently only provide two options, i.e. "enable" and "disable". Set the XEN_DOMCTL_CDF_iommu at domain construction time based on the property. Signed-off-by: Henry Wang Reviewed-by: Julien Grall --- v4: - No change. v3: - Use a separate variable to cache the condition from the "passthrough" flag separately to improve readability. - Update the doc to explain the default condition more clearly. v2: - New patch to replace the original patch in v1: "[PATCH 03/15] xen/arm: Always enable IOMMU" --- docs/misc/arm/device-tree/booting.txt | 16 ++++++++++++++++ xen/arch/arm/dom0less-build.c | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/misc/arm/device-tree/booting.txt b/docs/misc/arm/device-tree/booting.txt index bbd955e9c2..f1fd069c87 100644 --- a/docs/misc/arm/device-tree/booting.txt +++ b/docs/misc/arm/device-tree/booting.txt @@ -260,6 +260,22 @@ with the following properties: value specified by Xen command line parameter gnttab_max_maptrack_frames (or its default value if unspecified, i.e. 1024) is used. +- passthrough + + A string property specifying whether IOMMU mappings are enabled for the + domain and hence whether it will be enabled for passthrough hardware. + Possible property values are: + + - "enabled" + IOMMU mappings are enabled for the domain. Note that this option is the + default if the user provides the device partial passthrough device tree + for the domain. + + - "disabled" + IOMMU mappings are disabled for the domain and so hardware may not be + passed through. This option is the default if this property is missing + and the user does not provide the device partial device tree for the domain. + Under the "xen,domain" compatible node, one or more sub-nodes are present for the DomU kernel and ramdisk. diff --git a/xen/arch/arm/dom0less-build.c b/xen/arch/arm/dom0less-build.c index 74f053c242..5830a7051d 100644 --- a/xen/arch/arm/dom0less-build.c +++ b/xen/arch/arm/dom0less-build.c @@ -848,6 +848,8 @@ static int __init construct_domU(struct domain *d, void __init create_domUs(void) { struct dt_device_node *node; + const char *dom0less_iommu; + bool iommu = false; const struct dt_device_node *cpupool_node, *chosen = dt_find_node_by_path("/chosen"); @@ -895,8 +897,13 @@ void __init create_domUs(void) panic("Missing property 'cpus' for domain %s\n", dt_node_name(node)); - if ( dt_find_compatible_node(node, NULL, "multiboot,device-tree") && - iommu_enabled ) + if ( !dt_property_read_string(node, "passthrough", &dom0less_iommu) && + !strcmp(dom0less_iommu, "enabled") ) + iommu = true; + + if ( iommu_enabled && + (iommu || dt_find_compatible_node(node, NULL, + "multiboot,device-tree")) ) d_cfg.flags |= XEN_DOMCTL_CDF_iommu; if ( !dt_property_read_u32(node, "nr_spis", &d_cfg.arch.nr_spis) ) From patchwork Thu May 23 07:40:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671340 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 881B4C25B75 for ; Thu, 23 May 2024 07:41:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728096.1132889 (Exim 4.92) (envelope-from ) id 1sA34L-0002Fy-6t; Thu, 23 May 2024 07:40:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728096.1132889; Thu, 23 May 2024 07:40:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34L-0002Fn-3n; Thu, 23 May 2024 07:40:57 +0000 Received: by outflank-mailman (input) for mailman id 728096; Thu, 23 May 2024 07:40:56 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34K-0001WY-60 for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:40:56 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2415::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c93c26aa-18d7-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 09:40:54 +0200 (CEST) Received: from CH0PR03CA0328.namprd03.prod.outlook.com (2603:10b6:610:118::14) by PH7PR12MB6882.namprd12.prod.outlook.com (2603:10b6:510:1b8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Thu, 23 May 2024 07:40:51 +0000 Received: from CH1PEPF0000AD74.namprd04.prod.outlook.com (2603:10b6:610:118:cafe::c8) by CH0PR03CA0328.outlook.office365.com (2603:10b6:610:118::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20 via Frontend Transport; Thu, 23 May 2024 07:40:50 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH1PEPF0000AD74.mail.protection.outlook.com (10.167.244.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:50 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 May 2024 02:40:50 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:48 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c93c26aa-18d7-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GASANB7wRfDiBw1ZYy5MobrfNCEfRYjgsrg/RI9Os1jl+FYX8BtBBlsH2i6cm0Zx5rhfpcNYvoon0qGoYlky02pMMaAG7C7BlMh8+c2uOkoZh+fogGwJxBT18uvpXXqhqLRL/p70C75TwqHAKykez7Zzefbun15eQntzJm98y8yoT64NwCb+Am8oBuTqczJTcXXWq6T9vqHcxU1d3r/YNySJprxtD/pSXPrvfehaE7LxaZcacR/KCFCPMjiwxQabclPXi0DsOlMOrsVvmdiQ4wXVzEjAK5LZzyFiwf5RqNkIUQQMcnIWmJ/NuDA7dwWDPhR5WEtrcYh0pQkYOCg45A== 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=KLxhi2kA+DFIhfmJBOruoj4kiXc2RPsQrpkdr7sIoWE=; b=GVmSctfn71A0m1gonkGAMKOeFxZbt20ohEYTYxQCIPp1oP3L7lW8xv3S3Rm9dqRJrb6E8W/IImqt/oAlmrKTjJUShz7PAmfQcBPK2a4uz58cPPo1ifLksBODz1hmwbZ68L9l7VTGCoaYTekavu3/QGmy5cr4Ck4WxQN8Bj5R2GGDmqKh4TroRksRb3kVj78kRL+opHIleJ0Gl5uybTBZfud/tPYgkZytNeAI0BOKqM+84dSNp5h3Rh0HGEKplaRXnlJie6ZzOhKFDl5q+fv3waqRC2SAffuy9cYUPfxR9NaXIecEvL8rzQCI0sPsEbb7UOREOxv0euKyolsoSnMlPA== 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 (0) 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=KLxhi2kA+DFIhfmJBOruoj4kiXc2RPsQrpkdr7sIoWE=; b=aRguojq0DNlj0lcnHRcOhH6ezOWHKdVvcV/CDw4KPrD1YP5uaohbpDqT26/qwbSr5Jmn3St02CrnbPhrwAKjDTRO6fdGNk4DMET2i+xzmpr+Vei14dfgb4M0B+1ZVnWd2UCIQ2otTCapcJaaSRpKmRUcExijgJ0lLrwVB0oPymg= 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: Henry Wang To: CC: Anthony PERARD , George Dunlap , Nick Rosbrook , "Juergen Gross" , Henry Wang , Jason Andryuk Subject: [PATCH v4 3/9] tools/arm: Introduce the "nr_spis" xl config entry Date: Thu, 23 May 2024 15:40:34 +0800 Message-ID: <20240523074040.1611264-4-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD74:EE_|PH7PR12MB6882:EE_ X-MS-Office365-Filtering-Correlation-Id: ef06980a-a40e-4bda-512a-08dc7afbab4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: DQVn/2bkLGWMeex8Bl0oFAwDENUj5lUQVM7JhtUDpuqti28h65sxsB0XEmcWvu9Ll/jnDvQt2y8gPiOSDM+kqrLse/yY9l4shPu3u0tavdDdN0ny0Fovzz3PXO4vYyEFHd4COKWGtGJIY/vXuiFIlvdNwY+etuJYDnbshwKdKr/FwHz+d79Ek0XQstTzeJhaAtOANh72wnufn7Y55/SpfRPtOIZjj8El4mAreYGQRUR2/VufN9ZMG/wcoNsXu9f9Wk6JQ72EG6dy3oExY0XYaDy/U7DEZu9n0ohqtSo2+fNoSt/QUCzYNbvTWwM/xThDEUpxi5+HTv8cX0a8EvVj0XaH3MrC3qmsXfhdDo8yJE1q48EyV6jJYwFGqEcRomaccr1wLMWOW7rycs/ZuTc5Ee22l+GOerac/fUxrq0gm1t6eEr1ESi0x2xWji5qBG+FOqlt+cBbmaX51/QKi0TtvoMdE31nBm3/hmHZ5xcSC4jnE+z7HRiHpgQ1wc4Dy+J7DLh+/hKpuNYGJK/hBL4ew8LcNS2YJ16lCobsWuMKWuhorTcL8hCQiAGiKG2xp90g4ArdCTPIuB36vLrDLF8FFB3bBLAFjECIsS8qPv7RJw9STMKErZ3tjSQGZb5t9r4KweC4dd0GNBm2vn5qNK6zrV+hzCMqvkgDepTCbjrLzVMShw8k37hSM34lMNV2CEEadENZfUIp7OHXGsZDl/pbGiYaj9jPOi6RGX8O8MNgIaD9/mOJyHO6okRNPAnQqEdM2qTT8Bx6Uz6Om8Y4f9/1zpTq9BpNAqb8FZ9EGUHzNRJkKzX/B4vneUSKUkHggvr99QXjIzjSnrYoFBiBXdf/6cdl9uFLiI5mzqNzQhzeP9RR8v7DF99eOQFHOM8j94M1JFr/VKHscBBu1HrkYTNc0unvXPzsI7QQWu2etFHUSx7A65q1AFt395qgd2Emgo+XLd9cGnRBeCt2HK5dFTfI5uv+PCygWP4OPLsYH/qf5515ANqP9FTmVZVAR7N0UVgwlScJskf9F6cavBKbnGSznmxfN1OKEiq0lg4/BuAVnKQPu7yaIEC4ycxq8mXrXtLm2Ctrgxu01DFziwjXHpQldO7b4y3pOjSd5rVEnFd/mu5wIfG/GdIVw7ydpqv6YMonOKAiHtMQIW/OYz8fyJm3RU8DsswCWOYUGX7sXfa74orrLJlJFG7yn8CcHYj32AFNJY4W59+aXgH+NSPacbLBggyQCuf59WT7a5HSP1tFH34oD8j+W52GJqVgG0gLPR8sG14DWplVOnvaJ9oXxzknj1EM+9d+gSfsp6SpmJnWIpRVXokmg06Iq3R09mQ+Xx8DPHYKdCe5zm26dM2Tlpvtc6S7i7dMyuhuLyhsDqcrNmBSJiGCwkGht0ZC078NUjjs 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)(82310400017)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:50.8337 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ef06980a-a40e-4bda-512a-08dc7afbab4d 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: CH1PEPF0000AD74.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6882 Currently, the number of SPIs allocated to the domain is only configurable for Dom0less DomUs. Xen domains are supposed to be platform agnostics and therefore the numbers of SPIs for libxl guests should not be based on the hardware. Introduce a new xl config entry for Arm to provide a method for user to decide the number of SPIs. This would help to avoid bumping the `config->arch.nr_spis` in libxl everytime there is a new platform with increased SPI numbers. Update the doc and the golang bindings accordingly. Signed-off-by: Henry Wang Reviewed-by: Jason Andryuk --- v4: - Add Jason's Reviewed-by tag. v3: - Reword documentation to avoid ambiguity. v2: - New patch to replace the original patch in v1: "[PATCH 05/15] tools/libs/light: Increase nr_spi to 160" --- docs/man/xl.cfg.5.pod.in | 14 ++++++++++++++ tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 1 + tools/libs/light/libxl_arm.c | 4 ++-- tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 3 +++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 8f2b375ce9..416d582844 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -3072,6 +3072,20 @@ raised. =back +=over 4 + +=item B + +An optional 32-bit integer parameter specifying the number of SPIs (Shared +Peripheral Interrupts) to allocate for the domain. If the value specified by +the `nr_spis` parameter is smaller than the number of SPIs calculated by the +toolstack based on the devices allocated for the domain, or the `nr_spis` +parameter is not specified, the value calculated by the toolstack will be used +for the domain. Otherwise, the value specified by the `nr_spis` parameter will +be used. + +=back + =head3 x86 =over 4 diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index b9cb5b33c7..fe5110474d 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1154,6 +1154,7 @@ return fmt.Errorf("invalid union key '%v'", x.Type)} x.ArchArm.GicVersion = GicVersion(xc.arch_arm.gic_version) x.ArchArm.Vuart = VuartType(xc.arch_arm.vuart) x.ArchArm.SveVl = SveType(xc.arch_arm.sve_vl) +x.ArchArm.NrSpis = uint32(xc.arch_arm.nr_spis) if err := x.ArchX86.MsrRelaxed.fromC(&xc.arch_x86.msr_relaxed);err != nil { return fmt.Errorf("converting field ArchX86.MsrRelaxed: %v", err) } @@ -1670,6 +1671,7 @@ return fmt.Errorf("invalid union key '%v'", x.Type)} xc.arch_arm.gic_version = C.libxl_gic_version(x.ArchArm.GicVersion) xc.arch_arm.vuart = C.libxl_vuart_type(x.ArchArm.Vuart) xc.arch_arm.sve_vl = C.libxl_sve_type(x.ArchArm.SveVl) +xc.arch_arm.nr_spis = C.uint32_t(x.ArchArm.NrSpis) if err := x.ArchX86.MsrRelaxed.toC(&xc.arch_x86.msr_relaxed); err != nil { return fmt.Errorf("converting field ArchX86.MsrRelaxed: %v", err) } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/types.gen.go index 5b293755d7..c9e45b306f 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -597,6 +597,7 @@ ArchArm struct { GicVersion GicVersion Vuart VuartType SveVl SveType +NrSpis uint32 } ArchX86 struct { MsrRelaxed Defbool diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index 1cb89fa584..a4029e3ac8 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -181,8 +181,8 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, LOG(DEBUG, "Configure the domain"); - config->arch.nr_spis = nr_spis; - LOG(DEBUG, " - Allocate %u SPIs", nr_spis); + config->arch.nr_spis = max(nr_spis, d_config->b_info.arch_arm.nr_spis); + LOG(DEBUG, " - Allocate %u SPIs", config->arch.nr_spis); switch (d_config->b_info.arch_arm.gic_version) { case LIBXL_GIC_VERSION_DEFAULT: diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index 79e9c656cc..4e65e6fda5 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -722,6 +722,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), ("sve_vl", libxl_sve_type), + ("nr_spis", uint32), ])), ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool), ])), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index c504ab3711..e3a4800f6e 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -2935,6 +2935,9 @@ skip_usbdev: } } + if (!xlu_cfg_get_long (config, "nr_spis", &l, 0)) + b_info->arch_arm.nr_spis = l; + parse_vkb_list(config, d_config); d_config->virtios = NULL; From patchwork Thu May 23 07:40:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671338 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 7FA9EC25B79 for ; Thu, 23 May 2024 07:41:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728097.1132900 (Exim 4.92) (envelope-from ) id 1sA34P-0002aR-Ht; Thu, 23 May 2024 07:41:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728097.1132900; Thu, 23 May 2024 07:41: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 1sA34P-0002a2-EB; Thu, 23 May 2024 07:41:01 +0000 Received: by outflank-mailman (input) for mailman id 728097; Thu, 23 May 2024 07:40: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 1sA34N-0001WY-GQ for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:40:59 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2415::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cb2aae42-18d7-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 09:40:58 +0200 (CEST) Received: from MW4PR03CA0214.namprd03.prod.outlook.com (2603:10b6:303:b9::9) by BL3PR12MB6643.namprd12.prod.outlook.com (2603:10b6:208:38f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Thu, 23 May 2024 07:40:54 +0000 Received: from CO1PEPF000066ED.namprd05.prod.outlook.com (2603:10b6:303:b9:cafe::2f) by MW4PR03CA0214.outlook.office365.com (2603:10b6:303:b9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36 via Frontend Transport; Thu, 23 May 2024 07:40:54 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066ED.mail.protection.outlook.com (10.167.249.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:53 +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.35; Thu, 23 May 2024 02:40:52 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:50 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cb2aae42-18d7-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BAjQNZm/ATs7jCaRlEhbS7Nw5C78kdhdWkKY+KmIhV0cX4NtiF4QPSxtc/Xt1IlVT1SuyzkvX7TGHzG53LrMNaaViHLRUpU0mlKeP7YbF6oj22yNuCYk3lVoSdcdbB1AapQAuNQTXK179rfvCPqaErhQEprirOG/RWw6HohNeA1MK0p9q2wTIh13kGu5rRM05QlhqM+jIULWq/lfgO+lQJKhdiGClRpc95ExraEtCE28rf60mUBprBpGB0/ib1wEF6Qu/onkct1rtdSHwbf5ZAlEAzB4ukVqTs5VLUYvFQmfTVcV7Mw/UEx4SHxtfFFztdAnxPfyStUCdWvz0Q3eyA== 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=bJ4rFJutdXy/qfPZPTvRAO+qEyMuCy4lZffUC1ijz5Y=; b=TXoLpKg7Xbd+z/nzO7Ngb4nWAkG/qN4DWA0a215/cp+RLLFtwSTWOMnYRjjIx4GuM+azFIJGNW5IEXZiCmDyClIZpHUgyxn4mkfOcTZhV+DksfkBZujGbr+t4QBogaGdN8QNUFKoBUlHd51bIpQY0ZbDDqWuPovPzSkC1jff6RVAJvD4zyeCbo9nm+Rb4SSWA+V/Cch8/6tz8Fo7xYjH09ytMKx3Iq2+9gVEHj5I93gEwvMJLoYBYFRcAS4in+toRkm2x8DkypnNCEheX8qvdNJ9u7Q0+5SYuOACBBDtgQYPQXjZvxl5y4lpI7AniOGneFgaE9NiFpwtVJGydDuyBw== 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 (0) 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=bJ4rFJutdXy/qfPZPTvRAO+qEyMuCy4lZffUC1ijz5Y=; b=uiXBZP2Tg6MRcvKJnEBlCwVRNe4gcODnm8nXD4nDZveMFnwiD38u0jS3p83CTVGJABLAbe0NGgAe5N8JAGF3SQ/JduAOVXvoxK2GIWQLsqhE3LF0IxATU7Hr0DNE4Bc7kozfff1biJeCyYebL5xv28ReFbBjK+8QdJL24u7lCXw= 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: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , "Henry Wang" Subject: [PATCH v4 4/9] xen/arm/gic: Allow adding interrupt to running VMs Date: Thu, 23 May 2024 15:40:35 +0800 Message-ID: <20240523074040.1611264-5-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066ED:EE_|BL3PR12MB6643:EE_ X-MS-Office365-Filtering-Correlation-Id: 7161e61b-6859-4b92-08d0-08dc7afbace7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|82310400017|36860700004|376005; X-Microsoft-Antispam-Message-Info: LYeGWke6n4bX49lwvxP85Ozwipg4qx2/aH0d7Un85TTkALAGeAp4Uj5QfGTDBfXAIfeb2c8gHu8XC7YPqQ9qZG8KX/EawG9bDJQMLgqZ4KPkKPappLluKt5CAgerW39/7TUGf8t5Y+fXeV4VXQQO5/JZSIFm25T/Y/ucrZF38YVNdMNkuLZegOov3WIXNDTblsPBoPfD6d/2eO6jgSjacGhALoZF3TX9v9xc5AFInBXp4Zj8GJDwdGBm+uqYi6CcZU9KhKWpTo6hevZ9GTpBe4Tuge42MuyNTlyueZ9TEmYOiYkGzRLajFg6Bh8G/Yszul9MU7U8Bi0H0tdnCZEsGg9oxpWHlsJK4DzKzOPq7vm/S1HchCdNgZRrZMsCUHtdU5AicYbqGSLNia8F+xpd3VWvXMlAQijetkmvYunXb5pXNH6uGgnNEU7T7jcc65xyIg0m3YyKiDHwgAbLTNDkEkEG9PHjRHjR9wazh9bVULpB5nhlKkZEk5WZ51hHO/QkLrpLAGzXavYS/SbxjcT1mrpydE/1EDM5Xx1fkOj1qPbF69+KqWGGShYaPH8s8BdNydApGnL5ntdnAPA4fH1Npe7KLXGQvAlgTMZuOWzvpcIZn5GW1OzR0NP71FOYZgzp21ZDUDM9JODeHjofqkhmUnHit6AYprwRXKvVz25deIdjPh1gMWndRMPwY77O5P4BdiHg1dpfXxWJ55O4npal4ZNXr6odCKF9ZMzLtSGOMaha28QZ0eQgeQzldViIUypkwGffNrMbYmkazvHqjnjgLclZna94RcdqD6UUOp+utj6igelleEyeynOz6qwVy0uoJeWd9TxcKDAzY0onyLS4eOF3M9qpYHTFBCYaeBe2Y7FIOlOeSyEk/trjOJ78tNjJbkbZtpJ85VDvnk+QV6Zl1gJgtpjnpHRg8XzjW9rcmy6YD4DEZuXRQZ8CfEl5JbRbnCiRH9ri3kjhcfmzXyBj6blllFFKlBe5Hh0lumyVJMFZ/+RFb87FNs0r2qcDoV5r6FFjPKfI4mt6ZZGFUVw5oh3SWKahKKc0pRbyk1YIsgTWuJ6R6nbrNGb/Oz3RC7GeMjRjewoHrCqzbgi7JhFI/vFVszGqgEfZ+64BymI2ET0nnui8bLKohML2YMb7Vq1mvqvUa4X0+AGeR70eZqM7pi0ANYWxF8DJ4Zmjg93W2/RsLlwWxG5qNhAqTiCstsqIiIkrMjDFc5BvuSDfZ9i6cgMTPg4Mj7ClG/wPJHGRJISKOVylkfwkqk1hud1MsyWXnAYvYqhn6eoIbds+e75u4aW4VWwIylncgJpH9siiL4qerWCg1U2NjuMY2nkFg3UaWqate6R1U90Idcib8KwhocfbFjzFzCCs2LcMzxpfzHbbPSX1KkPmpZYCjuDtb0Kl 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)(1800799015)(82310400017)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:53.4407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7161e61b-6859-4b92-08d0-08dc7afbace7 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: CO1PEPF000066ED.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6643 Currently, adding physical interrupts are only allowed at the domain creation time. For use cases such as dynamic device tree overlay addition, the adding of physical IRQ to running domains should be allowed. Drop the above-mentioned domain creation check. Since this will introduce interrupt state unsync issues for cases when the interrupt is active or pending in the guest, therefore for these cases we simply reject the operation. Do it for both new and old vGIC implementations. Signed-off-by: Henry Wang Reviewed-by: Julien Grall --- v4: - Split the original patch, only do the adding IRQ stuff in this patch. v3: - Update in-code comments. - Correct the if conditions. - Add taking/releasing the vgic lock of the vcpu. v2: - Reject the case where the IRQ is active or pending in guest. --- xen/arch/arm/gic-vgic.c | 9 +++++++-- xen/arch/arm/gic.c | 8 -------- xen/arch/arm/vgic/vgic.c | 7 +++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c index 56490dbc43..b99e287224 100644 --- a/xen/arch/arm/gic-vgic.c +++ b/xen/arch/arm/gic-vgic.c @@ -442,9 +442,14 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq, if ( connect ) { - /* The VIRQ should not be already enabled by the guest */ + /* + * The VIRQ should not be already enabled by the guest nor + * active/pending in the guest. + */ if ( !p->desc && - !test_bit(GIC_IRQ_GUEST_ENABLED, &p->status) ) + !test_bit(GIC_IRQ_GUEST_ENABLED, &p->status) && + !test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) && + !test_bit(GIC_IRQ_GUEST_ACTIVE, &p->status) ) p->desc = desc; else ret = -EBUSY; diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 44c40e86de..b3467a76ae 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -135,14 +135,6 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int virq, ASSERT(virq < vgic_num_irqs(d)); ASSERT(!is_lpi(virq)); - /* - * When routing an IRQ to guest, the virtual state is not synced - * back to the physical IRQ. To prevent get unsync, restrict the - * routing to when the Domain is been created. - */ - if ( d->creation_finished ) - return -EBUSY; - ret = vgic_connect_hw_irq(d, NULL, virq, desc, true); if ( ret ) return ret; diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index b9463a5f27..048e12c562 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -876,8 +876,11 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *vcpu, if ( connect ) /* assign a mapped IRQ */ { - /* The VIRQ should not be already enabled by the guest */ - if ( !irq->hw && !irq->enabled ) + /* + * The VIRQ should not be already enabled by the guest nor + * active/pending in the guest + */ + if ( !irq->hw && !irq->enabled && !irq->active && !irq->pending_latch ) { irq->hw = true; irq->hwintid = desc->irq; From patchwork Thu May 23 07:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671341 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 6D25DC25B7F for ; Thu, 23 May 2024 07:41:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728098.1132910 (Exim 4.92) (envelope-from ) id 1sA34R-0002tB-Ro; Thu, 23 May 2024 07:41:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728098.1132910; Thu, 23 May 2024 07:41:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34R-0002sv-Mm; Thu, 23 May 2024 07:41:03 +0000 Received: by outflank-mailman (input) for mailman id 728098; Thu, 23 May 2024 07:41:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34P-0001WY-GT for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:41:01 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20601.outbound.protection.outlook.com [2a01:111:f403:2412::601]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cbe9361c-18d7-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 09:41:00 +0200 (CEST) Received: from SJ0PR03CA0271.namprd03.prod.outlook.com (2603:10b6:a03:39e::6) by CY5PR12MB6059.namprd12.prod.outlook.com (2603:10b6:930:2c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.19; Thu, 23 May 2024 07:40:57 +0000 Received: from CO1PEPF000066E7.namprd05.prod.outlook.com (2603:10b6:a03:39e:cafe::7) by SJ0PR03CA0271.outlook.office365.com (2603:10b6:a03:39e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55 via Frontend Transport; Thu, 23 May 2024 07:40:56 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066E7.mail.protection.outlook.com (10.167.249.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:56 +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.35; Thu, 23 May 2024 02:40:55 -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.35; Thu, 23 May 2024 02:40:55 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:52 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cbe9361c-18d7-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YgKPuDp7h7POl4wtY17dpSFPp8a6+4Lys+iwRMefruh2Udblq2blnNdDZi2gOiLTJUITY4Pt30iHICpvdu/IY45SLJxaonu2k56Nvtlcc2zkyH4fR7+F2SV2lm4pu1iQ0bAGDkbYbLp4KQCBL2pBRKC1MQ5j/hbMnaJX9OZivvlyyD4QIwrRKYg6VdSW624ucIJCCvaQ/E3Nfq2O/sIBjAebwwvhlXO/YjW+3HO4zenxkD3pN7vnBlXlyGeHyhY4jntT/HSyH9K2I1VT6bF4Dja1tXBj2pVOYYqvghCUZFXvc6doUtbVK3InJ7Xi7NdyaJ8M+146exxfVDx/GcgcJg== 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=6cGqHcXBoZTzyZBk/4TEkkSbTo+NOg9YMZd/62zSuww=; b=RBlHBzNTiHNVbAyJR/b4bLst0YADu4Ycino6UouZKWc+a32S6KnktaRy+HkL+wBuyLkQU44MdC0YXbpn7Jw0hhz5RBhs2zuzrZI2cG1blozJcZr0Te6yqw/3NUIk8vEP6mfpJDQUyjbmzrQVrYCjFWyG8HtgyVYH6hhhwJd5in2zvU+1ZwGbtZQy5DH0nrQFOYrLhPWJzzaVIoY+hTyn4DPYtcC+q3/WJdymv1+D9XHU9yos9RfxvUXiXUJ9EnRYOt+jPBCgqv5LA92mAWzhfLDk4+IPAGy8m8iJCZl1sdw7xKVUdCcSZ+hdT3DiK7To42ANjoRCkoDkvuYN1jiujA== 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 (0) 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=6cGqHcXBoZTzyZBk/4TEkkSbTo+NOg9YMZd/62zSuww=; b=xJskQFAZddZKAwcQxfx5spyajeQxOAUZ5CLC36EHTuG3H+tvT9g5A8R8BMNF7673A55ScT+DapVPdqY95hX84GlS1FcxFOdX3tbmIETcnb91ATT50UnPRkfKbGn9joKxDy/hbTtNDfXEw8PRM3KHl+ZS/DKxxHpZ1QwpgcJyPo4= 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: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Jan Beulich , Henry Wang Subject: [PATCH v4 5/9] xen/arm: Add XEN_DOMCTL_dt_overlay and device attachment to domains Date: Thu, 23 May 2024 15:40:36 +0800 Message-ID: <20240523074040.1611264-6-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066E7:EE_|CY5PR12MB6059:EE_ X-MS-Office365-Filtering-Correlation-Id: 45c5f866-43a4-4ba9-97dc-08dc7afbaeb7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: lecmbsste4sgjSXM7CrLlaewWO9a0Gm4oDdXUun5hp1CNdD9qi9oXY/NcOhPb5Aoly6URh3mwihLbtCIQmfwlpGGROZiV8qVCm01V9KDF/+8IjJGjGuDuecS7+hLjf+xuKlOO7yj3eP4wMqgb3LxaR6j0JVSUO9bPa33vfjWa8zmS9E7pcrBU0NY0a+0yXVsvVRR996oR0rCUp6Pky9x7oc7S6JkZfplifNdNbxdEz6zMt+D/7gJg2cNkFXmGsHsp4NYq4Ji3Oa37H5Bb7Y3dfBh/dWjPt2Yl393SUZSoIyW4MHU3Wz3lgvseYlLVizKeNWGdM2nUTgsBcxrGVlEuiywpIXShYZdoG+6qZxv4FJwADCHHz7ofWzVDnbxcVg7iFcoabqASPITLiWwvkIWCARk9yk3VEJVNPjY6Ne3w2KWdHvXswNje9US0aKIVjGcqigM0vM+mZyydpKzKBgRyMKyvmgl+zIDOpuarVZ8GHxTPn1nGtZwG5qDsWjVPbRoLy6wZQkrbwq+z1zOSzDWink23W28Nu2Uy3Vzgw9FCxDMDwkazl9GbGzrdD+5WP0VslJB4osAP7/n99Y5m3EzIkqYDAmCADFh1Qmzus9qwR7fwU5zDpYtC3s7MsEESyArq7eRLxQ5OKd7pq4jYq0I/ZLKCz/y0FQMqiLxhDEqDqWzt1YDp/v0CHQp45NTDPBHLxCATlpKeki+QaIdppgMBCQjKFeD2Rgel67RJyB6XRUALiud4f9ZrBIEkA6Zb1OdeSPcyomr03X19fD+Q3PuoIfi4W3GBVVIy14CYL+F1a1CCMjXVlTLLH4O0mQ3hR2FWerjAW+cUkfFGyNQ0gNwPR6H/wIU9FBuLJ8p9C0wk6n8OXiPb5HpAXBUBEAdKcD4EmM6lAAEpiiUTsIApv3jwBYeqtRT+04Yxj1ahBd3LJERH7yrzNs8rRYOG4hSzSZlTwousILBfu/w9gmMuKmpQTPgvB3Lj6pEJI0USgDcDNs6j2ce2oFZ9/GcYotpo3HG9ZIdMkL7zBnuFj1O8YwSw3LL7ok9Baq7HfOMcKCth25XCp/AaKMStMpjHWKLF66fPgmw2alA+ng3GbgHuqpfIu3w/SKoJmk6QkNPaR1FWYGxNqBJHyIZQ7yH/2KFiG9RxgzvWa0NU2gZY27kgBzjjcHxv6sj9rFcJmro2GuyZ5I4cjtLvOmqcZOam3DKCPRPD6cDMy3DBHqh7BeVLu5NkbdS+xy3q0Ogc5jJqnkBdpi4y3ZsqzuQBa1P1JQVxoLWdwsNBqmhk027kiIZ+Iife+WUP2fOe3jGp+/QzM00zk1pr49lswhj/DBugS9kIiAglfKOthZRkcgQoLCQ9ik3NLZht1itzJ7XNvbQDelnns7ksV2btW6C7aA4UHlTjAUd 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)(36860700004)(376005)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:56.4696 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 45c5f866-43a4-4ba9-97dc-08dc7afbaeb7 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: CO1PEPF000066E7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6059 In order to support the dynamic dtbo device assignment to a running VM, the add/remove of the DT overlay and the attach/detach of the device from the DT overlay should happen separately. Therefore, repurpose the existing XEN_SYSCTL_dt_overlay to only add the DT overlay to Xen device tree, instead of assigning the device to the hardware domain at the same time. Add the XEN_DOMCTL_dt_overlay with operations XEN_DOMCTL_DT_OVERLAY_ATTACH to do the device assignment to the domain. The hypervisor firstly checks the DT overlay passed from the toolstack is valid. Then the device nodes are retrieved from the overlay tracker based on the DT overlay. The attach of the device is implemented by mapping the IRQ and IOMMU resources. Signed-off-by: Henry Wang Signed-off-by: Vikram Garhwal --- v4: - Split the original patch, only do the device attachment. v3: - Style fixes for arch-selection #ifdefs. - Do not include public/domctl.h, only add a forward declaration of struct xen_domctl_dt_overlay. - Extract the overlay track entry finding logic to a function, drop the unused variables. - Use op code 1&2 for XEN_DOMCTL_DT_OVERLAY_{ATTACH,DETACH}. v2: - New patch. --- xen/arch/arm/domctl.c | 3 + xen/common/dt-overlay.c | 199 ++++++++++++++++++++++++++--------- xen/include/public/domctl.h | 14 +++ xen/include/public/sysctl.h | 11 +- xen/include/xen/dt-overlay.h | 7 ++ 5 files changed, 176 insertions(+), 58 deletions(-) diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index ad56efb0f5..12a12ee781 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -5,6 +5,7 @@ * Copyright (c) 2012, Citrix Systems */ +#include #include #include #include @@ -176,6 +177,8 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, return rc; } + case XEN_DOMCTL_dt_overlay: + return dt_overlay_domctl(d, &domctl->u.dt_overlay); default: return subarch_do_domctl(domctl, d, u_domctl); } diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index 9cece79067..1087f9b502 100644 --- a/xen/common/dt-overlay.c +++ b/xen/common/dt-overlay.c @@ -356,6 +356,42 @@ static int overlay_get_nodes_info(const void *fdto, char **nodes_full_path) return 0; } +/* This function should be called with the overlay_lock taken */ +static struct overlay_track * +find_track_entry_from_tracker(const void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + struct overlay_track *entry, *temp; + bool found_entry = false; + + ASSERT(spin_is_locked(&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 ) + { + found_entry = true; + break; + } + } + + if ( !found_entry ) + { + printk(XENLOG_ERR "Cannot find any matching tracker with input dtbo." + " Operation is supported only for prior added dtbo.\n"); + return NULL; + } + + return entry; +} + /* Check if node itself can be removed and remove node from IOMMU. */ static int remove_node_resources(struct dt_device_node *device_node) { @@ -485,8 +521,7 @@ 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; + struct overlay_track *entry; rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); if ( rc ) @@ -494,29 +529,10 @@ static long handle_remove_overlay_nodes(const void *overlay_fdt, 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 ) + entry = find_track_entry_from_tracker(overlay_fdt, overlay_fdt_size); + if ( entry == NULL ) { 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; } @@ -620,15 +636,7 @@ static long add_nodes(struct overlay_track *tr, char **nodes_full_path) return -EFAULT; } - rc = handle_device(hardware_domain, overlay_node, p2m_mmio_direct_c, - tr->iomem_ranges, - tr->irq_ranges); write_unlock(&dt_host_lock); - 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; @@ -638,9 +646,7 @@ static long add_nodes(struct overlay_track *tr, char **nodes_full_path) } /* * 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(). + * We use tr->dt_host_new to unflatten the updated device_tree_flattened. */ static long handle_add_overlay_nodes(void *overlay_fdt, uint32_t overlay_fdt_size) @@ -774,20 +780,6 @@ static long handle_add_overlay_nodes(void *overlay_fdt, 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 ) { @@ -843,14 +835,83 @@ static long handle_add_overlay_nodes(void *overlay_fdt, xfree(tr->nodes_address); xfree(tr->fdt); - rangeset_destroy(tr->irq_ranges); - rangeset_destroy(tr->iomem_ranges); - xfree(tr); return rc; } +static long handle_attach_overlay_nodes(struct domain *d, + const void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc; + unsigned int j; + struct overlay_track *entry; + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + return rc; + + spin_lock(&overlay_lock); + + entry = find_track_entry_from_tracker(overlay_fdt, overlay_fdt_size); + if ( entry == NULL ) + { + rc = -EINVAL; + goto out; + } + + entry->irq_ranges = rangeset_new(d, "Overlays: Interrupts", 0); + if (entry->irq_ranges == NULL) + { + rc = -ENOMEM; + printk(XENLOG_ERR "Creating IRQ rangeset failed"); + goto out; + } + + entry->iomem_ranges = rangeset_new(d, "Overlay: I/O Memory", 0); + if (entry->iomem_ranges == NULL) + { + rc = -ENOMEM; + printk(XENLOG_ERR "Creating IOMMU rangeset failed"); + goto out; + } + + for ( j = 0; j < entry->num_nodes; j++ ) + { + struct dt_device_node *overlay_node; + + overlay_node = (struct dt_device_node *)entry->nodes_address[j]; + if ( overlay_node == NULL ) + { + rc = -EINVAL; + goto out; + } + + write_lock(&dt_host_lock); + rc = handle_device(d, overlay_node, p2m_mmio_direct_c, + entry->iomem_ranges, entry->irq_ranges); + write_unlock(&dt_host_lock); + if ( rc ) + { + printk(XENLOG_ERR "Adding IRQ and IOMMU failed\n"); + goto out; + } + } + + spin_unlock(&overlay_lock); + + return 0; + + out: + spin_unlock(&overlay_lock); + + rangeset_destroy(entry->irq_ranges); + rangeset_destroy(entry->iomem_ranges); + + return rc; +} + long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) { long ret; @@ -890,6 +951,42 @@ long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) return ret; } +long dt_overlay_domctl(struct domain *d, struct xen_domctl_dt_overlay *op) +{ + long ret; + void *overlay_fdt; + + if ( op->overlay_op != XEN_DOMCTL_DT_OVERLAY_ATTACH ) + 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_DOMCTL_DT_OVERLAY_ATTACH ) + ret = handle_attach_overlay_nodes(d, overlay_fdt, op->overlay_fdt_size); + + xfree(overlay_fdt); + + return ret; +} + /* * Local variables: * mode: C diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index a33f9ec32b..ac3c2a7c4c 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1190,6 +1190,16 @@ struct xen_domctl_vmtrace_op { typedef struct xen_domctl_vmtrace_op xen_domctl_vmtrace_op_t; DEFINE_XEN_GUEST_HANDLE(xen_domctl_vmtrace_op_t); +#if defined(__arm__) || defined(__aarch64__) +struct xen_domctl_dt_overlay { + XEN_GUEST_HANDLE_64(const_void) overlay_fdt; /* IN: overlay fdt. */ + uint32_t overlay_fdt_size; /* IN: Overlay dtb size. */ +#define XEN_DOMCTL_DT_OVERLAY_ATTACH 1 + uint8_t overlay_op; /* IN: Attach. */ + uint8_t pad[3]; /* IN: Must be zero. */ +}; +#endif + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1277,6 +1287,7 @@ struct xen_domctl { #define XEN_DOMCTL_vmtrace_op 84 #define XEN_DOMCTL_get_paging_mempool_size 85 #define XEN_DOMCTL_set_paging_mempool_size 86 +#define XEN_DOMCTL_dt_overlay 87 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1339,6 +1350,9 @@ struct xen_domctl { struct xen_domctl_vuart_op vuart_op; struct xen_domctl_vmtrace_op vmtrace_op; struct xen_domctl_paging_mempool paging_mempool; +#if defined(__arm__) || defined(__aarch64__) + struct xen_domctl_dt_overlay dt_overlay; +#endif uint8_t pad[128]; } u; }; diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index febaa4b16a..3a6e7d48f0 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -1184,14 +1184,11 @@ 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__) +#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. + * Performs addition/removal of device tree nodes under parent node using dtbo + * from dt_host. */ struct xen_sysctl_dt_overlay { XEN_GUEST_HANDLE_64(const_void) overlay_fdt; /* IN: overlay fdt. */ @@ -1265,7 +1262,7 @@ struct xen_sysctl { struct xen_sysctl_cpu_policy cpu_policy; #endif -#if defined(__arm__) || defined (__aarch64__) +#if defined(__arm__) || defined(__aarch64__) struct xen_sysctl_dt_overlay dt_overlay; #endif uint8_t pad[128]; diff --git a/xen/include/xen/dt-overlay.h b/xen/include/xen/dt-overlay.h index c0567741ee..7f0f3741b5 100644 --- a/xen/include/xen/dt-overlay.h +++ b/xen/include/xen/dt-overlay.h @@ -39,15 +39,22 @@ struct overlay_track { }; struct xen_sysctl_dt_overlay; +struct xen_domctl_dt_overlay; #ifdef CONFIG_OVERLAY_DTB long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op); +long dt_overlay_domctl(struct domain *d, struct xen_domctl_dt_overlay *op); #else #include static inline long dt_overlay_sysctl(struct xen_sysctl_dt_overlay *op) { return -EOPNOTSUPP; } +static inline long dt_overlay_domctl(struct domain *d, + struct xen_domctl_dt_overlay *op) +{ + return -EOPNOTSUPP; +} #endif #endif /* __XEN_DT_OVERLAY_H__ */ From patchwork Thu May 23 07:40:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671344 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 8C42FC41513 for ; Thu, 23 May 2024 07:41:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728101.1132930 (Exim 4.92) (envelope-from ) id 1sA34Y-0003hP-N9; Thu, 23 May 2024 07:41:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728101.1132930; Thu, 23 May 2024 07:41: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 1sA34Y-0003gE-Gq; Thu, 23 May 2024 07:41:10 +0000 Received: by outflank-mailman (input) for mailman id 728101; Thu, 23 May 2024 07:41:09 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34W-0003CF-VT for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:41:08 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20600.outbound.protection.outlook.com [2a01:111:f403:2415::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cdf34002-18d7-11ef-b4bb-af5377834399; Thu, 23 May 2024 09:41:03 +0200 (CEST) Received: from CH0PR03CA0441.namprd03.prod.outlook.com (2603:10b6:610:10e::34) by LV3PR12MB9215.namprd12.prod.outlook.com (2603:10b6:408:1a0::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.18; Thu, 23 May 2024 07:40:59 +0000 Received: from CH1PEPF0000AD77.namprd04.prod.outlook.com (2603:10b6:610:10e:cafe::99) by CH0PR03CA0441.outlook.office365.com (2603:10b6:610:10e::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.18 via Frontend Transport; Thu, 23 May 2024 07:40:59 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH1PEPF0000AD77.mail.protection.outlook.com (10.167.244.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:40:58 +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.35; Thu, 23 May 2024 02:40:57 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:55 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cdf34002-18d7-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RBUWCnqg9UeHYedJVl/R9pfYRSQPbqjaNn7+kPZ1VzeYDdGsRAp6XO47j2WTc9R8hM4UNNlWKMNw9MswuMqsmKEnjdMfgGqrE4wyf3xQ5L0TofVKYiwN/gtb9hkGr8TqbdvBzej0OAR6vc5DxmMLvGN0qg4FskHGYTkKxlhZ63v0cofGYvrswBoEhfCeZ8RopH0nWDa1LGDZsA/ec4cxH9Zj+CN4JI0T4+i/Q7sIZD1vJQ/3sudVXdI5ooolnAkTZcHZi2yu8B501MN90jnYqJ6+zAOnPs4lfH8osgQlkR2uMslfZYvy/hi8DC71mal6htn6GKUl6Sy27xa20e76Yw== 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=L8dKwKh5Agkr6/Sz2gAOhHiky/a7zfL5mmaZ+kO5RLw=; b=n1oH2n8ilKylm7HfqTfqeCDmNiQtZwqTCQcKFooiKb/aHe0ze2d4w91fG5jwTa5/Ewa6XB40tDtz+8hCSkuEIqIfOyufbswZ7vWKRIkSI+OmcaI2TH+9GepKfewK2djNlRVg1uBg0F0Q6uftP6/mJQ0cSDpICce7ZkXgFJziWxsChmFYBhpk8vTg2lrUJvskgp9invOzTcyybXEf4uopUDYYm4Gdm6N4BJYZEd+i9WI4mv89/JiCoCu5VuOfrZ8amP9G3upRy8TnMQmepNchdZiJcpL0wxXcbc8DHoa6v6l9VmJouTLy1ba52svo04rMRpS5NXJUTMhsSXsX5u8oXw== 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 (0) 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=L8dKwKh5Agkr6/Sz2gAOhHiky/a7zfL5mmaZ+kO5RLw=; b=qu60VsrHqx7x0QzeoqjN1uswiuS4Q1T48lpY2u313+IUphvS2ILN1y95o22X8mXIlwIIRO/lLjU03QmQ+WB7xdH93inSSXHU55FDY6au3ea7lxuRv1I7M4lnt34nX9KtrG1WnBE3q4ESb9ADol4AxaplKS1KRoggPbLZzYm8kmQ= 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: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , "Henry Wang" Subject: [PATCH v4 6/9] xen/arm/gic: Allow removing interrupt to running VMs Date: Thu, 23 May 2024 15:40:37 +0800 Message-ID: <20240523074040.1611264-7-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD77:EE_|LV3PR12MB9215:EE_ X-MS-Office365-Filtering-Correlation-Id: 26087eb1-bd6e-4dcb-36f2-08dc7afbb00a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|36860700004|82310400017; X-Microsoft-Antispam-Message-Info: 589QVo1rUR6jtYI+hepZXhQS/2JuFhESRrE1KFczuIeIYQSskO+IhDLWCaOlUHGvySCx19xxCsbhFfvDxlEYvOmKeT8tUgDhd6i6eGKqvGTlfBDq5zP+wCyVgsGJbAP+G9sH6anfv2ucG5DNXxVZbqvkomx/ClEJHK1XMj+6s9BZxydxLttU5ejamBYAhW8iDb8Pdgvn3NtIK6YaSY/B0HxvWftP7f0CDPeUeJf7uMX5cnE+MABpDff/pLQDcKV6kRJaTp3vw8/07bZ+uEZgO3NbCyj/MH8peeG6167VzW9vcdPeiM2QdG/3PU2qY2pk2b8PGd7yQvWp9/qHwlvNKYvIYaiIHFRvHzGwuM3v+ECDZH2KsqqJ2WIQwqDdANA40bK7jsRe3Ajw1/clkgMXzbDOTEGaCfKJPT9eEVgS3XXjolOepU2d3oOJojTuh0jK+NVYIJUB0gb7Yh41QTKxMXrKZWwIF3DhNgf0qdpiqncx0la5AOMtFF/QOc1qlbWTnDn8hBiigpfhzqKGceSqJ8/gyWKUKzXMBYpXwQzcG+j4A/fGi8WZwnjrxo4cmeCjEfUf5BefQLSwlwoCvelkAPDRmp+Rrep0s8YKMOiOJneQK+7daTpCmFHKLxk1xPJ7HbGc1uZOHVAtnK0wEvYq5r6pQdd1qV7F6zsGcR8Os60w2KG4PRc9s+LcT7yjki5S/uzSpUplqRiCMCI/3AUFpoR5ZOz0c8S1j9BSGXigW6P6z5dcKzVWlH/8GfJbHybE2TKuzZep87BkPtsQcQUa9RG2aEPAHWZaGa0Wb5HBGoA9BE/vNzVLUtxeHFEirjvHV8fBKerQb9m1UKd/0BSeBMEvvtMMSUOdBi+UVu2qVaW9EDpHvxvN0XMK35Jm/mgo2DR9hvUqWEoI0EqVGCxWZUy4H/6xtm54Lh8BR9ZLbAuX1Fmp0asdNgpXH2RwbaTxTSLD/VXpJsPdxdfG5i62/EHK77LaRZnhmxtMZ++FcodvkTeUOdn6Sii9kTjxCw8CcwlL4L7dEIDmOT1TNgMIT1K6T0Kp1nY+CdbmS89ieHB8eFqu03mfGLoAHyg77CFxjbjs/pI/bG+0hN+jl54Fbsnm7stFkUUoiwnYcI+nyhL4L/VfLTIoUgy8oA/sCeZZOY6nDb4dIlipa+MqEUY6+j9RKnI+/ZZhiNV+PtC5ou5FZuvuqMVYsFcWFnThJiHQMdu/yQjOFY/o1a5xYH5H3R8SphjTcPMGA0yh7jnB4ry9W8P3JRGRfTY06Ca5swh4EeACv1QLdXY+G4llyZN2iBzyQV+jLZDmRkSqjkP+3FQHLoxRyEecKZET/bsAAEXtd746LkaBI2a7eyW9Y71YsTtKrJPV8SPbQzI+8P978YdRzxirDX2UX1v+FcpyI7C5 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)(376005)(1800799015)(36860700004)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:40:58.7826 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26087eb1-bd6e-4dcb-36f2-08dc7afbb00a 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: CH1PEPF0000AD77.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9215 From: Vikram Garhwal Currently, removing physical interrupts are only allowed at the domain destroy time. For use cases such as dynamic device tree overlay removing, the removing of physical IRQ to running domains should be allowed. Move the above-mentioned domain dying check to vgic_connect_hw_irq(). Similarly as the routing interrupt to running domains, reject the operation if the IRQ is active or pending in the guest. Do it for both new and old vGIC implementations. Since now vgic_connect_hw_irq() may reject the invalid operation case, move the clear of _IRQ_INPROGRESS flag in gic_remove_irq_from_guest() to after the successful execution of vgic_connect_hw_irq(). Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Signed-off-by: Henry Wang --- v4: - Split the original patch, only do the removing IRQ stuff in this patch. - Move the clear of _IRQ_INPROGRESS flag in gic_remove_irq_from_guest() to after the successful execution of vgic_connect_hw_irq(). - Special case the d->is_dying check. --- xen/arch/arm/gic-vgic.c | 27 ++++++++++++++++++++++++--- xen/arch/arm/gic.c | 9 +-------- xen/arch/arm/vgic/vgic.c | 24 ++++++++++++++++++++---- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c index b99e287224..56b6a3d5b0 100644 --- a/xen/arch/arm/gic-vgic.c +++ b/xen/arch/arm/gic-vgic.c @@ -439,6 +439,14 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq, /* We are taking to rank lock to prevent parallel connections. */ vgic_lock_rank(v_target, rank, flags); + /* Return with error if the IRQ is being migrated. */ + if( test_bit(GIC_IRQ_GUEST_MIGRATING, &p->status) ) + { + vgic_unlock_rank(v_target, rank, flags); + return -EBUSY; + } + + spin_lock(&v_target->arch.vgic.lock); if ( connect ) { @@ -456,12 +464,25 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq, } else { - if ( desc && p->desc != desc ) - ret = -EINVAL; + if ( d->is_dying ) + { + if ( desc && p->desc != desc ) + ret = -EINVAL; + else + p->desc = NULL; + } else - p->desc = NULL; + { + if ( (desc && p->desc != desc) || + test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) || + test_bit(GIC_IRQ_GUEST_ACTIVE, &p->status) ) + ret = -EINVAL; + else + p->desc = NULL; + } } + spin_unlock(&v_target->arch.vgic.lock); vgic_unlock_rank(v_target, rank, flags); return ret; diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index b3467a76ae..8633f14bdd 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -159,24 +159,17 @@ int gic_remove_irq_from_guest(struct domain *d, unsigned int virq, ASSERT(test_bit(_IRQ_GUEST, &desc->status)); ASSERT(!is_lpi(virq)); - /* - * Removing an interrupt while the domain is running may have - * undesirable effect on the vGIC emulation. - */ - if ( !d->is_dying ) - return -EBUSY; - desc->handler->shutdown(desc); /* EOI the IRQ if it has not been done by the guest */ if ( test_bit(_IRQ_INPROGRESS, &desc->status) ) gic_hw_ops->deactivate_irq(desc); - clear_bit(_IRQ_INPROGRESS, &desc->status); ret = vgic_connect_hw_irq(d, NULL, virq, desc, false); if ( ret ) return ret; + clear_bit(_IRQ_INPROGRESS, &desc->status); clear_bit(_IRQ_GUEST, &desc->status); desc->handler = &no_irq_type; diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 048e12c562..0c324b58f7 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -890,14 +890,30 @@ int vgic_connect_hw_irq(struct domain *d, struct vcpu *vcpu, } else /* remove a mapped IRQ */ { - if ( desc && irq->hwintid != desc->irq ) + if ( d->is_dying ) { - ret = -EINVAL; + if ( desc && irq->hwintid != desc->irq ) + { + ret = -EINVAL; + } + else + { + irq->hw = false; + irq->hwintid = 0; + } } else { - irq->hw = false; - irq->hwintid = 0; + if ( (desc && irq->hwintid != desc->irq) || + irq->active || irq->pending_latch ) + { + ret = -EINVAL; + } + else + { + irq->hw = false; + irq->hwintid = 0; + } } } From patchwork Thu May 23 07:40:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671342 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 DC0D3C25B75 for ; Thu, 23 May 2024 07:41:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728100.1132919 (Exim 4.92) (envelope-from ) id 1sA34X-0003M5-A0; Thu, 23 May 2024 07:41:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728100.1132919; Thu, 23 May 2024 07:41: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 1sA34X-0003Lu-6R; Thu, 23 May 2024 07:41:09 +0000 Received: by outflank-mailman (input) for mailman id 728100; Thu, 23 May 2024 07:41:08 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34W-0001WY-Bw for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:41:08 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on20600.outbound.protection.outlook.com [2a01:111:f403:2408::600]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d0c5d2ec-18d7-11ef-90a1-e314d9c70b13; Thu, 23 May 2024 09:41:07 +0200 (CEST) Received: from BY5PR20CA0024.namprd20.prod.outlook.com (2603:10b6:a03:1f4::37) by PH7PR12MB6738.namprd12.prod.outlook.com (2603:10b6:510:1a9::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Thu, 23 May 2024 07:41:03 +0000 Received: from CO1PEPF000066EC.namprd05.prod.outlook.com (2603:10b6:a03:1f4:cafe::ef) by BY5PR20CA0024.outlook.office365.com (2603:10b6:a03:1f4::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22 via Frontend Transport; Thu, 23 May 2024 07:41:03 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066EC.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:41:02 +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.35; Thu, 23 May 2024 02:40:59 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:40:58 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d0c5d2ec-18d7-11ef-90a1-e314d9c70b13 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZawFVej4XbPQ44lzG6OFWPH5F7gp/ntM/F0lJ6b4W2SDVG6DjqzJ0SNvVOIxD3r53kSxc5L6fD+Kr52Cnmtm6LaZbg0w8iAfiPChYlbhglrjpL/lPR2l0Fi4yTMANNn48FdBez2h92eTfP2Nq7kr2MUfBA/5RrcNpmUjgQbb4Vx9T3sQOxOglATWbMnQNNAuO+rzsKk4po+8/k7zrBCMpeyNU2qXQ3dbnuFF2gy0Om5o1Mv9Zd3ufqUnGHiZWxd/NCH8E6q+mi/y9t7dzxHyhEerFhI7NhijOyi8EEhqYQFTYuOL8SlU03Hfz25vIBXG62z6TYJkQGwZxfANnE6vwA== 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=2WjCV+UJTAIwa98i99pj6e9RnE3+oYy74bW5zI2VriQ=; b=n0nw5r70dTN9/IUIRZjlqTnDYsguiiKMq2UY84uPM9Krskv+CqFHFH0MWX77PGRKWu70gPA1O2RTg73EJCvn0kfeu0WfRybXdqTk53Xdic15frL7i72kusIMEI4lJSI2Pap4xaEuZgBlR7FG46PP2jj/4AM8Uh2T5OCXYrGgIBHEZjrQylsDS5wLBSX4hzC4/N2LEBJDpglYTRRt8pN3PGTo/1hawzq65eY8FD4Y430XRTYH7+2+v/970VwUzVZ1P2Lorxs/3ijI95QW4TD3q+oVw4FnwoeoYfkgsLV05B15JQCIf+qk+gs31soVDzagNE54iRJ/r7TsZMLEbt71qw== 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 (0) 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=2WjCV+UJTAIwa98i99pj6e9RnE3+oYy74bW5zI2VriQ=; b=05HiC3DdPgRXfDroX4eQlYRO5tbdoPbfu8wuUuR+jEopWi0wsgN2dwBI49/WQp8ffYVDGw/wvlcer1w7ymZNXR/tu6qsUQ4NXfrmVSa+xzYIc+Uf98VdNmdNW2Fds0lMh9ULejxDsVlNd8cHjPdds8syvPQajJlm1d8kyH2/OpQ= 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: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Andrew Cooper , George Dunlap , Jan Beulich , Henry Wang Subject: [PATCH v4 7/9] xen/arm: Support device detachment from domains Date: Thu, 23 May 2024 15:40:38 +0800 Message-ID: <20240523074040.1611264-8-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EC:EE_|PH7PR12MB6738:EE_ X-MS-Office365-Filtering-Correlation-Id: 4004e741-a608-4b1d-3e75-08dc7afbb262 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|36860700004|376005|82310400017; X-Microsoft-Antispam-Message-Info: HEj4UA5zBGDBgQ72s0ZLScb306lbL6WBiFpXCeolHkM2EqPOR/yIraiT8MBxqJVupoEd3MiBwopBNCVv61Kxnm9FkwhMdvnrIO3V4FEDxtp0uSUFUjgiIeG2rQNKK9MWcy3Twjvp0ojYy2XfnZia2Qeqlf0wcWA/vJK2T2Y4H2bGWWdUk6XC18mWzpeBaG5mZh8VG0Wmk0YVB42emsoK/FEW8Fa4dfWFHPBPDg9rvyRY4TtRq2HZpkc3Um44+VDwkKpet5svQLFOJSVZPE8qy3DS5v6Blq96W4+eLpSyhhdtlIKRW0l+jr68AACveMoXFMuTgJbZm3WM8B8vmjPfKv4sIlR9KMEsb0/0Ul7mnkAHL6XVU6ObtXBkzkEuTY0oe6jbdxrgT/xkLrDauvLiThgQTK6DrSYZCX1h1RMExcCl52WXoIjvmr4gVVzAx3mbAHG2VRKjDXktiuGQxEjOC2e3gq8rTpB0fhLQ+vfRFzm8xXIcY78nYzSTwKgfapaqeqcrl51894dIgowz+0Tm9tJl1YDlHHFkd8pBIrvPD/nL1h92a0ZRSJam6lYADZaN1DmgbYM3Ejc71up7BGVylEWJGlRmss5qzNux5Ezo+BMez0jrLiP8IRKyBB0GPB5eCmiT5GjtkxNvxLreDRUoIzOW5AceSnB1fMkgz/QdFR1WYnwqf4BFAzLGe86kl00neq9Fl1TqiH8ybmTcLLXq1euz1E71zoSaqvfwPjztlcZeW0QF+dXLCAw+NMYeYnzbFRi7sJHZrC/8e1CG8gFXf1ZBzDVbrMbQalRZzPUNpiTWJk/GWdN4TExm7dTGWecgLjFy1282bUrPGAURmHhA2Z/sxf0nOWrSV8VHcXOU6TdYf2Drwn8r/Sh9nKuvEfSEOC5H7QMuyqwahKvmk1eojH/J05VCMurl5YjCXu2Yb6PyLGfrieUuWHZaZg/8h349YpAeJQp7LGp1XyF2Oztx4jMGtvZeto3Xu2EokhY46dqw+q3KjC4C9nek97ckDiwZkNuPHfo6qIuzum79astagPxeGW3IN6XmkiKN0kEOrf+4jqhmbzlK2/yRJsU3ffDkSnTkHO5Sp0lvHJcoUD9ROJSOldq2u6l0iGLd5jEu+34WDH7NnKzc5k1TvFl2ncGLEtPgOEBiekDTqqTlrsa8eRfO3c4e9YPD5aZnhlU7oghHaDdMMNM4nMUcAVos/F3M4/yErrqej72ZyTOJNkgs/wq+wtp6pVqrkWSjxX7eC4B4GF7KJh2ks6gr5etccn4liRphAW/wHwtZPLEcpidz3tht6Y7/vUdGWvwftKIGVko78hCn72zq0JEwqE5zMqNofBodj5k0AwcgqJMGzv09w67qtWr42bhrjp/xKvqCkdk39/qRB1TfODGYZv5VH/xi 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)(1800799015)(36860700004)(376005)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:41:02.6368 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4004e741-a608-4b1d-3e75-08dc7afbb262 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: CO1PEPF000066EC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6738 Similarly as the device attachment from DT overlay to domain, this commit implements the device detachment from domain. The DOMCTL XEN_DOMCTL_dt_overlay op is extended to have the operation XEN_DOMCTL_DT_OVERLAY_DETACH. The detachment of the device is implemented by unmapping the IRQ and IOMMU resources. Note that with these changes, the device de-registration from the IOMMU driver should only happen at the time when the DT overlay is removed from the Xen device tree. Signed-off-by: Henry Wang Signed-off-by: Vikram Garhwal --- v4: - Split the original patch, only do device detachment from domain. --- xen/common/dt-overlay.c | 243 ++++++++++++++++++++++++++++-------- xen/include/public/domctl.h | 3 +- 2 files changed, 194 insertions(+), 52 deletions(-) diff --git a/xen/common/dt-overlay.c b/xen/common/dt-overlay.c index 1087f9b502..693b6e4777 100644 --- a/xen/common/dt-overlay.c +++ b/xen/common/dt-overlay.c @@ -392,24 +392,100 @@ find_track_entry_from_tracker(const void *overlay_fdt, return entry; } +static int remove_irq(unsigned long s, unsigned long e, void *data) +{ + struct domain *d = data; + int rc = 0; + + /* + * IRQ should always have access unless there are duplication of + * of irqs in device tree. There are few cases of xen device tree + * where there are duplicate interrupts for the same node. + */ + if (!irq_access_permitted(d, s)) + return 0; + /* + * TODO: We don't handle shared IRQs for now. So, it is assumed that + * the IRQs was not shared with another domain. + */ + rc = irq_deny_access(d, s); + if ( rc ) + { + printk(XENLOG_ERR "unable to revoke access for irq %ld\n", s); + return rc; + } + + rc = release_guest_irq(d, s); + if ( rc ) + { + printk(XENLOG_ERR "unable to release irq %ld\n", s); + return rc; + } + + return rc; +} + +static int remove_all_irqs(struct rangeset *irq_ranges, struct domain *d) +{ + return rangeset_report_ranges(irq_ranges, 0, ~0UL, remove_irq, d); +} + +static int remove_iomem(unsigned long s, unsigned long e, void *data) +{ + struct domain *d = data; + int rc = 0; + p2m_type_t t; + mfn_t mfn; + + mfn = p2m_lookup(d, _gfn(s), &t); + if ( mfn_x(mfn) == 0 || mfn_x(mfn) == ~0UL ) + return -EINVAL; + + rc = iomem_deny_access(d, s, e); + if ( rc ) + { + printk(XENLOG_ERR "Unable to remove %pd access to %#lx - %#lx\n", + d, s, e); + return rc; + } + + rc = unmap_mmio_regions(d, _gfn(s), e - s, _mfn(s)); + if ( rc ) + return rc; + + return rc; +} + +static int remove_all_iomems(struct rangeset *iomem_ranges, struct domain *d) +{ + return rangeset_report_ranges(iomem_ranges, 0, ~0UL, remove_iomem, d); +} + /* Check if node itself can be removed and remove node from IOMMU. */ -static int remove_node_resources(struct dt_device_node *device_node) +static int remove_node_resources(struct dt_device_node *device_node, + struct domain *d) { int rc = 0; unsigned int len; domid_t domid; - domid = dt_device_used_by(device_node); + if ( !d ) + { + domid = dt_device_used_by(device_node); - dt_dprintk("Checking if node %s is used by any domain\n", - device_node->full_name); + 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; + /* + * We also check if device is assigned to DOMID_IO as when a domain + * is destroyed device is assigned to DOMID_IO. + */ + if ( domid != DOMID_IO ) + { + printk(XENLOG_ERR "Device %s is being assigned to %u. Device is assigned to %d\n", + device_node->full_name, DOMID_IO, domid); + return -EINVAL; + } } /* Check if iommu property exists. */ @@ -417,9 +493,12 @@ static int remove_node_resources(struct dt_device_node *device_node) { if ( dt_device_is_protected(device_node) ) { - rc = iommu_remove_dt_device(device_node); - if ( rc < 0 ) - return rc; + if ( !list_empty(&device_node->domain_list) ) + { + rc = iommu_deassign_dt_device(d, device_node); + if ( rc < 0 ) + return rc; + } } } @@ -428,7 +507,8 @@ static int remove_node_resources(struct dt_device_node *device_node) /* Remove all descendants from IOMMU. */ static int -remove_descendant_nodes_resources(const struct dt_device_node *device_node) +remove_descendant_nodes_resources(const struct dt_device_node *device_node, + struct domain *d) { int rc = 0; struct dt_device_node *child_node; @@ -438,12 +518,12 @@ remove_descendant_nodes_resources(const struct dt_device_node *device_node) { if ( child_node->child ) { - rc = remove_descendant_nodes_resources(child_node); + rc = remove_descendant_nodes_resources(child_node, d); if ( rc ) return rc; } - rc = remove_node_resources(child_node); + rc = remove_node_resources(child_node, d); if ( rc ) return rc; } @@ -456,8 +536,7 @@ 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; + unsigned int j, len; for ( j = 0; j < tracker->num_nodes; j++ ) { @@ -467,18 +546,15 @@ static int remove_nodes(const struct overlay_track *tracker) write_lock(&dt_host_lock); - rc = remove_descendant_nodes_resources(overlay_node); - if ( rc ) + /* Check if iommu property exists. */ + if ( dt_get_property(overlay_node, "iommus", &len) ) { - write_unlock(&dt_host_lock); - return rc; - } - - rc = remove_node_resources(overlay_node); - if ( rc ) - { - write_unlock(&dt_host_lock); - return rc; + if ( dt_device_is_protected(overlay_node) ) + { + rc = iommu_remove_dt_device(overlay_node); + if ( rc < 0 ) + return rc; + } } dt_dprintk("Removing node: %s\n", overlay_node->full_name); @@ -493,22 +569,6 @@ static int remove_nodes(const struct overlay_track *tracker) 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; } @@ -534,7 +594,6 @@ static long handle_remove_overlay_nodes(const void *overlay_fdt, { rc = -EINVAL; goto out; - } rc = remove_nodes(entry); @@ -552,9 +611,6 @@ static long handle_remove_overlay_nodes(const void *overlay_fdt, xfree(entry->nodes_address); - rangeset_destroy(entry->irq_ranges); - rangeset_destroy(entry->iomem_ranges); - xfree(entry); out: @@ -840,6 +896,88 @@ static long handle_add_overlay_nodes(void *overlay_fdt, return rc; } +static long handle_detach_overlay_nodes(struct domain *d, + const void *overlay_fdt, + uint32_t overlay_fdt_size) +{ + int rc; + unsigned int j; + struct overlay_track *entry; + + rc = check_overlay_fdt(overlay_fdt, overlay_fdt_size); + if ( rc ) + return rc; + + spin_lock(&overlay_lock); + + entry = find_track_entry_from_tracker(overlay_fdt, overlay_fdt_size); + if ( entry == NULL ) + { + rc = -EINVAL; + goto out; + } + + for ( j = 0; j < entry->num_nodes; j++ ) + { + struct dt_device_node *overlay_node; + + overlay_node = (struct dt_device_node *)entry->nodes_address[j]; + if ( overlay_node == NULL ) + { + rc = -EINVAL; + goto out; + } + + write_lock(&dt_host_lock); + rc = remove_descendant_nodes_resources(overlay_node, d); + if ( rc ) + { + write_unlock(&dt_host_lock); + goto out; + } + + rc = remove_node_resources(overlay_node, d); + if ( rc ) + { + write_unlock(&dt_host_lock); + goto out; + } + write_unlock(&dt_host_lock); + + rc = remove_all_irqs(entry->irq_ranges, d); + if ( rc ) + goto out; + + rc = remove_all_iomems(entry->iomem_ranges, d); + if ( rc ) + goto out; + } + + /* Remove IRQ access. */ + if ( entry->irq_ranges ) + { + rc = rangeset_consume_ranges(entry->irq_ranges, irq_remove_cb, d); + if ( rc ) + goto out; + } + + /* Remove mmio access. */ + if ( entry->iomem_ranges ) + { + rc = rangeset_consume_ranges(entry->iomem_ranges, iomem_remove_cb, d); + if ( rc ) + goto out; + } + + rangeset_destroy(entry->irq_ranges); + rangeset_destroy(entry->iomem_ranges); + + out: + spin_unlock(&overlay_lock); + + return rc; +} + static long handle_attach_overlay_nodes(struct domain *d, const void *overlay_fdt, uint32_t overlay_fdt_size) @@ -956,7 +1094,8 @@ long dt_overlay_domctl(struct domain *d, struct xen_domctl_dt_overlay *op) long ret; void *overlay_fdt; - if ( op->overlay_op != XEN_DOMCTL_DT_OVERLAY_ATTACH ) + if ( op->overlay_op != XEN_DOMCTL_DT_OVERLAY_ATTACH && + op->overlay_op != XEN_DOMCTL_DT_OVERLAY_DETACH ) return -EOPNOTSUPP; if ( op->overlay_fdt_size == 0 || op->overlay_fdt_size > KB(500) ) @@ -979,7 +1118,9 @@ long dt_overlay_domctl(struct domain *d, struct xen_domctl_dt_overlay *op) return -EFAULT; } - if ( op->overlay_op == XEN_DOMCTL_DT_OVERLAY_ATTACH ) + if ( op->overlay_op == XEN_DOMCTL_DT_OVERLAY_DETACH ) + ret = handle_detach_overlay_nodes(d, overlay_fdt, op->overlay_fdt_size); + else ret = handle_attach_overlay_nodes(d, overlay_fdt, op->overlay_fdt_size); xfree(overlay_fdt); diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index ac3c2a7c4c..e91f743fa4 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1195,7 +1195,8 @@ struct xen_domctl_dt_overlay { XEN_GUEST_HANDLE_64(const_void) overlay_fdt; /* IN: overlay fdt. */ uint32_t overlay_fdt_size; /* IN: Overlay dtb size. */ #define XEN_DOMCTL_DT_OVERLAY_ATTACH 1 - uint8_t overlay_op; /* IN: Attach. */ +#define XEN_DOMCTL_DT_OVERLAY_DETACH 2 + uint8_t overlay_op; /* IN: Attach/Detach. */ uint8_t pad[3]; /* IN: Must be zero. */ }; #endif From patchwork Thu May 23 07:40:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671345 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 57208C25B75 for ; Thu, 23 May 2024 07:41:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728109.1132950 (Exim 4.92) (envelope-from ) id 1sA34c-0004YO-OQ; Thu, 23 May 2024 07:41:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728109.1132950; Thu, 23 May 2024 07:41: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 1sA34c-0004Y0-JH; Thu, 23 May 2024 07:41:14 +0000 Received: by outflank-mailman (input) for mailman id 728109; Thu, 23 May 2024 07:41: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 1sA34b-0003CF-Hg for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:41:13 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20600.outbound.protection.outlook.com [2a01:111:f403:2009::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d34da501-18d7-11ef-b4bb-af5377834399; Thu, 23 May 2024 09:41:11 +0200 (CEST) Received: from BY5PR20CA0013.namprd20.prod.outlook.com (2603:10b6:a03:1f4::26) by BL1PR12MB5804.namprd12.prod.outlook.com (2603:10b6:208:394::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.36; Thu, 23 May 2024 07:41:08 +0000 Received: from CO1PEPF000066EC.namprd05.prod.outlook.com (2603:10b6:a03:1f4:cafe::2e) by BY5PR20CA0013.outlook.office365.com (2603:10b6:a03:1f4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20 via Frontend Transport; Thu, 23 May 2024 07:41:07 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066EC.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:41:07 +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.35; Thu, 23 May 2024 02:41:01 -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.35; Thu, 23 May 2024 02:41:01 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:41:00 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d34da501-18d7-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X8xx40pf5Keh1b42FvaLrBPfygRwS+VlBg+4pTsdKe3/5zk4nHES1+k9oi3u2mVTJPO2rld5GoqAAHfBPBCZqCihVjTf8Ec3MQZuWIxrxlUfD/IrXGfrp2f3as9Q6SBfOB58run/nINP7IvutIjKp4NwkAdoSHWQj+q4pWFqBBU5gigCfobNgeWjdJ6oFvsNHi1jImBZAwgPrx6L+ELYrHnrDuOgH4ZxJPDjFH5dkrSpZnAYXcb5C4s6DNjutiejZSAcAfKr5oLmLQbz6gbYPblppVavrKc1ZakViO+w0BcJX6icO1nYeNZBIAPo4fuovImMA8RqWBkr8bRu3SSfNg== 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=da2DEjMTTPOqHs5JEHft5f2zNU/TKUOCNbSUhm9LjB0=; b=mJe/hsJJNhF9SfQulWbnW8YkZ51UUl+LS+LW9zlfazjX7EEK13nvmIsnqlw3dLjR+xF1bCUe9tO0BzNDt8svJckLgY9qdecfsN7B0Zot6c3I5HchUj5XsnaDybLHtb5hxBYLubL4r6wDCnMv4LXXZPYGEFZBIMtNVoi+R9szpFc1PbV1PulgxkT6u7hPEguLMKnkWpcemo8EU7pA6qE47jdIZDcfU7oXDPf3oQqXYVsIHmPimbtL/dkGsPnD7K/4qSBkBbCz/CJ5TLty9fTlctAGArW2gE0cl0MVXDeMjuR+LoXt62aKLrkiMozVxkEt/O+TI9ObnJN9/3jbCGOEJQ== 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 (0) 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=da2DEjMTTPOqHs5JEHft5f2zNU/TKUOCNbSUhm9LjB0=; b=Xdq9w1W82Bn0vuY6eT/+m7Ixhu5PytVvwZhlxWBg2SLQHyxj/d3M+f+I6XTMUXj7U6TXbb/iQy0tWCcx0EkK5NKziYi26jqNG/hWnJPqxc52tbxyMvEZHgL+iLb97Ne1e+v4NZvE8GNSsfBw82n61ZI8sVOl33bdhZAemF44NjM= 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: Henry Wang To: CC: Anthony PERARD , Juergen Gross , Henry Wang , Jason Andryuk Subject: [PATCH v4 8/9] tools: Introduce the "xl dt-overlay {attach,detach}" commands Date: Thu, 23 May 2024 15:40:39 +0800 Message-ID: <20240523074040.1611264-9-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EC:EE_|BL1PR12MB5804:EE_ X-MS-Office365-Filtering-Correlation-Id: 543ba5a1-7b6f-43ed-6a07-08dc7afbb558 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|36860700004|376005|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: thVannc2U8Dx/QzE1TkJBopXvcqv5OJO1x6Qv+15CEuSHxn6lj+eFTZmWNhzkI3HTlMG/cd2WkdjXcht9nqn2OuqxzADHOpbEP2ajzRD9F2iyeVAvir42gb3AIuo7mxkIBIRUOy4sXFqiecwP6OKOmGA18bbPgIJPseM2h/+r5KCNTpTCrwFR0UYPrGVHd5EvPe21LPzv7gegeIgqDDf1PUDzGk+sqzEgb91KVzifAqG962mH/R1fZnCaY1IC1fhxyU2wilKCjc7lGG3IPKgv7tNXgUb9iMcRkHDFCKYSD9MRasR7Z7A8A5AVvIIB64YeaTwxX/RXgImQ//RiV4yzA7gPOFBywzl3y7CMRcwQXWMEnWhI/LY4PacYosUfohypuvWYmOG1dW8OBPuBOsJz1i1KANjeMcfgp01wdt0tCSQFfBpARNRbHghaN8DCpum8/bA3H1QsWlK3KnVz9GZDZJ8Bx8Vh/6QOGdtjJLXvyRwTCT6QVFYD+rIHn2PjPAkqewG1i4E19ybdX/jkUGTe2PlVXjW7v73FajVGMOlgUf0d//LUoY/XCuYuGBezRKIJfMjq1gBSUUA4OS4M3av8cyYzoqH8QU8CPNj7WHmitm+oibjs98hor4MrtVMtJEoVGL2i65eniSZDFlfbKemdGuVce9BT+O9Ff8O5rovFCictvdzHNPToQlQ0snKJet8SHZNNIdaDNmn+0dRYcytvDIp0pBlxabx003sb/5y7LzvTkutaH7BYcOMDRy+7ZoJKYPb8mOoc+hKaEJC9gdUQr0X+fufjswffBO084hTxI8x1q/XykxT4ole9P5CxoS1sQCnQ8+RMeFq4/UxErk/maNgJhUGxmP7Tw/RQWabOh7mRr3U7Y7FCvEADDv2ntUGPrKGiFanZejcICUQPO7ma1KMy16F+YY92cZpx4ixLBUsTfveebLDgL9OmGxdqdP2tYaQn3AuICSuZKyWTli1b3uQwvy+9Bpu5XM9CQODlOTz4XA/cEdz5uEO/c8N+prTFj7MieelZIXNx36DU7l6F440XeVVOjrn4PhnvwNxj9iWsiWCfvI+3Z5YoHK/y+WK3x3AdArXQEydsUurLql9HWJq2gmCAPM9mlvMhV5ZMADX1M/aZaAy2wbJnrg28UHI/WdVEL0Ib48QqrSSLKNClpCCuoIYXzBD9/dqmYm7y8aBXXJTxuaYY+IH9m7ipSjCVpjji/G30Del/ThGG8HUOxj82i+5JE8TMivTO1vCR9mrk5sOjfCJWqftfp4bWoQQpowEcYmciPhjXzvc8zi/u8mvfyiDB6xHcY0sncY7LQU8nFNJ1g0a2NWaioe1Ej952p+sb/XW3c0syXKtMC9GOV9EYHCPXrg2wWKE8k1J6rmIX3z/i3cmPMAF1GeSw/pn 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)(36860700004)(376005)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:41:07.6055 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 543ba5a1-7b6f-43ed-6a07-08dc7afbb558 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: CO1PEPF000066EC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5804 With the XEN_DOMCTL_dt_overlay DOMCTL added, users should be able to attach/detach devices from the provided DT overlay to domains. Support this by introducing a new set of "xl dt-overlay" commands and related documentation, i.e. "xl dt-overlay {attach,detach}". Slightly rework the command option parsing logic. Signed-off-by: Henry Wang Reviewed-by: Jason Andryuk Reviewed-by: Stefano Stabellini --- v4: - Add Jason's Reviewed-by tag. v3: - Introduce new API libxl_dt_overlay_domain() and co., instead of reusing existing API libxl_dt_overlay(). - Add in-code comments for the LIBXL_DT_OVERLAY_* macros. - Use find_domain() to avoid getting domain_id from strtol(). v2: - New patch. --- tools/include/libxl.h | 10 +++++++ tools/include/xenctrl.h | 3 +++ tools/libs/ctrl/xc_dt_overlay.c | 31 +++++++++++++++++++++ tools/libs/light/libxl_dt_overlay.c | 28 +++++++++++++++++++ tools/xl/xl_cmdtable.c | 4 +-- tools/xl/xl_vmcontrol.c | 42 ++++++++++++++++++++--------- 6 files changed, 104 insertions(+), 14 deletions(-) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index 62cb07dea6..6cc6d6bf6a 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -2549,8 +2549,18 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, void libxl_device_pci_list_free(libxl_device_pci* list, int num); #if defined(__arm__) || defined(__aarch64__) +/* Values should keep consistent with the op from XEN_SYSCTL_dt_overlay */ +#define LIBXL_DT_OVERLAY_ADD 1 +#define LIBXL_DT_OVERLAY_REMOVE 2 int libxl_dt_overlay(libxl_ctx *ctx, void *overlay, uint32_t overlay_size, uint8_t overlay_op); + +/* Values should keep consistent with the op from XEN_DOMCTL_dt_overlay */ +#define LIBXL_DT_OVERLAY_DOMAIN_ATTACH 1 +#define LIBXL_DT_OVERLAY_DOMAIN_DETACH 2 +int libxl_dt_overlay_domain(libxl_ctx *ctx, uint32_t domain_id, + void *overlay_dt, uint32_t overlay_dt_size, + uint8_t overlay_op); #endif /* diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 4996855944..9ceca0cffc 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -2657,6 +2657,9 @@ int xc_domain_cacheflush(xc_interface *xch, uint32_t domid, #if defined(__arm__) || defined(__aarch64__) int xc_dt_overlay(xc_interface *xch, void *overlay_fdt, uint32_t overlay_fdt_size, uint8_t overlay_op); +int xc_dt_overlay_domain(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op, + uint32_t domain_id); #endif /* Compat shims */ diff --git a/tools/libs/ctrl/xc_dt_overlay.c b/tools/libs/ctrl/xc_dt_overlay.c index c2224c4d15..ea1da522d1 100644 --- a/tools/libs/ctrl/xc_dt_overlay.c +++ b/tools/libs/ctrl/xc_dt_overlay.c @@ -48,3 +48,34 @@ err: return err; } + +int xc_dt_overlay_domain(xc_interface *xch, void *overlay_fdt, + uint32_t overlay_fdt_size, uint8_t overlay_op, + uint32_t domain_id) +{ + int err; + struct xen_domctl domctl = { + .cmd = XEN_DOMCTL_dt_overlay, + .domain = domain_id, + .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(domctl.u.dt_overlay.overlay_fdt, overlay_fdt); + + if ( (err = do_domctl(xch, &domctl)) != 0 ) + PERROR("%s failed", __func__); + +err: + xc_hypercall_bounce_post(xch, overlay_fdt); + + return err; +} diff --git a/tools/libs/light/libxl_dt_overlay.c b/tools/libs/light/libxl_dt_overlay.c index a6c709a6dc..00503b76bd 100644 --- a/tools/libs/light/libxl_dt_overlay.c +++ b/tools/libs/light/libxl_dt_overlay.c @@ -69,3 +69,31 @@ out: return rc; } +int libxl_dt_overlay_domain(libxl_ctx *ctx, uint32_t domain_id, + 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_domain(ctx->xch, overlay_dt, overlay_dt_size, overlay_op, + domain_id); + if (r) { + LOG(ERROR, "%s: Attaching/Detaching overlay dtb failed.", __func__); + rc = ERROR_FAIL; + } + +out: + GC_FREE; + return rc; +} diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c index 1f3c6b5897..37770b20e3 100644 --- a/tools/xl/xl_cmdtable.c +++ b/tools/xl/xl_cmdtable.c @@ -634,8 +634,8 @@ const struct cmd_spec cmd_table[] = { #ifdef LIBXL_HAVE_DT_OVERLAY { "dt-overlay", &main_dt_overlay, 0, 1, - "Add/Remove a device tree overlay", - "add/remove <.dtbo>", + "Add/Remove a device tree overlay to Xen device tree, attach/detach the device to a domain", + " <.dtbo> OR <.dtbo> ", "-h print this help\n" }, #endif diff --git a/tools/xl/xl_vmcontrol.c b/tools/xl/xl_vmcontrol.c index 02575d5d36..ccfeec39f1 100644 --- a/tools/xl/xl_vmcontrol.c +++ b/tools/xl/xl_vmcontrol.c @@ -1268,32 +1268,46 @@ int main_create(int argc, char **argv) #ifdef LIBXL_HAVE_DT_OVERLAY 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; + uint32_t domain_id = 0; + bool domain_op = false; 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 { + if (strcmp(argv[optind], "add") == 0) + op = LIBXL_DT_OVERLAY_ADD; + else if (strcmp(argv[optind], "remove") == 0) + op = LIBXL_DT_OVERLAY_REMOVE; + else if (strcmp(argv[optind], "attach") == 0) { + op = LIBXL_DT_OVERLAY_DOMAIN_ATTACH; + domain_op = true; + } else if (strcmp(argv[optind], "detach") == 0) { + op = LIBXL_DT_OVERLAY_DOMAIN_DETACH; + domain_op = true; + } else { fprintf(stderr, "Invalid dt overlay operation\n"); return EXIT_FAILURE; } + overlay_config_file = argv[optind+1]; + + if (domain_op) { + if (argc <= optind + 2) { + fprintf(stderr, "Missing domain ID\n"); + help("dt-overlay"); + return EXIT_FAILURE; + } else { + domain_id = find_domain(argv[optind+2]); + } + } + if (overlay_config_file) { rc = libxl_read_file_contents(ctx, overlay_config_file, &overlay_dtb, &overlay_dtb_size); @@ -1309,7 +1323,11 @@ int main_dt_overlay(int argc, char **argv) return EXIT_FAILURE; } - rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + if (!domain_op) + rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op); + else + rc = libxl_dt_overlay_domain(ctx, domain_id, overlay_dtb, + overlay_dtb_size, op); free(overlay_dtb); From patchwork Thu May 23 07:40:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henry Wang X-Patchwork-Id: 13671343 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 8944EC25B7A for ; Thu, 23 May 2024 07:41:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.728103.1132935 (Exim 4.92) (envelope-from ) id 1sA34Z-0003tQ-Bb; Thu, 23 May 2024 07:41:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 728103.1132935; Thu, 23 May 2024 07:41:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sA34Z-0003qF-6V; Thu, 23 May 2024 07:41:11 +0000 Received: by outflank-mailman (input) for mailman id 728103; Thu, 23 May 2024 07:41: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 1sA34Y-0003CF-A9 for xen-devel@lists.xenproject.org; Thu, 23 May 2024 07:41:10 +0000 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on20600.outbound.protection.outlook.com [2a01:111:f403:2409::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d0c96977-18d7-11ef-b4bb-af5377834399; Thu, 23 May 2024 09:41:08 +0200 (CEST) Received: from CH3P220CA0028.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1e8::6) by SN7PR12MB6839.namprd12.prod.outlook.com (2603:10b6:806:265::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.20; Thu, 23 May 2024 07:41:05 +0000 Received: from CH1PEPF0000AD78.namprd04.prod.outlook.com (2603:10b6:610:1e8:cafe::18) by CH3P220CA0028.outlook.office365.com (2603:10b6:610:1e8::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34 via Frontend Transport; Thu, 23 May 2024 07:41:05 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by CH1PEPF0000AD78.mail.protection.outlook.com (10.167.244.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7611.14 via Frontend Transport; Thu, 23 May 2024 07:41:04 +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.35; Thu, 23 May 2024 02:41:04 -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.35; Thu, 23 May 2024 02:41:03 -0500 Received: from henry-MS-7D54.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 23 May 2024 02:41:02 -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: d0c96977-18d7-11ef-b4bb-af5377834399 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UmbpJ0HsSwwe+NJUpclGR6c3RxCh0P/ps3q7wVmhSEmnerM6SjhVj4T8DmBqzUIOxdZCaFGy/JxMm5TMJKuD8mfFc8vuFqdG1gBPTvsRhuXntrSxXCQDmoZt93I9QZP3U9eDC+5IRtYS54gjXlucnPt7US4lj8wAp2EkvZZqwHcxxN529JgwfRGDUW+jgt7KhmQKO2UwcSMPDdDG0wFRO7eyK//VSWBBEAW4Lar472c3dCDy99V4Z8brmIjKtrteYzTke1PYNrpRwSu8Hpkk6NLgatfk+7GisFvpbh0PX1OGKCQowsyUzHVgEGvPd3XW0hyThy3ncy1sTCqzMxGXDA== 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=j/FY1olHM2o9Q7bHo9+Dh+AEIc21S3KHBajG96rQ8uk=; b=GPy/cb2Ftw3Aaur26qyqNTFgeN/2u3/9MbDFiK8zqiTGDu8z/U3UXiy+xE156kpxoww6NtAXwGjSYzHpaGnVFih5/AM3N5qAmQxri2sp/sMawJ70kQlZZOITfeJjcsgfL9x+17ZmbCqDUe+bRNNfG+Bxlg0f5SMM5ycOrF2dXi5Z+lcYgqKYdgoaIX1nqNLhep5icI569r9zgJtfy8QIiN97v9p9ny6swpaNc5plh/Vyt88HZTzjYLR8pTTYfRmK6bSFcE/mNVw38ZZsBN2pO+MAC1Rlc8tluB1uHB3U9ifaSRas4mr1oVNtwXgeBI0sioKpR8uoXcl8VJyhaBct0Q== 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 (0) 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=j/FY1olHM2o9Q7bHo9+Dh+AEIc21S3KHBajG96rQ8uk=; b=x0HF11Ut5J5qvqv8o8lEU9slHgbH7ylvjLio4m13+rUqwcw5DQOaMpbwJuuD2ekcKieCMX1FFGUIGm3rGm2GehLf1h+a8gbdtTbQPA07GGgH+NeozFcnEizPLZbROMy1obq8hJaxfGk39w5UH0RZGM9MiMBgCfSOaeuPceWy6RQ= 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: Henry Wang To: CC: Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Henry Wang Subject: [PATCH v4 9/9] docs: Add device tree overlay documentation Date: Thu, 23 May 2024 15:40:40 +0800 Message-ID: <20240523074040.1611264-10-xin.wang2@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240523074040.1611264-1-xin.wang2@amd.com> References: <20240523074040.1611264-1-xin.wang2@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: xin.wang2@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD78:EE_|SN7PR12MB6839:EE_ X-MS-Office365-Filtering-Correlation-Id: c8cfb63d-fa69-4f2c-610d-08dc7afbb381 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|1800799015|376005|36860700004; X-Microsoft-Antispam-Message-Info: x8MX7l7cJJXwKSNdmYB957qHQ8qn5KZnsPnXe83e9gpHl7382t3HE5Mc6QG/gjk0ygz8Htq/J6xGJ6xR25aawR97fF04ipzWqCGogE9XKPLtcW9R65DOgcNSNg6kZiLd0NBfWPE1nOgNhYv4Acn+LQ30X/BZDdpDxR1N43GW2UJ/V4VM2WBr7pexlZu1VnJ7Nwt8RRF4ebpSaiyBQ/sBJSaMXP98iChBsTADivoRHBqewBd0f8IGq3JStb/bmhjKvvW1Byh1j1paIm/gNSQPXkrLYd8VuhoFjFzQ8U3vUBuXwotU1G4DCHYK8i9VOcAGQbKPibC5keQHs4e/vI1Jk2t7NSHw22bIqf3yBrnsbrdnnlbZONunHGV2WXw1FJ2gdymVnGNhg0i2S2S8MlgF3ybw0imC70Jp4AU9fZ4PMvgGFYpHSg8HlgdOrN00L1LFOIRPm81XpzhOvI5hB9HJkomb2G+KrpSOvaqQ4nHMBwsHhVSNxS+XJqwjOVFfWvbgiGGmXI0DlMUoyntQ084HHmOgyzPjXeGHRYKakXMO1it4xLJQ/JAAQd8CgkH4/UDmVXKJlWoR+vNE3ZoCkDIXGQcUu/XGefwmO9r7JWtkGuoVF1J+lvvi7/8JlwuHW7YCmigvhzUSIvBr/hauNDe4fl8IA8uGlYCOI4q23OuyXOmmbG9Jfp8eUNKqk6+0w5XnONGKIIjZcKU5CZIJsobwK6OHVmq0K5GWPVnSqvpC5MD+CSHwDVsTH25Ygy73NTTELS1By8xmkdlyPqkopfgGLT4QXrPqkfEwySxJLEaouqCnQHN4rdrxfgwbmK7IcTm01xRtveWNJlT2+e7MvtyU/IA34TM/OjLoLjD3dgnLmmgq77jlEOd8oaLBQ+DI7CjIMHIjB7lq+sezpMfkttFNnJ2fF3zrbaR1Ny8JVV41ybcBYEy0nHXcgE1hhDSyHrIcmclND3WqtrSbLE/teyjU2GvJ6h8rBgvQDki9pYQ9sIq/0x+0lTmBp28M3UVTXP5QIfTvtnTC+VKGRpz0t582Z8+JZPmkvjoYbUvC3x9VRHlATxYhC6sCXZFAJUWLdg6/sE/gqrku53hmK+WQrZTh85M1B5SRbjHdG02Kb7OM4Z0XRkgkxHnEoEkyajwl3I3dQFyT681KgFK0zR1y1VwVKjmvQeArUqE2SAH56ibvfT/kO6trqSObuDRJwNQutbmhGWTEMBEbLt9EChCZo+nxBPISv//bX4VXANDhF1j3CVvgF2Wi8jvPQQVXI68iLl395GobR9qF4F9n7E1FHDqw+mZ/8llJtmVwz/f0XDnnqUNwoTfnCTotvjD0bxCuUg5i 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)(82310400017)(1800799015)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 07:41:04.5967 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8cfb63d-fa69-4f2c-610d-08dc7afbb381 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: CH1PEPF0000AD78.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB6839 From: Vikram Garhwal Signed-off-by: Vikram Garhwal Signed-off-by: Stefano Stabellini Signed-off-by: Henry Wang --- v4: - No change. v3: - No change. v2: - Update the content based on the changes in this version. --- docs/misc/arm/overlay.txt | 99 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 docs/misc/arm/overlay.txt diff --git a/docs/misc/arm/overlay.txt b/docs/misc/arm/overlay.txt new file mode 100644 index 0000000000..811a6de369 --- /dev/null +++ b/docs/misc/arm/overlay.txt @@ -0,0 +1,99 @@ +# Device Tree Overlays support in Xen + +Xen now supports dynamic device assignment to running domains, +i.e. adding/removing nodes (using .dtbo) to/from Xen device tree, and +attaching/detaching them to/from a running domain with given $domid. + +Dynamic node assignment works in two steps: + +## Add/Remove device tree overlay to/from Xen device tree + +1. Xen tools check the dtbo given and parse all other user provided arguments +2. Xen tools pass the dtbo to Xen hypervisor via hypercall. +3. Xen hypervisor applies/removes the dtbo to/from Xen device tree. + +## Attach/Detach device from the DT overlay to/from domain + +1. Xen tools check the dtbo given and parse all other user provided arguments +2. Xen tools pass the dtbo to Xen hypervisor via hypercall. +3. Xen hypervisor attach/detach the device to/from the user-provided $domid by + mapping/unmapping node resources in the DT overlay. + +# Examples + +Here are a few examples on how to use it. + +## Dom0 device add + +For assigning a device tree overlay to Dom0, user should firstly properly +prepare the DT overlay. More information about device tree overlays can be +found in [1]. Then, in Dom0, enter the following: + + (dom0) xl dt-overlay add overlay.dtbo + +This will allocate the devices mentioned in overlay.dtbo to Xen device tree. + +To assign the newly added device from the dtbo to Dom0: + + (dom0) xl dt-overlay attach overlay.dtbo 0 + +Next, if the user wants to add the same device tree overlay to dom0 +Linux, execute the following: + + (dom0) mkdir -p /sys/kernel/config/device-tree/overlays/new_overlay + (dom0) cat overlay.dtbo > /sys/kernel/config/device-tree/overlays/new_overlay/dtbo + +Finally if needed, the relevant Linux kernel drive can be loaded using: + + (dom0) modprobe module_name.ko + +## Dom0 device remove + +For removing the device from Dom0, first detach the device from Dom0: + + (dom0) xl dt-overlay detach overlay.dtbo 0 + +NOTE: The user is expected to unload any Linux kernel modules which +might be accessing the devices in overlay.dtbo before detach the device. +Detaching devices without unloading the modules might result in a crash. + +Then remove the overlay from Xen device tree: + + (dom0) xl dt-overlay remove overlay.dtbo + +## DomU device add/remove + +All the nodes in dtbo will be assigned to a domain; the user will need +to prepare the dtb for the domU. For example, the `interrupt-parent` property +of the DomU overlay should be changed to the Xen hardcoded value `0xfde8`. +Below assumes the properly written DomU dtbo is `overlay_domu.dtbo`. + +User will need to create the DomU with below properties properly configured +in the xl config file: +- `iomem` +- `passthrough` (if IOMMU is needed) + +User will also need to modprobe the relevant drivers. + +Example for domU device add: + + (dom0) xl dt-overlay add overlay.dtbo # If not executed before + (dom0) xl dt-overlay attach overlay.dtbo $domid + (dom0) xl console $domid # To access $domid console + +Next, if the user needs to modify/prepare the overlay.dtbo suitable for +the domU: + + (domU) mkdir -p /sys/kernel/config/device-tree/overlays/new_overlay + (domU) cat overlay_domu.dtbo > /sys/kernel/config/device-tree/overlays/new_overlay/dtbo + +Finally, if needed, the relevant Linux kernel drive can be probed: + + (domU) modprobe module_name.ko + +Example for domU overlay remove: + + (dom0) xl dt-overlay detach overlay.dtbo $domid + (dom0) xl dt-overlay remove overlay.dtbo + +[1] https://www.kernel.org/doc/Documentation/devicetree/overlay-notes.txt