Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

virtio_net: Fix napi_skb_cache_put warning

After the commit bdacf3e34945 ("net: Use nested-BH locking for
napi_alloc_cache.") was merged, the following warning began to appear:

WARNING: CPU: 5 PID: 1 at net/core/skbuff.c:1451 napi_skb_cache_put+0x82/0x4b0

__warn+0x12f/0x340
napi_skb_cache_put+0x82/0x4b0
napi_skb_cache_put+0x82/0x4b0
report_bug+0x165/0x370
handle_bug+0x3d/0x80
exc_invalid_op+0x1a/0x50
asm_exc_invalid_op+0x1a/0x20
__free_old_xmit+0x1c8/0x510
napi_skb_cache_put+0x82/0x4b0
__free_old_xmit+0x1c8/0x510
__free_old_xmit+0x1c8/0x510
__pfx___free_old_xmit+0x10/0x10

The issue arises because virtio is assuming it's running in NAPI context
even when it's not, such as in the netpoll case.

To resolve this, modify virtnet_poll_tx() to only set NAPI when budget
is available. Same for virtnet_poll_cleantx(), which always assumed that
it was in a NAPI context.

Fixes: df133f3f9625 ("virtio_net: bulk free tx skbs")
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Heng Qi <hengqi@linux.alibaba.com>
Link: https://patch.msgid.link/20240712115325.54175-1-leitao@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Breno Leitao and committed by
Jakub Kicinski
f8321fa7 217b953a

+4 -4
+4 -4
drivers/net/virtio_net.c
··· 2750 2750 return packets; 2751 2751 } 2752 2752 2753 - static void virtnet_poll_cleantx(struct receive_queue *rq) 2753 + static void virtnet_poll_cleantx(struct receive_queue *rq, int budget) 2754 2754 { 2755 2755 struct virtnet_info *vi = rq->vq->vdev->priv; 2756 2756 unsigned int index = vq2rxq(rq->vq); ··· 2768 2768 2769 2769 do { 2770 2770 virtqueue_disable_cb(sq->vq); 2771 - free_old_xmit(sq, txq, true); 2771 + free_old_xmit(sq, txq, !!budget); 2772 2772 } while (unlikely(!virtqueue_enable_cb_delayed(sq->vq))); 2773 2773 2774 2774 if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) { ··· 2813 2813 unsigned int xdp_xmit = 0; 2814 2814 bool napi_complete; 2815 2815 2816 - virtnet_poll_cleantx(rq); 2816 + virtnet_poll_cleantx(rq, budget); 2817 2817 2818 2818 received = virtnet_receive(rq, budget, &xdp_xmit); 2819 2819 rq->packets_in_napi += received; ··· 2935 2935 txq = netdev_get_tx_queue(vi->dev, index); 2936 2936 __netif_tx_lock(txq, raw_smp_processor_id()); 2937 2937 virtqueue_disable_cb(sq->vq); 2938 - free_old_xmit(sq, txq, true); 2938 + free_old_xmit(sq, txq, !!budget); 2939 2939 2940 2940 if (sq->vq->num_free >= 2 + MAX_SKB_FRAGS) { 2941 2941 if (netif_tx_queue_stopped(txq)) {