RISC-V: KVM: Fix hugepage mapping handling during dirty logging
Anup Patel
anup at brainfault.org
Tue Mar 3 00:07:22 PST 2026
On Thu, Feb 26, 2026 at 2:52 PM <wang.yechao255 at zte.com.cn> wrote:
>
> From: Wang Yechao <wang.yechao255 at zte.com.cn>
>
> 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 at zte.com.cn>
> ---
> 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().
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
More information about the linux-riscv
mailing list