diff mbox series

[v4,27/36] KVM: arm64: Add a composite EL2 visibility helper

Message ID 20241009190019.3222687-28-maz@kernel.org (mailing list archive)
State New
Headers show
Series KVM: arm64: Add EL2 support to FEAT_S1PIE/S1POE | expand

Commit Message

Marc Zyngier Oct. 9, 2024, 7 p.m. UTC
We are starting to have a bunch of visibility helpers checking
for EL2 + something else, and we are going to add more.

Simplify things somehow by introducing a helper that implement
extractly that by taking a visibility helper as a parameter,
and convert the existing ones to that.

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/kvm/sys_regs.c | 32 +++++++++++---------------------
 1 file changed, 11 insertions(+), 21 deletions(-)

Comments

Oliver Upton Oct. 10, 2024, 7:52 a.m. UTC | #1
On Wed, Oct 09, 2024 at 08:00:10PM +0100, Marc Zyngier wrote:
> We are starting to have a bunch of visibility helpers checking
> for EL2 + something else, and we are going to add more.
> 
> Simplify things somehow by introducing a helper that implement
> extractly that by taking a visibility helper as a parameter,
> and convert the existing ones to that.
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>

nit: avoid churn and order this before introducing more open-coded
instances of EL2 + FEAT_something checks.
diff mbox series

Patch

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index b5c2662662af9..6c20de8607b2d 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -2277,16 +2277,18 @@  static u64 reset_hcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
 	return __vcpu_sys_reg(vcpu, r->reg) = val;
 }
 
+static unsigned int __el2_visibility(const struct kvm_vcpu *vcpu,
+				     const struct sys_reg_desc *rd,
+				     unsigned int (*fn)(const struct kvm_vcpu *,
+							const struct sys_reg_desc *))
+{
+	return el2_visibility(vcpu, rd) ?: fn(vcpu, rd);
+}
+
 static unsigned int sve_el2_visibility(const struct kvm_vcpu *vcpu,
 				       const struct sys_reg_desc *rd)
 {
-	unsigned int r;
-
-	r = el2_visibility(vcpu, rd);
-	if (r)
-		return r;
-
-	return sve_visibility(vcpu, rd);
+	return __el2_visibility(vcpu, rd, sve_visibility);
 }
 
 static bool access_zcr_el2(struct kvm_vcpu *vcpu,
@@ -2332,13 +2334,7 @@  static unsigned int tcr2_visibility(const struct kvm_vcpu *vcpu,
 static unsigned int tcr2_el2_visibility(const struct kvm_vcpu *vcpu,
 				    const struct sys_reg_desc *rd)
 {
-	unsigned int r;
-
-	r = el2_visibility(vcpu, rd);
-	if (r)
-		return r;
-
-	return tcr2_visibility(vcpu, rd);
+	return __el2_visibility(vcpu, rd, tcr2_visibility);
 }
 
 static unsigned int s1pie_visibility(const struct kvm_vcpu *vcpu,
@@ -2353,13 +2349,7 @@  static unsigned int s1pie_visibility(const struct kvm_vcpu *vcpu,
 static unsigned int s1pie_el2_visibility(const struct kvm_vcpu *vcpu,
 					 const struct sys_reg_desc *rd)
 {
-	unsigned int r;
-
-	r = el2_visibility(vcpu, rd);
-	if (r)
-		return r;
-
-	return s1pie_visibility(vcpu, rd);
+	return __el2_visibility(vcpu, rd, s1pie_visibility);
 }
 
 /*