* [PATCH 07/14] powerpc: Add support for restartable sequences
[not found] <20180430224433.17407-1-mathieu.desnoyers@efficios.com>
@ 2018-04-30 22:44 ` Mathieu Desnoyers
2018-05-16 16:18 ` Peter Zijlstra
2018-04-30 22:44 ` [PATCH 08/14] powerpc: Wire up restartable sequences system call Mathieu Desnoyers
1 sibling, 1 reply; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-04-30 22:44 UTC (permalink / raw)
To: Peter Zijlstra, Paul E . McKenney, Boqun Feng, Andy Lutomirski,
Dave Watson
Cc: linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H . Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, Steven Rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Will Deacon,
Michael Kerrisk, Joel Fernandes, Mathieu Desnoyers,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
linuxppc-dev
From: Boqun Feng <boqun.feng@gmail.com>
Call the rseq_handle_notify_resume() function on return to userspace if
TIF_NOTIFY_RESUME thread flag is set.
Perform fixup on the pre-signal when a signal is delivered on top of a
restartable sequence critical section.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: Peter Zijlstra <peterz@infradead.org>
CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
CC: linuxppc-dev@lists.ozlabs.org
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/kernel/signal.c | 3 +++
2 files changed, 4 insertions(+)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index c32a181a7cbb..ed21a777e8c6 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -223,6 +223,7 @@ config PPC
select HAVE_SYSCALL_TRACEPOINTS
select HAVE_VIRT_CPU_ACCOUNTING
select HAVE_IRQ_TIME_ACCOUNTING
+ select HAVE_RSEQ
select IRQ_DOMAIN
select IRQ_FORCED_THREADING
select MODULES_USE_ELF_RELA
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index 61db86ecd318..d3bb3aaaf5ac 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
/* Re-enable the breakpoints for the signal stack */
thread_change_pc(tsk, tsk->thread.regs);
+ rseq_signal_deliver(tsk->thread.regs);
+
if (is32) {
if (ksig.ka.sa.sa_flags & SA_SIGINFO)
ret = handle_rt_signal32(&ksig, oldset, tsk);
@@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
if (thread_info_flags & _TIF_NOTIFY_RESUME) {
clear_thread_flag(TIF_NOTIFY_RESUME);
tracehook_notify_resume(regs);
+ rseq_handle_notify_resume(regs);
}
user_enter();
--
2.11.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 08/14] powerpc: Wire up restartable sequences system call
[not found] <20180430224433.17407-1-mathieu.desnoyers@efficios.com>
2018-04-30 22:44 ` [PATCH 07/14] powerpc: Add support for restartable sequences Mathieu Desnoyers
@ 2018-04-30 22:44 ` Mathieu Desnoyers
1 sibling, 0 replies; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-04-30 22:44 UTC (permalink / raw)
To: Peter Zijlstra, Paul E . McKenney, Boqun Feng, Andy Lutomirski,
Dave Watson
Cc: linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H . Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, Steven Rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Will Deacon,
Michael Kerrisk, Joel Fernandes, Mathieu Desnoyers,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
linuxppc-dev
From: Boqun Feng <boqun.feng@gmail.com>
Wire up the rseq system call on powerpc.
This provides an ABI improving the speed of a user-space getcpu
operation on powerpc by skipping the getcpu system call on the fast
path, as well as improving the speed of user-space operations on per-cpu
data compared to using load-reservation/store-conditional atomics.
TODO: wire up rseq_syscall() on return from system call. It is used with
CONFIG_DEBUG_RSEQ=y to ensure system calls are not issued within rseq critical
section
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Paul Mackerras <paulus@samba.org>
CC: Michael Ellerman <mpe@ellerman.id.au>
CC: Peter Zijlstra <peterz@infradead.org>
CC: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
CC: linuxppc-dev@lists.ozlabs.org
---
arch/powerpc/include/asm/systbl.h | 1 +
arch/powerpc/include/asm/unistd.h | 2 +-
arch/powerpc/include/uapi/asm/unistd.h | 1 +
3 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/systbl.h b/arch/powerpc/include/asm/systbl.h
index d61f9c96d916..45d4d37495fd 100644
--- a/arch/powerpc/include/asm/systbl.h
+++ b/arch/powerpc/include/asm/systbl.h
@@ -392,3 +392,4 @@ SYSCALL(statx)
SYSCALL(pkey_alloc)
SYSCALL(pkey_free)
SYSCALL(pkey_mprotect)
+SYSCALL(rseq)
diff --git a/arch/powerpc/include/asm/unistd.h b/arch/powerpc/include/asm/unistd.h
index daf1ba97a00c..1e9708632dce 100644
--- a/arch/powerpc/include/asm/unistd.h
+++ b/arch/powerpc/include/asm/unistd.h
@@ -12,7 +12,7 @@
#include <uapi/asm/unistd.h>
-#define NR_syscalls 387
+#define NR_syscalls 388
#define __NR__exit __NR_exit
diff --git a/arch/powerpc/include/uapi/asm/unistd.h b/arch/powerpc/include/uapi/asm/unistd.h
index 389c36fd8299..ac5ba55066dd 100644
--- a/arch/powerpc/include/uapi/asm/unistd.h
+++ b/arch/powerpc/include/uapi/asm/unistd.h
@@ -398,5 +398,6 @@
#define __NR_pkey_alloc 384
#define __NR_pkey_free 385
#define __NR_pkey_mprotect 386
+#define __NR_rseq 387
#endif /* _UAPI_ASM_POWERPC_UNISTD_H_ */
--
2.11.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-04-30 22:44 ` [PATCH 07/14] powerpc: Add support for restartable sequences Mathieu Desnoyers
@ 2018-05-16 16:18 ` Peter Zijlstra
2018-05-16 20:13 ` Mathieu Desnoyers
0 siblings, 1 reply; 16+ messages in thread
From: Peter Zijlstra @ 2018-05-16 16:18 UTC (permalink / raw)
To: Mathieu Desnoyers
Cc: Paul E . McKenney, Boqun Feng, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H . Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, Steven Rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Will Deacon,
Michael Kerrisk, Joel Fernandes, Benjamin Herrenschmidt,
Paul Mackerras, Michael Ellerman, linuxppc-dev
On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote:
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index c32a181a7cbb..ed21a777e8c6 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -223,6 +223,7 @@ config PPC
> select HAVE_SYSCALL_TRACEPOINTS
> select HAVE_VIRT_CPU_ACCOUNTING
> select HAVE_IRQ_TIME_ACCOUNTING
> + select HAVE_RSEQ
> select IRQ_DOMAIN
> select IRQ_FORCED_THREADING
> select MODULES_USE_ELF_RELA
> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
> index 61db86ecd318..d3bb3aaaf5ac 100644
> --- a/arch/powerpc/kernel/signal.c
> +++ b/arch/powerpc/kernel/signal.c
> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
> /* Re-enable the breakpoints for the signal stack */
> thread_change_pc(tsk, tsk->thread.regs);
>
> + rseq_signal_deliver(tsk->thread.regs);
> +
> if (is32) {
> if (ksig.ka.sa.sa_flags & SA_SIGINFO)
> ret = handle_rt_signal32(&ksig, oldset, tsk);
> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
> if (thread_info_flags & _TIF_NOTIFY_RESUME) {
> clear_thread_flag(TIF_NOTIFY_RESUME);
> tracehook_notify_resume(regs);
> + rseq_handle_notify_resume(regs);
> }
>
> user_enter();
Again no rseq_syscall().
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-16 16:18 ` Peter Zijlstra
@ 2018-05-16 20:13 ` Mathieu Desnoyers
2018-05-17 1:19 ` Boqun Feng
0 siblings, 1 reply; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-05-16 20:13 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Paul E. McKenney, Boqun Feng, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, rostedt, Josh Triplett,
Linus Torvalds, Catalin Marinas, Will Deacon, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org wrote:
> On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote:
>> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> index c32a181a7cbb..ed21a777e8c6 100644
>> --- a/arch/powerpc/Kconfig
>> +++ b/arch/powerpc/Kconfig
>> @@ -223,6 +223,7 @@ config PPC
>> select HAVE_SYSCALL_TRACEPOINTS
>> select HAVE_VIRT_CPU_ACCOUNTING
>> select HAVE_IRQ_TIME_ACCOUNTING
>> + select HAVE_RSEQ
>> select IRQ_DOMAIN
>> select IRQ_FORCED_THREADING
>> select MODULES_USE_ELF_RELA
>> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
>> index 61db86ecd318..d3bb3aaaf5ac 100644
>> --- a/arch/powerpc/kernel/signal.c
>> +++ b/arch/powerpc/kernel/signal.c
>> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
>> /* Re-enable the breakpoints for the signal stack */
>> thread_change_pc(tsk, tsk->thread.regs);
>>
>> + rseq_signal_deliver(tsk->thread.regs);
>> +
>> if (is32) {
>> if (ksig.ka.sa.sa_flags & SA_SIGINFO)
>> ret = handle_rt_signal32(&ksig, oldset, tsk);
>> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long
>> thread_info_flags)
>> if (thread_info_flags & _TIF_NOTIFY_RESUME) {
>> clear_thread_flag(TIF_NOTIFY_RESUME);
>> tracehook_notify_resume(regs);
>> + rseq_handle_notify_resume(regs);
>> }
>>
>> user_enter();
>
> Again no rseq_syscall().
Same question for PowerPC as for ARM:
Considering that rseq_syscall is implemented as follows:
+void rseq_syscall(struct pt_regs *regs)
+{
+ unsigned long ip = instruction_pointer(regs);
+ struct task_struct *t = current;
+ struct rseq_cs rseq_cs;
+
+ if (!t->rseq)
+ return;
+ if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) ||
+ rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs))
+ force_sig(SIGSEGV, t);
+}
and that x86 calls it from syscall_return_slowpath() (which AFAIU is
now used in the fast-path since KPTI), I wonder where we should call
this on PowerPC ? I was under the impression that PowerPC return to
userspace fast-path was not calling C code unless work flags were set,
but I might be wrong.
Thoughts ?
Thanks!
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-16 20:13 ` Mathieu Desnoyers
@ 2018-05-17 1:19 ` Boqun Feng
2018-05-17 7:43 ` Peter Zijlstra
2018-05-17 15:28 ` Mathieu Desnoyers
0 siblings, 2 replies; 16+ messages in thread
From: Boqun Feng @ 2018-05-17 1:19 UTC (permalink / raw)
To: Mathieu Desnoyers
Cc: Peter Zijlstra, Paul E. McKenney, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, rostedt, Josh Triplett,
Linus Torvalds, Catalin Marinas, Will Deacon, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
[-- Attachment #1: Type: text/plain, Size: 3578 bytes --]
On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote:
> ----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org wrote:
>
> > On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote:
> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> >> index c32a181a7cbb..ed21a777e8c6 100644
> >> --- a/arch/powerpc/Kconfig
> >> +++ b/arch/powerpc/Kconfig
> >> @@ -223,6 +223,7 @@ config PPC
> >> select HAVE_SYSCALL_TRACEPOINTS
> >> select HAVE_VIRT_CPU_ACCOUNTING
> >> select HAVE_IRQ_TIME_ACCOUNTING
> >> + select HAVE_RSEQ
> >> select IRQ_DOMAIN
> >> select IRQ_FORCED_THREADING
> >> select MODULES_USE_ELF_RELA
> >> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
> >> index 61db86ecd318..d3bb3aaaf5ac 100644
> >> --- a/arch/powerpc/kernel/signal.c
> >> +++ b/arch/powerpc/kernel/signal.c
> >> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
> >> /* Re-enable the breakpoints for the signal stack */
> >> thread_change_pc(tsk, tsk->thread.regs);
> >>
> >> + rseq_signal_deliver(tsk->thread.regs);
> >> +
> >> if (is32) {
> >> if (ksig.ka.sa.sa_flags & SA_SIGINFO)
> >> ret = handle_rt_signal32(&ksig, oldset, tsk);
> >> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long
> >> thread_info_flags)
> >> if (thread_info_flags & _TIF_NOTIFY_RESUME) {
> >> clear_thread_flag(TIF_NOTIFY_RESUME);
> >> tracehook_notify_resume(regs);
> >> + rseq_handle_notify_resume(regs);
> >> }
> >>
> >> user_enter();
> >
> > Again no rseq_syscall().
>
> Same question for PowerPC as for ARM:
>
> Considering that rseq_syscall is implemented as follows:
>
> +void rseq_syscall(struct pt_regs *regs)
> +{
> + unsigned long ip = instruction_pointer(regs);
> + struct task_struct *t = current;
> + struct rseq_cs rseq_cs;
> +
> + if (!t->rseq)
> + return;
> + if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) ||
> + rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs))
> + force_sig(SIGSEGV, t);
> +}
>
> and that x86 calls it from syscall_return_slowpath() (which AFAIU is
> now used in the fast-path since KPTI), I wonder where we should call
So we actually detect this after the syscall takes effect, right? I
wonder whether this could be problematic, because "disallowing syscall"
in rseq areas may means the syscall won't take effect to some people, I
guess?
> this on PowerPC ? I was under the impression that PowerPC return to
> userspace fast-path was not calling C code unless work flags were set,
> but I might be wrong.
>
I think you're right. So we have to introduce callsite to rseq_syscall()
in syscall path, something like:
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 51695608c68b..a25734a96640 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -222,6 +222,9 @@ system_call_exit:
mtmsrd r11,1
#endif /* CONFIG_PPC_BOOK3E */
+ addi r3,r1,STACK_FRAME_OVERHEAD
+ bl rseq_syscall
+
ld r9,TI_FLAGS(r12)
li r11,-MAX_ERRNO
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
But I think it's important for us to first decide where (before or after
the syscall) we do the detection.
Regards,
Boqun
> Thoughts ?
>
> Thanks!
>
> Mathieu
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-17 1:19 ` Boqun Feng
@ 2018-05-17 7:43 ` Peter Zijlstra
2018-05-17 15:28 ` Mathieu Desnoyers
1 sibling, 0 replies; 16+ messages in thread
From: Peter Zijlstra @ 2018-05-17 7:43 UTC (permalink / raw)
To: Boqun Feng
Cc: Mathieu Desnoyers, Paul E. McKenney, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, rostedt, Josh Triplett,
Linus Torvalds, Catalin Marinas, Will Deacon, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
On Thu, May 17, 2018 at 09:19:49AM +0800, Boqun Feng wrote:
> On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote:
> > and that x86 calls it from syscall_return_slowpath() (which AFAIU is
> > now used in the fast-path since KPTI), I wonder where we should call
>
> So we actually detect this after the syscall takes effect, right? I
> wonder whether this could be problematic, because "disallowing syscall"
> in rseq areas may means the syscall won't take effect to some people, I
> guess?
It doesn't really matter I suspect, the important part is the program
getting killed.
I agree that doing it on sysenter is slightly nicer, but I'll take
sysexit if that's what it takes.
> > this on PowerPC ? I was under the impression that PowerPC return to
> > userspace fast-path was not calling C code unless work flags were set,
> > but I might be wrong.
> >
>
> I think you're right. So we have to introduce callsite to rseq_syscall()
> in syscall path, something like:
>
> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> index 51695608c68b..a25734a96640 100644
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -222,6 +222,9 @@ system_call_exit:
> mtmsrd r11,1
> #endif /* CONFIG_PPC_BOOK3E */
>
> + addi r3,r1,STACK_FRAME_OVERHEAD
> + bl rseq_syscall
> +
> ld r9,TI_FLAGS(r12)
> li r11,-MAX_ERRNO
> andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
>
> But I think it's important for us to first decide where (before or after
> the syscall) we do the detection.
The important thing is the processed getting very dead. Either sysenter
or sysexit gets that done.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-17 1:19 ` Boqun Feng
2018-05-17 7:43 ` Peter Zijlstra
@ 2018-05-17 15:28 ` Mathieu Desnoyers
2018-05-17 23:50 ` Boqun Feng
2018-05-18 12:38 ` Michael Ellerman
1 sibling, 2 replies; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-05-17 15:28 UTC (permalink / raw)
To: Boqun Feng, Will Deacon
Cc: Peter Zijlstra, Paul E. McKenney, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, rostedt, Josh Triplett,
Linus Torvalds, Catalin Marinas, Michael Kerrisk, Joel Fernandes,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
linuxppc-dev
----- On May 16, 2018, at 9:19 PM, Boqun Feng boqun.feng@gmail.com wrote:
> On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote:
>> ----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org wrote:
>>
>> > On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote:
>> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>> >> index c32a181a7cbb..ed21a777e8c6 100644
>> >> --- a/arch/powerpc/Kconfig
>> >> +++ b/arch/powerpc/Kconfig
>> >> @@ -223,6 +223,7 @@ config PPC
>> >> select HAVE_SYSCALL_TRACEPOINTS
>> >> select HAVE_VIRT_CPU_ACCOUNTING
>> >> select HAVE_IRQ_TIME_ACCOUNTING
>> >> + select HAVE_RSEQ
>> >> select IRQ_DOMAIN
>> >> select IRQ_FORCED_THREADING
>> >> select MODULES_USE_ELF_RELA
>> >> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
>> >> index 61db86ecd318..d3bb3aaaf5ac 100644
>> >> --- a/arch/powerpc/kernel/signal.c
>> >> +++ b/arch/powerpc/kernel/signal.c
>> >> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
>> >> /* Re-enable the breakpoints for the signal stack */
>> >> thread_change_pc(tsk, tsk->thread.regs);
>> >>
>> >> + rseq_signal_deliver(tsk->thread.regs);
>> >> +
>> >> if (is32) {
>> >> if (ksig.ka.sa.sa_flags & SA_SIGINFO)
>> >> ret = handle_rt_signal32(&ksig, oldset, tsk);
>> >> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long
>> >> thread_info_flags)
>> >> if (thread_info_flags & _TIF_NOTIFY_RESUME) {
>> >> clear_thread_flag(TIF_NOTIFY_RESUME);
>> >> tracehook_notify_resume(regs);
>> >> + rseq_handle_notify_resume(regs);
>> >> }
>> >>
>> >> user_enter();
>> >
>> > Again no rseq_syscall().
>>
>> Same question for PowerPC as for ARM:
>>
>> Considering that rseq_syscall is implemented as follows:
>>
>> +void rseq_syscall(struct pt_regs *regs)
>> +{
>> + unsigned long ip = instruction_pointer(regs);
>> + struct task_struct *t = current;
>> + struct rseq_cs rseq_cs;
>> +
>> + if (!t->rseq)
>> + return;
>> + if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) ||
>> + rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs))
>> + force_sig(SIGSEGV, t);
>> +}
>>
>> and that x86 calls it from syscall_return_slowpath() (which AFAIU is
>> now used in the fast-path since KPTI), I wonder where we should call
>
> So we actually detect this after the syscall takes effect, right? I
> wonder whether this could be problematic, because "disallowing syscall"
> in rseq areas may means the syscall won't take effect to some people, I
> guess?
>
>> this on PowerPC ? I was under the impression that PowerPC return to
>> userspace fast-path was not calling C code unless work flags were set,
>> but I might be wrong.
>>
>
> I think you're right. So we have to introduce callsite to rseq_syscall()
> in syscall path, something like:
>
> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> index 51695608c68b..a25734a96640 100644
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -222,6 +222,9 @@ system_call_exit:
> mtmsrd r11,1
> #endif /* CONFIG_PPC_BOOK3E */
>
> + addi r3,r1,STACK_FRAME_OVERHEAD
> + bl rseq_syscall
> +
> ld r9,TI_FLAGS(r12)
> li r11,-MAX_ERRNO
> andi.
> r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
>
> But I think it's important for us to first decide where (before or after
> the syscall) we do the detection.
As Peter said, we don't really care whether it's on syscall entry or exit, as
long as the process gets killed when the erroneous use is detected. I think doing
it on syscall exit is a bit easier because we can clearly access the userspace
TLS, which AFAIU may be less straightforward on syscall entry.
We may want to add #ifdef CONFIG_DEBUG_RSEQ / #endif around the code you
proposed above, so it's only compiled in if CONFIG_DEBUG_RSEQ=y.
On the ARM leg of the email thread, Will Deacon suggests to test whether current->rseq
is non-NULL before calling rseq_syscall(). I wonder if this added check is justified
as the assembly level, considering that this is just a debugging option. We already do
that check at the very beginning of rseq_syscall().
Thoughts ?
Thanks,
Mathieu
>
> Regards,
> Boqun
>
>> Thoughts ?
>>
>> Thanks!
>>
>> Mathieu
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
> > http://www.efficios.com
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-17 15:28 ` Mathieu Desnoyers
@ 2018-05-17 23:50 ` Boqun Feng
2018-05-18 18:17 ` Mathieu Desnoyers
2018-05-18 12:38 ` Michael Ellerman
1 sibling, 1 reply; 16+ messages in thread
From: Boqun Feng @ 2018-05-17 23:50 UTC (permalink / raw)
To: Mathieu Desnoyers, Will Deacon
Cc: Peter Zijlstra, Paul E. McKenney, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, rostedt, Josh Triplett,
Linus Torvalds, Catalin Marinas, Michael Kerrisk, Joel Fernandes,
Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
linuxppc-dev
On Thu, May 17, 2018, at 11:28 PM, Mathieu Desnoyers wrote:
> ----- On May 16, 2018, at 9:19 PM, Boqun Feng boqun.feng@gmail.com wrote:
>
> > On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote:
> >> ----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org wrote:
> >>
> >> > On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote:
> >> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> >> >> index c32a181a7cbb..ed21a777e8c6 100644
> >> >> --- a/arch/powerpc/Kconfig
> >> >> +++ b/arch/powerpc/Kconfig
> >> >> @@ -223,6 +223,7 @@ config PPC
> >> >> select HAVE_SYSCALL_TRACEPOINTS
> >> >> select HAVE_VIRT_CPU_ACCOUNTING
> >> >> select HAVE_IRQ_TIME_ACCOUNTING
> >> >> + select HAVE_RSEQ
> >> >> select IRQ_DOMAIN
> >> >> select IRQ_FORCED_THREADING
> >> >> select MODULES_USE_ELF_RELA
> >> >> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
> >> >> index 61db86ecd318..d3bb3aaaf5ac 100644
> >> >> --- a/arch/powerpc/kernel/signal.c
> >> >> +++ b/arch/powerpc/kernel/signal.c
> >> >> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
> >> >> /* Re-enable the breakpoints for the signal stack */
> >> >> thread_change_pc(tsk, tsk->thread.regs);
> >> >>
> >> >> + rseq_signal_deliver(tsk->thread.regs);
> >> >> +
> >> >> if (is32) {
> >> >> if (ksig.ka.sa.sa_flags & SA_SIGINFO)
> >> >> ret = handle_rt_signal32(&ksig, oldset, tsk);
> >> >> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long
> >> >> thread_info_flags)
> >> >> if (thread_info_flags & _TIF_NOTIFY_RESUME) {
> >> >> clear_thread_flag(TIF_NOTIFY_RESUME);
> >> >> tracehook_notify_resume(regs);
> >> >> + rseq_handle_notify_resume(regs);
> >> >> }
> >> >>
> >> >> user_enter();
> >> >
> >> > Again no rseq_syscall().
> >>
> >> Same question for PowerPC as for ARM:
> >>
> >> Considering that rseq_syscall is implemented as follows:
> >>
> >> +void rseq_syscall(struct pt_regs *regs)
> >> +{
> >> + unsigned long ip = instruction_pointer(regs);
> >> + struct task_struct *t = current;
> >> + struct rseq_cs rseq_cs;
> >> +
> >> + if (!t->rseq)
> >> + return;
> >> + if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) ||
> >> + rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs))
> >> + force_sig(SIGSEGV, t);
> >> +}
> >>
> >> and that x86 calls it from syscall_return_slowpath() (which AFAIU is
> >> now used in the fast-path since KPTI), I wonder where we should call
> >
> > So we actually detect this after the syscall takes effect, right? I
> > wonder whether this could be problematic, because "disallowing syscall"
> > in rseq areas may means the syscall won't take effect to some people, I
> > guess?
> >
> >> this on PowerPC ? I was under the impression that PowerPC return to
> >> userspace fast-path was not calling C code unless work flags were set,
> >> but I might be wrong.
> >>
> >
> > I think you're right. So we have to introduce callsite to rseq_syscall()
> > in syscall path, something like:
> >
> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> > index 51695608c68b..a25734a96640 100644
> > --- a/arch/powerpc/kernel/entry_64.S
> > +++ b/arch/powerpc/kernel/entry_64.S
> > @@ -222,6 +222,9 @@ system_call_exit:
> > mtmsrd r11,1
> > #endif /* CONFIG_PPC_BOOK3E */
> >
> > + addi r3,r1,STACK_FRAME_OVERHEAD
> > + bl rseq_syscall
> > +
> > ld r9,TI_FLAGS(r12)
> > li r11,-MAX_ERRNO
> > andi.
> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
> >
> > But I think it's important for us to first decide where (before or after
> > the syscall) we do the detection.
>
> As Peter said, we don't really care whether it's on syscall entry or
> exit, as
> long as the process gets killed when the erroneous use is detected. I
> think doing
> it on syscall exit is a bit easier because we can clearly access the
> userspace
> TLS, which AFAIU may be less straightforward on syscall entry.
>
Fair enough.
> We may want to add #ifdef CONFIG_DEBUG_RSEQ / #endif around the code you
> proposed above, so it's only compiled in if CONFIG_DEBUG_RSEQ=y.
>
OK.
> On the ARM leg of the email thread, Will Deacon suggests to test whether
> current->rseq
> is non-NULL before calling rseq_syscall(). I wonder if this added check
> is justified
> as the assembly level, considering that this is just a debugging option.
> We already do
> that check at the very beginning of rseq_syscall().
>
Yes, I think it's better to do the check in rseq_syscall(), leaving the asm
code a bit cleaner.
Regards,
Boqun
> Thoughts ?
>
> Thanks,
>
> Mathieu
>
> >
> > Regards,
> > Boqun
> >
> >> Thoughts ?
> >>
> >> Thanks!
> >>
> >> Mathieu
> >>
> >> --
> >> Mathieu Desnoyers
> >> EfficiOS Inc.
> > > http://www.efficios.com
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-17 15:28 ` Mathieu Desnoyers
2018-05-17 23:50 ` Boqun Feng
@ 2018-05-18 12:38 ` Michael Ellerman
1 sibling, 0 replies; 16+ messages in thread
From: Michael Ellerman @ 2018-05-18 12:38 UTC (permalink / raw)
To: Mathieu Desnoyers, Boqun Feng, Will Deacon
Cc: Peter Zijlstra, Paul E. McKenney, Andy Lutomirski, Dave Watson,
linux-kernel, linux-api, Paul Turner, Andrew Morton, Russell King,
Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Andrew Hunter,
Andi Kleen, Chris Lameter, Ben Maurer, rostedt, Josh Triplett,
Linus Torvalds, Catalin Marinas, Michael Kerrisk, Joel Fernandes,
Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev
Mathieu Desnoyers <mathieu.desnoyers@efficios.com> writes:
> ----- On May 16, 2018, at 9:19 PM, Boqun Feng boqun.feng@gmail.com wrote:
>> On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote:
>>> ----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org wrote:
>>> > On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote:
>>> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
>>> >> index c32a181a7cbb..ed21a777e8c6 100644
>>> >> --- a/arch/powerpc/Kconfig
>>> >> +++ b/arch/powerpc/Kconfig
>>> >> @@ -223,6 +223,7 @@ config PPC
>>> >> select HAVE_SYSCALL_TRACEPOINTS
>>> >> select HAVE_VIRT_CPU_ACCOUNTING
>>> >> select HAVE_IRQ_TIME_ACCOUNTING
>>> >> + select HAVE_RSEQ
>>> >> select IRQ_DOMAIN
>>> >> select IRQ_FORCED_THREADING
>>> >> select MODULES_USE_ELF_RELA
>>> >> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
>>> >> index 61db86ecd318..d3bb3aaaf5ac 100644
>>> >> --- a/arch/powerpc/kernel/signal.c
>>> >> +++ b/arch/powerpc/kernel/signal.c
>>> >> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk)
>>> >> /* Re-enable the breakpoints for the signal stack */
>>> >> thread_change_pc(tsk, tsk->thread.regs);
>>> >>
>>> >> + rseq_signal_deliver(tsk->thread.regs);
>>> >> +
>>> >> if (is32) {
>>> >> if (ksig.ka.sa.sa_flags & SA_SIGINFO)
>>> >> ret = handle_rt_signal32(&ksig, oldset, tsk);
>>> >> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long
>>> >> thread_info_flags)
>>> >> if (thread_info_flags & _TIF_NOTIFY_RESUME) {
>>> >> clear_thread_flag(TIF_NOTIFY_RESUME);
>>> >> tracehook_notify_resume(regs);
>>> >> + rseq_handle_notify_resume(regs);
>>> >> }
>>> >>
>>> >> user_enter();
>>> >
>>> > Again no rseq_syscall().
>>>
>>> Same question for PowerPC as for ARM:
>>>
>>> Considering that rseq_syscall is implemented as follows:
>>>
>>> +void rseq_syscall(struct pt_regs *regs)
>>> +{
>>> + unsigned long ip = instruction_pointer(regs);
>>> + struct task_struct *t = current;
>>> + struct rseq_cs rseq_cs;
>>> +
>>> + if (!t->rseq)
>>> + return;
>>> + if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) ||
>>> + rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs))
>>> + force_sig(SIGSEGV, t);
>>> +}
>>>
>>> and that x86 calls it from syscall_return_slowpath() (which AFAIU is
>>> now used in the fast-path since KPTI), I wonder where we should call
>>
>> So we actually detect this after the syscall takes effect, right? I
>> wonder whether this could be problematic, because "disallowing syscall"
>> in rseq areas may means the syscall won't take effect to some people, I
>> guess?
>>
>>> this on PowerPC ? I was under the impression that PowerPC return to
>>> userspace fast-path was not calling C code unless work flags were set,
>>> but I might be wrong.
>>>
>>
>> I think you're right. So we have to introduce callsite to rseq_syscall()
>> in syscall path, something like:
>>
>> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
>> index 51695608c68b..a25734a96640 100644
>> --- a/arch/powerpc/kernel/entry_64.S
>> +++ b/arch/powerpc/kernel/entry_64.S
>> @@ -222,6 +222,9 @@ system_call_exit:
>> mtmsrd r11,1
>> #endif /* CONFIG_PPC_BOOK3E */
>>
>> + addi r3,r1,STACK_FRAME_OVERHEAD
>> + bl rseq_syscall
>> +
>> ld r9,TI_FLAGS(r12)
>> li r11,-MAX_ERRNO
>> andi.
>> r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
>>
>> But I think it's important for us to first decide where (before or after
>> the syscall) we do the detection.
>
> As Peter said, we don't really care whether it's on syscall entry or exit, as
> long as the process gets killed when the erroneous use is detected. I think doing
> it on syscall exit is a bit easier because we can clearly access the userspace
> TLS, which AFAIU may be less straightforward on syscall entry.
Coming in to the thread late, sorry if I'm missing the point.
> We may want to add #ifdef CONFIG_DEBUG_RSEQ / #endif around the code you
> proposed above, so it's only compiled in if CONFIG_DEBUG_RSEQ=y.
That sounds good. A function call is not free even if it returns immediately.
> On the ARM leg of the email thread, Will Deacon suggests to test whether current->rseq
> is non-NULL before calling rseq_syscall(). I wonder if this added check is justified
> as the assembly level, considering that this is just a debugging option. We already do
> that check at the very beginning of rseq_syscall().
I guess it depends if this is one of those "debugging options" that's
going to end up turned on in distro kernels?
I think in that code we'd need to check paca->current->rseq, so that
wouldn't be free either.
cheers
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-17 23:50 ` Boqun Feng
@ 2018-05-18 18:17 ` Mathieu Desnoyers
2018-05-20 14:08 ` Boqun Feng
0 siblings, 1 reply; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-05-18 18:17 UTC (permalink / raw)
To: Boqun Feng
Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
----- On May 17, 2018, at 7:50 PM, Boqun Feng boqun.feng@gmail.com wrote:
[...]
>> > I think you're right. So we have to introduce callsite to rseq_syscall()
>> > in syscall path, something like:
>> >
>> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
>> > index 51695608c68b..a25734a96640 100644
>> > --- a/arch/powerpc/kernel/entry_64.S
>> > +++ b/arch/powerpc/kernel/entry_64.S
>> > @@ -222,6 +222,9 @@ system_call_exit:
>> > mtmsrd r11,1
>> > #endif /* CONFIG_PPC_BOOK3E */
>> >
>> > + addi r3,r1,STACK_FRAME_OVERHEAD
>> > + bl rseq_syscall
>> > +
>> > ld r9,TI_FLAGS(r12)
>> > li r11,-MAX_ERRNO
>> > andi.
>> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
>> >
By the way, I think this is not the right spot to call rseq_syscall, because
interrupts are disabled. I think we should move this hunk right after system_call_exit.
Would you like to implement and test an updated patch adding those calls for ppc 32 and 64 ?
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-18 18:17 ` Mathieu Desnoyers
@ 2018-05-20 14:08 ` Boqun Feng
2018-05-23 20:14 ` Mathieu Desnoyers
0 siblings, 1 reply; 16+ messages in thread
From: Boqun Feng @ 2018-05-20 14:08 UTC (permalink / raw)
To: Mathieu Desnoyers
Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
On Fri, May 18, 2018 at 02:17:17PM -0400, Mathieu Desnoyers wrote:
> ----- On May 17, 2018, at 7:50 PM, Boqun Feng boqun.feng@gmail.com wrote:
> [...]
> >> > I think you're right. So we have to introduce callsite to rseq_syscall()
> >> > in syscall path, something like:
> >> >
> >> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> >> > index 51695608c68b..a25734a96640 100644
> >> > --- a/arch/powerpc/kernel/entry_64.S
> >> > +++ b/arch/powerpc/kernel/entry_64.S
> >> > @@ -222,6 +222,9 @@ system_call_exit:
> >> > mtmsrd r11,1
> >> > #endif /* CONFIG_PPC_BOOK3E */
> >> >
> >> > + addi r3,r1,STACK_FRAME_OVERHEAD
> >> > + bl rseq_syscall
> >> > +
> >> > ld r9,TI_FLAGS(r12)
> >> > li r11,-MAX_ERRNO
> >> > andi.
> >> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
> >> >
>
> By the way, I think this is not the right spot to call rseq_syscall, because
> interrupts are disabled. I think we should move this hunk right after system_call_exit.
>
Good point.
> Would you like to implement and test an updated patch adding those calls for ppc 32 and 64 ?
>
I'd like to help, but I don't have a handy ppc environment for test...
So I made the below patch which has only been build-tested, hope it
could be somewhat helpful.
Regards,
Boqun
--------------------------------->8
Subject: [PATCH] powerpc: Add syscall detection for restartable sequences
Syscalls are not allowed inside restartable sequences, so add a call to
rseq_syscall() at the very beginning of system call exiting path for
CONFIG_DEBUG_RSEQ=y kernel. This could help us to detect whether there
is a syscall issued inside restartable sequences.
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
---
arch/powerpc/kernel/entry_32.S | 5 +++++
arch/powerpc/kernel/entry_64.S | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index eb8d01bae8c6..2f134eebe7ed 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -365,6 +365,11 @@ syscall_dotrace_cont:
blrl /* Call handler */
.globl ret_from_syscall
ret_from_syscall:
+#ifdef CONFIG_DEBUG_RSEQ
+ /* Check whether the syscall is issued inside a restartable sequence */
+ addi r3,r1,STACK_FRAME_OVERHEAD
+ bl rseq_syscall
+#endif
mr r6,r3
CURRENT_THREAD_INFO(r12, r1)
/* disable interrupts so current_thread_info()->flags can't change */
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 2cb5109a7ea3..2e2d59bb45d0 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -204,6 +204,11 @@ system_call: /* label this so stack traces look sane */
* This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL().
*/
system_call_exit:
+#ifdef CONFIG_DEBUG_RSEQ
+ /* Check whether the syscall is issued inside a restartable sequence */
+ addi r3,r1,STACK_FRAME_OVERHEAD
+ bl rseq_syscall
+#endif
/*
* Disable interrupts so current_thread_info()->flags can't change,
* and so that we don't get interrupted after loading SRR0/1.
--
2.16.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-20 14:08 ` Boqun Feng
@ 2018-05-23 20:14 ` Mathieu Desnoyers
2018-05-23 20:46 ` Paul E. McKenney
2018-05-23 21:29 ` Mathieu Desnoyers
0 siblings, 2 replies; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-05-23 20:14 UTC (permalink / raw)
To: Boqun Feng
Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
----- On May 20, 2018, at 10:08 AM, Boqun Feng boqun.feng@gmail.com wrote:
> On Fri, May 18, 2018 at 02:17:17PM -0400, Mathieu Desnoyers wrote:
>> ----- On May 17, 2018, at 7:50 PM, Boqun Feng boqun.feng@gmail.com wrote:
>> [...]
>> >> > I think you're right. So we have to introduce callsite to rseq_syscall()
>> >> > in syscall path, something like:
>> >> >
>> >> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
>> >> > index 51695608c68b..a25734a96640 100644
>> >> > --- a/arch/powerpc/kernel/entry_64.S
>> >> > +++ b/arch/powerpc/kernel/entry_64.S
>> >> > @@ -222,6 +222,9 @@ system_call_exit:
>> >> > mtmsrd r11,1
>> >> > #endif /* CONFIG_PPC_BOOK3E */
>> >> >
>> >> > + addi r3,r1,STACK_FRAME_OVERHEAD
>> >> > + bl rseq_syscall
>> >> > +
>> >> > ld r9,TI_FLAGS(r12)
>> >> > li r11,-MAX_ERRNO
>> >> > andi.
>> >> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
>> >> >
>>
>> By the way, I think this is not the right spot to call rseq_syscall, because
>> interrupts are disabled. I think we should move this hunk right after
>> system_call_exit.
>>
>
> Good point.
>
>> Would you like to implement and test an updated patch adding those calls for ppc
>> 32 and 64 ?
>>
>
> I'd like to help, but I don't have a handy ppc environment for test...
> So I made the below patch which has only been build-tested, hope it
> could be somewhat helpful.
Hi Boqun,
I tried your patch in a ppc64 le environment, and it does not survive boot
with CONFIG_DEBUG_RSEQ=y. init gets killed right away.
Moreover, I'm not sure that the r3 register don't contain something worth
saving before the call on ppc32. Just after there is a "mr" instruction
which AFAIU takes r3 as input register.
Can you look into it ?
Thanks,
Mathieu
>
> Regards,
> Boqun
>
> --------------------------------->8
> Subject: [PATCH] powerpc: Add syscall detection for restartable sequences
>
> Syscalls are not allowed inside restartable sequences, so add a call to
> rseq_syscall() at the very beginning of system call exiting path for
> CONFIG_DEBUG_RSEQ=y kernel. This could help us to detect whether there
> is a syscall issued inside restartable sequences.
>
> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> ---
> arch/powerpc/kernel/entry_32.S | 5 +++++
> arch/powerpc/kernel/entry_64.S | 5 +++++
> 2 files changed, 10 insertions(+)
>
> diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
> index eb8d01bae8c6..2f134eebe7ed 100644
> --- a/arch/powerpc/kernel/entry_32.S
> +++ b/arch/powerpc/kernel/entry_32.S
> @@ -365,6 +365,11 @@ syscall_dotrace_cont:
> blrl /* Call handler */
> .globl ret_from_syscall
> ret_from_syscall:
> +#ifdef CONFIG_DEBUG_RSEQ
> + /* Check whether the syscall is issued inside a restartable sequence */
> + addi r3,r1,STACK_FRAME_OVERHEAD
> + bl rseq_syscall
> +#endif
> mr r6,r3
> CURRENT_THREAD_INFO(r12, r1)
> /* disable interrupts so current_thread_info()->flags can't change */
> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> index 2cb5109a7ea3..2e2d59bb45d0 100644
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -204,6 +204,11 @@ system_call: /* label this so stack traces look sane */
> * This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL().
> */
> system_call_exit:
> +#ifdef CONFIG_DEBUG_RSEQ
> + /* Check whether the syscall is issued inside a restartable sequence */
> + addi r3,r1,STACK_FRAME_OVERHEAD
> + bl rseq_syscall
> +#endif
> /*
> * Disable interrupts so current_thread_info()->flags can't change,
> * and so that we don't get interrupted after loading SRR0/1.
> --
> 2.16.2
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-23 20:14 ` Mathieu Desnoyers
@ 2018-05-23 20:46 ` Paul E. McKenney
2018-05-23 21:29 ` Mathieu Desnoyers
1 sibling, 0 replies; 16+ messages in thread
From: Paul E. McKenney @ 2018-05-23 20:46 UTC (permalink / raw)
To: Mathieu Desnoyers
Cc: Boqun Feng, Will Deacon, Peter Zijlstra, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
On Wed, May 23, 2018 at 04:14:39PM -0400, Mathieu Desnoyers wrote:
> ----- On May 20, 2018, at 10:08 AM, Boqun Feng boqun.feng@gmail.com wrote:
>
> > On Fri, May 18, 2018 at 02:17:17PM -0400, Mathieu Desnoyers wrote:
> >> ----- On May 17, 2018, at 7:50 PM, Boqun Feng boqun.feng@gmail.com wrote:
> >> [...]
> >> >> > I think you're right. So we have to introduce callsite to rseq_syscall()
> >> >> > in syscall path, something like:
> >> >> >
> >> >> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> >> >> > index 51695608c68b..a25734a96640 100644
> >> >> > --- a/arch/powerpc/kernel/entry_64.S
> >> >> > +++ b/arch/powerpc/kernel/entry_64.S
> >> >> > @@ -222,6 +222,9 @@ system_call_exit:
> >> >> > mtmsrd r11,1
> >> >> > #endif /* CONFIG_PPC_BOOK3E */
> >> >> >
> >> >> > + addi r3,r1,STACK_FRAME_OVERHEAD
> >> >> > + bl rseq_syscall
> >> >> > +
> >> >> > ld r9,TI_FLAGS(r12)
> >> >> > li r11,-MAX_ERRNO
> >> >> > andi.
> >> >> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
> >> >> >
> >>
> >> By the way, I think this is not the right spot to call rseq_syscall, because
> >> interrupts are disabled. I think we should move this hunk right after
> >> system_call_exit.
> >>
> >
> > Good point.
> >
> >> Would you like to implement and test an updated patch adding those calls for ppc
> >> 32 and 64 ?
> >>
> >
> > I'd like to help, but I don't have a handy ppc environment for test...
> > So I made the below patch which has only been build-tested, hope it
> > could be somewhat helpful.
>
> Hi Boqun,
>
> I tried your patch in a ppc64 le environment, and it does not survive boot
> with CONFIG_DEBUG_RSEQ=y. init gets killed right away.
>
> Moreover, I'm not sure that the r3 register don't contain something worth
> saving before the call on ppc32. Just after there is a "mr" instruction
> which AFAIU takes r3 as input register.
>
> Can you look into it ?
Hello, Boqun,
You can also request access to a ppc64 environment here:
http://osuosl.org/services/powerdev/request_hosting/
Thanx, Paul
> Thanks,
>
> Mathieu
>
> >
> > Regards,
> > Boqun
> >
> > --------------------------------->8
> > Subject: [PATCH] powerpc: Add syscall detection for restartable sequences
> >
> > Syscalls are not allowed inside restartable sequences, so add a call to
> > rseq_syscall() at the very beginning of system call exiting path for
> > CONFIG_DEBUG_RSEQ=y kernel. This could help us to detect whether there
> > is a syscall issued inside restartable sequences.
> >
> > Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> > ---
> > arch/powerpc/kernel/entry_32.S | 5 +++++
> > arch/powerpc/kernel/entry_64.S | 5 +++++
> > 2 files changed, 10 insertions(+)
> >
> > diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
> > index eb8d01bae8c6..2f134eebe7ed 100644
> > --- a/arch/powerpc/kernel/entry_32.S
> > +++ b/arch/powerpc/kernel/entry_32.S
> > @@ -365,6 +365,11 @@ syscall_dotrace_cont:
> > blrl /* Call handler */
> > .globl ret_from_syscall
> > ret_from_syscall:
> > +#ifdef CONFIG_DEBUG_RSEQ
> > + /* Check whether the syscall is issued inside a restartable sequence */
> > + addi r3,r1,STACK_FRAME_OVERHEAD
> > + bl rseq_syscall
> > +#endif
> > mr r6,r3
> > CURRENT_THREAD_INFO(r12, r1)
> > /* disable interrupts so current_thread_info()->flags can't change */
> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> > index 2cb5109a7ea3..2e2d59bb45d0 100644
> > --- a/arch/powerpc/kernel/entry_64.S
> > +++ b/arch/powerpc/kernel/entry_64.S
> > @@ -204,6 +204,11 @@ system_call: /* label this so stack traces look sane */
> > * This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL().
> > */
> > system_call_exit:
> > +#ifdef CONFIG_DEBUG_RSEQ
> > + /* Check whether the syscall is issued inside a restartable sequence */
> > + addi r3,r1,STACK_FRAME_OVERHEAD
> > + bl rseq_syscall
> > +#endif
> > /*
> > * Disable interrupts so current_thread_info()->flags can't change,
> > * and so that we don't get interrupted after loading SRR0/1.
> > --
> > 2.16.2
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-23 20:14 ` Mathieu Desnoyers
2018-05-23 20:46 ` Paul E. McKenney
@ 2018-05-23 21:29 ` Mathieu Desnoyers
2018-05-24 1:03 ` Michael Ellerman
1 sibling, 1 reply; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-05-23 21:29 UTC (permalink / raw)
To: Boqun Feng
Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
Michael Ellerman, linuxppc-dev
----- On May 23, 2018, at 4:14 PM, Mathieu Desnoyers mathieu.desnoyers@efficios.com wrote:
> ----- On May 20, 2018, at 10:08 AM, Boqun Feng boqun.feng@gmail.com wrote:
>
>> On Fri, May 18, 2018 at 02:17:17PM -0400, Mathieu Desnoyers wrote:
>>> ----- On May 17, 2018, at 7:50 PM, Boqun Feng boqun.feng@gmail.com wrote:
>>> [...]
>>> >> > I think you're right. So we have to introduce callsite to rseq_syscall()
>>> >> > in syscall path, something like:
>>> >> >
>>> >> > diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
>>> >> > index 51695608c68b..a25734a96640 100644
>>> >> > --- a/arch/powerpc/kernel/entry_64.S
>>> >> > +++ b/arch/powerpc/kernel/entry_64.S
>>> >> > @@ -222,6 +222,9 @@ system_call_exit:
>>> >> > mtmsrd r11,1
>>> >> > #endif /* CONFIG_PPC_BOOK3E */
>>> >> >
>>> >> > + addi r3,r1,STACK_FRAME_OVERHEAD
>>> >> > + bl rseq_syscall
>>> >> > +
>>> >> > ld r9,TI_FLAGS(r12)
>>> >> > li r11,-MAX_ERRNO
>>> >> > andi.
>>> >> > r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
>>> >> >
>>>
>>> By the way, I think this is not the right spot to call rseq_syscall, because
>>> interrupts are disabled. I think we should move this hunk right after
>>> system_call_exit.
>>>
>>
>> Good point.
>>
>>> Would you like to implement and test an updated patch adding those calls for ppc
>>> 32 and 64 ?
>>>
>>
>> I'd like to help, but I don't have a handy ppc environment for test...
>> So I made the below patch which has only been build-tested, hope it
>> could be somewhat helpful.
>
> Hi Boqun,
>
> I tried your patch in a ppc64 le environment, and it does not survive boot
> with CONFIG_DEBUG_RSEQ=y. init gets killed right away.
The following fixup gets ppc64 to work:
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -208,6 +208,7 @@ system_call_exit:
/* Check whether the syscall is issued inside a restartable sequence */
addi r3,r1,STACK_FRAME_OVERHEAD
bl rseq_syscall
+ ld r3,RESULT(r1)
#endif
/*
* Disable interrupts so current_thread_info()->flags can't change,
> Moreover, I'm not sure that the r3 register don't contain something worth
> saving before the call on ppc32. Just after there is a "mr" instruction
> which AFAIU takes r3 as input register.
I'll start testing on ppc32 now.
Thanks,
Mathieu
>
> Can you look into it ?
>
> Thanks,
>
> Mathieu
>
>>
>> Regards,
>> Boqun
>>
>> --------------------------------->8
>> Subject: [PATCH] powerpc: Add syscall detection for restartable sequences
>>
>> Syscalls are not allowed inside restartable sequences, so add a call to
>> rseq_syscall() at the very beginning of system call exiting path for
>> CONFIG_DEBUG_RSEQ=y kernel. This could help us to detect whether there
>> is a syscall issued inside restartable sequences.
>>
>> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
>> ---
>> arch/powerpc/kernel/entry_32.S | 5 +++++
>> arch/powerpc/kernel/entry_64.S | 5 +++++
>> 2 files changed, 10 insertions(+)
>>
>> diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
>> index eb8d01bae8c6..2f134eebe7ed 100644
>> --- a/arch/powerpc/kernel/entry_32.S
>> +++ b/arch/powerpc/kernel/entry_32.S
>> @@ -365,6 +365,11 @@ syscall_dotrace_cont:
>> blrl /* Call handler */
>> .globl ret_from_syscall
>> ret_from_syscall:
>> +#ifdef CONFIG_DEBUG_RSEQ
>> + /* Check whether the syscall is issued inside a restartable sequence */
>> + addi r3,r1,STACK_FRAME_OVERHEAD
>> + bl rseq_syscall
>> +#endif
>> mr r6,r3
>> CURRENT_THREAD_INFO(r12, r1)
>> /* disable interrupts so current_thread_info()->flags can't change */
>> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
>> index 2cb5109a7ea3..2e2d59bb45d0 100644
>> --- a/arch/powerpc/kernel/entry_64.S
>> +++ b/arch/powerpc/kernel/entry_64.S
>> @@ -204,6 +204,11 @@ system_call: /* label this so stack traces look sane */
>> * This is blacklisted from kprobes further below with _ASM_NOKPROBE_SYMBOL().
>> */
>> system_call_exit:
>> +#ifdef CONFIG_DEBUG_RSEQ
>> + /* Check whether the syscall is issued inside a restartable sequence */
>> + addi r3,r1,STACK_FRAME_OVERHEAD
>> + bl rseq_syscall
>> +#endif
>> /*
>> * Disable interrupts so current_thread_info()->flags can't change,
>> * and so that we don't get interrupted after loading SRR0/1.
>> --
>> 2.16.2
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-23 21:29 ` Mathieu Desnoyers
@ 2018-05-24 1:03 ` Michael Ellerman
2018-05-28 7:00 ` Mathieu Desnoyers
0 siblings, 1 reply; 16+ messages in thread
From: Michael Ellerman @ 2018-05-24 1:03 UTC (permalink / raw)
To: Mathieu Desnoyers, Boqun Feng
Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
linuxppc-dev
Mathieu Desnoyers <mathieu.desnoyers@efficios.com> writes:
> ----- On May 23, 2018, at 4:14 PM, Mathieu Desnoyers mathieu.desnoyers@efficios.com wrote:
...
>>
>> Hi Boqun,
>>
>> I tried your patch in a ppc64 le environment, and it does not survive boot
>> with CONFIG_DEBUG_RSEQ=y. init gets killed right away.
Sorry this code is super gross and hard to deal with.
> The following fixup gets ppc64 to work:
>
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -208,6 +208,7 @@ system_call_exit:
> /* Check whether the syscall is issued inside a restartable sequence */
> addi r3,r1,STACK_FRAME_OVERHEAD
> bl rseq_syscall
> + ld r3,RESULT(r1)
> #endif
> /*
> * Disable interrupts so current_thread_info()->flags can't change,
I don't think that's safe.
If you look above that, we have r3, r8 and r12 all live:
.Lsyscall_exit:
std r3,RESULT(r1)
CURRENT_THREAD_INFO(r12, r1)
ld r8,_MSR(r1)
#ifdef CONFIG_PPC_BOOK3S
/* No MSR:RI on BookE */
andi. r10,r8,MSR_RI
beq- .Lunrecov_restore
#endif
They're all volatile across function calls:
http://openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240_68174.html
The system_call_exit symbol is actually there for kprobes and cosmetic
purposes. The actual syscall return flow starts at .Lsyscall_exit.
So I think this would work:
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index db4df061c33a..e19f377a25e0 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -184,6 +184,14 @@ system_call: /* label this so stack traces look sane */
.Lsyscall_exit:
std r3,RESULT(r1)
+
+#ifdef CONFIG_DEBUG_RSEQ
+ /* Check whether the syscall is issued inside a restartable sequence */
+ addi r3,r1,STACK_FRAME_OVERHEAD
+ bl rseq_syscall
+ ld r3,RESULT(r1)
+#endif
+
CURRENT_THREAD_INFO(r12, r1)
ld r8,_MSR(r1)
I'll try and get this series into my test setup at some point, been a
bit busy lately :)
cheers
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 07/14] powerpc: Add support for restartable sequences
2018-05-24 1:03 ` Michael Ellerman
@ 2018-05-28 7:00 ` Mathieu Desnoyers
0 siblings, 0 replies; 16+ messages in thread
From: Mathieu Desnoyers @ 2018-05-28 7:00 UTC (permalink / raw)
To: Michael Ellerman, Boqun Feng
Cc: Will Deacon, Peter Zijlstra, Paul E. McKenney, Andy Lutomirski,
Dave Watson, linux-kernel, linux-api, Paul Turner, Andrew Morton,
Russell King, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
Andrew Hunter, Andi Kleen, Chris Lameter, Ben Maurer, rostedt,
Josh Triplett, Linus Torvalds, Catalin Marinas, Michael Kerrisk,
Joel Fernandes, Benjamin Herrenschmidt, Paul Mackerras,
linuxppc-dev
----- On May 24, 2018, at 3:03 AM, Michael Ellerman mpe@ellerman.id.au wrote:
> Mathieu Desnoyers <mathieu.desnoyers@efficios.com> writes:
>> ----- On May 23, 2018, at 4:14 PM, Mathieu Desnoyers
>> mathieu.desnoyers@efficios.com wrote:
> ...
>>>
>>> Hi Boqun,
>>>
>>> I tried your patch in a ppc64 le environment, and it does not survive boot
>>> with CONFIG_DEBUG_RSEQ=y. init gets killed right away.
>
>
> Sorry this code is super gross and hard to deal with.
>
>> The following fixup gets ppc64 to work:
>>
>> --- a/arch/powerpc/kernel/entry_64.S
>> +++ b/arch/powerpc/kernel/entry_64.S
>> @@ -208,6 +208,7 @@ system_call_exit:
>> /* Check whether the syscall is issued inside a restartable sequence */
>> addi r3,r1,STACK_FRAME_OVERHEAD
>> bl rseq_syscall
>> + ld r3,RESULT(r1)
>> #endif
>> /*
>> * Disable interrupts so current_thread_info()->flags can't change,
>
> I don't think that's safe.
>
> If you look above that, we have r3, r8 and r12 all live:
>
> .Lsyscall_exit:
> std r3,RESULT(r1)
> CURRENT_THREAD_INFO(r12, r1)
>
> ld r8,_MSR(r1)
> #ifdef CONFIG_PPC_BOOK3S
> /* No MSR:RI on BookE */
> andi. r10,r8,MSR_RI
> beq- .Lunrecov_restore
> #endif
>
>
> They're all volatile across function calls:
>
> http://openpowerfoundation.org/wp-content/uploads/resources/leabi/content/dbdoclet.50655240_68174.html
>
>
> The system_call_exit symbol is actually there for kprobes and cosmetic
> purposes. The actual syscall return flow starts at .Lsyscall_exit.
>
> So I think this would work:
>
> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
> index db4df061c33a..e19f377a25e0 100644
> --- a/arch/powerpc/kernel/entry_64.S
> +++ b/arch/powerpc/kernel/entry_64.S
> @@ -184,6 +184,14 @@ system_call: /* label this so stack traces look sane */
>
> .Lsyscall_exit:
> std r3,RESULT(r1)
> +
> +#ifdef CONFIG_DEBUG_RSEQ
> + /* Check whether the syscall is issued inside a restartable sequence */
> + addi r3,r1,STACK_FRAME_OVERHEAD
> + bl rseq_syscall
> + ld r3,RESULT(r1)
> +#endif
> +
> CURRENT_THREAD_INFO(r12, r1)
>
> ld r8,_MSR(r1)
>
>
> I'll try and get this series into my test setup at some point, been a
> bit busy lately :)
Yes, this was needed. I had this in my tree already, but there is still
a kernel OOPS when running the rseq selftests on ppc64 with CONFIG_DEBUG_RSEQ=y.
My current dev tree is at: https://github.com/compudj/linux-percpu-dev/tree/rseq/dev-local
So considering we are at rc7 now, should I plan to removing the powerpc bits
for merge window submission, or is there someone planning to spend time on
fixing and testing ppc integration before the merge window opens ?
Thanks,
Mathieu
>
> cheers
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2018-05-28 7:00 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20180430224433.17407-1-mathieu.desnoyers@efficios.com>
2018-04-30 22:44 ` [PATCH 07/14] powerpc: Add support for restartable sequences Mathieu Desnoyers
2018-05-16 16:18 ` Peter Zijlstra
2018-05-16 20:13 ` Mathieu Desnoyers
2018-05-17 1:19 ` Boqun Feng
2018-05-17 7:43 ` Peter Zijlstra
2018-05-17 15:28 ` Mathieu Desnoyers
2018-05-17 23:50 ` Boqun Feng
2018-05-18 18:17 ` Mathieu Desnoyers
2018-05-20 14:08 ` Boqun Feng
2018-05-23 20:14 ` Mathieu Desnoyers
2018-05-23 20:46 ` Paul E. McKenney
2018-05-23 21:29 ` Mathieu Desnoyers
2018-05-24 1:03 ` Michael Ellerman
2018-05-28 7:00 ` Mathieu Desnoyers
2018-05-18 12:38 ` Michael Ellerman
2018-04-30 22:44 ` [PATCH 08/14] powerpc: Wire up restartable sequences system call 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).