Skip to content

Commit fe9f801

Browse files
kuba-moodavem330
authored andcommitted
net: veth: clear GRO when clearing XDP even when down
veth sets NETIF_F_GRO automatically when XDP is enabled, because both features use the same NAPI machinery. The logic to clear NETIF_F_GRO sits in veth_disable_xdp() which is called both on ndo_stop and when XDP is turned off. To avoid the flag from being cleared when the device is brought down, the clearing is skipped when IFF_UP is not set. Bringing the device down should indeed not modify its features. Unfortunately, this means that clearing is also skipped when XDP is disabled _while_ the device is down. And there's nothing on the open path to bring the device features back into sync. IOW if user enables XDP, disables it and then brings the device up we'll end up with a stray GRO flag set but no NAPI instances. We don't depend on the GRO flag on the datapath, so the datapath won't crash. We will crash (or hang), however, next time features are sync'ed (either by user via ethtool or peer changing its config). The GRO flag will go away, and veth will try to disable the NAPIs. But the open path never created them since XDP was off, the GRO flag was a stray. If NAPI was initialized before we'll hang in napi_disable(). If it never was we'll crash trying to stop uninitialized hrtimer. Move the GRO flag updates to the XDP enable / disable paths, instead of mixing them with the ndo_open / ndo_close paths. Fixes: d3256ef ("veth: allow enabling NAPI even without XDP") Reported-by: Thomas Gleixner <[email protected]> Reported-by: [email protected] Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2a770cd commit fe9f801

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

drivers/net/veth.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,14 +1208,6 @@ static int veth_enable_xdp(struct net_device *dev)
12081208
veth_disable_xdp_range(dev, 0, dev->real_num_rx_queues, true);
12091209
return err;
12101210
}
1211-
1212-
if (!veth_gro_requested(dev)) {
1213-
/* user-space did not require GRO, but adding XDP
1214-
* is supposed to get GRO working
1215-
*/
1216-
dev->features |= NETIF_F_GRO;
1217-
netdev_features_change(dev);
1218-
}
12191211
}
12201212
}
12211213

@@ -1235,18 +1227,9 @@ static void veth_disable_xdp(struct net_device *dev)
12351227
for (i = 0; i < dev->real_num_rx_queues; i++)
12361228
rcu_assign_pointer(priv->rq[i].xdp_prog, NULL);
12371229

1238-
if (!netif_running(dev) || !veth_gro_requested(dev)) {
1230+
if (!netif_running(dev) || !veth_gro_requested(dev))
12391231
veth_napi_del(dev);
12401232

1241-
/* if user-space did not require GRO, since adding XDP
1242-
* enabled it, clear it now
1243-
*/
1244-
if (!veth_gro_requested(dev) && netif_running(dev)) {
1245-
dev->features &= ~NETIF_F_GRO;
1246-
netdev_features_change(dev);
1247-
}
1248-
}
1249-
12501233
veth_disable_xdp_range(dev, 0, dev->real_num_rx_queues, false);
12511234
}
12521235

@@ -1654,6 +1637,14 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog,
16541637
}
16551638

16561639
if (!old_prog) {
1640+
if (!veth_gro_requested(dev)) {
1641+
/* user-space did not require GRO, but adding
1642+
* XDP is supposed to get GRO working
1643+
*/
1644+
dev->features |= NETIF_F_GRO;
1645+
netdev_features_change(dev);
1646+
}
1647+
16571648
peer->hw_features &= ~NETIF_F_GSO_SOFTWARE;
16581649
peer->max_mtu = max_mtu;
16591650
}
@@ -1669,6 +1660,14 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog,
16691660
if (dev->flags & IFF_UP)
16701661
veth_disable_xdp(dev);
16711662

1663+
/* if user-space did not require GRO, since adding XDP
1664+
* enabled it, clear it now
1665+
*/
1666+
if (!veth_gro_requested(dev)) {
1667+
dev->features &= ~NETIF_F_GRO;
1668+
netdev_features_change(dev);
1669+
}
1670+
16721671
if (peer) {
16731672
peer->hw_features |= NETIF_F_GSO_SOFTWARE;
16741673
peer->max_mtu = ETH_MAX_MTU;

0 commit comments

Comments
 (0)