From patchwork Thu Mar 7 12:39:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13585523 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 571E1C48BF6 for ; Thu, 7 Mar 2024 12:40:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.689875.1075282 (Exim 4.92) (envelope-from ) id 1riD35-0006Ev-J0; Thu, 07 Mar 2024 12:40:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 689875.1075282; Thu, 07 Mar 2024 12:40:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riD35-0006Eo-GG; Thu, 07 Mar 2024 12:40:35 +0000 Received: by outflank-mailman (input) for mailman id 689875; Thu, 07 Mar 2024 12:40:34 +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 1riD34-0004ja-GF for xen-devel@lists.xenproject.org; Thu, 07 Mar 2024 12:40:34 +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 e37bdc99-dc7f-11ee-afda-a90da7624cb6; Thu, 07 Mar 2024 13:40:33 +0100 (CET) Received: from SJ0PR05CA0106.namprd05.prod.outlook.com (2603:10b6:a03:334::21) by CH3PR12MB8971.namprd12.prod.outlook.com (2603:10b6:610:177::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Thu, 7 Mar 2024 12:40:31 +0000 Received: from CO1PEPF000042AA.namprd03.prod.outlook.com (2603:10b6:a03:334:cafe::82) by SJ0PR05CA0106.outlook.office365.com (2603:10b6:a03:334::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.6 via Frontend Transport; Thu, 7 Mar 2024 12:40:30 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000042AA.mail.protection.outlook.com (10.167.243.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Thu, 7 Mar 2024 12:40:29 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 06:40:29 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 04:40:28 -0800 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 06:40:27 -0600 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: e37bdc99-dc7f-11ee-afda-a90da7624cb6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bLdhMBlV9KCAe5MtTnpRljroS+gFNScAwnuuIijc2rQuS1Tq/wB8ikNVkfTBVV+OOmJVOHBH8NpzLd+U+8VGWlnJOoRmYNTOF5yFZm+80nNXDtWxWdY7fqrx/utuNH0bKxpaFIzH0F/j7gBl2N8hZIkAEnMaITgzHHTV8bsWOTqykPcG137WrNWXS8GM6DcRqF6jlD8Ppv/DpLSCkyGR8QOCQ1Odx2hz8FTDcEYplXqkYS9MctzSjVlha87LqRQM3sNwl+xr1DaAPNrwShaoI8T7ONFFOXX2k4zblhGEnDXE2Lmnjg+hseMyPaPKmaMJ6w8nw1sajP/fgjbCdyuA2A== 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=PMIOVJVSy6u/LzekxPUJWc7zfls/wR2k+xzI6m7KP7g=; b=MYK7FyQSwFSS0MHIBiekvZBs7MiTLmk8EPZ4L14Be2Zy4DIVYa4y/ntQFEaPCreN122Et8XQJi5nqOyBsQv3dBXYU9hg0M1RsIpLLjP5wuOeJGs+MYUFaxsdQTCYmnIfixJdzxbMv1kcYCkG+HQN8uV7EWQh38QZ1H5Si/68fVvmnsqrGbksiDOFKyEgxfuU3wDd8xQR7CmYThU78GNSl3NqwPstUZOd9bm+nNFeRlaX+B9xUov7SsLrcPGlxkO2Q8q+31oC3NnT33clul5znU6lAUijBi05hCQB503y6XX9HxWtTQ1KoUJB5wkKeLG125+2AI+tCCQ5rY5yEcXxmg== 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=PMIOVJVSy6u/LzekxPUJWc7zfls/wR2k+xzI6m7KP7g=; b=0vNuLyR4D/PTyHe09kSmUxygCkxesztwC5HVozByBY6AKtnhX/myL7160vB3u7o1wsx987HuZLIACOVHpfqEp8++F0xNpekTXoOETbDttgVNatxNU4pnnfI+fgJysoG0KCgAbanLJEd7TNLPDkkBA8iUIH7fqdCIqkBRPPvkfKY= 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: Ayan Kumar Halder To: CC: , , , , , , Ayan Kumar Halder Subject: [XEN v6 1/3] xen/arm: Introduce CONFIG_PARTIAL_EMULATION and "partial-emulation" cmd option Date: Thu, 7 Mar 2024 12:39:41 +0000 Message-ID: <20240307123943.1991755-2-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240307123943.1991755-1-ayan.kumar.halder@amd.com> References: <20240307123943.1991755-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042AA:EE_|CH3PR12MB8971:EE_ X-MS-Office365-Filtering-Correlation-Id: ff8503de-184a-4303-da77-08dc3ea3c5da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 59WKqOGY8lE0yAdkhnk9z7uaufBuS7swX3HL6qbM0elxFO2PGyZf7kpiol6jFjTBHEelD3DbDgUESODrSOQXJiOaKGOmpS+JhbCcT6XlnnpOCBC1yJs+w/zlr1/ZhtNVXCOGKzOR9eFP0dMDSnS5F0f+hS91kjTehHKrgOoB8OYnRa6YhlvaI1B2/aEzCKS/iOc8vQbU0598Th9nuWSlnt+ZmVanjc73feoHp+L5v60FKgkuLfFn06F5aj5/+G5tBI0nX63z3Yl4sS8q0F6nd9reqrnMxpj3G0732viOTm0PrB7M5SSapI79lY7dzl5ycmcWK5Cd3KKK5BNH7MPcRN5nmFyB9f1wSTGyFYJV/X62bQhd61f06GhOmYwVGDMhZoSvZbULBMZFysT8g/+nJRPZdr24KHPN6LwR0Z5WC5kXUBrDxGB8cjRM1iv50P/n/a/Zptt9ejlFzTs7sCQia5geo45pfWNSXv07oX9XboPGT5sAJrL2821mfySZ5KVW53Winq0PSpUB+9ZmYo86GkXSJyrsXKO4ThLTdR+yGomOh2KazJi4heWOeInmx8/3iyeMKYRz7Nmx/quBst7/Rixx/2A+76cdhktHG5viQ4Uvyraqvmho14X2u2+7PP5lWbOai+BNlvkB2cNfogrhLpUk2b2shPYH0dVdb7hLZ4K2hEosM2yAk/oiJtPL/64TUEfo1w9JO/QbqPTMO2AnK/cwaqXw9/ayQ65POJlgBHNOhWGAfoR0y6tYjo6dQjBu 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)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 12:40:29.8407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff8503de-184a-4303-da77-08dc3ea3c5da 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: CO1PEPF000042AA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8971 There can be situations when the registers cannot be emulated to their full functionality. This can be due to the complexity involved. In such cases, one can emulate those registers as RAZ/WI for example. We call them as partial emulation. Some registers are non-optional and as such there is nothing preventing an OS from accessing them. Instead of injecting undefined exception (which might result in crashing a guest), one may want to prefer a partial emulation to let the guest running (in some cases accepting the fact that it might result in unwanted behavior). A suitable example of this (as seen in subsequent patches) is emulation of DBGDTRTX_EL0 (on Arm64) and DBGDTRTXINT(on Arm32). These non-optional registers can be emulated as RAZ/WI and they can be enclosed within CONFIG_PARTIAL_EMULATION. Further, "partial-emulation" command line option allows us to enable/disable partial emulation at run time. While CONFIG_PARTIAL_EMULATION enables support for partial emulation at compile time (i.e. adds code for partial emulation), this option may be enabled or disabled by Yocto or other build systems. However if the build system turns this option on, users can use scripts like Imagebuilder to generate uboot-script which will append "partial-emulation=true" to xen command line to turn on the partial emulation. Thus, it helps to avoid rebuilding xen. By default, "CONFIG_PARTIAL_EMULATION=y" and "partial-emulation=false". This is done so that Xen supports partial emulation. However, customers are fully aware when they enable partial emulation. It's important to note that enabling such support might result in unwanted/non-spec compliant behavior. Added a note in SUPPORT.md to clarify the security support for partial emulation. Signed-off-by: Ayan Kumar Halder Signed-off-by: Michal Orzel Acked-by: Julien Grall --- Changes from v1 :- 1. New patch introduced in v2. v2 :- 1. Reordered the patches so that the config and command line option is introduced in the first patch. v3 :- 1. Defined a macro 'partial_emulation' to reduce if-defs. 2. Fixed style issues. v4 :- 1. Added a note in SUPPORT.md. v5 :- 1. Dropped R-b 2. Update the commit message and Kconfig message. 3. Update 'SUPPORT.md' message. SUPPORT.md | 9 +++++++++ docs/misc/xen-command-line.pandoc | 11 +++++++++++ xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/include/asm/traps.h | 6 ++++++ xen/arch/arm/traps.c | 9 +++++++++ 5 files changed, 44 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index 7eb6875cfa..b49da114ab 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -102,6 +102,15 @@ Extension to the GICv3 interrupt controller to support MSI. Status: Experimental +### ARM/Partial Emulation + +Enable partial emulation of registers, otherwise considered unimplemented, +that would normally trigger a fault injection. + + Status: Supported, with caveats + +Only the following system registers are security supported: + ### ARM Scalable Vector Extension (SVE/SVE2) Arm64 domains can use Scalable Vector Extension (SVE/SVE2). diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line.pandoc index 02896598df..023c5e7225 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1942,6 +1942,17 @@ This option is ignored in **pv-shim** mode. > Default: `on` +### partial-emulation (arm) +> `= ` + +> Default: `false` + +Flag to enable or disable partial emulation of system/coprocessor registers. +Only effective if CONFIG_PARTIAL_EMULATION is enabled. + +**WARNING: Enabling this option might result in unwanted/non-spec compliant +behavior.** + ### pci = List of [ serr=, perr= ] diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 40f834bb71..f8139a773a 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -234,6 +234,15 @@ config STATIC_EVTCHN This option enables establishing static event channel communication between domains on a dom0less system (domU-domU as well as domU-dom0). +config PARTIAL_EMULATION + bool "Enable partial emulation of system/coprocessor registers" + default y + help + This option enables partial emulation of registers to prevent possible + guests crashing when accessing registers which are not optional but have + not been emulated to their complete functionality. Enabling this might + result in unwanted/non-spec compliant behavior. + endmenu menu "ARM errata workaround via the alternative framework" diff --git a/xen/arch/arm/include/asm/traps.h b/xen/arch/arm/include/asm/traps.h index 883dae368e..9a60dbf70e 100644 --- a/xen/arch/arm/include/asm/traps.h +++ b/xen/arch/arm/include/asm/traps.h @@ -10,6 +10,12 @@ # include #endif +#ifdef CONFIG_PARTIAL_EMULATION +extern bool partial_emulation; +#else +#define partial_emulation false +#endif + /* * GUEST_BUG_ON is intended for checking that the guest state has not been * corrupted in hardware and/or that the hardware behaves as we diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 9c10e8f78c..d1c7a6c516 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -42,6 +42,15 @@ #include #include +/* + * partial_emulation: If true, partial emulation for system/coprocessor + * registers will be enabled. + */ +#ifdef CONFIG_PARTIAL_EMULATION +bool __ro_after_init partial_emulation = false; +boolean_param("partial-emulation", partial_emulation); +#endif + /* The base of the stack must always be double-word aligned, which means * that both the kernel half of struct cpu_user_regs (which is pushed in * entry.S) and struct cpu_info (which lives at the bottom of a Xen From patchwork Thu Mar 7 12:39:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13585524 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 93638C54798 for ; Thu, 7 Mar 2024 12:40:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.689876.1075293 (Exim 4.92) (envelope-from ) id 1riD39-0006W7-PV; Thu, 07 Mar 2024 12:40:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 689876.1075293; Thu, 07 Mar 2024 12:40:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riD39-0006Vy-Mo; Thu, 07 Mar 2024 12:40:39 +0000 Received: by outflank-mailman (input) for mailman id 689876; Thu, 07 Mar 2024 12:40:39 +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 1riD38-00060p-Uw for xen-devel@lists.xenproject.org; Thu, 07 Mar 2024 12:40:38 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20600.outbound.protection.outlook.com [2a01:111:f403:2418::600]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e54450b4-dc7f-11ee-a1ee-f123f15fe8a2; Thu, 07 Mar 2024 13:40:37 +0100 (CET) Received: from MW2PR16CA0066.namprd16.prod.outlook.com (2603:10b6:907:1::43) by PH7PR12MB9104.namprd12.prod.outlook.com (2603:10b6:510:2f3::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Thu, 7 Mar 2024 12:40:33 +0000 Received: from CO1PEPF000042A8.namprd03.prod.outlook.com (2603:10b6:907:1:cafe::49) by MW2PR16CA0066.outlook.office365.com (2603:10b6:907:1::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.26 via Frontend Transport; Thu, 7 Mar 2024 12:40:33 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000042A8.mail.protection.outlook.com (10.167.243.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Thu, 7 Mar 2024 12:40:32 +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, 7 Mar 2024 06:40:31 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 06:40:31 -0600 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 06:40:30 -0600 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: e54450b4-dc7f-11ee-a1ee-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ADEsEXqDv97laYcPccBjgvytDiQ7J6hxu6acZpQlc30abBFTvXcH0MD9DBT/JufTtqvujVYTaZdsXRPAaV9v1sNPeba0qXBLACoqYOZ5dxoUAQEy5x/L9PzPAH5D3EwS1a0eToVEdrbtaWnHyVY9IWszbBipc3sjs14NCufIiEpWRPFSQcBQF7TmOLOyzF8U5MfrTCZnyhHgWDwIdWsp1VlqupgdGuniQ63lwpTNYci1LHcKlH8N8DpjIvsa5ghZakWwrQbBSVVbZi17nZqChInMpNGy1gi2AhbMzgBkV0NVJX3xwUl1VSDa5yVy8ym2THEnIi+A0wIhaVqWqHzgKA== 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=WA09ySjvIBLO6YzmcvJCT2DSUP4qszeYzbwIgvcjmgo=; b=dWWt/OQDrpxXpc3I8+3dh4Zbu1ykD61CpE6f54nmTOQH5rY6StWtdiwglLcyC4jysBTrMMDTN7RS6gOPgOdpBRuAb8YKsyh1LA1Zhbcgo0WwLcT3bmB+kBWKFrn/A+GojdVNEl0/g7cNLuGgBiaQ8OTGoMBrfIMXPpr/nqz89xUKCrdswfFHrGHSdkAaBpxnGGR9Ey7WwqNxCX3CJ30yPLbqjHMHU/FurH+qJHgRTVN+x6YKL3uYp/9SVhaYCLxIpU4J16B5ZnKeTxb0BS/Qfu2mzoWtzfL2QLSw+enIw+KOmdhYShzpMaRSx35+OMnkaL4kCjlZCxiZOBXWC4RwEg== 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=WA09ySjvIBLO6YzmcvJCT2DSUP4qszeYzbwIgvcjmgo=; b=U7ElEWWhOTreyUpZ1SEopPHCKqKwFpog543aYqem8H3QI05kJ2k+fgxXpJF3niDn/xVwi4ilkxkGj2FjhiaBTGFnd8dMv5zDu7HadZxnZOyaslczDDN491TzQ7b6qh+dZC7SMCjAj4SRfkmQJzd4oB5GwbMvU4Ojt5WrTsErWMk= 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: Ayan Kumar Halder To: CC: , , , , , , Ayan Kumar Halder Subject: [XEN v6 2/3] xen/arm: arm64: Add emulation of Debug Data Transfer Registers Date: Thu, 7 Mar 2024 12:39:42 +0000 Message-ID: <20240307123943.1991755-3-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240307123943.1991755-1-ayan.kumar.halder@amd.com> References: <20240307123943.1991755-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: ayan.kumar.halder@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A8:EE_|PH7PR12MB9104:EE_ X-MS-Office365-Filtering-Correlation-Id: 77b989ad-e3b1-4ad5-2e4e-08dc3ea3c785 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HrSmHpLnOl/0Yr5QPRBQkGykp7CFCTk/GuxNmWxoZxBik91Hvj/lpod08yF1DugowsLV8d+DwW2J9kb0RJhNUSufZtKoJ8Fk9WNl5O3b59Ci77YasLh8QYNNLBNr+u0IOsJOaYoyXfyYpqZLbSXdJ0yiu9aBIzK3Fz1Trr49xHfCqtS9Ug91MfxVGMu+Nj39l3ulbNo0Ok21/1vJwlsFWA9QWUUu5WDgBqbNRPIfGoD85ykGQ31AU6SVvEupl9ShyD5sTUWEa9+4CUvptbCmmtTIVoKKwPBc6TVhNrDHwbNeNXLShAjdnxhWe3T8Ex99mpwiQmgOe+5jlHe+/ZoVllrnzrSw47DBLtlAC53n1LY0fwDu4kWMJssOkYEEJT69fBvruiOMpHWGmfy45d6wzLScouqoBMx1fVAPy84aUA1/yotxNNzfQEp99FPf7sRMcvXEuWpAN5wgKFyg6EeOKoJvqlr9nEqYKkCzTeIqeItkyDXUk5YO4kPy031rzcqvd8vL+45E8C25EhyIzh3bKwEjAP+EQn9YBdiBTrOvqWdWpkSXB8kRC1dpdruVE0P42hLBHEvfD2nud1ZsjzreuAMnr+lYdtCPKjK19Q2UtNI40GbZPoyL9JgtDhQDiRLFuksxtkVslHseKBURQ8dE0TWwKVSHtpvnd5kSUTam/1YqcTnVbg8dWTWm8fLFfP63XQTkgG9MjpWn5P5PLctJHhu6FfrbZ1d12ITICXjocbV3A21LmaEm8V5n+hU9C/vz 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)(82310400014)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 12:40:32.6190 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 77b989ad-e3b1-4ad5-2e4e-08dc3ea3c785 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: CO1PEPF000042A8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9104 From: Michal Orzel Currently, if user enables HVC_DCC config option in Linux, it invokes access to debug data transfer registers (i.e. DBGDTRTX_EL0 on arm64, DBGDTRTXINT on arm32). As these registers are not emulated, Xen injects an undefined exception to the guest and Linux crashes. To prevent this crash, introduce a partial emulation of DBGDTR[TR]X_EL0 (these registers share the same encoding) as RAZ/WI and MDCCSR_EL0 as TXfull. Refer ARM DDI 0487J.a ID042523, D19.3.8, DBGDTRTX_EL0 "If TXfull is set to 1, set DTRRX and DTRTX to UNKNOWN". Thus, any OS is expected to read MDCCSR_EL0 and check for TXfull before using DBGDTRTX_EL0. Linux does it via hvc_dcc_init() ---> hvc_dcc_check(), and returns -ENODEV in case TXfull bit is still set after writing a test character. This way we prevent the guest from making use of HVC DCC as a console. Signed-off-by: Michal Orzel Signed-off-by: Ayan Kumar Halder Acked-by: Julien Grall --- Changes from v1 :- 1. DBGDTR_EL0 does not emulate RXfull. This is to avoid giving the OS any indication that the RX buffer is full and is waiting to be read. 2. In Arm32, DBGOSLSR is emulated. Also DBGDTRTXINT is emulated at EL0 only. 3. Fixed the commit message and inline code comments. v2 :- 1. Split the patch into two (separate patches for arm64 and arm32). 2. Removed the "fail" label. 3. Fixed the commit message. v3 :- 1. "HSR_SYSREG_MDCCSR_EL0" emulation differs based on whether partial_emulation_enabled is true or not. 2. If partial_emulation_enabled is false, then access to HSR_SYSREG_DBGDTR_EL0, HSR_SYSREG_DBGDTRTX_EL0 would lead to undefined exception. v4 :- 1. Invoked "goto fail" from "default:" to ensure compliance with MISRA 15.3. v5 :- 1. Fixed style issues. 2. Removed R-b. 3. Removed HSR_SYSREG_ prefixes from registers. SUPPORT.md | 5 ++ xen/arch/arm/arm64/vsysreg.c | 69 +++++++++++++++++++--------- xen/arch/arm/include/asm/arm64/hsr.h | 3 ++ 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/SUPPORT.md b/SUPPORT.md index b49da114ab..afbd820084 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -111,6 +111,11 @@ that would normally trigger a fault injection. Only the following system registers are security supported: + MDCCSR_EL0 + DBGDTR_EL0 + DBGDTRTX_EL0 + DBGDTRRX_EL0 + ### ARM Scalable Vector Extension (SVE/SVE2) Arm64 domains can use Scalable Vector Extension (SVE/SVE2). diff --git a/xen/arch/arm/arm64/vsysreg.c b/xen/arch/arm/arm64/vsysreg.c index b5d54c569b..c73b2c95ce 100644 --- a/xen/arch/arm/arm64/vsysreg.c +++ b/xen/arch/arm/arm64/vsysreg.c @@ -82,6 +82,7 @@ TVM_REG(CONTEXTIDR_EL1) void do_sysreg(struct cpu_user_regs *regs, const union hsr hsr) { + const struct hsr_sysreg sysreg = hsr.sysreg; int regidx = hsr.sysreg.reg; struct vcpu *v = current; @@ -159,9 +160,6 @@ void do_sysreg(struct cpu_user_regs *regs, * * Unhandled: * MDCCINT_EL1 - * DBGDTR_EL0 - * DBGDTRRX_EL0 - * DBGDTRTX_EL0 * OSDTRRX_EL1 * OSDTRTX_EL1 * OSECCR_EL1 @@ -171,12 +169,42 @@ void do_sysreg(struct cpu_user_regs *regs, */ case HSR_SYSREG_MDSCR_EL1: return handle_raz_wi(regs, regidx, hsr.sysreg.read, hsr, 1); + + /* + * Xen doesn't expose a real (or emulated) Debug Communications Channel + * (DCC) to a domain. Yet the Arm ARM implies this is not an optional + * feature. So some domains may start to probe it. For instance, the + * HVC_DCC driver in Linux (since f377775dc083 and at least up to v6.7), + * will try to write some characters and check if the transmit buffer + * has emptied. + */ case HSR_SYSREG_MDCCSR_EL0: /* + * By setting TX status bit (only if partial emulation is enabled) to + * indicate the transmit buffer is full, we would hint the OS that the + * DCC is probably not working. + * + * Bit 29: TX full + * * Accessible at EL0 only if MDSCR_EL1.TDCC is set to 0. We emulate that * register as RAZ/WI above. So RO at both EL0 and EL1. */ - return handle_ro_raz(regs, regidx, hsr.sysreg.read, hsr, 0); + return handle_ro_read_val(regs, regidx, hsr.sysreg.read, hsr, 0, + partial_emulation ? (1U << 29) : 0); + + case HSR_SYSREG_DBGDTR_EL0: + /* DBGDTR[TR]X_EL0 share the same encoding */ + case HSR_SYSREG_DBGDTRTX_EL0: + /* + * Emulate as RAZ/WI (only if partial emulation is enabled) to prevent + * injecting undefined exception. + * Accessible at EL0 only if MDSCR_EL1.TDCC is set to 0. We emulate that + * register as RAZ/WI. + */ + if ( !partial_emulation ) + goto fail; + return handle_raz_wi(regs, regidx, hsr.sysreg.read, hsr, 0); + HSR_SYSREG_DBG_CASES(DBGBVR): HSR_SYSREG_DBG_CASES(DBGBCR): HSR_SYSREG_DBG_CASES(DBGWVR): @@ -394,26 +422,25 @@ void do_sysreg(struct cpu_user_regs *regs, * And all other unknown registers. */ default: - { - const struct hsr_sysreg sysreg = hsr.sysreg; - - gdprintk(XENLOG_ERR, - "%s %d, %d, c%d, c%d, %d %s x%d @ 0x%"PRIregister"\n", - sysreg.read ? "mrs" : "msr", - sysreg.op0, sysreg.op1, - sysreg.crn, sysreg.crm, - sysreg.op2, - sysreg.read ? "=>" : "<=", - sysreg.reg, regs->pc); - gdprintk(XENLOG_ERR, - "unhandled 64-bit sysreg access %#"PRIregister"\n", - hsr.bits & HSR_SYSREG_REGS_MASK); - inject_undef_exception(regs, hsr); - return; - } + goto fail; } regs->pc += 4; + return; + + fail: + gdprintk(XENLOG_ERR, + "%s %d, %d, c%d, c%d, %d %s x%d @ 0x%"PRIregister"\n", + sysreg.read ? "mrs" : "msr", + sysreg.op0, sysreg.op1, + sysreg.crn, sysreg.crm, + sysreg.op2, + sysreg.read ? "=>" : "<=", + sysreg.reg, regs->pc); + gdprintk(XENLOG_ERR, + "unhandled 64-bit sysreg access %#"PRIregister"\n", + hsr.bits & HSR_SYSREG_REGS_MASK); + inject_undef_exception(regs, hsr); } /* diff --git a/xen/arch/arm/include/asm/arm64/hsr.h b/xen/arch/arm/include/asm/arm64/hsr.h index e691d41c17..1495ccddea 100644 --- a/xen/arch/arm/include/asm/arm64/hsr.h +++ b/xen/arch/arm/include/asm/arm64/hsr.h @@ -47,6 +47,9 @@ #define HSR_SYSREG_OSDLR_EL1 HSR_SYSREG(2,0,c1,c3,4) #define HSR_SYSREG_DBGPRCR_EL1 HSR_SYSREG(2,0,c1,c4,4) #define HSR_SYSREG_MDCCSR_EL0 HSR_SYSREG(2,3,c0,c1,0) +#define HSR_SYSREG_DBGDTR_EL0 HSR_SYSREG(2,3,c0,c4,0) +#define HSR_SYSREG_DBGDTRTX_EL0 HSR_SYSREG(2,3,c0,c5,0) +#define HSR_SYSREG_DBGDTRRX_EL0 HSR_SYSREG(2,3,c0,c5,0) #define HSR_SYSREG_DBGBVRn_EL1(n) HSR_SYSREG(2,0,c0,c##n,4) #define HSR_SYSREG_DBGBCRn_EL1(n) HSR_SYSREG(2,0,c0,c##n,5) From patchwork Thu Mar 7 12:39:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13585525 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 02326C54798 for ; Thu, 7 Mar 2024 12:40:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.689877.1075303 (Exim 4.92) (envelope-from ) id 1riD3C-0006lw-1o; Thu, 07 Mar 2024 12:40:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 689877.1075303; Thu, 07 Mar 2024 12:40:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1riD3B-0006lk-UV; Thu, 07 Mar 2024 12:40:41 +0000 Received: by outflank-mailman (input) for mailman id 689877; Thu, 07 Mar 2024 12:40:41 +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 1riD3B-00060p-3c for xen-devel@lists.xenproject.org; Thu, 07 Mar 2024 12:40:41 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20601.outbound.protection.outlook.com [2a01:111:f403:2418::601]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id e6b5ae22-dc7f-11ee-a1ee-f123f15fe8a2; Thu, 07 Mar 2024 13:40:39 +0100 (CET) Received: from BYAPR01CA0014.prod.exchangelabs.com (2603:10b6:a02:80::27) by CY8PR12MB8195.namprd12.prod.outlook.com (2603:10b6:930:77::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Thu, 7 Mar 2024 12:40:35 +0000 Received: from SJ1PEPF00001CEA.namprd03.prod.outlook.com (2603:10b6:a02:80:cafe::63) by BYAPR01CA0014.outlook.office365.com (2603:10b6:a02:80::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.38 via Frontend Transport; Thu, 7 Mar 2024 12:40:35 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by SJ1PEPF00001CEA.mail.protection.outlook.com (10.167.242.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Thu, 7 Mar 2024 12:40:35 +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, 7 Mar 2024 06:40:34 -0600 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 7 Mar 2024 06:40:34 -0600 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 7 Mar 2024 06:40:33 -0600 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: e6b5ae22-dc7f-11ee-a1ee-f123f15fe8a2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YAyXdCV/J4N0JT8gTDwrBJlmEwmiYLfWetPGYHjEsnjjTWHKMx5czvMN4TPnxyvkG0j8Pdw0g/fMJOlhINB80ruIzliCnVbW0VtgMj3NmSFDUb7YIsyG6QPI5bnXbtekaS+EOUEGeOEFbqvFvu0sCAGYVHXesL9avx24QhOQREuMx06SJv9VJ5ST73XWd9yc6Gh+Dosui3ZDAw6qKTwZJMO/m8LXHEJY5ujvyNPCEGOsj0y23IxUVmD2UW37EqUjkYRKZaVBfSMQYOmyaThjIZbD79bHh9DGXwbamuo6anwrE1TaJ3Osh45pcxnmDeGga/37bieb+gfbSjhh+7V+UA== 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=OXmedK0QVYV/fwcpnxU7YEJJLCulbSQoe7KyRDQYIbc=; b=A5FpYE28p1/OmPdw1GyU58E/7kZYec8rSDxJi8+vtjxJZpVpBrn5tMcQy0fkT3onOQ6/39AIh3eLkyFHLMa2k2LReVhl3SCiuIk1BtE8PtWmjz+7rlT+RDwMbMVSEzDm8qRBmSBNVnKzwMKi4QFgXpIM3gSK18RyAEKHzkyGld/unzs5WCBva33ia0Jf57+jG5uwUyKoEN6fb0o+4Pd2Cz1F/C9zLqaiZfHZO9ODRcvoQ9ac1FlwSOE7hUgFwstcecDndK5viB/aVWSzm7Tq+UVDh9/qkfnUwI5XLVSxCg5FKUB9PkysgD59qJJqShiqsi/tcvLgc3H5PqsUcjFTeA== 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=OXmedK0QVYV/fwcpnxU7YEJJLCulbSQoe7KyRDQYIbc=; b=oecZOkyH1Ab1KnnO+55Mds7cfzkAljyfBEmYyLtW2k25sMKzEflEI0xIP3qOH8zxIFco4dmLeqGJ6ZgDYTRDr17UaX5A0jo+JxDP41+1xep9Gh9hMKOO3xGzgTibLlH1a0dr3NM26wHpIT/TV9lbTaEF4yeCXXYL7CSrmFp42IA= 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: Ayan Kumar Halder To: CC: , , , , , , Ayan Kumar Halder Subject: [XEN v6 3/3] xen/arm: arm32: Add emulation of Debug Data Transfer Registers Date: Thu, 7 Mar 2024 12:39:43 +0000 Message-ID: <20240307123943.1991755-4-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240307123943.1991755-1-ayan.kumar.halder@amd.com> References: <20240307123943.1991755-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB05.amd.com: ayan.kumar.halder@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CEA:EE_|CY8PR12MB8195:EE_ X-MS-Office365-Filtering-Correlation-Id: 41aa4874-edf2-44d1-00a1-08dc3ea3c8fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hPnoC1wDIG/EhSH152dotqXoK99hU8fT0/V+facNvujZA1JOsAhGqjHRegtozf/bz0dhuhuzs/4hUMAMSxFGTrlXAO7rOanq1wIJC3H11p5NF/oEfoH8p0z+937nlEJfFUxhSoxnEEK8e+tIieI8wEmFKGxdPe834H0/0oCAgM+KbKFCbkWCQ5uqVA6H4WvK1xLjy4YoKtknL/I3QP6ZBR60AmgyXzXQ+YDZuPjQAcavybVmekIa1qyABOcmvDPwyP6OMKJX1T3aap0rMVXD9hgjXhNwYo1CpZJH/EylQ9RsbC6X78STrA+so85njxKBYyEEA28bmDP+lGpmTJJTkV0+GjUAD+ws/S2w2v4AW6s2lA48pjf5dkIeKxu5dOPsElbrDgEOdwQNjAsVIYb7djNlL16JippRgTQvYposCtmoQSKTsxU5BPz7nSF5qNQGcsnRwCHwk18v6O2CLgtTEmj0/39DEgmVKshW6F5ampNX7iTqieds78rk1j48+iWiOHysGogXZxjddflD4/wRP++jDA37W3vS57eGQqZ0CtlmfaUw0pgD5pXWujRuHvudfOWrmKE+r1c6nU1mRRAfzt2Cz+66Fj/vWcW0YO+btRX97+N1B63KEU65MkH/PnHVLgUA+xmZGs5l8P1nympwAojG/p+Nt6/VhZbDxZh65or5gueyEFpyatiEb+YbT9Eqc4fUfQd6gqG/WAO5Ber/GA8b+lhDgjdpEYCfnt5UEOVcyhx5HZaLqznGEHBTMQTP 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)(82310400014)(36860700004)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2024 12:40:35.1223 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41aa4874-edf2-44d1-00a1-08dc3ea3c8fc 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: SJ1PEPF00001CEA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8195 When user enables HVC_DCC config option in Linux, it invokes access to debug transfer register (i.e. DBGDTRTXINT). As this register is not emulated, Xen injects an undefined exception to the guest and Linux crashes. To prevent this crash, introduce a partial emulation of DBGDTR[TR]XINT (these registers share the same encoding) as RAZ/WI and DBGDSCRINT as TXfull. Refer ARM DDI 0487J.a ID042523, G8.3.19, DBGDTRTXint: "If TXfull is set to 1, set DTRTX to UNKNOWN". As a pre-requisite, DBGOSLSR should be emulated in the same way as its AArch64 variant (i.e. OSLSR_EL1). This is to ensure that DBGOSLSR.OSLK is 0, which allows us to skip the emulation of DBGDSCREXT (TXfull is treated as UNK/SBZP) and focus on DBGDSCRINT. DBGOSLSR.OSLM[1] is set to 1 to mantain consistency with Arm64. Take the opportunity to fix the minimum EL for DBGDSCRINT, which should be 0. Signed-off-by: Ayan Kumar Halder Signed-off-by: Michal Orzel Acked-by: Julien Grall --- Changes from v1 :- 1. DBGDTR_EL0 does not emulate RXfull. This is to avoid giving the OS any indication that the RX buffer is full and is waiting to be read. 2. In Arm32, DBGOSLSR is emulated. Also DBGDTRTXINT is emulated at EL0 only. 3. Fixed the commit message and inline code comments. v2 :- 1. Split the patch into two (separate patches for arm64 and arm32). 2. Fixed in line comments and style related issues. 3. Updated commit message to mention DBGDSCRINT handling. v3 :- 1. The original emulation of DBGDSCRINT is retained when 'partial_emulation' is false. 2. If 'partial_emulation' is false, then access to DBGDTRTXINT will lead to undefined exception. v4 :- 1. Invoked "goto fail" from "default:" to ensure compliance with MISRA 15.3. v5 :- 1. Reword the commit message 2. Remove the 'return' at the end of function. SUPPORT.md | 3 ++ xen/arch/arm/include/asm/cpregs.h | 2 + xen/arch/arm/vcpreg.c | 62 ++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/SUPPORT.md b/SUPPORT.md index afbd820084..e0ff30cfe9 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -115,6 +115,9 @@ Only the following system registers are security supported: DBGDTR_EL0 DBGDTRTX_EL0 DBGDTRRX_EL0 + DBGDSCRINT + DBGDTRTXINT + DBGDTRRXINT ### ARM Scalable Vector Extension (SVE/SVE2) diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/cpregs.h index 6b083de204..aec9e8f329 100644 --- a/xen/arch/arm/include/asm/cpregs.h +++ b/xen/arch/arm/include/asm/cpregs.h @@ -75,6 +75,8 @@ #define DBGDIDR p14,0,c0,c0,0 /* Debug ID Register */ #define DBGDSCRINT p14,0,c0,c1,0 /* Debug Status and Control Internal */ #define DBGDSCREXT p14,0,c0,c2,2 /* Debug Status and Control External */ +#define DBGDTRRXINT p14,0,c0,c5,0 /* Debug Data Transfer Register, Receive */ +#define DBGDTRTXINT p14,0,c0,c5,0 /* Debug Data Transfer Register, Transmit */ #define DBGVCR p14,0,c0,c7,0 /* Vector Catch */ #define DBGBVR0 p14,0,c0,c0,4 /* Breakpoint Value 0 */ #define DBGBCR0 p14,0,c0,c0,5 /* Breakpoint Control 0 */ diff --git a/xen/arch/arm/vcpreg.c b/xen/arch/arm/vcpreg.c index a2d0500704..b203f4a142 100644 --- a/xen/arch/arm/vcpreg.c +++ b/xen/arch/arm/vcpreg.c @@ -493,11 +493,12 @@ void do_cp14_32(struct cpu_user_regs *regs, const union hsr hsr) * ARMv8 (DDI 0487A.d): D1-1509 Table D1-58 * * Unhandled: - * DBGOSLSR * DBGPRCR */ case HSR_CPREG32(DBGOSLAR): return handle_wo_wi(regs, regidx, cp32.read, hsr, 1); + case HSR_CPREG32(DBGOSLSR): + return handle_ro_read_val(regs, regidx, cp32.read, hsr, 1, 1U << 3); case HSR_CPREG32(DBGOSDLR): return handle_raz_wi(regs, regidx, cp32.read, hsr, 1); @@ -509,8 +510,6 @@ void do_cp14_32(struct cpu_user_regs *regs, const union hsr hsr) * * Unhandled: * DBGDCCINT - * DBGDTRRXint - * DBGDTRTXint * DBGWFAR * DBGDTRTXext * DBGDTRRXext, @@ -548,12 +547,27 @@ void do_cp14_32(struct cpu_user_regs *regs, const union hsr hsr) break; } + /* + * Xen doesn't expose a real (or emulated) Debug Communications Channel + * (DCC) to a domain. Yet the Arm ARM implies this is not an optional + * feature. So some domains may start to probe it. For instance, the + * HVC_DCC driver in Linux (since f377775dc083 and at least up to v6.7), + * will try to write some characters and check if the transmit buffer has + * emptied. + */ case HSR_CPREG32(DBGDSCRINT): /* - * Read-only register. Accessible by EL0 if DBGDSCRext.UDCCdis - * is set to 0, which we emulated below. + * By setting TX status bit (only if partial emulation is enabled) to + * indicate the transmit buffer is full, we would hint the OS that the + * DCC is probably not working. + * + * Bit 29: TX full + * + * Accessible at EL0 only if DBGDSCRext.UDCCdis is set to 0. We emulate + * this as RAZ/WI in the next case. So RO at both EL0 and EL1. */ - return handle_ro_raz(regs, regidx, cp32.read, hsr, 1); + return handle_ro_read_val(regs, regidx, cp32.read, hsr, 0, + partial_emulation ? (1U << 29) : 0); case HSR_CPREG32(DBGDSCREXT): /* @@ -562,6 +576,18 @@ void do_cp14_32(struct cpu_user_regs *regs, const union hsr hsr) */ return handle_raz_wi(regs, regidx, cp32.read, hsr, 1); + /* DBGDTR[TR]XINT share the same encoding */ + case HSR_CPREG32(DBGDTRTXINT): + /* + * Emulate as RAZ/WI (only if partial emulation is enabled) to prevent + * injecting undefined exception. + * Accessible at EL0 only if DBGDSCREXT is set to 0. We emulate that + * register as RAZ/WI. + */ + if ( !partial_emulation ) + goto fail; + return handle_raz_wi(regs, regidx, cp32.read, hsr, 0); + case HSR_CPREG32(DBGVCR): case HSR_CPREG32(DBGBVR0): case HSR_CPREG32(DBGBCR0): @@ -591,17 +617,20 @@ void do_cp14_32(struct cpu_user_regs *regs, const union hsr hsr) * And all other unknown registers. */ default: - gdprintk(XENLOG_ERR, - "%s p14, %d, r%d, cr%d, cr%d, %d @ 0x%"PRIregister"\n", - cp32.read ? "mrc" : "mcr", - cp32.op1, cp32.reg, cp32.crn, cp32.crm, cp32.op2, regs->pc); - gdprintk(XENLOG_ERR, "unhandled 32-bit cp14 access %#"PRIregister"\n", - hsr.bits & HSR_CP32_REGS_MASK); - inject_undef_exception(regs, hsr); - return; + goto fail; } advance_pc(regs, hsr); + return; + + fail: + gdprintk(XENLOG_ERR, + "%s p14, %d, r%d, cr%d, cr%d, %d @ 0x%"PRIregister"\n", + cp32.read ? "mrc" : "mcr", + cp32.op1, cp32.reg, cp32.crn, cp32.crm, cp32.op2, regs->pc); + gdprintk(XENLOG_ERR, "unhandled 32-bit cp14 access %#"PRIregister"\n", + hsr.bits & HSR_CP32_REGS_MASK); + inject_undef_exception(regs, hsr); } void do_cp14_64(struct cpu_user_regs *regs, const union hsr hsr) @@ -659,10 +688,7 @@ void do_cp14_dbg(struct cpu_user_regs *regs, const union hsr hsr) * ARMv8 (DDI 0487A.d): D1-1509 Table D1-58 * * Unhandled: - * DBGDTRTXint - * DBGDTRRXint - * - * And all other unknown registers. + * All unknown registers. */ gdprintk(XENLOG_ERR, "%s p14, %d, r%d, r%d, cr%d @ 0x%"PRIregister"\n",