powerpc: Switch signal 32 to using unsafe_put_user() and friends
Subsystems (2)
v2 cover powerpc: Switch signal 32 to using unsafe_put_user() and friends
This series leads to a reduction from 2.55s to 1.73s of the system CPU time with the following microbench app on an mpc832x with KUAP (approx 32%)
This series replaces copies to users by unsafe_put_user() and friends with user_write_access_begin() dance in signal32.
The advantages are:
- No KUAP unlock/lock at every copy
- More readable code.
- Better generated code.
Without KUAP, the difference is in the noise.
void sigusr1(int sig) { }
int main(int argc, char **argv)
{
int i = 100000;
signal(SIGUSR1, sigusr1);
for (;i--;)
raise(SIGUSR1);
exit(0);
}An additional 0.10s reduction is achieved by removing CONFIG_PPC_FPU, as the mpc832x has no FPU.
A bit less spectacular on an 8xx as KUAP is less heavy, prior to the series (with KUAP) it ran in 8.10 ms. Once applies the removal of FPU regs handling, we get 7.05s. With the full series, we get 6.9s. If artificially re-activating FPU regs handling with the full series, we get 7.6s.
So for the 8xx, the removal of the FPU regs copy is what makes the difference, but the rework of handle_signal also have a benefit.
Same as above, without KUAP the difference is in the noise.
Difference since v1(RFC):
- Almost copies to user are now replaced by unsafe_ alternative.
- Reworked a bit the FPU registers handling following feedback from Michael.
- Fixed a few build failures reported by Mr Robot on the RFC.
Christophe Leroy (25):
powerpc/signal: Move inline functions in signal.h powerpc/ptrace: Move declaration of ptrace_get_reg() and
ptrace_set_reg()
powerpc/ptrace: Consolidate reg index calculation powerpc/ptrace: Create ptrace_get_fpr() and ptrace_put_fpr() powerpc/signal: Don't manage floating point regs when no FPU powerpc/32s: Allow deselecting CONFIG_PPC_FPU on mpc832x powerpc/signal: Remove BUG_ON() in handler_signal functions powerpc/signal: Move access_ok() out of get_sigframe() powerpc/signal: Remove get_clean_sp()
powerpc/signal: Call get_tm_stackpointer() from get_sigframe() powerpc/signal: Refactor bad frame logging powerpc/signal32: Simplify logging in handle_rt_signal32() powerpc/signal32: Move handle_signal32() close to handle_rt_signal32() powerpc/signal32: Rename local pointers in handle_rt_signal32() powerpc/signal32: Misc changes to make handle_[rt_]_signal32() more
similar
powerpc/signal32: Move signal trampoline setup to handle_[rt_]signal32 powerpc/signal32: Switch handle_signal32() to user_access_begin()
logic
powerpc/signal32: Switch handle_rt_signal32() to user_access_begin()
logic
powerpc/signal32: Remove ifdefery in middle of if/else
signal: Add unsafe_put_compat_sigset()
powerpc/signal32: Add and use unsafe_put_sigset_t() powerpc/signal32: Switch swap_context() to user_access_begin() logic powerpc/signal: Create 'unsafe' versions of
copy_[ck][fpr/vsx]_to_user()
powerpc/signal32: Isolate non-copy actions in save_user_regs() and
save_tm_user_regs() powerpc/signal32: Transform save_user_regs() and save_tm_user_regs()
in 'unsafe' version
arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/processor.h | 16 +- arch/powerpc/include/asm/ptrace.h | 6 - arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kernel/head_32.S | 4 + arch/powerpc/kernel/process.c | 4 + arch/powerpc/kernel/ptrace/Makefile | 3 +- arch/powerpc/kernel/ptrace/ptrace-decl.h | 21 + arch/powerpc/kernel/ptrace/ptrace-fpu.c | 40 ++ arch/powerpc/kernel/ptrace/ptrace-view.c | 2 + arch/powerpc/kernel/ptrace/ptrace.c | 54 +- arch/powerpc/kernel/ptrace/ptrace32.c | 2 + arch/powerpc/kernel/signal.c | 59 +-- arch/powerpc/kernel/signal.h | 115 ++++- arch/powerpc/kernel/signal_32.c | 598 +++++++++++------------ arch/powerpc/kernel/signal_64.c | 21 +- arch/powerpc/kernel/traps.c | 2 + arch/powerpc/platforms/Kconfig.cputype | 15 +- include/linux/compat.h | 32 ++ 19 files changed, 566 insertions(+), 431 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-fpu.c
Signature · 1 line
2.25.0
PATCH v2 1/25 powerpc/signal: Move inline functions in signal.h
To really be inlined, the functions need to be defined in the same C file as the caller, or in an included header.
Move functions defined inline from signal .c in signal.h
--- arch/powerpc/kernel/signal.c | 30 -------------------------- arch/powerpc/kernel/signal.h | 41 +++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 38 deletions(-)
arch/powerpc/kernel/signal.c +0 -30
@@ -133,36 +133,6 @@ unsigned long copy_ckvsx_from_user(struct task_struct *task,return 0 ; }#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ -#else -inline unsigned long copy_fpr_to_user (void __user *to, -struct task_struct *task) -{ -return __copy_to_user (to, task->thread.fp_state.fpr, -ELF_NFPREG *sizeof (double )); -} - -inline unsigned long copy_fpr_from_user (struct task_struct *task, -void __user *from) -{ -return __copy_from_user (task->thread.fp_state.fpr, from, -ELF_NFPREG *sizeof (double )); -} - -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM -inline unsigned long copy_ckfpr_to_user (void __user *to, -struct task_struct *task) -{ -return __copy_to_user (to, task->thread.ckfp_state.fpr, -ELF_NFPREG *sizeof (double )); -} - -inline unsigned long copy_ckfpr_from_user (struct task_struct *task, -void __user *from) -{ -return __copy_from_user (task->thread.ckfp_state.fpr, from, -ELF_NFPREG *sizeof (double )); -} -#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ #endif /* Log an error when sending an unhandled signal to a process. Controlled
arch/powerpc/kernel/signal.h +33 -8
53 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH v2 2/25 powerpc/ptrace: Move declaration of ptrace_get_reg() and ptrace_set_reg()
In reply to Christophe Leroyptrace_get_reg() and ptrace_set_reg() are only used internally by ptrace.
Move them in arch/powerpc/kernel/ptrace/ptrace-decl.h
--- arch/powerpc/include/asm/ptrace.h | 6 ------ arch/powerpc/kernel/ptrace/ptrace-decl.h | 3 +++ arch/powerpc/kernel/ptrace/ptrace32.c | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-)
arch/powerpc/include/asm/ptrace.h +0 -6
@@ -171,12 +171,6 @@ static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)set_thread_flag (TIF_NOERROR ); \ }while (0 ) -struct task_struct; -extern int ptrace_get_reg (struct task_struct *task,int regno, -unsigned long *data); -extern int ptrace_put_reg (struct task_struct *task,int regno, -unsigned long data); - #define current_pt_regs() \ ((struct pt_regs *)((unsigned long )task_stack_page (current) +THREAD_SIZE ) -1 )
arch/powerpc/kernel/ptrace/ptrace-decl.h +3 -0
@@ -159,6 +159,9 @@ int tm_cgpr32_set(struct task_struct *target, const struct user_regset *regset,/* ptrace-view */ +int ptrace_get_reg (struct task_struct *task,int regno,unsigned long *data); +int ptrace_put_reg (struct task_struct *task,int regno,unsigned long data); +extern const struct user_regset_view user_ppc_native_view;/* ptrace-(no)adv */
arch/powerpc/kernel/ptrace/ptrace32.c +2 -0
@@ -23,6 +23,8 @@#include <asm/switch_to.h> +#include "ptrace-decl.h" +/* * does not yet catch signals sent when the child dies. * in exit.c or in signal.c.
Signature · 1 line
2.25.0
PATCH v2 3/25 powerpc/ptrace: Consolidate reg index calculation
In reply to Christophe LeroyToday we have:
#ifdef CONFIG_PPC32 index = addr >> 2; if ((addr & 3) || child->thread.regs == NULL) #else index = addr >> 3; if ((addr & 7)) #endif
sizeof(long) has value 4 for PPC32 and value 8 for PPC64.
Dividing by 4 is equivalent to >> 2 and dividing by 8 is equivalent to >> 3.
And 3 and 7 are respectively (sizeof(long) - 1).
Use sizeof(long) to get rid of the #ifdef CONFIG_PPC32 and consolidate the calculation and checking.
thread.regs have to be not NULL on both PPC32 and PPC64 so adding that test on PPC64 is harmless.
--- arch/powerpc/kernel/ptrace/ptrace.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
arch/powerpc/kernel/ptrace/ptrace.c +4 -14
@@ -55,14 +55,9 @@ long arch_ptrace(struct task_struct *child, long request, ret = -EIO ;/* convert to index and check */ -#ifdef CONFIG_PPC32 - index = addr >>2 ; -if ((addr &3 ) || (index >PT_FPSCR ) + index = addr /sizeof (long ); +if ((addr & (sizeof (long ) -1 )) || (index >PT_FPSCR ) || (child->thread.regs ==NULL )) -#else - index = addr >>3 ; - if ((addr & 7) || (index > PT_FPSCR)) -#endif break ;CHECK_FULL_REGS (child->thread.regs);
@@ -90,14 +85,9 @@ long arch_ptrace(struct task_struct *child, long request, ret = -EIO ;/* convert to index and check */ -#ifdef CONFIG_PPC32 - index = addr >>2 ; -if ((addr &3 ) || (index >PT_FPSCR ) + index = addr /sizeof (long ); +if ((addr & (sizeof (long ) -1 )) || (index >PT_FPSCR ) || (child->thread.regs ==NULL )) -#else - index = addr >>3 ; - if ((addr & 7) || (index > PT_FPSCR)) -#endif break ;CHECK_FULL_REGS (child->thread.regs);
Signature · 1 line
2.25.0
PATCH v2 4/25 powerpc/ptrace: Create ptrace_get_fpr() and ptrace_put_fpr()
In reply to Christophe LeroyOn the same model as ptrace_get_reg() and ptrace_put_reg(), create ptrace_get_fpr() and ptrace_put_fpr() to get/set the floating points registers.
We move the boundary checkings in them.
--- arch/powerpc/kernel/ptrace/Makefile | 1 + arch/powerpc/kernel/ptrace/ptrace-decl.h | 4 +++ arch/powerpc/kernel/ptrace/ptrace-fpu.c | 40 ++++++++++++++++++++++++ arch/powerpc/kernel/ptrace/ptrace.c | 40 +++++++----------------- 4 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 arch/powerpc/kernel/ptrace/ptrace-fpu.c
arch/powerpc/kernel/ptrace/Makefile +1 -0
@@ -6,6 +6,7 @@ CFLAGS_ptrace-view.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' obj-y += ptrace.o ptrace-view.o +obj-y += ptrace-fpu.o obj-$(CONFIG_COMPAT) += ptrace32.o obj-$(CONFIG_VSX) += ptrace-vsx.o ifneq ($(CONFIG_VSX),y)
arch/powerpc/kernel/ptrace/ptrace-decl.h +4 -0
@@ -164,6 +164,10 @@ int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data);extern const struct user_regset_view user_ppc_native_view; +/* ptrace-fpu */ +int ptrace_get_fpr (struct task_struct *child,int index,unsigned long *data); +int ptrace_put_fpr (struct task_struct *child,int index,unsigned long data); +/* ptrace-(no)adv */ void ppc_gethwdinfo (struct ppc_debug_info *dbginfo); int ptrace_get_debugreg(struct task_struct *child, unsigned long addr,
arch/powerpc/kernel/ptrace/ptrace-fpu.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/regset.h> + +#include <asm/switch_to.h> + +#include "ptrace-decl.h" + +int ptrace_get_fpr (struct task_struct *child,int index,unsigned long *data) +{ +unsigned int fpidx = index -PT_FPR0 ; + +if (index >PT_FPSCR ) +return -EIO ; + +flush_fp_to_thread (child); +if (fpidx < (PT_FPSCR -PT_FPR0 )) +memcpy (data, &child->thread.TS_FPR (fpidx),sizeof (long )); +else + *data = child->thread.fp_state.fpscr; + +return 0 ; +} + +int ptrace_put_fpr (struct task_struct *child,int index,unsigned long data) +{ +unsigned int fpidx = index -PT_FPR0 ; + +if (index >PT_FPSCR ) +return -EIO ; + +flush_fp_to_thread (child); +if (fpidx < (PT_FPSCR -PT_FPR0 )) +memcpy (&child->thread.TS_FPR (fpidx), &data,sizeof (long )); +else + child->thread.fp_state.fpscr = data; + +return 0 ; +} +
arch/powerpc/kernel/ptrace/ptrace.c +11 -29
@@ -56,25 +56,17 @@ long arch_ptrace(struct task_struct *child, long request, ret = -EIO ;/* convert to index and check */ index = addr /sizeof (long ); -if ((addr & (sizeof (long ) -1 )) || (index >PT_FPSCR ) - || (child->thread.regs ==NULL )) +if ((addr & (sizeof (long ) -1 )) || !child->thread.regs)break ;CHECK_FULL_REGS (child->thread.regs); -if (index <PT_FPR0 ) { +if (index <PT_FPR0 ) ret =ptrace_get_reg (child, (int ) index, &tmp); -if (ret) -break ; - }else { -unsigned int fpidx = index -PT_FPR0 ; - -flush_fp_to_thread (child); -if (fpidx < (PT_FPSCR -PT_FPR0 )) -memcpy (&tmp, &child->thread.TS_FPR (fpidx), -sizeof (long )); -else - tmp = child->thread.fp_state.fpscr; - } +else + ret =ptrace_get_fpr (child, index, &tmp); + +if (ret) +break ; ret =put_user (tmp, datalp);break ; }
@@ -86,24 +78,14 @@ long arch_ptrace(struct task_struct *child, long request, ret = -EIO ;/* convert to index and check */ index = addr /sizeof (long ); -if ((addr & (sizeof (long ) -1 )) || (index >PT_FPSCR ) - || (child->thread.regs ==NULL )) +if ((addr & (sizeof (long ) -1 )) || !child->thread.regs)break ;CHECK_FULL_REGS (child->thread.regs); -if (index <PT_FPR0 ) { +if (index <PT_FPR0 ) ret =ptrace_put_reg (child, index, data); - }else { -unsigned int fpidx = index -PT_FPR0 ; - -flush_fp_to_thread (child); -if (fpidx < (PT_FPSCR -PT_FPR0 )) -memcpy (&child->thread.TS_FPR (fpidx), &data, -sizeof (long )); -else - child->thread.fp_state.fpscr = data; - ret =0 ; - } +else + ret =ptrace_put_fpr (child, index, data);break ; }
Signature · 1 line
2.25.0
PATCH v2 5/25 powerpc/signal: Don't manage floating point regs when no FPU
In reply to Christophe LeroyThere is no point in copying floating point regs when there is no FPU and MATH_EMULATION is not selected.
Create a new CONFIG_PPC_FPU_REGS bool that is selected by CONFIG_MATH_EMULATION and CONFIG_PPC_FPU, and use it to opt out everything related to fp_state in thread_struct.
The asm const used only by fpu.S are opted out with CONFIG_PPC_FPU as fpu.S build is conditionnal to CONFIG_PPC_FPU.
The following app spends approx 8.1 seconds system time on an 8xx without the patch, and 7.0 seconds with the patch (13.5% reduction).
On an 832x, it spends approx 2.6 seconds system time without the patch and 2.1 seconds with the patch (19% reduction).
void sigusr1(int sig) { }
int main(int argc, char **argv)
{
int i = 100000;
signal(SIGUSR1, sigusr1);
for (;i--;)
raise(SIGUSR1);
exit(0);
}--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/processor.h | 2 ++ arch/powerpc/kernel/asm-offsets.c | 2 ++ arch/powerpc/kernel/process.c | 4 ++++ arch/powerpc/kernel/ptrace/Makefile | 4 ++-- arch/powerpc/kernel/ptrace/ptrace-decl.h | 14 ++++++++++++++ arch/powerpc/kernel/ptrace/ptrace-view.c | 2 ++ arch/powerpc/kernel/signal.h | 14 +++++++++++++- arch/powerpc/kernel/signal_32.c | 4 ++++ arch/powerpc/kernel/traps.c | 2 ++ arch/powerpc/platforms/Kconfig.cputype | 4 ++++ 11 files changed, 50 insertions(+), 3 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -416,6 +416,7 @@ config HUGETLB_PAGE_SIZE_VARIABLE config MATH_EMULATION bool "Math emulation" depends on 4xx || PPC_8xx || PPC_MPC832x || BOOKE + select PPC_FPU_REGS help Some PowerPC chips designed for embedded applications do not have a floating-point unit and therefore do not implement the
arch/powerpc/include/asm/processor.h +2 -0
@@ -175,8 +175,10 @@ struct thread_struct {#endif /* Debug Registers */ struct debug_reg debug; +#ifdef CONFIG_PPC_FPU_REGS struct thread_fp_state fp_state;struct thread_fp_state *fp_save_area; +#endif int fpexc_mode;/* floating-point exception mode */ unsigned int align_ctl;/* alignment handling control */ #ifdef CONFIG_HAVE_HW_BREAKPOINT
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -110,9 +110,11 @@ int main(void)#ifdef CONFIG_BOOKE OFFSET (THREAD_NORMSAVES , thread_struct, normsave[0 ]);#endif +#ifdef CONFIG_PPC_FPU OFFSET (THREAD_FPEXC_MODE , thread_struct, fpexc_mode);OFFSET (THREAD_FPSTATE , thread_struct, fp_state.fpr);OFFSET (THREAD_FPSAVEAREA , thread_struct, fp_save_area); +#endif OFFSET (FPSTATE_FPSCR , thread_fp_state, fpscr);OFFSET (THREAD_LOAD_FP , thread_struct, load_fp);#ifdef CONFIG_ALTIVEC
arch/powerpc/kernel/process.c +4 -0
@@ -1694,7 +1694,9 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, p->thread.ptrace_bps[i] =NULL ;#endif +#ifdef CONFIG_PPC_FPU_REGS p->thread.fp_save_area =NULL ; +#endif #ifdef CONFIG_ALTIVEC p->thread.vr_save_area =NULL ;#endif
@@ -1821,8 +1823,10 @@ void start_thread(struct pt_regs *regs, unsigned long start, unsigned long sp)#endif current->thread.load_slb =0 ; current->thread.load_fp =0 ; +#ifdef CONFIG_PPC_FPU_REGS memset (¤t->thread.fp_state,0 ,sizeof (current->thread.fp_state)); current->thread.fp_save_area =NULL ; +#endif #ifdef CONFIG_ALTIVEC memset (¤t->thread.vr_state,0 ,sizeof (current->thread.vr_state)); current->thread.vr_state.vscr.u[3 ] =0x00010000 ;/* Java mode disabled */
arch/powerpc/kernel/ptrace/Makefile +2 -2
@@ -6,11 +6,11 @@ CFLAGS_ptrace-view.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' obj-y += ptrace.o ptrace-view.o -obj-y += ptrace-fpu.o +obj-$(CONFIG_PPC_FPU_REGS) += ptrace-fpu.o obj-$(CONFIG_COMPAT) += ptrace32.o obj-$(CONFIG_VSX) += ptrace-vsx.o ifneq ($(CONFIG_VSX),y) -obj-y += ptrace-novsx.o +obj-$(CONFIG_PPC_FPU_REGS) += ptrace-novsx.o endif obj-$(CONFIG_ALTIVEC) += ptrace-altivec.o obj-$(CONFIG_SPE) += ptrace-spe.o
arch/powerpc/kernel/ptrace/ptrace-decl.h +14 -0
@@ -165,8 +165,22 @@ int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data);extern const struct user_regset_view user_ppc_native_view;/* ptrace-fpu */ +#ifdef CONFIG_PPC_FPU_REGS int ptrace_get_fpr (struct task_struct *child,int index,unsigned long *data);int ptrace_put_fpr (struct task_struct *child,int index,unsigned long data); +#else +static inline int +ptrace_get_fpr (struct task_struct *child,int index,unsigned long *data) +{ +return -EIO ; +} + +static inline int +ptrace_put_fpr (struct task_struct *child,int index,unsigned long data) +{ +return -EIO ; +} +#endif /* ptrace-(no)adv */ void ppc_gethwdinfo (struct ppc_debug_info *dbginfo);
arch/powerpc/kernel/ptrace/ptrace-view.c +2 -0
@@ -520,11 +520,13 @@ static const struct user_regset native_regsets[] = { .size = sizeof(long), .align = sizeof(long), .regset_get = gpr_get, .set = gpr_set }, +#ifdef CONFIG_PPC_FPU_REGS [REGSET_FPR] = { .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, .size = sizeof(double), .align = sizeof(double), .regset_get = fpr_get, .set = fpr_set }, +#endif #ifdef CONFIG_ALTIVEC [REGSET_VMX] = { .core_note_type = NT_PPC_VMX, .n = 34,
arch/powerpc/kernel/signal.h +13 -1
@@ -34,7 +34,7 @@ unsigned long copy_fpr_to_user(void __user *to, struct task_struct *task);unsigned long copy_ckfpr_to_user (void __user *to,struct task_struct *task);unsigned long copy_fpr_from_user (struct task_struct *task,void __user *from);unsigned long copy_ckfpr_from_user (struct task_struct *task,void __user *from); -#else +#elif defined(CONFIG_PPC_FPU_REGS )static inline unsigned long copy_fpr_to_user (void __user *to,struct task_struct *task) {
@@ -63,6 +63,18 @@ copy_ckfpr_from_user(struct task_struct *task, void __user *from) ELF_NFPREG * sizeof(double)); }#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ +#else +static inline unsigned long +copy_fpr_to_user (void __user *to,struct task_struct *task) +{ +return 0 ; +} + +static inline unsigned long +copy_fpr_from_user (struct task_struct *task,void __user *from) +{ +return 0 ; +}#endif #ifdef CONFIG_PPC64
arch/powerpc/kernel/signal_32.c +4 -0
@@ -814,7 +814,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, } regs->link = tramp; +#ifdef CONFIG_PPC_FPU_REGS tsk->thread.fp_state.fpscr =0 ;/* turn off all fp exceptions */ +#endif /* create a stack frame for the caller of the handler */ newsp = ((unsigned long )rt_sf) - (__SIGNAL_FRAMESIZE +16 );
@@ -1271,7 +1273,9 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, regs->link = tramp; +#ifdef CONFIG_PPC_FPU_REGS tsk->thread.fp_state.fpscr =0 ;/* turn off all fp exceptions */ +#endif /* create a stack frame for the caller of the handler */ newsp = ((unsigned long )frame) - __SIGNAL_FRAMESIZE;
arch/powerpc/kernel/traps.c +2 -0
@@ -1194,7 +1194,9 @@ static void parse_fpe(struct pt_regs *regs)flush_fp_to_thread (current); +#ifdef CONFIG_PPC_FPU_REGS code =__parse_fpscr (current->thread.fp_state.fpscr); +#endif _exception (SIGFPE , regs, code, regs->nip); }
arch/powerpc/platforms/Kconfig.cputype +4 -0
@@ -225,9 +225,13 @@ config PPC_E500MC such as e5500/e6500), and must be disabled for running on e500v1 or e500v2. +config PPC_FPU_REGS + bool + config PPC_FPU bool default y if PPC64 + select PPC_FPU_REGS config FSL_EMB_PERFMON bool "Freescale Embedded Perfmon"
Signature · 1 line
2.25.0
PATCH v2 6/25 powerpc/32s: Allow deselecting CONFIG_PPC_FPU on mpc832x
In reply to Christophe LeroyThe e300c2 core which is embedded in mpc832x CPU doesn't have an FPU.
Make it possible to not select CONFIG_PPC_FPU when building a kernel dedicated to that target.
--- arch/powerpc/kernel/head_32.S | 4 ++++ arch/powerpc/platforms/Kconfig.cputype | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
arch/powerpc/kernel/head_32.S +4 -0
@@ -413,6 +413,7 @@ Alignment: . = 0x800 DO_KVM 0x800 FPUnavailable: +#ifdef CONFIG_PPC_FPU BEGIN_FTR_SECTION /* * Certain Freescale cores don't have a FPU and treat fp instructions
@@ -426,6 +427,9 @@ END_FTR_SECTION_IFSET(CPU_FTR_FPU_UNAVAILABLE) b fast_exception_return 1: addi r3,r1,STACK_FRAME_OVERHEAD EXC_XFER_LITE(0x800, kernel_fp_unavailable_exception) +#else + b ProgramCheck +#endif /* Decrementer */ EXCEPTION(0x900, Decrementer, timer_interrupt, EXC_XFER_LITE)
arch/powerpc/platforms/Kconfig.cputype +9 -2
@@ -32,7 +32,7 @@ choice config PPC_BOOK3S_6xx bool "512x/52xx/6xx/7xx/74xx/82xx/83xx/86xx except 601" select PPC_BOOK3S_32 - select PPC_FPU + imply PPC_FPU select PPC_HAVE_PMU_SUPPORT select PPC_HAVE_KUEP select PPC_HAVE_KUAP
@@ -229,9 +229,16 @@ config PPC_FPU_REGS bool config PPC_FPU - bool + bool "Support for Floating Point Unit (FPU)" if PPC_MPC832x default y if PPC64 select PPC_FPU_REGS + help + This must be enabled to support the Floating Point Unit + Most 6xx have an FPU but e300c2 core (mpc832x) don't have + an FPU, so when building an embedded kernel for that target + you can disable FPU support. + + If unsure say Y. config FSL_EMB_PERFMON bool "Freescale Embedded Perfmon"
Signature · 1 line
2.25.0
PATCH v2 7/25 powerpc/signal: Remove BUG_ON() in handler_signal functions
In reply to Christophe LeroyThere is already the same BUG_ON() check in do_signal() which is the only caller of handle_rt_signal64() handle_rt_signal32() and handle_signal32().
Remove those three redundant BUG_ON().
--- arch/powerpc/kernel/signal_32.c | 4 ---- arch/powerpc/kernel/signal_64.c | 2 -- 2 files changed, 6 deletions(-)
arch/powerpc/kernel/signal_32.c +0 -4
@@ -764,8 +764,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,unsigned long msr = regs->msr;#endif -BUG_ON (tsk != current); -/* Set up Signal Frame */ /* Put a Real Time Context onto stack */ rt_sf =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*rt_sf),1 );
@@ -1227,8 +1225,6 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,unsigned long msr = regs->msr;#endif -BUG_ON (tsk != current); -/* Set up Signal Frame */ frame =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*frame),1 );if (unlikely (frame ==NULL ))
arch/powerpc/kernel/signal_64.c +0 -2
@@ -822,8 +822,6 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,unsigned long msr = regs->msr;#endif -BUG_ON (tsk != current); - frame =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*frame),0 );if (unlikely (frame ==NULL )) goto badframe;
Signature · 1 line
2.25.0
PATCH v2 8/25 powerpc/signal: Move access_ok() out of get_sigframe()
In reply to Christophe LeroyThis access_ok() will soon be performed by user_access_begin(). So move it out of get_sigframe().
--- arch/powerpc/kernel/signal.c | 4 ---- arch/powerpc/kernel/signal_32.c | 4 ++-- arch/powerpc/kernel/signal_64.c | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-)
arch/powerpc/kernel/signal.c +0 -4
@@ -154,10 +154,6 @@ void __user *get_sigframe(struct ksignal *ksig, unsigned long sp, oldsp =sigsp (oldsp, ksig); newsp = (oldsp - frame_size) & ~0xFUL ; -/* Check access */ -if (!access_ok ((void __user *)newsp, oldsp - newsp)) -return NULL ; -return (void __user *)newsp; }
arch/powerpc/kernel/signal_32.c +2 -2
@@ -768,7 +768,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* Put a Real Time Context onto stack */ rt_sf =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*rt_sf),1 ); addr = rt_sf; -if (unlikely (rt_sf ==NULL )) +if (!access_ok (rt_sf,sizeof (*rt_sf))) goto badframe;/* Put the siginfo & fill in most of the ucontext */
@@ -1227,7 +1227,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,/* Set up Signal Frame */ frame =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*frame),1 ); -if (unlikely (frame ==NULL )) +if (!access_ok (frame,sizeof (*frame))) goto badframe; sc = (struct sigcontext __user *) &frame->sctx;
arch/powerpc/kernel/signal_64.c +1 -1
@@ -823,7 +823,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,#endif frame =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*frame),0 ); -if (unlikely (frame ==NULL )) +if (!access_ok (frame,sizeof (*frame))) goto badframe; err |=__put_user (&frame->info, &frame->pinfo);
Signature · 1 line
2.25.0
PATCH v2 9/25 powerpc/signal: Remove get_clean_sp()
In reply to Christophe Leroyget_clean_sp() is only used once in kernel/signal.c .
GCC is smart enough to see that x & 0xffffffff is a nop calculation on PPC32, no need of a special PPC32 trivial version.
Include the logic from the PPC64 version of get_clean_sp() directly in get_sigframe().
--- arch/powerpc/include/asm/processor.h | 14 -------------- arch/powerpc/kernel/signal.c | 5 ++++- 2 files changed, 4 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/processor.h +0 -14
@@ -406,20 +406,6 @@ static inline void prefetchw(const void *x)#define HAVE_ARCH_PICK_MMAP_LAYOUT -#ifdef CONFIG_PPC64 -static inline unsigned long get_clean_sp (unsigned long sp,int is_32) -{ -if (is_32) -return sp &0x0ffffffffUL ; -return sp; -} -#else -static inline unsigned long get_clean_sp (unsigned long sp,int is_32) -{ -return sp; -} -#endif -/* asm stubs */ extern unsigned long isa300_idle_stop_noloss (unsigned long psscr_val);extern unsigned long isa300_idle_stop_mayloss (unsigned long psscr_val);
arch/powerpc/kernel/signal.c +4 -1
@@ -150,7 +150,10 @@ void __user *get_sigframe(struct ksignal *ksig, unsigned long sp,unsigned long oldsp, newsp;/* Default to using normal stack */ - oldsp =get_clean_sp (sp, is_32); +if (is_32) + oldsp = sp &0x0ffffffffUL ; +else + oldsp = sp; oldsp =sigsp (oldsp, ksig); newsp = (oldsp - frame_size) & ~0xFUL ;
Signature · 1 line
2.25.0
PATCH v2 10/25 powerpc/signal: Call get_tm_stackpointer() from get_sigframe()
In reply to Christophe LeroyInstead of calling get_tm_stackpointer() from the caller, call it directly from get_sigframe(). This avoids a double call and allows get_tm_stackpointer() to become static and be inlined into get_sigframe() by GCC.
--- arch/powerpc/kernel/signal.c | 9 ++++++--- arch/powerpc/kernel/signal.h | 6 ++---- arch/powerpc/kernel/signal_32.c | 4 ++-- arch/powerpc/kernel/signal_64.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-)
arch/powerpc/kernel/signal.c +6 -3
@@ -144,10 +144,13 @@ int show_unhandled_signals = 1;/* * Allocate space for the signal frame */ -void __user *get_sigframe (struct ksignal *ksig,unsigned long sp, -size_t frame_size,int is_32) +static unsigned long get_tm_stackpointer (struct task_struct *tsk); + +void __user *get_sigframe (struct ksignal *ksig,struct task_struct *tsk, +size_t frame_size,int is_32) {unsigned long oldsp, newsp; +unsigned long sp =get_tm_stackpointer (tsk);/* Default to using normal stack */ if (is_32)
@@ -304,7 +307,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)user_enter (); } -unsigned long get_tm_stackpointer (struct task_struct *tsk) +static unsigned long get_tm_stackpointer (struct task_struct *tsk) {/* When in an active transaction that takes a signal, we need to be * careful with the stack. It's possible that the stack has moved back
arch/powerpc/kernel/signal.h +2 -4
@@ -10,8 +10,8 @@#ifndef _POWERPC_ARCH_SIGNAL_H#define _POWERPC_ARCH_SIGNAL_H -extern void __user *get_sigframe (struct ksignal *ksig,unsigned long sp, -size_t frame_size,int is_32); +void __user *get_sigframe (struct ksignal *ksig,struct task_struct *tsk, +size_t frame_size,int is_32);extern int handle_signal32 (struct ksignal *ksig,sigset_t *oldset,struct task_struct *tsk);
@@ -19,8 +19,6 @@ extern int handle_signal32(struct ksignal *ksig, sigset_t *oldset,extern int handle_rt_signal32 (struct ksignal *ksig,sigset_t *oldset,struct task_struct *tsk); -extern unsigned long get_tm_stackpointer (struct task_struct *tsk); -#ifdef CONFIG_VSX extern unsigned long copy_vsx_to_user (void __user *to,struct task_struct *task);
arch/powerpc/kernel/signal_32.c +2 -2
@@ -766,7 +766,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* Set up Signal Frame */ /* Put a Real Time Context onto stack */ - rt_sf =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*rt_sf),1 ); + rt_sf =get_sigframe (ksig, tsk,sizeof (*rt_sf),1 ); addr = rt_sf;if (!access_ok (rt_sf,sizeof (*rt_sf))) goto badframe;
@@ -1226,7 +1226,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,#endif /* Set up Signal Frame */ - frame =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*frame),1 ); + frame =get_sigframe (ksig, tsk,sizeof (*frame),1 );if (!access_ok (frame,sizeof (*frame))) goto badframe; sc = (struct sigcontext __user *) &frame->sctx;
arch/powerpc/kernel/signal_64.c +1 -1
@@ -822,7 +822,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,unsigned long msr = regs->msr;#endif - frame =get_sigframe (ksig,get_tm_stackpointer (tsk),sizeof (*frame),0 ); + frame =get_sigframe (ksig, tsk,sizeof (*frame),0 );if (!access_ok (frame,sizeof (*frame))) goto badframe;
Signature · 1 line
2.25.0
PATCH v2 11/25 powerpc/signal: Refactor bad frame logging
In reply to Christophe LeroyThe logging of bad frame appears half a dozen of times and is pretty similar.
Create signal_fault() fonction to perform that logging.
--- arch/powerpc/kernel/signal.c | 11 +++++++++++ arch/powerpc/kernel/signal.h | 3 +++ arch/powerpc/kernel/signal_32.c | 35 +++++---------------------------- arch/powerpc/kernel/signal_64.c | 15 ++------------ 4 files changed, 21 insertions(+), 43 deletions(-)
arch/powerpc/kernel/signal.c +11 -0
@@ -355,3 +355,14 @@ static unsigned long get_tm_stackpointer(struct task_struct *tsk)#endif return ret; } + +static const char fm32[] =KERN_INFO "%s[%d]: bad frame in %s: %p nip %08lx lr %08lx\n" ; +static const char fm64[] =KERN_INFO "%s[%d]: bad frame in %s: %p nip %016lx lr %016lx\n" ; + +void signal_fault (struct task_struct *tsk,struct pt_regs *regs, +const char *where,void __user *ptr) +{ +if (show_unhandled_signals) +printk_ratelimited (regs->msr &MSR_64BIT ? fm64 : fm32, tsk->comm, +task_pid_nr (tsk), where, ptr, regs->nip, regs->link); +}
arch/powerpc/kernel/signal.h +3 -0
@@ -93,4 +93,7 @@ static inline int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,#endif /* !defined(CONFIG_PPC64) */ +void signal_fault (struct task_struct *tsk,struct pt_regs *regs, +const char *where,void __user *ptr); +#endif /* _POWERPC_ARCH_SIGNAL_H */
arch/powerpc/kernel/signal_32.c +5 -30
@@ -835,12 +835,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,return 0 ; badframe: -if (show_unhandled_signals) -printk_ratelimited (KERN_INFO -"%s[%d]: bad frame in handle_rt_signal32: " -"%p nip %08lx lr %08lx\n" , - tsk->comm, tsk->pid, - addr, regs->nip, regs->link); +signal_fault (tsk, regs,"handle_rt_signal32" , addr);return 1 ; }
@@ -1092,12 +1087,7 @@ SYSCALL_DEFINE0(rt_sigreturn)return 0 ; bad: -if (show_unhandled_signals) -printk_ratelimited (KERN_INFO -"%s[%d]: bad frame in sys_rt_sigreturn: " -"%p nip %08lx lr %08lx\n" , - current->comm, current->pid, - rt_sf, regs->nip, regs->link); +signal_fault (current, regs,"sys_rt_sigreturn" , rt_sf);force_sig (SIGSEGV );return 0 ;
@@ -1181,12 +1171,7 @@ SYSCALL_DEFINE3(debug_setcontext, struct ucontext __user *, ctx,* We kill the task with a SIGSEGV in this situation. */ if (do_setcontext (ctx, regs,1 )) { -if (show_unhandled_signals) -printk_ratelimited (KERN_INFO "%s[%d]: bad frame in " -"sys_debug_setcontext: %p nip %08lx " -"lr %08lx\n" , - current->comm, current->pid, - ctx, regs->nip, regs->link); +signal_fault (current, regs,"sys_debug_setcontext" , ctx);force_sig (SIGSEGV ); goto out;
@@ -1287,12 +1272,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,return 0 ; badframe: -if (show_unhandled_signals) -printk_ratelimited (KERN_INFO -"%s[%d]: bad frame in handle_signal32: " -"%p nip %08lx lr %08lx\n" , - tsk->comm, tsk->pid, - frame, regs->nip, regs->link); +signal_fault (tsk, regs,"handle_signal32" , frame);return 1 ; }
@@ -1363,12 +1343,7 @@ SYSCALL_DEFINE0(sigreturn)return 0 ; badframe: -if (show_unhandled_signals) -printk_ratelimited (KERN_INFO -"%s[%d]: bad frame in sys_sigreturn: " -"%p nip %08lx lr %08lx\n" , - current->comm, current->pid, - addr, regs->nip, regs->link); +signal_fault (current, regs,"sys_sigreturn" , addr);force_sig (SIGSEGV );return 0 ;
arch/powerpc/kernel/signal_64.c +2 -13
@@ -66,11 +66,6 @@ struct rt_sigframe {char abigap[USER_REDZONE_SIZE ]; } __attribute__ ((aligned (16))); -static const char fmt32[] =KERN_INFO \ -"%s[%d]: bad frame in %s: %08lx nip %08lx lr %08lx\n" ; -static const char fmt64[] =KERN_INFO \ -"%s[%d]: bad frame in %s: %016lx nip %016lx lr %016lx\n" ; -/* * This computes a quad word aligned pointer inside the vmx_reserve array * element. For historical reasons sigcontext might not be quad word aligned,
@@ -801,10 +796,7 @@ SYSCALL_DEFINE0(rt_sigreturn)return 0 ; badframe: -if (show_unhandled_signals) -printk_ratelimited (regs->msr &MSR_64BIT ? fmt64 : fmt32, - current->comm, current->pid,"rt_sigreturn" , - (long )uc, regs->nip, regs->link); +signal_fault (current, regs,"rt_sigreturn" , uc);force_sig (SIGSEGV );return 0 ;
@@ -911,10 +903,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set,return 0 ; badframe: -if (show_unhandled_signals) -printk_ratelimited (regs->msr &MSR_64BIT ? fmt64 : fmt32, - tsk->comm, tsk->pid,"setup_rt_frame" , - (long )frame, regs->nip, regs->link); +signal_fault (current, regs,"handle_rt_signal64" , frame);return 1 ; }
Signature · 1 line
2.25.0
Re: [PATCH v2 11/25] powerpc/signal: Refactor bad frame logging
Quoted 2 lines · Christophe Leroy
The logging of bad frame appears half a dozen of times and is pretty similar.
[]
arch/powerpc/kernel/signal.c
Quoted 1 line
arch/powerpc/kernel/signal.c +0
-0
[]
arch/powerpc/kernel/signal.c static unsigned long get_tm_stackpointer(struct task_struct *tsk) · line 360
Quoted 7 lines
arch/powerpc/kernel/signal.c +3
-0@@ -355,3 +355,14 @@ static unsigned long get_tm_stackpointer(struct task_struct *tsk)#endif return ret; } + +static const char fm32[] =KERN_INFO "%s[%d]: bad frame in %s: %p nip %08lx lr %08lx\n" ; +static const char fm64[] =KERN_INFO "%s[%d]: bad frame in %s: %p nip %016lx lr %016lx\n" ;
Why not remove this and use it in place with
%08lx/%016x used as %px with a case to (void *)?
arch/powerpc/kernel/signal.c static unsigned long get_tm_stackpointer(struct task_struct *tsk) · line 367
Quoted 6 lines
arch/powerpc/kernel/signal.c +6
-0+void signal_fault (struct task_struct *tsk,struct pt_regs *regs, +const char *where,void __user *ptr) +{ +if (show_unhandled_signals) +printk_ratelimited (regs->msr &MSR_64BIT ? fm64 : fm32, tsk->comm, +task_pid_nr (tsk), where, ptr, regs->nip, regs->link);
pr_info_ratelimited("%s[%d]: bad frame in %s: %p nip %016lx lr %016lx\n",
tsk->comm, task_pid_nr(tsk), where, ptr,
(void *)regs->nip, (void *)regs->link);PATCH v2 12/25 powerpc/signal32: Simplify logging in handle_rt_signal32()
In reply to Christophe LeroyIf something is bad in the frame, there is no point in knowing which part of the frame exactly is wrong as it got allocated as a single block.
Always print the root address of the frame in case of failed user access, just like handle_signal32().
--- arch/powerpc/kernel/signal_32.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/kernel/signal_32.c +1 -5
@@ -754,7 +754,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,struct rt_sigframe __user *rt_sf;struct mcontext __user *frame;struct mcontext __user *tm_frame =NULL ; -void __user *addr;unsigned long newsp =0 ;int sigret;unsigned long tramp;
@@ -767,7 +766,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* Set up Signal Frame */ /* Put a Real Time Context onto stack */ rt_sf =get_sigframe (ksig, tsk,sizeof (*rt_sf),1 ); - addr = rt_sf;if (!access_ok (rt_sf,sizeof (*rt_sf))) goto badframe;
@@ -782,7 +780,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* Save user registers on the stack */ frame = &rt_sf->uc.uc_mcontext; - addr = frame;if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) { sigret =0 ; tramp = tsk->mm->context.vdso_base + vdso32_rt_sigtramp;
@@ -818,7 +815,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* create a stack frame for the caller of the handler */ newsp = ((unsigned long )rt_sf) - (__SIGNAL_FRAMESIZE +16 ); - addr = (void __user *)regs->gpr[1 ];if (put_user (regs->gpr[1 ], (u32 __user *)newsp)) goto badframe;
@@ -835,7 +831,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,return 0 ; badframe: -signal_fault (tsk, regs,"handle_rt_signal32" , addr); +signal_fault (tsk, regs,"handle_rt_signal32" , rt_sf);return 1 ; }
Signature · 1 line
2.25.0
PATCH v2 13/25 powerpc/signal32: Move handle_signal32() close to handle_rt_signal32()
In reply to Christophe LeroyThose two functions are similar and serving the same purpose. To ease refactorisation, move them close to each other.
This is pure move, no code change, no cosmetic. Yes, checkpatch is not happy, most will clear later.
--- arch/powerpc/kernel/signal_32.c | 170 ++++++++++++++++---------------- 1 file changed, 85 insertions(+), 85 deletions(-)
arch/powerpc/kernel/signal_32.c +85 -85
@@ -836,6 +836,91 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,return 1 ; } +/* +* OK, we're invoking a handler +*/ +int handle_signal32 (struct ksignal *ksig,sigset_t *oldset, +struct task_struct *tsk) +{ +struct sigcontext __user *sc; +struct sigframe __user *frame; +struct mcontext __user *tm_mctx =NULL ; +unsigned long newsp =0 ; +int sigret; +unsigned long tramp; +struct pt_regs *regs = tsk->thread.regs; +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +/* Save the thread's msr before get_tm_stackpointer() changes it */ +unsigned long msr = regs->msr; +#endif + +/* Set up Signal Frame */ + frame =get_sigframe (ksig, tsk,sizeof (*frame),1 ); +if (!access_ok (frame,sizeof (*frame))) + goto badframe; + sc = (struct sigcontext __user *) &frame->sctx; + +#if _NSIG !=64 +#error "Please adjust handle_signal()" +#endif +if (__put_user (to_user_ptr (ksig->ka.sa.sa_handler), &sc->handler) + ||__put_user (oldset->sig[0 ], &sc->oldmask) +#ifdef CONFIG_PPC64 + ||__put_user ((oldset->sig[0 ] >>32 ), &sc->_unused[3 ]) +#else + ||__put_user (oldset->sig[1 ], &sc->_unused[3 ]) +#endif + ||__put_user (to_user_ptr (&frame->mctx), &sc->regs) + ||__put_user (ksig->sig, &sc->signal)) + goto badframe; + +if (vdso32_sigtramp && tsk->mm->context.vdso_base) { + sigret =0 ; + tramp = tsk->mm->context.vdso_base + vdso32_sigtramp; + }else { + sigret = __NR_sigreturn; + tramp = (unsigned long ) frame->mctx.tramp; + } + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + tm_mctx = &frame->mctx_transact; +if (MSR_TM_ACTIVE (msr)) { +if (save_tm_user_regs (regs, &frame->mctx, &frame->mctx_transact, + sigret, msr)) + goto badframe; + } + else +#endif + { +if (save_user_regs (regs, &frame->mctx, tm_mctx, sigret,1 )) + goto badframe; + } + + regs->link = tramp; + +#ifdef CONFIG_PPC_FPU_REGS + tsk->thread.fp_state.fpscr =0 ;/* turn off all fp exceptions */ +#endif + +/* create a stack frame for the caller of the handler */ + newsp = ((unsigned long )frame) - __SIGNAL_FRAMESIZE; +if (put_user (regs->gpr[1 ], (u32 __user *)newsp)) + goto badframe; + + regs->gpr[1 ] = newsp; + regs->gpr[3 ] = ksig->sig; + regs->gpr[4 ] = (unsigned long ) sc; + regs->nip = (unsigned long ) (unsigned long )ksig->ka.sa.sa_handler; +/* enter the signal handler in big-endian mode */ + regs->msr &= ~MSR_LE ; +return 0 ; + +badframe: +signal_fault (tsk, regs,"handle_signal32" , frame); + +return 1 ; +} +static int do_setcontext (struct ucontext __user *ucp,struct pt_regs *regs,int sig) {sigset_t set;
@@ -1188,91 +1273,6 @@ SYSCALL_DEFINE3(debug_setcontext, struct ucontext __user *, ctx, }#endif -/* -* OK, we're invoking a handler -*/ -int handle_signal32 (struct ksignal *ksig,sigset_t *oldset, -struct task_struct *tsk) -{ -struct sigcontext __user *sc; -struct sigframe __user *frame; -struct mcontext __user *tm_mctx =NULL ; -unsigned long newsp =0 ; -int sigret; -unsigned long tramp; -struct pt_regs *regs = tsk->thread.regs; -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM -/* Save the thread's msr before get_tm_stackpointer() changes it */ -unsigned long msr = regs->msr; -#endif - -/* Set up Signal Frame */ - frame =get_sigframe (ksig, tsk,sizeof (*frame),1 ); -if (!access_ok (frame,sizeof (*frame))) - goto badframe; - sc = (struct sigcontext __user *) &frame->sctx; - -#if _NSIG !=64 -#error "Please adjust handle_signal()" -#endif -if (__put_user (to_user_ptr (ksig->ka.sa.sa_handler), &sc->handler) - ||__put_user (oldset->sig[0 ], &sc->oldmask) -#ifdef CONFIG_PPC64 - ||__put_user ((oldset->sig[0 ] >>32 ), &sc->_unused[3 ]) -#else - ||__put_user (oldset->sig[1 ], &sc->_unused[3 ]) -#endif - ||__put_user (to_user_ptr (&frame->mctx), &sc->regs) - ||__put_user (ksig->sig, &sc->signal)) - goto badframe; - -if (vdso32_sigtramp && tsk->mm->context.vdso_base) { - sigret =0 ; - tramp = tsk->mm->context.vdso_base + vdso32_sigtramp; - }else { - sigret = __NR_sigreturn; - tramp = (unsigned long ) frame->mctx.tramp; - } - -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM - tm_mctx = &frame->mctx_transact; -if (MSR_TM_ACTIVE (msr)) { -if (save_tm_user_regs (regs, &frame->mctx, &frame->mctx_transact, - sigret, msr)) - goto badframe; - } - else -#endif - { -if (save_user_regs (regs, &frame->mctx, tm_mctx, sigret,1 )) - goto badframe; - } - - regs->link = tramp; - -#ifdef CONFIG_PPC_FPU_REGS - tsk->thread.fp_state.fpscr =0 ;/* turn off all fp exceptions */ -#endif - -/* create a stack frame for the caller of the handler */ - newsp = ((unsigned long )frame) - __SIGNAL_FRAMESIZE; -if (put_user (regs->gpr[1 ], (u32 __user *)newsp)) - goto badframe; - - regs->gpr[1 ] = newsp; - regs->gpr[3 ] = ksig->sig; - regs->gpr[4 ] = (unsigned long ) sc; - regs->nip = (unsigned long ) (unsigned long )ksig->ka.sa.sa_handler; -/* enter the signal handler in big-endian mode */ - regs->msr &= ~MSR_LE ; -return 0 ; - -badframe: -signal_fault (tsk, regs,"handle_signal32" , frame); - -return 1 ; -} -/* * Do a signal return; undo the signal stack. */
Signature · 1 line
2.25.0
PATCH v2 14/25 powerpc/signal32: Rename local pointers in handle_rt_signal32()
In reply to Christophe LeroyRename pointers in handle_rt_signal32() to make it more similar to handle_signal32()
tm_frame becomes tm_mctx
frame becomes mctxrt_sf becomes frame
--- arch/powerpc/kernel/signal_32.c | 51 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 26 deletions(-)
arch/powerpc/kernel/signal_32.c +25 -26
@@ -751,9 +751,9 @@ static long restore_tm_user_regs(struct pt_regs *regs,int handle_rt_signal32 (struct ksignal *ksig,sigset_t *oldset,struct task_struct *tsk) { -struct rt_sigframe __user *rt_sf; -struct mcontext __user *frame; -struct mcontext __user *tm_frame =NULL ; +struct rt_sigframe __user *frame; +struct mcontext __user *mctx; +struct mcontext __user *tm_mctx =NULL ;unsigned long newsp =0 ;int sigret;unsigned long tramp;
@@ -765,46 +765,45 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* Set up Signal Frame */ /* Put a Real Time Context onto stack */ - rt_sf =get_sigframe (ksig, tsk,sizeof (*rt_sf),1 ); -if (!access_ok (rt_sf,sizeof (*rt_sf))) + frame =get_sigframe (ksig, tsk,sizeof (*frame),1 ); +if (!access_ok (frame,sizeof (*frame))) goto badframe;/* Put the siginfo & fill in most of the ucontext */ -if (copy_siginfo_to_user (&rt_sf->info, &ksig->info) - ||__put_user (0 , &rt_sf->uc.uc_flags) - ||__save_altstack (&rt_sf->uc.uc_stack, regs->gpr[1 ]) - ||__put_user (to_user_ptr (&rt_sf->uc.uc_mcontext), - &rt_sf->uc.uc_regs) - ||put_sigset_t (&rt_sf->uc.uc_sigmask, oldset)) +if (copy_siginfo_to_user (&frame->info, &ksig->info) || +__put_user (0 , &frame->uc.uc_flags) || +__save_altstack (&frame->uc.uc_stack, regs->gpr[1 ]) || +__put_user (to_user_ptr (&frame->uc.uc_mcontext), &frame->uc.uc_regs) || +put_sigset_t (&frame->uc.uc_sigmask, oldset)) goto badframe;/* Save user registers on the stack */ - frame = &rt_sf->uc.uc_mcontext; + mctx = &frame->uc.uc_mcontext;if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) { sigret =0 ; tramp = tsk->mm->context.vdso_base + vdso32_rt_sigtramp; }else { sigret = __NR_rt_sigreturn; - tramp = (unsigned long ) frame->tramp; + tramp = (unsigned long )mctx->tramp; }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM - tm_frame = &rt_sf->uc_transact.uc_mcontext; + tm_mctx = &frame->uc_transact.uc_mcontext;if (MSR_TM_ACTIVE (msr)) { -if (__put_user ((unsigned long )&rt_sf->uc_transact, - &rt_sf->uc.uc_link) || -__put_user ((unsigned long )tm_frame, - &rt_sf->uc_transact.uc_regs)) +if (__put_user ((unsigned long )&frame->uc_transact, + &frame->uc.uc_link) || +__put_user ((unsigned long )tm_mctx, + &frame->uc_transact.uc_regs)) goto badframe; -if (save_tm_user_regs (regs, frame, tm_frame, sigret, msr)) +if (save_tm_user_regs (regs, mctx, tm_mctx, sigret, msr)) goto badframe; } else#endif { -if (__put_user (0 , &rt_sf->uc.uc_link)) +if (__put_user (0 , &frame->uc.uc_link)) goto badframe; -if (save_user_regs (regs, frame, tm_frame, sigret,1 )) +if (save_user_regs (regs, mctx, tm_mctx, sigret,1 )) goto badframe; } regs->link = tramp;
@@ -814,16 +813,16 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,#endif /* create a stack frame for the caller of the handler */ - newsp = ((unsigned long )rt_sf) - (__SIGNAL_FRAMESIZE +16 ); + newsp = ((unsigned long )frame) - (__SIGNAL_FRAMESIZE +16 );if (put_user (regs->gpr[1 ], (u32 __user *)newsp)) goto badframe;/* Fill registers for signal handler */ regs->gpr[1 ] = newsp; regs->gpr[3 ] = ksig->sig; - regs->gpr[4 ] = (unsigned long ) &rt_sf->info; - regs->gpr[5 ] = (unsigned long ) &rt_sf->uc; - regs->gpr[6 ] = (unsigned long ) rt_sf; + regs->gpr[4 ] = (unsigned long )&frame->info; + regs->gpr[5 ] = (unsigned long )&frame->uc; + regs->gpr[6 ] = (unsigned long )frame; regs->nip = (unsigned long ) ksig->ka.sa.sa_handler;/* enter the signal handler in native-endian mode */ regs->msr &= ~MSR_LE ;
@@ -831,7 +830,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,return 0 ; badframe: -signal_fault (tsk, regs,"handle_rt_signal32" , rt_sf); +signal_fault (tsk, regs,"handle_rt_signal32" , frame);return 1 ; }
Signature · 1 line
2.25.0
PATCH v2 15/25 powerpc/signal32: Misc changes to make handle_[rt_]_signal32() more similar
In reply to Christophe LeroyMiscellaneous changes to clean and make handle_signal32() and handle_rt_signal32() even more similar.
--- arch/powerpc/kernel/signal_32.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
arch/powerpc/kernel/signal_32.c +14 -10
@@ -764,8 +764,11 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,#endif /* Set up Signal Frame */ -/* Put a Real Time Context onto stack */ frame =get_sigframe (ksig, tsk,sizeof (*frame),1 ); + mctx = &frame->uc.uc_mcontext; +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + tm_mctx = &frame->uc_transact.uc_mcontext; +#endif if (!access_ok (frame,sizeof (*frame))) goto badframe;
@@ -778,7 +781,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, goto badframe;/* Save user registers on the stack */ - mctx = &frame->uc.uc_mcontext;if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) { sigret =0 ; tramp = tsk->mm->context.vdso_base + vdso32_rt_sigtramp;
@@ -788,7 +790,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM - tm_mctx = &frame->uc_transact.uc_mcontext;if (MSR_TM_ACTIVE (msr)) { if (__put_user((unsigned long)&frame->uc_transact, &frame->uc.uc_link) ||
@@ -843,6 +844,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, {struct sigcontext __user *sc;struct sigframe __user *frame; +struct mcontext __user *mctx;struct mcontext __user *tm_mctx =NULL ;unsigned long newsp =0 ;int sigret;
@@ -855,6 +857,10 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,/* Set up Signal Frame */ frame =get_sigframe (ksig, tsk,sizeof (*frame),1 ); + mctx = &frame->mctx; +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM + tm_mctx = &frame->mctx_transact; +#endif if (!access_ok (frame,sizeof (*frame))) goto badframe; sc = (struct sigcontext __user *) &frame->sctx;
@@ -869,7 +875,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,#else || __put_user(oldset->sig[1], &sc->_unused[3]) #endif - || __put_user(to_user_ptr(&frame->mctx), &sc->regs) + || __put_user(to_user_ptr(mctx), &sc->regs) || __put_user(ksig->sig, &sc->signal)) goto badframe;
@@ -878,20 +884,18 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, tramp = tsk->mm->context.vdso_base + vdso32_sigtramp; }else { sigret = __NR_sigreturn; - tramp = (unsigned long ) frame->mctx.tramp; + tramp = (unsigned long )mctx->tramp; }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM - tm_mctx = &frame->mctx_transact;if (MSR_TM_ACTIVE (msr)) { -if (save_tm_user_regs (regs, &frame->mctx, &frame->mctx_transact, - sigret, msr)) +if (save_tm_user_regs (regs, mctx, tm_mctx, sigret, msr)) goto badframe; } else#endif { -if (save_user_regs (regs, &frame->mctx, tm_mctx, sigret,1 )) +if (save_user_regs (regs, mctx, tm_mctx, sigret,1 )) goto badframe; }
@@ -909,7 +913,7 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, regs->gpr[1 ] = newsp; regs->gpr[3 ] = ksig->sig; regs->gpr[4 ] = (unsigned long ) sc; - regs->nip = (unsigned long ) (unsigned long )ksig->ka.sa.sa_handler; + regs->nip = (unsigned long )ksig->ka.sa.sa_handler;/* enter the signal handler in big-endian mode */ regs->msr &= ~MSR_LE ;return 0 ;
Signature · 1 line
2.25.0
PATCH v2 16/25 powerpc/signal32: Move signal trampoline setup to handle_[rt_]signal32
In reply to Christophe LeroyMove signal trampoline setup into handle_signal32() and handle_rt_signal32().
At the same time, remove the define which hides the mc_pad field used for trampoline.
--- arch/powerpc/kernel/signal_32.c | 61 ++++++++++++--------------------- 1 file changed, 22 insertions(+), 39 deletions(-)
arch/powerpc/kernel/signal_32.c +22 -39
@@ -199,9 +199,6 @@ struct sigframe {int abigap[56 ]; }; -/* We use the mc_pad field for the signal return trampoline. */ -#define tramp mc_pad -/* * When we have rt signals to deliver, we set up on the * user stack, going down from the original stack pointer:
@@ -236,8 +233,7 @@ struct rt_sigframe {* altivec/spe instructions at some point. */ static int save_user_regs (struct pt_regs *regs,struct mcontext __user *frame, -struct mcontext __user *tm_frame,int sigret, -int ctx_has_vsx_region) +struct mcontext __user *tm_frame,int ctx_has_vsx_region) {unsigned long msr = regs->msr;
@@ -320,15 +316,6 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,if (tm_frame &&__put_user (0 , &tm_frame->mc_gregs[PT_MSR ]))return 1 ; -if (sigret) { -/* Set up the sigreturn trampoline: li 0,sigret; sc */ -if (__put_user (PPC_INST_ADDI + sigret, &frame->tramp[0 ]) - ||__put_user (PPC_INST_SC , &frame->tramp[1 ])) -return 1 ; -flush_icache_range ((unsigned long ) &frame->tramp[0 ], - (unsigned long ) &frame->tramp[2 ]); - } -return 0 ; }
@@ -342,10 +329,8 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* * See save_user_regs() and signal_64.c:setup_tm_sigcontexts(). */ -static int save_tm_user_regs (struct pt_regs *regs, -struct mcontext __user *frame, -struct mcontext __user *tm_frame,int sigret, -unsigned long msr) +static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame, +struct mcontext __user *tm_frame,unsigned long msr) {WARN_ON (tm_suspend_disabled);
@@ -461,14 +446,6 @@ static int save_tm_user_regs(struct pt_regs *regs,if (__put_user (msr, &frame->mc_gregs[PT_MSR ]))return 1 ; -if (sigret) { -/* Set up the sigreturn trampoline: li 0,sigret; sc */ -if (__put_user (PPC_INST_ADDI + sigret, &frame->tramp[0 ]) - ||__put_user (PPC_INST_SC , &frame->tramp[1 ])) -return 1 ; -flush_icache_range ((unsigned long ) &frame->tramp[0 ], - (unsigned long ) &frame->tramp[2 ]); - }return 0 ; }
@@ -755,7 +732,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,struct mcontext __user *mctx;struct mcontext __user *tm_mctx =NULL ;unsigned long newsp =0 ; -int sigret;unsigned long tramp;struct pt_regs *regs = tsk->thread.regs;#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -782,11 +758,15 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,/* Save user registers on the stack */ if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) { - sigret =0 ; tramp = tsk->mm->context.vdso_base + vdso32_rt_sigtramp; }else { - sigret = __NR_rt_sigreturn; - tramp = (unsigned long )mctx->tramp; + tramp = (unsigned long )mctx->mc_pad; +/* Set up the sigreturn trampoline: li r0,sigret; sc */ +if (__put_user (PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0 ])) + goto badframe; +if (__put_user (PPC_INST_SC , &mctx->mc_pad[1 ])) + goto badframe; +flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -796,7 +776,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, __put_user((unsigned long)tm_mctx, &frame->uc_transact.uc_regs)) goto badframe; -if (save_tm_user_regs (regs, mctx, tm_mctx, sigret, msr)) +if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; }else
@@ -804,7 +784,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, {if (__put_user (0 , &frame->uc.uc_link)) goto badframe; -if (save_user_regs (regs, mctx, tm_mctx, sigret,1 )) +if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; } regs->link = tramp;
@@ -847,7 +827,6 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,struct mcontext __user *mctx;struct mcontext __user *tm_mctx =NULL ;unsigned long newsp =0 ; -int sigret;unsigned long tramp;struct pt_regs *regs = tsk->thread.regs;#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -880,22 +859,26 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, goto badframe;if (vdso32_sigtramp && tsk->mm->context.vdso_base) { - sigret =0 ; tramp = tsk->mm->context.vdso_base + vdso32_sigtramp; }else { - sigret = __NR_sigreturn; - tramp = (unsigned long )mctx->tramp; + tramp = (unsigned long )mctx->mc_pad; +/* Set up the sigreturn trampoline: li r0,sigret; sc */ +if (__put_user (PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0 ])) + goto badframe; +if (__put_user (PPC_INST_SC , &mctx->mc_pad[1 ])) + goto badframe; +flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (MSR_TM_ACTIVE (msr)) { -if (save_tm_user_regs (regs, mctx, tm_mctx, sigret, msr)) +if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; } else#endif { -if (save_user_regs (regs, mctx, tm_mctx, sigret,1 )) +if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; }
@@ -1047,7 +1030,7 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx, mctx = (struct mcontext __user *) ((unsigned long ) &old_ctx->uc_mcontext & ~0xfUL );if (!access_ok (old_ctx, ctx_size) - ||save_user_regs (regs, mctx,NULL ,0 , ctx_has_vsx_region) + ||save_user_regs (regs, mctx,NULL , ctx_has_vsx_region) ||put_sigset_t (&old_ctx->uc_sigmask, ¤t->blocked) ||__put_user (to_user_ptr (mctx), &old_ctx->uc_regs))return -EFAULT ;
Signature · 1 line
2.25.0
PATCH v2 17/25 powerpc/signal32: Switch handle_signal32() to user_access_begin() logic
In reply to Christophe LeroyReplace the access_ok() by user_access_begin() and change all user accesses to unsafe_ version.
Move flush_icache_range() outside the user access block.
--- arch/powerpc/kernel/signal_32.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
arch/powerpc/kernel/signal_32.c +16 -13
@@ -840,35 +840,35 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,#ifdef CONFIG_PPC_TRANSACTIONAL_MEM tm_mctx = &frame->mctx_transact;#endif -if (!access_ok (frame,sizeof (*frame))) +if (!user_write_access_begin (frame,sizeof (*frame))) goto badframe; sc = (struct sigcontext __user *) &frame->sctx;#if _NSIG !=64 #error "Please adjust handle_signal()"#endif -if (__put_user (to_user_ptr (ksig->ka.sa.sa_handler), &sc->handler) - ||__put_user (oldset->sig[0 ], &sc->oldmask) +unsafe_put_user (to_user_ptr (ksig->ka.sa.sa_handler), &sc->handler, failed); +unsafe_put_user (oldset->sig[0 ], &sc->oldmask, failed);#ifdef CONFIG_PPC64 - ||__put_user ((oldset->sig[0 ] >>32 ), &sc->_unused[3 ]) +unsafe_put_user ((oldset->sig[0 ] >>32 ), &sc->_unused[3 ], failed);#else - ||__put_user (oldset->sig[1 ], &sc->_unused[3 ]) +unsafe_put_user (oldset->sig[1 ], &sc->_unused[3 ], failed);#endif - ||__put_user (to_user_ptr (mctx), &sc->regs) - ||__put_user (ksig->sig, &sc->signal)) - goto badframe; +unsafe_put_user (to_user_ptr (mctx), &sc->regs, failed); +unsafe_put_user (ksig->sig, &sc->signal, failed);if (vdso32_sigtramp && tsk->mm->context.vdso_base) { tramp = tsk->mm->context.vdso_base + vdso32_sigtramp; }else { tramp = (unsigned long )mctx->mc_pad;/* Set up the sigreturn trampoline: li r0,sigret; sc */ -if (__put_user (PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0 ])) - goto badframe; -if (__put_user (PPC_INST_SC , &mctx->mc_pad[1 ])) - goto badframe; -flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); +unsafe_put_user (PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0 ], failed); +unsafe_put_user (PPC_INST_SC , &mctx->mc_pad[1 ], failed); } +user_write_access_end (); + +if (tramp == (unsigned long )mctx->mc_pad) +flush_icache_range (tramp, tramp +2 *sizeof (unsigned long ));#ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (MSR_TM_ACTIVE (msr)) {
@@ -901,6 +901,9 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, regs->msr &= ~MSR_LE ;return 0 ; +failed: +user_write_access_end (); + badframe:signal_fault (tsk, regs,"handle_signal32" , frame);
Signature · 1 line
2.25.0
PATCH v2 18/25 powerpc/signal32: Switch handle_rt_signal32() to user_access_begin() logic
In reply to Christophe LeroyOn the same way as handle_signal32(), replace all user accesses with equivalent unsafe_ versions, and move the trampoline code icache flush outside the user access block.
Functions that have no unsafe_ equivalent also remains outside the access block.
--- arch/powerpc/kernel/signal_32.c | 55 ++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 21 deletions(-)
arch/powerpc/kernel/signal_32.c +34 -21
@@ -58,8 +58,6 @@#define mcontext mcontext32#define ucontext ucontext32 -#define __save_altstack __compat_save_altstack -/* * Userspace code may pass a ucontext which doesn't include VSX added * at the end. We need to check for this case.
@@ -745,16 +743,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,#ifdef CONFIG_PPC_TRANSACTIONAL_MEM tm_mctx = &frame->uc_transact.uc_mcontext;#endif -if (!access_ok (frame,sizeof (*frame))) +if (!user_write_access_begin (frame,sizeof (*frame))) goto badframe;/* Put the siginfo & fill in most of the ucontext */ -if (copy_siginfo_to_user (&frame->info, &ksig->info) || -__put_user (0 , &frame->uc.uc_flags) || -__save_altstack (&frame->uc.uc_stack, regs->gpr[1 ]) || -__put_user (to_user_ptr (&frame->uc.uc_mcontext), &frame->uc.uc_regs) || -put_sigset_t (&frame->uc.uc_sigmask, oldset)) - goto badframe; +unsafe_put_user (0 , &frame->uc.uc_flags, failed); +#ifdef CONFIG_PPC64 +unsafe_compat_save_altstack (&frame->uc.uc_stack, regs->gpr[1 ], failed); +#else +unsafe_save_altstack (&frame->uc.uc_stack, regs->gpr[1 ], failed); +#endif +unsafe_put_user (to_user_ptr (&frame->uc.uc_mcontext), &frame->uc.uc_regs, failed); + +if (MSR_TM_ACTIVE (msr)) { +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +unsafe_put_user ((unsigned long )&frame->uc_transact, + &frame->uc.uc_link, failed); +unsafe_put_user ((unsigned long )tm_mctx, + &frame->uc_transact.uc_regs, failed); +#endif + }else { +unsafe_put_user (0 , &frame->uc.uc_link, failed); + }/* Save user registers on the stack */ if (vdso32_rt_sigtramp && tsk->mm->context.vdso_base) {
@@ -762,28 +772,28 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, }else { tramp = (unsigned long )mctx->mc_pad;/* Set up the sigreturn trampoline: li r0,sigret; sc */ -if (__put_user (PPC_INST_ADDI + __NR_sigreturn, &mctx->mc_pad[0 ])) - goto badframe; -if (__put_user (PPC_INST_SC , &mctx->mc_pad[1 ])) - goto badframe; -flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); +unsafe_put_user (PPC_INST_ADDI + __NR_rt_sigreturn, &mctx->mc_pad[0 ], + failed); +unsafe_put_user (PPC_INST_SC , &mctx->mc_pad[1 ], failed); } +user_write_access_end (); + +if (put_sigset_t (&frame->uc.uc_sigmask, oldset)) + goto badframe; +if (copy_siginfo_to_user (&frame->info, &ksig->info)) + goto badframe; + +if (tramp == (unsigned long )mctx->mc_pad) +flush_icache_range (tramp, tramp +2 *sizeof (unsigned long ));#ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (MSR_TM_ACTIVE (msr)) { -if (__put_user ((unsigned long )&frame->uc_transact, - &frame->uc.uc_link) || -__put_user ((unsigned long )tm_mctx, - &frame->uc_transact.uc_regs)) - goto badframe;if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; } else#endif { -if (__put_user (0 , &frame->uc.uc_link)) - goto badframe;if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; }
@@ -810,6 +820,9 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, regs->msr |= (MSR_KERNEL &MSR_LE );return 0 ; +failed: +user_write_access_end (); + badframe:signal_fault (tsk, regs,"handle_rt_signal32" , frame);
Signature · 1 line
2.25.0
PATCH v2 19/25 powerpc/signal32: Remove ifdefery in middle of if/else
In reply to Christophe LeroyMSR_TM_ACTIVE() is always defined and returns always 0 when CONFIG_PPC_TRANSACTIONAL_MEM is not selected, so the awful ifdefery in the middle of an if/else can be removed.
--- arch/powerpc/kernel/signal_32.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
arch/powerpc/kernel/signal_32.c +8 -14
@@ -447,6 +447,12 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame return 0; } +#else +static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame, +struct mcontext __user *tm_frame,unsigned long msr) +{ +return 0 ; +}#endif /*
@@ -732,10 +738,8 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,unsigned long newsp =0 ;unsigned long tramp;struct pt_regs *regs = tsk->thread.regs; -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM /* Save the thread's msr before get_tm_stackpointer() changes it */ unsigned long msr = regs->msr; -#endif /* Set up Signal Frame */ frame =get_sigframe (ksig, tsk,sizeof (*frame),1 );
@@ -786,14 +790,10 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,if (tramp == (unsigned long )mctx->mc_pad)flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (MSR_TM_ACTIVE (msr)) {if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; - } - else -#endif - { + }else {if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; }
@@ -842,10 +842,8 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,unsigned long newsp =0 ;unsigned long tramp;struct pt_regs *regs = tsk->thread.regs; -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM /* Save the thread's msr before get_tm_stackpointer() changes it */ unsigned long msr = regs->msr; -#endif /* Set up Signal Frame */ frame =get_sigframe (ksig, tsk,sizeof (*frame),1 );
@@ -883,14 +881,10 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,if (tramp == (unsigned long )mctx->mc_pad)flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); -#ifdef CONFIG_PPC_TRANSACTIONAL_MEM if (MSR_TM_ACTIVE (msr)) {if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; - } - else -#endif - { + }else {if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; }
Signature · 1 line
2.25.0
PATCH v2 20/25 signal: Add unsafe_put_compat_sigset()
In reply to Christophe LeroyImplement 'unsafe' version of put_compat_sigset()
For the bigendian, use unsafe_put_user() directly
to avoid intermediate copy through the stack.
For the littleendian, use a straight unsafe_copy_to_user().
--- include/linux/compat.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
include/linux/compat.h +32 -0
@@ -442,6 +442,38 @@ put_compat_sigset(compat_sigset_t __user *compat, const sigset_t *set,#endif } +#ifdef CONFIG_CPU_BIG_ENDIAN +#define unsafe_put_compat_sigset (compat, set, label) do { \ + compat_sigset_t __user *__c = compat; \ + const sigset_t *__s = set; \ + \ + switch (_NSIG_WORDS) { \ + case 4: \ + unsafe_put_user(__s->sig[3] >> 32, &__c->sig[7], label); \ + unsafe_put_user(__s->sig[3], &__c->sig[6], label); \ + fallthrough; \ + case 3: \ + unsafe_put_user(__s->sig[2] >> 32, &__c->sig[5], label); \ + unsafe_put_user(__s->sig[2], &__c->sig[4], label); \ + fallthrough; \ + case 2: \ + unsafe_put_user(__s->sig[1] >> 32, &__c->sig[3], label); \ + unsafe_put_user(__s->sig[1], &__c->sig[2], label); \ + fallthrough; \ + case 1: \ + unsafe_put_user(__s->sig[0] >> 32, &__c->sig[1], label); \ + unsafe_put_user(__s->sig[0], &__c->sig[0], label); \ + } \ +} while (0) +#else +#define unsafe_put_compat_sigset (compat, set, label) do { \ + compat_sigset_t __user *__c = compat; \ + const sigset_t *__s = set; \ + \ + unsafe_copy_to_user(__c, __s, sizeof(*__c), label); \ +} while (0) +#endif +extern int compat_ptrace_request (struct task_struct *child,compat_long_t request,compat_ulong_t addr,compat_ulong_t data);
Signature · 1 line
2.25.0
PATCH v2 21/25 powerpc/signal32: Add and use unsafe_put_sigset_t()
In reply to Christophe Leroyput_sigset_t() calls copy_to_user() for copying two words.
This is terribly inefficient for copying two words.
By switching to unsafe_put_user(), we end up with something as simple as:
3cc: 81 3d 00 00 lwz r9,0(r29) 3d0: 91 26 00 b4 stw r9,180(r6) 3d4: 81 3d 00 04 lwz r9,4(r29) 3d8: 91 26 00 b8 stw r9,184(r6)
--- arch/powerpc/kernel/signal_32.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
arch/powerpc/kernel/signal_32.c +11 -2
@@ -87,6 +87,8 @@ static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set)return put_compat_sigset (uset, set,sizeof (*uset)); } +#define unsafe_put_sigset_t unsafe_put_compat_sigset +static inline int get_sigset_t (sigset_t *set,const compat_sigset_t __user *uset) {
@@ -141,6 +143,13 @@ static inline int put_sigset_t(sigset_t __user *uset, sigset_t *set)return copy_to_user (uset, set,sizeof (*uset)); } +#define unsafe_put_sigset_t (uset, set, label) do { \ + sigset_t __user *__us = uset ; \ + const sigset_t *__s = set; \ + \ + unsafe_copy_to_user(__us, __s, sizeof(*__us), label); \ +} while (0) +static inline int get_sigset_t (sigset_t *set,const sigset_t __user *uset) {return copy_from_user (set, uset,sizeof (*uset));
@@ -780,10 +789,10 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, failed);unsafe_put_user (PPC_INST_SC , &mctx->mc_pad[1 ], failed); } +unsafe_put_sigset_t (&frame->uc.uc_sigmask, oldset, failed); +user_write_access_end (); -if (put_sigset_t (&frame->uc.uc_sigmask, oldset)) - goto badframe;if (copy_siginfo_to_user (&frame->info, &ksig->info)) goto badframe;
Signature · 1 line
2.25.0
PATCH v2 22/25 powerpc/signal32: Switch swap_context() to user_access_begin() logic
In reply to Christophe LeroyAs this was the last user of put_sigset_t(), remove it as well.
--- arch/powerpc/kernel/signal_32.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
arch/powerpc/kernel/signal_32.c +10 -14
@@ -82,11 +82,6 @@* Functions for flipping sigsets (thanks to brain dead generic * implementation that makes things simple for little endian only) */ -static inline int put_sigset_t (compat_sigset_t __user *uset,sigset_t *set) -{ -return put_compat_sigset (uset, set,sizeof (*uset)); -} -#define unsafe_put_sigset_t unsafe_put_compat_sigset static inline int get_sigset_t(sigset_t *set,
@@ -138,11 +133,6 @@ static inline int restore_general_regs(struct pt_regs *regs,#define GP_REGS_SIZE min(sizeof(elf_gregset_t), sizeof(struct pt_regs)) -static inline int put_sigset_t (sigset_t __user *uset,sigset_t *set) -{ -return copy_to_user (uset, set,sizeof (*uset)); -} -#define unsafe_put_sigset_t (uset, set, label) do { \ sigset_t __user *__us = uset ; \ const sigset_t *__s = set; \
@@ -1048,11 +1038,13 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx,*/ mctx = (struct mcontext __user *) ((unsigned long ) &old_ctx->uc_mcontext & ~0xfUL ); -if (!access_ok (old_ctx, ctx_size) - ||save_user_regs (regs, mctx,NULL , ctx_has_vsx_region) - ||put_sigset_t (&old_ctx->uc_sigmask, ¤t->blocked) - ||__put_user (to_user_ptr (mctx), &old_ctx->uc_regs)) +if (save_user_regs (regs, mctx,NULL , ctx_has_vsx_region)) +return -EFAULT ; +if (!user_write_access_begin (old_ctx, ctx_size))return -EFAULT ; +unsafe_put_sigset_t (&old_ctx->uc_sigmask, ¤t->blocked, failed); +unsafe_put_user (to_user_ptr (mctx), &old_ctx->uc_regs, failed); +user_write_access_end (); }if (new_ctx ==NULL )return 0 ;
@@ -1076,6 +1068,10 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx,set_thread_flag (TIF_RESTOREALL );return 0 ; + +failed: +user_write_access_end (); +return -EFAULT ; }#ifdef CONFIG_PPC64
Signature · 1 line
2.25.0
PATCH v2 23/25 powerpc/signal: Create 'unsafe' versions of copy_[ck][fpr/vsx]_to_user()
In reply to Christophe LeroyFor the non VSX version, that's trivial. Just use unsafe_copy_to_user() instead of __copy_to_user().
For the VSX version, remove the intermediate step through a buffer and use unsafe_put_user() directly. This generates a far smaller code which is acceptable to inline, see below:
Standard VSX version:
0000000000000000 <.copy_fpr_to_user>:
0: 7c 08 02 a6 mflr r0 4: fb e1 ff f8 std r31,-8(r1) 8: 39 00 00 20 li r8,32 c: 39 24 0b 80 addi r9,r4,2944 10: 7d 09 03 a6 mtctr r8 14: f8 01 00 10 std r0,16(r1) 18: f8 21 fe 71 stdu r1,-400(r1) 1c: 39 41 00 68 addi r10,r1,104 20: e9 09 00 00 ld r8,0(r9) 24: 39 4a 00 08 addi r10,r10,8 28: 39 29 00 10 addi r9,r9,16 2c: f9 0a 00 00 std r8,0(r10) 30: 42 00 ff f0 bdnz 20 <.copy_fpr_to_user+0x20> 34: e9 24 0d 80 ld r9,3456(r4) 38: 3d 42 00 00 addis r10,r2,0 3a: R_PPC64_TOC16_HA .toc 3c: eb ea 00 00 ld r31,0(r10) 3e: R_PPC64_TOC16_LO_DS .toc 40: f9 21 01 70 std r9,368(r1) 44: e9 3f 00 00 ld r9,0(r31) 48: 81 29 00 20 lwz r9,32(r9) 4c: 2f 89 00 00 cmpwi cr7,r9,0 50: 40 9c 00 18 bge cr7,68 <.copy_fpr_to_user+0x68> 54: 4c 00 01 2c isync 58: 3d 20 40 00 lis r9,16384 5c: 79 29 07 c6 rldicr r9,r9,32,31 60: 7d 3d 03 a6 mtspr 29,r9 64: 4c 00 01 2c isync 68: 38 a0 01 08 li r5,264 6c: 38 81 00 70 addi r4,r1,112 70: 48 00 00 01 bl 70 <.copy_fpr_to_user+0x70> 70: R_PPC64_REL24 .__copy_tofrom_user 74: 60 00 00 00 nop 78: e9 3f 00 00 ld r9,0(r31) 7c: 81 29 00 20 lwz r9,32(r9) 80: 2f 89 00 00 cmpwi cr7,r9,0 84: 40 9c 00 18 bge cr7,9c <.copy_fpr_to_user+0x9c> 88: 4c 00 01 2c isync 8c: 39 20 ff ff li r9,-1 90: 79 29 00 44 rldicr r9,r9,0,1 94: 7d 3d 03 a6 mtspr 29,r9 98: 4c 00 01 2c isync 9c: 38 21 01 90 addi r1,r1,400 a0: e8 01 00 10 ld r0,16(r1) a4: eb e1 ff f8 ld r31,-8(r1) a8: 7c 08 03 a6 mtlr r0
ac: 4e 80 00 20 blr
'unsafe' simulated VSX version (The ... are only nops) using unsafe_copy_fpr_to_user() macro:
unsigned long copy_fpr_to_user(void __user *to,
struct task_struct *task)
{
unsafe_copy_fpr_to_user(to, task, failed);
return 0;
failed:
return 1;
}0000000000000000 <.copy_fpr_to_user>:
0: 39 00 00 20 li r8,32 4: 39 44 0b 80 addi r10,r4,2944 8: 7d 09 03 a6 mtctr r8 c: 7c 69 1b 78 mr r9,r3 ... 20: e9 0a 00 00 ld r8,0(r10) 24: f9 09 00 00 std r8,0(r9) 28: 39 4a 00 10 addi r10,r10,16 2c: 39 29 00 08 addi r9,r9,8 30: 42 00 ff f0 bdnz 20 <.copy_fpr_to_user+0x20> 34: e9 24 0d 80 ld r9,3456(r4) 38: f9 23 01 00 std r9,256(r3) 3c: 38 60 00 00 li r3,0
40: 4e 80 00 20 blr
...
50: 38 60 00 01 li r3,1
54: 4e 80 00 20 blr
--- arch/powerpc/kernel/signal.h | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
arch/powerpc/kernel/signal.h +53 -0
@@ -32,7 +32,54 @@ unsigned long copy_fpr_to_user(void __user *to, struct task_struct *task);unsigned long copy_ckfpr_to_user (void __user *to,struct task_struct *task);unsigned long copy_fpr_from_user (struct task_struct *task,void __user *from);unsigned long copy_ckfpr_from_user (struct task_struct *task,void __user *from); + +#define unsafe_copy_fpr_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NFPREG - 1 ; i++) \ + unsafe_put_user(__t->thread.TS_FPR(i), &buf[i], label); \ + unsafe_put_user(__t->thread.fp_state.fpscr, &buf[i], label); \ +} while (0) + +#define unsafe_copy_vsx_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NVSRHALFREG ; i++) \ + unsafe_put_user(__t->thread.fp_state.fpr[i][TS_VSRLOWOFFSET], \ + &buf[i], label);\ +} while (0) + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +#define unsafe_copy_ckfpr_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NFPREG - 1 ; i++) \ + unsafe_put_user(__t->thread.TS_CKFPR(i), &buf[i], label);\ + unsafe_put_user(__t->thread.ckfp_state.fpscr, &buf[i], label); \ +} while (0) + +#define unsafe_copy_ckvsx_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NVSRHALFREG ; i++) \ + unsafe_put_user(__t->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET], \ + &buf[i], label);\ +} while (0) +#endif #elif defined(CONFIG_PPC_FPU_REGS ) + +#define unsafe_copy_fpr_to_user (to, task, label) \ + unsafe_copy_to_user(to, (task)->thread.fp_state.fpr, \ + ELF_NFPREG * sizeof(double), label) +static inline unsigned long copy_fpr_to_user (void __user *to,struct task_struct *task) {
@@ -48,6 +95,10 @@ copy_fpr_from_user(struct task_struct *task, void __user *from) }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +#define unsafe_copy_ckfpr_to_user (to, task, label) \ + unsafe_copy_to_user(to, (task)->thread.ckfp_state.fpr, \ + ELF_NFPREG * sizeof(double), label) +inline unsigned long copy_ckfpr_to_user (void __user *to,struct task_struct *task) { return __copy_to_user(to, task->thread.ckfp_state.fpr,
@@ -62,6 +113,8 @@ copy_ckfpr_from_user(struct task_struct *task, void __user *from) }#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ #else +#define unsafe_copy_fpr_to_user (to, task, label) do { } while (0) +static inline unsigned long copy_fpr_to_user (void __user *to,struct task_struct *task) {
Signature · 1 line
2.25.0
Re: [PATCH v2 23/25] powerpc/signal: Create 'unsafe' versions of copy_[ck][fpr/vsx]_to_user()
Quoted 107 lines · Christophe Leroy
For the non VSX version, that's trivial. Just use
unsafe_copy_to_user()instead of__copy_to_user().For the VSX version, remove the intermediate step through a buffer and use
unsafe_put_user()directly. This generates a far smaller code which is acceptable to inline, see below:Standard VSX version:
0000000000000000 <.copy_fpr_to_user>:
0: 7c 08 02 a6 mflr r0
4: fb e1 ff f8 std r31,-8(r1)
8: 39 00 00 20 li r8,32
c: 39 24 0b 80 addi r9,r4,2944
10: 7d 09 03 a6 mtctr r8
14: f8 01 00 10 std r0,16(r1)
18: f8 21 fe 71 stdu r1,-400(r1)
1c: 39 41 00 68 addi r10,r1,104
20: e9 09 00 00 ld r8,0(r9)
24: 39 4a 00 08 addi r10,r10,8
28: 39 29 00 10 addi r9,r9,16
2c: f9 0a 00 00 std r8,0(r10)
30: 42 00 ff f0 bdnz 20 <.copy_fpr_to_user+0x20> 34: e9 24 0d 80 ld r9,3456(r4)
38: 3d 42 00 00 addis r10,r2,0
3a:R_PPC64_TOC16_HA.toc
3c: eb ea 00 00 ld r31,0(r10)
3e:R_PPC64_TOC16_LO_DS.toc
40: f9 21 01 70 std r9,368(r1)
44: e9 3f 00 00 ld r9,0(r31)
48: 81 29 00 20 lwz r9,32(r9)
4c: 2f 89 00 00 cmpwi cr7,r9,0
50: 40 9c 00 18 bge cr7,68 <.copy_fpr_to_user+0x68> 54: 4c 00 01 2c isync
58: 3d 20 40 00 lis r9,16384
5c: 79 29 07 c6 rldicr r9,r9,32,31
60: 7d 3d 03 a6 mtspr 29,r9
64: 4c 00 01 2c isync
68: 38 a0 01 08 li r5,264
6c: 38 81 00 70 addi r4,r1,112
70: 48 00 00 01 bl 70 <.copy_fpr_to_user+0x70> 70:R_PPC64_REL24.__copy_tofrom_user
74: 60 00 00 00 nop
78: e9 3f 00 00 ld r9,0(r31)
7c: 81 29 00 20 lwz r9,32(r9)
80: 2f 89 00 00 cmpwi cr7,r9,0
84: 40 9c 00 18 bge cr7,9c <.copy_fpr_to_user+0x9c> 88: 4c 00 01 2c isync
8c: 39 20 ff ff li r9,-1
90: 79 29 00 44 rldicr r9,r9,0,1
94: 7d 3d 03 a6 mtspr 29,r9
98: 4c 00 01 2c isync
9c: 38 21 01 90 addi r1,r1,400
a0: e8 01 00 10 ld r0,16(r1)
a4: eb e1 ff f8 ld r31,-8(r1)
a8: 7c 08 03 a6 mtlr r0
ac: 4e 80 00 20 blr'unsafe' simulated VSX version (The ... are only nops) using
unsafe_copy_fpr_to_user()macro:unsigned long copy_fpr_to_user(void
__user*to,
structtask_struct*task)
{unsafe_copy_fpr_to_user(to, task, failed);
return 0;
failed:
return 1;
}0000000000000000 <.copy_fpr_to_user>:
0: 39 00 00 20 li r8,32
4: 39 44 0b 80 addi r10,r4,2944
8: 7d 09 03 a6 mtctr r8
c: 7c 69 1b 78 mr r9,r3
...
20: e9 0a 00 00 ld r8,0(r10)
24: f9 09 00 00 std r8,0(r9)
28: 39 4a 00 10 addi r10,r10,16
2c: 39 29 00 08 addi r9,r9,8
30: 42 00 ff f0 bdnz 20 <.copy_fpr_to_user+0x20>
34: e9 24 0d 80 ld r9,3456(r4)
38: f9 23 01 00 std r9,256(r3)
3c: 38 60 00 00 li r3,0
40: 4e 80 00 20 blr
...
50: 38 60 00 01 li r3,1
54: 4e 80 00 20 blrSigned-off-by Christophe Leroy <[email protected]>---
arch/powerpc/kernel/signal.h| 53 ++++++++++++++++++++++++++++++++++++1 file changed, 53 insertions(+)arch/powerpc/kernel/signal.h +0
-0@@ -32,7 +32,54 @@ unsigned long copy_fpr_to_user(void __user *to, struct task_struct *task);unsigned long
copy_ckfpr_to_user(void __user *to, struct task_struct *task);
unsigned longcopy_fpr_from_user(struct task_struct *task, void __user *from);
unsigned longcopy_ckfpr_from_user(struct task_struct *task, void __user *from);arch/powerpc/kernel/signal.h +1
-0+
arch/powerpc/kernel/signal.h unsigned long copy_fpr_to_user(void __user *to, struct task_struct *task); · line 45
Quoted 10 lines
arch/powerpc/kernel/signal.h +10
-0+#define unsafe_copy_fpr_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NFPREG - 1 ; i++) \ + unsafe_put_user(__t->thread.TS_FPR(i), &buf[i], label); \ + unsafe_put_user(__t->thread.fp_state.fpscr, &buf[i], label); \ +} while (0) +
I've been working on the PPC64 side of this "unsafe" rework using this series as a basis. One question here - I don't really understand what the benefit of re-implementing this logic in macros (similarly for the other copy_* functions below) is?
I am considering a "__unsafe_copy_*" implementation in signal.c for each (just the original implementation w/ using the "unsafe_" variants of the uaccess stuff) which gets called by the "safe" functions w/ the appropriate "user_*_access_begin/user_*_access_end". Something like (pseudo-ish code):
/* signal.c */
unsigned long __unsafe_copy_fpr_to_user(...)
{
...
unsafe_copy_to_user(..., bad);
return 0;
bad:
return 1; /* -EFAULT? */
}
unsigned long copy_fpr_to_user(...)
{
unsigned long err;
if (!user_write_access_begin(...))
return 1; /* -EFAULT? */
err = __unsafe_copy_fpr_to_user(...);
user_write_access_end();
return err;
}
/* signal.h */
unsigned long __unsafe_copy_fpr_to_user(...);
#define unsafe_copy_fpr_to_user(..., label) \
unsafe_op_wrap(__unsafe_copy_fpr_to_user(...), label)This way there is a single implementation for each copy routine "body". The "unsafe" wrappers then just exist as simple macros similar to what x86 does: "unsafe_" macro wraps "__unsafe" functions for the goto label.
Granted this does pollute "signal.h" w/ the "__unsafe_copy_*" prototypes...
Quoted 65 lines
arch/powerpc/kernel/signal.h +31
-0+#define unsafe_copy_vsx_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NVSRHALFREG ; i++) \ + unsafe_put_user(__t->thread.fp_state.fpr[i][TS_VSRLOWOFFSET], \ + &buf[i], label);\ +} while (0) + +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +#define unsafe_copy_ckfpr_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NFPREG - 1 ; i++) \ + unsafe_put_user(__t->thread.TS_CKFPR(i), &buf[i], label);\ + unsafe_put_user(__t->thread.ckfp_state.fpscr, &buf[i], label); \ +} while (0) + +#define unsafe_copy_ckvsx_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NVSRHALFREG ; i++) \ + unsafe_put_user(__t->thread.ckfp_state.fpr[i][TS_VSRLOWOFFSET], \ + &buf[i], label);\ +} while (0) +#endif #elif
defined(CONFIG_PPC_FPU_REGS)arch/powerpc/kernel/signal.h +5
-0+ +#define unsafe_copy_fpr_to_user (to, task, label) \ + unsafe_copy_to_user(to, (task)->thread.fp_state.fpr, \ + ELF_NFPREG * sizeof(double), label) +static inline unsigned long
copy_fpr_to_user(void __user *to, struct task_struct *task){arch/powerpc/kernel/signal.h +4
-0@@ -48,6 +95,10 @@ copy_fpr_from_user(struct task_struct *task, void __user *from) }#ifdef CONFIG_PPC_TRANSACTIONAL_MEM +#define unsafe_copy_ckfpr_to_user (to, task, label) \ + unsafe_copy_to_user(to, (task)->thread.ckfp_state.fpr, \ + ELF_NFPREG * sizeof(double), label) +inline unsigned long
copy_ckfpr_to_user(void __user *to, struct task_struct *task)
{
return __copy_to_user(to,task->thread.ckfp_state.fpr,arch/powerpc/kernel/signal.h +2
-0@@ -62,6 +113,8 @@ copy_ckfpr_from_user(struct task_struct *task, void __user *from) }#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ #else +#define unsafe_copy_fpr_to_user (to, task, label) do { } while (0) +static inline unsigned long
copy_fpr_to_user(void __user *to, struct task_struct *task){
--
2.25.0
Re: [PATCH v2 23/25] powerpc/signal: Create 'unsafe' versions of copy_[ck][fpr/vsx]_to_user()
Le 29/09/2020 à 04:04, Christopher M. Riedl a écrit :
Quoted 34 lines · Christophe Leroy
Quoted 33 lines
For the non VSX version, that's trivial. Just use
unsafe_copy_to_user()instead of__copy_to_user().For the VSX version, remove the intermediate step through a buffer and use
unsafe_put_user()directly. This generates a far smaller code which is acceptable to inline, see below:Signed-off-by Christophe Leroy <[email protected]>---
arch/powerpc/kernel/signal.h| 53 ++++++++++++++++++++++++++++++++++++1 file changed, 53 insertions(+)arch/powerpc/kernel/signal.h +0
-0@@ -32,7 +32,54 @@ unsigned long copy_fpr_to_user(void __user *to, struct task_struct *task);unsigned long
copy_ckfpr_to_user(void __user *to, struct task_struct *task);
unsigned longcopy_fpr_from_user(struct task_struct *task, void __user *from);
unsigned longcopy_ckfpr_from_user(struct task_struct *task, void __user *from);arch/powerpc/kernel/signal.h +8
-0+ +#define unsafe_copy_fpr_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NFPREG - 1 ; i++) \ + unsafe_put_user(__t->thread.TS_FPR(i), &buf[i], label); \
Quoted 8 lines
arch/powerpc/kernel/signal.h
Quoted 3 lines
+
unsafe_put_user(__t->thread.fp_state.fpscr, &buf[i], label); \arch/powerpc/kernel/signal.h +2
-0+}while (0 ) +I've been working on the PPC64 side of this "unsafe" rework using this series as a basis. One question here - I don't really understand what the benefit of re-implementing this logic in macros (similarly for the other copy_* functions below) is?
Not sure either.
The whole purpose is to not manage the error through a local var but exclusively use labels. However, GCC is probably smart enough to understand it and drop the local var while inlining.
One important thing however is to make sure we won't end up with an outline function, otherwise you completely loose the benefit of the label stuff. And you get a function call inside a user access, which is what we want to avoid.
Quoted 6 lines
I am considering a "__unsafe_copy_*" implementation in
signal.cfor each (just the original implementation w/ using the "unsafe_" variants of the uaccess stuff) which gets called by the "safe" functions w/ the appropriate "user_*_access_begin/user_*_access_end". Something like (pseudo-ish code):
Good idea, however ...
Quoted 10 lines
/* signal.c */
unsigned long __unsafe_copy_fpr_to_user(...)
{
...
unsafe_copy_to_user(..., bad);
return 0;
bad:
return 1; /* -EFAULT? */
}This __unsafe_copy_fpr_to_user() has to be in signal.h and must be tagged 'static __always_inline' for the reasons explained above.
Quoted 18 lines
unsigned long copy_fpr_to_user(...)
{
unsigned long err;
if (!user_write_access_begin(...))
return 1; /* -EFAULT? */
err = __unsafe_copy_fpr_to_user(...);
user_write_access_end();
return err;
}
/* signal.h */
unsigned long __unsafe_copy_fpr_to_user(...);
#define unsafe_copy_fpr_to_user(..., label) \
unsafe_op_wrap(__unsafe_copy_fpr_to_user(...), label)Quoted 3 lines
This way there is a single implementation for each copy routine "body". The "unsafe" wrappers then just exist as simple macros similar to what x86 does: "
unsafe_" macro wraps "__unsafe" functions for the goto label.
Yes, good point.
Christophe
Re: [PATCH v2 23/25] powerpc/signal: Create 'unsafe' versions of copy_[ck][fpr/vsx]_to_user()
Le 29/09/2020 à 07:22, Christophe Leroy a écrit :
Quoted 73 lines
Le 29/09/2020 à 04:04, Christopher M. Riedl a écrit :
Quoted 34 lines · Christophe Leroy
Quoted 33 lines
For the non VSX version, that's trivial. Just use
unsafe_copy_to_user()instead of__copy_to_user().For the VSX version, remove the intermediate step through a buffer and use
unsafe_put_user()directly. This generates a far smaller code which is acceptable to inline, see below:Signed-off-by Christophe Leroy <[email protected]>---
arch/powerpc/kernel/signal.h| 53 ++++++++++++++++++++++++++++++++++++1 file changed, 53 insertions(+)arch/powerpc/kernel/signal.h +0
-0@@ -32,7 +32,54 @@ unsigned long copy_fpr_to_user(void __user *to, struct task_struct *task);unsigned long
copy_ckfpr_to_user(void __user *to, struct task_struct *task);
unsigned longcopy_fpr_from_user(struct task_struct *task, void __user *from);
unsigned longcopy_ckfpr_from_user(struct task_struct *task, void __user *from);arch/powerpc/kernel/signal.h +8
-0+ +#define unsafe_copy_fpr_to_user (to, task, label) do { \ + struct task_struct *__t = task; \ + u64 __user *buf = (u64 __user *)to; \ + int i; \ + \ + for (i = 0; i < ELF_NFPREG - 1 ; i++) \ + unsafe_put_user(__t->thread.TS_FPR(i), &buf[i], label); \Quoted 8 lines
arch/powerpc/kernel/signal.h
Quoted 3 lines
+
unsafe_put_user(__t->thread.fp_state.fpscr, &buf[i], label); \arch/powerpc/kernel/signal.h +2
-0+}while (0 ) +I've been working on the PPC64 side of this "unsafe" rework using this series as a basis. One question here - I don't really understand what the benefit of re-implementing this logic in macros (similarly for the other copy_* functions below) is?
Not sure either.
The whole purpose is to not manage the error through a local var but exclusively use labels. However, GCC is probably smart enough to understand it and drop the local var while inlining.
One important thing however is to make sure we won't end up with an outline function, otherwise you completely loose the benefit of the label stuff. And you get a function call inside a user access, which is what we want to avoid.
Quoted 6 lines
I am considering a "__unsafe_copy_*" implementation in
signal.cfor each (just the original implementation w/ using the "unsafe_" variants of the uaccess stuff) which gets called by the "safe" functions w/ the appropriate "user_*_access_begin/user_*_access_end". Something like (pseudo-ish code):Good idea, however ...
Quoted 10 lines
/*
signal.c*/
unsigned long__unsafe_copy_fpr_to_user(...)
{
...
unsafe_copy_to_user(..., bad);
return 0;
bad:
return 1; /*-EFAULT? */
}
Quoted 14 lines
This
__unsafe_copy_fpr_to_user()has to be insignal.hand must be tagged 'static__always_inline' for the reasons explained above.Quoted 12 lines
unsigned long
copy_fpr_to_user(...)
{
unsigned long err;
if (!user_write_access_begin(...))
return 1; /*-EFAULT? */err =
__unsafe_copy_fpr_to_user(...);
user_write_access_end();
return err;
}
Also note that at the end (ie when both PPC32 and PPC64 signal code are using "unsafe" versions), the "safe" version won't be used anymore and will be dropped.
Christophe
PATCH v2 24/25 powerpc/signal32: Isolate non-copy actions in save_user_regs() and save_tm_user_regs()
In reply to Christophe LeroyReorder actions in save_user_regs() and save_tm_user_regs() to regroup copies together in order to switch to user_access_begin() logic in a later patch.
Move non-copy actions into new functions called prepare_save_user_regs() and prepare_save_tm_user_regs().
--- arch/powerpc/kernel/signal_32.c | 54 +++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 13 deletions(-)
arch/powerpc/kernel/signal_32.c +41 -13
@@ -229,14 +229,31 @@ struct rt_sigframe {* We only save the altivec/spe registers if the process has used * altivec/spe instructions at some point. */ +static void prepare_save_user_regs (int ctx_has_vsx_region) +{ +/* Make sure floating point registers are stored in regs */ +flush_fp_to_thread (current); +#ifdef CONFIG_ALTIVEC +if (current->thread.used_vr) +flush_altivec_to_thread (current); +if (cpu_has_feature (CPU_FTR_ALTIVEC )) + current->thread.vrsave =mfspr (SPRN_VRSAVE ); +#endif +#ifdef CONFIG_VSX +if (current->thread.used_vsr && ctx_has_vsx_region) +flush_vsx_to_thread (current); +#endif +#ifdef CONFIG_SPE +if (current->thread.used_spe) +flush_spe_to_thread (current); +#endif +} +static int save_user_regs (struct pt_regs *regs,struct mcontext __user *frame,struct mcontext __user *tm_frame,int ctx_has_vsx_region) {unsigned long msr = regs->msr; -/* Make sure floating point registers are stored in regs */ -flush_fp_to_thread (current); -/* save general registers */ if (save_general_regs (regs, frame))return 1 ;
@@ -244,7 +261,6 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,#ifdef CONFIG_ALTIVEC /* save altivec registers */ if (current->thread.used_vr) { -flush_altivec_to_thread (current);if (__copy_to_user (&frame->mc_vregs, ¤t->thread.vr_state,ELF_NVRREG *sizeof (vector128)))return 1 ;
@@ -260,8 +276,6 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* most significant bits of that same vector. --BenH * Note that the current VRSAVE value is in the SPR at this point. */ -if (cpu_has_feature (CPU_FTR_ALTIVEC )) - current->thread.vrsave =mfspr (SPRN_VRSAVE );if (__put_user (current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32 ]))return 1 ;#endif /* CONFIG_ALTIVEC */
@@ -281,7 +295,6 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* contains valid data */ if (current->thread.used_vsr && ctx_has_vsx_region) { -flush_vsx_to_thread (current);if (copy_vsx_to_user (&frame->mc_vsregs, current))return 1 ; msr |=MSR_VSX ;
@@ -290,7 +303,6 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,#ifdef CONFIG_SPE /* save spe registers */ if (current->thread.used_spe) { -flush_spe_to_thread (current);if (__copy_to_user (&frame->mc_vregs, current->thread.evr,ELF_NEVRREG *sizeof (u32)))return 1 ;
@@ -326,11 +338,23 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* * See save_user_regs() and signal_64.c:setup_tm_sigcontexts(). */ -static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame, -struct mcontext __user *tm_frame,unsigned long msr) +static void prepare_save_tm_user_regs (void ) {WARN_ON (tm_suspend_disabled); +#ifdef CONFIG_ALTIVEC +if (cpu_has_feature (CPU_FTR_ALTIVEC )) + current->thread.ckvrsave =mfspr (SPRN_VRSAVE ); +#endif +#ifdef CONFIG_SPE +if (current->thread.used_spe) +flush_spe_to_thread (current); +#endif +} + +static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame, +struct mcontext __user *tm_frame,unsigned long msr) +{/* Save both sets of general registers */ if (save_general_regs (¤t->thread.ckpt_regs, frame) ||save_general_regs (regs, tm_frame))
@@ -374,8 +398,6 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame* significant bits of a vector, we "cheat" and stuff VRSAVE in the * most significant bits of that same vector. --BenH */ -if (cpu_has_feature (CPU_FTR_ALTIVEC )) - current->thread.ckvrsave =mfspr (SPRN_VRSAVE );if (__put_user (current->thread.ckvrsave, (u32 __user *)&frame->mc_vregs[32 ]))return 1 ;
@@ -427,7 +449,6 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame* simply the same as in save_user_regs(). */ if (current->thread.used_spe) { -flush_spe_to_thread (current);if (__copy_to_user (&frame->mc_vregs, current->thread.evr,ELF_NEVRREG *sizeof (u32)))return 1 ;
@@ -447,6 +468,8 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame return 0; }#else +static void prepare_save_tm_user_regs (void ) { } +static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame,struct mcontext __user *tm_frame,unsigned long msr) {
@@ -790,9 +813,11 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,flush_icache_range (tramp, tramp +2 *sizeof (unsigned long ));if (MSR_TM_ACTIVE (msr)) { +prepare_save_tm_user_regs ();if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; }else { +prepare_save_user_regs (1 );if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; }
@@ -881,9 +906,11 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,flush_icache_range (tramp, tramp +2 *sizeof (unsigned long ));if (MSR_TM_ACTIVE (msr)) { +prepare_save_tm_user_regs ();if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) goto badframe; }else { +prepare_save_user_regs (1 );if (save_user_regs (regs, mctx, tm_mctx,1 )) goto badframe; }
@@ -1038,6 +1065,7 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx,*/ mctx = (struct mcontext __user *) ((unsigned long ) &old_ctx->uc_mcontext & ~0xfUL ); +prepare_save_user_regs (ctx_has_vsx_region);if (save_user_regs (regs, mctx,NULL , ctx_has_vsx_region))return -EFAULT ;if (!user_write_access_begin (old_ctx, ctx_size))
Signature · 1 line
2.25.0
PATCH v2 25/25 powerpc/signal32: Transform save_user_regs() and save_tm_user_regs() in 'unsafe' version
In reply to Christophe LeroyChange those two functions to be used within a user access block.
For that, change save_general_regs() to and unsafe_save_general_regs(), then replace all user accesses by unsafe_ versions.
This series leads to a reduction from 2.55s to 1.73s of the system CPU time with the following microbench app on an mpc832x with KUAP (approx 32%)
Without KUAP, the difference is in the noise.
void sigusr1(int sig) { }
int main(int argc, char **argv)
{
int i = 100000;
signal(SIGUSR1, sigusr1);
for (;i--;)
raise(SIGUSR1);
exit(0);
}An additional 0.10s reduction is achieved by removing CONFIG_PPC_FPU, as the mpc832x has no FPU.
A bit less spectacular on an 8xx as KUAP is less heavy, prior to the series (with KUAP) it ran in 8.10 ms. Once applies the removal of FPU regs handling, we get 7.05s. With the full series, we get 6.9s. If artificially re-activating FPU regs handling with the full series, we get 7.6s.
So for the 8xx, the removal of the FPU regs copy is what makes the difference, but the rework of handle_signal also have a benefit.
Same as above, without KUAP the difference is in the noise.
--- arch/powerpc/kernel/signal_32.c | 224 ++++++++++++++++---------------- 1 file changed, 111 insertions(+), 113 deletions(-)
arch/powerpc/kernel/signal_32.c +111 -113
@@ -93,8 +93,8 @@ static inline int get_sigset_t(sigset_t *set,#define to_user_ptr (p) ptr_to_compat(p)#define from_user_ptr (p) compat_ptr(p) -static inline int save_general_regs (struct pt_regs *regs, -struct mcontext __user *frame) +static __always_inline int +save_general_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame) {elf_greg_t64 *gregs = (elf_greg_t64 *)regs;int val, i;
@@ -108,10 +108,12 @@ static inline int save_general_regs(struct pt_regs *regs,else val = gregs[i]; -if (__put_user (val, &frame->mc_gregs[i])) -return -EFAULT ; +unsafe_put_user (val, &frame->mc_gregs[i], failed); }return 0 ; + +failed: +return 1 ; } static inline int restore_general_regs(struct pt_regs *regs,
@@ -148,11 +150,15 @@ static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset)#define to_user_ptr (p) ((unsigned long)(p))#define from_user_ptr (p) ((void __user *)(p)) -static inline int save_general_regs (struct pt_regs *regs, -struct mcontext __user *frame) +static __always_inline int +save_general_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame) {WARN_ON (!FULL_REGS (regs)); -return __copy_to_user (&frame->mc_gregs, regs,GP_REGS_SIZE ); +unsafe_copy_to_user (&frame->mc_gregs, regs,GP_REGS_SIZE , failed); +return 0 ; + +failed: +return 1 ; } static inline int restore_general_regs(struct pt_regs *regs,
@@ -170,6 +176,11 @@ static inline int restore_general_regs(struct pt_regs *regs, }#endif +#define unsafe_save_general_regs (regs, frame, label) do { \ + if (save_general_regs_unsafe(regs, frame)) \ + goto label; \ +} while (0) +/* * When we have signals to deliver, we set up on the * user stack, going down from the original stack pointer:
@@ -249,21 +260,19 @@ static void prepare_save_user_regs(int ctx_has_vsx_region)#endif } -static int save_user_regs (struct pt_regs *regs,struct mcontext __user *frame, -struct mcontext __user *tm_frame,int ctx_has_vsx_region) +static int save_user_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame, +struct mcontext __user *tm_frame,int ctx_has_vsx_region) {unsigned long msr = regs->msr;/* save general registers */ -if (save_general_regs (regs, frame)) -return 1 ; +unsafe_save_general_regs (regs, frame, failed);#ifdef CONFIG_ALTIVEC /* save altivec registers */ if (current->thread.used_vr) { -if (__copy_to_user (&frame->mc_vregs, ¤t->thread.vr_state, -ELF_NVRREG *sizeof (vector128))) -return 1 ; +unsafe_copy_to_user (&frame->mc_vregs, ¤t->thread.vr_state, +ELF_NVRREG *sizeof (vector128), failed);/* set MSR_VEC in the saved MSR value to indicate that frame->mc_vregs contains valid data */ msr |=MSR_VEC ;
@@ -276,11 +285,10 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* most significant bits of that same vector. --BenH * Note that the current VRSAVE value is in the SPR at this point. */ -if (__put_user (current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32 ])) -return 1 ; +unsafe_put_user (current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32 ], + failed);#endif /* CONFIG_ALTIVEC */ -if (copy_fpr_to_user (&frame->mc_fregs, current)) -return 1 ; +unsafe_copy_fpr_to_user (&frame->mc_fregs, current, failed);/* * Clear the MSR VSX bit to indicate there is no valid state attached
@@ -295,17 +303,15 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* contains valid data */ if (current->thread.used_vsr && ctx_has_vsx_region) { -if (copy_vsx_to_user (&frame->mc_vsregs, current)) -return 1 ; +unsafe_copy_vsx_to_user (&frame->mc_vsregs, current, failed); msr |=MSR_VSX ; }#endif /* CONFIG_VSX */ #ifdef CONFIG_SPE /* save spe registers */ if (current->thread.used_spe) { -if (__copy_to_user (&frame->mc_vregs, current->thread.evr, -ELF_NEVRREG *sizeof (u32))) -return 1 ; +unsafe_copy_to_user (&frame->mc_vregs, current->thread.evr, + ELF_NEVRREG * sizeof(u32)), failed);/* set MSR_SPE in the saved MSR value to indicate that frame->mc_vregs contains valid data */ msr |=MSR_SPE ;
@@ -313,21 +319,29 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,/* else assert((regs->msr & MSR_SPE) == 0) */ /* We always copy to/from spefscr */ -if (__put_user (current->thread.spefscr, (u32 __user *)&frame->mc_vregs +ELF_NEVRREG )) -return 1 ; +unsafe_put_user (current->thread.spefscr, + (u32 __user *)&frame->mc_vregs +ELF_NEVRREG , failed);#endif /* CONFIG_SPE */ -if (__put_user (msr, &frame->mc_gregs[PT_MSR ])) -return 1 ; +unsafe_put_user (msr, &frame->mc_gregs[PT_MSR ], failed); +/* We need to write 0 the MSR top 32 bits in the tm frame so that we * can check it on the restore to see if TM is active */ -if (tm_frame &&__put_user (0 , &tm_frame->mc_gregs[PT_MSR ])) -return 1 ; +if (tm_frame) +unsafe_put_user (0 , &tm_frame->mc_gregs[PT_MSR ], failed);return 0 ; + +failed: +return 1 ; } +#define unsafe_save_user_regs (regs, frame, tm_frame, has_vsx, label) do { \ + if (save_user_regs_unsafe(regs, frame, tm_frame, has_vsx)) \ + goto label; \ +} while (0) +#ifdef CONFIG_PPC_TRANSACTIONAL_MEM /* * Save the current user registers on the user stack.
@@ -336,7 +350,7 @@ static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,* We also save the transactional registers to a second ucontext in the * frame. * -* See save_user_regs() and signal_64.c:setup_tm_sigcontexts(). +* See save_user_regs_unsafe() and signal_64.c:setup_tm_sigcontexts(). */ static void prepare_save_tm_user_regs (void ) {
@@ -352,13 +366,12 @@ static void prepare_save_tm_user_regs(void)#endif } -static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame, -struct mcontext __user *tm_frame,unsigned long msr) +static int save_tm_user_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame, +struct mcontext __user *tm_frame,unsigned long msr) {/* Save both sets of general registers */ -if (save_general_regs (¤t->thread.ckpt_regs, frame) - ||save_general_regs (regs, tm_frame)) -return 1 ; +unsafe_save_general_regs (¤t->thread.ckpt_regs, frame, failed); +unsafe_save_general_regs (regs, tm_frame, failed);/* Stash the top half of the 64bit MSR into the 32bit MSR word * of the transactional mcontext. This way we have a backward-compatible
@@ -366,26 +379,21 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame* also look at what type of transaction (T or S) was active at the * time of the signal. */ -if (__put_user ((msr >>32 ), &tm_frame->mc_gregs[PT_MSR ])) -return 1 ; +unsafe_put_user ((msr >>32 ), &tm_frame->mc_gregs[PT_MSR ], failed);#ifdef CONFIG_ALTIVEC /* save altivec registers */ if (current->thread.used_vr) { -if (__copy_to_user (&frame->mc_vregs, ¤t->thread.ckvr_state, -ELF_NVRREG *sizeof (vector128))) -return 1 ; -if (msr &MSR_VEC ) { -if (__copy_to_user (&tm_frame->mc_vregs, - ¤t->thread.vr_state, -ELF_NVRREG *sizeof (vector128))) -return 1 ; - }else { -if (__copy_to_user (&tm_frame->mc_vregs, - ¤t->thread.ckvr_state, -ELF_NVRREG *sizeof (vector128))) -return 1 ; - } +unsafe_copy_to_user (&frame->mc_vregs, ¤t->thread.ckvr_state, +ELF_NVRREG *sizeof (vector128), failed); +if (msr &MSR_VEC ) +unsafe_copy_to_user (&tm_frame->mc_vregs, + ¤t->thread.vr_state, +ELF_NVRREG *sizeof (vector128), failed); +else +unsafe_copy_to_user (&tm_frame->mc_vregs, + ¤t->thread.ckvr_state, +ELF_NVRREG *sizeof (vector128), failed);/* set MSR_VEC in the saved MSR value to indicate that * frame->mc_vregs contains valid data
@@ -398,29 +406,21 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame* significant bits of a vector, we "cheat" and stuff VRSAVE in the * most significant bits of that same vector. --BenH */ -if (__put_user (current->thread.ckvrsave, - (u32 __user *)&frame->mc_vregs[32 ])) -return 1 ; -if (msr &MSR_VEC ) { -if (__put_user (current->thread.vrsave, - (u32 __user *)&tm_frame->mc_vregs[32 ])) -return 1 ; - }else { -if (__put_user (current->thread.ckvrsave, - (u32 __user *)&tm_frame->mc_vregs[32 ])) -return 1 ; - } +unsafe_put_user (current->thread.ckvrsave, + (u32 __user *)&frame->mc_vregs[32 ], failed); +if (msr &MSR_VEC ) +unsafe_put_user (current->thread.vrsave, + (u32 __user *)&tm_frame->mc_vregs[32 ], failed); +else +unsafe_put_user (current->thread.ckvrsave, + (u32 __user *)&tm_frame->mc_vregs[32 ], failed);#endif /* CONFIG_ALTIVEC */ -if (copy_ckfpr_to_user (&frame->mc_fregs, current)) -return 1 ; -if (msr &MSR_FP ) { -if (copy_fpr_to_user (&tm_frame->mc_fregs, current)) -return 1 ; - }else { -if (copy_ckfpr_to_user (&tm_frame->mc_fregs, current)) -return 1 ; - } +unsafe_copy_ckfpr_to_user (&frame->mc_fregs, current, failed); +if (msr &MSR_FP ) +unsafe_copy_fpr_to_user (&tm_frame->mc_fregs, current, failed); +else +unsafe_copy_ckfpr_to_user (&tm_frame->mc_fregs, current, failed);#ifdef CONFIG_VSX /*
@@ -430,53 +430,54 @@ static int save_tm_user_regs(struct pt_regs *regs, struct mcontext __user *frame* contains valid data */ if (current->thread.used_vsr) { -if (copy_ckvsx_to_user (&frame->mc_vsregs, current)) -return 1 ; -if (msr &MSR_VSX ) { -if (copy_vsx_to_user (&tm_frame->mc_vsregs, - current)) -return 1 ; - }else { -if (copy_ckvsx_to_user (&tm_frame->mc_vsregs, current)) -return 1 ; - } +unsafe_copy_ckvsx_to_user (&frame->mc_vsregs, current, failed); +if (msr &MSR_VSX ) +unsafe_copy_vsx_to_user (&tm_frame->mc_vsregs, current, failed); +else +unsafe_copy_ckvsx_to_user (&tm_frame->mc_vsregs, current, failed); msr |=MSR_VSX ; }#endif /* CONFIG_VSX */ #ifdef CONFIG_SPE /* SPE regs are not checkpointed with TM, so this section is -* simply the same as in save_user_regs(). +* simply the same as in save_user_regs_unsafe(). */ if (current->thread.used_spe) { -if (__copy_to_user (&frame->mc_vregs, current->thread.evr, -ELF_NEVRREG *sizeof (u32))) -return 1 ; +unsafe_copy_to_user (&frame->mc_vregs, current->thread.evr, +ELF_NEVRREG *sizeof (u32), failed);/* set MSR_SPE in the saved MSR value to indicate that * frame->mc_vregs contains valid data */ msr |=MSR_SPE ; }/* We always copy to/from spefscr */ -if (__put_user (current->thread.spefscr, (u32 __user *)&frame->mc_vregs +ELF_NEVRREG )) -return 1 ; +unsafe_put_user (current->thread.spefscr, + (u32 __user *)&frame->mc_vregs +ELF_NEVRREG , failed);#endif /* CONFIG_SPE */ -if (__put_user (msr, &frame->mc_gregs[PT_MSR ])) -return 1 ; +unsafe_put_user (msr, &frame->mc_gregs[PT_MSR ], failed);return 0 ; + +failed: + return 1; }#else static void prepare_save_tm_user_regs (void ) { } -static int save_tm_user_regs (struct pt_regs *regs,struct mcontext __user *frame, -struct mcontext __user *tm_frame,unsigned long msr) +static int save_tm_user_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame, +struct mcontext __user *tm_frame,unsigned long msr) {return 0 ; }#endif +#define unsafe_save_tm_user_regs (regs, frame, tm_frame, msr, label) do { \ + if (save_tm_user_regs_unsafe(regs, frame, tm_frame, msr)) \ + goto label; \ +} while (0) +/* * Restore the current user register values from the user stack, * (except for MSR).
@@ -769,6 +770,11 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,#ifdef CONFIG_PPC_TRANSACTIONAL_MEM tm_mctx = &frame->uc_transact.uc_mcontext;#endif +if (MSR_TM_ACTIVE (msr)) +prepare_save_tm_user_regs (); +else +prepare_save_user_regs (1 ); +if (!user_write_access_begin (frame,sizeof (*frame))) goto badframe;
@@ -788,8 +794,10 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,unsafe_put_user ((unsigned long )tm_mctx, &frame->uc_transact.uc_regs, failed);#endif +unsafe_save_tm_user_regs (regs, mctx, tm_mctx, msr, failed); }else {unsafe_put_user (0 , &frame->uc.uc_link, failed); +unsafe_save_user_regs (regs, mctx, tm_mctx,1 , failed); }/* Save user registers on the stack */
@@ -812,15 +820,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,if (tramp == (unsigned long )mctx->mc_pad)flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); -if (MSR_TM_ACTIVE (msr)) { -prepare_save_tm_user_regs (); -if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) - goto badframe; - }else { -prepare_save_user_regs (1 ); -if (save_user_regs (regs, mctx, tm_mctx,1 )) - goto badframe; - } regs->link = tramp;#ifdef CONFIG_PPC_FPU_REGS
@@ -875,6 +874,11 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,#ifdef CONFIG_PPC_TRANSACTIONAL_MEM tm_mctx = &frame->mctx_transact;#endif +if (MSR_TM_ACTIVE (msr)) +prepare_save_tm_user_regs (); +else +prepare_save_user_regs (1 ); +if (!user_write_access_begin (frame,sizeof (*frame))) goto badframe; sc = (struct sigcontext __user *) &frame->sctx;
@@ -892,6 +896,11 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,unsafe_put_user (to_user_ptr (mctx), &sc->regs, failed);unsafe_put_user (ksig->sig, &sc->signal, failed); +if (MSR_TM_ACTIVE (msr)) +unsafe_save_tm_user_regs (regs, mctx, tm_mctx, msr, failed); +else +unsafe_save_user_regs (regs, mctx, tm_mctx,1 , failed); +if (vdso32_sigtramp && tsk->mm->context.vdso_base) { tramp = tsk->mm->context.vdso_base + vdso32_sigtramp; }else {
@@ -905,16 +914,6 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,if (tramp == (unsigned long )mctx->mc_pad)flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); -if (MSR_TM_ACTIVE (msr)) { -prepare_save_tm_user_regs (); -if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) - goto badframe; - }else { -prepare_save_user_regs (1 ); -if (save_user_regs (regs, mctx, tm_mctx,1 )) - goto badframe; - } - regs->link = tramp;#ifdef CONFIG_PPC_FPU_REGS
@@ -1066,10 +1065,9 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx, mctx = (struct mcontext __user *) ((unsigned long ) &old_ctx->uc_mcontext & ~0xfUL );prepare_save_user_regs (ctx_has_vsx_region); -if (save_user_regs (regs, mctx,NULL , ctx_has_vsx_region)) -return -EFAULT ;if (!user_write_access_begin (old_ctx, ctx_size))return -EFAULT ; +unsafe_save_user_regs (regs, mctx,NULL , ctx_has_vsx_region, failed);unsafe_put_sigset_t (&old_ctx->uc_sigmask, ¤t->blocked, failed);unsafe_put_user (to_user_ptr (mctx), &old_ctx->uc_regs, failed);user_write_access_end ();
Signature · 1 line
2.25.0
kernel test robot
build botRe: [PATCH v2 25/25] powerpc/signal32: Transform save_user_regs() and save_tm_user_regs() in 'unsafe' version
I love your patch! Yet something to improve:
Hi Christophe,
I love your patch! Yet something to improve:
[auto build test ERROR on powerpc/next]
[also build test ERROR on linus/master v5.9-rc2 next-20200827] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-Switch-signal-32-to-using-unsafe_put_user-and-friends/20200819-012411 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: powerpc64-randconfig-r005-20200827 (attached as .config) compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/powerpc/kernel/signal_32.c: In function 'save_user_regs_unsafe':
>> arch/powerpc/kernel/signal_32.c:314:34: error: macro "unsafe_copy_to_user" requires 4 arguments, but only 3 given
314 | ELF_NEVRREG * sizeof(u32)), failed);
| ^
In file included from include/linux/uaccess.h:9,
from include/linux/sched/task.h:11,
from include/linux/sched/signal.h:9,
from include/linux/rcuwait.h:6,
from include/linux/percpu-rwsem.h:7,
from include/linux/fs.h:33,
from include/linux/huge_mm.h:8,
from include/linux/mm.h:672,
from arch/powerpc/kernel/signal_32.c:17:
arch/powerpc/include/asm/uaccess.h:605: note: macro "unsafe_copy_to_user" defined here
605 | #define unsafe_copy_to_user(d, s, l, e) \
|
>> arch/powerpc/kernel/signal_32.c:313:3: error: 'unsafe_copy_to_user' undeclared (first use in this function); did you mean 'raw_copy_to_user'?
313 | unsafe_copy_to_user(&frame->mc_vregs, current->thread.evr,
| ^~~~~~~~~~~~~~~~~~~
| raw_copy_to_user
arch/powerpc/kernel/signal_32.c:313:3: note: each undeclared identifier is reported only once for each function it appears in
>> arch/powerpc/kernel/signal_32.c:314:37: error: 'failed' undeclared (first use in this function)
314 | ELF_NEVRREG * sizeof(u32)), failed);
| ^~~~~~
arch/powerpc/kernel/signal_32.c:314:35: warning: left-hand operand of comma expression has no effect [-Wunused-value]
314 | ELF_NEVRREG * sizeof(u32)), failed);
| ^
>> arch/powerpc/kernel/signal_32.c:314:43: error: expected ';' before ')' token
314 | ELF_NEVRREG * sizeof(u32)), failed);
| ^
| ;
>> arch/powerpc/kernel/signal_32.c:314:43: error: expected statement before ')' token# https://github.com/0day-ci/linux/commit/2706ef40840de32202abda6d2d7e0c9ea96c511c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Christophe-Leroy/powerpc-Switch-signal-32-to-using-unsafe_put_user-and-friends/20200819-012411 git checkout 2706ef40840de32202abda6d2d7e0c9ea96c511c
vim +/unsafe_copy_to_user +314 arch/powerpc/kernel/signal_32.c
262
263 static int save_user_regs_unsafe(struct pt_regs *regs, struct mcontext __user *frame,
264 struct mcontext __user *tm_frame, int ctx_has_vsx_region)
265 {
266 unsigned long msr = regs->msr;
267
268 /* save general registers */
269 unsafe_save_general_regs(regs, frame, failed);
270
271 #ifdef CONFIG_ALTIVEC
272 /* save altivec registers */
273 if (current->thread.used_vr) {
274 unsafe_copy_to_user(&frame->mc_vregs, ¤t->thread.vr_state,
275 ELF_NVRREG * sizeof(vector128), failed);
276 /* set MSR_VEC in the saved MSR value to indicate that
277 frame->mc_vregs contains valid data */
278 msr |= MSR_VEC;
279 }
280 /* else assert((regs->msr & MSR_VEC) == 0) */
281
282 /* We always copy to/from vrsave, it's 0 if we don't have or don't
283 * use altivec. Since VSCR only contains 32 bits saved in the least
284 * significant bits of a vector, we "cheat" and stuff VRSAVE in the
285 * most significant bits of that same vector. --BenH
286 * Note that the current VRSAVE value is in the SPR at this point.
287 */
288 unsafe_put_user(current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32],
289 failed);
290 #endif /* CONFIG_ALTIVEC */
291 unsafe_copy_fpr_to_user(&frame->mc_fregs, current, failed);
292
293 /*
294 * Clear the MSR VSX bit to indicate there is no valid state attached
295 * to this context, except in the specific case below where we set it.
296 */
297 msr &= ~MSR_VSX;
298 #ifdef CONFIG_VSX
299 /*
300 * Copy VSR 0-31 upper half from thread_struct to local
301 * buffer, then write that to userspace. Also set MSR_VSX in
302 * the saved MSR value to indicate that frame->mc_vregs
303 * contains valid data
304 */
305 if (current->thread.used_vsr && ctx_has_vsx_region) {
306 unsafe_copy_vsx_to_user(&frame->mc_vsregs, current, failed);
307 msr |= MSR_VSX;
308 }
309 #endif /* CONFIG_VSX */
310 #ifdef CONFIG_SPE
311 /* save spe registers */
312 if (current->thread.used_spe) {
> 313 unsafe_copy_to_user(&frame->mc_vregs, current->thread.evr, > 314 ELF_NEVRREG * sizeof(u32)), failed);
315 /* set MSR_SPE in the saved MSR value to indicate that
316 frame->mc_vregs contains valid data */
317 msr |= MSR_SPE;
318 }
319 /* else assert((regs->msr & MSR_SPE) == 0) */
320
321 /* We always copy to/from spefscr */
322 unsafe_put_user(current->thread.spefscr,
323 (u32 __user *)&frame->mc_vregs + ELF_NEVRREG, failed);
324 #endif /* CONFIG_SPE */
325
326 unsafe_put_user(msr, &frame->mc_gregs[PT_MSR], failed);
327
328 /* We need to write 0 the MSR top 32 bits in the tm frame so that we
329 * can check it on the restore to see if TM is active
330 */
331 if (tm_frame)
332 unsafe_put_user(0, &tm_frame->mc_gregs[PT_MSR], failed);
333
334 return 0;
335
336 failed:
337 return 1;
338 }
339
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v2 25/25] powerpc/signal32: Transform save_user_regs() and save_tm_user_regs() in 'unsafe' version
Le 27/08/2020 à 11:07, kernel test robot a écrit :
Quoted 52 lines
Hi Christophe,
I love your patch! Yet something to improve:
[auto build test ERROR on powerpc/next]
[also build test ERROR on linus/master v5.9-rc2 next-20200827] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-Switch-signal-32-to-using-unsafe_put_user-and-friends/20200819-012411 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: powerpc64-randconfig-r005-20200827 (attached as .config) compiler: powerpc-linux-gcc (GCC) 9.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=powerpc64If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>):
arch/powerpc/kernel/signal_32.c: In function 'save_user_regs_unsafe':Quoted 1 line
Quoted 1 line
arch/powerpc/kernel/signal_32.c:314:34: error: macro "unsafe_copy_to_user" requires 4 arguments, but only 3 given314 | ELF_NEVRREG * sizeof(u32)), failed); | ^ In file included from include/linux/uaccess.h:9, from include/linux/sched/task.h:11, from include/linux/sched/signal.h:9, from include/linux/rcuwait.h:6, from include/linux/percpu-rwsem.h:7, from include/linux/fs.h:33, from include/linux/huge_mm.h:8, from include/linux/mm.h:672, from arch/powerpc/kernel/signal_32.c:17: arch/powerpc/include/asm/uaccess.h:605: note: macro "unsafe_copy_to_user" defined here 605 | #define unsafe_copy_to_user(d, s, l, e) \ |Quoted 1 line
Quoted 1 line
arch/powerpc/kernel/signal_32.c:313:3: error: 'unsafe_copy_to_user' undeclared (first use in this function); did you mean 'raw_copy_to_user'?313 | unsafe_copy_to_user(&frame->mc_vregs, current->thread.evr, | ^~~~~~~~~~~~~~~~~~~ | raw_copy_to_user
arch/powerpc/kernel/signal_32.c:313:3: note: each undeclared identifier is reported only once for each function it appears inQuoted 1 line
Quoted 1 line
arch/powerpc/kernel/signal_32.c:314:37: error: 'failed' undeclared (first use in this function)314 | ELF_NEVRREG * sizeof(u32)), failed); | ^~~~~~ arch/powerpc/kernel/signal_32.c:314:35: warning: left-hand operand of comma expression has no effect [-Wunused-value] 314 | ELF_NEVRREG * sizeof(u32)), failed); | ^
Quoted 6 lines
Quoted 1 line
Quoted 1 line
arch/powerpc/kernel/signal_32.c:314:43: error: expected ';' before ')' token314 | ELF_NEVRREG * sizeof(u32)), failed); | ^ | ;Quoted 1 line
Quoted 1 line
arch/powerpc/kernel/signal_32.c:314:43: error: expected statement before ')' token
Should be fixed by:
arch/powerpc/kernel/signal_32.c +1 -1
@@ -311,7 +311,7 @@ static int save_user_regs_unsafe(struct pt_regs *regs, struct mcontext __user *f/* save spe registers */ if (current->thread.used_spe) {unsafe_copy_to_user (&frame->mc_vregs, current->thread.evr, - ELF_NEVRREG * sizeof(u32)), failed); +ELF_NEVRREG *sizeof (u32), failed);/* set MSR_SPE in the saved MSR value to indicate that frame->mc_vregs contains valid data */ msr |=MSR_SPE ;
---
Christophe
Re: [PATCH v2 25/25] powerpc/signal32: Transform save_user_regs() and save_tm_user_regs() in 'unsafe' version
In reply to Christophe LeroyQuoted 97 lines · Christophe Leroy
Change those two functions to be used within a user access block.
For that, change
save_general_regs()to andunsafe_save_general_regs(), then replace all user accesses byunsafe_versions.This series leads to a reduction from 2.55s to 1.73s of the system CPU time with the following microbench app on an mpc832x with KUAP (approx 32%)
Without KUAP, the difference is in the noise.
void sigusr1(int sig) { }
int
main(int argc, char **argv)
{
int i = 100000;
signal(SIGUSR1, sigusr1);
for (;i--;)
raise(SIGUSR1);
exit(0);
}An additional 0.10s reduction is achieved by removing
CONFIG_PPC_FPU, as the mpc832x has no FPU.A bit less spectacular on an 8xx as KUAP is less heavy, prior to the series (with KUAP) it ran in 8.10 ms. Once applies the removal of FPU regs handling, we get 7.05s. With the full series, we get 6.9s. If artificially re-activating FPU regs handling with the full series, we get 7.6s.
So for the 8xx, the removal of the FPU regs copy is what makes the difference, but the rework of
handle_signalalso have a benefit.Same as above, without KUAP the difference is in the noise.
Signed-off-by Christophe Leroy <[email protected]>---
arch/powerpc/kernel/signal_32.c| 224 ++++++++++++++++----------------1 file changed, 111 insertions(+), 113 deletions(-)arch/powerpc/kernel/signal_32.c +2
-2@@ -93,8 +93,8 @@ static inline int get_sigset_t(sigset_t *set,#define to_user_ptr (p) ptr_to_compat(p)#define from_user_ptr (p) compat_ptr(p) -static inline int save_general_regs (struct pt_regs *regs, -struct mcontext __user *frame) +static __always_inline int +save_general_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame) {elf_greg_t64 *gregs = (elf_greg_t64 *)regs;int val, i;
arch/powerpc/kernel/signal_32.c +0
-0@@ -108,10 +108,12 @@ static inline int save_general_regs(struct pt_regs *regs,else
val = gregs[i];- if (
__put_user(val, &frame->mc_gregs[i]))
- return-EFAULT;
+unsafe_put_user(val, &frame->mc_gregs[i], failed); }
return 0;arch/powerpc/kernel/signal_32.c +3
-0+ +failed: +return 1 ;}
static inline int restore_general_regs(struct
pt_regs*regs,arch/powerpc/kernel/signal_32.c +7
-3@@ -148,11 +150,15 @@ static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset)#define to_user_ptr (p) ((unsigned long)(p))#define from_user_ptr (p) ((void __user *)(p)) -static inline int save_general_regs (struct pt_regs *regs, -struct mcontext __user *frame) +static __always_inline int +save_general_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame) {WARN_ON (!FULL_REGS (regs)); -return __copy_to_user (&frame->mc_gregs, regs,GP_REGS_SIZE ); +unsafe_copy_to_user (&frame->mc_gregs, regs,GP_REGS_SIZE , failed); +return 0 ; + +failed: +return 1 ; }static inline int restore_general_regs(struct
pt_regs*regs,
arch/powerpc/kernel/signal_32.c static inline int restore_general_regs(struct · line 181
Quoted 6 lines
arch/powerpc/kernel/signal_32.c +2
-0@@ -170,6 +176,11 @@ static inline int restore_general_regs(struct pt_regs *regs, }#endif +#define unsafe_save_general_regs (regs, frame, label) do { \ + if (save_general_regs_unsafe(regs, frame)) \
Minor nitpick (sorry); this naming seems a bit strange to me, in x86 it is "__unsafe_" as a prefix instead of "_unsafe" as a suffix. That sounds a bit better to me, what do you think? Unless there is some convention I am not aware of here apart from "unsafe_" using a goto label for errors.
Quoted 409 lines
arch/powerpc/kernel/signal_32.c +3
-0+ goto label; \ +}while (0 ) +/* * When we have signals to deliver, we set up on the * user stack, going down from the original stack pointer:
arch/powerpc/kernel/signal_32.c +5
-7@@ -249,21 +260,19 @@ static void prepare_save_user_regs(int ctx_has_vsx_region)#endif } -static int save_user_regs (struct pt_regs *regs,struct mcontext __user *frame, - struct mcontext __user *tm_frame, int ctx_has_vsx_region) +static int save_user_regs_unsafe(struct pt_regs *regs, struct mcontext__user *frame, +struct mcontext __user *tm_frame,int ctx_has_vsx_region) {unsigned long msr = regs->msr;/* save general registers */ -if (save_general_regs (regs, frame)) -return 1 ; +unsafe_save_general_regs (regs, frame, failed);#ifdef CONFIG_ALTIVEC /* save altivec registers */ if (current->thread.used_vr) { -if (__copy_to_user (&frame->mc_vregs, ¤t->thread.vr_state, -ELF_NVRREG *sizeof (vector128))) -return 1 ; +unsafe_copy_to_user (&frame->mc_vregs, ¤t->thread.vr_state, +ELF_NVRREG *sizeof (vector128), failed);/* set
MSR_VECin the saved MSR value to indicate thatframe->mc_vregscontains valid data */
msr |=MSR_VEC;arch/powerpc/kernel/signal_32.c +3
-4@@ -276,11 +285,10 @@ static int save_user_regs(struct pt_regs *regs,struct mcontext __user *frame, * most significant bits of that same vector. --BenH * Note that the current VRSAVE value is in the SPR at this point. */ -if (__put_user (current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32])) -return 1 ; +unsafe_put_user (current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32 ], + failed);#endif /* CONFIG_ALTIVEC */ -if (copy_fpr_to_user (&frame->mc_fregs, current)) -return 1 ; +unsafe_copy_fpr_to_user (&frame->mc_fregs, current, failed);/*
* Clear the MSR VSX bit to indicate there is no valid state attachedarch/powerpc/kernel/signal_32.c +3
-5@@ -295,17 +303,15 @@ static int save_user_regs(struct pt_regs *regs,struct mcontext __user *frame, * contains valid data */ if (current->thread.used_vsr && ctx_has_vsx_region) { -if (copy_vsx_to_user (&frame->mc_vsregs, current)) -return 1 ; +unsafe_copy_vsx_to_user (&frame->mc_vsregs, current, failed); msr |=MSR_VSX ; }#endif /* CONFIG_VSX */ #ifdef CONFIG_SPE /* save spe registers */ if (current->thread.used_spe) { -if (__copy_to_user (&frame->mc_vregs, current->thread.evr, -ELF_NEVRREG *sizeof (u32))) -return 1 ; +unsafe_copy_to_user (&frame->mc_vregs, current->thread.evr, + ELF_NEVRREG * sizeof(u32)), failed);/* set MSR_SPE in the saved MSR value to indicate that
frame->mc_vregscontains valid data */
msr |=MSR_SPE;arch/powerpc/kernel/signal_32.c +15
-6@@ -313,21 +319,29 @@ static int save_user_regs(struct pt_regs *regs,struct mcontext __user *frame,/* else assert((regs->msr & MSR_SPE) == 0) */ /* We always copy to/from spefscr */ - if (__put_user(current->thread.spefscr, (u32 __user *)&frame->mc_vregs + ELF_NEVRREG)) - return 1; + unsafe_put_user(current->thread.spefscr, + (u32 __user *)&frame->mc_vregs + ELF_NEVRREG, failed);#endif /* CONFIG_SPE */ - if (__put_user(msr, &frame->mc_gregs[PT_MSR])) - return 1; +unsafe_put_user (msr, &frame->mc_gregs[PT_MSR ], failed); +/* We need to write 0 the MSR top 32 bits in the tm frame so that we * can check it on the restore to see if TM is active */ - if (tm_frame && __put_user(0, &tm_frame->mc_gregs[PT_MSR])) - return 1; +if (tm_frame) +unsafe_put_user (0 , &tm_frame->mc_gregs[PT_MSR ], failed);return 0 ; + +failed: +return 1 ; } +#define unsafe_save_user_regs (regs, frame, tm_frame, has_vsx, label) do { \ +if (save_user_regs_unsafe (regs, frame, tm_frame, has_vsx)) \ + goto label; \ +}while (0 ) +#ifdef
CONFIG_PPC_TRANSACTIONAL_MEM
/*
* Save the current user registers on the user stack.arch/powerpc/kernel/signal_32.c +1
-1@@ -336,7 +350,7 @@ static int save_user_regs(struct pt_regs *regs,struct mcontext __user *frame, * We also save the transactional registers to a second ucontext in the * frame. * -* See save_user_regs() and signal_64.c:setup_tm_sigcontexts(). +* See save_user_regs_unsafe() and signal_64.c:setup_tm_sigcontexts(). */ static void prepare_save_tm_user_regs (void ){
arch/powerpc/kernel/signal_32.c +4
-5@@ -352,13 +366,12 @@ static void prepare_save_tm_user_regs(void)#endif } -static int save_tm_user_regs(struct pt_regs *regs, struct mcontext__user *frame, - struct mcontext __user *tm_frame, unsigned long msr) +static int save_tm_user_regs_unsafe(struct pt_regs *regs, structmcontext __user *frame, +struct mcontext __user *tm_frame,unsigned long msr) {/* Save both sets of general registers */ -if (save_general_regs (¤t->thread.ckpt_regs, frame) - ||save_general_regs (regs, tm_frame)) -return 1 ; +unsafe_save_general_regs (¤t->thread.ckpt_regs, frame, failed); +unsafe_save_general_regs (regs, tm_frame, failed);/* Stash the top half of the 64bit MSR into the 32bit MSR word
* of the transactional mcontext. This way we have a backward-compatiblearch/powerpc/kernel/signal_32.c +0
-0@@ -366,26 +379,21 @@ static int save_tm_user_regs(struct pt_regs *regs,struct mcontext
__user*frame
* also look at what type of transaction (T or S) was active at the
* time of the signal.
*/
- if (__put_user((msr >> 32), &tm_frame->mc_gregs[PT_MSR]))
- return 1;
+unsafe_put_user((msr >> 32), &tm_frame->mc_gregs[PT_MSR], failed);#ifdef
CONFIG_ALTIVEC
/* save altivec registers */
if (current->thread.used_vr) {
- if (__copy_to_user(&frame->mc_vregs,¤t->thread.ckvr_state,
-ELF_NVRREG* sizeof(vector128)))
- return 1;
- if (msr &MSR_VEC) {
- if (__copy_to_user(&tm_frame->mc_vregs,
-¤t->thread.vr_state,
-ELF_NVRREG* sizeof(vector128)))
- return 1;
- } else {
- if (__copy_to_user(&tm_frame->mc_vregs,
-¤t->thread.ckvr_state,
-ELF_NVRREG* sizeof(vector128)))
- return 1;
- }
+ unsafe_copy_to_user(&frame->mc_vregs,¤t->thread.ckvr_state,
+ELF_NVRREG* sizeof(vector128), failed);
+ if (msr &MSR_VEC)
+ unsafe_copy_to_user(&tm_frame->mc_vregs,
+¤t->thread.vr_state,
+ELF_NVRREG* sizeof(vector128), failed);
+ else
+ unsafe_copy_to_user(&tm_frame->mc_vregs,
+¤t->thread.ckvr_state,
+ELF_NVRREG* sizeof(vector128), failed);/* set
MSR_VECin the saved MSR value to indicate that
*frame->mc_vregscontains valid dataarch/powerpc/kernel/signal_32.c +0
-0@@ -398,29 +406,21 @@ static int save_tm_user_regs(struct pt_regs *regs,struct mcontext
__user*frame
* significant bits of a vector, we "cheat" and stuff VRSAVE in the
* most significant bits of that same vector. --BenH
*/
- if (__put_user(current->thread.ckvrsave,
- (u32__user*)&frame->mc_vregs[32]))
- return 1;
- if (msr &MSR_VEC) {
- if (__put_user(current->thread.vrsave,
- (u32__user*)&tm_frame->mc_vregs[32]))
- return 1;
- } else {
- if (__put_user(current->thread.ckvrsave,
- (u32__user*)&tm_frame->mc_vregs[32]))
- return 1;
- }
+ unsafe_put_user(current->thread.ckvrsave,
+ (u32__user*)&frame->mc_vregs[32], failed);
+ if (msr &MSR_VEC)
+ unsafe_put_user(current->thread.vrsave,
+ (u32__user*)&tm_frame->mc_vregs[32], failed);
+ else
+ unsafe_put_user(current->thread.ckvrsave,
+ (u32__user*)&tm_frame->mc_vregs[32], failed); #endif /*CONFIG_ALTIVEC*/- if (
copy_ckfpr_to_user(&frame->mc_fregs, current))
- return 1;
- if (msr &MSR_FP) {
- if (copy_fpr_to_user(&tm_frame->mc_fregs, current))
- return 1;
- } else {
- if (copy_ckfpr_to_user(&tm_frame->mc_fregs, current))
- return 1;
- }
+unsafe_copy_ckfpr_to_user(&frame->mc_fregs, current, failed);
+ if (msr &MSR_FP)
+unsafe_copy_fpr_to_user(&tm_frame->mc_fregs, current, failed);
+ else
+unsafe_copy_ckfpr_to_user(&tm_frame->mc_fregs, current, failed);#ifdef
CONFIG_VSX
/*arch/powerpc/kernel/signal_32.c +0
-0@@ -430,53 +430,54 @@ static int save_tm_user_regs(struct pt_regs *regs,struct mcontext
__user*frame
* contains valid data
*/
if (current->thread.used_vsr) {
- if (copy_ckvsx_to_user(&frame->mc_vsregs, current))
- return 1;
- if (msr &MSR_VSX) {
- if (copy_vsx_to_user(&tm_frame->mc_vsregs,
- current))
- return 1;
- } else {
- if (copy_ckvsx_to_user(&tm_frame->mc_vsregs, current))
- return 1;
- }
+unsafe_copy_ckvsx_to_user(&frame->mc_vsregs, current, failed);
+ if (msr &MSR_VSX)
+unsafe_copy_vsx_to_user(&tm_frame->mc_vsregs, current, failed);
+ else
+unsafe_copy_ckvsx_to_user(&tm_frame->mc_vsregs, current, failed);msr |=
MSR_VSX;
}
#endif /*CONFIG_VSX*/
#ifdefCONFIG_SPE
/* SPE regs are not checkpointed with TM, so this section is
- * simply the same as insave_user_regs().
+ * simply the same as insave_user_regs_unsafe(). */
if (current->thread.used_spe) {
- if (__copy_to_user(&frame->mc_vregs,current->thread.evr,
-ELF_NEVRREG* sizeof(u32)))
- return 1;
+ unsafe_copy_to_user(&frame->mc_vregs,current->thread.evr,
+ELF_NEVRREG* sizeof(u32), failed);
/* setMSR_SPEin the saved MSR value to indicate that
*frame->mc_vregscontains valid data */
msr |=MSR_SPE;
}/* We always copy to/from spefscr */
- if (__put_user(current->thread.spefscr, (u32__user*)&frame->mc_vregs
+ELF_NEVRREG))
- return 1;
+ unsafe_put_user(current->thread.spefscr,
+ (u32__user*)&frame->mc_vregs +ELF_NEVRREG, failed); #endif /*CONFIG_SPE*/- if (
__put_user(msr, &frame->mc_gregs[PT_MSR]))
- return 1;
+unsafe_put_user(msr, &frame->mc_gregs[PT_MSR], failed);return 0;
arch/powerpc/kernel/signal_32.c +3
-0+ +failed: +return 1 ;}
#else
static voidprepare_save_tm_user_regs(void){ }-static int save_tm_user_regs(struct
pt_regs*regs, struct mcontext__user*frame,
- struct mcontext__user*tm_frame, unsigned long msr) +static int save_tm_user_regs_unsafe(structpt_regs*regs, struct mcontext__user*frame,
+ struct mcontext__user*tm_frame, unsigned long msr)
{
return 0;
}
#endif+#define
unsafe_save_tm_user_regs(regs, frame, tm_frame, msr, label)do { \
+ if (save_tm_user_regs_unsafe(regs, frame, tm_frame, msr)) \
+ goto label; \arch/powerpc/kernel/signal_32.c +2
-0+}while (0 ) +/*
* Restore the current user register values from the user stack,
* (except for MSR).arch/powerpc/kernel/signal_32.c +7
-0@@ -769,6 +770,11 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,#ifdef CONFIG_PPC_TRANSACTIONAL_MEM tm_mctx = &frame->uc_transact.uc_mcontext;#endif +if (MSR_TM_ACTIVE (msr)) +prepare_save_tm_user_regs (); +else +prepare_save_user_regs (1 ); +if (!user_write_access_begin (frame,sizeof (*frame))) goto badframe;@@ -788,8 +794,10 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,unsafe_put_user ((unsigned long )tm_mctx, &frame->uc_transact.uc_regs, failed);#endif +unsafe_save_tm_user_regs (regs, mctx, tm_mctx, msr, failed); }else {unsafe_put_user (0 , &frame->uc.uc_link, failed); +unsafe_save_user_regs (regs, mctx, tm_mctx,1 , failed); }/* Save user registers on the stack */
arch/powerpc/kernel/signal_32.c +0
-9@@ -812,15 +820,6 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset, if (tramp == (unsigned long)mctx->mc_pad)flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); -if (MSR_TM_ACTIVE (msr)) { -prepare_save_tm_user_regs (); -if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) - goto badframe; - }else { -prepare_save_user_regs (1 ); -if (save_user_regs (regs, mctx, tm_mctx,1 )) - goto badframe; - } regs->link = tramp;#ifdef
CONFIG_PPC_FPU_REGSarch/powerpc/kernel/signal_32.c +5
-0@@ -875,6 +874,11 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,#ifdef CONFIG_PPC_TRANSACTIONAL_MEM tm_mctx = &frame->mctx_transact;#endif +if (MSR_TM_ACTIVE (msr)) +prepare_save_tm_user_regs (); +else +prepare_save_user_regs (1 ); +if (!user_write_access_begin (frame,sizeof (*frame))) goto badframe;sc = (struct sigcontext
__user*)&frame->sctx;arch/powerpc/kernel/signal_32.c +5
-0@@ -892,6 +896,11 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset,unsafe_put_user (to_user_ptr (mctx), &sc->regs, failed);unsafe_put_user (ksig->sig, &sc->signal, failed); +if (MSR_TM_ACTIVE (msr)) +unsafe_save_tm_user_regs (regs, mctx, tm_mctx, msr, failed); +else +unsafe_save_user_regs (regs, mctx, tm_mctx,1 , failed); +if (vdso32_sigtramp && tsk->mm->context.vdso_base) { tramp = tsk->mm->context.vdso_base + vdso32_sigtramp;} else {
arch/powerpc/kernel/signal_32.c +0
-10@@ -905,16 +914,6 @@ int handle_signal32(struct ksignal *ksig, sigset_t *oldset, if (tramp == (unsigned long)mctx->mc_pad)flush_icache_range (tramp, tramp +2 *sizeof (unsigned long )); -if (MSR_TM_ACTIVE (msr)) { -prepare_save_tm_user_regs (); -if (save_tm_user_regs (regs, mctx, tm_mctx, msr)) - goto badframe; - }else { -prepare_save_user_regs (1 ); -if (save_user_regs (regs, mctx, tm_mctx,1 )) - goto badframe; - } - regs->link = tramp;#ifdef
CONFIG_PPC_FPU_REGSarch/powerpc/kernel/signal_32.c +1
-2@@ -1066,10 +1065,9 @@ SYSCALL_DEFINE3(swapcontext, struct ucontext __user *, old_ctx, mctx = (struct mcontext __user *) ((unsigned long ) &old_ctx->uc_mcontext & ~0xfUL );prepare_save_user_regs (ctx_has_vsx_region); -if (save_user_regs (regs, mctx,NULL , ctx_has_vsx_region)) -return -EFAULT ;if (!user_write_access_begin (old_ctx, ctx_size))return -EFAULT ; +unsafe_save_user_regs (regs, mctx,NULL , ctx_has_vsx_region, failed);unsafe_put_sigset_t (&old_ctx->uc_sigmask, ¤t->blocked, failed);unsafe_put_user (to_user_ptr (mctx), &old_ctx->uc_regs, failed);
user_write_access_end();
--
2.25.0
Re: [PATCH v2 25/25] powerpc/signal32: Transform save_user_regs() and save_tm_user_regs() in 'unsafe' version
Le 29/09/2020 à 04:55, Christopher M. Riedl a écrit :
Quoted 102 lines · Christophe Leroy
Quoted 101 lines
Change those two functions to be used within a user access block.
For that, change
save_general_regs()to andunsafe_save_general_regs(), then replace all user accesses byunsafe_versions.This series leads to a reduction from 2.55s to 1.73s of the system CPU time with the following microbench app on an mpc832x with KUAP (approx 32%)
Without KUAP, the difference is in the noise.
void sigusr1(int sig) { }
int
main(int argc, char **argv)
{
int i = 100000;
signal(SIGUSR1, sigusr1);
for (;i--;)
raise(SIGUSR1);
exit(0);
}An additional 0.10s reduction is achieved by removing
CONFIG_PPC_FPU, as the mpc832x has no FPU.A bit less spectacular on an 8xx as KUAP is less heavy, prior to the series (with KUAP) it ran in 8.10 ms. Once applies the removal of FPU regs handling, we get 7.05s. With the full series, we get 6.9s. If artificially re-activating FPU regs handling with the full series, we get 7.6s.
So for the 8xx, the removal of the FPU regs copy is what makes the difference, but the rework of
handle_signalalso have a benefit.Same as above, without KUAP the difference is in the noise.
Signed-off-by Christophe Leroy <[email protected]>---
arch/powerpc/kernel/signal_32.c| 224 ++++++++++++++++----------------1 file changed, 111 insertions(+), 113 deletions(-)arch/powerpc/kernel/signal_32.c +2
-2@@ -93,8 +93,8 @@ static inline int get_sigset_t(sigset_t *set,#define to_user_ptr (p) ptr_to_compat(p)#define from_user_ptr (p) compat_ptr(p) -static inline int save_general_regs (struct pt_regs *regs, -struct mcontext __user *frame) +static __always_inline int +save_general_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame) {elf_greg_t64 *gregs = (elf_greg_t64 *)regs;int val, i;
arch/powerpc/kernel/signal_32.c +0
-0@@ -108,10 +108,12 @@ static inline int save_general_regs(struct pt_regs *regs,else
val = gregs[i];- if (
__put_user(val, &frame->mc_gregs[i]))
- return-EFAULT;
+unsafe_put_user(val, &frame->mc_gregs[i], failed); }
return 0;arch/powerpc/kernel/signal_32.c +3
-0+ +failed: +return 1 ;}
static inline int restore_general_regs(struct
pt_regs*regs,arch/powerpc/kernel/signal_32.c +7
-3@@ -148,11 +150,15 @@ static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset)#define to_user_ptr (p) ((unsigned long)(p))#define from_user_ptr (p) ((void __user *)(p)) -static inline int save_general_regs (struct pt_regs *regs, -struct mcontext __user *frame) +static __always_inline int +save_general_regs_unsafe (struct pt_regs *regs,struct mcontext __user *frame) {WARN_ON (!FULL_REGS (regs)); -return __copy_to_user (&frame->mc_gregs, regs,GP_REGS_SIZE ); +unsafe_copy_to_user (&frame->mc_gregs, regs,GP_REGS_SIZE , failed); +return 0 ; + +failed: +return 1 ; }static inline int restore_general_regs(struct
pt_regs*regs,arch/powerpc/kernel/signal_32.c +0
-0@@ -170,6 +176,11 @@ static inline int restore_general_regs(struct pt_regs *regs, }#endif
Quoted 7 lines
arch/powerpc/kernel/signal_32.c static inline int restore_general_regs(struct pt_regs *regs, · line 180
Quoted 2 lines
arch/powerpc/kernel/signal_32.c +2
-0+#define unsafe_save_general_regs (regs, frame, label) do { \ + if (save_general_regs_unsafe(regs, frame)) \Minor nitpick (sorry); this naming seems a bit strange to me, in x86 it is "
__unsafe_" as a prefix instead of "_unsafe" as a suffix. That sounds a bit better to me, what do you think? Unless there is some convention I am not aware of here apart from "unsafe_" using a goto label for errors.
You are probably right, I have never been good at naming stuff.
Christophe
Michael Ellerman
AppliedQuoted 8 lines · Christophe Leroy
This series leads to a reduction from 2.55s to 1.73s of the system CPU time with the following microbench app on an mpc832x with KUAP (approx 32%)
This series replaces copies to users by
unsafe_put_user()and friends withuser_write_access_begin()dance in signal32.[...]
Applied to powerpc/next.
[01/25] powerpc/signal: Move inline functions in signal.h
https://git.kernel.org/powerpc/c/95593e930d7d067ca9bbee996c845248930a01f9 [02/25] powerpc/ptrace: Move declaration of ptrace_get_reg() and ptrace_set_reg() https://git.kernel.org/powerpc/c/67e364b3295f9dbf3b820d0edde86fb7c95efc98 [03/25] powerpc/ptrace: Consolidate reg index calculation https://git.kernel.org/powerpc/c/e009fa433542cd09d6279e361b767a1f44ffd29a [04/25] powerpc/ptrace: Create ptrace_get_fpr() and ptrace_put_fpr() https://git.kernel.org/powerpc/c/4d90eb97e292c7b14de8ba59fded35b340c73101 [05/25] powerpc/signal: Don't manage floating point regs when no FPU https://git.kernel.org/powerpc/c/b6254ced4da6cf28d49fbffe24ee4b3286dcb3f4 [06/25] powerpc/32s: Allow deselecting CONFIG_PPC_FPU on mpc832x https://git.kernel.org/powerpc/c/7d68c89169508064c460a1208f38ed0589d226fa [07/25] powerpc/signal: Remove BUG_ON() in handler_signal functions https://git.kernel.org/powerpc/c/3fcfb5d1bf731bdbd847c29df57a5372d8ea58d3 [08/25] powerpc/signal: Move access_ok() out of get_sigframe() https://git.kernel.org/powerpc/c/454b1abb588b3942655638a8bcf1ea4501260579 [09/25] powerpc/signal: Remove get_clean_sp() https://git.kernel.org/powerpc/c/0ecbc6ad18e324012234183e21805423f5e0cc79 [10/25] powerpc/signal: Call get_tm_stackpointer() from get_sigframe() https://git.kernel.org/powerpc/c/c180cb305c9bba094657259487d563c8fbfb648b [11/25] powerpc/signal: Refactor bad frame logging https://git.kernel.org/powerpc/c/7fe8f773ee248c726cec2addcdb94056049d6e34 [12/25] powerpc/signal32: Simplify logging in handle_rt_signal32() https://git.kernel.org/powerpc/c/debf122c777f361137a3114db7be8aecc65f6af2 [13/25] powerpc/signal32: Move handle_signal32() close to handle_rt_signal32() https://git.kernel.org/powerpc/c/3eea688be0ccba2221e047b7df6f9ae87361cdd6 [14/25] powerpc/signal32: Rename local pointers in handle_rt_signal32() https://git.kernel.org/powerpc/c/8e91cf8501f14d8b6727c71c98fd743e95e9b402 [15/25] powerpc/signal32: Misc changes to make handle_[rt_]_signal32() more similar https://git.kernel.org/powerpc/c/91b8ecd419cb46058e99b3a574184883c02b7729 [16/25] powerpc/signal32: Move signal trampoline setup to handle_[rt_]signal32 https://git.kernel.org/powerpc/c/8d33001dd650b88e915a1a13e2ca807350e374df [17/25] powerpc/signal32: Switch handle_signal32() to user_access_begin() logic https://git.kernel.org/powerpc/c/ad65f4909fd3736d84533784cd9ab76905536b34 [18/25] powerpc/signal32: Switch handle_rt_signal32() to user_access_begin() logic https://git.kernel.org/powerpc/c/9504db3e90b22dca19d8152ed5a82c68512dac0e [19/25] powerpc/signal32: Remove ifdefery in middle of if/else https://git.kernel.org/powerpc/c/f1cf4f93de2ff66313a091320d7683735816a0bc [20/25] signal: Add unsafe_put_compat_sigset() https://git.kernel.org/powerpc/c/14026b94ccfe626e512bc9fa01e0e72ee75c7a98 [21/25] powerpc/signal32: Add and use unsafe_put_sigset_t() https://git.kernel.org/powerpc/c/de781ebdf6b8a256742da4fd6b0e39bb22ed9fe3 [22/25] powerpc/signal32: Switch swap_context() to user_access_begin() logic https://git.kernel.org/powerpc/c/31147d7d6133ea17504b118114a191a8af85f3de [23/25] powerpc/signal: Create 'unsafe' versions of copy_[ck][fpr/vsx]_to_user() https://git.kernel.org/powerpc/c/b3484a1d4d1fb54ad7b615a13003d8bc11919c96 [24/25] powerpc/signal32: Isolate non-copy actions in save_user_regs() and save_tm_user_regs() https://git.kernel.org/powerpc/c/968c4fccd1bb8b440326dac5078ad87d17af4a47 [25/25] powerpc/signal32: Transform save_user_regs() and save_tm_user_regs() in 'unsafe' version https://git.kernel.org/powerpc/c/ef75e73182949a94bde169a774de1b62ae21fbbc
cheers