🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by 题目自拟闯天涯 Fri, 23 Oct 2026 01:44
[BUG] net: stmmac: napi_disable() spins forever on enp2s0 close, deadlocking the whole rtnetlink layer
#6642
Author: 题目自拟闯天涯
Date: Fri, 23 Oct 2026 01:44
202 lines
17772 bytes
Hi Maxime, netdev,

I am hitting a hard machine hang on a Motorcomm YT8531S PHY behind the
dwmac-motorcomm/stmmac glue. The hang is inside napi_disable_locked(),
reached from stmmac_release() while NetworkManager tears the interface
down for a system hibernate. Because napi_disable() runs under
netdev_lock() and the entire call chain is inside rtnetlink context, the
rtnl_mutex is never released, and every netlink operation in the system
ends up blocked in D state. The box can only be recovered with a hard
power cycle.

It is 100% reproducible here as long as enp2s0 is administratively UP at
the moment a hibernate is requested.


Environment
-----------
  Distro : Ubuntu 24.04.4 LTS
  Kernel : 7.0.0-38-generic (Ubuntu 7.0.0-38.38~24.04.4-generic)
  NIC    : Motorcomm, PCI 0000:02:00.0
           dwmac-motorcomm 0000:02:00.0: User ID: 0x10, Synopsys ID: 0x52
           dwmac-motorcomm 0000:02:00.0: DWMAC4/5
           YT8531S Gigabit Ethernet stmmac-200:00
  Driver : st_gmac (stmmac + dwmac_motorcomm)
  Link   : no cable attached, interface still administratively UP
  WoL    : enabled at the time of the bug (ethtool: Wake-on: g)


Reproduction
------------
  ip link set enp2s0 up        # no cable needed
  systemctl hibernate          # NetworkManager stops the device

Result: NetworkManager hangs in stmmac_release -> napi_disable; every
ip/netlink user blocks; hard power-off required.


Hung task dump (live capture)
-----------------------------
  INFO: task Qt bearer threa:4035 blocked for more than 30 seconds.
  task:Qt bearer threa state:D stack:0 pid:4035 tgid:3927
  Call Trace:
   __mutex_lock
   rtnl_dumpit
   netlink_dump
   __netlink_dump_start
   rtnetlink_rcv_msg
   netlink_rcv_skb
   netlink_unicast
   netlink_sendmsg

  INFO: task Qt bearer threa:4035 is blocked on a mutex likely owned by
        task NetworkManager:1414.

  task:NetworkManager state:D stack:0 pid:1414 tgid:1414
  Call Trace:
   __schedule
   schedule
   schedule_hrtimeout_range_clock
   usleep_range_state
   napi_disable_locked+0xe9/0x100
   napi_disable+0x25/0x50
   __stmmac_disable_all_queues+0x96/0x100 [stmmac]
   __stmmac_release+0x83/0x2e0 [stmmac]
   stmmac_release+0x46/0x80 [stmmac]
   __dev_close_many
   __dev_change_flags
   netif_change_flags
   do_setlink
   __rtnl_newlink
   rtnl_newlink
   rtnetlink_rcv_msg
   netlink_rcv_skb
   netlink_unicast
   netlink_sendmsg
   __sys_sendmsg
   __x64_sys_sendmsg
   do_syscall_64


Analysis
--------
napi_disable_locked() has no timeout:

  void napi_disable_locked(struct napi_struct *n)
  {
          set_bit(NAPI_STATE_DISABLE, &n->state);
          val = READ_ONCE(n->state);
          do {
                  while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) {
                          usleep_range(20, 200);
                          val = READ_ONCE(n->state);
                  }
                  new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC;
                  ...
          } while (!try_cmpxchg(&n->state, &val, new));
  }

and napi_complete_done() bails out early without clearing SCHED when
NPSVC is set:

  bool napi_complete_done(struct napi_struct *n, int work_done)
  {
          if (unlikely(n->state & (NAPIF_STATE_NPSVC |
                                   NAPIF_STATE_IN_BUSY_POLL)))
                  return false;
          ...
  }

The call site orders PHY teardown before NAPI teardown:

  static void __stmmac_release(struct net_device *dev)
  {
          /* Stop and disconnect the PHY */
          phylink_stop(priv->phylink);          /* MAC goes down here */

          stmmac_disable_all_queues(priv);      /* -> napi_disable() */

          for (chan = 0; ...) hrtimer_cancel(...);

          netif_tx_disable(dev);

          /* Free the IRQ lines */
          stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
          ...
  }

Between phylink_stop() (which reaches stmmac_mac_link_down() and takes
the MAC down, so no further RX completion interrupts are generated) and
stmmac_free_irq(), there is a window where a NAPI instance can already be
scheduled with nothing left to advance it. napi_disable_locked() then
waits on a bit that nobody will clear.

The same helper is reached from stmmac_suspend():

  int stmmac_suspend(struct device *dev)
  {
          if (!ndev || !netif_running(ndev))
                  goto suspend_bsp;       /* DOWN -> safe */
          ...
          stmmac_disable_all_queues(priv);

so once the interface has been UP at any point, both
`ip link set enp2s0 down` and hibernate can hit this. Keeping the
interface DOWN avoids it entirely, which is consistent with a previous
hibernate on this same machine (with the NIC down) having succeeded.

The escalation to a system-wide deadlock comes from the new locking:

  void napi_disable(struct napi_struct *n)
  {
          netdev_lock(n->dev);
          napi_disable_locked(n);
          netdev_unlock(n->dev);
  }

The caller already holds rtnl_mutex
(rtnl_newlink -> do_setlink -> __dev_close_many -> ndo_stop), so a stuck
napi_disable() pins both locks and takes the whole netlink layer with it.


Workaround currently deployed
-----------------------------
  /etc/NetworkManager/conf.d/99-unmanaged-enp2s0.conf:
    [keyfile]
    unmanaged-devices=interface-name:enp2s0

plus WoL disabled and the interface kept DOWN. With that, hibernate
completes and the deadlock is not reachable.


Suggestion
----------
1) Please consider draining NAPI before tearing down the PHY, e.g.

        netif_tx_disable(dev);
        stmmac_disable_all_queues(priv);
        for (chan = 0; ...) hrtimer_cancel(...);
        phylink_stop(priv->phylink);
        stmmac_free_irq(dev, REQ_IRQ_ERR_ALL, 0);
        stmmac_stop_all_dma(priv);

   (I have not tested this; you know the phylink ordering constraints
   far better than I do.)

2) Independently of the driver, an unbounded wait inside
   napi_disable_locked() with no diagnostic turns a single stuck
   interface into a whole-machine deadlock. Even a WARN + stack dump
   after N seconds would make this class of bug debuggable instead of
   requiring a power cycle.

The full hung task dump (2486 lines, all blocked tasks with complete
call traces) is available on request.


This machine is a disposable test box for this issue and I can reproduce
on demand, run ftrace/kprobe, or test patches.


Thanks,
Lidi Tian
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads