Re: [PATCH v2 2/2] RISC-V: KVM: Fix skip of valid pages in kvm_riscv_gstage_unmap_range

Anup Patel <[email protected]>
Newsgroups org.infradead.lists.kvm-riscv,org.infradead.lists.linux-riscv,org.kernel.vger.kvm,org.kernel.vger.linux-kernel
Message-ID <CAAhSdy0KLEaCevhDTR-vK4EFZuFV5Nc32eZHhqndOuXkqW4bEA@mail.gmail.com>
On Fri, Jun 5, 2026 at 4:33 AM <[email protected]> wrote:
>
> From: Wu Fei <[email protected]>
>
> Same as kvm_riscv_gstage_wp_range, the possible valid pages should not
> be skipped if !found_leaf. Different from wp case, which can
> write-protect more than asked, unmap can't do that, no splitting is
> added right now but a warning is logged instead.
>
> Signed-off-by: Wu Fei <[email protected]>

LGTM.

Reviewed-by: Anup Patel <[email protected]>

Queued this patch for Linux-7.2

Thanks,
Anup


> ---
>  arch/riscv/kvm/gstage.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c
> index 2b141a78ecac..d78f5aeb8b40 100644
> --- a/arch/riscv/kvm/gstage.c
> +++ b/arch/riscv/kvm/gstage.c
> @@ -395,15 +395,19 @@ void kvm_riscv_gstage_unmap_range(struct kvm_gstage *gstage,
>                 if (ret)
>                         break;
>
> -               if (!found_leaf)
> -                       goto next;
> -
> -               if (!(addr & (page_size - 1)) && ((end - addr) >= page_size))
> -                       kvm_riscv_gstage_op_pte(gstage, addr, ptep,
> -                                               ptep_level, GSTAGE_OP_CLEAR);
> +               if (!found_leaf) {
> +                       addr = ALIGN(addr + 1, page_size);
> +               } else {
> +                       if (!(addr & (page_size - 1)) && ((end - addr) >= page_size))
> +                               kvm_riscv_gstage_op_pte(gstage, addr, ptep,
> +                                                       ptep_level, GSTAGE_OP_CLEAR);
> +                       else {
> +                               WARN_ONCE(1, "Skip unmap range addr: %#llx, end: %#llx, page_size: %#lx\n",
> +                                               addr, end, page_size);
> +                       }
>
> -next:
> -               addr += page_size;
> +                       addr += page_size;
> +               }
>
>                 /*
>                  * If the range is too large, release the kvm->mmu_lock
> --
> 2.51.0
>

-- 
kvm-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kvm-riscv
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.