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=1796163643; b=LIN7iwG2BzJP1rvQzHi6g5V+LA6zmsu6aIKwN1ElcN80ye97TEReXdDJ0RY3f4oo1Gvj RyxfRk2/Q1/5Piov/9Py9Y1qaXT0FO6S+kq55U33eKg101j+sVYDgUNsUQ+DyyO5qgSmI ZgZlN6wWSFcGUNr0O3NYWl2QRdOk1vB8VRBgQLDThjJyPx9Q5ua63HKip6lyiDDDkW8YB tKjRuVv5HmC8R5j4juVC52PbdBXBBn8TyLn+uo7svgi1wxuOp+I4vyglKxlArqQ2Y7lrr HrThcxtL2SjvfXwZaDN1LrVF4sxsxkXYGEgJMFfh/40MrAtu3/mpfIzcZlYCTrUmRHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796163643; 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=I6v778FizIMIkBGq+Pdb9+nB6a5TLqDPbk69RnP9/4U=; b=4eIZJbGoniDMHsIoOeC1QWvVItGbuF5MvuvPfmbt8BVqOICR2/WQSkopipD9c3t0P7uo M5LDpXTP0gjUnW1jd2jl5agaK9LjH/zxp6ONKsde16PGZnfV8zAAtMO4oqxerB9frTcZB 54IlalIOSSozo7ZK0KNxqakowCaqXM6pz1hm8hn099QXI42KyFPvhIiq+xrVX+qos9TL6 +wPj/TGymWhWsHeTpZDoER/ob9xDFna6NsQe3jNtOJYPy6p9zxYM8yWp3wcShmqpa/x6u ohmwIhfUkgBzW7SYtQe1pnyMMBloBxM51XSqgNFGH4K3bZHXxVbuquLIqmzT/9FtULg== 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=ms0xSJcb; 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 581D7606A32D; Tue, 1 Dec 2026 22:20:43 +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=ms0xSJcb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8862D1F00899; Tue, 1 Dec 2026 22:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796163642; bh=I6v778FizIMIkBGq+Pdb9+nB6a5TLqDPbk69RnP9/4U=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ms0xSJcbzaa2qXhnP69IL72wJIvzq+a2s6Ua/uVsChS2Cu/vsti9DrU2NUA12H3Mg ImX2xZogr7Zns+YV4ehJ3c4uhBTkjBCvQPVEQXB/UI5OWXKpw6VwI9uGwRe90Zb/4s dchklnpXaBaQZCnvnWmyAaZnl0Yh1bVGRUnWam38a8Ay8xPG36vUlguHx6hTzBoqXX EyryRfF2TJqtPOTYnomNX+cqPfup6nmP3ooeeoXLXZvQn5hcEvDtZSqvBiVR+ZlJCc GWRr66h71wioMyMD8CcWY3nl1KBnrf2TkmUan8+I8dcDT7dhBcoDrLQ1acTiHEKWy7 mkTzEG3nn6nBw== Subject: Re: [PATCH net v6 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: Tue, 01 Dec 2026 22:20:41 +0000 Message-ID: <179616364113.3146.14418828915964343531@kernel.org> In-Reply-To: <20261130213740.3323814-7-antonio@mandelbit.com> References: <20261130213740.3323814-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 4 potential issue(s) to consider. Critical: 0 · High: 1 (2) · Medium: 3 · Low: 0 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 patch uses `desc != NULL` (plus `!netif_device_present()` in igb_xdp_setup) to decide that the queues are live and the NAPIs… - [Medium] The commit message names the root cause as '__igb_resume() rebuilds the queue counts and the rings without RTNL', but the fix… - [Medium] The patch deliberately ignores the return value of pm_runtime_get_sync() in igb_xdp(). - [Medium] igb: broken failed-resume and 3K-buffer checks in igb_xdp_setup() Pre-existing issues: - [High] This bug predates the patch, but the patch fixes the same bug class for igb_xdp() only. - [High] This bug predates the patch, but the new guard does not cover it. -- igb: resume the device before changing XDP or XSK settings This commit holds a runtime PM reference for the duration of igb_xdp(), so the rings exist while XDP and XSK settings are changed. It also adds checks to igb_xdp_setup(), igb_xsk_pool_enable() and igb_xsk_pool_disable(). These checks leave alone rings that have no resources after a failed resume. > diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c > index 11c136d7bea75..79652ccbfdf00 100644 > --- a/drivers/net/ethernet/intel/igb/igb_main.c > +++ b/drivers/net/ethernet/intel/igb/igb_main.c > @@ -2909,6 +2909,16 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf) > } > } > > + /* After a failed resume the device is detached and its rings have no > + * resources: only update the software state, and don't add a program > + */ > + if (running && !netif_device_present(dev) && > + (!adapter->num_rx_queues || !adapter->rx_ring[0]->desc)) { > + if (prog && !adapter->xdp_prog) > + return -ENODEV; > + running = false; > + } [Severity: Medium] Is this check in the right place, and is running the right condition to gate it on? It only runs when netif_running(dev) is true. __igb_shutdown() calls igb_clear_interrupt_scheme() even when the interface is down, so if the interface is down when __igb_resume() fails, adapter->num_rx_queues is still 0. The frame size loop above then runs zero times and this check is skipped. A new program therefore gets attached to a detached device without any MTU validation. The opposite case is also possible. IGB_RING_FLAG_RX_3K_BUFFER is only set by igb_set_rx_buffer_len() from igb_configure_rx(). It is not set when igb_init_interrupt_scheme() allocates the rings. __igb_resume() reallocates the rings, but it doesn't reach igb_configure() when the interface is down. It also doesn't get there when __igb_open() fails in igb_setup_all_tx_resources() or igb_setup_all_rx_resources(). On PAGE_SIZE < 8192, igb_rx_bufsz() then returns 2048 instead of 3072. With a program attached and an MTU that needs 3K buffers, the frame size loop then returns -EINVAL before this check is reached, even when prog is NULL. Removing or replacing the program fails. dev_xdp_uninstall() ignores that error at unregister time, so the reference held in adapter->xdp_prog is never dropped. Isn't that the leak this check is meant to avoid? The down case can now be hit after a successful resume too. igb_xdp() resumes the device, so the loop no longer sees num_rx_queues == 0. igb_xsk_pool_enable() has a similar gap. Its new check only refuses when netif_running(netdev) is true. If the interface is closed after __igb_open() failed during resume, a pool can still be enabled on a detached device whose rings have no resources. Would it work to do the failed-resume check before the frame size loop, base it on netif_device_present() rather than running, and only validate the ring buffer sizes when a program is being added? Or should the loop compute the buffer size the way igb_set_rx_buffer_len() does, instead of reading ring flags that only igb_configure_rx() sets? [Severity: High] Does this guard cover a device that PCI error recovery has detached? igb_io_error_detected() detaches the device and calls igb_down(), but it leaves the rings and IRQs allocated: igb_io_error_detected() { ... netif_device_detach(netdev); if (state == pci_channel_io_perm_failure) return PCI_ERS_RESULT_DISCONNECT; rtnl_lock(); if (netif_running(netdev)) igb_down(adapter); rtnl_unlock(); pci_disable_device(pdev); ... } In that state the device is RPM_ACTIVE, so pm_runtime_get_sync() returns immediately. rx_ring[0]->desc is non-NULL, so running stays true. When a program is added or removed, igb_close() does nothing because the device isn't present: int igb_close(struct net_device *netdev) { if (netif_device_present(netdev) || netdev->dismantle) return __igb_close(netdev, false); return 0; } igb_open() then runs __igb_open() a second time on live rings. Isn't this the same double open the commit message describes? The second open overwrites and leaks the descriptor DMA memory and buffer_info. With MSI-X, igb_request_msix() fails because the vectors are still requested. The fallback in igb_request_irq() then calls igb_clear_interrupt_scheme(). That frees q_vectors that the registered ring IRQ handlers still use as dev_id. The error path leaves tx_buffer_info and desc NULL and ring->dma stale, and igb_xdp_setup() still returns 0. Later, igb_io_resume()->igb_up()->igb_configure_tx_ring() writes the stale dma into TDBAL/TDBAH and calls memset() on the NULL tx_buffer_info with RTNL held. The new XSK checks have the same gap. In igb_xsk_pool_disable(), and in igb_xsk_pool_enable() when XDP is enabled, the desc test passes: if_running = netif_running(adapter->netdev) && igb_xdp_is_enabled(adapter) && qid < adapter->num_rx_queues && rx_ring->desc; igb_txrx_ring_disable() then calls napi_disable() on a NAPI that igb_down() already disabled. Wouldn't that wait forever with RTNL held? igb_down() sets __IGB_DOWN on both the failed-resume path and the AER path. Would testing __IGB_DOWN cover this case? Always skipping the close/open pair on a detached device might also work. [Severity: High] This is a pre-existing issue, but this guard also requires !netif_device_present(). Because of that, it doesn't catch the state left when the igb_open() call at the end of igb_xdp_setup() fails: if (running) igb_open(dev); return 0; __igb_open() can fail in igb_setup_all_tx_resources(), igb_setup_all_rx_resources() or igb_request_irq(). Its error path frees the rings, so desc becomes NULL, and it returns before napi_enable(). The interface stays IFF_UP and present, and the NAPIs stay disabled from the earlier igb_down(). On the next program add or remove, running and need_reset are both true, and igb_close()->__igb_close()->igb_down() calls napi_disable() on the already disabled NAPIs. Can napi_disable_locked() then loop forever on NAPIF_STATE_SCHED with RTNL held? "ip link set down" looks like it would hang the same way. The new XSK checks treat netif_running() && !desc as "no resources" no matter whether the device is present. Should igb_xdp_setup() match them? Should the igb_open() error also be returned to the caller? > + > old_prog = xchg(&adapter->xdp_prog, prog); > need_reset = (!!prog != !!old_prog); [ ... ] > @@ -2943,16 +2953,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: Medium] The commit message gives the cause as "__igb_resume() rebuilds the queue counts and the rings without RTNL". Does pm_runtime_get_sync() also serialise against system resume? On system resume, igb_resume()->__igb_resume(dev, false) still rebuilds the rings before it takes RTNL: if (igb_init_interrupt_scheme(adapter, true)) { ... if (!rpm) rtnl_lock(); igb_set_interrupt_capability() sets adapter->num_rx_queues before igb_alloc_q_vectors() fills adapter->rx_ring[]. The device is RPM_ACTIVE at that point, so pm_runtime_get_sync() returns 1 immediately. Kernel contexts that aren't frozen can still call ndo_bpf under RTNL in that window. One example is xp_release_deferred() on system_wq, which does rtnl_lock() and then xp_clear_dev(). Could such a caller see num_rx_queues > 0 while rx_ring[qid] is still NULL? It would then dereference NULL through rx_ring->desc in igb_xsk_pool_disable(), or through igb_rx_bufsz(ring) and adapter->rx_ring[0]->desc in igb_xdp_setup(). [Severity: Medium] The return value of pm_runtime_get_sync() is ignored because, after a failed resume, the callees "find the device down". Does that state stay the same for the rest of igb_xdp()? __igb_resume() can fail with -EBUSY or -EAGAIN, for example from the shared legacy request_irq() fallback in igb_request_irq(). rpm_callback() treats those errors as transient, and the device goes back to RPM_SUSPENDED. The usage count held by igb_xdp() doesn't stop another rpm_resume() from a context that doesn't take RTNL, such as writing "on" to power/control or igb_rpm_retry_task(). That resume runs igb_runtime_resume()->__igb_resume(dev, true) without RTNL. It re-runs igb_init_interrupt_scheme(), allocates desc and enables NAPI. Meanwhile igb_xdp_setup() or igb_xsk_pool_*() read num_rx_queues, rx_ring[] and desc without a lock. Could the "no resources, don't touch NAPI" decision go stale here? Ring memory could also be reinitialised under the reader, or program updates could land on rings that are being replaced. [Severity: High] This isn't a bug introduced by this patch, but igb_xdp() is the only ndo that this patch resumes. Do igb_change_mtu() and igb_set_features()->igb_reinit_locked()/igb_reset() have the same problem on a runtime suspended device? While the device is runtime suspended, igb_free_q_vectors() has set num_rx_queues, num_tx_queues and num_q_vectors to 0 and cleared adapter->q_vector[]. netif_running() is still true. In igb_change_mtu(): if (igb_xdp_is_enabled(adapter)) { int i; for (i = 0; i < adapter->num_rx_queues; i++) { ... if (netif_running(netdev)) igb_down(adapter); ... if (netif_running(netdev)) igb_up(adapter); The XDP frame size loop runs zero times, so igb_change_mtu() accepts an MTU that igb_xdp_setup() would reject. Without MSI-X, igb_up() calls igb_assign_vector(adapter->q_vector[0], 0) with a NULL q_vector. Is that a NULL dereference with RTNL held? With MSI-X, igb_up() clears __IGB_DOWN while num_tx_queues is 0. igb_xdp_xmit() only checks __IGB_DOWN before it calls igb_xdp_tx_queue_mapping(): if (r_idx >= adapter->num_tx_queues) r_idx = r_idx % adapter->num_tx_queues; Can an XDP_REDIRECT into igb then divide by zero? igb_down() also reads the registers of a device in D3. If those reads return all-ones, igb_rd32() sets hw->hw_addr to NULL and warns. __igb_resume() never restores hw_addr, so the NIC looks like it stays unusable until the driver is reloaded. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130213740.3323814-1-antonio%40mandelbit.com