Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Can Qi" <qican5708@163.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: riscv: Free detached G-stage page tables outside mmu_lock
Date: Sun, 20 Sep 2026 12:50:11 +0000	[thread overview]
Message-ID: <20260920125012.6A37B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260920123117.49830-1-qican5708@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kvm: riscv: read_unlock() with IRQs disabled triggers PREEMPT_RT WARN
--

commit 4942abf031219dcd47ba5f900125f636dc95e221
Author: Can Qi <qican5708@163.com>

KVM: riscv: Free detached G-stage page tables outside mmu_lock

This commit modifies the KVM RISC-V MMU to detach and free G-stage page
tables outside of mmu_lock to reduce lock contention during large VM
teardown. It quiesces guest and host hardware users before freeing the
detached tree, and replaces the KVM-wide split page cache with a
per-operation cache.

> diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c
> index 88e0c369b3544..da3308a3d0203 100644
> --- a/arch/riscv/kvm/vcpu_exit.c
> +++ b/arch/riscv/kvm/vcpu_exit.c
> @@ -90,7 +90,21 @@ unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu,
>  	register unsigned long ttmp asm("a1");
>  	unsigned long flags, val, tmp, old_stvec, old_hstatus;
>  
> +	/*
> +	 * Prevent G-stage teardown while HLV/HLVX can walk the page tables.
> +	 * The active-root check prevents a new walk from starting after detach.
> +	 */
> +	read_lock(&vcpu->kvm->mmu_lock);
> +	if (!vcpu->kvm->arch.pgd) {
> +		read_unlock(&vcpu->kvm->mmu_lock);
> +		trap->scause = EXC_LOAD_GUEST_PAGE_FAULT;
> +		trap->stval = guest_addr;
> +		return 0;
> +	}
>  	local_irq_save(flags);
> +	/* Publish the hardware walk before dropping the root lifetime lock. */
> +	smp_store_mb(vcpu->mode, READING_SHADOW_PAGE_TABLES);
> +	read_unlock(&vcpu->kvm->mmu_lock);

[Severity: High]
Does this sequence trigger a kernel warning on PREEMPT_RT systems?

On PREEMPT_RT, rwlocks are sleepable rt_rwlocks, and read_unlock() calls
migrate_enable(), which explicitly warns if called with interrupts disabled.
Since local_irq_save() disables interrupts just before
read_unlock(&vcpu->kvm->mmu_lock) is called, it seems this would cause a
WARN/BUG splat in kvm_riscv_vcpu_unpriv_read().

This path appears to be reachable by any untrusted guest capable of issuing
unprivileged accesses that trap to KVM, making it a guest-triggerable host
issue in PREEMPT_RT environments.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260920123117.49830-1-qican5708@163.com?part=1

  reply	other threads:[~2026-09-20 12:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 12:31 [PATCH] KVM: riscv: Free detached G-stage page tables outside mmu_lock Can Qi
2026-09-20 12:50 ` sashiko-bot [this message]
2026-09-20 14:08 ` [PATCH v2] " Can Qi
2026-09-20 14:30   ` sashiko-bot

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=20260920125012.6A37B1F000FF@smtp.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