🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23352

Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths

#23352
From: Xuanqiang Luo
Date: Fri, 27 Nov 2026 06:18
99 lines
14325 bytes
On 2026/11/26 at 17:48 gang.yan@linux.dev wrote:
> November 24, 2026 at 9:06 PM, "Xuanqiang Luo" <xuanqiang.luo@linux.dev mailto:xuanqiang.luo@linux.dev?to=%22Xuanqiang%20Luo%22%20%3Cxuanqiang.luo%40linux.dev%3E > wrote:
> 
> 
>>
>> From: Xuanqiang Luo <luoxuanqiang@kylinos.cn>
>>
>> With CONFIG_STACKPROTECTOR_STRONG=y, a function that has a local array or
>> passes the address of one of its locals to another function needs a stack
>> canary. The canary is set up and checked on every call, also when the
>> local is only used on a path that almost never runs.
>>
>> This series removes the canary from functions of the TCP/IPv4 fast paths,
>> by returning results by value, by using storage that is not on the stack,
>> or by not calling a function that has nothing to do.
>>
>> Patch 1 returns the two mptcp_space() values in a structure, so that
>> __tcp_select_window() no longer needs a canary.
>>
>> Patch 2 changes ip_neigh_gw4() to take a pointer to the address, like
>> ip_neigh_gw6(), so that ip_finish_output2() no longer needs a canary.
>>
>> Patch 3 uses pskb_may_pull() in icmp_filter(), so that
>> raw_local_deliver() no longer needs a canary.
>>
>> Patch 4 turns skb_try_coalesce() into an inline wrapper over a function
>> returning its results by value, so that its callers no longer need a
>> canary because of it.
>>
>> Patch 5 returns the result of the TCP receive coalescing by value, so
>> that tcp_rcv_established() and tcp_data_queue() no longer need a canary.
>>
>> Patch 6 calls bpf_skops_write_hdr_opt(), which needs a canary, only if a
>> BPF program reserved room for TCP options.
>>
>> The bloat-o-meter numbers are from gcc 16.2 on x86_64. The functions
>> named in patches 1 to 5 also lose their canary with clang 23.1.6 on
>> x86_64, with and without ThinLTO, and on arm64.
>>
> 
> Hi Xuanqiang,
> 
> Thanks for this series. Besides the code size, do you have any runtime perf
> numbers (TCP_RR, cycles per packet...)? I think it may help the maintainers
> judge the real gain.
Hi Gang,

I omitted runtime numbers from the cover letter because earlier cross-NIC
TCP_RR runs were within boot-to-boot noise, and I did not want to overstate
the gain. I re-ran the full 6-patch series against its base commit
(a4c450594f5d) in a tighter setup on an x86_64 server (Hygon C86-4G,
ConnectX-5 10GbE mlx5, GCC 12.3, CONFIG_STACKPROTECTOR_STRONG=y, identical
.config, nokaslr, boost off, isolated CPUs/IRQs, busy_read=0, 3 alternating
boots per kernel x 4 runs):

1. Single-CPU loopback 1-byte TCP_RR (both endpoints on 1 CPU running the
    kernel under test, 99.9% busy with no cross-CPU lock contention; each
    RR counts 2 TX + 2 RX = 4 Tcp InSegs+OutSegs):
    - instructions:k / tx:  33,562.3 -> 33,410.6 (-151.8, -0.45%, CV 0.01%)
    - instructions:k / seg:  8,372.8 ->  8,336.1 ( -36.8, -0.44%, CV 0.02%)
    - branches:k / tx:       7,627.9 ->  7,604.4 ( -23.5, -0.31%, CV 0.03%)
    - cycles:k / tx:        48,883.8 -> 48,613.8 (-270.0, -0.55%)
    - throughput:           52,804   -> 53,068 tps (+0.50%)

2. Cross-host 10GbE mlx5 8-flow 1-byte TCP_RR (server CPU-bound on 1 app
    CPU + 1 IRQ CPU, client pinned on a fixed peer kernel):
    - instructions:k / pkt: 12,040.6 -> 11,946.0 ( -94.6, -0.79%, CV 0.43%)
    - cycles:k / pkt:       19,652.2 -> 19,450.1 (-202.1, -1.03%, CV 0.52%)
    - throughput:           79,455   -> 79,883 tps (+0.54%)

3. Loopback small-write TCP_STREAM (-m 512 -D, 2 CPUs):
    - instructions:k / seg:  5,805.6 ->  5,713.7 ( -91.9, -1.58%)
    - cycles:k / seg:        8,538.5 ->  8,416.8 (-121.7, -1.42%)
    - throughput:            641.8   ->  650.5 Mbit/s (+1.37%)
    (Note: in the 2-CPU / multi-flow cases above, perf shows part of the
     larger per-packet drop comes from fewer spinlock-slowpath and idle-loop
     samples in addition to the direct TCP path savings; test 1 isolates
     the direct instruction/branch reduction.)

4. perf record (cycles:k and instructions:k) confirms
    bpf_skops_write_hdr_opt() drops from 0.04-0.12% to 0.00% across all
    profiled workloads, with consistent drops in tcp_rcv_established(),
    __tcp_transmit_skb(), and __tcp_select_window().

One caveat to be transparent: on a loopback 1-byte UDP_RR control (which
only exercises patch 2's ip_finish_output2() canary removal),
instructions:k/tx changed by the expected -23.2 insns/tx (-0.07%) and
branches:k/tx was flat (+0.02%), yet wall-clock tps/cycles still shifted
by -0.80%/+0.68% due to fixed code-layout/IPC differences under nokaslr.

So the reliable runtime signal here is the deterministic drop in kernel
instructions and branches (~152 insns / ~23.5 branches per loopback TCP_RR)
and the disappearance of bpf_skops_write_hdr_opt() from the profile, while
wall-clock TCP_RR tps/cycles (~0.5%) remain in the same range as
code-alignment effects on this machine.

Thanks,
Xuanqiang
Technical Details
Message-ID: <d5c55d47-8651-4c75-a0b6-2734a1394a9e@linux.dev>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372477-linux-kernel-netdev=dewy.ru
References: <20261124130631.1886963-1-xuanqiang.luo@linux.dev> <133c1ca98af6beb48c0db1e6bb539a2a76ccda49@linux.dev>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372477-linux-kernel-netdev=dewy.ru
From: xuanqiang.luo@linux.dev (Xuanqiang Luo)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4
 fast paths
Date: Fri, 27 Nov 2026 15:18:02 +0900
Organization: Usenet Network
Message-ID: <d5c55d47-8651-4c75-a0b6-2734a1394a9e@linux.dev>
References: <20261124130631.1886963-1-xuanqiang.luo@linux.dev>
 <133c1ca98af6beb48c0db1e6bb539a2a76ccda49@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="655538"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7DYwwZ8HKOC++pq7SgHpcH3mLUE= sha256:wP+IWiaXMr0LZRZiPfO0o1MLNpB9XZ5Xe0TGCGpoXTw=
	sha1:qO3mCNHvCl9YeVGc+NMHe62OXGM= sha256:Zh6WSFADdfn3Au4VL0jF/9tac/t6mYug1GPavxXOdw4=
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 C59E9125F11; Fri, 27 Nov 2026 09:18:43 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.151
X-Spam-Status: No, score=-3.151 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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 (1024-bit key)
	header.d=linux.dev
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 mNjd-nhh5RZZ;
	Fri, 27 Nov 2026 09:18:40 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-372477-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 95FE4125F0D; Fri, 27 Nov 2026 09:18:30 +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 B61BA2FE2F; Fri, 27 Nov 2026 06:18:28 +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=1795760308;
	b=hO8SaviJj3Db9DiHM6bwcG3dAYC7aZuEqMolxES1zAEPlf2WZa0sM46jBFLIz+XoCFW0
	 I7xX61N3YZXA+ED8qXjIcawus+BnVp9ClazjC76yHwqqGS6oYncaBJiYqvXv0F7iPcCZ5
	 YcKttNC0fGhmjwD59j2wO4IWiEeA0KP1kJjuC+tiMaGNCQLQVhS2xLVzIyMYOQ2Ejyi/F
	 c7mALYuBQCc+a6v0IUVBRQ25tTaxQfqi+Wz1OtUrSAmDxCZ3ZMm6vOGg7Sob51mw356DK
	 tSMZ/zVUbWLby+cXNqkENUfWhS1CISBHWOJUmR9Bm/3mBvSVR4JrIOA5USojoF/kTjQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795760308;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=Xall2LvYqrNEWJ3haGr3baDKY0fqS4yjvxamjxNnjGY=;
	b=VvaSec/nvO9jpB/ekVGpm1Gzu74fhKiJZ26jET/RYI1vVPiJVXWbdNrXIjb1FcAmKd/Q
	 bSIAMbxRoMUA5jcldSAioUlsMKMt+ZSroUdi1m8BozBJ238MqUXJGZHXw5X+Y8g2b8De2
	 U2WDY3gnlUgcGgiKRo/mCULobby4VsUH7K17ypQ4SFK3g8ULlgEeiDvbrchKXql9yaWSd
	 Ig4W+BWGvCWiLSGUoIT7BacI6B0d3omuMUrFVopjsymQjd4UMtY67xylnxKmmoVdt+z6H
	 pnjPLQQL1Rq9CafzP1RyEzbELb1fac5KApGDIANx8eHEb8TgQ6qcUZQAgTRz93LmxMQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sKr55MTO;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 DD918606A332;
	Fri, 27 Nov 2026 06:18:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sKr55MTO
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795760307;
	b=RaPJ8kdRqylIl1y8y3wPbIHlXArFTs/hoPkyDCQ87alDoGlwfRHx3wK4o9ySkPnTWV+h
	 5Ez64rlOrUuqdxQQcNieqkcdLpOvS7ZeYE/xIqDNSgHho/gBU/+xt7RwMGo2/f3EYb6eY
	 ff/AJTm2oh48G6t2uKTyf47TtV6phQwBP0XsKf2PVskLX1/SAg0XhRJlb7395oh2xuAdy
	 cOkbNXadbaP2eh0rTj3YkmQbJ7Ew3JYWtJhs1gJjFTVUAU6PQrHbaYaJtiE0mecssGdrx
	 uFGHTjsJXNEPTasgelOfnVMJqwzmBRDmKp5EhJhAIKdbvmd1AQ5MwtmUF4YszuFsVbw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795760307;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=Xall2LvYqrNEWJ3haGr3baDKY0fqS4yjvxamjxNnjGY=;
	b=E5zIdocz8agGxPSOD6iY5jFV4mdG1/71Ael56TQgviDPY402FTGV2jNVAtOjaTm/fb3A
	 FGRazexEW/MXeZyH131quraeo6OnKjWL9XI886Djq78m7cR6S++Xnt2aRhaBa6OGnWOmI
	 8hHxp0CFeSsDhvFh0CvS+jKZBcAOlx7rrKxHUhjE7cKqEO2FLKBQikdJ92IDj8rke0i/Q
	 VHZN5E5M/PLq7C/14j0QF7fcyIrGuGxVyJAucXkZ1aBjk38PrseILom3baZVCr4KeF/Qg
	 3uYXHqvR8WLwVpbdYk7wuxNOh3863Zu0frBapdTMJET3NvYLWR4ScVPrjbwJc+2i1RA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sKr55MTO;
	arc=none smtp.remote-ip=91.218.175.47
X-Received: from mta0.migadu.com (out-47.mta0.migadu.com [91.218.175.47])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 263C9606A31C
	for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 06:18:25 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 263C9606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=kS24aWEDVFAGZg9av7QpzpXRdTf89yuZQQWrd8Pe7YI=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795760304; v=1; x=1796365104;
 b=sKr55MTON/+6jrOYoyP4mbHJKogHVXu9Sy8xuEmw89uAYd4PLeivI6FcOlRQwTBLAeu3cSVF
 uh7hEohrUeSmHTgPd+SFC4C0L1YiokNOradNPZrh86Ik6+ihBWo4j2q8XICHqB01t4IjwRlu1z1
 xSzqw+oyTwgaacapk//YEWLo=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id 7a6dd275991888ae;
	Fri, 27 Nov 2026 06:18:24 +0000
X-Mizu-Trace-ID: 7a6dd275991888ae
X-Migadu-Flow: FLOW_OUT
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
X-User-Agent: Mozilla Thunderbird
X-Cc: "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>,
 Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>,
 John Fastabend <john.fastabend@gmail.com>,
 Andrii Nakryiko <andrii@kernel.org>, Eduard Zingerman <eddyz87@gmail.com>,
 Kumar Kartikeya Dwivedi <memxor@gmail.com>,
 Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>,
 Yonghong Song <yonghong.song@linux.dev>, Jiri Olsa <jolsa@kernel.org>,
 Emil Tsalapatis <emil@etsalapatis.com>,
 Ihor Solodrai <ihor.solodrai@linux.dev>, Matthieu Baerts
 <matttbe@kernel.org>, Mat Martineau <martineau@kernel.org>,
 Geliang Tang <geliang@kernel.org>, David Ahern <dsahern@kernel.org>,
 Ido Schimmel <idosch@nvidia.com>, Stanislav Fomichev <sdf@fomichev.me>,
 Neal Cardwell <ncardwell@google.com>, Kuniyuki Iwashima <kuniyu@google.com>,
 Pablo Neira Ayuso <pablo@netfilter.org>, Florian Westphal <fw@strlen.de>,
 Phil Sutter <phil@nwl.cc>, bpf@vger.kernel.org,
 linux-kernel@vger.kernel.org, mptcp@lists.linux.dev,
 netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
 Xuanqiang Luo <luoxuanqiang@kylinos.cn>, david.laight.linux@gmail.com
X-In-Reply-To: <133c1ca98af6beb48c0db1e6bb539a2a76ccda49@linux.dev>