Skip to content

Commit 663abf0

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Make PIR{,E0}_EL1 save/restore conditional on FEAT_TCRX
As per the architecture, if FEAT_S1PIE is implemented, then FEAT_TCRX must be implemented as well. Take advantage of this to avoid checking for S1PIE when TCRX isn't implemented. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 1b04fd4 commit 663abf0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
7373
ctxt_sys_reg(ctxt, TTBR0_EL1) = read_sysreg_el1(SYS_TTBR0);
7474
ctxt_sys_reg(ctxt, TTBR1_EL1) = read_sysreg_el1(SYS_TTBR1);
7575
ctxt_sys_reg(ctxt, TCR_EL1) = read_sysreg_el1(SYS_TCR);
76-
if (ctxt_has_tcrx(ctxt))
76+
if (ctxt_has_tcrx(ctxt)) {
7777
ctxt_sys_reg(ctxt, TCR2_EL1) = read_sysreg_el1(SYS_TCR2);
78+
79+
if (ctxt_has_s1pie(ctxt)) {
80+
ctxt_sys_reg(ctxt, PIR_EL1) = read_sysreg_el1(SYS_PIR);
81+
ctxt_sys_reg(ctxt, PIRE0_EL1) = read_sysreg_el1(SYS_PIRE0);
82+
}
83+
}
7884
ctxt_sys_reg(ctxt, ESR_EL1) = read_sysreg_el1(SYS_ESR);
7985
ctxt_sys_reg(ctxt, AFSR0_EL1) = read_sysreg_el1(SYS_AFSR0);
8086
ctxt_sys_reg(ctxt, AFSR1_EL1) = read_sysreg_el1(SYS_AFSR1);
@@ -84,10 +90,6 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)
8490
ctxt_sys_reg(ctxt, CONTEXTIDR_EL1) = read_sysreg_el1(SYS_CONTEXTIDR);
8591
ctxt_sys_reg(ctxt, AMAIR_EL1) = read_sysreg_el1(SYS_AMAIR);
8692
ctxt_sys_reg(ctxt, CNTKCTL_EL1) = read_sysreg_el1(SYS_CNTKCTL);
87-
if (ctxt_has_s1pie(ctxt)) {
88-
ctxt_sys_reg(ctxt, PIR_EL1) = read_sysreg_el1(SYS_PIR);
89-
ctxt_sys_reg(ctxt, PIRE0_EL1) = read_sysreg_el1(SYS_PIRE0);
90-
}
9193
ctxt_sys_reg(ctxt, PAR_EL1) = read_sysreg_par();
9294
ctxt_sys_reg(ctxt, TPIDR_EL1) = read_sysreg(tpidr_el1);
9395

@@ -149,8 +151,14 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)
149151
write_sysreg_el1(ctxt_sys_reg(ctxt, CPACR_EL1), SYS_CPACR);
150152
write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR0_EL1), SYS_TTBR0);
151153
write_sysreg_el1(ctxt_sys_reg(ctxt, TTBR1_EL1), SYS_TTBR1);
152-
if (ctxt_has_tcrx(ctxt))
154+
if (ctxt_has_tcrx(ctxt)) {
153155
write_sysreg_el1(ctxt_sys_reg(ctxt, TCR2_EL1), SYS_TCR2);
156+
157+
if (ctxt_has_s1pie(ctxt)) {
158+
write_sysreg_el1(ctxt_sys_reg(ctxt, PIR_EL1), SYS_PIR);
159+
write_sysreg_el1(ctxt_sys_reg(ctxt, PIRE0_EL1), SYS_PIRE0);
160+
}
161+
}
154162
write_sysreg_el1(ctxt_sys_reg(ctxt, ESR_EL1), SYS_ESR);
155163
write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR0_EL1), SYS_AFSR0);
156164
write_sysreg_el1(ctxt_sys_reg(ctxt, AFSR1_EL1), SYS_AFSR1);
@@ -160,10 +168,6 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)
160168
write_sysreg_el1(ctxt_sys_reg(ctxt, CONTEXTIDR_EL1), SYS_CONTEXTIDR);
161169
write_sysreg_el1(ctxt_sys_reg(ctxt, AMAIR_EL1), SYS_AMAIR);
162170
write_sysreg_el1(ctxt_sys_reg(ctxt, CNTKCTL_EL1), SYS_CNTKCTL);
163-
if (ctxt_has_s1pie(ctxt)) {
164-
write_sysreg_el1(ctxt_sys_reg(ctxt, PIR_EL1), SYS_PIR);
165-
write_sysreg_el1(ctxt_sys_reg(ctxt, PIRE0_EL1), SYS_PIRE0);
166-
}
167171
write_sysreg(ctxt_sys_reg(ctxt, PAR_EL1), par_el1);
168172
write_sysreg(ctxt_sys_reg(ctxt, TPIDR_EL1), tpidr_el1);
169173

0 commit comments

Comments
 (0)