public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Shengwen Cheng <shengwen1997.tw@gmail.com>
Cc: jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
	eperezma@redhat.com, virtualization@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virtio_ring: reject NULL recycle callback in reset/resize helpers
Date: Sun, 15 Mar 2026 11:30:01 -0400	[thread overview]
Message-ID: <20260315112904-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260315152403.127645-1-shengwen1997.tw@gmail.com>

On Sun, Mar 15, 2026 at 11:24:03PM +0800, Shengwen Cheng wrote:
> virtqueue_reset() and virtqueue_resize() rely on the recycle callback
> to release each detached unused buffer after disable_vq_and_reset().
> 
> As a defensive change, reject a NULL recycle callback explicitly to make
> this requirement clear. Update virtqueue_disable_and_recycle() to warn
> and return -EINVAL when @recycle is NULL, and update the descriptions
> for virtqueue_reset() and virtqueue_resize() to document that @recycle
> must not be %NULL.

I see little point in this change, sorry.

> ---
>  drivers/virtio/virtio_ring.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 335692d41617..563cee634426 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -2698,6 +2698,9 @@ static int virtqueue_disable_and_recycle(struct virtqueue *_vq,
>  	void *buf;
>  	int err;
>  
> +	if (WARN_ON_ONCE(!recycle))
> +		return -EINVAL;
> +
>  	if (!vq->we_own_ring)
>  		return -EPERM;
>  
> @@ -3311,7 +3314,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_map);
>   * virtqueue_resize - resize the vring of vq
>   * @_vq: the struct virtqueue we're talking about.
>   * @num: new ring num
> - * @recycle: callback to recycle unused buffers
> + * @recycle: callback to recycle unused buffers, must not be %NULL
>   * @recycle_done: callback to be invoked when recycle for all unused buffers done
>   *
>   * When it is really necessary to create a new vring, it will set the current vq
> @@ -3367,7 +3370,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
>  /**
>   * virtqueue_reset - detach and recycle all unused buffers
>   * @_vq: the struct virtqueue we're talking about.
> - * @recycle: callback to recycle unused buffers
> + * @recycle: callback to recycle unused buffers, must not be %NULL
>   * @recycle_done: callback to be invoked when recycle for all unused buffers done
>   *
>   * Caller must ensure we don't call this with other virtqueue operations
> -- 
> 2.34.1


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

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-15 15:24 [PATCH] virtio_ring: reject NULL recycle callback in reset/resize helpers Shengwen Cheng
2026-03-15 15:30 ` Michael S. Tsirkin [this message]

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=20260315112904-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shengwen1997.tw@gmail.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.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