All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasily Gorbik <gor@linux.ibm.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Shuah Khan <shuah@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH 1/1] rseq/selftests: add __rseq_abi misalignment check
Date: Mon, 6 Aug 2018 13:47:02 +0200	[thread overview]
Message-ID: <patch-1.thread-5c3a1c.git-5c3a1ce06b75.your-ad-here.call-01533555685-ext-8699@work.hours> (raw)
In-Reply-To: <cover.thread-5c3a1c.your-ad-here.call-01533555685-ext-8699@work.hours>

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


WARNING: multiple messages have this Message-ID (diff)
From: gor at linux.ibm.com (Vasily Gorbik)
Subject: [PATCH 1/1] rseq/selftests: add __rseq_abi misalignment check
Date: Mon, 6 Aug 2018 13:47:02 +0200	[thread overview]
Message-ID: <patch-1.thread-5c3a1c.git-5c3a1ce06b75.your-ad-here.call-01533555685-ext-8699@work.hours> (raw)
In-Reply-To: <cover.thread-5c3a1c.your-ad-here.call-01533555685-ext-8699@work.hours>

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 at 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

WARNING: multiple messages have this Message-ID (diff)
From: gor@linux.ibm.com (Vasily Gorbik)
Subject: [PATCH 1/1] rseq/selftests: add __rseq_abi misalignment check
Date: Mon, 6 Aug 2018 13:47:02 +0200	[thread overview]
Message-ID: <patch-1.thread-5c3a1c.git-5c3a1ce06b75.your-ad-here.call-01533555685-ext-8699@work.hours> (raw)
Message-ID: <20180806114702.FMVdipOruMso8zUnrnM1BR3QVvLnxye-1bcVj9ju7Gc@z> (raw)
In-Reply-To: <cover.thread-5c3a1c.your-ad-here.call-01533555685-ext-8699@work.hours>

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 at 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-08-06 11:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 11:47 ` gor
2018-08-06 11:47 ` Vasily Gorbik [this message]
2018-08-06 11:47   ` [PATCH 1/1] " Vasily Gorbik
2018-08-06 11:47   ` gor
2018-08-06 13:27 ` [PATCH v2 " Vasily Gorbik
2018-08-06 13:27   ` Vasily Gorbik
2018-08-06 13:27   ` gor
2018-08-06 14:09   ` Paul E. McKenney
2018-08-06 14:09     ` Paul E. McKenney
2018-08-06 14:09     ` paulmck
2018-08-07 22:22 ` [PATCH 0/1] " Mathieu Desnoyers
2018-08-07 22:22   ` Mathieu Desnoyers
2018-08-07 22:22   ` mathieu.desnoyers

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=patch-1.thread-5c3a1c.git-5c3a1ce06b75.your-ad-here.call-01533555685-ext-8699@work.hours \
    --to=gor@linux.ibm.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    /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.