hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/net/ipv4/tcp_metrics.c
....@@ -329,7 +329,7 @@
329329 int m;
330330
331331 sk_dst_confirm(sk);
332
- if (net->ipv4.sysctl_tcp_nometrics_save || !dst)
332
+ if (READ_ONCE(net->ipv4.sysctl_tcp_nometrics_save) || !dst)
333333 return;
334334
335335 rcu_read_lock();
....@@ -385,7 +385,8 @@
385385
386386 if (tcp_in_initial_slowstart(tp)) {
387387 /* Slow start still did not finish. */
388
- if (!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH)) {
388
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) &&
389
+ !tcp_metric_locked(tm, TCP_METRIC_SSTHRESH)) {
389390 val = tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
390391 if (val && (tp->snd_cwnd >> 1) > val)
391392 tcp_metric_set(tm, TCP_METRIC_SSTHRESH,
....@@ -400,7 +401,8 @@
400401 } else if (!tcp_in_slow_start(tp) &&
401402 icsk->icsk_ca_state == TCP_CA_Open) {
402403 /* Cong. avoidance phase, cwnd is reliable. */
403
- if (!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH))
404
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) &&
405
+ !tcp_metric_locked(tm, TCP_METRIC_SSTHRESH))
404406 tcp_metric_set(tm, TCP_METRIC_SSTHRESH,
405407 max(tp->snd_cwnd >> 1, tp->snd_ssthresh));
406408 if (!tcp_metric_locked(tm, TCP_METRIC_CWND)) {
....@@ -416,7 +418,8 @@
416418 tcp_metric_set(tm, TCP_METRIC_CWND,
417419 (val + tp->snd_ssthresh) >> 1);
418420 }
419
- if (!tcp_metric_locked(tm, TCP_METRIC_SSTHRESH)) {
421
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) &&
422
+ !tcp_metric_locked(tm, TCP_METRIC_SSTHRESH)) {
420423 val = tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
421424 if (val && tp->snd_ssthresh > val)
422425 tcp_metric_set(tm, TCP_METRIC_SSTHRESH,
....@@ -425,7 +428,8 @@
425428 if (!tcp_metric_locked(tm, TCP_METRIC_REORDERING)) {
426429 val = tcp_metric_get(tm, TCP_METRIC_REORDERING);
427430 if (val < tp->reordering &&
428
- tp->reordering != net->ipv4.sysctl_tcp_reordering)
431
+ tp->reordering !=
432
+ READ_ONCE(net->ipv4.sysctl_tcp_reordering))
429433 tcp_metric_set(tm, TCP_METRIC_REORDERING,
430434 tp->reordering);
431435 }
....@@ -441,6 +445,7 @@
441445 {
442446 struct dst_entry *dst = __sk_dst_get(sk);
443447 struct tcp_sock *tp = tcp_sk(sk);
448
+ struct net *net = sock_net(sk);
444449 struct tcp_metrics_block *tm;
445450 u32 val, crtt = 0; /* cached RTT scaled by 8 */
446451
....@@ -458,7 +463,8 @@
458463 if (tcp_metric_locked(tm, TCP_METRIC_CWND))
459464 tp->snd_cwnd_clamp = tcp_metric_get(tm, TCP_METRIC_CWND);
460465
461
- val = tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
466
+ val = READ_ONCE(net->ipv4.sysctl_tcp_no_ssthresh_metrics_save) ?
467
+ 0 : tcp_metric_get(tm, TCP_METRIC_SSTHRESH);
462468 if (val) {
463469 tp->snd_ssthresh = val;
464470 if (tp->snd_ssthresh > tp->snd_cwnd_clamp)
....@@ -512,16 +518,6 @@
512518
513519 inet_csk(sk)->icsk_rto = TCP_TIMEOUT_FALLBACK;
514520 }
515
- /* Cut cwnd down to 1 per RFC5681 if SYN or SYN-ACK has been
516
- * retransmitted. In light of RFC6298 more aggressive 1sec
517
- * initRTO, we only reset cwnd when more than 1 SYN/SYN-ACK
518
- * retransmission has occurred.
519
- */
520
- if (tp->total_retrans > 1)
521
- tp->snd_cwnd = 1;
522
- else
523
- tp->snd_cwnd = tcp_init_cwnd(tp, dst);
524
- tp->snd_cwnd_stamp = tcp_jiffies32;
525521 }
526522
527523 bool tcp_peer_is_proven(struct request_sock *req, struct dst_entry *dst)
....@@ -658,7 +654,7 @@
658654 {
659655 int n = 0;
660656
661
- nest = nla_nest_start(msg, TCP_METRICS_ATTR_VALS);
657
+ nest = nla_nest_start_noflag(msg, TCP_METRICS_ATTR_VALS);
662658 if (!nest)
663659 goto nla_put_failure;
664660 for (i = 0; i < TCP_METRIC_MAX_KERNEL + 1; i++) {
....@@ -948,17 +944,17 @@
948944 return 0;
949945 }
950946
951
-static const struct genl_ops tcp_metrics_nl_ops[] = {
947
+static const struct genl_small_ops tcp_metrics_nl_ops[] = {
952948 {
953949 .cmd = TCP_METRICS_CMD_GET,
950
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
954951 .doit = tcp_metrics_nl_cmd_get,
955952 .dumpit = tcp_metrics_nl_dump,
956
- .policy = tcp_metrics_nl_policy,
957953 },
958954 {
959955 .cmd = TCP_METRICS_CMD_DEL,
956
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
960957 .doit = tcp_metrics_nl_cmd_del,
961
- .policy = tcp_metrics_nl_policy,
962958 .flags = GENL_ADMIN_PERM,
963959 },
964960 };
....@@ -968,10 +964,11 @@
968964 .name = TCP_METRICS_GENL_NAME,
969965 .version = TCP_METRICS_GENL_VERSION,
970966 .maxattr = TCP_METRICS_ATTR_MAX,
967
+ .policy = tcp_metrics_nl_policy,
971968 .netnsok = true,
972969 .module = THIS_MODULE,
973
- .ops = tcp_metrics_nl_ops,
974
- .n_ops = ARRAY_SIZE(tcp_metrics_nl_ops),
970
+ .small_ops = tcp_metrics_nl_ops,
971
+ .n_small_ops = ARRAY_SIZE(tcp_metrics_nl_ops),
975972 };
976973
977974 static unsigned int tcpmhash_entries;
....@@ -1000,7 +997,7 @@
1000997
1001998 slots = tcpmhash_entries;
1002999 if (!slots) {
1003
- if (totalram_pages >= 128 * 1024)
1000
+ if (totalram_pages() >= 128 * 1024)
10041001 slots = 16 * 1024;
10051002 else
10061003 slots = 8 * 1024;