Skip to contentSkip to conversation

bpf/selftests: Fix namespace mount setup in tc_redirect

PATCH Applied Jiri Olsa 3 participants 6 messages Jan 4, 2022 – Jan 19, 2022

Subsystems (5)
lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

PATCH 1/1 bpf/selftests: Fix namespace mount setup in tc_redirect

The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests.

  # cat /proc/self/mountinfo | grep debugfs
  34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw
  # cat /proc/self/mountinfo | grep sysfs
  23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw
  # mount | grep debugfs
  debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
  # ./test_progs -t tc_redirect
  #164 tc_redirect:OK
  Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
  # mount | grep debugfs
  # cat /proc/self/mountinfo | grep debugfs
  # cat /proc/self/mountinfo | grep sysfs
  25 86 0:22 / /sys rw,relatime shared:2 - sysfs sysfs rw

Making the sysfs private under the new namespace so the umount won't trigger the global sysfs umount.

---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/bpf/prog_tests/tc_redirect.c +7 -0
index 4b18b73df10b..c2426df58e17 100644
@@ -105,6 +105,13 @@ static int setns_by_fd(int nsfd)
 	if (!ASSERT_OK(err, "unshare"))
 		return err;
 
+	/* Make our /sys mount private, so the following umount won't
+	 * trigger the global umount in case it's shared.
+	 */
+	err = mount("none", "/sys", NULL, MS_PRIVATE, NULL);
+	if (!ASSERT_OK(err, "remount private /sys"))
+		return err;
+
 	err = umount2("/sys", MNT_DETACH);
 	if (!ASSERT_OK(err, "umount2 /sys"))
 		return err;
Signature · 1 line
2.33.1
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 6 lines · On Tue, 4 Jan 2022 13:10:30 +0100 you wrote:

The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests.

Quoted 8 lines
  # cat /proc/self/mountinfo | grep debugfs
  34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw
  # cat /proc/self/mountinfo | grep sysfs
  23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw
  # mount | grep debugfs
  debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)

[...]

Here is the summary with links:
- bpf/selftests: Fix namespace mount setup in tc_redirect

    https://git.kernel.org/bpf/bpf-next/c/5e22dd186267

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#2 lore raw
In reply to Jiri Olsa
Quoted 18 lines · Jiri Olsa

The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests.

  # cat /proc/self/mountinfo | grep debugfs
  34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw
  # cat /proc/self/mountinfo | grep sysfs
  23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw
  # mount | grep debugfs
  debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
  # ./test_progs -t tc_redirect
  #164 tc_redirect:OK
  Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
Quoted 7 lines
  # mount | grep debugfs
  # cat /proc/self/mountinfo | grep debugfs
  # cat /proc/self/mountinfo | grep sysfs
  25 86 0:22 / /sys rw,relatime shared:2 - sysfs sysfs rw

Making the sysfs private under the new namespace so the umount won't trigger the global sysfs umount.

Hey Jiri,

Thanks for the fix. Did you try making tc_redirect non-serial again (s/serial_test_tc_redirect/test_tc_redirect/) and doing parallelized test_progs run (./test_progs -j) in a tight loop for a while? I suspect this might have been an issue forcing us to make this test serial in the first place, so now that it's fixed, we can make parallel test_progs a bit faster.

Quoted 29 lines
---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/bpf/prog_tests/tc_redirect.c +7 -1
index 4b18b73df10b..c2426df58e17 100644
@@ -105,6 +105,13 @@ static int setns_by_fd(int nsfd)
        if (!ASSERT_OK(err, "unshare"))
                return err;
 
+       /* Make our /sys mount private, so the following umount won't
+        * trigger the global umount in case it's shared.
+        */
+       err = mount("none", "/sys", NULL, MS_PRIVATE, NULL);
+       if (!ASSERT_OK(err, "remount private /sys"))
+               return err;
+
        err = umount2("/sys", MNT_DETACH);
        if (!ASSERT_OK(err, "umount2 /sys"))
                return err;
--

2.33.1

author
#3 lore raw
Quoted 27 lines · Andrii Nakryiko
Quoted 18 lines · Jiri Olsa

The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests.

  # cat /proc/self/mountinfo | grep debugfs
  34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw
  # cat /proc/self/mountinfo | grep sysfs
  23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw
  # mount | grep debugfs
  debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
  # ./test_progs -t tc_redirect
  #164 tc_redirect:OK
  Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
Quoted 7 lines
  # mount | grep debugfs
  # cat /proc/self/mountinfo | grep debugfs
  # cat /proc/self/mountinfo | grep sysfs
  25 86 0:22 / /sys rw,relatime shared:2 - sysfs sysfs rw

Making the sysfs private under the new namespace so the umount won't trigger the global sysfs umount.

Quoted 8 lines

Hey Jiri,

Thanks for the fix. Did you try making tc_redirect non-serial again (s/serial_test_tc_redirect/test_tc_redirect/) and doing parallelized test_progs run (./test_progs -j) in a tight loop for a while? I suspect this might have been an issue forcing us to make this test serial in the first place, so now that it's fixed, we can make parallel test_progs a bit faster.

hi,
right, will try

jirka

Quoted 31 lines
Quoted 30 lines
---
 tools/testing/selftests/bpf/prog_tests/tc_redirect.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/bpf/prog_tests/tc_redirect.c +7 -1
index 4b18b73df10b..c2426df58e17 100644
@@ -105,6 +105,13 @@ static int setns_by_fd(int nsfd)
        if (!ASSERT_OK(err, "unshare"))
                return err;
 
+       /* Make our /sys mount private, so the following umount won't
+        * trigger the global umount in case it's shared.
+        */
+       err = mount("none", "/sys", NULL, MS_PRIVATE, NULL);
+       if (!ASSERT_OK(err, "remount private /sys"))
+               return err;
+
        err = umount2("/sys", MNT_DETACH);
        if (!ASSERT_OK(err, "umount2 /sys"))
                return err;
--

2.33.1

author
#4 lore raw
Quoted 37 lines · Jiri Olsa
Quoted 27 lines · Andrii Nakryiko
Quoted 18 lines · Jiri Olsa

The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests.

  # cat /proc/self/mountinfo | grep debugfs
  34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw
  # cat /proc/self/mountinfo | grep sysfs
  23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw
  # mount | grep debugfs
  debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
  # ./test_progs -t tc_redirect
  #164 tc_redirect:OK
  Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
Quoted 7 lines
  # mount | grep debugfs
  # cat /proc/self/mountinfo | grep debugfs
  # cat /proc/self/mountinfo | grep sysfs
  25 86 0:22 / /sys rw,relatime shared:2 - sysfs sysfs rw

Making the sysfs private under the new namespace so the umount won't trigger the global sysfs umount.

Quoted 8 lines

Hey Jiri,

Thanks for the fix. Did you try making tc_redirect non-serial again (s/serial_test_tc_redirect/test_tc_redirect/) and doing parallelized test_progs run (./test_progs -j) in a tight loop for a while? I suspect this might have been an issue forcing us to make this test serial in the first place, so now that it's fixed, we can make parallel test_progs a bit faster.

Quoted 2 lines

hi,
right, will try

so I can't reproduce the issue in the first place - that means without my fix and with reverted serial_test_tc_redirect change - by running parallelized test_progs, could you guys try it?

jirka

#5 lore raw
Quoted 39 lines · Jiri Olsa
Quoted 37 lines · Jiri Olsa
Quoted 35 lines · Andrii Nakryiko
Quoted 18 lines · Jiri Olsa

The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests.

  # cat /proc/self/mountinfo | grep debugfs
  34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw
  # cat /proc/self/mountinfo | grep sysfs
  23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw
  # mount | grep debugfs
  debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
  # ./test_progs -t tc_redirect
  #164 tc_redirect:OK
  Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
Quoted 7 lines
  # mount | grep debugfs
  # cat /proc/self/mountinfo | grep debugfs
  # cat /proc/self/mountinfo | grep sysfs
  25 86 0:22 / /sys rw,relatime shared:2 - sysfs sysfs rw

Making the sysfs private under the new namespace so the umount won't trigger the global sysfs umount.

Hey Jiri,

Thanks for the fix. Did you try making tc_redirect non-serial again (s/serial_test_tc_redirect/test_tc_redirect/) and doing parallelized test_progs run (./test_progs -j) in a tight loop for a while? I suspect this might have been an issue forcing us to make this test serial in the first place, so now that it's fixed, we can make parallel test_progs a bit faster.

Quoted 7 lines
Quoted 2 lines

hi,
right, will try

so I can't reproduce the issue in the first place - that means without my fix and with reverted serial_test_tc_redirect change - by running parallelized test_progs, could you guys try it?

I tried it for a bunch of iterations and didn't repro it either. Doesn't mean much as CI's environment is different, but I think it might be worth making it parallel again and see if it reproes in CI again.

Quoted 2 lines

jirka