[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fa80d5a7-790d-4f10-bef3-f5c708218f83@linux.dev>
Date: Wed, 15 Oct 2025 12:07:38 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Kuniyuki Iwashima <kuniyu@...gle.com>
Cc: Alexei Starovoitov <ast@...nel.org>, Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
John Fastabend <john.fastabend@...il.com>,
Stanislav Fomichev <sdf@...ichev.me>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Neal Cardwell <ncardwell@...gle.com>, Willem de Bruijn <willemb@...gle.com>,
Mina Almasry <almasrymina@...gle.com>,
Roman Gushchin <roman.gushchin@...ux.dev>,
Shakeel Butt <shakeel.butt@...ux.dev>, Kuniyuki Iwashima
<kuni1840@...il.com>, bpf@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH v2 bpf-next/net 6/6] selftest: bpf: Add test for
sk->sk_bypass_prot_mem.
On 10/14/25 4:54 PM, Kuniyuki Iwashima wrote:
> +static int tcp_create_sockets(struct test_case *test_case, int sk[], int len)
> +{
> + int server, i, err = 0;
> +
> + server = start_server(test_case->family, test_case->type, NULL, 0, 0);
> + if (!ASSERT_GE(server, 0, "start_server_str"))
> + return server;
> +
> + /* Keep for-loop so we can change NR_SOCKETS easily. */
> + for (i = 0; i < len; i += 2) {
> + sk[i] = connect_to_fd(server, 0);
> + if (sk[i] < 0) {
> + ASSERT_GE(sk[i], 0, "connect_to_fd");
> + err = sk[i];
> + break;
> + }
> +
> + sk[i + 1] = accept(server, NULL, NULL);
> + if (sk[i + 1] < 0) {
> + ASSERT_GE(sk[i + 1], 0, "accept");
> + err = sk[i + 1];
> + break;
> + }
> + }
> +
> + close(server);
> +
> + return err;
> +}
> +
> +static int check_bypass(struct test_case *test_case,
> + struct sk_bypass_prot_mem *skel, bool bypass)
> +{
> + char buf[BUF_SINGLE] = {};
> + long memory_allocated[2];
> + int sk[NR_SOCKETS] = {};
> + int err, i, j;
> +
> + err = test_case->create_sockets(test_case, sk, ARRAY_SIZE(sk));
> + if (err)
> + goto close;
> +
> + memory_allocated[0] = test_case->get_memory_allocated(test_case, skel);
> +
> + /* allocate pages >= NR_PAGES */
> + for (i = 0; i < ARRAY_SIZE(sk); i++) {
> + for (j = 0; j < NR_SEND; j++) {
> + int bytes = send(sk[i], buf, sizeof(buf), 0);
> +
> + /* Avoid too noisy logs when something failed. */
> + if (bytes != sizeof(buf)) {
> + ASSERT_EQ(bytes, sizeof(buf), "send");
> + if (bytes < 0) {
> + err = bytes;
> + goto drain;
> + }
> + }
> + }
> + }
> +
> + memory_allocated[1] = test_case->get_memory_allocated(test_case, skel);
> +
> + if (bypass)
> + ASSERT_LE(memory_allocated[1], memory_allocated[0] + 10, "bypass");
> + else
> + ASSERT_GT(memory_allocated[1], memory_allocated[0] + NR_PAGES, "no bypass");
> +
> +drain:
> + if (test_case->type == SOCK_DGRAM) {
> + /* UDP starts purging sk->sk_receive_queue after one RCU
> + * grace period, then udp_memory_allocated goes down,
> + * so drain the queue before close().
> + */
> + for (i = 0; i < ARRAY_SIZE(sk); i++) {
> + for (j = 0; j < NR_SEND; j++) {
> + int bytes = recv(sk[i], buf, 1, MSG_DONTWAIT | MSG_TRUNC);
> +
> + if (bytes == sizeof(buf))
> + continue;
> + if (bytes != -1 || errno != EAGAIN)
> + PRINT_FAIL("bytes: %d, errno: %s\n", bytes, strerror(errno));
> + break;
> + }
> + }
> + }
> +
> +close:
> + for (i = 0; i < ARRAY_SIZE(sk); i++) {
> + if (sk[i] <= 0)
Theoretically, 0 is a legit fd. The tcp_create_sockets above is also testing
ASSERT_GE(sk[i], 0, ...). I changed to test "< 0" here and initialize all sk[]
to -1 at the beginning of this function.
> + break;
> +
> + close(sk[i]);
> + }
> +
> + return err;
> +}
> +
> +struct test_case test_cases[] = {
Added static.
Applied. Thanks.
Powered by blists - more mailing lists