Skip to content

Commit 4151bb6

Browse files
author
Marc Zyngier
committed
KVM: arm64: Fix SMPRI_EL1/TPIDR2_EL0 trapping on VHE
The trapping of SMPRI_EL1 and TPIDR2_EL0 currently only really work on nVHE, as only this mode uses the fine-grained trapping that controls these two registers. Move the trapping enable/disable code into __{de,}activate_traps_common(), allowing it to be called when it actually matters on VHE, and remove the flipping of EL2 control for TPIDR2_EL0, which only affects the host access of this register. Fixes: 861262a ("KVM: arm64: Handle SME host state when running guests") Reported-by: Mark Brown <[email protected]> Reviewed-by: Mark Brown <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 7a2726e commit 4151bb6

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ static inline void __activate_traps_common(struct kvm_vcpu *vcpu)
8787

8888
vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2);
8989
write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
90+
91+
if (cpus_have_final_cap(ARM64_SME)) {
92+
sysreg_clear_set_s(SYS_HFGRTR_EL2,
93+
HFGxTR_EL2_nSMPRI_EL1_MASK |
94+
HFGxTR_EL2_nTPIDR2_EL0_MASK,
95+
0);
96+
sysreg_clear_set_s(SYS_HFGWTR_EL2,
97+
HFGxTR_EL2_nSMPRI_EL1_MASK |
98+
HFGxTR_EL2_nTPIDR2_EL0_MASK,
99+
0);
100+
}
90101
}
91102

92103
static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
@@ -96,6 +107,15 @@ static inline void __deactivate_traps_common(struct kvm_vcpu *vcpu)
96107
write_sysreg(0, hstr_el2);
97108
if (kvm_arm_support_pmu_v3())
98109
write_sysreg(0, pmuserenr_el0);
110+
111+
if (cpus_have_final_cap(ARM64_SME)) {
112+
sysreg_clear_set_s(SYS_HFGRTR_EL2, 0,
113+
HFGxTR_EL2_nSMPRI_EL1_MASK |
114+
HFGxTR_EL2_nTPIDR2_EL0_MASK);
115+
sysreg_clear_set_s(SYS_HFGWTR_EL2, 0,
116+
HFGxTR_EL2_nSMPRI_EL1_MASK |
117+
HFGxTR_EL2_nTPIDR2_EL0_MASK);
118+
}
99119
}
100120

101121
static inline void ___activate_traps(struct kvm_vcpu *vcpu)

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
5555
write_sysreg(val, cptr_el2);
5656
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el2);
5757

58-
if (cpus_have_final_cap(ARM64_SME)) {
59-
val = read_sysreg_s(SYS_HFGRTR_EL2);
60-
val &= ~(HFGxTR_EL2_nTPIDR2_EL0_MASK |
61-
HFGxTR_EL2_nSMPRI_EL1_MASK);
62-
write_sysreg_s(val, SYS_HFGRTR_EL2);
63-
64-
val = read_sysreg_s(SYS_HFGWTR_EL2);
65-
val &= ~(HFGxTR_EL2_nTPIDR2_EL0_MASK |
66-
HFGxTR_EL2_nSMPRI_EL1_MASK);
67-
write_sysreg_s(val, SYS_HFGWTR_EL2);
68-
}
69-
7058
if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {
7159
struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt;
7260

@@ -110,20 +98,6 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
11098

11199
write_sysreg(this_cpu_ptr(&kvm_init_params)->hcr_el2, hcr_el2);
112100

113-
if (cpus_have_final_cap(ARM64_SME)) {
114-
u64 val;
115-
116-
val = read_sysreg_s(SYS_HFGRTR_EL2);
117-
val |= HFGxTR_EL2_nTPIDR2_EL0_MASK |
118-
HFGxTR_EL2_nSMPRI_EL1_MASK;
119-
write_sysreg_s(val, SYS_HFGRTR_EL2);
120-
121-
val = read_sysreg_s(SYS_HFGWTR_EL2);
122-
val |= HFGxTR_EL2_nTPIDR2_EL0_MASK |
123-
HFGxTR_EL2_nSMPRI_EL1_MASK;
124-
write_sysreg_s(val, SYS_HFGWTR_EL2);
125-
}
126-
127101
cptr = CPTR_EL2_DEFAULT;
128102
if (vcpu_has_sve(vcpu) && (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED))
129103
cptr |= CPTR_EL2_TZ;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
6363
__activate_traps_fpsimd32(vcpu);
6464
}
6565

66-
if (cpus_have_final_cap(ARM64_SME))
67-
write_sysreg(read_sysreg(sctlr_el2) & ~SCTLR_ELx_ENTP2,
68-
sctlr_el2);
69-
7066
write_sysreg(val, cpacr_el1);
7167

7268
write_sysreg(__this_cpu_read(kvm_hyp_vector), vbar_el1);
@@ -88,10 +84,6 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
8884
*/
8985
asm(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_SPECULATIVE_AT));
9086

91-
if (cpus_have_final_cap(ARM64_SME))
92-
write_sysreg(read_sysreg(sctlr_el2) | SCTLR_ELx_ENTP2,
93-
sctlr_el2);
94-
9587
write_sysreg(CPACR_EL1_DEFAULT, cpacr_el1);
9688

9789
if (!arm64_kernel_unmapped_at_el0())

0 commit comments

Comments
 (0)