]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RISC-V: KVM: Fix skip of valid pages in kvm_riscv_gstage_wp_range
authorWu Fei <wu.fei9@sanechips.com.cn>
Thu, 4 Jun 2026 23:03:14 +0000 (07:03 +0800)
committerAnup Patel <anup@brainfault.org>
Sun, 7 Jun 2026 06:11:43 +0000 (11:41 +0530)
The current gstage range walker unconditionally advances by 'page_size'
when a leaf PTE is not found, e.g. when the range to wp is
[0xfffff01fc000, 0xfffff023c000) and page_size is 2MB, if found_leaf of
0xfffff01fc000 returns false, it skip the whole range, but it's possible
to have valid entries in [0xfffff0200000, 0xfffff023c000).

Signed-off-by: Wu Fei <wu.fei9@sanechips.com.cn>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260604230317.30501-2-atwufei@163.com
Signed-off-by: Anup Patel <anup@brainfault.org>
arch/riscv/kvm/gstage.c

index b83b85d1c016c624cf6886b6bf061a445957bdac..30ce40e8809fbb9846a9d86ea8d11537588b079a 100644 (file)
@@ -455,14 +455,14 @@ bool kvm_riscv_gstage_wp_range(struct kvm_gstage *gstage, gpa_t start, gpa_t end
                if (ret)
                        break;
 
-               if (!found_leaf)
-                       goto next;
-
-               addr = ALIGN_DOWN(addr, page_size);
-               flush |= kvm_riscv_gstage_op_pte(gstage, addr, ptep,
-                                                ptep_level, GSTAGE_OP_WP);
-next:
-               addr += page_size;
+               if (!found_leaf) {
+                       addr = ALIGN(addr + 1, page_size);
+               } else {
+                       addr = ALIGN_DOWN(addr, page_size);
+                       flush |= kvm_riscv_gstage_op_pte(gstage, addr, ptep,
+                                                        ptep_level, GSTAGE_OP_WP);
+                       addr += page_size;
+               }
        }
 
        return flush;