* [PATCH net-next] tcp: change bpf_skops_hdr_opt_len() signature
@ 2026-06-01 9:38 Eric Dumazet
2026-06-01 15:41 ` Stanislav Fomichev
2026-06-01 18:22 ` Kuniyuki Iwashima
0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2026-06-01 9:38 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, Neal Cardwell, Kuniyuki Iwashima, netdev,
eric.dumazet, Eric Dumazet
Some compilers do not inline bpf_skops_hdr_opt_len() from
tcp_established_options(), forcing an expensive stack canary
when CONFIG_STACKPROTECTOR_STRONG=y.
Change bpf_skops_hdr_opt_len() to return @remaining by value
to remove this stack canary from TCP fast path.
$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
add/remove: 0/0 grow/shrink: 1/1 up/down: 10/-59 (-49)
Function old new delta
bpf_skops_hdr_opt_len 297 307 +10
tcp_established_options 574 515 -59
Total: Before=31456795, After=31456746, chg -0.00%
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
net/ipv4/tcp_output.c | 51 +++++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
index 31b459ecbe8307a8660623038fea6fa7b0860f7f..d3b8e61d3c5e7fb2723950b4d29aca535378df40 100644
--- a/net/ipv4/tcp_output.c
+++ b/net/ipv4/tcp_output.c
@@ -466,22 +466,22 @@ static int bpf_skops_write_hdr_opt_arg0(struct sk_buff *skb,
}
/* req, syn_skb and synack_type are used when writing synack */
-static void bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
- struct request_sock *req,
- struct sk_buff *syn_skb,
- enum tcp_synack_type synack_type,
- struct tcp_out_options *opts,
- unsigned int *remaining)
+static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
+ struct request_sock *req,
+ struct sk_buff *syn_skb,
+ enum tcp_synack_type synack_type,
+ struct tcp_out_options *opts,
+ u32 remaining)
{
struct bpf_sock_ops_kern sock_ops;
int err;
if (likely(!BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) ||
- !*remaining)
- return;
+ !remaining)
+ return remaining;
- /* *remaining has already been aligned to 4 bytes, so *remaining >= 4 */
+ /* remaining has already been aligned to 4 bytes, so remaining >= 4 */
/* init sock_ops */
memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));
@@ -513,21 +513,21 @@ static void bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
}
sock_ops.args[0] = bpf_skops_write_hdr_opt_arg0(skb, synack_type);
- sock_ops.remaining_opt_len = *remaining;
+ sock_ops.remaining_opt_len = remaining;
/* tcp_current_mss() does not pass a skb */
if (skb)
bpf_skops_init_skb(&sock_ops, skb, 0);
err = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
- if (err || sock_ops.remaining_opt_len == *remaining)
- return;
+ if (err || sock_ops.remaining_opt_len == remaining)
+ return remaining;
- opts->bpf_opt_len = *remaining - sock_ops.remaining_opt_len;
+ opts->bpf_opt_len = remaining - sock_ops.remaining_opt_len;
/* round up to 4 bytes */
opts->bpf_opt_len = (opts->bpf_opt_len + 3) & ~3;
- *remaining -= opts->bpf_opt_len;
+ return remaining - opts->bpf_opt_len;
}
static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
@@ -575,13 +575,14 @@ static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
max_opt_len - nr_written);
}
#else
-static void bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
- struct request_sock *req,
- struct sk_buff *syn_skb,
- enum tcp_synack_type synack_type,
- struct tcp_out_options *opts,
- unsigned int *remaining)
+static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
+ struct request_sock *req,
+ struct sk_buff *syn_skb,
+ enum tcp_synack_type synack_type,
+ struct tcp_out_options *opts,
+ u32 remaining)
{
+ return remaining;
}
static void bpf_skops_write_hdr_opt(struct sock *sk, struct sk_buff *skb,
@@ -1050,7 +1051,8 @@ static unsigned int tcp_syn_options(struct sock *sk, struct sk_buff *skb,
remaining -= tcp_options_fit_accecn(opts, 0, remaining);
}
- bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts, &remaining);
+ remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
+ remaining);
return MAX_TCP_OPTION_SPACE - remaining;
}
@@ -1137,8 +1139,8 @@ static unsigned int tcp_synack_options(const struct sock *sk,
remaining -= tcp_options_fit_accecn(opts, 0, remaining);
}
- bpf_skops_hdr_opt_len((struct sock *)sk, skb, req, syn_skb,
- synack_type, opts, &remaining);
+ remaining = bpf_skops_hdr_opt_len((struct sock *)sk, skb, req, syn_skb,
+ synack_type, opts, remaining);
return MAX_TCP_OPTION_SPACE - remaining;
}
@@ -1228,7 +1230,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG))) {
unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
- bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts, &remaining);
+ remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
+ remaining);
size = MAX_TCP_OPTION_SPACE - remaining;
}
--
2.54.0.1013.g208068f2d8-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] tcp: change bpf_skops_hdr_opt_len() signature
2026-06-01 9:38 [PATCH net-next] tcp: change bpf_skops_hdr_opt_len() signature Eric Dumazet
@ 2026-06-01 15:41 ` Stanislav Fomichev
2026-06-01 18:22 ` Kuniyuki Iwashima
1 sibling, 0 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2026-06-01 15:41 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
Neal Cardwell, Kuniyuki Iwashima, netdev, eric.dumazet
On 06/01, Eric Dumazet wrote:
> Some compilers do not inline bpf_skops_hdr_opt_len() from
> tcp_established_options(), forcing an expensive stack canary
> when CONFIG_STACKPROTECTOR_STRONG=y.
>
> Change bpf_skops_hdr_opt_len() to return @remaining by value
> to remove this stack canary from TCP fast path.
>
> $ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
> add/remove: 0/0 grow/shrink: 1/1 up/down: 10/-59 (-49)
> Function old new delta
> bpf_skops_hdr_opt_len 297 307 +10
> tcp_established_options 574 515 -59
> Total: Before=31456795, After=31456746, chg -0.00%
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] tcp: change bpf_skops_hdr_opt_len() signature
2026-06-01 9:38 [PATCH net-next] tcp: change bpf_skops_hdr_opt_len() signature Eric Dumazet
2026-06-01 15:41 ` Stanislav Fomichev
@ 2026-06-01 18:22 ` Kuniyuki Iwashima
1 sibling, 0 replies; 3+ messages in thread
From: Kuniyuki Iwashima @ 2026-06-01 18:22 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
Neal Cardwell, netdev, eric.dumazet
On Mon, Jun 1, 2026 at 2:38 AM Eric Dumazet <edumazet@google.com> wrote:
>
> Some compilers do not inline bpf_skops_hdr_opt_len() from
> tcp_established_options(), forcing an expensive stack canary
> when CONFIG_STACKPROTECTOR_STRONG=y.
>
> Change bpf_skops_hdr_opt_len() to return @remaining by value
> to remove this stack canary from TCP fast path.
>
> $ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
> add/remove: 0/0 grow/shrink: 1/1 up/down: 10/-59 (-49)
> Function old new delta
> bpf_skops_hdr_opt_len 297 307 +10
> tcp_established_options 574 515 -59
> Total: Before=31456795, After=31456746, chg -0.00%
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-01 18:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-01 9:38 [PATCH net-next] tcp: change bpf_skops_hdr_opt_len() signature Eric Dumazet
2026-06-01 15:41 ` Stanislav Fomichev
2026-06-01 18:22 ` Kuniyuki Iwashima
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox