From patchwork Wed Aug 21 12:25:03 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: 13771329 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 0EA00C52D6F for ; Wed, 21 Aug 2024 12:25:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.781075.1190665 (Exim 4.92) (envelope-from ) id 1sgkP8-0005iW-Pr; Wed, 21 Aug 2024 12:25:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 781075.1190665; Wed, 21 Aug 2024 12:25: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 1sgkP8-0005ho-MV; Wed, 21 Aug 2024 12:25:34 +0000 Received: by outflank-mailman (input) for mailman id 781075; Wed, 21 Aug 2024 12:25: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 1sgkP7-0004Qc-Ag for xen-devel@lists.xenproject.org; Wed, 21 Aug 2024 12:25:33 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062c.outbound.protection.outlook.com [2a01:111:f403:2417::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 75181d4c-5fb8-11ef-a508-bb4a2ccca743; Wed, 21 Aug 2024 14:25:32 +0200 (CEST) Received: from PH8PR22CA0008.namprd22.prod.outlook.com (2603:10b6:510:2d1::20) by IA1PR12MB6649.namprd12.prod.outlook.com (2603:10b6:208:3a2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Wed, 21 Aug 2024 12:25:25 +0000 Received: from SN1PEPF000397AF.namprd05.prod.outlook.com (2603:10b6:510:2d1:cafe::c8) by PH8PR22CA0008.outlook.office365.com (2603:10b6:510:2d1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17 via Frontend Transport; Wed, 21 Aug 2024 12:25:25 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF000397AF.mail.protection.outlook.com (10.167.248.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Wed, 21 Aug 2024 12:25:24 +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; Wed, 21 Aug 2024 07:25:24 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Wed, 21 Aug 2024 07:25:23 -0500 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; Wed, 21 Aug 2024 07:25:22 -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: 75181d4c-5fb8-11ef-a508-bb4a2ccca743 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oudwCcprACAl0tUB4KWWBiBMhqr1PW9mBLxwggayDPkUnYZ/WX7kEy/fKl/P2s1Kq7ovvspxAp4NMbILjCkFuu5WYbW6mUooklom3INTeBN8OxE62kxe96Nsc9eWpXYLNx3xHTB5IhIE1jT4YS+HnuVhJ7cb/qA5lWYIi8Kxxm8J2XfA3svPjZe+iKGg5BCROqBwyoht0miUeLjLzuRirn0VlcMaRD9pBzN6agr72ziWfXpoxcwFi6aAYfIQ1TKffwQIMJNr9toNfKe0MGhALlfN+/8CYrUBfVgmKqs9SS20N7XoHimdnNRzNTJaqhewoqBN1C73Px+5pQXa8mzWhg== 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=3qR+j28zT01ixWDL3qZTBCcQC9zkoG5HXJead8PRpjI=; b=g9WqkLpVQnmUmlpqByNztJwHBux1iwX3GOctPodUUtpHDg8P6iPMvaGS7vpBB3N6bOpBCJv2v7yGVzMjYMSOB8EpgiSCx6s2/LNW+s7ws4pIpS7gRoPtgFIrQmKhbKNb5Q7GUfQSF3TIcvWOlFWSNvri7l2jV422fcgFPtytX69oBpB1RJmdMUaBL8frcRKht/tSX/ojqQhDp9k+qB5nbG4vd4/pddXrRC/yJw0+8hcQUGemCqe2C4t5oo7vpXKQWb+HFarrg6x2P1myqpz8i68wx3wqsLOW+Q6cV3EWPtJSJzAiNaCi9hz0sY1i24zg+ms/qAXV47yD/VNPQ5QQQw== 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=3qR+j28zT01ixWDL3qZTBCcQC9zkoG5HXJead8PRpjI=; b=0nUU3col59qbLpOgIHs09UPkmHMvN2FOWdnzr1QLvhH3T15X0gczOI5Et4bBVQ0/7aTxTsU6R19HR8b8Ur3KaLEG8iXF4es6B6x2GyRU3rB4CBWJjBV5baw3wb1lIgnaymLyYiJGWHiGaTXLA/vWm+H8YOxm1yyQ5/MR8BpObQw= 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: Penny Zheng , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Andrew Cooper , Jan Beulich , Shawn Anastasio , Alistair Francis , Bob Eshleman , "Connor Davis" , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Chen , Ayan Kumar Halder Subject: [PATCH] xen: make VMAP support in MMU system only Date: Wed, 21 Aug 2024 13:25:03 +0100 Message-ID: <20240821122503.2315844-5-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240821122503.2315844-1-ayan.kumar.halder@amd.com> References: <20240821122503.2315844-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000397AF:EE_|IA1PR12MB6649:EE_ X-MS-Office365-Filtering-Correlation-Id: 071592b1-1352-4fce-61e6-08dcc1dc5544 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: Qsi/YYQT2lBz9iFT1oJQH0xkb1rGJrLJ4wxuZ+qdbV759XtlLA5c8P0/XlF67VOZs1Eq6h3S9Y+Negq2Y6WfJaVJ+1XxCqLIwXM653/9yKUC5isAGBfZ3lHHk6/0mECSeiUqPPQt9tptzOeRruHj86OsOND4zHoS/5ptqU9mlEKToEYJ6m8z4LgJvHzUeNDhApvk2HBCu8s586wXn+VYk4KggfaZ3RMhOSTYfv6PsHEeaoURCQivgVFnUf2/HQEJaJH5+sDPuGLY7iqnqtjX67HgLnVctzIJphLKmNuPqwA0mcTnzPtskcCi0YMdikLzOU+bBi3NqT2M+5sn4e0iFzVms2q8ZUI5EcQyER9xFVYxymYdHzF0tb3n+7H9mJvm2/jGCTtpYUoX4au23sa6hD+8YKj//DgUdDYCTt1T9H/joYR8jQKfCNndjbaes63rmwjA02oPiIJanJba1N+fE3npaPq2kFSIvB1+oRUKoHh5fPt4R6x0wS/GEyWt/ALw8cT1c7lE2QbUD7yf3m9e1rZ4f9GItZnXd+N6F298TMMaRR9AquHq+nG5urdmOvI+56jIjd+h4RTG1fo+lEohEz1yPYKC8I4r1HmN8VapwYRdw57J/06RCCO+uVY3oLqwQR9DF87LWbDYeclc7huNAF5LyvWn+HypeyDaiAqdjvA7LDAHNtGOFVJYqbe9ThWclLEJbYsyTn19dPWpKonjadOTP0zNVhWNFtYdWh/eqBIvHyFVbZuGE5Ti7IxJRAiM9c6H/NdDZrxzTzSCU4sgax4cTUXmE7hDMZa/zkE6RocT6pIqjcbKZltyaiMBucZPGqb+MReSvsztR90St9SosSa3RxIKNqhE7HBeq0o/h7TYG2dnZIj2CLPg9xOue9DZ2boO/U0LH74ju4KxWzJuEklPwTKO4LNq5+c//YniNUM2WYJU0589g3ATpROHtb2G6Q4jBNgn95RjlWi0B1pWgctfOwWlOONXF/un9n7apghpIaCSqkTlCCmWgUEfmFtcvUE67q924dIvVWWiBzlnVQ96DcXX6wc4ofi+58iFENCx30W/vtilDN3vF6rx4B9Eyi2PNjXErKslXcxv3jKUsZhJEY6F6hcn/fVY73Ec0F8Ixj2oxFcrEoviXqQkDCofmTW9T3dgHiy9Tl8yoIEhJaiCi72OWVnVp3vbqKiCGUzR3RZ/6LSBIGu11w6s36WChbZxUMWZ8mnUbUmCOtqX80XIzeM5sWRdqV1+JPjQLHNa5fLmzMMD//0AuAPE3UYE/2rY/vmFZU7Y0Bc7oROxvnxvbGq4r97RZsDj3iIcYW7vubg/39zbOPGivNao8jDuf4cF4cWNqmdFcUGPIqCl/vjz1n0UL8oDxa+tcfGbwE8zfuqTz/OT+oQ0J74+UUnsh3prfntXPxAcOY+M6LPalw== 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)(36860700013)(82310400026)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 12:25:24.6497 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 071592b1-1352-4fce-61e6-08dcc1dc5544 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: SN1PEPF000397AF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6649 From: Penny Zheng Introduce CONFIG_VMAP which is selected by the architectures that use MMU. vm_init() does not do anything if CONFIG_VMAP is not enabled. VMAP is widely used in ALTERNATIVE feature to remap a range of memory with new memory attributes. Since this is highly dependent on virtual address translation, we choose to fold VMAP in MMU system. In this patch, we introduce a new Kconfig CONFIG_HAS_VMAP, and make it only support in MMU system on ARM architecture. And ALTERNATIVE now depends on VMAP. HARDEN_BRANCH_PREDICTOR is now gated on MMU as speculative attacks are not possible on non MMU based systems (ie Cortex-R52, R82). See https://developer.arm.com/Arm%20Security%20Center/Speculative%20Processor%20Vulnerability. Also took the opportunity to remove "#ifdef VMAP_VIRT_START .. endif" from vmap.c. Instead vmap.c is compiled when HAS_VMAP is enabled. Thus, HAS_VMAP is now enabled from x86, ppc and riscv architectures as all of them use MMU and has VMAP_VIRT_START defined. Signed-off-by: Penny Zheng Signed-off-by: Wei Chen Signed-off-by: Ayan Kumar Halder Acked-by: Julien Grall --- Changes from :- v1 - 1. HARDEN_BRANCH_PREDICTOR is now gated on HAS_VMAP. 2. cpuerrata.c is not gated on HAS_VMAP. v2 - 1. Introduced CONFIG_VMAP in common/Kconfig. 2. Architectures using MMU select this config. 3. vm_init() now uses CONFIG_VMAP. v3 - 1. HARDEN_BRANCH_PREDICTOR is now gated on MMU. 2. vmap.c is compiled when CONFIG_HAS_VMAP is enabled. 3. HAS_VMAP is enabled from x86, ppc and riscv architectures. xen/arch/arm/Kconfig | 4 +++- xen/arch/arm/setup.c | 2 ++ xen/arch/ppc/Kconfig | 1 + xen/arch/riscv/Kconfig | 1 + xen/arch/x86/Kconfig | 1 + xen/common/Kconfig | 3 +++ xen/common/Makefile | 2 +- xen/common/vmap.c | 2 -- xen/include/xen/vmap.h | 2 ++ 9 files changed, 14 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index 21d03d9f44..323c967361 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -12,7 +12,7 @@ config ARM_64 config ARM def_bool y select FUNCTION_ALIGNMENT_4B - select HAS_ALTERNATIVE + select HAS_ALTERNATIVE if HAS_VMAP select HAS_DEVICE_TREE select HAS_PASSTHROUGH select HAS_UBSAN @@ -61,6 +61,7 @@ config PADDR_BITS config MMU def_bool y select HAS_PMAP + select HAS_VMAP source "arch/Kconfig" @@ -171,6 +172,7 @@ config ARM_SSBD config HARDEN_BRANCH_PREDICTOR bool "Harden the branch predictor against aliasing attacks" if EXPERT + depends on MMU default y help Speculation attacks against some high-performance processors rely on diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index cb2c0a16b8..7f686d2cca 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -447,7 +447,9 @@ void asmlinkage __init start_xen(unsigned long boot_phys_offset, * It needs to be called after do_initcalls to be able to use * stop_machine (tasklets initialized via an initcall). */ +#ifdef CONFIG_HAS_ALTERNATIVE apply_alternatives_all(); +#endif enable_errata_workarounds(); enable_cpu_features(); diff --git a/xen/arch/ppc/Kconfig b/xen/arch/ppc/Kconfig index f6a77a8200..6db575a48d 100644 --- a/xen/arch/ppc/Kconfig +++ b/xen/arch/ppc/Kconfig @@ -2,6 +2,7 @@ config PPC def_bool y select FUNCTION_ALIGNMENT_4B select HAS_DEVICE_TREE + select HAS_VMAP config PPC64 def_bool y diff --git a/xen/arch/riscv/Kconfig b/xen/arch/riscv/Kconfig index 259eea8d3b..7a113c7774 100644 --- a/xen/arch/riscv/Kconfig +++ b/xen/arch/riscv/Kconfig @@ -3,6 +3,7 @@ config RISCV select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME select HAS_DEVICE_TREE + select HAS_VMAP config RISCV_64 def_bool y diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 7ef5c8bc48..1784f01aad 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -29,6 +29,7 @@ config X86 select HAS_PIRQ select HAS_SCHED_GRANULARITY select HAS_UBSAN + select HAS_VMAP select HAS_VPCI if HVM select NEEDS_LIBELF diff --git a/xen/common/Kconfig b/xen/common/Kconfig index 565ceda741..90268d9249 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -83,6 +83,9 @@ config HAS_SCHED_GRANULARITY config HAS_UBSAN bool +config HAS_VMAP + bool + config MEM_ACCESS_ALWAYS_ON bool diff --git a/xen/common/Makefile b/xen/common/Makefile index 7e66802a9e..fc52e0857d 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -52,7 +52,7 @@ obj-$(CONFIG_TRACEBUFFER) += trace.o obj-y += version.o obj-y += virtual_region.o obj-y += vm_event.o -obj-y += vmap.o +obj-$(CONFIG_HAS_VMAP) += vmap.o obj-y += vsprintf.o obj-y += wait.o obj-bin-y += warning.init.o diff --git a/xen/common/vmap.c b/xen/common/vmap.c index ced9cbf26f..47225fecc0 100644 --- a/xen/common/vmap.c +++ b/xen/common/vmap.c @@ -1,4 +1,3 @@ -#ifdef VMAP_VIRT_START #include #include #include @@ -427,4 +426,3 @@ void *_xvrealloc(void *va, size_t size, unsigned int align) return ptr; } -#endif diff --git a/xen/include/xen/vmap.h b/xen/include/xen/vmap.h index fdae37e950..c1dd7ac22f 100644 --- a/xen/include/xen/vmap.h +++ b/xen/include/xen/vmap.h @@ -141,7 +141,9 @@ void *arch_vmap_virt_end(void); /* Initialises the VMAP_DEFAULT virtual range */ static inline void vm_init(void) { +#ifdef CONFIG_HAS_VMAP vm_init_type(VMAP_DEFAULT, (void *)VMAP_VIRT_START, arch_vmap_virt_end()); +#endif } #endif /* __XEN_VMAP_H__ */