Skip to content

Commit 52f6c4f

Browse files
chazyMarc Zyngier
authored andcommitted
KVM: arm64: Change 32-bit handling of VM system registers
We currently handle 32-bit accesses to trapped VM system registers using the 32-bit index into the coproc array on the vcpu structure, which is a union of the coproc array and the sysreg array. Since all the 32-bit coproc indices are created to correspond to the architectural mapping between 64-bit system registers and 32-bit coprocessor registers, and because the AArch64 system registers are the double in size of the AArch32 coprocessor registers, we can always find the system register entry that we must update by dividing the 32-bit coproc index by 2. This is going to make our lives much easier when we have to start accessing system registers that use deferred save/restore and might have to be read directly from the physical CPU. Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Signed-off-by: Christoffer Dall <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 0c389d9 commit 52f6c4f

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,6 @@ struct kvm_vcpu_arch {
295295
#define vcpu_cp14(v,r) ((v)->arch.ctxt.copro[(r)])
296296
#define vcpu_cp15(v,r) ((v)->arch.ctxt.copro[(r)])
297297

298-
#ifdef CONFIG_CPU_BIG_ENDIAN
299-
#define vcpu_cp15_64_high(v,r) vcpu_cp15((v),(r))
300-
#define vcpu_cp15_64_low(v,r) vcpu_cp15((v),(r) + 1)
301-
#else
302-
#define vcpu_cp15_64_high(v,r) vcpu_cp15((v),(r) + 1)
303-
#define vcpu_cp15_64_low(v,r) vcpu_cp15((v),(r))
304-
#endif
305-
306298
struct kvm_vm_stat {
307299
ulong remote_tlb_flush;
308300
};

arch/arm64/kvm/sys_regs.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,26 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu,
121121
const struct sys_reg_desc *r)
122122
{
123123
bool was_enabled = vcpu_has_cache_enabled(vcpu);
124+
u64 val;
125+
int reg = r->reg;
124126

125127
BUG_ON(!p->is_write);
126128

127-
if (!p->is_aarch32) {
128-
vcpu_sys_reg(vcpu, r->reg) = p->regval;
129+
/* See the 32bit mapping in kvm_host.h */
130+
if (p->is_aarch32)
131+
reg = r->reg / 2;
132+
133+
if (!p->is_aarch32 || !p->is_32bit) {
134+
val = p->regval;
129135
} else {
130-
if (!p->is_32bit)
131-
vcpu_cp15_64_high(vcpu, r->reg) = upper_32_bits(p->regval);
132-
vcpu_cp15_64_low(vcpu, r->reg) = lower_32_bits(p->regval);
136+
val = vcpu_sys_reg(vcpu, reg);
137+
if (r->reg % 2)
138+
val = (p->regval << 32) | (u64)lower_32_bits(val);
139+
else
140+
val = ((u64)upper_32_bits(val) << 32) |
141+
lower_32_bits(p->regval);
133142
}
143+
vcpu_sys_reg(vcpu, reg) = val;
134144

135145
kvm_toggle_cache(vcpu, was_enabled);
136146
return true;

0 commit comments

Comments
 (0)