All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shahar Shitrit" <shshitrit@nvidia.com>
Cc: virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path
Date: Thu, 03 Dec 2026 15:05:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-248056@kernel.org> (raw)
In-Reply-To: <20261202150502.3350030-3-shshitrit@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] virtio_pci: race and premature work cancel in
  vp_modern_avq_cleanup()
--

commit dbe6d2ad6d64e5dddf1bddc940f5ef549b3aca9d
Author: Shahar Shitrit <shshitrit@nvidia.com>

virtio_pci: Fix sleeping under spinlock in admin command path

This commit replaces the spinlock protecting the admin virtqueue with a
mutex to allow GFP_KERNEL allocations in virtqueue_add_sgs(), and defers
the completion callback from interrupt context to a work item.

> 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
[ ... ]
> @@ -344,20 +352,27 @@ static void vp_modern_avq_activate(struct virtio_device *vdev)
>  static void vp_modern_avq_cleanup(struct virtio_device *vdev)
>  {
>  	struct virtio_pci_device *vp_dev = to_vp_device(vdev);
> +	struct virtio_pci_admin_vq *admin_vq;
>  	struct virtio_admin_cmd *cmd;
>  	struct virtqueue *vq;
>  
> +	admin_vq = &vp_dev->admin_vq;
> +
>  	if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
>  		return;
>  
> -	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);
>  }
>  
>  static void vp_modern_del_vqs(struct virtio_device *vdev)

[Severity: Medium]
Can cancelling admin_vq->work in vp_modern_avq_cleanup() fail already
completed commands with -EIO and trigger BAD_RING() in
virtqueue_get_buf()?

Previously, vp_modern_avq_done() drained the used ring synchronously in
vring_interrupt(), so virtio_synchronize_cbs() guaranteed all used entries
were consumed and vq->last_used_idx was up to date before cleanup ran.
Now vp_modern_avq_done() only schedules admin_vq->work, leaving used
entries in the ring (more_used(vq) == true) when vring_interrupt()
returns.

If admin_vq->work is pending when vp_modern_avq_cleanup() runs,
cancel_work_sync() drops the work without draining the used ring.
virtqueue_detach_unused_buf() then detaches those completed buffers,
clearing desc_state[id].data = NULL and completing the commands with
-EIO, while vq->last_used_idx remains unadvanced.

Because vp_modern_del_vqs() calls vp_modern_avq_cleanup() before
vp_del_vqs() removes the admin virtqueue from vp_dev->virtqueues or frees
its IRQ, an interrupt firing on a shared vector before vp_del_vq() is
reached sees more_used(vq) == true and reschedules admin_vq->work:

CPU0                              CPU1
vp_modern_del_vqs()
  vp_modern_avq_cleanup()
    cancel_work_sync(&admin_vq->work)
    virtqueue_detach_unused_buf(vq)
      desc_state[id].data = NULL
                                  <hardirq>
                                  vring_interrupt()
                                    more_used(vq) == true
                                    vp_modern_avq_done()
                                      schedule_work(&admin_vq->work)
                                  vp_modern_avq_work()
                                    virtqueue_get_buf(vq, &len)
                                      !desc_state[id].data
                                      BAD_RING()
  vp_del_vqs()
    ...
    vp_del_vq()

Flushing admin_vq->work (or draining the used ring) instead of cancelling
it, and doing so after the admin virtqueue is unhooked from interrupt
dispatch, would avoid both issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202150502.3350030-1-shshitrit@nvidia.com?part=2

  reply	other threads:[~2026-12-03 15:05 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 15:04 [PATCH net-next v24 00/14] virtio_net: Add ethtool flow rules support Shahar Shitrit
2026-12-02 15:04 ` [PATCH net-next v24 01/14] virtio_pci: Remove supported_caps cache and build assert Shahar Shitrit
2026-12-02 15:04 ` [PATCH net-next v24 02/14] virtio_pci: Fix sleeping under spinlock in admin command path Shahar Shitrit
2026-12-03 15:05   ` sashiko-bot [this message]
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 03/14] virtio: Add config_op for admin commands Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 04/14] virtio: Expose generic device capability operations Shahar Shitrit
2026-12-03 15:05   ` sashiko-bot
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 05/14] virtio: Expose object create and destroy API Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 06/14] virtio_net: Query and set flow filter caps Shahar Shitrit
2026-12-03 13:16   ` Michael S. Tsirkin
2026-12-03 15:05   ` sashiko-bot
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 07/14] virtio_net: Create a FF group for ethtool steering Shahar Shitrit
2026-12-03 15:05   ` sashiko-bot
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 08/14] ethtool: Introduce ethtool_flow_type_mask() Shahar Shitrit
2026-12-02 15:04 ` [PATCH net-next v24 09/14] virtio_net: Implement layer 2 ethtool flow rules Shahar Shitrit
2026-12-03 13:19   ` Michael S. Tsirkin
2026-12-03 15:05   ` sashiko-bot
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:04 ` [PATCH net-next v24 10/14] virtio_net: Use existing classifier if possible Shahar Shitrit
2026-12-03 13:20   ` Michael S. Tsirkin
2026-12-02 15:04 ` [PATCH net-next v24 11/14] virtio_net: Implement IPv4 ethtool flow rules Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:05 ` [PATCH net-next v24 12/14] virtio_net: Add support for IPv6 ethtool steering Shahar Shitrit
2026-12-02 15:05 ` [PATCH net-next v24 13/14] virtio_net: Add support for TCP and UDP ethtool rules Shahar Shitrit
2026-12-03 15:06   ` sashiko-bot
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:05 ` [PATCH net-next v24 14/14] virtio_net: Add get ethtool flow rules ops Shahar Shitrit
2026-12-03 15:51   ` netdev-bot+sashiko
2026-12-02 15:08 ` [PATCH net-next v24 00/14] virtio_net: Add ethtool flow rules support netdev-bot+sinfo
     [not found]   ` <BL0PR12MB5505B05C081539D249C49DCCDA4B2@BL0PR12MB5505.namprd12.prod.outlook.com>
2026-12-03 11:06     ` Shahar Shitrit
2026-12-03 15:06 ` 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=sashiko-outbox-248056@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shshitrit@nvidia.com \
    --cc=virtualization@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.