From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796259858; b=dQck88yZJPTDvP6K9Rr3tcmjXE+ThvjjPINU0oC8XPO4FB78lfS7WPf/+iHF+1yQ54um RXS51K9wg5Q4XR784ouQlYtatcWFYR3HlcSGsgj+kOZRYDthgMUCZUf7FvA79nN2ejR8X MIynGZMs7v/s9mAMkfGT0EL5Ko8r4TjQJFWWeH6hog0zMAthvwS2B9ypUGk6EwTz3TJem V5zC5H2UCXc7KkdU198MXZ+fcLIYQw6OWWtJSm0HQENdBKLWB+Sv5rBwDZNAgpxSJNoiS FCgcaodyYPa216RWM8E/+3v6QZvOxQol7pNP0TgYZiLxgjHWUWDrP9JgJRCS5ixogeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796259858; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=CR6P+5+WfHz0ocD1aUAs0jDEc9anQ5HL09pMcgQ00/s=; b=ZqCQDqBPu5W/4ZJ6Neievp2VJkXZ+0jmQHLCEeSG2HvfzoLB5L++bS7il699UfDW/ltc q/4q5Ov/rlMYK77k3iIbRmI33G3bRvFgkP/z6kOn4CLCSFdaYkfcVGkD1l2DvvMHPQzZj eTrf6mFAW3B89IdZlUveWSsdmNJZOtYndLpQeDbsqE00JfL4CugrMVWPK30dAnQ3jCJuQ I0JDb+5n2Req+1I0/MimTmWoqfwkc5qIjKtPXfXsuqdpeBsMUdtTLC/ABMZwILKtnePv9 9e7Im0cTGr1x+3GQt2KtFsALzrg+LI5Elje/7gcM6sQ0GWZX0zM16WXMFnsRkU0kn3A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=crXMAsNP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C7AA606A688; Thu, 3 Dec 2026 01:04:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=crXMAsNP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41D0A1F000C1; Thu, 3 Dec 2026 01:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796259857; bh=CR6P+5+WfHz0ocD1aUAs0jDEc9anQ5HL09pMcgQ00/s=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=crXMAsNPVVOINZV6RE7JNZ2yoanJrpfE+2+E4aiunPwTJ2SNFrUemYTY6Q316w6Md 1jnF3dqiWvAHpbasANgk12FWEnY+LdnBeSH9XgEbYAwlFilf+lstaAWgRYJVfBeVA5 89aMbWvgLV3fvhpY2P1x/PUzIEa+cogBoLr3dLa2qhiZy+nN+jFxZ2h39DaF3ouBBQ g4ExZLNNaDkF4EU5xaIzccragTtQpiRIwA/TTPIFeKYNIrCT/BMtCrMkLI4U2RnEz0 fSUhHAzusyDk+Cdv9VbzRSLD/3b1QJ8FeRrbux2PG3Hb0cd59+UZO9umnugVbnp2KY DDyyX33GtvfMg== Subject: Re: [PATCH net v7 6/7] igb: resume the device before changing XDP or XSK settings From: netdev-bot+sashiko@kernel.org To: antonio@mandelbit.com Cc: intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, janislacis06@gmail.com, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, sriram.yagnaraman@ericsson.com, kurt@linutronix.de, maciej.fijalkowski@intel.com, hkallweit1@gmail.com, joe@dama.to, rafael@kernel.org, sven.auhagen@voleatech.de, netdev@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org Date: Thu, 03 Dec 2026 01:04:15 +0000 Message-ID: <179625985576.3146.4302216571406577976@kernel.org> In-Reply-To: <20261202002317.3140591-7-antonio@mandelbit.com> References: <20261202002317.3140591-7-antonio@mandelbit.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider. Critical: 0 · High: 3 · Medium: 1 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [High] The new guards in igb_xsk_pool_enable() and igb_xsk_pool_disable() (drivers/net/ethernet/intel/igb/igb_xsk.c) use… - [High] igb_xdp_setup() makes its close/open decision from one read of netif_device_present() under RTNL. - [High] The new "only update the software state" path for a detached device in igb_xdp_setup() can lead to an out-of-bounds write in… - [Medium] igb_xdp() now calls pm_runtime_get_sync() first. - [Low] The new comment in igb_xdp() says that if resuming fails, igb_xdp_setup() and igb_xsk_pool_setup() "find the device down". -- igb: resume the device before changing XDP or XSK settings This patch holds a runtime PM reference for the whole of igb_xdp(). That stops __igb_resume() from rebuilding the rings while XDP or XSK setup is running. It also skips or refuses XSK ring changes when the rings have no descriptors after a failed resume, makes igb_xdp_setup() update only the software state on a detached device, and checks the Rx buffer size only when a program is added or replaced. > diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c > index 11c136d7bea75..a6fa33cb4521a 100644 > --- a/drivers/net/ethernet/intel/igb/igb_main.c > +++ b/drivers/net/ethernet/intel/igb/igb_main.c > @@ -2896,8 +2896,17 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf) > bool running = netif_running(dev); > bool need_reset; > > - /* verify igb ring attributes are sufficient for XDP */ > - for (i = 0; i < adapter->num_rx_queues; i++) { > + /* igb_close() doesn't close a detached device (after a failed resume, > + * or during PCI error recovery): only update the software state > + */ > + if (!netif_device_present(dev)) > + running = false; [Severity: High] Can this netif_device_present() check race with PCI error recovery? The PCI error handlers change the present bit outside RTNL: igb_io_error_detected() { netif_device_detach(netdev); ... rtnl_lock(); if (netif_running(netdev)) igb_down(adapter); rtnl_unlock(); ... } igb_io_resume() { rtnl_lock(); ... if (igb_up(adapter)) { ... rtnl_unlock(); netif_device_attach(netdev); ... } igb_close() also reads the bit again on its own: int igb_close(struct net_device *netdev) { if (netif_device_present(netdev) || netdev->dismantle) return __igb_close(netdev, false); return 0; } Suppose igb_xdp_setup() sees the device as present with need_reset true, and igb_io_error_detected() then detaches it. igb_close() returns 0 without closing, and igb_xdp_setup() still calls igb_open() on an interface that is already open. Isn't that the double open the commit message says is fixed? The reverse case can happen too. An ndo_bpf caller waiting on RTNL while igb_io_resume() runs igb_up() can get the lock before netif_device_attach() runs. It then sees !present, sets running to false and only xchg()s ring->xdp_prog. If a program is removed this way while a zero-copy pool is bound, the ring stays in ZC mode and ring->xdp_prog becomes NULL: igb_clean_rx_irq_zc() { ... /* xdp_prog cannot be NULL in the ZC path */ xdp_prog = READ_ONCE(rx_ring->xdp_prog); ... } Would igb_run_xdp_zc() then call bpf_prog_run_xdp() with a NULL prog from NAPI? [Severity: High] Can this software-only path leave the Rx rings with the wrong rx_buffer_info layout? With an XDP program attached and a zero-copy pool bound, igb_xsk_pool_enable()->igb_realloc_rx_buffer_info(rx_ring, true) sizes the array for ZC: int size = pool_present ? sizeof(*ring->rx_buffer_info_zc) * ring->count : sizeof(*ring->rx_buffer_info) * ring->count; Then a PCI error hits. igb_io_error_detected() detaches the device and calls igb_down(), which keeps the ring resources. If the XDP program is removed before igb_io_resume(), this path only clears adapter->xdp_prog and ring->xdp_prog. Nothing calls igb_realloc_rx_buffer_info(ring, false). Later, igb_io_resume()->igb_up()->igb_configure()->igb_configure_rx()-> igb_configure_rx_ring() finds no pool, because igb_xsk_pool() returns NULL once XDP is disabled: else memset(ring->rx_buffer_info, 0, sizeof(*ring->rx_buffer_info) * ring->count); Don't this memset() and the igb_alloc_rx_buffers() call that follows write struct igb_rx_buffer entries past the end of the 8-byte-per-entry ZC allocation? Before this patch, this case went through igb_open()-> igb_setup_rx_resources(), which allocated a full-size igb_rx_buffer array. > + > + /* verify igb ring attributes are sufficient for XDP, only when adding > + * or replacing a program: rings allocated by a resume don't know their > + * buffer size until they are configured > + */ > + for (i = 0; prog && i < adapter->num_rx_queues; i++) { > struct igb_ring *ring = adapter->rx_ring[i]; > > if (frame_size > igb_rx_bufsz(ring)) { [Severity: Medium] igb_xdp() now calls pm_runtime_get_sync() first. With that, can this check refuse a valid attach on a down interface? On a down, runtime suspended interface, __igb_resume()-> igb_init_interrupt_scheme() allocates fresh rings. netif_running() is false, so igb_set_rx_buffer_len() never runs for them. Neither IGB_RING_FLAG_RX_3K_BUFFER nor IGB_RING_FLAG_RX_BUILD_SKB_ENABLED gets set, and igb_rx_bufsz() returns IGB_RXBUFFER_2048. At open, igb_set_rx_buffer_len() would have chosen 3K buffers: if (adapter->max_frame_size > IGB_MAX_FRAME_BUILD_SKB || IGB_2K_TOO_SMALL_WITH_PADDING || rd32(E1000_RCTL) & E1000_RCTL_SBP) set_ring_uses_large_buffer(rx_ring); So with PAGE_SIZE < 8192 and an MTU between 2023 and 3046, adding a program now fails with "The RX buffer size is too small for the frame size". Before this patch, runtime suspend had freed the rings and num_rx_queues was 0 at this point, so the attach succeeded. The new comment says rings allocated by a resume don't know their buffer size, yet the check is skipped only for removal. Should it also be skipped for rings that haven't been configured yet? > @@ -2943,16 +2952,29 @@ 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. If resuming fails, igb_xdp_setup() and > + * igb_xsk_pool_setup() find the device down. > + */ > + pm_runtime_get_sync(&adapter->pdev->dev); [Severity: Low] Is "find the device down" accurate here? When __igb_open() fails inside __igb_resume(), nothing clears __LINK_STATE_START, so netif_running() is still true. The device is only not attached, and its rings have no resources. The new checks depend on exactly that state: netif_running() && !rx_ring[qid]->desc in igb_xsk_pool_enable(), and netif_device_present() in igb_xdp_setup(). Could the comment say that the device is detached but still running? [ ... ] > diff --git a/drivers/net/ethernet/intel/igb/igb_xsk.c b/drivers/net/ethernet/intel/igb/igb_xsk.c > index b6234e349ef20..e70f8184debe6 100644 > --- a/drivers/net/ethernet/intel/igb/igb_xsk.c > +++ b/drivers/net/ethernet/intel/igb/igb_xsk.c > @@ -120,6 +120,10 @@ static int igb_xsk_pool_enable(struct igb_adapter *adapter, > qid >= netdev->real_num_tx_queues) > return -EINVAL; > > + /* After a failed resume the rings have no resources */ > + if (netif_running(netdev) && !adapter->rx_ring[qid]->desc) > + return -ENODEV; > + > err = xsk_pool_dma_map(pool, &adapter->pdev->dev, IGB_RX_DMA_ATTR); > if (err) > return err; > @@ -160,11 +164,11 @@ static int igb_xsk_pool_disable(struct igb_adapter *adapter, u16 qid) > rx_ring = adapter->rx_ring[qid]; > /* The stack can know more queues than the device has, e.g. while > * runtime suspended, which frees the rings: skip the rings it > - * doesn't have. > + * doesn't have, or that have no resources after a failed resume. > */ > if_running = netif_running(adapter->netdev) && > igb_xdp_is_enabled(adapter) && > - qid < adapter->num_rx_queues; > + qid < adapter->num_rx_queues && rx_ring->desc; > if (if_running) > igb_txrx_ring_disable(adapter, qid); [Severity: High] Does the rx_ring->desc check cover PCI error recovery? igb_io_error_detected() detaches the device and calls igb_down(), which disables every NAPI: for (i = 0; i < adapter->num_q_vectors; i++) { if (adapter->q_vector[i]) { napi_disable(&adapter->q_vector[i]->napi); igb_down() doesn't free the descriptor rings, though, and netif_running() stays true. Now suppose a zero-copy AF_XDP socket is closed, or a new one is bound, while an XDP program is attached. if_running is true here in igb_xsk_pool_disable(), and the new !desc test in igb_xsk_pool_enable() passes as well. Both paths then reach igb_txrx_ring_disable(): /* Rx/Tx share the same napi context. */ napi_disable(&rx_ring->q_vector->napi); Won't this second napi_disable() spin forever in napi_disable_locked() with RTNL held? igb_io_resume() also takes rtnl_lock(), so recovery would hang as well. igb_xdp_setup() handles the detached case with netif_device_present(). Would netif_device_present() or test_bit(__IGB_DOWN, &adapter->state) be a better gate here than rx_ring->desc? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202002317.3140591-1-antonio%40mandelbit.com