Skip to contentSkip to conversation

mptcp: exclude MSG_PEEK from receive buffer autotuning

PATCH In review Lin Lei 3 participants 3 messages Nov 20

Subsystems (3)
lore
Share & tools
lore

Lin Lei

author
#0 lore raw

PATCH v2 1/1 mptcp: exclude MSG_PEEK from receive buffer autotuning

__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")

---
Changes in v2:
- Send this fix separately from the other patches.
- Update the author and sign-off and add the Reviewed-by tags.

v1: https://lore.kernel.org/all/[email protected]/

 net/mptcp/protocol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +2 -1
index b375da1f17fed..ca0ebcf11e02c 100644
@@ -2216,7 +2216,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;
 }
 

base-commit: 4d67cf2fd2352f130c42494a933ba9158b925c65

Signature · 1 line
2.43.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
#2 lore raw
In reply to Lin Lei

Hi Lin,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Unstable: 6 failed test(s): regression:sched-baseline(3) regression:sched-bbr regression:sched-clientlim regression:sched-rmem(4) regression:sched-serverlim validation:sched-loss(2) ⚠️ (1 improvements, 90 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/44702283372

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/5ac9fdbe3174
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1217034

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)