Skip to content

Commit

Permalink
virtio_ring: add a func argument 'recycle_done' to virtqueue_reset()
Browse files Browse the repository at this point in the history
[ Upstream commit 8d2da07 ]

When virtqueue_reset() has actually recycled all unused buffers,
additional work may be required in some cases. Relying solely on its
return status is fragile, so introduce a new function argument
'recycle_done', which is invoked when it really occurs.

Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Stable-dep-of: 76a771e ("virtio_net: ensure netdev_tx_reset_queue is called on bind xsk for tx")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Koichiro Den authored and Greg Kroah-Hartman committed May 22, 2025
1 parent 1cf8bdd commit 343a775
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -5547,7 +5547,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu

virtnet_rx_pause(vi, rq);

err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf);
err = virtqueue_reset(rq->vq, virtnet_rq_unmap_free_buf, NULL);
if (err) {
netdev_err(vi->dev, "reset rx fail: rx queue index: %d err: %d\n", qindex, err);

Expand Down Expand Up @@ -5576,7 +5576,7 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi,

virtnet_tx_pause(vi, sq);

err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf);
err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf, NULL);
if (err) {
netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err);
pool = NULL;
Expand Down
6 changes: 5 additions & 1 deletion drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,7 @@ EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped);
* virtqueue_reset - detach and recycle all unused buffers
* @_vq: the struct virtqueue we're talking about.
* @recycle: callback to recycle unused buffers
* @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
* at the same time (except where noted).
Expand All @@ -2826,14 +2827,17 @@ EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped);
* -EPERM: Operation not permitted
*/
int virtqueue_reset(struct virtqueue *_vq,
void (*recycle)(struct virtqueue *vq, void *buf))
void (*recycle)(struct virtqueue *vq, void *buf),
void (*recycle_done)(struct virtqueue *vq))
{
struct vring_virtqueue *vq = to_vvq(_vq);
int err;

err = virtqueue_disable_and_recycle(_vq, recycle);
if (err)
return err;
if (recycle_done)
recycle_done(_vq);

if (vq->packed_ring)
virtqueue_reinit_packed(vq);
Expand Down
3 changes: 2 additions & 1 deletion include/linux/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ int virtqueue_resize(struct virtqueue *vq, u32 num,
void (*recycle)(struct virtqueue *vq, void *buf),
void (*recycle_done)(struct virtqueue *vq));
int virtqueue_reset(struct virtqueue *vq,
void (*recycle)(struct virtqueue *vq, void *buf));
void (*recycle)(struct virtqueue *vq, void *buf),
void (*recycle_done)(struct virtqueue *vq));

struct virtio_admin_cmd {
__le16 opcode;
Expand Down

0 comments on commit 343a775

Please sign in to comment.