From patchwork Tue Jun 4 13:05:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13685270 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 667C0C25B78 for ; Tue, 4 Jun 2024 13:06:15 +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=jodMBOZwE743KcAWW8teia/JA164gBWWET0Pydxqha0=; b=S3xEdiPOjVfgKr R1rplvqKSoaHExWKxGRHJXNi9N1HfIVIPYYi9aOUNBPFQSwUlIU5LtjTRtHjuR5T9EyS+yC13kZKv MRJAJLDhmQjGe8HTdyFt8V5tgyoo1rH6r08giKGB3NuERFvZHD1/SKBjltMqGgImhMGZ+jFKcONkC AvqXa6aEem3WwJlgyDAd+UCs222S+lTiAa1wlZZGfICQk+2p5Rrp/IPSq9WhtTCSaoATn83cZ9l6e YkoHIDG4ddVqnWJAl/VxRhd4+ZwvQ7Dy2P8Zy1spYAdrR+RvQp3xlTOHX4ira7ZB9aMw0L6zOr8mm HpPE8XQXgAHhn+46VGZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sETrY-00000002R5Q-0BrF; Tue, 04 Jun 2024 13:06:04 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sETrU-00000002R3O-3f0s for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2024 13:06:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 277046128B; Tue, 4 Jun 2024 13:06:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2E5CC3277B; Tue, 4 Jun 2024 13:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717506359; bh=W4XtQbfKfPiW8qFhBjSSzdUa5W+6VR/bSx7605s9t/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roM4mJEnLK8KlmFzS2WdPUl6U74GyJJPZa4siHn8vKobsMun3PMTGOVimVRyVSCbD tBdZvNBDjlanrnChiIdg+JIHpPZJr1TZjIIgN4loyu2/1O+plErxcnuHHPq8ziQTSa cWNYFkGd5gyEAty8rE3xaISHl/Sc39CB/GTc/4rvUwtDUQxOOMvql3ErJ9aNyRF7ie e83EZ71LfubI32VY1hw9r1g90o5JVTrFjU/OzyGnNcFdCkxm6NqpMtUOtpKvIUhEmC EwjxJlMdyJnAxx4nidl4rFCvMl6rBjYxptwKoNGXH1WV5UKwcb69pEEQq9nuPcebDm S33D8hKkkw2fA== 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 1sETrS-000ZSS-3k; Tue, 04 Jun 2024 14:05:58 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Joey Gouly Subject: [PATCH 4/4] KVM: arm64: nv: Handle CPACR_EL1 traps Date: Tue, 4 Jun 2024 14:05:53 +0100 Message-Id: <20240604130553.199981-5-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240604130553.199981-1-maz@kernel.org> References: <20240604130553.199981-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, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, joey.gouly@arm.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-20240604_060601_109735_555FA963 X-CRM114-Status: GOOD ( 14.13 ) 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 Handle CPACR_EL1 accesses when running a VHE guest. In order to limit the cost of the emulation, implement it ass a shallow exit. In the other cases: - this is a nVHE L1 which will write to memory, and we don't trap - this is a L2 guest: * the L1 has CPTR_EL2.TCPAC==0, and the L2 has direct register access * the L1 has CPTR_EL2.TCPAC==1, and the L2 will trap, but the handling is defered to the general handling for forwarding Signed-off-by: Marc Zyngier --- arch/arm64/kvm/hyp/vhe/switch.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/vhe/switch.c b/arch/arm64/kvm/hyp/vhe/switch.c index b4ba236526d6..c1711f2b92b8 100644 --- a/arch/arm64/kvm/hyp/vhe/switch.c +++ b/arch/arm64/kvm/hyp/vhe/switch.c @@ -295,10 +295,40 @@ static bool kvm_hyp_handle_eret(struct kvm_vcpu *vcpu, u64 *exit_code) return true; } +static bool kvm_hyp_handle_cpacr_el1(struct kvm_vcpu *vcpu, u64 *exit_code) +{ + u64 esr = kvm_vcpu_get_esr(vcpu); + int rt; + + if (!is_hyp_ctxt(vcpu) || esr_sys64_to_sysreg(esr) != SYS_CPACR_EL1) + return false; + + rt = kvm_vcpu_sys_get_rt(vcpu); + + if ((esr & ESR_ELx_SYS64_ISS_DIR_MASK) == ESR_ELx_SYS64_ISS_DIR_READ) { + vcpu_set_reg(vcpu, rt, __vcpu_sys_reg(vcpu, CPTR_EL2)); + } else { + vcpu_write_sys_reg(vcpu, vcpu_get_reg(vcpu, rt), CPTR_EL2); + __activate_cptr_traps(vcpu); + } + + __kvm_skip_instr(vcpu); + + return true; +} + +static bool kvm_hyp_handle_sysreg_vhe(struct kvm_vcpu *vcpu, u64 *exit_code) +{ + if (kvm_hyp_handle_cpacr_el1(vcpu, exit_code)) + return true; + + return kvm_hyp_handle_sysreg(vcpu, exit_code); +} + static const exit_handler_fn hyp_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = NULL, [ESR_ELx_EC_CP15_32] = kvm_hyp_handle_cp15_32, - [ESR_ELx_EC_SYS64] = kvm_hyp_handle_sysreg, + [ESR_ELx_EC_SYS64] = kvm_hyp_handle_sysreg_vhe, [ESR_ELx_EC_SVE] = kvm_hyp_handle_fpsimd, [ESR_ELx_EC_FP_ASIMD] = kvm_hyp_handle_fpsimd, [ESR_ELx_EC_IABT_LOW] = kvm_hyp_handle_iabt_low,