linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] selftests/membarrier: Skip an unregistered memory barrier test on Musl
@ 2026-08-03 12:48 Chris Gellermann
  2026-08-03 12:48 ` [PATCH 1/2] selftests/membarrier: Introduce helper to get membarrier command registrations Chris Gellermann
  2026-08-03 12:49 ` [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc Chris Gellermann
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Gellermann @ 2026-08-03 12:48 UTC (permalink / raw)
  To: shuah, linux-kselftest
  Cc: richard.weiyang, akpm, reddybalavignesh9979, linux-kernel,
	Chris Gellermann

The membarrier test "membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED not
registered failure" fails in the multithreaded test scenario when using
Musl libc as the command gets preregistered implicitly during thread
creation. Skip the test if command registration is detected.

Chris Gellermann (2):
  selftests/membarrier: Introduce helper to get membarrier command
    registrations
  selftests/membarrier: Skip unpermitted membarrier command test if
    preregistered by libc

 .../selftests/membarrier/membarrier_test_impl.h | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

--
2.47.3

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

* [PATCH 1/2] selftests/membarrier: Introduce helper to get membarrier command registrations
  2026-08-03 12:48 [PATCH 0/2] selftests/membarrier: Skip an unregistered memory barrier test on Musl Chris Gellermann
@ 2026-08-03 12:48 ` Chris Gellermann
  2026-08-03 12:49 ` [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc Chris Gellermann
  1 sibling, 0 replies; 5+ messages in thread
From: Chris Gellermann @ 2026-08-03 12:48 UTC (permalink / raw)
  To: shuah, linux-kselftest
  Cc: richard.weiyang, akpm, reddybalavignesh9979, linux-kernel,
	Chris Gellermann

This allows reusage.

Signed-off-by: Chris Gellermann <christian.gellermann@codasip.com>
---
 tools/testing/selftests/membarrier/membarrier_test_impl.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/membarrier/membarrier_test_impl.h b/tools/testing/selftests/membarrier/membarrier_test_impl.h
index f6d7c44b2288..29aac3bc4988 100644
--- a/tools/testing/selftests/membarrier/membarrier_test_impl.h
+++ b/tools/testing/selftests/membarrier/membarrier_test_impl.h
@@ -16,6 +16,11 @@ static int sys_membarrier(int cmd, int flags)
 	return syscall(__NR_membarrier, cmd, flags);
 }
 
+static int membarrier_get_registrations(void)
+{
+	return sys_membarrier(MEMBARRIER_CMD_GET_REGISTRATIONS, 0);
+}
+
 static int test_membarrier_get_registrations(int cmd)
 {
 	int ret, flags = 0;
@@ -24,7 +29,7 @@ static int test_membarrier_get_registrations(int cmd)
 
 	registrations |= cmd;
 
-	ret = sys_membarrier(MEMBARRIER_CMD_GET_REGISTRATIONS, 0);
+	ret = membarrier_get_registrations();
 	if (ret < 0) {
 		ksft_exit_fail_msg(
 			"%s test: flags = %d, errno = %d\n",
-- 
2.47.3


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

* [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc
  2026-08-03 12:48 [PATCH 0/2] selftests/membarrier: Skip an unregistered memory barrier test on Musl Chris Gellermann
  2026-08-03 12:48 ` [PATCH 1/2] selftests/membarrier: Introduce helper to get membarrier command registrations Chris Gellermann
@ 2026-08-03 12:49 ` Chris Gellermann
  2026-08-03 20:31   ` Andrew Morton
  2026-08-03 20:37   ` Andrew Morton
  1 sibling, 2 replies; 5+ messages in thread
From: Chris Gellermann @ 2026-08-03 12:49 UTC (permalink / raw)
  To: shuah, linux-kselftest
  Cc: richard.weiyang, akpm, reddybalavignesh9979, linux-kernel,
	Chris Gellermann

On thread creation, Musl registers the private expedited memory barrier,
see pthread_create [1]. Thus, invoking the barrier command will no
longer be rejected by the kernel with EPERM. The test checking this will
fail. Check if the memory barrier command has been registered and skip
the test in this case.

Link: https://git.musl-libc.org/cgit/musl/tree/src/thread/pthread_create.c#n260 [1]
Signed-off-by: Chris Gellermann <christian.gellermann@codasip.com>
---
 .../selftests/membarrier/membarrier_test_impl.h        | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/testing/selftests/membarrier/membarrier_test_impl.h b/tools/testing/selftests/membarrier/membarrier_test_impl.h
index 29aac3bc4988..b4dcbb32538d 100644
--- a/tools/testing/selftests/membarrier/membarrier_test_impl.h
+++ b/tools/testing/selftests/membarrier/membarrier_test_impl.h
@@ -113,6 +113,16 @@ static int test_membarrier_private_expedited_fail(void)
 	int cmd = MEMBARRIER_CMD_PRIVATE_EXPEDITED, flags = 0;
 	const char *test_name = "sys membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED not registered failure";
 
+	/*
+	 * Some C libraries, like Musl, register the private expedited barrier
+	 * command when creating a thread. Expecting an EPERM on an unregistered
+	 * command will therefore no longer work. Skip the test in this case.
+	 */
+	if (MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED & membarrier_get_registrations()) {
+		ksft_test_result_skip("%s test: Command already registered\n", test_name);
+		return 0;
+	}
+
 	if (sys_membarrier(cmd, flags) != -1) {
 		ksft_exit_fail_msg(
 			"%s test: flags = %d. Should fail, but passed\n",
-- 
2.47.3


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

* Re: [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc
  2026-08-03 12:49 ` [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc Chris Gellermann
@ 2026-08-03 20:31   ` Andrew Morton
  2026-08-03 20:37   ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-08-03 20:31 UTC (permalink / raw)
  To: Chris Gellermann
  Cc: shuah, linux-kselftest, richard.weiyang, reddybalavignesh9979,
	linux-kernel

On Mon,  3 Aug 2026 14:49:00 +0200 Chris Gellermann <christian.gellermann@codasip.com> wrote:

> On thread creation, Musl registers the private expedited memory barrier,
> see pthread_create [1]. Thus, invoking the barrier command will no
> longer be rejected by the kernel with EPERM. The test checking this will
> fail. Check if the memory barrier command has been registered and skip
> the test in this case.
> 

Who the heck maintains sched/membarrier?

Short answer: everybody I've ever met.  All are cheerfully cc'ed.

Perhaps finer-tuned answer: Peter.

> --- a/tools/testing/selftests/membarrier/membarrier_test_impl.h
> +++ b/tools/testing/selftests/membarrier/membarrier_test_impl.h
> @@ -113,6 +113,16 @@ static int test_membarrier_private_expedited_fail(void)
>  	int cmd = MEMBARRIER_CMD_PRIVATE_EXPEDITED, flags = 0;
>  	const char *test_name = "sys membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED not registered failure";
>  
> +	/*
> +	 * Some C libraries, like Musl, register the private expedited barrier
> +	 * command when creating a thread. Expecting an EPERM on an unregistered
> +	 * command will therefore no longer work. Skip the test in this case.
> +	 */
> +	if (MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED & membarrier_get_registrations()) {
> +		ksft_test_result_skip("%s test: Command already registered\n", test_name);
> +		return 0;
> +	}

AI review
(https://sashiko.dev/#/patchset/20260803124900.3328789-1-christian.gellermann@codasip.com)
thinks that membarrier_get_registrations() can return -1 on old
kernels, so we should check for that before testing for
MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED.

Seems nonsensical to me - membarrier_get_registrations() doesn't do that.

And policy (my policy, at least) is that selftests test the kernel
they're shipped with and anyone who tries to run them against any older
or newer kernel is all out of luck.


That being said, and stepping back a bit, is this test testing
something which we would test?  If pass/fail depends upon deepest
details of the chosen libc flavour then perhaps the whole test was
ill-conceived.  wdyt?



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

* Re: [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc
  2026-08-03 12:49 ` [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc Chris Gellermann
  2026-08-03 20:31   ` Andrew Morton
@ 2026-08-03 20:37   ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2026-08-03 20:37 UTC (permalink / raw)
  To: Chris Gellermann
  Cc: shuah, linux-kselftest, richard.weiyang, reddybalavignesh9979,
	linux-kernel, Mathieu Desnoyers, Paul E. McKenney, Ingo Molnar,
	Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman, Valentin Schneider,
	K Prateek Nayak

On Mon,  3 Aug 2026 14:49:00 +0200 Chris Gellermann <christian.gellermann@codasip.com> wrote:

> On thread creation, Musl registers the private expedited memory barrier,
> see pthread_create [1]. Thus, invoking the barrier command will no
> longer be rejected by the kernel with EPERM. The test checking this will
> fail. Check if the memory barrier command has been registered and skip
> the test in this case.
> 

Who the heck maintains sched/membarrier?

Short answer: everybody I've ever met.  All are cheerfully cc'ed.

Perhaps finer-tuned answer: Peter.

> --- a/tools/testing/selftests/membarrier/membarrier_test_impl.h
> +++ b/tools/testing/selftests/membarrier/membarrier_test_impl.h
> @@ -113,6 +113,16 @@ static int test_membarrier_private_expedited_fail(void)
>  	int cmd = MEMBARRIER_CMD_PRIVATE_EXPEDITED, flags = 0;
>  	const char *test_name = "sys membarrier MEMBARRIER_CMD_PRIVATE_EXPEDITED not registered failure";
>  
> +	/*
> +	 * Some C libraries, like Musl, register the private expedited barrier
> +	 * command when creating a thread. Expecting an EPERM on an unregistered
> +	 * command will therefore no longer work. Skip the test in this case.
> +	 */
> +	if (MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED & membarrier_get_registrations()) {
> +		ksft_test_result_skip("%s test: Command already registered\n", test_name);
> +		return 0;
> +	}

AI review
(https://sashiko.dev/#/patchset/20260803124900.3328789-1-christian.gellermann@codasip.com)
thinks that membarrier_get_registrations() can return -1 on old
kernels, so we should check for that before testing for
MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED.

Seems nonsensical to me - membarrier_get_registrations() doesn't do that.

And policy (my policy, at least) is that selftests test the kernel
they're shipped with and anyone who tries to run them against any older
or newer kernel is all out of luck.


That being said, and stepping back a bit, is this test testing
something which we would test?  If pass/fail depends upon deepest
details of the chosen libc flavour then perhaps the whole test was
ill-conceived.  wdyt?



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

end of thread, other threads:[~2026-08-03 20:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 12:48 [PATCH 0/2] selftests/membarrier: Skip an unregistered memory barrier test on Musl Chris Gellermann
2026-08-03 12:48 ` [PATCH 1/2] selftests/membarrier: Introduce helper to get membarrier command registrations Chris Gellermann
2026-08-03 12:49 ` [PATCH 2/2] selftests/membarrier: Skip unpermitted membarrier command test if preregistered by libc Chris Gellermann
2026-08-03 20:31   ` Andrew Morton
2026-08-03 20:37   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).