Skip to content

Commit 00301ef

Browse files
author
Paolo Abeni
committed
Merge branch 'virtio_net-correct-netdev_tx_reset_queue-invocation-points'
Koichiro Den says: ==================== virtio_net: correct netdev_tx_reset_queue() invocation points When virtnet_close is followed by virtnet_open, some TX completions can possibly remain unconsumed, until they are finally processed during the first NAPI poll after the netdev_tx_reset_queue(), resulting in a crash [1]. Commit b96ed2c ("virtio_net: move netdev_tx_reset_queue() call before RX napi enable") was not sufficient to eliminate all BQL crash scenarios for virtio-net. This issue can be reproduced with the latest net-next master by running: `while :; do ip l set DEV down; ip l set DEV up; done` under heavy network TX load from inside the machine. This patch series resolves the issue and also addresses similar existing problems: (a). Drop netdev_tx_reset_queue() from open/close path. This eliminates the BQL crashes due to the problematic open/close path. (b). As a result of (a), netdev_tx_reset_queue() is now explicitly required in freeze/restore path. Add netdev_tx_reset_queue() immediately after free_unused_bufs() invocation. (c). Fix missing resetting in virtnet_tx_resize(). virtnet_tx_resize() has lacked proper resetting since commit c8bd1f7 ("virtio_net: add support for Byte Queue Limits"). (d). Fix missing resetting in the XDP_SETUP_XSK_POOL path. Similar to (c), this path lacked proper resetting. Call netdev_tx_reset_queue() when virtqueue_reset() has actually recycled unused buffers. This patch series consists of six commits: [1/6]: Resolves (a) and (b). # also -stable 6.11.y [2/6]: Minor fix to make [4/6] streamlined. [3/6]: Prerequisite for (c). # also -stable 6.11.y [4/6]: Resolves (c) (incl. Prerequisite for (d)) # also -stable 6.11.y [5/6]: Preresuisite for (d). [6/6]: Resolves (d). Changes for v4: - move netdev_tx_reset_queue() out of free_unused_bufs() - submit to net, not net-next Changes for v3: - replace 'flushed' argument with 'recycle_done' Changes for v2: - add tx queue resetting for (b) to (d) above v3: https://lore.kernel.org/all/[email protected]/ v2: https://lore.kernel.org/all/[email protected]/ v1: https://lore.kernel.org/all/[email protected]/ [1]: ------------[ cut here ]------------ kernel BUG at lib/dynamic_queue_limits.c:99! Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 7 UID: 0 PID: 1598 Comm: ip Tainted: G N 6.12.0net-next_main+ #2 Tainted: [N]=TEST Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), \ BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 RIP: 0010:dql_completed+0x26b/0x290 Code: b7 c2 49 89 e9 44 89 da 89 c6 4c 89 d7 e8 ed 17 47 00 58 65 ff 0d 4d 27 90 7e 0f 85 fd fe ff ff e8 ea 53 8d ff e9 f3 fe ff ff <0f> 0b 01 d2 44 89 d1 29 d1 ba 00 00 00 00 0f 48 ca e9 28 ff ff ff RSP: 0018:ffffc900002b0d08 EFLAGS: 00010297 RAX: 0000000000000000 RBX: ffff888102398c80 RCX: 0000000080190009 RDX: 0000000000000000 RSI: 000000000000006a RDI: 0000000000000000 RBP: ffff888102398c00 R08: 0000000000000000 R09: 0000000000000000 R10: 00000000000000ca R11: 0000000000015681 R12: 0000000000000001 R13: ffffc900002b0d68 R14: ffff88811115e000 R15: ffff8881107aca40 FS: 00007f41ded69500(0000) GS:ffff888667dc0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000556ccc2dc1a0 CR3: 0000000104fd8003 CR4: 0000000000772ef0 PKRU: 55555554 Call Trace: <IRQ> ? die+0x32/0x80 ? do_trap+0xd9/0x100 ? dql_completed+0x26b/0x290 ? dql_completed+0x26b/0x290 ? do_error_trap+0x6d/0xb0 ? dql_completed+0x26b/0x290 ? exc_invalid_op+0x4c/0x60 ? dql_completed+0x26b/0x290 ? asm_exc_invalid_op+0x16/0x20 ? dql_completed+0x26b/0x290 __free_old_xmit+0xff/0x170 [virtio_net] free_old_xmit+0x54/0xc0 [virtio_net] virtnet_poll+0xf4/0xe30 [virtio_net] ? __update_load_avg_cfs_rq+0x264/0x2d0 ? update_curr+0x35/0x260 ? reweight_entity+0x1be/0x260 __napi_poll.constprop.0+0x28/0x1c0 net_rx_action+0x329/0x420 ? enqueue_hrtimer+0x35/0x90 ? trace_hardirqs_on+0x1d/0x80 ? kvm_sched_clock_read+0xd/0x20 ? sched_clock+0xc/0x30 ? kvm_sched_clock_read+0xd/0x20 ? sched_clock+0xc/0x30 ? sched_clock_cpu+0xd/0x1a0 handle_softirqs+0x138/0x3e0 do_softirq.part.0+0x89/0xc0 </IRQ> <TASK> __local_bh_enable_ip+0xa7/0xb0 virtnet_open+0xc8/0x310 [virtio_net] __dev_open+0xfa/0x1b0 __dev_change_flags+0x1de/0x250 dev_change_flags+0x22/0x60 do_setlink.isra.0+0x2df/0x10b0 ? rtnetlink_rcv_msg+0x34f/0x3f0 ? netlink_rcv_skb+0x54/0x100 ? netlink_unicast+0x23e/0x390 ? netlink_sendmsg+0x21e/0x490 ? ____sys_sendmsg+0x31b/0x350 ? avc_has_perm_noaudit+0x67/0xf0 ? cred_has_capability.isra.0+0x75/0x110 ? __nla_validate_parse+0x5f/0xee0 ? __pfx___probestub_irq_enable+0x3/0x10 ? __create_object+0x5e/0x90 ? security_capable+0x3b/0x7�[I0 rtnl_newlink+0x784/0xaf0 ? avc_has_perm_noaudit+0x67/0xf0 ? cred_has_capability.isra.0+0x75/0x110 ? stack_depot_save_flags+0x24/0x6d0 ? __pfx_rtnl_newlink+0x10/0x10 rtnetlink_rcv_msg+0x34f/0x3f0 ? do_syscall_64+0x6c/0x180 ? entry_SYSCALL_64_after_hwframe+0x76/0x7e ? __pfx_rtnetlink_rcv_msg+0x10/0x10 netlink_rcv_skb+0x54/0x100 netlink_unicast+0x23e/0x390 netlink_sendmsg+0x21e/0x490 ____sys_sendmsg+0x31b/0x350 ? copy_msghdr_from_user+0x6d/0xa0 ___sys_sendmsg+0x86/0xd0 ? __pte_offset_map+0x17/0x160 ? preempt_count_add+0x69/0xa0 ? __call_rcu_common.constprop.0+0x147/0x610 ? preempt_count_add+0x69/0xa0 ? preempt_count_add+0x69/0xa0 ? _raw_spin_trylock+0x13/0x60 ? trace_hardirqs_on+0x1d/0x80 __sys_sendmsg+0x66/0xc0 do_syscall_64+0x6c/0x180 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f41defe5b34 Code: 15 e1 12 0f 00 f7 d8 64 89 02 b8 ff ff ff ff eb bf 0f 1f 44 00 00 f3 0f 1e fa 80 3d 35 95 0f 00 00 74 13 b8 2e 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 4c c3 0f 1f 00 55 48 89 e5 48 83 ec 20 89 55 RSP: 002b:00007ffe5336ecc8 EFLAGS: 00000202 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007f41defe5b34 RDX: 0000000000000000 RSI: 00007ffe5336ed30 RDI: 0000000000000003 RBP: 00007ffe5336eda0 R08: 0000000000000010 R09: 0000000000000001 R10: 00007ffe5336f6f9 R11: 0000000000000202 R12: 0000000000000003 R13: 0000000067452259 R14: 0000556ccc28b040 R15: 0000000000000000 </TASK> [...] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents af47a32 + 76a771e commit 00301ef

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

drivers/net/virtio_net.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ struct virtio_net_common_hdr {
503503
static struct virtio_net_common_hdr xsk_hdr;
504504

505505
static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf);
506+
static void virtnet_sq_free_unused_buf_done(struct virtqueue *vq);
506507
static int virtnet_xdp_handler(struct bpf_prog *xdp_prog, struct xdp_buff *xdp,
507508
struct net_device *dev,
508509
unsigned int *xdp_xmit,
@@ -3054,7 +3055,6 @@ static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index)
30543055
if (err < 0)
30553056
goto err_xdp_reg_mem_model;
30563057

3057-
netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, qp_index));
30583058
virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi);
30593059
virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi);
30603060

@@ -3332,7 +3332,7 @@ static int virtnet_rx_resize(struct virtnet_info *vi,
33323332

33333333
virtnet_rx_pause(vi, rq);
33343334

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

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

33963396
virtnet_tx_pause(vi, sq);
33973397

3398-
err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf);
3398+
err = virtqueue_resize(sq->vq, ring_num, virtnet_sq_free_unused_buf,
3399+
virtnet_sq_free_unused_buf_done);
33993400
if (err)
34003401
netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err);
34013402

@@ -5710,7 +5711,7 @@ static int virtnet_rq_bind_xsk_pool(struct virtnet_info *vi, struct receive_queu
57105711

57115712
virtnet_rx_pause(vi, rq);
57125713

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

@@ -5739,7 +5740,8 @@ static int virtnet_sq_bind_xsk_pool(struct virtnet_info *vi,
57395740

57405741
virtnet_tx_pause(vi, sq);
57415742

5742-
err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf);
5743+
err = virtqueue_reset(sq->vq, virtnet_sq_free_unused_buf,
5744+
virtnet_sq_free_unused_buf_done);
57435745
if (err) {
57445746
netdev_err(vi->dev, "reset tx fail: tx queue index: %d err: %d\n", qindex, err);
57455747
pool = NULL;
@@ -6214,7 +6216,7 @@ static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf)
62146216
{
62156217
struct virtnet_info *vi = vq->vdev->priv;
62166218
struct send_queue *sq;
6217-
int i = vq2rxq(vq);
6219+
int i = vq2txq(vq);
62186220

62196221
sq = &vi->sq[i];
62206222

@@ -6234,6 +6236,14 @@ static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf)
62346236
}
62356237
}
62366238

6239+
static void virtnet_sq_free_unused_buf_done(struct virtqueue *vq)
6240+
{
6241+
struct virtnet_info *vi = vq->vdev->priv;
6242+
int i = vq2txq(vq);
6243+
6244+
netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, i));
6245+
}
6246+
62376247
static void free_unused_bufs(struct virtnet_info *vi)
62386248
{
62396249
void *buf;
@@ -6966,11 +6976,20 @@ static int virtnet_probe(struct virtio_device *vdev)
69666976

69676977
static void remove_vq_common(struct virtnet_info *vi)
69686978
{
6979+
int i;
6980+
69696981
virtio_reset_device(vi->vdev);
69706982

69716983
/* Free unused buffers in both send and recv, if any. */
69726984
free_unused_bufs(vi);
69736985

6986+
/*
6987+
* Rule of thumb is netdev_tx_reset_queue() should follow any
6988+
* skb freeing not followed by netdev_tx_completed_queue()
6989+
*/
6990+
for (i = 0; i < vi->max_queue_pairs; i++)
6991+
netdev_tx_reset_queue(netdev_get_tx_queue(vi->dev, i));
6992+
69746993
free_receive_bufs(vi);
69756994

69766995
free_receive_page_frags(vi);

drivers/virtio/virtio_ring.c

Lines changed: 10 additions & 2 deletions
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);
@@ -2823,6 +2827,7 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
28232827
* virtqueue_reset - detach and recycle all unused buffers
28242828
* @_vq: the struct virtqueue we're talking about.
28252829
* @recycle: callback to recycle unused buffers
2830+
* @recycle_done: callback to be invoked when recycle for all unused buffers done
28262831
*
28272832
* Caller must ensure we don't call this with other virtqueue operations
28282833
* at the same time (except where noted).
@@ -2834,14 +2839,17 @@ EXPORT_SYMBOL_GPL(virtqueue_resize);
28342839
* -EPERM: Operation not permitted
28352840
*/
28362841
int virtqueue_reset(struct virtqueue *_vq,
2837-
void (*recycle)(struct virtqueue *vq, void *buf))
2842+
void (*recycle)(struct virtqueue *vq, void *buf),
2843+
void (*recycle_done)(struct virtqueue *vq))
28382844
{
28392845
struct vring_virtqueue *vq = to_vvq(_vq);
28402846
int err;
28412847

28422848
err = virtqueue_disable_and_recycle(_vq, recycle);
28432849
if (err)
28442850
return err;
2851+
if (recycle_done)
2852+
recycle_done(_vq);
28452853

28462854
if (vq->packed_ring)
28472855
virtqueue_reinit_packed(vq);

include/linux/virtio.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ 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,
114-
void (*recycle)(struct virtqueue *vq, void *buf));
115+
void (*recycle)(struct virtqueue *vq, void *buf),
116+
void (*recycle_done)(struct virtqueue *vq));
115117

116118
struct virtio_admin_cmd {
117119
__le16 opcode;

0 commit comments

Comments
 (0)