Netdev List
 help / color / mirror / Atom feed
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: Re: [PATCH net-next v6 13/16] net: macb: move printk() calls out of bp->lock critical section
Date: Mon, 03 Aug 2026 18:14:06 +0200	[thread overview]
Message-ID: <DKFFXBM6VKXZ.22PW13MLAXSF@bootlin.com> (raw)
In-Reply-To: <20260731-macb-context-v6-13-49d5a1439d48@bootlin.com>

Replying to net sashiko
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260731-macb-context-v6-0-49d5a1439d48%40bootlin.com

> commit 99f5236ffcf1506bce8a08773b0456e50c57986e
> Author: Théo Lebrun <theo.lebrun@bootlin.com>
>
> net: macb: move printk() calls out of bp->lock critical section
>
> The two netdev_err() calls in macb_tx_error_task() are deferred until after
> the spin_unlock_irqrestore(&bp->lock, flags), using the existing
> halt_timeout flag plus a new buggy_driver flag. The stated goal is to
> guarantee that netpoll can never be entered while bp->lock is held.
>
> > diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> > index 987fafb2bf40d..65d5ff8a5e230 100644
> > --- a/drivers/net/ethernet/cadence/macb_main.c
> > +++ b/drivers/net/ethernet/cadence/macb_main.c
> > @@ -1358,9 +1358,6 @@ static void macb_tx_error_task(struct work_struct *work)
> >  			 * since it's the only one written back by the hardware
> >  			 */
> >  			if (!(ctrl & MACB_BIT(TX_BUF_EXHAUSTED))) {
> > -				netdev_vdbg(bp->netdev, "txerr skb %u (data %p) TX complete\n",
> > -					    macb_tx_ring_wrap(ctx, tail),
> > -					    skb->data);
> >  				bp->netdev->stats.tx_packets++;
> >  				queue->stats.tx_packets++;
> >  				packets++;
>
> [Severity: Low]
> [Finding: main-1-1]
> [Sources: opus-5]
> This isn't a bug, but the commit message only describes deferring the
> netdev_err() calls, while this hunk deletes the per-descriptor
> netdev_vdbg() trace outright rather than moving it. Its arguments are
> per-descriptor (macb_tx_ring_wrap(ctx, tail) and skb->data) and cannot be
> reproduced after the loop, so VERBOSE_DEBUG builds lose that TX error
> recovery trace. Could the commit message mention this removal?

See below.

>
> > @@ -1374,8 +1371,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);
> >  		}
>
> [Severity: Low]
> [Finding: main-1-1]
> [Sources: opus-5]
> Same finding as above: this also converts a per-descriptor message into one
> aggregated message per invocation, so the number of affected descriptors is
> no longer visible. Worth a line in the commit message as well?

Yes! Mentioned in cover letter but not enough in commit message.

> > @@ -1412,6 +1408,13 @@ 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);
> > +
> > +	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");
> > +
> >  	napi_enable(&queue->napi_tx);
> >  }
>
> [Severity: High]
> [Finding: main-1-0]
> [Sources: opus-5]
> The commit message says the goal is "to ensure we can never netpoll under
> bp->lock's reign". Is that invariant actually established, given the
> netdev_err() still present in macb_interrupt_misc()?
>
> 	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));
> 	}
>
> macb_interrupt() holds the lock across the whole status loop, including that
> call:
>
> 	spin_lock(&bp->lock);
> 	while (status) {
> 		...
> 		if (unlikely(status & MACB_INT_MISC_FLAGS))
> 			if (macb_interrupt_misc(queue, status))
> 				break;
> 		status = queue_readl(queue, ISR);
> 	}
> 	spin_unlock(&bp->lock);
>
> [...]

Argh, yes. I had seen this printk() following the last review iteration
but I couldn't think of a way to land in the interrupt handler while
netpoll was doing its job. But actually it's the other way around: we
might be in the IRQ handler and call our printk that triggers netpoll
mode, re-entering into macb_interrupt_misc().

Let's drop that netdev_err() in macb_interrupt_misc(). I've checked
again, it's the only non-debug printk I could find potentially in a
bp->lock section.

If you have debug prints active AND you land in this race, you have your
hands in the engine anyway. This isn't hurting any real driver user. So
I explicitely ignore them.

(Note: I will re-add the netdev_vdbg() in macb_tx_error_task().)

Thanks,

-- 
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

  reply	other threads:[~2026-08-03 16:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31 16:34 [PATCH net-next v6 00/16] net: macb: implement context swapping Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 01/16] net: macb: drop "consistent" from alloc/free function names Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 02/16] net: macb: unify device pointer naming convention Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 03/16] net: macb: unify variable naming convention in at91ether functions Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 04/16] net: macb: unify queue index variable naming convention and types Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 05/16] net: macb: enforce reverse christmas tree (RCT) convention Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 06/16] net: macb: allocate tieoff descriptor once across device lifetime Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 07/16] net: macb: introduce macb_context struct for buffer management Théo Lebrun
2026-08-03 15:11   ` Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 08/16] net: macb: avoid macb_init_rx_buffer_size() modifying state Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 09/16] net: macb: make `struct macb` subset reachable from macb_context struct Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 10/16] net: macb: change caps helpers signatures Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 11/16] net: macb: change function signatures to take contexts Théo Lebrun
2026-08-03 15:30   ` Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 12/16] net: macb: introduce macb_context_alloc() helper Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 13/16] net: macb: move printk() calls out of bp->lock critical section Théo Lebrun
2026-08-03 16:14   ` Théo Lebrun [this message]
2026-07-31 16:34 ` [PATCH net-next v6 14/16] net: macb: read ISR inside " Théo Lebrun
2026-08-03 17:01   ` Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 15/16] net: macb: use context swapping in .set_ringparam() Théo Lebrun
2026-08-03 19:18   ` Théo Lebrun
2026-07-31 16:34 ` [PATCH net-next v6 16/16] net: macb: use context swapping in .ndo_change_mtu() Théo Lebrun
2026-08-03 19:39   ` 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=DKFFXBM6VKXZ.22PW13MLAXSF@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