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 v5 14/15] net: macb: use context swapping in .set_ringparam()
Date: Fri, 31 Jul 2026 18:10:33 +0200 [thread overview]
Message-ID: <DKCVYZ69KGSM.2R1ELFSWRG5HM@bootlin.com> (raw)
In-Reply-To: <20260724-macb-context-v5-14-569b1852bc7f@bootlin.com>
Sashiko replies.
Both sashiko.dev and sashiko-netdev has comments on this patch.
https://sashiko.dev/#/patchset/20260724-macb-context-v5-0-569b1852bc7f%40bootlin.com
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260724-macb-context-v5-0-569b1852bc7f%40bootlin.com?patch=8011
---
sashiko.dev:
> > +static void macb_context_swap_end(struct macb *bp,
> > + struct macb_context *new_ctx)
> > +{
> [ ... ]
> > + ctrl = macb_readl(bp, NCR);
> > + macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE));
> > +
> > + spin_unlock_irqrestore(&bp->lock, flags);
> > +
> > + mutex_unlock(&bp->mac_cfg_lock);
> > +
> > + netif_tx_start_all_queues(bp->netdev);
>
> [Severity: High]
> Does unconditionally enabling the MAC receiver, transmitter, and TX queues
> here risk overriding phylink's link-down state?
>
> If a user changes ring parameters via ethtool on an administratively up
> interface that currently has no physical carrier, could this forcefully
> enable the hardware and violate the phylink state machine contract?
Yes. We need to check for that using netif_carrier_ok(). We already have
our bp->mac_cfg_lock mutex delaying the conflicting phylink ops.
Note: we'll add the mutex lock in macb_hresp_error_task() which toggles
the carrier state.
>
> > +
> > + /* Free old context. */
> > +
> > + macb_free(old_ctx);
> > + kfree(old_ctx);
> > +}
---
sashiko-netdev:
> > +static void macb_context_swap_end(struct macb *bp,
> > + struct macb_context *new_ctx)
> > +{
> > + struct macb_context *old_ctx;
> > + struct macb_queue *queue;
> > + unsigned long flags;
> > + unsigned int q;
> > + u32 ctrl;
> > +
> > + lockdep_assert_held(&bp->mac_cfg_lock);
> > +
> > + /* Swap contexts & give buffer pointers to HW. */
> > +
> > + old_ctx = bp->ctx;
> > + bp->ctx = new_ctx;
> > + macb_init_buffers(bp);
> > +
> > + /* Start NAPI, HW Tx/Rx and software Tx. */
> > +
> > + 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);
> > +
> > + /* Re-arm normal interrupt processing before enabling IRQs. */
> > + bp->ctx_swap = false;
> > +
> > + macb_configure_dma(bp);
> > +
> > + for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) {
> > + queue_writel(queue, IER,
> > + bp->rx_intr_mask |
> > + MACB_TX_INT_FLAGS |
> > + MACB_BIT(HRESP));
> > + }
> > +
> > + ctrl = macb_readl(bp, NCR);
> > + macb_writel(bp, NCR, ctrl | MACB_BIT(RE) | MACB_BIT(TE));
> > +
> > + spin_unlock_irqrestore(&bp->lock, flags);
> > +
> > + mutex_unlock(&bp->mac_cfg_lock);
> > +
> > + netif_tx_start_all_queues(bp->netdev);
>
> [Medium]
> Can there be a window between mutex_unlock(&bp->mac_cfg_lock) and
> netif_tx_start_all_queues(bp->netdev) where phylink_resolve runs
> macb_mac_link_down(), which now also takes mac_cfg_lock and calls
> netif_tx_stop_all_queues()?
>
> If mac_link_down runs in that window:
>
> static void macb_mac_link_down(...)
> {
> mutex_lock(&bp->mac_cfg_lock);
> ...
> netif_tx_stop_all_queues(netdev);
> mutex_unlock(&bp->mac_cfg_lock);
> }
>
> then the subsequent netif_tx_start_all_queues() in macb_context_swap_end()
> would clear __QUEUE_STATE_DRV_XOFF and undo the stop that mac_link_down
> just performed.
>
> For comparison, macb_mac_link_up() calls netif_tx_wake_all_queues() while
> still holding mac_cfg_lock, and macb_mac_link_down() calls
> netif_tx_stop_all_queues() while still holding it. Would moving the
> netif_tx_start_all_queues() call above mutex_unlock() here match that
> pattern and close the window?
Agreed. netif_tx_start_all_queues() will move one line up.
>
> > +
> > + /* Free old context. */
> > +
> > + macb_free(old_ctx);
> > + kfree(old_ctx);
> > +}
>
> > @@ -3816,9 +3953,10 @@ static int macb_set_ringparam(struct net_device *netdev,
> > struct kernel_ethtool_ringparam *kernel_ring,
> > struct netlink_ext_ack *extack)
> > {
> > + unsigned int new_rx_size, new_tx_size;
> > struct macb *bp = netdev_priv(netdev);
> > - u32 new_rx_size, new_tx_size;
> > - unsigned int reset = 0;
> > + bool running = netif_running(netdev);
> > + struct macb_context *new_ctx;
> >
> > if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
> > return -EINVAL;
> > @@ -3837,16 +3975,24 @@ static int macb_set_ringparam(struct net_device *netdev,
> > return 0;
> > }
> >
> > - if (netif_running(bp->netdev)) {
> > - reset = 1;
> > - macb_close(bp->netdev);
> > + if (running) {
> > + /* Context swapping is not supported for AT91. */
> > + if (bp->caps & MACB_CAPS_MACB_IS_EMAC)
> > + return -EBUSY;
>
> [Medium]
> Before this change, ethtool --set-ring on an administratively up AT91
> EMAC interface went through the macb_close()/macb_open() path and
> succeeded. After this change AT91 EMAC returns -EBUSY when the interface
> is up, so users must now bring the link down, adjust ring sizes, and
> bring it back up.
>
> Should this user-visible behavior change be called out in the commit
> message, or would it be preferable to keep the previous close/reopen
> sequence as an AT91-only fallback so existing management scripts continue
> to work?
No we don't want the fallback.
Yes I'll mention this in the commit message.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-07-31 16:10 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 15:29 [PATCH net-next v5 00/15] net: macb: implement context swapping Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 01/15] net: macb: drop "consistent" from alloc/free function names Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 02/15] net: macb: unify device pointer naming convention Théo Lebrun
2026-07-24 19:35 ` Nicolai Buchwitz
2026-07-24 15:29 ` [PATCH net-next v5 03/15] net: macb: unify variable naming convention in at91ether functions Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 04/15] net: macb: unify queue index variable naming convention and types Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 05/15] net: macb: enforce reverse christmas tree (RCT) convention Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 06/15] net: macb: allocate tieoff descriptor once across device lifetime Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 07/15] net: macb: introduce macb_context struct for buffer management Théo Lebrun
2026-07-31 14:39 ` Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 08/15] net: macb: avoid macb_init_rx_buffer_size() modifying state Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 09/15] net: macb: make `struct macb` subset reachable from macb_context struct Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 10/15] net: macb: change caps helpers signatures Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 11/15] net: macb: change function signatures to take contexts Théo Lebrun
2026-07-24 19:36 ` Nicolai Buchwitz
2026-07-31 14:55 ` Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 12/15] net: macb: introduce macb_context_alloc() helper Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 13/15] net: macb: read ISR inside bp->lock critical section Théo Lebrun
2026-07-31 15:08 ` Théo Lebrun
2026-07-24 15:29 ` [PATCH net-next v5 14/15] net: macb: use context swapping in .set_ringparam() Théo Lebrun
2026-07-24 19:38 ` Nicolai Buchwitz
2026-07-31 16:10 ` Théo Lebrun [this message]
2026-07-24 15:29 ` [PATCH net-next v5 15/15] net: macb: use context swapping in .ndo_change_mtu() Théo Lebrun
2026-07-31 16:21 ` Théo Lebrun
2026-07-30 11:52 ` [PATCH net-next v5 00/15] net: macb: implement context swapping Paolo Abeni
2026-07-30 16:17 ` 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=DKCVYZ69KGSM.2R1ELFSWRG5HM@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