1 From a95517992a37488c0bc8b629c47c570e580e407d Mon Sep 17 00:00:00 2001
2 From: Greg Ungerer <gerg@uclinux.org>
3 Date: Mon, 15 Feb 2016 16:36:29 +1000
4 Subject: m68k: Use conventional function parameters for do_sigreturn
6 Create conventional stack parameters for the calls to do_sigreturn and
7 do_rt_sigreturn. The current C code for do_sigreturn and do_rt_sigreturn
8 dig into the stack to create local pointers to the saved switch stack
9 and the pt_regs structs.
11 The motivation for this change is a problem with non-MMU targets that
12 have broken signal return paths on newer versions of gcc. It appears as
13 though gcc has determined that the pointers into the saved stack structs,
14 and the saved structs themselves, are function parameters and updates to
15 them will be lost on function return, so they are optimized away. This
16 results in large parts of restore_sigcontext() and mangle_kernel_stack()
17 functions being removed. Of course this results in non-functional code
18 causing kernel oops. This problem has been observed with gcc version
19 5.2 and 5.3, and probably exists in earlier versions as well.
21 Using conventional stack parameter pointers passed to these functions has
22 the advantage of the code here not needing to know the exact details of
23 how the underlying entry handler layed these structs out on the stack.
24 So the rather ugly pointer setup casting and arg referencing can be
27 The resulting code after this change is a few bytes larger (due to the
28 overhead of creating the stack args and their tear down). Not being hot
29 paths I don't think this is too much of a problem here.
31 An alternative solution is to put a barrier() in the do_sigreturn() code,
32 but this doesn't feel quite as clean as this solution.
34 This change has been compile tested on all defconfigs, and run tested on
35 Atari (through aranym), ColdFire with MMU (M5407EVB) and ColdFire with
36 no-MMU (QEMU and M5208EVB).
38 Signed-off-by: Greg Ungerer <gerg@uclinux.org>
39 Acked-by: Andreas Schwab <schwab@linux-m68k.org>
40 Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
42 arch/m68k/kernel/entry.S | 6 ++++++
43 arch/m68k/kernel/signal.c | 8 ++------
44 2 files changed, 8 insertions(+), 6 deletions(-)
46 diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S
47 index b54ac7a..97cd3ea 100644
48 --- a/arch/m68k/kernel/entry.S
49 +++ b/arch/m68k/kernel/entry.S
50 @@ -71,13 +71,19 @@ ENTRY(__sys_vfork)
54 + movel %sp,%sp@- | switch_stack pointer
55 + pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
61 ENTRY(sys_rt_sigreturn)
63 + movel %sp,%sp@- | switch_stack pointer
64 + pea %sp@(SWITCH_STACK_SIZE+4) | pt_regs pointer
70 diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
71 index af1c4f3..2dcee3a 100644
72 --- a/arch/m68k/kernel/signal.c
73 +++ b/arch/m68k/kernel/signal.c
74 @@ -737,10 +737,8 @@ badframe:
78 -asmlinkage int do_sigreturn(unsigned long __unused)
79 +asmlinkage int do_sigreturn(struct pt_regs *regs, struct switch_stack *sw)
81 - struct switch_stack *sw = (struct switch_stack *) &__unused;
82 - struct pt_regs *regs = (struct pt_regs *) (sw + 1);
83 unsigned long usp = rdusp();
84 struct sigframe __user *frame = (struct sigframe __user *)(usp - 4);
86 @@ -764,10 +762,8 @@ badframe:
90 -asmlinkage int do_rt_sigreturn(unsigned long __unused)
91 +asmlinkage int do_rt_sigreturn(struct pt_regs *regs, struct switch_stack *sw)
93 - struct switch_stack *sw = (struct switch_stack *) &__unused;
94 - struct pt_regs *regs = (struct pt_regs *) (sw + 1);
95 unsigned long usp = rdusp();
96 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(usp - 4);