Skip to content

Commit ceac8db

Browse files
edumazetkuba-moo
authored andcommitted
tcp: change bpf_skops_hdr_opt_len() signature
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> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20260601093819.469626-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent c0b3005 commit ceac8db

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

net/ipv4/tcp_output.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -466,22 +466,22 @@ static int bpf_skops_write_hdr_opt_arg0(struct sk_buff *skb,
466466
}
467467

468468
/* req, syn_skb and synack_type are used when writing synack */
469-
static void bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
470-
struct request_sock *req,
471-
struct sk_buff *syn_skb,
472-
enum tcp_synack_type synack_type,
473-
struct tcp_out_options *opts,
474-
unsigned int *remaining)
469+
static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
470+
struct request_sock *req,
471+
struct sk_buff *syn_skb,
472+
enum tcp_synack_type synack_type,
473+
struct tcp_out_options *opts,
474+
u32 remaining)
475475
{
476476
struct bpf_sock_ops_kern sock_ops;
477477
int err;
478478

479479
if (likely(!BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk),
480480
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG)) ||
481-
!*remaining)
482-
return;
481+
!remaining)
482+
return remaining;
483483

484-
/* *remaining has already been aligned to 4 bytes, so *remaining >= 4 */
484+
/* remaining has already been aligned to 4 bytes, so remaining >= 4 */
485485

486486
/* init sock_ops */
487487
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,
513513
}
514514

515515
sock_ops.args[0] = bpf_skops_write_hdr_opt_arg0(skb, synack_type);
516-
sock_ops.remaining_opt_len = *remaining;
516+
sock_ops.remaining_opt_len = remaining;
517517
/* tcp_current_mss() does not pass a skb */
518518
if (skb)
519519
bpf_skops_init_skb(&sock_ops, skb, 0);
520520

521521
err = BPF_CGROUP_RUN_PROG_SOCK_OPS_SK(&sock_ops, sk);
522522

523-
if (err || sock_ops.remaining_opt_len == *remaining)
524-
return;
523+
if (err || sock_ops.remaining_opt_len == remaining)
524+
return remaining;
525525

526-
opts->bpf_opt_len = *remaining - sock_ops.remaining_opt_len;
526+
opts->bpf_opt_len = remaining - sock_ops.remaining_opt_len;
527527
/* round up to 4 bytes */
528528
opts->bpf_opt_len = (opts->bpf_opt_len + 3) & ~3;
529529

530-
*remaining -= opts->bpf_opt_len;
530+
return remaining - opts->bpf_opt_len;
531531
}
532532

533533
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,
575575
max_opt_len - nr_written);
576576
}
577577
#else
578-
static void bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
579-
struct request_sock *req,
580-
struct sk_buff *syn_skb,
581-
enum tcp_synack_type synack_type,
582-
struct tcp_out_options *opts,
583-
unsigned int *remaining)
578+
static u32 bpf_skops_hdr_opt_len(struct sock *sk, struct sk_buff *skb,
579+
struct request_sock *req,
580+
struct sk_buff *syn_skb,
581+
enum tcp_synack_type synack_type,
582+
struct tcp_out_options *opts,
583+
u32 remaining)
584584
{
585+
return remaining;
585586
}
586587

587588
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,
10501051
remaining -= tcp_options_fit_accecn(opts, 0, remaining);
10511052
}
10521053

1053-
bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts, &remaining);
1054+
remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
1055+
remaining);
10541056

10551057
return MAX_TCP_OPTION_SPACE - remaining;
10561058
}
@@ -1137,8 +1139,8 @@ static unsigned int tcp_synack_options(const struct sock *sk,
11371139
remaining -= tcp_options_fit_accecn(opts, 0, remaining);
11381140
}
11391141

1140-
bpf_skops_hdr_opt_len((struct sock *)sk, skb, req, syn_skb,
1141-
synack_type, opts, &remaining);
1142+
remaining = bpf_skops_hdr_opt_len((struct sock *)sk, skb, req, syn_skb,
1143+
synack_type, opts, remaining);
11421144

11431145
return MAX_TCP_OPTION_SPACE - remaining;
11441146
}
@@ -1227,7 +1229,8 @@ static unsigned int tcp_established_options(struct sock *sk, struct sk_buff *skb
12271229
BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG))) {
12281230
unsigned int remaining = MAX_TCP_OPTION_SPACE - size;
12291231

1230-
bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts, &remaining);
1232+
remaining = bpf_skops_hdr_opt_len(sk, skb, NULL, NULL, 0, opts,
1233+
remaining);
12311234

12321235
size = MAX_TCP_OPTION_SPACE - remaining;
12331236
}

0 commit comments

Comments
 (0)