From: "Jiayuan Chen" <jiayuan.chen@linux.dev>
To: bpf@vger.kernel.org
Cc: "John Fastabend" <john.fastabend@gmail.com>,
"Jakub Sitnicki" <jakub@cloudflare.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Neal Cardwell" <ncardwell@google.com>,
"Kuniyuki Iwashima" <kuniyu@google.com>,
"David Ahern" <dsahern@kernel.org>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"KP Singh" <kpsingh@kernel.org>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Michal Luczaj" <mhal@rbox.co>,
"Cong Wang" <cong.wang@bytedance.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v8 3/3] bpf, selftest: Add tests for FIONREAD and copied_seq
Date: Sat, 24 Jan 2026 10:47:51 +0000 [thread overview]
Message-ID: <56db5e4bb54678e0615501693a5eee0b88e2bf3e@linux.dev> (raw)
In-Reply-To: <20260124061502.24350-4-jiayuan.chen@linux.dev>
January 24, 2026 at 14:14, "Jiayuan Chen" <jiayuan.chen@linux.dev mailto:jiayuan.chen@linux.dev?to=%22Jiayuan%20Chen%22%20%3Cjiayuan.chen%40linux.dev%3E > wrote:
[...]
> +
> +/* it is used to send data to via native stack and BPF redirecting */
> +static void test_sockmap_multi_channels(int sotype)
> +{
> + int map, err, sent, recvd, zero = 0, one = 1, avail = 0;
> + struct test_sockmap_pass_prog *skel = NULL;
> + int c0 = -1, p0 = -1, c1 = -1, p1 = -1;
> + char buf[10] = "0123456789", rcv[11];
> + struct bpf_program *prog;
> +
> + skel = test_sockmap_pass_prog__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "open_and_load"))
> + return;
> +
> + err = create_socket_pairs(AF_INET, sotype, &c0, &c1, &p0, &p1);
> + if (err)
> + goto end;
> +
> + prog = skel->progs.prog_skb_verdict_ingress;
> + map = bpf_map__fd(skel->maps.sock_map_rx);
> +
> + err = bpf_prog_attach(bpf_program__fd(prog), map, BPF_SK_SKB_STREAM_VERDICT, 0);
> + if (!ASSERT_OK(err, "bpf_prog_attach verdict"))
> + goto end;
> +
> + err = bpf_map_update_elem(map, &zero, &p0, BPF_ANY);
> + if (!ASSERT_OK(err, "bpf_map_update_elem(p0)"))
> + goto end;
> +
> + err = bpf_map_update_elem(map, &one, &p1, BPF_ANY);
> + if (!ASSERT_OK(err, "bpf_map_update_elem"))
> + goto end;
> +
> + /* send data to p1 via native stack */
> + sent = xsend(c1, buf, 2, 0);
> + if (!ASSERT_EQ(sent, 2, "xsend(2)"))
> + goto end;
> +
> + poll_read(p1, IO_TIMEOUT_SEC);
> + err = ioctl(p1, FIONREAD, &avail);
> + ASSERT_OK(err, "ioctl(FIONREAD) partial call");
> + ASSERT_EQ(avail, 2, "ioctl(FIONREAD) partial return");
> +
> + /* send data to p1 via bpf redirecting */
> + sent = xsend(c0, buf + 2, sizeof(buf) - 2, 0);
> + if (!ASSERT_EQ(sent, sizeof(buf) - 2, "xsend(remain-data)"))
> + goto end;
> +
> + poll_read(p1, IO_TIMEOUT_SEC);
It's a race in the test - poll_read() returns early because the first 2 bytes are
already in the queue, but the second send hasn't been processed yet.
Will fix with a polling wait for FIONREAD.
pw-bot: cr
> + err = ioctl(p1, FIONREAD, &avail);
> + ASSERT_OK(err, "ioctl(FIONREAD) full call");
> + ASSERT_EQ(avail, sotype == SOCK_DGRAM ? 2 : sizeof(buf), "ioctl(FIONREAD) full return");
> +
> + recvd = recv_timeout(p1, rcv, sizeof(rcv), MSG_DONTWAIT, 1);
> + if (!ASSERT_EQ(recvd, sizeof(buf), "recv_timeout(p1)") ||
> + !ASSERT_OK(memcmp(buf, rcv, recvd), "data mismatch"))
> + goto end;
> +end:
> + if (c0 >= 0)
> + close(c0);
> + if (p0 >= 0)
> + close(p0);
> + if (c1 >= 0)
> + close(c1);
> + if (p1 >= 0)
> + close(p1);
> + test_sockmap_pass_prog__destroy(skel);
> +}
> +
> void test_sockmap_basic(void)
> {
> if (test__start_subtest("sockmap create_update_free"))
> @@ -1108,4 +1363,14 @@ void test_sockmap_basic(void)
> test_sockmap_skb_verdict_vsock_poll();
> if (test__start_subtest("sockmap vsock unconnected"))
> test_sockmap_vsock_unconnected();
> + if (test__start_subtest("sockmap with zc"))
> + test_sockmap_zc();
> + if (test__start_subtest("sockmap recover"))
> + test_sockmap_copied_seq(false);
> + if (test__start_subtest("sockmap recover with strp"))
> + test_sockmap_copied_seq(true);
> + if (test__start_subtest("sockmap tcp multi channels"))
> + test_sockmap_multi_channels(SOCK_STREAM);
> + if (test__start_subtest("sockmap udp multi channels"))
> + test_sockmap_multi_channels(SOCK_DGRAM);
> }
> diff --git a/tools/testing/selftests/bpf/progs/test_sockmap_pass_prog.c b/tools/testing/selftests/bpf/progs/test_sockmap_pass_prog.c
> index 69aacc96db36..ef9edca184ea 100644
> --- a/tools/testing/selftests/bpf/progs/test_sockmap_pass_prog.c
> +++ b/tools/testing/selftests/bpf/progs/test_sockmap_pass_prog.c
> @@ -44,4 +44,18 @@ int prog_skb_parser(struct __sk_buff *skb)
> return SK_PASS;
> }
>
> +SEC("sk_skb/stream_verdict")
> +int prog_skb_verdict_ingress(struct __sk_buff *skb)
> +{
> + int one = 1;
> +
> + return bpf_sk_redirect_map(skb, &sock_map_rx, one, BPF_F_INGRESS);
> +}
> +
> +SEC("sk_skb/stream_parser")
> +int prog_skb_verdict_ingress_strp(struct __sk_buff *skb)
> +{
> + return skb->len;
> +}
> +
> char _license[] SEC("license") = "GPL";
> --
> 2.43.0
>
prev parent reply other threads:[~2026-01-24 10:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-24 6:14 [PATCH bpf-next v8 0/3] bpf: Fix FIONREAD and copied_seq issues Jiayuan Chen
2026-01-24 6:14 ` [PATCH bpf-next v8 1/3] bpf, sockmap: Fix incorrect copied_seq calculation Jiayuan Chen
2026-01-24 6:14 ` [PATCH bpf-next v8 2/3] bpf, sockmap: Fix FIONREAD for sockmap Jiayuan Chen
2026-01-24 6:14 ` [PATCH bpf-next v8 3/3] bpf, selftest: Add tests for FIONREAD and copied_seq Jiayuan Chen
2026-01-24 10:47 ` Jiayuan Chen [this message]
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=56db5e4bb54678e0615501693a5eee0b88e2bf3e@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=eddyz87@gmail.com \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=horms@kernel.org \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mhal@rbox.co \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.