From nobody Thu Jan 30 05:58:08 2025 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=1730119619; cv=pass; d=zohomail.com; s=zohoarc; b=guBIPA6acnzwPcZiJx/uH2aCm7k/5nq1gbt91f8vspdYVLq4uKeE+5eeYM/u0uz35OErpJdVEHPLlWjdWAH8gigIlr/xp2LO3wZhJoLDdFRTx5BSZTRZmnGWuQfJeTSnK3R37rhG1X06wpWYesuWO25PML/3+f9wEtKVcbA88cY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730119619; 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=Gbtn/b9PyyI/M8LkjdkVTqNsj2orDE7jZ4wJ89CVFig=; b=RHHd1hyQVusoIwCV2++YzXAcjz8ctNMt9TRvEjCuhioK35GUeg7E8zj0nEwZYSIA2AJJnp1kjCImr+iGInnOI4t9T5mFOYl3iRyT9ekOGkKHQn7axlLaFq1I8sfdPADqX2bsgZh0PA3zLYY3m2srrSBHNZNAVsEcOU2LrM44gd4= 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 173011961909111.981568944899777; Mon, 28 Oct 2024 05:46:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.826454.1240745 (Exim 4.92) (envelope-from ) id 1t5P8q-0006Wt-2C; Mon, 28 Oct 2024 12:46:40 +0000 Received: by outflank-mailman (output) from mailman id 826454.1240745; Mon, 28 Oct 2024 12:46:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8p-0006Wi-Uo; Mon, 28 Oct 2024 12:46:39 +0000 Received: by outflank-mailman (input) for mailman id 826454; Mon, 28 Oct 2024 12:46:38 +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 1t5P8o-00050g-Mk for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 12:46:38 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20606.outbound.protection.outlook.com [2a01:111:f403:200a::606]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ab555208-952a-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 13:46:38 +0100 (CET) Received: from PH7P220CA0098.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32d::9) by DS7PR12MB8417.namprd12.prod.outlook.com (2603:10b6:8:eb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Mon, 28 Oct 2024 12:46:29 +0000 Received: from CY4PEPF0000E9CD.namprd03.prod.outlook.com (2603:10b6:510:32d:cafe::2e) by PH7P220CA0098.outlook.office365.com (2603:10b6:510:32d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.26 via Frontend Transport; Mon, 28 Oct 2024 12:46:29 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9CD.mail.protection.outlook.com (10.167.241.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Mon, 28 Oct 2024 12:46:28 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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.39; Mon, 28 Oct 2024 07:46:27 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 28 Oct 2024 07:46:27 -0500 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.39 via Frontend Transport; Mon, 28 Oct 2024 07:46:26 -0500 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ab555208-952a-11ef-a0c2-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=m3I883Oyut7aFQMbsqhpzpFIoI2GvBA+PT0q955pOKZN9OZEYV+IRo/dvPQ/0TpYDdsWDDWnMGOU/xQBWTTyDL7CT96pjHNF5YHZIb2d3IxO9QtaGcKySR3F9M199Cmn9Xrp+LqHHyu5a/z4OrhCdGzNxI8Zji8+HtqFwXwHwUVEmP/Ji1Tu4aX94s62OjaArZg9Kh+T+bAh/4wtHf0g+70gdkW/ub+opegXv5hoJ3qegPsuicfS5H+8fn8n2zjAvrsL84Bj63tEZVBkaHbS7TuhBfz9aWvgtpxYUBbO/cV8ZEfWU3NaJvztCmeOw97H13QP3gEofXrNYyUXQ4UVpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Gbtn/b9PyyI/M8LkjdkVTqNsj2orDE7jZ4wJ89CVFig=; b=eqIt/y/DM58FmHhTLH/shJ3YcB7rbOR/kEzmUCaltaSIxAvW38GypwLP+EMjc8dQr4DW6CzSOC2ah09GsWe2w/CsI75JAbJf5GY9p7jlHEXhyLijWW2n1SJM1VjTvnNIguvNJuj0jy1nyXyGPPIPrSx4McjOau4np43pmDJI4svlaqJITfPlMuMgo990EmzQduCxAY4KbwGvc/oqNY2zVD1cvAyDxjg4iMLtxTT2nacx7oDD+TmNrD9X/1ktBUBXHdK02qzaj5L7N7HSinI4xYVhMxNmHdUCSRBeE/afpAGGltBxvKnZzDcNl6D+c4a0Txh3WRzIkEXdYo3tP2tSiw== 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=Gbtn/b9PyyI/M8LkjdkVTqNsj2orDE7jZ4wJ89CVFig=; b=nR+NzA3XLeMIo8kSSZIWwIYs/MksP4PtL9jK1Da+TKc3dEakVkaJrsQwxBsgdBCWzAEt+EMFIM0rD535iOgLSjt+5dd+SPRCOcsmIJC8zmkVSyPYBgB5gkxmG5ff2U9IkJq2rhcWWj4xGwcbSoSWQnWOM8TRU2DxQ8bQZHU6sIo= 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 , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" Subject: [PATCH v4 5/6] xen/arm: mpu: Enable MPU Date: Mon, 28 Oct 2024 12:45:46 +0000 Message-ID: <20241028124547.1371867-6-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241028124547.1371867-1-ayan.kumar.halder@amd.com> References: <20241028124547.1371867-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: CY4PEPF0000E9CD:EE_|DS7PR12MB8417:EE_ X-MS-Office365-Filtering-Correlation-Id: a973a085-f70c-45d5-4065-08dcf74e8ae4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?7bKTzqvEBYthZpBLNCfgPh0lcQ2qoMSh+ev3T8WNJXv3OZjfyTbadUSQ0B9l?= =?us-ascii?Q?U2jLqbLtCnt9jsKJ/X8FXmMkdyu+zF6ywpnVZdsJQ5HmWiKXGMUpbgOlnMJj?= =?us-ascii?Q?tJolUWxpHSx5fxSn+XuvDGGgjTPw/COh0FJDOlcLcWRM/CQV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DUXQzeYx36Hne9ETbgqGKylF2ui3HEj8pIFgXUzjzFmq?= =?us-ascii?Q?k5Jmt1Rlr2LDYzuRIFXc0xD72bd9Lai/C2LpgXgunNWuaQaxcMqh5QV1/sj4?= =?us-ascii?Q?Tu39Y3U150KquOeihxTq2w/v+iAaimJw2YYAsRBDZtd1RmtZ1KQh5ZIpmks2?= =?us-ascii?Q?N4k2uOtkZyo7XmRPajXM5lXbmybFkYaEunPElMBM+qifrke2Uc3zdqQUlf1/?= =?us-ascii?Q?kBBUrnilt9XnuHfhOKW504cAAmSursMP9rnFO2xI8q57ohjFLzzwSMFgtm6o?= =?us-ascii?Q?tiuK/0e+N1uU7EDLiHszoVOOsIKpOAxMUIbXnTRjM59m2x2GMAEAcUaA9+9t?= =?us-ascii?Q?9qOs/kVprb1n5hkKPzaUvfLUzae52pIyiQ+RXWd1AWuE2QXY7Q=3D=3D?= 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:(13230040)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 12:46:28.7929 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a973a085-f70c-45d5-4065-08dcf74e8ae4 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: CY4PEPF0000E9CD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8417 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1730119620151116600 Content-Type: text/plain; charset="utf-8" After the regions have been created, now we enable the MPU. For this we dis= able the background region so that the new memory map created for the regions ta= ke effect. Also, we treat all RW regions as non executable and the data cache = is enabled. As enable_mpu() is invoked from enable_boot_cpu_mm(), one needs to save and restore the lr. Signed-off-by: Ayan Kumar Halder Acked-by: Julien Grall Reviewed-by: Luca Fancellu --- Changes from :- v2 - 1. Extracted from the previous patch into a new one. 2. Disabled background region. v3 - 1. Removed dsb before setting SCTLR_EL2. The reason being From ARM DDI 0487K.a D23-7349: "Direct writes to these registers (includes SCTLR_EL2) are not allowed to a= ffect any instructions appearing in program order before the direct write." So, we don't need a synchronization barrier before writing to SCTLR_EL2. Further, we do have synchronization barriers after writing the MPU region registers (which happens before we read SCTLR_EL2). So, SCTLR_EL2 is written after the MPU registers are synchronized. And, thus adding a 'isb' to flush= the instruction pipeline ensures that the subsequent instructions are fetched a= fter the MPU has been enabled. 2. Saved and restored lr in enable_boot_cpu_mm(). xen/arch/arm/arm64/mpu/head.S | 30 ++++++++++++++++++-- xen/arch/arm/include/asm/arm64/mpu/sysregs.h | 3 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S index 9377ae778c..0edadb009c 100644 --- a/xen/arch/arm/arm64/mpu/head.S +++ b/xen/arch/arm/arm64/mpu/head.S @@ -68,6 +68,29 @@ FUNC_LOCAL(fail_insufficient_regions) b 1b END(fail_insufficient_regions) =20 +/* + * Enable EL2 MPU and data cache + * If the Background region is enabled, then the MPU uses the default memo= ry + * map as the Background region for generating the memory + * attributes when MPU is disabled. + * Since the default memory map of the Armv8-R AArch64 architecture is + * IMPLEMENTATION DEFINED, we intend to turn off the Background region her= e. + * + * Clobbers x0 + * + */ +FUNC_LOCAL(enable_mpu) + mrs x0, SCTLR_EL2 + bic x0, x0, #SCTLR_ELx_BR /* Disable Background region */ + orr x0, x0, #SCTLR_Axx_ELx_M /* Enable MPU */ + orr x0, x0, #SCTLR_Axx_ELx_C /* Enable D-cache */ + orr x0, x0, #SCTLR_Axx_ELx_WXN /* Enable WXN */ + msr SCTLR_EL2, x0 + isb + + ret +END(enable_mpu) + /* * Maps the various sections of Xen (described in xen.lds.S) as different = MPU * regions. @@ -75,10 +98,11 @@ END(fail_insufficient_regions) * Inputs: * lr : Address to return to. * - * Clobbers x0 - x5 + * Clobbers x0 - x6 * */ FUNC(enable_boot_cpu_mm) + mov x6, lr =20 /* Get the number of regions specified in MPUIR_EL2 */ mrs x5, MPUIR_EL2 @@ -110,8 +134,10 @@ FUNC(enable_boot_cpu_mm) ldr x2, =3D__bss_end prepare_xen_region x0, x1, x2, x3, x4, x5 =20 - ret + bl enable_mpu =20 + mov lr, x6 + ret END(enable_boot_cpu_mm) =20 /* diff --git a/xen/arch/arm/include/asm/arm64/mpu/sysregs.h b/xen/arch/arm/in= clude/asm/arm64/mpu/sysregs.h index b0c31a58ec..3769d23c80 100644 --- a/xen/arch/arm/include/asm/arm64/mpu/sysregs.h +++ b/xen/arch/arm/include/asm/arm64/mpu/sysregs.h @@ -15,6 +15,9 @@ /* MPU Protection Region Selection Register encode */ #define PRSELR_EL2 S3_4_C6_C2_1 =20 +/* Backgroud region enable/disable */ +#define SCTLR_ELx_BR BIT(17, UL) + #endif /* __ASM_ARM_ARM64_MPU_SYSREGS_H */ =20 /* --=20 2.25.1