Skip to content

Commit 55b5bac

Browse files
author
Marc Zyngier
committed
KVM: arm64: nvhe: Synchronise with page table walker on vcpu run
When taking an exception between the EL1&0 translation regime and the EL2 translation regime, the page table walker is allowed to complete the walks started from EL0 or EL1 while running at EL2. It means that altering the system registers that define the EL1&0 translation regime is fraught with danger *unless* we wait for the completion of such walk with a DSB (R_LFHQG and subsequent statements in the ARM ARM). We already did the right thing for other external agents (SPE, TRBE), but not the PTW. Rework the existing SPE/TRBE synchronisation to include the PTW, and add the missing DSB on guest exit. Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 197b6b6 commit 55b5bac

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

arch/arm64/kvm/hyp/nvhe/debug-sr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static void __debug_save_spe(u64 *pmscr_el1)
3737

3838
/* Now drain all buffered data to memory */
3939
psb_csync();
40-
dsb(nsh);
4140
}
4241

4342
static void __debug_restore_spe(u64 pmscr_el1)
@@ -69,7 +68,6 @@ static void __debug_save_trace(u64 *trfcr_el1)
6968
isb();
7069
/* Drain the trace buffer to memory */
7170
tsb_csync();
72-
dsb(nsh);
7371
}
7472

7573
static void __debug_restore_trace(u64 trfcr_el1)

arch/arm64/kvm/hyp/nvhe/switch.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
272272
*/
273273
__debug_save_host_buffers_nvhe(vcpu);
274274

275+
/*
276+
* We're about to restore some new MMU state. Make sure
277+
* ongoing page-table walks that have started before we
278+
* trapped to EL2 have completed. This also synchronises the
279+
* above disabling of SPE and TRBE.
280+
*
281+
* See DDI0487I.a D8.1.5 "Out-of-context translation regimes",
282+
* rule R_LFHQG and subsequent information statements.
283+
*/
284+
dsb(nsh);
285+
275286
__kvm_adjust_pc(vcpu);
276287

277288
/*
@@ -306,6 +317,13 @@ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
306317
__timer_disable_traps(vcpu);
307318
__hyp_vgic_save_state(vcpu);
308319

320+
/*
321+
* Same thing as before the guest run: we're about to switch
322+
* the MMU context, so let's make sure we don't have any
323+
* ongoing EL1&0 translations.
324+
*/
325+
dsb(nsh);
326+
309327
__deactivate_traps(vcpu);
310328
__load_host_stage2();
311329

0 commit comments

Comments
 (0)