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=-15.7 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,USER_AGENT_SANE_1 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 BD372C433C1 for ; Mon, 29 Mar 2021 18:04:37 +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 6C93961920 for ; Mon, 29 Mar 2021 18:04:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C93961920 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AzrDH7aVYppkkpd0sBxPK8X351H063QnMhW1AYRrR7I=; b=HXzp0aKW4/I4UtbCaEJqQty5F 3Co507Pt4FlJ5DN7Xpm+q1qAQuHWGn22pvWgcWGPEHYodp9QOtJlEGHx3AN0mweYOeTHNBF/B8gnM Cooi0NjR/IDApsEeKfIgMj5b7KT6VsC74wC6bQLxMC+XeUtnRAFPNmt9H4yXRCVv7FKsI8VNx9h4H r2ruT3fUiKSwUZQ+PSfesvFEzON8CNczHt6/s63NoKXO8JnLgEVFO0fXpZR5Oz9v57uxlL6x10Skf 4xm3y7Ol/dA/yp0th2roRkxwlUzL17HicSg1hlMYTW23W/qSPyAlmbM25mWzkakV58mhvRSWx42RW wTIm/oKNQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lQwCR-000y2e-1p; Mon, 29 Mar 2021 18:01:20 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lQp25-000Zsf-Cb for linux-arm-kernel@lists.infradead.org; Mon, 29 Mar 2021 10:22:07 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id E4D4461874; Mon, 29 Mar 2021 10:22:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617013324; bh=9xRijc2hDEE1X2P1pQBNNGKe+i8lGpDurlKS2Cpf6mU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gngkmcWCnDgGZMvRsUAdgqSm95Xa7iEIfGG4LDJqPtDEac+6P7vpZkyxZSvEpi5y2 bS3JrRFNRvh39pQdxX+ITRZ5t0NzxTLd5N44wFdmE/bflqEtARFovD1jlID9WKfTfM o/aDvPVL4ZerLEAsNquOkMWlNQhJzaaIFKtIIuhWdzP3j0GbkVQViOQm5m6n4Jqurl hHZ1bvVh7z5p/41UvZ4Wq58UQc3J/fGnrafuYXdjEZE+4iTzz4+kaJHy8esvyV9EGz HQMfZ56lA7Tly1mZs+izd14Lm4iXUGuXxeeDnROLbKvFyUadiYdzdtZbyONfBEHjU5 uK3yFF/qky4YQ== Date: Mon, 29 Mar 2021 11:22:00 +0100 From: Will Deacon To: Marc Zyngier 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 Message-ID: <20210329102159.GD3207@willie-the-truck> References: <20210325124721.941182-1-maz@kernel.org> <20210325124721.941182-3-maz@kernel.org> <20210325193318.GD16123@willie-the-truck> <87sg4if9fx.wl-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87sg4if9fx.wl-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210329_112205_958639_BD57230C X-CRM114-Status: GOOD ( 35.28 ) 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 Fri, Mar 26, 2021 at 11:20:18AM +0000, Marc Zyngier wrote: > 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. I think the best thing to do would be to fail to initialise KVM if the kernel is stuck at EL2 but we don't have VHE support compiled in. Is that do-able? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel