Skip to content

Commit

Permalink
tcp: support TCP_DELACK_MAX_US for set/getsockopt use
Browse files Browse the repository at this point in the history
Support adjusting/reading delayed ack max for socket level by using
set/getsockopt().

This option aligns with TCP_BPF_DELACK_MAX usage. Considering that bpf
option was implemented before this patch, so we need to use a standalone
new option for pure tcp set/getsockopt() use.

Add WRITE_ONCE/READ_ONCE() to prevent data-race if setsockopt()
happens to write one value to icsk_delack_max while icsk_delack_max is
being read.

Signed-off-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250317120314.41404-3-kerneljasonxing@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jason Xing authored and Jakub Kicinski committed Mar 25, 2025
1 parent f38805c commit 9552f90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/uapi/linux/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ enum {
#define TCP_IS_MPTCP 43 /* Is MPTCP being used? */
#define TCP_RTO_MAX_MS 44 /* max rto time in ms */
#define TCP_RTO_MIN_US 45 /* min rto time in us */
#define TCP_DELACK_MAX_US 46 /* max delayed ack time in us */

#define TCP_REPAIR_ON 1
#define TCP_REPAIR_OFF 0
Expand Down
13 changes: 12 additions & 1 deletion net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3353,7 +3353,7 @@ int tcp_disconnect(struct sock *sk, int flags)
icsk->icsk_probes_tstamp = 0;
icsk->icsk_rto = TCP_TIMEOUT_INIT;
WRITE_ONCE(icsk->icsk_rto_min, TCP_RTO_MIN);
icsk->icsk_delack_max = TCP_DELACK_MAX;
WRITE_ONCE(icsk->icsk_delack_max, TCP_DELACK_MAX);
tp->snd_ssthresh = TCP_INFINITE_SSTHRESH;
tcp_snd_cwnd_set(tp, TCP_INIT_CWND);
tp->snd_cwnd_cnt = 0;
Expand Down Expand Up @@ -3841,6 +3841,14 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
WRITE_ONCE(inet_csk(sk)->icsk_rto_min, rto_min);
return 0;
}
case TCP_DELACK_MAX_US: {
int delack_max = usecs_to_jiffies(val);

if (delack_max > TCP_DELACK_MAX || delack_max < TCP_TIMEOUT_MIN)
return -EINVAL;
WRITE_ONCE(inet_csk(sk)->icsk_delack_max, delack_max);
return 0;
}
}

sockopt_lock_sock(sk);
Expand Down Expand Up @@ -4683,6 +4691,9 @@ int do_tcp_getsockopt(struct sock *sk, int level,
case TCP_RTO_MIN_US:
val = jiffies_to_usecs(READ_ONCE(inet_csk(sk)->icsk_rto_min));
break;
case TCP_DELACK_MAX_US:
val = jiffies_to_usecs(READ_ONCE(inet_csk(sk)->icsk_delack_max));
break;
default:
return -ENOPROTOOPT;
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/tcp_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -4179,7 +4179,7 @@ u32 tcp_delack_max(const struct sock *sk)
{
u32 delack_from_rto_min = max(tcp_rto_min(sk), 2) - 1;

return min(inet_csk(sk)->icsk_delack_max, delack_from_rto_min);
return min(READ_ONCE(inet_csk(sk)->icsk_delack_max), delack_from_rto_min);
}

/* Send out a delayed ack, the caller does the policy checking
Expand Down

0 comments on commit 9552f90

Please sign in to comment.