Skip to contentSkip to conversation

bpf: support setting max RTO for bpf_setsockopt

PATCH Superseded Jason Xing 4 participants 24 messages Feb 13, 2025 – Feb 15, 2025

Subsystems (8)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jason Xing

author
#0 lore raw

cover bpf: support setting max RTO for bpf_setsockopt

Support max RTO set by BPF program calling bpf_setsockopt(). Add corresponding selftests.

Jason Xing (3):
tcp: add TCP_RTO_MAX_MIN_SEC definition
bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt selftests/bpf: add rto max for bpf_setsockopt test

 Documentation/networking/ip-sysctl.rst        |  3 +-
 include/net/tcp.h                             |  1 +
 include/uapi/linux/bpf.h                      |  2 ++
 net/core/filter.c                             |  6 ++++
 net/ipv4/sysctl_net_ipv4.c                    |  3 +-
 net/ipv4/tcp.c                                |  3 +-
 tools/include/uapi/linux/bpf.h                |  2 ++
 .../bpf/prog_tests/tcp_hdr_options.c          | 28 +++++++++++++------
 .../bpf/progs/test_tcp_hdr_options.c          | 26 +++++++++++++++++
 .../selftests/bpf/test_tcp_hdr_options.h      |  3 ++
 10 files changed, 66 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 1/3 tcp: add TCP_RTO_MAX_MIN_SEC definition

Add minimum value definition as the lower bound of RTO MAX set by users. In the next patch, bpf_sol_tcp_setsockopt() will use this in the test statement.

---
 include/net/tcp.h          | 1 +
 net/ipv4/sysctl_net_ipv4.c | 3 ++-
 net/ipv4/tcp.c             | 3 ++-
 3 files changed, 5 insertions(+), 2 deletions(-)
include/net/tcp.h +1 -0
index 7fd2d7fa4532..b6bedbe68636 100644
@@ -143,6 +143,7 @@ static_assert((1 << ATO_BITS) > TCP_DELACK_MAX);
 #define TCP_DELACK_MIN	4U
 #define TCP_ATO_MIN	4U
 #endif
+#define TCP_RTO_MAX_MIN_SEC 1
 #define TCP_RTO_MAX_SEC 120
 #define TCP_RTO_MAX	((unsigned)(TCP_RTO_MAX_SEC * HZ))
 #define TCP_RTO_MIN	((unsigned)(HZ / 5))
net/ipv4/sysctl_net_ipv4.c +2 -1
index 3a43010d726f..53942c225e0b 100644
@@ -28,6 +28,7 @@ static int tcp_adv_win_scale_max = 31;
 static int tcp_app_win_max = 31;
 static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
 static int tcp_min_snd_mss_max = 65535;
+static int tcp_rto_max_min = TCP_RTO_MAX_MIN_SEC * MSEC_PER_SEC;
 static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
 static int ip_privileged_port_min;
 static int ip_privileged_port_max = 65535;
@@ -1590,7 +1591,7 @@ static struct ctl_table ipv4_net_table[] = {
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ONE_THOUSAND,
+		.extra1		= &tcp_rto_max_min,
 		.extra2		= &tcp_rto_max_max,
 	},
 };
net/ipv4/tcp.c +2 -1
index 992d5c9b2487..2373ab1a1d47 100644
@@ -3812,7 +3812,8 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
 					   TCP_RTO_MAX / HZ));
 		return 0;
 	case TCP_RTO_MAX_MS:
-		if (val < MSEC_PER_SEC || val > TCP_RTO_MAX_SEC * MSEC_PER_SEC)
+		if (val < TCP_RTO_MAX_MIN_SEC * MSEC_PER_SEC ||
+		    val > TCP_RTO_MAX_SEC * MSEC_PER_SEC)
 			return -EINVAL;
 		WRITE_ONCE(inet_csk(sk)->icsk_rto_max, msecs_to_jiffies(val));
 		return 0;
Signature · 1 line
2.43.5
author
#3 lore raw

PATCH 2/3 bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
 Documentation/networking/ip-sysctl.rst | 3 ++-
 include/uapi/linux/bpf.h               | 2 ++
 net/core/filter.c                      | 6 ++++++
 tools/include/uapi/linux/bpf.h         | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +2 -1
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
 tcp_rto_max_ms - INTEGER
 	Maximal TCP retransmission timeout (in ms).
-	Note that TCP_RTO_MAX_MS socket option has higher precedence.
+	Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+	higher precedence for configuring this setting.
 
 	When changing tcp_rto_max_ms, it is important to understand
 	that tcp_retries2 might need a change.
include/uapi/linux/bpf.h +2 -0
index 2acf9b336371..8ab6ef144217 100644
@@ -2868,6 +2868,7 @@ union bpf_attr {
  * 		  **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
  * 		  **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
  *		  **TCP_BPF_RTO_MIN**, **TCP_BPF_SOCK_OPS_CB_FLAGS**.
+ *		  **TCP_BPF_RTO_MAX**
  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
  * 		* **IPPROTO_IPV6**, which supports the following *optname*\ s:
  * 		  **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
@@ -7091,6 +7092,7 @@ enum {
 	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
 	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
 	TCP_BPF_SOCK_OPS_CB_FLAGS = 1008, /* Get or Set TCP sock ops flags */
+	TCP_BPF_RTO_MAX		= 1009, /* Max delay ack in msecs */
 };
 
 enum {
net/core/filter.c +6 -0
index 2ec162dd83c4..a21a147e0a86 100644
@@ -5303,6 +5303,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,
 			return -EINVAL;
 		tp->bpf_sock_ops_cb_flags = val;
 		break;
+	case TCP_BPF_RTO_MAX:
+		if (val > TCP_RTO_MAX_SEC * MSEC_PER_SEC ||
+		    val < TCP_RTO_MAX_MIN_SEC * MSEC_PER_SEC)
+			return -EINVAL;
+		inet_csk(sk)->icsk_rto_max = msecs_to_jiffies(val);
+		break;
 	default:
 		return -EINVAL;
 	}
tools/include/uapi/linux/bpf.h +2 -0
index 2acf9b336371..8ab6ef144217 100644
@@ -2868,6 +2868,7 @@ union bpf_attr {
  * 		  **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
  * 		  **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
  *		  **TCP_BPF_RTO_MIN**, **TCP_BPF_SOCK_OPS_CB_FLAGS**.
+ *		  **TCP_BPF_RTO_MAX**
  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
  * 		* **IPPROTO_IPV6**, which supports the following *optname*\ s:
  * 		  **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
@@ -7091,6 +7092,7 @@ enum {
 	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
 	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
 	TCP_BPF_SOCK_OPS_CB_FLAGS = 1008, /* Get or Set TCP sock ops flags */
+	TCP_BPF_RTO_MAX		= 1009, /* Max delay ack in msecs */
 };
 
 enum {
Signature · 1 line
2.43.5
author
#21 lore raw

PATCH 3/3 selftests/bpf: add rto max for bpf_setsockopt test

In reply to Jason Xing

Add TCP_BPF_RTO_MAX selftests for active and passive flows in the BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB and BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB bpf callbacks.

---
 .../bpf/prog_tests/tcp_hdr_options.c          | 28 +++++++++++++------
 .../bpf/progs/test_tcp_hdr_options.c          | 26 +++++++++++++++++
 .../selftests/bpf/test_tcp_hdr_options.h      |  3 ++
 3 files changed, 49 insertions(+), 8 deletions(-)
tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c +20 -8
index 56685fc03c7e..714d48df6b3a 100644
@@ -60,8 +60,9 @@ static void print_hdr_stg(const struct hdr_stg *hdr_stg, const char *prefix)
 
 static void print_option(const struct bpf_test_option *opt, const char *prefix)
 {
-	fprintf(stderr, "%s{flags:0x%x, max_delack_ms:%u, rand:0x%x}\n",
-		prefix ? : "", opt->flags, opt->max_delack_ms, opt->rand);
+	fprintf(stderr, "%s{flags:0x%x, max_delack_ms:%u, rand:0x%x}, max_rto_sec:%u\n",
+		prefix ? : "", opt->flags, opt->max_delack_ms, opt->rand,
+		opt->max_rto_sec);
 }
 
 static void sk_fds_close(struct sk_fds *sk_fds)
@@ -300,13 +301,17 @@ static void fastopen_estab(void)
 	hdr_stg_map_fd = bpf_map__fd(skel->maps.hdr_stg_map);
 	lport_linum_map_fd = bpf_map__fd(skel->maps.lport_linum_map);
 
-	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				     OPTION_F_MAX_RTO_SEC;
 	exp_passive_estab_in.rand = 0xfa;
 	exp_passive_estab_in.max_delack_ms = 11;
+	exp_passive_estab_in.max_rto_sec = 1;
 
-	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				    OPTION_F_MAX_RTO_SEC;
 	exp_active_estab_in.rand = 0xce;
 	exp_active_estab_in.max_delack_ms = 22;
+	exp_active_estab_in.max_rto_sec = 2;
 
 	exp_passive_hdr_stg.fastopen = true;
 
@@ -337,14 +342,17 @@ static void syncookie_estab(void)
 	hdr_stg_map_fd = bpf_map__fd(skel->maps.hdr_stg_map);
 	lport_linum_map_fd = bpf_map__fd(skel->maps.lport_linum_map);
 
-	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				     OPTION_F_MAX_RTO_SEC;
 	exp_passive_estab_in.rand = 0xfa;
 	exp_passive_estab_in.max_delack_ms = 11;
+	exp_passive_estab_in.max_rto_sec = 1;
 
 	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
-					OPTION_F_RESEND;
+				    OPTION_F_RESEND | OPTION_F_MAX_RTO_SEC;
 	exp_active_estab_in.rand = 0xce;
 	exp_active_estab_in.max_delack_ms = 22;
+	exp_active_estab_in.max_rto_sec = 2;
 
 	exp_passive_hdr_stg.syncookie = true;
 	exp_active_hdr_stg.resend_syn = true;
@@ -413,13 +421,17 @@ static void __simple_estab(bool exprm)
 	hdr_stg_map_fd = bpf_map__fd(skel->maps.hdr_stg_map);
 	lport_linum_map_fd = bpf_map__fd(skel->maps.lport_linum_map);
 
-	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_passive_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				     OPTION_F_MAX_RTO_SEC;
 	exp_passive_estab_in.rand = 0xfa;
 	exp_passive_estab_in.max_delack_ms = 11;
+	exp_passive_estab_in.max_rto_sec = 1;
 
-	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS;
+	exp_active_estab_in.flags = OPTION_F_RAND | OPTION_F_MAX_DELACK_MS |
+				    OPTION_F_MAX_RTO_SEC;
 	exp_active_estab_in.rand = 0xce;
 	exp_active_estab_in.max_delack_ms = 22;
+	exp_active_estab_in.max_rto_sec = 2;
 
 	prepare_out();
 
tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c +26 -0
index 5f4e87ee949a..92da239adb49 100644
@@ -80,6 +80,9 @@ static void write_test_option(const struct bpf_test_option *test_opt,
 
 	if (TEST_OPTION_FLAGS(test_opt->flags, OPTION_RAND))
 		data[offset++] = test_opt->rand;
+
+	if (TEST_OPTION_FLAGS(test_opt->flags, OPTION_MAX_RTO_SEC))
+		data[offset++] = test_opt->max_rto_sec;
 }
 
 static int store_option(struct bpf_sock_ops *skops,
@@ -124,6 +127,9 @@ static int parse_test_option(struct bpf_test_option *opt, const __u8 *start)
 	if (TEST_OPTION_FLAGS(opt->flags, OPTION_RAND))
 		opt->rand = *start++;
 
+	if (TEST_OPTION_FLAGS(opt->flags, OPTION_MAX_RTO_SEC))
+		opt->max_rto_sec = *start++;
+
 	return 0;
 }
 
@@ -411,6 +417,14 @@ static int set_rto_min(struct bpf_sock_ops *skops, __u8 peer_max_delack_ms)
 			      sizeof(min_rto_us));
 }
 
+static int set_rto_max(struct bpf_sock_ops *skops, __u8 max_rto_sec)
+{
+	__u32 max_rto_ms = max_rto_sec * 1000;
+
+	return bpf_setsockopt(skops, SOL_TCP, TCP_BPF_RTO_MAX, &max_rto_ms,
+			      sizeof(max_rto_ms));
+}
+
 static int handle_active_estab(struct bpf_sock_ops *skops)
 {
 	struct hdr_stg init_stg = {
@@ -459,6 +473,12 @@ static int handle_active_estab(struct bpf_sock_ops *skops)
 			RET_CG_ERR(err);
 	}
 
+	if (active_estab_in.max_rto_sec) {
+		err = set_rto_max(skops, active_estab_in.max_rto_sec);
+		if (err)
+			RET_CG_ERR(err);
+	}
+
 	return CG_OK;
 }
 
@@ -525,6 +545,12 @@ static int handle_passive_estab(struct bpf_sock_ops *skops)
 			RET_CG_ERR(err);
 	}
 
+	if (passive_estab_in.max_rto_sec) {
+		err = set_rto_max(skops, passive_estab_in.max_rto_sec);
+		if (err)
+			RET_CG_ERR(err);
+	}
+
 	return CG_OK;
 }
 
tools/testing/selftests/bpf/test_tcp_hdr_options.h +3 -0
index 56c9f8a3ad3d..c91fad861f84 100644
@@ -8,18 +8,21 @@ struct bpf_test_option {
 	__u8 flags;
 	__u8 max_delack_ms;
 	__u8 rand;
+	__u8 max_rto_sec;
 } __attribute__((packed));
 
 enum {
 	OPTION_RESEND,
 	OPTION_MAX_DELACK_MS,
 	OPTION_RAND,
+	OPTION_MAX_RTO_SEC,
 	__NR_OPTION_FLAGS,
 };
 
 #define OPTION_F_RESEND		(1 << OPTION_RESEND)
 #define OPTION_F_MAX_DELACK_MS	(1 << OPTION_MAX_DELACK_MS)
 #define OPTION_F_RAND		(1 << OPTION_RAND)
+#define OPTION_F_MAX_RTO_SEC	(1 << OPTION_MAX_RTO_SEC)
 #define OPTION_MASK		((1 << __NR_OPTION_FLAGS) - 1)
 
 #define TEST_OPTION_FLAGS(flags, option) (1 & ((flags) >> (option)))
Signature · 1 line
2.43.5
#4 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Jason Xing

From: Jason Xing <[email protected]>
Date: Thu, 13 Feb 2025 08:43:53 +0800

Quoted 52 lines

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
 Documentation/networking/ip-sysctl.rst | 3 ++-
 include/uapi/linux/bpf.h               | 2 ++
 net/core/filter.c                      | 6 ++++++
 tools/include/uapi/linux/bpf.h         | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +2 -1
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
 tcp_rto_max_ms - INTEGER
 	Maximal TCP retransmission timeout (in ms).
-	Note that TCP_RTO_MAX_MS socket option has higher precedence.
+	Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+	higher precedence for configuring this setting.
 
 	When changing tcp_rto_max_ms, it is important to understand
 	that tcp_retries2 might need a change.
include/uapi/linux/bpf.h +2 -0
index 2acf9b336371..8ab6ef144217 100644
@@ -2868,6 +2868,7 @@ union bpf_attr {
  * 		  **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
  * 		  **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
  *		  **TCP_BPF_RTO_MIN**, **TCP_BPF_SOCK_OPS_CB_FLAGS**.
+ *		  **TCP_BPF_RTO_MAX**
  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
  * 		* **IPPROTO_IPV6**, which supports the following *optname*\ s:
  * 		  **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
@@ -7091,6 +7092,7 @@ enum {
 	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
 	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
 	TCP_BPF_SOCK_OPS_CB_FLAGS = 1008, /* Get or Set TCP sock ops flags */
+	TCP_BPF_RTO_MAX		= 1009, /* Max delay ack in msecs */
 };
 
 enum {
net/core/filter.c +0 -0
index 2ec162dd83c4..a21a147e0a86 100644
@@ -5303,6 +5303,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,
 			return -EINVAL;
 		tp->bpf_sock_ops_cb_flags = val;

net/core/filter.c static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname, · line 5314

Quoted 10 lines
net/core/filter.c +6 -0
 		break;
+	case TCP_BPF_RTO_MAX:
+		if (val > TCP_RTO_MAX_SEC * MSEC_PER_SEC ||
+		    val < TCP_RTO_MAX_MIN_SEC * MSEC_PER_SEC)
+			return -EINVAL;
+		inet_csk(sk)->icsk_rto_max = msecs_to_jiffies(val);
+		break;
 	default:
 		return -EINVAL;
 	}

You need not define TCP_BPF_RTO_MAX because TCP_RTO_MAX is not a BPF specific option, and you can just reuse do_tcp_setsockopt(), then bpf_getsockopt() also works.

---8<---

net/core/filter.c +1 -0
index 2ec162dd83c4..77732f10097c 100644
@@ -5382,6 +5382,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
 	case TCP_USER_TIMEOUT:
 	case TCP_NOTSENT_LOWAT:
 	case TCP_SAVE_SYN:
+	case TCP_RTO_MAX:
 		if (*optlen != sizeof(int))
 			return -EINVAL;
 		break;

---8<---

#22 lore raw

Re: [PATCH net-next 3/3] selftests/bpf: add rto max for bpf_setsockopt test

In reply to Jason Xing

From: Jason Xing <[email protected]>
Date: Thu, 13 Feb 2025 08:43:54 +0800

Quoted 9 lines

Add TCP_BPF_RTO_MAX selftests for active and passive flows in the BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB and BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB bpf callbacks.

---
 .../bpf/prog_tests/tcp_hdr_options.c          | 28 +++++++++++++------
 .../bpf/progs/test_tcp_hdr_options.c          | 26 +++++++++++++++++
 .../selftests/bpf/test_tcp_hdr_options.h      |  3 ++

It would be nice to update sol_tcp_testsp[] with TCP_RTO_MAX_MS in tools/testing/selftests/bpf/progs/setget_sockopt.c.

#5 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Kuniyuki Iwashima

From: Kuniyuki Iwashima <[email protected]>
Date: Thu, 13 Feb 2025 11:25:01 +0900

Quoted 28 lines
Quoted 7 lines
net/core/filter.c +0 -0
index 2ec162dd83c4..a21a147e0a86 100644
@@ -5303,6 +5303,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,
 			return -EINVAL;
 		tp->bpf_sock_ops_cb_flags = val;

net/core/filter.c static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname, · line 5314

Quoted 10 lines
net/core/filter.c +6 -0
 		break;
+	case TCP_BPF_RTO_MAX:
+		if (val > TCP_RTO_MAX_SEC * MSEC_PER_SEC ||
+		    val < TCP_RTO_MAX_MIN_SEC * MSEC_PER_SEC)
+			return -EINVAL;
+		inet_csk(sk)->icsk_rto_max = msecs_to_jiffies(val);
+		break;
 	default:
 		return -EINVAL;
 	}

You need not define TCP_BPF_RTO_MAX because TCP_RTO_MAX is not a BPF specific option, and you can just reuse do_tcp_setsockopt(), then bpf_getsockopt() also works.

---8<---

net/core/filter.c +0 -0
index 2ec162dd83c4..77732f10097c 100644

net/core/filter.c static int sol_tcp_sockopt(struct sock *sk, int optname, · line 5385

Quoted 4 lines
net/core/filter.c +1 -0
@@ -5382,6 +5382,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
 	case TCP_USER_TIMEOUT:
 	case TCP_NOTSENT_LOWAT:
 	case TCP_SAVE_SYN:
+	case TCP_RTO_MAX:

s/TCP_RTO_MAX/TCP_RTO_MAX_MS/ :)

Quoted 4 lines
net/core/filter.c +0 -1
 		if (*optlen != sizeof(int))
 			return -EINVAL;
 		break;
---8<---
author
#23 lore raw

Re: [PATCH net-next 3/3] selftests/bpf: add rto max for bpf_setsockopt test

In reply to Kuniyuki Iwashima
Quoted 7 lines · Kuniyuki Iwashima

From: Jason Xing <[email protected]>
Date: Thu, 13 Feb 2025 08:43:54 +0800

Quoted 4 lines

Add TCP_BPF_RTO_MAX selftests for active and passive flows in the BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB and BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB bpf callbacks.

Quoted 8 lines
Quoted 5 lines
---
 .../bpf/prog_tests/tcp_hdr_options.c          | 28 +++++++++++++------
 .../bpf/progs/test_tcp_hdr_options.c          | 26 +++++++++++++++++
 .../selftests/bpf/test_tcp_hdr_options.h      |  3 ++

It would be nice to update sol_tcp_testsp[] with TCP_RTO_MAX_MS in tools/testing/selftests/bpf/progs/setget_sockopt.c.

Sure, it's not hard to add this test.

Thanks,
Jason

author
#6 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Kuniyuki Iwashima
Quoted 25 lines · Kuniyuki Iwashima

From: Kuniyuki Iwashima <[email protected]>
Date: Thu, 13 Feb 2025 11:25:01 +0900

Quoted 22 lines
Quoted 7 lines
net/core/filter.c +0 -0
index 2ec162dd83c4..a21a147e0a86 100644
@@ -5303,6 +5303,12 @@ static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname,
                    return -EINVAL;
            tp->bpf_sock_ops_cb_flags = val;

net/core/filter.c static int bpf_sol_tcp_setsockopt(struct sock *sk, int optname, · line 5314

Quoted 10 lines
net/core/filter.c +6 -0
            break;
+   case TCP_BPF_RTO_MAX:
+           if (val > TCP_RTO_MAX_SEC * MSEC_PER_SEC ||
+               val < TCP_RTO_MAX_MIN_SEC * MSEC_PER_SEC)
+                   return -EINVAL;
+           inet_csk(sk)->icsk_rto_max = msecs_to_jiffies(val);
+           break;
    default:
            return -EINVAL;
    }

You need not define TCP_BPF_RTO_MAX because TCP_RTO_MAX is not a BPF specific option, and you can just reuse do_tcp_setsockopt(), then bpf_getsockopt() also works.

Quoted 12 lines

net/core/filter.c static int sol_tcp_sockopt(struct sock *sk, int optname, · line 5385

Quoted 10 lines

---8<---

net/core/filter.c +1 -0
index 2ec162dd83c4..77732f10097c 100644
@@ -5382,6 +5382,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
      case TCP_USER_TIMEOUT:
      case TCP_NOTSENT_LOWAT:
      case TCP_SAVE_SYN:
+     case TCP_RTO_MAX:

s/TCP_RTO_MAX/TCP_RTO_MAX_MS/ :)

Thanks for spotting this simpler approach. It works.

Thanks,
Jason

Quoted 6 lines
Quoted 6 lines
net/core/filter.c +0 -1
              if (*optlen != sizeof(int))
                      return -EINVAL;
              break;
---8<---
#7 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Jason Xing
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
 Documentation/networking/ip-sysctl.rst | 3 ++-
 include/uapi/linux/bpf.h               | 2 ++
 net/core/filter.c                      | 6 ++++++
 tools/include/uapi/linux/bpf.h         | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
 tcp_rto_max_ms - INTEGER
 	Maximal TCP retransmission timeout (in ms).
-	Note that TCP_RTO_MAX_MS socket option has higher precedence.
+	Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+	higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation. And the precedence as well.

WRT precedence, can you install setsockopt cgroup program and filter out calls to TCP_RTO_MAX_MS?

author
#8 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 19 lines · Stanislav Fomichev
Quoted 17 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
 Documentation/networking/ip-sysctl.rst | 3 ++-
 include/uapi/linux/bpf.h               | 2 ++
 net/core/filter.c                      | 6 ++++++
 tools/include/uapi/linux/bpf.h         | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
Quoted 8 lines

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 5 lines
Documentation/networking/ip-sysctl.rst +2 -1
 tcp_rto_max_ms - INTEGER
      Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation. And the precedence as well.

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Quoted 3 lines

WRT precedence, can you install setsockopt cgroup program and filter out calls to TCP_RTO_MAX_MS?

Yesterday, as suggested by Kuniyuki, I decided to re-use the same logic of TCP_RTO_MAX_MS for bpf_setsockopt():

net/core/filter.c +1 -0
index 2ec162dd83c4..ffec7b4357f9 100644
@@ -5382,6 +5382,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
        case TCP_USER_TIMEOUT:
        case TCP_NOTSENT_LOWAT:
        case TCP_SAVE_SYN:
+       case TCP_RTO_MAX_MS:
                if (*optlen != sizeof(int))
                        return -EINVAL;
                break;

Are you referring to using the previous way (by introducing a new flag for BPF) because we need to know the explicit precedence between setsockopt() and bpf_setsockopt() or other reasons? If so, I think there are more places than setsockopt() to modify.

And, sorry that I don't follow what you meant by saying "install setsockopt cgroup program" here. Please provide more hints.

Thanks for the review:)

Thanks,
Jason

#9 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 19 lines · Jason Xing
Quoted 18 lines · Stanislav Fomichev
Quoted 17 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
  Documentation/networking/ip-sysctl.rst | 3 ++-
  include/uapi/linux/bpf.h               | 2 ++
  net/core/filter.c                      | 6 ++++++
  tools/include/uapi/linux/bpf.h         | 2 ++
  4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
Quoted 6 lines
Quoted 6 lines

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 5 lines
Documentation/networking/ip-sysctl.rst +2 -1
  tcp_rto_max_ms - INTEGER
       Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

+1

I haven't looked at the patches. The cover letter has no word on the use case. Using test_tcp_hdr_options.c as the test is unnecessarily complicated just for adding a new optname support. setget_sockopt.c is the right test to reuse.

Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

pw-bot: cr

author
#10 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 28 lines · Martin KaFai Lau
Quoted 19 lines · Jason Xing
Quoted 18 lines · Stanislav Fomichev
Quoted 17 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
  Documentation/networking/ip-sysctl.rst | 3 ++-
  include/uapi/linux/bpf.h               | 2 ++
  net/core/filter.c                      | 6 ++++++
  tools/include/uapi/linux/bpf.h         | 2 ++
  4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
Quoted 6 lines
Quoted 6 lines

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 5 lines
Documentation/networking/ip-sysctl.rst +2 -1
  tcp_rto_max_ms - INTEGER
       Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

I will add and copy some words from Eric's patch series :)

Quoted 2 lines

Using test_tcp_hdr_options.c as the test is unnecessarily complicated just for adding a new optname support. setget_sockopt.c is the right test to reuse.

Will use setget_sockopt.c only.

Quoted 6 lines
Quoted 4 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

Thanks,
Jason

Quoted 2 lines

pw-bot: cr

#11 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 29 lines · Jason Xing
Quoted 28 lines · Martin KaFai Lau
Quoted 25 lines · Jason Xing
Quoted 24 lines · Stanislav Fomichev
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
   Documentation/networking/ip-sysctl.rst | 3 ++-
   include/uapi/linux/bpf.h               | 2 ++
   net/core/filter.c                      | 6 ++++++
   tools/include/uapi/linux/bpf.h         | 2 ++
   4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
   tcp_rto_max_ms - INTEGER
        Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 3 lines
Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

The question was your _use case_ in bpf. Not what the TCP_RTO_MAX_MS does. Your current use case is to have bpf setting it after reading the tcp header option, like the selftest in patch 3?

Quoted 7 lines

I will add and copy some words from Eric's patch series :)

Quoted 3 lines
Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

Quoted 8 lines
Quoted 1 line

There is the bpf-next/net tree. It should have the needed changes.

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

There is a net branch:
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

author
#12 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 31 lines · Martin KaFai Lau
Quoted 29 lines · Jason Xing
Quoted 28 lines · Martin KaFai Lau
Quoted 25 lines · Jason Xing
Quoted 24 lines · Stanislav Fomichev
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
   Documentation/networking/ip-sysctl.rst | 3 ++-
   include/uapi/linux/bpf.h               | 2 ++
   net/core/filter.c                      | 6 ++++++
   tools/include/uapi/linux/bpf.h         | 2 ++
   4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
   tcp_rto_max_ms - INTEGER
        Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

The question was your _use case_ in bpf. Not what the TCP_RTO_MAX_MS does. Your current use case is to have bpf setting it after reading the tcp header option, like the selftest in patch 3?

Oops, I misunderstood the real situation of the tcp header option test. My intention is to bpf_setsockopt() just like setget_sockopt does.

Thanks for reminding me. I will totally remove the header test in the next version.

Quoted 13 lines
Quoted 13 lines

I will add and copy some words from Eric's patch series :)

Quoted 4 lines
Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

Quoted 6 lines
Quoted 3 lines

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

There is a net branch:
https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

But this branch hasn't included the rto max feature. I was trying to say that what I wrote is based on the rto max feature which only exists in the net-next tree for now.

I wonder whether I need to introduce a new flag like this patch or reuse the TCP_RTO_MAX_MS socket option for bpf?

Thanks,
Jason

#13 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 40 lines · Jason Xing
Quoted 31 lines · Martin KaFai Lau
Quoted 29 lines · Jason Xing
Quoted 28 lines · Martin KaFai Lau
Quoted 25 lines · Jason Xing
Quoted 24 lines · Stanislav Fomichev
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
    Documentation/networking/ip-sysctl.rst | 3 ++-
    include/uapi/linux/bpf.h               | 2 ++
    net/core/filter.c                      | 6 ++++++
    tools/include/uapi/linux/bpf.h         | 2 ++
    4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
    tcp_rto_max_ms - INTEGER
         Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

The question was your _use case_ in bpf. Not what the TCP_RTO_MAX_MS does. Your current use case is to have bpf setting it after reading the tcp header option, like the selftest in patch 3?

Quoted 6 lines

Oops, I misunderstood the real situation of the tcp header option test. My intention is to bpf_setsockopt() just like setget_sockopt does.

Thanks for reminding me. I will totally remove the header test in the next version.

If your use case was in the header, it is ok although it won't be the first useful place I have in my mind. Regardless, it is useful to say a few words where you are planning to set it in the bpf. During a cb in sockops or during socket create ...etc. Without it, we can only guess from the selftest :(

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

I will add and copy some words from Eric's patch series :)

Quoted 4 lines
Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

There is a net branch:

              ^^^
Quoted 3 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

But this branch hasn't included the rto max feature. I was trying to

Which branch? I was talking about the **net** branch. Not the master branch. Try to pull again if your local copy does not have it. The net branch should have the TCP_RTO_MAX_MS patches.

Quoted 3 lines

say that what I wrote is based on the rto max feature which only exists in the net-next tree for now.

author
#14 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 42 lines · Martin KaFai Lau
Quoted 40 lines · Jason Xing
Quoted 38 lines · Martin KaFai Lau
Quoted 29 lines · Jason Xing
Quoted 28 lines · Martin KaFai Lau
Quoted 25 lines · Jason Xing
Quoted 24 lines · Stanislav Fomichev
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
    Documentation/networking/ip-sysctl.rst | 3 ++-
    include/uapi/linux/bpf.h               | 2 ++
    net/core/filter.c                      | 6 ++++++
    tools/include/uapi/linux/bpf.h         | 2 ++
    4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
    tcp_rto_max_ms - INTEGER
         Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 3 lines
Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

The question was your _use case_ in bpf. Not what the TCP_RTO_MAX_MS does. Your current use case is to have bpf setting it after reading the tcp header option, like the selftest in patch 3?

Quoted 8 lines
Quoted 6 lines

Oops, I misunderstood the real situation of the tcp header option test. My intention is to bpf_setsockopt() just like setget_sockopt does.

Thanks for reminding me. I will totally remove the header test in the next version.

If your use case was in the header, it is ok although it won't be the first

I was planning to add a simple test to only see if the rto max for bpf feature works, so I found the rto min selftests and then did a similar one.

Quoted 3 lines

useful place I have in my mind. Regardless, it is useful to say a few words where you are planning to set it in the bpf. During a cb in sockops or during socket create ...etc. Without it, we can only guess from the selftest :(

I see your point. After evaluating and comparing those two tests, I think the setsock_opt is a better place to go. Do we even apply the use of rto min to setsock_opt as well?

What do you think?

Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

I will add and copy some words from Eric's patch series :)

Quoted 4 lines
Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

There is a net branch:

               ^^^
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

But this branch hasn't included the rto max feature. I was trying to

Which branch? I was talking about the **net** branch. Not the master branch. Try to pull again if your local copy does not have it. The net branch should have the TCP_RTO_MAX_MS patches.

Oh, I always use the master branch, never heard of net branch. You're right, I checked out the net branch and then found it. Thanks.

One more thing I have to ask in advance is that in this case what the title looks like? [patch bpf] or [patch bpf net]?

Thanks,
Jason

Quoted 6 lines
Quoted 4 lines

say that what I wrote is based on the rto max feature which only exists in the net-next tree for now.

#19 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Jason Xing
Quoted 53 lines · Jason Xing
Quoted 19 lines · Stanislav Fomichev
Quoted 17 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
 Documentation/networking/ip-sysctl.rst | 3 ++-
 include/uapi/linux/bpf.h               | 2 ++
 net/core/filter.c                      | 6 ++++++
 tools/include/uapi/linux/bpf.h         | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
Quoted 8 lines

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 5 lines
Documentation/networking/ip-sysctl.rst +2 -1
 tcp_rto_max_ms - INTEGER
      Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation. And the precedence as well.

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Quoted 3 lines

WRT precedence, can you install setsockopt cgroup program and filter out calls to TCP_RTO_MAX_MS?

Yesterday, as suggested by Kuniyuki, I decided to re-use the same logic of TCP_RTO_MAX_MS for bpf_setsockopt():

net/core/filter.c +1 -0
index 2ec162dd83c4..ffec7b4357f9 100644
@@ -5382,6 +5382,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
        case TCP_USER_TIMEOUT:
        case TCP_NOTSENT_LOWAT:
        case TCP_SAVE_SYN:
+       case TCP_RTO_MAX_MS:
                if (*optlen != sizeof(int))
                        return -EINVAL;
                break;
Quoted 7 lines

Are you referring to using the previous way (by introducing a new flag for BPF) because we need to know the explicit precedence between setsockopt() and bpf_setsockopt() or other reasons? If so, I think there are more places than setsockopt() to modify.

And, sorry that I don't follow what you meant by saying "install setsockopt cgroup program" here. Please provide more hints.

Ah, sorry, I misread it as bpf options taking precedence over tcp ones; ignore the suggestion about setsockopt cgroup prog.

And yes, reusing the logic of TCP_RTO_MAX_MS looks better!

author
#20 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 60 lines · Stanislav Fomichev
Quoted 58 lines · Jason Xing
Quoted 19 lines · Stanislav Fomichev
Quoted 17 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
 Documentation/networking/ip-sysctl.rst | 3 ++-
 include/uapi/linux/bpf.h               | 2 ++
 net/core/filter.c                      | 6 ++++++
 tools/include/uapi/linux/bpf.h         | 2 ++
 4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
Quoted 8 lines

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 5 lines
Documentation/networking/ip-sysctl.rst +2 -1
 tcp_rto_max_ms - INTEGER
      Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation. And the precedence as well.

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Quoted 3 lines

WRT precedence, can you install setsockopt cgroup program and filter out calls to TCP_RTO_MAX_MS?

Yesterday, as suggested by Kuniyuki, I decided to re-use the same logic of TCP_RTO_MAX_MS for bpf_setsockopt():

net/core/filter.c +1 -0
index 2ec162dd83c4..ffec7b4357f9 100644
@@ -5382,6 +5382,7 @@ static int sol_tcp_sockopt(struct sock *sk, int optname,
        case TCP_USER_TIMEOUT:
        case TCP_NOTSENT_LOWAT:
        case TCP_SAVE_SYN:
+       case TCP_RTO_MAX_MS:
                if (*optlen != sizeof(int))
                        return -EINVAL;
                break;

Are you referring to using the previous way (by introducing a new flag for BPF) because we need to know the explicit precedence between setsockopt() and bpf_setsockopt() or other reasons? If so, I think there are more places than setsockopt() to modify.

Quoted 7 lines
Quoted 2 lines

And, sorry that I don't follow what you meant by saying "install setsockopt cgroup program" here. Please provide more hints.

Ah, sorry, I misread it as bpf options taking precedence over tcp ones; ignore the suggestion about setsockopt cgroup prog.

And yes, reusing the logic of TCP_RTO_MAX_MS looks better!

Okay, then I will send a patch soon. BTW, which tree should this series go in? Should I use the prefix '[patch bpf-next]' or something else in the title?

Thanks,
Jason

#15 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

In reply to Jason Xing
Quoted 60 lines · Jason Xing
Quoted 42 lines · Martin KaFai Lau
Quoted 40 lines · Jason Xing
Quoted 38 lines · Martin KaFai Lau
Quoted 29 lines · Jason Xing
Quoted 28 lines · Martin KaFai Lau
Quoted 25 lines · Jason Xing
Quoted 24 lines · Stanislav Fomichev
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
     Documentation/networking/ip-sysctl.rst | 3 ++-
     include/uapi/linux/bpf.h               | 2 ++
     net/core/filter.c                      | 6 ++++++
     tools/include/uapi/linux/bpf.h         | 2 ++
     4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
     tcp_rto_max_ms - INTEGER
          Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 3 lines
Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

The question was your _use case_ in bpf. Not what the TCP_RTO_MAX_MS does. Your current use case is to have bpf setting it after reading the tcp header option, like the selftest in patch 3?

Quoted 8 lines
Quoted 6 lines

Oops, I misunderstood the real situation of the tcp header option test. My intention is to bpf_setsockopt() just like setget_sockopt does.

Thanks for reminding me. I will totally remove the header test in the next version.

If your use case was in the header, it is ok although it won't be the first

I was planning to add a simple test to only see if the rto max for bpf feature works, so I found the rto min selftests and then did a similar one.

Quoted 3 lines

useful place I have in my mind. Regardless, it is useful to say a few words where you are planning to set it in the bpf. During a cb in sockops or during socket create ...etc. Without it, we can only guess from the selftest :(

Quoted 5 lines

I see your point. After evaluating and comparing those two tests, I think the setsock_opt is a better place to go. Do we even apply the use of rto min to setsock_opt as well?

What do you think?

Adding to sol_tcp_tests[] as Kuniyuki suggested should be the straight forward way.

Please still describe how you are going to use it in bpf in the cover letter.

Quoted 31 lines
Quoted 23 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

I will add and copy some words from Eric's patch series :)

Quoted 4 lines
Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

There is a net branch:

                ^^^
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

But this branch hasn't included the rto max feature. I was trying to

Which branch? I was talking about the **net** branch. Not the master branch. Try to pull again if your local copy does not have it. The net branch should have the TCP_RTO_MAX_MS patches.

Quoted 5 lines

Oh, I always use the master branch, never heard of net branch. You're right, I checked out the net branch and then found it. Thanks.

One more thing I have to ask in advance is that in this case what the title looks like? [patch bpf] or [patch bpf net]?

[PATCH bpf-next]

author
#16 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 66 lines · Martin KaFai Lau
Quoted 64 lines · Jason Xing
Quoted 42 lines · Martin KaFai Lau
Quoted 40 lines · Jason Xing
Quoted 38 lines · Martin KaFai Lau
Quoted 29 lines · Jason Xing
Quoted 28 lines · Martin KaFai Lau
Quoted 25 lines · Jason Xing
Quoted 24 lines · Stanislav Fomichev
Quoted 16 lines · Jason Xing

Support bpf_setsockopt() to set the maximum value of RTO for BPF program.

---
     Documentation/networking/ip-sysctl.rst | 3 ++-
     include/uapi/linux/bpf.h               | 2 ++
     net/core/filter.c                      | 6 ++++++
     tools/include/uapi/linux/bpf.h         | 2 ++
     4 files changed, 12 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +0 -0
index 054561f8dcae..78eb0959438a 100644

Documentation/networking/ip-sysctl.rst tcp_rto_min_us - INTEGER · line 1245

Quoted 6 lines
Documentation/networking/ip-sysctl.rst +2 -1
@@ -1241,7 +1241,8 @@ tcp_rto_min_us - INTEGER
 
     tcp_rto_max_ms - INTEGER
          Maximal TCP retransmission timeout (in ms).
-     Note that TCP_RTO_MAX_MS socket option has higher precedence.
+     Note that TCP_BPF_RTO_MAX and TCP_RTO_MAX_MS socket option have the
+     higher precedence for configuring this setting.

The cover letter needs more explanation about the motivation.

Quoted 3 lines
Quoted 3 lines

+1

I haven't looked at the patches. The cover letter has no word on the use case.

The question was your _use case_ in bpf. Not what the TCP_RTO_MAX_MS does. Your current use case is to have bpf setting it after reading the tcp header option, like the selftest in patch 3?

Quoted 8 lines
Quoted 6 lines

Oops, I misunderstood the real situation of the tcp header option test. My intention is to bpf_setsockopt() just like setget_sockopt does.

Thanks for reminding me. I will totally remove the header test in the next version.

If your use case was in the header, it is ok although it won't be the first

I was planning to add a simple test to only see if the rto max for bpf feature works, so I found the rto min selftests and then did a similar one.

Quoted 3 lines

useful place I have in my mind. Regardless, it is useful to say a few words where you are planning to set it in the bpf. During a cb in sockops or during socket create ...etc. Without it, we can only guess from the selftest :(

I see your point. After evaluating and comparing those two tests, I think the setsock_opt is a better place to go. Do we even apply the use of rto min to setsock_opt as well?

Quoted 5 lines
Quoted 1 line

What do you think?

Adding to sol_tcp_tests[] as Kuniyuki suggested should be the straight forward way.

Please still describe how you are going to use it in bpf in the cover letter.

Sure, I will.

Another related topic about rto min test, do you think it's necessary to add TCP_BPF_RTO_MIN into the setget_sockopt test?

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

I will add and copy some words from Eric's patch series :)

Quoted 4 lines
Quoted 2 lines

I am targeting the net-next tree because of recent changes[1] made by Eric. It probably hasn't merged into the bpf-next tree.

There is the bpf-next/net tree. It should have the needed changes.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

[1] was recently merged in the net-next tree, so the only one branch I can target is net-next.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=ae9b3c0e79bc

Am I missing something?

There is a net branch:

                ^^^
Quoted 3 lines
Quoted 1 line

https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git

But this branch hasn't included the rto max feature. I was trying to

Which branch? I was talking about the **net** branch. Not the master branch. Try to pull again if your local copy does not have it. The net branch should have the TCP_RTO_MAX_MS patches.

Quoted 7 lines
Quoted 5 lines

Oh, I always use the master branch, never heard of net branch. You're right, I checked out the net branch and then found it. Thanks.

One more thing I have to ask in advance is that in this case what the title looks like? [patch bpf] or [patch bpf net]?

[PATCH bpf-next]

Thanks. Will do it.

Thanks,
Jason

#17 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 2 lines · Jason Xing

Another related topic about rto min test, do you think it's necessary to add TCP_BPF_RTO_MIN into the setget_sockopt test?

hmm... not sure why it is related to the existing TCP_BPF_RTO_MIN. I thought this patch is adding the new TCP_RTO_MAX_MS...

or you want to say, while adding a TCP_RTO_MAX_MS test, add a test for the existing TCP_BPF_RTO_MIN also because it is missing in the setget_sockopt?
iirc, I added setget_sockopt.c to test a patch that reuses the kernel do_*_{set,get}sockopt. Thus, it assumes the optname supports both set and get. TCP_BPF_RTO_MIN does not support get, so I suspect setget_sockopt will not be a good fit. They are unrelated, so I would leave it out of your patch for now.

author
#18 lore raw

Re: [PATCH net-next 2/3] bpf: add TCP_BPF_RTO_MAX for bpf_setsockopt

Quoted 8 lines · Martin KaFai Lau
Quoted 2 lines · Jason Xing

Another related topic about rto min test, do you think it's necessary to add TCP_BPF_RTO_MIN into the setget_sockopt test?

hmm... not sure why it is related to the existing TCP_BPF_RTO_MIN. I thought this patch is adding the new TCP_RTO_MAX_MS...

Quoted 6 lines

or you want to say, while adding a TCP_RTO_MAX_MS test, add a test for the existing TCP_BPF_RTO_MIN also because it is missing in the setget_sockopt? iirc, I added setget_sockopt.c to test a patch that reuses the kernel do_*_{set,get}sockopt. Thus, it assumes the optname supports both set and get. TCP_BPF_RTO_MIN does not support get, so I suspect setget_sockopt will not be a good fit. They are unrelated, so I would leave it out of your patch for now.

From my perspective, rto min or max is quite similar and only related to the time limitation of RTO, so I assume they can have the same usage... Right, what you said is exactly what I would like to know. As you said, handling rto min will not be included in this series.

Thanks,
Jason