Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xie Bo" <xb@ultrarisc.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] RISC-V: KVM: Serialize IMSIC attributes with vCPU migration
Date: Tue, 21 Jul 2026 07:53:41 +0000	[thread overview]
Message-ID: <20260721075342.279D01F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260721073612.137259-1-xb@ultrarisc.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Uninterruptible `mutex_lock` in device ioctl causes unkillable task hang.

Pre-existing issues:
- [High] Hardware state corruption due to missing CPU check in `kvm_riscv_vcpu_aia_imsic_put()`.
--

--- Patch [1]: [PATCH] RISC-V: KVM: Serialize IMSIC attributes with vCPU migration ---
commit 477c5bd7ef196223bb86313755b20f69e286864b
Author: Xie Bo <xb@ultrarisc.com>
RISC-V: KVM: Serialize IMSIC attributes with vCPU migration

KVM device ioctls are not serialized against KVM_RUN. This patch serializes
the entire IMSIC attribute operation with the target vCPU mutex to prevent
the VS-file from being migrated and recycled until the attribute access
completes.

> diff --git a/arch/riscv/kvm/aia_imsic.c b/arch/riscv/kvm/aia_imsic.c
> index d38f5de0834c5..2a4f88efee17f 100644
> --- a/arch/riscv/kvm/aia_imsic.c
> +++ b/arch/riscv/kvm/aia_imsic.c
> @@ -969,9 +969,13 @@ int kvm_riscv_aia_imsic_rw_attr(struct kvm *kvm, unsigned long type,
>  	if (!vcpu)
>  		return -ENODEV;
>  
> +	mutex_lock(&vcpu->mutex);

[Severity: High]
Does this uninterruptible mutex_lock() cause an unkillable task hang if the
target vCPU is currently executing a guest via KVM_RUN and holding its
vcpu->mutex?

Since it is reachable by userspace via KVM_SET_DEVICE_ATTR or
KVM_GET_DEVICE_ATTR, could a user program racing with KVM_RUN block
indefinitely in D-state?

Should this use mutex_lock_killable() instead to prevent a local denial
of service that triggers the hung task watchdog?

[ ... ]

[Severity: High]
This isn't a bug introduced by this patch, but looking at
kvm_riscv_vcpu_aia_imsic_put(), does it blindly set CSR_HGEIE on the local
CPU without verifying that imsic->vsfile_cpu matches the current
smp_processor_id()?

arch/riscv/kvm/aia_imsic.c:kvm_riscv_vcpu_aia_imsic_put() {
    ...
    if (imsic->vsfile_cpu > -1)
        csr_set(CSR_HGEIE, BIT(imsic->vsfile_hgei));
    ...
}

If a vCPU blocks in kvm_vcpu_block(), it can be migrated to a different CPU
upon wakeup. If it loops and sleeps again without returning to KVM_RUN
(where imsic->vsfile_cpu is updated), kvm_sched_out() will be invoked on the
new CPU.

Could this call kvm_riscv_vcpu_aia_imsic_put() and write to CSR_HGEIE on the
new CPU using imsic->vsfile_hgei allocated for the old CPU, resulting in
cross-CPU hardware state corruption affecting interrupts of other KVM guests?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721073612.137259-1-xb@ultrarisc.com?part=1

  reply	other threads:[~2026-07-21  7:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  7:36 [PATCH] RISC-V: KVM: Serialize IMSIC attributes with vCPU migration Xie Bo
2026-07-21  7:53 ` sashiko-bot [this message]
2026-08-08 13:38 ` Anup Patel
2026-08-10  1:21 ` [PATCH v2] " Xie Bo via B4 Relay
2026-08-10  1:33   ` 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=20260721075342.279D01F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xb@ultrarisc.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