Skip to content

Commit 744e9b2

Browse files
committed
Merge: virtio_net: correct netdev_tx_reset_queue() invocation point
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/95 JIRA: https://issues.redhat.com/browse/RHEL-56981 UPSTREAM status: merged BUILD: https://brew-task-repos.engineering.redhat.com/repos/scratch/lulu/kernel/6.12.0/342.el10/ Signed-off-by: Cindy Lu <lulu@redhat.com> Approved-by: Laurent Vivier <lvivier@redhat.com> Approved-by: Jason Wang <jasowang@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Jan Stancek <jstancek@redhat.com>
2 parents 030cf0f + 3c3f924 commit 744e9b2

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

drivers/net/virtio_net.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ struct virtio_net_common_hdr {
502502
};
503503

504504
static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf);
505+
static void virtnet_sq_free_unused_buf_done(struct virtqueue *vq);
505506
static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
506507
struct net_device *dev,
507508
unsigned int *xdp_xmit,
@@ -2892,7 +2893,6 @@ static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index)
28922893
if (err < 0)
28932894
goto err_xdp_reg_mem_model;
28942895

2895-
netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, qp_index));
28962896
virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi);
28972897
virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi);
28982898

@@ -3160,7 +3160,7 @@ static int virtnet_rx_resize(struct virtnet_info *vi,
31603160

31613161
virtnet_rx_pause(vi, rq);
31623162

3163-
err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf);
3163+
err = virtqueue_resize(rq->vq, ring_num, virtnet_rq_unmap_free_buf, NULL);
31643164
if (err)
31653165
netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err);
31663166

@@ -3223,7 +3223,8 @@ static int virtnet_tx_resize(struct virtnet_info *vi, struct send_queue *sq,
32233223

32243224
virtnet_tx_pause(vi, sq);
32253225

3226-
err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf);
3226+
err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf,
3227+
virtnet_sq_free_unused_buf_done);
32273228
if (err)
32283229
netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err);
32293230

@@ -5530,7 +5531,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
55305531

55315532
virtnet_rx_pause(vi, rq);
55325533

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

@@ -5991,6 +5992,14 @@ static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf)
59915992
xdp_return_frame(ptr_to_xdp(buf));
59925993
}
59935994

5995+
static void virtnet_sq_free_unused_buf_done(struct virtqueue *vq)
5996+
{
5997+
struct virtnet_info *vi = vq->vdev->priv;
5998+
int i = vq2txq(vq);
5999+
6000+
netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, i));
6001+
}
6002+
59946003
static void free_unused_bufs(struct virtnet_info *vi)
59956004
{
59966005
void *buf;
@@ -6722,11 +6731,20 @@ static int virtnet_probe(struct virtio_device *vdev)
67226731

67236732
static void remove_vq_common(struct virtnet_info *vi)
67246733
{
6734+
int i;
6735+
67256736
virtio_reset_device(vi->vdev);
67266737

67276738
/* Free unused buffers in both send and recv, if any. */
67286739
free_unused_bufs(vi);
67296740

6741+
/*
6742+
* Rule of thumb is netdev_tx_reset_queue() should follow any
6743+
* skb freeing not followed by netdev_tx_completed_queue()
6744+
*/
6745+
for (i = 0; i < vi->max_queue_pairs; i++)
6746+
netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, i));
6747+
67306748
free_receive_bufs(vi);
67316749

67326750
free_receive_page_frags(vi);

drivers/virtio/virtio_ring.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,7 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_dma);
27162716
* @_vq: the struct virtqueue we're talking about.
27172717
* @num: new ring num
27182718
* @recycle: callback to recycle unused buffers
2719+
* @recycle_done: callback to be invoked when recycle for all unused buffers done
27192720
*
27202721
* When it is really necessary to create a new vring, it will set the current vq
27212722
* into the reset state. Then call the passed callback to recycle the buffer
@@ -2736,7 +2737,8 @@ EXPORT_SYMBOL_GPL(vring_create_virtqueue_dma);
27362737
*
27372738
*/
27382739
int virtqueue_resize(struct virtqueue *_vq, u32 num,
2739-
void (*recycle)(struct virtqueue *vq, void *buf))
2740+
void (*recycle)(struct virtqueue *vq, void *buf),
2741+
void (*recycle_done)(struct virtqueue *vq))
27402742
{
27412743
struct vring_virtqueue *vq = to_vvq(_vq);
27422744
int err;
@@ -2753,6 +2755,8 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num,
27532755
err = virtqueue_disable_and_recycle(_vq, recycle);
27542756
if (err)
27552757
return err;
2758+
if (recycle_done)
2759+
recycle_done(_vq);
27562760

27572761
if (vq->packed_ring)
27582762
err = virtqueue_resize_packed(_vq, num);
@@ -2811,6 +2815,7 @@ EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped);
28112815
* virtqueue_reset - detach and recycle all unused buffers
28122816
* @_vq: the struct virtqueue we're talking about.
28132817
* @recycle: callback to recycle unused buffers
2818+
* @recycle_done: callback to be invoked when recycle for all unused buffers done
28142819
*
28152820
* Caller must ensure we don't call this with other virtqueue operations
28162821
* at the same time (except where noted).
@@ -2822,14 +2827,17 @@ EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped);
28222827
* -EPERM: Operation not permitted
28232828
*/
28242829
int virtqueue_reset(struct virtqueue *_vq,
2825-
void (*recycle)(struct virtqueue *vq, void *buf))
2830+
void (*recycle)(struct virtqueue *vq, void *buf),
2831+
void (*recycle_done)(struct virtqueue *vq))
28262832
{
28272833
struct vring_virtqueue *vq = to_vvq(_vq);
28282834
int err;
28292835

28302836
err = virtqueue_disable_and_recycle(_vq, recycle);
28312837
if (err)
28322838
return err;
2839+
if (recycle_done)
2840+
recycle_done(_vq);
28332841

28342842
if (vq->packed_ring)
28352843
virtqueue_reinit_packed(vq);

include/linux/virtio.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ dma_addr_t virtqueue_get_avail_addr(const struct virtqueue *vq);
100100
dma_addr_t virtqueue_get_used_addr(const struct virtqueue *vq);
101101

102102
int virtqueue_resize(struct virtqueue *vq, u32 num,
103-
void (*recycle)(struct virtqueue *vq, void *buf));
103+
void (*recycle)(struct virtqueue *vq, void *buf),
104+
void (*recycle_done)(struct virtqueue *vq));
104105
int virtqueue_reset(struct virtqueue *vq,
105-
void (*recycle)(struct virtqueue *vq, void *buf));
106+
void (*recycle)(struct virtqueue *vq, void *buf),
107+
void (*recycle_done)(struct virtqueue *vq));
106108

107109
struct virtio_admin_cmd {
108110
__le16 opcode;

0 commit comments

Comments
 (0)