Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a69283a

Browse files
Fuad TabbaMarc Zyngier
authored andcommitted
KVM: arm64: Refactor CPACR trap bit setting/clearing to use ELx format
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>
1 parent 1696fc2 commit a69283a

File tree

6 files changed

+14
-19
lines changed

6 files changed

+14
-19
lines changed

arch/arm64/include/asm/el2_setup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
/* Coprocessor traps */
147147
.macro __init_el2_cptr
148148
__check_hvhe .LnVHE_\@, x1
149-
mov x0, #(CPACR_EL1_FPEN_EL1EN | CPACR_EL1_FPEN_EL0EN)
149+
mov x0, #CPACR_ELx_FPEN
150150
msr cpacr_el1, x0
151151
b .Lskip_set_cptr_\@
152152
.LnVHE_\@:
@@ -277,7 +277,7 @@
277277

278278
// (h)VHE case
279279
mrs x0, cpacr_el1 // Disable SVE traps
280-
orr x0, x0, #(CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN)
280+
orr x0, x0, #CPACR_ELx_ZEN
281281
msr cpacr_el1, x0
282282
b .Lskip_set_cptr_\@
283283

@@ -298,7 +298,7 @@
298298

299299
// (h)VHE case
300300
mrs x0, cpacr_el1 // Disable SME traps
301-
orr x0, x0, #(CPACR_EL1_SMEN_EL0EN | CPACR_EL1_SMEN_EL1EN)
301+
orr x0, x0, #CPACR_ELx_SMEN
302302
msr cpacr_el1, x0
303303
b .Lskip_set_cptr_sme_\@
304304

arch/arm64/include/asm/kvm_emulate.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,16 @@ static __always_inline u64 kvm_get_reset_cptr_el2(struct kvm_vcpu *vcpu)
632632
u64 val;
633633

634634
if (has_vhe()) {
635-
val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |
636-
CPACR_EL1_ZEN_EL1EN);
635+
val = (CPACR_ELx_FPEN | CPACR_EL1_ZEN_EL1EN);
637636
if (cpus_have_final_cap(ARM64_SME))
638637
val |= CPACR_EL1_SMEN_EL1EN;
639638
} else if (has_hvhe()) {
640-
val = (CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN);
639+
val = CPACR_ELx_FPEN;
641640

642641
if (!vcpu_has_sve(vcpu) || !guest_owns_fp_regs())
643-
val |= CPACR_EL1_ZEN_EL1EN | CPACR_EL1_ZEN_EL0EN;
642+
val |= CPACR_ELx_ZEN;
644643
if (cpus_have_final_cap(ARM64_SME))
645-
val |= CPACR_EL1_SMEN_EL1EN | CPACR_EL1_SMEN_EL0EN;
644+
val |= CPACR_ELx_SMEN;
646645
} else {
647646
val = CPTR_NVHE_EL2_RES1;
648647

arch/arm64/kvm/fpsimd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
161161
if (has_vhe() && system_supports_sme()) {
162162
/* Also restore EL0 state seen on entry */
163163
if (vcpu_get_flag(vcpu, HOST_SME_ENABLED))
164-
sysreg_clear_set(CPACR_EL1, 0,
165-
CPACR_EL1_SMEN_EL0EN |
166-
CPACR_EL1_SMEN_EL1EN);
164+
sysreg_clear_set(CPACR_EL1, 0, CPACR_ELx_SMEN);
167165
else
168166
sysreg_clear_set(CPACR_EL1,
169167
CPACR_EL1_SMEN_EL0EN,

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void pvm_init_traps_aa64pfr0(struct kvm_vcpu *vcpu)
6565
/* Trap SVE */
6666
if (!FIELD_GET(ARM64_FEATURE_MASK(ID_AA64PFR0_EL1_SVE), feature_ids)) {
6767
if (has_hvhe())
68-
cptr_clear |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
68+
cptr_clear |= CPACR_ELx_ZEN;
6969
else
7070
cptr_set |= CPTR_EL2_TZ;
7171
}

arch/arm64/kvm/hyp/nvhe/switch.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
4848
val |= has_hvhe() ? CPACR_EL1_TTA : CPTR_EL2_TTA;
4949
if (cpus_have_final_cap(ARM64_SME)) {
5050
if (has_hvhe())
51-
val &= ~(CPACR_EL1_SMEN_EL1EN | CPACR_EL1_SMEN_EL0EN);
51+
val &= ~CPACR_ELx_SMEN;
5252
else
5353
val |= CPTR_EL2_TSM;
5454
}
5555

5656
if (!guest_owns_fp_regs()) {
5757
if (has_hvhe())
58-
val &= ~(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN |
59-
CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN);
58+
val &= ~(CPACR_ELx_FPEN | CPACR_ELx_ZEN);
6059
else
6160
val |= CPTR_EL2_TFP | CPTR_EL2_TZ;
6261

arch/arm64/kvm/hyp/vhe/switch.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
9393

9494
val = read_sysreg(cpacr_el1);
9595
val |= CPACR_ELx_TTA;
96-
val &= ~(CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN |
97-
CPACR_EL1_SMEN_EL0EN | CPACR_EL1_SMEN_EL1EN);
96+
val &= ~(CPACR_ELx_ZEN | CPACR_ELx_SMEN);
9897

9998
/*
10099
* With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
@@ -109,9 +108,9 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
109108

110109
if (guest_owns_fp_regs()) {
111110
if (vcpu_has_sve(vcpu))
112-
val |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
111+
val |= CPACR_ELx_ZEN;
113112
} else {
114-
val &= ~(CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN);
113+
val &= ~CPACR_ELx_FPEN;
115114
__activate_traps_fpsimd32(vcpu);
116115
}
117116

0 commit comments

Comments
 (0)