RISC-V: KVM: Fix hugepage mapping handling during dirty logging

From: wang.yechao255

Date: Thu Feb 26 2026 - 04:25:10 EST


From: Wang Yechao <wang.yechao255@xxxxxxxxxx>

When dirty logging is enabled, the gstage page tables must be mapped
at PAGE_SIZE granularity to track dirty pages accurately. Currently,
if a huge PTE is encountered during the write-protect fault, the code
returns -EEXIST, which breaks VM migration.

Instead of returning an error, drop the huge PTE and map only the page
that is currently being accessed. This on‑demand approach avoids the
overhead of splitting the entire huge page into small pages upfront.

Signed-off-by: Wang Yechao <wang.yechao255@xxxxxxxxxx>
---
arch/riscv/kvm/gstage.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c
index b67d60d722c2..16c8afdafbfb 100644
--- a/arch/riscv/kvm/gstage.c
+++ b/arch/riscv/kvm/gstage.c
@@ -134,7 +134,7 @@ int kvm_riscv_gstage_set_pte(struct kvm_gstage *gstage,

while (current_level != map->level) {
if (gstage_pte_leaf(ptep))
- return -EEXIST;
+ set_pte(ptep, __pte(0));

if (!pte_val(ptep_get(ptep))) {
if (!pcache)
--
2.27.0