arch/riscv/kvm/gstage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
From: Wang Yechao <wang.yechao255@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@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));
if (!pte_val(ptep_get(ptep))) {
if (!pcache)
--
2.27.0
On Thu, Feb 26, 2026 at 2:52 PM <wang.yechao255@zte.com.cn> wrote:
>
> From: Wang Yechao <wang.yechao255@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@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
> On Thu, Feb 26, 2026 at 2:52 PM <wang.yechao255@zte.com.cn> wrote:
> >
> > From: Wang Yechao <wang.yechao255@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@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().
>
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
© 2016 - 2026 Red Hat, Inc.