tcp: preserve receive-window accounting across ratio drift
Subsystems (10)
v2 cover tcp: preserve receive-window accounting across ratio drift
From: Wesley Atwell <[email protected]>
This series keeps sender-visible TCP receive-window accounting tied to the scaling basis that was in force when the window was advertised, even if later receive-side truesize inflation lowers scaling_ratio or the live receive window retracts below the largest right edge already exposed to the sender.
After the receive-window retraction changes, the receive path needs to keep track of two related pieces of sender-visible state:
1. the live advertised receive window
2. the maximum advertised right edge and the basis it was exposed with
This repost snapshots both, uses them to repair receive-buffer backing when ratio drift would otherwise strand sender-visible space, extends TCP_REPAIR_WINDOW so repair/restore can round-trip the new state, and adds truesize-drift coverage through TUN packetdrill tests and netdevsim-based selftests.
v2:
- repost to net-next and use the [PATCH net-next v2] prefix
- rebase the receive-window accounting changes on top of the retraction model
- split the series more finely
- snapshot both the live rwnd basis and the max advertised-window basis
- extend TCP_REPAIR_WINDOW to preserve legacy, v1, and current layouts
- add TUN RX truesize injection and packetdrill coverage for ratio drift
- split the generic netdevsim PSP extension cleanup into its own final patch after the peer RX truesize support
- add the requested ABI/runtime comments at the non-obvious review points
Testing:
- full runtime selftest coverage for netdevsim, tcp_ao, mptcp, and packetdrill; all runtime suites completed successfully
- tcp_ao completed 24/24 top-level tests, covering 803 passing checks, 6 expected failures, 36 skips, and 0 unexpected failures
- mptcp completed 588 passing checks in aggregate, with 28 skips and 0 unexpected failures
- packetdrill completed 219/219 runtime cases with 0 failures, including the new tests
- netdevsim completed 18/18 top-level runtime tests with 0 failures, including the peer RX truesize and related netdevsim coverage used by this series
Wesley Atwell (14):
tcp: factor receive-memory accounting helpers
tcp: snapshot advertise-time scaling for rcv_wnd
tcp: refresh rcv_wnd snapshots at TCP write sites
tcp: snapshot the maximum advertised receive window
tcp: grow rcvbuf to back scaled-window quantization slack
tcp: regrow rcvbuf when scaling_ratio drops after advertisement
tcp: honor the maximum advertised window after live retraction
tcp: extend TCP_REPAIR_WINDOW for live and max-window snapshots
mptcp: refresh TCP receive-window snapshots on subflows
tcp: expose rmem and backlog in tcp and mptcp rcvbuf_grow tracepoints
selftests: tcp_ao: cover legacy, v1, and retracted repair windows tun/selftests: add RX truesize injection for TCP window tests
netdevsim: add peer RX truesize support for selftests
netdevsim: release pinned PSP ext on drop paths
.../networking/net_cachelines/tcp_sock.rst | 2 + drivers/net/netdevsim/netdev.c | 156 ++++++- drivers/net/netdevsim/netdevsim.h | 4 + drivers/net/tun.c | 65 +++ include/linux/tcp.h | 2 + include/net/tcp.h | 118 ++++- include/trace/events/mptcp.h | 11 +- include/trace/events/tcp.h | 12 +- include/uapi/linux/if_tun.h | 4 + include/uapi/linux/tcp.h | 8 + net/ipv4/tcp.c | 75 ++- net/ipv4/tcp_fastopen.c | 2 +- net/ipv4/tcp_input.c | 160 ++++++- net/ipv4/tcp_minisocks.c | 4 +- net/ipv4/tcp_output.c | 25 +- net/mptcp/options.c | 14 +- net/mptcp/protocol.h | 14 +- .../selftests/drivers/net/netdevsim/Makefile | 1 + .../drivers/net/netdevsim/peer-rx-truesize.sh | 426 ++++++++++++++++++ .../tcp_rcv_neg_window_truesize.pkt | 143 ++++++ .../net/packetdrill/tcp_rcv_toobig.pkt | 35 ++ .../packetdrill/tcp_rcv_toobig_default.pkt | 97 ++++ .../tcp_rcv_toobig_default_truesize.pkt | 118 +++++ .../tcp_rcv_wnd_shrink_allowed_truesize.pkt | 49 ++ .../testing/selftests/net/tcp_ao/lib/aolib.h | 83 +++- .../testing/selftests/net/tcp_ao/lib/repair.c | 18 +- .../selftests/net/tcp_ao/self-connect.c | 201 ++++++++- tools/testing/selftests/net/tun.c | 140 +++++- 28 files changed, 1911 insertions(+), 76 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/netdevsim/peer-rx-truesize.sh create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window_truesize.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_toobig.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_toobig_default.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_toobig_default_truesize.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed_truesize.pkt
base-commit: f807b5b9b89eb9220d034115c272c312251cbcac
Signature · 1 line
2.43.0
PATCH v2 1/14 tcp: factor receive-memory accounting helpers
From: Wesley Atwell <[email protected]>
Factor the core receive-memory byte accounting into small helpers so window selection, pressure checks, and prune decisions all start from one set of quantities.
This is preparatory only. Later patches will use the same helpers when tying sender-visible receive-window state back to hard memory admission.
--- include/net/tcp.h | 32 +++++++++++++++++++++++++++----- net/ipv4/tcp_input.c | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-)
include/net/tcp.h +27 -5
@@ -1751,12 +1751,34 @@ static inline void tcp_scaling_ratio_init(struct sock *sk)tcp_sk (sk)->scaling_ratio =TCP_DEFAULT_SCALING_RATIO ; } +/* TCP receive-side accounting reuses sk_rcvbuf as both a hard memory limit +* and as the source material for the advertised receive window after +* scaling_ratio conversion. Keep the byte accounting explicit so admission, +* pruning, and rwnd selection all start from the same quantities. +*/ +static inline int tcp_rmem_used (const struct sock *sk) +{ +return atomic_read (&sk->sk_rmem_alloc); +} + +static inline int tcp_rmem_avail (const struct sock *sk) +{ +return READ_ONCE (sk->sk_rcvbuf) -tcp_rmem_used (sk); +} + +/* Sender-visible rwnd headroom also reserves bytes already queued on backlog. +* Those bytes are not free to advertise again until __release_sock() drains +* backlog and clears sk_backlog.len. +*/ +static inline int tcp_rwnd_avail (const struct sock *sk) +{ +return tcp_rmem_avail (sk) -READ_ONCE (sk->sk_backlog.len); +} +/* Note: caller must be prepared to deal with negative returns */ static inline int tcp_space (const struct sock *sk) { -return tcp_win_from_space (sk,READ_ONCE (sk->sk_rcvbuf) - -READ_ONCE (sk->sk_backlog.len) - -atomic_read (&sk->sk_rmem_alloc)); +return tcp_win_from_space (sk,tcp_rwnd_avail (sk)); }static inline int tcp_full_space (const struct sock *sk)
@@ -1799,7 +1821,7 @@ static inline bool tcp_rmem_pressure(const struct sock *sk) rcvbuf =READ_ONCE (sk->sk_rcvbuf); threshold = rcvbuf - (rcvbuf >>3 ); -return atomic_read (&sk->sk_rmem_alloc) > threshold; +return tcp_rmem_used (sk) > threshold; }static inline bool tcp_epollin_ready (const struct sock *sk,int target)
@@ -1949,7 +1971,7 @@ static inline void tcp_fast_path_check(struct sock *sk)if (RB_EMPTY_ROOT (&tp->out_of_order_queue) && tp->rcv_wnd && -atomic_read (&sk->sk_rmem_alloc) < sk->sk_rcvbuf && +tcp_rmem_avail (sk) >0 && !tp->urg_data)tcp_fast_path_on (tp); }
net/ipv4/tcp_input.c +1 -1
@@ -5959,7 +5959,7 @@ static int tcp_prune_queue(struct sock *sk, const struct sk_buff *in_skb)struct tcp_sock *tp =tcp_sk (sk);/* Do nothing if our queues are empty. */ -if (!atomic_read (&sk->sk_rmem_alloc)) +if (!tcp_rmem_used (sk))return -1 ;NET_INC_STATS (sock_net (sk),LINUX_MIB_PRUNECALLED );
Signature · 1 line
2.43.0
PATCH v2 2/14 tcp: snapshot advertise-time scaling for rcv_wnd
In reply to [email protected]From: Wesley Atwell <[email protected]>
Track the scaling basis that was in force when tp->rcv_wnd was last advertised, and provide helpers to refresh or interpret that snapshot.
Later patches use this live-window basis to preserve sender-visible rwnd accounting when receive-side memory costs drift after advertisement.
--- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 1 + include/net/tcp.h | 52 ++++++++++++++++++- net/ipv4/tcp.c | 1 + 4 files changed, 54 insertions(+), 1 deletion(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -0
@@ -11,6 +11,7 @@ Type Name fastpath_tx_access fastpa struct inet_connection_sock inet_conn u16 tcp_header_len read_mostly read_mostly tcp_bound_to_half_wnd,tcp_current_mss(tx);tcp_rcv_established(rx) u16 gso_segs read_mostly tcp_xmit_size_goal +u8 rcv_wnd_scaling_ratio read_write read_mostly tcp_set_rcv_wnd,tcp_can_ingest,tcp_repair_set_window,do_tcp_getsockopt __be32 pred_flags read_write read_mostly tcp_select_window(tx);tcp_rcv_established(rx) u64 bytes_received read_write tcp_rcv_nxt_update(rx) u32 segs_in read_write tcp_v6_rcv(rx)
include/linux/tcp.h +1 -0
@@ -297,6 +297,7 @@ struct tcp_sock { est_ecnfield:2,/* ECN field for AccECN delivered estimates */ accecn_opt_demand:2,/* Demand AccECN option for n next ACKs */ prev_ecnfield:2; /* ECN bits from the previous segment */ +u8 rcv_wnd_scaling_ratio;/* 0 if unknown, else tp->rcv_wnd basis */ __be32 pred_flags;u64 tcp_clock_cache;/* cache last tcp_clock_ns() (see tcp_mstamp_refresh()) */ u64 tcp_mstamp;/* most recent packet received/sent */
include/net/tcp.h +51 -1
64 lines not on this page · raw message
net/ipv4/tcp.c +1 -0
@@ -5275,6 +5275,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd_scaling_ratio); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_mwnd_seq); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_tstamp);
Signature · 1 line
2.43.0
PATCH v2 3/14 tcp: refresh rcv_wnd snapshots at TCP write sites
In reply to [email protected]From: Wesley Atwell <[email protected]>
Refresh the live rwnd snapshot whenever TCP updates tp->rcv_wnd at the normal write sites, including child setup, tcp_select_window(), and the initial connect-time window selection.
This keeps the live sender-visible window paired with the scaling basis that was actually advertised.
--- net/ipv4/tcp_minisocks.c | 2 +- net/ipv4/tcp_output.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)
net/ipv4/tcp_minisocks.c +1 -1
@@ -603,7 +603,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk, newtp->rx_opt.sack_ok = ireq->sack_ok; newtp->window_clamp = req->rsk_window_clamp; newtp->rcv_ssthresh = req->rsk_rcv_wnd; - newtp->rcv_wnd = req->rsk_rcv_wnd; +tcp_set_rcv_wnd (newtp, req->rsk_rcv_wnd); newtp->rcv_mwnd_seq = newtp->rcv_wup + req->rsk_rcv_wnd; newtp->rx_opt.wscale_ok = ireq->wscale_ok;if (newtp->rx_opt.wscale_ok) {
net/ipv4/tcp_output.c +6 -2
@@ -291,7 +291,7 @@ static u16 tcp_select_window(struct sock *sk)*/ if (unlikely (inet_csk (sk)->icsk_ack.pending &ICSK_ACK_NOMEM )) { tp->pred_flags =0 ; - tp->rcv_wnd =0 ; +tcp_set_rcv_wnd (tp,0 ); tp->rcv_wup = tp->rcv_nxt;tcp_update_max_rcv_wnd_seq (tp);return 0 ;
@@ -315,7 +315,7 @@ static u16 tcp_select_window(struct sock *sk) } } - tp->rcv_wnd = new_win; +tcp_set_rcv_wnd (tp, new_win); tp->rcv_wup = tp->rcv_nxt;tcp_update_max_rcv_wnd_seq (tp);
@@ -4148,6 +4148,10 @@ static void tcp_connect_init(struct sock *sk)READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_window_scaling), &rcv_wscale, rcv_wnd); +/* tcp_select_initial_window() filled tp->rcv_wnd through its out-param, +* so snapshot the scaling_ratio we will use for that initial rwnd. +*/ +tcp_set_rcv_wnd (tp, tp->rcv_wnd); tp->rx_opt.rcv_wscale = rcv_wscale; tp->rcv_ssthresh = tp->rcv_wnd;
Signature · 1 line
2.43.0
PATCH v2 4/14 tcp: snapshot the maximum advertised receive window
In reply to [email protected]From: Wesley Atwell <[email protected]>
Track the maximum sender-visible receive-window right edge separately from the live rwnd, along with the scaling basis that was in force when that larger window was advertised.
This gives later admission and restore paths enough information to reason about retracted windows without losing the original sender- visible bound.
--- .../networking/net_cachelines/tcp_sock.rst | 1 + include/linux/tcp.h | 1 + include/net/tcp.h | 21 ++++++++++++++++++- net/ipv4/tcp.c | 1 + net/ipv4/tcp_fastopen.c | 2 +- net/ipv4/tcp_input.c | 4 ++-- net/ipv4/tcp_minisocks.c | 2 +- net/ipv4/tcp_output.c | 2 +- 8 files changed, 28 insertions(+), 6 deletions(-)
Documentation/networking/net_cachelines/tcp_sock.rst +1 -0
@@ -11,6 +11,7 @@ Type Name fastpath_tx_access fastpa struct inet_connection_sock inet_conn u16 tcp_header_len read_mostly read_mostly tcp_bound_to_half_wnd,tcp_current_mss(tx);tcp_rcv_established(rx) u16 gso_segs read_mostly tcp_xmit_size_goal +u8 rcv_mwnd_scaling_ratio read_write read_mostly tcp_init_max_rcv_wnd_seq,tcp_update_max_rcv_wnd_seq,tcp_repair_set_window,do_tcp_getsockopt u8 rcv_wnd_scaling_ratio read_write read_mostly tcp_set_rcv_wnd,tcp_can_ingest,tcp_repair_set_window,do_tcp_getsockopt __be32 pred_flags read_write read_mostly tcp_select_window(tx);tcp_rcv_established(rx) u64 bytes_received read_write tcp_rcv_nxt_update(rx)
include/linux/tcp.h +1 -0
@@ -297,6 +297,7 @@ struct tcp_sock { est_ecnfield:2,/* ECN field for AccECN delivered estimates */ accecn_opt_demand:2,/* Demand AccECN option for n next ACKs */ prev_ecnfield:2; /* ECN bits from the previous segment */ +u8 rcv_mwnd_scaling_ratio;/* 0 if unknown, else tp->rcv_mwnd_seq basis */ u8 rcv_wnd_scaling_ratio;/* 0 if unknown, else tp->rcv_wnd basis */ __be32 pred_flags;u64 tcp_clock_cache;/* cache last tcp_clock_ns() (see tcp_mstamp_refresh()) */
include/net/tcp.h +20 -1
@@ -947,13 +947,21 @@ static inline u32 tcp_max_receive_window(const struct tcp_sock *tp)return (u32 ) win; } +static inline void tcp_init_max_rcv_wnd_seq (struct tcp_sock *tp) +{ + tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd; + tp->rcv_mwnd_scaling_ratio = tp->rcv_wnd_scaling_ratio; +} +/* Check if we need to update the maximum receive window sequence number */ static inline void tcp_update_max_rcv_wnd_seq (struct tcp_sock *tp) {u32 wre = tp->rcv_wup + tp->rcv_wnd; -if (after (wre, tp->rcv_mwnd_seq)) +if (after (wre, tp->rcv_mwnd_seq)) { tp->rcv_mwnd_seq = wre; + tp->rcv_mwnd_scaling_ratio = tp->rcv_wnd_scaling_ratio; + } }/* Choose a new window, without checks for shrinking, and without
@@ -1766,6 +1774,16 @@ static inline bool tcp_space_from_rcv_wnd(const struct tcp_sock *tp, int win, space); } +/* Same as tcp_space_from_rcv_wnd(), but for the remembered maximum +* sender-visible receive window. +*/ +static inline bool tcp_space_from_rcv_mwnd (const struct tcp_sock *tp,int win, +int *space) +{ +return tcp_space_from_wnd_snapshot (tp->rcv_mwnd_scaling_ratio, win, + space); +} +/* Assume a 50% default for skb->len/skb->truesize ratio. * This may be adjusted later in tcp_measure_rcv_mss(). */
@@ -1776,6 +1794,7 @@ static inline void tcp_scaling_ratio_init(struct sock *sk)struct tcp_sock *tp =tcp_sk (sk); tp->scaling_ratio =TCP_DEFAULT_SCALING_RATIO ; + tp->rcv_mwnd_scaling_ratio =TCP_DEFAULT_SCALING_RATIO ; tp->rcv_wnd_scaling_ratio =TCP_DEFAULT_SCALING_RATIO ; }
net/ipv4/tcp.c +1 -0
@@ -5275,6 +5275,7 @@ static void __init tcp_struct_check(void) CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ce); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, received_ecn_bytes); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, app_limited); + CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_mwnd_scaling_ratio); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd_scaling_ratio); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_wnd); CACHELINE_ASSERT_GROUP_MEMBER(struct tcp_sock, tcp_sock_write_txrx, rcv_mwnd_seq);
net/ipv4/tcp_fastopen.c +1 -1
@@ -377,7 +377,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,tcp_rsk (req)->rcv_nxt = tp->rcv_nxt; tp->rcv_wup = tp->rcv_nxt; - tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd; +tcp_init_max_rcv_wnd_seq (tp);/* tcp_conn_request() is sending the SYNACK, * and queues the child into listener accept queue. */
net/ipv4/tcp_input.c +2 -2
@@ -6902,7 +6902,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,*/ WRITE_ONCE (tp->rcv_nxt,TCP_SKB_CB (skb)->seq +1 ); tp->rcv_wup =TCP_SKB_CB (skb)->seq +1 ; - tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd; +tcp_init_max_rcv_wnd_seq (tp);/* RFC1323: The window in SYN & SYN/ACK segments is * never scaled.
@@ -7015,7 +7015,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,WRITE_ONCE (tp->rcv_nxt,TCP_SKB_CB (skb)->seq +1 );WRITE_ONCE (tp->copied_seq, tp->rcv_nxt); tp->rcv_wup =TCP_SKB_CB (skb)->seq +1 ; - tp->rcv_mwnd_seq = tp->rcv_wup + tp->rcv_wnd; +tcp_init_max_rcv_wnd_seq (tp);/* RFC1323: The window in SYN & SYN/ACK segments is * never scaled.
net/ipv4/tcp_minisocks.c +1 -1
@@ -604,7 +604,7 @@ struct sock *tcp_create_openreq_child(const struct sock *sk, newtp->window_clamp = req->rsk_window_clamp; newtp->rcv_ssthresh = req->rsk_rcv_wnd;tcp_set_rcv_wnd (newtp, req->rsk_rcv_wnd); - newtp->rcv_mwnd_seq = newtp->rcv_wup + req->rsk_rcv_wnd; +tcp_init_max_rcv_wnd_seq (newtp); newtp->rx_opt.wscale_ok = ireq->wscale_ok;if (newtp->rx_opt.wscale_ok) { newtp->rx_opt.snd_wscale = ireq->snd_wscale;
net/ipv4/tcp_output.c +1 -1
@@ -4171,7 +4171,7 @@ static void tcp_connect_init(struct sock *sk)else tp->rcv_tstamp = tcp_jiffies32; tp->rcv_wup = tp->rcv_nxt; - tp->rcv_mwnd_seq = tp->rcv_nxt + tp->rcv_wnd; +tcp_init_max_rcv_wnd_seq (tp);WRITE_ONCE (tp->copied_seq, tp->rcv_nxt);inet_csk (sk)->icsk_rto =tcp_timeout_init (sk);
Signature · 1 line
2.43.0
PATCH v2 5/14 tcp: grow rcvbuf to back scaled-window quantization slack
In reply to [email protected]From: Wesley Atwell <[email protected]>
Teach TCP to grow sk_rcvbuf when scale rounding would otherwise expose more sender-visible window than the current hard receive-memory backing can cover.
The new helper keeps backlog and memory-pressure limits in the same units as the rest of the receive path, while __tcp_select_window() backs any rounding slack before advertising it.
--- include/net/tcp.h | 12 ++++++++++++ net/ipv4/tcp_input.c | 36 ++++++++++++++++++++++++++++++++++-- net/ipv4/tcp_output.c | 15 +++++++++++++-- 3 files changed, 59 insertions(+), 4 deletions(-)
include/net/tcp.h +12 -0
@@ -397,6 +397,7 @@ int tcp_ioctl(struct sock *sk, int cmd, int *karg);enum skb_drop_reason tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb);void tcp_rcv_established (struct sock *sk,struct sk_buff *skb);void tcp_rcvbuf_grow (struct sock *sk,u32 newval); +bool tcp_try_grow_rcvbuf (struct sock *sk,int needed);void tcp_rcv_space_adjust (struct sock *sk);int tcp_twsk_unique (struct sock *sk,struct sock *sktw,void *twp);void tcp_twsk_destructor (struct sock *sk);
@@ -1844,6 +1845,17 @@ static inline int tcp_rwnd_avail(const struct sock *sk)return tcp_rmem_avail (sk) -READ_ONCE (sk->sk_backlog.len); } +/* Passive children clone the listener's sk_socket until accept() grafts +* their own struct socket, so only sockets that point back to themselves +* should autotune receive-buffer backing. +*/ +static inline bool tcp_rcvbuf_grow_allowed (const struct sock *sk) +{ +struct socket *sock =READ_ONCE (sk->sk_socket); + +return sock &&READ_ONCE (sock->sk) == sk; +} +/* Note: caller must be prepared to deal with negative returns */ static inline int tcp_space (const struct sock *sk) {
net/ipv4/tcp_input.c +34 -2
@@ -774,6 +774,38 @@ static void tcp_init_buffer_space(struct sock *sk) (u32)TCP_INIT_CWND * tp->advmss); } +/* Try to grow sk_rcvbuf so the hard receive-memory limit covers @needed +* bytes beyond sk_rmem_alloc while preserving sender-visible headroom +* already consumed by sk_backlog.len. +*/ +bool tcp_try_grow_rcvbuf (struct sock *sk,int needed) +{ +struct net *net =sock_net (sk); +int backlog; +int rmem2; +int target; + + needed =max (needed,0 ); + backlog =READ_ONCE (sk->sk_backlog.len); + target =tcp_rmem_used (sk) + backlog + needed; + +if (target <=READ_ONCE (sk->sk_rcvbuf)) +return true; + + rmem2 =READ_ONCE (net->ipv4.sysctl_tcp_rmem[2 ]); +if (READ_ONCE (sk->sk_rcvbuf) >= rmem2 || + (sk->sk_userlocks &SOCK_RCVBUF_LOCK ) || +tcp_under_memory_pressure (sk) || +sk_memory_allocated (sk) >=sk_prot_mem_limits (sk,0 )) +return false; + +WRITE_ONCE (sk->sk_rcvbuf, +min_t (int, rmem2, +max_t (int,READ_ONCE (sk->sk_rcvbuf), target))); + +return target <=READ_ONCE (sk->sk_rcvbuf); +} +/* 4. Recalculate window clamp after socket hit its memory bounds. */ static void tcp_clamp_window (struct sock *sk) {
@@ -785,14 +817,14 @@ static void tcp_clamp_window(struct sock *sk) icsk->icsk_ack.quick =0 ; rmem2 =READ_ONCE (net->ipv4.sysctl_tcp_rmem[2 ]); -if (sk->sk_rcvbuf < rmem2 && +if (READ_ONCE (sk->sk_rcvbuf) < rmem2 && !(sk->sk_userlocks &SOCK_RCVBUF_LOCK ) && !tcp_under_memory_pressure (sk) &&sk_memory_allocated (sk) <sk_prot_mem_limits (sk,0 )) {WRITE_ONCE (sk->sk_rcvbuf,min (atomic_read (&sk->sk_rmem_alloc), rmem2)); } -if (atomic_read (&sk->sk_rmem_alloc) > sk->sk_rcvbuf) +if (atomic_read (&sk->sk_rmem_alloc) >READ_ONCE (sk->sk_rcvbuf)) tp->rcv_ssthresh =min (tp->window_clamp,2U * tp->advmss); }
net/ipv4/tcp_output.c +13 -2
@@ -3375,13 +3375,24 @@ u32 __tcp_select_window(struct sock *sk)* scaled window will not line up with the MSS boundary anyway. */ if (tp->rx_opt.rcv_wscale) { +int rcv_wscale =1 << tp->rx_opt.rcv_wscale; + window = free_space;/* Advertise enough space so that it won't get scaled away. -* Import case: prevent zero window announcement if +* Important case: prevent zero-window announcement if * 1<<rcv_wscale > mss. */ - window =ALIGN (window, (1 << tp->rx_opt.rcv_wscale)); + window =ALIGN (window, rcv_wscale); + +/* Back any scale-quantization slack before we expose it. +* Otherwise tcp_can_ingest() can reject data which is still +* within the sender-visible window. +*/ +if (window > free_space && + (!tcp_rcvbuf_grow_allowed (sk) || + !tcp_try_grow_rcvbuf (sk,tcp_space_from_win (sk, window)))) + window =round_down (free_space, rcv_wscale); }else { window = tp->rcv_wnd;/* Get the largest window that is a nice multiple of mss.
Signature · 1 line
2.43.0
PATCH v2 6/14 tcp: regrow rcvbuf when scaling_ratio drops after advertisement
In reply to [email protected]From: Wesley Atwell <[email protected]>
When tcp_measure_rcv_mss() lowers scaling_ratio after a window was already advertised, grow sk_rcvbuf so the remaining live sender-visible window still has matching hard receive-memory backing.
This repairs the live advertised window only. Retracted-window rescue is handled separately in a later patch.
--- net/ipv4/tcp_input.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
net/ipv4/tcp_input.c +26 -0
@@ -221,6 +221,31 @@ static __cold void tcp_gro_dev_warn(const struct sock *sk, const struct sk_buffrcu_read_unlock (); } +/* If scaling_ratio drops after we already advertised tp->rcv_wnd, grow +* sk_rcvbuf so the remaining live window still maps back to hard memory +* units under the old advertise-time basis. +*/ +static void tcp_try_grow_advertised_window (struct sock *sk, +const struct sk_buff *skb) +{ +struct tcp_sock *tp =tcp_sk (sk); +int needed; + +/* Keep this repair aligned with tcp_rcvbuf_grow(): do not adjust +* receive-buffer backing for not-yet-accepted or orphaned sockets. +*/ +if (!tcp_rcvbuf_grow_allowed (sk)) +return ; + +if (!tcp_receive_window (tp)) +return ; + +if (!tcp_space_from_rcv_wnd (tp,tcp_receive_window (tp), &needed)) +return ; + +tcp_try_grow_rcvbuf (sk, needed); +} +/* Adapt the MSS value used to make delayed ack decision to the * real world. */
@@ -251,6 +276,7 @@ static void tcp_measure_rcv_mss(struct sock *sk, const struct sk_buff *skb)if (old_ratio !=tcp_sk (sk)->scaling_ratio) {struct tcp_sock *tp =tcp_sk (sk); +tcp_try_grow_advertised_window (sk, skb); val =tcp_win_from_space (sk, sk->sk_rcvbuf);tcp_set_window_clamp (sk, val);
Signature · 1 line
2.43.0
PATCH v2 7/14 tcp: honor the maximum advertised window after live retraction
In reply to [email protected]From: Wesley Atwell <[email protected]>
If receive-side accounting retracts the live rwnd below a larger sender-visible window that was already advertised, allow one in-order skb within that historical bound to repair its backing and reach the normal receive path.
Hard receive-memory admission is still enforced through the existing prune and collapse path. The rescue only changes how data already inside sender-visible sequence space is classified and backed.
--- net/ipv4/tcp_input.c | 92 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 6 deletions(-)
net/ipv4/tcp_input.c +86 -6
@@ -5376,24 +5376,86 @@ static void tcp_ofo_queue(struct sock *sk)static bool tcp_prune_ofo_queue (struct sock *sk,const struct sk_buff *in_skb);static int tcp_prune_queue (struct sock *sk,const struct sk_buff *in_skb); +/* Sequence checks run against the sender-visible receive window before this +* point. If later receive-side accounting retracts the live receive window +* below the maximum right edge we already advertised, allow one in-order skb +* which still fits inside that sender-visible bound to reach the normal +* receive queue path. +* +* Keep receive-memory admission itself on the legacy hard-cap path so prune +* and collapse behavior stay aligned with the established retracted-window +* handling. +*/ +static bool tcp_skb_in_retracted_window (const struct tcp_sock *tp, +const struct sk_buff *skb) +{ +u32 live_end = tp->rcv_nxt +tcp_receive_window (tp); +u32 max_end = tp->rcv_nxt +tcp_max_receive_window (tp); + +return after (max_end, live_end) && +after (TCP_SKB_CB (skb)->end_seq, live_end) && + !after (TCP_SKB_CB (skb)->end_seq, max_end); +} +static bool tcp_can_ingest (const struct sock *sk,const struct sk_buff *skb) { -unsigned int rmem =atomic_read (&sk->sk_rmem_alloc); +return tcp_rmem_used (sk) <=READ_ONCE (sk->sk_rcvbuf); +} + +/* Caller already established that @skb extends into the retracted-but-still- +* valid sender-visible window. For in-order progress, regrow sk_rcvbuf before +* falling into prune/forced-mem handling. +* +* This path intentionally repairs backing for one in-order skb that is already +* within sender-visible sequence space, rather than treating it like ordinary +* receive-buffer autotuning. +* +* Keep this rescue bounded to the span accepted by this skb instead of the +* full historical tp->rcv_mwnd_seq. However, never grow below skb->truesize, +* because sk_rmem_schedule() still charges hard memory, not sender-visible +* window bytes. +*/ +static void tcp_try_grow_retracted_skb (struct sock *sk, +const struct sk_buff *skb) +{ +struct tcp_sock *tp =tcp_sk (sk); +int needed = skb->truesize; +int span_space; +u32 span_win; + +if (TCP_SKB_CB (skb)->seq != tp->rcv_nxt) +return ; + + span_win =TCP_SKB_CB (skb)->end_seq - tp->rcv_nxt; +if (TCP_SKB_CB (skb)->tcp_flags &TCPHDR_FIN ) + span_win--; + +if (tcp_space_from_rcv_mwnd (tp, span_win, &span_space)) + needed =max_t (int, needed, span_space); -return rmem <= sk->sk_rcvbuf; +tcp_try_grow_rcvbuf (sk, needed); } +/* Sender-visible window rescue does not relax hard receive-memory admission. +* If growth did not make room, fall back to the established prune/collapse +* path. +*/ static int tcp_try_rmem_schedule (struct sock *sk,const struct sk_buff *skb,unsigned int size) { -if (!tcp_can_ingest (sk, skb) || - !sk_rmem_schedule (sk, skb, size)) { +bool can_ingest =tcp_can_ingest (sk, skb); +bool scheduled = can_ingest &&sk_rmem_schedule (sk, skb, size); + +if (!scheduled) { +int pruned =tcp_prune_queue (sk, skb); -if (tcp_prune_queue (sk, skb) <0 ) +if (pruned <0 )return -1 ;while (!sk_rmem_schedule (sk, skb, size)) { -if (!tcp_prune_ofo_queue (sk, skb)) +bool pruned_ofo =tcp_prune_ofo_queue (sk, skb); + +if (!pruned_ofo)return -1 ; } }
@@ -5629,6 +5691,7 @@ void tcp_data_ready(struct sock *sk)static void tcp_data_queue (struct sock *sk,struct sk_buff *skb) {struct tcp_sock *tp =tcp_sk (sk); +bool retracted;enum skb_drop_reason reason;bool fragstolen;int eaten;
@@ -5647,6 +5710,7 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) }tcp_cleanup_skb (skb);__skb_pull (skb,tcp_hdr (skb)->doff *4 ); + retracted = skb->len &&tcp_skb_in_retracted_window (tp, skb); reason =SKB_DROP_REASON_NOT_SPECIFIED ; tp->rx_opt.dsack =0 ;
@@ -5667,6 +5731,9 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb) (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)) goto queue_and_out; +if (retracted) + goto queue_and_out; + reason =SKB_DROP_REASON_TCP_ZEROWINDOW ;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPZEROWINDOWDROP ); goto out_of_window;
@@ -5674,7 +5741,20 @@ static void tcp_data_queue(struct sock *sk, struct sk_buff *skb)/* Ok. In sequence. In window. */ queue_and_out: +if (unlikely (retracted)) +tcp_try_grow_retracted_skb (sk, skb); +if (tcp_try_rmem_schedule (sk, skb, skb->truesize)) { +/* If the live rwnd collapsed to zero while rescuing an +* skb that still fit in sender-visible sequence space, +* report zero-window rather than generic proto-mem. +*/ +if (unlikely (!tcp_receive_window (tp) && retracted)) { + reason =SKB_DROP_REASON_TCP_ZEROWINDOW ; +NET_INC_STATS (sock_net (sk), +LINUX_MIB_TCPZEROWINDOWDROP ); + goto out_of_window; + }/* TODO: maybe ratelimit these WIN 0 ACK ? */ inet_csk (sk)->icsk_ack.pending |= (ICSK_ACK_NOMEM |ICSK_ACK_NOW );
Signature · 1 line
2.43.0
PATCH v2 8/14 tcp: extend TCP_REPAIR_WINDOW for live and max-window snapshots
In reply to [email protected]From: Wesley Atwell <[email protected]>
Extend TCP_REPAIR_WINDOW so repair and restore can round-trip both the live rwnd snapshot and the remembered maximum sender-visible window.
Keep the ABI append-only by accepting the legacy and v1 prefix lengths on both get and set, rebuilding any missing max-window state from the live window when older userspace restores a socket.
--- include/net/tcp.h | 13 +++---- include/uapi/linux/tcp.h | 8 +++++ net/ipv4/tcp.c | 73 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 13 deletions(-)
include/net/tcp.h +7 -6
@@ -1766,13 +1766,14 @@ static inline bool tcp_space_from_wnd_snapshot(u8 scaling_ratio, int win, }/* Rebuild hard receive-memory units for data already covered by tp->rcv_wnd if -* the advertise-time basis is known. +* the advertise-time basis is known. Legacy TCP_REPAIR restores can only +* recover tp->rcv_wnd itself; callers must fall back when the snapshot is +* unknown. */ static inline bool tcp_space_from_rcv_wnd (const struct tcp_sock *tp,int win,int *space) { -return tcp_space_from_wnd_snapshot (tp->rcv_wnd_scaling_ratio, win, - space); +return tcp_space_from_wnd_snapshot (tp->rcv_wnd_scaling_ratio, win, space); }/* Same as tcp_space_from_rcv_wnd(), but for the remembered maximum
@@ -1800,9 +1801,9 @@ static inline void tcp_scaling_ratio_init(struct sock *sk) }/* tp->rcv_wnd is paired with the scaling_ratio that was in force when that -* window was last advertised. Callers can leave a zero snapshot when the -* advertise-time basis is unknown and refresh the pair on the next local -* window update. +* window was last advertised. Legacy TCP_REPAIR restores can only recover the +* window value itself and use a zero snapshot until a fresh local window +* advertisement refreshes the pair. */ static inline void tcp_set_rcv_wnd_snapshot (struct tcp_sock *tp,u32 win,u8 scaling_ratio)
include/uapi/linux/tcp.h +8 -0
@@ -152,6 +152,11 @@ struct tcp_repair_opt {__u32 opt_val; }; +/* Append-only repair ABI. +* Older userspace may stop at rcv_wup or rcv_wnd_scaling_ratio. +* The kernel accepts those prefix lengths and rebuilds any missing +* receive-window snapshot state on restore. +*/ struct tcp_repair_window {__u32 snd_wl1;__u32 snd_wnd;
@@ -159,6 +164,9 @@ struct tcp_repair_window {__u32 rcv_wnd;__u32 rcv_wup; +__u32 rcv_wnd_scaling_ratio;/* 0 means live-window basis unknown */ +__u32 rcv_mwnd_seq; +__u32 rcv_mwnd_scaling_ratio;/* 0 means max-window basis unknown */ };enum {
net/ipv4/tcp.c +66 -7
110 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 9/14 mptcp: refresh TCP receive-window snapshots on subflows
In reply to [email protected]From: Wesley Atwell <[email protected]>
When MPTCP resynchronizes the per-subflow TCP shadow window from the mptcp-level receive state, refresh the live rwnd snapshot and the remembered maximum-window snapshot along with it.
That keeps subflow TCP bookkeeping aligned with the sender-visible window state tracked in the core TCP patches.
--- net/mptcp/options.c | 14 +++++++++----- net/mptcp/protocol.h | 14 +++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-)
net/mptcp/options.c +9 -5
@@ -1073,9 +1073,12 @@ static void rwin_update(struct mptcp_sock *msk, struct sock *ssk,return ;/* Some other subflow grew the mptcp-level rwin since rcv_wup, -* resync. +* resync. Keep the TCP shadow window in its advertised u32 domain +* and refresh the advertise-time scaling snapshot while doing so. */ - tp->rcv_wnd += mptcp_rcv_wnd - subflow->rcv_wnd_sent; +tcp_set_rcv_wnd (tp,min_t (u64, (u64 )tp->rcv_wnd + + (mptcp_rcv_wnd - subflow->rcv_wnd_sent), +U32_MAX ));tcp_update_max_rcv_wnd_seq (tp); subflow->rcv_wnd_sent = mptcp_rcv_wnd; }
@@ -1335,12 +1338,13 @@ static void mptcp_set_rwin(struct tcp_sock *tp, struct tcphdr *th)if (rcv_wnd_new != rcv_wnd_old) { raise_win:/* The msk-level rcv wnd is after the tcp level one, -* sync the latter. +* sync the latter and refresh its advertise-time scaling +* snapshot. */ rcv_wnd_new = rcv_wnd_old; win = rcv_wnd_old - ack_seq; - new_win =min_t (u64, win,U32_MAX ); - tp->rcv_wnd = new_win; +tcp_set_rcv_wnd (tp,min_t (u64, win,U32_MAX )); + new_win = tp->rcv_wnd;tcp_update_max_rcv_wnd_seq (tp);/* Make sure we do not exceed the maximum possible
net/mptcp/protocol.h +11 -3
@@ -408,11 +408,19 @@ static inline int mptcp_space_from_win(const struct sock *sk, int win)return __tcp_space_from_win (mptcp_sk (sk)->scaling_ratio, win); } +/* MPTCP exposes window space from the mptcp-level receive queue, so it tracks +* a separate backlog counter from the subflow backlog embedded in struct sock. +*/ +static inline int mptcp_rwnd_avail (const struct sock *sk) +{ +return READ_ONCE (sk->sk_rcvbuf) - +READ_ONCE (mptcp_sk (sk)->backlog_len) - +tcp_rmem_used (sk); +} +static inline int __mptcp_space (const struct sock *sk) { -return mptcp_win_from_space (sk,READ_ONCE (sk->sk_rcvbuf) - -READ_ONCE (mptcp_sk (sk)->backlog_len) - -sk_rmem_alloc_get (sk)); +return mptcp_win_from_space (sk,mptcp_rwnd_avail (sk)); }static inline struct mptcp_data_frag *mptcp_send_head (const struct sock *sk)
Signature · 1 line
2.43.0
PATCH v2 10/14 tcp: expose rmem and backlog in tcp and mptcp rcvbuf_grow tracepoints
In reply to [email protected]From: Wesley Atwell <[email protected]>
Extend the tcp_rcvbuf_grow and mptcp_rcvbuf_grow tracepoints with the live receive-memory allocation and backlog occupancy that now drive the window-growth decisions in this series.
That makes it easier to inspect sender-visible rwnd state against the actual hard receive-memory inputs.
--- include/trace/events/mptcp.h | 11 +++++++---- include/trace/events/tcp.h | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-)
include/trace/events/mptcp.h +7 -4
@@ -199,6 +199,8 @@ TRACE_EVENT(mptcp_rcvbuf_grow, __field(__u32, inq) __field(__u32, space) __field(__u32, ooo_space) + __field(__u32, rmem_alloc) + __field(__u32, backlog_len) __field(__u32, rcvbuf) __field(__u32, rcv_wnd)__field (__u8, scaling_ratio)
@@ -228,6 +230,8 @@ TRACE_EVENT(mptcp_rcvbuf_grow,MPTCP_SKB_CB (msk->ooo_last_skb)->end_seq - msk->ack_seq; + __entry->rmem_alloc =tcp_rmem_used (sk); + __entry->backlog_len =READ_ONCE (msk->backlog_len); __entry->rcvbuf = sk->sk_rcvbuf; __entry->rcv_wnd =atomic64_read (&msk->rcv_wnd_sent) - msk->ack_seq;
@@ -248,12 +252,11 @@ TRACE_EVENT(mptcp_rcvbuf_grow, __entry->skaddr = sk; ), -TP_printk ("time=%u rtt_us=%u copied=%u inq=%u space=%u ooo=%u scaling_ratio=%u " -"rcvbuf=%u rcv_wnd=%u family=%d sport=%hu dport=%hu saddr=%pI4 " -"daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c skaddr=%p" , +TP_printk ("time=%u rtt_us=%u copied=%u inq=%u space=%u ooo=%u scaling_ratio=%u rmem_alloc=%u backlog_len=%u rcvbuf=%u rcv_wnd=%u family=%d sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c skaddr=%p" , __entry->time, __entry->rtt_us, __entry->copied, __entry->inq, __entry->space, __entry->ooo_space, - __entry->scaling_ratio, __entry->rcvbuf, __entry->rcv_wnd, + __entry->scaling_ratio, __entry->rmem_alloc, + __entry->backlog_len, __entry->rcvbuf, __entry->rcv_wnd, __entry->family, __entry->sport, __entry->dport, __entry->saddr, __entry->daddr, __entry->saddr_v6, __entry->daddr_v6, __entry->skaddr)
include/trace/events/tcp.h +7 -5
@@ -217,6 +217,8 @@ TRACE_EVENT(tcp_rcvbuf_grow, __field(__u32, inq) __field(__u32, space) __field(__u32, ooo_space) + __field(__u32, rmem_alloc) + __field(__u32, backlog_len) __field(__u32, rcvbuf) __field(__u32, rcv_ssthresh)__field (__u32, window_clamp)
@@ -247,6 +249,8 @@ TRACE_EVENT(tcp_rcvbuf_grow,TCP_SKB_CB (tp->ooo_last_skb)->end_seq - tp->rcv_nxt; + __entry->rmem_alloc =tcp_rmem_used (sk); + __entry->backlog_len =READ_ONCE (sk->sk_backlog.len); __entry->rcvbuf = sk->sk_rcvbuf; __entry->rcv_ssthresh = tp->rcv_ssthresh; __entry->window_clamp = tp->window_clamp;
@@ -269,13 +273,11 @@ TRACE_EVENT(tcp_rcvbuf_grow, __entry->sock_cookie =sock_gen_cookie (sk); ), - TP_printk("time=%u rtt_us=%u copied=%u inq=%u space=%u ooo=%u scaling_ratio=%u rcvbuf=%u " - "rcv_ssthresh=%u window_clamp=%u rcv_wnd=%u " - "family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 " - "saddrv6=%pI6c daddrv6=%pI6c skaddr=%p sock_cookie=%llx", + TP_printk("time=%u rtt_us=%u copied=%u inq=%u space=%u ooo=%u scaling_ratio=%u rmem_alloc=%u backlog_len=%u rcvbuf=%u rcv_ssthresh=%u window_clamp=%u rcv_wnd=%u family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c skaddr=%p sock_cookie=%llx", __entry->time, __entry->rtt_us, __entry->copied, __entry->inq, __entry->space, __entry->ooo_space, - __entry->scaling_ratio, __entry->rcvbuf, + __entry->scaling_ratio, __entry->rmem_alloc, + __entry->backlog_len, __entry->rcvbuf, __entry->rcv_ssthresh, __entry->window_clamp, __entry->rcv_wnd, show_family_name(__entry->family),
Signature · 1 line
2.43.0
PATCH v2 11/14 selftests: tcp_ao: cover legacy, v1, and retracted repair windows
In reply to [email protected]From: Wesley Atwell <[email protected]>
Extend the tcp_ao repair selftests to exercise the legacy, v1, and current TCP_REPAIR_WINDOW layouts, plus a synthesized retracted-window image that preserves a larger historical right edge.
These tests validate both the append-only ABI contract and the restore- time rebuilding of any snapshot state older userspace could not save.
--- .../testing/selftests/net/tcp_ao/lib/aolib.h | 83 +++++++- .../testing/selftests/net/tcp_ao/lib/repair.c | 18 +- .../selftests/net/tcp_ao/self-connect.c | 201 +++++++++++++++++- 3 files changed, 279 insertions(+), 23 deletions(-)
tools/testing/selftests/net/tcp_ao/lib/aolib.h +76 -7
@@ -13,6 +13,7 @@#include <linux/snmp.h> #include <linux/tcp.h> #include <netinet/in.h> +#include <stddef.h> #include <stdarg.h> #include <stdbool.h> #include <stdlib.h>
@@ -671,17 +672,55 @@ struct tcp_sock_state {int timestamp; }; -extern void __test_sock_checkpoint (int sk,struct tcp_sock_state *state, -void *addr,size_t addr_size); +/* Legacy userspace stops before the snapshot field and therefore exercises +* the kernel's unknown-snapshot fallback path. +*/ +static inline socklen_t test_tcp_repair_window_legacy_size (void ) +{ +return offsetof(struct tcp_repair_window , rcv_wnd_scaling_ratio); +} + +static inline socklen_t test_tcp_repair_window_v1_size (void ) +{ +return offsetof(struct tcp_repair_window , rcv_mwnd_seq); +} + +static inline socklen_t test_tcp_repair_window_exact_size (void ) +{ +return sizeof (struct tcp_repair_window ); +} + +void __test_sock_checkpoint_opt (int sk,struct tcp_sock_state *state, +socklen_t trw_len, +void *addr,size_t addr_size);static inline void test_sock_checkpoint (int sk,struct tcp_sock_state *state,sockaddr_af *saddr) { -__test_sock_checkpoint (sk, state, saddr,sizeof (*saddr)); +__test_sock_checkpoint_opt (sk, state,test_tcp_repair_window_exact_size (), + saddr,sizeof (*saddr)); +} + +static inline void test_sock_checkpoint_legacy (int sk, +struct tcp_sock_state *state, +sockaddr_af *saddr) +{ +__test_sock_checkpoint_opt (sk, state,test_tcp_repair_window_legacy_size (), + saddr,sizeof (*saddr)); +} + +static inline void test_sock_checkpoint_v1 (int sk, +struct tcp_sock_state *state, +sockaddr_af *saddr) +{ +__test_sock_checkpoint_opt (sk, state,test_tcp_repair_window_v1_size (), + saddr,sizeof (*saddr)); }extern void test_ao_checkpoint (int sk,struct tcp_ao_repair *state); -extern void __test_sock_restore (int sk,const char *device, -struct tcp_sock_state *state, -void *saddr,void *daddr,size_t addr_size); +void __test_sock_restore_opt (int sk,const char *device, +struct tcp_sock_state *state, +socklen_t trw_len, +void *saddr,void *daddr, +size_t addr_size); static inline void test_sock_restore(int sk, struct tcp_sock_state *state, sockaddr_af *saddr, const union tcp_addr daddr,
@@ -690,7 +729,37 @@ static inline void test_sock_restore(int sk, struct tcp_sock_state *state,sockaddr_af addr;tcp_addr_to_sockaddr_in (&addr, &daddr,htons (dport)); -__test_sock_restore (sk, veth_name, state, saddr, &addr,sizeof (addr)); +__test_sock_restore_opt (sk, veth_name, state, +test_tcp_repair_window_exact_size (), + saddr, &addr,sizeof (addr)); +} + +static inline void test_sock_restore_legacy (int sk, +struct tcp_sock_state *state, +sockaddr_af *saddr, +const union tcp_addr daddr, +unsigned int dport) +{ +sockaddr_af addr; + +tcp_addr_to_sockaddr_in (&addr, &daddr,htons (dport)); +__test_sock_restore_opt (sk, veth_name, state, +test_tcp_repair_window_legacy_size (), + saddr, &addr,sizeof (addr)); +} + +static inline void test_sock_restore_v1 (int sk, +struct tcp_sock_state *state, +sockaddr_af *saddr, +const union tcp_addr daddr, +unsigned int dport) +{ +sockaddr_af addr; + +tcp_addr_to_sockaddr_in (&addr, &daddr,htons (dport)); +__test_sock_restore_opt (sk, veth_name, state, +test_tcp_repair_window_v1_size (), + saddr, &addr,sizeof (addr)); }extern void test_ao_restore (int sk,struct tcp_ao_repair *state);extern void test_sock_state_free (struct tcp_sock_state *state);
tools/testing/selftests/net/tcp_ao/lib/repair.c +10 -8
@@ -66,8 +66,9 @@ static void test_sock_checkpoint_queue(int sk, int queue, int qlen,test_error ("recv(%d): %d" , qlen, ret); } -void __test_sock_checkpoint (int sk,struct tcp_sock_state *state, -void *addr,size_t addr_size) +void __test_sock_checkpoint_opt (int sk,struct tcp_sock_state *state, +socklen_t trw_len, +void *addr,size_t addr_size) {socklen_t len =sizeof (state->info);int ret;
@@ -82,9 +83,9 @@ void __test_sock_checkpoint(int sk, struct tcp_sock_state *state,if (getsockname (sk, addr, &len) || len != addr_size)test_error ("getsockname(): %d" , (int )len); - len =sizeof (state->trw); + len = trw_len; ret =getsockopt (sk,SOL_TCP ,TCP_REPAIR_WINDOW , &state->trw, &len); -if (ret || len !=sizeof (state->trw)) +if (ret || len != trw_len)test_error ("getsockopt(TCP_REPAIR_WINDOW): %d" , (int )len);if (ioctl (sk,SIOCOUTQ , &state->outq_len))
@@ -160,9 +161,10 @@ static void test_sock_restore_queue(int sk, int queue, void *buf, int len) }while (len >0 ); } -void __test_sock_restore (int sk,const char *device, -struct tcp_sock_state *state, -void *saddr,void *daddr,size_t addr_size) +void __test_sock_restore_opt (int sk,const char *device, +struct tcp_sock_state *state, +socklen_t trw_len, +void *saddr,void *daddr,size_t addr_size) {struct tcp_repair_opt opts[4 ];unsigned int opt_nr =0 ;
@@ -215,7 +217,7 @@ void __test_sock_restore(int sk, const char *device, }test_sock_restore_queue (sk,TCP_RECV_QUEUE , state->in.buf, state->inq_len);test_sock_restore_queue (sk,TCP_SEND_QUEUE , state->out.buf, state->outq_len); -if (setsockopt (sk,SOL_TCP ,TCP_REPAIR_WINDOW , &state->trw,sizeof (state->trw))) +if (setsockopt (sk,SOL_TCP ,TCP_REPAIR_WINDOW , &state->trw, trw_len))test_error ("setsockopt(TCP_REPAIR_WINDOW)" ); }
tools/testing/selftests/net/tcp_ao/self-connect.c +193 -8
253 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 12/14 tun/selftests: add RX truesize injection for TCP window tests
In reply to [email protected]From: Wesley Atwell <[email protected]>
Add a test-only TUN ioctl that inflates RX skb->truesize, plus the packetdrill-side helper needed to drive that ioctl through packetdrill's own TUN queue file descriptor.
Use that plumbing to cover the receive-window regressions where scaling_ratio drifts after advertisement, alongside the baseline too-big packetdrill cases that exercise the same sender-visible rwnd accounting from the non-injected path.
--- drivers/net/tun.c | 65 ++++++++ include/uapi/linux/if_tun.h | 4 + .../tcp_rcv_neg_window_truesize.pkt | 143 ++++++++++++++++++ .../net/packetdrill/tcp_rcv_toobig.pkt | 35 +++++ .../packetdrill/tcp_rcv_toobig_default.pkt | 97 ++++++++++++ .../tcp_rcv_toobig_default_truesize.pkt | 118 +++++++++++++++ .../tcp_rcv_wnd_shrink_allowed_truesize.pkt | 49 ++++++ tools/testing/selftests/net/tun.c | 140 ++++++++++++++++- 8 files changed, 650 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window_truesize.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_toobig.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_toobig_default.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_toobig_default_truesize.pkt create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed_truesize.pkt
drivers/net/tun.c +65 -0
@@ -53,6 +53,7 @@#include <linux/if_ether.h> #include <linux/if_tun.h> #include <linux/if_vlan.h> +#include <linux/overflow.h> #include <linux/crc32.h> #include <linux/math.h> #include <linux/nsproxy.h>
@@ -85,8 +86,13 @@#include "tun_vnet.h" +struct tun_file ; + +#define TUNSETTRUESIZE_OLD _IOW('T', 228, unsigned int) +static void tun_default_link_ksettings (struct net_device *dev,struct ethtool_link_ksettings *cmd); +static void tun_rx_update_truesize (struct tun_file *tfile,struct sk_buff *skb);#define TUN_RX_PAD (NET_IP_ALIGN + NET_SKB_PAD)
@@ -138,6 +144,7 @@ struct tun_file {u16 queue_index;unsigned int ifindex; }; +u32 rx_extra_truesize;struct napi_struct napi;bool napi_enabled;bool napi_frags_enabled;
@@ -1817,6 +1824,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, goto free_skb; } +tun_rx_update_truesize (tfile, skb);switch (tun->flags &TUN_TYPE_MASK ) {case IFF_TUN :if (tun->flags &IFF_NO_PI ) {
@@ -2373,6 +2381,25 @@ static void tun_put_page(struct tun_page *tpage)__page_frag_cache_drain (tpage->page, tpage->count); } +/* Tests can inflate skb->truesize on ingress to exercise receive-memory +* accounting against a scaling_ratio that drifts after a window was +* advertised. The knob is per queue file, defaults to zero, and only changes +* behavior when explicitly enabled through the TUN fd. +*/ +static void tun_rx_update_truesize (struct tun_file *tfile,struct sk_buff *skb) +{ +u32 extra =READ_ONCE (tfile->rx_extra_truesize); +unsigned int truesize; + +if (!extra) +return ; + +if (check_add_overflow (skb->truesize, extra, &truesize)) + truesize =UINT_MAX ; + + skb->truesize = truesize; +} + static int tun_xdp_one(struct tun_struct *tun, struct tun_file *tfile, struct xdp_buff *xdp, int *flush,
@@ -2459,6 +2486,7 @@ static int tun_xdp_one(struct tun_struct *tun, goto out; } +tun_rx_update_truesize (tfile, skb); skb->protocol =eth_type_trans (skb, tun->dev);skb_reset_network_header (skb);skb_probe_transport_header (skb);
@@ -3045,6 +3073,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,struct tun_struct *tun;void __user * argp = (void __user *)arg;unsigned int carrier; +unsigned int extra_truesize;struct ifreq ifr;kuid_t owner;kgid_t group;
@@ -3309,6 +3338,40 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret =tun_net_change_carrier (tun->dev, (bool )carrier);break ; +/* Support both the legacy pointer-payload form and the scalar form +* used by the selftest helper when injecting truesize from +* packetdrill shell commands. +*/ +case TUNSETTRUESIZE : +case TUNSETTRUESIZE_OLD : + ret = -EPERM ; +if (!ns_capable (net->user_ns,CAP_NET_ADMIN )) + goto unlock; + +if (cmd ==TUNSETTRUESIZE_OLD ) { + ret = -EFAULT ; +if (copy_from_user (&extra_truesize, argp, +sizeof (extra_truesize))) { + ret = -EINVAL ; +if (arg >U32_MAX ) + goto unlock; + + extra_truesize = arg; + } + }else { + ret = -EINVAL ; +if (arg >U32_MAX ) + goto unlock; + + extra_truesize = arg; + } + +WRITE_ONCE (tfile->rx_extra_truesize, extra_truesize); +netif_info (tun, drv, tun->dev, +"rx extra truesize set to %u\n" , extra_truesize); + ret =0 ; +break ; +case TUNGETDEVNETNS : ret = -EPERM ;if (!ns_capable (net->user_ns,CAP_NET_ADMIN ))
@@ -3348,6 +3411,7 @@ static long tun_chr_compat_ioctl(struct file *file,case TUNGETSNDBUF :case TUNSETSNDBUF :case SIOCGIFHWADDR : +case TUNSETTRUESIZE_OLD :case SIOCSIFHWADDR : arg = (unsigned long )compat_ptr (arg);break ;
@@ -3408,6 +3472,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)RCU_INIT_POINTER (tfile->tun,NULL ); tfile->flags =0 ; tfile->ifindex =0 ; + tfile->rx_extra_truesize =0 ;init_waitqueue_head (&tfile->socket.wq.wait);
include/uapi/linux/if_tun.h +4 -0
@@ -61,6 +61,10 @@#define TUNSETFILTEREBPF _IOR('T', 225, int)#define TUNSETCARRIER _IOW('T', 226, int)#define TUNGETDEVNETNS _IO('T', 227) +/* Test-only: add scalar bytes to skb->truesize on RX after TUN allocates +* an skb. +*/ +#define TUNSETTRUESIZE _IO('T', 228)/* TUNSETIFF ifr flags */ #define IFF_TUN 0x0001
tools/testing/selftests/net/packetdrill/tcp_rcv_neg_window_truesize.pkt new file +143 -0
143 lines not on this page · raw message
tools/testing/selftests/net/packetdrill/tcp_rcv_toobig.pkt new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 + +--mss=1000 + +`./defaults.sh` + + 0 `nstat -n` + +// Establish a connection. + +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 + +0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 + +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [20000], 4) = 0 + +0 bind(3, ..., ...) = 0 + +0 listen(3, 1) = 0 + + +0 < S 0:0(0) win 32792 <mss 1000,nop,wscale 7> + +0 > S. 0:0(0) ack 1 win 18980 <mss 1460,nop,wscale 0> + +.1 < . 1:1(0) ack 1 win 257 + + +0 accept(3, ..., ...) = 4 + + +0 < P. 1:20001(20000) ack 1 win 257 + +.04 > . 1:1(0) ack 20001 win 18000 + + +0 setsockopt(4, SOL_SOCKET, SO_RCVBUF, [12000], 4) = 0 + +0 < P. 20001:80001(60000) ack 1 win 257 + +0 > . 1:1(0) ack 20001 win 18000 + + +0 read(4, ..., 20000) = 20000 + +// A too big packet is accepted if the receive queue is empty, but the +// stronger admission path must not zero the receive buffer while doing so. + +0 < P. 20001:80001(60000) ack 1 win 257 + * > . 1:1(0) ack 80001 win 0 + +0 %{ assert SK_MEMINFO_RCVBUF > 0, SK_MEMINFO_RCVBUF }%
tools/testing/selftests/net/packetdrill/tcp_rcv_toobig_default.pkt new file +97 -0
97 lines not on this page · raw message
tools/testing/selftests/net/packetdrill/tcp_rcv_toobig_default_truesize.pkt new file +118 -0
118 lines not on this page · raw message
tools/testing/selftests/net/packetdrill/tcp_rcv_wnd_shrink_allowed_truesize.pkt new file +49 -0
49 lines not on this page · raw message
tools/testing/selftests/net/tun.c +139 -1
163 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 13/14 netdevsim: add peer RX truesize support for selftests
In reply to [email protected]From: Wesley Atwell <[email protected]>
Add a debugfs-controlled peer RX truesize knob to netdevsim, inflate the forwarded skb only on the peer RX side, and cover the resulting socket memory-accounting behavior with a dedicated selftest.
This keeps the synthetic cost out of the sender-side skb geometry while giving the selftests a second runtime vehicle for the receive-memory accounting exercised by the TCP rwnd work.
--- drivers/net/netdevsim/netdev.c | 145 +++++- drivers/net/netdevsim/netdevsim.h | 4 + .../selftests/drivers/net/netdevsim/Makefile | 1 + .../drivers/net/netdevsim/peer-rx-truesize.sh | 426 ++++++++++++++++++ 4 files changed, 575 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/drivers/net/netdevsim/peer-rx-truesize.sh
drivers/net/netdevsim/netdev.c +144 -1
@@ -17,8 +17,10 @@#include <linux/etherdevice.h> #include <linux/ethtool_netlink.h> #include <linux/kernel.h> +#include <linux/kstrtox.h> #include <linux/module.h> #include <linux/netdevice.h> +#include <linux/refcount.h> #include <linux/slab.h> #include <net/netdev_queues.h> #include <net/netdev_rx_queue.h>
@@ -37,6 +39,91 @@ MODULE_IMPORT_NS("NETDEV_INTERNAL");#define NSIM_RING_SIZE 256 +struct nsim_rx_truesize { +refcount_t refs; +u32 value; +}; + +static struct nsim_rx_truesize * +nsim_rx_truesize_get (struct nsim_rx_truesize *rx_truesize) +{ +if (!rx_truesize) +return NULL ; + +if (!refcount_inc_not_zero (&rx_truesize->refs)) +return NULL ; + +return rx_truesize; +} + +static void nsim_rx_truesize_put (struct nsim_rx_truesize *rx_truesize) +{ +if (!rx_truesize) +return ; + +if (refcount_dec_and_test (&rx_truesize->refs)) +kfree (rx_truesize); +} + +static ssize_t nsim_rx_truesize_read (struct file *file,char __user *user_buf, +size_t count,loff_t *ppos) +{ +struct nsim_rx_truesize *rx_truesize = file->private_data; +char buf[24 ]; +int len; + + len =scnprintf (buf,sizeof (buf),"%u\n" , +READ_ONCE (rx_truesize->value)); + +return simple_read_from_buffer (user_buf, count, ppos, buf, len); +} + +static ssize_t nsim_rx_truesize_write (struct file *file, +const char __user *user_buf, +size_t count,loff_t *ppos) +{ +struct nsim_rx_truesize *rx_truesize = file->private_data; +u32 value; +int err; + + err =kstrtou32_from_user (user_buf, count,0 , &value); +if (err) +return err; + +WRITE_ONCE (rx_truesize->value, value); + +return count; +} + +static int nsim_rx_truesize_open (struct inode *inode,struct file *file) +{ +struct nsim_rx_truesize *rx_truesize; + + rx_truesize =nsim_rx_truesize_get (inode->i_private); +if (!rx_truesize) +return -ENODEV ; + + file->private_data = rx_truesize; + +return nonseekable_open (inode, file); +} + +static int nsim_rx_truesize_release (struct inode *inode,struct file *file) +{ +nsim_rx_truesize_put (file->private_data); + +return 0 ; +} + +static const struct file_operations nsim_rx_truesize_fops = { + .owner =THIS_MODULE , + .open = nsim_rx_truesize_open, + .read = nsim_rx_truesize_read, + .write = nsim_rx_truesize_write, + .release = nsim_rx_truesize_release, + .llseek = noop_llseek, +}; +static void nsim_start_peer_tx_queue (struct net_device *dev,struct nsim_rq *rq) {struct netdevsim *ns =netdev_priv (dev);
@@ -117,6 +204,28 @@ static int nsim_forward_skb(struct net_device *tx_dev,return nsim_napi_rx (tx_dev, rx_dev, rq, skb); } +/* Tests can inflate peer RX skb->truesize to exercise receiver-side TCP +* accounting under scaling-ratio drift without perturbing sender-side skb +* ownership. +*/ +static void nsim_rx_update_truesize (struct sk_buff *skb,u32 extra) +{ +unsigned int truesize; + +if (!extra) +return ; + +if (check_add_overflow (skb->truesize, extra, &truesize)) + truesize =UINT_MAX ; + + skb->truesize = truesize; +} + +static u32 nsim_rx_extra_truesize (const struct netdevsim *ns) +{ +return READ_ONCE (ns->rx_truesize->value); +} +static netdev_tx_t nsim_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct netdevsim *ns =netdev_priv (dev);
@@ -125,7 +234,9 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)unsigned int len = skb->len;struct netdevsim *peer_ns;struct netdev_config *cfg; +struct sk_buff *nskb;struct nsim_rq *rq; +u32 extra;int rxq;int dr;
@@ -160,7 +271,24 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev) cfg->hds_thresh > len)))skb_linearize (skb); + extra =nsim_rx_extra_truesize (peer_ns);skb_tx_timestamp (skb); +if (extra) { +/* Clone before inflating truesize so only the peer RX path sees +* the synthetic cost; sender-side skb accounting stays put. +*/ + nskb =skb_clone (skb,GFP_ATOMIC ); +if (!nskb) { +if (psp_ext) +__skb_ext_put (psp_ext); + goto out_drop_free; + } + +consume_skb (skb); + skb = nskb; +nsim_rx_update_truesize (skb, extra); + } +if (unlikely (nsim_forward_skb (dev, peer_dev, skb, rq, psp_ext) ==NET_RX_DROP )) goto out_drop_cnt;
@@ -1121,6 +1249,7 @@ struct netdevsim *nsim_create(struct nsim_dev *nsim_dev, u8 perm_addr[ETH_ALEN]) {struct net_device *dev; +struct nsim_rx_truesize *rx_truesize;struct netdevsim *ns;int err;
@@ -1140,6 +1269,13 @@ struct netdevsim *nsim_create(struct nsim_dev *nsim_dev, ns->nsim_bus_dev = nsim_dev->nsim_bus_dev;SET_NETDEV_DEV (dev, &ns->nsim_bus_dev->dev);SET_NETDEV_DEVLINK_PORT (dev, &nsim_dev_port->devlink_port); + rx_truesize =kzalloc_obj (*rx_truesize); +if (!rx_truesize) { + err = -ENOMEM ; + goto err_free_netdev; + } +refcount_set (&rx_truesize->refs,1 ); + ns->rx_truesize = rx_truesize;nsim_ethtool_init (ns);if (nsim_dev_port_is_pf (nsim_dev_port)) err =nsim_init_netdevsim (ns);
@@ -1153,21 +1289,27 @@ struct netdevsim *nsim_create(struct nsim_dev *nsim_dev, ns->qr_dfs =debugfs_create_file ("queue_reset" ,0200 , nsim_dev_port->ddir, ns, &nsim_qreset_fops); + ns->rx_truesize_dfs =debugfs_create_file ("rx_extra_truesize" ,0600 , + nsim_dev_port->ddir, + ns->rx_truesize, + &nsim_rx_truesize_fops);return ns; err_free_netdev: +nsim_rx_truesize_put (ns->rx_truesize);free_netdev (dev);return ERR_PTR (err); }void nsim_destroy (struct netdevsim *ns) { +struct nsim_rx_truesize *rx_truesize = ns->rx_truesize;struct net_device *dev = ns->netdev;struct netdevsim *peer; +debugfs_remove (ns->rx_truesize_dfs);debugfs_remove (ns->qr_dfs);debugfs_remove (ns->pp_dfs); -if (ns->nb.notifier_call)unregister_netdevice_notifier_dev_net (ns->netdev, &ns->nb, &ns->nn);
@@ -1198,6 +1340,7 @@ void nsim_destroy(struct netdevsim *ns) }free_netdev (dev); +nsim_rx_truesize_put (rx_truesize); }bool netdev_is_nsim (struct net_device *dev)
drivers/net/netdevsim/netdevsim.h +4 -0
@@ -75,6 +75,8 @@ struct nsim_macsec {u8 nsim_secy_count; }; +struct nsim_rx_truesize ; +struct nsim_ethtool_pauseparam {bool rx;bool tx;
@@ -144,6 +146,8 @@ struct netdevsim { } udp_ports;struct page *page; +struct nsim_rx_truesize *rx_truesize; +struct dentry *rx_truesize_dfs;struct dentry *pp_dfs;struct dentry *qr_dfs;
tools/testing/selftests/drivers/net/netdevsim/Makefile +1 -0
@@ -14,6 +14,7 @@ TEST_PROGS := \ macsec-offload.sh \ nexthop.sh \ peer.sh \ + peer-rx-truesize.sh \ psample.sh \ tc-mq-visibility.sh \ udp_tunnel_nic.sh \
tools/testing/selftests/drivers/net/netdevsim/peer-rx-truesize.sh new file +426 -0
426 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 14/14 netdevsim: release pinned PSP ext on drop paths
In reply to [email protected]From: Wesley Atwell <[email protected]>
nsim_do_psp() can leave an extra extension reference pinned until nsim_psp_handle_ext() reattaches it to a forwarded skb.
Route the drop paths through a common helper and release that extra reference when __dev_forward_skb() fails and when start_xmit() drops the skb before it reaches the peer RX path.
This is separate from the peer RX truesize test hook itself.
--- drivers/net/netdevsim/netdev.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/net/netdevsim/netdev.c +14 -5
@@ -187,6 +187,15 @@ static int nsim_napi_rx(struct net_device *tx_dev, struct net_device *rx_dev,return NET_RX_SUCCESS ; } +/* nsim_do_psp() pins an extra extension ref until nsim_psp_handle_ext() +* reattaches it to a forwarded skb. +*/ +static void nsim_psp_ext_put (struct skb_ext *psp_ext) +{ +if (psp_ext) +__skb_ext_put (psp_ext); +} + static int nsim_forward_skb(struct net_device *tx_dev, struct net_device *rx_dev, struct sk_buff *skb,
@@ -196,8 +205,10 @@ static int nsim_forward_skb(struct net_device *tx_dev,int ret; ret =__dev_forward_skb (rx_dev, skb); -if (ret) +if (ret) { +nsim_psp_ext_put (psp_ext);return ret; + }nsim_psp_handle_ext (skb, psp_ext);
@@ -278,11 +289,8 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)* the synthetic cost; sender-side skb accounting stays put. */ nskb =skb_clone (skb,GFP_ATOMIC ); -if (!nskb) { -if (psp_ext) -__skb_ext_put (psp_ext); +if (!nskb) goto out_drop_free; - }consume_skb (skb); skb = nskb;
@@ -303,6 +311,7 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev) out_drop_any: dr =SKB_DROP_REASON_NOT_SPECIFIED ; out_drop_free: +nsim_psp_ext_put (psp_ext);kfree_skb_reason (skb, dr); out_drop_cnt:rcu_read_unlock ();
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v2 13/14] netdevsim: add peer RX truesize support for selftests
In reply to [email protected]tools/testing/selftests/drivers/net/netdevsim/Makefile TEST_PROGS := \ · line 20
Quoted 12 lines · On Sat, 14 Mar 2026 14:13:47 -0600 [email protected] wrote:
tools/testing/selftests/drivers/net/netdevsim/Makefile +1
-0@@ -14,6 +14,7 @@ TEST_PROGS := \ macsec-offload.sh \ nexthop.sh \ peer.sh \ + peer-rx-truesize.sh \ psample.sh \ tc-mq-visibility.sh \ udp_tunnel_nic.sh \
I think our order checker thinks that is not alphabetical. You can find the scripts here:
https://github.com/linux-netdev/nipa/tree/main/tests/patch/check_selftest
It'd be good if you can try the "running locally" section from README
Jakub Kicinski
maintainerRe: [PATCH net-next v2 12/14] tun/selftests: add RX truesize injection for TCP window tests
In reply to [email protected]Quoted 8 lines · On Sat, 14 Mar 2026 14:13:46 -0600 [email protected] wrote:
Add a test-only TUN ioctl that inflates RX
skb->truesize, plus the packetdrill-side helper needed to drive that ioctl through packetdrill's own TUN queue file descriptor.Use that plumbing to cover the receive-window regressions where
scaling_ratiodrifts after advertisement, alongside the baseline too-big packetdrill cases that exercise the same sender-visible rwnd accounting from the non-injected path.
You missed adding the tun program to the Makefile.
tcp-rcv-neg-window-truesize-pkt
tcp-rcv-toobig-default-truesize-pkt
tcp-rcv-wnd-shrink-allowed-truesize-pkt
Fail with:
sh: line 1: ../tun: No such file or directory tcp_rcv_*_truesize.pkt:*: error executing `../tun --set-rx-truesize tun0 6553\
6` command: non-zero status 127
https://netdev.bots.linux.dev/contest.html?pw-n=0&branch=net-next-2026-03-15--00-00&pw-n=0&pass=0
Jakub Kicinski
maintainerQuoted 5 lines · On Sat, 14 Mar 2026 14:13:34 -0600 [email protected] wrote:
This series keeps sender-visible TCP receive-window accounting tied to the scaling basis that was in force when the window was advertised, even if later receive-side truesize inflation lowers
scaling_ratioor the live receive window retracts below the largest right edge already exposed to the sender.
Please wait until at least Monday before reposting this. LLM-pocalypse is hitting us hard
Paolo Abeni
maintainerRe: [PATCH net-next v2 05/14] tcp: grow rcvbuf to back scaled-window quantization slack
In reply to [email protected]Quoted 32 lines · On 3/14/26 9:13 PM, [email protected] wrote:
From: Wesley Atwell <[email protected]>
Teach TCP to grow
sk_rcvbufwhen scale rounding would otherwise expose more sender-visible window than the current hard receive-memory backing can cover.The new helper keeps backlog and memory-pressure limits in the same units as the rest of the receive path, while
__tcp_select_window()backs any rounding slack before advertising it.Signed-off-by Wesley Atwell <[email protected]>--- include/net/tcp.h | 12 ++++++++++++ net/ipv4/tcp_input.c | 36 ++++++++++++++++++++++++++++++++++-- net/ipv4/tcp_output.c | 15 +++++++++++++-- 3 files changed, 59 insertions(+), 4 deletions(-)include/net/tcp.h +1
-0@@ -397,6 +397,7 @@ int tcp_ioctl(struct sock *sk, int cmd, int *karg);enum skb_drop_reason tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb);void tcp_rcv_established (struct sock *sk,struct sk_buff *skb);void tcp_rcvbuf_grow (struct sock *sk,u32 newval); +bool tcp_try_grow_rcvbuf (struct sock *sk,int needed);void tcp_rcv_space_adjust (struct sock *sk);int tcp_twsk_unique (struct sock *sk,struct sock *sktw,void *twp);void tcp_twsk_destructor (struct sock *sk);@@ -1844,6 +1845,17 @@ static inline int tcp_rwnd_avail(const struct sock *sk)return tcp_rmem_avail (sk) -READ_ONCE (sk->sk_backlog.len); }
include/net/tcp.h static inline int tcp_rwnd_avail(const struct sock *sk) · line 1856
Quoted 10 lines
include/net/tcp.h +9
-0+/* Passive children clone the listener's sk_socket until accept() grafts +* their own struct socket, so only sockets that point back to themselves +* should autotune receive-buffer backing. +*/ +static inline bool tcp_rcvbuf_grow_allowed (const struct sock *sk) +{ +struct socket *sock =READ_ONCE (sk->sk_socket); + +return sock &&READ_ONCE (sock->sk) == sk;
This is executed under the sk socket lock, ONCE annotation not needed.
Quoted 33 lines
include/net/tcp.h +2
-0+} +/* Note: caller must be prepared to deal with negative returns */ static inline int tcp_space (const struct sock *sk) {net/ipv4/tcp_input.c +20
-0@@ -774,6 +774,38 @@ static void tcp_init_buffer_space(struct sock *sk) (u32)TCP_INIT_CWND * tp->advmss); } +/* Try to grow sk_rcvbuf so the hard receive-memory limit covers @needed +* bytes beyond sk_rmem_alloc while preserving sender-visible headroom +* already consumed by sk_backlog.len. +*/ +bool tcp_try_grow_rcvbuf (struct sock *sk,int needed) +{ +struct net *net =sock_net (sk); +int backlog; +int rmem2; +int target; + + needed =max (needed,0 ); + backlog =READ_ONCE (sk->sk_backlog.len); + target =tcp_rmem_used (sk) + backlog + needed; + +if (target <=READ_ONCE (sk->sk_rcvbuf)) +return true; + + rmem2 =READ_ONCE (net->ipv4.sysctl_tcp_rmem[2 ]); + if (READ_ONCE(sk->sk_rcvbuf) >= rmem2 ||
net/ipv4/tcp_input.c static void tcp_init_buffer_space(struct sock *sk) · line 806
Quoted 10 lines
net/ipv4/tcp_input.c +10
-0+ (sk->sk_userlocks &SOCK_RCVBUF_LOCK ) || +tcp_under_memory_pressure (sk) || + sk_memory_allocated(sk) >= sk_prot_mem_limits(sk, 0)) + return false; + +WRITE_ONCE (sk->sk_rcvbuf, +min_t (int, rmem2, +max_t (int,READ_ONCE (sk->sk_rcvbuf), target))); + +return target <=READ_ONCE (sk->sk_rcvbuf);
Same here, and more cases below.
/P
Paolo Abeni
maintainerQuoted 11 lines · On 3/14/26 9:13 PM, [email protected] wrote:
From: Wesley Atwell <[email protected]>
This series keeps sender-visible TCP receive-window accounting tied to the scaling basis that was in force when the window was advertised, even if later receive-side truesize inflation lowers
scaling_ratioor the live receive window retracts below the largest right edge already exposed to the sender.After the receive-window retraction changes, the receive path needs to keep track of two related pieces of sender-visible state:
Quoted 8 lines
1. the live advertised receive window
2. the maximum advertised right edge and the basis it was exposed withThis repost snapshots both, uses them to repair receive-buffer backing when ratio drift would otherwise strand sender-visible space, extends
TCP_REPAIR_WINDOWso repair/restore can round-trip the new state, and adds truesize-drift coverage through TUN packetdrill tests and netdevsim-based selftests.
The series is IMHO significantly not trivial. Can the end-user meet the relevant condition in practice? How? What is the net benefit in practice? Is that observable under usual conditions or require exceptional circumstances?
I think we need a strong motivation to merge this kind of changes.
/P
Paolo Abeni
maintainerRe: [PATCH net-next v2 05/14] tcp: grow rcvbuf to back scaled-window quantization slack
In reply to [email protected]Quoted 30 lines · On 3/14/26 9:13 PM, [email protected] wrote:
From: Wesley Atwell <[email protected]>
Teach TCP to grow
sk_rcvbufwhen scale rounding would otherwise expose more sender-visible window than the current hard receive-memory backing can cover.The new helper keeps backlog and memory-pressure limits in the same units as the rest of the receive path, while
__tcp_select_window()backs any rounding slack before advertising it.Signed-off-by Wesley Atwell <[email protected]>--- include/net/tcp.h | 12 ++++++++++++ net/ipv4/tcp_input.c | 36 ++++++++++++++++++++++++++++++++++-- net/ipv4/tcp_output.c | 15 +++++++++++++-- 3 files changed, 59 insertions(+), 4 deletions(-)include/net/tcp.h +1
-0@@ -397,6 +397,7 @@ int tcp_ioctl(struct sock *sk, int cmd, int *karg);enum skb_drop_reason tcp_rcv_state_process (struct sock *sk,struct sk_buff *skb);void tcp_rcv_established (struct sock *sk,struct sk_buff *skb);void tcp_rcvbuf_grow (struct sock *sk,u32 newval); +bool tcp_try_grow_rcvbuf (struct sock *sk,int needed);void tcp_rcv_space_adjust (struct sock *sk);int tcp_twsk_unique (struct sock *sk,struct sock *sktw,void *twp);void tcp_twsk_destructor (struct sock *sk);
include/net/tcp.h static inline int tcp_rwnd_avail(const struct sock *sk) · line 1849
Quoted 5 lines
include/net/tcp.h +2
-0@@ -1844,6 +1845,17 @@ static inline int tcp_rwnd_avail(const struct sock *sk)return tcp_rmem_avail (sk) -READ_ONCE (sk->sk_backlog.len); } +/* Passive children clone the listener's sk_socket until accept() grafts +* their own struct socket,
AFAICS, the above statement is false, see sk_set_socket() in sk_clone()
include/net/tcp.h static inline int tcp_rwnd_avail(const struct sock *sk) · line 1854
Quoted 6 lines
so only sockets that point back to themselves
+ * should autotune receive-buffer backing.
+ */include/net/tcp.h +3
-0+static inline bool tcp_rcvbuf_grow_allowed (const struct sock *sk) +{ +struct socket *sock =READ_ONCE (sk->sk_socket);
You can just check sk->sk_socket. Also you could re-use this helper in tcp_data_queue_ofo().
/P
Paolo Abeni
maintainerRe: [PATCH net-next v2 05/14] tcp: grow rcvbuf to back scaled-window quantization slack
In reply to [email protected]Quoted 18 lines · On 3/14/26 9:13 PM, [email protected] wrote:
net/ipv4/tcp_output.c +3
-2@@ -3375,13 +3375,24 @@ u32 __tcp_select_window(struct sock *sk)* scaled window will not line up with the MSS boundary anyway. */ if (tp->rx_opt.rcv_wscale) { +int rcv_wscale =1 << tp->rx_opt.rcv_wscale; + window = free_space;/* Advertise enough space so that it won't get scaled away. -* Import case: prevent zero window announcement if +* Important case: prevent zero-window announcement if * 1<<rcv_wscale > mss. */ - window =ALIGN (window, (1 << tp->rx_opt.rcv_wscale));
net/ipv4/tcp_output.c u32 __tcp_select_window(struct sock *sk) · line 3395
Quoted 10 lines
net/ipv4/tcp_output.c +10
-0+ window =ALIGN (window, rcv_wscale); + +/* Back any scale-quantization slack before we expose it. +* Otherwise tcp_can_ingest() can reject data which is still +* within the sender-visible window. +*/ +if (window > free_space && + (!tcp_rcvbuf_grow_allowed (sk) || + !tcp_try_grow_rcvbuf (sk,tcp_space_from_win (sk, window)))) + window =round_down (free_space, rcv_wscale);
It looks like this can cause the advertised window to shrink even if we are in the 'do not allow window to shrink' branch.
Also why the other branch (shrinking allowed) is not touched?
/P
Paolo Abeni
maintainerRe: [PATCH net-next v2 07/14] tcp: honor the maximum advertised window after live retraction
In reply to [email protected]Quoted 17 lines · On 3/14/26 9:13 PM, [email protected] wrote:
net/ipv4/tcp_input.c +10
-3+/* Sender-visible window rescue does not relax hard receive-memory admission. +* If growth did not make room, fall back to the established prune/collapse +* path. +*/ static int tcp_try_rmem_schedule (struct sock *sk,const struct sk_buff *skb,unsigned int size) { -if (!tcp_can_ingest (sk, skb) || - !sk_rmem_schedule (sk, skb, size)) { +bool can_ingest =tcp_can_ingest (sk, skb); +bool scheduled = can_ingest &&sk_rmem_schedule (sk, skb, size); + +if (!scheduled) { +int pruned =tcp_prune_queue (sk, skb); -if (tcp_prune_queue (sk, skb) <0 ) +if (pruned <0 )
net/ipv4/tcp_input.c static void tcp_ofo_queue(struct sock *sk) · line 5461
Quoted 10 lines
net/ipv4/tcp_input.c +3
-1return -1 ;while (!sk_rmem_schedule (sk, skb, size)) { -if (!tcp_prune_ofo_queue (sk, skb)) +bool pruned_ofo =tcp_prune_ofo_queue (sk, skb); + +if (!pruned_ofo)return -1 ; } }
The above chunk is AFAICS pure noise. Please have a more careful local review of this series before any next revision.
/P
Paolo Abeni
maintainerHi,
Quoted 3 lines · Wesley Atwell
The strongest real anchor here is the already documented regression around sender-visible rwnd diverging from hard receive-memory backing, rather than a general receive-accounting cleanup.
I likely missed some of the prior discussion. Could you please share a pointer/link to the mentioned regression report?
When posting on netdev please:
- use plaintext only messages
- avoid top-posting
Thanks,
Paolo
Hi Paolo,
The link I meant is the netdev regression discussion that led to:
026dfef287c0 ("tcp: give up on stronger sk_rcvbuf checks (for now)")
The report/discussion thread is here:
https://lore.kernel.org/[email protected]
The revert posting itself is here:
https://patch.msgid.link/[email protected]
I should not have implied that there was a separate prior regression report beyond that thread.
Thanks for the note on formatting. I will keep follow-ups in plaintext and avoid top-posting.
Thanks,
Wesley