KVM: arm64: Refactor CPACR trap bit setting/clearing to use ELx format
authorFuad Tabba <tabba@google.com>
Mon, 3 Jun 2024 12:28:50 +0000 (13:28 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 4 Jun 2024 14:06:33 +0000 (15:06 +0100)
When setting/clearing CPACR bits for EL0 and EL1, use the ELx
format of the bits, which covers both. This makes the code
clearer, and reduces the chances of accidentally missing a bit.

No functional change intended.

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://lore.kernel.org/r/20240603122852.3923848-9-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/el2_setup.h
arch/arm64/include/asm/kvm_emulate.h
arch/arm64/kvm/fpsimd.c
arch/arm64/kvm/hyp/nvhe/pkvm.c
arch/arm64/kvm/hyp/nvhe/switch.c
arch/arm64/kvm/hyp/vhe/switch.c

index e4546b29dd0cbfbb5b902e15caadab69458b1fac..fd87c4b8f984039ceeba3d2da074f66293733a64 100644 (file)
 /* Coprocessor traps */
 .macro __init_el2_cptr
        __check_hvhe .LnVHE_\@, x1
-       mov     x0, #(CPACR_EL1_FPEN_EL1EN | CPACR_EL1_FPEN_EL0EN)
+       mov     x0, #CPACR_ELx_FPEN
        msr     cpacr_el1, x0
        b       .Lskip_set_cptr_\@
 .LnVHE_\@:
 
        // (h)VHE case
        mrs     x0, cpacr_el1                   // Disable SVE traps
-       orr     x0, x0, #(CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN)
+       orr     x0, x0, #CPACR_ELx_ZEN
        msr     cpacr_el1, x0
        b       .Lskip_set_cptr_\@
 
 
        // (h)VHE case
        mrs     x0, cpacr_el1                   // Disable SME traps
-       orr     x0, x0, #(CPACR_EL1_SMEN_EL0EN | CPACR_EL1_SMEN_EL1EN)
+       orr     x0, x0, #CPACR_ELx_SMEN
        msr     cpacr_el1, x0
        b       .Lskip_set_cptr_sme_\@
 
index 2d7a0bdf9d03f52970fd764b8f0a139131faac1e..21650e7924d45846dacc0c99344d98c03f0eb574 100644 (file)
@@ -632,17 +632,16 @@ static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu)
        u64 val;
 
        if (has_vhe()) {
-               val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |
-                      CPACR_EL1_ZEN_EL1EN);
+               val = (CPACR_ELx_FPEN | CPACR_EL1_ZEN_EL1EN);
                if (cpus_have_final_cap(ARM64_SME))
                        val |= CPACR_EL1_SMEN_EL1EN;
        } else if (has_hvhe()) {
-               val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN);
+               val = CPACR_ELx_FPEN;
 
                if (!vcpu_has_sve(vcpu) || !guest_owns_fp_regs())
-                       val |= CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN;
+                       val |= CPACR_ELx_ZEN;
                if (cpus_have_final_cap(ARM64_SME))
-                       val |= CPACR_EL1_SMEN_EL1EN | CPACR_EL1_SMEN_EL0EN;
+                       val |= CPACR_ELx_SMEN;
        } else {
                val = CPTR_NVHE_EL2_RES1;
 
index 1807d3a79a8af8dbc22a5c34f4e289d3359b90f2..eb21f29d91fc5ebae4f0fc26e768063b55fbba7b 100644 (file)
@@ -161,9 +161,7 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
        if (has_vhe() && system_supports_sme()) {
                /* Also restore EL0 state seen on entry */
                if (vcpu_get_flag(vcpu, HOST_SME_ENABLED))
-                       sysreg_clear_set(CPACR_EL1, 0,
-                                        CPACR_EL1_SMEN_EL0EN |
-                                        CPACR_EL1_SMEN_EL1EN);
+                       sysreg_clear_set(CPACR_EL1, 0, CPACR_ELx_SMEN);
                else
                        sysreg_clear_set(CPACR_EL1,
                                         CPACR_EL1_SMEN_EL0EN,
index ea67fcbf837617d570732d2e99c890bb317ba380..95cf1857425175dd1779442c5c76f17c2b62d766 100644 (file)
@@ -65,7 +65,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
        /* Trap SVE */
        if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_SVE), feature_ids)) {
                if (has_hvhe())
-                       cptr_clear |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
+                       cptr_clear |= CPACR_ELx_ZEN;
                else
                        cptr_set |= CPTR_EL2_TZ;
        }
index bef74de7065b3139b9b303edf98fc56a60a49eb6..6af179c6356d666b68e426429572ce6d559bbd82 100644 (file)
@@ -48,15 +48,14 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
        val |= has_hvhe() ? CPACR_EL1_TTA : CPTR_EL2_TTA;
        if (cpus_have_final_cap(ARM64_SME)) {
                if (has_hvhe())
-                       val &= ~(CPACR_EL1_SMEN_EL1EN | CPACR_EL1_SMEN_EL0EN);
+                       val &= ~CPACR_ELx_SMEN;
                else
                        val |= CPTR_EL2_TSM;
        }
 
        if (!guest_owns_fp_regs()) {
                if (has_hvhe())
-                       val &= ~(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |
-                                CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN);
+                       val &= ~(CPACR_ELx_FPEN | CPACR_ELx_ZEN);
                else
                        val |= CPTR_EL2_TFP | CPTR_EL2_TZ;
 
index 20073579e9f5b4ad68a8299958594438b4dd192d..8fbb6a2e0559d7e7d8d90ce11b618f35a723c46e 100644 (file)
@@ -93,8 +93,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
        val = read_sysreg(cpacr_el1);
        val |= CPACR_ELx_TTA;
-       val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN |
-                CPACR_EL1_SMEN_EL0EN | CPACR_EL1_SMEN_EL1EN);
+       val &= ~(CPACR_ELx_ZEN | CPACR_ELx_SMEN);
 
        /*
         * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
@@ -109,9 +108,9 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
        if (guest_owns_fp_regs()) {
                if (vcpu_has_sve(vcpu))
-                       val |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
+                       val |= CPACR_ELx_ZEN;
        } else {
-               val &= ~(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN);
+               val &= ~CPACR_ELx_FPEN;
                __activate_traps_fpsimd32(vcpu);
        }