Article View: linux.kernel.netdev
Article #26479Re: [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 15:51
Date: Thu, 03 Dec 2026 15:51
198 lines
15334 bytes
15334 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] When virtqueue_add_sgs() returns -ENOSPC,
virtqueue_exec_admin_cmd() keeps polling: mutex_unlock(),โฆ
- [Low] Suppose the device has finished an admin command: it has written
the status/result buffers and the used-ring entry, and the IRQ hasโฆ
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a high-
impact race on the path this patch reworks.
--
virtio_pci: Fix sleeping under spinlock in admin command path
This patch replaces the admin virtqueue spinlock with a mutex, so that
virtqueue_exec_admin_cmd() can call virtqueue_add_sgs() with GFP_KERNEL.
The virtqueue callback runs in interrupt context, so the used-buffer
processing in vp_modern_avq_done() moves to a work item,
vp_modern_avq_work(). The teardown paths cancel this work before the
admin vq is drained and deleted.
> diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
> index 3a97d0471dd27..d5ab2c11d0842 100644
> --- a/drivers/virtio/virtio_pci_modern.c
> +++ b/drivers/virtio/virtio_pci_modern.c
> @@ -47,13 +47,22 @@ static int vp_avq_index(struct virtio_device *vdev, u16 *index, u16 *num)
> void vp_modern_avq_done(struct virtqueue *vq)
> {
> struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
> - struct virtio_pci_admin_vq *admin_vq = &vp_dev->admin_vq;
> +
> + schedule_work(&vp_dev->admin_vq.work);
> +}
[ ... ]
> @@ -100,26 +108,26 @@ static int virtqueue_exec_admin_cmd(struct virtio_pci_admin_vq *admin_vq,
> if (virtqueue_is_broken(vq))
> return -EIO;
>
> - spin_lock_irqsave(&admin_vq->lock, flags);
> + mutex_lock(&admin_vq->lock);
> ret = virtqueue_add_sgs(vq, sgs, out_num, in_num, cmd, GFP_KERNEL);
> if (ret < 0) {
> if (ret == -ENOSPC) {
> - spin_unlock_irqrestore(&admin_vq->lock, flags);
> - cpu_relax();
> + mutex_unlock(&admin_vq->lock);
> + cond_resched();
> goto again;
> }
[Severity: Low]
Used descriptors are now reclaimed only in vp_modern_avq_work(). Could
this -ENOSPC retry loop end up busy-waiting on the same kworker it is
competing with?
Before this patch, vp_modern_avq_done() ran in hard IRQ context and
always preempted the poller. Now schedule_work() queues a SCHED_NORMAL
per-CPU work item on the CPU that took the interrupt. That work item
also needs admin_vq->lock, which the poller keeps taking and dropping.
If the poller runs on that CPU and never sleeps, progress depends on the
scheduler preempting it:
- a SCHED_FIFO/RR poller lets the kworker run only through RT
throttling or the fair dl_server
- a poller that is itself a work item in the same per-CPU pool holds
off the avq work until the CPU-intensive watchdog fires (about 10ms)
- with PREEMPT_NONE, the poller yields only once need_resched is set
Nothing wakes the submitter when descriptors are freed. This isn't a
hard deadlock, since tick preemption, the workqueue watchdog and RT
throttling all eventually let the kworker run.
Should the submitter sleep until vp_modern_avq_work() frees descriptors,
instead of polling with cond_resched()?
> goto unlock_err;
> }
> if (!virtqueue_kick(vq))
> goto unlock_err;
> - spin_unlock_irqrestore(&admin_vq->lock, flags);
> + mutex_unlock(&admin_vq->lock);
>
> wait_for_completion(&cmd->completion);
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Since
this path is being reworked, though: what stops a command from being
posted after vp_modern_avq_cleanup() has drained the queue?
virtqueue_exec_admin_cmd() reads admin_vq->info->vq and checks
virtqueue_is_broken() without holding admin_vq->lock. After it takes
the mutex, it never checks whether teardown has started.
Admin commands can also come from VF context. The vfio virtio variant
driver calls virtio_pci_admin_legacy_io_write() and the migration
helpers, and these go through virtio_pci_vf_get_pf_dev(). That helper
only checks that the PF's PCI driver is virtio_pci:
pf_vp_dev = pci_iov_get_pf_drvdata(pdev, &virtio_pci_driver);
It does not cover the virtio driver being unbound from the PF's virtio
device through sysfs, or a freeze. pci_disable_sriov() in
virtio_pci_remove() only covers PCI-level removal.
A possible interleaving:
CPU1 (PF teardown) CPU0 (VF admin command)
vp_modern_del_vqs()
vp_modern_avq_cleanup()
mutex_lock()
detach all buffers, -EIO
mutex_unlock()
virtqueue_exec_admin_cmd()
mutex_lock()
virtqueue_add_sgs()
virtqueue_kick()
mutex_unlock()
wait_for_completion()
vp_del_vqs()
vp_del_vq()
del_vq()
vring_del_virtqueue()
If CPU0 posts the buffer before vp_del_vq(), nothing ever completes it.
wait_for_completion() then blocks forever in TASK_UNINTERRUPTIBLE with
no timeout.
vring_del_virtqueue() does not take admin_vq->lock. If CPU0's add/kick
overlaps it, can CPU0 access freed vring memory?
Also, vp_del_vqs() never clears vp_dev->admin_vq.info. Would a VF
command issued after the unbind dereference the freed info through
admin_vq->info->vq?
The mutex added to vp_modern_avq_cleanup() serializes the detach loop
against the add. However, no shutting-down state is checked under the
lock. Should the teardown check and virtqueue_add_sgs() be in the same
critical section?
[ ... ]
> @@ -344,20 +352,27 @@ static void vp_modern_avq_activate(struct virtio_device *vdev)
> static void vp_modern_avq_cleanup(struct virtio_device *vdev)
> {
[ ... ]
> - vq = vp_dev->admin_vq.info->vq;
> + vq = admin_vq->info->vq;
> if (!vq)
> return;
>
> + cancel_work_sync(&admin_vq->work);
> +
> + mutex_lock(&admin_vq->lock);
> while ((cmd = virtqueue_detach_unused_buf(vq))) {
> cmd->ret = -EIO;
> complete(&cmd->completion);
> }
> + mutex_unlock(&admin_vq->lock);
[Severity: Low]
Can a command that the device already completed be reported as -EIO
here?
Suppose the device has written the status and the used-ring entry, and
the interrupt has queued vp_modern_avq_work(), but the work has not run
yet. cancel_work_sync() then throws that pending processing away instead
of running it.
virtqueue_detach_unused_buf_split() returns every desc_state[] entry
that has data set, including entries already in the used ring:
for (i = 0; i < vq->split.vring.num; i++) {
if (!vq->split.desc_state[i].data)
continue;
The completed command therefore gets cmd->ret = -EIO, and
vp_modern_admin_cmd_exec() skips reading the device's status.
Before this patch, the window was IRQ latency. It is now workqueue
latency.
Would flush_work(), or draining with virtqueue_get_buf() under the mutex
before the detach loop, let these commands complete with their real
result?
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202150502.3350030-1-shshitrit%40nvidia.com
Technical Details
Message-ID:
<179631310252.3146.17412875041611432271@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376730-linux-kernel-netdev=dewy.ruReferences:
<20261202150502.3350030-3-shshitrit@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376730-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path Date: Thu, 03 Dec 2026 15:51:42 +0000 Organization: Usenet Network Message-ID: <179631310252.3146.17412875041611432271@kernel.org> References: <20261202150502.3350030-3-shshitrit@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2533857"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:xDiK43WaEP4QRcSoZnyhDBFL8OU= sha256:ksae357F4Kad0QtZDc3wQhp1TMM3MA3iTJ1WsEaL0VY= sha1:vGxlqLeXqt7jq5SYwMFVcSTg4FA= sha256:At/nYKXRiNXpt0KXVZ95nPuFTGrsouV/tnL6ZvhEPUw= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 745A41179B6; Thu, 3 Dec 2026 18:52:06 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.64 X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FMBY7KMQFUvz; Thu, 3 Dec 2026 18:52:03 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376730-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 059931179BD; Thu, 3 Dec 2026 18:51:54 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 19CBB2BA5E; Thu, 3 Dec 2026 15:51:50 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796313110; b=CzVIVGCIThSf0HbNo7dVEsSAFVqS2ZHzA9RtVIFxMabFgvc4D+c1hfbPLchYmJ89IL91 KvlEhJwXlqxRp1DrDmzbBqRvA7fdQ+s3x4YSU49SdTdmT98TJLkOZ4KFB41pfW8GJs73O iZVJl86PHDQitnYc6ZYPxd4h4DQmnQZ17GxMbIZQLwTlc9HYqlcMcH/2+n5Pdv6TWel54 qsYLz36PVf98gt4Gy6wF1jF1ehyW6q/vrhMX5zzf9qA5OirgCtu8bkcCoP6NNhL66E9fZ PMIp/NWRwQsnITAWyCI6SKM0Jk5+s6FgQSv6q4LO5tLLrAWbHBY0Nj9y49IKdCc7RMg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313110; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=5RwAtz8ohu1gcFxNQczZB5jG4Jk828al1RtfKSEPzyY=; b=sy1Xxqm3gHnsyrSHv+Hd759za0tRopOwunY06ojXERtyOmrijRTXtzTkN3g5yYyGdPhS iwBvXGnDLkwStjLi6IxUO1T817dDA2FkTJg+mht5DsnIIjQZaKqaZw+C/bu17RrrkblQ5 5It1xOBx+OgVFS20o4qK6C8bDxXV8cXYHbFMJfe608qQfz4AW/puwh8RrlZHzN317bHSO G56JAgw3M4ZLM46b4G+tglkSNIkwm2cx8+QxOZVN0D/CAf6YOD+/jHoQnkhc48GXQnkAC n/LS8JA/zCbSv0e5652lEiLbg4TcZHPry3L+5ze95kEo2UQKA1hqB/cqAT74ZdpaxqQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Kg/s0cuP"; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5DAD606A32C; Thu, 3 Dec 2026 15:51:49 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Kg/s0cuP X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796313104; b=lbM9qZ3sZu1gZa98pAmdrga4/Dwl6ycENWLzbK7Y9R+U/M9gMwjceNVltHcJgpOgKFeM ysyXCdEoFNrIjArtVqVy6/EtcbD4bT4ZqiZWzKWIxTou3XcZk5t8wTy8vNnslMN0OiSi5 200yuditNiW9rOqAXPHGf/MhuR/R4rdzR0E5UHrheP7j7oYzP8rBH0lVQ9p8R/4iI1lkl BSk37BkF397K7igqT3c9lkAVXPyY3vUnlyu2CxliRBtCUV5dC4/fzag0g6Xn6b/GYbbvC kC9YZSFnp3qngf0HM37QovxheWJAzJ2u82ALug86Q0L6/gxL116WCBTXeTz+EzJF3Fw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313104; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=5RwAtz8ohu1gcFxNQczZB5jG4Jk828al1RtfKSEPzyY=; b=qAhA5X6mQRa+DS4LnrDNRv2UOQH4LVu55SOFZzjwriqJPNEORKI/Mk0K6e0YLOTaS4SX /W1jWNly62u4ubVXyfFaNfEsD3zqeq5uO3pwcG07Kv0k031rGiDKk9Lj0jOcsvinWZBTQ zqVG+/dFLq1x8dnGjRmKqqKffmFsI/p/Wih8C3S5n4JHCJf+S7xzqhwxvbd56N0lWDTwS Nm1c7kBg2KH9Nu7FYmXzAQHGY/SnwPFhgEXJsuj2SDUlJrVrPIwEe2Wtb7BIusRusszmB EifldqQb7Bn+ky3X+3rM0GQP7hWtrYU1og5mLwziSn0jGDRDHtgJgJzPLQu9+waBrLA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Kg/s0cuP"; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D0E3606A322; Thu, 3 Dec 2026 15:51:44 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09A401F000C1; Thu, 3 Dec 2026 15:51:42 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796313103; bh=5RwAtz8ohu1gcFxNQczZB5jG4Jk828al1RtfKSEPzyY=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Kg/s0cuPW9vc3ogGm5/9lz93jFl2C1X08VcqCyux/YKpIakHVT1csa8a+ALBOI0Kj pIKMMBuLFoEDfsiwYMtyc2sIS10+zSCMk3gDcgC+vJiLbRtrcSY0bCFJqfTP0AH8cI 9n5iuXSmXhFeK2qLFFZ/BK9Kf1QIxO0qK5Npeay02bcgpPapRnHgrtttMQ/WPCyv3y 57lqfST9PfIFU2oQbmDNQhplIW4cKhjQsR9AEnJ5yAqaArY85G5iYvzyScpd03AK4K 2Jnyp41UzYXwEhM5T47m5U64BvVZ5TZl7/Vb4CNPrmZ1gtycRzCJbkVZRNhRuh997F 1R+ur2nQ4RSDw== X-Cc: netdev@vger.kernel.org, mst@redhat.com, jasowang@redhat.com, pabeni@redhat.com, virtualization@lists.linux.dev, parav@nvidia.com, yohadt@nvidia.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, jgg@ziepe.ca, kevin.tian@intel.com, kuba@kernel.org, andrew+netdev@lunn.ch, edumazet@google.com, danielj@nvidia.com X-In-Reply-To: <20261202150502.3350030-3-shshitrit@nvidia.com> X-sashiko-severity: Low X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list