Skip to content

Commit 7c582bf

Browse files
James MorseMarc Zyngier
authored andcommitted
KVM: arm64: Stop writing aarch32's CSSELR into ACTLR
aarch32 has pairs of registers to access the high and low parts of 64bit registers. KVM has a union of 64bit sys_regs[] and 32bit copro[]. The 32bit accessors read the high or low part of the 64bit sys_reg[] value through the union. Both sys_reg_descs[] and cp15_regs[] list access_csselr() as the accessor for CSSELR{,_EL1}. access_csselr() is only aware of the 64bit sys_regs[], and expects r->reg to be 'CSSELR_EL1' in the enum, index 2 of the 64bit array. cp15_regs[] uses the 32bit copro[] alias of sys_regs[]. Here CSSELR is c0_CSSELR which is the same location in sys_reg[]. r->reg is 'c0_CSSELR', index 4 in the 32bit array. access_csselr() uses the 32bit r->reg value to access the 64bit array, so reads and write the wrong value. sys_regs[4], is ACTLR_EL1, which is subsequently save/restored when we enter the guest. ACTLR_EL1 is supposed to be read-only for the guest. This register only affects execution at EL1, and the host's value is restored before we return to host EL1. Convert the 32bit register index back to the 64bit version. Suggested-by: Marc Zyngier <[email protected]> Signed-off-by: James Morse <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent 7ae2f3d commit 7c582bf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,10 +1319,16 @@ static bool access_clidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
13191319
static bool access_csselr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,
13201320
const struct sys_reg_desc *r)
13211321
{
1322+
int reg = r->reg;
1323+
1324+
/* See the 32bit mapping in kvm_host.h */
1325+
if (p->is_aarch32)
1326+
reg = r->reg / 2;
1327+
13221328
if (p->is_write)
1323-
vcpu_write_sys_reg(vcpu, p->regval, r->reg);
1329+
vcpu_write_sys_reg(vcpu, p->regval, reg);
13241330
else
1325-
p->regval = vcpu_read_sys_reg(vcpu, r->reg);
1331+
p->regval = vcpu_read_sys_reg(vcpu, reg);
13261332
return true;
13271333
}
13281334

0 commit comments

Comments
 (0)