Skip to content

Commit e3f6836

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Simplify sysreg access on exception delivery
Distinguishing between NV and VHE is slightly pointless, and only serves as an extra complication, or a way to introduce bugs, such as the way SPSR_EL1 gets written without checking for the state being resident. Get rid if this silly distinction, and fix the bug in one go. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent b720269 commit e3f6836

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

arch/arm64/kvm/hyp/exception.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,28 @@
2222

2323
static inline u64 __vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg)
2424
{
25-
u64 val;
26-
27-
if (unlikely(vcpu_has_nv(vcpu)))
25+
if (has_vhe())
2826
return vcpu_read_sys_reg(vcpu, reg);
29-
else if (vcpu_get_flag(vcpu, SYSREGS_ON_CPU) &&
30-
__vcpu_read_sys_reg_from_cpu(reg, &val))
31-
return val;
3227

3328
return __vcpu_sys_reg(vcpu, reg);
3429
}
3530

3631
static inline void __vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg)
3732
{
38-
if (unlikely(vcpu_has_nv(vcpu)))
33+
if (has_vhe())
3934
vcpu_write_sys_reg(vcpu, val, reg);
40-
else if (!vcpu_get_flag(vcpu, SYSREGS_ON_CPU) ||
41-
!__vcpu_write_sys_reg_to_cpu(val, reg))
35+
else
4236
__vcpu_assign_sys_reg(vcpu, reg, val);
4337
}
4438

4539
static void __vcpu_write_spsr(struct kvm_vcpu *vcpu, unsigned long target_mode,
4640
u64 val)
4741
{
48-
if (unlikely(vcpu_has_nv(vcpu))) {
42+
if (has_vhe()) {
4943
if (target_mode == PSR_MODE_EL1h)
5044
vcpu_write_sys_reg(vcpu, val, SPSR_EL1);
5145
else
5246
vcpu_write_sys_reg(vcpu, val, SPSR_EL2);
53-
} else if (has_vhe()) {
54-
write_sysreg_el1(val, SYS_SPSR);
5547
} else {
5648
__vcpu_assign_sys_reg(vcpu, SPSR_EL1, val);
5749
}

0 commit comments

Comments
 (0)