powerpc/32: Implement C syscall entry/exit (complement)
Subsystems (2)
v6 cover powerpc/32: Implement C syscall entry/exit (complement)
This series implements C syscall entry/exit for PPC32. It reuses the work already done for PPC64.
This series is based on today's next-test (f538b53fd47a) where main patchs from v5 are merged in.
The first patch is important for performance.
v6:
- Forced scv param to 0 on syscall_exit_prepare(), and added is_not_scv bool.
- Reworked the last patch to avoid code duplication.
Christophe Leroy (2):
powerpc/syscall: Do not check unsupported scv vector on PPC32 powerpc/32: Handle bookE debugging in C in syscall entry/exit
arch/powerpc/include/asm/interrupt.h | 12 +++++++ arch/powerpc/include/asm/ptrace.h | 5 +++ arch/powerpc/include/asm/reg_booke.h | 3 ++ arch/powerpc/kernel/entry_32.S | 7 ---- arch/powerpc/kernel/head_32.h | 15 --------- arch/powerpc/kernel/head_booke.h | 19 ----------- arch/powerpc/kernel/interrupt.c | 50 ++++++++++++++++++---------- 7 files changed, 52 insertions(+), 59 deletions(-)
Signature · 1 line
2.25.0
PATCH v6 1/2 powerpc/syscall: Do not check unsupported scv vector on PPC32
Only book3s/64 has scv. No need to check the 0x7ff0 trap on 32 or 64e. For that, add a helper trap_is_unsupported_scv() similar to trap_is_scv().
And ignore the scv parameter in syscall_exit_prepare (Save 14 cycles 346 => 332 cycles)
---
v5: Added a helper trap_is_unsupported_scv()
v6: Still set r5 when calling syscall_exit_prepare() and introduce a local bool 'is_not_scv'
--- arch/powerpc/include/asm/ptrace.h | 5 +++++ arch/powerpc/kernel/interrupt.c | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-)
arch/powerpc/include/asm/ptrace.h +5 -0
@@ -232,6 +232,11 @@ static inline bool trap_is_scv(struct pt_regs *regs)return (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) &&TRAP (regs) ==0x3000 ); } +static inline bool trap_is_unsupported_scv (struct pt_regs *regs) +{ +return IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) &&TRAP (regs) ==0x7ff0 ; +} +static inline bool trap_is_syscall (struct pt_regs *regs) {return (trap_is_scv (regs) ||TRAP (regs) ==0xc00 );
arch/powerpc/kernel/interrupt.c +5 -4
@@ -88,7 +88,7 @@ notrace long system_call_exception(long r3, long r4, long r5,local_irq_enable ();if (unlikely (current_thread_info ()->flags & _TIF_SYSCALL_DOTRACE)) { -if (unlikely (regs->trap ==0x7ff0 )) { +if (unlikely (trap_is_unsupported_scv (regs))) {/* Unsupported scv vector */ _exception (SIGILL , regs,ILL_ILLOPC , regs->nip);return regs->gpr[3 ];
@@ -111,7 +111,7 @@ notrace long system_call_exception(long r3, long r4, long r5, r8 = regs->gpr[8 ]; }else if (unlikely (r0 >= NR_syscalls)) { -if (unlikely (regs->trap ==0x7ff0 )) { +if (unlikely (trap_is_unsupported_scv (regs))) {/* Unsupported scv vector */ _exception (SIGILL , regs,ILL_ILLOPC , regs->nip);return regs->gpr[3 ];
@@ -220,6 +220,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,unsigned long *ti_flagsp = ¤t_thread_info ()->flags;unsigned long ti_flags;unsigned long ret =0 ; +bool is_not_scv = !IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) || !scv;CT_WARN_ON (ct_state () ==CONTEXT_USER );
@@ -234,7 +235,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, ti_flags = *ti_flagsp; -if (unlikely (r3 >= (unsigned long )-MAX_ERRNO ) && !scv) { +if (unlikely (r3 >= (unsigned long )-MAX_ERRNO ) && is_not_scv) {if (likely (!(ti_flags & (_TIF_NOERROR | _TIF_RESTOREALL)))) { r3 = -r3; regs->ccr |=0x10000000 ;/* Set SO bit in CR */
@@ -305,7 +306,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,user_enter_irqoff ();/* scv need not set RI=0 because SRRs are not used */ -if (unlikely (!__prep_irq_for_enabled_exit (!scv))) { +if (unlikely (!__prep_irq_for_enabled_exit (is_not_scv))) {user_exit_irqoff ();local_irq_enable ();local_irq_disable ();
Signature · 1 line
2.25.0
PATCH v6 2/2 powerpc/32: Handle bookE debugging in C in syscall entry/exit
In reply to Christophe LeroyThe handling of SPRN_DBCR0 and other registers can easily be done in C instead of ASM.
For that, create booke_load_dbcr0() and booke_restore_dbcr0().
---
v5: New
v6: Refactor into helpers
--- arch/powerpc/include/asm/interrupt.h | 12 ++++++++ arch/powerpc/include/asm/reg_booke.h | 3 ++ arch/powerpc/kernel/entry_32.S | 7 ----- arch/powerpc/kernel/head_32.h | 15 ---------- arch/powerpc/kernel/head_booke.h | 19 ------------- arch/powerpc/kernel/interrupt.c | 41 ++++++++++++++++++---------- 6 files changed, 42 insertions(+), 55 deletions(-)
arch/powerpc/include/asm/interrupt.h +12 -0
@@ -14,6 +14,18 @@ struct interrupt_state {#endif }; +static inline void booke_restore_dbcr0 (void ) +{ +#ifdef CONFIG_PPC_ADV_DEBUG_REGS +unsigned long dbcr0 = current->thread.debug.dbcr0; + +if (IS_ENABLED (CONFIG_PPC32 ) &&unlikely (dbcr0 &DBCR0_IDM )) { +mtspr (SPRN_DBSR ,-1 ); +mtspr (SPRN_DBCR0 , global_dbcr0[smp_processor_id ()]); + } +#endif +} +static inline void interrupt_enter_prepare (struct pt_regs *regs,struct interrupt_state *state) {/*
arch/powerpc/include/asm/reg_booke.h +3 -0
@@ -691,6 +691,9 @@#define mttmr (rn, v) asm volatile(MTTMR(rn, %0) : \ : "r" ((unsigned long)(v)) \ : "memory") + +extern unsigned long global_dbcr0[]; +#endif /* !__ASSEMBLY__ */ #endif /* __ASM_POWERPC_REG_BOOKE_H__ */
arch/powerpc/kernel/entry_32.S +0 -7
@@ -343,13 +343,6 @@ ret_from_syscall: addi r4,r1,STACK_FRAME_OVERHEAD li r5,0 bl syscall_exit_prepare -#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE) - /* If the process has its own DBCR0 value, load it up. The internal - debug mode bit tells us that dbcr0 should be loaded. */ - lwz r0,THREAD+THREAD_DBCR0(r2) - andis. r10,r0,DBCR0_IDM@h - bnel- load_dbcr0 -#endif #ifdef CONFIG_PPC_47x lis r4,icache_44x_need_flush@ha lwz r5,icache_44x_need_flush@l(r4)
arch/powerpc/kernel/head_32.h +0 -15
@@ -153,21 +153,6 @@ SAVE_4GPRS(3, r11) SAVE_2GPRS(7, r11) addi r2,r12,-THREAD -#if defined(CONFIG_40x) -/* Check to see if the dbcr0 register is set up to debug. Use the -internal debug mode bit to do this. */ - lwz r12,THREAD_DBCR0(r12) - andis. r12,r12,DBCR0_IDM@h - beq+ 3f -/* From user and task is ptraced - load up global dbcr0 */ - li r12,-1 /* clear all pending debug events */ - mtspr SPRN_DBSR,r12 - lis r11,global_dbcr0@ha - addi r11,r11,global_dbcr0@l - lwz r12,0(r11) - mtspr SPRN_DBCR0,r12 -3: -#endifb transfer_to_syscall/* jump to handler */ .endm
arch/powerpc/kernel/head_booke.h +0 -19
@@ -130,25 +130,6 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV) SAVE_2GPRS(7, r11) addi r2,r10,-THREAD -/* Check to see if the dbcr0 register is set up to debug. Use the - internal debug mode bit to do this. */ - lwz r12,THREAD_DBCR0(r10) - andis. r12,r12,DBCR0_IDM@h - beq+ 3f -/* From user and task is ptraced - load up global dbcr0 */ - li r12,-1 /* clear all pending debug events */ - mtspr SPRN_DBSR,r12 - lis r11,global_dbcr0@ha - addi r11,r11,global_dbcr0@l -#ifdef CONFIG_SMP - lwz r10, TASK_CPU(r2) - slwi r10, r10, 2 - add r11, r11, r10 -#endif - lwz r12,0(r11) - mtspr SPRN_DBCR0,r12 - -3:b transfer_to_syscall/* jump to handler */ .endm
arch/powerpc/kernel/interrupt.c +27 -14
71 lines not on this page · raw message
Signature · 1 line
2.25.0
[PATCH v6 3/2] powerpc/syscall: Avoid storing 'current' in another pointer
In reply to Christophe LeroyBy saving the pointer pointing to thread_info.flags, gcc copies r2 in a non-volatile register.
We know 'current' doesn't change, so avoid that intermediaite pointer.
Reduces null_syscall benchmark by 2 cycles (322 => 320 cycles)
On PPC64, gcc seems to know that 'current' is not changing, and it keeps it in a non volatile register to avoid multiple read of 'current' in paca.
---
v5: Also in interrupt exit prepare
v6: Removed change related to booke current->thread.debug
v7: Rebased on top of "powerpc/32: Handle bookE debugging in C in syscall entry/exit"
--- arch/powerpc/kernel/interrupt.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
arch/powerpc/kernel/interrupt.c +9 -12
@@ -241,7 +241,6 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, struct pt_regs *regs, long scv) { -unsigned long *ti_flagsp = ¤t_thread_info ()->flags;unsigned long ti_flags;unsigned long ret =0 ;bool is_not_scv = !IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) || !scv;
@@ -257,7 +256,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,/* Check whether the syscall is issued inside a restartable sequence */ rseq_syscall (regs); - ti_flags = *ti_flagsp; + ti_flags =current_thread_info ()->flags;if (unlikely (r3 >= (unsigned long )-MAX_ERRNO ) && is_not_scv) {if (likely (!(ti_flags & (_TIF_NOERROR | _TIF_RESTOREALL)))) {
@@ -271,7 +270,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3, ret = _TIF_RESTOREALL; else regs->gpr[3] = r3; -clear_bits (_TIF_PERSYSCALL_MASK, ti_flagsp); +clear_bits (_TIF_PERSYSCALL_MASK, ¤t_thread_info ()->flags); }else { regs->gpr[3 ] = r3; }
@@ -284,7 +283,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,local_irq_disable (); again: - ti_flags =READ_ONCE (*ti_flagsp); + ti_flags =READ_ONCE (current_thread_info ()->flags);while (unlikely (ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {local_irq_enable ();if (ti_flags & _TIF_NEED_RESCHED) {
@@ -300,7 +299,7 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,do_notify_resume (regs, ti_flags); }local_irq_disable (); - ti_flags =READ_ONCE (*ti_flagsp); + ti_flags =READ_ONCE (current_thread_info ()->flags); }if (IS_ENABLED (CONFIG_PPC_BOOK3S ) &&IS_ENABLED (CONFIG_PPC_FPU )) {
@@ -357,7 +356,6 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,#ifndef CONFIG_PPC_BOOK3E_64 /* BOOK3E not yet using this */ notrace unsigned long interrupt_exit_user_prepare (struct pt_regs *regs,unsigned long msr) { -unsigned long *ti_flagsp = ¤t_thread_info ()->flags;unsigned long ti_flags;unsigned long flags;unsigned long ret =0 ;
@@ -380,7 +378,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsignedlocal_irq_save (flags); again: - ti_flags =READ_ONCE (*ti_flagsp); + ti_flags =READ_ONCE (current_thread_info ()->flags);while (unlikely (ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {local_irq_enable ();/* returning to user: may enable */ if (ti_flags & _TIF_NEED_RESCHED) {
@@ -391,7 +389,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs, unsigneddo_notify_resume (regs, ti_flags); }local_irq_disable (); - ti_flags =READ_ONCE (*ti_flagsp); + ti_flags =READ_ONCE (current_thread_info ()->flags); }if (IS_ENABLED (CONFIG_PPC_BOOK3S ) &&IS_ENABLED (CONFIG_PPC_FPU )) {
@@ -443,7 +441,6 @@ void preempt_schedule_irq(void);notrace unsigned long interrupt_exit_kernel_prepare (struct pt_regs *regs,unsigned long msr) { -unsigned long *ti_flagsp = ¤t_thread_info ()->flags;unsigned long flags;unsigned long ret =0 ;#ifdef CONFIG_PPC64
@@ -466,8 +463,8 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign amr =kuap_get_and_check_amr ();#endif -if (unlikely (*ti_flagsp & _TIF_EMULATE_STACK_STORE)) { -clear_bits (_TIF_EMULATE_STACK_STORE, ti_flagsp); +if (unlikely (current_thread_info ()->flags & _TIF_EMULATE_STACK_STORE)) { +clear_bits (_TIF_EMULATE_STACK_STORE, ¤t_thread_info ()->flags); ret =1 ; }
@@ -479,7 +476,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs, unsign again:if (IS_ENABLED (CONFIG_PREEMPT )) {/* Return to preemptible kernel context */ -if (unlikely (*ti_flagsp & _TIF_NEED_RESCHED)) { +if (unlikely (current_thread_info ()->flags & _TIF_NEED_RESCHED)) {if (preempt_count () ==0 )preempt_schedule_irq (); }
Signature · 1 line
2.25.0
Michael Ellerman
AppliedQuoted 8 lines · Christophe Leroy
This series implements C syscall entry/exit for PPC32. It reuses the work already done for PPC64.
This series is based on today's next-test (
f538b53fd47a) where main patchs from v5 are merged in.The first patch is important for performance.
[...]
Applied to powerpc/next.
[1/3] powerpc/syscall: Do not check unsupported scv vector on PPC32
https://git.kernel.org/powerpc/c/b966f2279048ee9f30d83ef8568b99fa40917c54 [2/3] powerpc/32: Handle bookE debugging in C in syscall entry/exit https://git.kernel.org/powerpc/c/d524dda719f06967db4d3ba519edf9267f84c155 [3/3] powerpc/syscall: Avoid storing 'current' in another pointer https://git.kernel.org/powerpc/c/5b90b9661a3396e00f6e8bcbb617a0787fb683d0
cheers