[PATCH v2 1/2] RISC-V: KVM: Fix skip of valid pages in kvm_riscv_gstage_wp_range
Anup Patel
anup at brainfault.org
Sat Jun 6 23:20:31 PDT 2026
On Fri, Jun 5, 2026 at 4:33 AM <atwufei at 163.com> wrote:
>
> From: Wu Fei <wu.fei9 at sanechips.com.cn>
>
> 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 at sanechips.com.cn>
LGTM.
Reviewed-by: Anup Patel <anup at brainfault.org>
Queued this patch for Linux-7.2
Thanks,
Anup
> ---
> arch/riscv/kvm/gstage.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c
> index d9fe8be2a151..2b141a78ecac 100644
> --- a/arch/riscv/kvm/gstage.c
> +++ b/arch/riscv/kvm/gstage.c
> @@ -429,14 +429,14 @@ void 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);
> - 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);
> + kvm_riscv_gstage_op_pte(gstage, addr, ptep,
> + ptep_level, GSTAGE_OP_WP);
> + addr += page_size;
> + }
> }
> }
>
> --
> 2.51.0
>
More information about the linux-riscv
mailing list