๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #1571

Re: [PATCH net] net/sched: act_api: take tcfa_lock for hardware stats updates

#1571
From: netdev-bot+sashiko
Date: Sat, 10 Oct 2026 05:52
118 lines
9866 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The per-CPU branch of tcf_action_update_stats()
  (net/sched/act_api.c) is still racy after this patch.

--

net/sched: act_api: take tcfa_lock for hardware stats updates

This commit takes tcfa_lock with spin_lock_bh() around hardware stats
updates in tcf_action_update_stats() for actions without per-CPU stats.
It also moves the preempt_disable()/preempt_enable() pair from the two
callers into the per-CPU branch of tcf_action_update_stats(), so that
PREEMPT_RT does not take a spinlock_t with preemption disabled.

> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index e45a63be397ce..f6f8cd0a5af64 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c

[ ... ]

> @@ -1588,6 +1586,7 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets,
>  			     u64 drops, bool hw)
>  {
>  	if (a->cpu_bstats) {
> +		preempt_disable();
>  		_bstats_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);
>  
>  		this_cpu_add(a->cpu_qstats->drops, drops);
> @@ -1595,13 +1594,16 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets,
>  		if (hw)
>  			_bstats_update(this_cpu_ptr(a->cpu_bstats_hw),
>  				       bytes, packets);
> +		preempt_enable();
>  		return;
>  	}

[Severity: High]
The commit message says pinning the CPU is enough for the per-CPU path. Is
it, given that BH stays enabled here?

This per-CPU branch is the default, used unless
TCA_ACT_FLAGS_NO_PERCPU_STATS is set. The hardware stats writer reaches it
from process context:

tcf_dump_walker()  (holds mutex idrinfo->lock)
  tcf_action_update_hw_stats()
    tcf_action_stats_update()
      tcf_gact_stats_update()
        tcf_action_update_stats()

fl_hw_update_stats() / mall_stats_hw_filter()
  tcf_exts_hw_stats_update()
    ...
      tcf_action_update_stats()

A softirq on the same CPU can run while this writer is between
u64_stats_update_begin() and u64_stats_update_end() in _bstats_update().
That softirq can write the same per-CPU syncp from the software datapath:

tcf_gact_act()
  tcf_action_update_bstats()
    bstats_update(this_cpu_ptr(a->cpu_bstats), skb)

It can also read it from the rate estimator:

est_timer()
  est_fetch_counters()
    gnet_stats_add_basic()
      gnet_stats_add_basic_cpu()
        u64_stats_fetch_begin(&bcpu->syncp)

On 32-bit, u64_stats_add() is a plain p->v += val, and
__u64_stats_update_begin() only does preempt_disable_nested() plus
write_seqcount_begin(). Neither of those keeps BH out.

Could a softirq bstats_update() that lands inside the interrupted
read-modify-write then be overwritten, losing updates?

And if est_timer fires on this CPU while the writer holds the seqcount
odd, would read_seqcount_begin() spin forever? The interrupted writer
can't resume until the softirq returns. The estimator takes tcfa_lock
through e->stats_lock in est_fetch_counters(), but the per-CPU writer
never takes that lock, so it doesn't help here.

These look like the same symptoms the commit message describes ("lose
counter updates", "seqcount odd and make its readers spin forever"). They
seem to be fixed only for the non-per-CPU branch.

The race was already present through the callers' preempt_disable()
before this patch. Since this hunk rewrites that block, would
local_bh_disable()/local_bh_enable() work instead of
preempt_disable()/preempt_enable() here? That would also keep the task
on the current CPU and is safe on PREEMPT_RT.

>  
> +	spin_lock_bh(&a->tcfa_lock);
>  	_bstats_update(&a->tcfa_bstats, bytes, packets);
>  	atomic_add(drops, &a->tcfa_drops);
>  	if (hw)
>  		_bstats_update(&a->tcfa_bstats_hw, bytes, packets);
> +	spin_unlock_bh(&a->tcfa_lock);
>  }
>  EXPORT_SYMBOL(tcf_action_update_stats);

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009051703.3615846-1-acassen%40corp.free.fr
Technical Details
Message-ID: <179161157546.434549.9093736644956306615@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344063-linux-kernel-netdev=dewy.ru
References: <20261009051703.3615846-1-acassen@corp.free.fr>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344063-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net/sched: act_api: take tcfa_lock for hardware stats updates
Date: Sat, 10 Oct 2026 05:52:55 +0000
Organization: Usenet Network
Message-ID: <179161157546.434549.9093736644956306615@kernel.org>
References: <20261009051703.3615846-1-acassen@corp.free.fr>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1266685"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+09s0eXuhDA5vn8Q9CPQ5yHTL9A= sha256:0WmcXmVkZZ/6aBOMNJD8bni1u0xZ/nRadK0SK3XLjOk=
	sha1:hsKPv8L2NuzGcYQiYVucEw4Wjuk= sha256:4KBwFHsd66PLfrS28NMbQUJNSYxeo/157vD+K3RnAG4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id B5FBC10F854; Sat, 10 Oct 2026 08:53:13 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.641
X-Spam-Status: No, score=-3.641 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 2BO5DnSH-T29;
	Sat, 10 Oct 2026 08:53:05 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-344063-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 2E71A10F262; Sat, 10 Oct 2026 08:53:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id 2349E319DB; Sat, 10 Oct 2026 05:52:59 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ECDF387359;
	Sat, 10 Oct 2026 05:52:58 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QOgkK5i7"
X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4728E370D6E
	for <netdev@vger.kernel.org>; Sat, 10 Oct 2026 05:52:56 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791611578; cv=none; b=PGwt15lW9w+RrT07QhECgNMu5VAijmFiYRc5EOMhcR9T8/DOj2IrPvQNlg831zbWZdayB4b+5gFgHbz2lDqy2L9W043lucJq0jzuvDjYqMnlrzhGxEUOEfB98Gn75vR3Q6nn1cdp0o4EDniH4ftFAM+srmFCPxItyNHs3nrHjXU=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791611578; c=relaxed/simple;
	bh=LWlDKF50WQzp/8c5IiMmc5IqPdNFpeMIxfZ1jFvg9O0=;
	h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References:
	 Content-Type:MIME-Version; b=lEvFGw7Du35lpRNz+tHtGlyWBwPFodjY2Mqa70pGCKI0cIq2vospQGa2xBCEvyEe9mrnHXfL6J/10kKMuWTvtqxff+4Lmk/rUk3WQxMR8vVU+syjfC8g7QLfUSut17USRgo0whABeP4flh6HG8SznOrVZ77LtiqTGgSnXzLwSNo=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QOgkK5i7; arc=none smtp.client-ip=100.103.45.18
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 034401F000FF;
	Sat, 10 Oct 2026 05:52:55 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1791611576;
	bh=0K6hmcX6NNTeJvar8oL2JSoi1NMF+DBugT04LsGaiE8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=QOgkK5i7ILAQ053kTre8ejyvMSVGK1O7XQgMyb+cm5sobOwgrZMXtmUlfSLL8wV37
	 /Z4YzO6BGNAbES5VdPXsNWpKcopBeHhgbHwDUPmK77YpHcPdLygpD5dRTEkmn58X6b
	 dwWgZptPE9rxco1KIFyQlrFI01B9km16zhub2BISMAe9xlx9QfLAx0iEYQEOw3F9BT
	 KXEuxKlX/Qtov7N0FmwOsnr6S7Bx+dXr4wFY+w9Z0uUO1GhkApTEWKx5cJwJHMPL6v
	 KoCi5a2M5+xXfQWdqToecAE9gVD+lmSMuBuMuwDqA4GOSOipT1tvsQPKsFGdbmdQVS
	 MJAYRODVMAQrg==
X-Cc: jhs@mojatatu.com, jiri@resnulli.us, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
 vladbu@nvidia.com, bigeasy@linutronix.de, clrkwllms@kernel.org,
 rostedt@goodmis.org, netdev@vger.kernel.org
X-In-Reply-To: <20261009051703.3615846-1-acassen@corp.free.fr>
X-sashiko-severity: High
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>