[PATCH 0/5] KVM: riscv: Speed up dirty logging write faults

Anup Patel anup at brainfault.org
Wed Jun 3 06:12:30 PDT 2026


On Sun, May 17, 2026 at 9:05 PM Jinyu Tang <tjytimi at 163.com> wrote:
>
> This series speeds up the common dirty logging write fault path for
> RISC-V KVM.
>
> When dirty logging is enabled, guest writes to write-protected G-stage
> 4K leaves currently go through the full fault path and take mmu_lock for
> write.  That is expensive once the leaf already exists and
> only needs its permission and dirty state updated.
>
> The series first makes the existing MMU notifier locking contract
> explicit, switches RISC-V KVM to KVM's rwlock form of mmu_lock, adds an
> atomic G-stage PTE update helper, uses it for existing permission
> updates, and finally handles dirty logging write faults under the read
> side of mmu_lock when a 4K G-stage leaf is already present.
>
> The locking and concurrency model follows existing KVM patterns from x86
> and arm64: use an rwlock mmu_lock, keep structural page-table changes on
> the write side, and use atomic PTE updates for permission-only changes
> that may race with another vCPU.
>
> The fast path marks the memslot page dirty before making the PTE writable
> again.  It also sets the PTE dirty bit, so systems that trap when D is
> clear do not fall back to the slow path for a writable-but-clean PTE.
>
> Performance was measured with KVM selftests inside a QEMU RISC-V host.
>
>   dirty_log_perf_test -m 19 -v 4 -b 1G -i 3
>     base dirty memory avg, iterations 2-3: 53.262493s
>     patch 1-4 dirty memory avg, iterations 2-3: 52.735675s
>     patch 1-5 dirty memory avg, iterations 2-3: 26.422964s
>     patch 1-5 improvement over base: 50.4%
>
>   dirty_log_perf_test -m 19 -v 4 -b 64M -i 3
>     base dirty memory avg, iterations 2-3: 3.203170s
>     patch 1-5 dirty memory avg, iterations 2-3: 1.762452s
>     improvement: 45.0%
>
> Patch 1-4 are prerequisites for the read-side fast path. The
> main speedup comes from patch 5 avoiding the full fault path
> for dirty logging write faults.
>
> Jinyu Tang (5):
>   KVM: riscv: Rely on common MMU notifier locking
>   KVM: riscv: Use an rwlock for mmu_lock
>   KVM: riscv: Add a G-stage PTE cmpxchg helper
>   KVM: riscv: Update G-stage PTE permissions atomically
>   KVM: riscv: Fast-path dirty logging write faults
>
>  arch/riscv/include/asm/kvm_gstage.h |   4 ++
>  arch/riscv/include/asm/kvm_host.h   |   2 +
>  arch/riscv/kvm/gstage.c             |  35 +++++++---
>  arch/riscv/kvm/mmu.c                | 105 +++++++++++++++++++++++-----
>  4 files changed, 122 insertions(+), 24 deletions(-)
>
> --
> 2.43.0
>

LGTM. I tried this at my end as well.

Reviewed-by: Anup Patel <anup at brainfault.org>

Queued this series for Linux-7.2

Thanks,
Anup



More information about the kvm-riscv mailing list