Skip to content

net: macb: fix close races (and RX refill error handling)

Théo Lebrun lkml netdev stable 3 versions – Applied

Status from this message: This series was applied to netdev/net-next.git (main)

Get series with b4
b4 am [email protected] change-id 20260918-macb-close-dbbd23b4b8f2

Versions newest first

  1. v2 Latest3 patches 2 repliesApplied 3/3
  2. v1 posting 2/23 patches 7 repliesSuperseded
  3. v1 posting 1/23 patches 4 repliesSuperseded

Changes in v2 from the cover letter

- P1: ensure gem_rx() and macb_rx_pending() don't consume the
descriptors where alloc failed.
- P2: gem_rx_refill() now only propagates an error if zero descriptors
are ready. We tolerate partial refill hoping the next one will help.
- P2: we do *NOT* fix the set_ringparam codepath reported by Sashiko. Proper implementation will come with context swapping which will
reuse the infra put in place in P3.
- P3: the hresp_err_bh_work/tx_lpi_work Sashiko-reported race has been fixed in a standalone, *NOT* here.
https://lore.kernel.org/netdev/[email protected]/
- Take 2x Reviewed-by: Nicolai.
- Rebase onto latest net/main (11536ee3d3e0), nothing to report.
- Link to v1: https://patch.msgid.link/[email protected]
- Nicolai's v1 reviews (duplicate thread):
https://patch.msgid.link/[email protected]

Patches in v2 All 3 applied

#Subject and filesSizeRepliesApplied
1/3net: macb: never give hardware a NULL RX bufferdrivers/net/ethernet/cadence/macb_main.c+16 -01 replyApplied
2/3net: macb: propagate RX ring refill errorsdrivers/net/ethernet/cadence/macb.h drivers/net/ethernet/cadence/macb_main.c+27 -81 replyApplied
3/3net: macb: quiesce IRQs and drain BH on interface closedrivers/net/ethernet/cadence/macb.h drivers/net/ethernet/cadence/macb_main.c+69 -200 repliesApplied

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchNicolai Buchwitz
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH net v2 0/3] net: macb: fix close races (and RX refill error handling)

The context-swapping series [0] has been ongoing for a while. The most interesting part is a proper hardware shutdown sequence, which is truly lacking in other parts of the MACB driver: at close, at suspend and in the HRESP error task.

Instead of introducing that sequence for a new feature, apply it now to fix the main offender, the close path. That fixes the races listed in patch 3 and will allow the sequence to be reused later.

The first two patches are also fixes, but not related to the shutdown
sequence: they address allocation-failure codepaths. They are sent alongside patch 3 because they touch the same code and would cause merge conflicts if applied separately.

Now, let me list issues I'm aware of that we do *not* fix here, to make the scope explicit:
- HRESP task should sync with all other contexts. It frees buffers under the feet of the whole driver. The hardware shutdown sequence will help.
- Suspend callback is also racy with BH primitives. We'll be able to reuse the hardware shutdown sequence.
- Even if we assume tasks are frozen, the phylink ops aren't and might trigger between suspend and resume callbacks. Here we need to
(1) early return in phylink ops and (2) at resume put the HW in its proper state according to phylink ops that occured.
- Alloc failure codepaths aren't perfect outside open. Hardware and ring buffers are left in a sad state. We can probably do better.

[0]: https://lore.kernel.org/all/[email protected]/

---
Changes in v2:
- P1: ensure gem_rx() and macb_rx_pending() don't consume the
descriptors where alloc failed.
- P2: gem_rx_refill() now only propagates an error if zero descriptors
are ready. We tolerate partial refill hoping the next one will help.
- P2: we do *NOT* fix the set_ringparam codepath reported by Sashiko. Proper implementation will come with context swapping which will
reuse the infra put in place in P3.
- P3: the hresp_err_bh_work/tx_lpi_work Sashiko-reported race has been fixed in a standalone, *NOT* here.
https://lore.kernel.org/netdev/[email protected]/
- Take 2x Reviewed-by: Nicolai.
- Rebase onto latest net/main (11536ee3d3e0), nothing to report.
- Link to v1: https://patch.msgid.link/[email protected]
- Nicolai's v1 reviews (duplicate thread):
https://patch.msgid.link/[email protected]

To: Conor Dooley <[email protected]>
To: Andrew Lunn <[email protected]>
To: "David S. Miller" <[email protected]>
To: Jakub Kicinski <[email protected]>
To: Paolo Abeni <[email protected]>
To: Simon Horman <[email protected]>
To: Sean Anderson <[email protected]>
To: Antoine Tenart <[email protected]>
To: Eric Dumazet <[email protected]>
To: Nicolas Ferre <[email protected]>
To: Russell King <[email protected]>

Cc Nicolai Buchwitz <[email protected]>
Cc Vladimir Kondratiev <[email protected]>
Cc Gregory CLEMENT <[email protected]>
Cc Tawfik Bayouk <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Maxime Chevallier <[email protected]>

---
Théo Lebrun (3):
net: macb: never give hardware a NULL RX buffer
net: macb: propagate RX ring refill errors
net: macb: quiesce IRQs and drain BH on interface close

 drivers/net/ethernet/cadence/macb.h      |   7 +-
 drivers/net/ethernet/cadence/macb_main.c | 133 ++++++++++++++++++++++++-------
 2 files changed, 112 insertions(+), 28 deletions(-)

---
base-commit: 7c416e8f8423e6fe9b48e0b9c174bd902789f8db
change-id: 20260918-macb-close-dbbd23b4b8f2

Best regards,

Signature · 1 line
Théo Lebrun <[email protected]>