Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp133724pxy; Sat, 14 Aug 2021 02:40:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG70hhv3hQBIINeJi2K1WY/J8KNu2ERsQPpJyT3yxwsqFw/QUReO/Q75aykw9MUbVu77N3 X-Received: by 2002:a92:8702:: with SMTP id m2mr4912290ild.250.1628934048229; Sat, 14 Aug 2021 02:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628934048; cv=none; d=google.com; s=arc-20160816; b=x48Px8sSR5tNZrYomu3h6NXPyo/VG9LGkWP3P/WCRcrWuanZ3Jw6IWYjcd4PL63rg3 0CowVqb8WUq1QXBNRMlrCVoJEiSCrkPndLxUfjxy06A7LTqvHIG+QsEYtctqic7yaHRv Mme+q+Jk0AiuqXN1xWU3woVIZDBMXUJ+/E71ykdSRNSNy+rqn9Mc7lOpSYg5EIqEp8pj Mp4LfIcSuTFooJM7zsUl5oCN3k1vTjrBShIwgOJFxjpoQGKZTZxNVzLvfDESV4baPGcr 5CNqLUYhIAybWIBD9t24WYPB6218se7ajiXb0RyK3N+Taz1T1gKXA/0l8ih3oc7e4K7c Ddyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=4N2tx8L1h6D6HFgsxK7RWKAh5F6RpJFXJ7fdpzpXoEc=; b=Kar7wvOSh7a5va9pRr5t2HXzRz5PbmP26dgfJqYKJOifCxPnDq1iHmxHCDDT1l85U+ csahGoe0P0NFfUg96cOQqJSz5lw7tNTiepT/ZE1AVWdKWBxKPpqSV8XnqLm0QoP4DNbo 34gIfbA0HtoOI6o8Mu/qanBfPc6gTxOehs6LE+6qva6/dHO+4rItlFkyRj5Q2D7qpO88 8c+fFzKfVyELsIW3R9RzUnVWayTPW7aT/Og0BoDaXkeGnOsL8vUVrwedBZvI3ZAMPE4n gQLGGI8Ljrkd8HY523DRRgtkrbt69mIk5CUJ30JCw5Yy1luVI0D9JoAFqv8zmMKa97Yc WVDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d131si6936529iog.11.2021.08.14.02.40.37; Sat, 14 Aug 2021 02:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237720AbhHNJjD (ORCPT + 99 others); Sat, 14 Aug 2021 05:39:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:35508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236824AbhHNJjB (ORCPT ); Sat, 14 Aug 2021 05:39:01 -0400 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 9369560EE4; Sat, 14 Aug 2021 09:38:32 +0000 (UTC) Received: from 109-170-232-56.xdsl.murphx.net ([109.170.232.56] 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.2) (envelope-from ) id 1mEq7a-004xKo-He; Sat, 14 Aug 2021 10:38:30 +0100 Date: Sat, 14 Aug 2021 10:38:30 +0100 Message-ID: <87h7fs1i3t.wl-maz@kernel.org> From: Marc Zyngier To: Robin Murphy Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , Will Deacon , Catalin Marinas , Mark Rutland , Ard Biesheuvel , Florian Fainelli , bcm-kernel-feedback-list@broadcom.com, kernel-team@android.com Subject: Re: [PATCH 2/5] arm64: Handle UNDEF in the EL2 stub vectors In-Reply-To: <060ef66a-6d6f-082e-5f69-117235b8ce4e@arm.com> References: <20210812190213.2601506-1-maz@kernel.org> <20210812190213.2601506-3-maz@kernel.org> <2f6bf17f-d235-8311-13d5-dcb3d00e23c4@arm.com> <87im091bu7.wl-maz@kernel.org> <060ef66a-6d6f-082e-5f69-117235b8ce4e@arm.com> 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") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 109.170.232.56 X-SA-Exim-Rcpt-To: robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, zajec5@gmail.com, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, ardb@kernel.org, f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 13 Aug 2021 19:17:56 +0100, Robin Murphy wrote: > > On 2021-08-13 18:41, Marc Zyngier wrote: > > On Fri, 13 Aug 2021 14:08:23 +0100, > > Robin Murphy wrote: > >> > >> On 2021-08-12 20:02, Marc Zyngier wrote: > >>> As we want to handle the silly case where HVC has been disabled > >>> from EL3, augment our ability to handle exception at EL2. > >>> > >>> Check for unknown exceptions (usually UNDEF) coming from EL2, > >>> and treat them as a failing HVC call into the stubs. While > >>> this isn't great and obviously doesn't catter for the gigantic > >>> range of possible exceptions, it isn't any worse than what we > >>> have today. > >>> > >>> Just don't try and use it for anything else. > >>> > >>> Signed-off-by: Marc Zyngier > >>> --- > >>> arch/arm64/kernel/hyp-stub.S | 19 ++++++++++++++++++- > >>> 1 file changed, 18 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S > >>> index 43d212618834..026a34515b21 100644 > >>> --- a/arch/arm64/kernel/hyp-stub.S > >>> +++ b/arch/arm64/kernel/hyp-stub.S > >>> @@ -46,7 +46,16 @@ SYM_CODE_END(__hyp_stub_vectors) > >>> .align 11 > >>> SYM_CODE_START_LOCAL(elx_sync) > >>> - cmp x0, #HVC_SET_VECTORS > >>> + mrs x4, spsr_el2 > >>> + and x4, x4, #PSR_MODE_MASK > >>> + orr x4, x4, #1 > >>> + cmp x4, #PSR_MODE_EL2h > >>> + b.ne 0f > >>> + mrs x4, esr_el2 > >>> + eor x4, x4, #ESR_ELx_IL > >>> + cbz x4, el2_undef > >> > >> Hmm, might it be neater to check ESR_EL2.ISS to see if we landed here > >> for any reason *other* than a successfully-executed HVC? > > > > We absolutely could. However, the sixpence question (yes, that's the > > Brexit effect for you) is "what do you do with exceptions that are > > neither UNDEF now HVC?". > > > > We are taking a leap of faith by assuming that the only thing that > > will UNDEF at EL2 while the stubs are installed is HVC. If anything > > else occurs, I have no idea what to do with it. I guess we could always > > ignore it instead of treating it as a HVC (as it is done at the > > moment). > > Right, I think that concern applies pretty much equally whichever way > you slice it. "Any exception other than an unknown from EL2 must imply > HVC" doesn't seem any less sketchy than "Any exception other than HVC > implies something is horribly wrong and abandoning EL2 might be wise" > to me, but it was primarily that the latter avoids having to faff with > the SPSR as well. Actually, that's not a bad idea at all. Here's my take on the theme, completely untested: diff --git a/arch/arm64/kernel/hyp-stub.S b/arch/arm64/kernel/hyp-stub.S index 43d212618834..5783dbab529f 100644 --- a/arch/arm64/kernel/hyp-stub.S +++ b/arch/arm64/kernel/hyp-stub.S @@ -46,6 +46,23 @@ SYM_CODE_END(__hyp_stub_vectors) .align 11 SYM_CODE_START_LOCAL(elx_sync) + // tpidr_el2 isn't used for anything while the stubs are + // installed, so use it to save x0 while we guess the + // exception type. No, we don't have a stack... + msr tpidr_el2, x0 + mrs x0, esr_el2 + ubfx x0, x0, #26, #6 + cmp x0, #ESR_ELx_EC_HVC64 + b.eq elx_hvc + cbz x0, elx_unknown + + // For anything else, we have no reasonable way to handle + // the exception. Go back to the faulting instruction... + mrs x0, tpidr_el2 + eret + +elx_hvc: + mrs x0, tpidr_el2 cmp x0, #HVC_SET_VECTORS b.ne 1f msr vbar_el2, x1 @@ -71,6 +88,14 @@ SYM_CODE_START_LOCAL(elx_sync) 9: mov x0, xzr eret + +elx_unknown: + // Assumes this was a HVC that went really wrong... + mrs x0, elr_el2 + add x0, x0, #4 + msr elr_el2, x0 + mov_q x0, HVC_STUB_ERR + eret SYM_CODE_END(elx_sync) // nVHE? No way! Give me the real thing! > No big deal either way, just one of my "I reckon this could be > shorter..." musings; it's been particularly Friday today :) Well, I just made it a lot longer! :D Let me know what you think. Thanks, M. -- Without deviation from the norm, progress is not possible.