BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wei Hu" <weh@linux.microsoft.com>
Cc: linux-rdma@vger.kernel.org, linux-hyperv@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH net-next v7 04/13] net: mana: swap queue sets in mana_set_channels
Date: Sat, 17 Oct 2026 15:39:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-175604@kernel.org> (raw)
In-Reply-To: <ec57f3853ef344a7d5ec8907ba530313b0163bae.1791710735.git.weh@linux.microsoft.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] bpf: concurrent writers to tx_stats->syncp without mutual exclusion
- [High] net: missing BH disable around u64_stats_update_begin() in mana_fold_rxq_stats()
--

commit 347c8bd66ee5005e7aea875ed691f7a765b23452
Author: Long Li <longli@microsoft.com>

net: mana: swap queue sets in mana_set_channels

This patch introduces a replacement queue set building before quiescing TX.
It drains the old TX queues and swaps pointers, handling statistics folding
upon successful or failed rollback.

> --- a/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_bpf.c
> @@ -59,6 +59,11 @@ int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames,
>  	if (unlikely(!apc->port_is_up))
>  		return 0;
>  
> +	/* Pair with the smp_wmb() in mana_publish_qset() before reading queue
> +	 * state.
> +	 */
> +	smp_rmb();
> +
>  	q_idx = smp_processor_id() % ndev->real_num_tx_queues;
>  
>  	for (i = 0; i < n; i++) {

[Severity: High]
Does mana_xdp_xmit() require a lock when updating tx_stats->syncp further
down in this function?

This function acts as the ndo_xdp_xmit callback and maps CPUs to queues
using smp_processor_id() % ndev->real_num_tx_queues. If multiple CPUs map
to the same queue index, or if mana_start_xmit() runs concurrently on the
same queue, multiple threads could concurrently invoke
u64_stats_update_begin(&tx_stats->syncp).

Since there isn't a per-queue mutual exclusion lock acquired here (unlike
the core stack serialization in mana_start_xmit()), could this concurrency
corrupt the sequence counter and cause readers to spin infinitely on 32-bit
systems?

[ ... ]

> --- a/drivers/net/ethernet/microsoft/mana/mana_en.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
[ ... ]
> @@ -1123,6 +1161,58 @@ static void mana_free_queue_stats(struct mana_port_context *apc)
>  	apc->txq_stats = NULL;
>  }
>  
> +/* Fold under RTNL after drain_stats writers quiesce. Clear drain_stats to
> + * prevent double counting on rollback.
> + */
> +static void mana_fold_rxq_stats(struct mana_port_context *apc,
> +				struct mana_rxq *rxq)
> +{
> +	struct mana_stats_rx *src = &rxq->drain_stats;
> +	struct mana_stats_rx *dst;
> +	unsigned int i;
> +
> +	ASSERT_RTNL();
> +
> +	if (!apc->rxq_stats_ret || rxq->rxq_idx >= apc->max_queues)
> +		return;
> +
> +	dst = &apc->rxq_stats_ret[rxq->rxq_idx];
> +
> +	u64_stats_update_begin(&dst->syncp);
> +	dst->packets		+= src->packets;
> +	dst->bytes		+= src->bytes;

[Severity: High]
Could this u64_stats_update_begin() call deadlock a preempting softirq
reader?

This function runs in process context under rtnl_lock(), which is a mutex
and does not disable bottom halves. Readers of network statistics (like
ndo_get_stats64) can be executed from softirq context.

If a softirq interrupts mana_fold_rxq_stats() on the same CPU while the
writer holds an odd sequence counter, the reader will loop forever in
u64_stats_fetch_retry().

Should this use local_bh_disable() or the _bh wrapper for the stats update
to prevent this scenario?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791710735.git.weh@linux.microsoft.com?part=4

  reply	other threads:[~2026-10-17 15:39 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16 15:38 [PATCH net-next v7 00/13] net: mana: reconfigure by replacing the queue set Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 01/13] net: mana: add queue-set allocation and teardown helpers Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 02/13] net: mana: share the EQ pool across a queue-set swap Wei Hu
2026-10-17 15:39   ` sashiko-bot
2026-10-16 15:38 ` [PATCH net-next v7 03/13] net: mana: keep per-queue statistics in the port context Wei Hu
2026-10-17 15:39   ` sashiko-bot
2026-10-16 15:38 ` [PATCH net-next v7 04/13] net: mana: swap queue sets in mana_set_channels Wei Hu
2026-10-17 15:39   ` sashiko-bot [this message]
2026-10-16 15:38 ` [PATCH net-next v7 05/13] net: mana: swap queue sets in mana_set_ringparam Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 06/13] net: mana: swap queue sets in mana_set_priv_flags Wei Hu
2026-10-17 15:39   ` sashiko-bot
2026-10-16 15:38 ` [PATCH net-next v7 07/13] net: mana: swap queue sets in mana_change_mtu Wei Hu
2026-10-17 15:39   ` sashiko-bot
2026-10-16 15:38 ` [PATCH net-next v7 08/13] net: mana: swap queue sets in mana_xdp_set Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 09/13] net: mana: do not bail out of mana_detach on dealloc failure Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 10/13] net: mana: release EQs left idle by a channel-count reduction Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 11/13] net: mana: keep a user-configured RSS table across a queue rebuild Wei Hu
2026-10-17 15:39   ` sashiko-bot
2026-10-16 15:38 ` [PATCH net-next v7 12/13] net: mana: keep the surviving queues when the channel count is reduced Wei Hu
2026-10-16 15:38 ` [PATCH net-next v7 13/13] net: mana: keep the existing queues when the channel count is raised Wei Hu

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=sashiko-outbox-175604@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=weh@linux.microsoft.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