Skip to content

Commit 0370964

Browse files
author
Marc Zyngier
committed
KVM: arm64: Synchronize sysreg state on injecting an AArch32 exception
On a VHE system, the EL1 state is left in the CPU most of the time, and only syncronized back to memory when vcpu_put() is called (most of the time on preemption). Which means that when injecting an exception, we'd better have a way to either: (1) write directly to the EL1 sysregs (2) synchronize the state back to memory, and do the changes there For an AArch64, we already do (1), so we are safe. Unfortunately, doing the same thing for AArch32 would be pretty invasive. Instead, we can easily implement (2) by calling the put/load architectural backends, and keep preemption disabled. We can then reload the state back into EL1. Cc: [email protected] Reported-by: James Morse <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 3204be4 commit 0370964

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

arch/arm64/kvm/aarch32.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ static const u8 return_offsets[8][2] = {
3333
[7] = { 4, 4 }, /* FIQ, unused */
3434
};
3535

36+
static bool pre_fault_synchronize(struct kvm_vcpu *vcpu)
37+
{
38+
preempt_disable();
39+
if (vcpu->arch.sysregs_loaded_on_cpu) {
40+
kvm_arch_vcpu_put(vcpu);
41+
return true;
42+
}
43+
44+
preempt_enable();
45+
return false;
46+
}
47+
48+
static void post_fault_synchronize(struct kvm_vcpu *vcpu, bool loaded)
49+
{
50+
if (loaded) {
51+
kvm_arch_vcpu_load(vcpu, smp_processor_id());
52+
preempt_enable();
53+
}
54+
}
55+
3656
/*
3757
* When an exception is taken, most CPSR fields are left unchanged in the
3858
* handler. However, some are explicitly overridden (e.g. M[4:0]).
@@ -155,7 +175,10 @@ static void prepare_fault32(struct kvm_vcpu *vcpu, u32 mode, u32 vect_offset)
155175

156176
void kvm_inject_undef32(struct kvm_vcpu *vcpu)
157177
{
178+
bool loaded = pre_fault_synchronize(vcpu);
179+
158180
prepare_fault32(vcpu, PSR_AA32_MODE_UND, 4);
181+
post_fault_synchronize(vcpu, loaded);
159182
}
160183

161184
/*
@@ -168,6 +191,9 @@ static void inject_abt32(struct kvm_vcpu *vcpu, bool is_pabt,
168191
u32 vect_offset;
169192
u32 *far, *fsr;
170193
bool is_lpae;
194+
bool loaded;
195+
196+
loaded = pre_fault_synchronize(vcpu);
171197

172198
if (is_pabt) {
173199
vect_offset = 12;
@@ -191,6 +217,8 @@ static void inject_abt32(struct kvm_vcpu *vcpu, bool is_pabt,
191217
/* no need to shuffle FS[4] into DFSR[10] as its 0 */
192218
*fsr = DFSR_FSC_EXTABT_nLPAE;
193219
}
220+
221+
post_fault_synchronize(vcpu, loaded);
194222
}
195223

196224
void kvm_inject_dabt32(struct kvm_vcpu *vcpu, unsigned long addr)

0 commit comments

Comments
 (0)