Re: RISC-V: KVM: Fix hugepage mapping handling during dirty logging
From: wang.yechao255
Date: Tue Mar 03 2026 - 04:49:53 EST
> On Thu, Feb 26, 2026 at 2:52 PM <wang.yechao255@xxxxxxxxxx> wrote:
> >
> > 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));
>
> Making a leaf PTE invalid mut be followed by TLB invalidation
> using gstage_tlb_flush().
>
Thank you for the review. You are right, I missed the required TLB invalidation.
> I think returning -EEXIST is the right thing to do here because
> caller has to split a huge PTE with proper TLB invalidation.
>
> Regards,
> Anup
ok, let the caller split the huge PTE with proper TLB invalidation.
I will update the patch accordingly in the next version.
Regards,
Yechao