arm64: Always use individual bits in CPACR floating point enables
authorMark Brown <broonie@kernel.org>
Mon, 7 Feb 2022 15:20:31 +0000 (15:20 +0000)
committerWill Deacon <will@kernel.org>
Fri, 25 Feb 2022 14:28:18 +0000 (14:28 +0000)
CPACR_EL1 has several bitfields for controlling traps for floating point
features to EL1, each of which has a separate bits for EL0 and EL1. Marc
Zyngier noted that we are not consistent in our use of defines to
manipulate these, sometimes using a define covering the whole field and
sometimes using defines for the individual bits. Make this consistent by
expanding the whole field defines where they are used (currently only in
the KVM code) and deleting them so that no further uses can be
introduced.

Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20220207152109.197566-3-broonie@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/kvm_arm.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kvm/hyp/include/hyp/switch.h
arch/arm64/kvm/hyp/vhe/switch.c

index eec790842fe2301c15d6ff4173baa4b2ae625ded..1767ded8388802bfc94a444e1bb28129dd993bc3 100644 (file)
        ECN(BKPT32), ECN(VECTOR32), ECN(BRK64)
 
 #define CPACR_EL1_TTA          (1 << 28)
-#define CPACR_EL1_DEFAULT      (CPACR_EL1_FPEN | CPACR_EL1_ZEN_EL1EN)
+#define CPACR_EL1_DEFAULT      (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |\
+                                CPACR_EL1_ZEN_EL1EN)
 
 #endif /* __ARM64_KVM_ARM_H__ */
index 1da4c43d597d0cdb29ce7273b8d10707747145dd..e66dd9ebc3374674eff32a969cc2472e4b14632b 100644 (file)
 
 #define CPACR_EL1_FPEN_EL1EN   (BIT(20)) /* enable EL1 access */
 #define CPACR_EL1_FPEN_EL0EN   (BIT(21)) /* enable EL0 access, if EL1EN set */
-#define CPACR_EL1_FPEN         (CPACR_EL1_FPEN_EL1EN | CPACR_EL1_FPEN_EL0EN)
 
 #define CPACR_EL1_ZEN_EL1EN    (BIT(16)) /* enable EL1 access */
 #define CPACR_EL1_ZEN_EL0EN    (BIT(17)) /* enable EL0 access, if EL1EN set */
-#define CPACR_EL1_ZEN          (CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN)
 
 /* TCR EL1 Bit Definitions */
 #define SYS_TCR_EL1_TCMA1      (BIT(58))
index 701cfb964905df6384168380505408b0fc4be0a1..6379a1e3e6e51a376fe7a9a3171443f2be303bf6 100644 (file)
@@ -174,9 +174,9 @@ static bool kvm_hyp_handle_fpsimd(struct kvm_vcpu *vcpu, u64 *exit_code)
 
        /* Valid trap.  Switch the context: */
        if (has_vhe()) {
-               reg = CPACR_EL1_FPEN;
+               reg = CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN;
                if (sve_guest)
-                       reg |= CPACR_EL1_ZEN;
+                       reg |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
 
                sysreg_clear_set(cpacr_el1, 0, reg);
        } else {
index 11d053fdd604b9dcbf0f91f2db53313f658513e5..619353b06e38f8455c543524fbe82b4f2a12c93b 100644 (file)
@@ -38,7 +38,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
        val = read_sysreg(cpacr_el1);
        val |= CPACR_EL1_TTA;
-       val &= ~CPACR_EL1_ZEN;
+       val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN);
 
        /*
         * With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
@@ -53,9 +53,9 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
 
        if (update_fp_enabled(vcpu)) {
                if (vcpu_has_sve(vcpu))
-                       val |= CPACR_EL1_ZEN;
+                       val |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
        } else {
-               val &= ~CPACR_EL1_FPEN;
+               val &= ~(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN);
                __activate_traps_fpsimd32(vcpu);
        }