From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09A401F000C1; Thu, 3 Dec 2026 15:51:42 +0000 (UTC) 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== Subject: Re: [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path From: netdev-bot+sashiko@kernel.org To: shshitrit@nvidia.com 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 Date: Thu, 03 Dec 2026 15:51:42 +0000 Message-ID: <179631310252.3146.17412875041611432271@kernel.org> In-Reply-To: <20261202150502.3350030-3-shshitrit@nvidia.com> References: <20261202150502.3350030-3-shshitrit@nvidia.com> X-sashiko-severity: Low Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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