Skip to content

Commit 8d6712c

Browse files
lkpdnPaolo Abeni
authored andcommitted
virtio_ring: add a func argument 'recycle_done' to virtqueue_resize()
When virtqueue_resize() 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 the recycle really occurs. Cc: <[email protected]> # v6.11+ Signed-off-by: Koichiro Den <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Xuan Zhuo <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4571dc7 commit 8d6712c

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

drivers/net/virtio_net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,7 @@ static int virtnet_rx_resize(struct virtnet_info *vi,
33313331

33323332
virtnet_rx_pause(vi, rq);
33333333

3334-
err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf);
3334+
err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf, NULL);
33353335
if (err)
33363336
netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err);
33373337

@@ -3394,7 +3394,7 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *sq,
33943394

33953395
virtnet_tx_pause(vi, sq);
33963396

3397-
err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf);
3397+
err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf, NULL);
33983398
if (err)
33993399
netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err);
34003400

drivers/virtio/virtio_ring.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_dma);
27722772
* @_vq: the struct virtqueue we're talking about.
27732773
* @num: new ring num
27742774
* @recycle: callback to recycle unused buffers
2775+
* @recycle_done: callback to be invoked when recycle for all unused buffers done
27752776
*
27762777
* When it is really necessary to create a new vring, it will set the current vq
27772778
* into the reset state. Then call the passed callback to recycle the buffer
@@ -2792,7 +2793,8 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_dma);
27922793
*
27932794
*/
27942795
int virtqueue_resize(struct virtqueue *_vq, u32 num,
2795-
void (*recycle)(struct virtqueue *vq, void *buf))
2796+
void (*recycle)(struct virtqueue *vq, void *buf),
2797+
void (*recycle_done)(struct virtqueue *vq))
27962798
{
27972799
struct vring_virtqueue *vq = to_vvq(_vq);
27982800
int err;
@@ -2809,6 +2811,8 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num,
28092811
err = virtqueue_disable_and_recycle(_vq, recycle);
28102812
if (err)
28112813
return err;
2814+
if (recycle_done)
2815+
recycle_done(_vq);
28122816

28132817
if (vq->packed_ring)
28142818
err = virtqueue_resize_packed(_vq, num);

include/linux/virtio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ dma_addr_t virtqueue_get_avail_addr(const struct virtqueue *vq);
109109
dma_addr_t virtqueue_get_used_addr(const struct virtqueue *vq);
110110

111111
int virtqueue_resize(struct virtqueue *vq, u32 num,
112-
void (*recycle)(struct virtqueue *vq, void *buf));
112+
void (*recycle)(struct virtqueue *vq, void *buf),
113+
void (*recycle_done)(struct virtqueue *vq));
113114
int virtqueue_reset(struct virtqueue *vq,
114115
void (*recycle)(struct virtqueue *vq, void *buf));
115116

0 commit comments

Comments
 (0)