From: sashiko-bot@kernel.org
To: "Can Qi" <qican5708@163.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2] KVM: riscv: Allow rescheduling during G-stage unmap
Date: Mon, 23 Nov 2026 07:16:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-228803@kernel.org> (raw)
In-Reply-To: <20261123064935.1608890-1-qican5708@163.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: riscv: callers re-flush full range after batched unmap
yields
--
commit 98e1340ab679b1cafbeb059326e3045e4ca36e66
Author: Can Qi <qican5708@163.com>
KVM: riscv: Allow rescheduling during G-stage unmap
This commit allows G-stage unmap walks to yield mmu_lock, flushing pending
TLB batches before rescheduling and stopping if the root page table is
detached concurrently.
> diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c
> index be70607a33ea0..47b906769f497 100644
> --- a/arch/riscv/kvm/gstage.c
> +++ b/arch/riscv/kvm/gstage.c
> @@ -423,9 +423,19 @@ bool kvm_riscv_gstage_unmap_range(struct kvm_gstage *gstage,
> bool found_leaf;
> unsigned long page_size;
> gpa_t addr = start, end = start + size;
> - bool flush = false;
> + gfn_t last_flush_gfn = start >> PAGE_SHIFT;
> + bool pending_flush = false;
[ ... ]
> @@ -448,12 +458,21 @@ bool kvm_riscv_gstage_unmap_range(struct kvm_gstage *gstage,
> /*
> * If the range is too large, release the kvm->mmu_lock
> * to prevent starvation and lockup detector warnings.
> + * Flush first so another invalidator cannot miss cleared PTEs.
> */
> - if (!(gstage->flags & KVM_GSTAGE_FLAGS_LOCAL) && may_block && addr < end)
> + if (!(gstage->flags & KVM_GSTAGE_FLAGS_LOCAL) && may_block && addr < end &&
> + (need_resched() || rwlock_needbreak(&gstage->kvm->mmu_lock))) {
> + if (pending_flush) {
> + kvm_flush_remote_tlbs_range(gstage->kvm, last_flush_gfn,
> + (addr >> PAGE_SHIFT) - last_flush_gfn);
> + pending_flush = false;
> + }
> + last_flush_gfn = addr >> PAGE_SHIFT;
> cond_resched_rwlock_write(&gstage->kvm->mmu_lock);
> + }
> }
>
> - return flush;
> + return pending_flush;
> }
[Severity: Medium]
Does returning only pending_flush discard last_flush_gfn and cause callers
to re-flush the entire original range whenever a PTE is cleared after the
last yield?
When kvm_riscv_gstage_unmap_range() yields and then clears a PTE in the
remaining tail, kvm_arch_flush_shadow_memslot() and kvm_unmap_gfn_range()
call kvm_flush_remote_tlbs_range() from the start of the full range
instead of from last_flush_gfn. Because
kvm_riscv_local_hfence_gvma_vmid_gpa() falls back to a full-VMID TLB flush
when the range exceeds PTRS_PER_PTE (512 pages), any unmap of a range
larger than 2 MiB that yields and clears a tail PTE still triggers a
full-VMID flush across all vCPUs in addition to the intermediate batch
flushes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123064935.1608890-1-qican5708@163.com?part=1
next prev parent reply other threads:[~2026-11-23 7:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:50 [PATCH] KVM: riscv: Allow rescheduling during G-stage unmap Can Qi
2026-11-23 6:24 ` sashiko-bot
2026-11-23 6:49 ` [PATCH v2] " Can Qi
2026-11-23 7:16 ` sashiko-bot [this message]
2026-11-23 7:29 ` [PATCH v3] " Can Qi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-228803@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=qican5708@163.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox