Skip to content

Commit 3f7915c

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: Handle AArch32 SPSR_{irq,abt,und,fiq} as RAZ/WI
When trapping accesses from a NV guest that tries to access SPSR_{irq,abt,und,fiq}, make sure we handle them as RAZ/WI, as if AArch32 wasn't implemented. This involves a bit of repainting to make the visibility handler more generic. Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent c7d11a6 commit 3f7915c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

arch/arm64/include/asm/sysreg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,10 @@
505505
#define SYS_SPSR_EL2 sys_reg(3, 4, 4, 0, 0)
506506
#define SYS_ELR_EL2 sys_reg(3, 4, 4, 0, 1)
507507
#define SYS_SP_EL1 sys_reg(3, 4, 4, 1, 0)
508+
#define SYS_SPSR_irq sys_reg(3, 4, 4, 3, 0)
509+
#define SYS_SPSR_abt sys_reg(3, 4, 4, 3, 1)
510+
#define SYS_SPSR_und sys_reg(3, 4, 4, 3, 2)
511+
#define SYS_SPSR_fiq sys_reg(3, 4, 4, 3, 3)
508512
#define SYS_IFSR32_EL2 sys_reg(3, 4, 5, 0, 1)
509513
#define SYS_AFSR0_EL2 sys_reg(3, 4, 5, 1, 0)
510514
#define SYS_AFSR1_EL2 sys_reg(3, 4, 5, 1, 1)

arch/arm64/kvm/sys_regs.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,8 +1791,8 @@ static unsigned int el2_visibility(const struct kvm_vcpu *vcpu,
17911791
* HCR_EL2.E2H==1, and only in the sysreg table for convenience of
17921792
* handling traps. Given that, they are always hidden from userspace.
17931793
*/
1794-
static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu,
1795-
const struct sys_reg_desc *rd)
1794+
static unsigned int hidden_user_visibility(const struct kvm_vcpu *vcpu,
1795+
const struct sys_reg_desc *rd)
17961796
{
17971797
return REG_HIDDEN_USER;
17981798
}
@@ -1803,7 +1803,7 @@ static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu,
18031803
.reset = rst, \
18041804
.reg = name##_EL1, \
18051805
.val = v, \
1806-
.visibility = elx2_visibility, \
1806+
.visibility = hidden_user_visibility, \
18071807
}
18081808

18091809
/*
@@ -2387,6 +2387,16 @@ static const struct sys_reg_desc sys_reg_descs[] = {
23872387
EL2_REG(ELR_EL2, access_rw, reset_val, 0),
23882388
{ SYS_DESC(SYS_SP_EL1), access_sp_el1},
23892389

2390+
/* AArch32 SPSR_* are RES0 if trapped from a NV guest */
2391+
{ SYS_DESC(SYS_SPSR_irq), .access = trap_raz_wi,
2392+
.visibility = hidden_user_visibility },
2393+
{ SYS_DESC(SYS_SPSR_abt), .access = trap_raz_wi,
2394+
.visibility = hidden_user_visibility },
2395+
{ SYS_DESC(SYS_SPSR_und), .access = trap_raz_wi,
2396+
.visibility = hidden_user_visibility },
2397+
{ SYS_DESC(SYS_SPSR_fiq), .access = trap_raz_wi,
2398+
.visibility = hidden_user_visibility },
2399+
23902400
{ SYS_DESC(SYS_IFSR32_EL2), trap_undef, reset_unknown, IFSR32_EL2 },
23912401
EL2_REG(AFSR0_EL2, access_rw, reset_val, 0),
23922402
EL2_REG(AFSR1_EL2, access_rw, reset_val, 0),

0 commit comments

Comments
 (0)