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: 13789971 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D762417C987; Wed, 4 Sep 2024 08:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725438280; cv=none; b=XqCPiJxMhcX8d+dLuyztisffP051cPLMQnag3WAd2j6rt8M+g5+I/y1vsefzkL3b0OpaHV8HisfULZuqmyd8UlZ+cZu3JbodWOfhwkA9hrEveXx9A5TfgM9Ytu82m8dehcrjqBROdy09GJdF5ceaVZEgqLyUctHjQBD+KZUkcJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725438280; c=relaxed/simple; bh=fZHddvF+qYhgRuvqft59eESqhUj0wguwxqDnkpoLylI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LbHkZOCbaeNTLFqyaKpSpk/hB47hQAHB8uNWJh7T98vagf+aOkzDs8BIficGSJEkf+tCBCugHr1ZEsw/yh6tLkOBROwUD6AzJ95IUhJcaxlwqvkYzBwu7XKkyGQt2yLq4V1cMYReeBs5WEvdeaMdyRZBrvCizcowYFdMXSzypQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gs7dD/FY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Gs7dD/FY" 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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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), }; From patchwork Wed Sep 4 08:24:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13789973 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D75DF17279E; Wed, 4 Sep 2024 08:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725438280; cv=none; b=Znl40fCKC2xi/cJcu24V+b6nD8fhGiz3XNZsO9Ja7cWAuXIMvUs7zK0ESqovu+o0mK4TJaMlOlZ4jm8vhNRALMc+peo2NgjOw9OSn0Gy60PAQMnpNk/Pyv2FOJeKqKpR00Z1gzrje/t3ZlQmUaHcBu6SV+WNIU1YsQkKCjmI1mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725438280; c=relaxed/simple; bh=xIxn7pFaazMnNLaow2U2RFpl78qYQZADsRhk/aFuMDA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dRnbaldaKbpU8BhCPlwFn2pmWVCZ4rfEstXEjXF/E3PfZVTo12yeP4oOQRkVUK+VTPV7ud4QcnHz8/0iW9+PdEYRxbFiBz2K0k9NqXDVcwUsPdhOQ5X7PUFfpzf2ls39KomtuXwPwnezNMHeqAhfZRIReBznQ6i0VA4UgVATUNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lK8Pv7uV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lK8Pv7uV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90313C4AF0C; 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=xIxn7pFaazMnNLaow2U2RFpl78qYQZADsRhk/aFuMDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lK8Pv7uVaM8ay9ZRDgWSyp/oCUG9wsKhrj29HfzCgqFOc53VoOqiSC5bN3al2MWYo DB4ljJGq70CvJR2+NuvmR9npIOHuen01PxZoL+e/NnGw/aiBse9PFjjv7SO3ibaKUg XErXRAz0nGfW1Fc2IsXd2X0QFgT1sEwxdphtH2u+cPicKtJzHGWotgE2ZfbK51Viv7 SpxZCJ37q2O5pBG8JLmpcaHPnURqglF+o8BnG+7tcLP3DnhAbhjMkdQMan8DTqk2Tr xH9ZoNQLCI5IkAH2gxK+fYTckbHv++jlu6THNuh82k8wq4zIGmGq9DdeUKDy+AVUdu r1ANSNNMST3Jg== 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-LD; 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 2/3] KVM: arm64: Simplify visibility handling of AArch32 SPSR_* Date: Wed, 4 Sep 2024 09:24:18 +0100 Message-Id: <20240904082419.1982402-3-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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Since SPSR_* are not associated with any register in the sysreg array, nor do they have .get_user()/.set_user() helpers, they are invisible to userspace with that encoding. Therefore hidden_user_visibility() serves no purpose here, and can be safely removed. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 5328fac8d547..2586ad29eaa0 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2795,14 +2795,10 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_SP_EL1), access_sp_el1}, /* AArch32 SPSR_* are RES0 if trapped from a NV guest */ - { SYS_DESC(SYS_SPSR_irq), .access = trap_raz_wi, - .visibility = hidden_user_visibility }, - { SYS_DESC(SYS_SPSR_abt), .access = trap_raz_wi, - .visibility = hidden_user_visibility }, - { SYS_DESC(SYS_SPSR_und), .access = trap_raz_wi, - .visibility = hidden_user_visibility }, - { SYS_DESC(SYS_SPSR_fiq), .access = trap_raz_wi, - .visibility = hidden_user_visibility }, + { SYS_DESC(SYS_SPSR_irq), .access = trap_raz_wi }, + { SYS_DESC(SYS_SPSR_abt), .access = trap_raz_wi }, + { SYS_DESC(SYS_SPSR_und), .access = trap_raz_wi }, + { SYS_DESC(SYS_SPSR_fiq), .access = trap_raz_wi }, { SYS_DESC(SYS_IFSR32_EL2), undef_access, reset_unknown, IFSR32_EL2 }, EL2_REG(AFSR0_EL2, access_rw, reset_val, 0), From patchwork Wed Sep 4 08:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13789974 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D766A17C9AA; Wed, 4 Sep 2024 08:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725438280; cv=none; b=AwKHxxKH3Dd2LYlOk6BEJgCUOWwmga8thy2Eh21Hgo7UW9ofkL0VPAauybUTxpNDqojkttUgZl42NniFy/DWI0FfzOc4a7GBJsql9aGFYwgyTeTbJJkSrPE6pO8bmP0VaJ1Uq+MdHGtR8CSm9XWMVoqOO4OomaghnDgQG5f33c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725438280; c=relaxed/simple; bh=Fhau2/U9M+BMgStDw+xZRk0wrsOilXlXn/q0zd3fcrw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lNLjq3vv3Nz1DmE/JR/4swdGXrTAEK5O4hnpgE2vu75vVQQ3oPQPGHRAPL6skegibV7Y48XtRz4zd2FoegAkYEhPJAyUx/FeDBjJYVqdQ08Q93P+MaHHIO8TT98evGxU1guB83esrlhlsgaQekorWg/HNlnyIdkjxWfzQYzdQVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VA4vu3BP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VA4vu3BP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D573C4CEC8; 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=Fhau2/U9M+BMgStDw+xZRk0wrsOilXlXn/q0zd3fcrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VA4vu3BPknG/Obx0pIjackogjRv5u15j+TfoA+6I8De+vJGJoZkn2Qewj2a4EMlhF 6Szr1TPenZP55XizUZNyvSHWJcTknL/8k4JO49FrPcBmHaT4XyXtbCIdRdjGCEoCJv Syrk2DV5UJQ/bz7+9pk06uLfatWG7LAjaGxfMlEnpWotn+ZXa/BQPx8oa0xRM7jQAG k5Z52WyUmpBq24z7kW/devw2p2ZEk/jY54fCLu4nqEl16jIQL/KC3iKnJ1ao+hPYyK CWFmvR8V6gHO0Ny6DK59XsRWuP/vJU6Rp4W4stNpa4bTSM1cpMfWAfwRZwHuQ9Heqx VRuptPWSKW/lQ== 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-R3; 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 3/3] KVM: arm64: Get rid of REG_HIDDEN_USER visibility qualifier Date: Wed, 4 Sep 2024 09:24:19 +0100 Message-Id: <20240904082419.1982402-4-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> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 Now that REG_HIDDEN_USER has no direct user anymore, remove it entirely and update all users of sysreg_hidden_user() to call sysreg_hidden() instead. Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 17 +++-------------- arch/arm64/kvm/sys_regs.h | 14 ++------------ 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 2586ad29eaa0..09a6a45efb49 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2094,17 +2094,6 @@ static bool bad_redir_trap(struct kvm_vcpu *vcpu, #define EL2_REG_VNCR(name, rst, v) EL2_REG(name, bad_vncr_trap, rst, v) #define EL2_REG_REDIR(name, rst, v) EL2_REG(name, bad_redir_trap, rst, v) -/* - * EL{0,1}2 registers are the EL2 view on an EL0 or EL1 register when - * HCR_EL2.E2H==1, and only in the sysreg table for convenience of - * handling traps. Given that, they are always hidden from userspace. - */ -static unsigned int hidden_user_visibility(const struct kvm_vcpu *vcpu, - const struct sys_reg_desc *rd) -{ - return REG_HIDDEN_USER; -} - /* * Since reset() callback and field val are not used for idregs, they will be * used for specific purposes for idregs. @@ -4364,7 +4353,7 @@ int kvm_sys_reg_get_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, int ret; r = id_to_sys_reg_desc(vcpu, reg->id, table, num); - if (!r || sysreg_hidden_user(vcpu, r)) + if (!r || sysreg_hidden(vcpu, r)) return -ENOENT; if (r->get_user) { @@ -4408,7 +4397,7 @@ int kvm_sys_reg_set_user(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg, return -EFAULT; r = id_to_sys_reg_desc(vcpu, reg->id, table, num); - if (!r || sysreg_hidden_user(vcpu, r)) + if (!r || sysreg_hidden(vcpu, r)) return -ENOENT; if (sysreg_user_write_ignore(vcpu, r)) @@ -4494,7 +4483,7 @@ static int walk_one_sys_reg(const struct kvm_vcpu *vcpu, if (!(rd->reg || rd->get_user)) return 0; - if (sysreg_hidden_user(vcpu, rd)) + if (sysreg_hidden(vcpu, rd)) return 0; if (!copy_reg_to_user(rd, uind)) diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h index dfb2ec83b284..1d94ed6efad2 100644 --- a/arch/arm64/kvm/sys_regs.h +++ b/arch/arm64/kvm/sys_regs.h @@ -95,9 +95,8 @@ struct sys_reg_desc { }; #define REG_HIDDEN (1 << 0) /* hidden from userspace and guest */ -#define REG_HIDDEN_USER (1 << 1) /* hidden from userspace only */ -#define REG_RAZ (1 << 2) /* RAZ from userspace and guest */ -#define REG_USER_WI (1 << 3) /* WI from userspace only */ +#define REG_RAZ (1 << 1) /* RAZ from userspace and guest */ +#define REG_USER_WI (1 << 2) /* WI from userspace only */ static __printf(2, 3) inline void print_sys_reg_msg(const struct sys_reg_params *p, @@ -165,15 +164,6 @@ static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu, return sysreg_visibility(vcpu, r) & REG_HIDDEN; } -static inline bool sysreg_hidden_user(const struct kvm_vcpu *vcpu, - const struct sys_reg_desc *r) -{ - if (likely(!r->visibility)) - return false; - - return r->visibility(vcpu, r) & (REG_HIDDEN | REG_HIDDEN_USER); -} - static inline bool sysreg_visible_as_raz(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) {