Skip to contentSkip to conversation

rseq01: basic test rseq

PATCH Superseded Wei Gao via ltp 2 participants 15 messages Feb 13, 2023 – Mar 14, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rseq01: basic test rseq

Add basic check for the newly added glibc API in LTP. This test references the glibc test case tst-rseq.c.

---
 runtest/syscalls                          |  2 +
 testcases/kernel/syscalls/rseq/.gitignore |  1 +
 testcases/kernel/syscalls/rseq/Makefile   |  7 +++
 testcases/kernel/syscalls/rseq/rseq01.c   | 74 +++++++++++++++++++++++
 4 files changed, 84 insertions(+)
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +7 -0
new file mode 100644
index 000000000..159d5651c
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rseq/rseq01.c new file +74 -0

74 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

Quoted 53 lines

Add basic check for the newly added glibc API in LTP. This test references the glibc test case tst-rseq.c.

---
 runtest/syscalls                          |  2 +
 testcases/kernel/syscalls/rseq/.gitignore |  1 +
 testcases/kernel/syscalls/rseq/Makefile   |  7 +++
 testcases/kernel/syscalls/rseq/rseq01.c   | 74 +++++++++++++++++++++++
 4 files changed, 84 insertions(+)
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +7 -0
new file mode 100644
index 000000000..159d5651c
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rseq/rseq01.c new file +0 -0
new file mode 100644
index 000000000..ac096471e

testcases/kernel/syscalls/rseq/rseq01.c line 7

Quoted 7 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +7 -0
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021-2023 Free Software Foundation, Inc.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the GNU C Library; if not, see
+ * <https://www.gnu.org/licenses/>.

This part that says anything about GNU C Library shouldn't be there, the copyright itself should be enough to keep the reference where the code came from.

testcases/kernel/syscalls/rseq/rseq01.c line 12

Quoted 4 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +4 -0
+ * Restartable Sequences single-threaded tests.
+ * These tests validate that rseq is registered from main in an executable
+ * not linked against libpthread.
+ */

This should be changed into docparse readable description.

Quoted 11 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +11 -0
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include <stdbool.h>
+
+#if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35))
+# include <sys/rseq.h>
+#endif
+

testcases/kernel/syscalls/rseq/rseq01.c line 34

Quoted 10 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +10 -0
+#ifdef RSEQ_SIG
+# include <stdlib.h>
+# include <string.h>
+# include <syscall.h>
+# include <sched.h>
+
+static int sys_rseq(struct rseq *rseq_abi, uint32_t rseq_len, int flags, uint32_t sig)
+{
+	return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
+}

Can we please add a configure cehck and a fallback header into a lapi/ ?

LTP runs on different libc implmentations and such ifdefs shouldn't be used at all.

Quoted 45 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +39 -0
+static void check_rseq_available(void)
+{
+	int rc;
+
+	rc = sys_rseq(NULL, 0, 0, 0);
+	if (rc != -1)
+		tst_brk(TFAIL | TTERRNO, "Unexpected rseq return value %d ", rc);
+	switch (errno) {
+	case ENOSYS:
+		tst_res(TCONF,
+				"kernel does not support rseq, skipping test");
+	case EINVAL:
+		/* rseq is implemented, but detected an invalid rseq_len parameter.  */
+		break;
+	default:
+		tst_brk(TFAIL | TTERRNO, "Unexpected rseq error ");
+	}
+}
+
+static void run(void)
+{
+	check_rseq_available();
+
+	TST_EXP_PASS(!(sched_getcpu() >= 0));
+}
+#else /* RSEQ_SIG */
+
+static void run(void)
+{
+	tst_res(TCONF,
+		"glibc does not define RSEQ_SIG, skipping test");
+}
+
+#endif /* RSEQ_SIG */
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v2 1/1 rseq01: basic test rseq

In reply to Wei Gao via ltp

Add basic check for the newly added glibc API in LTP. This test references the glibc test case tst-rseq.c.

---
 configure.ac                              |  1 +
 include/lapi/rseq.h                       | 57 +++++++++++++++++++++++
 runtest/syscalls                          |  2 +
 testcases/kernel/syscalls/rseq/.gitignore |  1 +
 testcases/kernel/syscalls/rseq/Makefile   |  7 +++
 testcases/kernel/syscalls/rseq/rseq01.c   | 28 +++++++++++
 6 files changed, 96 insertions(+)
 create mode 100644 include/lapi/rseq.h
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
configure.ac +1 -0
index c2b0f48e7..43b9ca3ce 100644
@@ -80,6 +80,7 @@ AC_CHECK_HEADERS_ONCE([ \
     sys/utsname.h \
     sys/xattr.h \
     xfs/xqm.h \
+    sys/rseq.h \
 ])
 AC_CHECK_HEADERS(fts.h, [have_fts=1])
 AC_SUBST(HAVE_FTS_H, $have_fts)
include/lapi/rseq.h new file +57 -0

57 lines not on this page · raw message

runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +7 -0
new file mode 100644
index 000000000..159d5651c
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rseq/rseq01.c new file +28 -0
new file mode 100644
index 000000000..6f3e7ff97
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021-2023 Free Software Foundation, Inc.
+ * Copyright (c) 2023 Wei Gao <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Restartable Sequences basic tests.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sched.h>
+#include "lapi/rseq.h"
+
+static void run(void)
+{
+	check_rseq_available();
+
+	TST_EXP_PASS(!(sched_getcpu() >= 0));
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 50 lines

Add basic check for the newly added glibc API in LTP. This test references the glibc test case tst-rseq.c.

---
 configure.ac                              |  1 +
 include/lapi/rseq.h                       | 57 +++++++++++++++++++++++
 runtest/syscalls                          |  2 +
 testcases/kernel/syscalls/rseq/.gitignore |  1 +
 testcases/kernel/syscalls/rseq/Makefile   |  7 +++
 testcases/kernel/syscalls/rseq/rseq01.c   | 28 +++++++++++
 6 files changed, 96 insertions(+)
 create mode 100644 include/lapi/rseq.h
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
configure.ac +1 -0
index c2b0f48e7..43b9ca3ce 100644
@@ -80,6 +80,7 @@ AC_CHECK_HEADERS_ONCE([ \
     sys/utsname.h \
     sys/xattr.h \
     xfs/xqm.h \
+    sys/rseq.h \
 ])
 AC_CHECK_HEADERS(fts.h, [have_fts=1])
 AC_SUBST(HAVE_FTS_H, $have_fts)
include/lapi/rseq.h new file +15 -0
new file mode 100644
index 000000000..7f4834f2c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021-2023 Free Software Foundation, Inc.
+ * Copyright (c) 2023 Wei Gao <[email protected]>
+ */
+
+#ifndef LAPI_RSEQ_H__
+#define LAPI_RSEQ_H__
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syscall.h>

include/lapi/rseq.h line 25

Quoted 10 lines
include/lapi/rseq.h new file +10 -0
+#include "config.h"
+#include "tst_test.h"
+
+
+#if defined(HAVE_SYS_RSEQ_H)
+# include <sys/rseq.h>
+#endif
+
+
+#if defined(HAVE_SYS_RSEQ_H) && defined(RSEQ_SIG)

^
Where is this macro defined?

include/lapi/rseq.h line 28

Quoted 3 lines
include/lapi/rseq.h new file +3 -0
+static int sys_rseq(struct rseq *rseq_abi, uint32_t rseq_len, int flags, uint32_t sig)
+{
+	return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
                ^
		tst_syscall
Quoted 10 lines
include/lapi/rseq.h new file +10 -0
+}
+
+static void check_rseq_available(void)
+{
+	int rc;
+
+	rc = sys_rseq(NULL, 0, 0, 0);
+	if (rc != -1)
+		tst_brk(TFAIL | TTERRNO, "Unexpected rseq return value %d ", rc);
+	switch (errno) {

include/lapi/rseq.h line 48

Quoted 10 lines
include/lapi/rseq.h new file +10 -0
+	case ENOSYS:
+		tst_brk(TCONF,
+				"kernel does not support rseq, skipping test");
+	case EINVAL:
+		/* rseq is implemented, but detected an invalid rseq_len parameter.  */
+		break;
+	default:
+		tst_brk(TFAIL | TTERRNO, "Unexpected rseq error ");
+	}
+}

These two functions should be defined regardless of the presense of the sys/rqseq.h header.

The configure checks for the header are there to ensure there are no collisions between the function/macro definitions we carry in LTP and the ones in the libc library.

More generally there is no correlation between kernel version and libc version installed on the system. We deal with that in LTP by adding:

- configure check for particular functionality
- fallback definitions in lapi/ headers in case that system headers does not include the definitions we need
- syscall availability check in the test setup()

With that we can run the test if the syscall() is supported by kernel and exit greacefuly otherwhise.

Quoted 60 lines
include/lapi/rseq.h new file +9 -0
+#else /* HAVE_SYS_RSEQ_H && RSEQ_SIG */
+static void check_rseq_available(void)
+{
+	tst_brk(TCONF,
+		"glibc does not support rseq, skipping test");
+}
+#endif /* HAVE_SYS_RSEQ_H && RSEQ_SIG */
+
+#endif /* LAPI_RSEQ_H__ */
runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +7 -0
new file mode 100644
index 000000000..159d5651c
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rseq/rseq01.c new file +12 -0
new file mode 100644
index 000000000..6f3e7ff97
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021-2023 Free Software Foundation, Inc.
+ * Copyright (c) 2023 Wei Gao <[email protected]>
+ */
+
+/*\
+ * [Description]
+ *
+ * Restartable Sequences basic tests.
+ */
+

testcases/kernel/syscalls/rseq/rseq01.c line 22

Quoted 10 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +10 -0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sched.h>
+#include "lapi/rseq.h"
+
+static void run(void)
+{
+	check_rseq_available();
+
+	TST_EXP_PASS(!(sched_getcpu() >= 0));

This does not actually check anything useful.

Very basic test would register rqseq, then loop over available CPUs, pin a process to the CPU and check that rqsed did register the buffers. The very basic test would look like:

https://github.com/torvalds/linux/blob/master/tools/testing/selftests/rseq/basic_test.c

Quoted 12 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +6 -0
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw
Quoted 10 lines · Cyril Hrubis

Hi!

Quoted 6 lines

Add basic check for the newly added glibc API in LTP. This test references the glibc test case tst-rseq.c.

---
+#if defined(HAVE_SYS_RSEQ_H) && defined(RSEQ_SIG)

^
Where is this macro defined?

RSEQ_SIG is arch specific macro , following are result in my test system:

find / -name "*.h" | xargs grep RSEQ_SIG
/usr/include/x86_64-linux-gnu/bits/rseq.h:#define RSEQ_SIG 0x53053053

dpkg -S /usr/include/x86_64-linux-gnu/bits/rseq.h libc6-dev:amd64: /usr/include/x86_64-linux-gnu/bits/rseq.h

Quoted 11 lines

testcases/kernel/syscalls/rseq/rseq01.c line 22

Quoted 9 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +9 -0
+#include <stdio.h>
+#include <sched.h>
+#include "lapi/rseq.h"
+
+static void run(void)
+{
+	check_rseq_available();
+
+	TST_EXP_PASS(!(sched_getcpu() >= 0));

This does not actually check anything useful.

This case used to test against glibc's implementation, correct me if i am wrong. Once i saw following commit in glibc, so i think we can use sched_getcpu do some sanity check for rseq implementation in glibc.
1d350aa060 Linux: Use rseq to accelerate sched_getcpu

Quoted 7 lines

Very basic test would register rqseq, then loop over available CPUs, pin a process to the CPU and check that rqsed did register the buffers. The very basic test would look like:

https://github.com/torvalds/linux/blob/master/tools/testing/selftests/rseq/basic_test.c

Thanks for your feedback, i have a question on test direction, which one is our target?

1) Check system call ONLY regardless glibc version/implementation then we move linux kernel test(as above link you mentioned) into our test.

2) Check glibc's implemenation for rseq(from 2.35), such as 1.check sched_getcpu, 2.check glibc API
how to disable rseq feature which support automaticly from glibc start. (e3e589829d nptl: Add glibc.pthread.rseq tunable to control rseq registration). Then our target is move glibc test case to our test.

Quoted 16 lines
Quoted 12 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +6 -0
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Hi!

Quoted 11 lines
Quoted 4 lines
Quoted 1 line

+#if defined(HAVE_SYS_RSEQ_H) && defined(RSEQ_SIG)

^
Where is this macro defined?

RSEQ_SIG is arch specific macro , following are result in my test system:

find / -name "*.h" | xargs grep RSEQ_SIG
/usr/include/x86_64-linux-gnu/bits/rseq.h:#define RSEQ_SIG 0x53053053

dpkg -S /usr/include/x86_64-linux-gnu/bits/rseq.h libc6-dev:amd64: /usr/include/x86_64-linux-gnu/bits/rseq.h

If that is a macro defined in a header the it does not make sense to guard like this. We add fallback definitions instead of disabling code this way.

Quoted 11 lines
Quoted 11 lines

testcases/kernel/syscalls/rseq/rseq01.c line 22

Quoted 9 lines
testcases/kernel/syscalls/rseq/rseq01.c new file +9 -0
+#include <stdio.h>
+#include <sched.h>
+#include "lapi/rseq.h"
+
+static void run(void)
+{
+	check_rseq_available();
+
+	TST_EXP_PASS(!(sched_getcpu() >= 0));

This does not actually check anything useful.

Quoted 4 lines

This case used to test against glibc's implementation, correct me if i am wrong. Once i saw following commit in glibc, so i think we can use sched_getcpu do some sanity check for rseq implementation in glibc.
1d350aa060 Linux: Use rseq to accelerate sched_getcpu

The sched_getcpu() would not test rseq at all on anything but glibc and would give users false hope that rseq was actually tested even if it was not.

If you want to make sure sched_getcpu() works fine you should write sched_getcpu() test instead.

Quoted 7 lines
Quoted 6 lines

Very basic test would register rqseq, then loop over available CPUs, pin a process to the CPU and check that rqsed did register the buffers. The very basic test would look like:

https://github.com/torvalds/linux/blob/master/tools/testing/selftests/rseq/basic_test.c

Quoted 6 lines

Thanks for your feedback, i have a question on test direction, which one is our target?

1) Check system call ONLY regardless glibc version/implementation then we move linux kernel test(as above link you mentioned) into our test.

2) Check glibc's implemenation for rseq(from 2.35), such as 1.check sched_getcpu, 2.check glibc API
how to disable rseq feature which support automaticly from glibc start. (e3e589829d nptl: Add glibc.pthread.rseq tunable to control rseq registration). Then our target is move glibc test case to our test.

Please forget about glibc, it's not the only libc out there. The test has to work correctly regardless the libc implementation, there are at least five different libc variants used out there.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

v3 cover Move linux rseq test into ltp

In reply to Wei Gao via ltp

*** BLURB HERE ***

Wei Gao (2):
rseq: Copy linux rseq test header files to ltp
rseq01: basic test rseq

 include/lapi/compiler.h                    |   30 +
 include/lapi/rseq-abi.h                    |  151 +++
 include/lapi/rseq-arm.h                    |  827 ++++++++++++
 include/lapi/rseq-arm64.h                  |  695 ++++++++++
 include/lapi/rseq-generic-thread-pointer.h |   25 +
 include/lapi/rseq-mips.h                   |  777 +++++++++++
 include/lapi/rseq-ppc-thread-pointer.h     |   30 +
 include/lapi/rseq-ppc.h                    |  791 ++++++++++++
 include/lapi/rseq-riscv.h                  |  677 ++++++++++
 include/lapi/rseq-s390.h                   |  610 +++++++++
 include/lapi/rseq-skip.h                   |   65 +
 include/lapi/rseq-thread-pointer.h         |   19 +
 include/lapi/rseq-x86-thread-pointer.h     |   40 +
 include/lapi/rseq-x86.h                    | 1365 ++++++++++++++++++++
 include/lapi/rseq.h                        |  313 +++++
 runtest/syscalls                           |    2 +
 testcases/kernel/syscalls/rseq/.gitignore  |    1 +
 testcases/kernel/syscalls/rseq/Makefile    |   10 +
 testcases/kernel/syscalls/rseq/rseq01.c    |   55 +
 19 files changed, 6483 insertions(+)
 create mode 100644 include/lapi/compiler.h
 create mode 100644 include/lapi/rseq-abi.h
 create mode 100644 include/lapi/rseq-arm.h
 create mode 100644 include/lapi/rseq-arm64.h
 create mode 100644 include/lapi/rseq-generic-thread-pointer.h
 create mode 100644 include/lapi/rseq-mips.h
 create mode 100644 include/lapi/rseq-ppc-thread-pointer.h
 create mode 100644 include/lapi/rseq-ppc.h
 create mode 100644 include/lapi/rseq-riscv.h
 create mode 100644 include/lapi/rseq-s390.h
 create mode 100644 include/lapi/rseq-skip.h
 create mode 100644 include/lapi/rseq-thread-pointer.h
 create mode 100644 include/lapi/rseq-x86-thread-pointer.h
 create mode 100644 include/lapi/rseq-x86.h
 create mode 100644 include/lapi/rseq.h
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 1/2 rseq: Copy linux rseq test header files to ltp

---
 include/lapi/compiler.h                    |   30 +
 include/lapi/rseq-abi.h                    |  151 +++
 include/lapi/rseq-arm.h                    |  827 ++++++++++++
 include/lapi/rseq-arm64.h                  |  695 ++++++++++
 include/lapi/rseq-generic-thread-pointer.h |   25 +
 include/lapi/rseq-mips.h                   |  777 +++++++++++
 include/lapi/rseq-ppc-thread-pointer.h     |   30 +
 include/lapi/rseq-ppc.h                    |  791 ++++++++++++
 include/lapi/rseq-riscv.h                  |  677 ++++++++++
 include/lapi/rseq-s390.h                   |  610 +++++++++
 include/lapi/rseq-skip.h                   |   65 +
 include/lapi/rseq-thread-pointer.h         |   19 +
 include/lapi/rseq-x86-thread-pointer.h     |   40 +
 include/lapi/rseq-x86.h                    | 1365 ++++++++++++++++++++
 14 files changed, 6102 insertions(+)
 create mode 100644 include/lapi/compiler.h
 create mode 100644 include/lapi/rseq-abi.h
 create mode 100644 include/lapi/rseq-arm.h
 create mode 100644 include/lapi/rseq-arm64.h
 create mode 100644 include/lapi/rseq-generic-thread-pointer.h
 create mode 100644 include/lapi/rseq-mips.h
 create mode 100644 include/lapi/rseq-ppc-thread-pointer.h
 create mode 100644 include/lapi/rseq-ppc.h
 create mode 100644 include/lapi/rseq-riscv.h
 create mode 100644 include/lapi/rseq-s390.h
 create mode 100644 include/lapi/rseq-skip.h
 create mode 100644 include/lapi/rseq-thread-pointer.h
 create mode 100644 include/lapi/rseq-x86-thread-pointer.h
 create mode 100644 include/lapi/rseq-x86.h
include/lapi/compiler.h new file +30 -0
new file mode 100644
index 000000000..876eb6a7f
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
+/*
+ * rseq/compiler.h
+ *
+ * Work-around asm goto compiler bugs.
+ *
+ * (C) Copyright 2021 - Mathieu Desnoyers <[email protected]>
+ */
+
+#ifndef RSEQ_COMPILER_H
+#define RSEQ_COMPILER_H
+
+/*
+ * gcc prior to 4.8.2 miscompiles asm goto.
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
+ *
+ * gcc prior to 8.1.0 miscompiles asm goto at O1.
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103908
+ *
+ * clang prior to version 13.0.1 miscompiles asm goto at O2.
+ * https://github.com/llvm/llvm-project/issues/52735
+ *
+ * Work around these issues by adding a volatile inline asm with
+ * memory clobber in the fallthrough after the asm goto and at each
+ * label target.  Emit this for all compilers in case other similar
+ * issues are found in the future.
+ */
+#define rseq_after_asm_goto()	asm volatile ("" : : : "memory")
+
+#endif  /* RSEQ_COMPILER_H_ */
include/lapi/rseq-abi.h new file +151 -0

151 lines not on this page · raw message

include/lapi/rseq-arm.h new file +827 -0

827 lines not on this page · raw message

include/lapi/rseq-arm64.h new file +695 -0

695 lines not on this page · raw message

include/lapi/rseq-generic-thread-pointer.h new file +25 -0
new file mode 100644
index 000000000..38c584661
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
+/*
+ * rseq-generic-thread-pointer.h
+ *
+ * (C) Copyright 2021 - Mathieu Desnoyers <[email protected]>
+ */
+
+#ifndef _RSEQ_GENERIC_THREAD_POINTER
+#define _RSEQ_GENERIC_THREAD_POINTER
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Use gcc builtin thread pointer. */
+static inline void *rseq_thread_pointer(void)
+{
+	return __builtin_thread_pointer();
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
include/lapi/rseq-mips.h new file +777 -0

777 lines not on this page · raw message

include/lapi/rseq-ppc-thread-pointer.h new file +30 -0
new file mode 100644
index 000000000..263eee84f
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
+/*
+ * rseq-ppc-thread-pointer.h
+ *
+ * (C) Copyright 2021 - Mathieu Desnoyers <[email protected]>
+ */
+
+#ifndef _RSEQ_PPC_THREAD_POINTER
+#define _RSEQ_PPC_THREAD_POINTER
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline void *rseq_thread_pointer(void)
+{
+#ifdef __powerpc64__
+	register void *__result asm ("r13");
+#else
+	register void *__result asm ("r2");
+#endif
+	asm ("" : "=r" (__result));
+	return __result;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
include/lapi/rseq-ppc.h new file +791 -0

465 lines not on this page · raw message

include/lapi/rseq-riscv.h new file +677 -0

677 lines not on this page · raw message

include/lapi/rseq-s390.h new file +610 -0

610 lines not on this page · raw message

include/lapi/rseq-skip.h new file +65 -0

65 lines not on this page · raw message

include/lapi/rseq-thread-pointer.h new file +19 -0
new file mode 100644
index 000000000..977c25d75

Lines of this file are not shown. View the raw message.

include/lapi/rseq-x86-thread-pointer.h new file +40 -0
new file mode 100644
index 000000000..d3133587d

Lines of this file are not shown. View the raw message.

include/lapi/rseq-x86.h new file +1365 -0

1,365 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

Part of the diff is not shown here. View the raw message.

#8 lore raw

Re: [LTP] [PATCH v3 1/2] rseq: Copy linux rseq test header files to ltp

Hi!

Quoted 16 lines
---
 include/lapi/compiler.h                    |   30 +
 include/lapi/rseq-abi.h                    |  151 +++
 include/lapi/rseq-arm.h                    |  827 ++++++++++++
 include/lapi/rseq-arm64.h                  |  695 ++++++++++
 include/lapi/rseq-generic-thread-pointer.h |   25 +
 include/lapi/rseq-mips.h                   |  777 +++++++++++
 include/lapi/rseq-ppc-thread-pointer.h     |   30 +
 include/lapi/rseq-ppc.h                    |  791 ++++++++++++
 include/lapi/rseq-riscv.h                  |  677 ++++++++++
 include/lapi/rseq-s390.h                   |  610 +++++++++
 include/lapi/rseq-skip.h                   |   65 +
 include/lapi/rseq-thread-pointer.h         |   19 +
 include/lapi/rseq-x86-thread-pointer.h     |   40 +
 include/lapi/rseq-x86.h                    | 1365 ++++++++++++++++++++

We actually does not need most of the code. The only thing that we use from the architecture specific headers is the RSEQ_SIG constant. So unless you actually plan to write tests that use the assembly code in these headers I would put just the RSEQ_SIG into the lapi/rseq.h instead.

There is no point in adding complex code that is not going to the be used.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v3 1/2] rseq: Copy linux rseq test header files to ltp

Quoted 18 lines · Cyril Hrubis

Hi!

Quoted 16 lines
---
 include/lapi/compiler.h                    |   30 +
 include/lapi/rseq-abi.h                    |  151 +++
 include/lapi/rseq-arm.h                    |  827 ++++++++++++
 include/lapi/rseq-arm64.h                  |  695 ++++++++++
 include/lapi/rseq-generic-thread-pointer.h |   25 +
 include/lapi/rseq-mips.h                   |  777 +++++++++++
 include/lapi/rseq-ppc-thread-pointer.h     |   30 +
 include/lapi/rseq-ppc.h                    |  791 ++++++++++++
 include/lapi/rseq-riscv.h                  |  677 ++++++++++
 include/lapi/rseq-s390.h                   |  610 +++++++++
 include/lapi/rseq-skip.h                   |   65 +
 include/lapi/rseq-thread-pointer.h         |   19 +
 include/lapi/rseq-x86-thread-pointer.h     |   40 +
 include/lapi/rseq-x86.h                    | 1365 ++++++++++++++++++++
Quoted 8 lines

We actually does not need most of the code. The only thing that we use from the architecture specific headers is the RSEQ_SIG constant. So unless you actually plan to write tests that use the assembly code in these headers I would put just the RSEQ_SIG into the lapi/rseq.h instead.

There is no point in adding complex code that is not going to the be used.

Yes, indeed, that's why i have made a patch v5 to ONLY work on x86_64 together with only function/macro to be used. Try to make test case small but the size is still big. This system call has no easy/friendly end user inteface .

Quoted 3 lines
Signature · 2 lines
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v3 1/2] rseq: Copy linux rseq test header files to ltp

Hi!

Quoted 11 lines
Quoted 8 lines

We actually does not need most of the code. The only thing that we use from the architecture specific headers is the RSEQ_SIG constant. So unless you actually plan to write tests that use the assembly code in these headers I would put just the RSEQ_SIG into the lapi/rseq.h instead.

There is no point in adding complex code that is not going to the be used.

Yes, indeed, that's why i have made a patch v5 to ONLY work on x86_64 together with only function/macro to be used. Try to make test case small but the size is still big. This system call has no easy/friendly end user inteface .

Now I'm confused, I do not see a v5 rseq patchset. Also there is no need to limit the test to x86_64 all that we need is a per architecture RSEQ_SIG definition.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

Re: [LTP] [PATCH v3 1/2] rseq: Copy linux rseq test header files to ltp

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 8 lines
Quoted 8 lines

We actually does not need most of the code. The only thing that we use from the architecture specific headers is the RSEQ_SIG constant. So unless you actually plan to write tests that use the assembly code in these headers I would put just the RSEQ_SIG into the lapi/rseq.h instead.

There is no point in adding complex code that is not going to the be used.

Quoted 8 lines
Quoted 3 lines

Yes, indeed, that's why i have made a patch v5 to ONLY work on x86_64 together with only function/macro to be used. Try to make test case small but the size is still big. This system call has no easy/friendly end user inteface .

Now I'm confused, I do not see a v5 rseq patchset. Also there is no need to limit the test to x86_64 all that we need is a per architecture RSEQ_SIG definition.

https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Maybe already set to change request so you can not see it?

Quoted 3 lines
Signature · 2 lines
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v3 2/2 rseq01: basic test rseq

In reply to Wei Gao via ltp
---
 include/lapi/rseq.h                       | 313 ++++++++++++++++++++++
 runtest/syscalls                          |   2 +
 testcases/kernel/syscalls/rseq/.gitignore |   1 +
 testcases/kernel/syscalls/rseq/Makefile   |  10 +
 testcases/kernel/syscalls/rseq/rseq01.c   |  55 ++++
 5 files changed, 381 insertions(+)
 create mode 100644 include/lapi/rseq.h
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
include/lapi/rseq.h new file +313 -0
new file mode 100644
index 000000000..5fb29f85f
@@ -0,0 +1,313 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * rseq.h
+ *
+ * Copyright (C) 2016 Mathieu Desnoyers <[email protected]>
+ * Copyright (c) 2023 Wei Gao <[email protected]>
+ *
+ */
+
+#ifndef LAPI_RSEQ_H__
+#define LAPI_RSEQ_H__
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <syscall.h>
+#include <assert.h>
+#include <signal.h>
+#include <limits.h>
+#include <dlfcn.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <pthread.h>
+#include <signal.h>
+#include <sched.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include "rseq-abi.h"
+#include "compiler.h"
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/rseq-thread-pointer.h"
+
+/*
+ * Empty code injection macros, override when testing.
+ * It is important to consider that the ASM injection macros need to be
+ * fully reentrant (e.g. do not modify the stack).
+ */
+#ifndef RSEQ_INJECT_ASM
+#define RSEQ_INJECT_ASM(n)
+#endif
+
+#ifndef RSEQ_INJECT_C
+#define RSEQ_INJECT_C(n)
+#endif
+
+#ifndef RSEQ_INJECT_INPUT
+#define RSEQ_INJECT_INPUT
+#endif
+
+#ifndef RSEQ_INJECT_CLOBBER
+#define RSEQ_INJECT_CLOBBER
+#endif
+
+#ifndef RSEQ_INJECT_FAILED
+#define RSEQ_INJECT_FAILED
+#endif
+
+
+/* Offset from the thread pointer to the rseq area.  */
+extern ptrdiff_t rseq_offset;
+/* Size of the registered rseq area.  0 if the registration was
+   unsuccessful.  */
+extern unsigned int rseq_size;
+/* Flags used during rseq registration.  */
+extern unsigned int rseq_flags;
+
+static inline struct rseq_abi *rseq_get_abi(void)
+{
+	return (struct rseq_abi *) ((uintptr_t) rseq_thread_pointer() + rseq_offset);
+}
+
+#define rseq_likely(x)		__builtin_expect(!!(x), 1)
+#define rseq_unlikely(x)	__builtin_expect(!!(x), 0)
+#define rseq_barrier()		__asm__ __volatile__("" : : : "memory")
+
+#define RSEQ_ACCESS_ONCE(x)	(*(__volatile__  __typeof__(x) *)&(x))
+#define RSEQ_WRITE_ONCE(x, v)	__extension__ ({ RSEQ_ACCESS_ONCE(x) = (v); })
+#define RSEQ_READ_ONCE(x)	RSEQ_ACCESS_ONCE(x)
+
+#define __rseq_str_1(x)	#x
+#define __rseq_str(x)		__rseq_str_1(x)
+
+#define rseq_log(fmt, args...)						       \
+	fprintf(stderr, fmt "(in %s() at " __FILE__ ":" __rseq_str(__LINE__)"\n", \
+		## args, __func__)
+
+#define rseq_bug(fmt, args...)		\
+	do {				\
+		rseq_log(fmt, ##args);	\
+		abort();		\
+	} while (0)
+
+#if defined(__x86_64__) || defined(__i386__)
+#include "lapi/rseq-x86.h"
+#elif defined(__ARMEL__)
+#include "lapi/rseq-arm.h"
+#elif defined (__AARCH64EL__)
+#include "lapi/rseq-arm64.h"
+#elif defined(__PPC__)
+#include "lapi/rseq-ppc.h"
+#elif defined(__mips__)
+#include "lapi/rseq-mips.h"
+#elif defined(__s390__)
+#include "lapi/rseq-s390.h"
+#elif defined(__riscv)
+#include "lapi/rseq-riscv.h"
+#else
+#error unsupported target
+#endif
+
+/*
+ * Register rseq for the current thread. This needs to be called once
+ * by any thread which uses restartable sequences, before they start
+ * using restartable sequences, to ensure restartable sequences
+ * succeed. A restartable sequence executed from a non-registered
+ * thread will always fail.
+ */
+int rseq_register_current_thread(void);
+
+/*
+ * Unregister rseq for current thread.
+ */
+int rseq_unregister_current_thread(void);
+
+/*
+ * Restartable sequence fallback for reading the current CPU number.
+ */
+int32_t rseq_fallback_current_cpu(void);
+
+/*
+ * Values returned can be either the current CPU number, -1 (rseq is
+ * uninitialized), or -2 (rseq initialization has failed).
+ */
+static inline int32_t rseq_current_cpu_raw(void)
+{
+	return RSEQ_ACCESS_ONCE(rseq_get_abi()->cpu_id);
+}
+
+/*
+ * Returns a possible CPU number, which is typically the current CPU.
+ * The returned CPU number can be used to prepare for an rseq critical
+ * section, which will confirm whether the cpu number is indeed the
+ * current one, and whether rseq is initialized.
+ *
+ * The CPU number returned by rseq_cpu_start should always be validated
+ * by passing it to a rseq asm sequence, or by comparing it to the
+ * return value of rseq_current_cpu_raw() if the rseq asm sequence
+ * does not need to be invoked.
+ */
+static inline uint32_t rseq_cpu_start(void)
+{
+	return RSEQ_ACCESS_ONCE(rseq_get_abi()->cpu_id_start);
+}
+
+static inline uint32_t rseq_current_cpu(void)
+{
+	int32_t cpu;
+
+	cpu = rseq_current_cpu_raw();
+	if (rseq_unlikely(cpu < 0))
+		cpu = rseq_fallback_current_cpu();
+	return cpu;
+}
+
+static inline void rseq_clear_rseq_cs(void)
+{
+	RSEQ_WRITE_ONCE(rseq_get_abi()->rseq_cs.arch.ptr, 0);
+}
+
+/*
+ * rseq_prepare_unload() should be invoked by each thread executing a rseq
+ * critical section at least once between their last critical section and
+ * library unload of the library defining the rseq critical section (struct
+ * rseq_cs) or the code referred to by the struct rseq_cs start_ip and
+ * post_commit_offset fields. This also applies to use of rseq in code
+ * generated by JIT: rseq_prepare_unload() should be invoked at least once by
+ * each thread executing a rseq critical section before reclaim of the memory
+ * holding the struct rseq_cs or reclaim of the code pointed to by struct
+ * rseq_cs start_ip and post_commit_offset fields.
+ */
+static inline void rseq_prepare_unload(void)
+{
+	rseq_clear_rseq_cs();
+}
+
+static const ptrdiff_t *libc_rseq_offset_p;
+static const unsigned int *libc_rseq_size_p;
+static const unsigned int *libc_rseq_flags_p;
+
+/* Offset from the thread pointer to the rseq area.  */
+ptrdiff_t rseq_offset;
+
+/* Size of the registered rseq area.  0 if the registration was
+   unsuccessful.  */
+unsigned int rseq_size = -1U;
+
+/* Flags used during rseq registration.  */
+unsigned int rseq_flags;
+
+static int rseq_ownership;
+
+static
+__thread struct rseq_abi __rseq_abi __attribute__((tls_model("initial-exec"))) = {
+	.cpu_id = RSEQ_ABI_CPU_ID_UNINITIALIZED,
+};
+
+static int sys_rseq(struct rseq_abi *rseq_abi, uint32_t rseq_len,
+		    int flags, uint32_t sig)
+{
+	return tst_syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig);
+}
+
+int rseq_available(void)
+{
+	int rc;
+
+	rc = sys_rseq(NULL, 0, 0, 0);
+	if (rc != -1)
+		tst_brk(TFAIL | TTERRNO, "Unexpected rseq return value");
+	switch (errno) {
+	case ENOSYS:
+		return 0;
+	case EINVAL:
+		return 1;
+	default:
+		tst_brk(TFAIL | TTERRNO, "Unexpected rseq return value");
+	}
+	return 1;
+}
+
+int rseq_register_current_thread(void)
+{
+	int rc;
+
+	if (!rseq_ownership) {
+		/* Treat libc's ownership as a successful registration. */
+		return 0;
+	}
+	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq_abi), 0, RSEQ_SIG);
+	if (rc)
+		return -1;
+	TST_EXP_POSITIVE(rseq_current_cpu_raw());
+	return 0;
+}
+
+int rseq_unregister_current_thread(void)
+{
+	int rc;
+
+	if (!rseq_ownership) {
+		/* Treat libc's ownership as a successful unregistration. */
+		return 0;
+	}
+	rc = sys_rseq(&__rseq_abi, sizeof(struct rseq_abi), RSEQ_ABI_FLAG_UNREGISTER, RSEQ_SIG);
+	if (rc)
+		return -1;
+	return 0;
+}
+
+static __attribute__((constructor))
+void rseq_init(void)
+{
+	libc_rseq_offset_p = dlsym(RTLD_NEXT, "__rseq_offset");
+	libc_rseq_size_p = dlsym(RTLD_NEXT, "__rseq_size");
+	libc_rseq_flags_p = dlsym(RTLD_NEXT, "__rseq_flags");
+	if (libc_rseq_size_p && libc_rseq_offset_p && libc_rseq_flags_p &&
+			*libc_rseq_size_p != 0) {
+		/* rseq registration owned by glibc */
+		rseq_offset = *libc_rseq_offset_p;
+		rseq_size = *libc_rseq_size_p;
+		rseq_flags = *libc_rseq_flags_p;
+		return;
+	}
+	if (!rseq_available())
+		return;
+	rseq_ownership = 1;
+	rseq_offset = (void *)&__rseq_abi - rseq_thread_pointer();
+	rseq_size = sizeof(struct rseq_abi);
+	rseq_flags = 0;
+}
+
+static __attribute__((destructor))
+void rseq_exit(void)
+{
+	if (!rseq_ownership)
+		return;
+	rseq_offset = 0;
+	rseq_size = -1U;
+	rseq_ownership = 0;
+}
+
+int32_t rseq_fallback_current_cpu(void)
+{
+	int32_t cpu;
+
+	cpu = sched_getcpu();
+	if (cpu < 0) {
+		tst_brk(TFAIL | TTERRNO, "sched_getcpu() failed");
+	}
+	return cpu;
+}
+
+#endif  /* LAPI_RSEQ_H__ */
+
runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +10 -0
new file mode 100644
index 000000000..2897fc581
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+rseq01: CFLAGS += -lpthread -ldl
+
testcases/kernel/syscalls/rseq/rseq01.c new file +55 -0

55 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v4 1/1 rseq01: basic test rseq

---
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/rseq/.gitignore     |   1 +
 testcases/kernel/syscalls/rseq/Makefile       |  10 +
 testcases/kernel/syscalls/rseq/rseq-abi.h     | 151 ++++++++
 .../syscalls/rseq/rseq-x86-thread-pointer.h   |  40 +++
 testcases/kernel/syscalls/rseq/rseq.h         | 221 ++++++++++++
 testcases/kernel/syscalls/rseq/rseq01.c       | 333 ++++++++++++++++++
 7 files changed, 758 insertions(+)
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq-abi.h
 create mode 100644 testcases/kernel/syscalls/rseq/rseq-x86-thread-pointer.h
 create mode 100644 testcases/kernel/syscalls/rseq/rseq.h
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +10 -0
new file mode 100644
index 000000000..2897fc581
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+rseq01: CFLAGS += -lpthread -ldl
+
testcases/kernel/syscalls/rseq/rseq-abi.h new file +151 -0

151 lines not on this page · raw message

testcases/kernel/syscalls/rseq/rseq-x86-thread-pointer.h new file +40 -0
new file mode 100644
index 000000000..d3133587d
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
+/*
+ * rseq-x86-thread-pointer.h
+ *
+ * (C) Copyright 2021 - Mathieu Desnoyers <[email protected]>
+ */
+
+#ifndef _RSEQ_X86_THREAD_POINTER
+#define _RSEQ_X86_THREAD_POINTER
+
+#include <features.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if __GNUC_PREREQ (11, 1)
+static inline void *rseq_thread_pointer(void)
+{
+	return __builtin_thread_pointer();
+}
+#else
+static inline void *rseq_thread_pointer(void)
+{
+	void *__result;
+
+# ifdef __x86_64__
+	__asm__ ("mov %%fs:0, %0" : "=r" (__result));
+# else
+	__asm__ ("mov %%gs:0, %0" : "=r" (__result));
+# endif
+	return __result;
+}
+#endif /* !GCC 11 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
testcases/kernel/syscalls/rseq/rseq.h new file +221 -0

221 lines not on this page · raw message

testcases/kernel/syscalls/rseq/rseq01.c new file +333 -0

333 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v5 1/1 rseq01: basic test rseq

---
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/rseq/.gitignore     |   1 +
 testcases/kernel/syscalls/rseq/Makefile       |  10 +
 testcases/kernel/syscalls/rseq/rseq-abi.h     | 151 ++++++++
 .../syscalls/rseq/rseq-x86-thread-pointer.h   |  40 +++
 testcases/kernel/syscalls/rseq/rseq.h         | 221 ++++++++++++
 testcases/kernel/syscalls/rseq/rseq01.c       | 322 ++++++++++++++++++
 7 files changed, 747 insertions(+)
 create mode 100644 testcases/kernel/syscalls/rseq/.gitignore
 create mode 100644 testcases/kernel/syscalls/rseq/Makefile
 create mode 100644 testcases/kernel/syscalls/rseq/rseq-abi.h
 create mode 100644 testcases/kernel/syscalls/rseq/rseq-x86-thread-pointer.h
 create mode 100644 testcases/kernel/syscalls/rseq/rseq.h
 create mode 100644 testcases/kernel/syscalls/rseq/rseq01.c
runtest/syscalls +2 -0
index ae37a1192..f46950b27 100644
@@ -1752,6 +1752,8 @@ copy_file_range01 copy_file_range01
 copy_file_range02 copy_file_range02
 copy_file_range03 copy_file_range03
 
+rseq01 rseq01
+
 statx01 statx01
 statx02 statx02
 statx03 statx03
testcases/kernel/syscalls/rseq/.gitignore new file +1 -0
new file mode 100644
index 000000000..8a6c7ee36
@@ -0,0 +1 @@
+/rseq01
testcases/kernel/syscalls/rseq/Makefile new file +10 -0
new file mode 100644
index 000000000..2897fc581
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#  Copyright (C) 2012 Linux Test Project, Inc.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+rseq01: CFLAGS += -lpthread -ldl
+
testcases/kernel/syscalls/rseq/rseq-abi.h new file +151 -0

151 lines not on this page · raw message

testcases/kernel/syscalls/rseq/rseq-x86-thread-pointer.h new file +40 -0
new file mode 100644
index 000000000..d3133587d
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: LGPL-2.1-only OR MIT */
+/*
+ * rseq-x86-thread-pointer.h
+ *
+ * (C) Copyright 2021 - Mathieu Desnoyers <[email protected]>
+ */
+
+#ifndef _RSEQ_X86_THREAD_POINTER
+#define _RSEQ_X86_THREAD_POINTER
+
+#include <features.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if __GNUC_PREREQ (11, 1)
+static inline void *rseq_thread_pointer(void)
+{
+	return __builtin_thread_pointer();
+}
+#else
+static inline void *rseq_thread_pointer(void)
+{
+	void *__result;
+
+# ifdef __x86_64__
+	__asm__ ("mov %%fs:0, %0" : "=r" (__result));
+# else
+	__asm__ ("mov %%gs:0, %0" : "=r" (__result));
+# endif
+	return __result;
+}
+#endif /* !GCC 11 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
testcases/kernel/syscalls/rseq/rseq.h new file +221 -0

221 lines not on this page · raw message

testcases/kernel/syscalls/rseq/rseq01.c new file +322 -0

322 lines not on this page · raw message

Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp