From nobody Sun May 12 21:26:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1708431502; cv=pass; d=zohomail.com; s=zohoarc; b=XxlsoG8/rmbgADyc2kL6NkIsw8I44e08rfJWB9JsC8MpVtC7IOs7WYI+UW39FA7spCnsm7BVKlx8jm5Py46kGD9BA89u3znZJeFjVnRs9UxvCLZi/r7MzsIwpK8qBHbucPkdZy8BQ4MOhWklKvL4FsBgCM+b0kP/06wfvuUUgZE= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431502; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EETal9k4inYY30L6I7esCkTiZAi5uczUE8BepjuzslE=; b=kcvexBl7fsYYw8qiTkO2D4ag6TkU5o2WUgroXa2cTBuvP7R/XYZqP5XCCNfpj/t3cMArxO89SQ59Jev+iqiY4sC2NZ+bHEzVdUpCbk6mFO/GvHMsI+tBN9h2x/xke1BM8Zczt5fR8XtCfBYxA561BJV6AUwEM9FFE/LYQ3x7Qvs= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1708431502211343.6029177464968; Tue, 20 Feb 2024 04:18:22 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.683467.1063009 (Exim 4.92) (envelope-from ) id 1rcP4a-0000vS-NR; Tue, 20 Feb 2024 12:18:08 +0000 Received: by outflank-mailman (output) from mailman id 683467.1063009; Tue, 20 Feb 2024 12:18:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rcP4a-0000vL-Ja; Tue, 20 Feb 2024 12:18:08 +0000 Received: by outflank-mailman (input) for mailman id 683467; Tue, 20 Feb 2024 12:18:07 +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 1rcP4Z-0000eL-6q for xen-devel@lists.xenproject.org; Tue, 20 Feb 2024 12:18:07 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060d.outbound.protection.outlook.com [2a01:111:f400:7e88::60d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 19998b1e-cfea-11ee-8a52-1f161083a0e0; Tue, 20 Feb 2024 13:18:06 +0100 (CET) Received: from DS7PR05CA0018.namprd05.prod.outlook.com (2603:10b6:5:3b9::23) by DS0PR12MB8815.namprd12.prod.outlook.com (2603:10b6:8:14f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.19; Tue, 20 Feb 2024 12:18:03 +0000 Received: from CY4PEPF0000EDD5.namprd03.prod.outlook.com (2603:10b6:5:3b9:cafe::65) by DS7PR05CA0018.outlook.office365.com (2603:10b6:5:3b9::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.32 via Frontend Transport; Tue, 20 Feb 2024 12:18:03 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD5.mail.protection.outlook.com (10.167.241.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Tue, 20 Feb 2024 12:18:02 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 20 Feb 2024 06:18:01 -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; Tue, 20 Feb 2024 06:18:00 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 19998b1e-cfea-11ee-8a52-1f161083a0e0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dT6qtKa1jn2HtlsPJY3QrZixOO6HpPIQOk9L/HFzls2TfJaMb2DZfs161H6Wgy5j3zlGG1SprKm7mdGOknqmEqj06bulb3PrGP88FLLBspvT55UKRZzFz/zyX+IAYJ+nJBsD103qlx9V7thUPl4YwhkVS0QZW/ewXVtjc2BP24OuX6xSi3Mm/aNdqdzhSrbNjcKhEl3OeT4NDunJWSYygh3ZVPjtMCx8XbZ/MDpRJEMfKipLjpOCXM2WK84jAREvJN0AVoEu3WFpIzke2Jaedl4DXphlJT8MGRk/xigDUmQLGKmvVY7nH35q1PKCmi/k9gHVDGTiiWe/Fmjfa9pCbg== 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=EETal9k4inYY30L6I7esCkTiZAi5uczUE8BepjuzslE=; b=HlzR6PCqALmq8oAtDX1J8PnEaKCMTMm5P8nZzioJnTtvzd0N9yqEUVwcWQhINxhaphs9Fv96MCfF3frwCcyQ57mkPJ1FgCJ4nW7kWDxued/e5rOPD8up/NuVk5iSUboCLB8W7Xdea+L+/wiBXX0AKDyHoXGDv1uDJd812/nVehYq4xT/YSu1vVEioVmE/mbZkAANxibpv1X8DbClv3QYerspBjyrRBD4X0EC5d370Tgd5nCLHWVzDgmwuDuzGfb1jmGUNsECaopaMGhUNk04ogUhRxI78R2a/pkeqyKRhjI10zjumohPLOgI2Pqjw/snKRSH4IKsbu0aFq8Q+bn7Vw== 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=EETal9k4inYY30L6I7esCkTiZAi5uczUE8BepjuzslE=; b=HDAL8Gh49RH+c1UjsiJT07FgZYCz32mIHvGEEIn0Z0SSt+bZcLQOTf+b78kG4gS6R3aeoKvEJQUwhW/yqDI1G2DcevHQde+1c+DpoLBUI/hBQDG+CklbKBSNON2WhYUSbvr+FUs9fmN12GpPwfJgG+G16gmJeycUt6AVpkJitH4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: , , , , , , Ayan Kumar Halder Subject: [XEN v5 1/3] xen/arm: Introduce CONFIG_PARTIAL_EMULATION and "partial-emulation" cmd option Date: Tue, 20 Feb 2024 12:17:41 +0000 Message-ID: <20240220121743.3680715-2-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220121743.3680715-1-ayan.kumar.halder@amd.com> References: <20240220121743.3680715-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD5:EE_|DS0PR12MB8815:EE_ X-MS-Office365-Filtering-Correlation-Id: c1916796-d8fe-4ce8-20a5-08dc320dfc6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: we1UyW+4gi0X5d2+VXFcmabEEwPPHq/c+XQR4xwMzGsQjS4YrTIX7x+AjlHo2KmlwtstXGhgi7hONjEr63kyFoaHiGt2eA9ornWm0dGVCVOP3XdZtpd/IL3Bt9toTx8j9cUaHuXu4f1rtCVnEMJQ9tLoKWfzYq8avZR4uPdVzOZnAIhQgtftrNnRF+euIf3WshI3b9OCKhGAtg10sBZdCGQeh91B0pSw7z9hD2x0fJXEEBmU3qt7ja/4WAqn0LBMSniXXyhmN9AKFuR84dl0iXZy0OYIdu9DVLs2sdbBGZiy1+KOC8MCkwMECAxzvGoHMCzzgYgqfF2kB+xL6tBKqj4iUYVJySa58ncZdkryVO/WLes21BnBn1CipsW9bPMy4O/9purFbzqlo4cCe4owhC9GRPsrEhZQ9Bb8XMYmvIxAwAogbbowFZeguSqtwYk3NUxX/sALvXlyesYrlNULaabaMz1CyFXAfNv4+hkM47c1M+Cjps1F2bRINcJ8dGME78z/Ug6b4EMUhiK019OU1jSLpek5NdXNXHley9nQma5d8C5jc3ciI3i5eHZE6gqwqJVLGn74dL4ha+komapbFIaPLfbP2retrQBwCTnTmSRzRZHj2Ikq+O6Hg2BMSLojKEjOmeas6pY6EJhCaxNn/iCsQXuaYQDoGMFfF+Yxo7k= 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)(230273577357003)(36860700004)(46966006)(40470700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2024 12:18:02.9673 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1916796-d8fe-4ce8-20a5-08dc320dfc6b 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: CY4PEPF0000EDD5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8815 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1708431504079100001 Content-Type: text/plain; charset="utf-8" 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, o= ne 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 (thus crashing a guest), one may w= ant to prefer a partial emulation to let the guest running (in some cases accep= ting 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=3Dtrue" to xen command line to turn on the partial emula= tion. Thus, it helps to avoid rebuilding xen. By default, "CONFIG_PARTIAL_EMULATION=3Dy" and "partial-emulation=3Dfalse". 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 Reviewed-by: Michal Orzel --- 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. SUPPORT.md | 12 ++++++++++++ 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, 47 insertions(+) diff --git a/SUPPORT.md b/SUPPORT.md index a90d1108c9..037578b10c 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -101,6 +101,18 @@ Extension to the GICv3 interrupt controller to support= MSI. =20 Status: Experimental =20 +### ARM/Partial Emulation + +Enable partial emulation of registers, otherwise considered unimplemented, +that would normally trigger a fault injection. + + Status: Supported, with caveats + +Bugs allowing the userspace to attack the guest OS will not be considered +security vulnerabilities. + +Bugs that could compromise Xen will be considered security vulnerabilities. + ### ARM Scalable Vector Extension (SVE/SVE2) =20 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 be76be8d53..0cac601066 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. =20 > Default: `on` =20 +### partial-emulation (arm) +> `=3D ` + +> Default: `false` + +Flag to enable or disable partial emulation of system/coprocessor register= s. +Only effective if CONFIG_PARTIAL_EMULATION is enabled. + +**WARNING: Enabling this option might result in unwanted/non-spec compliant +behavior.** + ### pci =3D List of [ serr=3D, perr=3D ] =20 diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 50e9bfae1a..dc243f4124 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -225,6 +225,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). =20 +config PARTIAL_EMULATION + bool "Enable partial emulation of system/coprocessor registers" + default y + help + This option enables partial emulation of registers to prevent guests + crashing when accessing registers which are not optional but have not b= een + emulated to their complete functionality. Enabling this might result in + unwanted/non-spec compliant behavior. + endmenu =20 menu "ARM errata workaround via the alternative framework" diff --git a/xen/arch/arm/include/asm/traps.h b/xen/arch/arm/include/asm/tr= aps.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 =20 +#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 =20 +/* + * partial_emulation: If true, partial emulation for system/coprocessor + * registers will be enabled. + */ +#ifdef CONFIG_PARTIAL_EMULATION +bool __ro_after_init partial_emulation =3D 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 --=20 2.25.1 From nobody Sun May 12 21:26:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1708431572; cv=pass; d=zohomail.com; s=zohoarc; b=GqOKeUL+B9jueK+sktgpgyFMZMv4sMdmGo0oX+Cq4rXs0gt1yhAAe8Z1sQ2diF62w+maFf9UONei7tpONnPVG8XnOkvsC6BxQybxmUcvGtQJGw8JoHTEnah2sNraP0M2L7tPLEGX4vgEYx+ycoMjybLzp9cO1hNjhXTXhBBVnFQ= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431572; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TyheUcKZClDVXN1YlPjAzeLmxnokNyXGDiz7llZyvHQ=; b=QubaB2Ds5rSF/7n12ZXxQXjn7EiIxAaAzulx/oPhB77Rbp/B29YSZy1eYgvzSFpKywoTrTDk9nI4xr2Mnju8Lb+vO3MBWCwDyzIW/J8GUD3fJlYvglktmp+NuhlfVgXFBclqZllStfC+mnBiJ4eDDAa9KkA6Nih4kN7G6D53Fmk= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 170843157227719.72038234399554; Tue, 20 Feb 2024 04:19:32 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.683475.1063019 (Exim 4.92) (envelope-from ) id 1rcP5k-0001n5-0R; Tue, 20 Feb 2024 12:19:20 +0000 Received: by outflank-mailman (output) from mailman id 683475.1063019; Tue, 20 Feb 2024 12:19:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rcP5j-0001my-U5; Tue, 20 Feb 2024 12:19:19 +0000 Received: by outflank-mailman (input) for mailman id 683475; Tue, 20 Feb 2024 12:19:19 +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 1rcP5i-0001mj-Vm for xen-devel@lists.xenproject.org; Tue, 20 Feb 2024 12:19:18 +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 43c8ef3f-cfea-11ee-8a52-1f161083a0e0; Tue, 20 Feb 2024 13:19:17 +0100 (CET) Received: from DS7PR05CA0022.namprd05.prod.outlook.com (2603:10b6:5:3b9::27) by BL0PR12MB4916.namprd12.prod.outlook.com (2603:10b6:208:1ce::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.20; Tue, 20 Feb 2024 12:19:13 +0000 Received: from CY4PEPF0000EDD5.namprd03.prod.outlook.com (2603:10b6:5:3b9:cafe::d1) by DS7PR05CA0022.outlook.office365.com (2603:10b6:5:3b9::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.15 via Frontend Transport; Tue, 20 Feb 2024 12:19:13 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD5.mail.protection.outlook.com (10.167.241.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Tue, 20 Feb 2024 12:19:13 +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; Tue, 20 Feb 2024 06:19:12 -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; Tue, 20 Feb 2024 06:19:12 -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; Tue, 20 Feb 2024 06:19:11 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 43c8ef3f-cfea-11ee-8a52-1f161083a0e0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0lV63jXy2bt9vgQdON2yGMcaTkCgTFgDhzL+NRNgozQvyh/vsnhHr57xwc1AdvE09XilBHieknXYSTj+FAZpHfdcWPerWlN3LeQGeK4bNd++GeJwQ4eAm78ZWlCukguqmWY0Y+rNgWJA37iFkdQ8EpWseYm0ilwmnOBZiDU8KJZpPOHZMpH59Qq36B3HRzBo9wnLCijG+UgA/lT7MVgqejK00yHcfANKRDSw0P9343UHWvWq+ZVwMrGo0laJMa9vd5UjlYWyA32QV8+AcTSSYEHTAKQ5ldAaLDC0geA3NPU9KTUxMFPKEAkHg7hOIifJ0ta1LxInR1ElODo00X3wA== 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=TyheUcKZClDVXN1YlPjAzeLmxnokNyXGDiz7llZyvHQ=; b=aUVSLx/hw8NBtHcbgMvjHzeO0ev8HOs9mDverkKEjxz58La/G95x2IbT4v6d30q7tmO/z11WcRxRUPdJtxAjpMxVKCjPlUCpI68pMvNeG0WPrHD6uVmxTcZ3sHgOfQIkwk3H436gasMEalpJvK6JyLgihW+CLm2XXqGyl3mJgTsGouuWJDXdHTW3Y8qWZiuehdZWd9tiYq2/WT+Ike1wKpZtCv2SweAXAHx/6SlyLicZpHwG5jhJYHv/wFywlOR8KH32z1SM8HYV35HWsSGJHClAFpMUbdCYwkmuLKEs1htTDBjEsYTsTEWt0bEdF6ZxbU3RfInB8o/RAK6jR9rcgg== 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=TyheUcKZClDVXN1YlPjAzeLmxnokNyXGDiz7llZyvHQ=; b=ALLVrMhhNMJfoDkrNLePd/ehOGV6H5/hD46zPfrUDkpfAfHpwlUbir2BD63eQNXZmMPo8CzIas9dvK1Y0aeliYIMQpcN/LMo7EN6azns1f5T8JFtVHnlJkV8wS6hPq69uJX064+CMFxPwbqa832lZnzSa1yUVzzQmRDwF8ChRlM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: , , , , , , Ayan Kumar Halder Subject: [XEN v5 2/3] xen/arm: arm64: Add emulation of Debug Data Transfer Registers Date: Tue, 20 Feb 2024 12:17:42 +0000 Message-ID: <20240220121743.3680715-3-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220121743.3680715-1-ayan.kumar.halder@amd.com> References: <20240220121743.3680715-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD5:EE_|BL0PR12MB4916:EE_ X-MS-Office365-Filtering-Correlation-Id: c4deb2e0-a812-42fc-e205-08dc320e266b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fgErVotxVtLU/1F9k57JNye2xARh6V9xIOKCdK0h76Uy5Rk5ZlogZ9O46ecKNY+xhC2OmLA6kEavoytjnGonYjnPA4Qh8fxfpEs/g+VGCTKxkppcrkCn57NGECnX9qPVEHL4Q5jeBLYE5y5alCozw7hccMsssk7rrLYqA7br4N0o7dlLwpU4Z7JxMeHOk92RyW0ev/3T9zn1ZRReZV/2uV1/6trR1aWpjNlWewgzI48tmCcmgDPxHpnyrvkv6n2ElrB0Q4yzyecoMtbBZkA7+2wrxj9FPshhuV8gwjDWOcHcQEmvIJ7TauPF0yPCHy0BWS2S7Ax6NdHTMgPI616ZWQrpoLAeEE4bdFUITVncMh+UOM7kR3bUWfVk6+LEbC17G/Up78/duzw1gyv31ksX27Mp6dnwzMjeObQYdiMA2Hg0b6ybHcf4DpVTZOwf/T+cV7CtwEZ1X/AbcpuGOsJyvO5PNNCbFp0uHs3/TYeEfXRYlffByJvIzadE80RDSiuRt5O0XQdYd+LR/xsBal1nVLdYpbtWII9MMbfF5+0keQqQKxbTIn07f+E7uxMv6UDK4lHEcfXSYxBpSz6Fb5gi8Hru93+/c1Bxy7ktA6zCtp/CakzbNi9vXlHoMfO4PXf/Ia/2jfrrA9F6cybK8qDUG4m1RZ/znZZlY/SuqcB9hfM= 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)(40470700004)(46966006);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2024 12:19:13.4209 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4deb2e0-a812-42fc-e205-08dc320e266b 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: CY4PEPF0000EDD5.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4916 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1708431574253100001 Content-Type: text/plain; charset="utf-8" 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 TXful= l. 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 Reviewed-by: Michal Orzel --- 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=20 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.=20 v4 :- 1. Invoked "goto fail" from "default:" to ensure compliance with MISRA 15.3. xen/arch/arm/arm64/vsysreg.c | 68 +++++++++++++++++++--------- xen/arch/arm/include/asm/arm64/hsr.h | 3 ++ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/arm64/vsysreg.c b/xen/arch/arm/arm64/vsysreg.c index b5d54c569b..80918bc799 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 =3D hsr.sysreg; int regidx =3D hsr.sysreg.reg; struct vcpu *v =3D current; =20 @@ -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 emulat= e 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 pre= vent + * injecting undefined exception. + * Accessible at EL0 only if MDSCR_EL1.TDCC is set to 0. We emulat= e 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,24 @@ void do_sysreg(struct cpu_user_regs *regs, * And all other unknown registers. */ default: - { - const struct hsr_sysreg sysreg =3D 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 ? "=3D>" : "<=3D", - 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; } =20 regs->pc +=3D 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.c= rn, + sysreg.crm, sysreg.op2, sysreg.read ? "=3D>" : "<=3D", 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; } =20 /* diff --git a/xen/arch/arm/include/asm/arm64/hsr.h b/xen/arch/arm/include/as= m/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) =20 #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) --=20 2.25.1 From nobody Sun May 12 21:26:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1708431579; cv=pass; d=zohomail.com; s=zohoarc; b=RB792JuTYNbsTUDwnDxY59UbPaFVZC2zfZw15T7/6++vFogkTCHmcbBw+Fg4hMvsfVQ/6+OD2fHL/GxTYOu+vk6TTfjXr2CuVMGw/PqjgjtvUDUwHtpeIitOGz8H9iK93XRbvgPy8ebHzhLRBhnSNuZRMBZkfCEzmmp8shQf9bg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708431579; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PhMwKyVo3kV6ClvTBpqbApB6tIudAzmtxwRqsvXdrFs=; b=jIZsqpdPCCdoXkpFJvH4LupTXrMKN7SXRyp5TWHbbT9/IQzTZE2imzNGYZFDDBaKlo8S/KAwJNds3FjTMVjTg9UjV7/aNKj+g5OZNwxYr1MzhP/eDKZvvINGTLUbaRE7+t3xjFSDw8e5QD4T009GYBrxKC/7FcUMt6hjFE3U4/g= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1708431579442107.3627293104962; Tue, 20 Feb 2024 04:19:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.683476.1063028 (Exim 4.92) (envelope-from ) id 1rcP5o-00027S-Bz; Tue, 20 Feb 2024 12:19:24 +0000 Received: by outflank-mailman (output) from mailman id 683476.1063028; Tue, 20 Feb 2024 12:19:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rcP5o-00027L-90; Tue, 20 Feb 2024 12:19:24 +0000 Received: by outflank-mailman (input) for mailman id 683476; Tue, 20 Feb 2024 12:19:22 +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 1rcP5m-0001mj-Nr for xen-devel@lists.xenproject.org; Tue, 20 Feb 2024 12:19:22 +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 468c6110-cfea-11ee-8a52-1f161083a0e0; Tue, 20 Feb 2024 13:19:22 +0100 (CET) Received: from CYZPR11CA0024.namprd11.prod.outlook.com (2603:10b6:930:8d::9) by CYYPR12MB8961.namprd12.prod.outlook.com (2603:10b6:930:bf::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.20; Tue, 20 Feb 2024 12:19:17 +0000 Received: from CY4PEPF0000EDD7.namprd03.prod.outlook.com (2603:10b6:930:8d:cafe::64) by CYZPR11CA0024.outlook.office365.com (2603:10b6:930:8d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.40 via Frontend Transport; Tue, 20 Feb 2024 12:19:17 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD7.mail.protection.outlook.com (10.167.241.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7292.25 via Frontend Transport; Tue, 20 Feb 2024 12:19:17 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 20 Feb 2024 06:19:15 -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; Tue, 20 Feb 2024 06:19:14 -0600 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 468c6110-cfea-11ee-8a52-1f161083a0e0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WSsUIBUGmcyd7LuDyoccMlqiRxnGzGDhK2hU3YOdVzJfr7TvsLcFxemCph24hJZaRDEFW638npeauQKY6esEiJ9oSwFQeTIR2g6+8GB1xBygjf0oq9J8EMYEJ3q7RaVXXO1TspQopaJYnInkJGKSa3O+bOa9zXWcqC9pGA241m5PZtEs4ebaD+VgpKGyA7dBUNOMscm3e5vcjTSyNr/LsqnwnUOe1VT5XQyItr9bd40ICufKG3Qs39dtOCTcakOlLr4594MWWNodAcM72DpnYpK+KTzPqdWQihsvLcK/32U4l487lOBde0O6w4JlEGbZVxUeR/4TyC92ZCvjnE3xtg== 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=PhMwKyVo3kV6ClvTBpqbApB6tIudAzmtxwRqsvXdrFs=; b=BaMhWqkfMNVLZVPykLAlaaubHTtmeyarrZyNFWGYqf7qLJra9VMOuZ8cxyP34TIVYJ+5KtHpki7CA9Wd72gYP+DgxrPpSaRIQw/YQmipGVcKXwo5+PM8Ty/dB+OdT/W6VyEC89xhvkyMZp6HSvSOW7vZ/TC31h8SvYOnzIBBAGhAKaB7fLSFqXjozU9d7OMOjFqB9YxGadB8stL2Mon0KnHlRMuV4Dm/MDwGyyiFG1PS5MDMOSBdBjtfks/boxk0qo37ayw35jvxG177QRCOHD1HYYse3BtXgKCmaIyq3v9L0JZdY23ikEefn0ReOW7lrExJancaS0cxeuAl4R/S9Q== 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=PhMwKyVo3kV6ClvTBpqbApB6tIudAzmtxwRqsvXdrFs=; b=B1NPj/4rKBQE0tFtJjAHtRy01GR+GmMSoHWNV2mRq2tGOh5bvoMt17iKbfOWR4cSufMvasX1SWXxPTTN/aD+OOwZ7sS7/5PIrUgDWG06jGiOPX7+8+f2Len6wtsDl3a6ivn3e+KaPuzTNPq4ErSW0D75Q8/cTxi5MfOApHe0ywg= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: , , , , , , Ayan Kumar Halder Subject: [XEN v5 3/3] xen/arm: arm32: Add emulation of Debug Data Transfer Registers Date: Tue, 20 Feb 2024 12:17:43 +0000 Message-ID: <20240220121743.3680715-4-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240220121743.3680715-1-ayan.kumar.halder@amd.com> References: <20240220121743.3680715-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD7:EE_|CYYPR12MB8961:EE_ X-MS-Office365-Filtering-Correlation-Id: 41435a71-6529-419c-ca3c-08dc320e28b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qJxf9g7TyisYRj5LmoWbUfyKbkbQz/mPtUCK72cUQ7jGlA7lbZ8dynYDp+yIp9oRYPWNLRxsmB3iNHkIGR18X1u45vD+55T3kkc2hJQhbXQzOuwBGLx9oUqKyJRgEg7tcFOTrZd6F4sW+qsiVWwDILMU47M4ANN6key9upJBbtQ24mfY/Q64T19I1nZB5p2qNZ9BN84BYiDEx7QES86hboYPmpeBBOX1/g1Guj7VpcvmxTQOWnVX6+0LbFeO3eSWkhgCIBYEcwFX9TopYc4t/paagxc+ejmsSF1yUiyPbYdbG6sMzKh8GIv7nn41Cxo9p5xYyGRreokcawyEBns/4jqdplr/gyF3pdvtnIqLzxirQg4axkvH8Dfo7pGM51hiNXmD9m1k7TYVvVMk0mUgkjSU4DGHEIg7zQ4TU9vIrtXiC7C2mz2evXa4quHWD9Gc9f/Z0HjDhFsy4kOEF5kUjtYxatHoSbGauMSQkQA3u0nQZA0I011ADtqWdrFooMIk032vYl5JJJwiXxr4Tqfq0GcHMNI3s5nJ+VVd3o2xbzDWyGa32RKYZrGHaeDxPMJaIsD2/O7xyGJfb3SRT2Nv+okf+jhuf6204V44TizGcZVEKgCdsbP3yC9kxF/HHczfQwBqrpu5iYvbNaovOqrGXTMB6/R7HwHeYKNQmAaGxPQ= 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)(230273577357003)(36860700004)(46966006)(40470700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2024 12:19:17.2738 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41435a71-6529-419c-ca3c-08dc320e28b7 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: CY4PEPF0000EDD7.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8961 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1708431580302100001 Content-Type: text/plain; charset="utf-8" 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 DBGDTRTXINT as RAZ/= WI and TXfull should be set to 1. So that Linux will see that TXfull is set, a= nd it will not thereafter access DBGDTRTXINT (it will access it at least once = to later check if TXfull is set). As a pre-requisite, DBGOSLSR should be emulated in the same way as its AArc= h64 variant (ie OSLSR_EL1). This is to ensure that DBGOSLSR.OSLK is 0, thus DBGDSCRINT.TXfull is treated as UNK/SBZP. DBGOSLSR.OSLM[1] is set to 1 to mantain consistency with OSLSR= _EL1. Only DBGDSCRINT can be emulated. DBGDSCRINT can be accessed at EL0 as DBGDS= CREXT is emulated as RAZ (as DBGOSLSR.OSLK =3D=3D 0). So, we took the opportunity= to fix the minimum EL for DBGDSCRINT.DBGDSCRINT.TXfull is set to 1. Refer ARM DDI 0487J.a ID042523, G8.3.19, DBGDTRTXint "If TXfull is set to 1, set DTRTX to UNKNOWN". So, DBGDTR[TR]XINT is emulated as RAZ/WI. Thus, any OS is expected to read DBGDSCRINT and check for TXfull before usi= ng DBGDTRTXINT. Signed-off-by: Ayan Kumar Halder Reviewed-by: Michal Orzel --- 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. xen/arch/arm/include/asm/cpregs.h | 2 + xen/arch/arm/vcpreg.c | 63 ++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/include/asm/cpregs.h b/xen/arch/arm/include/asm/c= pregs.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 Intern= al */ #define DBGDSCREXT p14,0,c0,c2,2 /* Debug Status and Control Extern= al */ +#define DBGDTRRXINT p14,0,c0,c5,0 /* Debug Data Transfer Register, R= eceive */ +#define DBGDTRTXINT p14,0,c0,c5,0 /* Debug Data Transfer Register, T= ransmit */ #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..1a2d79b818 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 uni= on 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); =20 @@ -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 uni= on hsr hsr) break; } =20 + /* + * 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 em= ulate + * 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); =20 case HSR_CPREG32(DBGDSCREXT): /* @@ -562,6 +576,18 @@ void do_cp14_32(struct cpu_user_regs *regs, const unio= n hsr hsr) */ return handle_raz_wi(regs, regidx, cp32.read, hsr, 1); =20 + /* DBGDTR[TR]XINT share the same encoding */ + case HSR_CPREG32(DBGDTRTXINT): + /* + * Emulate as RAZ/WI (only if partial emulation is enabled) to pre= vent + * injecting undefined exception. + * Accessible at EL0 only if DBGDSCREXT is set to 0. We emulate th= at + * 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,21 @@ void do_cp14_32(struct cpu_user_regs *regs, const uni= on 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; } =20 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); + return; } =20 void do_cp14_64(struct cpu_user_regs *regs, const union hsr hsr) @@ -659,10 +689,7 @@ void do_cp14_dbg(struct cpu_user_regs *regs, const uni= on 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", --=20 2.25.1