From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Théo Lebrun" <theo.lebrun@bootlin.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Richard Cochran" <richardcochran@gmail.com>,
"Russell King" <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Paolo Valerio" <pvalerio@redhat.com>,
"Nicolai Buchwitz" <nb@tipi-net.de>,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Maxime Chevallier" <maxime.chevallier@bootlin.com>
Subject: [PATCH net-next v8 14/17] net: macb: move printk() calls out of bp->lock critical section
Date: Wed, 05 Aug 2026 19:42:43 +0200 [thread overview]
Message-ID: <20260805-macb-context-v8-14-bc302ffd1174@bootlin.com> (raw)
In-Reply-To: <20260805-macb-context-v8-0-bc302ffd1174@bootlin.com>
printk() while bp->lock is acquired is dangerous if netconsole is active
on the interface. In that setup, we might land in macb_poll_controller()
-> macb_interrupt() -> spin_lock(&bp->lock) but bp->lock is already
acquired.
This is not an issue currently because macb_interrupt() first checks IRQ
status, potentially early returns, then grabs lock. This early exit is
expected in netpoll scenario.
However if we came to reading the status inside the bp->lock critical
section (as it should be to avoid races), then this would turn into a
deadlock. And we will.
Solution: move printk() calls out of the critical section, to ensure we
can never netpoll under bp->lock's reign. Added benefit is a smaller
and simpler atomic section.
--
In macb_tx_error_task(), defer netdev_err("halt tx timed out") call to
after the critical section. Update the message to highlight it occurred
in the past. Inherit the buffer exhaustion boolean variable name from
the old code comment.
In macb_tx_error_task(), defer the netdev_err("TX buffers exhausted
mid-frame") call out of the loop. This also means it goes from
1-per-error to 1-per-task-invocation.
In IRQ handling, move HRESP error printing out of macb_interrupt_misc()
into macb_interrupt(). Again, it means we dedup error reporting if
status is read multiple times in a row with HRESP bit set. This is fine
as from past instances I've seen, this message spams our log if it
occurs.
Notice we *ignore* debug printks; if you are debugging MACB maybe don't
use netconsole...
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
---
drivers/net/ethernet/cadence/macb_main.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index 5a4eb87f5a97..4bf55994420f 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -1303,6 +1303,7 @@ static void macb_tx_error_task(struct work_struct *work)
struct macb_tx_skb *tx_skb;
struct macb_dma_desc *desc;
bool halt_timeout = false;
+ bool buggy_driver = false;
struct sk_buff *skb;
unsigned long flags;
unsigned int tail;
@@ -1329,7 +1330,6 @@ static void macb_tx_error_task(struct work_struct *work)
* macb/gem must be halted to write TBQP register
*/
if (macb_halt_tx(bp)) {
- netdev_err(bp->netdev, "BUG: halt tx timed out\n");
macb_writel(bp, NCR, macb_readl(bp, NCR) & (~MACB_BIT(TE)));
halt_timeout = true;
}
@@ -1374,8 +1374,7 @@ static void macb_tx_error_task(struct work_struct *work)
* those. Statistics are updated by hardware.
*/
if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED))
- netdev_err(bp->netdev,
- "BUG: TX buffers exhausted mid-frame\n");
+ buggy_driver = true;
desc->ctrl = ctrl | MACB_BIT(TX_USED);
}
@@ -1412,7 +1411,14 @@ static void macb_tx_error_task(struct work_struct *work)
macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART));
spin_unlock_irqrestore(&bp->lock, flags);
+
napi_enable(&queue->napi_tx);
+
+ if (halt_timeout)
+ netdev_err(bp->netdev, "BUG: halt tx timed out, we ignored it\n");
+
+ if (buggy_driver)
+ netdev_err(bp->netdev, "BUG: TX buffers exhausted mid-frame\n");
}
static bool ptp_one_step_sync(struct sk_buff *skb)
@@ -2165,7 +2171,6 @@ static int macb_interrupt_misc(struct macb_queue *queue, u32 status)
if (status & MACB_BIT(HRESP)) {
queue_work(system_bh_wq, &bp->hresp_err_bh_work);
- netdev_err(netdev, "DMA bus error: HRESP not OK\n");
macb_queue_isr_clear(bp, queue, MACB_BIT(HRESP));
}
@@ -2185,6 +2190,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
struct macb_queue *queue = dev_id;
struct macb *bp = queue->bp;
struct net_device *netdev = bp->netdev;
+ bool hresp_err = false;
u32 status;
status = queue_readl(queue, ISR);
@@ -2231,15 +2237,22 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
napi_schedule_irqoff(&queue->napi_tx);
}
- if (unlikely(status & MACB_INT_MISC_FLAGS))
+ if (unlikely(status & MACB_INT_MISC_FLAGS)) {
if (macb_interrupt_misc(queue, status))
break;
+ if (status & MACB_BIT(HRESP))
+ hresp_err = true;
+ }
+
status = queue_readl(queue, ISR);
}
spin_unlock(&bp->lock);
+ if (hresp_err)
+ netdev_err(netdev, "DMA bus error: HRESP not OK\n");
+
return IRQ_HANDLED;
}
--
2.55.0
next prev parent reply other threads:[~2026-08-05 17:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 17:42 [PATCH net-next v8 00/17] net: macb: implement context swapping Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 01/17] net: macb: drop "consistent" from alloc/free function names Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 02/17] net: macb: unify device pointer naming convention Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 03/17] net: macb: unify variable naming convention in at91ether functions Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 04/17] net: macb: unify queue index variable naming convention and types Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 05/17] net: macb: enforce reverse christmas tree (RCT) convention Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 06/17] net: macb: allocate tieoff descriptor once across device lifetime Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 07/17] net: macb: refuse set_ringparam on EMAC Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 08/17] net: macb: introduce macb_context struct for buffer management Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 09/17] net: macb: avoid macb_init_rx_buffer_size() modifying state Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 10/17] net: macb: make `struct macb` subset reachable from macb_context struct Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 11/17] net: macb: change caps helpers signatures Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 12/17] net: macb: change function signatures to take contexts Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 13/17] net: macb: introduce macb_context_alloc() helper Théo Lebrun
2026-08-05 17:42 ` Théo Lebrun [this message]
2026-08-05 17:42 ` [PATCH net-next v8 15/17] net: macb: read ISR inside bp->lock critical section Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 16/17] net: macb: use context swapping in .set_ringparam() Théo Lebrun
2026-08-05 17:42 ` [PATCH net-next v8 17/17] net: macb: use context swapping in .ndo_change_mtu() Théo Lebrun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260805-macb-context-v8-14-bc302ffd1174@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andrew+netdev@lunn.ch \
--cc=benoit.monin@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=conor.dooley@microchip.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gregory.clement@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=nb@tipi-net.de \
--cc=netdev@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=pabeni@redhat.com \
--cc=pvalerio@redhat.com \
--cc=richardcochran@gmail.com \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox