🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5497

Re: [PATCH net-next v3 1/4] net/sched/sch_cake: serialize reconfiguration with the datapath

#5497
From: Toke Høiland-Jørgensen
Date: Tue, 20 Oct 2026 12:49
81 lines
11243 bytes
Jamal Hadi Salim <jhs@mojatatu.com> writes:

> This is a follow-up to commit 7cbfb180945c ("net/sched: sch_cake: fix
> autorate reconfiguration throttling").  That change only stored
> last_reconfig_time; it did not address the concurrency between the
> autorate rate update in cake_enqueue() and the netlink reconfiguration
> path, which the original review flagged.
>
> The issue:
> cake_change() -> cake_config_change() updates the fields of the shared
> struct cake_sched_config under RTNL but not under the qdisc lock: it only
> took sch_tree_lock() later, around cake_reconfigure().  The datapath in
> turn serializes cake_enqueue() with itself under the qdisc lock, and its
> autorate-ingress path stores the estimated rate into
> q->config->rate_bps.  Two writers therefore update the same rate with no
> common lock:
>
>   CPU0: cake_enqueue() sees CAKE_FLAG_AUTORATE_INGRESS, computes an
>         estimate, and is about to store it.
>   CPU1: 'tc qdisc change ... bandwidth X' clears autorate in its local
>         rate_flags, writes rate_bps = X, publishes the cleared flag, and
>         waits in sch_tree_lock().
>   CPU0: stores the estimate, calls cake_reconfigure(), and unlocks.
>   CPU1: reconfigures from the estimate and returns.
>
> The qdisc is left with autorate disabled but with the estimate installed
> instead of X.
>
> The fix:
> Commit the parsed configuration and reconfigure while holding the same
> qdisc lock that serializes the datapath, so the netlink writer and the
> autorate writer can no longer interleave.  rate_bps needs no atomic: it is
> only ever loaded and stored, so plain READ_ONCE()/WRITE_ONCE() annotations
> are enough for the accesses that run outside the lock.  The lockless
> paths read the rate once into a local and reuse that value, so a single
> coherent snapshot is used per operation.
>
> The annotations do not make a 64-bit access single-copy atomic on 32-bit:
> READ_ONCE()/WRITE_ONCE() are still two 32-bit accesses there.  The lockless
> readers -- cake_config_dump() and the cake_mq children, which observe the
> shared config under a different child's lock -- can therefore still see a
> torn rate on 32-bit.  That rate is an advisory shaper value and is accepted
> as best-effort; the state that must be consistent (the configured rate and
> the autorate flag) is written under the qdisc lock.
>
> Conditions to recreate the bug:
> The lost update (a) needs no sanitizer. Put cake in autorate-ingress on a
> device, drive bursty traffic with gaps so the 250 ms autorate reconfiguration
> fires, and concurrently loop 'tc qdisc change ... cake bandwidth <N>kbit'
> without autorate-ingress (specifying a bandwidth clears the flag).
> If the autorate store lands after the change wrote its rate but before the
> change reconfigures, the qdisc ends up with autorate disabled and the estimate
> installed instead of <N>; reading the rate back then shows the estimate, which
> an unfixed kernel can do and a fixed one cannot.
> (b) The unsynchronized access is reported by KCSAN: build with CONFIG_KCSAN=y
> and run the same trigger with the change loop keeping autorate-ingress set;
> KCSAN reports a data race in cake_config_change / cake_enqueue.
> The non-atomic 64-bit store only shows up as tearing on a 32-bit machine;
> on 64-bit the store is atomic and KCSAN flags the access discipline instead.
>
> Reported-by: Sashiko (gemini) <sashiko-bot@kernel.org>
> Link: https://sashiko.dev/#/patchset/20260816012109.2865223-1-ooonea@gmail.com
> Link: https://lore.kernel.org/netdev/20260816012109.2865223-1-ooonea@gmail.com/
> Link: https://lore.kernel.org/netdev/875wzctsky.fsf@toke.dk/
> Link: https://lore.kernel.org/netdev/87ld7t3kl3.fsf@all.your.base.are.belong.to.us/
> Reviewed-by: Victor Nogueira <victor@mojatatu.com>
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>

Acked-by: Toke Høiland-Jørgensen <toke@toke.dk>
Technical Details
Message-ID: <87wlrctu2y.fsf@toke.dk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349288-linux-kernel-netdev=dewy.ru
References: <QDISC-5RTM.v3.r0.20261020053711@mojatatu.com> <QDISC-5RTM.v3.r0.20261020053711-1@mojatatu.com>

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-349288-linux-kernel-netdev=dewy.ru
From: toke@toke.dk (Toke Høiland-Jørgensen)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 1/4] net/sched/sch_cake: serialize
 reconfiguration with the datapath
Date: Tue, 20 Oct 2026 14:49:57 +0200
Organization: Usenet Network
Message-ID: <87wlrctu2y.fsf@toke.dk>
References: <QDISC-5RTM.v3.r0.20261020053711@mojatatu.com>
 <QDISC-5RTM.v3.r0.20261020053711-1@mojatatu.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3854492"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:OURahmq8DdcKq0IT7XohkvBx12o= sha256:MC0qavzR9KoMt0Y5DSVjyTPkje8BA/CULEWu63WIk4U=
	sha1:PgfMvi/CJrolN6tze6J5N+w6paI= sha256:XShXI4dCOQUddM13S6OPTSfIfBbsb07RgXxe/AH/5uQ=
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 522A0110CF2; Tue, 20 Oct 2026 15:53:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.849
X-Spam-Status: No, score=-1.849 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_ADSP_ALL=1.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
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 SouJxSV7QROM;
	Tue, 20 Oct 2026 15:53:13 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-349288-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=toke.dk
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id BA025110CEF; Tue, 20 Oct 2026 15:53:09 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 8D0692FECF; Tue, 20 Oct 2026 12:50:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792500602;
	b=btBHZmqQqvTrhJ3ylAAfUeG/WKGHOfpcdppjTfEamkf7GTWisZJRYN6IpvoDw84241vg
	 Js4o2pFPYYVkQDJQhk6JyCSEUppYiqTg7B7t7rz2q7TI/I97bj+R1am9AAgIzjJfDVmn7
	 Orj2SUh+CtuJ5xerasUZQyctYgZp4zRtTXAELFOrZwik2MENgmt2A2dqh/FTdIQDAKzvv
	 0EN0J+NQomF7p58nxf8CQ6Q/N3+FFGPLZa0YWBrrsxXEq7/nlek8TMQeZr5CB7BG1i8Na
	 NAwqseD3K597IuRRLsePT8bZLbQi+38pJBF27wrcyWr3faBWdAb+mr4CmwZ0ipZQEPA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792500602;
	h=X-Original-To:Received:DMARC-Filter:From:To:Cc:Subject:In-Reply-To:
	 References:Date:X-Clacks-Overhead:Message-ID:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=IzQx6pHKIouWCSktHVNsKQuHimzuXnFnXJ6+lki+f2c=;
	b=xhcX+xxnLOBswu2ZSXTipk17Kuyx0+Pw/VH04qGfwk3P5H6Gh+SLU/lXYeu5oVVhtNLv
	 WPbnlAi95HbBDzHfytSXDoccmRzcmmx67HiN7QEB5vPtcQASjobmwJrik1o3SuoNf2Ldi
	 E0EgiDf7LtfQY6XmH9BKhicINXnvVknDYLkk/Uz4zddsmITU80+6QT4CTk4pXXIX/3S+g
	 bk6XQ4q38MEPh2MMySscWwZGTXc/pXWTEjtAvOVGr0XaYAcTdqnVquPWGIL/PNbP1JC29
	 mSmP/eIMabyvm7f45khTzaZgmtHXxMH6sQzPTpkHrhpVn1onLGLzuasvUtpnATpwArQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dmarc=pass header.from=toke.dk;
	spf=pass smtp.mailfrom=toke.dk;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 60318606A31D;
	Tue, 20 Oct 2026 12:50:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=45.145.95.4
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792500601;
	b=mMZ1QB6z5CDBLd4uO75GucAWYcQ4qmUDkyFQALUuzfO9iSsJLV7wOdHYGu1ybyB+S9kM
	 8LhGke4+83udBKFL2zkO5aee9jTnNBykktz9LtV6RNX4uplkLD8fKjiJ3+gle5qpuaXTv
	 8Xa/1LAuU8P1hmPDDWEoKASp0FrMuWrTPcyBRmjaelbpjmaVXLzt+0iUzaXblqvDRvkF3
	 E0ZhxGj6prYDw48sAda9PaprmvZd5W45+2WSxgz0EAcaejt3TQ0A0QO977oL/OAPmsjeF
	 ZvjIiIuzBbllvUChjEFLDv8ChulIpEcssgxR3dKwXgnkCVW/3oVtqZbsgMkjL95iciA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792500601;
	h=DMARC-Filter:From:To:Cc:Subject:In-Reply-To:References:Date:
	 X-Clacks-Overhead:Message-ID:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=IzQx6pHKIouWCSktHVNsKQuHimzuXnFnXJ6+lki+f2c=;
	b=2mVGRuQYkVDFGGQ9c2lVqUNku6bL1YBK+ZkYC6MvbLj692ljS3TwXWSkU1VLcXRX7sJp
	 8TfZGJmYf+AZOipqbQZ/CRQUrWzMN8zyUfJwrjgVYPMJ2fV0XhSyJ2caWggXhphi3HABm
	 HgkCdgMLUSlUNx4w07zRniBECNnDB8SERmpzK57LWeSf1pRJ5zNfQohP0OApvW6V1B2R5
	 BcmkfR85QfDYLuEsPaOM+4ZIJoVTJg9/iudI8FGlhM/VXzFB6VywPlChOvLTvQxQAyNEW
	 Rjuo3YbheEBRZuTBrgOU0HS3e2YOzTmiQYZg4MNN1E1022s81TE7vPcJXEO/S229AFA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=toke.dk;
	spf=pass smtp.mailfrom=toke.dk;
	arc=none smtp.remote-ip=45.145.95.4
X-Received: from mail.toke.dk (mail.toke.dk [45.145.95.4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 400A6606A319
	for <netdev@vger.kernel.org>; Tue, 20 Oct 2026 12:50:00 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 400A6606A319
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=toke.dk
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toke.dk
X-Authentication-Results: mail.toke.dk; dkim=none
X-Cc: Jamal Hadi Salim <jhs@mojatatu.com>, Björn Töpel
 <bjorn@kernel.org>,
 Jiri Pirko <jiri@resnulli.us>, "David S . Miller" <davem@davemloft.net>,
 Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>,
 Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
 cake@lists.bufferbloat.net, Victor Nogueira <victor@mojatatu.com>, Sashiko
 <sashiko-bot@kernel.org>
X-In-Reply-To: <QDISC-5RTM.v3.r0.20261020053711-1@mojatatu.com>
X-Clacks-Overhead: GNU Terry Pratchett
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list