igc: Allow hot-swapping XDP program
authorSong Yoong Siang <yoong.siang.song@intel.com>
Mon, 6 Jan 2025 22:19:15 +0000 (14:19 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 8 Jan 2025 02:14:09 +0000 (18:14 -0800)
Currently, the driver would always close and reopen the network interface
when setting/removing the XDP program, regardless of the presence of XDP
resources. This could cause unnecessary disruptions.

To avoid this, introduces a check to determine if there is a need to
close and reopen the interface, allowing for seamless hot-swapping of
XDP programs.

Signed-off-by: Song Yoong Siang <yoong.siang.song@intel.com>
Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Tested-by: Avigail Dahan <avigailx.dahan@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Link: https://patch.msgid.link/20250106221929.956999-8-anthony.l.nguyen@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/intel/igc/igc_xdp.c

index e27af72aada8b61cb0ab11dbb44988f53b71626d..869815f48ac1d2d6fb185756348d75d8054497cf 100644 (file)
@@ -13,6 +13,7 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
        struct net_device *dev = adapter->netdev;
        bool if_running = netif_running(dev);
        struct bpf_prog *old_prog;
+       bool need_update;
 
        if (dev->mtu > ETH_DATA_LEN) {
                /* For now, the driver doesn't support XDP functionality with
@@ -22,7 +23,8 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
                return -EOPNOTSUPP;
        }
 
-       if (if_running)
+       need_update = !!adapter->xdp_prog != !!prog;
+       if (if_running && need_update)
                igc_close(dev);
 
        old_prog = xchg(&adapter->xdp_prog, prog);
@@ -34,7 +36,7 @@ int igc_xdp_set_prog(struct igc_adapter *adapter, struct bpf_prog *prog,
        else
                xdp_features_clear_redirect_target(dev);
 
-       if (if_running)
+       if (if_running && need_update)
                igc_open(dev);
 
        return 0;