From: sashiko-bot@kernel.org
To: "Nnamdi Onyeyiri" <nnamdio@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4 2/2] bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup
Date: Wed, 15 Jul 2026 21:47:08 +0000 [thread overview]
Message-ID: <20260715214709.518671F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260715213538.37229-3-nnamdio@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Flaky test assertion due to jiffy-based timeout resolution.
- [Medium] Infinite busy-loop in server thread on fatal socket error.
--
--- Patch [2]: [PATCH v4 2/2] bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup ---
commit f1fdd86e116d5c194a4d7e31256e4a2e38d105e0
Author: Nnamdi Onyeyiri <nnamdio@gmail.com>
bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup
This commit adds a selftest to ensure tcp_bpf_recvmsg() and
tcp_bpf_recvmsg_parser() correctly handle spurious wakeups in
tcp_msg_wait_data(). It verifies that recvfrom() doesn't return EAGAIN without
a timeout and properly respects SO_RCVTIMEO when configured.
> diff --git a/tools/testing/selftests/net/sockmap_recvfrom.c b/tools/testing/selftests/net/sockmap_recvfrom.c
> new file mode 100644
> index 0000000000000..25657fc3dbcd2
> --- /dev/null
> +++ b/tools/testing/selftests/net/sockmap_recvfrom.c
[ ... ]
> +static void process_client(int fd, atomic_int *running, bool *failed)
> +{
[ ... ]
> + while (atomic_load(running)) {
> + ssize_t len = recvfrom(fd, buf, sizeof(buf), 0, NULL, NULL);
> +
> + if (len == -1) {
> + if (errno != EAGAIN && errno != EINTR)
> + *failed = true;
> + continue;
[Severity: Medium]
Will this result in an infinite busy-loop if a fatal socket error occurs?
If recvfrom() encounters a fatal error like ECONNRESET, *failed is set to true
but the loop continues. Since the socket remains in an error state, subsequent
calls to recvfrom() will immediately return -1 without blocking.
This creates a tight busy-wait loop that starves the CPU until the global test
timeout intervenes. Should this break out of the loop on fatal errors instead?
> + }
> +
> + if (len <= 0 || buf[len - 1] == PAYLOAD_END)
> + break;
> + }
[ ... ]
> +TEST_F(sockmap_recvfrom, with_timeout)
> +{
[ ... ]
> + for (int i = 0; i < MAX_ITERATIONS; ++i) {
> + struct timespec beg;
> + struct timespec end;
> + int err;
> +
> + int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
> +
> + ASSERT_NE(fd, -1);
> + ASSERT_EQ(connect(fd, (struct sockaddr *)&self->addr, sizeof(self->addr)), 0);
> +
> + ASSERT_EQ(send_payload(_metadata, fd, self->payload, self->payload_len), 0);
> +
> + ASSERT_EQ(setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)), 0);
> +
> + clock_gettime(CLOCK_MONOTONIC, &beg);
> + ASSERT_EQ(recvfrom(fd, ignored, sizeof(ignored), 0, NULL, NULL), -1);
> + err = errno;
> + clock_gettime(CLOCK_MONOTONIC, &end);
> +
> + ASSERT_EQ(err, EAGAIN);
> + ASSERT_GE(to_nanos(&end) - to_nanos(&beg), timeo.tv_usec * 1000);
[Severity: Medium]
Is it safe to assume strict microsecond precision for SO_RCVTIMEO here?
The test expects the blocked duration to be strictly greater than or equal to
5ms. However, in the kernel, socket timeouts are converted to jiffies via
sk_rcvtimeo.
On systems with HZ=100, 5ms translates to less than a jiffy. Even on HZ=1000,
waiting 5 jiffies can complete in slightly over 4ms depending on tick
alignment.
Because the test demands strict microsecond accuracy from a jiffy-based timer,
could this cause intermittent test failures?
> +
> + close(fd);
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260715213538.37229-1-nnamdio@gmail.com?part=2
next prev parent reply other threads:[~2026-07-15 21:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 18:43 [BUG] bpf, sockmap: spurious wakeup by tcp_msg_wait_data() causing unexpected EAGAIN in recvfrom() Nnamdi Onyeyiri
2026-07-09 18:55 ` sashiko-bot
2026-07-10 20:17 ` Nnamdi Onyeyiri
2026-07-13 4:14 ` Jiayuan Chen
2026-07-14 18:19 ` John Fastabend
2026-07-14 20:39 ` [PATCH v3 0/2] bpf, sockmap: handle spurious tcp_msg_wait_data() wakeup Nnamdi Onyeyiri
2026-07-14 20:39 ` [PATCH v3 1/2] " Nnamdi Onyeyiri
2026-07-14 20:51 ` sashiko-bot
2026-07-14 20:39 ` [PATCH v3 2/2] " Nnamdi Onyeyiri
2026-07-14 20:52 ` sashiko-bot
2026-07-15 21:35 ` [PATCH v4 0/2] " Nnamdi Onyeyiri
2026-07-15 21:35 ` [PATCH v4 1/2] " Nnamdi Onyeyiri
2026-07-15 21:35 ` [PATCH v4 2/2] " Nnamdi Onyeyiri
2026-07-15 21:47 ` sashiko-bot [this message]
2026-07-16 1:30 ` [PATCH v4 0/2] " Jiayuan Chen
2026-07-14 18:16 ` [BUG] bpf, sockmap: spurious wakeup by tcp_msg_wait_data() causing unexpected EAGAIN in recvfrom() John Fastabend
2026-07-14 20:47 ` Nnamdi Onyeyiri
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=20260715214709.518671F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=nnamdio@gmail.com \
--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