[PW_SID:1096100] KVM: riscv: Speed up dirty logging write faults#1957
[PW_SID:1096100] KVM: riscv: Speed up dirty logging write faults#1957linux-riscv-bot wants to merge 6 commits into
Conversation
The common KVM invalidation paths call kvm_unmap_gfn_range() with
mmu_lock already held for write.
For the standard MMU notifier path, the call chain is:
kvm_mmu_notifier_invalidate_range_start()
kvm_handle_hva_range()
kvm_unmap_gfn_range()
kvm_mmu_notifier_invalidate_range_start() leaves range.lockless clear.
kvm_handle_hva_range() therefore takes KVM_MMU_LOCK(kvm) before invoking
the handler.
The guest_memfd path has the same locking contract:
__kvm_gmem_invalidate_begin()
kvm_mmu_unmap_gfn_range()
kvm_unmap_gfn_range()
__kvm_gmem_invalidate_begin() explicitly takes KVM_MMU_LOCK(kvm) before
calling kvm_mmu_unmap_gfn_range().
So remove the local trylock and make the common locking contract explicit
with lockdep_assert_held_write() like x86.
Signed-off-by: Jinyu Tang <tjytimi@163.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
RISC-V KVM currently uses a spinlock for mmu_lock. That serializes all G-stage MMU operations, including permission-only updates that do not allocate or free page-table pages. Use KVM's rwlock form of mmu_lock, as x86 and arm64 already do. Keep the existing map, unmap and teardown paths on the write side. This prepares RISC-V for read-side handling of G-stage permission updates. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Permission-only G-stage PTE updates can run in parallel once they are moved to the read side of mmu_lock. Plain set_pte() is not enough for that case because another CPU may update the same PTE first. x86 handles the same class of SPTE races with cmpxchg-based updates in its fast page fault and TDP MMU paths. Add a small RISC-V helper for atomic G-stage PTE updates. The helper reports contention to the caller and flushes the target range only when the PTE value actually changes. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
When a fault hits an existing G-stage leaf with the same PFN, KVM only needs to update the PTE permissions. This path will be used by read-side fault handling, so it must not overwrite a concurrent PTE update. Use the cmpxchg helper when relaxing permissions on an existing leaf, following the same concurrency model used by x86 for atomic SPTE permission updates. Retry if another CPU changed the PTE first, and use cpu_relax() while spinning. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
With dirty logging enabled, guest writes often fault on an existing 4K G-stage leaf that was write-protected only for dirty tracking. The slow path still performs the full fault handling flow and takes mmu_lock for write, even though the page-table shape does not change. x86 handles the analogous case in its fast page fault path by atomically making a writable SPTE writable again when the fault is only a write-protection fault. Add the same style of fast path for RISC-V. If a write fault hits an existing 4K leaf in a writable dirty-log memslot, mark the page dirty and atomically set the PTE writable and dirty under the read side of mmu_lock. The dirty bitmap is updated before the PTE becomes writable again. The PTE D bit is also set so systems that trap on a clear D bit do not fall back to the slow path for a writable but clean PTE. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 1: "[1/5] KVM: riscv: Rely on common MMU notifier locking" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 2: "[2/5] KVM: riscv: Use an rwlock for mmu_lock" |
|
Patch 3: "[3/5] KVM: riscv: Add a G-stage PTE cmpxchg helper" |
|
Patch 3: "[3/5] KVM: riscv: Add a G-stage PTE cmpxchg helper" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 4: "[4/5] KVM: riscv: Update G-stage PTE permissions atomically" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
|
Patch 5: "[5/5] KVM: riscv: Fast-path dirty logging write faults" |
a1231b7 to
c03cdce
Compare
PR for series 1096100 applied to workflow__riscv__fixes
Name: KVM: riscv: Speed up dirty logging write faults
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1096100
Version: 1