From patchwork Fri Jan 7 19:43:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 12707010 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 9BECEC433F5 for ; Fri, 7 Jan 2022 19:45:25 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l90SdDXi3wW6sMHCSVQE2wYqJA/iJrKymNcz7yn8QyI=; b=oYqMger5iZ3Ov+ MSU+EDGxoKu1kUZJQsXAugUZjD13twXtEvtWXcrD5pD457tcqwzcZykByu4Hzv4nDaBj6mFVOvLZ/ 12Yv+kYaDgQr04GJuIv0GnWV5JhKCk17vdZ2q6rLyLwHdx4zT6uwKozWWMYtzsovZUPpOmOZ2fO0p isUK0AYBAwKo0jEVdPAwVpNliaQ3hZjtmDWBpPT9p516m9YgF9fFZXXIXvtht3eNdEQtZMfsuX31/ MqTUKybX9/otTIPO7J1LVM0jqksMRLEuAuP/9zZYYv6j+kbyzHNpuJ5Own6LyWFX9L02l0lIubeTy 6qiXe+JpZjfCXVG7LmoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9l-0056MO-8Z; Fri, 07 Jan 2022 19:44:09 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9b-0056JL-Dn for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 19:44:01 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 14878B82767; Fri, 7 Jan 2022 19:43:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB022C36AF4; Fri, 7 Jan 2022 19:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641584636; bh=3/20dWOwwSNZJBhLqL6LA9DAw+PK6AmauF9/RAJDr8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kJIvwmZqos7K7pa1InpJaYEK4SDmiJmjsPxdzESJqAZawqFXeZp/R0CVGKQuqoo+e HL0eVs9g/5Ff2dqjjwcqirUvEXHqBZ265xFbpqde7EaGON/X2jfTDHJD/+MMxEp/mb SCOYJjOIrT0PhafvgGYz2Igie681WIg0MHSGOt+34o2sbB9MdpaXskCFJbKYKkGMwt onAiUQNC2HrzjrKWGFynz6b70h7+kTPayinYNm5w/etkS58a07dQjS5D/PtdL0eSVA w9oVc3XgZt2W0lJV2JWt0tl9BMz9mPqbiUBiA9QF0m1lNFsAZNbWktK+J1Ku6Rh4Gn FXrtpPegg1hag== From: Nathan Chancellor To: Greg Kroah-Hartman , Sasha Levin , Catalin Marinas , Will Deacon Cc: Mark Rutland , Marc Zyngier , Nick Desaulniers , linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH RFC 4.9 1/5] bug: split BUILD_BUG stuff out into Date: Fri, 7 Jan 2022 12:43:31 -0700 Message-Id: <20220107194335.3090066-2-nathan@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107194335.3090066-1-nathan@kernel.org> References: <20220107194335.3090066-1-nathan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_114359_776023_BECBE0E2 X-CRM114-Status: GOOD ( 29.11 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ian Abbott commit bc6245e5efd70c41eaf9334b1b5e646745cb0fb3 upstream. Including pulls in a lot of bloat from and that is not needed to call the BUILD_BUG() family of macros. Split them out into their own header, . Also correct some checkpatch.pl errors for the BUILD_BUG_ON_ZERO() and BUILD_BUG_ON_NULL() macros by adding parentheses around the bitfield widths that begin with a minus sign. Link: http://lkml.kernel.org/r/20170525120316.24473-6-abbotti@mev.co.uk Signed-off-by: Ian Abbott Acked-by: Michal Nazarewicz Acked-by: Kees Cook Cc: Steven Rostedt Cc: Peter Zijlstra Cc: Jakub Kicinski Cc: Rasmus Villemoes Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [nathan: Just take this patch, not the checkpatch.pl patches before it] Signed-off-by: Nathan Chancellor --- include/linux/bug.h | 72 +-------------------------------- include/linux/build_bug.h | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 71 deletions(-) create mode 100644 include/linux/build_bug.h diff --git a/include/linux/bug.h b/include/linux/bug.h index 0faae96302bd..eafb6213e582 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -3,6 +3,7 @@ #include #include +#include enum bug_trap_type { BUG_TRAP_TYPE_NONE = 0, @@ -13,80 +14,9 @@ enum bug_trap_type { struct pt_regs; #ifdef __CHECKER__ -#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) -#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) -#define BUILD_BUG_ON_ZERO(e) (0) -#define BUILD_BUG_ON_NULL(e) ((void*)0) -#define BUILD_BUG_ON_INVALID(e) (0) -#define BUILD_BUG_ON_MSG(cond, msg) (0) -#define BUILD_BUG_ON(condition) (0) -#define BUILD_BUG() (0) #define MAYBE_BUILD_BUG_ON(cond) (0) #else /* __CHECKER__ */ -/* Force a compilation error if a constant expression is not a power of 2 */ -#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \ - BUILD_BUG_ON(((n) & ((n) - 1)) != 0) -#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ - BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) - -/* Force a compilation error if condition is true, but also produce a - result (of value 0 and type size_t), so the expression can be used - e.g. in a structure initializer (or where-ever else comma expressions - aren't permitted). */ -#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) -#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) - -/* - * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the - * expression but avoids the generation of any code, even if that expression - * has side-effects. - */ -#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) - -/** - * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied - * error message. - * @condition: the condition which the compiler should know is false. - * - * See BUILD_BUG_ON for description. - */ -#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) - -/** - * BUILD_BUG_ON - break compile if a condition is true. - * @condition: the condition which the compiler should know is false. - * - * If you have some code which relies on certain constants being equal, or - * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to - * detect if someone changes it. - * - * The implementation uses gcc's reluctance to create a negative array, but gcc - * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to - * inline functions). Luckily, in 4.3 they added the "error" function - * attribute just for this type of case. Thus, we use a negative sized array - * (should always create an error on gcc versions older than 4.4) and then call - * an undefined function with the error attribute (should always create an - * error on gcc 4.3 and later). If for some reason, neither creates a - * compile-time error, we'll still have a link-time error, which is harder to - * track down. - */ -#ifndef __OPTIMIZE__ -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) -#else -#define BUILD_BUG_ON(condition) \ - BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) -#endif - -/** - * BUILD_BUG - break compile if used. - * - * If you have some code that you expect the compiler to eliminate at - * build time, you should use BUILD_BUG to detect if it is - * unexpectedly used. - */ -#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") - #define MAYBE_BUILD_BUG_ON(cond) \ do { \ if (__builtin_constant_p((cond))) \ diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h new file mode 100644 index 000000000000..b7d22d60008a --- /dev/null +++ b/include/linux/build_bug.h @@ -0,0 +1,84 @@ +#ifndef _LINUX_BUILD_BUG_H +#define _LINUX_BUILD_BUG_H + +#include + +#ifdef __CHECKER__ +#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) (0) +#define BUILD_BUG_ON_ZERO(e) (0) +#define BUILD_BUG_ON_NULL(e) ((void *)0) +#define BUILD_BUG_ON_INVALID(e) (0) +#define BUILD_BUG_ON_MSG(cond, msg) (0) +#define BUILD_BUG_ON(condition) (0) +#define BUILD_BUG() (0) +#else /* __CHECKER__ */ + +/* Force a compilation error if a constant expression is not a power of 2 */ +#define __BUILD_BUG_ON_NOT_POWER_OF_2(n) \ + BUILD_BUG_ON(((n) & ((n) - 1)) != 0) +#define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ + BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) + +/* + * Force a compilation error if condition is true, but also produce a + * result (of value 0 and type size_t), so the expression can be used + * e.g. in a structure initializer (or where-ever else comma expressions + * aren't permitted). + */ +#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); })) +#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:(-!!(e)); })) + +/* + * BUILD_BUG_ON_INVALID() permits the compiler to check the validity of the + * expression but avoids the generation of any code, even if that expression + * has side-effects. + */ +#define BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) + +/** + * BUILD_BUG_ON_MSG - break compile if a condition is true & emit supplied + * error message. + * @condition: the condition which the compiler should know is false. + * + * See BUILD_BUG_ON for description. + */ +#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) + +/** + * BUILD_BUG_ON - break compile if a condition is true. + * @condition: the condition which the compiler should know is false. + * + * If you have some code which relies on certain constants being equal, or + * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to + * detect if someone changes it. + * + * The implementation uses gcc's reluctance to create a negative array, but gcc + * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to + * inline functions). Luckily, in 4.3 they added the "error" function + * attribute just for this type of case. Thus, we use a negative sized array + * (should always create an error on gcc versions older than 4.4) and then call + * an undefined function with the error attribute (should always create an + * error on gcc 4.3 and later). If for some reason, neither creates a + * compile-time error, we'll still have a link-time error, which is harder to + * track down. + */ +#ifndef __OPTIMIZE__ +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#else +#define BUILD_BUG_ON(condition) \ + BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) +#endif + +/** + * BUILD_BUG - break compile if used. + * + * If you have some code that you expect the compiler to eliminate at + * build time, you should use BUILD_BUG to detect if it is + * unexpectedly used. + */ +#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed") + +#endif /* __CHECKER__ */ + +#endif /* _LINUX_BUILD_BUG_H */ From patchwork Fri Jan 7 19:43:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 12707011 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 364EFC433F5 for ; Fri, 7 Jan 2022 19:45:31 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1wyANfAKqn7e7ZKV6gp1Rmmy12EYmkl9r4rRiH3cCYQ=; b=huL7H0k2GbF3Qm xrSLLpX97jJsMmpOc+TXa2fTLcZgT4fZERaviGpC9LkW6gQ3mmiJ0a1tv0AsOKFjHsi+xtPStcomK 0djo2q9HXv9Dl1XJVE+nEICJUgxd7XqFjTmU+HAPWcFRrpy85V4JJcsO1WzsnL/bAxDa2ApqGvhDl p0XynrZ1fKsGbjp2mewMSpPIE6ivvFhWc4p0+FVGXrsTVvO26L5RWYtWKhZTd/Lup4R1Q65Fc+utw 7465ONL6sw1CoxMSbQ/dzAwGp9jCO03iw7zADo9F8A7vb7QqEWjn2dAjYiL5sGgOY08zvGkxKW3qL 5LhKrpDNPWOe4T2U0SUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9u-0056OJ-Vn; Fri, 07 Jan 2022 19:44:19 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9c-0056Jl-NE for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 19:44:01 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED1C861EEC; Fri, 7 Jan 2022 19:43:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53217C36AE9; Fri, 7 Jan 2022 19:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641584639; bh=m61fuw1pNqrst7HLX3tjWWgGYWOPsNFFFghJhYPmSmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kbgPV3t8QrUmD2HnDIOaXpJIDDPm6qaXONETzG3lIat9eubaqXRAustox8oo0GtfW YRzJNxtvnJDXpsENKajOs0xiY1yRuRRDAN1KUuQ8pV5420B2iG2pVyPslI36nWvEqs UD/CTkBWE4duTwiFm4BdC67WFkqXcL8vmudiqBb4AKnlftH6Cwv1/Fq6WA+aR21sYA c4egkzXda5F++epcEqSYvKlffLED26LsdKZX4EeXXQZKWhglk+6EnWHfJSNjgjI3Bi 5TG+k/VVIg2XiBm0RiZDWZ0YUxwQAv+hKG/QMs0oEa5y4/mbLIvBu5tq0nHIpnn049 BiJutRHUN2wkw== From: Nathan Chancellor To: Greg Kroah-Hartman , Sasha Levin , Catalin Marinas , Will Deacon Cc: Mark Rutland , Marc Zyngier , Nick Desaulniers , linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH RFC 4.9 2/5] arm64: Remove a redundancy in sysreg.h Date: Fri, 7 Jan 2022 12:43:32 -0700 Message-Id: <20220107194335.3090066-3-nathan@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107194335.3090066-1-nathan@kernel.org> References: <20220107194335.3090066-1-nathan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_114400_821621_F5738040 X-CRM114-Status: GOOD ( 12.74 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Stefan Traby commit d38338e396ee0571b3502962fd2fbaec4d2d9a8f upstream. This is really trivial; there is a dup (1 << 16) in the code Acked-by: Will Deacon Signed-off-by: Stefan Traby Signed-off-by: Marc Zyngier Signed-off-by: Nathan Chancellor --- arch/arm64/include/asm/sysreg.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 88bbe364b6ae..7a9f0a71f441 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -95,8 +95,8 @@ #define SCTLR_ELx_M 1 #define SCTLR_EL2_RES1 ((1 << 4) | (1 << 5) | (1 << 11) | (1 << 16) | \ - (1 << 16) | (1 << 18) | (1 << 22) | (1 << 23) | \ - (1 << 28) | (1 << 29)) + (1 << 18) | (1 << 22) | (1 << 23) | (1 << 28) | \ + (1 << 29)) #define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ SCTLR_ELx_SA | SCTLR_ELx_I) From patchwork Fri Jan 7 19:43:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 12707012 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 9C177C433EF for ; Fri, 7 Jan 2022 19:45:42 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hIbASzqJaoqdfavZPtjkpHHA46BLjGxrnQ80IbxltYs=; b=pr4onaTK5IwRH5 hIcbDI8/UZNKxLG5QdijAsQl/SfqJ2SnAOmjvsc8OAUIR5O8UD4WitQxwZh3I8nxsLBRPuFexa5em lbh2sjzmGadqmyDiiai7VRPoYvu0BLqZKgEqol18nUfHXPyjjFs0K/g92V09MpJwOkmtsVF+lihT9 Bvif72FC6x3xq5/Z5FGrsV+jGatlXKKXSEPhYNOFu4VLlC1rrTTTx6kL2H4cYaA550GNhtxxbxxlG GSvBxYMxridiy03mZdd4/1RRU4GenYVRiB30axDwGD12rieKh5XQhLzM7pd3iSMhAQ0uI8cuS6FsJ HiSrkE/huW/ku04e8Pqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5vA4-0056R1-O3; Fri, 07 Jan 2022 19:44:28 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9e-0056KV-Nq for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 19:44:04 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1972061EEC; Fri, 7 Jan 2022 19:44:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CED73C36AF6; Fri, 7 Jan 2022 19:43:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641584641; bh=pUhhdPd+RzZRxCZiQKKatqdJiYDHPOjal68wgZclLUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gLcWua10BSWFs1tzn8R0O9LdAEPfjI2J/mCkZIYGMP1etayiU740tg8inPMM/9UAz 83L6chu71gxLPrNskNJHYeddudOhCqOCzkqSHmu/OVLrqaIVT5LIj6CMCb7zpIPvOP h5SFjTQyVPVch6CP0tWVRijt4oqP6IYQVp7MaswmjOVVblRnvxiV6JRHUt6v1M/jJs s5I4x5DvnMq58Va9lS0bWwZ13+meCMgtMnA8IJUuZrwD63jv6eFiklttiS1bEyXttE n5nLhuiM524i0FtNBBazC5hsFCC+24hI5zY4nE2zvmyLHc8oD1Ep8nf0j9WsgAy0WG EHk/jSJooETiQ== From: Nathan Chancellor To: Greg Kroah-Hartman , Sasha Levin , Catalin Marinas , Will Deacon Cc: Mark Rutland , Marc Zyngier , Nick Desaulniers , linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH RFC 4.9 3/5] arm64: reduce el2_setup branching Date: Fri, 7 Jan 2022 12:43:33 -0700 Message-Id: <20220107194335.3090066-4-nathan@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107194335.3090066-1-nathan@kernel.org> References: <20220107194335.3090066-1-nathan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_114402_843679_A822F719 X-CRM114-Status: GOOD ( 14.24 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mark Rutland commit 3ad47d055aa88d9f4189253f5b5c485f4c4626b2 upstream. The early el2_setup code is a little convoluted, with two branches where one would do. This makes the code more painful to read than is necessary. We can remove a branch and simplify the logic by moving the early return in the booted-at-EL1 case earlier in the function. This separates it from all the setup logic that only makes sense for EL2. Acked-by: Marc Zyngier Signed-off-by: Mark Rutland Cc: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Nathan Chancellor --- arch/arm64/kernel/head.S | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 387542383662..b15abc6ae4af 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -489,13 +489,8 @@ ENTRY(el2_setup) msr SPsel, #1 // We want to use SP_EL{1,2} mrs x0, CurrentEL cmp x0, #CurrentEL_EL2 - b.ne 1f - mrs x0, sctlr_el2 -CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2 -CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2 - msr sctlr_el2, x0 - b 2f -1: mrs x0, sctlr_el1 + b.eq 1f + mrs x0, sctlr_el1 CPU_BE( orr x0, x0, #(3 << 24) ) // Set the EE and E0E bits for EL1 CPU_LE( bic x0, x0, #(3 << 24) ) // Clear the EE and E0E bits for EL1 msr sctlr_el1, x0 @@ -503,7 +498,11 @@ CPU_LE( bic x0, x0, #(3 << 24) ) // Clear the EE and E0E bits for EL1 isb ret -2: +1: mrs x0, sctlr_el2 +CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2 +CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2 + msr sctlr_el2, x0 + #ifdef CONFIG_ARM64_VHE /* * Check for VHE being present. For the rest of the EL2 setup, From patchwork Fri Jan 7 19:43:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 12707013 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 03912C433F5 for ; Fri, 7 Jan 2022 19:45:53 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6qgp86N6JdzrPd2F+ZTtmVBHbO5QKvl86xZqRZtugi0=; b=22EpKa9xcBQH72 2/WMCSHacI0X7zrbrZUjHna0lDYDm3yiR43D0nRUtQxlNHBnM+ibiZuqR8GEYqZtq9L+dv5TsLFAs RTzVutfE5Qd20d5aBLgCcOw0PTp3fpraC5JUWtJVZKtue0E3xO5q/Uafjp7Ct+DD/qdCWCsu/IfTL gMIyYoCeO7xUJOGhLt0WA9KWYNpfCHJs+daoMheO5Qg3gHJ/w0On6EYsejJl5wF/D/69afsZbBkgo SsCYCUCTGLntx7ZP3+HLB/5Aef6iYJmffECO+9C9VLLlNfuYk83+Pjk1lbrKkl1OHyU2GgSWkbKaw 7q2IiaZHLRVNm5K8WZbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5vAG-0056VO-LY; Fri, 07 Jan 2022 19:44:40 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9h-0056LA-UZ for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 19:44:07 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B283BB82765; Fri, 7 Jan 2022 19:44:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58F80C36AED; Fri, 7 Jan 2022 19:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641584644; bh=GO9iL6Qi1ajaccImX9GcZ0L+1uDe8ATmtJQ1yhUiskc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FdHb8k14YHP2arXIYvO53uNJtJ/AGs0FKgM+Ddpjyh6/rQ/uQoSFxMHmpP+JUXxfs G87IB4eDF8GPCQTExwyXpCtvlOVIRobDAdmNCWT312YtpcftbxxO9dGRsj/TVQWTX7 BgApLX1YFxCJ5A1x6vZtORG3tzbPWwvbO1KdOFSh9fXM3CMlcP65OzfLerB/trfJms bnTz73Q3W8tqjHIghJDQkqZqhDOEofvYNbSFGIkaLUL4bd5jqqEyLJ28n+tYLXdwpB Td8p0DsyaT/o64uTdcuAhhUylQHK2sD333vG4jdaypOnboTg1SPglHQPUKRnEasrWu odBJjYwtp/E0A== From: Nathan Chancellor To: Greg Kroah-Hartman , Sasha Levin , Catalin Marinas , Will Deacon Cc: Mark Rutland , Marc Zyngier , Nick Desaulniers , linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH RFC 4.9 4/5] arm64: move !VHE work to end of el2_setup Date: Fri, 7 Jan 2022 12:43:34 -0700 Message-Id: <20220107194335.3090066-5-nathan@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107194335.3090066-1-nathan@kernel.org> References: <20220107194335.3090066-1-nathan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_114406_296912_578CD76F X-CRM114-Status: GOOD ( 15.83 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mark Rutland commit d61c97a7773d0848b4bf5c4697855c7ce117362c upstream. We only need to initialise sctlr_el1 if we're installing an EL2 stub, so we may as well defer this until we're doing so. Similarly, we can defer intialising CPTR_EL2 until then, as we do not access any trapped functionality as part of el2_setup. This patch modified el2_setup accordingly, allowing us to remove a branch and simplify the code flow. Acked-by: Marc Zyngier Signed-off-by: Mark Rutland Cc: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Nathan Chancellor --- arch/arm64/kernel/head.S | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index b15abc6ae4af..c067b13e93cc 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -553,26 +553,6 @@ set_hcr: msr vpidr_el2, x0 msr vmpidr_el2, x1 - /* - * When VHE is not in use, early init of EL2 and EL1 needs to be - * done here. - * When VHE _is_ in use, EL1 will not be used in the host and - * requires no configuration, and all non-hyp-specific EL2 setup - * will be done via the _EL1 system register aliases in __cpu_setup. - */ - cbnz x2, 1f - - /* sctlr_el1 */ - mov x0, #0x0800 // Set/clear RES{1,0} bits -CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems -CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems - msr sctlr_el1, x0 - - /* Coprocessor traps. */ - mov x0, #0x33ff - msr cptr_el2, x0 // Disable copro. traps to EL2 -1: - #ifdef CONFIG_COMPAT msr hstr_el2, xzr // Disable CP15 traps to EL2 #endif @@ -598,6 +578,23 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems ret install_el2_stub: + /* + * When VHE is not in use, early init of EL2 and EL1 needs to be + * done here. + * When VHE _is_ in use, EL1 will not be used in the host and + * requires no configuration, and all non-hyp-specific EL2 setup + * will be done via the _EL1 system register aliases in __cpu_setup. + */ + /* sctlr_el1 */ + mov x0, #0x0800 // Set/clear RES{1,0} bits +CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems +CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems + msr sctlr_el1, x0 + + /* Coprocessor traps. */ + mov x0, #0x33ff + msr cptr_el2, x0 // Disable copro. traps to EL2 + /* Hypervisor stub */ adrp x0, __hyp_stub_vectors add x0, x0, #:lo12:__hyp_stub_vectors From patchwork Fri Jan 7 19:43:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 12707014 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 BDE8AC433F5 for ; Fri, 7 Jan 2022 19:46:03 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YlwrqMRZlkRJaBsDRbJq1Ow9hQbpyy9+huFtjV05t5Y=; b=Nkvp0W+YWLGlPt j8ihXHhKLSiZebWQkb1SZ5stTxM7sZM96MTUXCYwK+Nb04bFzM+zC6PdZXYWBDbhfvpbVa+SBoD6q enpqvr7UPHkM7xzE9zslqfH6Zlkg7M0lJLsiXYbkUPuQlt1uB8mDsYE89S6cvqAqTqeXBulc01gLY TNPDjI/aW53Tv331aIOq3VDpbu0W9S8ViHPiHGpji3u2Z+l3YY68K3/5DF5JTNSvC9pIrICpULTwO Sj10nzDDj32GK1zg6jMhkdXdoLQUmVedA8CA781mpTZ+wIIJvfS9jo/o+wmwjb1d7qOaqAG/pbnSM FCUw7sWpbtg6TjQ3vi9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5vAU-0056dL-PM; Fri, 07 Jan 2022 19:44:54 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5v9j-0056M2-U1 for linux-arm-kernel@lists.infradead.org; Fri, 07 Jan 2022 19:44:09 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7C2C160AC1; Fri, 7 Jan 2022 19:44:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5376C36AF5; Fri, 7 Jan 2022 19:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641584646; bh=YzG/O/GbySemFBZGauWQruoxp1XCwxvRhWcRz5Jn56U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WBz0bxom5GDq6ZbrGK8MEPp0yY/aplNmbMy7rMOedSkKUtt1lZ/EgjzVTBiyqU32C Qyh/YlvVD9D3Qdc7gFBXPpAT19nvBDcn++FSL4v623OsmhfXh8bpy+c+pyj7YULCcj r+rMCcrCP9NuBoBg7dbgXDfLYJJgKCJxtfcWumWZv93QqCKVplpego/z8zAebw5cc2 bYhHVKb94HY/CxXx7mTdj/akjjFK2qZpQ+y8cXYKhSGvIk00KUxGY6fg7qfaXKjnVb DfHo0sbBA/4fZ4xlGWA5rtoe4x1PiFawm0wKgy0hrS3K/vDTQ0GgJvnYD872QPYAsE vF8VA+ikS5YTw== From: Nathan Chancellor To: Greg Kroah-Hartman , Sasha Levin , Catalin Marinas , Will Deacon Cc: Mark Rutland , Marc Zyngier , Nick Desaulniers , linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH RFC 4.9 5/5] arm64: sysreg: Move to use definitions for all the SCTLR bits Date: Fri, 7 Jan 2022 12:43:35 -0700 Message-Id: <20220107194335.3090066-6-nathan@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220107194335.3090066-1-nathan@kernel.org> References: <20220107194335.3090066-1-nathan@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220107_114408_088360_D55622BD X-CRM114-Status: GOOD ( 18.05 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: James Morse [ Upstream commit 7a00d68ebe5f07cb1db17e7fedfd031f0d87e8bb ] __cpu_setup() configures SCTLR_EL1 using some hard coded hex masks, and el2_setup() duplicates some this when setting RES1 bits. Lets make this the same as KVM's hyp_init, which uses named bits. First, we add definitions for all the SCTLR_EL{1,2} bits, the RES{1,0} bits, and those we want to set or clear. Add a build_bug checks to ensures all bits are either set or clear. This means we don't need to preserve endian-ness configuration generated elsewhere. Finally, move the head.S and proc.S users of these hard-coded masks over to the macro versions. Signed-off-by: James Morse Signed-off-by: Catalin Marinas Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman Signed-off-by: Nathan Chancellor --- arch/arm64/include/asm/sysreg.h | 65 ++++++++++++++++++++++++++++++++- arch/arm64/kernel/head.S | 13 ++----- arch/arm64/mm/proc.S | 24 +----------- 3 files changed, 67 insertions(+), 35 deletions(-) diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index 7a9f0a71f441..ae1b31d02784 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -20,6 +20,7 @@ #ifndef __ASM_SYSREG_H #define __ASM_SYSREG_H +#include #include #include @@ -88,25 +89,81 @@ /* Common SCTLR_ELx flags. */ #define SCTLR_ELx_EE (1 << 25) +#define SCTLR_ELx_WXN (1 << 19) #define SCTLR_ELx_I (1 << 12) #define SCTLR_ELx_SA (1 << 3) #define SCTLR_ELx_C (1 << 2) #define SCTLR_ELx_A (1 << 1) #define SCTLR_ELx_M 1 +#define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ + SCTLR_ELx_SA | SCTLR_ELx_I) + +/* SCTLR_EL2 specific flags. */ #define SCTLR_EL2_RES1 ((1 << 4) | (1 << 5) | (1 << 11) | (1 << 16) | \ (1 << 18) | (1 << 22) | (1 << 23) | (1 << 28) | \ (1 << 29)) +#define SCTLR_EL2_RES0 ((1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | \ + (1 << 10) | (1 << 13) | (1 << 14) | (1 << 15) | \ + (1 << 17) | (1 << 20) | (1 << 21) | (1 << 24) | \ + (1 << 26) | (1 << 27) | (1 << 30) | (1 << 31)) + +#ifdef CONFIG_CPU_BIG_ENDIAN +#define ENDIAN_SET_EL2 SCTLR_ELx_EE +#define ENDIAN_CLEAR_EL2 0 +#else +#define ENDIAN_SET_EL2 0 +#define ENDIAN_CLEAR_EL2 SCTLR_ELx_EE +#endif + +/* SCTLR_EL2 value used for the hyp-stub */ +#define SCTLR_EL2_SET (ENDIAN_SET_EL2 | SCTLR_EL2_RES1) +#define SCTLR_EL2_CLEAR (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ + SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_WXN | \ + ENDIAN_CLEAR_EL2 | SCTLR_EL2_RES0) + +/* Check all the bits are accounted for */ +#define SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS BUILD_BUG_ON((SCTLR_EL2_SET ^ SCTLR_EL2_CLEAR) != ~0) -#define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ - SCTLR_ELx_SA | SCTLR_ELx_I) /* SCTLR_EL1 specific flags. */ #define SCTLR_EL1_UCI (1 << 26) +#define SCTLR_EL1_E0E (1 << 24) #define SCTLR_EL1_SPAN (1 << 23) +#define SCTLR_EL1_NTWE (1 << 18) +#define SCTLR_EL1_NTWI (1 << 16) #define SCTLR_EL1_UCT (1 << 15) +#define SCTLR_EL1_DZE (1 << 14) +#define SCTLR_EL1_UMA (1 << 9) #define SCTLR_EL1_SED (1 << 8) +#define SCTLR_EL1_ITD (1 << 7) #define SCTLR_EL1_CP15BEN (1 << 5) +#define SCTLR_EL1_SA0 (1 << 4) + +#define SCTLR_EL1_RES1 ((1 << 11) | (1 << 20) | (1 << 22) | (1 << 28) | \ + (1 << 29)) +#define SCTLR_EL1_RES0 ((1 << 6) | (1 << 10) | (1 << 13) | (1 << 17) | \ + (1 << 21) | (1 << 27) | (1 << 30) | (1 << 31)) + +#ifdef CONFIG_CPU_BIG_ENDIAN +#define ENDIAN_SET_EL1 (SCTLR_EL1_E0E | SCTLR_ELx_EE) +#define ENDIAN_CLEAR_EL1 0 +#else +#define ENDIAN_SET_EL1 0 +#define ENDIAN_CLEAR_EL1 (SCTLR_EL1_E0E | SCTLR_ELx_EE) +#endif + +#define SCTLR_EL1_SET (SCTLR_ELx_M | SCTLR_ELx_C | SCTLR_ELx_SA |\ + SCTLR_EL1_SA0 | SCTLR_EL1_SED | SCTLR_ELx_I |\ + SCTLR_EL1_DZE | SCTLR_EL1_UCT | SCTLR_EL1_NTWI |\ + SCTLR_EL1_NTWE | SCTLR_EL1_SPAN | ENDIAN_SET_EL1 |\ + SCTLR_EL1_UCI | SCTLR_EL1_RES1) +#define SCTLR_EL1_CLEAR (SCTLR_ELx_A | SCTLR_EL1_CP15BEN | SCTLR_EL1_ITD |\ + SCTLR_EL1_UMA | SCTLR_ELx_WXN | ENDIAN_CLEAR_EL1 |\ + SCTLR_EL1_RES0) + +/* Check all the bits are accounted for */ +#define SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS BUILD_BUG_ON((SCTLR_EL1_SET ^ SCTLR_EL1_CLEAR) != ~0) /* id_aa64isar0 */ #define ID_AA64ISAR0_RDM_SHIFT 28 @@ -244,6 +301,7 @@ #else +#include #include asm( @@ -300,6 +358,9 @@ static inline void config_sctlr_el1(u32 clear, u32 set) { u32 val; + SCTLR_EL2_BUILD_BUG_ON_MISSING_BITS; + SCTLR_EL1_BUILD_BUG_ON_MISSING_BITS; + val = read_sysreg(sctlr_el1); val &= ~clear; val |= set; diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index c067b13e93cc..04f81675b6b3 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -490,17 +490,13 @@ ENTRY(el2_setup) mrs x0, CurrentEL cmp x0, #CurrentEL_EL2 b.eq 1f - mrs x0, sctlr_el1 -CPU_BE( orr x0, x0, #(3 << 24) ) // Set the EE and E0E bits for EL1 -CPU_LE( bic x0, x0, #(3 << 24) ) // Clear the EE and E0E bits for EL1 + mov_q x0, (SCTLR_EL1_RES1 | ENDIAN_SET_EL1) msr sctlr_el1, x0 mov w0, #BOOT_CPU_MODE_EL1 // This cpu booted in EL1 isb ret -1: mrs x0, sctlr_el2 -CPU_BE( orr x0, x0, #(1 << 25) ) // Set the EE bit for EL2 -CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2 +1: mov_q x0, (SCTLR_EL2_RES1 | ENDIAN_SET_EL2) msr sctlr_el2, x0 #ifdef CONFIG_ARM64_VHE @@ -585,10 +581,7 @@ install_el2_stub: * requires no configuration, and all non-hyp-specific EL2 setup * will be done via the _EL1 system register aliases in __cpu_setup. */ - /* sctlr_el1 */ - mov x0, #0x0800 // Set/clear RES{1,0} bits -CPU_BE( movk x0, #0x33d0, lsl #16 ) // Set EE and E0E on BE systems -CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems + mov_q x0, (SCTLR_EL1_RES1 | ENDIAN_SET_EL1) msr sctlr_el1, x0 /* Coprocessor traps. */ diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 1b91b8c8999b..266211a0ecd6 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -413,11 +413,7 @@ ENTRY(__cpu_setup) /* * Prepare SCTLR */ - adr x5, crval - ldp w5, w6, [x5] - mrs x0, sctlr_el1 - bic x0, x0, x5 // clear bits - orr x0, x0, x6 // set bits + mov_q x0, SCTLR_EL1_SET /* * Set/prepare TCR and TTBR. We use 512GB (39-bit) address range for * both user and kernel. @@ -453,21 +449,3 @@ ENTRY(__cpu_setup) msr tcr_el1, x10 ret // return to head.S ENDPROC(__cpu_setup) - - /* - * We set the desired value explicitly, including those of the - * reserved bits. The values of bits EE & E0E were set early in - * el2_setup, which are left untouched below. - * - * n n T - * U E WT T UD US IHBS - * CE0 XWHW CZ ME TEEA S - * .... .IEE .... NEAI TE.I ..AD DEN0 ACAM - * 0011 0... 1101 ..0. ..0. 10.. .0.. .... < hardware reserved - * .... .1.. .... 01.1 11.1 ..01 0.01 1101 < software settings - */ - .type crval, #object -crval: - .word 0xfcffffff // clear - .word 0x34d5d91d // set - .popsection