From patchwork Tue Aug 15 18:38:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13354104 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 8B9CEC001E0 for ; Tue, 15 Aug 2023 18:47:28 +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: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i+xKxapES052YaJfk21klc4sbGtuKFK4ZLcMOnmEtKc=; b=WaMs1a+tiUlQW+ E1c5RcwUJi5RM0aeskY9Vvo1Az4JaRccd3ICI00jDkFzJPd7WsxmhGkUsYb7Hl0hhUZuyEI/8KCvJ 4iMYSRk5xibK4YOSCyQXX1JqcGVBI+PAGOKCY1aPcYivCHcRnF607BDI/N8tltQ0xv6KxMWTy707h P9KstZImdcfVy4CA6TjvBHoL+dE29KAslbq6OZLgDkEZRsuBTULTbgeJnOAnPpDhxwFadpr5s0xvm kC0VZiDiQOeeA0YhZXRqyV6K9Hv0+Q9QEbL3vreVqL3fUHvrtHv9StTXz/n8eLWRWrrK1GILyMIuU Eb4r/0o0Kh9Yf+kVnOeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVz4L-002D8i-2L; Tue, 15 Aug 2023 18:47:05 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qVz4I-002D6p-0L for linux-arm-kernel@lists.infradead.org; Tue, 15 Aug 2023 18:47:03 +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 9E4A565F8D; Tue, 15 Aug 2023 18:47:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01E59C433C7; Tue, 15 Aug 2023 18:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692125221; bh=2MC33VMubl8Wc9QSc0xTB0giIGZo60Zeezs0Qg0LdXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=edoi+fZeepxyjeapWBbtnA720RNM/axdOSszV/L3UCZXf3aFzsuK9V3bB7WQNUdAJ Q8kBsxZHMw0vmOMSc2jhaTiWhyP5kZQoTIQeAH629aChNdkxDR/Gf0tnICqHOTsyl0 5J99Hx18ks+7eCfxgzXtLxLmqHKbw1qe1GWXJm60xzyUqKDbQnyeORdwT910v1UNsa t4m++3W7GfgXvKVNaeWx6V9ZihtDa5MtEfpChLHMukiAsgbS06l7ENDhA2OvnFoEdJ nrFq95Lbz/EqFR2yPvnrJXFok5g3lTMx5zdh4Pz30tZChIRl0KTJwYefDhkqokGBta BgrtD5qKvB3dA== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qVywr-0055Sd-Nk; Tue, 15 Aug 2023 19:39:21 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Eric Auger , Mark Brown , Mark Rutland , Will Deacon , Alexandru Elisei , Andre Przywara , Chase Conklin , Ganapatrao Kulkarni , Darren Hart , Miguel Luis , Jing Zhang , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH v4 24/28] KVM: arm64: nv: Expand ERET trap forwarding to handle FGT Date: Tue, 15 Aug 2023 19:38:58 +0100 Message-Id: <20230815183903.2735724-25-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230815183903.2735724-1-maz@kernel.org> References: <20230815183903.2735724-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, eric.auger@redhat.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, jingzhangos@google.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-20230815_114702_232239_58111575 X-CRM114-Status: GOOD ( 15.78 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We already handle ERET being trapped from a L1 guest in hyp context. However, with FGT, we can also have ERET being trapped from L2, and this needs to be reinjected into L1. Add the required exception routing. Signed-off-by: Marc Zyngier Reviewed-by: Jing Zhang --- arch/arm64/kvm/handle_exit.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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; }