Skip to content

Commit 8af52fe

Browse files
stephan-ghkuba-moo
authored andcommitted
virtio_net: fix xdp_rxq_info bug after suspend/resume
The following sequence currently causes a driver bug warning when using virtio_net: # ip link set eth0 up # echo mem > /sys/power/state (or e.g. # rtcwake -s 10 -m mem) <resume> # ip link set eth0 down Missing register, driver bug WARNING: CPU: 0 PID: 375 at net/core/xdp.c:138 xdp_rxq_info_unreg+0x58/0x60 Call trace: xdp_rxq_info_unreg+0x58/0x60 virtnet_close+0x58/0xac __dev_close_many+0xac/0x140 __dev_change_flags+0xd8/0x210 dev_change_flags+0x24/0x64 do_setlink+0x230/0xdd0 ... This happens because virtnet_freeze() frees the receive_queue completely (including struct xdp_rxq_info) but does not call xdp_rxq_info_unreg(). Similarly, virtnet_restore() sets up the receive_queue again but does not call xdp_rxq_info_reg(). Actually, parts of virtnet_freeze_down() and virtnet_restore_up() are almost identical to virtnet_close() and virtnet_open(): only the calls to xdp_rxq_info_(un)reg() are missing. This means that we can fix this easily and avoid such problems in the future by just calling virtnet_close()/open() from the freeze/restore handlers. Aside from adding the missing xdp_rxq_info calls the only difference is that the refill work is only cancelled if netif_running(). However, this should not make any functional difference since the refill work should only be active if the network interface is actually up. Fixes: 754b8a2 ("virtio_net: setup xdp_rxq_info") Signed-off-by: Stephan Gerhold <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Jason Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 448ad88 commit 8af52fe

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

drivers/net/virtio_net.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,30 +2768,23 @@ static const struct ethtool_ops virtnet_ethtool_ops = {
27682768
static void virtnet_freeze_down(struct virtio_device *vdev)
27692769
{
27702770
struct virtnet_info *vi = vdev->priv;
2771-
int i;
27722771

27732772
/* Make sure no work handler is accessing the device */
27742773
flush_work(&vi->config_work);
27752774

27762775
netif_tx_lock_bh(vi->dev);
27772776
netif_device_detach(vi->dev);
27782777
netif_tx_unlock_bh(vi->dev);
2779-
cancel_delayed_work_sync(&vi->refill);
2780-
2781-
if (netif_running(vi->dev)) {
2782-
for (i = 0; i < vi->max_queue_pairs; i++) {
2783-
napi_disable(&vi->rq[i].napi);
2784-
virtnet_napi_tx_disable(&vi->sq[i].napi);
2785-
}
2786-
}
2778+
if (netif_running(vi->dev))
2779+
virtnet_close(vi->dev);
27872780
}
27882781

27892782
static int init_vqs(struct virtnet_info *vi);
27902783

27912784
static int virtnet_restore_up(struct virtio_device *vdev)
27922785
{
27932786
struct virtnet_info *vi = vdev->priv;
2794-
int err, i;
2787+
int err;
27952788

27962789
err = init_vqs(vi);
27972790
if (err)
@@ -2800,15 +2793,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
28002793
virtio_device_ready(vdev);
28012794

28022795
if (netif_running(vi->dev)) {
2803-
for (i = 0; i < vi->curr_queue_pairs; i++)
2804-
if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL))
2805-
schedule_delayed_work(&vi->refill, 0);
2806-
2807-
for (i = 0; i < vi->max_queue_pairs; i++) {
2808-
virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
2809-
virtnet_napi_tx_enable(vi, vi->sq[i].vq,
2810-
&vi->sq[i].napi);
2811-
}
2796+
err = virtnet_open(vi->dev);
2797+
if (err)
2798+
return err;
28122799
}
28132800

28142801
netif_tx_lock_bh(vi->dev);

0 commit comments

Comments
 (0)