mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats
@ 2026-10-09  2:04 Qiliang Yuan
  2026-10-09  2:04 ` [PATCH bpf-next v2 1/2] selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private Qiliang Yuan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qiliang Yuan @ 2026-10-09  2:04 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai,
	Alexei Starovoitov, Daniel Borkmann, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Shuah Khan, Yosry Ahmed, Hao Luo
  Cc: bpf, linux-kselftest, linux-kernel, Qiliang Yuan

cgroup_hierarchical_stats mounts a bpffs on /sys/fs/bpf to pin its
iterators, then moves into a private mount namespace to set up its
cgroups, and unmounts the bpffs in the end if it mounted it itself.

The bpffs lands in the mount namespace shared with the tests running
in parallel, on top of the one already there, and hides what they pin,
which makes bpftool_maps_access and bpftool_metadata fail now and then.
The unmount can't remove it from there, and it checks the other way
around whether the test mounted a bpffs anyway.

Patch 1 mounts the bpffs in the private mount namespace, patch 2 makes
the cleanup unmount the bpffs that the test mounted.

Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
---
V1 -> V2:
- Mount the bpffs in the private mount namespace instead of skipping the
  mount when /sys/fs/bpf is a bpffs already (Yosry, CI bot)
- Put that patch first, so that the unmount fix applies to a bpffs it can
  actually unmount
- Pick up Reviewed-by from Yosry on the unmount fix

v1: https://lore.kernel.org/r/20261008-selftests-bpf-cgroup-stats-bpffs-v1-0-76b9a6d1be34@gmail.com

---
Qiliang Yuan (2):
      selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private
      selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted

 tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
---
base-commit: e1d84a37cba984388988d2f1ddc84561413f0db2
change-id: 20261008-selftests-bpf-cgroup-stats-bpffs-4534db24d15c

Best regards,
-- 
Qiliang Yuan <odys.yuan@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf-next v2 1/2] selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private
  2026-10-09  2:04 [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats Qiliang Yuan
@ 2026-10-09  2:04 ` Qiliang Yuan
  2026-10-09  2:04 ` [PATCH bpf-next v2 2/2] selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted Qiliang Yuan
  2026-10-16  3:00 ` [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Qiliang Yuan @ 2026-10-09  2:04 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai,
	Alexei Starovoitov, Daniel Borkmann, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Shuah Khan, Yosry Ahmed, Hao Luo
  Cc: bpf, linux-kselftest, linux-kernel, Qiliang Yuan

setup_hierarchy() mounts a bpffs on /sys/fs/bpf with setup_bpffs(), and
then sets up the cgroups with setup_cgroups(), which moves the test into
a private mount namespace.

The bpffs thus lands in the mount namespace that test_progs shares with
the tests running in parallel, on top of the bpffs already there, and
hides what they pin. cleanup_bpffs() later runs in the private mount
namespace and can't unmount it, so it stays there for good.
bpftool_maps_access then fails to pin an iterator because
/sys/fs/bpf/test_bpftool_map doesn't exist anymore, and bpftool_metadata
can't find the program it pinned in /sys/fs/bpf/test_metadata.

Set up the cgroups first, so that the bpffs is mounted in the private
mount namespace.

Fixes: 88886309d2e8 ("selftests/bpf: add a selftest for cgroup hierarchical stats collection")
Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c b/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c
index 3bd27d2ea668c..ad19d6d41918a 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c
@@ -151,7 +151,7 @@ static void cleanup_cgroups(void)
 /* Sets up cgroup hiearchary, returns 0 on success. */
 static int setup_hierarchy(void)
 {
-	return setup_bpffs() || setup_cgroups();
+	return setup_cgroups() || setup_bpffs();
 }
 
 static void destroy_hierarchy(void)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf-next v2 2/2] selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted
  2026-10-09  2:04 [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats Qiliang Yuan
  2026-10-09  2:04 ` [PATCH bpf-next v2 1/2] selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private Qiliang Yuan
@ 2026-10-09  2:04 ` Qiliang Yuan
  2026-10-16  3:00 ` [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Qiliang Yuan @ 2026-10-09  2:04 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Ihor Solodrai,
	Alexei Starovoitov, Daniel Borkmann, Kumar Kartikeya Dwivedi,
	Martin KaFai Lau, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, Shuah Khan, Yosry Ahmed, Hao Luo
  Cc: bpf, linux-kselftest, linux-kernel, Qiliang Yuan

setup_bpffs() mounts a bpffs on /sys/fs/bpf and records in mounted_bpffs
whether it did, so that cleanup_bpffs() unmounts only a bpffs that the
test mounted itself.

cleanup_bpffs() checks the flag the other way around. As mounting on
/sys/fs/bpf succeeds even when a bpffs is already there, the test never
unmounts the bpffs it mounted, and every run leaves another one stacked
on /sys/fs/bpf of the mount namespace that the test_progs worker keeps
running later tests in.

Unmount the bpffs only when setup_bpffs() mounted it.

Fixes: 88886309d2e8 ("selftests/bpf: add a selftest for cgroup hierarchical stats collection")
Signed-off-by: Qiliang Yuan <odys.yuan@gmail.com>
Reviewed-by: Yosry Ahmed <yosry@kernel.org>
---
 tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c b/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c
index ad19d6d41918a..cc6ab2c263da1 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c
@@ -110,7 +110,7 @@ static void cleanup_bpffs(void)
 	ASSERT_OK(rmdir(BPFFS_ATTACH_COUNTERS), "rmdir "BPFFS_ATTACH_COUNTERS);
 
 	/* Unmount bpffs, if it wasn't already mounted when we started */
-	if (mounted_bpffs)
+	if (!mounted_bpffs)
 		return;
 
 	ASSERT_OK(umount(BPFFS_ROOT), "unmount bpffs");

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats
  2026-10-09  2:04 [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats Qiliang Yuan
  2026-10-09  2:04 ` [PATCH bpf-next v2 1/2] selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private Qiliang Yuan
  2026-10-09  2:04 ` [PATCH bpf-next v2 2/2] selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted Qiliang Yuan
@ 2026-10-16  3:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-10-16  3:00 UTC (permalink / raw)
  To: Qiliang Yuan
  Cc: andrii, eddyz87, ihor.solodrai, ast, daniel, memxor, martin.lau,
	song, yonghong.song, jolsa, emil, shuah, yosry, haoluo, bpf,
	linux-kselftest, linux-kernel

Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Fri, 09 Oct 2026 10:04:36 +0800 you wrote:
> cgroup_hierarchical_stats mounts a bpffs on /sys/fs/bpf to pin its
> iterators, then moves into a private mount namespace to set up its
> cgroups, and unmounts the bpffs in the end if it mounted it itself.
> 
> The bpffs lands in the mount namespace shared with the tests running
> in parallel, on top of the one already there, and hides what they pin,
> which makes bpftool_maps_access and bpftool_metadata fail now and then.
> The unmount can't remove it from there, and it checks the other way
> around whether the test mounted a bpffs anyway.
> 
> [...]

Here is the summary with links:
  - [bpf-next,v2,1/2] selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private
    https://git.kernel.org/bpf/bpf-next/c/3c824dfd17e6
  - [bpf-next,v2,2/2] selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted
    https://git.kernel.org/bpf/bpf-next/c/e0645cfd0e1b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-16  3:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09  2:04 [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats Qiliang Yuan
2026-10-09  2:04 ` [PATCH bpf-next v2 1/2] selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private Qiliang Yuan
2026-10-09  2:04 ` [PATCH bpf-next v2 2/2] selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted Qiliang Yuan
2026-10-16  3:00 ` [PATCH bpf-next v2 0/2] selftests/bpf: Fix the bpffs handling of cgroup_hierarchical_stats patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®