* [PATCH] virtio_ring: reject NULL recycle callback in reset/resize helpers
@ 2026-03-15 15:24 Shengwen Cheng
2026-03-15 15:30 ` Michael S. Tsirkin
0 siblings, 1 reply; 2+ messages in thread
From: Shengwen Cheng @ 2026-03-15 15:24 UTC (permalink / raw)
To: mst, jasowang
Cc: xuanzhuo, eperezma, virtualization, linux-kernel, Shengwen Cheng
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.
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] virtio_ring: reject NULL recycle callback in reset/resize helpers
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
0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2026-03-15 15:30 UTC (permalink / raw)
To: Shengwen Cheng; +Cc: jasowang, xuanzhuo, eperezma, virtualization, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-15 15:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox