* [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting
@ 2026-11-17 5:22 lei lei
2026-11-17 5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: lei lei @ 2026-11-17 5:22 UTC (permalink / raw)
To: netdev@vger.kernel.org
Cc: mptcp@lists.linux.dev, edumazet@kernel.org, ncardwell@google.com,
kuniyu@google.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, matttbe@kernel.org,
martineau@kernel.org, geliang@kernel.org
This series fixes receive-buffer sizing and accounting errors in TCP
and MPTCP.
The first two patches prevent integer truncation from producing an
undersized receive-memory budget. __tcp_space_from_win() can return a
truncated int, while tcp_rcvbuf_grow() and mptcp_rcvbuf_grow() can wrap
a u32 window prediction. The fixes saturate the conversion result at
INT_MAX and keep growth predictions in u64 until they are bounded for
the existing helper interface. Patch 2 depends on patch 1.
The third patch restores the MSG_PEEK exclusion from MPTCP receive
autotuning. Repeated peeks currently count the same queued bytes as
application consumption, which can inflate the receive-memory budget
without the application draining the queue.
Validation used targeted IPv4 loopback socket tests on unpatched and
patched kernels in x86_64 QEMU/KVM guests. GCC 13.3 builds completed
without warnings. The tests confirmed that, with the fixes applied:
- Large SO_RCVLOWAT settings on TCP and MPTCP correctly increase the
receive-memory budget to INT_MAX when tcp_rmem[2] is INT_MAX and
the window-to-memory conversion exceeds the representable range.
- For queued bursts whose predicted window exceeds 32 bits, TCP and
MPTCP receive budgets now reach the configured 64 MiB limit.
- Repeated MSG_PEEK calls leave both a fixed 32 KiB MPTCP receive
queue and its memory budget unchanged. A subsequent consuming read
returns the original data intact.
The investigation began with sk_rcvbuf failing to grow despite
application reads during normal use, constraining the advertised
receive window.
OpenAI Codex assisted with designing trigger conditions and socket
tests for reproduction and validation.
lllei (3):
tcp: saturate window-to-memory conversions at INT_MAX
net: bound receive window predictions before narrowing
mptcp: exclude MSG_PEEK from receive buffer autotuning
include/net/tcp.h | 2 +-
net/ipv4/tcp_input.c | 11 ++++++-----
net/mptcp/protocol.c | 12 +++++++-----
3 files changed, 14 insertions(+), 11 deletions(-)
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
--
2.43.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX
2026-11-17 5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
@ 2026-11-17 5:22 ` lei lei
2026-11-19 7:54 ` Eric Dumazet
2026-11-17 5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
2026-11-17 5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
2 siblings, 1 reply; 8+ messages in thread
From: lei lei @ 2026-11-17 5:22 UTC (permalink / raw)
To: netdev@vger.kernel.org
Cc: mptcp@lists.linux.dev, edumazet@kernel.org, ncardwell@google.com,
kuniyu@google.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, matttbe@kernel.org,
martineau@kernel.org, geliang@kernel.org
__tcp_space_from_win() computes a receive-memory requirement in u64 but
returns int. A result above INT_MAX can therefore become negative or
wrap to a smaller positive value before the caller compares or limits it.
TCP and MPTCP SO_RCVLOWAT handling compare this result with sk_rcvbuf.
They can accept a large low watermark without increasing the receive
budget because the truncated requirement appears smaller than the
existing buffer. Receive autotuning uses the same conversion helper.
Saturate the u64 result at INT_MAX before returning it. This matches the
int type of sk_rcvbuf and preserves the value and rounding of every
representable result.
TCP and MPTCP loopback tests with tcp_rmem[2]=INT_MAX and
SO_RCVLOWAT=INT_MAX/2 reproduce the missed update after learning a
scaling ratio below 128. With this change, both budgets reach INT_MAX.
Fixes: dfa2f0483360 ("tcp: get rid of sysctl_tcp_adv_win_scale")
Signed-off-by: lllei <llleigoing@outlook.com>
---
include/net/tcp.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 5c9203aae..09827f1ae 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1799,7 +1799,7 @@ static inline int __tcp_space_from_win(u8 scaling_ratio, int win)
u64 val = (u64)win << TCP_RMEM_TO_WIN_SCALE;
do_div(val, scaling_ratio);
- return val;
+ return min_t(u64, val, INT_MAX);
}
static inline int tcp_space_from_win(const struct sock *sk, int win)
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 2/3] net: bound receive window predictions before narrowing
2026-11-17 5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
2026-11-17 5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
@ 2026-11-17 5:22 ` lei lei
2026-11-19 7:56 ` Eric Dumazet
2026-11-17 5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
2 siblings, 1 reply; 8+ messages in thread
From: lei lei @ 2026-11-17 5:22 UTC (permalink / raw)
To: netdev@vger.kernel.org
Cc: mptcp@lists.linux.dev, edumazet@kernel.org, ncardwell@google.com,
kuniyu@google.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, matttbe@kernel.org,
martineau@kernel.org, geliang@kernel.org
tcp_rcvbuf_grow() and mptcp_rcvbuf_grow() compute growth terms in u64 but
accumulate the predicted receive window in u32. The prediction can wrap
before conversion to a memory budget and application of tcp_rmem[2].
For example, oldval=16 KiB and newval=4104 KiB produce a slow-start
window prediction of 4 GiB + 8 MiB. Storing it in u32 leaves only 8 MiB,
so the memory limit is applied to an already truncated prediction.
Keep rcvwin in u64 and promote newval before the initial shift. Clamp
the completed prediction at INT_MAX before passing it to the existing
int-input window-to-memory helpers. Since scaling_ratio is a nonzero
u8, the required memory is at least as large as the window. Predictions
above INT_MAX therefore already require a saturated receive budget.
The helpers' return saturation and the existing tcp_rmem[2] limit then
provide the appropriate memory bound.
TCP and MPTCP loopback tests using small warm-up reads followed by a
queued burst of about 4 MiB previously left the budget below the
configured 64 MiB limit. With this change, both reach that limit.
Fixes: aa251c84636c ("tcp: fix too slow tcp_rcvbuf_grow() action")
Signed-off-by: lllei <llleigoing@outlook.com>
---
net/ipv4/tcp_input.c | 11 ++++++-----
net/mptcp/protocol.c | 9 +++++----
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index a2074a1af..6d5950dbe 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -940,9 +940,9 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
{
const struct net *net = sock_net(sk);
struct tcp_sock *tp = tcp_sk(sk);
- u32 rcvwin, rcvbuf, cap, oldval;
+ u32 rcvbuf, cap, oldval;
u32 rtt_threshold, rtt_us;
- u64 grow;
+ u64 rcvwin, grow;
oldval = tp->rcvq_space.space;
tp->rcvq_space.space = newval;
@@ -952,7 +952,7 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
return;
/* DRS is always one RTT late. */
- rcvwin = newval << 1;
+ rcvwin = (u64)newval << 1;
rtt_us = tp->rcv_rtt_est.rtt_us >> 3;
rtt_threshold = READ_ONCE(net->ipv4.sysctl_tcp_rcvbuf_low_rtt);
@@ -961,10 +961,10 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
* It might take few additional ms to reach 'line rate',
* but will avoid sk_rcvbuf inflation and poor cache use.
*/
- grow = div_u64((u64)rcvwin * rtt_us, rtt_threshold);
+ grow = div_u64(rcvwin * rtt_us, rtt_threshold);
} else {
/* slow start: allow the sender to double its rate. */
- grow = div_u64(((u64)rcvwin << 1) * (newval - oldval), oldval);
+ grow = div_u64((rcvwin << 1) * (newval - oldval), oldval);
}
rcvwin += grow;
@@ -973,6 +973,7 @@ void tcp_rcvbuf_grow(struct sock *sk, u32 newval)
cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]);
+ rcvwin = min_t(u64, rcvwin, INT_MAX);
rcvbuf = min_t(u32, tcp_space_from_win(sk, rcvwin), cap);
if (rcvbuf > sk->sk_rcvbuf) {
WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 8968db580..b3b979403 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -216,8 +216,8 @@ static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
{
struct mptcp_sock *msk = mptcp_sk(sk);
const struct net *net = sock_net(sk);
- u32 rcvwin, rcvbuf, cap, oldval;
- u64 grow;
+ u32 rcvbuf, cap, oldval;
+ u64 rcvwin, grow;
oldval = msk->rcvq_space.space;
msk->rcvq_space.space = newval;
@@ -226,15 +226,16 @@ static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
return false;
/* DRS is always one RTT late. */
- rcvwin = newval << 1;
+ rcvwin = (u64)newval << 1;
/* slow start: allow the sender to double its rate. */
- grow = (u64)rcvwin * (newval - oldval);
+ grow = rcvwin * (newval - oldval);
do_div(grow, oldval);
rcvwin += grow << 1;
cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]);
+ rcvwin = min_t(u64, rcvwin, INT_MAX);
rcvbuf = min_t(u32, mptcp_space_from_win(sk, rcvwin), cap);
if (rcvbuf > sk->sk_rcvbuf) {
WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning
2026-11-17 5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
2026-11-17 5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
2026-11-17 5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
@ 2026-11-17 5:22 ` lei lei
2026-11-19 7:59 ` Eric Dumazet
2 siblings, 1 reply; 8+ messages in thread
From: lei lei @ 2026-11-17 5:22 UTC (permalink / raw)
To: netdev@vger.kernel.org
Cc: mptcp@lists.linux.dev, edumazet@kernel.org, ncardwell@google.com,
kuniyu@google.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, matttbe@kernel.org,
martineau@kernel.org, geliang@kernel.org
__mptcp_recvmsg_mskq() passes bytes copied by MSG_PEEK to
mptcp_rcv_space_adjust(), although those bytes remain in the receive
queue. Repeated peeks count the same data as new application
consumption and can inflate the receive-memory budget. Subtracting the
unread queue at a measurement boundary cannot undo that repeated count.
The receive path originally skipped this adjustment for MSG_PEEK.
Commit 581302298524 ("mptcp: error out earlier on disconnect") moved
the adjustment calls without preserving that check.
Only adjust receive space for non-peeking reads. Keep the returned
byte count unchanged.
A loopback test leaves a fixed 32 KiB queue unread and peeks 4096 times.
Before this change, sk_rcvbuf grows to the configured 8 MiB limit.
Afterwards, both the budget and the queue remain unchanged, and a
subsequent consuming read returns the original data intact.
Fixes: 581302298524 ("mptcp: error out earlier on disconnect")
Signed-off-by: lllei <llleigoing@outlook.com>
---
net/mptcp/protocol.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b3b979403..79db8063a 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2215,7 +2215,8 @@ static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
break;
}
- mptcp_rcv_space_adjust(msk, copied);
+ if (!(flags & MSG_PEEK))
+ mptcp_rcv_space_adjust(msk, copied);
return copied;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX
2026-11-17 5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
@ 2026-11-19 7:54 ` Eric Dumazet
0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2026-11-19 7:54 UTC (permalink / raw)
To: lei lei
Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
ncardwell@google.com, kuniyu@google.com, davem@davemloft.net,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org
Le mar. 17 nov. 2026 à 06:22, lei lei <llleigoing@outlook.com> a écrit :
>
> __tcp_space_from_win() computes a receive-memory requirement in u64 but
> returns int. A result above INT_MAX can therefore become negative or
> wrap to a smaller positive value before the caller compares or limits it.
>
> TCP and MPTCP SO_RCVLOWAT handling compare this result with sk_rcvbuf.
> They can accept a large low watermark without increasing the receive
> budget because the truncated requirement appears smaller than the
> existing buffer. Receive autotuning uses the same conversion helper.
>
> Saturate the u64 result at INT_MAX before returning it. This matches the
> int type of sk_rcvbuf and preserves the value and rounding of every
> representable result.
>
> TCP and MPTCP loopback tests with tcp_rmem[2]=INT_MAX and
> SO_RCVLOWAT=INT_MAX/2 reproduce the missed update after learning a
> scaling ratio below 128. With this change, both budgets reach INT_MAX.
I do not think this is a fix, and I do not think it belongs to net tree.
The conversion overflows only if
val * 256 / scaling_ratio > INT_MAX
which is the same thing as saying that @val is bigger than the window
an INT_MAX sk_rcvbuf can offer at this scaling_ratio.
sk_rcvbuf being an int, the requested SO_RCVLOWAT can not be honored
in this case, with or without your patch. With scaling_ratio == 64,
the biggest possible window is ~512MB, a 1GB lowat is never reached.
So the changelog saying the budget is now "correct" is misleading:
sk_rcvbuf is set to INT_MAX and the application is still woken up
before sk_rcvlowat bytes are queued, from tcp_epollin_ready(),
when the receive window is about to close.
Note that scaling_ratio is not a constant, it is updated in
tcp_measure_rcv_mss() for the lifetime of the flow. A sk_rcvbuf sized
at setsockopt() time is too small as soon as the ratio decreases,
far below the overflow point. Huge SO_RCVLOWAT values are best effort.
To hit this, the admin has to set tcp_rmem[2] above 2GB, and the
application has to call setsockopt(SO_RCVLOWAT) with a ~1GB value
after a low scaling_ratio was learned. (Before any data is received,
the ratio is 128 and @val is capped to tcp_rmem[2]/2, no overflow
is possible.)
Also, with your patch, sk_rcvbuf can be set to INT_MAX while
tcp_rmem[2] is smaller than that (say 3GB/2, scaling_ratio 64),
because __tcp_set_rcvlowat() and mptcp_set_rcvlowat() do not clamp
@space to tcp_rmem[2]. This is not new, but saturating makes
it more visible.
Your cover letter mentions that this started with sk_rcvbuf failing
to grow "during normal use". What was the workload, and what were the
tcp_rmem values ? I would prefer we look at the real problem.
If you still want the saturation as a cleanup, please send it to
net-next, without a Fixes: tag, and with a changelog describing
what is really changed for the user.
>
> Fixes: dfa2f0483360 ("tcp: get rid of sysctl_tcp_adv_win_scale")
> Signed-off-by: lllei <llleigoing@outlook.com>
Sashiko already pointed this: your From: is "lei lei", this
Signed-off-by: is "lllei". Please use your real name in both,
see Documentation/process/submitting-patches.rst.
Thanks.
pw-bot: cr
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 2/3] net: bound receive window predictions before narrowing
2026-11-17 5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
@ 2026-11-19 7:56 ` Eric Dumazet
0 siblings, 0 replies; 8+ messages in thread
From: Eric Dumazet @ 2026-11-19 7:56 UTC (permalink / raw)
To: lei lei
Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
ncardwell@google.com, kuniyu@google.com, davem@davemloft.net,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org
Le mar. 17 nov. 2026 à 06:22, lei lei <llleigoing@outlook.com> a écrit :
>
> tcp_rcvbuf_grow() and mptcp_rcvbuf_grow() compute growth terms in u64 but
> accumulate the predicted receive window in u32. The prediction can wrap
> before conversion to a memory budget and application of tcp_rmem[2].
>
> For example, oldval=16 KiB and newval=4104 KiB produce a slow-start
> window prediction of 4 GiB + 8 MiB. Storing it in u32 leaves only 8 MiB,
> so the memory limit is applied to an already truncated prediction.
The arithmetic is right, but I do not see a bug worth a net patch
and stable backports.
This needs @newval to be ~256 times @oldval between two consecutive
measurements. The "allow the sender to double its rate" logic was
never meant to be meaningful for such a sample: a 4GB prediction
out of 4MB copied to user space is garbage, wrapped or not.
What happens today: this round gets a smaller sk_rcvbuf increase than
the formula asked for (or none). sk_rcvbuf never shrinks here, and
the next measurement has a sane @oldval. So we lose one step.
What happens with your patch: a single sample like this sends
sk_rcvbuf straight to tcp_rmem[2].
This is the kind of sk_rcvbuf inflation we have been trying to avoid
lately, see commit aa251c84636c and the tcp_rcvbuf_low_rtt logic.
I am not convinced this is an improvement.
>
> Keep rcvwin in u64 and promote newval before the initial shift. Clamp
> the completed prediction at INT_MAX before passing it to the existing
> int-input window-to-memory helpers. Since scaling_ratio is a nonzero
> u8, the required memory is at least as large as the window. Predictions
> above INT_MAX therefore already require a saturated receive budget.
> The helpers' return saturation and the existing tcp_rmem[2] limit then
> provide the appropriate memory bound.
>
> TCP and MPTCP loopback tests using small warm-up reads followed by a
> queued burst of about 4 MiB previously left the budget below the
> configured 64 MiB limit. With this change, both reach that limit.
For TCP, the slow start branch is only taken if the RTT is above
tcp_rcvbuf_low_rtt (1ms by default). I guess you had to change this
sysctl to get this result over loopback ? Please describe the full
setup, including tcp_rmem[1].
More importantly, reaching tcp_rmem[2] after a single 4MB burst is
not a goal. What is the user visible problem here ? Do you have
numbers (throughput, drops, rcv window) for a real flow ?
If there is a real case where growth is too slow, I would rather
discuss the heuristic than the type of @rcvwin.
If you send this again:
- net-next, no Fixes: tag, unless you can show a real regression.
- Please split TCP and MPTCP changes. One patch with a "net:" prefix
touching both, with a single Fixes: tag pointing to a TCP commit
is not right for mptcp_rcvbuf_grow().
>
> Fixes: aa251c84636c ("tcp: fix too slow tcp_rcvbuf_grow() action")
> Signed-off-by: lllei <llleigoing@outlook.com>
Same remark about the Signed-off-by: than for patch 1.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning
2026-11-17 5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
@ 2026-11-19 7:59 ` Eric Dumazet
2026-11-19 18:33 ` Matthieu Baerts
0 siblings, 1 reply; 8+ messages in thread
From: Eric Dumazet @ 2026-11-19 7:59 UTC (permalink / raw)
To: lei lei
Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
ncardwell@google.com, kuniyu@google.com, davem@davemloft.net,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org
Le mar. 17 nov. 2026 à 06:22, lei lei <llleigoing@outlook.com> a écrit :
>
> __mptcp_recvmsg_mskq() passes bytes copied by MSG_PEEK to
> mptcp_rcv_space_adjust(), although those bytes remain in the receive
> queue. Repeated peeks count the same data as new application
> consumption and can inflate the receive-memory budget. Subtracting the
> unread queue at a measurement boundary cannot undo that repeated count.
>
> The receive path originally skipped this adjustment for MSG_PEEK.
> Commit 581302298524 ("mptcp: error out earlier on disconnect") moved
> the adjustment calls without preserving that check.
>
> Only adjust receive space for non-peeking reads. Keep the returned
> byte count unchanged.
This one looks good to me.
mptcp_rcv_space_adjust() accumulates @copied in msk->rcvq_space.copied,
and mptcp_inq_hint() is subtracted once per measurement, so N peeks
of the same bytes are indeed counted N times.
(TCP also calls tcp_rcv_space_adjust() for MSG_PEEK, but it uses
tp->copied_seq, which is not changed by a peek, so it has no such
issue.)
The Fixes: tag is correct, commit 581302298524 removed the
"if (!(flags & MSG_PEEK))" test.
>
> A loopback test leaves a fixed 32 KiB queue unread and peeks 4096 times.
> Before this change, sk_rcvbuf grows to the configured 8 MiB limit.
> Afterwards, both the budget and the queue remain unchanged, and a
> subsequent consuming read returns the original data intact.
It would be nice to have this test in
tools/testing/selftests/net/mptcp/ (or as a packetdrill test),
MPTCP maintainers can tell you what they prefer.
>
> Fixes: 581302298524 ("mptcp: error out earlier on disconnect")
> Signed-off-by: lllei <llleigoing@outlook.com>
Given my comments on patches 1 and 2, I suggest you send this
patch alone, it does not depend on them.
With the Signed-off-by: fixed:
Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning
2026-11-19 7:59 ` Eric Dumazet
@ 2026-11-19 18:33 ` Matthieu Baerts
0 siblings, 0 replies; 8+ messages in thread
From: Matthieu Baerts @ 2026-11-19 18:33 UTC (permalink / raw)
To: Eric Dumazet
Cc: lei lei, netdev@vger.kernel.org, mptcp@lists.linux.dev,
ncardwell@google.com, kuniyu@google.com, davem@davemloft.net,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
martineau@kernel.org, geliang@kernel.org
Hi Eric, Lei,
Thank you for the patch, and for the review!
On 19/11/2026 08:59, Eric Dumazet wrote:
> Le mar. 17 nov. 2026 à 06:22, lei lei <llleigoing@outlook.com> a écrit :
>>
>> __mptcp_recvmsg_mskq() passes bytes copied by MSG_PEEK to
>> mptcp_rcv_space_adjust(), although those bytes remain in the receive
>> queue. Repeated peeks count the same data as new application
>> consumption and can inflate the receive-memory budget. Subtracting the
>> unread queue at a measurement boundary cannot undo that repeated count.
>>
>> The receive path originally skipped this adjustment for MSG_PEEK.
>> Commit 581302298524 ("mptcp: error out earlier on disconnect") moved
>> the adjustment calls without preserving that check.
>>
>> Only adjust receive space for non-peeking reads. Keep the returned
>> byte count unchanged.
>
> This one looks good to me.
>
> mptcp_rcv_space_adjust() accumulates @copied in msk->rcvq_space.copied,
> and mptcp_inq_hint() is subtracted once per measurement, so N peeks
> of the same bytes are indeed counted N times.
>
> (TCP also calls tcp_rcv_space_adjust() for MSG_PEEK, but it uses
> tp->copied_seq, which is not changed by a peek, so it has no such
> issue.)
>
> The Fixes: tag is correct, commit 581302298524 removed the
> "if (!(flags & MSG_PEEK))" test.
It looks good to me too, please send a v2 with the Signed-off-by:
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
>> A loopback test leaves a fixed 32 KiB queue unread and peeks 4096 times.
>> Before this change, sk_rcvbuf grows to the configured 8 MiB limit.
>> Afterwards, both the budget and the queue remain unchanged, and a
>> subsequent consuming read returns the original data intact.
>
> It would be nice to have this test in
> tools/testing/selftests/net/mptcp/ (or as a packetdrill test),
> MPTCP maintainers can tell you what they prefer.
Good idea! We prefer a packetdrill test here, using the MPTCP fork [1]:
such tests are usually shorter and easier to read than a new selftest,
and our CI
runs them.
@Lei: could you open a PR on this separate repository with a new test,
please? For example in gtests/net/mptcp/syscalls/recv_peek_rcvbuf.pkt,
next to recv_peek_waitall.pkt. Feel free to use the following script if
it works on your side. You can test it with:
./packetdrill/run_all.py -lv mptcp/syscalls/recv_peek_rcvbuf.pkt
------------------------- 8< -------------------------
// MSG_PEEK must not be counted as consumed data by the rcvbuf autotuning
--tolerance_usecs=100000
`../common/defaults.sh`
// Small initial rcvbuf: without the fix, a few peeks are enough to grow it
+0.0 `sysctl -q net.ipv4.tcp_rmem="4096 8192 15728640"`
+0.0 socket(..., SOCK_STREAM, IPPROTO_MPTCP) = 3
+0.0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
+0.0 bind(3, ..., ...) = 0
+0.0 listen(3, 1) = 0
// With TS, the first data gives an RTT sample (~100ms), needed by autotuning
+0.0 < S 0:0(0) win 65535 <mss 1460, sackOK, TS val 100 ecr 0, nop, wscale 8, mpcapable v1 flags[flag_h] nokey>
+0.0 > S. 0:0(0) ack 1 <mss 1460, sackOK, TS val 700 ecr 100, nop, wscale 8, mpcapable v1 flags[flag_h] key[skey]>
+0.1 < . 1:1(0) ack 1 win 256 <nop, nop, TS val 200 ecr 700, mpcapable v1 flags[flag_h] key[ckey=2, skey]>
+0.0 accept(3, ..., ...) = 4
+0.0 < P. 1:1001(1000) ack 1 win 256 <nop, nop, TS val 300 ecr 700, mpcapable v1 flags[flag_h] key[skey, ckey] mpcdatalen 1000, nop, nop>
+0.0 > . 1:1(0) ack 1001 <nop, nop, TS val 700 ecr 300, dss dack8=1001 dll=0 nocs>
// Peek the same data multiple times within one RTT...
+0.0 recv(4, ..., 1000, MSG_PEEK) = 1000
+0.0 recv(4, ..., 1000, MSG_PEEK) = 1000
+0.0 recv(4, ..., 1000, MSG_PEEK) = 1000
+0.0 recv(4, ..., 1000, MSG_PEEK) = 1000
+0.0 recv(4, ..., 1000, MSG_PEEK) = 1000
// ... then once more after one RTT: nothing consumed, the rcvbuf is unchanged
+0.2 recv(4, ..., 1000, MSG_PEEK) = 1000
+0.0 getsockopt(4, SOL_SOCKET, SO_RCVBUF, [8192], [4]) = 0
------------------------- 8< -------------------------
[1] https://github.com/multipath-tcp/packetdrill
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-19 18:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 5:22 [PATCH net 0/3] tcp, mptcp: fix receive buffer sizing and peek accounting lei lei
2026-11-17 5:22 ` [PATCH net 1/3] tcp: saturate window-to-memory conversions at INT_MAX lei lei
2026-11-19 7:54 ` Eric Dumazet
2026-11-17 5:22 ` [PATCH net 2/3] net: bound receive window predictions before narrowing lei lei
2026-11-19 7:56 ` Eric Dumazet
2026-11-17 5:22 ` [PATCH net 3/3] mptcp: exclude MSG_PEEK from receive buffer autotuning lei lei
2026-11-19 7:59 ` Eric Dumazet
2026-11-19 18:33 ` Matthieu Baerts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox