Skip to content

Commit 16edf51

Browse files
kuba-moogregkh
authored andcommitted
net: veth: clear GRO when clearing XDP even when down
[ Upstream commit fe9f801 ] 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 <tglx@linutronix.de> Reported-by: syzbot+039399a9b96297ddedca@syzkaller.appspotmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1a86827 commit 16edf51

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

drivers/net/veth.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,14 +1200,6 @@ static int veth_enable_xdp(struct net_device *dev)
12001200
veth_disable_xdp_range(dev, 0, dev->real_num_rx_queues, true);
12011201
return err;
12021202
}
1203-
1204-
if (!veth_gro_requested(dev)) {
1205-
/* user-space did not require GRO, but adding XDP
1206-
* is supposed to get GRO working
1207-
*/
1208-
dev->features |= NETIF_F_GRO;
1209-
netdev_features_change(dev);
1210-
}
12111203
}
12121204
}
12131205

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

1230-
if (!netif_running(dev) || !veth_gro_requested(dev)) {
1222+
if (!netif_running(dev) || !veth_gro_requested(dev))
12311223
veth_napi_del(dev);
12321224

1233-
/* if user-space did not require GRO, since adding XDP
1234-
* enabled it, clear it now
1235-
*/
1236-
if (!veth_gro_requested(dev) && netif_running(dev)) {
1237-
dev->features &= ~NETIF_F_GRO;
1238-
netdev_features_change(dev);
1239-
}
1240-
}
1241-
12421225
veth_disable_xdp_range(dev, 0, dev->real_num_rx_queues, false);
12431226
}
12441227

@@ -1646,6 +1629,14 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog,
16461629
}
16471630

16481631
if (!old_prog) {
1632+
if (!veth_gro_requested(dev)) {
1633+
/* user-space did not require GRO, but adding
1634+
* XDP is supposed to get GRO working
1635+
*/
1636+
dev->features |= NETIF_F_GRO;
1637+
netdev_features_change(dev);
1638+
}
1639+
16491640
peer->hw_features &= ~NETIF_F_GSO_SOFTWARE;
16501641
peer->max_mtu = max_mtu;
16511642
}
@@ -1661,6 +1652,14 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog,
16611652
if (dev->flags & IFF_UP)
16621653
veth_disable_xdp(dev);
16631654

1655+
/* if user-space did not require GRO, since adding XDP
1656+
* enabled it, clear it now
1657+
*/
1658+
if (!veth_gro_requested(dev)) {
1659+
dev->features &= ~NETIF_F_GRO;
1660+
netdev_features_change(dev);
1661+
}
1662+
16641663
if (peer) {
16651664
peer->hw_features |= NETIF_F_GSO_SOFTWARE;
16661665
peer->max_mtu = ETH_MAX_MTU;

0 commit comments

Comments
 (0)