From nobody Thu Apr 16 02:00:59 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E76133803E2 for ; Tue, 3 Mar 2026 07:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772524142; cv=none; b=O96FJ/H73E6IHsMYIuqdug2l9CBtbV8wrVart0ChB8RRDyGjtQXUUoTZoQb/qW8pPQFJAOEX3F+3M22Qgcu3vXOTSSJSe1z3y+AOIxc5Bm8ZfmC4lgP/WhcrKzZ+TMCzgdveS/s60KLP+LT+1A0HjacUidgzltyriqzB0hN/8To= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772524142; c=relaxed/simple; bh=/EwBHS+MulbJHdk14Rvjdo5dRfJFU8A5WHKgAg3MG3Y=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=HofzkASYmDrDOu/razONx/KPTVG/4zrLM8vdbe+kVp5KWmEmo/3F9ALN7ysZrP1U3PXcKPLpiZHNienck72bAc8mDDmOnsex9RX8tnz6kySVA4RzZxhEtaKCqEa5bTfHslbCE/IiFiWYdwyf8muXnXNSST4+a31NXaCAfqAYzZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QV4mZsgC; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QV4mZsgC" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c70f91776fcso2093727a12.0 for ; Mon, 02 Mar 2026 23:49:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772524140; x=1773128940; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NB1o9BGlkqLq/oNw4ApXQsql6klhqpWH7aXO0uKuMWk=; b=QV4mZsgCQdV46iKkv1BlcLaK/yjp4NrlUHot2tFGC6OorwWR9zecipTBUVSx/K3aut NpUo27OwOOgCsy+G/C8/Z9KzOe3bUAGPEQhVDY4epzN/ZGoOY70wdnFsQomDgmVW3ZjF BfP4mg9xloQ5lWEMJW0jnYNIntEs18GWyoZm79T6BdtWHfVnLnaS3K3JJ5XzpOIuhCT4 FymccYK1GOpjbgHHa/iiP+T009Vp/lOjDEbpAkVibvoxbHzUfp1CH9csotTUL2tN48k8 mJVskD2y6o6DcfyzjgT1lMX/oob2lyCgAvJUvOCThGffBSCyBeIAjzA1KaeCLYrdaGTT VIqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772524140; x=1773128940; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NB1o9BGlkqLq/oNw4ApXQsql6klhqpWH7aXO0uKuMWk=; b=vjtdRpPBMdK5SJLfeebNzIPvYm7CaAa1KTv/6Ntg0RDWIeF/tFBey59C35Y3my5t/R p02STXfEZzcMaECUdYESn30U7RDahpKv6hBTOC9k7xvl10cRyS9RpTj7WA016k3sPj3d XBX0fBdjtDk8JZZTuuJG2mT/rvf6LCJhIqQuV6RH5voWyk9Nj6+8+7x5/c+IwOPQ7RjU Jo7s8p8JP6DOdccBhwj+Fw+QUncDycHOdsvkIr8najEKnUe8zSWRYbm4M4jHwaM1khVN kUdv5GZjnamoxKPCwNcChPMwxKSLh7bqMC67oFglBCW1WgSoKfBCvt5uNRkJ6lZXFZMj ROTg== X-Forwarded-Encrypted: i=1; AJvYcCWW/OTPvoEk/8dtV30kNNOlFcSPQzx8bitM08CBbwt61/FUty4RDBV+mQNxnnP+wHTjtSVFnAf60KXRjk4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx60P8BKXxCeUUwXg6EvQZocybCz2Jy+osfzOc1GnanKP8n3Kkg cVIRPfIwMoFSijP5Egws+vCKb2eY2FXNq3OlvyvMVmLRerruFFz6uvjF X-Gm-Gg: ATEYQzyn1h4D+Kw8Ef6fY+cKHGhs6MeYh6VrYMNXSIq+uRbk8F2XmbrpST0wh8BmHPf hLCYQ5L1ntpbJ5l6Grt5qqOyjVcHCgcCZncKbUp8153shWypXXSEgZTvAIP6Wo0TTN8b9UFyWNz kAoJWqiO20PgGa0Vfhz44hA3sMyA1bbA25ty/t8xY/nKFvXKnjSE/5frJLb4IRBPCdifeRc9/wq qUOQkDqJD+t8tmiF4rRV4XB9rH8zKwQeZnuvHcb31NRKi3dApl3PHGhuXtWy3XQltEQNxGxL0lv Nl23Fg3YInW2TO+P7CuWqjyt64jhcudkEii65PZpjXJzYYv0dHQxZRtAcu5qEnAJo5stkYFQmQR Nd0zD2uggSvO00EmIYmM/TtdZ0G50YQdml8dzOKZarj+aaFq3fwc/ohXzJV869jUZ0aeneztNl8 h21YrLUHaLvcPXzLIeBr01ObklzFerwUFYmZdWPHCqRe7Ri0F6vcOaiqoSuldP3a4XwY3XWdqYH PHIWc6dbcBe X-Received: by 2002:a05:6a21:1bc3:b0:38d:efcb:2e99 with SMTP id adf61e73a8af0-395c3a4a2a8mr14271672637.22.1772524140121; Mon, 02 Mar 2026 23:49:00 -0800 (PST) Received: from dpc2500057.. (fsb6a9315e.tkyc502.ap.nuro.jp. [182.169.49.94]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c70fa806295sm13731037a12.16.2026.03.02.23.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 23:48:59 -0800 (PST) From: Keita Morisaki To: Eric Dumazet , Neal Cardwell , "David S . Miller" , David Ahern , Jakub Kicinski , Paolo Abeni Cc: Kuniyuki Iwashima , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Keita Morisaki Subject: [PATCH net-next] tcp: replace per-packet memset in __tcp_transmit_skb() Date: Tue, 3 Mar 2026 16:48:47 +0900 Message-Id: <20260303074847.2814835-1-kmta1236@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Replace memset(&opts, 0, sizeof(opts)) with targeted initialization of only the three fields read unconditionally by tcp_options_write() and bpf_skops_write_hdr_opt(): mss, num_sack_blocks, and bpf_opt_len. struct tcp_out_options is 40 bytes without MPTCP and 96 bytes with CONFIG_MPTCP=3Dy (typical distro config). Every remaining field is either assigned before first use by tcp_established_options()/tcp_syn_options(), or gated behind its OPTION_* flag in tcp_options_write(). This memset runs on every transmitted TCP packet, so removing it reduces per-packet overhead on the hot path. Assembly comparison (x86-64, GCC 13, CONFIG_MPTCP=3Dn): Before: 5 store instructions zeroing 40 bytes After: 3 store instructions zeroing 4 bytes With CONFIG_MPTCP=3Dy the savings are larger: 12 stores (96 bytes) become 3 stores (4 bytes). A BUILD_BUG_ON guards against future field additions: if the struct size changes, the assertion fires and forces the developer to audit whether the new field needs explicit zeroing. Also add opts->options =3D 0 at the top of tcp_syn_options(), which already used |=3D without a prior clear. tcp_established_options() already clears opts->options at its top. Signed-off-by: Keita Morisaki --- net/ipv4/tcp_output.c | 16 ++++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 326b58ff1118d..ae04c697dbacc 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -965,6 +965,8 @@ static unsigned int tcp_syn_options(struct sock *sk, st= ruct sk_buff *skb, struct tcp_fastopen_request *fastopen =3D tp->fastopen_req; bool timestamps; + opts->options =3D 0; + /* Better than switch (key.type) as it has static branches */ if (tcp_key_is_md5(key)) { timestamps =3D false; @@ -1549,7 +1551,20 @@ static int __tcp_transmit_skb(struct sock *sk, struc= t sk_buff *skb, inet =3D inet_sk(sk); tcb =3D TCP_SKB_CB(skb); - memset(&opts, 0, sizeof(opts)); + /* Only zero fields read unconditionally by tcp_options_write() + * or bpf_skops_write_hdr_opt(). Other fields are set by + * tcp_established_options()/tcp_syn_options() before use, or + * gated behind their OPTION_* flag. + * + * If you add a field to tcp_out_options, this will fire =E2=80=94 + * audit whether the new field needs zeroing here. + */ + BUILD_BUG_ON(sizeof(opts) !=3D + sizeof(struct mptcp_out_options) + 40); + opts.mss =3D 0; + opts.num_sack_blocks =3D 0; + opts.bpf_opt_len =3D 0; tcp_get_current_key(sk, &key); if (unlikely(tcb->tcp_flags & TCPHDR_SYN)) { base-commit: 7dff99b354601e04378b4490e1b1b5765a3c3a88 -- 2.43.0