From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 32F90C4167B for ; Wed, 29 Nov 2023 11:19:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ykhP4nvQ5JNAcR5rXONcoYBcodX09qRRMhA8a4N0Ots=; b=PwG2IDJmNhrdrABb3uK+UJHGM7 0tMqMD8FytQFPCW0MsiU/b13Xtl/AfZyk5/MepaQDqwCa1q+cIjri43Ph5Tji62nYpS6OY12Zj2Dn 5oTA+nNnOTaxoIch3WbIolO/5wy234JqABYW7wjXB6Hey2QcFrM+gA32O/oUSlxzoXW3QLTObpjPS bGbJVADKLIhNKx+o4Df0eYHQJNnyV4l0Giz5/Byufam6NN4+W5Hb3Ked31vN2a0VB+9hBWFGouiXd bIqP1AzOTQNJzISqGunRsUU0eMIG72oqAjIyXscEVtIT6vEYpmCt/r2qa1OB4puVEi5G7eTeHMJQ8 SYNAx1Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8Iaz-0080Vu-2Z; Wed, 29 Nov 2023 11:19:09 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8IaW-008067-1B for linux-arm-kernel@bombadil.infradead.org; Wed, 29 Nov 2023 11:18:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=5o3FoAeOgv0c5YT0d3WVZLtLTtxqJ3TLMBpE03N02zk=; b=sThiZmmr6M+mVOVTg8R3kyfqkM PCohQyfLH3xMlkNFcG9lQwgP4QQuCOp585rpA7AjZchK9Mx4llpoDp9XbAIuejxI2NcXsdebcS4ah vCXxd8tSkRpBSsSmu3pcCJ6VffpAcm7RO6AVgi1pNybVvd+jpLhd5ffn3yvzB9X5rYci9LF2ADJQJ bjoxq3r95AzsBNEdDjgY8sYA8BsO3Sjngo8kVM9o7PMp378Ww923/oa6A7p7msaIPc+0JN715DdHw hOqmWbHOuFSTa+FXonXA3+uZIkDI3u3QJb+AvWAYuCi0eSVscq4XM/KGSEAhENoNDjaV33jCQmQzz CkfaVdow==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1r8IaR-00DKQX-1Z for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 11:18:38 +0000 Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-33303db14d9so2199850f8f.1 for ; Wed, 29 Nov 2023 03:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701256711; x=1701861511; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5o3FoAeOgv0c5YT0d3WVZLtLTtxqJ3TLMBpE03N02zk=; b=e6+1vjryyyZ9yrMd/GfF8igU5x5L+hF22PLW5uPChD4QvZOCUUClwIB+75utIszr8J S5Ip4g6+knUis+BtBGV3uu/8zngKa6Uoh9scwJyzH+dOP9JUg0XRNscrDwxz9ZahlaGT lVzkacJoSsghnr9ulYxZcGxauzxSFfm+8JKABmYK2KzdJaOARpYP+pFQZp0xsOVRM23a 3UZkj6OqoF135GYI/Y8ppeqwO9lka9s6nj/rGKvGqukbnwIELBjHk+qJpcvwmr5YkGJk 3sNFOPAT275hi95ntUIsw4Z2XD6BJEWFjk47FxH39DFkfkmlzznCasgtpMBjYqbGtwi8 vRfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701256711; x=1701861511; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5o3FoAeOgv0c5YT0d3WVZLtLTtxqJ3TLMBpE03N02zk=; b=EkdXMIcv97OEr3sMjNNpgZ9GSzCtjH21MUrjKL1uhhWQgMxD423FDVsiM0RYJBtIVE O+GRX9RchHLrHm6kVJbqCawwD7X8WZjulZuhYNYuL8/OoRVF7QaSC4KA7c43wGg0XblA Pm/SgRa6kfxmLpZVL5xhJFqhuTZjho3Iy2BQUephbaeokdrEwfk9GeMCNKNCU8EJQZsn TvUWnqgrQgd4eL2zPP740WC0sIkKZSzAERJoWJ5r6x8GJ+ayOrudswssIsD+UVUbjcm0 k1eTY5Hc9h3Ei2CgYuPTWlxENueR38//Ln0hnVz7NF/3FJOojsAf5tRz0itLezagVQsB 9A6A== X-Gm-Message-State: AOJu0YxHkpVHUoZHb9VrCXI/1rFD7O1pBLlYDuvArhoRXVyGH+8hqrv0 27gd2+tW7eircLi9FehAMYLSWtJt8Il3RUmR9DMTRlX4DdNoZwK6QYs0gxw2x+hRNuNzWxWEdBT h2TqI8/wFB7hhC2pbvNpFC+/T/i+JWBzkmr62Iyo1ODkB5m+hLkK/uOwdN2NK0Cqm9VHRC9Piix E= X-Google-Smtp-Source: AGHT+IEiZ+SgQ3TZe0wpKe0mMninnXJabZsCyTRLWrpTaWqzLk6KetdEQ/J0idqhj3aXdtsRsD4SwTnL X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:9c82:0:b0:332:f889:39f8 with SMTP id d2-20020adf9c82000000b00332f88939f8mr205049wre.3.1701256711439; Wed, 29 Nov 2023 03:18:31 -0800 (PST) Date: Wed, 29 Nov 2023 12:16:29 +0100 In-Reply-To: <20231129111555.3594833-43-ardb@google.com> Mime-Version: 1.0 References: <20231129111555.3594833-43-ardb@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5079; i=ardb@kernel.org; h=from:subject; bh=h/fPNLFPKmdAqPP051jhtIRK6N3d3dxplZSoyq7GqHg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JITVddqJw74ttnQeur1qgfaHPI5TL5SHPbNsy0xWC61NN5 ZJMPjB1lLIwiHEwyIopsgjM/vtu5+mJUrXOs2Rh5rAygQxh4OIUgIl43GP4Hz85eeMV1u0SL7u/ p/E31dc2fVGMvS7rtXhJltqq7NfVXIwMa6bed9JK+GbDUNJa22CwW3JRFuea/hPVPfa6bh01pkW MAA== X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231129111555.3594833-76-ardb@google.com> Subject: [PATCH v6 33/41] arm64: mm: Make kaslr_requires_kpti() a static inline From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_111835_178569_8EA4816F X-CRM114-Status: GOOD ( 22.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel In preparation for moving the first assignment of arm64_use_ng_mappings to an earlier stage in the boot, ensure that kaslr_requires_kpti() is accessible without relying on the core kernel's view on whether or not KASLR is enabled. So make it a static inline, and move the kaslr_enabled() check out of it and into the callers, one of which will disappear in a subsequent patch. Once/when support for the obsolete ThunderX 1 platform is dropped, this check reduces to a E0PD feature check on the local CPU. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/mmu.h | 38 +++++++++++++++++- arch/arm64/kernel/cpufeature.c | 42 +------------------- arch/arm64/kernel/setup.c | 2 +- 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/arch/arm64/include/asm/mmu.h b/arch/arm64/include/asm/mmu.h index 2fcf51231d6e..d0b8b4b413b6 100644 --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -71,7 +71,43 @@ extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, pgprot_t prot, bool page_mappings_only); extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot); extern void mark_linear_text_alias_ro(void); -extern bool kaslr_requires_kpti(void); + +/* + * This check is triggered during the early boot before the cpufeature + * is initialised. Checking the status on the local CPU allows the boot + * CPU to detect the need for non-global mappings and thus avoiding a + * pagetable re-write after all the CPUs are booted. This check will be + * anyway run on individual CPUs, allowing us to get the consistent + * state once the SMP CPUs are up and thus make the switch to non-global + * mappings if required. + */ +static inline bool kaslr_requires_kpti(void) +{ + /* + * E0PD does a similar job to KPTI so can be used instead + * where available. + */ + if (IS_ENABLED(CONFIG_ARM64_E0PD)) { + u64 mmfr2 = read_sysreg_s(SYS_ID_AA64MMFR2_EL1); + if (cpuid_feature_extract_unsigned_field(mmfr2, + ID_AA64MMFR2_EL1_E0PD_SHIFT)) + return false; + } + + /* + * Systems affected by Cavium erratum 24756 are incompatible + * with KPTI. + */ + if (IS_ENABLED(CONFIG_CAVIUM_ERRATUM_27456)) { + extern const struct midr_range cavium_erratum_27456_cpus[]; + + if (is_midr_in_range_list(read_cpuid_id(), + cavium_erratum_27456_cpus)) + return false; + } + + return true; +} #define INIT_MM_CONTEXT(name) \ .pgd = init_pg_dir, diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 889411f87e90..39f5df0773cb 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1649,46 +1649,6 @@ has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) return has_cpuid_feature(entry, scope); } -/* - * This check is triggered during the early boot before the cpufeature - * is initialised. Checking the status on the local CPU allows the boot - * CPU to detect the need for non-global mappings and thus avoiding a - * pagetable re-write after all the CPUs are booted. This check will be - * anyway run on individual CPUs, allowing us to get the consistent - * state once the SMP CPUs are up and thus make the switch to non-global - * mappings if required. - */ -bool kaslr_requires_kpti(void) -{ - if (!IS_ENABLED(CONFIG_RANDOMIZE_BASE)) - return false; - - /* - * E0PD does a similar job to KPTI so can be used instead - * where available. - */ - if (IS_ENABLED(CONFIG_ARM64_E0PD)) { - u64 mmfr2 = read_sysreg_s(SYS_ID_AA64MMFR2_EL1); - if (cpuid_feature_extract_unsigned_field(mmfr2, - ID_AA64MMFR2_EL1_E0PD_SHIFT)) - return false; - } - - /* - * Systems affected by Cavium erratum 24756 are incompatible - * with KPTI. - */ - if (IS_ENABLED(CONFIG_CAVIUM_ERRATUM_27456)) { - extern const struct midr_range cavium_erratum_27456_cpus[]; - - if (is_midr_in_range_list(read_cpuid_id(), - cavium_erratum_27456_cpus)) - return false; - } - - return kaslr_enabled(); -} - static bool __meltdown_safe = true; static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ @@ -1741,7 +1701,7 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, } /* Useful for KASLR robustness */ - if (kaslr_requires_kpti()) { + if (kaslr_enabled() && kaslr_requires_kpti()) { if (!__kpti_forced) { str = "KASLR"; __kpti_forced = 1; diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 4b0b3515ee20..c2d6852a4e0c 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -288,7 +288,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) * mappings from the start, avoiding the cost of rewriting * everything later. */ - arm64_use_ng_mappings = kaslr_requires_kpti(); + arm64_use_ng_mappings = kaslr_enabled() && kaslr_requires_kpti(); early_fixmap_init(); early_ioremap_init(); -- 2.43.0.rc1.413.gea7ed67945-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel