Skip to contentSkip to conversation

Support rseq on arm64

PATCH In review Will Deacon 3 participants 11 messages Jul 9, 2018 – Jul 10, 2018

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover Support rseq on arm64

Hello,

This is version two of the patches previously posted here:

http://lkml.kernel.org/r/[email protected]

Changes since v1 include:

* Move abort handler in-line to avoid possibility of it being out-of-range for conditional branch instructions

I've tested both native and compat (little-endian only) with the selftests and they pass successfully on my Seattle box.

Thanks,

Will

--->8

Will Deacon (3):
arm64: rseq: Implement backend rseq calls and select HAVE_RSEQ
asm-generic: unistd.h: Wire up sys_rseq rseq/selftests: Add support for arm64

 arch/arm64/Kconfig                        |   1 +
 arch/arm64/include/asm/unistd.h           |   2 +-
 arch/arm64/include/asm/unistd32.h         |   2 +
 arch/arm64/kernel/entry.S                 |   2 +
 arch/arm64/kernel/ptrace.c                |   2 +
 arch/arm64/kernel/signal.c                |   3 +
 include/uapi/asm-generic/unistd.h         |   4 +-
 tools/testing/selftests/rseq/param_test.c |  20 +
 tools/testing/selftests/rseq/rseq-arm64.h | 594 ++++++++++++++++++++++++++++++
 tools/testing/selftests/rseq/rseq.h       |   2 +
 10 files changed, 630 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/rseq/rseq-arm64.h
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 1/3 arm64: rseq: Implement backend rseq calls and select HAVE_RSEQ

Implement calls to rseq_signal_deliver, rseq_handle_notify_resume and rseq_syscall so that we can select HAVE_RSEQ on arm64.

---
 arch/arm64/Kconfig                | 1 +
 arch/arm64/include/asm/unistd.h   | 2 +-
 arch/arm64/include/asm/unistd32.h | 2 ++
 arch/arm64/kernel/entry.S         | 2 ++
 arch/arm64/kernel/ptrace.c        | 2 ++
 arch/arm64/kernel/signal.c        | 3 +++
 6 files changed, 11 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +1 -0
index 42c090cf0292..26cb550673b2 100644
@@ -127,6 +127,7 @@ config ARM64
 	select HAVE_PERF_USER_STACK_DUMP
 	select HAVE_REGS_AND_STACK_ACCESS_API
 	select HAVE_RCU_TABLE_FREE
+	select HAVE_RSEQ
 	select HAVE_STACKPROTECTOR
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KPROBES
arch/arm64/include/asm/unistd.h +1 -1
index a0baa9af5487..e0d0f5b856e7 100644
@@ -43,7 +43,7 @@
 #define __ARM_NR_compat_cacheflush	(__ARM_NR_COMPAT_BASE+2)
 #define __ARM_NR_compat_set_tls		(__ARM_NR_COMPAT_BASE+5)
 
-#define __NR_compat_syscalls		398
+#define __NR_compat_syscalls		399
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +2 -0
index ef292160748c..0fdc7ef8a776 100644
@@ -817,6 +817,8 @@ __SYSCALL(__NR_pkey_alloc, sys_pkey_alloc)
 __SYSCALL(__NR_pkey_free, sys_pkey_free)
 #define __NR_statx 397
 __SYSCALL(__NR_statx, sys_statx)
+#define __NR_rseq 398
+__SYSCALL(__NR_rseq, sys_rseq)
 
 /*
  * Please add new compat syscalls above this comment and update
arch/arm64/kernel/entry.S +2 -0
index 28ad8799406f..1eda9e1a1f4a 100644
@@ -904,6 +904,7 @@ ENDPROC(el0_error)
 ret_fast_syscall:
 	disable_daif
 	str	x0, [sp, #S_X0]			// returned x0
+#ifndef CONFIG_DEBUG_RSEQ
 	ldr	x1, [tsk, #TSK_TI_FLAGS]	// re-check for syscall tracing
 	and	x2, x1, #_TIF_SYSCALL_WORK
 	cbnz	x2, ret_fast_syscall_trace
@@ -911,6 +912,7 @@ ret_fast_syscall:
 	cbnz	x2, work_pending
 	enable_step_tsk x1, x2
 	kernel_exit 0
+#endif
 ret_fast_syscall_trace:
 	enable_daif
 	b	__sys_trace_return_skipped	// we already saved x0
arch/arm64/kernel/ptrace.c +2 -0
index 5c338ce5a7fa..9f479c111675 100644
@@ -1656,6 +1656,8 @@ asmlinkage void syscall_trace_exit(struct pt_regs *regs)
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall(regs, PTRACE_SYSCALL_EXIT);
+
+	rseq_syscall(regs);
 }
 
 /*
arch/arm64/kernel/signal.c +3 -0
index 511af13e8d8f..e3b1d1b0aee8 100644
@@ -802,6 +802,8 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 	int usig = ksig->sig;
 	int ret;
 
+	rseq_signal_deliver(ksig, regs);
+
 	/*
 	 * Set up the stack frame
 	 */
@@ -940,6 +942,7 @@ asmlinkage void do_notify_resume(struct pt_regs *regs,
 			if (thread_flags & _TIF_NOTIFY_RESUME) {
 				clear_thread_flag(TIF_NOTIFY_RESUME);
 				tracehook_notify_resume(regs);
+				rseq_handle_notify_resume(NULL, regs);
 			}
 
 			if (thread_flags & _TIF_FOREIGN_FPSTATE)
Signature · 1 line
2.1.4
#2 lore raw

PATCH v2 2/3 asm-generic: unistd.h: Wire up sys_rseq

In reply to Will Deacon

The new rseq call arrived in 4.18-rc1, so provide it in the asm-generic unistd.h for architectures such as arm64.

---
 include/uapi/asm-generic/unistd.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/uapi/asm-generic/unistd.h +3 -1
index 42990676a55e..df4bedb9b01c 100644
@@ -734,9 +734,11 @@ __SYSCALL(__NR_pkey_free,     sys_pkey_free)
 __SYSCALL(__NR_statx,     sys_statx)
 #define __NR_io_pgetevents 292
 __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents)
+#define __NR_rseq 293
+__SYSCALL(__NR_rseq, sys_rseq)
 
 #undef __NR_syscalls
-#define __NR_syscalls 293
+#define __NR_syscalls 294
 
 /*
  * 32 bit systems traditionally used different
Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH v2 2/3] asm-generic: unistd.h: Wire up sys_rseq

Hi Arnd,

Quoted 8 lines · Will Deacon

The new rseq call arrived in 4.18-rc1, so provide it in the asm-generic unistd.h for architectures such as arm64.

---
 include/uapi/asm-generic/unistd.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Please can you Ack this, so I can take it the arm64 tree?

Thanks,

Will

Quoted 20 lines
include/uapi/asm-generic/unistd.h +3 -1
index 42990676a55e..df4bedb9b01c 100644
@@ -734,9 +734,11 @@ __SYSCALL(__NR_pkey_free,     sys_pkey_free)
 __SYSCALL(__NR_statx,     sys_statx)
 #define __NR_io_pgetevents 292
 __SC_COMP(__NR_io_pgetevents, sys_io_pgetevents, compat_sys_io_pgetevents)
+#define __NR_rseq 293
+__SYSCALL(__NR_rseq, sys_rseq)
 
 #undef __NR_syscalls
-#define __NR_syscalls 293
+#define __NR_syscalls 294
 
 /*
  * 32 bit systems traditionally used different
Signature · 1 line
2.1.4
maintainer Acked-by
#4 lore raw

Re: [PATCH v2 2/3] asm-generic: unistd.h: Wire up sys_rseq

Quoted 6 lines · Will Deacon

Hi Arnd,

Quoted 3 lines · Will Deacon

The new rseq call arrived in 4.18-rc1, so provide it in the asm-generic unistd.h for architectures such as arm64.

Quoted 7 lines
Quoted 5 lines
---
 include/uapi/asm-generic/unistd.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Please can you Ack this, so I can take it the arm64 tree?

I just checked again that this syscall is compatible with compat mode on all architectures that need it, so the addition is safe.

#5 lore raw

PATCH v2 3/3 rseq/selftests: Add support for arm64

In reply to Will Deacon

Hook up arm64 support to the rseq selftests.

---
 tools/testing/selftests/rseq/param_test.c |  20 +
 tools/testing/selftests/rseq/rseq-arm64.h | 594 ++++++++++++++++++++++++++++++
 tools/testing/selftests/rseq/rseq.h       |   2 +
 3 files changed, 616 insertions(+)
 create mode 100644 tools/testing/selftests/rseq/rseq-arm64.h
tools/testing/selftests/rseq/param_test.c +20 -0
index 615252331813..fa144c556371 100644
@@ -114,6 +114,26 @@ unsigned int yield_mod_cnt, nr_abort;
 	"bne 222b\n\t" \
 	"333:\n\t"
 
+#elif defined(__AARCH64EL__)
+
+#define RSEQ_INJECT_INPUT \
+	, [loop_cnt_1] "Qo" (loop_cnt[1]) \
+	, [loop_cnt_2] "Qo" (loop_cnt[2]) \
+	, [loop_cnt_3] "Qo" (loop_cnt[3]) \
+	, [loop_cnt_4] "Qo" (loop_cnt[4]) \
+	, [loop_cnt_5] "Qo" (loop_cnt[5]) \
+	, [loop_cnt_6] "Qo" (loop_cnt[6])
+
+#define INJECT_ASM_REG	RSEQ_ASM_TMP_REG32
+
+#define RSEQ_INJECT_ASM(n) \
+	"	ldr	" INJECT_ASM_REG ", %[loop_cnt_" #n "]\n"	\
+	"	cbz	" INJECT_ASM_REG ", 333f\n"			\
+	"222:\n"							\
+	"	sub	" INJECT_ASM_REG ", " INJECT_ASM_REG ", #1\n"	\
+	"	cbnz	" INJECT_ASM_REG ", 222b\n"			\
+	"333:\n"
+
 #elif __PPC__
 
 #define RSEQ_INJECT_INPUT \
tools/testing/selftests/rseq/rseq-arm64.h new file +594 -0

594 lines not on this page · raw message

tools/testing/selftests/rseq/rseq.h +2 -0
index 86ce22417e0d..bbdf472776b3 100644
@@ -71,6 +71,8 @@ extern __thread volatile struct rseq __rseq_abi;
 #include <rseq-x86.h>
 #elif defined(__ARMEL__)
 #include <rseq-arm.h>
+#elif defined (__AARCH64EL__)
+#include <rseq-arm64.h>
 #elif defined(__PPC__)
 #include <rseq-ppc.h>
 #elif defined(__mips__)
Signature · 1 line
2.1.4
maintainer Acked-by on the v2 series
#6 lore raw
In reply to Will Deacon
Quoted 6 lines · Will Deacon will.deacon at arm.com

Hello,

This is version two of the patches previously posted here:

http://lkml.kernel.org/r/1529949285-11013-1-git-send-email-will.deacon at arm.com

Quoted 7 lines

Changes since v1 include:

* Move abort handler in-line to avoid possibility of it being out-of-range for conditional branch instructions

I've tested both native and compat (little-endian only) with the selftests and they pass successfully on my Seattle box.

For the whole series:

Thanks!

Mathieu

Quoted 27 lines

Thanks,

Will

--->8

Will Deacon (3):
arm64: rseq: Implement backend rseq calls and select HAVE_RSEQ
asm-generic: unistd.h: Wire up sys_rseq rseq/selftests: Add support for arm64

arch/arm64/Kconfig                        |   1 +
arch/arm64/include/asm/unistd.h           |   2 +-
arch/arm64/include/asm/unistd32.h         |   2 +
arch/arm64/kernel/entry.S                 |   2 +
arch/arm64/kernel/ptrace.c                |   2 +
arch/arm64/kernel/signal.c                |   3 +
include/uapi/asm-generic/unistd.h         |   4 +-
tools/testing/selftests/rseq/param_test.c |  20 +
tools/testing/selftests/rseq/rseq-arm64.h | 594 ++++++++++++++++++++++++++++++
tools/testing/selftests/rseq/rseq.h       |   2 +
10 files changed, 630 insertions(+), 2 deletions(-)

create mode 100644 tools/testing/selftests/rseq/rseq-arm64.h

--
2.1.4

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#7 lore raw
Quoted 13 lines · Mathieu Desnoyers
Quoted 11 lines · ----- On Jul 9, 2018, at 10:19 AM, Will Deacon [email protected] wrote:

Hello,

This is version two of the patches previously posted here:

http://lkml.kernel.org/r/[email protected]

Changes since v1 include:

* Move abort handler in-line to avoid possibility of it being out-of-range for conditional branch instructions

Quoted 6 lines
Quoted 2 lines

I've tested both native and compat (little-endian only) with the selftests and they pass successfully on my Seattle box.

For the whole series:

Thanks, Mathieu! Are you ok with me taking this via the arm64 tree for 4.19 once I have an Ack for the asm-generic change, or would you rather this went via somewhere else?

Cheers,

Will

#8 lore raw
Quoted 17 lines · Will Deacon will.deacon at arm.com
Quoted 16 lines · Mathieu Desnoyers
Quoted 13 lines · Will Deacon will.deacon at arm.com

Hello,

This is version two of the patches previously posted here:

http://lkml.kernel.org/r/1529949285-11013-1-git-send-email-will.deacon at arm.com

Changes since v1 include:

* Move abort handler in-line to avoid possibility of it being out-of-range for conditional branch instructions

I've tested both native and compat (little-endian only) with the selftests and they pass successfully on my Seattle box.

Quoted 7 lines
Quoted 3 lines

For the whole series:

Thanks, Mathieu! Are you ok with me taking this via the arm64 tree for 4.19 once I have an Ack for the asm-generic change, or would you rather this went via somewhere else?

Adding Thomas Gleixner in CC. He has been picking up the rseq bits for 4.18. I've noticed it was rather easier to gather rseq stuff through a single tree (less chances of confusion).

Also, support for additional architectures (e.g. MIPS) was added to rseq after rc1. Is it too late to merge arm64 support targeting 4.18 ?

Thanks,

Mathieu

Quoted 4 lines

Cheers,

Will

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#9 lore raw
Quoted 23 lines · Mathieu Desnoyers
Quoted 21 lines · ----- On Jul 9, 2018, at 12:53 PM, Will Deacon [email protected] wrote:
Quoted 19 lines · Mathieu Desnoyers
Quoted 6 lines · ----- On Jul 9, 2018, at 10:19 AM, Will Deacon [email protected] wrote:

Hello,

This is version two of the patches previously posted here:

http://lkml.kernel.org/r/[email protected]

Quoted 7 lines

Changes since v1 include:

* Move abort handler in-line to avoid possibility of it being out-of-range for conditional branch instructions

I've tested both native and compat (little-endian only) with the selftests and they pass successfully on my Seattle box.

For the whole series:

Quoted 7 lines
Quoted 3 lines

Thanks, Mathieu! Are you ok with me taking this via the arm64 tree for 4.19 once I have an Ack for the asm-generic change, or would you rather this went via somewhere else?

Adding Thomas Gleixner in CC. He has been picking up the rseq bits for 4.18. I've noticed it was rather easier to gather rseq stuff through a single tree (less chances of confusion).

Whilst I can see that making some sense for the selftests (particularly if the ABI is liable to further changes before 4.18 is released), I'd prefer to take the arm64 bits via the arm64 tree, as they will conflict with some ongoing work to rewrite the syscall entry path in C which I plan to queue in the next week (pending final testing results).

Quoted 2 lines

Also, support for additional architectures (e.g. MIPS) was added to rseq after rc1. Is it too late to merge arm64 support targeting 4.18 ?

Personally, I don't see the rush, but I won't stop anybody who wants to try steam-rollering them into mainline ;)

Will

#10 lore raw
Quoted 32 lines · Will Deacon will.deacon at arm.com
Quoted 23 lines · Mathieu Desnoyers
Quoted 21 lines · Will Deacon will.deacon at arm.com
Quoted 19 lines · Mathieu Desnoyers
Quoted 6 lines · Will Deacon will.deacon at arm.com

Hello,

This is version two of the patches previously posted here:

http://lkml.kernel.org/r/1529949285-11013-1-git-send-email-will.deacon at arm.com

Quoted 7 lines

Changes since v1 include:

* Move abort handler in-line to avoid possibility of it being out-of-range for conditional branch instructions

I've tested both native and compat (little-endian only) with the selftests and they pass successfully on my Seattle box.

For the whole series:

Quoted 7 lines
Quoted 3 lines

Thanks, Mathieu! Are you ok with me taking this via the arm64 tree for 4.19 once I have an Ack for the asm-generic change, or would you rather this went via somewhere else?

Adding Thomas Gleixner in CC. He has been picking up the rseq bits for 4.18. I've noticed it was rather easier to gather rseq stuff through a single tree (less chances of confusion).

Quoted 5 lines

Whilst I can see that making some sense for the selftests (particularly if the ABI is liable to further changes before 4.18 is released), I'd prefer to take the arm64 bits via the arm64 tree, as they will conflict with some ongoing work to rewrite the syscall entry path in C which I plan to queue in the next week (pending final testing results).

Considering this, indeed going through the arm64 tree seems like the right approach.

Quoted 6 lines
Quoted 3 lines

Also, support for additional architectures (e.g. MIPS) was added to rseq after rc1. Is it too late to merge arm64 support targeting 4.18 ?

Personally, I don't see the rush, but I won't stop anybody who wants to try steam-rollering them into mainline ;)

There is indeed no rush. 4.19 it is then.

Thanks!

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com