The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <conor.dooley@microchip.com>, <andrew+netdev@lunn.ch>,
	<davem@davemloft.net>, <edumazet@kernel.org>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <linux@armlinux.org.uk>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<nb@tipi-net.de>, <pvalerio@redhat.com>,
	<vladimir.kondratiev@mobileye.com>, <gregory.clement@bootlin.com>,
	<benoit.monin@bootlin.com>, <tawfik.bayouk@mobileye.com>,
	<thomas.petazzoni@bootlin.com>, <vineeth.karumanchi@amd.com>
Subject: Re: [PATCH net-next v8 2/3] net: macb: implement ethtool_ops.get|set_channels()
Date: Fri, 27 Nov 2026 18:14:38 +0100	[thread overview]
Message-ID: <DN65UVCVRPGW.3O5CCD2XBNR@bootlin.com> (raw)
In-Reply-To: <179571152544.3135.2345418313808406902@kernel.org>

Hello netdev-bot+sashiko,

On Thu Nov 26, 2026 at 5:45 PM CET,  wrote:
> 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
>
> [ ... ]
>
>> @@ -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?

That is correct. What the model doesn't point out above is that the
reason for all those changes is pretty simple: our context swap window
might now error out. Before all swap operations had to succeed. Now we
have netif_set_real_num_queues() which must be called in the window and
which can fail.

>> +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?

When cap is absent, bp->configured_num_queues == bp->max_num_queues.
So this review sounds wrong.

>> +	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?

ACK, will grab the bp->mac_cfg_lock mutex. It is done before the context
swap window so it is all safe and easy.

Thanks,

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


  reply	other threads:[~2026-11-27 17:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 16:45 [PATCH net-next v8 0/3] net: macb: implement ethtool set channels count operation Théo Lebrun
2026-11-24 16:45 ` [PATCH net-next v8 1/3] net: macb: cache ENST config across link down/up Théo Lebrun
2026-11-26 16:45   ` netdev-bot+sashiko
2026-11-27 16:51     ` Théo Lebrun
2026-11-24 16:45 ` [PATCH net-next v8 2/3] net: macb: implement ethtool_ops.get|set_channels() Théo Lebrun
2026-11-26 16:45   ` netdev-bot+sashiko
2026-11-27 17:14     ` Théo Lebrun [this message]
2026-11-24 16:45 ` [PATCH net-next v8 3/3] net: macb: distribute evenly Tx SRAM segments Théo Lebrun
2026-11-26 16:45   ` netdev-bot+sashiko
2026-11-27 17:15     ` 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=DN65UVCVRPGW.3O5CCD2XBNR@bootlin.com \
    --to=theo.lebrun@bootlin.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=benoit.monin@bootlin.com \
    --cc=conor.dooley@microchip.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nb@tipi-net.de \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pvalerio@redhat.com \
    --cc=tawfik.bayouk@mobileye.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vineeth.karumanchi@amd.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