From: Jinyu Tang <tjytimi@163.com>
To: Anup Patel <apatel@ventanamicro.com>,
Anup Patel <anup@brainfault.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
"Atish Patra" <atish.patra@linux.dev>,
"Paul Walmsley" <pjw@kernel.org>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
"Radim Krčmář" <radim.krcmar@oss.qualcomm.com>,
"Andrew Jones" <andrew.jones@oss.qualcomm.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Yong-Xuan Wang" <yongxuan.wang@sifive.com>,
"Nutty Liu" <nutty.liu@hotmail.com>,
"Jinyu Tang" <tjytimi@163.com>
Subject: [PATCH 1/5] KVM: riscv: Rely on common MMU notifier locking
Date: Sun, 17 May 2026 23:34:23 +0800 [thread overview]
Message-ID: <20260517153427.94889-2-tjytimi@163.com> (raw)
In-Reply-To: <20260517153427.94889-1-tjytimi@163.com>
The common KVM invalidation paths call kvm_unmap_gfn_range() with
mmu_lock already held for write.
For the standard MMU notifier path, the call chain is:
kvm_mmu_notifier_invalidate_range_start()
kvm_handle_hva_range()
kvm_unmap_gfn_range()
kvm_mmu_notifier_invalidate_range_start() leaves range.lockless clear.
kvm_handle_hva_range() therefore takes KVM_MMU_LOCK(kvm) before invoking
the handler.
The guest_memfd path has the same locking contract:
__kvm_gmem_invalidate_begin()
kvm_mmu_unmap_gfn_range()
kvm_unmap_gfn_range()
__kvm_gmem_invalidate_begin() explicitly takes KVM_MMU_LOCK(kvm) before
calling kvm_mmu_unmap_gfn_range().
So remove the local trylock and make the common locking contract explicit
with lockdep_assert_held_write() like x86.
Signed-off-by: Jinyu Tang <tjytimi@163.com>
---
arch/riscv/kvm/mmu.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
index 2d3def024..0197e41fc 100644
--- a/arch/riscv/kvm/mmu.c
+++ b/arch/riscv/kvm/mmu.c
@@ -230,18 +230,16 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
{
struct kvm_gstage gstage;
- bool mmu_locked;
if (!kvm->arch.pgd)
return false;
+ lockdep_assert_held_write(&kvm->mmu_lock);
+
kvm_riscv_gstage_init(&gstage, kvm);
- mmu_locked = spin_trylock(&kvm->mmu_lock);
kvm_riscv_gstage_unmap_range(&gstage, range->start << PAGE_SHIFT,
(range->end - range->start) << PAGE_SHIFT,
range->may_block);
- if (mmu_locked)
- spin_unlock(&kvm->mmu_lock);
return false;
}
--
2.43.0
next prev parent reply other threads:[~2026-05-17 15:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-17 15:34 [PATCH 0/5] KVM: riscv: Speed up dirty logging write faults Jinyu Tang
2026-05-17 15:34 ` Jinyu Tang [this message]
2026-05-17 15:34 ` [PATCH 2/5] KVM: riscv: Use an rwlock for mmu_lock Jinyu Tang
2026-05-17 15:34 ` [PATCH 3/5] KVM: riscv: Add a G-stage PTE cmpxchg helper Jinyu Tang
2026-05-17 15:34 ` [PATCH 4/5] KVM: riscv: Update G-stage PTE permissions atomically Jinyu Tang
2026-05-17 15:34 ` [PATCH 5/5] KVM: riscv: Fast-path dirty logging write faults Jinyu Tang
2026-05-28 22:35 ` Inochi Amaoto
2026-06-03 13:12 ` [PATCH 0/5] KVM: riscv: Speed up " Anup Patel
2026-06-26 8:21 ` patchwork-bot+linux-riscv
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=20260517153427.94889-2-tjytimi@163.com \
--to=tjytimi@163.com \
--cc=alex@ghiti.fr \
--cc=andrew.jones@oss.qualcomm.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=atish.patra@linux.dev \
--cc=conor.dooley@microchip.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=nutty.liu@hotmail.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=pbonzini@redhat.com \
--cc=pjw@kernel.org \
--cc=radim.krcmar@oss.qualcomm.com \
--cc=seanjc@google.com \
--cc=yongxuan.wang@sifive.com \
/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
all inboxes | Powered by JetHome®