KVM: riscv: Allow rescheduling during G-stage unmap and teardown
Subsystems (3)
PATCH v7 1/1 KVM: riscv: Allow rescheduling during G-stage unmap and teardown
Removing a populated memslot or destroying a VM can walk a large G-stage range while holding mmu_lock. Limit the time spent holding the lock continuously and let other tasks run while tearing down a VM.
Process sleepable memslot and MMU notifier unmaps in PMD-sized chunks. Advance past holes and fully covered block mappings, even when they extend past a chunk. Finish any pending remote TLB invalidations before yielding the lock, and read the current root under the lock before walking the next chunk. Use a full VMID flush before dropping the lock so repeated requests can coalesce in each vCPU's request bit and avoid queueing per-page invalidations for PMD-sized batches. Flush the remaining range before returning.
Detach the root and request the full VM TLB flush under mmu_lock before starting teardown. The VM is being rolled back during setup, its owner mm is exiting, or the last KVM reference has been dropped. No vCPU can still run with the detached root in these cases.
Recursively clear the old tree outside mmu_lock and check for rescheduling as page tables are removed. Keep RCU-delayed freeing for the root and its descendants so lockless aging walkers can finish.
Codex assisted with implementation and earlier QEMU validation. Sashiko identified redundant final range flushes and the cost of queueing range fences at reschedule points.
---
Changes in v7
- Use a full VMID flush before yielding to avoid queueing range fences for PMD-sized batches. Keep the final range flush.
Changes in v6
- Add the co-developer credit and sign-off trailers.
Changes in v5
- Rebase on the RISC-V KVM queue at ffdc855900a8.
- Keep the existing G-stage initializer and lockless aging path.
- Use an outer PMD-sized walk for memslot and notifier unmaps. Batch invalidations until a possible lock drop or the end of the walk.
- Detach the G-stage root before the recursive VM teardown and allow rescheduling while reclaiming the old page tables.
v4: https://lore.kernel.org/r/[email protected]
arch/riscv/include/asm/kvm_gstage.h | 6 +- arch/riscv/kvm/gstage.c | 77 ++++++++++---------- arch/riscv/kvm/mmu.c | 108 +++++++++++++++++----------- 3 files changed, 108 insertions(+), 83 deletions(-)
arch/riscv/include/asm/kvm_gstage.h +3 -3
@@ -80,10 +80,10 @@ enum kvm_riscv_gstage_op {bool kvm_riscv_gstage_op_pte (struct kvm_gstage *gstage,gpa_t addr,pte_t *ptep,u32 ptep_level,enum kvm_riscv_gstage_op op); -bool kvm_riscv_gstage_unmap_range (struct kvm_gstage *gstage, -gpa_t start,gpa_t size,bool may_block); +s64 kvm_riscv_gstage_unmap_range (struct kvm_gstage *gstage, +gpa_t addr,gpa_t end,gpa_t chunk_end,bool *flush); -bool kvm_riscv_gstage_unmap_all (struct kvm_gstage *gstage); +void kvm_riscv_gstage_unmap_all (struct kvm_gstage *gstage);bool kvm_riscv_gstage_wp_range (struct kvm_gstage *gstage,gpa_t start,gpa_t end); bool kvm_riscv_gstage_age_range(struct kvm_gstage *gstage, gpa_t start,
arch/riscv/kvm/gstage.c +40 -37
126 lines not on this page · raw message
arch/riscv/kvm/mmu.c +65 -43
155 lines not on this page · raw message
base-commit: ffdc855900a894034a63a46d699e0326dea3c991
Signature · 7 lines
2.56.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv