igb_xdp() can run while the device is runtime suspended or resuming, and __igb_resume() rebuilds the queue counts and the rings without RTNL. igb_xdp_setup() and igb_xsk_pool_setup() can then see a queue count whose rings don't exist yet (NULL dereference), or a NAPI that isn't enabled yet (napi_disable() never returns). Changing the XDP program of a runtime suspended device also opened it twice. Resume the device for the duration of igb_xdp(), as ethtool does. Like the other resumes done with RTNL held, this can still deadlock with a runtime suspend already in progress, which takes RTNL itself; closing an AF_XDP socket or changing the XDP program is now one of them. Tested with the 82576 emulated by QEMU by closing a zero-copy AF_XDP socket and attaching an XDP program while the device is runtime suspended; the latter no longer warns in __netif_napi_del_locked() because of the double open. The races themselves weren't reproduced. Fixes: 9cbc948b5a20 ("igb: add XDP support") Fixes: 80f6ccf9f116 ("igb: Introduce XSK data structures and helpers") Cc: stable@vger.kernel.org Signed-off-by: Antonio Quartulli --- v5: new patch (Sashiko) drivers/net/ethernet/intel/igb/igb_main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index acd9a33..80ae03d 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -2942,16 +2942,28 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf) static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) { struct igb_adapter *adapter = netdev_priv(dev); + int err; + + /* The rings only exist while the device is resumed, and resuming + * rebuilds them without RTNL + */ + pm_runtime_get_sync(&adapter->pdev->dev); switch (xdp->command) { case XDP_SETUP_PROG: - return igb_xdp_setup(dev, xdp); + err = igb_xdp_setup(dev, xdp); + break; case XDP_SETUP_XSK_POOL: - return igb_xsk_pool_setup(adapter, xdp->xsk.pool, - xdp->xsk.queue_id); + err = igb_xsk_pool_setup(adapter, xdp->xsk.pool, + xdp->xsk.queue_id); + break; default: - return -EINVAL; + err = -EINVAL; } + + pm_runtime_put(&adapter->pdev->dev); + + return err; } int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp) -- 2.56.1