From patchwork Mon Nov 18 12:12:48 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: 13878466 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 C058ED4920F for ; Mon, 18 Nov 2024 12:13:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.839316.1255125 (Exim 4.92) (envelope-from ) id 1tD0dD-0006oB-8Q; Mon, 18 Nov 2024 12:13:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 839316.1255125; Mon, 18 Nov 2024 12:13:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tD0dD-0006o4-5V; Mon, 18 Nov 2024 12:13:27 +0000 Received: by outflank-mailman (input) for mailman id 839316; Mon, 18 Nov 2024 12:13:25 +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 1tD0dB-0006nk-Lp for xen-devel@lists.xenproject.org; Mon, 18 Nov 2024 12:13:25 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20608.outbound.protection.outlook.com [2a01:111:f403:2412::608]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7f60e820-a5a6-11ef-a0c8-8be0dac302b0; Mon, 18 Nov 2024 13:13:21 +0100 (CET) Received: from DM6PR11CA0030.namprd11.prod.outlook.com (2603:10b6:5:190::43) by CH2PR12MB4040.namprd12.prod.outlook.com (2603:10b6:610:ac::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22; Mon, 18 Nov 2024 12:13:13 +0000 Received: from DS2PEPF00003442.namprd04.prod.outlook.com (2603:10b6:5:190:cafe::31) by DM6PR11CA0030.outlook.office365.com (2603:10b6:5:190::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22 via Frontend Transport; Mon, 18 Nov 2024 12:13:13 +0000 Received: from SATLEXMB04.amd.com (165.204.84.12) by DS2PEPF00003442.mail.protection.outlook.com (10.167.17.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Mon, 18 Nov 2024 12:13: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.39; Mon, 18 Nov 2024 06:13:13 -0600 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB05.amd.com (10.181.40.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 18 Nov 2024 06:13:12 -0600 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Mon, 18 Nov 2024 06:13:11 -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: 7f60e820-a5a6-11ef-a0c8-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDE6MTExOmY0MDM6MjQxMjo6NjA4IiwiaGVsbyI6Ik5BTTEwLU1XMi1vYmUub3V0Ym91bmQucHJvdGVjdGlvbi5vdXRsb29rLmNvbSJ9 X-Custom-Transaction: eyJpZCI6IjdmNjBlODIwLWE1YTYtMTFlZi1hMGM4LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxOTMyMDAxLjk3ODU4Miwic2VuZGVyIjoiYXlhbi5rdW1hci5oYWxkZXJAYW1kLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A+ZFcb8EImFu1nT3r+PRJ6dv83MkvZzaQ8OzDy3Nbq8b5lammoYqHivAYpq6W3ai3nssUZdBrSozwnLpaY6z+OeSB7/XZkKd1KQCeEjrSrUaiVbCQjV62BUX59VUaC7KPEp4cnBpTXIUryeY/aBjaEC++c3hFa1AFmCMrZ3xm9sW+ZlUrI2hCbwet4kAKB1bBJ7qE91fRbGxshvcy9KgM71vQ9m4n6p4xQWc6ey7aXsWLKOVX1hhqwM3fz1PO43wyxDg6DwXQDO9ziQSd5k4VuSrn74sKeKsBOOp2i9CcVKF45R+9E0fbPwa+R39mgFAV7nR4QYyAr4gg6kxuPJFzA== 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=5uRGvx+KoW4EOPw2mfGTehds5bl03kdfygMMa3gQhYM=; b=ic5ksn5Cjz7l3nbsnwY8kHnMZ6nqJde1AzUoqLRzcIMVHsT6cVi57uZQZnEscv9fQIGrnIVnkO6aK7PRR9Nd+FGWvLdgf8rSOvFIqvnf0m6sFCSsoGsloSgI5EVVJPkQ5G8UDoeMtaaGctsqDiggoiS5kjrHuA6NmMnFJZ+4WKVZBO9JPp55GAtAm94YdGrKz0VmYk0/z6JKhhi/RVGk4vqUPkvqBgaNNfivBtCEBz0A4ic1GnYWcr9maogHmo2eSZOP8ttW6W47U1W2r++pc2TZ6RyDfD9osXZeOhkr9IGvli4VbNwV2SRYGEVZxPSFf3MG4xFZUtM6V8t5UQh3Tw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 165.204.84.12) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine 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=5uRGvx+KoW4EOPw2mfGTehds5bl03kdfygMMa3gQhYM=; b=s4jJMfad+crOpQMjAcNepMw4N18/fxFNZmFf97rsePme1nGBiASDDI0tttgZ86MpJL8y7+l0LKNrx0YUqJm+Fh/UJ+U/LzGv80Ikr3zg56W3icOFr+62heA25Dc8b1NMgsmrCctqeaQZrgMM1wk4GuUgRNB5gcNQ/aTOBGj8YK8= X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 165.204.84.12) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning amd.com discourages use of 165.204.84.12 as permitted sender) From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Luca Fancellu Subject: [PATCH v6 1/3] xen/arm: mpu: Create boot-time MPU protection regions Date: Mon, 18 Nov 2024 12:12:48 +0000 Message-ID: <20241118121250.4027441-2-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241118121250.4027441-1-ayan.kumar.halder@amd.com> References: <20241118121250.4027441-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: DS2PEPF00003442:EE_|CH2PR12MB4040:EE_ X-MS-Office365-Filtering-Correlation-Id: 25256eba-ac25-4d15-c3e0-08dd07ca6020 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: dQl5hbi1PjzcmmLbc0UUGP3ex50sOvZM+s/gl/gBltzf2G8DRrnbNo9OCRbDS0m4u8cbJCoFjF+ryZWtv8q5oLXsFIijKJ1xbS2axSJuCkvr1ovAvQ2IpOwhrNlSxT4BD3SNUJlDOWU2wXBQw/pB37GeS+KhM1VVYsdKiqbAKbVo8gZKU+OuS23SF98y6ggcVEUVXZjjUQZzEVvDAcbME3gUhruz1eaR+Tm8QYgFsDD5IjEw8xP8NdG2MAUPQsoUmFTn8PdsQyRpeaWHl+c881KGiunnUq7TsjYNt9BDOT9LcNgfQOBz3SfLsOSi0QZ4fCwf0cj3BLqovx0+hwOINimCpBIGi80/zdgacAvD9voCHkSMbi6rHmcrdS+ASmPcLqtFdQm+N7umz4LY1UWi1moAydpBGDpr+NavxQtPrV56mdcTwD4C6Wf/+MNh/cXoLHxu7Z9TQSym0ldkB3tgxzZ1S+qLlhQYc59lgBj26gGgNRiNJc4ZI+8klfjiJeEPcIr05JV8hlKOi9H5K+0JN6IFeO33gqngOg+AFgPABPYPmgCqEqWHzPkEtOtZ58S3dVpa2gqiGBQZKeWLWMDLycwYg+DnjWOfhI4k0U53K4vqzJIfH5urV5Z4PovBlWNFSLyENcTGqZQDl+xmJhXSVvISPbqc3hElXesBNkOaeAlQe4zq8tPq5TQIjlKKWF5xE8aefcMxSRr/S/NL+v+aWCTk4VkP227CkJy+C5Pf7T5SG0IVwsGy5PmtCRlPigqD4MJKx33WFpx2atjCFtbY79Oes40uJHCp2iy4eQqJ/DKnaPL6WOuRBpH7sgKGXpy7w5rkQWB3t/QkuvTl75lC7h3+e1mJ8/U/DocCsVQjDTclWWDl/BfLMq4Ol/Xz8X8iNarn4UV7dsV719mF343GKq5pXbUNrxm7/gP0IpgyaBiz/ZSoDQI5X4usNWBPj4jCH/gp/fSymZ7fDDpFcMUL7Y+JdIylWmIlvLTQMZDcHKbdBMBKFdgqiSoDVZAp3zfLgr+BIi+1hz+ELP1G6DoSfzLrbot36LOVWHINkvqIBTmzVh4cMyPUYm6LfAPVv5n4GoGx3p8W3qsx/2HDJT55uc9uCttqPufyBwtThftvSU1I9jrVtvwjOn8XgJJnQjPaB34dyg8WcFWgaawyL5CvcB1KiKrYCYDgUM9uA+LhwOdqcIbTj/ONqbYy6g6GKhYZeo3VlhbgAU+4fKu+1hUR7a/9PrZ0S09OvFdOCw5wF+CzFOv134weq6LwdL09BXHWYcUJZLEhlcFHets4L31SCIyHrRiFXxkEF4B9blqtQVaDiVxwgRVqc9d91EFcF43YhdxfzS11i9XA8LZbC0dFi8Bk5i17xDXZLzpBpz2V2UymEecNnA3WzcZFINlnnsqWZxLTpC3RZvD5mYDXAAbjqQ== X-Forefront-Antispam-Report: CIP:165.204.84.12;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:atlvpn-bp.amd.com;CAT:NONE;SFS:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2024 12:13:13.2932 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25256eba-ac25-4d15-c3e0-08dd07ca6020 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.12];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003442.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4040 Define enable_boot_cpu_mm() for the Armv8-R AArch64. Like boot-time page table in MMU system, we need a boot-time MPU protection region configuration in MPU system so Xen can fetch code and data from normal memory. To do this, Xen maps the following sections of the binary as separate regions (with permissions) :- 1. Text (Read only at EL2, execution is permitted) 2. RO data (Read only at EL2) 3. RO after init data and RW data (Read/Write at EL2) 4. Init Text (Read only at EL2, execution is permitted) 5. Init data and BSS (Read/Write at EL2) Before creating a region, we check if the count exceeds the number defined in MPUIR_EL2. If so, then the boot fails. Also we check if the region is empty or not. IOW, if the start and end address are same, we skip mapping the region. To map a region, Xen uses the PRBAR_EL2, PRLAR_EL2 and PRSELR_EL2 registers. One can refer to ARM DDI 0600B.a ID062922 G1.3 "General System Control Registers", to get the definitions of these registers. Also, refer to G1.2 "Accessing MPU memory region registers", the following ``` The MPU provides two register interfaces to program the MPU regions: - Access to any of the MPU regions via PRSELR_ELx, PRBAR_ELx, and PRLAR_ELx. ``` We use the above mechanism to create the MPU memory regions. Also, the compiler needs the flag ("-march=armv8-r") in order to build Xen for Armv8-R AArch64 MPU based systems. There will be no need for us to explicitly define MPU specific registers. Signed-off-by: Ayan Kumar Halder Reviewed-by: Luca Fancellu --- Changes from :- v1 - 1. Fix some of the coding style issues. 2. Reword the help message. 3. Updat the commit message. v2 - Add clarification for the use of page and page size. v3 - 1. Add a new file arm64/mpu/mm.c to contain the build assertion for page size. 2. Enclosed the check for the start address within "#ifdef CONFIG_MPU". v4 - 1. Increment the region selector in prepare_xen_region 2. Ensure that the first 8 bits of MPUIR_EL2 are read, to determine the maximum number of supported regions. 3. Remove the inclusion of mm.h. *MPU_REGION* macros have been moved from mm.h to mpu.h. The reason being mm.h cannot be included in an assembly file. 4. Add the build flags for "Armv8-R AArch64 MPU". As a result, we don't need to define MPU registers. So, removed xen/arch/arm/include/asm/arm64/mpu/sysregs.h. v5 - 1. Modified the description of prepare_xen_region (added parameter details which are clobbered and preserved, base address need not be page-aligned). 2. Modified description of enable_boot_cpu_mm (removed 'Inputs' as lr is no longer preserved). xen/arch/arm/arch.mk | 4 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 123 +++++++++++++++++++++++++++ xen/arch/arm/include/asm/arm64/mpu.h | 25 ++++++ xen/arch/arm/include/asm/mm.h | 2 +- xen/arch/arm/xen.lds.S | 1 + 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/arm64/mpu/head.S create mode 100644 xen/arch/arm/include/asm/arm64/mpu.h diff --git a/xen/arch/arm/arch.mk b/xen/arch/arm/arch.mk index 022dcda192..9c4bedfb3b 100644 --- a/xen/arch/arm/arch.mk +++ b/xen/arch/arm/arch.mk @@ -9,7 +9,11 @@ CFLAGS-$(CONFIG_ARM_32) += -msoft-float CFLAGS-$(CONFIG_ARM_32) += -mcpu=cortex-a15 CFLAGS-$(CONFIG_ARM_32) += -mno-unaligned-access +ifeq ($(CONFIG_MPU),y) +CFLAGS-$(CONFIG_ARM_64) += -march=armv8-r +else CFLAGS-$(CONFIG_ARM_64) += -mcpu=generic +endif CFLAGS-$(CONFIG_ARM_64) += -mgeneral-regs-only # No fp registers etc $(call cc-option-add,CFLAGS-$(CONFIG_ARM_64),CC,-mno-outline-atomics) diff --git a/xen/arch/arm/arm64/mpu/Makefile b/xen/arch/arm/arm64/mpu/Makefile index b18cec4836..a8a750a3d0 100644 --- a/xen/arch/arm/arm64/mpu/Makefile +++ b/xen/arch/arm/arm64/mpu/Makefile @@ -1 +1,2 @@ +obj-y += head.o obj-y += mm.o diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S new file mode 100644 index 0000000000..1ab65e8ebb --- /dev/null +++ b/xen/arch/arm/arm64/mpu/head.S @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include + +#define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ +#define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ +#define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ + +#define REGION_NORMAL_PRLAR 0x0f /* NS=0 ATTR=111 EN=1 */ + +/* + * Macro to prepare and set a EL2 MPU memory region. + * We will also create an according MPU memory region entry, which + * is a structure of pr_t, in table \prmap. + * + * sel: region selector + * base: reg storing base address + * limit: reg storing limit address + * prbar: store computed PRBAR_EL2 value + * prlar: store computed PRLAR_EL2 value + * maxcount: maximum number of EL2 regions supported + * attr_prbar: PRBAR_EL2-related memory attributes. If not specified it will be + * REGION_DATA_PRBAR + * attr_prlar: PRLAR_EL2-related memory attributes. If not specified it will be + * REGION_NORMAL_PRLAR + * + * Preserves \maxcount + * Clobbers \sel, \base, \limit, \prbar, \prlar + * + * Note that all parameters using registers should be distinct. + */ +.macro prepare_xen_region, sel, base, limit, prbar, prlar, maxcount, attr_prbar=REGION_DATA_PRBAR, attr_prlar=REGION_NORMAL_PRLAR + /* Check if the region is empty */ + cmp \base, \limit + beq 1f + + /* Check if the number of regions exceeded the count specified in MPUIR_EL2 */ + cmp \sel, \maxcount + bge fail_insufficient_regions + + /* Prepare value for PRBAR_EL2 reg and preserve it in \prbar.*/ + and \base, \base, #MPU_REGION_MASK + mov \prbar, #\attr_prbar + orr \prbar, \prbar, \base + + /* Limit address should be inclusive */ + sub \limit, \limit, #1 + and \limit, \limit, #MPU_REGION_MASK + mov \prlar, #\attr_prlar + orr \prlar, \prlar, \limit + + msr PRSELR_EL2, \sel + isb + msr PRBAR_EL2, \prbar + msr PRLAR_EL2, \prlar + dsb sy + isb + + add \sel, \sel, #1 + +1: +.endm + +/* + * Failure caused due to insufficient MPU regions. + */ +FUNC_LOCAL(fail_insufficient_regions) + PRINT("- Selected MPU region is above the implemented number in MPUIR_EL2 -\r\n") +1: wfe + b 1b +END(fail_insufficient_regions) + +/* + * Maps the various sections of Xen (described in xen.lds.S) as different MPU + * regions. + * + * Clobbers x0 - x5 + * + */ +FUNC(enable_boot_cpu_mm) + /* Get the number of regions specified in MPUIR_EL2 */ + mrs x5, MPUIR_EL2 + and x5, x5, #NUM_MPU_REGIONS_MASK + + /* x0: region sel */ + mov x0, xzr + /* Xen text section. */ + ldr x1, =_stext + ldr x2, =_etext + prepare_xen_region x0, x1, x2, x3, x4, x5, attr_prbar=REGION_TEXT_PRBAR + + /* Xen read-only data section. */ + ldr x1, =_srodata + ldr x2, =_erodata + prepare_xen_region x0, x1, x2, x3, x4, x5, attr_prbar=REGION_RO_PRBAR + + /* Xen read-only after init and data section. (RW data) */ + ldr x1, =__ro_after_init_start + ldr x2, =__init_begin + prepare_xen_region x0, x1, x2, x3, x4, x5 + + /* Xen code section. */ + ldr x1, =__init_begin + ldr x2, =__init_data_begin + prepare_xen_region x0, x1, x2, x3, x4, x5, attr_prbar=REGION_TEXT_PRBAR + + /* Xen data and BSS section. */ + ldr x1, =__init_data_begin + ldr x2, =__bss_end + prepare_xen_region x0, x1, x2, x3, x4, x5 + + ret +END(enable_boot_cpu_mm) + +/* + * Local variables: + * mode: ASM + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/arm64/mpu.h b/xen/arch/arm/include/asm/arm64/mpu.h new file mode 100644 index 0000000000..f8a029f1a1 --- /dev/null +++ b/xen/arch/arm/include/asm/arm64/mpu.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * mpu.h: Arm Memory Protection Unit definitions. + */ + +#ifndef __ARM64_MPU_H__ +#define __ARM64_MPU_H__ + +#define MPU_REGION_SHIFT 6 +#define MPU_REGION_ALIGN (_AC(1, UL) << MPU_REGION_SHIFT) +#define MPU_REGION_MASK (~(MPU_REGION_ALIGN - 1)) + +#define NUM_MPU_REGIONS_SHIFT 8 +#define NUM_MPU_REGIONS (_AC(1, UL) << NUM_MPU_REGIONS_SHIFT) +#define NUM_MPU_REGIONS_MASK (NUM_MPU_REGIONS - 1) +#endif /* __ARM64_MPU_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h index 5abd4b0d1c..59b774b7b8 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -16,7 +16,7 @@ #if defined(CONFIG_MMU) # include -#else +#elif !defined(CONFIG_MPU) # error "Unknown memory management layout" #endif diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index d1e579e8a8..bbccff1a03 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -147,6 +147,7 @@ SECTIONS *(.altinstr_replacement) } :text . = ALIGN(PAGE_SIZE); + __init_data_begin = .; .init.data : { *(.init.rodata) *(.init.rodata.*) From patchwork Mon Nov 18 12:12:49 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: 13878467 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 81B2BD4920F for ; Mon, 18 Nov 2024 12:13:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.839317.1255135 (Exim 4.92) (envelope-from ) id 1tD0dJ-00078t-F9; Mon, 18 Nov 2024 12:13:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 839317.1255135; Mon, 18 Nov 2024 12:13:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tD0dJ-00078k-CY; Mon, 18 Nov 2024 12:13:33 +0000 Received: by outflank-mailman (input) for mailman id 839317; Mon, 18 Nov 2024 12:13:32 +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 1tD0dH-0006nk-Up for xen-devel@lists.xenproject.org; Mon, 18 Nov 2024 12:13:31 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062f.outbound.protection.outlook.com [2a01:111:f403:2417::62f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 849eef51-a5a6-11ef-a0c8-8be0dac302b0; Mon, 18 Nov 2024 13:13:29 +0100 (CET) Received: from DS7PR03CA0053.namprd03.prod.outlook.com (2603:10b6:5:3b5::28) by CY8PR12MB7587.namprd12.prod.outlook.com (2603:10b6:930:9a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22; Mon, 18 Nov 2024 12:13:25 +0000 Received: from DS2PEPF00003447.namprd04.prod.outlook.com (2603:10b6:5:3b5:cafe::c5) by DS7PR03CA0053.outlook.office365.com (2603:10b6:5:3b5::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.20 via Frontend Transport; Mon, 18 Nov 2024 12:13:25 +0000 Received: from SATLEXMB04.amd.com (165.204.84.12) by DS2PEPF00003447.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Mon, 18 Nov 2024 12:13:24 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 18 Nov 2024 06:13:23 -0600 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Mon, 18 Nov 2024 06:13:22 -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: 849eef51-a5a6-11ef-a0c8-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDE6MTExOmY0MDM6MjQxNzo6NjJmIiwiaGVsbyI6Ik5BTTEyLURNNi1vYmUub3V0Ym91bmQucHJvdGVjdGlvbi5vdXRsb29rLmNvbSJ9 X-Custom-Transaction: eyJpZCI6Ijg0OWVlZjUxLWE1YTYtMTFlZi1hMGM4LThiZTBkYWMzMDJiMCIsInRzIjoxNzMxOTMyMDA5LjIzNDYzNiwic2VuZGVyIjoiYXlhbi5rdW1hci5oYWxkZXJAYW1kLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HgIxYZ6oW2R1GmwX5wGwcEC2QZh+wm1f/tB/SQKUXBavUfmYLGh1WlfHQXnekzK9dHJdj23/E9BtNdHPzW0b4q9TF9YXH/xRf5OTEC/irkYvmIvbjt0GXcXDO66CjrHHSKgPXeedlqEMkfknewKwRCKipF9Mu3sngygtec3iXfL0eIMPwiZSHoTSeF0VzatHX5kktoZFCdNmcByO0iVm9cla4zN6vk9nHsjhsYQTX6bjJ3O56FqMp3wPeWpztgeR34bN28MXwMRHh3Am6kLyyPIYVEcNeEorSIFWwBYsmVofvack2xEpKC6u4KMJwF60Qm1G9TZ4UKs/nwB8YeD70g== 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=Pf5rKI3RCPGFn3GWmPsWPEZ7LwVUj9QdIKHlVuEvfDQ=; b=w4Dx2mclJNo77LhujtR/xrj6pikK3NtMMFm+0mEAMf+u6t3UuEroOYAtxUuGqbIfPk5SCU8iH553UJP+MIm1gaf6p599/I0wAG14+lXC1okzoatjByGk/6NOrNAspQz9Ysid4+ed5v3yhXFav4Z067EUSPcVs1nxxCYgw2Nmh5NnCWiITACAbah+0R1n/5+YMmN7WPBdFUxnlxTM7LaNSHPyke37FFVZLmveybQAOKnWhLkB0wXUCNDNyn7fncEf9w5oqppQ8C35wr2REPm1Kzd6S2VfGeEes/5dpepzWZmhB0JMAYye2mmzsA9yDVpK7sXIWdlm2sOotfB/nJ1EWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 165.204.84.12) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine 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=Pf5rKI3RCPGFn3GWmPsWPEZ7LwVUj9QdIKHlVuEvfDQ=; b=bGuwEd6N0+Fw1lt88r6XI2et6BuWcXmbbFLq1T9Ag6eMDa3UHWS/iuBaHgqG/FijLinVm4KC0RkZYPtQimg63ixlvEtvLv9wXXXXQup42cymtmNxT2hHi9/3xGyulJnMDbC0r1By5vIMwN6954Nh4LavAtEJZH7R8SkjG5ljbHE= X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 165.204.84.12) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning amd.com discourages use of 165.204.84.12 as permitted sender) From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Luca Fancellu , Julien Grall Subject: [PATCH v6 2/3] xen/arm: mpu: Enable MPU Date: Mon, 18 Nov 2024 12:12:49 +0000 Message-ID: <20241118121250.4027441-3-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241118121250.4027441-1-ayan.kumar.halder@amd.com> References: <20241118121250.4027441-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB04.amd.com: ayan.kumar.halder@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00003447:EE_|CY8PR12MB7587:EE_ X-MS-Office365-Filtering-Correlation-Id: b9b904da-e4f7-4005-4c43-08dd07ca66d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: siOztfXVwhd2dAmEfNf19u0hWVCeQI0O3dB2g7a4pmdfKka5qPaYXj7m688V+YlsSFuzHpnrrX4xfDrr8V+HGTle+o+CVHWeMJJ/a6BJvgUQ4fQE48uq78sAghdDtiyHK3KCXWkwFSAACLjwyR4VxXF70jgropeEfJD0r7CE20Hcch3NnNrIXMCLEfx8M1c+1NpLPqqvoTaucdKBwq74ibhD/Xz1HTeq2UC++qQNRn/O2X++fDM9Q5w8JElfG9tjQZmfY33XLNYN/Kh7ZwbbSmlID6gRajqRbeMH2PV17Lk7o51jcAdXQMhUgh5weyeOtXW5j6GuCJ7prbgrTD+kFINvLUL9XzonPi5OLMImQtHCyMdLtt+kdV5pVvaoMKUumChrcGQClvrsk/zYnhl2T3da7PJMeut24xP1XBGJAQPs79nQxonqPNR/v2ornwHNxDcvPdAsvsi87U8aONVV+fH0I0KCN1Dn20UC7hmchOia6gj9O0XChKfgS2ijaRbJSYvYsE9798o9IbrruNuQ7nw6yWXuYkRsFJuOLoCDsse9jZjBwP7Rxkcx6dPegxrzxFVzIdheRZIlgj4J6JIiwrRq7vaSaI/glE41YjFBhAl3h7VTfyQqKtLdYpIg9eAUmXzjTsk61py9LOm45hNXPvZ/un8Gvv3wQB6lIFh3qyYCE2PlzsmWMQemBWpl+F+UYXeZBpnwFW6uQcZwIVbkg3c3S/x0qn9p5fpraXJfzOvK6gi4QbkqNn/PkjGEL21YihiAwSGW04CqHpWpM4fCNcTI7q1y+qE0YFWH7nOYLcpW1xgGrt11E1SRhvR46x3OGmmUsE7F4G03II9KvVJZB9B+WvsOAiDh99lJ4kENCsL65WHhTSB0DgnW97bV2gH5xYv+dZOaqHSHI3D2CXKxPUiM7ZM1Lq1zIL69+4PoP9VVmgCBn3TaLl9RweicIulzdfOYgWsYg59upwjR/zA6hjIgO97TtACwEiIyyZ+GPl0pCBZox0wKgYFqzvhAqQHH689DlbkHg31GBwsOjY6wfoDxgVcyBzVzN9S9dJRT+QYSeqA/zolDrH+I/ZURPFZxiYb2rdRW0akHrcSWU1kO79HRxwnA9bA0CVAHx4GNplzG8gqHgDxozoFncrEJrMMrNta7X8BaC4U+mxczIBHq0cL5L2n1JX3PkUz/QKuL80GQwwvL0nhTi84dn+InhrynS0LuN8K/1mFCVF5eGFV0sjNd0Q9xSyLZdLJMjdf5aXk39bz7tH40iAJUXGTiIex+ZbGZW9KZ4zuhzwe8g6sc2gBL9PaxObUodhcatbS0GDHE9eI38zVPeVPw1YBg+A4pJSvAOIsH8UuzBS8DdMdVP3JwYzrmGS43PqFDvvrtZXm8oXaRVpyuOOtZLHLVD+F3GbSVU1/W8lDHkOKVsqavBQ== X-Forefront-Antispam-Report: CIP:165.204.84.12;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:atlvpn-bp.amd.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2024 12:13:24.5387 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9b904da-e4f7-4005-4c43-08dd07ca66d2 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.12];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS2PEPF00003447.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7587 After the regions have been created, now we enable the MPU. For this we disable the background region so that the new memory map created for the regions take effect. Also, we treat all RW regions as non executable and the data cache is enabled. Signed-off-by: Ayan Kumar Halder Reviewed-by: Luca Fancellu Acked-by: Julien Grall --- 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 affect 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 after the MPU has been enabled. 2. Saved and restored lr in enable_boot_cpu_mm(). v4 - 1. Moved the definition of SCTLR_ELx_BR from sysregs.h from head.S. The reason being sysregs.h does not exist any longer (refer to previous patch for details) and SCTLR_ELx_BR is used in head.S only. (I have preserved the R-b abd A-b, let me know if that is ok). v5 - 1. No changes. xen/arch/arm/arm64/mpu/head.S | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S index 1ab65e8ebb..c56c693cc2 100644 --- a/xen/arch/arm/arm64/mpu/head.S +++ b/xen/arch/arm/arm64/mpu/head.S @@ -5,6 +5,9 @@ #include +/* Backgroud region enable/disable */ +#define SCTLR_ELx_BR BIT(17, UL) + #define REGION_TEXT_PRBAR 0x38 /* SH=11 AP=10 XN=00 */ #define REGION_RO_PRBAR 0x3A /* SH=11 AP=10 XN=10 */ #define REGION_DATA_PRBAR 0x32 /* SH=11 AP=00 XN=10 */ @@ -73,6 +76,29 @@ FUNC_LOCAL(fail_insufficient_regions) b 1b END(fail_insufficient_regions) +/* + * Enable EL2 MPU and data cache + * If the Background region is enabled, then the MPU uses the default memory + * 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 here. + * + * 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. @@ -112,6 +138,7 @@ FUNC(enable_boot_cpu_mm) ldr x2, =__bss_end prepare_xen_region x0, x1, x2, x3, x4, x5 + b enable_mpu ret END(enable_boot_cpu_mm) From patchwork Mon Nov 18 12:12:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13878468 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 567D3D49211 for ; Mon, 18 Nov 2024 12:13:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.839321.1255146 (Exim 4.92) (envelope-from ) id 1tD0dV-0007cO-Ud; Mon, 18 Nov 2024 12:13:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 839321.1255146; Mon, 18 Nov 2024 12:13:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tD0dV-0007cH-Q5; Mon, 18 Nov 2024 12:13:45 +0000 Received: by outflank-mailman (input) for mailman id 839321; Mon, 18 Nov 2024 12:13:45 +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 1tD0dV-0007aK-3W for xen-devel@lists.xenproject.org; Mon, 18 Nov 2024 12:13:45 +0000 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20625.outbound.protection.outlook.com [2a01:111:f403:2412::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8b1e5498-a5a6-11ef-99a3-01e77a169b0f; Mon, 18 Nov 2024 13:13:41 +0100 (CET) Received: from BN9PR03CA0251.namprd03.prod.outlook.com (2603:10b6:408:ff::16) by SA1PR12MB7104.namprd12.prod.outlook.com (2603:10b6:806:29e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.23; Mon, 18 Nov 2024 12:13:34 +0000 Received: from BL6PEPF0002256E.namprd02.prod.outlook.com (2603:10b6:408:ff:cafe::3e) by BN9PR03CA0251.outlook.office365.com (2603:10b6:408:ff::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22 via Frontend Transport; Mon, 18 Nov 2024 12:13:34 +0000 Received: from SATLEXMB03.amd.com (165.204.84.12) by BL6PEPF0002256E.mail.protection.outlook.com (10.167.249.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Mon, 18 Nov 2024 12:13:34 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 18 Nov 2024 06:13:33 -0600 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Mon, 18 Nov 2024 06:13:32 -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: 8b1e5498-a5a6-11ef-99a3-01e77a169b0f X-Custom-Connection: eyJyZW1vdGVpcCI6IjJhMDE6MTExOmY0MDM6MjQxMjo6NjI1IiwiaGVsbyI6Ik5BTTEwLU1XMi1vYmUub3V0Ym91bmQucHJvdGVjdGlvbi5vdXRsb29rLmNvbSJ9 X-Custom-Transaction: eyJpZCI6IjhiMWU1NDk4LWE1YTYtMTFlZi05OWEzLTAxZTc3YTE2OWIwZiIsInRzIjoxNzMxOTMyMDIxLjQwNTc1Mywic2VuZGVyIjoiYXlhbi5rdW1hci5oYWxkZXJAYW1kLmNvbSIsInJlY2lwaWVudCI6Inhlbi1kZXZlbEBsaXN0cy54ZW5wcm9qZWN0Lm9yZyJ9 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=raxAJz5SsrKA7qQx+A2qmkWjtZHgkCPCGJ407LxS6AltLxx0PbjCuuvuXNYIFwlbO5BGlOoM8Cl8ykqtihOYUjPA1iy3UNHbDwSmTMvCetFvQRpiPPDrYpLlXukJzjHGr0jyn1YumYXJrk6Xp14JREAd52S6jyXnmEFWkVRjVMgfa0/bHTspR7y0J8iFxGe/hNZEMRTyn2v/kWhHAyZ6j8dzCXuDfpiijLdGhrRKRf8Ast1pqk3aPK0siuXZm5E8g4L9Tf3afuzYd229nEcDeBsLCZo+Sr6WS0ajIPbCDAo5zQ0uU5Q0XkqyrcorKTIKbgWiE7vo8KP0wMy9OQhrVw== 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=THkJUSUkfVKn7mJityoAfrgY4wqfLzF0xJ68zkmM5zk=; b=nFaWcCjWLkm2fETA+iwvbFktUfLHPbZE8EcFqSADEAvIEI73Ding2KYa9WtoRVe4nqVztBKgTY+Wmh1/YLyRl6UMUQEKdop2BkY6lS+bLx8hek2H8XlRjcBpm3Sn6+xQS21Bs6lAaLtPiFjZSHJMmmj2UXz4TtswDSevbK+9LlfoLlL6qSH9dXe5Hd69Ty1jTM0nATSJcqgstVxQySLYf9jJOWbZKbAVlvX67un2MGpay0ZjC2RU/VBPz07ore9pmSpA6V9qTbFdw6KL+ElOPNhsf0MbkF3E5GPiXYLUf1kIsd5ytjlwrcuOgGM7tDDE7kiVqNsCNDv915jVeaJN1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 165.204.84.12) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine 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=THkJUSUkfVKn7mJityoAfrgY4wqfLzF0xJ68zkmM5zk=; b=HjPc2SH9O5XNei3dSMM21JhWy+87WrJMoBmFPYDUFlvoZukibkikxdS/fXeEsqtpFSd+PXq+XXL4cgq8haQQ3EwG4XovYVAVRY1dp8qT8iGxEQCSzXmjD8Aq75DTNjavBhPURfrpWHGOS94Tmw4X4zbCDhPjK/BfAP2N2OCQ/e4= X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 165.204.84.12) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning amd.com discourages use of 165.204.84.12 as permitted sender) From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Luca Fancellu , Julien Grall Subject: [PATCH v6 3/3] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm Date: Mon, 18 Nov 2024 12:12:50 +0000 Message-ID: <20241118121250.4027441-4-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241118121250.4027441-1-ayan.kumar.halder@amd.com> References: <20241118121250.4027441-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Received-SPF: None (SATLEXMB03.amd.com: ayan.kumar.halder@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0002256E:EE_|SA1PR12MB7104:EE_ X-MS-Office365-Filtering-Correlation-Id: 195080aa-d1b8-48af-a52a-08dd07ca6c78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?q?iMj3xuGNuqlzfTZ8c0+Xc/GKe5P7V5W?= =?utf-8?q?8Tsg64dzkpRjJbjzdF7N2U6EjQ+sjpmqkdh2JNL/3HafJ057bD3o4LpPqps5SPICH?= =?utf-8?q?fESdcsyuL2F/+Cc5MvEMv+frzHtP2ilE3iSNPEESYE8/U2tkQza33HxATSojZDxz9?= =?utf-8?q?TyavlRLs5KYLAVSzUDlXmn44OIvz44DWuNKWMrCGmvoR6FIighGGjmuCvg+07qQi9?= =?utf-8?q?SfsgW432YFFBqY6Fzrfw9NK6fJUu+ASW1s1/+56z2S3yDODV6aW7scOFLfxXpJ82M?= =?utf-8?q?aWqlMmJg0qaPiUbIt7isITDTCQBNVCH3TLCTDVEhAbYDeDPMo/zECPbaC21REjGze?= =?utf-8?q?DDmeNI6YJUX6xmZOAPnJ7yU07ZLPLmGZ2GSeHRRu7YvlUEw1NtRnk1lWQUPjxS6So?= =?utf-8?q?YsGlIknhF7zCF3MDg1QZTqhbYd8fqEkdzb+6EEDsEx3Di2x3oFmnEz7/00H7+L7HU?= =?utf-8?q?XpF7alHUoLfpDbjrBkOSC3LSlIWl6e6ayZuEYEdXWnXgNJ7+ssyW+S/T89yT+K/GM?= =?utf-8?q?+77GDKnJcgiq47cZgKbyA0Uct8lyWzBnzd0KkwlvVpdmC6V98qN2O78AdoX9KiNvK?= =?utf-8?q?LyeCnXe+naO/gfcyUGsW86ZvpUFJOfxcQNMwI0wxtGdzFpdmnyr5yMkjsS8DG/nTE?= =?utf-8?q?30tVVgChPIooDorozkW+Rx0/djuRKbWlcBBY7qvliFoJK8eR+ALY9MZPthAaKb55y?= =?utf-8?q?fdyjg20oi7RjGKh1yupJ9sps0sBT+a8Na4mSYXWnEP5yS9ToqHYvflW3nFOia1Ge+?= =?utf-8?q?seVzg7QmoKgN6hjk+8bvhZV7TSkMi5rXM0hUBpUW3zMXEJCKuvHksnrb67+l9CDse?= =?utf-8?q?4G0+AFq4wO3JoqxWAspwKphULSR6Cmeixl8gb5/oa9/coEgJkzjsycxU2CpBu+XiY?= =?utf-8?q?8NRvuEhyeB72znQkWqOjlxCnjQzePkkV+TAzQ96WlKssYn1QjyRPqZmSBeUF7fJrz?= =?utf-8?q?LUqKf8zaAxywaCZCZI1oJDPnOVUasz1fpoCXv2VbIL2JtCZzzYZNE4vyrE/aXngTv?= =?utf-8?q?XOpP/ihCuad+oIQKp5Qky5BBEcNncr8nluKP9Ap8B8D1OA1cL33eq5/WUmCIAh2kd?= =?utf-8?q?mCvd4QmCSqZZkDGxR+EZBdJj3PL7Pp84IqLKYzBmsW3DJ24AQDWVwe0t/mc/Ogfge?= =?utf-8?q?KeZYY0GfslJhE45HB+Z5Hel+QnMEnYJjjuUU0q9R1g4GfC5SQHet2Rilv1eYW7y04?= =?utf-8?q?AJH1LIdViTDK2Oq6oSUEoyf6KAvW5n9oytb77XiR7Ze7nrrgHoHe/aCP9/PkJJDcQ?= =?utf-8?q?UCmD5a0hYAJpQjr40AKZD9jZfDQPMDsJSHvhFPbraW79N7d1sbykzKtLAYrCN6qIi?= =?utf-8?q?5QDzPMpZC3HUHw3OR1DPn74X+1O5JTBIUA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.12;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:atlvpn-bp.amd.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2024 12:13:34.0331 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 195080aa-d1b8-48af-a52a-08dd07ca6c78 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.12];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0002256E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7104 Secondary cpus initialization is not yet supported. Thus, we print an appropriate message and put the secondary cpus in WFE state. And we introduce to BUILD_BUG_ON to prevent users using from building Xen on multiprocessor based MPU systems. In Arm, there is no clean way to disable SMP. As of now, we wish to support MPU on UNP only. So, we have defined the default range of NR_CPUs to be 1 for MPU. Signed-off-by: Ayan Kumar Halder Reviewed-by: Luca Fancellu Acked-by: Julien Grall --- Changes from :- v1 - 1. NR_CPUS is defined as 1 for MPU 2. Added a message in enable_secondary_cpu_mm() v2 - 1. Added the range 2. Clarified in the commit message why/how we have disabled SMP. v3 - 1. BUILD_BUG_ON() is moved to smp.c. v4 - 1. Moved "default "1" if ARM && MPU” right after “default "256" if X86”. v5 - 1. Added Ack. xen/arch/Kconfig | 2 ++ xen/arch/arm/arm64/mpu/head.S | 10 ++++++++++ xen/arch/arm/smp.c | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/xen/arch/Kconfig b/xen/arch/Kconfig index 308ce129a8..9f4835e37f 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -6,8 +6,10 @@ config PHYS_ADDR_T_32 config NR_CPUS int "Maximum number of CPUs" + range 1 1 if ARM && MPU range 1 16383 default "256" if X86 + default "1" if ARM && MPU default "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S index c56c693cc2..f692fc7443 100644 --- a/xen/arch/arm/arm64/mpu/head.S +++ b/xen/arch/arm/arm64/mpu/head.S @@ -142,6 +142,16 @@ FUNC(enable_boot_cpu_mm) ret END(enable_boot_cpu_mm) +/* + * We don't yet support secondary CPUs bring-up. Implement a dummy helper to + * please the common code. + */ +ENTRY(enable_secondary_cpu_mm) + PRINT("- SMP not enabled yet -\r\n") +1: wfe + b 1b +ENDPROC(enable_secondary_cpu_mm) + /* * Local variables: * mode: ASM diff --git a/xen/arch/arm/smp.c b/xen/arch/arm/smp.c index c11bba93ad..b372472188 100644 --- a/xen/arch/arm/smp.c +++ b/xen/arch/arm/smp.c @@ -1,4 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include @@ -6,6 +7,16 @@ #include #include +static void __init __maybe_unused build_assertions(void) +{ +#ifdef CONFIG_MPU + /* + * Currently, SMP is not enabled on MPU based systems. + */ + BUILD_BUG_ON(NR_CPUS > 1); +#endif +} + void arch_flush_tlb_mask(const cpumask_t *mask) { /* No need to IPI other processors on ARM, the processor takes care of it. */