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 4B88BC001DB for ; Thu, 10 Aug 2023 10:42:44 +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=vvbVy/Ga02MqIdPTWmSoB2vTatcFRoVXjI/8CWwkluw=; b=lt0WP1iHAoSE4l 9PVioeScmJb2p7eSVQhnla/UGWhWMlA0rAnaTFfVqJrMyMrhLFpcPnZKa+cun0pF/S2VuVxvGw5OS qxgbvhatE3MnIecAPEaqroBYLdcqd7MXmELgGmlpNK5Zf61Ox8gzLVkhY4pD/ku4FdDP/+eWCPxG/ EquO3D7i8BBjDDWX4tVvuxj6mZgxu2zZ1BvgQNPvRo+QKdtJZ0+1dEb2+2u/3LE06nsmC00IYF/Mx 3acwDkauBf2rIcZMtX4SO53rwgYFMxtEeep8dVnwgRpuofkrSyUaf3m+VgAzchiAY4BoJAWX2YiUy 1XC6vjQMwdLe73HCU9yA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU37V-007CPP-0A; Thu, 10 Aug 2023 10:42:21 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU37S-007CKd-1R for linux-arm-kernel@lists.infradead.org; Thu, 10 Aug 2023 10:42:19 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1F0AE65875; Thu, 10 Aug 2023 10:42:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75D3DC433C8; Thu, 10 Aug 2023 10:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691664134; bh=rrp6egUzhCSa8LB4UJXtnPAZrjrtZeHOWdqGHCsqluk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=t6qhRVWyE5x6ITeOhf9/PxysjQOKZagU8QhWv+3yyXYtylVd9PdAyoGaHFePMLH8R innN86AF7/9DBVtFW8YFDGcHxVDy4FkPYQffNPs+Zxd/vSSZPaTqIeBpl3dupA4mSR y+bZEk04ovsKeFWACp64EQhP/ogIVRfEdY0jrJ9J6QF7fj/Cfj04a+aKcHhBMEXbwT lIg9twdHPN0yXRsfl27gAUH7atabe8lggvyhCiVBc36bjp5UKX2A5eJrJipoziTFnw otfK7NVGOBx9KcP44PovncC/3m3J8oglS+Gk6GbB2dClqjMtOd4YpEvwCxAY5m9Dzj mFbyWLJrogUaQ== Received: from [195.11.108.100] (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 1qU37M-003nbt-0F; Thu, 10 Aug 2023 11:42:12 +0100 Date: Thu, 10 Aug 2023 11:42:19 +0100 Message-ID: <87wmy3p4ac.wl-maz@kernel.org> From: Marc Zyngier To: eric.auger@redhat.com Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Mark Brown , Mark Rutland , Will Deacon , Alexandru Elisei , Andre Przywara , Chase Conklin , Ganapatrao Kulkarni , Darren Hart , Miguel Luis , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: Re: [PATCH v3 23/27] KVM: arm64: nv: Add SVC trap forwarding In-Reply-To: <2a751a64-559e-cb17-4359-7f368c1b42ca@redhat.com> References: <20230808114711.2013842-1-maz@kernel.org> <20230808114711.2013842-24-maz@kernel.org> <2a751a64-559e-cb17-4359-7f368c1b42ca@redhat.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/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: 195.11.108.100 X-SA-Exim-Rcpt-To: eric.auger@redhat.com, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, broonie@kernel.org, mark.rutland@arm.com, will@kernel.org, alexandru.elisei@arm.com, andre.przywara@arm.com, chase.conklin@arm.com, gankulkarni@os.amperecomputing.com, darren@os.amperecomputing.com, miguel.luis@oracle.com, 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-20230810_034218_593472_ADA1AF16 X-CRM114-Status: GOOD ( 24.73 ) 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 Hi Eric, On Thu, 10 Aug 2023 09:35:41 +0100, Eric Auger wrote: > > Hi Marc, > > On 8/8/23 13:47, Marc Zyngier wrote: > > HFGITR_EL2 allows the trap of SVC instructions to EL2. Allow these > > traps to be forwarded. Take this opportunity to deny any 32bit activity > > when NV is enabled. > > I can't figure out how HFGITR_EL2.{SVC_EL1, SVC_EL0 and ERET} are > handled. Please could you explain. - SVC: KVM itself never traps it, so any trap of SVC must be the result of a guest trap -- we don't need to do any demultiplexing. We thus directly inject the trap back. This is what the comment in handle_svc() tries to capture, but obviously fails to convey the point. - ERET: This is already handled since 6898a55ce38c ("KVM: arm64: nv: Handle trapped ERET from virtual EL2"). Similarly to SVC, KVM never traps it unless we run NV. Now, looking into it, I think I'm missing the additional case where the L2 guest runs at vEL1. I'm about to add the following patchlet: diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 3b86d534b995..617ae6dea5d5 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -222,7 +222,22 @@ static int kvm_handle_eret(struct kvm_vcpu *vcpu) if (kvm_vcpu_get_esr(vcpu) & ESR_ELx_ERET_ISS_ERET) return kvm_handle_ptrauth(vcpu); - kvm_emulate_nested_eret(vcpu); + /* + * If we got here, two possibilities: + * + * - the guest is in EL2, and we need to fully emulate ERET + * + * - the guest is in EL1, and we need to reinject the + * exception into the L1 hypervisor. + * + * If KVM ever traps ERET for its own use, we'll have to + * revisit this. + */ + if (is_hyp_ctxt(vcpu)) + kvm_emulate_nested_eret(vcpu); + else + kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu)); + return 1; } Does the above help? 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