[PATCH] RISC-V: KVM: Use raw_spinlock for VMID update critical section
[email protected] Thu, 16 Jul 2026 14:40:11 +0800
| Newsgroups | org.infradead.lists.kvm-riscv,dev.linux.lists.linux-rt-devel,org.infradead.lists.linux-riscv,org.kernel.vger.kvm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: "Yuhang.chen" <[email protected]> The VMID update critical section performs an IPI broadcast via on_each_cpu_mask() on VMID version rollover, which must not be preempted under PREEMPT_RT. Convert vmid_lock to raw_spinlock_t and use plain raw_spin_lock()/raw_spin_unlock() (interrupts stay enabled, since on_each_cpu_mask() requires it). Assisted-by: YuanSheng:deepseek-v4-pro Co-developed-by: Quan Zhou <[email protected]> Signed-off-by: Quan Zhou <[email protected]> Signed-off-by: Yuhang.chen <[email protected]> --- arch/riscv/kvm/vmid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/riscv/kvm/vmid.c b/arch/riscv/kvm/vmid.c index c15bdb1dd8be..21c2b276b55d 100644 --- a/arch/riscv/kvm/vmid.c +++ b/arch/riscv/kvm/vmid.c @@ -21,7 +21,7 @@ static unsigned long vmid_version = 1; static unsigned long vmid_next; static unsigned long vmid_bits __ro_after_init; -static DEFINE_SPINLOCK(vmid_lock); +static DEFINE_RAW_SPINLOCK(vmid_lock); void __init kvm_riscv_gstage_vmid_detect(void) { @@ -78,14 +78,14 @@ void kvm_riscv_gstage_vmid_update(struct kvm_vcpu *vcpu) if (!kvm_riscv_gstage_vmid_ver_changed(vmid)) return; - spin_lock(&vmid_lock); + raw_spin_lock(&vmid_lock); /* * We need to re-check the vmid_version here to ensure that if * another vcpu already allocated a valid vmid for this vm. */ if (!kvm_riscv_gstage_vmid_ver_changed(vmid)) { - spin_unlock(&vmid_lock); + raw_spin_unlock(&vmid_lock); return; } @@ -117,7 +117,7 @@ void kvm_riscv_gstage_vmid_update(struct kvm_vcpu *vcpu) WRITE_ONCE(vmid->vmid_version, READ_ONCE(vmid_version)); - spin_unlock(&vmid_lock); + raw_spin_unlock(&vmid_lock); /* Request G-stage page table update for all VCPUs */ kvm_for_each_vcpu(i, v, vcpu->kvm) -- 2.34.1 -- kvm-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kvm-riscv