* [PATCH net v2 0/3] net: macb: fix close races (and RX refill error handling)
@ 2026-09-25 13:59 Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 1/3] net: macb: never give hardware a NULL RX buffer Théo Lebrun
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Théo Lebrun @ 2026-09-25 13:59 UTC (permalink / raw)
To: Conor Dooley, Andrew Lunn, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, Sean Anderson, Antoine Tenart,
Eric Dumazet, Nicolas Ferre, Russell King
Cc: netdev, linux-kernel, Nicolai Buchwitz, Vladimir Kondratiev,
Gregory CLEMENT, Tawfik Bayouk, Thomas Petazzoni,
Maxime Chevallier, Théo Lebrun, stable
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/20260812-macb-context-v9-0-7ddbf5f715e0@bootlin.com/
---
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/20260925-macb-netdev-register-race-v1-1-752f90ce1c39@bootlin.com/
- Take 2x Reviewed-by: Nicolai.
- Rebase onto latest net/main (11536ee3d3e0), nothing to report.
- Link to v1: https://patch.msgid.link/20260918-macb-close-v1-0-05e32ce98813@bootlin.com
- Nicolai's v1 reviews (duplicate thread):
https://patch.msgid.link/20260918-macb-close-v1-0-221d916b7961@bootlin.com
To: Conor Dooley <conor.dooley@microchip.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>
To: "David S. Miller" <davem@davemloft.net>
To: Jakub Kicinski <kuba@kernel.org>
To: Paolo Abeni <pabeni@redhat.com>
To: Simon Horman <horms@kernel.org>
To: Sean Anderson <sean.anderson@linux.dev>
To: Antoine Tenart <atenart@kernel.org>
To: Eric Dumazet <edumazet@kernel.org>
To: Nicolas Ferre <nicolas.ferre@microchip.com>
To: Russell King <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: Nicolai Buchwitz <nb@tipi-net.de>
Cc: Vladimir Kondratiev <vladimir.kondratiev@mobileye.com>
Cc: Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: Tawfik Bayouk <tawfik.bayouk@mobileye.com>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
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,
--
Théo Lebrun <theo.lebrun@bootlin.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2 1/3] net: macb: never give hardware a NULL RX buffer
2026-09-25 13:59 [PATCH net v2 0/3] net: macb: fix close races (and RX refill error handling) Théo Lebrun
@ 2026-09-25 13:59 ` Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 2/3] net: macb: propagate RX ring refill errors Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 3/3] net: macb: quiesce IRQs and drain BH on interface close Théo Lebrun
2 siblings, 0 replies; 5+ messages in thread
From: Théo Lebrun @ 2026-09-25 13:59 UTC (permalink / raw)
To: Conor Dooley, Andrew Lunn, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, Sean Anderson, Antoine Tenart,
Eric Dumazet, Nicolas Ferre, Russell King
Cc: netdev, linux-kernel, Nicolai Buchwitz, Vladimir Kondratiev,
Gregory CLEMENT, Tawfik Bayouk, Thomas Petazzoni,
Maxime Chevallier, Théo Lebrun, stable
The refill logic is simple: iterate over all pending rx slots, allocate
SKB (& DMA map) if needed and hand it off to the hardware by clearing
the RX_USED flag.
If the refill operation fails mid-way, it early returns leaving the
remaining slots untouched. In an initialised ring that is safe: a slot
is either owned by the hardware holding a valid buffer, or
software-owned (RX_USED set) waiting for refill to hand it a new one.
When slots have never been initialised however, we are in trouble.
After dma_alloc_coherent() of the rx ring buffer, all slots have NULL
pointers and RX_USED cleared meaning HW will try using them. Ensure
this does not happen by setting the RX_USED flag on all slots before
calling refill at buffer alloc, in gem_init_rx_ring(). That way even if
refill fails on an alloc/dma_map, the HW won't try using NULL pointers
as buffers.
Note we tweak gem_rx() and macb_rx_pending(): their previous stop
condition was only if desc was RX_USED. Now it must be either RX_USED
or we got out of the range of successfully allocated descriptors
(detected using the rx_tail and rx_prepared_head cursors).
Otherwise gem_rx() could consume unallocated buffers.
Theoretical bugfix, never encountered in practice. To reproduce,
introduce memory pressure (less than 512 SKBs of free memory) and open
the interface.
Note that this codepath also hits at resume, on HRESP errors and on
set_ringparam (while interface is running).
Fixes: 4df95131ea80 ("net/macb: change RX path for GEM")
Cc: stable@vger.kernel.org
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb_main.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 8e5c034dc3a4..7f25574928d7 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -1596,6 +1596,13 @@ static int gem_rx(struct macb_queue *queue, struct napi_struct *napi,
dma_addr_t addr;
bool rxused;
+ /* Only descriptors in [rx_tail, rx_prepared_head) were armed
+ * for hardware. Outside, we might have RX_USED descriptors for
+ * alloc failures.
+ */
+ if (queue->rx_tail == queue->rx_prepared_head)
+ break;
+
entry = macb_rx_ring_wrap(bp, queue->rx_tail);
desc = macb_rx_desc(queue, entry);
@@ -1859,6 +1866,10 @@ static bool macb_rx_pending(struct macb_queue *queue)
struct macb_dma_desc *desc;
unsigned int entry;
+ /* No armed descriptor left: nothing can be pending. */
+ if (macb_is_gem(bp) && queue->rx_tail == queue->rx_prepared_head)
+ return false;
+
entry = macb_rx_ring_wrap(bp, queue->rx_tail);
desc = macb_rx_desc(queue, entry);
@@ -2795,9 +2806,14 @@ static int macb_alloc(struct macb *bp)
static void gem_init_rx_ring(struct macb_queue *queue)
{
+ unsigned int i;
+
queue->rx_tail = 0;
queue->rx_prepared_head = 0;
+ for (i = 0; i < queue->bp->rx_ring_size; i++)
+ macb_rx_desc(queue, i)->addr |= MACB_BIT(RX_USED);
+
gem_rx_refill(queue);
}
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2 2/3] net: macb: propagate RX ring refill errors
2026-09-25 13:59 [PATCH net v2 0/3] net: macb: fix close races (and RX refill error handling) Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 1/3] net: macb: never give hardware a NULL RX buffer Théo Lebrun
@ 2026-09-25 13:59 ` Théo Lebrun
2026-09-25 14:20 ` Nicolai Buchwitz
2026-09-25 13:59 ` [PATCH net v2 3/3] net: macb: quiesce IRQs and drain BH on interface close Théo Lebrun
2 siblings, 1 reply; 5+ messages in thread
From: Théo Lebrun @ 2026-09-25 13:59 UTC (permalink / raw)
To: Conor Dooley, Andrew Lunn, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, Sean Anderson, Antoine Tenart,
Eric Dumazet, Nicolas Ferre, Russell King
Cc: netdev, linux-kernel, Nicolai Buchwitz, Vladimir Kondratiev,
Gregory CLEMENT, Tawfik Bayouk, Thomas Petazzoni,
Maxime Chevallier, Théo Lebrun, stable
gem_rx_refill() is responsible for Rx SKB allocation, including at open,
but its prototype indicates a void return value.
Therefore we change the code to propagate allocation and DMA mapping
errors back up the stack, making sure the open fails if no descriptors
were allocated. Change all those to return errno-style ints:
- gem_rx_refill()
- its parent gem_init_rx_ring()
- its grand-parent gem_init_rings()
- the macbgem_ops.mog_init_rings function pointer
- its grand-uncle macb_init_rings()
We tolerate some allocation failures: we accept running with the rx ring
only partially filled with successful descriptors. It is important we
refuse the zero-valid-descriptor case: nothing would ever trigger a
refill, which only happens once a frame has been received.
Theoretical bugfix, never encountered in practice. To reproduce,
introduce memory pressure (less than 512 SKBs of free memory) and open
the interface. I expect the last queue to be unusable because it has
zero usable rx buffers.
Note that other callers of refill (resume, HRESP error task, NAPI)
cannot do anything useful with that error and keep their best-effort
refill, hoping it will improve.
Fixes: 4df95131ea80 ("net/macb: change RX path for GEM")
Cc: stable@vger.kernel.org
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb.h | 2 +-
drivers/net/ethernet/cadence/macb_main.c | 33 +++++++++++++++++++++++++-------
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index d6931c41f39d..cfaa0ca49f1a 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -1197,7 +1197,7 @@ struct macb_queue;
struct macb_or_gem_ops {
int (*mog_alloc_rx_buffers)(struct macb *bp);
void (*mog_free_rx_buffers)(struct macb *bp);
- void (*mog_init_rings)(struct macb *bp);
+ int (*mog_init_rings)(struct macb *bp);
int (*mog_rx)(struct macb_queue *queue, struct napi_struct *napi,
int budget);
};
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 7f25574928d7..18a1b5f7ad91 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -1486,7 +1486,7 @@ static int macb_tx_complete(struct macb_queue *queue, int budget)
return packets;
}
-static void gem_rx_refill(struct macb_queue *queue)
+static int gem_rx_refill(struct macb_queue *queue)
{
struct macb *bp = queue->bp;
struct macb_dma_desc *desc;
@@ -1558,6 +1558,14 @@ static void gem_rx_refill(struct macb_queue *queue)
netdev_vdbg(bp->netdev, "rx ring: queue: %p, prepared head %d, tail %d\n",
queue, queue->rx_prepared_head, queue->rx_tail);
+
+ /* Fail if queue has zero prepared descriptors. This is critical because
+ * nothing will ever trigger a refill again.
+ */
+ if (queue->rx_prepared_head == queue->rx_tail)
+ return -ENOMEM;
+
+ return 0;
}
/* Mark DMA descriptors from begin up to and not including end as unused */
@@ -2804,7 +2812,7 @@ static int macb_alloc(struct macb *bp)
return -ENOMEM;
}
-static void gem_init_rx_ring(struct macb_queue *queue)
+static int gem_init_rx_ring(struct macb_queue *queue)
{
unsigned int i;
@@ -2814,14 +2822,16 @@ static void gem_init_rx_ring(struct macb_queue *queue)
for (i = 0; i < queue->bp->rx_ring_size; i++)
macb_rx_desc(queue, i)->addr |= MACB_BIT(RX_USED);
- gem_rx_refill(queue);
+ return gem_rx_refill(queue);
}
-static void gem_init_rings(struct macb *bp)
+static int gem_init_rings(struct macb *bp)
{
struct macb_queue *queue;
struct macb_dma_desc *desc = NULL;
+ int last_err = 0;
unsigned int q;
+ int err;
int i;
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
@@ -2834,11 +2844,15 @@ static void gem_init_rings(struct macb *bp)
queue->tx_head = 0;
queue->tx_tail = 0;
- gem_init_rx_ring(queue);
+ err = gem_init_rx_ring(queue);
+ if (err)
+ last_err = err;
}
+
+ return last_err;
}
-static void macb_init_rings(struct macb *bp)
+static int macb_init_rings(struct macb *bp)
{
int i;
struct macb_dma_desc *desc = NULL;
@@ -2853,6 +2867,8 @@ static void macb_init_rings(struct macb *bp)
bp->queues[0].tx_head = 0;
bp->queues[0].tx_tail = 0;
desc->ctrl |= MACB_BIT(TX_WRAP);
+
+ return 0;
}
static void macb_reset_hw(struct macb *bp)
@@ -3183,7 +3199,9 @@ static int macb_open(struct net_device *netdev)
goto pm_exit;
}
- bp->macbgem_ops.mog_init_rings(bp);
+ err = bp->macbgem_ops.mog_init_rings(bp);
+ if (err)
+ goto free_rings;
macb_init_buffers(bp);
for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
@@ -3221,6 +3239,7 @@ static int macb_open(struct net_device *netdev)
napi_disable(&queue->napi_rx);
napi_disable(&queue->napi_tx);
}
+free_rings:
macb_free(bp);
pm_exit:
pm_runtime_put_sync(&bp->pdev->dev);
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2 3/3] net: macb: quiesce IRQs and drain BH on interface close
2026-09-25 13:59 [PATCH net v2 0/3] net: macb: fix close races (and RX refill error handling) Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 1/3] net: macb: never give hardware a NULL RX buffer Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 2/3] net: macb: propagate RX ring refill errors Théo Lebrun
@ 2026-09-25 13:59 ` Théo Lebrun
2 siblings, 0 replies; 5+ messages in thread
From: Théo Lebrun @ 2026-09-25 13:59 UTC (permalink / raw)
To: Conor Dooley, Andrew Lunn, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, Sean Anderson, Antoine Tenart,
Eric Dumazet, Nicolas Ferre, Russell King
Cc: netdev, linux-kernel, Nicolai Buchwitz, Vladimir Kondratiev,
Gregory CLEMENT, Tawfik Bayouk, Thomas Petazzoni,
Maxime Chevallier, Théo Lebrun, stable
The macb_close() operation is facing races as it disables IRQs late in
its sequence and keeps BH primitives alive while shutdown.
Non exhaustive list of races that could occur:
- macb_tx_error_task() could be scheduled and access the buffers freed
by macb_close().
- macb_tx_error_task() or macb_hresp_error_task() might re-enable
interrupts after the IDR write in macb_close().
- macb_close() calls napi_disable() meaning that if
macb_tx_error_task() occurs later, it will deadlock on napi_disable()
that shouldn't be called if NAPI is already disabled.
- macb_hresp_error_task() might reinit every RX/TX ring under
macb_close()'s foot.
- macb_interrupt() might re-enable NAPI just after it has been
disabled by macb_close().
Instead, disable all our primitives one by one:
- (1) mask and sync on IRQ handlers,
- (2) drain any scheduled bp->hresp_err_bh_work,
- (3) drain any scheduled queue->tx_error_task,
- (4) drain queue->napi_rx/napi_tx,
- (5) drain bp->tx_lpi_work.
Careful! Ordering is important because our scheduling primitives can
wake each other up. Recap table:
| | enable/disable | schedule |
| |----|-------|-------|------|----|----|--------|-----|
| |IRQs|napi_tx|napi_rx|tx_lpi|napi|napi|tx_error|hresp|
| Context | | | | task | rx | tx | task |task |
|===============|====|=======|=======|======|====|====|========|=====|
| open | X | X | X | | | | | |
| link_up | X | | | | | | | |
| link_down | X | | | | | | | |
| close | X | X | X | | | | | |
| enable_tx_lpi | | | | X | | | | |
| swap | X | X | X | X | | | | |
| suspend | X | X | X | | | | | |
| resume | X | X | X | | | | | |
|---------------|----|-------|-------|------|----|----|--------|-----|
| irq & netpoll | X | | | | X | X | X | X |
|---------------|----|-------|-------|------|----|----|--------|-----|
| napi_rx | X | | | | X | | | |
| napi_tx | X | | | X | | X | | |
|---------------|----|-------|-------|------|----|----|--------|-----|
| tx_error_task | X | X | | | | | | |
| hresp task | X | | | | | | | |
As example, one ordering constraint that can be deduced from the table:
napi_tx can schedule tx_lpi_task meaning napi_tx must be disabled
before tx_lpi_task, else we risk napi_tx re-enabling tx_lpi_task after
it has been disabled by macb_close().
We do *not* use IDR masking to shutdown IRQs because that risks
conflicting with BH primitives we have not disabled yet. For example if
we writel(IDR) in macb_close() and napi_rx is pending then IRQs might
be unmasked by the NAPI poll. As for why we do not use disable_irq():
we will have situations where we are quiesced but want to listen to
some IRQs and (minor reason) we register shared IRQ handlers so we
shouldn't disable the full IRQ line.
Instead we introduce a bool that tells macb_interrupt() to self-disarm.
Its default value is true as we start closed. It gets set to false
while interface is active. Reading into my crystal ball, we'll reuse
that flag in suspend/WOL, set_ringparam and change_mtu (context swap).
Note that old IRQ handler tried preventing a race with close by
self-disarming based on netif_running(). This might work, but it does
not prevent a race with the error codepath of macb_open() which needs
to run with IRQs dis-armed but netif_running() returns true during that
time.
Fixes: e86cd53afc59 ("net/macb: better manage tx errors")
Cc: stable@vger.kernel.org
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb.h | 5 ++
drivers/net/ethernet/cadence/macb_main.c | 84 ++++++++++++++++++++++++--------
2 files changed, 69 insertions(+), 20 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index cfaa0ca49f1a..1cb2778fe49e 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -1382,6 +1382,11 @@ struct macb {
struct delayed_work tx_lpi_work;
u32 tx_lpi_timer;
+ /* ISR must not drive NAPI & BH mechanisms. True when the interface
+ * is closed. Protected by bp->lock.
+ */
+ bool irq_quiesced;
+
int rx_bd_rd_prefetch;
int tx_bd_rd_prefetch;
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 18a1b5f7ad91..1d6361c0d8bc 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -2009,6 +2009,53 @@ static int macb_tx_poll(struct napi_struct *napi, int budget)
return work_done;
}
+static void macb_quiesce_start(struct macb *bp)
+{
+ struct macb_queue *queue;
+ unsigned long flags;
+ unsigned int q;
+
+ spin_lock_irqsave(&bp->lock, flags);
+ bp->irq_quiesced = true;
+ spin_unlock_irqrestore(&bp->lock, flags);
+
+ for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue)
+ synchronize_irq(queue->irq);
+
+ cancel_work_sync(&bp->hresp_err_bh_work);
+
+ for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
+ /* Must be done before NAPI is disabled: the task ends with a
+ * napi_enable() call.
+ */
+ cancel_work_sync(&queue->tx_error_task);
+
+ napi_disable(&queue->napi_rx);
+ napi_disable(&queue->napi_tx);
+ }
+
+ /* Must be done after napi_tx is disabled: its completion re-arms
+ * the LPI timer.
+ */
+ cancel_delayed_work_sync(&bp->tx_lpi_work);
+}
+
+static void macb_quiesce_end(struct macb *bp)
+{
+ struct macb_queue *queue;
+ unsigned long flags;
+ unsigned int q;
+
+ for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
+ napi_enable(&queue->napi_rx);
+ napi_enable(&queue->napi_tx);
+ }
+
+ spin_lock_irqsave(&bp->lock, flags);
+ bp->irq_quiesced = false;
+ spin_unlock_irqrestore(&bp->lock, flags);
+}
+
static void macb_hresp_error_task(struct work_struct *work)
{
struct macb *bp = from_work(bp, work, hresp_err_bh_work);
@@ -2151,8 +2198,8 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
spin_lock(&bp->lock);
while (status) {
- /* close possible race with dev_close */
- if (unlikely(!netif_running(netdev))) {
+ /* self-disarm while the netdev is closed */
+ if (unlikely(bp->irq_quiesced)) {
queue_writel(queue, IDR, -1);
macb_queue_isr_clear(bp, queue, -1);
break;
@@ -3179,8 +3226,6 @@ static int macb_open(struct net_device *netdev)
{
size_t bufsz = netdev->mtu + ETH_HLEN + ETH_FCS_LEN + NET_IP_ALIGN;
struct macb *bp = netdev_priv(netdev);
- struct macb_queue *queue;
- unsigned int q;
int err;
netdev_dbg(bp->netdev, "open\n");
@@ -3204,10 +3249,7 @@ static int macb_open(struct net_device *netdev)
goto free_rings;
macb_init_buffers(bp);
- for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
- napi_enable(&queue->napi_rx);
- napi_enable(&queue->napi_tx);
- }
+ macb_quiesce_end(bp);
macb_init_hw(bp);
@@ -3234,11 +3276,10 @@ static int macb_open(struct net_device *netdev)
phy_power_off(bp->phy);
reset_hw:
+ /* The netdev stays down: quiesce and drain, as macb_close() does. */
+ macb_quiesce_start(bp);
+
macb_reset_hw(bp);
- for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
- napi_disable(&queue->napi_rx);
- napi_disable(&queue->napi_tx);
- }
free_rings:
macb_free(bp);
pm_exit:
@@ -3249,19 +3290,17 @@ static int macb_open(struct net_device *netdev)
static int macb_close(struct net_device *netdev)
{
struct macb *bp = netdev_priv(netdev);
- struct macb_queue *queue;
unsigned long flags;
unsigned int q;
+ macb_quiesce_start(bp);
+
+ /* Drain the BH contexts before stopping the queues: NAPI completion
+ * and tx_error_task wake them up.
+ */
netif_tx_stop_all_queues(netdev);
-
- for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
- napi_disable(&queue->napi_rx);
- napi_disable(&queue->napi_tx);
+ for (q = 0; q < bp->num_queues; ++q)
netdev_tx_reset_queue(netdev_get_tx_queue(netdev, q));
- }
-
- cancel_delayed_work_sync(&bp->tx_lpi_work);
phylink_stop(bp->phylink);
phylink_disconnect_phy(bp->phylink);
@@ -4783,6 +4822,11 @@ static int macb_init_dflt(struct platform_device *pdev)
bp->tx_ring_size = DEFAULT_TX_RING_SIZE;
bp->rx_ring_size = DEFAULT_RX_RING_SIZE;
+ /* No locking needed because the IRQs are not requested yet. The
+ * flag is cleared by macb_open() and re-armed by macb_close().
+ */
+ bp->irq_quiesced = true;
+
/* set the queue register mapping once for all: queue0 has a special
* register mapping but we don't want to test the queue index then
* compute the corresponding register offset at run time.
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2 2/3] net: macb: propagate RX ring refill errors
2026-09-25 13:59 ` [PATCH net v2 2/3] net: macb: propagate RX ring refill errors Théo Lebrun
@ 2026-09-25 14:20 ` Nicolai Buchwitz
0 siblings, 0 replies; 5+ messages in thread
From: Nicolai Buchwitz @ 2026-09-25 14:20 UTC (permalink / raw)
To: Théo Lebrun
Cc: Conor Dooley, Andrew Lunn, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, Sean Anderson, Antoine Tenart,
Eric Dumazet, Nicolas Ferre, Russell King, netdev, linux-kernel,
Vladimir Kondratiev, Gregory CLEMENT, Tawfik Bayouk,
Thomas Petazzoni, Maxime Chevallier, stable
On 25.9.2026 15:59, Théo Lebrun wrote:
> gem_rx_refill() is responsible for Rx SKB allocation, including at
> open,
> but its prototype indicates a void return value.
>
> Therefore we change the code to propagate allocation and DMA mapping
> errors back up the stack, making sure the open fails if no descriptors
> were allocated. Change all those to return errno-style ints:
> - gem_rx_refill()
> - its parent gem_init_rx_ring()
> - its grand-parent gem_init_rings()
> - the macbgem_ops.mog_init_rings function pointer
> - its grand-uncle macb_init_rings()
>
> We tolerate some allocation failures: we accept running with the rx
> ring
> only partially filled with successful descriptors. It is important we
> refuse the zero-valid-descriptor case: nothing would ever trigger a
> refill, which only happens once a frame has been received.
>
> Theoretical bugfix, never encountered in practice. To reproduce,
> introduce memory pressure (less than 512 SKBs of free memory) and open
> the interface. I expect the last queue to be unusable because it has
> zero usable rx buffers.
>
> Note that other callers of refill (resume, HRESP error task, NAPI)
> cannot do anything useful with that error and keep their best-effort
> refill, hoping it will improve.
>
> Fixes: 4df95131ea80 ("net/macb: change RX path for GEM")
> Cc: stable@vger.kernel.org
> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
> ---
> [...]
Reviewed-by: Nicolai Buchwitz <nb@tipi-net.de>
Thanks,
Nicolai
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-25 14:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25 13:59 [PATCH net v2 0/3] net: macb: fix close races (and RX refill error handling) Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 1/3] net: macb: never give hardware a NULL RX buffer Théo Lebrun
2026-09-25 13:59 ` [PATCH net v2 2/3] net: macb: propagate RX ring refill errors Théo Lebrun
2026-09-25 14:20 ` Nicolai Buchwitz
2026-09-25 13:59 ` [PATCH net v2 3/3] net: macb: quiesce IRQs and drain BH on interface close Théo Lebrun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®