Re: [PATCH net-next v8 2/3] net: macb: implement ethtool_ops.get|set_channels()

From: netdev-bot+sashiko

Date: Thu Nov 26 2026 - 11:45:35 EST


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message does not mention changes to shared context-
swap code that the existing MTU and ringparam paths also use.
- [Low] On multi-queue GEM devices without MACB_CAPS_QUEUE_DISABLE,
macb_get_channels() advertises a channel range that…
- [Low] macb_set_channels() checks `bp->enst.queue_mask >> num_queues`
before it takes bp->mac_cfg_lock.

--

net: macb: implement ethtool_ops.get|set_channels()

This commit moves the queue count into the per-context struct and adds
bp->max_num_queues and bp->configured_num_queues. It also implements the
ethtool get/set_channels operations. When the interface is running,
set_channels allocates a new context with the requested queue count and
swaps it in through the existing context swap window.

> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index 1e06666921160..bcf77b2763448 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c

[ ... ]

> @@ -3359,10 +3385,6 @@ static void macb_context_swap_start(struct macb *bp)
> */
> netif_tx_disable(bp->netdev);
>
> - /* Now that everything is stopped, clear DQL. */
> - for (q = 0; q < bp->num_queues; ++q)
> - netdev_tx_reset_queue(netdev_get_tx_queue(bp->netdev, q));
> -
> /* Safe to call outside bp->lock because bp->irq_quiesced ensures the IRQ
> * handling is a no-op and all BH features are disabled.
> *

[ ... ]

> @@ -3399,16 +3421,28 @@ static void macb_context_swap_end(struct macb *bp,
>
> lockdep_assert_held(&bp->mac_cfg_lock);
>
> - /* Swap contexts & give buffer pointers to HW. */
> + /* Swap contexts & give buffer pointers to HW.
> + * !new_ctx means that the swap failed and we keep the old context.
> + */
>
> - old_ctx = bp->ctx;
> - WRITE_ONCE(bp->ctx, new_ctx);
> - wmb(); /* ensure IRQ enabled below read the new context */
> - macb_init_buffers(bp);
> + if (new_ctx) {
> + old_ctx = bp->ctx;
> + WRITE_ONCE(bp->ctx, new_ctx);
> + wmb(); /* ensure IRQ enabled below read the new context */
> +
> + macb_init_buffers(bp);
> +
> + /* Clear DQL (only on successful context swap). */
> + for (q = 0; q < bp->max_num_queues; ++q)
> + netdev_tx_reset_queue(netdev_get_tx_queue(bp->netdev,
> + q));
> + } else {
> + gem_shuffle_tx_rings(bp);
> + }

[Severity: Low]
This isn't a bug, but the commit message doesn't mention that this patch
reworks the context swap helpers that macb_change_mtu() and
macb_set_ringparam() share. The message says set_channels:

"ends up only being an assignment to bp->configured_num_queues plus a
call into netif_set_real_num_queues()"

The patch also:

- moves the netdev_tx_reset_queue() loop from macb_context_swap_start()
into macb_context_swap_end(). The loop now runs only on a successful
swap and is bounded by bp->max_num_queues instead of the active
queue count.
- adds a new_ctx == NULL rollback mode to macb_context_swap_end(). It
keeps the old context, skips macb_init_buffers(), calls
gem_shuffle_tx_rings() and skips the free.
- makes macb_interrupt() self-disarm on queues where
q >= ctx->num_queues.
- switches gem_get_rx_ring_count() and macb_poll_controller() to
bp->configured_num_queues.

The existing MTU and ringparam callers always pass a non-NULL new_ctx, so
their behaviour doesn't appear to change.

Could the commit message describe these helper changes, or could they go
in a preparatory patch?

[ ... ]

> +static int macb_set_channels(struct net_device *netdev,
> + struct ethtool_channels *ch)
> +{
> + struct macb *bp = netdev_priv(netdev);
> + unsigned int num_queues = ch->combined_count;
> + bool running = netif_running(bp->netdev);
> + struct macb_context *new_ctx;
> + int ret;
> +
> + /* MACB_CAPS_QUEUE_DISABLE means that the field QUEUE_DISABLE/BIT0 in
> + * the per-queue RBQP/TBQP registers disable Tx/Rx queues. If we don't
> + * have that capability we can have multiple queues but we must always
> + * run with all enabled.
> + */
> + if (!(bp->caps & MACB_CAPS_QUEUE_DISABLE))
> + return -EOPNOTSUPP;

[Severity: Low]
Does macb_get_channels() advertise a range that this check never accepts?

macb_get_channels() always reports:

ch->max_combined = bp->max_num_queues;
ch->combined_count = bp->configured_num_queues;

Some multi-queue GEM configs don't set MACB_CAPS_QUEUE_DISABLE, for
example zynqmp_config, raspberrypi_rp1_config, pic64hpsc_config and
default_gem_config. On those devices ethtool -l shows something like
"Combined: max N, current N", but every request for 1..N-1 fails here
with EOPNOTSUPP.

Should max_combined be reported as bp->configured_num_queues when the
capability is absent?

> +
> + if (num_queues > bp->max_num_queues)
> + return -EINVAL;
> +
> + if (num_queues == bp->configured_num_queues)
> + return 0;
> +
> + /* If we allow disabling a queue which has TAPRIO active, we'll keep a
> + * transmission window which would be unusable.
> + */
> + if (bp->enst.queue_mask >> num_queues) {
> + netdev_err(bp->netdev, "TAPRIO schedule gates queues >= %u; destroy the qdisc before reducing channels\n",
> + num_queues);
> + return -EBUSY;
> + }

[Severity: Low]
Is it safe to read bp->enst.queue_mask here without bp->mac_cfg_lock?

In the running case the lock is only taken later, in
macb_context_swap_start(). In the not-running case it is never taken.

Other writers of bp->enst hold mac_cfg_lock. For example,
macb_taprio_destroy() does:

guard(mutex)(&bp->mac_cfg_lock);

netdev_reset_tc(netdev);
memset(&bp->enst, 0, sizeof(bp->enst));

macb_mac_link_up() also clears it on a link speed change. It holds only
mac_cfg_lock and runs from the phylink_resolve() worker without rtnl:

memset(&bp->enst, 0, sizeof(bp->enst));

So this unlocked read can race with a locked write, which KCSAN could
report. The worst outcome looks like a spurious -EBUSY.

Could this check be done under mac_cfg_lock?

> +
> + if (running) {
> + new_ctx = macb_context_alloc(bp, num_queues, netdev->mtu,
> + bp->configured_rx_ring_size,
> + bp->configured_tx_ring_size);
> + if (IS_ERR(new_ctx))
> + return PTR_ERR(new_ctx);
> +
> + macb_context_swap_start(bp);
> + }

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-macb-set-channels-v8-0-770cf8e50e6d%40bootlin.com