[PATCH v5 0/2] RISC-V: KVM: Huge page recovery during disable-dirty-log
From: Wang Yechao
Date: Mon Sep 14 2026 - 02:07:50 EST
When dirty logging is enabled, the gstage mappings are split into
4K pages to track dirty pages. If the migration fails or is canceled,
in order to keep the VM's performance consistent with that before
dirty logging was enabled, we need to recover the gstage huge page mappings
when dirty logging is disabled.
With this series, dirty_log_perf_test shows a decrease in the number of
vCPU faults:
$ perf stat -e kvm:kvm_page_fault \
/dirty_log_perf_test -s anonymous_hugetlb_1gb -v 1 -e -b 1G
Before: 1,574,460 kvm:kvm_page_fault
After : 788,048 kvm:kvm_page_fault
Changes in v5:
Fix the issues reported by sashiko
- Use _PAGE_PFN_SHIFT instead of pfn_pte to make huge pte.
- Validate host size via hugetlb_mapping_size() before recovery.
- Skip bad advancement after mmu_recover_huge_pages_range.
Changes in v4:
- Rebased on Linux v7.3-rc2.
- Squash Patch01 into Patch03.
- The 1G mapping recovery is performed only after all 2M leaf recover succeed.
https://lore.kernel.org/linux-riscv/20260913070352.3626956-1-wang.yechao255@xxxxxxxxxx
Changes in v3:
- Rebased on https://github.com/kvm-riscv/linux/tree/riscv_kvm_queue
- Add support to recover 1GB mappings for gstage.
- Refactor kvm_arch_commit_memory_region to be identical to arm64.
(sashiko AI Reviews)
- Scan the child page table for the first valid leaf PTE to recover.
- Add the memslot boundaries check when recover hugepages.
- Move the cond_resched_lock to the start loop iteration.
- The kvm_page_fault tracepoint be placed before the conditional block.
- Remove the fault_supports_gstage_huge_mapping check.
https://lore.kernel.org/linux-riscv/20260605160019772GJy5SDmWQQF7sSqvJ0JtC@xxxxxxxxxx/
Changes in v2:
- Rebased on Linux v7.1-rc1.
- Skip recovering huge pte if the first child pte is not leaf.
- Link to v2:
https://lore.kernel.org/linux-riscv/20260429173002565bdp1o7P0bvOs6yTz64yNx@xxxxxxxxxx/
- Link to v1:
https://lore.kernel.org/linux-riscv/20260407171052241tmZDFGusMP_wlEsBVVtJo@xxxxxxxxxx/
Wang Yechao (2):
RISC-V: KVM: add tracepoint for guest page faults
RISC-V: KVM: Recover gstage huge page mappings during
disable-dirty-log
arch/riscv/include/asm/kvm_gstage.h | 4 +
arch/riscv/kvm/gstage.c | 67 +++++++++++++++
arch/riscv/kvm/mmu.c | 123 +++++++++++++++++++++++++++-
arch/riscv/kvm/trace.h | 22 +++++
arch/riscv/kvm/vcpu_exit.c | 2 +
5 files changed, 217 insertions(+), 1 deletion(-)
--
2.27.0