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 6B459C43334 for ; Mon, 27 Jun 2022 15:15: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=vssSwPBTrrmaAtmlOVsI73Z459K7X3Ip4N71xSTAek4=; b=HhlEEz1AXXVyen ohn8JejRXso+ha9EccwbtDCIrd7MarBEadjy9KvuRvzdCHkYhXpEVyszlrNbiSqpGoGxOmyc0bOcg WZn0gmA9+KdHjHN5209kWPHHt25j2xVSz2EexyVZx9tD1iW7Vaz8N78rfhMgM8Ezn9bpVi/scfuEj GnA2z9Db+wRrTBiK6jjYrY4WwU2qcpAZH+63YSJQmnPBJLBCgWTeRmM5KVsTQaAtKQN+2vvGEpvKk e/DDeKXM80ke+V+QaLadVQMK14xiYgLwYEMs4IorNCuC0YX/688HPEvAqDV9ojkY0gH2BxXcDp9/f Pa0xPt4pTbqMRX0BRetw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o5qRc-001ZQM-Cw; Mon, 27 Jun 2022 15:14:32 +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 1o5qRW-001ZNk-9c for linux-arm-kernel@lists.infradead.org; Mon, 27 Jun 2022 15:14:27 +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 D3C1D615C7; Mon, 27 Jun 2022 15:14:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15E6CC341CF; Mon, 27 Jun 2022 15:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656342865; bh=DnIaM4xRJr0aOSByZcvyBbb3o6txgxtjph0/rVq6jzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AD9E2DWvmAp6go1FgDiaUuQZyjYv6yhYZ6wQr71HDidsgsHijex6djOMu4MfLGcbP The+6Vu92jwSd96DgEPBi/cpBK++LV9AqA7qGcPgMSDrz+LbhogUGDUAiaYNmecNnG XB90Kd22RvA7blojrlsm13PN6QMgznkNnhrWCIXfxitKemn+hDNXx+x2sklc2mBeuM VA7t3DnGCIZE/cky+4gG9deXgFZAXD9KA/wmw3qbXgELTjvkA4cRi9d1QEeGATBmYF vrFMdHUiKM8EfdCwgpeai12k2j5BvGmUjnsKI9L3oep0B5VX/gMsoZsk+9XIF815fm 1356CQ/+iTgyA== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1o5qRT-003TzH-3X; Mon, 27 Jun 2022 16:14:23 +0100 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org Cc: Will Deacon , Catalin Marinas , Mark Rutland , Ard Biesheuvel , broonie@kernel.org, danielmentz@google.com, saravanak@google.com, kernel-team@android.com Subject: [PATCH 2/6] arm64: Save state of HCR_EL2.E2H before switch to EL1 Date: Mon, 27 Jun 2022 16:14:08 +0100 Message-Id: <20220627151412.1496361-3-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220627151412.1496361-1-maz@kernel.org> References: <20220627151412.1496361-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, ardb@kernel.org, broonie@kernel.org, danielmentz@google.com, saravanak@google.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220627_081426_458015_DB55141B X-CRM114-Status: GOOD ( 20.62 ) 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 As we're about to switch the way E2H-stuck CPUs boot, save the boot CPU E2H state into a global variable that can then be checked by the iderg override code. This allows us to replace the is_kernel_in_hyp_mode() check with a simple comparison with this variable, even when running at EL1. Note that the variable's validity is pretty short (it cannot be trusted once a secondary has booted). Use with caution. Signed-off-by: Marc Zyngier --- arch/arm64/kernel/head.S | 11 +++++++++++ arch/arm64/kernel/idreg-override.c | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index f8550a939a6e..d35287c22d30 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -527,6 +527,8 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL) */ mrs x0, hcr_el2 and x0, x0, #HCR_E2H + adr_l x1, __e2h_state + str x0, [x1] cbz x0, 1f /* Switching to VHE requires a sane SCTLR_EL1 as a start */ @@ -599,6 +601,15 @@ SYM_DATA_END(__boot_cpu_mode) SYM_DATA_START(__early_cpu_boot_status) .quad 0 SYM_DATA_END(__early_cpu_boot_status) +/* + * The value of the boot CPU's HCR_EL2.E2H state before dropping to + * EL1, so that the idreg override code can work out whether it can + * run in nVHE mode. Note that this is meaningless once a secondary + * CPU has booted, as it will have been overwritten. + */ +SYM_DATA_START(__e2h_state) + .quad 0 +SYM_DATA_END(__e2h_state) .popsection diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index 8a2ceb591686..6abff337b23b 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -31,13 +31,13 @@ struct ftr_set_desc { static bool __init mmfr1_vh_filter(u64 val) { + extern u64 __e2h_state; /* - * If we ever reach this point while running VHE, we're - * guaranteed to be on one of these funky, VHE-stuck CPUs. If - * the user was trying to force nVHE on us, proceed with - * attitude adjustment. + * If the boot CPU has HCR_EL2.E2H set, we're guaranteed to be + * on one of these funky, VHE-stuck CPUs. If the user was + * trying to force nVHE on us, proceed with attitude adjustment. */ - return !(is_kernel_in_hyp_mode() && val == 0); + return !(__e2h_state != 0 && val == 0); } static const struct ftr_set_desc mmfr1 __initconst = { -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel