Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 (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). - [Medium] Now that this patch makes back-to-back sxgbe_release()/sxgbe_open() succeed, for example from… - [Low] The commit message leaves out two user-visible effects of the devm IRQ leak that this patch fixes. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but sxgbe_change_mtu() (sxgbe_main.c:1836-1837) calls sxgbe_release(dev)… - [High] This problem wasn't introduced by this patch, but sxgbe_poll_controller() (sxgbe_main.c:1941-1948, wired as… - [High] This problem wasn't introduced by this patch, but sxgbe_release() (sxgbe_main.c:1218-1219) calls… -- net: sxgbe: free the interrupts in sxgbe_release() This patch converts the IRQ requests in sxgbe_open() from devm_request_irq() to request_irq(). It frees the common, LPI, TX queue and RX queue interrupts in sxgbe_release() and on the sxgbe_open() error path, so that the interface can be brought up again after being stopped.
> The handlers stay installed after the interface is stopped, and the > next sxgbe_open() fails with -EBUSY on the first TX queue interrupt, > which is not shared. The interface cannot be brought up again until > the driver is rebound.
[Severity: Low] Could the commit message also mention two other effects of the leaked devm IRQs that this patch fixes? The first is MTU changes. sxgbe_change_mtu() does this on a running interface: sxgbe_release(dev); return sxgbe_open(dev); Before this patch the reopen always failed with -EBUSY, so every MTU change on a running interface failed. The netdev was then left marked running with the PHY disconnected, the DMA rings freed, NAPI disabled and the clock gated. The second is unbind. sxgbe_drv_remove() calls unregister_netdev() and then free_netdev(ndev), but the devm IRQ actions are only released after remove() returns. Until then sxgbe_common_interrupt() was still registered on the IRQF_SHARED common and LPI lines, with dev_id pointing at the freed net_device. With CONFIG_DEBUG_SHIRQ, __free_irq() calls shared handlers once on free, which makes this use-after-free deterministic. Would stable backporters want both of these described?
> diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c > index f2fecc3bcea12..4a7d149149ad8 100644 > --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c > +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
[ ... ]
> @@ -1112,39 +1112,36 @@ static int sxgbe_open(struct net_device *dev)
[ ... ]
> /* Request RX DMA irq lines */ > SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) { > - ret = devm_request_irq(priv->device, > - (priv->rxq[queue_num])->irq_no, > - sxgbe_rx_interrupt, 0, > - dev->name, priv->rxq[queue_num]); > + ret = request_irq((priv->rxq[queue_num])->irq_no, > + sxgbe_rx_interrupt, 0, > + dev->name, priv->rxq[queue_num]);
[Severity: High] This is a pre-existing issue, but the RX handler is registered here with priv->rxq[queue_num] as dev_id. sxgbe_poll_controller() calls the same handler with the net_device instead: drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c:sxgbe_poll_controller() { ... disable_irq(priv->irq); sxgbe_rx_interrupt(priv->irq, dev); enable_irq(priv->irq); } sxgbe_rx_interrupt() casts dev_id back to a queue and then dereferences priv->hw: struct sxgbe_rx_queue *rxq = (struct sxgbe_rx_queue *)dev_id; struct sxgbe_priv_data *priv = rxq->priv_ptr; priv_ptr is the first member of struct sxgbe_rx_queue, so priv becomes the first word of struct net_device (the priv_flags_fast bitfields). Can this oops when netconsole is bound to an sxgbe interface and the TX queue is busy? __netpoll_send_skb() netpoll_poll_dev() ndo_poll_controller() sxgbe_poll_controller() sxgbe_rx_interrupt(priv->irq, dev) Two related points: - sxgbe_poll_controller() disables priv->irq, the common line, not an RX line. - The kernel-doc for sxgbe_tx_interrupt() and sxgbe_rx_interrupt() says "@dev_id: to pass the net device pointer". That matches neither the registration nor the casts. This patch rewrites the request_irq() calls that define the dev_id contract. Should sxgbe_poll_controller() be updated to match? [ ... ]
> @@ -1205,6 +1213,7 @@ static int sxgbe_open(struct net_device *dev) > static int sxgbe_release(struct net_device *dev) > { > struct sxgbe_priv_data *priv = netdev_priv(dev); > + int queue_num; > > if (priv->eee_enabled) > timer_delete_sync(&priv->eee_ctrl_timer);
[Severity: High] This isn't a bug introduced by this patch, but the EEE timer is deleted before phy_stop(), phy_disconnect() and napi_disable(). At that point the RX and TX handlers are still installed and NAPI is still enabled. Can an RX or TX interrupt in that window re-arm the timer? sxgbe_poll() calls sxgbe_tx_all_clean(), which does: if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { sxgbe_enable_eee_mode(priv); mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); } sxgbe_eee_ctrl_timer() also re-arms itself unconditionally: sxgbe_enable_eee_mode(priv); mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); Once re-armed, the timer keeps running after close and accesses priv->ioaddr after clk_disable_unprepare(). That leads to two further problems: - On the next sxgbe_open() (or ethtool set_eee), sxgbe_eee_init() calls timer_setup() and add_timer() on the still-pending timer. That would corrupt the timer wheel. - On unbind, sxgbe_drv_remove() calls free_netdev() while the timer is still pending. Before this patch, reopen failed at the TX request_irq() before it reached sxgbe_eee_init(). Now reopen succeeds, so sxgbe_open() is a new way to call timer_setup() on a pending timer. Would it be better to stop the timer with timer_shutdown_sync() or timer_delete_sync() after napi_disable() and after the IRQs are freed?
> @@ -1229,6 +1238,15 @@ static int sxgbe_release(struct net_device *dev) > /* disable MTL queue */ > sxgbe_disable_mtl_engine(priv); > > + /* Free the IRQ lines */ > + SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) > + free_irq(priv->rxq[queue_num]->irq_no, priv->rxq[queue_num]); > + SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) > + free_irq(priv->txq[queue_num]->irq_no, priv->txq[queue_num]); > + if (priv->lpi_irq != dev->irq) > + free_irq(priv->lpi_irq, dev); > + free_irq(priv->irq, dev);
[Severity: Medium] sxgbe_release() followed directly by sxgbe_open() now succeeds, for example from sxgbe_change_mtu(). Does anything clear the DMA channel interrupt state between the two calls? The channel IRQs are freed here after stop_tx() and stop_rx(), without masking SXGBE_DMA_CHA_INT_ENABLE_REG or clearing SXGBE_DMA_CHA_STATUS_REG. SXGBE_DMA_ENA_INT includes TSE/RSE (transmit and receive stopped). sxgbe_open() does no DMA soft reset; sxgbe_sw_reset() is only called from sxgbe_drv_probe(). It also rewrites the enable register before any request_irq(): sxgbe_open() sxgbe_init_dma_engine() sxgbe_dma_channel_init() writel(SXGBE_DMA_ENA_INT, ioaddr + SXGBE_DMA_CHA_INT_ENABLE_REG(cha_num)); Suppose a TPS status latches after the TX free_irq() here. The TX request_irq() in the next sxgbe_open() would then unmask a pending source. sxgbe_tx_interrupt() would decode TPS as tx_hard_error and call sxgbe_restart_tx_queue(). That starts the TX queue DMA, increments tx_errors and wakes the queue. All of this would happen before sxgbe_mtl_operation_mode(), start_tx(), the MAC TX enable and napi_enable(). If a later RX request_irq() then fails, the new rx_irq_error and tx_irq_error unwind frees the descriptor rings but does not stop the TX DMA that the handler re-enabled. Could that leave the channel enabled with its descriptor registers pointing at freed memory? Whether the hardware can latch TPS after the TX handler is removed depends on DMA stop timing.
> + > /* Release and free the Rx/Tx resources */ > free_dma_desc_resources(priv);
[Severity: High] This is a pre-existing issue, but what happens in sxgbe_change_mtu() if the reopen fails? sxgbe_release(dev); return sxgbe_open(dev); sxgbe_release() calls napi_disable(). Every failure path in sxgbe_open() returns before napi_enable(): - init_dma_desc_rings() failure - sxgbe_init_phy() failure - any request_irq() failure, through the new labels Those paths free the DMA rings, IRQs and PHY and gate the clock, but the netdev stays netif_running(). The next ndo_stop (ifdown or unregister) calls sxgbe_release() again: dev_close() sxgbe_release() napi_disable() napi_disable_locked() while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) { usleep_range(20, 200); val = READ_ONCE(n->state); } The first napi_disable() left both bits set. Can this loop forever while rtnl and the netdev instance lock are held? Even without the hang, sxgbe_release() would go on to call the newly added free_irq() on IRQs that are already freed, and free_dma_desc_resources() on rings that are already freed. Before this patch, any MTU change on a running interface followed by ifdown hit this, because the reopen always failed with -EBUSY. With this patch it only happens when sxgbe_open() fails inside sxgbe_change_mtu().
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40mbzuai.ac.ae