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 6F1E7C77B7D for ; Mon, 15 May 2023 17:50:07 +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=tkCS3XDmskAw4w7V3us+sS2ohyhIeQ/TYfyeRYVhaRg=; b=idD01Eo60vQ3pZ 2vs4tPniZ58rV072HbejVWlorxw/HvEXfFIlyfJma6vX0QbzphdFI7s2yt+CffspRupunreVjfW0y ReHhAxsxL9FcV4b59/vXlGmm6gdKeYKWTXx01038sMM10FNy+RymOfdhx0IVtUWmSeS0CKrzOBIor u+9L+VS/v7jpP5nwAq5rlD0Xbm4HqOIKu2DA3Pl8wUU5qdiELa03PRPENCokUsl4IXw1w5VQ3Td0g bqXDuAbTBEWUxt5lzzievkekuQz2lXdWO0wdTDC5BjJENVQZzXEXwC/0pfCbNXcKrmkHLHPymXcum Bhy1292wljMqlG9coU7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pycKN-0031y5-0W; Mon, 15 May 2023 17:49:43 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pycJP-0031At-28 for linux-arm-kernel@bombadil.infradead.org; Mon, 15 May 2023 17:48:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=28WWDpBNbi9on2IgyPBxd+jEXp3E1/4Eb6gSTI2I96M=; b=Nb2eR+JCerdgknyfKPcAHSpRko +Yhtkd4vCLx4kcHITVbBU07vIj6QQHv1z+SRDvgVGf0hiiZqGI6WeuTiZJgvnEUsL+b8QfXYfNrX0 IPFa8GVN62Xe5muCwi9mpaUy3PenVIGlW8MH20v5oNEXXmEiuA6v1tgTIjM1YiTf8nzEA93X5qKQT PTgwkRY9fE8I5q79jgcu00L1t5MoAz5nNcctFlzVVChrD8/OhZWQ66LQxT2UyiYlrJZydo7LxeneU h4uaef5eEeHc8tA2oRwLszQqzbGn2jryiTq01+jlfak0GXKYh5R/7mrQsl1K/4mYKY87RPQeVdg6s hlhCZ8jA==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pycJM-00BXlI-13 for linux-arm-kernel@lists.infradead.org; Mon, 15 May 2023 17:48:42 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D5F0662EFF; Mon, 15 May 2023 17:48:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45C8BC433D2; Mon, 15 May 2023 17:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684172919; bh=uDu/P8ije5njWio+YUZzvWweON/h4ewRjVQnVqdIEmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VewrugagB+d2VdMnqkCNtW6yg7D6wfrcy3haWAKpiezUhrohb8SkOH2TPyXnC6Rtx VUTB/Hull3tZ7RLkb0nEcaypW4B/z3cR3YwllObXb6oSekZyWhAhrZIL3t7QWiLT+M qdOaj12zQtwoUjQnDefVCWabxVhmu1ze2GZHqf0pb1rqtzwqqIES/ywB2TQzQqVp6b +4OILLUGlLJS+uWojnNwNnpsg2eyffx2TeuGegu3whV1pWwrMjm79PYZIrHs9tYINR 6H3Hj7TStyeg1Vf01ZR86iuWrKUdl1VFQGSNOAy5OGx7Th6iy6NuoYkGJxTNTZyUBw SECWZiorMj4kA== 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 1pyc2j-00FJAF-E3; Mon, 15 May 2023 18:31:29 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Alexandru Elisei , Andre Przywara , Chase Conklin , Christoffer Dall , Ganapatrao Kulkarni , Darren Hart , Jintack Lim , Russell King , Miguel Luis , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH v10 23/59] KVM: arm64: nv: Respect virtual HCR_EL2.{NV,TSC) settings Date: Mon, 15 May 2023 18:30:27 +0100 Message-Id: <20230515173103.1017669-24-maz@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230515173103.1017669-1-maz@kernel.org> References: <20230515173103.1017669-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, alexandru.elisei@arm.com, andre.przywara@arm.com, chase.conklin@arm.com, christoffer.dall@arm.com, gankulkarni@os.amperecomputing.com, darren@os.amperecomputing.com, jintack@cs.columbia.edu, rmk+kernel@armlinux.org.uk, 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-20230515_184840_728974_53C12D0D X-CRM114-Status: GOOD ( 17.87 ) 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 From: Jintack Lim Forward traps due to HCR_EL2.{NV,TSC} bits to the virtual EL2 if they are not coming from the virtual EL2, corresponding to SMC and ERET instructions. Signed-off-by: Jintack Lim [Moved code to emulate-nested.c] Signed-off-by: Christoffer Dall [maz: drastically simplified] Signed-off-by: Marc Zyngier --- arch/arm64/include/asm/kvm_nested.h | 1 + arch/arm64/kvm/emulate-nested.c | 27 +++++++++++++++++++++++++++ arch/arm64/kvm/handle_exit.c | 7 +++++++ 3 files changed, 35 insertions(+) diff --git a/arch/arm64/include/asm/kvm_nested.h b/arch/arm64/include/asm/kvm_nested.h index 9099df57037d..948ba0337558 100644 --- a/arch/arm64/include/asm/kvm_nested.h +++ b/arch/arm64/include/asm/kvm_nested.h @@ -59,6 +59,7 @@ static inline u64 translate_ttbr0_el2_to_ttbr0_el1(u64 ttbr0) return ttbr0 & ~GENMASK_ULL(63, 48); } +extern bool forward_smc_trap(struct kvm_vcpu *vcpu); extern bool __check_nv_sr_forward(struct kvm_vcpu *vcpu); struct sys_reg_params; diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c index 101292c43602..08b152f8ba6a 100644 --- a/arch/arm64/kvm/emulate-nested.c +++ b/arch/arm64/kvm/emulate-nested.c @@ -900,6 +900,26 @@ bool __check_nv_sr_forward(struct kvm_vcpu *vcpu) return true; } +static bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit) +{ + bool control_bit_set; + + if (!vcpu_has_nv(vcpu)) + return false; + + control_bit_set = __vcpu_sys_reg(vcpu, HCR_EL2) & control_bit; + if (!vcpu_is_el2(vcpu) && control_bit_set) { + kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu)); + return true; + } + return false; +} + +bool forward_smc_trap(struct kvm_vcpu *vcpu) +{ + return forward_traps(vcpu, HCR_TSC); +} + static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr) { u64 mode = spsr & PSR_MODE_MASK; @@ -938,6 +958,13 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) u64 spsr, elr, mode; bool direct_eret; + /* + * Forward this trap to the virtual EL2 if the virtual + * HCR_EL2.NV bit is set and this is coming from !EL2. + */ + if (forward_traps(vcpu, HCR_NV)) + return; + /* * Going through the whole put/load motions is a waste of time * if this is a VHE guest hypervisor returning to its own diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index c4dc144726ee..5903102c83f5 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -55,6 +55,13 @@ static int handle_hvc(struct kvm_vcpu *vcpu) static int handle_smc(struct kvm_vcpu *vcpu) { + /* + * Forward this trapped smc instruction to the virtual EL2 if + * the guest has asked for it. + */ + if (forward_smc_trap(vcpu)) + return 1; + /* * "If an SMC instruction executed at Non-secure EL1 is * trapped to EL2 because HCR_EL2.TSC is 1, the exception is a -- 2.34.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel