* [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB.
@ 2026-12-04 8:54 Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow Kuniyuki Iwashima
` (10 more replies)
0 siblings, 11 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
Currently, PLB (Protective Load Balancing) relies on ECN signals
and is only hooked into DCTCP. However, ECN is often unavailable
in cloud VM and virtualised network environments, and widely deployed
congestion control algorithms such as CUBIC and BBR cannot benefit
from PLB.
This series introduces Generic PLB, a congestion-control-agnostic
PLB mechanism triggered by a combination of packet loss and low
delivery rate.
Generic PLB adds one per-netns sysctl knob:
net.ipv4.tcp_plb_loss_rehash_prob (default: 128, range: 0 - 255)
Every 5th Fast Recovery, tcp_plb_check_rehash_loss() computes a
rehash probability in [0, 255] from rate_prob and floor, and
rehashes the flow via tcp_plb_rehash() if a random number in
[0, 254] is smaller than the probability:
prob = max(rate_prob, floor)
if (get_random_u32_below(255) < prob)
tcp_plb_rehash(sk);
See patch 8 for experiment results.
Overview:
Patch 1 - 2 : Trivial non-urgent fixes
Patch 3 - 6 : Factor out common PLB code from ECN-PLB
Patch 7 : Lower tcp_plb_suspend_rto_sec default for both PLB
Patch 8 : Introduce Generic PLB
Patch 9 : Packetdrill tests
Patch 10 : Deflake ecmp_rehash.sh
Kuniyuki Iwashima (10):
tcp: Return early when tcp_plb_check_rehash() does not rehash a flow.
tcp: Don't call get_random_u32_below(0) in
tcp_plb_update_state_upon_rto().
tcp: Move struct tcp_plb_state to struct tcp_sock.
tcp: Call tcp_plb_update_state_upon_rto() after rehash in
tcp_write_timeout().
tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn().
tcp: Factorise tcp_plb_rehash().
tcp: Lower tcp_plb_suspend_rto_sec default.
tcp: Introduce Generic PLB.
selftest: packetdrill: Add tests for Generic PLB.
selftest: net: Disable Generic PLB in ecmp_rehash.sh.
Documentation/networking/ip-sysctl.rst | 24 ++-
.../net_cachelines/netns_ipv4_sysctl.rst | 1 +
.../networking/net_cachelines/tcp_sock.rst | 5 +
include/linux/tcp.h | 9 +
include/net/netns/ipv4.h | 3 +-
include/net/tcp.h | 21 +--
net/core/net_namespace.c | 2 +
net/ipv4/sysctl_net_ipv4.c | 7 +
net/ipv4/tcp.c | 6 +
net/ipv4/tcp_dctcp.c | 17 +-
net/ipv4/tcp_input.c | 15 ++
net/ipv4/tcp_ipv4.c | 3 +-
net/ipv4/tcp_plb.c | 136 ++++++++++----
net/ipv4/tcp_timer.c | 1 +
tools/testing/selftests/net/ecmp_rehash.sh | 1 +
.../net/packetdrill/tcp_plb_loss_rate.pkt | 83 +++++++++
.../packetdrill/tcp_plb_loss_rto_suspend.pkt | 166 ++++++++++++++++++
.../net/packetdrill/tcp_plb_loss_tlp.pkt | 102 +++++++++++
18 files changed, 536 insertions(+), 66 deletions(-)
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 02/10] tcp: Don't call get_random_u32_below(0) in tcp_plb_update_state_upon_rto() Kuniyuki Iwashima
` (9 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev, Mubashir Adnan Qureshi
LINUX_MIB_TCPDUPLICATEDATAREHASH and LINUX_MIB_TCPTIMEOUTREHASH
are incremented only when a flow is actually rehashed and
__sk_rethink_txhash_reset_dst() returns true.
OTOH, even when it returns false, tcp_plb_check_rehash() resets
plb->consec_cong_rounds and increments LINUX_MIB_TCPPLBREHASH
and tp->plb_rehash.
Let's do nothing when __sk_rethink_txhash_reset_dst() returns
false in tcp_plb_check_rehash().
Fixes: 1a91bb7c3ebf ("tcp: add PLB functionality for TCP")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Cc: Mubashir Adnan Qureshi <mubashirq@google.com>
---
net/ipv4/tcp_plb.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index bcc2f0add6af..0cc14cf41f8a 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -78,7 +78,9 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
if (plb->pause_until)
return;
- __sk_rethink_txhash_reset_dst(sk);
+ if (!__sk_rethink_txhash_reset_dst(sk))
+ return;
+
plb->consec_cong_rounds = 0;
WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 02/10] tcp: Don't call get_random_u32_below(0) in tcp_plb_update_state_upon_rto().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock Kuniyuki Iwashima
` (8 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev, Jason A. Donenfeld
Even when net.ipv4.tcp_plb_suspend_rto_sec is set to 0,
tcp_plb_update_state_upon_rto() calls get_random_u32_below().
Since the cited commit, when get_random_u32_below() is called with 0,
it falls back to get_random_u32(), which results in [0, UINT_MAX].
Then, plb->pause_until is set to a random value, which is normally
cleared in tcp_plb_check_rehash() while tcp_plb_suspend_rto_sec stays
0, but can pause PLB unintentionally if the sysctl is raised later.
Let's not set pause_until when tcp_plb_suspend_rto_sec is 0.
Fixes: 7f576b2593a9 ("random: add helpers for random numbers with given floor or range")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
---
net/ipv4/tcp_plb.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 0cc14cf41f8a..d101a424c444 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -100,8 +100,10 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
return;
pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
- pause += get_random_u32_below(pause);
- plb->pause_until = tcp_jiffies32 + pause;
+ if (pause) {
+ pause += get_random_u32_below(pause);
+ plb->pause_until = tcp_jiffies32 + pause;
+ }
/* Reset PLB state upon RTO, since an RTO causes a sk_rethink_txhash() call
* that may switch this connection to a path with completely different
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 02/10] tcp: Don't call get_random_u32_below(0) in tcp_plb_update_state_upon_rto() Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 10:34 ` David Laight
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 8:54 ` [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout() Kuniyuki Iwashima
` (7 subsequent siblings)
10 siblings, 2 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
Currently, PLB is only used by DCTCP, but we will generalise
it for other CCs.
struct tcp_plb_state is 5 bytes and moving it to tcp_sock
creates a hole after the struct without __packed.
Let's inline consec_cong_rounds and pause_until to tcp_sock.
plb_consec_cong_rounds uses 8 bits because compilers had to
generate inefficient RMW for consec_cong_rounds:5 to preserve
unused:3.
Note that dctcp_init() no longer clears plb_pause_until so that
an active RTO pause is preserved across handshake SYN RTOs and
CC changes. tcp_disconnect() clears both fields.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
.../networking/net_cachelines/tcp_sock.rst | 2 +
include/linux/tcp.h | 4 ++
include/net/tcp.h | 20 ++--------
net/ipv4/tcp.c | 2 +
net/ipv4/tcp_dctcp.c | 18 ++++-----
net/ipv4/tcp_plb.c | 40 ++++++++++---------
6 files changed, 39 insertions(+), 47 deletions(-)
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 78f74eb76990..6eb058478665 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -158,6 +158,8 @@ u32 bpf_tcp_ops_flags read_mostly read_m
u8 bpf_sock_ops_cb_flags
u8:1 bpf_chg_cc_inprogress
u16 timeout_rehash
+u8 plb_consec_cong_rounds
+u32 plb_pause_until
u32 rcv_ooopack
u32 rcv_rtt_last_tsecr
struct rcv_rtt_est read_write tcp_rcv_space_adjust,tcp_rcv_established
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 3d6eb6c8681d..3f275ac8e512 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -506,6 +506,10 @@ struct tcp_sock {
u16 timeout_rehash; /* Timeout-triggered rehash attempts */
+ /* State for PLB (Protective Load Balancing) for a single TCP connection. */
+ u8 plb_consec_cong_rounds; /* consecutive congested rounds */
+ u32 plb_pause_until; /* jiffies32 when PLB can resume rerouting */
+
u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
/* TCP-specific MTU probe information. */
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 68a60268d19d..bcff640c16a1 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2735,23 +2735,9 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
*/
#define TCP_PLB_SCALE 8
-/* State for PLB (Protective Load Balancing) for a single TCP connection. */
-struct tcp_plb_state {
- u8 consec_cong_rounds:5, /* consecutive congested rounds */
- unused:3;
- u32 pause_until; /* jiffies32 when PLB can resume rerouting */
-};
-
-static inline void tcp_plb_init(const struct sock *sk,
- struct tcp_plb_state *plb)
-{
- plb->consec_cong_rounds = 0;
- plb->pause_until = 0;
-}
-void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
- const int cong_ratio);
-void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb);
-void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
+void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
+void tcp_plb_check_rehash(struct sock *sk);
+void tcp_plb_update_state_upon_rto(struct sock *sk);
static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
{
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 58767b3b1b9a..002eaca58c46 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3488,6 +3488,8 @@ int tcp_disconnect(struct sock *sk, int flags)
tp->tlp_high_seq = 0;
tp->last_oow_ack_time = 0;
tp->plb_rehash = 0;
+ tp->plb_consec_cong_rounds = 0;
+ tp->plb_pause_until = 0;
/* There's a bubble in the pipe until at least the first ACK. */
tp->app_limited = ~0U;
tp->rate_app_limited = 1;
diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
index 5b457f68a581..bc3724d1da90 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -54,7 +54,6 @@ struct dctcp {
u32 next_seq;
u32 ce_state;
u32 loss_cwnd;
- struct tcp_plb_state plb;
};
static unsigned int dctcp_shift_g __read_mostly = 4; /* g = 1/2^4 */
@@ -88,7 +87,7 @@ static void dctcp_reset(const struct tcp_sock *tp, struct dctcp *ca)
__bpf_kfunc static void dctcp_init(struct sock *sk)
{
- const struct tcp_sock *tp = tcp_sk(sk);
+ struct tcp_sock *tp = tcp_sk(sk);
if (tcp_ecn_mode_any(tp) ||
(sk->sk_state == TCP_LISTEN ||
@@ -103,8 +102,7 @@ __bpf_kfunc static void dctcp_init(struct sock *sk)
ca->ce_state = 0;
dctcp_reset(tp, ca);
- tcp_plb_init(sk, &ca->plb);
-
+ tp->plb_consec_cong_rounds = 0;
return;
}
@@ -126,8 +124,8 @@ __bpf_kfunc static u32 dctcp_ssthresh(struct sock *sk)
__bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
{
- const struct tcp_sock *tp = tcp_sk(sk);
struct dctcp *ca = inet_csk_ca(sk);
+ struct tcp_sock *tp = tcp_sk(sk);
/* Expired RTT */
if (!before(tp->snd_una, ca->next_seq)) {
@@ -145,8 +143,8 @@ __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
*/
if (delivered_ce > 0)
ce_ratio = (delivered_ce << TCP_PLB_SCALE) / delivered;
- tcp_plb_update_state(sk, &ca->plb, (int)ce_ratio);
- tcp_plb_check_rehash(sk, &ca->plb);
+ tcp_plb_update_state(sk, (int)ce_ratio);
+ tcp_plb_check_rehash(sk);
}
/* alpha = (1 - g) * alpha + g * F */
@@ -200,7 +198,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
dctcp_ece_ack_update(sk, ev, &ca->prior_rcv_nxt, &ca->ce_state);
break;
case CA_EVENT_LOSS:
- tcp_plb_update_state_upon_rto(sk, &ca->plb);
+ tcp_plb_update_state_upon_rto(sk);
dctcp_react_to_loss(sk);
break;
default:
@@ -211,9 +209,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
__bpf_kfunc static void dctcp_cwnd_event_tx_start(struct sock *sk)
{
- struct dctcp *ca = inet_csk_ca(sk);
-
- tcp_plb_check_rehash(sk, &ca->plb); /* Maybe rehash when inflight is 0 */
+ tcp_plb_check_rehash(sk); /* Maybe rehash when inflight is 0 */
}
static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index d101a424c444..26ca53d6fb9d 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -23,9 +23,9 @@
#include <net/tcp.h>
/* Called once per round-trip to update PLB state for a connection. */
-void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
- const int cong_ratio)
+void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
{
+ struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
@@ -33,10 +33,10 @@ void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
if (cong_ratio >= 0) {
if (cong_ratio < READ_ONCE(net->ipv4.sysctl_tcp_plb_cong_thresh))
- plb->consec_cong_rounds = 0;
- else if (plb->consec_cong_rounds <
+ tp->plb_consec_cong_rounds = 0;
+ else if (tp->plb_consec_cong_rounds <
READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds))
- plb->consec_cong_rounds++;
+ tp->plb_consec_cong_rounds++;
}
}
EXPORT_SYMBOL_GPL(tcp_plb_update_state);
@@ -44,21 +44,22 @@ EXPORT_SYMBOL_GPL(tcp_plb_update_state);
/* Check whether recent congestion has been persistent enough to warrant
* a load balancing decision that switches the connection to another path.
*/
-void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
+void tcp_plb_check_rehash(struct sock *sk)
{
+ bool forced_rehash = false, idle_rehash = false;
+ struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
u32 max_suspend;
- bool forced_rehash = false, idle_rehash = false;
if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
return;
- forced_rehash = plb->consec_cong_rounds >=
+ forced_rehash = tp->plb_consec_cong_rounds >=
READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds);
/* If sender goes idle then we check whether to rehash. */
idle_rehash = READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds) &&
!tcp_sk(sk)->packets_out &&
- plb->consec_cong_rounds >=
+ tp->plb_consec_cong_rounds >=
READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
if (!forced_rehash && !idle_rehash)
@@ -70,19 +71,19 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
* RTO event that constrains PLB rehashing.
*/
max_suspend = 2 * READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
- if (plb->pause_until &&
- (!before(tcp_jiffies32, plb->pause_until) ||
- before(tcp_jiffies32 + max_suspend, plb->pause_until)))
- plb->pause_until = 0;
+ if (tp->plb_pause_until &&
+ (!before(tcp_jiffies32, tp->plb_pause_until) ||
+ before(tcp_jiffies32 + max_suspend, tp->plb_pause_until)))
+ tp->plb_pause_until = 0;
- if (plb->pause_until)
+ if (tp->plb_pause_until)
return;
if (!__sk_rethink_txhash_reset_dst(sk))
return;
- plb->consec_cong_rounds = 0;
- WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1);
+ tp->plb_consec_cong_rounds = 0;
+ WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
}
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
@@ -91,8 +92,9 @@ EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
* balancing decisions switch traffic to a black-holed path that was
* previously avoided with a sk_rethink_txhash() call at RTO time.
*/
-void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
+void tcp_plb_update_state_upon_rto(struct sock *sk)
{
+ struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
u32 pause;
@@ -102,13 +104,13 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
if (pause) {
pause += get_random_u32_below(pause);
- plb->pause_until = tcp_jiffies32 + pause;
+ tp->plb_pause_until = tcp_jiffies32 + pause;
}
/* Reset PLB state upon RTO, since an RTO causes a sk_rethink_txhash() call
* that may switch this connection to a path with completely different
* congestion characteristics.
*/
- plb->consec_cong_rounds = 0;
+ tp->plb_consec_cong_rounds = 0;
}
EXPORT_SYMBOL_GPL(tcp_plb_update_state_upon_rto);
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (2 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 8:54 ` [PATCH v1 net-next 05/10] tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn() Kuniyuki Iwashima
` (6 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
dctcp_cwnd_event() calls tcp_plb_update_state_upon_rto() upon
CA_EVENT_LOSS in tcp_enter_loss() to reset plb_consec_cong_rounds
and pause PLB after an RTO triggers a path rehash.
However, tcp_enter_loss() does not always correspond to an RTO
rehash:
1. tcp_enter_loss() is called from 3 paths but the first two
do not rehash the flow:
- tcp_fastopen_synack_timer()
- tcp_retransmit_timer() when !tp->snd_wnd
- tcp_retransmit_timer() when tcp_write_timeout() returns 0
2. Even on the last path, tcp_enter_loss() skips CA_EVENT_LOSS
if after(tp->high_seq, tp->snd_una) is true and the socket
is in TCP_CA_CWR (e.g. after receiving ECN CE in DCTCP),
TCP_CA_Recovery, or TCP_CA_Loss with icsk_retransmits > 0.
In the second case, even when tcp_write_timeout() rehashes the
flow, tcp_plb_update_state_upon_rto() is missed.
Then, a subsequent tcp_plb_check_rehash() in dctcp_update_alpha()
or dctcp_cwnd_event_tx_start() can immediately rehash the flow
again, potentially back to the previous bad path.
Let's move tcp_plb_update_state_upon_rto() just after
__sk_rethink_txhash_reset_dst() in tcp_write_timeout().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
net/ipv4/tcp_dctcp.c | 1 -
net/ipv4/tcp_plb.c | 1 -
net/ipv4/tcp_timer.c | 1 +
3 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
index bc3724d1da90..bbfff24ed5f0 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -198,7 +198,6 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
dctcp_ece_ack_update(sk, ev, &ca->prior_rcv_nxt, &ca->ce_state);
break;
case CA_EVENT_LOSS:
- tcp_plb_update_state_upon_rto(sk);
dctcp_react_to_loss(sk);
break;
default:
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 26ca53d6fb9d..c21fcb7945c0 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -113,4 +113,3 @@ void tcp_plb_update_state_upon_rto(struct sock *sk)
*/
tp->plb_consec_cong_rounds = 0;
}
-EXPORT_SYMBOL_GPL(tcp_plb_update_state_upon_rto);
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
index 814fadb30749..a3210cda2515 100644
--- a/net/ipv4/tcp_timer.c
+++ b/net/ipv4/tcp_timer.c
@@ -297,6 +297,7 @@ static int tcp_write_timeout(struct sock *sk)
}
if (__sk_rethink_txhash_reset_dst(sk)) {
+ tcp_plb_update_state_upon_rto(sk);
WRITE_ONCE(tp->timeout_rehash, tp->timeout_rehash + 1);
__NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTREHASH);
}
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 05/10] tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (3 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout() Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash() Kuniyuki Iwashima
` (5 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
The current PLB requires ECN signals.
We will introduce Generic PLB, which does not use ECN.
Let's rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
include/net/tcp.h | 2 +-
net/ipv4/tcp_dctcp.c | 4 ++--
net/ipv4/tcp_plb.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index bcff640c16a1..7e53293ed3c8 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2736,7 +2736,7 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
#define TCP_PLB_SCALE 8
void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
-void tcp_plb_check_rehash(struct sock *sk);
+void tcp_plb_check_rehash_ecn(struct sock *sk);
void tcp_plb_update_state_upon_rto(struct sock *sk);
static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
index bbfff24ed5f0..37653a8765c9 100644
--- a/net/ipv4/tcp_dctcp.c
+++ b/net/ipv4/tcp_dctcp.c
@@ -144,7 +144,7 @@ __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
if (delivered_ce > 0)
ce_ratio = (delivered_ce << TCP_PLB_SCALE) / delivered;
tcp_plb_update_state(sk, (int)ce_ratio);
- tcp_plb_check_rehash(sk);
+ tcp_plb_check_rehash_ecn(sk);
}
/* alpha = (1 - g) * alpha + g * F */
@@ -208,7 +208,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
__bpf_kfunc static void dctcp_cwnd_event_tx_start(struct sock *sk)
{
- tcp_plb_check_rehash(sk); /* Maybe rehash when inflight is 0 */
+ tcp_plb_check_rehash_ecn(sk); /* Maybe rehash when inflight is 0 */
}
static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index c21fcb7945c0..0006d3b1bf55 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -44,7 +44,7 @@ EXPORT_SYMBOL_GPL(tcp_plb_update_state);
/* Check whether recent congestion has been persistent enough to warrant
* a load balancing decision that switches the connection to another path.
*/
-void tcp_plb_check_rehash(struct sock *sk)
+void tcp_plb_check_rehash_ecn(struct sock *sk)
{
bool forced_rehash = false, idle_rehash = false;
struct tcp_sock *tp = tcp_sk(sk);
@@ -86,7 +86,7 @@ void tcp_plb_check_rehash(struct sock *sk)
WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
}
-EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
+EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
/* Upon RTO, disallow load balancing for a while, to avoid having load
* balancing decisions switch traffic to a black-holed path that was
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash().
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (4 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 05/10] tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn() Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default Kuniyuki Iwashima
` (4 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
We will introduces Generic PLB.
It will share some code with tcp_plb_check_rehash_ecn() to
perform rehash, update plb_pause_until, and increment stats.
Let's factorise the common part as tcp_plb_rehash().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
net/ipv4/tcp_plb.c | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 0006d3b1bf55..794bddc4dc2d 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -41,30 +41,12 @@ void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
}
EXPORT_SYMBOL_GPL(tcp_plb_update_state);
-/* Check whether recent congestion has been persistent enough to warrant
- * a load balancing decision that switches the connection to another path.
- */
-void tcp_plb_check_rehash_ecn(struct sock *sk)
+static void tcp_plb_rehash(struct sock *sk)
{
- bool forced_rehash = false, idle_rehash = false;
struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
u32 max_suspend;
- if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
- return;
-
- forced_rehash = tp->plb_consec_cong_rounds >=
- READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds);
- /* If sender goes idle then we check whether to rehash. */
- idle_rehash = READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds) &&
- !tcp_sk(sk)->packets_out &&
- tp->plb_consec_cong_rounds >=
- READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
-
- if (!forced_rehash && !idle_rehash)
- return;
-
/* Note that tcp_jiffies32 can wrap; we detect wraps by checking for
* cases where the max suspension end is before the actual suspension
* end. We clear pause_until to 0 to indicate there is no recent
@@ -86,6 +68,32 @@ void tcp_plb_check_rehash_ecn(struct sock *sk)
WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
}
+
+/* Check whether recent congestion has been persistent enough to warrant
+ * a load balancing decision that switches the connection to another path.
+ */
+void tcp_plb_check_rehash_ecn(struct sock *sk)
+{
+ bool forced_rehash = false, idle_rehash = false;
+ struct tcp_sock *tp = tcp_sk(sk);
+ struct net *net = sock_net(sk);
+
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
+ return;
+
+ forced_rehash = tp->plb_consec_cong_rounds >=
+ READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds);
+ /* If sender goes idle then we check whether to rehash. */
+ idle_rehash = READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds) &&
+ !tcp_sk(sk)->packets_out &&
+ tp->plb_consec_cong_rounds >=
+ READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
+
+ if (!forced_rehash && !idle_rehash)
+ return;
+
+ tcp_plb_rehash(sk);
+}
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
/* Upon RTO, disallow load balancing for a while, to avoid having load
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (5 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash() Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (3 subsequent siblings)
10 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
tcp_plb_suspend_rto_sec specifies the base duration to suspend
PLB repathing after an RTO triggers a rehash, pausing PLB for a
random duration in [1x, 2x) of this value. Currently, it defaults
to 60, suspending PLB for 60 - 120 seconds.
ECN-PLB normally detects congestion via ECN before an RTO occurs,
so stopping PLB upon RTO rarely becomes an issue. However, even
under ECN-PLB, 60 - 120 seconds is unnecessarily long and lowers
fairness when occasional RTOs happen.
Moreover, Generic PLB introduced by the next patch runs alongside
occasional tail-drop and probe-induced RTOs, where suspending PLB
for 60 - 120 seconds effectively disables it.
On the other hand, setting tcp_plb_suspend_rto_sec to 0 allows
flows rescued off a blackholed link by an RTO to be immediately
rehashed back onto the dead path upon subsequent congestion or
probe losses.
A 5-second base duration (5 - 10 second pause) keeps both ECN-PLB
and Generic PLB responsive without causing immediate re-entry
thrashing onto blackholed links.
Let's lower the default value to 5.
Note that the link-repair-time guidance in ip-sysctl.rst is also
removed, as this setting balances blackhole cooldown against PLB
responsiveness rather than link repair time.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Documentation/networking/ip-sysctl.rst | 5 ++---
net/ipv4/tcp_ipv4.c | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index 671011c74e14..dffcec335a77 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1413,12 +1413,11 @@ tcp_plb_suspend_rto_sec - INTEGER
having PLB repath onto a connectivity "black hole", after an RTO a TCP
connection suspends PLB repathing for a random duration between 1x and
2x of this parameter. Randomness is added to avoid concurrent rehashing
- of multiple TCP connections. This should be set corresponding to the
- amount of time it takes to repair a failed link.
+ of multiple TCP connections.
Possible Values: 0 - 255
- Default: 60
+ Default: 5
tcp_plb_cong_thresh - INTEGER
Fraction of packets marked with congestion over a round (RTT) to
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index f2a5c8f3bf9d..14ba61845f49 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -3528,7 +3528,7 @@ static int __net_init tcp_sk_init(struct net *net)
net->ipv4.sysctl_tcp_plb_enabled = 0; /* Disabled by default */
net->ipv4.sysctl_tcp_plb_idle_rehash_rounds = 3;
net->ipv4.sysctl_tcp_plb_rehash_rounds = 12;
- net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 60;
+ net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 5;
/* Default congestion threshold for PLB to mark a round is 50% */
net->ipv4.sysctl_tcp_plb_cong_thresh = (1 << TCP_PLB_SCALE) / 2;
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (6 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
` (2 subsequent siblings)
10 siblings, 1 reply; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
Currently, PLB (Protective Load Balancing) relies on ECN signals
and is only hooked into DCTCP. However, ECN is often unavailable
in cloud VM and virtualised network environments, and widely deployed
congestion control algorithms such as CUBIC and BBR cannot benefit
from PLB.
This commit introduces Generic PLB, a congestion-control-agnostic
PLB mechanism triggered by a combination of packet loss and low
delivery rate.
Generic PLB adds one per-netns sysctl knob:
net.ipv4.tcp_plb_loss_rehash_prob (default: 128, range: 0 - 255)
Every 5th Fast Recovery, tcp_plb_check_rehash_loss() computes a
rehash probability in [0, 255] from rate_prob and floor, and
rehashes the flow via tcp_plb_rehash() if a random number in
[0, 254] is smaller than the probability:
prob = max(rate_prob, floor)
if (get_random_u32_below(255) < prob)
tcp_plb_rehash(sk);
1. Rehash probability based on delivery rate regression (rate_prob)
rate_prob is a repath probability calculation that reflects
how much the current delivery rate (cur_rate) has regressed
relative to tp->plb_max_rate, the highest delivery rate recorded
in tcp_rate_gen():
deficit = (plb_max_rate - cur_rate) / plb_max_rate
rate_prob = min(255, 4 * base_prob * deficit^2)
Squaring deficit suppresses noise churn under small jitter
while quickly evacuating severely degraded paths.
To filter burst noise and avoid 64-bit division on the ACK
fast path, tcp_rate_gen() updates tp->plb_max_rate when a
sample exceeds tp->plb_max_rate by more than 1/8, applying
1/8 upward EWMA after the first sample.
2. Rehash probability floor (floor):
rate_prob cannot trigger when a flow initially lands on a bad
path and has not yet observed a healthy rate. Thus, floor is
used to explore alternative paths.
For the first two rehashes (tp->plb_rehash < 2), floor is set
to base_prob >> 1 (25% at default 128). The cumulative
rehash probability across n evaluations is:
1 - (1 - p)^n
With tcp_plb_loss_rehash_prob = 128, a flow rehashes by the
20th Fast Recovery (n = 4) with ~68% probability:
1 - (1 - 0.25)^4 = 0.6836
Once the flow has rehashed twice (tp->plb_rehash >= 2), it
likely already knows a healthy tp->plb_max_rate, where a 25%
floor is too high and causes unnecessary churn. Thus, floor
is lowered to base_prob >> 3 (6.25%) thereafter.
3. Stale-hop peak rate decay (tp->plb_stale_hops):
After repathing, keeping tp->plb_max_rate at a stale high value
can inflate rehashes if all paths share lower bandwidth.
Conversely, decaying tp->plb_max_rate on every single hop erodes
good-path memory during short exploration on asymmetric ECMP.
Therefore, tp->plb_stale_hops counts consecutive rehashes
without recovery within ~15% of the peak (deficit < 38).
Once three consecutive rehashes stay >= ~15% below
tp->plb_max_rate, each subsequent stale rehash decays
tp->plb_max_rate by 1/8 (to 7/8) so the flow adapts to the
new paths.
Below are benchmark results with the script below [0] across a 4-way
IPv6 ECMP router topology (r0..r3, net.ipv6.fib_multipath_hash_policy
= 0) under three failure and weight-mismatch scenarios:
a. Single-link degradation with 3% random packet loss (base RTT 4 ms;
r0..r2: 4 Gbps healthy, r3: 800 Mbps with 3% loss; 20 flows paced
at 440 Mbps = 8.8 Gbps total demand; mean of 3 runs):
Scenario Total(M) Min(M) Jain Flows(r0..r3) Retrans
---------------------------- -------- ------ ------ --------------- -------
20x CUBIC (PLB OFF) 7699.77 16.10 0.8925 5.7/5.3/6.7/2.7 1088
20x CUBIC (Generic-PLB ON) 8578.08 313.25 0.9917 6.3/7.0/6.3/0.3 390
20x BBR (PLB OFF) 8116.67 228.09 0.9704 4.7/6.0/6.3/3.0 18552
20x BBR (Generic-PLB ON) 8643.48 424.69 0.9997 8.0/5.3/6.7/0.0 908
20x DCTCP (PLB OFF) 7160.94 27.71 0.8308 4.7/5.3/6.0/4.0 1951
20x DCTCP (Both PLB ON) 8700.88 415.98 0.9998 6.3/6.7/7.0/0.3 303
10x CUBIC + 10x BBR (OFF) 7333.90 8.02 0.8873 6.0/5.0/5.0/4.0 16615
10x CUBIC + 10x BBR (ON) 8563.66 364.49 0.9980 6.0/8.0/5.7/1.0 2816
10x CUBIC + 10x DCTCP (OFF) 7036.39 24.59 0.8314 5.7/6.3/4.3/3.7 2023
10x CUBIC + 10x DCTCP (ON) 8380.88 172.64 0.9745 5.7/6.7/7.0/0.7 656
Generic PLB evacuates flows from the lossy path r3, recovering
per-flow minimum goodput and reducing retransmissions by 64% - 95%.
b. Spine switch failure / ECMP hash-collapse (base RTT 4 ms; 8 switches
in 4 pairs of 2.8 Gbps; one switch in pair r3 fails so r3 has
1.4 Gbps capacity and half buffer with 0% random loss while still
receiving 1/4 of ECMP hashes; 56 flows paced at 160 Mbps = 8.96 Gbps
demand, 96% of surviving capacity; mean of 3 runs):
Scenario Total(M) Min(M) Jain Flows(r0..r3) Retrans
---------------------------- -------- ------ ------ ------------------- -------
56x CUBIC (PLB OFF) 7894.50 80.31 0.9584 14.0/14.3/12.3/12.3 5148
56x CUBIC (Generic-PLB ON) 8604.32 143.26 0.9994 16.7/15.7/15.7/7.7 4041
56x BBR (PLB OFF) 8576.75 146.80 0.9997 16.0/15.3/16.0/7.3 27681
56x BBR (Generic-PLB ON) 8641.33 149.46 0.9998 15.3/16.3/16.3/7.7 14884
56x DCTCP (PLB OFF) 7982.80 95.07 0.9642 14.7/14.7/15.0/11.7 6083
56x DCTCP (Both PLB ON) 8632.26 144.06 0.9995 15.7/16.0/16.0/8.3 3502
28x CUBIC + 28x BBR (OFF) 8149.27 94.77 0.9811 15.3/16.0/13.7/9.7 8480
28x CUBIC + 28x BBR (ON) 8585.09 140.94 0.9993 16.7/15.0/15.7/7.3 5143
28x CUBIC + 28x DCTCP (OFF) 7826.17 78.05 0.9643 11.7/18.0/14.0/12.3 6329
28x CUBIC + 28x DCTCP (ON) 8623.33 147.09 0.9996 15.7/16.0/15.3/8.7 3857
Generic PLB spreads flows in proportion to path capacity (converging
towards the ideal 16/16/16/8 flow distribution across [2.8G, 2.8G,
2.8G, 1.4G]), recovering minimum flow goodput and cutting
retransmissions by 22% - 46%.
c. Inverted WCMP weight mismatch (2 ms return delay, HTB + bfifo with
TSO/GSO/GRO enabled; 64 flows across r0..r3 with weights
[1, 1, 2, 2] vs capacities [3.2G, 3.2G, 1.6G, 1.6G] for M=4, and
[1, 1, 3, 3] vs [3.6G, 3.6G, 1.2G, 1.2G] for M=9, where
M = (w_b / c_b) / (w_a / c_a) is the worst-to-best ratio of WCMP
weight fraction w_i = weight_i / sum(weight) to capacity fraction
c_i = cap_i / sum(cap); CUBIC unpaced, BBR unpaced for M=4 and
paced at 120 Mbps for M=9; mean of 5 runs):
Scenario Total(M) Min(M) Jain Share(r0..r3 %) Retrans
---------------------------- -------- ------ ------ ------------------- -------
64x CUBIC M=4 (PLB OFF) 9049.36 57.59 0.6479 34.6/33.4/16.3/15.7 30246
64x CUBIC M=4 (Generic-PLB) 9053.84 66.40 0.8984 34.5/33.5/16.3/15.7 29921
64x BBR M=4 (PLB OFF) 9036.99 43.09 0.7037 34.8/33.5/16.2/15.5 1072387
64x BBR M=4 (Generic-PLB) 9046.21 56.38 0.8062 34.7/33.5/16.2/15.5 1106217
64x CUBIC M=9 (PLB OFF) 9054.20 36.43 0.4541 38.7/37.4/12.2/11.8 24724
64x CUBIC M=9 (Generic-PLB) 9053.08 40.46 0.7532 38.7/37.5/12.2/11.7 28021
64x BBR M=9 120M (PLB OFF) 4908.21 26.49 0.8216 25.9/29.5/22.8/21.8 104658
64x BBR M=9 120M (Generic-PLB) 5748.63 31.60 0.8796 33.2/29.5/19.2/18.1 8310
Under extreme M=4 and M=9 weight inversions, Generic PLB migrates
excess flows off the overloaded r2/r3 paths towards the underutilised
r0/r1 paths, improving per-flow Jain's index across both CUBIC and
BBR (0.45 -> 0.75 on unpaced CUBIC M=9) and raising aggregate BBR
goodput by +17.1% while cutting retransmissions by 92.1% on M=9.
Link: https://gist.github.com/q2ven/c04b56477dea4d1a58f5eadc4b07f9e0 #[0]
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
Documentation/networking/ip-sysctl.rst | 19 ++++-
.../net_cachelines/netns_ipv4_sysctl.rst | 1 +
.../networking/net_cachelines/tcp_sock.rst | 3 +
include/linux/tcp.h | 5 ++
include/net/netns/ipv4.h | 3 +-
include/net/tcp.h | 1 +
net/core/net_namespace.c | 2 +
net/ipv4/sysctl_net_ipv4.c | 7 ++
net/ipv4/tcp.c | 4 ++
net/ipv4/tcp_input.c | 15 ++++
net/ipv4/tcp_ipv4.c | 1 +
net/ipv4/tcp_plb.c | 69 +++++++++++++++++--
12 files changed, 123 insertions(+), 7 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
index dffcec335a77..3046f6725b21 100644
--- a/Documentation/networking/ip-sysctl.rst
+++ b/Documentation/networking/ip-sysctl.rst
@@ -1360,8 +1360,8 @@ tcp_child_ehash_entries - INTEGER
tcp_plb_enabled - BOOLEAN
If enabled and the underlying congestion control (e.g. DCTCP) supports
- and enables PLB feature, TCP PLB (Protective Load Balancing) is
- enabled. PLB is described in the following paper:
+ ECN-based PLB feature, TCP PLB (Protective Load Balancing) is enabled.
+ PLB is described in the following paper:
https://doi.org/10.1145/3544216.3544226. Based on PLB parameters,
upon sensing sustained congestion, TCP triggers a change in
flow label field for outgoing IPv6 packets. A change in flow label
@@ -1437,6 +1437,21 @@ tcp_plb_cong_thresh - INTEGER
Default: 128
+tcp_plb_loss_rehash_prob - INTEGER
+ Base probability for Generic PLB repathing, mapped from [0, 1]
+ to [0, 255] (e.g., 128 means 50%). Setting this to 0 disables
+ Generic PLB.
+
+ Unlike tcp_plb_enabled which relies on ECN signals, Generic PLB
+ is congestion-control-agnostic and triggers repathing based on
+ packet loss and delivery rate regression relative to the flow's
+ recent peak delivery rate. Larger tcp_plb_loss_rehash_prob
+ values make repathing more aggressive.
+
+ Possible Values: 0 - 255
+
+ Default: 128
+
tcp_pingpong_thresh - INTEGER
The number of estimated data replies sent for estimated incoming data
requests that must happen before TCP considers that a connection is a
diff --git a/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst b/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst
index 2833ce6cba1d..99cccfbb5444 100644
--- a/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst
+++ b/Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst
@@ -136,6 +136,7 @@ u32 tcp_challenge_count
u8 sysctl_tcp_plb_enabled
u8 sysctl_tcp_plb_idle_rehash_rounds
u8 sysctl_tcp_plb_rehash_rounds
+u8 sysctl_tcp_plb_loss_rehash_prob read_mostly tcp_rate_gen
u8 sysctl_tcp_plb_suspend_rto_sec
int sysctl_tcp_plb_cong_thresh
int sysctl_udp_wmem_min
diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
index 6eb058478665..43fcfd0356c0 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -159,11 +159,14 @@ u8 bpf_sock_ops_cb_flags
u8:1 bpf_chg_cc_inprogress
u16 timeout_rehash
u8 plb_consec_cong_rounds
+u8 plb_loss_recoveries
+u8 plb_stale_hops
u32 plb_pause_until
u32 rcv_ooopack
u32 rcv_rtt_last_tsecr
struct rcv_rtt_est read_write tcp_rcv_space_adjust,tcp_rcv_established
struct rcvq_space read_write tcp_rcv_space_adjust
+u64 plb_max_rate read_write tcp_rate_gen
struct mtu_probe
u32 plb_rehash
u32 mtu_info
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 3f275ac8e512..cdbd25e2a26b 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -379,6 +379,9 @@ struct tcp_sock {
u32 seq;
u64 time;
} rcvq_space;
+ u64 plb_max_rate; /* PLB est. recent max rate
+ * ((MSS packets / us) << 20)
+ */
__cacheline_group_end(tcp_sock_write_rx);
/* End of Hot Path */
@@ -508,6 +511,8 @@ struct tcp_sock {
/* State for PLB (Protective Load Balancing) for a single TCP connection. */
u8 plb_consec_cong_rounds; /* consecutive congested rounds */
+ u8 plb_loss_recoveries; /* fast recoveries since last PLB check */
+ u8 plb_stale_hops; /* consecutive degraded rehashes */
u32 plb_pause_until; /* jiffies32 when PLB can resume rerouting */
u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 3efbc7f4b4f7..b225f30580f9 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -83,7 +83,8 @@ struct netns_ipv4 {
u8 sysctl_ip_early_demux;
u8 sysctl_tcp_early_demux;
u8 sysctl_tcp_l3mdev_accept;
- /* 3 bytes hole, try to pack */
+ u8 sysctl_tcp_plb_loss_rehash_prob;
+ /* 1 bytes hole, try to pack */
int sysctl_tcp_reordering;
int sysctl_tcp_rmem[3];
int sysctl_tcp_rcvbuf_low_rtt;
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 7e53293ed3c8..a956ed173e70 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2737,6 +2737,7 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
void tcp_plb_check_rehash_ecn(struct sock *sk);
+void tcp_plb_check_rehash_loss(struct sock *sk);
void tcp_plb_update_state_upon_rto(struct sock *sk);
static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 217021eeab13..e12de8cf7707 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -1252,6 +1252,8 @@ static void __init netns_ipv4_struct_check(void)
sysctl_tcp_early_demux);
CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
sysctl_tcp_l3mdev_accept);
+ CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
+ sysctl_tcp_plb_loss_rehash_prob);
CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
sysctl_tcp_reordering);
CACHELINE_ASSERT_GROUP_MEMBER(struct netns_ipv4, netns_ipv4_read_rx,
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index fb0f3124836d..f99852d3fda4 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -1598,6 +1598,13 @@ static const struct ctl_table ipv4_net_table[] = {
.proc_handler = proc_dou8vec_minmax,
.extra2 = &tcp_plb_max_rounds,
},
+ {
+ .procname = "tcp_plb_loss_rehash_prob",
+ .data = &init_net.ipv4.sysctl_tcp_plb_loss_rehash_prob,
+ .maxlen = sizeof(u8),
+ .mode = 0644,
+ .proc_handler = proc_dou8vec_minmax,
+ },
{
.procname = "tcp_plb_suspend_rto_sec",
.data = &init_net.ipv4.sysctl_tcp_plb_suspend_rto_sec,
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 002eaca58c46..aa18d018f2eb 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3487,8 +3487,11 @@ int tcp_disconnect(struct sock *sk, int flags)
tp->sacked_out = 0;
tp->tlp_high_seq = 0;
tp->last_oow_ack_time = 0;
+ tp->plb_max_rate = 0;
tp->plb_rehash = 0;
tp->plb_consec_cong_rounds = 0;
+ tp->plb_loss_recoveries = 0;
+ tp->plb_stale_hops = 0;
tp->plb_pause_until = 0;
/* There's a bubble in the pipe until at least the first ACK. */
tp->app_limited = ~0U;
@@ -5330,6 +5333,7 @@ static void __init tcp_struct_check(void)
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_collapse_credit);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcv_rtt_est);
CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, rcvq_space);
+ CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_rx, plb_max_rate);
}
void __init tcp_init(void)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 975e6501aef8..8902103ab932 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1831,6 +1831,18 @@ static void tcp_rate_gen(struct sock *sk, u32 delivered, u32 lost,
tp->rate_delivered = rs->delivered;
tp->rate_interval_us = rs->interval_us;
tp->rate_app_limited = rs->is_app_limited;
+
+ if (READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_plb_loss_rehash_prob) &&
+ (u64)rs->delivered << 20 >
+ (u64)(tp->plb_max_rate + (tp->plb_max_rate >> 3)) * rs->interval_us) {
+ u64 new_rate;
+
+ new_rate = div64_ul((u64)rs->delivered << 20, rs->interval_us);
+ if (!tp->plb_max_rate)
+ tp->plb_max_rate = new_rate;
+ else
+ tp->plb_max_rate += (new_rate - tp->plb_max_rate) >> 3;
+ }
}
}
@@ -3235,6 +3247,8 @@ void tcp_enter_recovery(struct sock *sk, bool ece_ack)
tcp_init_cwnd_reduction(sk);
}
tcp_set_ca_state(sk, TCP_CA_Recovery);
+
+ tcp_plb_check_rehash_loss(sk);
}
static void tcp_update_rto_time(struct tcp_sock *tp)
@@ -4201,6 +4215,7 @@ static void tcp_process_tlp_ack(struct sock *sk, u32 ack, int flag)
tcp_try_keep_open(sk);
NET_INC_STATS(sock_net(sk),
LINUX_MIB_TCPLOSSPROBERECOVERY);
+ tcp_plb_check_rehash_loss(sk);
} else if (!(flag & (FLAG_SND_UNA_ADVANCED |
FLAG_NOT_DUP | FLAG_DATA_SACKED))) {
/* Pure dupack: original and TLP probe arrived; no loss */
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 14ba61845f49..05c916a3f34e 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -3531,6 +3531,7 @@ static int __net_init tcp_sk_init(struct net *net)
net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 5;
/* Default congestion threshold for PLB to mark a round is 50% */
net->ipv4.sysctl_tcp_plb_cong_thresh = (1 << TCP_PLB_SCALE) / 2;
+ net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128;
/* Reno is always built in */
if (!net_eq(net, &init_net) &&
diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
index 794bddc4dc2d..324bcb27f540 100644
--- a/net/ipv4/tcp_plb.c
+++ b/net/ipv4/tcp_plb.c
@@ -41,7 +41,7 @@ void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
}
EXPORT_SYMBOL_GPL(tcp_plb_update_state);
-static void tcp_plb_rehash(struct sock *sk)
+static bool tcp_plb_rehash(struct sock *sk)
{
struct tcp_sock *tp = tcp_sk(sk);
struct net *net = sock_net(sk);
@@ -59,14 +59,16 @@ static void tcp_plb_rehash(struct sock *sk)
tp->plb_pause_until = 0;
if (tp->plb_pause_until)
- return;
+ return false;
if (!__sk_rethink_txhash_reset_dst(sk))
- return;
+ return false;
tp->plb_consec_cong_rounds = 0;
+ tp->plb_loss_recoveries = 0;
WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
+ return true;
}
/* Check whether recent congestion has been persistent enough to warrant
@@ -96,6 +98,63 @@ void tcp_plb_check_rehash_ecn(struct sock *sk)
}
EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
+void tcp_plb_check_rehash_loss(struct sock *sk)
+{
+ u32 base_prob, rate_prob, floor, prob;
+ struct tcp_sock *tp = tcp_sk(sk);
+ struct net *net = sock_net(sk);
+ u64 cur_rate, max_rate;
+
+ base_prob = READ_ONCE(net->ipv4.sysctl_tcp_plb_loss_rehash_prob);
+ if (!base_prob)
+ return;
+
+ if (++tp->plb_loss_recoveries < 5)
+ return;
+
+ tp->plb_loss_recoveries = 0;
+
+ /* self-normalise MSS-per-sec rate, using the highest
+ * observed rate. More regression, more rehash.
+ */
+ rate_prob = 0;
+ cur_rate = (u64)tp->rate_delivered << 20;
+ max_rate = tp->plb_max_rate * tp->rate_interval_us;
+ if (max_rate > cur_rate) {
+ u64 deficit;
+
+ deficit = mul_u64_u64_div_u64(max_rate - cur_rate,
+ 1 << 8, max_rate);
+ rate_prob = (4 * base_prob * deficit * deficit) >> 16;
+ rate_prob = min_t(u32, rate_prob, 255);
+
+ /* Don't decay plb_max_rate if the regression is
+ * under 15% (38/256).
+ */
+ if (deficit < 38)
+ tp->plb_stale_hops = 0;
+ } else {
+ tp->plb_stale_hops = 0;
+ }
+
+ if (tp->plb_rehash < 2)
+ floor = base_prob >> 1;
+ else
+ floor = base_prob >> 3;
+
+ prob = max(rate_prob, floor);
+ if (get_random_u32_below(255) >= prob)
+ return;
+
+ if (!tcp_plb_rehash(sk))
+ return;
+
+ if (tp->plb_stale_hops < 3)
+ tp->plb_stale_hops++;
+ if (tp->plb_stale_hops == 3)
+ tp->plb_max_rate -= tp->plb_max_rate >> 3;
+}
+
/* Upon RTO, disallow load balancing for a while, to avoid having load
* balancing decisions switch traffic to a black-holed path that was
* previously avoided with a sk_rethink_txhash() call at RTO time.
@@ -106,7 +165,8 @@ void tcp_plb_update_state_upon_rto(struct sock *sk)
struct net *net = sock_net(sk);
u32 pause;
- if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
+ if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled) &&
+ !READ_ONCE(net->ipv4.sysctl_tcp_plb_loss_rehash_prob))
return;
pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
@@ -120,4 +180,5 @@ void tcp_plb_update_state_upon_rto(struct sock *sk)
* congestion characteristics.
*/
tp->plb_consec_cong_rounds = 0;
+ tp->plb_loss_recoveries = 0;
}
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for Generic PLB.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (7 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 8:54 ` [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh Kuniyuki Iwashima
2026-12-04 9:03 ` [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB netdev-bot+sinfo
10 siblings, 1 reply; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
tcp_plb_loss_rate.pkt verifies that rehash happens when
cur_rate drops sharply.
tcp_plb_loss_rto_suspend.pkt verifies Generic PLB is also
suspended for net.ipv4.tcp_plb_suspend_rto_sec seconds.
tcp_plb_loss_tlp.pkt verifies spurious TLP does not rehash
but TLP loss rehashes the flow.
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
.../net/packetdrill/tcp_plb_loss_rate.pkt | 83 +++++++++
.../packetdrill/tcp_plb_loss_rto_suspend.pkt | 166 ++++++++++++++++++
.../net/packetdrill/tcp_plb_loss_tlp.pkt | 102 +++++++++++
3 files changed, 351 insertions(+)
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
new file mode 100644
index 000000000000..2e81fde34e60
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test TCP Generic PLB: rate-drop triggered PLB rehash in Fast Recovery.
+// - Phase 1: 4 Fast Recovery rounds (< 5) -> no rehash.
+// - Phase 2: Record non-app-limited plb_max_rate, then drop cur_rate
+// upon entering the 5th Fast Recovery -> rehash.
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_early_retrans=0
+sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+// Use 10ms handshake RTT (srtt ~ 10ms, RTO ~ 210ms > 50ms rate-drop wait).
+ +.01 < S 0:0(0) win 32792 <mss 100,sackOK,nop,nop,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
+ +.01 < . 1:1(0) ack 1 win 320
+ +0 accept(3, ..., ...) = 4
+
+// Grow cwnd to 40 in Slow Start and record high plb_max_rate (~1125B / 10ms).
+ +0 write(4, ..., 3000) = 3000
+ +0 > (flowlabel 0x1) P. 1:1001(1000) ack 1
+ +.01 < . 1:1(0) ack 1001 win 320
+ +0 > (flowlabel 0x1) P. 1001:3001(2000) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320
+
+// Phase 1: 4 Fast Recovery rounds (plb_loss_recoveries = 1..4 < 5 -> no rehash).
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3001:3401(400) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320 <sack 3101:3401,nop,nop>
+ +0 > (flowlabel 0x1) . 3001:3101(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3401 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3401:3801(400) ack 1
+ +.01 < . 1:1(0) ack 3401 win 320 <sack 3501:3801,nop,nop>
+ +0 > (flowlabel 0x1) . 3401:3501(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3801 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3801:4201(400) ack 1
+ +.01 < . 1:1(0) ack 3801 win 320 <sack 3901:4201,nop,nop>
+ +0 > (flowlabel 0x1) . 3801:3901(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4201 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 4201:4601(400) ack 1
+ +.01 < . 1:1(0) ack 4201 win 320 <sack 4301:4601,nop,nop>
+ +0 > (flowlabel 0x1) . 4201:4301(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4601 win 320
+ +0 %{ assert tcpi_ca_state == TCP_CA_Open, tcpi_ca_state }%
+
+// Phase 2 (5th recovery with delivery rate drop -> rehash): cwnd == 9.
+// Write 9 + 4 = 13 segments (1300B).
+// Batch 1 (900B) is sent with is_app_limited = 1.
+ +.01 write(4, ..., 1300) = 1300
+ +0 > (flowlabel 0x1) . 4601:5501(900) ack 1
+
+// ACK Batch 1 at +.01: clears app_limited and clocks out Batch 2 (400B)
+// with is_app_limited = 0.
+ +.01 < . 1:1(0) ack 5501 win 320
+ +0 > (flowlabel 0x1) P. 5501:5901(400) ack 1
+
+// Lose 5501:5601.
+// 1st SACK at +.05 updates rate sample to 1 segment / 50ms with is_app_limited = 0.
+// 2nd SACK makes sacked_out == 3 and enters Fast Recovery on the 5th recovery.
+ +.05 < . 1:1(0) ack 5501 win 320 <sack 5601:5701,nop,nop>
+ +0 < . 1:1(0) ack 5501 win 320 <sack 5601:5901,nop,nop>
+
+// Rate-drop on 5th recovery triggers rehash:
+// Fast retransmit has flowlabel 0x2 and tcpi_rehash == 1.
+ +0 > (flowlabel 0x2) . 5501:5601(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+
+// Clean finish.
+ +.01 < . 1:1(0) ack 5901 win 320
diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
new file mode 100644
index 000000000000..c44f7c65c8e5
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rto_suspend.pkt
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test TCP Generic PLB: RTO reset of plb_loss_recoveries and RTO suspension.
+// - Pre-RTO: 1 Fast Recovery sets plb_loss_recoveries = 1.
+// - RTO: rehashes the socket, sets plb_pause_until to [1.0s, 2.0s),
+// and resets plb_loss_recoveries to 0.
+// - Phase 1: 5 Fast Recoveries within < 1.0s reach plb_loss_recoveries == 5
+// with rate_prob == 255, but rehash is suppressed by plb_pause_until.
+// - Phase 2: After > 2.0s, 4 Fast Recoveries (< 5) do not rehash, and the
+// 5th Fast Recovery clears plb_pause_until and triggers PLB rehash.
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_early_retrans=0
+sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255
+sysctl -q net.ipv4.tcp_plb_suspend_rto_sec=1`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+// Use 10ms handshake RTT.
+ +.01 < S 0:0(0) win 32792 <mss 100,sackOK,nop,nop,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
+ +.01 < . 1:1(0) ack 1 win 320
+ +0 accept(3, ..., ...) = 4
+
+// Grow cwnd to 40 in Slow Start and record high plb_max_rate (~1125B / 10ms).
+ +0 write(4, ..., 3000) = 3000
+ +0 > (flowlabel 0x1) P. 1:1001(1000) ack 1
+ +.01 < . 1:1(0) ack 1001 win 320
+ +0 > (flowlabel 0x1) P. 1001:3001(2000) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320
+
+// Pre-RTO Fast Recovery: plb_loss_recoveries becomes 1.
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3001:3401(400) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320 <sack 3101:3401,nop,nop>
+ +0 > (flowlabel 0x1) . 3001:3101(100) ack 1
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3401 win 320
+
+// RTO: rehashes flowlabel to 0x2 (tcpi_rehash == 1), sets pause_until to [1s, 2s),
+// and resets plb_loss_recoveries from 1 to 0.
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x1) P. 3401:3501(100) ack 1
++.19~+.27 > (flowlabel 0x2) P. 3401:3501(100) ack 1
+ +.01 < . 1:1(0) ack 3501 win 320
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+
+// Phase 1: 5 Fast Recoveries within < 1.0s since RTO.
+// Recovery 1 (plb_loss_recoveries == 1):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3501:3601(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3601:3701(100) ack 1
+ +.01 < . 1:1(0) ack 3501 win 320 <sack 3601:3701,nop,nop>
+ +0 > (flowlabel 0x2) P. 3501:3601(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3701 win 320
+
+// Recovery 2 (plb_loss_recoveries == 2):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3701:3801(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3801:3901(100) ack 1
+ +.01 < . 1:1(0) ack 3701 win 320 <sack 3801:3901,nop,nop>
+ +0 > (flowlabel 0x2) P. 3701:3801(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 3901 win 320
+
+// Recovery 3 (plb_loss_recoveries == 3):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 3901:4001(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4001:4101(100) ack 1
+ +.01 < . 1:1(0) ack 3901 win 320 <sack 4001:4101,nop,nop>
+ +0 > (flowlabel 0x2) P. 3901:4001(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4101 win 320
+
+// Recovery 4 (plb_loss_recoveries == 4):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4101:4201(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4201:4301(100) ack 1
+ +.01 < . 1:1(0) ack 4101 win 320 <sack 4201:4301,nop,nop>
+ +0 > (flowlabel 0x2) P. 4101:4201(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4301 win 320
+
+// Deliver non-app-limited data and wait 50ms to establish low rate sample
+// (rate_prob == 255) before Recovery 5 in Phase 1:
+ +0 write(4, ..., 300) = 300
+ +0 > (flowlabel 0x2) . 4301:4501(200) ack 1
+ +.01 < . 1:1(0) ack 4501 win 320
+ +0 > (flowlabel 0x2) P. 4501:4601(100) ack 1
+ +.05 < . 1:1(0) ack 4601 win 320
+
+// Recovery 5 (plb_loss_recoveries reaches 5 and resets to 0; suppressed by pause_until):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4601:4701(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4701:4801(100) ack 1
+ +.01 < . 1:1(0) ack 4601 win 320 <sack 4701:4801,nop,nop>
+ +0 > (flowlabel 0x2) P. 4601:4701(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 4801 win 320
+
+// Phase 2: Wait 2.5s (> 2.0s max suspension window).
+// Recovery 1 in Phase 2 (plb_loss_recoveries == 1):
+ +2.5 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4801:4901(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 4901:5001(100) ack 1
+ +.01 < . 1:1(0) ack 4801 win 320 <sack 4901:5001,nop,nop>
+ +0 > (flowlabel 0x2) P. 4801:4901(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5001 win 320
+
+// Recovery 2 in Phase 2 (plb_loss_recoveries == 2):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5001:5101(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5101:5201(100) ack 1
+ +.01 < . 1:1(0) ack 5001 win 320 <sack 5101:5201,nop,nop>
+ +0 > (flowlabel 0x2) P. 5001:5101(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5201 win 320
+
+// Recovery 3 in Phase 2 (plb_loss_recoveries == 3):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5201:5301(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5301:5401(100) ack 1
+ +.01 < . 1:1(0) ack 5201 win 320 <sack 5301:5401,nop,nop>
+ +0 > (flowlabel 0x2) P. 5201:5301(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5401 win 320
+
+// Recovery 4 in Phase 2 (plb_loss_recoveries == 4):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5401:5501(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5501:5601(100) ack 1
+ +.01 < . 1:1(0) ack 5401 win 320 <sack 5501:5601,nop,nop>
+ +0 > (flowlabel 0x2) P. 5401:5501(100) ack 1
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 5601 win 320
+
+// Deliver non-app-limited data and wait 50ms to establish low rate sample:
+ +0 write(4, ..., 300) = 300
+ +0 > (flowlabel 0x2) . 5601:5801(200) ack 1
+ +.01 < . 1:1(0) ack 5801 win 320
+ +0 > (flowlabel 0x2) P. 5801:5901(100) ack 1
+ +.05 < . 1:1(0) ack 5901 win 320
+
+// Recovery 5 in Phase 2 (plb_loss_recoveries reaches 5 -> clears pause_until and rehashes):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 5901:6001(100) ack 1
+ +.02 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 6001:6101(100) ack 1
+ +.01 < . 1:1(0) ack 5901 win 320 <sack 6001:6101,nop,nop>
+ +0 > (flowlabel 0x3) P. 5901:6001(100) ack 1
+ +0 %{ assert tcpi_rehash == 2, tcpi_rehash }%
+ +.01 < . 1:1(0) ack 6101 win 320
diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
new file mode 100644
index 000000000000..d6c8ee5d184e
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_tlp.pkt
@@ -0,0 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Test TCP Generic PLB: TLP loss probe triggered PLB rehash.
+// - Setup: Establish high plb_max_rate and 4 Fast Recoveries
+// so plb_loss_recoveries == 4.
+// - Part A: Spurious TLP acked by DSACK does not call
+// tcp_plb_check_rehash_loss() -> no rehash.
+// - Part B: Real tail loss detected by TLP (after(ack, tp->tlp_high_seq))
+// increments plb_loss_recoveries to 5 and triggers PLB rehash.
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+ +0 bind(3, ..., ...) = 0
+ +0 listen(3, 1) = 0
+
+// Use 10ms handshake RTT.
+ +.01 < S 0:0(0) win 32792 <mss 100,sackOK,nop,nop,nop,wscale 7>
+ +0 > S. 0:0(0) ack 1 <mss 1460,nop,nop,sackOK,nop,wscale 8>
+ +.01 < . 1:1(0) ack 1 win 320
+ +0 accept(3, ..., ...) = 4
+
+// Grow cwnd to 40 in Slow Start and record high plb_max_rate (~1125B / 10ms).
+ +0 write(4, ..., 3000) = 3000
+ +0 > (flowlabel 0x1) P. 1:1001(1000) ack 1
+ +.01 < . 1:1(0) ack 1001 win 320
+ +0 > (flowlabel 0x1) P. 1001:3001(2000) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320
+
+// Trigger 4 Fast Recovery rounds so plb_loss_recoveries == 4 (< 5).
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3001:3401(400) ack 1
+ +.01 < . 1:1(0) ack 3001 win 320 <sack 3101:3401,nop,nop>
+ +0 > (flowlabel 0x1) . 3001:3101(100) ack 1
+ +.01 < . 1:1(0) ack 3401 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3401:3801(400) ack 1
+ +.01 < . 1:1(0) ack 3401 win 320 <sack 3501:3801,nop,nop>
+ +0 > (flowlabel 0x1) . 3401:3501(100) ack 1
+ +.01 < . 1:1(0) ack 3801 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 3801:4201(400) ack 1
+ +.01 < . 1:1(0) ack 3801 win 320 <sack 3901:4201,nop,nop>
+ +0 > (flowlabel 0x1) . 3801:3901(100) ack 1
+ +.01 < . 1:1(0) ack 4201 win 320
+
+ +0 write(4, ..., 400) = 400
+ +0 > (flowlabel 0x1) P. 4201:4601(400) ack 1
+ +.01 < . 1:1(0) ack 4201 win 320 <sack 4301:4601,nop,nop>
+ +0 > (flowlabel 0x1) . 4201:4301(100) ack 1
+ +.01 < . 1:1(0) ack 4601 win 320
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+
+// Part A: DSACK TLP (no actual loss) must NOT call tcp_plb_check_rehash_loss().
+// cwnd == 9. Write 9 + 2 = 11 segments (1100B) so Batch 2 (5501:5701, 200B)
+// is clocked out with is_app_limited = 0.
+ +0 write(4, ..., 1100) = 1100
+ +0 > (flowlabel 0x1) . 4601:5501(900) ack 1
+ +.01 < . 1:1(0) ack 5501 win 320
+ +0 > (flowlabel 0x1) P. 5501:5701(200) ack 1
+
+// With packets_out == 2 > 1 and srtt == 10ms, TLP probe fires
+// at 2 * srtt + 2ms = 22ms:
++.018~+.040 > (flowlabel 0x1) P. 5601:5701(100) ack 1
+
+// Wait +.05 (< 210ms RTO) and ACK 5601 (1 segment / ~72ms with is_app_limited = 0),
+// rearming RTO while keeping tlp_high_seq == 5701.
+ +.05 < . 1:1(0) ack 5601 win 320
+
+// Wait +.05 and receive DSACK. FLAG_DSACK_TLP skips tcp_plb_check_rehash_loss(),
+// so plb_loss_recoveries stays 4 and no rehash occurs.
+ +.05 < . 1:1(0) ack 5701 win 320 <sack 5601:5701,nop,nop>
+ +0 %{ assert tcpi_rehash == 0, tcpi_rehash }%
+
+// Part B: TLP Loss Recovery (after(ack, tp->tlp_high_seq)) calls
+// tcp_plb_check_rehash_loss(), incrementing plb_loss_recoveries to 5.
+// Write 2 segments (200B) so packets_out == 2 > 1:
+ +0 write(4, ..., 200) = 200
+ +0 > (flowlabel 0x1) P. 5701:5901(200) ack 1
+
+// With packets_out == 2 > 1 and srtt ~ 18ms, TLP probe fires at
+// 2 * srtt + 2ms ~ 38ms (tlp_high_seq = 5901):
++.028~+.055 > (flowlabel 0x1) P. 5801:5901(100) ack 1
+
+// Sender transmits new data while TLP is in flight (tlp_high_seq remains 5901):
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x1) P. 5901:6001(100) ack 1
+
+// Peer cumulatively ACKs 6001 (ack 6001 > tlp_high_seq 5901).
+// tcp_process_tlp_ack() runs before tcp_rate_gen(), sees
+// after(ack, tp->tlp_high_seq) on the 5th recovery, and triggers rehash!
+ +.01 < . 1:1(0) ack 6001 win 320
+ +0 %{ assert tcpi_rehash == 1, tcpi_rehash }%
+
+// Outbound packet now has flowlabel 0x2.
+ +0 write(4, ..., 100) = 100
+ +0 > (flowlabel 0x2) P. 6001:6101(100) ack 1
+ +.01 < . 1:1(0) ack 6101 win 320
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (8 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
@ 2026-12-04 8:54 ` Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 9:03 ` [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB netdev-bot+sinfo
10 siblings, 1 reply; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 8:54 UTC (permalink / raw)
To: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn
Cc: Simon Horman, Yuchung Cheng, Kuniyuki Iwashima, Kuniyuki Iwashima,
netdev
ecmp_rehash.sh uses unpaced socat over veth, where packet drops
or SMP reordering can trigger >= 5 Fast Recoveries.
With Generic PLB enabled by default, tcp_plb_check_rehash_loss()
can rehash the client socket, and the resulting IPv6 flow label
change can also trigger tcp_rcv_spurious_retrans() on the server
side.
This makes test_ecmp_dst_rebuild_consistency() and
test_ecmp_syncookie_path_consistency() flaky.
Let's disable Generic PLB in setup().
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
tools/testing/selftests/net/ecmp_rehash.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/net/ecmp_rehash.sh b/tools/testing/selftests/net/ecmp_rehash.sh
index f05a6c8edd2a..a2b732cf2418 100755
--- a/tools/testing/selftests/net/ecmp_rehash.sh
+++ b/tools/testing/selftests/net/ecmp_rehash.sh
@@ -186,6 +186,7 @@ setup()
ip netns exec "$ns" sysctl -qw net.ipv6.conf.default.accept_dad=0
ip netns exec "$ns" sysctl -qw net.ipv6.conf.all.forwarding=1
ip netns exec "$ns" sysctl -qw net.core.txrehash=1
+ ip netns exec "$ns" sysctl -qw net.ipv4.tcp_plb_loss_rehash_prob=0
done
local i sub
--
2.56.1.915.g69d5ec7298-goog
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB.
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
` (9 preceding siblings ...)
2026-12-04 8:54 ` [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh Kuniyuki Iwashima
@ 2026-12-04 9:03 ` netdev-bot+sinfo
2026-12-04 9:29 ` Kuniyuki Iwashima
10 siblings, 1 reply; 23+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 9:03 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Yuchung Cheng,
Kuniyuki Iwashima, netdev
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB.
2026-12-04 9:03 ` [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB netdev-bot+sinfo
@ 2026-12-04 9:29 ` Kuniyuki Iwashima
0 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 9:29 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Yuchung Cheng,
Kuniyuki Iwashima, netdev
On Fri, Dec 4, 2026 at 1:03 AM <netdev-bot+sinfo@kernel.org> wrote:
>
> Hi!
>
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
>
> - How the issue was discovered, e.g. hit in production, hit during
> development, syzbot report, manual code inspection, LLM or static
> analysis tool scan.
Found by Sashiko review during development,
>
> - Whether the issue was actually triggered,
and it was triggered.
> or is only theoretical
> (e.g. found by LLM and not proven at runtime). If it was triggered
> please include the symptoms, like the stack trace or kernel messages.
>
> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account.
>
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> --
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
2026-12-04 8:54 ` [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock Kuniyuki Iwashima
@ 2026-12-04 10:34 ` David Laight
2026-12-04 12:33 ` Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
1 sibling, 1 reply; 23+ messages in thread
From: David Laight @ 2026-12-04 10:34 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Yuchung Cheng,
Kuniyuki Iwashima, netdev
On Fri, 4 Dec 2026 17:54:33 +0900
Kuniyuki Iwashima <kuniyu@google.com> wrote:
> Currently, PLB is only used by DCTCP, but we will generalise
> it for other CCs.
>
> struct tcp_plb_state is 5 bytes and moving it to tcp_sock
> creates a hole after the struct without __packed.
>
> Let's inline consec_cong_rounds and pause_until to tcp_sock.
>
> plb_consec_cong_rounds uses 8 bits because compilers had to
> generate inefficient RMW for consec_cong_rounds:5 to preserve
> unused:3.
>
> Note that dctcp_init() no longer clears plb_pause_until so that
> an active RTO pause is preserved across handshake SYN RTOs and
> CC changes. tcp_disconnect() clears both fields.
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> ---
> .../networking/net_cachelines/tcp_sock.rst | 2 +
> include/linux/tcp.h | 4 ++
> include/net/tcp.h | 20 ++--------
> net/ipv4/tcp.c | 2 +
> net/ipv4/tcp_dctcp.c | 18 ++++-----
> net/ipv4/tcp_plb.c | 40 ++++++++++---------
> 6 files changed, 39 insertions(+), 47 deletions(-)
>
> diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
> index 78f74eb76990..6eb058478665 100644
> --- a/Documentation/networking/net_cachelines/tcp_sock.rst
> +++ b/Documentation/networking/net_cachelines/tcp_sock.rst
> @@ -158,6 +158,8 @@ u32 bpf_tcp_ops_flags read_mostly read_m
> u8 bpf_sock_ops_cb_flags
> u8:1 bpf_chg_cc_inprogress
> u16 timeout_rehash
> +u8 plb_consec_cong_rounds
> +u32 plb_pause_until
> u32 rcv_ooopack
> u32 rcv_rtt_last_tsecr
> struct rcv_rtt_est read_write tcp_rcv_space_adjust,tcp_rcv_established
> diff --git a/include/linux/tcp.h b/include/linux/tcp.h
> index 3d6eb6c8681d..3f275ac8e512 100644
> --- a/include/linux/tcp.h
> +++ b/include/linux/tcp.h
> @@ -506,6 +506,10 @@ struct tcp_sock {
>
> u16 timeout_rehash; /* Timeout-triggered rehash attempts */
>
> + /* State for PLB (Protective Load Balancing) for a single TCP connection. */
> + u8 plb_consec_cong_rounds; /* consecutive congested rounds */
> + u32 plb_pause_until; /* jiffies32 when PLB can resume rerouting */
> +
There are probably better places to put those fields to avoid the 3 byte pad.
Possibly reorder the fields so that plb_consec_cong_rounds can share a byte
with bpf_chg_cc_inprogress?
David
> u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
>
> /* TCP-specific MTU probe information. */
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 68a60268d19d..bcff640c16a1 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -2735,23 +2735,9 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
> */
> #define TCP_PLB_SCALE 8
>
> -/* State for PLB (Protective Load Balancing) for a single TCP connection. */
> -struct tcp_plb_state {
> - u8 consec_cong_rounds:5, /* consecutive congested rounds */
> - unused:3;
> - u32 pause_until; /* jiffies32 when PLB can resume rerouting */
> -};
> -
> -static inline void tcp_plb_init(const struct sock *sk,
> - struct tcp_plb_state *plb)
> -{
> - plb->consec_cong_rounds = 0;
> - plb->pause_until = 0;
> -}
> -void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
> - const int cong_ratio);
> -void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb);
> -void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
> +void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
> +void tcp_plb_check_rehash(struct sock *sk);
> +void tcp_plb_update_state_upon_rto(struct sock *sk);
>
> static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
> {
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 58767b3b1b9a..002eaca58c46 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -3488,6 +3488,8 @@ int tcp_disconnect(struct sock *sk, int flags)
> tp->tlp_high_seq = 0;
> tp->last_oow_ack_time = 0;
> tp->plb_rehash = 0;
> + tp->plb_consec_cong_rounds = 0;
> + tp->plb_pause_until = 0;
> /* There's a bubble in the pipe until at least the first ACK. */
> tp->app_limited = ~0U;
> tp->rate_app_limited = 1;
> diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
> index 5b457f68a581..bc3724d1da90 100644
> --- a/net/ipv4/tcp_dctcp.c
> +++ b/net/ipv4/tcp_dctcp.c
> @@ -54,7 +54,6 @@ struct dctcp {
> u32 next_seq;
> u32 ce_state;
> u32 loss_cwnd;
> - struct tcp_plb_state plb;
> };
>
> static unsigned int dctcp_shift_g __read_mostly = 4; /* g = 1/2^4 */
> @@ -88,7 +87,7 @@ static void dctcp_reset(const struct tcp_sock *tp, struct dctcp *ca)
>
> __bpf_kfunc static void dctcp_init(struct sock *sk)
> {
> - const struct tcp_sock *tp = tcp_sk(sk);
> + struct tcp_sock *tp = tcp_sk(sk);
>
> if (tcp_ecn_mode_any(tp) ||
> (sk->sk_state == TCP_LISTEN ||
> @@ -103,8 +102,7 @@ __bpf_kfunc static void dctcp_init(struct sock *sk)
> ca->ce_state = 0;
>
> dctcp_reset(tp, ca);
> - tcp_plb_init(sk, &ca->plb);
> -
> + tp->plb_consec_cong_rounds = 0;
> return;
> }
>
> @@ -126,8 +124,8 @@ __bpf_kfunc static u32 dctcp_ssthresh(struct sock *sk)
>
> __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
> {
> - const struct tcp_sock *tp = tcp_sk(sk);
> struct dctcp *ca = inet_csk_ca(sk);
> + struct tcp_sock *tp = tcp_sk(sk);
>
> /* Expired RTT */
> if (!before(tp->snd_una, ca->next_seq)) {
> @@ -145,8 +143,8 @@ __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
> */
> if (delivered_ce > 0)
> ce_ratio = (delivered_ce << TCP_PLB_SCALE) / delivered;
> - tcp_plb_update_state(sk, &ca->plb, (int)ce_ratio);
> - tcp_plb_check_rehash(sk, &ca->plb);
> + tcp_plb_update_state(sk, (int)ce_ratio);
> + tcp_plb_check_rehash(sk);
> }
>
> /* alpha = (1 - g) * alpha + g * F */
> @@ -200,7 +198,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
> dctcp_ece_ack_update(sk, ev, &ca->prior_rcv_nxt, &ca->ce_state);
> break;
> case CA_EVENT_LOSS:
> - tcp_plb_update_state_upon_rto(sk, &ca->plb);
> + tcp_plb_update_state_upon_rto(sk);
> dctcp_react_to_loss(sk);
> break;
> default:
> @@ -211,9 +209,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
>
> __bpf_kfunc static void dctcp_cwnd_event_tx_start(struct sock *sk)
> {
> - struct dctcp *ca = inet_csk_ca(sk);
> -
> - tcp_plb_check_rehash(sk, &ca->plb); /* Maybe rehash when inflight is 0 */
> + tcp_plb_check_rehash(sk); /* Maybe rehash when inflight is 0 */
> }
>
> static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
> diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
> index d101a424c444..26ca53d6fb9d 100644
> --- a/net/ipv4/tcp_plb.c
> +++ b/net/ipv4/tcp_plb.c
> @@ -23,9 +23,9 @@
> #include <net/tcp.h>
>
> /* Called once per round-trip to update PLB state for a connection. */
> -void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
> - const int cong_ratio)
> +void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
> {
> + struct tcp_sock *tp = tcp_sk(sk);
> struct net *net = sock_net(sk);
>
> if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
> @@ -33,10 +33,10 @@ void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
>
> if (cong_ratio >= 0) {
> if (cong_ratio < READ_ONCE(net->ipv4.sysctl_tcp_plb_cong_thresh))
> - plb->consec_cong_rounds = 0;
> - else if (plb->consec_cong_rounds <
> + tp->plb_consec_cong_rounds = 0;
> + else if (tp->plb_consec_cong_rounds <
> READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds))
> - plb->consec_cong_rounds++;
> + tp->plb_consec_cong_rounds++;
> }
> }
> EXPORT_SYMBOL_GPL(tcp_plb_update_state);
> @@ -44,21 +44,22 @@ EXPORT_SYMBOL_GPL(tcp_plb_update_state);
> /* Check whether recent congestion has been persistent enough to warrant
> * a load balancing decision that switches the connection to another path.
> */
> -void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
> +void tcp_plb_check_rehash(struct sock *sk)
> {
> + bool forced_rehash = false, idle_rehash = false;
> + struct tcp_sock *tp = tcp_sk(sk);
> struct net *net = sock_net(sk);
> u32 max_suspend;
> - bool forced_rehash = false, idle_rehash = false;
>
> if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
> return;
>
> - forced_rehash = plb->consec_cong_rounds >=
> + forced_rehash = tp->plb_consec_cong_rounds >=
> READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds);
> /* If sender goes idle then we check whether to rehash. */
> idle_rehash = READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds) &&
> !tcp_sk(sk)->packets_out &&
> - plb->consec_cong_rounds >=
> + tp->plb_consec_cong_rounds >=
> READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
>
> if (!forced_rehash && !idle_rehash)
> @@ -70,19 +71,19 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
> * RTO event that constrains PLB rehashing.
> */
> max_suspend = 2 * READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
> - if (plb->pause_until &&
> - (!before(tcp_jiffies32, plb->pause_until) ||
> - before(tcp_jiffies32 + max_suspend, plb->pause_until)))
> - plb->pause_until = 0;
> + if (tp->plb_pause_until &&
> + (!before(tcp_jiffies32, tp->plb_pause_until) ||
> + before(tcp_jiffies32 + max_suspend, tp->plb_pause_until)))
> + tp->plb_pause_until = 0;
>
> - if (plb->pause_until)
> + if (tp->plb_pause_until)
> return;
>
> if (!__sk_rethink_txhash_reset_dst(sk))
> return;
>
> - plb->consec_cong_rounds = 0;
> - WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1);
> + tp->plb_consec_cong_rounds = 0;
> + WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
> NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
> }
> EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
> @@ -91,8 +92,9 @@ EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
> * balancing decisions switch traffic to a black-holed path that was
> * previously avoided with a sk_rethink_txhash() call at RTO time.
> */
> -void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
> +void tcp_plb_update_state_upon_rto(struct sock *sk)
> {
> + struct tcp_sock *tp = tcp_sk(sk);
> struct net *net = sock_net(sk);
> u32 pause;
>
> @@ -102,13 +104,13 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
> pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
> if (pause) {
> pause += get_random_u32_below(pause);
> - plb->pause_until = tcp_jiffies32 + pause;
> + tp->plb_pause_until = tcp_jiffies32 + pause;
> }
>
> /* Reset PLB state upon RTO, since an RTO causes a sk_rethink_txhash() call
> * that may switch this connection to a path with completely different
> * congestion characteristics.
> */
> - plb->consec_cong_rounds = 0;
> + tp->plb_consec_cong_rounds = 0;
> }
> EXPORT_SYMBOL_GPL(tcp_plb_update_state_upon_rto);
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
2026-12-04 10:34 ` David Laight
@ 2026-12-04 12:33 ` Kuniyuki Iwashima
0 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-04 12:33 UTC (permalink / raw)
To: David Laight
Cc: Eric Dumazet, Neal Cardwell, David S . Miller, Jakub Kicinski,
Paolo Abeni, Willem de Bruijn, Simon Horman, Yuchung Cheng,
Kuniyuki Iwashima, netdev
On Fri, Dec 4, 2026 at 2:34 AM David Laight
<david.laight.linux@gmail.com> wrote:
>
> On Fri, 4 Dec 2026 17:54:33 +0900
> Kuniyuki Iwashima <kuniyu@google.com> wrote:
>
> > Currently, PLB is only used by DCTCP, but we will generalise
> > it for other CCs.
> >
> > struct tcp_plb_state is 5 bytes and moving it to tcp_sock
> > creates a hole after the struct without __packed.
> >
> > Let's inline consec_cong_rounds and pause_until to tcp_sock.
> >
> > plb_consec_cong_rounds uses 8 bits because compilers had to
> > generate inefficient RMW for consec_cong_rounds:5 to preserve
> > unused:3.
> >
> > Note that dctcp_init() no longer clears plb_pause_until so that
> > an active RTO pause is preserved across handshake SYN RTOs and
> > CC changes. tcp_disconnect() clears both fields.
> >
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> > ---
> > .../networking/net_cachelines/tcp_sock.rst | 2 +
> > include/linux/tcp.h | 4 ++
> > include/net/tcp.h | 20 ++--------
> > net/ipv4/tcp.c | 2 +
> > net/ipv4/tcp_dctcp.c | 18 ++++-----
> > net/ipv4/tcp_plb.c | 40 ++++++++++---------
> > 6 files changed, 39 insertions(+), 47 deletions(-)
> >
> > diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst b/Documentation/networking/net_cachelines/tcp_sock.rst
> > index 78f74eb76990..6eb058478665 100644
> > --- a/Documentation/networking/net_cachelines/tcp_sock.rst
> > +++ b/Documentation/networking/net_cachelines/tcp_sock.rst
> > @@ -158,6 +158,8 @@ u32 bpf_tcp_ops_flags read_mostly read_m
> > u8 bpf_sock_ops_cb_flags
> > u8:1 bpf_chg_cc_inprogress
> > u16 timeout_rehash
> > +u8 plb_consec_cong_rounds
> > +u32 plb_pause_until
> > u32 rcv_ooopack
> > u32 rcv_rtt_last_tsecr
> > struct rcv_rtt_est read_write tcp_rcv_space_adjust,tcp_rcv_established
> > diff --git a/include/linux/tcp.h b/include/linux/tcp.h
> > index 3d6eb6c8681d..3f275ac8e512 100644
> > --- a/include/linux/tcp.h
> > +++ b/include/linux/tcp.h
> > @@ -506,6 +506,10 @@ struct tcp_sock {
> >
> > u16 timeout_rehash; /* Timeout-triggered rehash attempts */
> >
> > + /* State for PLB (Protective Load Balancing) for a single TCP connection. */
> > + u8 plb_consec_cong_rounds; /* consecutive congested rounds */
> > + u32 plb_pause_until; /* jiffies32 when PLB can resume rerouting */
> > +
>
> There are probably better places to put those fields to avoid the 3 byte pad.
> Possibly reorder the fields so that plb_consec_cong_rounds can share a byte
> with bpf_chg_cc_inprogress?
The hole is used by a later patch.
Thanks.
>
> David
>
> > u32 rcv_ooopack; /* Received out-of-order packets, for tcpinfo */
> >
> > /* TCP-specific MTU probe information. */
> > diff --git a/include/net/tcp.h b/include/net/tcp.h
> > index 68a60268d19d..bcff640c16a1 100644
> > --- a/include/net/tcp.h
> > +++ b/include/net/tcp.h
> > @@ -2735,23 +2735,9 @@ extern void tcp_rack_reo_timeout(struct sock *sk);
> > */
> > #define TCP_PLB_SCALE 8
> >
> > -/* State for PLB (Protective Load Balancing) for a single TCP connection. */
> > -struct tcp_plb_state {
> > - u8 consec_cong_rounds:5, /* consecutive congested rounds */
> > - unused:3;
> > - u32 pause_until; /* jiffies32 when PLB can resume rerouting */
> > -};
> > -
> > -static inline void tcp_plb_init(const struct sock *sk,
> > - struct tcp_plb_state *plb)
> > -{
> > - plb->consec_cong_rounds = 0;
> > - plb->pause_until = 0;
> > -}
> > -void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
> > - const int cong_ratio);
> > -void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb);
> > -void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb);
> > +void tcp_plb_update_state(struct sock *sk, const int cong_ratio);
> > +void tcp_plb_check_rehash(struct sock *sk);
> > +void tcp_plb_update_state_upon_rto(struct sock *sk);
> >
> > static inline void tcp_warn_once(const struct sock *sk, bool cond, const char *str)
> > {
> > diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> > index 58767b3b1b9a..002eaca58c46 100644
> > --- a/net/ipv4/tcp.c
> > +++ b/net/ipv4/tcp.c
> > @@ -3488,6 +3488,8 @@ int tcp_disconnect(struct sock *sk, int flags)
> > tp->tlp_high_seq = 0;
> > tp->last_oow_ack_time = 0;
> > tp->plb_rehash = 0;
> > + tp->plb_consec_cong_rounds = 0;
> > + tp->plb_pause_until = 0;
> > /* There's a bubble in the pipe until at least the first ACK. */
> > tp->app_limited = ~0U;
> > tp->rate_app_limited = 1;
> > diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
> > index 5b457f68a581..bc3724d1da90 100644
> > --- a/net/ipv4/tcp_dctcp.c
> > +++ b/net/ipv4/tcp_dctcp.c
> > @@ -54,7 +54,6 @@ struct dctcp {
> > u32 next_seq;
> > u32 ce_state;
> > u32 loss_cwnd;
> > - struct tcp_plb_state plb;
> > };
> >
> > static unsigned int dctcp_shift_g __read_mostly = 4; /* g = 1/2^4 */
> > @@ -88,7 +87,7 @@ static void dctcp_reset(const struct tcp_sock *tp, struct dctcp *ca)
> >
> > __bpf_kfunc static void dctcp_init(struct sock *sk)
> > {
> > - const struct tcp_sock *tp = tcp_sk(sk);
> > + struct tcp_sock *tp = tcp_sk(sk);
> >
> > if (tcp_ecn_mode_any(tp) ||
> > (sk->sk_state == TCP_LISTEN ||
> > @@ -103,8 +102,7 @@ __bpf_kfunc static void dctcp_init(struct sock *sk)
> > ca->ce_state = 0;
> >
> > dctcp_reset(tp, ca);
> > - tcp_plb_init(sk, &ca->plb);
> > -
> > + tp->plb_consec_cong_rounds = 0;
> > return;
> > }
> >
> > @@ -126,8 +124,8 @@ __bpf_kfunc static u32 dctcp_ssthresh(struct sock *sk)
> >
> > __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
> > {
> > - const struct tcp_sock *tp = tcp_sk(sk);
> > struct dctcp *ca = inet_csk_ca(sk);
> > + struct tcp_sock *tp = tcp_sk(sk);
> >
> > /* Expired RTT */
> > if (!before(tp->snd_una, ca->next_seq)) {
> > @@ -145,8 +143,8 @@ __bpf_kfunc static void dctcp_update_alpha(struct sock *sk, u32 flags)
> > */
> > if (delivered_ce > 0)
> > ce_ratio = (delivered_ce << TCP_PLB_SCALE) / delivered;
> > - tcp_plb_update_state(sk, &ca->plb, (int)ce_ratio);
> > - tcp_plb_check_rehash(sk, &ca->plb);
> > + tcp_plb_update_state(sk, (int)ce_ratio);
> > + tcp_plb_check_rehash(sk);
> > }
> >
> > /* alpha = (1 - g) * alpha + g * F */
> > @@ -200,7 +198,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
> > dctcp_ece_ack_update(sk, ev, &ca->prior_rcv_nxt, &ca->ce_state);
> > break;
> > case CA_EVENT_LOSS:
> > - tcp_plb_update_state_upon_rto(sk, &ca->plb);
> > + tcp_plb_update_state_upon_rto(sk);
> > dctcp_react_to_loss(sk);
> > break;
> > default:
> > @@ -211,9 +209,7 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
> >
> > __bpf_kfunc static void dctcp_cwnd_event_tx_start(struct sock *sk)
> > {
> > - struct dctcp *ca = inet_csk_ca(sk);
> > -
> > - tcp_plb_check_rehash(sk, &ca->plb); /* Maybe rehash when inflight is 0 */
> > + tcp_plb_check_rehash(sk); /* Maybe rehash when inflight is 0 */
> > }
> >
> > static size_t dctcp_get_info(struct sock *sk, u32 ext, int *attr,
> > diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
> > index d101a424c444..26ca53d6fb9d 100644
> > --- a/net/ipv4/tcp_plb.c
> > +++ b/net/ipv4/tcp_plb.c
> > @@ -23,9 +23,9 @@
> > #include <net/tcp.h>
> >
> > /* Called once per round-trip to update PLB state for a connection. */
> > -void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
> > - const int cong_ratio)
> > +void tcp_plb_update_state(struct sock *sk, const int cong_ratio)
> > {
> > + struct tcp_sock *tp = tcp_sk(sk);
> > struct net *net = sock_net(sk);
> >
> > if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
> > @@ -33,10 +33,10 @@ void tcp_plb_update_state(const struct sock *sk, struct tcp_plb_state *plb,
> >
> > if (cong_ratio >= 0) {
> > if (cong_ratio < READ_ONCE(net->ipv4.sysctl_tcp_plb_cong_thresh))
> > - plb->consec_cong_rounds = 0;
> > - else if (plb->consec_cong_rounds <
> > + tp->plb_consec_cong_rounds = 0;
> > + else if (tp->plb_consec_cong_rounds <
> > READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds))
> > - plb->consec_cong_rounds++;
> > + tp->plb_consec_cong_rounds++;
> > }
> > }
> > EXPORT_SYMBOL_GPL(tcp_plb_update_state);
> > @@ -44,21 +44,22 @@ EXPORT_SYMBOL_GPL(tcp_plb_update_state);
> > /* Check whether recent congestion has been persistent enough to warrant
> > * a load balancing decision that switches the connection to another path.
> > */
> > -void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
> > +void tcp_plb_check_rehash(struct sock *sk)
> > {
> > + bool forced_rehash = false, idle_rehash = false;
> > + struct tcp_sock *tp = tcp_sk(sk);
> > struct net *net = sock_net(sk);
> > u32 max_suspend;
> > - bool forced_rehash = false, idle_rehash = false;
> >
> > if (!READ_ONCE(net->ipv4.sysctl_tcp_plb_enabled))
> > return;
> >
> > - forced_rehash = plb->consec_cong_rounds >=
> > + forced_rehash = tp->plb_consec_cong_rounds >=
> > READ_ONCE(net->ipv4.sysctl_tcp_plb_rehash_rounds);
> > /* If sender goes idle then we check whether to rehash. */
> > idle_rehash = READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds) &&
> > !tcp_sk(sk)->packets_out &&
> > - plb->consec_cong_rounds >=
> > + tp->plb_consec_cong_rounds >=
> > READ_ONCE(net->ipv4.sysctl_tcp_plb_idle_rehash_rounds);
> >
> > if (!forced_rehash && !idle_rehash)
> > @@ -70,19 +71,19 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
> > * RTO event that constrains PLB rehashing.
> > */
> > max_suspend = 2 * READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
> > - if (plb->pause_until &&
> > - (!before(tcp_jiffies32, plb->pause_until) ||
> > - before(tcp_jiffies32 + max_suspend, plb->pause_until)))
> > - plb->pause_until = 0;
> > + if (tp->plb_pause_until &&
> > + (!before(tcp_jiffies32, tp->plb_pause_until) ||
> > + before(tcp_jiffies32 + max_suspend, tp->plb_pause_until)))
> > + tp->plb_pause_until = 0;
> >
> > - if (plb->pause_until)
> > + if (tp->plb_pause_until)
> > return;
> >
> > if (!__sk_rethink_txhash_reset_dst(sk))
> > return;
> >
> > - plb->consec_cong_rounds = 0;
> > - WRITE_ONCE(tcp_sk(sk)->plb_rehash, tcp_sk(sk)->plb_rehash + 1);
> > + tp->plb_consec_cong_rounds = 0;
> > + WRITE_ONCE(tp->plb_rehash, tp->plb_rehash + 1);
> > NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPPLBREHASH);
> > }
> > EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
> > @@ -91,8 +92,9 @@ EXPORT_SYMBOL_GPL(tcp_plb_check_rehash);
> > * balancing decisions switch traffic to a black-holed path that was
> > * previously avoided with a sk_rethink_txhash() call at RTO time.
> > */
> > -void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
> > +void tcp_plb_update_state_upon_rto(struct sock *sk)
> > {
> > + struct tcp_sock *tp = tcp_sk(sk);
> > struct net *net = sock_net(sk);
> > u32 pause;
> >
> > @@ -102,13 +104,13 @@ void tcp_plb_update_state_upon_rto(struct sock *sk, struct tcp_plb_state *plb)
> > pause = READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
> > if (pause) {
> > pause += get_random_u32_below(pause);
> > - plb->pause_until = tcp_jiffies32 + pause;
> > + tp->plb_pause_until = tcp_jiffies32 + pause;
> > }
> >
> > /* Reset PLB state upon RTO, since an RTO causes a sk_rethink_txhash() call
> > * that may switch this connection to a path with completely different
> > * congestion characteristics.
> > */
> > - plb->consec_cong_rounds = 0;
> > + tp->plb_consec_cong_rounds = 0;
> > }
> > EXPORT_SYMBOL_GPL(tcp_plb_update_state_upon_rto);
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock.
2026-12-04 8:54 ` [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock Kuniyuki Iwashima
2026-12-04 10:34 ` David Laight
@ 2026-12-05 9:17 ` netdev-bot+sashiko
1 sibling, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 9:17 UTC (permalink / raw)
To: kuniyu
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Stale comment after the field rename.
--
tcp: Move struct tcp_plb_state to struct tcp_sock.
This commit removes struct tcp_plb_state from struct dctcp. Its two
fields now live directly in struct tcp_sock as plb_consec_cong_rounds
and plb_pause_until, so other congestion control modules can use PLB
later. The tcp_plb_*() helpers now take only the socket. dctcp_init()
no longer clears plb_pause_until, and tcp_disconnect() resets both
fields.
> diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
> index d101a424c444c..26ca53d6fb9d8 100644
> --- a/net/ipv4/tcp_plb.c
> +++ b/net/ipv4/tcp_plb.c
[ ... ]
> @@ -70,19 +71,19 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)
> * RTO event that constrains PLB rehashing.
> */
> max_suspend = 2 * READ_ONCE(net->ipv4.sysctl_tcp_plb_suspend_rto_sec) * HZ;
> - if (plb->pause_until &&
> - (!before(tcp_jiffies32, plb->pause_until) ||
> - before(tcp_jiffies32 + max_suspend, plb->pause_until)))
> - plb->pause_until = 0;
> + if (tp->plb_pause_until &&
> + (!before(tcp_jiffies32, tp->plb_pause_until) ||
> + before(tcp_jiffies32 + max_suspend, tp->plb_pause_until)))
> + tp->plb_pause_until = 0;
[Severity: Low]
This isn't a bug, but the comment above this block in
tcp_plb_check_rehash() still uses the old field name:
* end. We clear pause_until to 0 to indicate there is no recent
* RTO event that constrains PLB rehashing.
This patch removes pause_until, and the code below the comment now uses
tp->plb_pause_until. Should the comment say plb_pause_until?
The later patch "tcp: Factorise tcp_plb_rehash()" moves this comment
into tcp_plb_rehash() without changing it, so the old name is still
there at the end of the series.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout().
2026-12-04 8:54 ` [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout() Kuniyuki Iwashima
@ 2026-12-05 9:17 ` netdev-bot+sashiko
0 siblings, 0 replies; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 9:17 UTC (permalink / raw)
To: kuniyu
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit fixes a real, long-standing behavioural bug but has no
Fixes: tag, and the message does not say why the tag is left out.
- [Low] After this patch the sysctl documentation no longer matches the
code.
--
tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout().
This patch moves tcp_plb_update_state_upon_rto() from the CA_EVENT_LOSS
case of dctcp_cwnd_event() into tcp_write_timeout(). It now runs right
after a successful __sk_rethink_txhash_reset_dst(), so PLB is paused and
reset whenever an RTO rehashes the flow, even when tcp_enter_loss() skips
CA_EVENT_LOSS.
> Let's move tcp_plb_update_state_upon_rto() just after
> __sk_rethink_txhash_reset_dst() in tcp_write_timeout().
>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
[Severity: Low]
Should this patch carry a Fixes: tag?
The commit message describes a real behaviour bug. tcp_enter_loss() only
raises CA_EVENT_LOSS here:
if (icsk->icsk_ca_state <= TCP_CA_Disorder ||
!after(tp->high_seq, tp->snd_una) ||
(icsk->icsk_ca_state == TCP_CA_Loss && !icsk->icsk_retransmits)) {
...
tcp_ca_event(sk, CA_EVENT_LOSS);
Take a DCTCP socket in TCP_CA_CWR after a CE echo, with high_seq still
after snd_una. It can be rehashed in tcp_write_timeout() without any PLB
pause. Its plb_consec_cong_rounds is probably already high from the CE
marks.
The CA_EVENT_LOSS placement in dctcp_cwnd_event() looks like it came from:
Fixes: c30f8e0b0480 ("tcp: add support for PLB in DCTCP")
Two earlier patches in this series already carry Fixes: tags: "tcp: Return
early when tcp_plb_check_rehash() does not rehash a flow." and "tcp: Don't
call get_random_u32_below(0) in tcp_plb_update_state_upon_rto()."
This patch only applies on top of "tcp: Move struct tcp_plb_state to struct
tcp_sock." because it drops the &ca->plb argument. A stable backport would
need a different form.
If the tag is left out on purpose, could the commit message say so? That
would help backporters.
> diff --git a/net/ipv4/tcp_dctcp.c b/net/ipv4/tcp_dctcp.c
> index bc3724d1da904..bbfff24ed5f0a 100644
> --- a/net/ipv4/tcp_dctcp.c
> +++ b/net/ipv4/tcp_dctcp.c
> @@ -198,7 +198,6 @@ __bpf_kfunc static void dctcp_cwnd_event(struct sock *sk, enum tcp_ca_event ev)
> dctcp_ece_ack_update(sk, ev, &ca->prior_rcv_nxt, &ca->ce_state);
> break;
> case CA_EVENT_LOSS:
> - tcp_plb_update_state_upon_rto(sk);
> dctcp_react_to_loss(sk);
> break;
> default:
[ ... ]
> diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
> index 814fadb30749b..a3210cda2515b 100644
> --- a/net/ipv4/tcp_timer.c
> +++ b/net/ipv4/tcp_timer.c
> @@ -297,6 +297,7 @@ static int tcp_write_timeout(struct sock *sk)
> }
>
> if (__sk_rethink_txhash_reset_dst(sk)) {
> + tcp_plb_update_state_upon_rto(sk);
> WRITE_ONCE(tp->timeout_rehash, tp->timeout_rehash + 1);
> __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTREHASH);
> }
[Severity: Low]
Now that this is the only caller, does the tcp_plb_suspend_rto_sec entry
in Documentation/networking/ip-sysctl.rst still match the code? It says:
Time, in seconds, to suspend PLB in event of an RTO. In order to avoid
having PLB repath onto a connectivity "black hole", after an RTO a TCP
connection suspends PLB repathing for a random duration between 1x and
2x of this parameter.
After this patch the pause only happens when an RTO rehash succeeds. The
zero-window branch of tcp_retransmit_timer() never reaches
tcp_write_timeout():
tcp_enter_loss(sk);
tcp_retransmit_skb(sk, skb, 1);
__sk_dst_reset(sk);
goto out_reset_timer;
The TFO SYN-ACK RTO path in tcp_fastopen_synack_timer() doesn't reach it
either.
Before this patch, both paths paused PLB when ca_state was
<= TCP_CA_Disorder, through this chain:
tcp_enter_loss()->tcp_ca_event(CA_EVENT_LOSS)->dctcp_cwnd_event()
The commit message says this narrowing is intended. Another patch in the
series, "tcp: Lower tcp_plb_suspend_rto_sec default.", describes the sysctl
as suspending PLB "after an RTO triggers a rehash". That patch edits the
same paragraph but keeps the plain "after an RTO" wording.
Should the sysctl text say the pause only follows an RTO rehash? The
"upon RTO" comment above tcp_plb_update_state_upon_rto() in tcp_plb.c
could be updated the same way.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB.
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
@ 2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-05 12:13 ` Kuniyuki Iwashima
0 siblings, 1 reply; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 9:17 UTC (permalink / raw)
To: kuniyu
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 4
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] Generic PLB is on by default
(net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128 in tcp_sk_init()) for…
- [Medium] The stale-hop decay in tcp_plb_check_rehash_loss() starts one
hop earlier than the commit message describes.
- [Low] The commit message ('Every 5th Fast Recovery'), the sysctl docs
and the field comment on struct tcp_sock::plb_loss_recoveries ('fast…
- [Low] The new tcp_plb_loss_rehash_prob documentation describes Generic
PLB as generally applicable.
- [Low] ip-sysctl.rst describes tcp_plb_loss_rehash_prob as the 'Base
probability for Generic PLB repathing, mapped from [0, 1] to [0, 255]…
- [Low] The comment in tcp_plb_check_rehash_loss() says 'self-normalise
MSS-per-sec rate', but the struct tcp_sock::plb_max_rate definition…
--
tcp: Introduce Generic PLB.
This commit adds Generic PLB. It is a variant of Protective Load
Balancing that does not depend on the congestion control, and it
rehashes the txhash based on packet loss and delivery rate regression.
A new per-netns sysctl, net.ipv4.tcp_plb_loss_rehash_prob (default 128),
sets the base probability, which is evaluated on every 5th loss
recovery. A per-flow peak delivery rate is tracked in tcp_rate_gen()
and decayed after repeated stale rehashes.
Link: https://gist.github.com/q2ven/c04b56477dea4d1a58f5eadc4b07f9e0
> diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
> index dffcec335a779..3046f6725b218 100644
> --- a/Documentation/networking/ip-sysctl.rst
> +++ b/Documentation/networking/ip-sysctl.rst
[ ... ]
> @@ -1437,6 +1437,21 @@ tcp_plb_cong_thresh - INTEGER
>
> Default: 128
>
> +tcp_plb_loss_rehash_prob - INTEGER
> + Base probability for Generic PLB repathing, mapped from [0, 1]
> + to [0, 255] (e.g., 128 means 50%). Setting this to 0 disables
> + Generic PLB.
[Severity: Low]
Is "128 means 50%" accurate for how the value is used?
tcp_plb_check_rehash_loss() never uses base_prob directly as the repath
probability:
rate_prob = (4 * base_prob * deficit * deficit) >> 16;
...
prob = max(rate_prob, floor);
Here floor is base_prob >> 1 while plb_rehash < 2, and base_prob >> 3
after that. The check also only runs on every 5th loss event. base_prob
is the real probability only when the delivery rate has dropped by
exactly 50%.
Could this entry describe the floor, the deficit scaling and the 5-event
cadence, so admins can predict what a given value does?
> +
> + Unlike tcp_plb_enabled which relies on ECN signals, Generic PLB
> + is congestion-control-agnostic and triggers repathing based on
> + packet loss and delivery rate regression relative to the flow's
> + recent peak delivery rate. Larger tcp_plb_loss_rehash_prob
> + values make repathing more aggressive.
[Severity: Low]
Should this entry say that the repath only changes the IPv6 flow label?
The tcp_plb_enabled text above says so explicitly:
PLB changes socket txhash which results in a change in IPv6 Flow Label
field, and currently no-op for IPv4 headers.
tcp_plb_rehash() calls __sk_rethink_txhash_reset_dst(). That function
only resets the dst for AF_INET6, and its comment says "IPv4 ECMP path
selection does not use sk_txhash".
Generic PLB is still enabled by default for IPv4 sockets. For plain IPv4
traffic it bumps LINUX_MIB_TCPPLBREHASH and tp->plb_rehash, and applies
the stale-hop decay to plb_max_rate, but nothing changes on the wire.
The exception is when the host does its own encapsulation based on
skb->hash.
The commit message cites cloud VM environments as the motivation, but
it does not mention the IPv6-only scope, and all the benchmarks are
IPv6.
> +
> + Possible Values: 0 - 255
> +
> + Default: 128
> +
[ ... ]
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index d2445dc259324..ab524990b8786 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
[ ... ]
> @@ -4201,6 +4215,7 @@ static void tcp_process_tlp_ack(struct sock *sk, u32 ack, int flag)
> tcp_try_keep_open(sk);
> NET_INC_STATS(sock_net(sk),
> LINUX_MIB_TCPLOSSPROBERECOVERY);
> + tcp_plb_check_rehash_loss(sk);
[Severity: Low]
The commit message says "Every 5th Fast Recovery", and the new field
comment in include/linux/tcp.h says:
u8 plb_loss_recoveries; /* fast recoveries since last PLB check */
This branch of tcp_process_tlp_ack() goes through
tcp_init_cwnd_reduction(), TCP_CA_CWR, tcp_end_cwnd_reduction() and
tcp_try_keep_open(). It never enters TCP_CA_Recovery, but it still
increments plb_loss_recoveries.
The counter is also reset outside the 5-event check. tcp_plb_rehash()
resets it, and that function is shared with the ECN PLB path.
tcp_plb_update_state_upon_rto() resets it too. So it really counts loss
events since the last rehash, RTO or evaluation.
The real cadence is therefore faster than the "~68% by the 20th Fast
Recovery" model. The TLP hook looks intentional, since the packetdrill
test later in the series exercises it. Could the commit message, the
ip-sysctl.rst entry and the tcp.h comment be updated to cover it?
> } else if (!(flag & (FLAG_SND_UNA_ADVANCED |
> FLAG_NOT_DUP | FLAG_DATA_SACKED))) {
> /* Pure dupack: original and TLP probe arrived; no loss */
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index c1d2acb8b7b4e..85abbf6d58b93 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -3534,6 +3534,7 @@ static int __net_init tcp_sk_init(struct net *net)
> net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 5;
> /* Default congestion threshold for PLB to mark a round is 50% */
> net->ipv4.sysctl_tcp_plb_cong_thresh = (1 << TCP_PLB_SCALE) / 2;
> + net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128;
[Severity: Medium]
Is it intended to turn Generic PLB on by default for every TCP socket in
every netns, whatever the congestion control? The ECN-based
tcp_plb_enabled defaults to off.
With this default, tcp_plb_check_rehash_loss() runs on every
tcp_enter_recovery(), which is reached from tcp_fastretrans_alert() and
from the timer-driven tcp_rack_reo_timeout(). It also runs on the TLP
loss branch of tcp_process_tlp_ack(). Every 5th such event it rehashes
with probability max(rate_prob, floor).
The floor applies even when the delivery rate has not dropped at all:
if (tp->plb_rehash < 2)
floor = base_prob >> 1;
else
floor = base_prob >> 3;
prob = max(rate_prob, floor);
Wouldn't a long-lived IPv6 flow on a single path with steady random
loss then keep changing its flow label and resetting its dst for the
life of the connection, with nothing to gain?
plb_max_rate only ever rises in tcp_rate_gen(). The only decay is the
stale-hop path. Consider a flow whose fair share drops because more
flows join a shared bottleneck, which is not an ECMP problem. It would
see a large deficit and a high rate_prob, and keep rehashing until the
stale-hop decay catches up.
sk_txrehash defaults to SOCK_TXREHASH_ENABLED, so nothing else gates
this. tcp_plb_update_state_upon_rto() also now runs its pause and reset
logic by default.
The commit message gives the default of 128, and the selftests later in
the series rely on it. The benchmarks, though, only cover a controlled
4-way IPv6 ECMP setup. Would it be better to default to 0, or to explain
in the commit message why this new rehash trigger is safe for all
existing TCP traffic?
>
> /* Reno is always built in */
> if (!net_eq(net, &init_net) &&
> diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
> index 794bddc4dc2d2..324bcb27f540a 100644
> --- a/net/ipv4/tcp_plb.c
> +++ b/net/ipv4/tcp_plb.c
[ ... ]
> @@ -96,6 +98,63 @@ void tcp_plb_check_rehash_ecn(struct sock *sk)
> }
> EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
>
> +void tcp_plb_check_rehash_loss(struct sock *sk)
> +{
[ ... ]
> + /* self-normalise MSS-per-sec rate, using the highest
> + * observed rate. More regression, more rehash.
> + */
[Severity: Low]
This isn't a bug, but the comment says MSS-per-sec. The plb_max_rate
field in include/linux/tcp.h is documented as ((MSS packets / us) << 20),
and tcp_rate_gen() computes it as ((u64)rs->delivered << 20) /
rs->interval_us. Should the comment say packets per microsecond scaled
by 2^20?
> + rate_prob = 0;
> + cur_rate = (u64)tp->rate_delivered << 20;
> + max_rate = tp->plb_max_rate * tp->rate_interval_us;
> + if (max_rate > cur_rate) {
> + u64 deficit;
> +
> + deficit = mul_u64_u64_div_u64(max_rate - cur_rate,
> + 1 << 8, max_rate);
> + rate_prob = (4 * base_prob * deficit * deficit) >> 16;
> + rate_prob = min_t(u32, rate_prob, 255);
> +
> + /* Don't decay plb_max_rate if the regression is
> + * under 15% (38/256).
> + */
> + if (deficit < 38)
> + tp->plb_stale_hops = 0;
> + } else {
> + tp->plb_stale_hops = 0;
> + }
[ ... ]
> + if (!tcp_plb_rehash(sk))
> + return;
> +
> + if (tp->plb_stale_hops < 3)
> + tp->plb_stale_hops++;
> + if (tp->plb_stale_hops == 3)
> + tp->plb_max_rate -= tp->plb_max_rate >> 3;
> +}
[Severity: Medium]
Does this match the commit message?
Therefore, tp->plb_stale_hops counts consecutive rehashes
without recovery within ~15% of the peak (deficit < 38).
Once three consecutive rehashes stay >= ~15% below
tp->plb_max_rate, each subsequent stale rehash decays
tp->plb_max_rate by 1/8 (to 7/8) so the flow adapts to the
new paths.
plb_stale_hops is reset only when the current evaluation looks healthy,
and that happens before the rehash decision. It is then incremented on
every successful rehash, including an exploratory floor-probability hop
away from a healthy path. The decay also runs on the same rehash that
brings the counter to 3:
E1: healthy -> stale = 0, floor rehash -> stale = 1
E2: degraded -> rehash -> stale = 2
E3: degraded -> rehash -> stale = 3 -> plb_max_rate decayed
At that point only two hops are known to have landed on degraded paths,
and the third hop's result has not been seen yet. Would this erode the
good-path memory one hop earlier than described?
Should the increment depend on the path just left being degraded? Or
should the decay apply only when the counter was already 3 before this
rehash?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for Generic PLB.
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
@ 2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-05 12:18 ` Kuniyuki Iwashima
0 siblings, 1 reply; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 9:17 UTC (permalink / raw)
To: kuniyu
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The three new packetdrill scripts (tcp_plb_loss_rate.pkt,
tcp_plb_loss_rto_suspend.pkt, tcp_plb_loss_tlp.pkt) check the IPv6…
- [Low] The header comment of tcp_plb_loss_rate.pkt says Phase 2 will
"Record non-app-limited plb_max_rate, then drop cur_rate".
--
selftest: packetdrill: Add tests for Generic PLB.
This adds three packetdrill scripts for Generic PLB. tcp_plb_loss_rate.pkt
covers a rehash triggered by a rate drop in fast recovery, and
tcp_plb_loss_rto_suspend.pkt covers suspension after RTO. tcp_plb_loss_tlp.pkt
covers TLP: a spurious TLP must not rehash, while a TLP that detects real loss
must.
> diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
> new file mode 100644
> index 0000000000000..2e81fde34e606
> --- /dev/null
> +++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
> @@ -0,0 +1,83 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Test TCP Generic PLB: rate-drop triggered PLB rehash in Fast Recovery.
> +// - Phase 1: 4 Fast Recovery rounds (< 5) -> no rehash.
> +// - Phase 2: Record non-app-limited plb_max_rate, then drop cur_rate
> +// upon entering the 5th Fast Recovery -> rehash.
[Severity: Low]
The header says Phase 2 will "Record non-app-limited plb_max_rate". Is
that accurate?
In tcp_rate_gen(), plb_max_rate only goes up. It changes only when a
sample is more than 1.125x the current value:
(u64)rs->delivered << 20 >
(u64)(tp->plb_max_rate + (tp->plb_max_rate >> 3)) * rs->interval_us
The high plb_max_rate is already set during setup, by the ACKs of 1:1001
and 1001:3001. The Phase 2 samples (9 segments / ~10ms, then 1 segment /
50ms) are too low to change it.
What Phase 2 actually records is the low non-app-limited sample in
tp->rate_delivered / tp->rate_interval_us. tcp_plb_check_rehash_loss()
reads that as cur_rate.
Could the comment describe that instead?
> +
> +`./defaults.sh
> +sysctl -q net.ipv4.tcp_early_retrans=0
> +sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255`
[Severity: Medium]
Should this script set --ip_version=ipv6?
Every outbound packet is matched with a flowlabel. The rehash shows up as
the flow label changing from 0x1 to 0x2:
+0 > (flowlabel 0x2) . 5501:5601(100) ack 1
The script has no --ip_version line, though. ksft_runner.sh then falls
back to all three families:
ip_versions=$(grep -E '^--ip_version=' $script | cut -d '=' -f 2)
if [[ -z $ip_versions ]]; then
ip_versions="ipv4 ipv6 ipv4-mapped-ipv6"
So the script runs three times. In the ipv4 and ipv4-mapped-ipv6 runs the
packets on the wire are IPv4, and IPv4 has no flow label field.
If packetdrill rejects or fails to match a (flowlabel N) spec on IPv4
packets, would 2 of the 3 ktap results fail for this script? If it ignores
the spec instead, the IPv4 runs only check tcpi_rehash.
Other family-specific scripts in this directory pin the family. For
example, tcp_syncookies_ip6_9k.pkt uses --ip_version=ipv6.
tcp_plb_loss_rto_suspend.pkt and tcp_plb_loss_tlp.pkt have the same
problem. Both match flow labels on every outbound packet and neither has
an --ip_version line. The later ecmp_rehash.sh change in this series
doesn't touch these scripts, so the problem is still there at the end of
the series.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh.
2026-12-04 8:54 ` [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh Kuniyuki Iwashima
@ 2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-05 12:23 ` Kuniyuki Iwashima
0 siblings, 1 reply; 23+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 9:17 UTC (permalink / raw)
To: kuniyu
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch hides a kernel-side interaction between Generic PLB
and the receiver's duplicate-data rehash heuristic; it does not fix it.
- [Low] Series ordering / bisectability: ecmp_rehash.sh is flaky in two
intermediate commits.
--
selftest: net: Disable Generic PLB in ecmp_rehash.sh.
This commit sets net.ipv4.tcp_plb_loss_rehash_prob=0 in each netns that
setup() creates in ecmp_rehash.sh. Generic PLB is on by default, and after
repeated fast recoveries it can rehash the client socket. That rehash makes
test_ecmp_dst_rebuild_consistency() and
test_ecmp_syncookie_path_consistency() flaky.
> diff --git a/tools/testing/selftests/net/ecmp_rehash.sh b/tools/testing/selftests/net/ecmp_rehash.sh
> index f05a6c8edd2a8..a2b732cf24189 100755
> --- a/tools/testing/selftests/net/ecmp_rehash.sh
> +++ b/tools/testing/selftests/net/ecmp_rehash.sh
> @@ -186,6 +186,7 @@ setup()
> ip netns exec "$ns" sysctl -qw net.ipv6.conf.default.accept_dad=0
> ip netns exec "$ns" sysctl -qw net.ipv6.conf.all.forwarding=1
> ip netns exec "$ns" sysctl -qw net.core.txrehash=1
> + ip netns exec "$ns" sysctl -qw net.ipv4.tcp_plb_loss_rehash_prob=0
[Severity: Low]
Should this line be folded into "tcp: Introduce Generic PLB."?
That commit turns the feature on by default in tcp_sk_init():
net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128;
It also adds tcp_plb_check_rehash_loss() calls to tcp_enter_recovery() and
to the TLP loss branch of tcp_process_tlp_ack().
This commit message says that default makes ecmp_rehash.sh flaky. The
test-side change only lands two commits later, though. That leaves two
commits where the selftest can fail at random, which can confuse bisects:
"tcp: Introduce Generic PLB." and "selftest: packetdrill: Add tests for
Generic PLB.".
The sysctl only exists from "tcp: Introduce Generic PLB." onward, so this
line can't move earlier by itself. Could it be folded into that commit?
Alternatively, the feature could land default-off, with the default flipped
after this selftest change.
[Severity: Medium]
Does this hide a kernel-side interaction rather than fix it?
tcp_enter_recovery() rehashes before the fast retransmit goes out:
tcp_set_ca_state(sk, TCP_CA_Recovery);
tcp_plb_check_rehash_loss(sk);
So the fast retransmit is the first segment to carry the new sk_txhash and
IPv6 flow label. The recovery may be spurious, for example because of the
reordering the commit message describes. In that case the peer already has
the data and goes through:
tcp_data_queue()
tcp_rcv_spurious_retrans()
icsk_ack.lrcv_flowlabel was saved from earlier in-order data, so the flow
label no longer matches. The peer then takes this branch:
if (inet_csk(sk)->icsk_ca_state != TCP_CA_Loss &&
skb->protocol == htons(ETH_P_IPV6) &&
(tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel !=
ntohl(ip6_flowlabel(ipv6_hdr(skb)))) &&
__sk_rethink_txhash_reset_dst(sk)) {
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPDUPLICATEDATAREHASH);
}
The comment above this heuristic says it assumes the sender suffered an RTO
and that our ACKs are not reaching the other side. With Generic PLB on by
default, a sender-side loss-PLB repath would have two effects on the peer:
- It repaths its ACK direction even though nothing is wrong with that path.
- It bumps TcpDuplicateDataRehash for events that are not ACK-path
failures. ecmp_rehash.sh itself reads that counter as evidence of an
ACK-path failure.
No commit in the series changes tcp_rcv_spurious_retrans(). This patch only
sets tcp_plb_loss_rehash_prob=0 inside the test netns. As a result, IPv6
ECMP deployments that use auto flow labels get this behaviour by default.
Should the peer heuristic be kept from firing on flow label changes caused
by PLB? If not, should the changelog of "tcp: Introduce Generic PLB."
describe this as accepted behaviour?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB.
2026-12-05 9:17 ` netdev-bot+sashiko
@ 2026-12-05 12:13 ` Kuniyuki Iwashima
0 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-05 12:13 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
On Sat, 05 Dec 2026 09:17:54 +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 6 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 2 · Low: 4
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] Generic PLB is on by default
> (net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128 in tcp_sk_init()) for…
> - [Medium] The stale-hop decay in tcp_plb_check_rehash_loss() starts one
> hop earlier than the commit message describes.
> - [Low] The commit message ('Every 5th Fast Recovery'), the sysctl docs
> and the field comment on struct tcp_sock::plb_loss_recoveries ('fast…
> - [Low] The new tcp_plb_loss_rehash_prob documentation describes Generic
> PLB as generally applicable.
> - [Low] ip-sysctl.rst describes tcp_plb_loss_rehash_prob as the 'Base
> probability for Generic PLB repathing, mapped from [0, 1] to [0, 255]…
> - [Low] The comment in tcp_plb_check_rehash_loss() says 'self-normalise
> MSS-per-sec rate', but the struct tcp_sock::plb_max_rate definition…
>
> --
>
> tcp: Introduce Generic PLB.
>
> This commit adds Generic PLB. It is a variant of Protective Load
> Balancing that does not depend on the congestion control, and it
> rehashes the txhash based on packet loss and delivery rate regression.
> A new per-netns sysctl, net.ipv4.tcp_plb_loss_rehash_prob (default 128),
> sets the base probability, which is evaluated on every 5th loss
> recovery. A per-flow peak delivery rate is tracked in tcp_rate_gen()
> and decayed after repeated stale rehashes.
>
> Link: https://gist.github.com/q2ven/c04b56477dea4d1a58f5eadc4b07f9e0
>
> > diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
> > index dffcec335a779..3046f6725b218 100644
> > --- a/Documentation/networking/ip-sysctl.rst
> > +++ b/Documentation/networking/ip-sysctl.rst
>
> [ ... ]
>
> > @@ -1437,6 +1437,21 @@ tcp_plb_cong_thresh - INTEGER
> >
> > Default: 128
> >
> > +tcp_plb_loss_rehash_prob - INTEGER
> > + Base probability for Generic PLB repathing, mapped from [0, 1]
> > + to [0, 255] (e.g., 128 means 50%). Setting this to 0 disables
> > + Generic PLB.
>
> [Severity: Low]
> Is "128 means 50%" accurate for how the value is used?
> tcp_plb_check_rehash_loss() never uses base_prob directly as the repath
> probability:
>
> rate_prob = (4 * base_prob * deficit * deficit) >> 16;
> ...
> prob = max(rate_prob, floor);
>
> Here floor is base_prob >> 1 while plb_rehash < 2, and base_prob >> 3
> after that. The check also only runs on every 5th loss event. base_prob
> is the real probability only when the delivery rate has dropped by
> exactly 50%.
>
> Could this entry describe the floor, the deficit scaling and the 5-event
> cadence, so admins can predict what a given value does?
>
> > +
> > + Unlike tcp_plb_enabled which relies on ECN signals, Generic PLB
> > + is congestion-control-agnostic and triggers repathing based on
> > + packet loss and delivery rate regression relative to the flow's
> > + recent peak delivery rate. Larger tcp_plb_loss_rehash_prob
> > + values make repathing more aggressive.
>
> [Severity: Low]
> Should this entry say that the repath only changes the IPv6 flow label?
> The tcp_plb_enabled text above says so explicitly:
>
> PLB changes socket txhash which results in a change in IPv6 Flow Label
> field, and currently no-op for IPv4 headers.
>
> tcp_plb_rehash() calls __sk_rethink_txhash_reset_dst(). That function
> only resets the dst for AF_INET6, and its comment says "IPv4 ECMP path
> selection does not use sk_txhash".
>
> Generic PLB is still enabled by default for IPv4 sockets. For plain IPv4
> traffic it bumps LINUX_MIB_TCPPLBREHASH and tp->plb_rehash, and applies
> the stale-hop decay to plb_max_rate, but nothing changes on the wire.
> The exception is when the host does its own encapsulation based on
> skb->hash.
>
> The commit message cites cloud VM environments as the motivation, but
> it does not mention the IPv6-only scope, and all the benchmarks are
> IPv6.
>
> > +
> > + Possible Values: 0 - 255
> > +
> > + Default: 128
> > +
>
> [ ... ]
>
> > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> > index d2445dc259324..ab524990b8786 100644
> > --- a/net/ipv4/tcp_input.c
> > +++ b/net/ipv4/tcp_input.c
>
> [ ... ]
>
> > @@ -4201,6 +4215,7 @@ static void tcp_process_tlp_ack(struct sock *sk, u32 ack, int flag)
> > tcp_try_keep_open(sk);
> > NET_INC_STATS(sock_net(sk),
> > LINUX_MIB_TCPLOSSPROBERECOVERY);
> > + tcp_plb_check_rehash_loss(sk);
>
> [Severity: Low]
> The commit message says "Every 5th Fast Recovery", and the new field
> comment in include/linux/tcp.h says:
>
> u8 plb_loss_recoveries; /* fast recoveries since last PLB check */
>
> This branch of tcp_process_tlp_ack() goes through
> tcp_init_cwnd_reduction(), TCP_CA_CWR, tcp_end_cwnd_reduction() and
> tcp_try_keep_open(). It never enters TCP_CA_Recovery, but it still
> increments plb_loss_recoveries.
>
> The counter is also reset outside the 5-event check. tcp_plb_rehash()
> resets it, and that function is shared with the ECN PLB path.
> tcp_plb_update_state_upon_rto() resets it too. So it really counts loss
> events since the last rehash, RTO or evaluation.
>
> The real cadence is therefore faster than the "~68% by the 20th Fast
> Recovery" model. The TLP hook looks intentional, since the packetdrill
> test later in the series exercises it. Could the commit message, the
> ip-sysctl.rst entry and the tcp.h comment be updated to cover it?
>
> > } else if (!(flag & (FLAG_SND_UNA_ADVANCED |
> > FLAG_NOT_DUP | FLAG_DATA_SACKED))) {
> > /* Pure dupack: original and TLP probe arrived; no loss */
> > diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> > index c1d2acb8b7b4e..85abbf6d58b93 100644
> > --- a/net/ipv4/tcp_ipv4.c
> > +++ b/net/ipv4/tcp_ipv4.c
> > @@ -3534,6 +3534,7 @@ static int __net_init tcp_sk_init(struct net *net)
> > net->ipv4.sysctl_tcp_plb_suspend_rto_sec = 5;
> > /* Default congestion threshold for PLB to mark a round is 50% */
> > net->ipv4.sysctl_tcp_plb_cong_thresh = (1 << TCP_PLB_SCALE) / 2;
> > + net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128;
>
> [Severity: Medium]
> Is it intended to turn Generic PLB on by default for every TCP socket in
> every netns, whatever the congestion control?
Yes, it's intentional.
Generic PLB does not require network-side ECN deployment, so enabling
it by default allows general TCP workloads (such as CUBIC/BBR in cloud
VMs) to benefit automatically, just like RTO-triggered rehashing
(net.core.txrehash=1).
> The ECN-based
> tcp_plb_enabled defaults to off.
>
> With this default, tcp_plb_check_rehash_loss() runs on every
> tcp_enter_recovery(), which is reached from tcp_fastretrans_alert() and
> from the timer-driven tcp_rack_reo_timeout(). It also runs on the TLP
> loss branch of tcp_process_tlp_ack(). Every 5th such event it rehashes
> with probability max(rate_prob, floor).
>
> The floor applies even when the delivery rate has not dropped at all:
>
> if (tp->plb_rehash < 2)
> floor = base_prob >> 1;
> else
> floor = base_prob >> 3;
>
> prob = max(rate_prob, floor);
>
> Wouldn't a long-lived IPv6 flow on a single path with steady random
> loss then keep changing its flow label and resetting its dst for the
> life of the connection, with nothing to gain?
On a single-path flow with steady random loss, floor drops to 16/255
(~6.3%) after two rehashes, and it's evaluated only on every 5th loss
recovery (~1 rehash per ~80 loss events), which adds negligible overhead
and is harmless when there is only one path.
>
> plb_max_rate only ever rises in tcp_rate_gen(). The only decay is the
> stale-hop path. Consider a flow whose fair share drops because more
> flows join a shared bottleneck, which is not an ECMP problem. It would
> see a large deficit and a high rate_prob, and keep rehashing until the
> stale-hop decay catches up.
On a shared bottleneck where fair share drops, the plb_stale_hops
decay brings plb_max_rate down to the new fair share so rehashing
settles.
>
> sk_txrehash defaults to SOCK_TXREHASH_ENABLED, so nothing else gates
> this. tcp_plb_update_state_upon_rto() also now runs its pause and reset
> logic by default.
>
> The commit message gives the default of 128, and the selftests later in
> the series rely on it. The benchmarks, though, only cover a controlled
> 4-way IPv6 ECMP setup. Would it be better to default to 0, or to explain
> in the commit message why this new rehash trigger is safe for all
> existing TCP traffic?
I'll mention that in v2.
>
> >
> > /* Reno is always built in */
> > if (!net_eq(net, &init_net) &&
> > diff --git a/net/ipv4/tcp_plb.c b/net/ipv4/tcp_plb.c
> > index 794bddc4dc2d2..324bcb27f540a 100644
> > --- a/net/ipv4/tcp_plb.c
> > +++ b/net/ipv4/tcp_plb.c
>
> [ ... ]
>
> > @@ -96,6 +98,63 @@ void tcp_plb_check_rehash_ecn(struct sock *sk)
> > }
> > EXPORT_SYMBOL_GPL(tcp_plb_check_rehash_ecn);
> >
> > +void tcp_plb_check_rehash_loss(struct sock *sk)
> > +{
>
> [ ... ]
>
> > + /* self-normalise MSS-per-sec rate, using the highest
> > + * observed rate. More regression, more rehash.
> > + */
>
> [Severity: Low]
> This isn't a bug, but the comment says MSS-per-sec. The plb_max_rate
> field in include/linux/tcp.h is documented as ((MSS packets / us) << 20),
> and tcp_rate_gen() computes it as ((u64)rs->delivered << 20) /
> rs->interval_us. Should the comment say packets per microsecond scaled
> by 2^20?
>
> > + rate_prob = 0;
> > + cur_rate = (u64)tp->rate_delivered << 20;
> > + max_rate = tp->plb_max_rate * tp->rate_interval_us;
> > + if (max_rate > cur_rate) {
> > + u64 deficit;
> > +
> > + deficit = mul_u64_u64_div_u64(max_rate - cur_rate,
> > + 1 << 8, max_rate);
> > + rate_prob = (4 * base_prob * deficit * deficit) >> 16;
> > + rate_prob = min_t(u32, rate_prob, 255);
> > +
> > + /* Don't decay plb_max_rate if the regression is
> > + * under 15% (38/256).
> > + */
> > + if (deficit < 38)
> > + tp->plb_stale_hops = 0;
> > + } else {
> > + tp->plb_stale_hops = 0;
> > + }
>
> [ ... ]
>
> > + if (!tcp_plb_rehash(sk))
> > + return;
> > +
> > + if (tp->plb_stale_hops < 3)
> > + tp->plb_stale_hops++;
> > + if (tp->plb_stale_hops == 3)
> > + tp->plb_max_rate -= tp->plb_max_rate >> 3;
> > +}
>
> [Severity: Medium]
> Does this match the commit message?
>
> Therefore, tp->plb_stale_hops counts consecutive rehashes
> without recovery within ~15% of the peak (deficit < 38).
> Once three consecutive rehashes stay >= ~15% below
> tp->plb_max_rate, each subsequent stale rehash decays
> tp->plb_max_rate by 1/8 (to 7/8) so the flow adapts to the
> new paths.
>
> plb_stale_hops is reset only when the current evaluation looks healthy,
> and that happens before the rehash decision. It is then incremented on
> every successful rehash, including an exploratory floor-probability hop
> away from a healthy path. The decay also runs on the same rehash that
> brings the counter to 3:
>
> E1: healthy -> stale = 0, floor rehash -> stale = 1
> E2: degraded -> rehash -> stale = 2
> E3: degraded -> rehash -> stale = 3 -> plb_max_rate decayed
>
> At that point only two hops are known to have landed on degraded paths,
> and the third hop's result has not been seen yet. Would this erode the
> good-path memory one hop earlier than described?
>
> Should the increment depend on the path just left being degraded?
Ah, good catch.
Leaving a healthy path via a floor rehash should not increment
plb_stale_hops right after resetting it to 0.
Decaying on the 3rd degraded rehash (after 2 un-decayed degraded hops)
is the intended balance and matches the benchmarked behaviour when
congestion starts, avoiding overly slow convergence on a shared bottleneck.
In v2, I'll update plb_stale_hops / decay only when deficit >= 38:
if (degraded) {
if (tp->plb_stale_hops < 2)
tp->plb_stale_hops++;
else
tp->plb_max_rate -= tp->plb_max_rate >> 3;
}
---
pw-bot: cr
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for Generic PLB.
2026-12-05 9:17 ` netdev-bot+sashiko
@ 2026-12-05 12:18 ` Kuniyuki Iwashima
0 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-05 12:18 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
On Sat, 05 Dec 2026 09:17:56 +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] The three new packetdrill scripts (tcp_plb_loss_rate.pkt,
> tcp_plb_loss_rto_suspend.pkt, tcp_plb_loss_tlp.pkt) check the IPv6…
> - [Low] The header comment of tcp_plb_loss_rate.pkt says Phase 2 will
> "Record non-app-limited plb_max_rate, then drop cur_rate".
>
> --
>
> selftest: packetdrill: Add tests for Generic PLB.
>
> This adds three packetdrill scripts for Generic PLB. tcp_plb_loss_rate.pkt
> covers a rehash triggered by a rate drop in fast recovery, and
> tcp_plb_loss_rto_suspend.pkt covers suspension after RTO. tcp_plb_loss_tlp.pkt
> covers TLP: a spurious TLP must not rehash, while a TLP that detects real loss
> must.
>
> > diff --git a/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
> > new file mode 100644
> > index 0000000000000..2e81fde34e606
> > --- /dev/null
> > +++ b/tools/testing/selftests/net/packetdrill/tcp_plb_loss_rate.pkt
> > @@ -0,0 +1,83 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +//
> > +// Test TCP Generic PLB: rate-drop triggered PLB rehash in Fast Recovery.
> > +// - Phase 1: 4 Fast Recovery rounds (< 5) -> no rehash.
> > +// - Phase 2: Record non-app-limited plb_max_rate, then drop cur_rate
> > +// upon entering the 5th Fast Recovery -> rehash.
>
> [Severity: Low]
> The header says Phase 2 will "Record non-app-limited plb_max_rate". Is
> that accurate?
"non-app-limited" is stale comment from a draft version, I'll remove it.
>
> In tcp_rate_gen(), plb_max_rate only goes up. It changes only when a
> sample is more than 1.125x the current value:
>
> (u64)rs->delivered << 20 >
> (u64)(tp->plb_max_rate + (tp->plb_max_rate >> 3)) * rs->interval_us
>
> The high plb_max_rate is already set during setup, by the ACKs of 1:1001
> and 1001:3001. The Phase 2 samples (9 segments / ~10ms, then 1 segment /
> 50ms) are too low to change it.
>
> What Phase 2 actually records is the low non-app-limited sample in
> tp->rate_delivered / tp->rate_interval_us. tcp_plb_check_rehash_loss()
> reads that as cur_rate.
>
> Could the comment describe that instead?
>
> > +
> > +`./defaults.sh
> > +sysctl -q net.ipv4.tcp_early_retrans=0
> > +sysctl -q net.ipv4.tcp_plb_loss_rehash_prob=255`
>
> [Severity: Medium]
> Should this script set --ip_version=ipv6?
packetdrill ignores flowlabel annotation in IPv4, so it passes
without failure. That said, we don't need to cover ipv4.
I'll add --ip_version=ipv6.
>
> Every outbound packet is matched with a flowlabel. The rehash shows up as
> the flow label changing from 0x1 to 0x2:
>
> +0 > (flowlabel 0x2) . 5501:5601(100) ack 1
>
> The script has no --ip_version line, though. ksft_runner.sh then falls
> back to all three families:
>
> ip_versions=$(grep -E '^--ip_version=' $script | cut -d '=' -f 2)
> if [[ -z $ip_versions ]]; then
> ip_versions="ipv4 ipv6 ipv4-mapped-ipv6"
>
> So the script runs three times. In the ipv4 and ipv4-mapped-ipv6 runs the
> packets on the wire are IPv4, and IPv4 has no flow label field.
>
> If packetdrill rejects or fails to match a (flowlabel N) spec on IPv4
> packets, would 2 of the 3 ktap results fail for this script? If it ignores
> the spec instead, the IPv4 runs only check tcpi_rehash.
>
> Other family-specific scripts in this directory pin the family. For
> example, tcp_syncookies_ip6_9k.pkt uses --ip_version=ipv6.
>
> tcp_plb_loss_rto_suspend.pkt and tcp_plb_loss_tlp.pkt have the same
> problem. Both match flow labels on every outbound packet and neither has
> an --ip_version line. The later ecmp_rehash.sh change in this series
> doesn't touch these scripts, so the problem is still there at the end of
> the series.
>
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh.
2026-12-05 9:17 ` netdev-bot+sashiko
@ 2026-12-05 12:23 ` Kuniyuki Iwashima
0 siblings, 0 replies; 23+ messages in thread
From: Kuniyuki Iwashima @ 2026-12-05 12:23 UTC (permalink / raw)
To: netdev-bot+sashiko
Cc: edumazet, ncardwell, davem, kuba, pabeni, willemb, horms, ycheng,
kuni1840, netdev
On Sat, 05 Dec 2026 09:17:57 +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 1
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [Medium] The patch hides a kernel-side interaction between Generic PLB
> and the receiver's duplicate-data rehash heuristic; it does not fix it.
> - [Low] Series ordering / bisectability: ecmp_rehash.sh is flaky in two
> intermediate commits.
>
> --
>
> selftest: net: Disable Generic PLB in ecmp_rehash.sh.
>
> This commit sets net.ipv4.tcp_plb_loss_rehash_prob=0 in each netns that
> setup() creates in ecmp_rehash.sh. Generic PLB is on by default, and after
> repeated fast recoveries it can rehash the client socket. That rehash makes
> test_ecmp_dst_rebuild_consistency() and
> test_ecmp_syncookie_path_consistency() flaky.
>
> > diff --git a/tools/testing/selftests/net/ecmp_rehash.sh b/tools/testing/selftests/net/ecmp_rehash.sh
> > index f05a6c8edd2a8..a2b732cf24189 100755
> > --- a/tools/testing/selftests/net/ecmp_rehash.sh
> > +++ b/tools/testing/selftests/net/ecmp_rehash.sh
> > @@ -186,6 +186,7 @@ setup()
> > ip netns exec "$ns" sysctl -qw net.ipv6.conf.default.accept_dad=0
> > ip netns exec "$ns" sysctl -qw net.ipv6.conf.all.forwarding=1
> > ip netns exec "$ns" sysctl -qw net.core.txrehash=1
> > + ip netns exec "$ns" sysctl -qw net.ipv4.tcp_plb_loss_rehash_prob=0
>
> [Severity: Low]
> Should this line be folded into "tcp: Introduce Generic PLB."?
>
> That commit turns the feature on by default in tcp_sk_init():
>
> net->ipv4.sysctl_tcp_plb_loss_rehash_prob = 128;
>
> It also adds tcp_plb_check_rehash_loss() calls to tcp_enter_recovery() and
> to the TLP loss branch of tcp_process_tlp_ack().
>
> This commit message says that default makes ecmp_rehash.sh flaky. The
> test-side change only lands two commits later, though. That leaves two
> commits where the selftest can fail at random, which can confuse bisects:
> "tcp: Introduce Generic PLB." and "selftest: packetdrill: Add tests for
> Generic PLB.".
>
> The sysctl only exists from "tcp: Introduce Generic PLB." onward, so this
> line can't move earlier by itself. Could it be folded into that commit?
> Alternatively, the feature could land default-off, with the default flipped
> after this selftest change.
>
> [Severity: Medium]
> Does this hide a kernel-side interaction rather than fix it?
No.
The peer cannot distinguish a PLB-triggered flow label change from
an RTO-triggered one in tcp_rcv_spurious_retrans().
Existing ECN-PLB (tcp_plb_check_rehash_ecn()) already has the exact
same behaviour when it changes the flow label outside TCP_CA_Loss.
This only occurs when a spurious fast recovery coincides with a
probabilistic PLB check (every 5th loss recovery) and simply rehashes
the peer's ACK path.
Also, ecmp_rehash.sh must disable Generic PLB regardless of
tcp_rcv_spurious_retrans() because test_ecmp_dst_rebuild_consistency()
expects the client flow to stay on the same ECMP path and fails from
client-side TCPPLBRehash alone.
>
> tcp_enter_recovery() rehashes before the fast retransmit goes out:
>
> tcp_set_ca_state(sk, TCP_CA_Recovery);
>
> tcp_plb_check_rehash_loss(sk);
>
> So the fast retransmit is the first segment to carry the new sk_txhash and
> IPv6 flow label. The recovery may be spurious, for example because of the
> reordering the commit message describes. In that case the peer already has
> the data and goes through:
>
> tcp_data_queue()
> tcp_rcv_spurious_retrans()
>
> icsk_ack.lrcv_flowlabel was saved from earlier in-order data, so the flow
> label no longer matches. The peer then takes this branch:
>
> if (inet_csk(sk)->icsk_ca_state != TCP_CA_Loss &&
> skb->protocol == htons(ETH_P_IPV6) &&
> (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel !=
> ntohl(ip6_flowlabel(ipv6_hdr(skb)))) &&
> __sk_rethink_txhash_reset_dst(sk)) {
> NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPDUPLICATEDATAREHASH);
> }
>
> The comment above this heuristic says it assumes the sender suffered an RTO
> and that our ACKs are not reaching the other side. With Generic PLB on by
> default, a sender-side loss-PLB repath would have two effects on the peer:
>
> - It repaths its ACK direction even though nothing is wrong with that path.
>
> - It bumps TcpDuplicateDataRehash for events that are not ACK-path
> failures. ecmp_rehash.sh itself reads that counter as evidence of an
> ACK-path failure.
>
> No commit in the series changes tcp_rcv_spurious_retrans(). This patch only
> sets tcp_plb_loss_rehash_prob=0 inside the test netns. As a result, IPv6
> ECMP deployments that use auto flow labels get this behaviour by default.
>
> Should the peer heuristic be kept from firing on flow label changes caused
> by PLB? If not, should the changelog of "tcp: Introduce Generic PLB."
> describe this as accepted behaviour?
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204085551.1518105-1-kuniyu%40google.com
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2026-12-05 12:23 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 8:54 [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 01/10] tcp: Return early when tcp_plb_check_rehash() does not rehash a flow Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 02/10] tcp: Don't call get_random_u32_below(0) in tcp_plb_update_state_upon_rto() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 03/10] tcp: Move struct tcp_plb_state to struct tcp_sock Kuniyuki Iwashima
2026-12-04 10:34 ` David Laight
2026-12-04 12:33 ` Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 8:54 ` [PATCH v1 net-next 04/10] tcp: Call tcp_plb_update_state_upon_rto() after rehash in tcp_write_timeout() Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-04 8:54 ` [PATCH v1 net-next 05/10] tcp: Rename tcp_plb_check_rehash() to tcp_plb_check_rehash_ecn() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 06/10] tcp: Factorise tcp_plb_rehash() Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 07/10] tcp: Lower tcp_plb_suspend_rto_sec default Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 08/10] tcp: Introduce Generic PLB Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-05 12:13 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 09/10] selftest: packetdrill: Add tests for " Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-05 12:18 ` Kuniyuki Iwashima
2026-12-04 8:54 ` [PATCH v1 net-next 10/10] selftest: net: Disable Generic PLB in ecmp_rehash.sh Kuniyuki Iwashima
2026-12-05 9:17 ` netdev-bot+sashiko
2026-12-05 12:23 ` Kuniyuki Iwashima
2026-12-04 9:03 ` [PATCH v1 net-next 00/10] tcp: Introduce Generic PLB netdev-bot+sinfo
2026-12-04 9:29 ` Kuniyuki Iwashima
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.