]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RISC-V: KVM: Enhance the logging check for mmu mapping
authorInochi Amaoto <inochiama@gmail.com>
Thu, 28 May 2026 11:38:39 +0000 (19:38 +0800)
committerAnup Patel <anup@brainfault.org>
Fri, 5 Jun 2026 14:48:32 +0000 (20:18 +0530)
When enabling dirty ring, the dirty bitmap is disable, and the logging
check is always false as the RISC-V architecture does not select
"NEED_KVM_DIRTY_RING_WITH_BITMAP". Although the dirty log is recorded
since the write path already trying to add the dirty log, the logic for
logging check is broken and some side effect will occurs.

Enhance the logging check for mmu mapping so it can check both the dirty
ring and the dirty bitmap.

Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260528113840.2629186-1-inochiama@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/mmu.c

index c847b101c73ef72f72d2589a758a12bb96788652..38d3eaa1c5e50d9286a1285f1b5f63e9804f71d3 100644 (file)
@@ -157,9 +157,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
                                enum kvm_mr_change change)
 {
        /*
-        * At this point memslot has been committed and there is an
-        * allocated dirty_bitmap[], dirty pages will be tracked while
-        * the memory slot is write protected.
+        * At this point memslot has been committed and dirty pages will be
+        * tracked while the memory slot is write protected.
         */
        if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
                if (kvm_dirty_log_manual_protect_and_init_set(kvm))
@@ -521,8 +520,8 @@ int kvm_riscv_mmu_map(struct kvm_vcpu *vcpu, struct kvm_memory_slot *memslot,
        struct vm_area_struct *vma;
        struct kvm *kvm = vcpu->kvm;
        struct kvm_mmu_memory_cache *pcache = &vcpu->arch.mmu_page_cache;
-       bool logging = (memslot->dirty_bitmap &&
-                       !(memslot->flags & KVM_MEM_READONLY)) ? true : false;
+       bool logging = kvm_slot_dirty_track_enabled(memslot) &&
+                      !(memslot->flags & KVM_MEM_READONLY);
        unsigned long vma_pagesize, mmu_seq;
        struct kvm_gstage gstage;
        struct page *page;