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 X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 071DAC433DB for ; Fri, 26 Mar 2021 11:21:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7DAD361A38 for ; Fri, 26 Mar 2021 11:21:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7DAD361A38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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:Subject:Cc:To: From:Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LSQfSCOe5+7Y90yY6B7LC5QZxT4DmeywWjWEUiULPx0=; b=FE6THnLU+TP7IWrkYe+mBG1g6 M9uXISBkistm3LpZr3X6bCwlKCm95e7WHBmHvhK6EtNjyqHaZ552LCoOAgMqo4cXErsY+fCPbA65N ZHUEmhRVlGq6i5M+sR6iXc3u8qEFVWSYbZWT+nD4aI+4iblAmwd23Su25qZSScy9klYt4wV8z35pL JaOgeGySl+m1gs/mAO7N33c9kuTXOAhNqzKznHfqpYXg9wSEpHxkxoMI3sG96ua/tDflunT6yR7VW D+gjeiu+gfj/XIOykD4lM33v5SYjsFoJAiA2eEmRvVhDozr7k97n7PMQdf+ViCw/bc1S77XiprGP+ GjpsDtA5Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lPkVv-003Qka-Ig; Fri, 26 Mar 2021 11:20:27 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lPkVr-003QjL-3Y for linux-arm-kernel@lists.infradead.org; Fri, 26 Mar 2021 11:20:25 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 51F3C619FC; Fri, 26 Mar 2021 11:20:21 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lPkVn-003y5Y-58; Fri, 26 Mar 2021 11:20:19 +0000 Date: Fri, 26 Mar 2021 11:20:18 +0000 Message-ID: <87sg4if9fx.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Hector Martin , Arnd Bergmann , Mark Rutland , Catalin Marinas , kernel-team@android.com Subject: Re: [PATCH 2/2] arm64: Cope with CPUs stuck in VHE mode In-Reply-To: <20210325193318.GD16123@willie-the-truck> References: <20210325124721.941182-1-maz@kernel.org> <20210325124721.941182-3-maz@kernel.org> <20210325193318.GD16123@willie-the-truck> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: will@kernel.org, linux-arm-kernel@lists.infradead.org, marcan@marcan.st, arnd@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.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-20210326_112024_096422_EED18538 X-CRM114-Status: GOOD ( 35.36 ) 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 On Thu, 25 Mar 2021 19:33:19 +0000, Will Deacon wrote: > > On Thu, Mar 25, 2021 at 12:47:21PM +0000, Marc Zyngier wrote: > > It seems that the CPUs part of the SoC known as Apple M1 have the > > terrible habit of being stuck with HCR_EL2.E2H==1, in violation > > of the architecture. > > > > Try and work around this deplorable state of affairs by detecting > > the stuck bit early and short-circuit the nVHE dance. Additional > > filtering code ensures that attempts at switching to nVHE from > > the command-line are also ignored. > > > > It is still unknown whether there are many more such nuggets > > to be found... > > > > Reported-by: Hector Martin > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/kernel/head.S | 33 +++++++++++++++++++++++++++--- > > arch/arm64/kernel/hyp-stub.S | 15 ++++++++++---- > > arch/arm64/kernel/idreg-override.c | 13 +++++++++++- > > 3 files changed, 53 insertions(+), 8 deletions(-) > > > > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S > > index 840bda1869e9..db2de5b8f3d9 100644 > > --- a/arch/arm64/kernel/head.S > > +++ b/arch/arm64/kernel/head.S > > @@ -477,14 +477,13 @@ EXPORT_SYMBOL(kimage_vaddr) > > * booted in EL1 or EL2 respectively. > > */ > > SYM_FUNC_START(init_kernel_el) > > - mov_q x0, INIT_SCTLR_EL1_MMU_OFF > > - msr sctlr_el1, x0 > > - > > mrs x0, CurrentEL > > cmp x0, #CurrentEL_EL2 > > b.eq init_el2 > > > > SYM_INNER_LABEL(init_el1, SYM_L_LOCAL) > > + mov_q x0, INIT_SCTLR_EL1_MMU_OFF > > + msr sctlr_el1, x0 > > isb > > mov_q x0, INIT_PSTATE_EL1 > > msr spsr_el1, x0 > > @@ -504,6 +503,34 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL) > > msr vbar_el2, x0 > > isb > > > > + /* > > + * Fruity CPUs seem to have HCR_EL2.E2H set to RES1, > > + * making it impossible to start in nVHE mode. Is that > > + * compliant with the architecture? Absolutely not! > > + */ > > + mrs x0, hcr_el2 > > + and x0, x0, #HCR_E2H > > + cbz x0, 1f > > + > > + /* Switching to VHE requires a sane SCTLR_EL1 as a start */ > > + mov_q x0, INIT_SCTLR_EL1_MMU_OFF > > + msr_s SYS_SCTLR_EL12, x0 > > + > > + /* > > + * Force an eret into a helper "function", and let it return > > + * to our original caller... This makes sure that we have > > + * initialised the basic PSTATE state. > > + */ > > + mov x0, #INIT_PSTATE_EL2 > > + msr spsr_el1, x0 > > + adr_l x0, stick_to_vhe > > + msr elr_el1, x0 > > + eret > > What does this do if CONFIG_VHE=n on one of these CPUs? Interesting question. With this patch, it will actually boot, and behave just fine as long as you don't run a guest (the percpu offset being stored in TPIDR_EL1 will then be corrupted, though you may not even get there because of the sysreg renaming being unexpectedly active). I guess I could either make this code conditional on CONFIG_ARM64_VHE and let the machine crash early without a word, or have some later checks once the machine started booting. In the later case, displaying anything useful is going to be a challenge though (the odds of someone having a serial console on this box are close to nil). Pick your poison. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel