From: sashiko-bot@kernel.org
To: "Hui Zhu" <hui.zhu@linux.dev>
Cc: tj@kernel.org, mkoutny@suse.com, hannes@cmpxchg.org, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 3/4] selftests/bpf: add thread_wq cgroup test
Date: Fri, 07 Aug 2026 07:19:51 +0000 [thread overview]
Message-ID: <20260807071952.0EE2E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <dbc676924bb41d1e943df252460e5068a4cf71ad.1786086076.git.zhuhui@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Missing memory barriers between the worker kthread and userspace polling can cause test flakiness on weakly-ordered architectures.
- [Medium] The test uses an arbitrary `sleep(2)` to wait for asynchronous map destruction, creating a race condition that can leak the cgroup.
--
--- Patch [3]: [PATCH bpf-next 3/4] selftests/bpf: add thread_wq cgroup test ---
commit 0a433d40343251b2dbfb625551f8882c1faf6d99
Author: Hui Zhu <zhuhui@kylinos.cn>
selftests/bpf: add thread_wq cgroup test
This commit adds test cases for bpf_thread_wq with cgroup attachment.
It tests execution both within a specified cgroup and without cgroup
attachment, verifying that callbacks run in the appropriate context.
> diff --git a/tools/testing/selftests/bpf/prog_tests/thread_wq_cgroup.c b/tools/testing/selftests/bpf/prog_tests/thread_wq_cgroup.c
> new file mode 100644
> index 0000000000000..7537b03f17e2a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/thread_wq_cgroup.c
> @@ -0,0 +1,87 @@
[ ... ]
> + for (waited_secs = 0; waited_secs < WAIT_TIMEOUT_SECS; waited_secs++) {
> + if (skel->bss->twq_done)
> + break;
> + sleep(1);
> + }
> + if (!ASSERT_TRUE(skel->bss->twq_done, "twq_done in cgroup"))
> + goto cleanup;
> + if (!ASSERT_EQ(skel->bss->callback_cgroup_id, cg_id,
> + "callback_cgroup_id in cgroup"))
[Severity: Medium]
Could this result in spurious test failures on architectures with weak memory
ordering?
Since the userspace reader loops and polls the twq_done flag without an
acquire memory barrier, might it observe twq_done == 1 but read a stale
callback_cgroup_id of 0, thus failing the check in test_thread_wq_cgroup()?
> + goto cleanup;
> +
> + /* Run bpf_thread_wq without cgroup attachment (cgroup_id = 0). */
[ ... ]
> +cleanup:
> + if (skel) {
> + thread_wq_cgroup__destroy(skel);
> + /* Wait thread_wq kthread quit. */
> + sleep(2);
> + }
> + if (cg_fd >= 0)
> + close(cg_fd);
> + cleanup_cgroup_environment();
> +}
[Severity: Medium]
Is it possible for the test cgroup to leak if the map destruction takes
longer than 2 seconds?
The cleanup path relies on an arbitrary sleep(2) to wait for asynchronous map
destruction. When thread_wq_cgroup__destroy() closes the map file descriptor,
it triggers deferred map destruction via a system workqueue.
If the system is under heavy load and this takes longer than 2 seconds,
could cleanup_cgroup_environment() attempt to remove the test cgroup while
the kthread is still attached, causing the removal to fail with -EBUSY?
> diff --git a/tools/testing/selftests/bpf/progs/thread_wq_cgroup.c b/tools/testing/selftests/bpf/progs/thread_wq_cgroup.c
> new file mode 100644
> index 0000000000000..c70a37f55397d
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/thread_wq_cgroup.c
> @@ -0,0 +1,56 @@
[ ... ]
> +__u64 target_cgroup_id;
> +__u64 callback_cgroup_id;
> +int twq_done;
> +int test_key;
> +
> +static int twq_callback(void *map, int *key, void *value)
> +{
> + callback_cgroup_id = bpf_get_current_cgroup_id();
> + twq_done = 1;
> + return 0;
> +}
[Severity: Medium]
Can this write ordering lead to stale payload reads in userspace on weakly
ordered architectures?
The BPF worker kthread stores callback_cgroup_id and then sets twq_done = 1
without a release memory barrier. Can the CPU or compiler reorder these
operations in twq_callback(), allowing userspace to see twq_done == 1
before the payload is visible?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1786086076.git.zhuhui@kylinos.cn?part=3
next prev parent reply other threads:[~2026-08-07 7:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 7:01 [PATCH bpf-next 0/4] bpf: BPF-driven proactive memcg reclaim Hui Zhu
2026-08-07 7:01 ` [PATCH bpf-next 1/4] mm/bpf: Add bpf_try_to_free_mem_cgroup_pages kfunc Hui Zhu
2026-08-07 7:23 ` sashiko-bot
2026-08-07 7:01 ` [PATCH bpf-next 2/4] bpf: add bpf_thread_wq kthread-backed workqueue with cgroup placement Hui Zhu
2026-08-07 7:42 ` sashiko-bot
2026-08-11 21:52 ` Mykyta Yatsenko
2026-08-07 7:04 ` [PATCH bpf-next 3/4] selftests/bpf: add thread_wq cgroup test Hui Zhu
2026-08-07 7:19 ` sashiko-bot [this message]
2026-08-07 7:04 ` [PATCH bpf-next 4/4] selftests/bpf: add memcg async reclaim test for bpf_wq/bpf_thread_wq Hui Zhu
2026-08-07 7:30 ` sashiko-bot
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=20260807071952.0EE2E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hui.zhu@linux.dev \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
/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.