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 7E82FC433EF for ; Thu, 30 Jun 2022 16:07:39 +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=K2JkUijUoDVxkHPrIzahy/BF/Bh/yfJ6XTMIgUKEIng=; b=qs6c73AUDnA9zt mBrXteFgi0nXKHmQETV+aWvCe0J5pTNpat+3VwSl4WZNz8DIdxh83GRW8iT1Ip3h1wI1P4nDBpCKB IgapuPKyy29pn5fMLvqS4oZlsbQF8fYVBMj8XPENOJ+IWW79mRygUu3bSx9kZA9NgopuZNKm/L654 eVyY/T2x1js5AJr1hs5maJOshXjR3VYCZOycxKyp/AZnv3vlrYbilokplq1eqJ2BPSqhjt5V7yPtT TKG1PNYvU59bMOMj1dDZazAwfeNVs9e0rg+joYbf3zztectMI9flQC4Em92zxihlQS2dvtywjZNC4 fgyh2IgenILK4S4NZdfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o6wgb-000VPi-3m; Thu, 30 Jun 2022 16:06:34 +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 1o6wfT-000Utv-A1 for linux-arm-kernel@lists.infradead.org; Thu, 30 Jun 2022 16:05:26 +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 6EAE961F84; Thu, 30 Jun 2022 16:05:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 980E2C341CF; Thu, 30 Jun 2022 16:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656605121; bh=sroMY6StedMWZbt50TE36X9DVsoaFsl/ecJ4+V5JU0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEyPscRN3o0Ja+RpdWEQGDcCGJiyV2AiJiqwyCJXIYV4VAQW7mpd+r203yZaVSNis Wr20cdCQXK9qyDI/2NdF5m5ZFHmbw15vV7weNXzbneGtP12AnhmdsQNXiMvDXeVW0j bUflVv5pTh1EA4GOaQv0eu+upvrpUxp33r+7rw16aml4cHxr0kY3IT1lzlSOoduH2j iaFsIfkyfrFFWE/jLZBNPoIQZS/0f8AU+ZYoD2tJd20bIpNUivtpCF8yJXMeD2nWeZ Nu5/zpyE3eSito32I1ApdPjrKsobWduTl6zK1Q3CcymORk6ickjas4s/nPE0bWTAxE PLwZVSLiulLUg== 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 1o6wfP-004OGk-Gy; Thu, 30 Jun 2022 17:05:19 +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 v2 2/9] arm64: Save state of HCR_EL2.E2H before switch to EL1 Date: Thu, 30 Jun 2022 17:04:53 +0100 Message-Id: <20220630160500.1536744-3-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220630160500.1536744-1-maz@kernel.org> References: <20220630160500.1536744-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-20220630_090523_487346_616DE8EB X-CRM114-Status: GOOD ( 21.60 ) 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 as a flag tied to the boot mode that can then be checked by the idreg override code. This allows us to replace the is_kernel_in_hyp_mode() check with a simple comparison with this state, even when running at EL1. Note that this flag isn't saved in __boot_cpu_mode, and is only kept in a register in the assembly code. Use with caution. Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/virt.h | 7 +++++++ arch/arm64/kernel/head.S | 7 +++++-- arch/arm64/kernel/idreg-override.c | 11 ++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/virt.h b/arch/arm64/include/asm/virt.h index dec6eee0eda5..4eb601e7de50 100644 --- a/arch/arm64/include/asm/virt.h +++ b/arch/arm64/include/asm/virt.h @@ -49,6 +49,13 @@ #define BOOT_CPU_MODE_EL1 (0xe11) #define BOOT_CPU_MODE_EL2 (0xe12) +/* + * Flags returned together with the boot mode, but not preserved in + * __boot_cpu_mode. Used by the idreg override code to work out the + * boot state. + */ +#define BOOT_CPU_FLAG_E2H BIT_ULL(32) + #ifndef __ASSEMBLY__ #include diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 04ebfe663eae..053cd6803147 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -447,6 +447,7 @@ SYM_FUNC_START_LOCAL(__primary_switched) bl kasan_early_init #endif mov x0, x22 // pass FDT address in x0 + mov x1, x20 // pass the full boot status bl init_feature_override // Parse cpu feature overrides mov x0, x20 bl finalise_el2 // Prefer VHE if possible @@ -469,8 +470,9 @@ SYM_FUNC_END(__primary_switched) * Since we cannot always rely on ERET synchronizing writes to sysregs (e.g. if * SCTLR_ELx.EOS is clear), we place an ISB prior to ERET. * - * Returns either BOOT_CPU_MODE_EL1 or BOOT_CPU_MODE_EL2 in w0 if - * booted in EL1 or EL2 respectively. + * Returns either BOOT_CPU_MODE_EL1 or BOOT_CPU_MODE_EL2 in x0 if + * booted in EL1 or EL2 respectively, with the top 32 bits containing + * potential context flags. These flags are *not* stored in __boot_cpu_mode. */ SYM_FUNC_START(init_kernel_el) mrs x0, CurrentEL @@ -535,6 +537,7 @@ __cpu_stick_to_vhe: mov x0, #HVC_FINALISE_EL2 hvc #0 mov x0, #BOOT_CPU_MODE_EL2 + orr x0, x0, #BOOT_CPU_FLAG_E2H ret SYM_FUNC_END(init_kernel_el) diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c index f92836e196e5..03185bc46d69 100644 --- a/arch/arm64/kernel/idreg-override.c +++ b/arch/arm64/kernel/idreg-override.c @@ -19,6 +19,8 @@ #define FTR_ALIAS_NAME_LEN 30 #define FTR_ALIAS_OPTION_LEN 116 +static u64 __boot_status __initdata; + struct ftr_set_desc { char name[FTR_DESC_NAME_LEN]; struct arm64_ftr_override *override; @@ -37,7 +39,8 @@ static bool __init mmfr1_vh_filter(u64 val) * the user was trying to force nVHE on us, proceed with * attitude adjustment. */ - return !(is_kernel_in_hyp_mode() && val == 0); + return !(__boot_status == (BOOT_CPU_FLAG_E2H | BOOT_CPU_MODE_EL2) && + val == 0); } static const struct ftr_set_desc mmfr1 __initconst = { @@ -229,9 +232,9 @@ static __init void parse_cmdline(const void *fdt) } /* Keep checkers quiet */ -void init_feature_override(const void *fdt); +void init_feature_override(const void *fdt, u64 boot_status); -asmlinkage void __init init_feature_override(const void *fdt) +asmlinkage void __init init_feature_override(const void *fdt, u64 boot_status) { int i; @@ -242,6 +245,8 @@ asmlinkage void __init init_feature_override(const void *fdt) } } + __boot_status = boot_status; + parse_cmdline(fdt); for (i = 0; i < ARRAY_SIZE(regs); i++) { -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel