linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] rseq/selftests: add __rseq_abi misalignment check
@ 2018-08-06 11:47 Vasily Gorbik
  2018-08-06 11:47 ` [PATCH 1/1] " Vasily Gorbik
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Vasily Gorbik @ 2018-08-06 11:47 UTC (permalink / raw)
  To: Mathieu Desnoyers, Shuah Khan, Thomas Gleixner
  Cc: Peter Zijlstra, Paul E. McKenney, Boqun Feng, linux-kernel,
	linux-kselftest

While implementing rseq selftest for s390 a glibc problem with tls
variables alignment has been discovered. It turned out to be a general
problem affecting several architectures. The bug opened for this problem:

https://sourceware.org/bugzilla/show_bug.cgi?id=23403

There is no fix yet. On s390 __rseq_abi ends up aligned to 0x10 instead
of 0x20 which makes rseq selftest fail every time.

The change proposed adds __rseq_abi misalignment check, produces user
friendly message and skips the test.

Vasily Gorbik (1):
  rseq/selftests: add __rseq_abi misalignment check

 tools/testing/selftests/rseq/rseq.c           | 19 +++++++++++++++++++
 .../testing/selftests/rseq/run_param_test.sh  |  4 ++--
 2 files changed, 21 insertions(+), 2 deletions(-)

-- 
2.18.0.13.gd42ae10


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

* [PATCH 1/1] rseq/selftests: add __rseq_abi misalignment check
  2018-08-06 11:47 [PATCH 0/1] rseq/selftests: add __rseq_abi misalignment check Vasily Gorbik
@ 2018-08-06 11:47 ` Vasily Gorbik
  2018-08-06 13:27 ` [PATCH v2 " Vasily Gorbik
  2018-08-07 22:22 ` [PATCH 0/1] " Mathieu Desnoyers
  2 siblings, 0 replies; 5+ messages in thread
From: Vasily Gorbik @ 2018-08-06 11:47 UTC (permalink / raw)
  To: Mathieu Desnoyers, Shuah Khan, Thomas Gleixner
  Cc: Peter Zijlstra, Paul E. McKenney, Boqun Feng, linux-kernel,
	linux-kselftest

The kernel rseq syscall expects that struct rseq is 32 bytes aligned and
returns EINVAL otherwise. Even though __rseq_abi is declared as static
and proper aligned attribute is present __rseq_abi is a part of thread
local storage. It turns out that on some platforms TLS itself is not
properly aligned (at least for threads created), which is a glibc nptl
bug and should be eventually fixed and backported. But in a meanwhile
add __rseq_abi misalignment check, which would detect this situation
and skip rseq test with some user friendly message.

glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23403

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
 tools/testing/selftests/rseq/rseq.c           | 19 +++++++++++++++++++
 .../testing/selftests/rseq/run_param_test.sh  |  4 ++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/rseq/rseq.c
index 4847e97ed049..50b13318395a 100644
--- a/tools/testing/selftests/rseq/rseq.c
+++ b/tools/testing/selftests/rseq/rseq.c
@@ -64,6 +64,23 @@ static int sys_rseq(volatile struct rseq *rseq_abi, uint32_t rseq_len,
 	return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
 }
 
+/*
+ * rseq syscall might fail on some platforms due to wrong alignment of TLS
+ * variables:
+ * https://sourceware.org/bugzilla/show_bug.cgi?id=23403
+ *
+ * check if glibc bug is present and skip the test in this case
+ */
+static void assert_rseq_abi_aligned()
+{
+	if ((unsigned long)&__rseq_abi & (__alignof__(__rseq_abi) - 1)) {
+		fputs("__rseq_abi is not properly aligned, which is a known \n"
+		      "glibc nptl bug (https://sourceware.org/bugzilla/show_bug.cgi?id=23403).\n"
+		      "You need a fixed version of glibc to run this test.\n", stderr);
+		exit(4); /* skip this test */
+	}
+}
+
 int rseq_register_current_thread(void)
 {
 	int rc, ret = 0;
@@ -72,6 +89,7 @@ int rseq_register_current_thread(void)
 	signal_off_save(&oldset);
 	if (refcount++)
 		goto end;
+	assert_rseq_abi_aligned();
 	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), 0, RSEQ_SIG);
 	if (!rc) {
 		assert(rseq_current_cpu_raw() >= 0);
@@ -94,6 +112,7 @@ int rseq_unregister_current_thread(void)
 	signal_off_save(&oldset);
 	if (--refcount)
 		goto end;
+	assert_rseq_abi_aligned();
 	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq),
 		      RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
 	if (!rc)
diff --git a/tools/testing/selftests/rseq/run_param_test.sh b/tools/testing/selftests/rseq/run_param_test.sh
index 3acd6d75ff9f..56caf5e3de3e 100755
--- a/tools/testing/selftests/rseq/run_param_test.sh
+++ b/tools/testing/selftests/rseq/run_param_test.sh
@@ -34,9 +34,9 @@ function do_tests()
 	local i=0
 	while [ "$i" -lt "${#TEST_LIST[@]}" ]; do
 		echo "Running test ${TEST_NAME[$i]}"
-		./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
+		./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit $?
 		echo "Running compare-twice test ${TEST_NAME[$i]}"
-		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
+		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit $?
 		let "i++"
 	done
 }
-- 
2.18.0.13.gd42ae10


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

* [PATCH v2 1/1] rseq/selftests: add __rseq_abi misalignment check
  2018-08-06 11:47 [PATCH 0/1] rseq/selftests: add __rseq_abi misalignment check Vasily Gorbik
  2018-08-06 11:47 ` [PATCH 1/1] " Vasily Gorbik
@ 2018-08-06 13:27 ` Vasily Gorbik
  2018-08-06 14:09   ` Paul E. McKenney
  2018-08-07 22:22 ` [PATCH 0/1] " Mathieu Desnoyers
  2 siblings, 1 reply; 5+ messages in thread
From: Vasily Gorbik @ 2018-08-06 13:27 UTC (permalink / raw)
  To: Mathieu Desnoyers, Shuah Khan, Thomas Gleixner
  Cc: Peter Zijlstra, Paul E. McKenney, Boqun Feng, linux-kernel,
	linux-kselftest

The kernel rseq syscall expects that struct rseq is 32 bytes aligned and
returns EINVAL otherwise. Even though __rseq_abi is declared as static
and proper aligned attribute is present __rseq_abi is a part of thread
local storage. It turns out that on some platforms TLS itself is not
properly aligned (at least for threads created), which is a glibc nptl
bug and should be eventually fixed and backported. But in a meanwhile
add __rseq_abi misalignment check, which would detect this situation
and skip rseq test with some user friendly message.

glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23403

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
 tools/testing/selftests/rseq/rseq.c           | 20 +++++++++++++++++++
 .../testing/selftests/rseq/run_param_test.sh  |  4 ++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/rseq/rseq.c
index 4847e97ed049..3de7f0e7442e 100644
--- a/tools/testing/selftests/rseq/rseq.c
+++ b/tools/testing/selftests/rseq/rseq.c
@@ -64,6 +64,24 @@ static int sys_rseq(volatile struct rseq *rseq_abi, uint32_t rseq_len,
 	return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
 }
 
+/*
+ * rseq syscall might fail on some platforms due to wrong alignment of TLS
+ * variables:
+ * https://sourceware.org/bugzilla/show_bug.cgi?id=23403
+ *
+ * check if glibc bug is present and skip the test in this case
+ */
+static void assert_rseq_abi_aligned(void)
+{
+	if ((unsigned long)&__rseq_abi & (__alignof__(__rseq_abi) - 1)) {
+		fputs("__rseq_abi is not properly aligned, which is a known\n"
+		      "glibc nptl bug (https://sourceware.org/bugzilla/show_bug.cgi?id=23403).\n"
+		      "You need a fixed version of glibc to run this test.\n",
+		      stderr);
+		exit(4); /* skip this test */
+	}
+}
+
 int rseq_register_current_thread(void)
 {
 	int rc, ret = 0;
@@ -72,6 +90,7 @@ int rseq_register_current_thread(void)
 	signal_off_save(&oldset);
 	if (refcount++)
 		goto end;
+	assert_rseq_abi_aligned();
 	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), 0, RSEQ_SIG);
 	if (!rc) {
 		assert(rseq_current_cpu_raw() >= 0);
@@ -94,6 +113,7 @@ int rseq_unregister_current_thread(void)
 	signal_off_save(&oldset);
 	if (--refcount)
 		goto end;
+	assert_rseq_abi_aligned();
 	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq),
 		      RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
 	if (!rc)
diff --git a/tools/testing/selftests/rseq/run_param_test.sh b/tools/testing/selftests/rseq/run_param_test.sh
index 3acd6d75ff9f..56caf5e3de3e 100755
--- a/tools/testing/selftests/rseq/run_param_test.sh
+++ b/tools/testing/selftests/rseq/run_param_test.sh
@@ -34,9 +34,9 @@ function do_tests()
 	local i=0
 	while [ "$i" -lt "${#TEST_LIST[@]}" ]; do
 		echo "Running test ${TEST_NAME[$i]}"
-		./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
+		./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit $?
 		echo "Running compare-twice test ${TEST_NAME[$i]}"
-		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
+		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit $?
 		let "i++"
 	done
 }
-- 
2.18.0.13.gd42ae10


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

* Re: [PATCH v2 1/1] rseq/selftests: add __rseq_abi misalignment check
  2018-08-06 13:27 ` [PATCH v2 " Vasily Gorbik
@ 2018-08-06 14:09   ` Paul E. McKenney
  0 siblings, 0 replies; 5+ messages in thread
From: Paul E. McKenney @ 2018-08-06 14:09 UTC (permalink / raw)
  To: Vasily Gorbik
  Cc: Mathieu Desnoyers, Shuah Khan, Thomas Gleixner, Peter Zijlstra,
	Boqun Feng, linux-kernel, linux-kselftest

On Mon, Aug 06, 2018 at 03:27:23PM +0200, Vasily Gorbik wrote:
> The kernel rseq syscall expects that struct rseq is 32 bytes aligned and
> returns EINVAL otherwise. Even though __rseq_abi is declared as static
> and proper aligned attribute is present __rseq_abi is a part of thread
> local storage. It turns out that on some platforms TLS itself is not
> properly aligned (at least for threads created), which is a glibc nptl
> bug and should be eventually fixed and backported. But in a meanwhile
> add __rseq_abi misalignment check, which would detect this situation
> and skip rseq test with some user friendly message.
> 
> glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23403
> 
> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>

Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

> ---
>  tools/testing/selftests/rseq/rseq.c           | 20 +++++++++++++++++++
>  .../testing/selftests/rseq/run_param_test.sh  |  4 ++--
>  2 files changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/rseq/rseq.c
> index 4847e97ed049..3de7f0e7442e 100644
> --- a/tools/testing/selftests/rseq/rseq.c
> +++ b/tools/testing/selftests/rseq/rseq.c
> @@ -64,6 +64,24 @@ static int sys_rseq(volatile struct rseq *rseq_abi, uint32_t rseq_len,
>  	return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
>  }
> 
> +/*
> + * rseq syscall might fail on some platforms due to wrong alignment of TLS
> + * variables:
> + * https://sourceware.org/bugzilla/show_bug.cgi?id=23403
> + *
> + * check if glibc bug is present and skip the test in this case
> + */
> +static void assert_rseq_abi_aligned(void)
> +{
> +	if ((unsigned long)&__rseq_abi & (__alignof__(__rseq_abi) - 1)) {
> +		fputs("__rseq_abi is not properly aligned, which is a known\n"
> +		      "glibc nptl bug (https://sourceware.org/bugzilla/show_bug.cgi?id=23403).\n"
> +		      "You need a fixed version of glibc to run this test.\n",
> +		      stderr);
> +		exit(4); /* skip this test */
> +	}
> +}
> +
>  int rseq_register_current_thread(void)
>  {
>  	int rc, ret = 0;
> @@ -72,6 +90,7 @@ int rseq_register_current_thread(void)
>  	signal_off_save(&oldset);
>  	if (refcount++)
>  		goto end;
> +	assert_rseq_abi_aligned();
>  	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq), 0, RSEQ_SIG);
>  	if (!rc) {
>  		assert(rseq_current_cpu_raw() >= 0);
> @@ -94,6 +113,7 @@ int rseq_unregister_current_thread(void)
>  	signal_off_save(&oldset);
>  	if (--refcount)
>  		goto end;
> +	assert_rseq_abi_aligned();
>  	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq),
>  		      RSEQ_FLAG_UNREGISTER, RSEQ_SIG);
>  	if (!rc)
> diff --git a/tools/testing/selftests/rseq/run_param_test.sh b/tools/testing/selftests/rseq/run_param_test.sh
> index 3acd6d75ff9f..56caf5e3de3e 100755
> --- a/tools/testing/selftests/rseq/run_param_test.sh
> +++ b/tools/testing/selftests/rseq/run_param_test.sh
> @@ -34,9 +34,9 @@ function do_tests()
>  	local i=0
>  	while [ "$i" -lt "${#TEST_LIST[@]}" ]; do
>  		echo "Running test ${TEST_NAME[$i]}"
> -		./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
> +		./param_test ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit $?
>  		echo "Running compare-twice test ${TEST_NAME[$i]}"
> -		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit 1
> +		./param_test_compare_twice ${TEST_LIST[$i]} -r ${REPS} ${@} ${EXTRA_ARGS} || exit $?
>  		let "i++"
>  	done
>  }
> -- 
> 2.18.0.13.gd42ae10


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

* Re: [PATCH 0/1] rseq/selftests: add __rseq_abi misalignment check
  2018-08-06 11:47 [PATCH 0/1] rseq/selftests: add __rseq_abi misalignment check Vasily Gorbik
  2018-08-06 11:47 ` [PATCH 1/1] " Vasily Gorbik
  2018-08-06 13:27 ` [PATCH v2 " Vasily Gorbik
@ 2018-08-07 22:22 ` Mathieu Desnoyers
  2 siblings, 0 replies; 5+ messages in thread
From: Mathieu Desnoyers @ 2018-08-07 22:22 UTC (permalink / raw)
  To: gor, Linus Torvalds
  Cc: shuah, Thomas Gleixner, Peter Zijlstra, Paul E. McKenney,
	Boqun Feng, linux-kernel, linux-kselftest

----- On Aug 6, 2018, at 7:47 AM, gor gor@linux.ibm.com wrote:

> While implementing rseq selftest for s390 a glibc problem with tls
> variables alignment has been discovered. It turned out to be a general
> problem affecting several architectures. The bug opened for this problem:
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=23403
> 
> There is no fix yet. On s390 __rseq_abi ends up aligned to 0x10 instead
> of 0x20 which makes rseq selftest fail every time.
> 
> The change proposed adds __rseq_abi misalignment check, produces user
> friendly message and skips the test.

That's a very unfortunate situation. I'm concerned about adding glibc-specific
error messages in rseq selftests though. I'm curious to hear what others think
about this.

I would have thought simply improving rseq registration error handling from
having the test program return nonzero to add a perror() in there would be
a more generic way to handle this.

Regarding the message printed by your check: "you need a fixed version of glibc to
run this test". I disagree with it. Someone can effectively run the test on
a bogus glibc and it serves its purpose: it reports that glibc is buggy.

I would understand adding this kind of test in an user-facing application or
library to detect bogus glibc (in fact I've used similar approaches in lttng-ust
to detect bogus compilers), but why add this to skip a selftest program, which
sole purpose is to test the stack underneath it ?

Thanks,

Mathieu

> 
> Vasily Gorbik (1):
>  rseq/selftests: add __rseq_abi misalignment check
> 
> tools/testing/selftests/rseq/rseq.c           | 19 +++++++++++++++++++
> .../testing/selftests/rseq/run_param_test.sh  |  4 ++--
> 2 files changed, 21 insertions(+), 2 deletions(-)
> 
> --
> 2.18.0.13.gd42ae10

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

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

end of thread, other threads:[~2018-08-07 22:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-06 11:47 [PATCH 0/1] rseq/selftests: add __rseq_abi misalignment check Vasily Gorbik
2018-08-06 11:47 ` [PATCH 1/1] " Vasily Gorbik
2018-08-06 13:27 ` [PATCH v2 " Vasily Gorbik
2018-08-06 14:09   ` Paul E. McKenney
2018-08-07 22:22 ` [PATCH 0/1] " Mathieu Desnoyers

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).