All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jakub Sitnicki" <jakub@cloudflare.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] selftests/bpf: Cover concurrent sockmap update and delete
Date: Fri, 30 Oct 2026 12:13:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-190999@kernel.org> (raw)
In-Reply-To: <20261030-bpf-next-v1-1-035eabf8eae7@cloudflare.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Low] selftests/bpf: non-standard multi-line comments in sockmap_listen.c
- [Low] selftests/bpf: deprecated CHECK_FAIL wrappers used in test_update_delete_with_prog()
--

commit c179b4e18de0bb4b1070c566c62402a2a9a2d3f1
Author: Jakub Sitnicki <jakub@cloudflare.com>

selftests/bpf: Cover concurrent sockmap update and delete

This commit adds a sockmap_listen subtest that concurrently inserts and
deletes a TCP socket in a sockmap with an attached verdict program to
exercise races between insert and delete paths under KCSAN.

> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
> index 235e1d56f044f..dca1f0de92e0e 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c
> @@ -646,6 +646,82 @@ static void test_race_insert_listen(struct test_sockmap_listen *skel __always_un
>  	xclose(s);
>  }
>  
> +struct update_delete_ctx {
> +	unsigned int nr_iter;
> +	unsigned int done;
> +	int mapfd;
> +};
> +
> +static void *delete_elem_thread(void *arg)
> +{
> +	struct update_delete_ctx *ctx = arg;
> +	unsigned int i;
> +
> +	for (i = 0; i < ctx->nr_iter; i++) {
> +		/* Expecting EINVAL (sockmap) or ENOENT (sockhash) when the
> +		 * entry is already gone.
> +		 */
> +		if (bpf_map_delete_elem(ctx->mapfd, &(u32){0}) &&
> +		    errno != EINVAL && errno != ENOENT) {
> +			FAIL_ERRNO("map_delete");
> +			break;
> +		}
> +	}
> +
> +	WRITE_ONCE(ctx->done, 1);
> +	return NULL;
> +}
> +
> +/* One thread keeps inserting a socket into a sockmap with an attached
> + * verdict program while another thread deletes the same map entry.
> + */
> +static void test_update_delete_with_prog(struct test_sockmap_listen *skel,
> +					 int family, int sotype, int mapfd)
> +{
> +	struct update_delete_ctx ctx = { 0 };
> +	int err, s, verdict;
> +	pthread_t t;
> +	u64 value;
> +
> +	verdict = bpf_program__fd(skel->progs.prog_skb_verdict);
> +	err = xbpf_prog_attach(verdict, mapfd, BPF_SK_SKB_VERDICT, 0);
> +	if (err)
> +		return;
> +
> +	s = xsocket(family, sotype, 0);
> +	if (s < 0)
> +		goto detach;
> +
> +	err = xlisten(s, 1);
> +	if (err)
> +		goto close;
> +
> +	ctx.mapfd = mapfd;
> +	ctx.nr_iter = 10000;
> +
> +	err = xpthread_create(&t, NULL, delete_elem_thread, &ctx);
> +	if (err)
> +		goto close;
> +
> +	value = s;
> +	while (!READ_ONCE(ctx.done)) {
> +		/* Expecting EBUSY while a deleted socket's psock still
> +		 * holds the verdict program.
> +		 */

[Severity: Low]
This isn't a bug, but should the three new multi-line comments in
delete_elem_thread() and test_update_delete_with_prog() in
tools/testing/selftests/bpf/prog_tests/sockmap_listen.c place the opening
/* on its own line with the comment text starting on the following line to
match BPF coding style conventions?

> +		err = bpf_map_update_elem(mapfd, &(u32){0}, &value, BPF_ANY);
> +		if (err && errno != EBUSY) {
> +			FAIL_ERRNO("map_update");
> +			break;
> +		}

[Severity: Low]
In tools/testing/selftests/bpf/prog_tests/socket_helpers.h, FAIL_ERRNO()
and the x* helper wrappers (such as xbpf_prog_attach(), xsocket(),
xlisten(), xpthread_create(), xpthread_join(), xclose(), and
xbpf_prog_detach2()) report failures through _FAIL(), which expands to the
deprecated CHECK_FAIL() macro:

#define _FAIL(errnum, fmt...)                                                  \
	({                                                                     \
		error_at_line(0, (errnum), __func__, __LINE__, fmt);           \
		CHECK_FAIL(true);                                              \
	})

Could delete_elem_thread() and test_update_delete_with_prog() in
tools/testing/selftests/bpf/prog_tests/sockmap_listen.c use the ASSERT_*()
macros from test_progs.h (such as ASSERT_OK(), ASSERT_OK_FD(), and
ASSERT_TRUE() or ASSERT_EQ()) instead of FAIL_ERRNO() and the CHECK_FAIL()
wrappers when checking setup and map update/delete results?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261030-bpf-next-v1-0-035eabf8eae7@cloudflare.com?part=1

  reply	other threads:[~2026-10-30 12:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 12:01 [PATCH bpf-next 0/2] Fix psock update-side data races on sk->sk_prot and progs Jakub Sitnicki
2026-10-30 12:01 ` [PATCH bpf-next 1/2] selftests/bpf: Cover concurrent sockmap update and delete Jakub Sitnicki
2026-10-30 12:13   ` sashiko-bot [this message]
2026-10-30 12:01 ` [PATCH bpf-next 2/2] bpf, sockmap: Fix psock update-side data races on sk->sk_prot and progs Jakub Sitnicki
2026-10-30 12:45   ` bot+bpf-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-190999@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=jakub@cloudflare.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 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.