From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796403775; b=MawIS6AxQmHJeCE/L153/NXIrahMTDv1yw3nX3Z8d61rV5W2rkoPGbiiDREH9eLIhBDH JwKTcvlva+WZby0aLN9wpAaHv1Lm6suvZRkBrkWXS2Xmu62mX63Lsm7Vw5nfknDsIY6zS R12y4t67tYPVNgp05fqbjqwc517TaZi3qDCJ7Xt1ZteqNzHujXsaHtQiowNErVRzl0rdh mrq5TsZDxS36gJqIZ5l3Ud9tDGD8DnN4cMb0LHkqcD1tw3/SULPJFQin+/DQijfcY+sME /0nQ8+GjYO4PxdG125cQWKmRc1zZkf2BF8H71LodKEUCm/x0cCQr9RD8e744PsfIl8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796403775; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=DtjY2dd+NFR+xqiURxIUX9aBDHFLn2UWlq2hfF/zN0c=; b=35BVgEycNu36MYIJlr8kI2YgRBde7KExyzoQAiMGZvYlfXF2m4b34tTg/Fmn7e8Yesh2 w4P+yp3vK4+gzMechhqyOhVYg8C60R3zSYmduS4FyMyyPYtMHLKLOIZbTOHxa5rg37SOT KT9tIjpTVj94ZYG8klTrGqMUNvkFqHTgx5hzlPRtcK6IwJ7jJ8avKaJ23bNqSbyO+TWxY q+8g6ajvxX1kQfI1StyCU5GTOG2HV3VQ6QiLuiImawtGX5uEm8j8Y3jehRUOeTv3I5mw9 rqJYEWF7EL2d7VD9qWD+t4GbhXFR4EoPDiZpbsNiQXcstdFWo0YlqWGmRNvMt3ZTicg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kV4i0v9k; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDE9C606A322; Fri, 4 Dec 2026 17:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kV4i0v9k Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12DC01F00A0F; Fri, 4 Dec 2026 17:02:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796403775; bh=DtjY2dd+NFR+xqiURxIUX9aBDHFLn2UWlq2hfF/zN0c=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=kV4i0v9kyn4GF7CxpO6KbPAIGLln/abdkGfOHvE+dlYyrCN3nWofvwPrybYC95j7D CFg1Z0ag/7MT+MvwLUC2R069/blVd3rHNJl97ZQnQ0y43ZXgIMmd95UnsWyuSYkQb4 u/P/wF6pjH+ZIWEyZusNgjTL+RpRT2MLgI7w8HCeZg6OC/O8ziYIVkzpNzrUUMQDCk HkJhdUuRcFPc60UEaLF+l0ZOtF/2rhUqVQXLxTgeLcrsOOes2FTESFbG9V5p/ECmba NTgTEG1ktMc4NTap2wonrwVv2JIRH37+veF51tK3GnTjE7OMjgk61ywxEjB+RkL6Yv hrPPgbD/lI1yQ== Date: Fri, 4 Dec 2026 17:02:46 +0000 From: Simon Horman To: David Laight Cc: Xuanqiang Luo , netdev@vger.kernel.org, "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Matthieu Baerts , Mat Martineau , Geliang Tang , David Ahern , Ido Schimmel , Stanislav Fomichev , Neal Cardwell , Kuniyuki Iwashima , Pablo Neira Ayuso , Florian Westphal , Phil Sutter , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, mptcp@lists.linux.dev, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Xuanqiang Luo Subject: Re: [PATCH net-next v1 0/6] net: avoid stack canaries in TCP/IPv4 fast paths Message-ID: <20261204170246.GA192805@horms.kernel.org> References: <20261124130631.1886963-1-xuanqiang.luo@linux.dev> <20261126102058.1fecf50f@pumpkin> <20261127104100.3c915088@pumpkin> X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127104100.3c915088@pumpkin> On Fri, Nov 27, 2026 at 10:41:00AM +0000, David Laight wrote: > On Fri, 27 Nov 2026 15:33:15 +0900 > Xuanqiang Luo wrote: > > > On 2026/11/26 at 19:20 David Laight wrote: > > > On Tue, 24 Nov 2026 22:06:25 +0900 > > > Xuanqiang Luo wrote: > > > > > >> From: Xuanqiang Luo > > >> > > >> 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. > > > > > > While all (I think) architectures can return a big integer in two > > > registers (dx:ax on x86), not all ABI do the same for small structures. > > > For those architectures returning a struct by value is implemented by > > > passing the address of a hidden on stack structure. > > > So code generation may be worse than passing the values by reference. > > > I can't remember the list of architectures, mostly old ones - but not > > > 32bit x86 because the compiler option was set when regparm=3 was added > > > for 2.6. > > > (Note that this is different from passing small structures by value.) > > > > > > David > > > > Hi David, > > > > Good point! thanks for bringing that up. > > > > The small-struct-by-value pattern in patches 1 and 4 follows the same > > approach Eric used in commit 7a4cd71fa451 ("net: add > > vlan_get_protocol_offset_inline() helper"), which returns a 2-field > > struct vlan_type_depth to avoid stack canaries in callers. > > > > I did note the 8-byte struct ABI distinction you mentioned: > > - On the main 64-bit targets (x86_64, arm64, riscv64, ppc64le, loongarch64) > > as well as 32-bit x86 (with -mregparm=3 / reg-struct-return), both > > 8-byte structs (struct mptcp_space_info and struct skb_coalesce_res) are > > returned in registers and the stack canaries are dropped cleanly. > > - On ABIs that return structs (> 4 bytes on 32-bit ARM EABI, or any struct > > on s390x) via a hidden stack buffer, it indeed falls back to a hidden > > pointer. Even there, the callers previously passed *two* pointers to > > locals (&space/&full_space in patch 1, &fragstolen/&delta_truesize in > > patch 4), so passing one hidden 8-byte return slot should not be worse > > than before, while keeping the code cleaner and type-safe. > > There might be a subtle difference in the function itself. > I think the result structure gets allocated on stack and then a memcpy() > used to copy that to the caller's buffer during the function return. > That may, or may not, be faster. > > > > > That said, if maintainers prefer packing the two fields into a u64 so that > > even 32-bit ARM / s390x return them in registers, I'd be happy to change > > patches 1 and 4 to do that in v2. > > That is horrid ... and you'd need to use a u128 on 64bit. > It really is a shame that C doesn't have a syntax for returning 2 integers > even though pretty much all ABI have always supported it. I think this patch-set takes the right approach. For the series: Reviewed-by: Simon Horman