From: sashiko-bot@kernel.org
To: "Geliang Tang" <geliang@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next v8 6/7] selftests: mptcp: connect: add zerocopy io mode
Date: Mon, 23 Nov 2026 08:37:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-228908@kernel.org> (raw)
In-Reply-To: <9d10433a1bc453357a5994906ff3029f0e1f76a1.1795421388.git.tanggeliang@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] selftests: mptcp: premature buffer free in do_sendmsg_zc()
after first cmsg
- [Medium] selftests: mptcp: undersized msg_control buffer in
drain_errqueue_zc()
- [Medium] selftests: mptcp: ignored zc errors and wait on 0 sent in
do_sendmsg_zc()
- [Medium] selftests: mptcp: unconditional set_sndbuf() and 0-size MPTFO
in copyfd_io_zc()
- [Low] selftests: mptcp: int overflow in size * 2 and unlooped read in
do_sendmsg_zc()
--
commit 0f0d4fe1bd34bb0fc128a15413afd453172d8483
Author: Geliang Tang <geliang@kernel.org>
selftests: mptcp: connect: add zerocopy io mode
This commit adds a 'zerocopy' I/O mode to the mptcp_connect selftest that
transmits data using sendmsg() with MSG_ZEROCOPY and drains completion
notifications from the socket error queue.
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index 8c788977e5947..08fd505132030 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
[ ... ]
> @@ -1014,6 +1016,180 @@ static int copyfd_io_splice(int infd, int peerfd, int outfd, unsigned int size,
> return err;
> }
>
> +static bool process_cmsg_zc(struct msghdr *errmsg)
> +{
> + struct sock_extended_err *serr;
> + struct cmsghdr *cm;
> +
> + for (cm = CMSG_FIRSTHDR(errmsg); cm; cm = CMSG_NXTHDR(errmsg, cm)) {
> + if (cm->cmsg_level != SOL_IP && cm->cmsg_level != SOL_IPV6)
> + continue;
> + if (cm->cmsg_type != IP_RECVERR &&
> + cm->cmsg_type != IPV6_RECVERR)
> + continue;
> +
> + serr = (struct sock_extended_err *)CMSG_DATA(cm);
> + if (serr->ee_origin == SO_EE_ORIGIN_ZEROCOPY)
> + return true;
> + }
> +
> + return false;
> +}
> +
> +static bool drain_errqueue_zc(int peerfd)
> +{
> + size_t ctl_len = CMSG_SPACE(sizeof(struct sock_extended_err));
> + struct msghdr errmsg = {};
> + bool found = false;
> + char *ctl;
> +
> + ctl = malloc(ctl_len);
[Severity: Medium]
Is ctl_len large enough for the control messages queued on the error
queue?
ip_recv_error() and ipv6_recv_error() append an offender sockaddr_in or
sockaddr_in6 after struct sock_extended_err, so a buffer of
CMSG_SPACE(sizeof(struct sock_extended_err)) triggers MSG_CTRUNC on every
recvmsg(MSG_ERRQUEUE) call. They also call sock_recv_timestamp() before
queuing IP_RECVERR or IPV6_RECVERR, so running with -c TIMESTAMPNS fills
the entire 32-byte control buffer with the timestamp cmsg and drops the
zero-copy completion cmsg, leaving wait_for_completions_zc() to stall
until timeout.
> + if (!ctl) {
> + perror("malloc ctl");
> + return false;
> + }
> +
> + errmsg.msg_control = ctl;
> +
> + while (!found) {
> + errmsg.msg_controllen = ctl_len;
> + if (recvmsg(peerfd, &errmsg, MSG_ERRQUEUE) < 0)
> + break;
> +
> + found = process_cmsg_zc(&errmsg);
> + }
> +
> + free(ctl);
> + return found;
> +}
> +
> +static void wait_for_completions_zc(int peerfd)
> +{
> + struct pollfd pfd = { .fd = peerfd, .events = POLLERR };
> + struct timespec start, now;
> + int timeout_ms = 5000;
> +
> + if (cfg_time > 0)
> + timeout_ms = cfg_time;
> +
> + clock_gettime(CLOCK_MONOTONIC, &start);
> + for (;;) {
> + long elapsed_ms, remaining_ms;
> +
> + if (drain_errqueue_zc(peerfd))
> + break;
[Severity: Medium]
Does wait_for_completions_zc() return as soon as the first
SO_EE_ORIGIN_ZEROCOPY notification arrives rather than waiting for all
issued sendmsg(MSG_ZEROCOPY) calls to complete?
Each sendmsg() in do_sendmsg_zc() allocates a new notification ID in
mptcp_sendmsg() via msg_zerocopy_realloc() (and in TCP whenever the 512 KB
byte limit is exceeded), so transfers larger than SO_SNDBUF (clamped to
sysctl_wmem_max) produce multiple completion IDs. Stopping after the
first cmsg without checking the completed [serr->ee_info, serr->ee_data]
range against the number of sendmsg() calls causes do_sendmsg_zc() to call
free(buf) while later zero-copy segments are still pinned and in flight,
and leaves unread notifications on sk_error_queue.
> +
> + clock_gettime(CLOCK_MONOTONIC, &now);
> + elapsed_ms = (now.tv_sec - start.tv_sec) * 1000L +
> + (now.tv_nsec - start.tv_nsec) / 1000000L;
> + if (elapsed_ms >= timeout_ms)
> + break;
> +
> + remaining_ms = timeout_ms - elapsed_ms;
> + if (remaining_ms > 200)
> + remaining_ms = 200;
> + if (poll(&pfd, 1, remaining_ms) < 0)
> + break;
> + }
> +}
> +
> +static int do_sendmsg_zc(int infd, int peerfd, size_t size,
> + struct wstate *winfo)
> +{
> + struct iovec iov = {};
> + struct msghdr msg = {
> + .msg_iov = &iov,
> + .msg_iovlen = 1,
> + };
> + size_t sent = 0;
> + ssize_t ret;
> + void *buf;
> + int err;
> +
> + err = spool_buf(peerfd, winfo);
> + if (err)
> + return err;
> +
> + buf = malloc(size);
> + if (!buf) {
> + perror("malloc");
> + return 1;
> + }
> +
> + if (read(infd, buf, size) != (ssize_t)size) {
> + perror("read input");
> + err = 1;
> + goto out;
> + }
[Severity: Low]
Can a single unlooped read(infd, buf, size) fail on partial reads or EINTR
for large input files? In addition, set_sndbuf(peerfd, size * 2) in
copyfd_io_zc() multiplies unsigned int size by 2, which overflows signed
int in setsockopt(SO_SNDBUF) when size exceeds INT_MAX / 2.
> +
> + while (sent < size) {
> + iov.iov_base = buf + sent;
> + iov.iov_len = size - sent;
> +
> + ret = sendmsg(peerfd, &msg, MSG_ZEROCOPY);
> + if (ret <= 0) {
> + if (ret < 0) {
> + perror("sendmsg MSG_ZEROCOPY");
> + err = 1;
> + }
> + break;
> + }
> + sent += ret;
> + }
> + if (sent != size)
> + fprintf(stderr, "sendmsg short: %zu/%zu bytes queued\n",
> + sent, size);
> +
> + if (size > 0)
> + wait_for_completions_zc(peerfd);
[Severity: Medium]
Should do_sendmsg_zc() check sent > 0 instead of size > 0 before calling
wait_for_completions_zc(), and propagate completion and short-send
failures?
If the first sendmsg() fails (for example with ENOBUFS when RLIMIT_MEMLOCK
is exceeded), sent is 0 and no completion will ever be queued, yet
wait_for_completions_zc() still blocks for the full 5000 ms timeout.
Furthermore, wait_for_completions_zc() returns void (ignoring poll_timeout
from -t) so completion timeouts, poll() errors, and malloc() failures in
drain_errqueue_zc() return 0 from do_sendmsg_zc(); process_cmsg_zc() does
not check serr->ee_errno or SO_EE_CODE_ZEROCOPY_COPIED; and a 0 return
from sendmsg() with sent < size logs "sendmsg short" without setting
err = 1.
> +
> +out:
> + free(buf);
> + return err;
> +}
> +
> +static int copyfd_io_zc(int infd, int peerfd, int outfd, unsigned int size,
> + bool *in_closed_after_out, struct wstate *winfo)
> +{
> + socklen_t len;
> + int on = 1;
> + int err;
> +
> + set_sndbuf(peerfd, size * 2);
[ ... ]
> @@ -1054,6 +1230,17 @@ static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, struct
> &in_closed_after_out, winfo);
> break;
>
> + case CFG_MODE_ZEROCOPY:
> + file_size = get_infd_size(infd);
> + if (file_size < 0)
> + return file_size;
> + if (cfg_sockopt_types.mptfo && winfo->total_len &&
> + file_size >= winfo->total_len)
> + file_size -= winfo->total_len;
> + ret = copyfd_io_zc(infd, peerfd, outfd, file_size,
> + &in_closed_after_out, winfo);
> + break;
[Severity: Medium]
What happens when -o MPTFO is used with an input file of 8192 bytes or
smaller, or when -S is passed to configure SO_SNDBUF?
When MPTFO is enabled and the input file fits in winfo->buf (8192 bytes),
sock_connect_mptcp() reads the entire file into winfo->buf, so
file_size -= winfo->total_len reduces size to 0; copyfd_io_zc() then calls
set_sndbuf(peerfd, 0) and do_sendmsg_zc() calls malloc(0), which fails the
test on libcs where malloc(0) returns NULL. In addition, calling
set_sndbuf(peerfd, size * 2) unconditionally in copyfd_io_zc() overrides
any -S cfg_sndbuf option and sets SOCK_SNDBUF_LOCK, disabling TCP and
MPTCP send buffer autotuning.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795421388.git.tanggeliang@kylinos.cn?part=6
next prev parent reply other threads:[~2026-11-23 8:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 8:19 [PATCH mptcp-next v8 0/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-23 8:19 ` [PATCH mptcp-next v8 1/7] ipv4: fix uninitialized memory in zerocopy cmsg Geliang Tang
2026-11-23 8:37 ` sashiko-bot
2026-11-23 8:19 ` [PATCH mptcp-next v8 2/7] mptcp: use local variable tp in sendmsg_frag Geliang Tang
2026-11-23 8:19 ` [PATCH mptcp-next v8 3/7] mptcp: remove redundant orig_offset in carve_data_frag Geliang Tang
2026-11-23 8:19 ` [PATCH mptcp-next v8 4/7] mptcp: add MSG_ZEROCOPY support Geliang Tang
2026-11-23 8:46 ` sashiko-bot
2026-11-23 8:19 ` [PATCH mptcp-next v8 5/7] mptcp: handle SO_ZEROCOPY in setsockopt Geliang Tang
2026-11-23 8:36 ` sashiko-bot
2026-11-23 8:19 ` [PATCH mptcp-next v8 6/7] selftests: mptcp: connect: add zerocopy io mode Geliang Tang
2026-11-23 8:37 ` sashiko-bot [this message]
2026-11-23 8:19 ` [PATCH mptcp-next v8 7/7] selftests: mptcp: connect: cover zerocopy mode Geliang Tang
2026-11-23 10:42 ` [PATCH mptcp-next v8 0/7] mptcp: add MSG_ZEROCOPY support MPTCP CI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-228908@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=geliang@kernel.org \
--cc=mptcp@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox