bnxt, qede and bnx2x clear NETIF_F_GRO_HW whenever NETIF_F_GRO is off. Nothing in the stack needs that. HW-GRO'd skbs arrive already coalesced with gso_size set, exactly like LRO frames, and LRO never depended on the software GRO bit. netif_elide_gro() only gates the software path, and the in-driver consumers of the offload key off the feature bit itself, not off NETIF_F_GRO. The coupling gets in the way of exercising the offload on its own: turning SW GRO off to isolate HW GRO takes HW GRO down with it on these three drivers, which is why the GRO selftests carry a generic XDP hack. The core only ever constrained GRO_HW on RXCSUM, RXFCS and LRO, and the other HW-GRO capable drivers do not couple the two either. User visible change: "ethtool -K $dev gro off" no longer implies "rx-gro-hw off" on bnxt, qede and bnx2x. Signed-off-by: Jakub Kicinski --- v2: no change v1: https://lore.kernel.org/20261118232315.3593731-2-kuba@kernel.org --- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 2 +- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 3 --- drivers/net/ethernet/qlogic/qede/qede_filter.c | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c index 6fb0619731ae..5686c4ecb944 100644 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c @@ -4934,7 +4934,7 @@ netdev_features_t bnx2x_fix_features(struct net_device *dev, if (!(features & NETIF_F_RXCSUM)) features &= ~NETIF_F_LRO; - if (!(features & NETIF_F_GRO) || !bnx2x_mtu_allows_gro(dev->mtu)) + if (!bnx2x_mtu_allows_gro(dev->mtu)) features &= ~NETIF_F_GRO_HW; if (features & NETIF_F_GRO_HW) features &= ~NETIF_F_LRO; diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 5c6c2219a481..ca7cb573d63c 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -14108,9 +14108,6 @@ static netdev_features_t bnxt_fix_features(struct net_device *dev, if ((bp->flags & BNXT_FLAG_NO_AGG_RINGS) || bp->xdp_prog) features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); - if (!(features & NETIF_F_GRO)) - features &= ~NETIF_F_GRO_HW; - if (features & NETIF_F_GRO_HW) features &= ~NETIF_F_LRO; diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c index 5bf32f1034e0..d0e203167e35 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c @@ -915,8 +915,7 @@ netdev_features_t qede_fix_features(struct net_device *dev, { struct qede_dev *edev = netdev_priv(dev); - if (edev->xdp_prog || edev->ndev->mtu > PAGE_SIZE || - !(features & NETIF_F_GRO)) + if (edev->xdp_prog || edev->ndev->mtu > PAGE_SIZE) features &= ~NETIF_F_GRO_HW; return features; -- 2.56.1 gro_stats.py carries its own copy of set_ethtool_feat(), which never reads the features back. The only check whether HW GRO really ended up enabled is the one guarding the generic XDP workaround, which is about to go away. Use the shared helper, so that the test can ask for that check like gro_lib.py does. A fixed feature now results in an XFAIL rather than a SKIP, same as in gro_lib.py. Signed-off-by: Jakub Kicinski --- v2: new patch --- .../selftests/drivers/net/hw/gro_stats.py | 45 +++++-------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/tools/testing/selftests/drivers/net/hw/gro_stats.py b/tools/testing/selftests/drivers/net/hw/gro_stats.py index 70e76e3888bd..a413e6fed210 100755 --- a/tools/testing/selftests/drivers/net/hw/gro_stats.py +++ b/tools/testing/selftests/drivers/net/hw/gro_stats.py @@ -13,7 +13,7 @@ from lib.py import ksft_run, ksft_exit, ksft_pr from lib.py import ksft_eq, ksft_ge, ksft_variants from lib.py import NetDrvEpEnv, NetdevFamily from lib.py import KsftSkipEx -from lib.py import bkg, cmd, defer, ethtool, ip +from lib.py import bkg, cmd, defer, ethtool, ip, set_ethtool_feat # gro.c uses hardcoded DPORT=8000 @@ -137,41 +137,16 @@ def _run_gro_test(cfg, test_name, num_flows=None, ignore_fail=False, raise KsftSkipEx(f"Driver does not report '{stat}' via qstats") -def _set_ethtool_feat(cfg, current, feats): - """Set ethtool features with defer to restore original state.""" - s2n = {True: "on", False: "off"} - - new = ["-K", cfg.ifname] - old = ["-K", cfg.ifname] - no_change = True - for name, state in feats.items(): - new += [name, s2n[state]] - old += [name, s2n[current[name]["active"]]] - - if current[name]["active"] != state: - no_change = False - if current[name]["fixed"]: - raise KsftSkipEx(f"Device does not support {name}") - if no_change: - return - - eth_cmd = ethtool(" ".join(new)) - defer(ethtool, " ".join(old)) - - # If ethtool printed something kernel must have modified some features - if eth_cmd.stdout: - ksft_pr(eth_cmd) - - def _setup_hw_gro(cfg): """Enable HW GRO on the device, disabling SW GRO.""" feat = ethtool(f"-k {cfg.ifname}", json=True)[0] # Try to disable SW GRO and enable HW GRO - _set_ethtool_feat(cfg, feat, - {"generic-receive-offload": False, - "rx-gro-hw": True, - "large-receive-offload": False}) + set_ethtool_feat(cfg.ifname, feat, + {"generic-receive-offload": False, + "rx-gro-hw": True, + "large-receive-offload": False}, + check=False) # Some NICs treat HW GRO as a GRO sub-feature so disabling GRO # will also clear HW GRO. Use a hack of installing XDP generic @@ -186,10 +161,10 @@ def _run_gro_test(cfg, test_name, num_flows=None, ignore_fail=False, # Attaching XDP may change features, fetch the latest state feat = ethtool(f"-k {cfg.ifname}", json=True)[0] - _set_ethtool_feat(cfg, feat, - {"generic-receive-offload": True, - "rx-gro-hw": True, - "large-receive-offload": False}) + set_ethtool_feat(cfg.ifname, feat, + {"generic-receive-offload": True, + "rx-gro-hw": True, + "large-receive-offload": False}) def _check_gro_stats(cfg, test_queue, stats_before, -- 2.56.1 The HW GRO tests want SW GRO out of the way so that what they observe can only have come from the device. On drivers which keyed HW GRO off NETIF_F_GRO that was not expressible with ethtool alone, so the setup fell back to attaching a generic XDP program, which suppresses SW GRO as a side effect. Those drivers no longer tie the two features together, so ask for the feature combination directly. Signed-off-by: Jakub Kicinski --- v2: - drop check=False in gro_stats.py too, now that it uses the shared helper (Willem) v1: https://lore.kernel.org/20261118232315.3593731-3-kuba@kernel.org --- .../testing/selftests/drivers/net/gro_lib.py | 21 +------------------ .../selftests/drivers/net/hw/gro_stats.py | 21 +------------------ 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/tools/testing/selftests/drivers/net/gro_lib.py b/tools/testing/selftests/drivers/net/gro_lib.py index 875a715b2ae1..6eff19db3541 100644 --- a/tools/testing/selftests/drivers/net/gro_lib.py +++ b/tools/testing/selftests/drivers/net/gro_lib.py @@ -263,26 +263,7 @@ def _run_gro_bin(cfg, test_name, protocol=None, num_flows=None, set_ethtool_feat(cfg.ifname, cfg.feat, {"generic-receive-offload": False, "rx-gro-hw": True, - "large-receive-offload": False}, - check=False) - - # Some NICs treat HW GRO as a GRO sub-feature so disabling GRO - # will also clear HW GRO. Use a hack of installing XDP generic - # to skip SW GRO, even when enabled. - feat = ethtool(f"-k {cfg.ifname}", json=True)[0] - if not feat["rx-gro-hw"]["active"]: - ksft_pr("Driver clears HW GRO and SW GRO is cleared, using generic XDP workaround") - prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" - ip(f"link set dev {cfg.ifname} xdpgeneric obj {prog} sec xdp") - defer(ip, f"link set dev {cfg.ifname} xdpgeneric off") - - # Attaching XDP may change features, fetch the latest state - feat = ethtool(f"-k {cfg.ifname}", json=True)[0] - - set_ethtool_feat(cfg.ifname, feat, - {"generic-receive-offload": True, - "rx-gro-hw": True, - "large-receive-offload": False}) + "large-receive-offload": False}) elif mode == "lro": # netdevsim advertises LRO for feature inheritance testing with # bonding/team tests but it doesn't actually perform the offload diff --git a/tools/testing/selftests/drivers/net/hw/gro_stats.py b/tools/testing/selftests/drivers/net/hw/gro_stats.py index a413e6fed210..2cccab12f68c 100755 --- a/tools/testing/selftests/drivers/net/hw/gro_stats.py +++ b/tools/testing/selftests/drivers/net/hw/gro_stats.py @@ -145,26 +145,7 @@ def _run_gro_test(cfg, test_name, num_flows=None, ignore_fail=False, set_ethtool_feat(cfg.ifname, feat, {"generic-receive-offload": False, "rx-gro-hw": True, - "large-receive-offload": False}, - check=False) - - # Some NICs treat HW GRO as a GRO sub-feature so disabling GRO - # will also clear HW GRO. Use a hack of installing XDP generic - # to skip SW GRO, even when enabled. - feat = ethtool(f"-k {cfg.ifname}", json=True)[0] - if not feat["rx-gro-hw"]["active"]: - ksft_pr("Driver clears HW GRO when SW GRO is cleared, using generic XDP workaround") - prog = cfg.net_lib_dir / "xdp_dummy.bpf.o" - ip(f"link set dev {cfg.ifname} xdpgeneric obj {prog} sec xdp") - defer(ip, f"link set dev {cfg.ifname} xdpgeneric off") - - # Attaching XDP may change features, fetch the latest state - feat = ethtool(f"-k {cfg.ifname}", json=True)[0] - - set_ethtool_feat(cfg.ifname, feat, - {"generic-receive-offload": True, - "rx-gro-hw": True, - "large-receive-offload": False}) + "large-receive-offload": False}) def _check_gro_stats(cfg, test_queue, stats_before, -- 2.56.1 XDP has to see the frames as the wire delivered them, so HW-GRO must be off while a program is attached. Drivers currently open-code that policy, and they diverge: mlx5, gve and virtio_net refuse the attach, bnxt and qede clear the feature from ndo_fix_features(), and idpf does nothing at all and happily runs RSC under XDP. Clear HW-GRO in __netdev_update_features(), and make sure XDP setup paths refresh the features. Take extra care to make sure the disablement actually works, some drivers add the feature back in ndo_fix_features, even when removed from wanted features (mlx5 does for header-data-split). This change also removes the warn-only check dev_disable_gro_hw() performed. On mlx5 with tcp-data-split on, attaching a multi-buf generic XDP program reached generic_xdp_install(), whose dev_disable_gro_hw() cleared wanted_features, recomputed, saw mlx5e_fix_features() put NETIF_F_GRO_HW straight back, and splatted: ------------[ cut here ]------------ netdevice: eth0: failed to disable GRO_HW! WARNING: net/core/dev.c:1880 at generic_xdp_install+0x135/0x190, CPU#53: ip/667 RIP: 0010:generic_xdp_install+0x17a/0x190 Call Trace: dev_xdp_install+0x2aa/0x380 dev_xdp_attach+0x41f/0x460 dev_change_xdp_fd+0xbb/0x110 do_setlink+0xfb9/0x1030 rtnl_newlink+0x9f5/0xaf0 rtnetlink_rcv_msg+0x442/0x490 netlink_rcv_skb+0x16a/0x1a0 netlink_unicast+0x1fc/0x320 netlink_sendmsg+0x2d6/0x380 and then attached anyway, leaving XDP looking at coalesced frames. The device also lost the bit from wanted_features for good, so HW-GRO never came back after detach - on mlx5 that took header-data split with it, and with it devmem and io_uring zero-copy Rx. Signed-off-by: Jakub Kicinski --- v2: no change v1: https://lore.kernel.org/20261118232315.3593731-4-kuba@kernel.org --- .../networking/net_cachelines/net_device.rst | 1 + include/linux/netdevice.h | 6 ++ net/core/dev.c | 97 ++++++++++++++----- 3 files changed, 81 insertions(+), 23 deletions(-) diff --git a/Documentation/networking/net_cachelines/net_device.rst b/Documentation/networking/net_cachelines/net_device.rst index 7620d3fcb8dc..25cf02a184ec 100644 --- a/Documentation/networking/net_cachelines/net_device.rst +++ b/Documentation/networking/net_cachelines/net_device.rst @@ -169,6 +169,7 @@ unsigned_long:1 see_all_hwtstamp_requests unsigned_long:1 change_proto_down unsigned_long:1 netns_immutable unsigned_long:1 fcoe_mtu +unsigned_long:1 xdp_pending unsigned_long:1 xdp_from_upper struct list_head net_notifier_list struct macsec_ops* macsec_ops diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0325c6f2a7d1..049538b13e61 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2531,6 +2531,12 @@ struct net_device { unsigned long change_proto_down:1; unsigned long netns_immutable:1; unsigned long fcoe_mtu:1; + /** + * @xdp_pending: an XDP program is being installed, but is not in + * @xdp_state yet. Most users should access it implicitly via + * helpers like dev_xdp_prog_count(), rather than directly. + */ + unsigned long xdp_pending:1; /** * @xdp_from_upper: the program in @xdp_state was installed by an * upper device with netif_xdp_propagate(); it belongs to the diff --git a/net/core/dev.c b/net/core/dev.c index 4ca8a9f5a7a5..5d38cdb6c326 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1902,23 +1902,6 @@ void netif_disable_lro(struct net_device *dev) } } -/** - * dev_disable_gro_hw - disable HW Generic Receive Offload on a device - * @dev: device - * - * Disable HW Generic Receive Offload (GRO_HW) on a net device. Must be - * called under RTNL. This is needed if Generic XDP is installed on - * the device. - */ -static void dev_disable_gro_hw(struct net_device *dev) -{ - dev->wanted_features &= ~NETIF_F_GRO_HW; - netdev_update_features(dev); - - if (unlikely(dev->features & NETIF_F_GRO_HW)) - netdev_WARN(dev, "failed to disable GRO_HW!\n"); -} - const char *netdev_cmd_to_name(enum netdev_cmd cmd) { #define N(val) \ @@ -6657,7 +6640,6 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp) } else if (new && !old) { static_branch_inc(&generic_xdp_needed_key); netif_disable_lro(dev); - dev_disable_gro_hw(dev); } break; @@ -10576,7 +10558,7 @@ u8 dev_xdp_prog_count(struct net_device *dev) for (i = 0; i < __MAX_XDP_MODE; i++) if (dev->xdp_state[i].prog || dev->xdp_state[i].link) count++; - return count; + return count ?: !!dev->xdp_pending; } EXPORT_SYMBOL_GPL(dev_xdp_prog_count); @@ -10617,6 +10599,32 @@ static void dev_xdp_set_prog(struct net_device *dev, enum bpf_xdp_mode mode, dev->xdp_state[mode].prog = prog; } +/* Try to clear HW-GRO before the driver reconfigures for XDP. + * Driver may add features back in via ndo_fix_features(), due to feature + * dependencies. In that case we can't run XDP at all. + */ +static int dev_xdp_clear_rx_agg(struct net_device *dev, + struct netlink_ext_ack *extack) +{ + if (!(dev->features & NETIF_F_GRO_HW)) + return 0; + if (!(dev->hw_features & NETIF_F_GRO_HW)) { + NL_SET_ERR_MSG(extack, + "unable to disable HW-GRO, fixed on"); + return -EOPNOTSUPP; + } + + netdev_update_features(dev); + + if (dev->features & NETIF_F_GRO_HW) { + NL_SET_ERR_MSG(extack, + "unable to disable HW-GRO, required by another feature"); + return -EBUSY; + } + + return 0; +} + int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf) { struct bpf_prog *old_prog; @@ -10650,11 +10658,17 @@ int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf) "unable to propagate XDP to device using memory provider"); return -EBUSY; } + + dev->xdp_pending = 1; + + err = dev_xdp_clear_rx_agg(dev, bpf->extack); + if (err) + goto err_clear_pending; } err = dev->netdev_ops->ndo_bpf(dev, bpf); if (err) - return err; + goto err_clear_pending; if (bpf->prog) bpf_prog_inc(bpf->prog); @@ -10667,11 +10681,22 @@ int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf) old_prog = dev_xdp_prog(dev, XDP_MODE_DRV); bpf_prog_change_xdp(old_prog, bpf->prog); dev_xdp_set_prog(dev, XDP_MODE_DRV, bpf->prog); + dev->xdp_pending = 0; dev->xdp_from_upper = !!bpf->prog; - if (old_prog) + + if (old_prog) { bpf_prog_put(old_prog); + /* The last program is gone, HW-GRO may be available again */ + if (!bpf->prog) + netdev_update_features(dev); + } return 0; + +err_clear_pending: + dev->xdp_pending = 0; + netdev_update_features(dev); + return err; } EXPORT_SYMBOL_GPL(netif_xdp_propagate); @@ -10880,19 +10905,36 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack return -EOPNOTSUPP; } + if (new_prog) { + dev->xdp_pending = 1; + err = dev_xdp_clear_rx_agg(dev, extack); + if (err) + goto err_clear_pending; + } + err = dev_xdp_install(dev, mode, bpf_op, extack, flags, new_prog); if (err) - return err; + goto err_clear_pending; } if (link) dev_xdp_set_link(dev, mode, link); else dev_xdp_set_prog(dev, mode, new_prog); - if (cur_prog) + dev->xdp_pending = 0; + if (cur_prog) { bpf_prog_put(cur_prog); + /* The last program is gone, HW-GRO may be available again */ + if (!new_prog) + netdev_update_features(dev); + } return 0; + +err_clear_pending: + dev->xdp_pending = 0; + netdev_update_features(dev); + return err; } static int dev_xdp_attach_link(struct net_device *dev, @@ -10918,6 +10960,7 @@ static int dev_xdp_detach_link(struct net_device *dev, bpf_op = dev_xdp_bpf_op(dev, mode); WARN_ON(dev_xdp_install(dev, mode, bpf_op, NULL, 0, NULL)); dev_xdp_set_link(dev, mode, NULL); + netdev_update_features(dev); return 0; } @@ -11390,6 +11433,14 @@ int __netdev_update_features(struct net_device *dev) features = netdev_get_wanted_features(dev); + /* GRO_HW may be added back in via ndo_fix_features e.g. if driver needs + * it to honor the HDS config, clear it before the fix features call. + */ + if ((features & NETIF_F_GRO_HW) && dev_xdp_prog_count(dev)) { + netdev_dbg(dev, "Dropping HW-GRO feature since XDP is attached.\n"); + features &= ~NETIF_F_GRO_HW; + } + if (dev->netdev_ops->ndo_fix_features) features = dev->netdev_ops->ndo_fix_features(dev, features); -- 2.56.1 LRO is the older take on the same thing as HW-GRO. And similarly to HW-GRO XDP cannot be handed post-LRO frames. Drivers open-code the exclusion just like they did for HW-GRO, and disagree just the same: mlx5 and netvsc refuse the attach, bnxt and ixgbe clear the feature from ndo_fix_features(), vmxnet3 writes dev->features behind the core's back, and atlantic only minds single-buffer programs. Clear LRO next to HW-GRO, with the same ordering and the same refusal if a driver insists on keeping it. atlantic loses LRO under a multi-buffer program now as well. XDP_TX and redirect can't carry the GSO metadata of a coalesced frame, however many buffers it spans. Drop netif_disable_lro() from generic_xdp_install(), like the previous patch dropped dev_disable_gro_hw(). The core covers the device itself, and LRO no longer stays off after the detach. This changes the behavior for lower devices. netif_disable_lro() walked them, dev_disable_gro_hw() never did. And unlike HW-GRO, LRO is in NETIF_F_UPPER_DISABLES, an upper which loses it clears it from the wanted_features of its lowers for good. bond and team carry LRO only to hand it down, so a program on a bond still turns LRO off on the slaves, and they don't get it back after the detach. Making sure lowers don't coalesce is a separate problem, for HW-GRO and LRO alike. LRO state with the program [attached / after it's detached], netdevsim as the single device, bond of two vmxnet3 ports: program on device w/o patch w/ patch ------------ ------- ----------- --------- dev, native dev on / on `1 off / on dev, generic dev off / off off / on bond, native bond on / on off / on slaves off / off`2 off / off bond, generic bond off / off off / on slaves off / off off / off `1 netdevsim ignores LRO under XDP, real drivers turned it off one way or another `2 vmxnet3 clears LRO from dev->features by itself and nothing turns it back on, bnxt slaves would get it back Ideally we'd want [off / on] (XDP disables LRO, LRO comes back once XDP is cleared). But the two "off"s after detach on slaves are not worth the complexity IMHO. Reviewed-by: Willem de Bruijn Signed-off-by: Jakub Kicinski --- v2: no change v1: https://lore.kernel.org/20261118232315.3593731-5-kuba@kernel.org --- include/linux/netdev_features.h | 6 ++++++ net/core/dev.c | 36 ++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h index 8eb6b8033606..62a05df8ee68 100644 --- a/include/linux/netdev_features.h +++ b/include/linux/netdev_features.h @@ -234,6 +234,12 @@ static inline int find_next_netdev_feature(u64 feature, unsigned long start) */ #define NETIF_F_UPPER_DISABLES NETIF_F_LRO +/* + * Receive offloads which coalesce frames. XDP has to see the frames as the + * wire delivered them, so these are disabled while a program is attached. + */ +#define NETIF_F_XDP_DISABLES (NETIF_F_GRO_HW | NETIF_F_LRO) + /* changeable features with no special hardware requirements */ #define NETIF_F_SOFT_FEATURES (NETIF_F_GSO | NETIF_F_GRO) diff --git a/net/core/dev.c b/net/core/dev.c index 5d38cdb6c326..308501d384b6 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6639,7 +6639,6 @@ static int generic_xdp_install(struct net_device *dev, struct netdev_bpf *xdp) static_branch_dec(&generic_xdp_needed_key); } else if (new && !old) { static_branch_inc(&generic_xdp_needed_key); - netif_disable_lro(dev); } break; @@ -10599,26 +10598,35 @@ static void dev_xdp_set_prog(struct net_device *dev, enum bpf_xdp_mode mode, dev->xdp_state[mode].prog = prog; } -/* Try to clear HW-GRO before the driver reconfigures for XDP. +static const char *dev_xdp_rx_agg_name(netdev_features_t features) +{ + return features & NETIF_F_GRO_HW ? "HW-GRO" : "LRO"; +} + +/* Try to clear HW-GRO and LRO before the driver reconfigures for XDP. * Driver may add features back in via ndo_fix_features(), due to feature * dependencies. In that case we can't run XDP at all. */ static int dev_xdp_clear_rx_agg(struct net_device *dev, struct netlink_ext_ack *extack) { - if (!(dev->features & NETIF_F_GRO_HW)) + netdev_features_t agg = dev->features & NETIF_F_XDP_DISABLES; + + if (!agg) return 0; - if (!(dev->hw_features & NETIF_F_GRO_HW)) { - NL_SET_ERR_MSG(extack, - "unable to disable HW-GRO, fixed on"); + if (agg & ~dev->hw_features) { + NL_SET_ERR_MSG_FMT(extack, "unable to disable %s, fixed on", + dev_xdp_rx_agg_name(agg & ~dev->hw_features)); return -EOPNOTSUPP; } netdev_update_features(dev); - if (dev->features & NETIF_F_GRO_HW) { - NL_SET_ERR_MSG(extack, - "unable to disable HW-GRO, required by another feature"); + agg = dev->features & NETIF_F_XDP_DISABLES; + if (agg) { + NL_SET_ERR_MSG_FMT(extack, + "unable to disable %s, required by another feature", + dev_xdp_rx_agg_name(agg)); return -EBUSY; } @@ -10686,7 +10694,7 @@ int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf) if (old_prog) { bpf_prog_put(old_prog); - /* The last program is gone, HW-GRO may be available again */ + /* No program left, HW-GRO and LRO may be available again */ if (!bpf->prog) netdev_update_features(dev); } @@ -10924,7 +10932,7 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack dev->xdp_pending = 0; if (cur_prog) { bpf_prog_put(cur_prog); - /* The last program is gone, HW-GRO may be available again */ + /* No program left, HW-GRO and LRO may be available again */ if (!new_prog) netdev_update_features(dev); } @@ -11436,9 +11444,9 @@ int __netdev_update_features(struct net_device *dev) /* GRO_HW may be added back in via ndo_fix_features e.g. if driver needs * it to honor the HDS config, clear it before the fix features call. */ - if ((features & NETIF_F_GRO_HW) && dev_xdp_prog_count(dev)) { - netdev_dbg(dev, "Dropping HW-GRO feature since XDP is attached.\n"); - features &= ~NETIF_F_GRO_HW; + if ((features & NETIF_F_XDP_DISABLES) && dev_xdp_prog_count(dev)) { + netdev_dbg(dev, "Dropping HW-GRO and LRO features since XDP is attached.\n"); + features &= ~NETIF_F_XDP_DISABLES; } if (dev->netdev_ops->ndo_fix_features) -- 2.56.1 The core clears HW-GRO and LRO before ndo_bpf runs and keeps them off for as long as a program is attached. mlx5e_fix_features() never sees either with params->xdp_prog set, and packet merge is always off by the time mlx5e_xdp_set() gets called, packet_merge.type only follows the two feature handlers. If tcp-data-split keeps HW-GRO on, the core refuses the attach with -EBUSY before calling the driver. The netdev_update_features() call at the end of mlx5e_xdp_set() was there to apply and release the XDP clause of mlx5e_fix_features(). The core recomputes the features itself, on detach after the program is gone. XDP features were only advertised with packet merge off, matching the old refusal. Key them off tcp-data-split instead, the only setting under which the attach is still refused. The AF_XDP check stays, the core doesn't know about XSK pools. This does change user visible behavior: attaching XDP with HW-GRO or LRO on used to fail with -EINVAL and now succeeds with them turned off. Signed-off-by: Jakub Kicinski --- v2: - drop the netdev_update_features() call from mlx5e_xdp_set() (Dragos) - key XDP features off tcp-data-split rather than packet merge (Dragos) v1: https://lore.kernel.org/20261118232315.3593731-6-kuba@kernel.org --- .../ethernet/mellanox/mlx5/core/en_ethtool.c | 8 +++- .../net/ethernet/mellanox/mlx5/core/en_main.c | 40 +++---------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index 8e7c748caf2d..da224ad3dea9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -488,9 +488,13 @@ static int mlx5e_set_ringparam(struct net_device *dev, if (err) return err; - /* Might need to adjust HW-GRO if it was kept on/off due to hds. */ - if (dev->cfg->hds_config != kernel_param->tcp_data_split) + /* Might need to adjust HW-GRO if it was kept on/off due to hds. + * XDP features depend on hds as well. + */ + if (dev->cfg->hds_config != kernel_param->tcp_data_split) { netdev_update_features(priv->netdev); + mlx5e_set_xdp_feature(priv); + } return 0; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 06a8a4be4be7..08568137d044 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -4487,12 +4487,14 @@ static int mlx5e_handle_feature(struct net_device *netdev, void mlx5e_set_xdp_feature(struct mlx5e_priv *priv) { + struct netdev_config *cfg = priv->netdev->cfg_pending; struct mlx5e_params *params = &priv->channels.params; struct net_device *netdev = priv->netdev; xdp_features_t val = 0; + /* XDP can't run with HW-GRO, and tcp-data-split keeps HW-GRO on */ if (netdev->netdev_ops->ndo_bpf && - params->packet_merge.type == MLX5E_PACKET_MERGE_NONE) + cfg->hds_config != ETHTOOL_TCP_DATA_SPLIT_ENABLED) val = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | NETDEV_XDP_ACT_XSK_ZEROCOPY | NETDEV_XDP_ACT_RX_SG; @@ -4604,17 +4606,6 @@ static netdev_features_t mlx5e_fix_features(struct net_device *netdev, } } - if (params->xdp_prog) { - if (features & NETIF_F_LRO) { - netdev_warn(netdev, "LRO is incompatible with XDP\n"); - features &= ~NETIF_F_LRO; - } - if (features & NETIF_F_GRO_HW) { - netdev_warn(netdev, "HW GRO is incompatible with XDP\n"); - features &= ~NETIF_F_GRO_HW; - } - } - if (priv->xsk.refcnt) { if (features & NETIF_F_LRO) { netdev_warn(netdev, "LRO is incompatible with AF_XDP (%u XSKs are active)\n", @@ -5203,20 +5194,6 @@ static void mlx5e_tx_timeout(struct net_device *dev, unsigned int txqueue) queue_work(priv->wq, &priv->tx_timeout_work); } -static int mlx5e_xdp_allowed(struct net_device *netdev, struct mlx5_core_dev *mdev, - struct mlx5e_params *params) -{ - if (params->packet_merge.type != MLX5E_PACKET_MERGE_NONE) { - netdev_warn(netdev, "can't set XDP while HW-GRO/LRO is on, disable them first\n"); - return -EINVAL; - } - - if (!mlx5e_params_validate_xdp(netdev, mdev, params)) - return -EINVAL; - - return 0; -} - static void mlx5e_rq_replace_xdp_prog(struct mlx5e_rq *rq, struct bpf_prog *prog) { struct bpf_prog *old_prog; @@ -5241,10 +5218,9 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog) new_params = priv->channels.params; new_params.xdp_prog = prog; - if (prog) { - err = mlx5e_xdp_allowed(netdev, priv->mdev, &new_params); - if (err) - goto unlock; + if (prog && !mlx5e_params_validate_xdp(netdev, priv->mdev, &new_params)) { + err = -EINVAL; + goto unlock; } /* no need for full reset when exchanging programs */ @@ -5279,10 +5255,6 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog) unlock: mutex_unlock(&priv->state_lock); - /* Need to fix some features. */ - if (!err) - netdev_update_features(netdev); - return err; } -- 2.56.1 The core keeps HW-GRO and LRO off while a program is attached, from before ndo_bpf is called until it's gone. The xdp_prog check in bnxt_fix_features() never changes the outcome any more. Without agg rings, which single-buffer XDP at a small MTU implies, neither offload works, so that part stays. Signed-off-by: Jakub Kicinski --- v2: no change v1: https://lore.kernel.org/20261118232315.3593731-7-kuba@kernel.org --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index ca7cb573d63c..168ef8f08aed 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -14105,7 +14105,7 @@ static netdev_features_t bnxt_fix_features(struct net_device *dev, bp->tx_ring_size < 2 * BNXT_SW_USO_MAX_DESCS) features &= ~NETIF_F_GSO_UDP_L4; - if ((bp->flags & BNXT_FLAG_NO_AGG_RINGS) || bp->xdp_prog) + if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); if (features & NETIF_F_GRO_HW) -- 2.56.1 The core clears HW-GRO before ndo_bpf runs and keeps it off for as long as a program is attached, which makes two bits of qede dead: - the xdp_prog check in qede_fix_features(); - qede_set_features() skipping the reload when a program is attached, HW-GRO can't change while edev->xdp_prog is set any more. qede_alloc_mem_rxq() clearing NETIF_F_GRO_HW from dev->features directly has to stay. Firmware recovery re-runs qede_init_ndev(), which rewrites dev->features with HW-GRO on, and nothing recomputes them. The direct write no longer leaves HW-GRO off after the program is removed, the core recomputes the features on detach. Signed-off-by: Jakub Kicinski --- v2: - keep clearing NETIF_F_GRO_HW in qede_alloc_mem_rxq(), FW recovery needs it v1: https://lore.kernel.org/20261118232315.3593731-8-kuba@kernel.org --- drivers/net/ethernet/qlogic/qede/qede_filter.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_filter.c b/drivers/net/ethernet/qlogic/qede/qede_filter.c index d0e203167e35..9c68579c5b33 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_filter.c +++ b/drivers/net/ethernet/qlogic/qede/qede_filter.c @@ -915,7 +915,7 @@ netdev_features_t qede_fix_features(struct net_device *dev, { struct qede_dev *edev = netdev_priv(dev); - if (edev->xdp_prog || edev->ndev->mtu > PAGE_SIZE) + if (edev->ndev->mtu > PAGE_SIZE) features &= ~NETIF_F_GRO_HW; return features; @@ -936,15 +936,8 @@ int qede_set_features(struct net_device *dev, netdev_features_t features) args.u.features = features; args.func = &qede_set_features_reload; - /* Make sure that we definitely need to reload. - * In case of an eBPF attached program, there will be no FW - * aggregations, so no need to actually reload. - */ __qede_lock(edev); - if (edev->xdp_prog) - args.func(edev, &args); - else - qede_reload(edev, &args, true); + qede_reload(edev, &args, true); __qede_unlock(edev); return 1; -- 2.56.1 The core clears NETIF_F_GRO_HW before ndo_bpf runs and refuses to turn it back on while a program is attached, so neither of these can fire any more. That holds for a program an upper device pushes down as well, which is why this comes last - gve_verify_xdp_configuration() was the only thing standing between a bonded gve port and XDP running with RSC still on. The user visible behavior changes as intended: attaching XDP to a gve device with HW-GRO on used to fail with -EOPNOTSUPP and now succeeds with HW-GRO turned off, which is what bnxt and qede have always done. The header-data split refusal right below keys off priv->header_split_enabled and stays. Reviewed-by: Ankit Garg Reviewed-by: Harshitha Ramamurthy Signed-off-by: Jakub Kicinski --- v2: no change v1: https://lore.kernel.org/20261118232315.3593731-9-kuba@kernel.org --- drivers/net/ethernet/google/gve/gve_main.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 35cf0f06a0f2..59ced629dcf6 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -1804,12 +1804,6 @@ static int gve_verify_xdp_configuration(struct net_device *dev, return -EOPNOTSUPP; } - if (dev->features & NETIF_F_GRO_HW) { - NL_SET_ERR_MSG_MOD(extack, - "XDP is not supported when HW-GRO is on."); - return -EOPNOTSUPP; - } - if (priv->header_split_enabled) { NL_SET_ERR_MSG_MOD(extack, "XDP is not supported when header-data split is enabled."); @@ -2218,12 +2212,6 @@ static int gve_set_features(struct net_device *netdev, if ((netdev->features & NETIF_F_GRO_HW) != (features & NETIF_F_GRO_HW)) { netdev->features ^= NETIF_F_GRO_HW; - if (priv->xdp_prog && (netdev->features & NETIF_F_GRO_HW)) { - netdev_warn(netdev, - "HW-GRO is not supported when XDP is on."); - err = -EOPNOTSUPP; - goto revert_features; - } if (netif_running(netdev)) { err = gve_adjust_config(priv, &tx_alloc_cfg, &rx_alloc_cfg); if (err) -- 2.56.1