Re: [PATCH net-next v5 3/4] tcp: add TCP_ECN_SEND_ECT_1 flag for congestion control
From: netdev-bot+sashiko
Date: Tue Dec 01 2026 - 08:10:29 EST
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 2
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] Undisclosed behaviour change in tcp_init_congestion_control()
(net/ipv4/tcp_cong.c:248-253).
- [Medium] TCP_ECN_SEND_ECT_1 is cleared only in
tcp_reinit_congestion_control() (net/ipv4/tcp_cong.c:269), which is…
- [Medium] tcp: premature established ECT in
tcp_init_congestion_control() breaks TFO
- [Low] The commit message says TCP_ECN_SEND_ECT_1 lets a CC choose
ECT(1) or ECT(0) 'when congestion control is initialized after ECN…
- [Low] If a BPF sock_ops program switches the CC from
BPF_SOCK_OPS_TCP_CONNECT_CB, any TCP_ECN_SEND_ECT_1 the CC sets in its…
--
tcp: add TCP_ECN_SEND_ECT_1 flag for congestion control
This commit adds a TCP_ECN_SEND_ECT_1 bit to tp->ecn_flags. A congestion
control module can set it to choose ECT(1) instead of ECT(0) for the
established flow. tcp_init_congestion_control() and the AccECN branch of
tcp_ecn_send() now use a new INET_ECN_xmit_established_ect() helper that
reads the bit, and tcp_reinit_congestion_control() clears the bit before
switching CCs.
> diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
> index 3331679c81d70..34617106f5e5e 100644
> --- a/net/ipv4/tcp_cong.c
> +++ b/net/ipv4/tcp_cong.c
> @@ -240,7 +240,14 @@ void tcp_init_congestion_control(struct sock *sk)
> tcp_sk(sk)->prior_ssthresh = 0;
> if (icsk->icsk_ca_ops->init)
> icsk->icsk_ca_ops->init(sk);
> - if (tcp_ca_needs_ecn(sk))
> + /*
> + * Select the initial ECN codepoint based on the congestion
> + * control module flag, while each module is responsible for
> + * handling fallback cases when negotiation did not succeed.
> + */
> + if (tcp_ca_needs_accecn(sk))
> + INET_ECN_xmit_established_ect(sk);
> + else if (tcp_ca_needs_ecn(sk))
> INET_ECN_xmit(sk);
> else
> INET_ECN_dontxmit(sk);
[Severity: Medium]
Does setting the established codepoint here break AccECN on passive
TCP Fast Open connections?
For a TFO SYN, tcp_conn_request() creates the child socket before the
SYN-ACK is sent:
tcp_conn_request()
tcp_try_fastopen()
tcp_fastopen_create_child()
syn_recv_sock()
tcp_create_openreq_child()
tcp_ecn_openreq_child() /* tp->syn_ect_snt = 0 */
tcp_init_transfer()
tcp_init_congestion_control()
INET_ECN_xmit_established_ect() /* child tos = ECT */
af_ops->send_synack(fastopen_sk, ..., TCP_SYNACK_FASTOPEN, skb)
tcp_v4_send_synack() and tcp_v6_send_synack() then build the SYN-ACK
from the child's tos/tclass. With this patch, that now carries ECT(0)
or ECT(1) for any CC with TCP_CONG_NEEDS_ACCECN, even one without
TCP_CONG_NEEDS_ECN. The codepoint is recorded in
tcp_rsk(req)->syn_ect_snt. However, the child's tp->syn_ect_snt was
copied from treq->syn_ect_snt earlier, while it was still 0
(Not-ECT).
When the client's third ACK reflects the SYN-ACK codepoint in ACE,
tcp_rcv_state_process() in TCP_SYN_RECV calls tcp_accecn_third_ack()
with tp->syn_ect_snt == 0. The transition check then fails and sets
TCP_ACCECN_ACE_FAIL_RECV. From then on, tcp_ecn_send() takes the
INET_ECN_dontxmit() branch.
If that is right, an AccECN CC would lose ECN for the rest of the
connection on every passive TFO connection. With the default
sysctl_tcp_ecn_fallback this is deterministic, not a corner case.
Should the child's tp->syn_ect_snt follow what the SYN-ACK actually
carried? Or should the established codepoint only be applied once the
SYN-ACK has gone out? It may also be worth checking whether NEEDS_ECN
CCs, which already reach INET_ECN_xmit() here, see the same mismatch.
[Severity: Medium]
Does this change behaviour for a CC that has TCP_CONG_NEEDS_ACCECN but not
TCP_CONG_NEEDS_ECN?
Before this patch, such a CC got INET_ECN_dontxmit() here. Now its socket
TOS/tclass always gets ECT(0) or ECT(1), whatever ECN mode was actually
negotiated.
tcp_ecn_send_syn() sets use_ecn whenever use_accecn is true, so this CC
does try to negotiate. With a non-ECN peer the mode ends up as
TCP_ECN_DISABLED. tcp_init_transfer()->tcp_init_congestion_control() then
takes this new branch, and tcp_ecn_send() never clears the result:
net/ipv4/tcp_output.c:tcp_ecn_send() {
...
if (!tcp_ecn_mode_any(tp))
return;
...
}
Wouldn't every packet of this non-ECN connection then go out ECT-marked?
An AQM would CE-mark those packets instead of dropping them, and no CE
feedback would ever come back.
The ECT write happens after ->init(), so the module can't undo it by
calling INET_ECN_dontxmit() in init. Its only option seems to be swapping
icsk_ca_ops to an ops without NEEDS_ACCECN, as DCTCP does with dctcp_reno.
BPF struct_ops CCs can register with this flag, because
TCP_CONG_NEEDS_ACCECN is part of TCP_CONG_MASK.
The flag's definition says:
/* Require successfully negotiated AccECN capability */
#define TCP_CONG_NEEDS_ACCECN BIT(2)
The commit message doesn't mention this change, and only the new comment
here hints at the "module handles fallback" contract.
Should this branch check the negotiated mode? If not, could the commit
message describe the new contract?
> @@ -251,12 +258,15 @@ static void tcp_reinit_congestion_control(struct sock *sk,
> const struct tcp_congestion_ops *ca)
> {
> struct inet_connection_sock *icsk = inet_csk(sk);
> + struct tcp_sock *tp = tcp_sk(sk);
>
> tcp_cleanup_congestion_control(sk);
> WRITE_ONCE(icsk->icsk_ca_ops, ca);
> icsk->icsk_ca_setsockopt = 1;
> memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
>
> + /* Reset ECT(1) selection before initializing a new CC */
> + tp->ecn_flags &= ~TCP_ECN_SEND_ECT_1;
[Severity: Medium]
This is the only place TCP_ECN_SEND_ECT_1 is cleared, and it only covers
the setsockopt(TCP_CONGESTION) path. Can a stale bit survive the other
paths that tear down or replace the CC?
tcp_disconnect() releases the CC and wipes icsk_ca_priv, but leaves
tp->ecn_flags as it is:
net/ipv4/tcp.c:tcp_disconnect() {
...
if (icsk->icsk_ca_initialized && icsk->icsk_ca_ops->release)
icsk->icsk_ca_ops->release(sk);
memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
icsk->icsk_ca_initialized = 0;
...
}
For passive children, tcp_create_openreq_child() clones the listener's
ecn_flags. tcp_ecn_openreq_child() then only calls tcp_ecn_mode_set(),
which clears just the mode bits:
tp->ecn_flags &= ~TCP_ECN_MODE_ANY;
tp->ecn_flags |= mode;
So bit 5 survives. tcp_ca_openreq_child() can then give the child a
different CC, either through RTAX_CC_ALGO or
tcp_assign_congestion_control(), without clearing it.
For example:
1. A socket connects with a BPF CC that sets TCP_ECN_SEND_ECT_1.
2. It is disconnected with connect(AF_UNSPEC).
3. It calls listen().
Every accepted child inherits the bit, even if its CC is CUBIC. With
AccECN negotiated, tcp_ecn_send()->INET_ECN_xmit_established_ect() would
then send ECT(1) on every segment for a classic CC.
Would clearing the bit in tcp_init_congestion_control() before ->init(),
or in tcp_cleanup_congestion_control(), cover these paths?
> if (ca->flags & TCP_CONG_NEEDS_ECN)
> INET_ECN_xmit_negotiation_ect(sk);
> else
[Severity: Low]
Is the CC's ECT(1) request lost when a BPF sock_ops program switches the
CC from BPF_SOCK_OPS_TCP_CONNECT_CB?
tcp_connect()
tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB)
bpf_setsockopt(TCP_CONGESTION)
tcp_reinit_congestion_control()
tcp_init_congestion_control() /* sk is in SYN_SENT */
ca->init() /* sets TCP_ECN_SEND_ECT_1 */
icsk->icsk_ca_initialized = 1;
...
tcp_ecn_send_syn()
tp->ecn_flags = 0; /* bit is wiped */
After the handshake, tcp_init_transfer() skips the re-init:
if (!icsk->icsk_ca_initialized)
tcp_init_congestion_control(sk);
So the bit is never set again. In AccECN mode, tcp_ecn_send() sends ECT(0)
for a CC that asked for ECT(1).
This hazard is new, because before this patch the CC's codepoint choice
wasn't stored in ecn_flags. The fallback is the conservative ECT(0). A CC
that checks tcp_ecn_mode_accecn() in init would fall back on this path
anyway, as DCTCP does.
Is losing the bit here intended?
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 08d0d4a639fec..7b694479095e0 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -350,7 +350,7 @@ static void tcp_ecn_send(struct sock *sk, struct sk_buff *skb,
> if (tcp_ecn_mode_accecn(tp)) {
> if (!tcp_accecn_ace_fail_recv(tp) &&
> !tcp_accecn_ace_fail_send(tp))
> - INET_ECN_xmit(sk);
> + INET_ECN_xmit_established_ect(sk);
[Severity: Low]
The commit message says the new bit:
enables a congestion control module to control whether the connection
transmits using ECT(1) (if the bit is set) or ECT(0) (otherwise),
when congestion control is initialized after ECN negotiation.
Does this match what the code does?
At init, tcp_init_congestion_control() only uses the bit for CCs with
TCP_CONG_NEEDS_ACCECN. Here in tcp_ecn_send(), it is used on every
segment in AccECN mode, for every CC. The commit message doesn't mention
this per-segment change.
In RFC3168 fallback mode, new data always gets ECT(0). Pure ACKs and
retransmits of a NEEDS_ECN CC keep the current TOS:
} else {
/* Not-retransmitted data segment: set ECT and inject CWR. */
if (skb->len != tcp_header_len &&
!before(TCP_SKB_CB(skb)->seq, tp->snd_nxt)) {
INET_ECN_xmit(sk);
...
} else if (!tcp_ca_needs_ecn(sk)) {
/* ACK or retransmitted segment: clear ECT|CE */
INET_ECN_dontxmit(sk);
}
Take a NEEDS_ECN|NEEDS_ACCECN CC that set the bit and then fell back to
RFC3168. Its pure ACKs and retransmits would keep the ECT(1) set at init
until the first new data segment switches the socket to ECT(0). The flow
would then send a mix of codepoints, not the single one the commit message
describes.
Could the commit message describe the actual scope of the bit?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130125658.20292-1-chia-yu.chang%40nokia-bell-labs.com