From patchwork Wed Sep 4 08:24:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13790080 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 E7695CD3431 for ; Wed, 4 Sep 2024 08:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MXv18elTNhoTPaJvD5DE1MGgx7c0c1B3N6yeuplg3Y4=; b=AdWfe8lUhxNX4GqimudeUrOHhU NNrz1nMdFeSGgtXcmj83PxYKWjiWNz7BUHbsayi9VkBFXGi3WyxkYbAqIDWDYjHUKyf8XBI0Ukb4K 2aoUwdOKCHBUH6kfYlccsEebFRFv9GIu3N1EdlUnQbktEsfNeuSOldx2n9IoZAsWmdUorxNRkev3F ldXiMUkT9pEfb7JA9wf3k5SlkXN1/pCKVs47bpj/RH510YIfng4+ICgR6KJzQjPI9uad18CwZuW9E t/o5oDvfRVD8/VgJHy1pZ+k2V4WzX+g9kv/mXAWcPayACWoyUU8jzbZgEyvW9vFy6/GoN/3M5ymqx 4a1JCljA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllWJ-00000003S0B-2Cfx; Wed, 04 Sep 2024 08:37:43 +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 1sllJh-00000003OIi-20vn for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 08:24:45 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 6D8235C579C; Wed, 4 Sep 2024 08:24:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92877C4CECA; Wed, 4 Sep 2024 08:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725438280; bh=fZHddvF+qYhgRuvqft59eESqhUj0wguwxqDnkpoLylI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gs7dD/FYwUpk6GUD26LeNN+TuWtGlRVm52wdMzUTi74VXpAI5kyudsp8PBlSjOFY6 TvfY7qMfOkm9Gy1bpC9s5k+FTEwIRZBabu83Y/nRgM5eB47ddL92klDlRefp9jtUHn tiDSgzvFC2D8zb3HgROaT66+U/MWxS/nI/7Su2cgvb738enJetviCNBrCHEKpXhgb3 64PZq/I/906Lb03ZPjZWC2IaBMROqDPqCvdDMXfb+qSj5hA9HuJcIuRJpxGx1d+Dqj p8ONNnh0PBpExNS2XrOnXRhFOV3miVhMh8vzmyKchScy5tWOarJkaqIJWYqweqotv8 Ap4x6Y+hmHKvw== 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 1sllJe-009VF3-FH; Wed, 04 Sep 2024 09:24:38 +0100 From: Marc Zyngier To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH 1/3] KVM: arm64: Simplify handling of CNTKCTL_EL12 Date: Wed, 4 Sep 2024 09:24:17 +0100 Message-Id: <20240904082419.1982402-2-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240904082419.1982402-1-maz@kernel.org> References: <20240904082419.1982402-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, kvm@vger.kernel.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-20240904_012441_637599_0F31A09D X-CRM114-Status: GOOD ( 13.30 ) 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 go trough a great deal of effort to map CNTKCTL_EL12 to CNTKCTL_EL1 while hidding this mapping from userspace via a special visibility helper. However, it would be far simpler to just provide an accessor doing the mapping job, removing the need for a visibility helper. With that done, we can also remove the EL12_REG() macro which serves no purpose. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 45c9e3b2acd4..5328fac8d547 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2105,15 +2105,6 @@ static unsigned int hidden_user_visibility(const struct kvm_vcpu *vcpu, return REG_HIDDEN_USER; } -#define EL12_REG(name, acc, rst, v) { \ - SYS_DESC(SYS_##name##_EL12), \ - .access = acc, \ - .reset = rst, \ - .reg = name##_EL1, \ - .val = v, \ - .visibility = hidden_user_visibility, \ -} - /* * Since reset() callback and field val are not used for idregs, they will be * used for specific purposes for idregs. @@ -2221,6 +2212,18 @@ static bool access_spsr(struct kvm_vcpu *vcpu, return true; } +static bool access_cntkctl_el12(struct kvm_vcpu *vcpu, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + if (p->is_write) + __vcpu_sys_reg(vcpu, CNTKCTL_EL1) = p->regval; + else + p->regval = __vcpu_sys_reg(vcpu, CNTKCTL_EL1); + + return true; +} + static u64 reset_hcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { u64 val = r->val; @@ -2825,7 +2828,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { EL2_REG_VNCR(CNTVOFF_EL2, reset_val, 0), EL2_REG(CNTHCTL_EL2, access_rw, reset_val, 0), - EL12_REG(CNTKCTL, access_rw, reset_val, 0), + { SYS_DESC(SYS_CNTKCTL_EL12), access_cntkctl_el12 }, EL2_REG(SP_EL2, NULL, reset_unknown, 0), };