From patchwork Mon Oct 28 12:45:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13853443 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 078CBD10C0B for ; Mon, 28 Oct 2024 12:46:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826443.1240695 (Exim 4.92) (envelope-from ) id 1t5P8O-0004fK-Em; Mon, 28 Oct 2024 12:46:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826443.1240695; Mon, 28 Oct 2024 12:46:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8O-0004fD-BN; Mon, 28 Oct 2024 12:46:12 +0000 Received: by outflank-mailman (input) for mailman id 826443; Mon, 28 Oct 2024 12:46:10 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8M-0004Qp-UP for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 12:46:10 +0000 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20625.outbound.protection.outlook.com [2a01:111:f403:2009::625]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9a64753a-952a-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 13:46:09 +0100 (CET) Received: from PH8PR05CA0014.namprd05.prod.outlook.com (2603:10b6:510:2cc::7) by BN5PR12MB9509.namprd12.prod.outlook.com (2603:10b6:408:2a8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.25; Mon, 28 Oct 2024 12:46:05 +0000 Received: from CY4PEPF0000E9D2.namprd03.prod.outlook.com (2603:10b6:510:2cc:cafe::80) by PH8PR05CA0014.outlook.office365.com (2603:10b6:510:2cc::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.11 via Frontend Transport; Mon, 28 Oct 2024 12:46:04 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D2.mail.protection.outlook.com (10.167.241.137) 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:04 +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, 28 Oct 2024 07:46:03 -0500 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.39; Mon, 28 Oct 2024 07:46:03 -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:02 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9a64753a-952a-11ef-99a3-01e77a169b0f ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lwhqCnyLQKeD/i8x6y0clE+m+6lu3TAvl6ewlQyscDM6iDCyMhssZSmfWIfAkKD1cy8DZ2uRobAABiDD3bqyvRX2jNA5UzJpkpzsp/XPDgpBohoEYe4MEoxBZjCxLGEqz3MEKMNuaiIF3SHGDUbC5YOBzwEeSKpgOuW0JCy3WZqkJJ7718zP8FtJoavq9Ec6/gfDkJCg0fTQ8Jqh9QPvJxQzWV8RdVAmlWTVvT71pVVaoQzK6SaLKjRB2MyV9Cm9IFDsTowuBtTNuQZeS88T9oIL1LECIw+2e7LSszt6eyQCdHAwmAlXYhSQUTrgOgQvbscwrzdE7A97uu8VooZV8w== 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=ZFcBkE/m8lBfaY/RDGSA74usJ37yqes+AbUBa2xX70A=; b=cAW06+L9ec1sN1DBh5vst50QR2DrE3Uj+TLRxNOL3TqBztiG880z8FekhYNs/cNakTGQD2eBkBfKJL10OkmM7TVz5qB9kAxJtPpDBB1qhcelbWn1TbFYBEVpgMBAMd/khyU0EiKoBAErKnvG73cIwUiCDWFSwAqdMZyaZqPOD0XBbVzhY5Ex3Xruw5mhx8Ugmy1//Tq27ua7g4vgsJNdTkkBWygcKZay0uJx1VPGszpR1i/HK9mwcXqkldYVasseQKtNXXgJsDrSd1+8rQ7mXVLykTAUo6mGVxwuJC2nmagxV4wrpdczgKk8RXZ+5t4F9B0abhKyVTHXUSmz1xxqdA== 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=ZFcBkE/m8lBfaY/RDGSA74usJ37yqes+AbUBa2xX70A=; b=Ed/Vlc5FhM82IZXFH+IHF8mKTb08v+dmz6oXLUpjMWfW106MOT0dDu/q3amEOqB1rmv7yY4X3kuxdzqeL9Ih8/DcovUTj7vMCf5hFK+w+7i2y05A+ILyf9GyVPHEfcv/hsnLeOwJQigBOFiFpFrs6GVFcU+Rw+p1O/cH+VgvOvE= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" Subject: [PATCH v4 1/6] xen/arm: Skip initializing the BSS section when it is empty Date: Mon, 28 Oct 2024 12:45:42 +0000 Message-ID: <20241028124547.1371867-2-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 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: CY4PEPF0000E9D2:EE_|BN5PR12MB9509:EE_ X-MS-Office365-Filtering-Correlation-Id: 53cd0bc6-e4b2-4d50-0ff7-08dcf74e7c38 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13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RTl8p+EfD3GuA7JEtAZpUvEKYOPj9k5WKz4B726OsQEJmwzVzu/tMgTd4knFjYY5y/+4RLBB/NOKiERuJKwhyZW4DNyN9LqB5Z7/IyjXYyA38NZE/9qLJULRNQCwWw7pYVrmjebRetASaXph+m2KUbfPT3WT2hm5ClPSTrQwho8Y0ikAbNPYYM8/O4zpsN32ljY7DKcmqjBwLBh/WHXIfKkeshcsjsdU0UMEqgNayD4e4QSmyq/iNOkEQ5kOvBEyZp5Ah2NqhxzdNJeQeGZHg6GvsXq3D5CB5ZLG3sPiLvaBq/nmzi/Y1c2D3iR//DeWY1iEzfNHtsR1oOrfXEaw3vd9r+igfJkK3kiq3zEe1WDBXidOMdKuKFbx/ZeLIsrGOJGrtV+nz2GdyGucnDuA== 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)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 12:46:04.1607 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 53cd0bc6-e4b2-4d50-0ff7-08dcf74e7c38 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: CY4PEPF0000E9D2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN5PR12MB9509 If the BSS section is empty, then the function should return. If one does not check whether the BSS section is empty or not, then there is a risk of writing 0s outside of BSS section (which may contain critical data). Fixes: dac84b66cc9a ("xen: arm64: initial build + config changes, start of day code") Signed-off-by: Ayan Kumar Halder Reviewed-by: Luca Fancellu --- Changes from :- v1..v2 - New patch introduced in v3. v3 - 1. Update the check in arm32 as well. 2. Drop the R-bs. xen/arch/arm/arm32/head.S | 3 +++ xen/arch/arm/arm64/head.S | 2 ++ 2 files changed, 5 insertions(+) diff --git a/xen/arch/arm/arm32/head.S b/xen/arch/arm/arm32/head.S index a96d5d3503..4ff5c220bc 100644 --- a/xen/arch/arm/arm32/head.S +++ b/xen/arch/arm/arm32/head.S @@ -185,12 +185,15 @@ zero_bss: PRINT("- Zero BSS -\r\n") mov_w r0, __bss_start /* r0 := vaddr(__bss_start) */ mov_w r1, __bss_end /* r1 := vaddr(__bss_end) */ + cmp r1, r0 + beq skip_bss mov r2, #0 1: str r2, [r0], #4 cmp r0, r1 blo 1b +skip_bss: mov pc, lr ENDPROC(zero_bss) diff --git a/xen/arch/arm/arm64/head.S b/xen/arch/arm/arm64/head.S index 14c3720d80..72c7b24498 100644 --- a/xen/arch/arm/arm64/head.S +++ b/xen/arch/arm/arm64/head.S @@ -346,6 +346,8 @@ FUNC_LOCAL(zero_bss) PRINT("- Zero BSS -\r\n") ldr x0, =__bss_start /* x0 := vaddr(__bss_start) */ ldr x1, =__bss_end /* x1 := vaddr(__bss_end) */ + cmp x1, x0 + beq skip_bss 1: str xzr, [x0], #8 cmp x0, x1 From patchwork Mon Oct 28 12:45:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ayan Kumar Halder X-Patchwork-Id: 13853445 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 45121D10C0B for ; Mon, 28 Oct 2024 12:46:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826444.1240705 (Exim 4.92) (envelope-from ) id 1t5P8c-00053S-Mb; Mon, 28 Oct 2024 12:46:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826444.1240705; Mon, 28 Oct 2024 12:46:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8c-00053F-JZ; Mon, 28 Oct 2024 12:46:26 +0000 Received: by outflank-mailman (input) for mailman id 826444; Mon, 28 Oct 2024 12:46:24 +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 1t5P8a-00050g-Qg for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 12:46:24 +0000 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2062e.outbound.protection.outlook.com [2a01:111:f403:2408::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a2f82cb6-952a-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 13:46:23 +0100 (CET) Received: from MW4PR04CA0263.namprd04.prod.outlook.com (2603:10b6:303:88::28) by CH3PR12MB8308.namprd12.prod.outlook.com (2603:10b6:610:131::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.20; Mon, 28 Oct 2024 12:46:18 +0000 Received: from BL6PEPF00022574.namprd02.prod.outlook.com (2603:10b6:303:88:cafe::e8) by MW4PR04CA0263.outlook.office365.com (2603:10b6:303:88::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21 via Frontend Transport; Mon, 28 Oct 2024 12:46:18 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF00022574.mail.protection.outlook.com (10.167.249.42) 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:17 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 28 Oct 2024 07:46:16 -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:15 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a2f82cb6-952a-11ef-a0c2-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=OmxHYJh9YA4OueVMzcJcEVtMKJVB84TGatuFhs0UbluAgUZGwBPXrMEXx6rrGTHEduiNe0kvFWI6GYdKHpl/UF3oflm7kL6eIYvewF7vzAD4kXg4K826dpLaG2pknz4XL+LOM34xBEVSJBN5Euk2M5nelCRJaTyguoFM04rn4eYt51so7+yCahjPml1gwFibnEL5mVa7w3czN3pSQB3QypKyTcGdaJRQ5f4iwEOPdNgLV4swQ8jW11eD2xsQoLogffW3lFMkx5eoc7Yr3DX4OXD1lep8PQADhb/2X8iciF7ua7/1+41fTfLxSiPkuOLQqls4mz6A3SxGSri/DKYfRQ== 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=ptl+NdoV/c7naiFmhPcaykhIi3QSimLXcLj6cNBxMSU=; b=IhIIrgRXBo1/ZvDr806T9lXXNH6Jdy5WTJl27S1owkqV2mIM1QvcxOlZHX7OFMIXj07NoqgJ+3C/AEoOE7HQpEILShDr8ER43JdJ9oQFL4aZ8ngGpjdFgnwPEFjpqcMFurewH+qJE1PmpGVQT5VPEPQQ+dfFN2wH5YtI+InWeaRzvA5XCNZnjNdwwcLJg0xEmpInEJsGAq6EKXAj0WLWccnaiJ2jcAhnMOjCTrbJ4YA1sVHc9zQ5SczPN6tSV+OWP4Hu/ydCkJQHLJvkSEw18OLV3nyHhkdDSwa3ynu2Ex7Cgiu172nxxSo/p17/2uVpUIySMfvO8RP2U7OLR8dgFw== 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=ptl+NdoV/c7naiFmhPcaykhIi3QSimLXcLj6cNBxMSU=; b=fN7PdrU0I2yoqzGVtJdnE9aelqDxTL5HQMdtyTWzFHrB8viK45HS8p6zp9hn28fWiiM3gZrl0yHR6K414uIVf37umOFjGUzzx1rO85b9Ezp684T8EuONdVkOPvstuPcuf8X1/1ing7U1oLyA5I+l4GWQnzQWU8uKwrzWgpWTbD8= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Oleksii Kurochko , Community Manager , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk , Luca Fancellu , Julien Grall Subject: [PATCH v4 2/6] xen/arm: mpu: Introduce choice between MMU and MPU Date: Mon, 28 Oct 2024 12:45:43 +0000 Message-ID: <20241028124547.1371867-3-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 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: BL6PEPF00022574:EE_|CH3PR12MB8308:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a7282d1-38a6-458d-3b19-08dcf74e83f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: OZZ/qsC0xia9PAG661a1SSmFrWamhni3iyOiu8nRz7sChbTWCSK0YHPeQVvuWl0GjlUo8PueV1zi5/DRN23xg+GgRsW9exlPGBrT1881LYhME31sVJ7GK3dDX0w4Hr1woe6FnX0QDHbpS56GqmiDaDG/K0hsFPsnWp80Eo5Ye2hnE0WEIlrtNtKoWXghV4zunjcFF9N5Ged1vUvbHg+Tabj9EFTcF+wETutBw6gIZROpQY5+iZALO0LcQhy7xyPBP4/q9ebUrsEP9NGlVdbH04N/iF3qBC2usVqq+3xSDC31IUqBDzgMIGohwZtCoVVmV6/Ro52CsGay8/XCqOxZELn87BJ3fCdAHZj/J49fwLu+A7326sqihJca1ZCw6cqy6fD9CI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03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 12:46:17.2120 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a7282d1-38a6-458d-3b19-08dcf74e83f1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00022574.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8308 There are features in the forthcoming patches which are dependent on MPU. For eg fixed start address. Also, some of the Xen features (eg STATIC_MEMORY) will be selected by the MPU configuration. Thus, this patch introduces a choice between MMU and MPU for the type of memory management system. By default, MMU is selected. MPU is now gated by UNSUPPORTED. Update SUPPORT.md to state that the support for MPU is experimental. Also updated CHANGELOG.md as well. Signed-off-by: Ayan Kumar Halder Reviewed-by: Luca Fancellu Acked-by: Julien Grall --- Changes from :- v1 - 1. Reword the help messages. 2. Update Support.md. v2 - 1. Reword the help message. v3 - 1. Update Changelog. 2. Add R-b and Ack. CHANGELOG.md | 2 ++ SUPPORT.md | 1 + xen/arch/arm/Kconfig | 17 ++++++++++++++++- xen/arch/arm/platforms/Kconfig | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c499d12dc4..79524cc15f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Prefer ACPI reboot over UEFI ResetSystem() run time service call. ### Added + - On Arm: + - Support for earlyboot of Xen on Armv8-R (experimental). ### Removed - On x86: diff --git a/SUPPORT.md b/SUPPORT.md index 23dd7e6424..94610d3c91 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -40,6 +40,7 @@ supported in this document. Status, Xen in AArch64 mode: Supported Status, Xen in AArch32 mode: Tech Preview + Status, Xen in Armv8-R: Experimental Status, Cortex A57 r0p0-r1p1: Supported, not security supported Status, Cortex A77 r0p0-r1p0: Supported, not security supported diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 323c967361..ed92eb67cb 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -58,10 +58,25 @@ config PADDR_BITS default 40 if ARM_PA_BITS_40 default 48 if ARM_64 +choice + prompt "Memory management system" + default MMU + help + User can choose between the different forms of memory management system. + config MMU - def_bool y + bool "MMU" select HAS_PMAP select HAS_VMAP + help + Select it if you plan to run Xen on A-profile Armv7+ + +config MPU + bool "MPU" if UNSUPPORTED + help + Memory Protection Unit (MPU). Select if you plan to run Xen on ARMv8-R + systems supporting EL2. (UNSUPPORTED) +endchoice source "arch/Kconfig" diff --git a/xen/arch/arm/platforms/Kconfig b/xen/arch/arm/platforms/Kconfig index 76f7e76b1b..02322c259c 100644 --- a/xen/arch/arm/platforms/Kconfig +++ b/xen/arch/arm/platforms/Kconfig @@ -1,5 +1,5 @@ choice - prompt "Platform Support" + prompt "Platform Support" if MMU default ALL_PLAT help Choose which hardware platform to enable in Xen. From patchwork Mon Oct 28 12:45:44 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: 13853446 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 45072D10C0B for ; Mon, 28 Oct 2024 12:46:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826446.1240714 (Exim 4.92) (envelope-from ) id 1t5P8i-0005WH-TT; Mon, 28 Oct 2024 12:46:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826446.1240714; Mon, 28 Oct 2024 12:46:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8i-0005WA-Qo; Mon, 28 Oct 2024 12:46:32 +0000 Received: by outflank-mailman (input) for mailman id 826446; Mon, 28 Oct 2024 12:46:30 +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 1t5P8g-0004Qp-Q9 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 12:46:30 +0000 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2060a.outbound.protection.outlook.com [2a01:111:f403:2413::60a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a6a1a87a-952a-11ef-99a3-01e77a169b0f; Mon, 28 Oct 2024 13:46:29 +0100 (CET) Received: from DM6PR01CA0029.prod.exchangelabs.com (2603:10b6:5:296::34) by CY5PR12MB6300.namprd12.prod.outlook.com (2603:10b6:930:f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 28 Oct 2024 12:46:24 +0000 Received: from CY4PEPF0000E9CF.namprd03.prod.outlook.com (2603:10b6:5:296:cafe::56) by DM6PR01CA0029.outlook.office365.com (2603:10b6:5:296::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.21 via Frontend Transport; Mon, 28 Oct 2024 12:46:24 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9CF.mail.protection.outlook.com (10.167.241.134) 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:24 +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, 28 Oct 2024 07:46:23 -0500 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.39; Mon, 28 Oct 2024 07:46:22 -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:21 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a6a1a87a-952a-11ef-99a3-01e77a169b0f ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RBycu7yJe0h0S/DW+SO4EmLdwW3ooTKDFBuDuMBTRbWD7Xj5iKZyGYBWozcnI0feFghbCcI1RaAzCk0x23lEr1KWwYY7PazIBmFsFrDgqI2pgWLwJshcsEZLfFwLP9H/bH48OfOk6Nat9GsVsXAQt7ayYZUib3XtoC1YU3kpp8TmEOnpH68s8WFS60XozpEUxyTCl0rT4ZUvWcvLVis/P50Dw08rAElFIe9qI6Pp/fK0Lw1BLbfM/ytt8BBuSxPQo2Y06y1YpsarfIGaELrDIQfg1WrxS/lHHYSb3gtK842gUnuxaw2RbqIcJyDseGdFciN9rrky7xTkQykc90dOmA== 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=lNYvm8YWxvjs04dfYHZIpT38yoOVT4AS9ee8RDi6eKk=; b=rth3iX0bGY2FRebgm8Wm6uEbuN7R8oemB/YsABGg465pTv8ilUiDqqQulEhwJOCMKa3B33ejOHw/rwYQKxVi53L7mi/p2E/Rt4v17dIV8VxJo12YXssv8gTDDLzH4aHhNVv+/X72we9AxkVlKN9Zi3J9iU70PxrJJfkUipD+lK9+9FLEiEBrCzwZLEcuMx199I83ZfQ/Yx3zX84Hw2hwCY1zo+jRmTS+OlaNempiIMtHg25k6hjywBIVyGXTFK6GLrYa0/5pVvnsi0RNFUZPsFX83RzX0Y7kCQwQp10PnTvpuJ0oXlR4Ws7HHBFdEODjY8RE9oAInwqq2G8YmXvPnA== 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=lNYvm8YWxvjs04dfYHZIpT38yoOVT4AS9ee8RDi6eKk=; b=Wa+cLSZ4shfylDcJ2xd+hR/QfB5CXC3dRVtEmWeQQy3egpsrQE0QtNPKFJfg+EgsTQIr0LEx9iuPWbyB5IqfOH87JGaBf3UI76Ca/yxODL3PzTmjZO+smQtkV121rsUx7mc6fz+wr2SB0Z1a8/P/2EKZMbOKFphaNvgBRj38WI4= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: Wei Chen , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , "Jiamei . Xie" , "Ayan Kumar Halder" Subject: [PATCH v4 3/6] xen/arm: mpu: Define Xen start address for MPU systems Date: Mon, 28 Oct 2024 12:45:44 +0000 Message-ID: <20241028124547.1371867-4-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 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: CY4PEPF0000E9CF:EE_|CY5PR12MB6300:EE_ X-MS-Office365-Filtering-Correlation-Id: 71c798de-dfc8-4f03-d253-08dcf74e880f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|376014|1800799024; X-Microsoft-Antispam-Message-Info: TF14+F83SaNxu4Udbngw5wZLlwGfMVwL5/bI3PYN2TMlK/EUcoijiIUHPZ8oRL7FFA2kSwYL6A871yI1SvoG1kQuosRnowYzBtH77KtB3iMkUFIHOs9GaUS0PvpwoOnzt/ICVEkmSMHK14hDdX+aeRmukaG7wTz0hDBnnTv0KcUdDxhiAwGA/nF42f0KyQNrX3msJZR8Zi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z2guoxs2JEobmK5QUdQ0eiTQCtg+bvGuVaY+6ZLkOe5Nu0ktFCmAtWDmcMwRjitBy2fl9vAU0SVUTvkhbtbZwhlpmeHcDq0pl0d7TAxuerbVxAQ95Hrz9h9CfxQnOWglNdomdbOZd44OvHOaOb2Gg== 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)(82310400026)(36860700013)(376014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 12:46:24.0297 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 71c798de-dfc8-4f03-d253-08dcf74e880f 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: CY4PEPF0000E9CF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6300 From: Wei Chen On Armv8-A, Xen has a fixed virtual start address (link address too) for all Armv8-A platforms. In an MMU based system, Xen can map its loaded address to this virtual start address. So, on Armv8-A platforms, the Xen start address does not need to be configurable. But on Armv8-R platforms, there is no MMU to map loaded address to a fixed virtual address and different platforms will have very different address space layout. So Xen cannot use a fixed physical address on MPU based system and need to have it configurable. So, we introduce a Kconfig option for users to set the start address. The start address needs to be aligned to 4KB. We have a check for this alignment. MPU allows us to define regions which are 64 bits aligned. This restriction comes from the bitfields of PRBAR, PRLAR (the lower 6 bits are 0 extended to provide the base and limit address of a region). This means that the start address of Xen needs to be at least 64 bits aligned (as it will correspond to the start address of memory protection region). As for now Xen on MPU tries to use the same memory alignment restrictions as it has been for MMU. We have added a build assertion to ensure that the page size is 4KB. Unlike MMU where the starting virtual address is 2MB, Xen on MPU needs the start address to be 4KB (ie page size) aligned. In case if the user forgets to set the start address, then 0xffffffff is used as default. This is to trigger the error (on alignment check) and thereby prompt user to set the start address. Also updated config.h so that it includes mpu/layout.h when CONFIG_MPU is defined. Signed-off-by: Wei Chen Signed-off-by: Jiamei.Xie 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". xen/arch/arm/Kconfig | 10 ++++++++ xen/arch/arm/arm64/Makefile | 1 + xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/mm.c | 15 ++++++++++++ xen/arch/arm/include/asm/config.h | 4 +++- xen/arch/arm/include/asm/mpu/layout.h | 33 +++++++++++++++++++++++++++ xen/arch/arm/xen.lds.S | 7 ++++++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/arm64/mpu/Makefile create mode 100644 xen/arch/arm/arm64/mpu/mm.c create mode 100644 xen/arch/arm/include/asm/mpu/layout.h diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index ed92eb67cb..15b2e4a227 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -23,6 +23,16 @@ config ARCH_DEFCONFIG default "arch/arm/configs/arm32_defconfig" if ARM_32 default "arch/arm/configs/arm64_defconfig" if ARM_64 +config XEN_START_ADDRESS + hex "Xen start address: keep default to use platform defined address" + default 0xFFFFFFFF + depends on MPU + help + Used to set customized address at which which Xen will be linked on MPU + systems. Must be aligned to 4KB. + 0xFFFFFFFF is used as default value to indicate that user has not + customized this address. + menu "Architecture Features" choice diff --git a/xen/arch/arm/arm64/Makefile b/xen/arch/arm/arm64/Makefile index 72161ff22e..6491c5350b 100644 --- a/xen/arch/arm/arm64/Makefile +++ b/xen/arch/arm/arm64/Makefile @@ -1,5 +1,6 @@ obj-y += lib/ obj-$(CONFIG_MMU) += mmu/ +obj-$(CONFIG_MPU) += mpu/ obj-y += cache.o obj-y += cpufeature.o diff --git a/xen/arch/arm/arm64/mpu/Makefile b/xen/arch/arm/arm64/mpu/Makefile new file mode 100644 index 0000000000..b18cec4836 --- /dev/null +++ b/xen/arch/arm/arm64/mpu/Makefile @@ -0,0 +1 @@ +obj-y += mm.o diff --git a/xen/arch/arm/arm64/mpu/mm.c b/xen/arch/arm/arm64/mpu/mm.c new file mode 100644 index 0000000000..0b8748e575 --- /dev/null +++ b/xen/arch/arm/arm64/mpu/mm.c @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +static void __init __maybe_unused build_assertions(void) +{ + /* + * Unlike MMU, MPU does not use pages for translation. However, we continue + * to use PAGE_SIZE to denote 4KB. This is so that the existing memory + * management based on pages, continue to work for now. + */ + BUILD_BUG_ON(PAGE_SIZE != SZ_4K); +} diff --git a/xen/arch/arm/include/asm/config.h b/xen/arch/arm/include/asm/config.h index a2e22b659d..0a51142efd 100644 --- a/xen/arch/arm/include/asm/config.h +++ b/xen/arch/arm/include/asm/config.h @@ -69,8 +69,10 @@ #include #include -#ifdef CONFIG_MMU +#if defined(CONFIG_MMU) #include +#elif defined(CONFIG_MPU) +#include #else # error "Unknown memory management layout" #endif diff --git a/xen/arch/arm/include/asm/mpu/layout.h b/xen/arch/arm/include/asm/mpu/layout.h new file mode 100644 index 0000000000..d6d397f4c2 --- /dev/null +++ b/xen/arch/arm/include/asm/mpu/layout.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_LAYOUT_H__ +#define __ARM_MPU_LAYOUT_H__ + +#define XEN_START_ADDRESS CONFIG_XEN_START_ADDRESS + +/* + * All MPU platforms need to provide a XEN_START_ADDRESS for linker. This + * address indicates where Xen image will be loaded and run from. This + * address must be aligned to a PAGE_SIZE. + */ +#if (XEN_START_ADDRESS % PAGE_SIZE) != 0 +#error "XEN_START_ADDRESS must be aligned to 4KB" +#endif + +/* + * For MPU, XEN's virtual start address is same as the physical address. + * The reason being MPU treats VA == PA. IOW, it cannot map the physical + * address to a different fixed virtual address. So, the virtual start + * address is determined by the physical address at which Xen is loaded. + */ +#define XEN_VIRT_START _AT(paddr_t, XEN_START_ADDRESS) + +#endif /* __ARM_MPU_LAYOUT_H__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 5b9abc9a2d..d1e579e8a8 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -213,6 +213,13 @@ SECTIONS * match the context. */ ASSERT(_start == XEN_VIRT_START, "_start != XEN_VIRT_START") +#ifdef CONFIG_MPU +/* + * On MPU based platforms, the starting address is to be provided by user. + * One need to check that it is 4KB aligned. + */ +ASSERT(IS_ALIGNED(_start, 4096), "starting address should be aligned to 4KB") +#endif /* * We require that Xen is loaded at a page boundary, so this ensures that any From patchwork Mon Oct 28 12:45:45 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: 13853448 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 F108BD10C0B for ; Mon, 28 Oct 2024 12:46:47 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826451.1240725 (Exim 4.92) (envelope-from ) id 1t5P8k-0005nW-B6; Mon, 28 Oct 2024 12:46:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826451.1240725; Mon, 28 Oct 2024 12:46:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8k-0005nJ-6w; Mon, 28 Oct 2024 12:46:34 +0000 Received: by outflank-mailman (input) for mailman id 826451; Mon, 28 Oct 2024 12:46:33 +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 1t5P8j-00050g-8W for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 12:46:33 +0000 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on20602.outbound.protection.outlook.com [2a01:111:f403:200a::602]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a8ba37e3-952a-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 13:46:32 +0100 (CET) Received: from PH8PR05CA0010.namprd05.prod.outlook.com (2603:10b6:510:2cc::15) by SN7PR12MB7106.namprd12.prod.outlook.com (2603:10b6:806:2a1::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.28; Mon, 28 Oct 2024 12:46:26 +0000 Received: from CY4PEPF0000E9D2.namprd03.prod.outlook.com (2603:10b6:510:2cc:cafe::a) by PH8PR05CA0010.outlook.office365.com (2603:10b6:510:2cc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.11 via Frontend Transport; Mon, 28 Oct 2024 12:46:26 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D2.mail.protection.outlook.com (10.167.241.137) 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:25 +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.39; Mon, 28 Oct 2024 07:46:25 -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:24 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a8ba37e3-952a-11ef-a0c2-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RoaicQE6Fedcmbg1DuPONq+10a9dRi+H9JTZp6HtNcVMy7ofXlUGxPAfq70neDO8HnR8dUQCsMsph+LoOpxKiCRN6gjX/zJMDBLEDDsRcyhWNKItmVz5CVQ0dsj7lAM8sBMPwDyCL+pmUirhvJYeaDA6ESnxuUp4sUhHKI8C8dnOGI6BFkNgi4LM6U2Kpfi4aAV+FgyPZIbJxP2yHdseNoM87uKrxIU8/7USDwLlPi7OfcApRtXIeOla05emX20JYeifGIE4/dNDBBomaliOmFbJGRGwzSn8gkBrK+aecklfCT0roMnaWza5u1nVhNoTEbZF6gIVkA3NaMeVa7P+kA== 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=MyhtbxHUC08uI+MsIp0gmuNpSuHqjK/LKiAaR17085A=; b=O6fObCsquHVYm79KrwZI1NPP6xO28bCj8jMiyzx2y4/phCHsMI30hAkWlMUZIF2fF4qraBdpdUqUIttM0tvns8HfOl7bbjOv0/VyvzKmkrQGeUzRQgkrgwH5PP9aHdjQnU5hKdhhE9Rlz2KCgeJYz5eM3JCcx1M9BzVkDQ+vxiANWUL4+bZHnn5TuFwEvICP6CvuczvASGhddfzY5vrUfVjqlHEwGlbNHe6bOP9VHAjFkuJWcFVgZF85XnBNyFpFwdFrp5iPu8sNc5rNp3gXyaCtC6os9atkEhn6JXLnPpqu0sUC7KSZHAZHQq18WwBzxahLvnIatlFJFeSUqfr6dA== 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=MyhtbxHUC08uI+MsIp0gmuNpSuHqjK/LKiAaR17085A=; b=D/N6ep35AFfc7bIvPL878/o8Kr230b6j/8r3KfHeZoTgz+TPD/fiYmI/bYmzI48bwYEpTJcPE73hHFDdj24sQRu58E4JM4ylrGyQvgerH2YjQFMP7se2HjZ0r0/MuaqBf+Xn7Qkr2DnvKpCozr/wBlGqrLyz4LyEWe8OW8FuPYQ= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" Subject: [PATCH v4 4/6] xen/arm: mpu: Create boot-time MPU protection regions Date: Mon, 28 Oct 2024 12:45:45 +0000 Message-ID: <20241028124547.1371867-5-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 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: CY4PEPF0000E9D2:EE_|SN7PR12MB7106:EE_ X-MS-Office365-Filtering-Correlation-Id: 732400f7-d55e-4caa-dcf7-08dcf74e892e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: qBz9smjOOSPXPosvmlDg75QR6cFMmr8R7NZ14Msm9zRQ5rtnmXn5QnZSkAMWhxqgkatoCNStluGLz/qUHcNAGO1I/7kjhVjeCx3mdbR2bPvSeawfRFFtzA2pkHMrxcQW1Dsu9yHKFtAyCCGFE0lF0dCDYzjGF06vlFRneTpy2hoQB+f8WS2YvIWTq5OYtopEiYplV4VGFoPrgU44YkcO45Qpa1Aqb+B0qoJpYMVgE9YHaQlJqBFRIdr1Ti4pIjNzq20JGHxnaktcYTFBs5QwgEw555XYsxnJSfYUodd6sN6PXkyyTHNOgarIRBFYI7VaW3Ier1d/TDE71b2BrCsAEyZj5IHQEudnIN+fVQLVG+w8QktmWhf+AYP4XvPEkwOJnpHYle7Y3Y3WK9Bq06jG/2DZgQgEsAmeJSxGeIpbe0f87BelsB7678X7RTl6cIv31dQN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.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 12:46:25.9421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 732400f7-d55e-4caa-dcf7-08dcf74e892e 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: CY4PEPF0000E9D2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7106 Define enable_boot_cpu_mm() for the AArch64-V8R system. 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. MPU specific registers are defined in xen/arch/arm/include/asm/arm64/mpu/sysregs.h. Signed-off-by: Ayan Kumar Halder --- Changes from :- v1 - 1. Instead of mapping a (XEN_START_ADDRESS + 2MB) as a single MPU region, we have separate MPU regions for different parts of the Xen binary. The reason being different regions will nned different permissions (as mentioned in the linker script). 2. Introduced a label (__init_data_begin) to mark the beginning of the init data section. 3. Moved MPU specific register definitions to mpu/sysregs.h. 4. Fixed coding style issues. 5. Included page.h in mpu/head.S as page.h includes sysregs.h. I haven't seen sysregs.h included directly from head.S or mmu/head.S. (Outstanding comment not addressed). v2 - 1. Extracted "enable_mpu()" in a separate patch. 2. Removed alignment for limit address. 3. Merged some of the sections for preparing the early boot regions. 4. Checked for the max limit of MPU regions before creating a new region. 5. Checked for empty regions. v3 :- 1. Modified prepare_xen_region() so that we check for empty region within this. Also, index of regions (to be programmed in PRSELR_EL2) should start from 0. 2. Removed load_paddr() as the offset is 0. 3. Introduced fail_insufficient_regions() to handle failure caused when the number of regions to be allocated is not sufficient. xen/arch/arm/arm64/mpu/Makefile | 1 + xen/arch/arm/arm64/mpu/head.S | 122 +++++++++++++++++++ xen/arch/arm/include/asm/arm64/mpu/sysregs.h | 27 ++++ xen/arch/arm/include/asm/mm.h | 2 + xen/arch/arm/include/asm/mpu/arm64/mm.h | 22 ++++ xen/arch/arm/include/asm/mpu/mm.h | 20 +++ xen/arch/arm/xen.lds.S | 1 + 7 files changed, 195 insertions(+) create mode 100644 xen/arch/arm/arm64/mpu/head.S create mode 100644 xen/arch/arm/include/asm/arm64/mpu/sysregs.h create mode 100644 xen/arch/arm/include/asm/mpu/arm64/mm.h create mode 100644 xen/arch/arm/include/asm/mpu/mm.h 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..9377ae778c --- /dev/null +++ b/xen/arch/arm/arm64/mpu/head.S @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Start-of-day code for an Armv8-R MPU system. + */ + +#include +#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. + * + * Inputs: + * sel: region selector + * base: reg storing base address (should be page-aligned) + * 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 + */ +.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 + +1: +.endm + +/* + * Failure caused due to insufficient MPU regions. + */ +FUNC_LOCAL(fail_insufficient_regions) + PRINT("- Number of MPU regions set in MPUIR_EL2 is too less -\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. + * + * Inputs: + * lr : Address to return to. + * + * Clobbers x0 - x5 + * + */ +FUNC(enable_boot_cpu_mm) + + /* Get the number of regions specified in MPUIR_EL2 */ + mrs x5, MPUIR_EL2 + + /* 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/sysregs.h b/xen/arch/arm/include/asm/arm64/mpu/sysregs.h new file mode 100644 index 0000000000..b0c31a58ec --- /dev/null +++ b/xen/arch/arm/include/asm/arm64/mpu/sysregs.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_ARM_ARM64_MPU_SYSREGS_H +#define __ASM_ARM_ARM64_MPU_SYSREGS_H + +/* Number of EL2 MPU regions */ +#define MPUIR_EL2 S3_4_C0_C0_4 + +/* EL2 MPU Protection Region Base Address Register encode */ +#define PRBAR_EL2 S3_4_C6_C8_0 + +/* EL2 MPU Protection Region Limit Address Register encode */ +#define PRLAR_EL2 S3_4_C6_C8_1 + +/* MPU Protection Region Selection Register encode */ +#define PRSELR_EL2 S3_4_C6_C2_1 + +#endif /* __ASM_ARM_ARM64_MPU_SYSREGS_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..7e61f37612 100644 --- a/xen/arch/arm/include/asm/mm.h +++ b/xen/arch/arm/include/asm/mm.h @@ -16,6 +16,8 @@ #if defined(CONFIG_MMU) # include +#elif defined(CONFIG_MPU) +# include #else # error "Unknown memory management layout" #endif diff --git a/xen/arch/arm/include/asm/mpu/arm64/mm.h b/xen/arch/arm/include/asm/mpu/arm64/mm.h new file mode 100644 index 0000000000..c2640b50df --- /dev/null +++ b/xen/arch/arm/include/asm/mpu/arm64/mm.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * mm.h: Arm Memory Protection Unit definitions. + */ + +#ifndef __ARM64_MPU_MM_H__ +#define __ARM64_MPU_MM_H__ + +#define MPU_REGION_SHIFT 6 +#define MPU_REGION_ALIGN (_AC(1, UL) << MPU_REGION_SHIFT) +#define MPU_REGION_MASK (~(MPU_REGION_ALIGN - 1)) + +#endif /* __ARM64_MPU_MM_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/mpu/mm.h b/xen/arch/arm/include/asm/mpu/mm.h new file mode 100644 index 0000000000..92599a1d75 --- /dev/null +++ b/xen/arch/arm/include/asm/mpu/mm.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ARM_MPU_MM__ +#define __ARM_MPU_MM__ + +#if defined(CONFIG_ARM_64) +# include +#else +# error "unknown ARM variant" +#endif + +#endif /* __ARM_MPU_MM__ */ +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ 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 Oct 28 12:45:46 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: 13853449 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 B5E89D10C11 for ; Mon, 28 Oct 2024 12:46:53 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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 (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 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: 7bKTzqvEBYthZpBLNCfgPh0lcQ2qoMSh+ev3T8WNJXv3OZjfyTbadUSQ0B9lU2jLqbLtCnt9jsKJ/X8FXmMkdyu+zF6ywpnVZdsJQ5HmWiKXGMUpbgOlnMJjtJolUWxpHSx5fxSn+XuvDGGgjTPw/COh0FJDOlcLcWRM/CQVXb5mtVEqG66DptcXl4fyHClCWzrme6sgX3RNU6gVf/uFaf/R1cHjONCqJvDFXkdWvvuTTqMuO1cxeg0ZZYP0LUFeLzImSHQRCy4NTTqC0VqHRWfUXON/5RbcnqWnEBMduMYbmIcLFXCjR/PCN1k8KLM5LfcBNem5LNnL6BaUNFehqO5w+z/uxUB+s1kSJhyDyCD+RpGrvns3Zb7gYL/fNdGPJCJuNfO4B95QlwpwF+Dt9yOPtJ0hmER7xJ9gUaf4+aLdiBfSOZpP0G8NmZawdLe7X0MtH1r5DmKB0gjJuxsepvqc2F86Yb5R5JqWumzC7hKTJRMdrU/+zkl4MNJHI2ACY4XCVaGdO3lBI043+0QzMrihEaAvPdTSs3KGZ64cNz7js92QLQIjHKPd79/H3Je6KWZV3706/tsZroSWpLcKdeDKBd2csldFePaF4ihwXj87Cm/WhfxobUE/5WcuA2gJgng8Wgdv43p4Sr9+bNjIGjJS2irzHAiwe418UKN/wVxDMPO4+ibJOvhOXwgX6wUdtllcd0yLZBfeclIbgBgBTYphTbFwwXqnFoJvDkSAt4bWbcxFO1/W6bxnChjVExSH0a3M3iLbdoNXrvZps1xxIc72D4Hv3iMdk8q1wcgZDvgqiTb7+MQq4yvtCY9lNCLapRXzxU0PqkM8ECPsVz4nxHmPDVKcWNRZVoHAe9nczsKaW2WYkeBEfJV6OxPkcA50sNCqCORFnJNgZdsNuIldeGWNXTijvaX+C8AuXp/eG+0DqGwfCxVtkC2FbtpLtTag8f6Cc9V4sym4Nrnvg9inuHnFEdN/fqLQo3isEpUkFYMoSqIP37FGAR5U3S+4iu0pXnXRX7cM5BZVDUXQzeYx36Hne9ETbgqGKylF2ui3HEj8pIFgXUzjzFmqk5Jmt1Rlr2LDYzuRIFXc0xD72bd9Lai/C2LpgXgunNWuaQaxcMqh5QV1/sj4Tu39Y3U150KquOeihxTq2w/v+iAaimJw2YYAsRBDZtd1RmtZ1KQh5ZIpmks2N4k2uOtkZyo7XmRPajXM5lXbmybFkYaEunPElMBM+qifrke2Uc3zdqQUlf1/kBBUrnilt9XnuHfhOKW504cAAmSursMP9rnFO2xI8q57ohjFLzzwSMFgtm6otiuK/0e+N1uU7EDLiHszoVOOsIKpOAxMUIbXnTRjM59m2x2GMAEAcUaA9+9t9qOs/kVprb1n5hkKPzaUvfLUzae52pIyiQ+RXWd1AWuE2QXY7Q== 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 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. As enable_mpu() is invoked from enable_boot_cpu_mm(), one needs to save and restore the lr. Signed-off-by: Ayan Kumar Halder 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 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(). 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) +/* + * 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. @@ -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 /* Get the number of regions specified in MPUIR_EL2 */ mrs x5, MPUIR_EL2 @@ -110,8 +134,10 @@ FUNC(enable_boot_cpu_mm) ldr x2, =__bss_end prepare_xen_region x0, x1, x2, x3, x4, x5 - ret + bl enable_mpu + mov lr, x6 + ret END(enable_boot_cpu_mm) /* diff --git a/xen/arch/arm/include/asm/arm64/mpu/sysregs.h b/xen/arch/arm/include/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 +/* Backgroud region enable/disable */ +#define SCTLR_ELx_BR BIT(17, UL) + #endif /* __ASM_ARM_ARM64_MPU_SYSREGS_H */ /* From patchwork Mon Oct 28 12:45:47 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: 13853447 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 4D2EAD1039A for ; Mon, 28 Oct 2024 12:46:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.826452.1240735 (Exim 4.92) (envelope-from ) id 1t5P8m-00065b-JN; Mon, 28 Oct 2024 12:46:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 826452.1240735; Mon, 28 Oct 2024 12:46:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t5P8m-00065Q-FL; Mon, 28 Oct 2024 12:46:36 +0000 Received: by outflank-mailman (input) for mailman id 826452; Mon, 28 Oct 2024 12:46:35 +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 1t5P8l-00050g-12 for xen-devel@lists.xenproject.org; Mon, 28 Oct 2024 12:46:35 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2061a.outbound.protection.outlook.com [2a01:111:f403:2406::61a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a965d574-952a-11ef-a0c2-8be0dac302b0; Mon, 28 Oct 2024 13:46:34 +0100 (CET) Received: from MW4PR04CA0245.namprd04.prod.outlook.com (2603:10b6:303:88::10) by DS0PR12MB7802.namprd12.prod.outlook.com (2603:10b6:8:145::5) 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:31 +0000 Received: from BL6PEPF00022574.namprd02.prod.outlook.com (2603:10b6:303:88:cafe::9a) by MW4PR04CA0245.outlook.office365.com (2603:10b6:303:88::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23 via Frontend Transport; Mon, 28 Oct 2024 12:46:30 +0000 Received: from SATLEXMB03.amd.com (165.204.84.17) by BL6PEPF00022574.mail.protection.outlook.com (10.167.249.42) 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:30 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) 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, 28 Oct 2024 07:46:30 -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:29 -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:28 -0500 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a965d574-952a-11ef-a0c2-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=utYT/0/qj3Y5kKAeBTKBkaobdm9di9wZ6AL4r1e98rLqo8jMasPm39+cv0A7gcq72dxJY2HHL+Qs26W0Figbgn3EMhcI3/CqOJX2PBPiBxp4qEat17jTJxmyfsmCDPVkTfN9Ebf/lSgAaZ9CT8D5qNzIFFOPGF1tm41vuoO0inwrxmduGPxbn8Fbyxj8Ry92PvUycwnshopdK3iBT+SJzer+3hiNSS5na+3NwauNQe4CxsDU6rd34bIjFGVmq8jmj+t1QdsrR8LHwK6IZU290jeDa+fcDUfXiBEkuDnH8s636+qDDy+ClP3pn1ZrDv3oFiPQSnCC3+3vklJfhHRJlw== 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=E4ilOMJ0iLFTChx6I4m08V3KKvqq6Suvoj0IUas/+dk=; b=JYsAo6pMSsfH6oKIT+t8oa6d/CiV9K6hO0R5jgx7Bq17pA70QNunhRsBR80Csn9Hejy1tnTSBglQvlV7dBsSjUXZY9HtTDCbhxwtpCpi+xTfmDxPPS3PBv4mi7vAHCTatkDWc7nDrIKAU8wIJeDR8HnWumwtOcyZXBJmABpu9KdHg6CUqqmUaKAi2TXYIThI+A2qd0I9TkaBNLFg1wzMoh3plOLeds9JpR4i98w6qmzcbtMZqL/gkiyF38O8mPeFDM4o1XfD4RUGBHOKKTZTr1XpZUTTP/aksb7BAViC92QGG82T9lk91ccVM2ZhiBjqPKVvD8lidVbEtfE9M7riPQ== 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=E4ilOMJ0iLFTChx6I4m08V3KKvqq6Suvoj0IUas/+dk=; b=lZhITCuqQZOJ5XeQFfP6q0oPYrMLis3i+TYjv0lf0zCsZT5Mogry6bamTkcrhDicwu7tD2ky/VprbZJjjUQi4XqngWch+LwmiQ5ZlkbHRLn+Bs31S2HoHarEIHwTtI66DsiDddk/UsMWHUiMoGv0vfn/GSecfXV2uZN2Itv96+g= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; pr=C From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , "Bertrand Marquis" , Michal Orzel , Volodymyr Babchuk Subject: [PATCH v4 6/6] xen/arm: mpu: Implement a dummy enable_secondary_cpu_mm Date: Mon, 28 Oct 2024 12:45:47 +0000 Message-ID: <20241028124547.1371867-7-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 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF00022574:EE_|DS0PR12MB7802:EE_ X-MS-Office365-Filtering-Correlation-Id: a2d27b14-c259-4f8a-90b5-08dcf74e8be0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: RmhAJoKWcSepcARtEC+MOLVdyHdtUItooXLteO87lYEHMUEhnh6M7tZHZr95aOHZ70QEG9RaBEx+OghUXygN6eMp6HNt+dZ1fEA86eUfvhaf9az6RnZb8hBdRnAvpssN32DN9xQq30KneQAxDP3aAGPRbCAqi3bih23sXAbxFOLyO7iSYcconYUwSatgr9kMt/yWChajte49pfxGQ6QShuZidf96RtJDXW6NFACZuNNzPHDgsFgXNEvAxEEPW1b1gAG1kXxKlmhGM1e+fEtvOVhGVkKNmIU0ggqVKRD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gR3B6QSQqKyqO2Lix49bRG/dlSIWlwE/Kr/oZMJVabLGIfHw== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 12:46:30.5246 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2d27b14-c259-4f8a-90b5-08dcf74e8be0 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF00022574.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7802 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 --- 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. 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..aa383577a4 100644 --- a/xen/arch/Kconfig +++ b/xen/arch/Kconfig @@ -6,11 +6,13 @@ 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 "8" if ARM && RCAR3 default "4" if ARM && QEMU default "4" if ARM && MPSOC + default "1" if ARM && MPU default "128" if ARM help Controls the build-time size of various arrays and bitmaps diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S index 0edadb009c..5a6aaf47cd 100644 --- a/xen/arch/arm/arm64/mpu/head.S +++ b/xen/arch/arm/arm64/mpu/head.S @@ -140,6 +140,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. */