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 55840C04FFE for ; Wed, 8 May 2024 06:05:09 +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: 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=7r+CLXK0WkSQa7+xQxaHxqK4hf4NcdBHh3ZKcs+W3JI=; b=EHblfAMJQQQ4Qr /kqW5jsO/O70rzKsfToCAibrwc5BOOBygMas3SqMNyKQMIyK0DGqKTg6pH3tSmzyM1H5UyK11MNMy TrHmrpyeP/zG35z6VQtfug+CrFHin1Jc2M0reBdFRjM519cqpUuNtVJ5so93DZdtw/cuqjOf014io Yu5wvwgEtIsXzUcfeY7j39/+tr0jKhREllNbGUCeeggKzVGE90YX2UFEWBnRWkKf17ffeb1iUrlmb NaERbC1UteNfqHahDT5yl+vxs1Bi9PmimT7aQHec5d31NG9lURxRtHrZ/0BVq0fzhVuNVXhdI8RW7 YeLkwYANPBQUyECE1lYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4aQ8-0000000EBpu-0Gyr; Wed, 08 May 2024 06:04:52 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s4aQ2-0000000EBoP-0MOy for linux-arm-kernel@lists.infradead.org; Wed, 08 May 2024 06:04:49 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CD1C9CE0F22; Wed, 8 May 2024 06:04:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17A71C113CC; Wed, 8 May 2024 06:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715148283; bh=zR/J/GQwZZOwdR5Vz+cQ0vtwUaYOtxxQWeQiJU7jJl8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lEyLfjgHyL2A7vdOPnsomxYbOvpKv/cJ3ra/IoyPzYtBJnxcTixj5RH53wrata6eG k9pgiAw2wVFcwsMT8/1qnRqGyFCtd/mVCB7HrLb4Dy7P5WpP8QskfIS+PLQcjXWzak x7BwcQkRcMfONWXml58inDjrBpRDwxZ/DvhirZs9SAdEDR3UiltAEK85vgHHNuPEsb OKLe4bHZItqLk63gWEHjR7R9IoMDYhBKQxjNg2wtnmWeWd62QLnMf+65SvPF/GFOB1 MmHonyjeWu5Uap7LAMjIalcDyE0WZMVgcrF2RT030TIAxEuubH8oraVCQbUcGqN1mB Tj8PuATo4dXsA== Received: from cpe.ge-3-3-8-100.vbrnqe11.dk.customer.tdc.net ([80.164.103.190] 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.95) (envelope-from ) id 1s4aPw-00BWru-6v; Wed, 08 May 2024 07:04:40 +0100 Date: Wed, 08 May 2024 07:04:34 +0100 Message-ID: <87ikzozvnx.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: Re: [PATCH] KVM: arm64: Correct BTYPE/SS in host SMC emulation In-Reply-To: <20240507145733.GB22453@willie-the-truck> References: <20240502180020.3215547-1-maz@kernel.org> <20240507145733.GB22453@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/28.2 (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: 80.164.103.190 X-SA-Exim-Rcpt-To: will@kernel.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.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-20240507_230446_505922_712BF186 X-CRM114-Status: GOOD ( 34.53 ) 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 Tue, 07 May 2024 15:57:34 +0100, Will Deacon wrote: > > On Thu, May 02, 2024 at 07:00:20PM +0100, Marc Zyngier wrote: > > When taking a trap for an SMC instruction on the host, we must > > stau true to the letter of the architecture and perform all the > > typo: stay > > > actions that the CPU would otherwise do. Among those are clearing > > the BTYPE and SS bits. > > > > Just do that. > > > > Fixes: a805e1fb3099 ("KVM: arm64: Add SMC handler in nVHE EL2") > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/kvm/hyp/include/hyp/adjust_pc.h | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h b/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h > > index 4fdfeabefeb4..b1afb7b59a31 100644 > > --- a/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h > > +++ b/arch/arm64/kvm/hyp/include/hyp/adjust_pc.h > > @@ -47,7 +47,13 @@ static inline void __kvm_skip_instr(struct kvm_vcpu *vcpu) > > */ > > static inline void kvm_skip_host_instr(void) > > { > > + u64 spsr = read_sysreg_el2(SYS_SPSR); > > + > > write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); > > + > > + spsr &= ~(PSR_BTYPE_MASK | DBG_SPSR_SS); > > + > > + write_sysreg_el2(spsr, SYS_SPSR); > > The handling of SS looks correct to me, but I think the BTYPE > manipulation could do with a little more commentary as it looks quite > subtle when the SMC is in a guarded page. Am I right in thinking: > > * If the SMC is in a guarded page, the Branch Target exception is > higher priority (12) than the trap to EL2 and so the host will > handle it. > > * Therefore if a trapping SMC is in a guarded page, BTYPE must be > zero and we don't have to worry about injecting a Branch Target > exception. > > * Otherwise, if the SMC is in a non-guarded page, we should clear it > to 0 per the architecture (R_YWFHD). > > ? This is all correct. If we get to emulate the SMC by trapping to EL2, it is that the instruction already satisfied the more basic execution requirements such as having an acceptable BTYPE at that PC. If that's OK with you, I'll nick that write-up and stick it into the next revision of the patch. > Having said that, I can't actually find the priority of an SMC trapped > to EL2 by HCR_EL2.TSC in the Arm ARM. Trapped HVCs are priority 15 and > SMCs trapped to EL3 are priority 23. My understanding is that this falls into the catch-all priority 22 of R_ZFGJP ("Other than an exception defined by priorities 4-21 inclusive, any exception that is the result of a configurable access to instructions, where the exception is taken to EL2."). Thanks, 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