Skip to content

Commit 6f76a01

Browse files
chleroympe
authored andcommitted
powerpc/syscall: implement system call entry/exit logic in C for PPC32
That's port of PPC64 syscall entry/exit logic in C to PPC32. Performancewise on 8xx: Before : 304 cycles on null_syscall After : 348 cycles on null_syscall Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/a93b08e1275e9d1f0b1c39043d1b827586b2b401.1612796617.git.christophe.leroy@csgroup.eu
1 parent fbcee2e commit 6f76a01

File tree

3 files changed

+30
-229
lines changed

3 files changed

+30
-229
lines changed

arch/powerpc/kernel/entry_32.S

Lines changed: 30 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -329,117 +329,23 @@ stack_ovf:
329329
_ASM_NOKPROBE_SYMBOL(stack_ovf)
330330
#endif
331331

332-
#ifdef CONFIG_TRACE_IRQFLAGS
333-
trace_syscall_entry_irq_off:
334-
/*
335-
* Syscall shouldn't happen while interrupts are disabled,
336-
* so let's do a warning here.
337-
*/
338-
0: trap
339-
EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
340-
bl trace_hardirqs_on
341-
342-
/* Now enable for real */
343-
LOAD_REG_IMMEDIATE(r10, MSR_KERNEL | MSR_EE)
344-
mtmsr r10
345-
346-
REST_GPR(0, r1)
347-
REST_4GPRS(3, r1)
348-
REST_2GPRS(7, r1)
349-
b DoSyscall
350-
#endif /* CONFIG_TRACE_IRQFLAGS */
351-
352332
.globl transfer_to_syscall
353333
transfer_to_syscall:
354334
SAVE_NVGPRS(r1)
355335
#ifdef CONFIG_PPC_BOOK3S_32
356336
kuep_lock r11, r12
357337
#endif
358-
#ifdef CONFIG_TRACE_IRQFLAGS
359-
andi. r12,r9,MSR_EE
360-
beq- trace_syscall_entry_irq_off
361-
#endif /* CONFIG_TRACE_IRQFLAGS */
362338

363-
/*
364-
* Handle a system call.
365-
*/
366-
.stabs "arch/powerpc/kernel/",N_SO,0,0,0f
367-
.stabs "entry_32.S",N_SO,0,0,0f
368-
0:
369-
370-
_GLOBAL(DoSyscall)
371-
stw r3,ORIG_GPR3(r1)
372-
li r12,0
373-
stw r12,RESULT(r1)
374-
#ifdef CONFIG_TRACE_IRQFLAGS
375-
/* Make sure interrupts are enabled */
376-
mfmsr r11
377-
andi. r12,r11,MSR_EE
378-
/* We came in with interrupts disabled, we WARN and mark them enabled
379-
* for lockdep now */
380-
0: tweqi r12, 0
381-
EMIT_BUG_ENTRY 0b,__FILE__,__LINE__, BUGFLAG_WARNING
382-
#endif /* CONFIG_TRACE_IRQFLAGS */
383-
lwz r11,TI_FLAGS(r2)
384-
andi. r11,r11,_TIF_SYSCALL_DOTRACE
385-
bne- syscall_dotrace
386-
syscall_dotrace_cont:
387-
cmplwi 0,r0,NR_syscalls
388-
lis r10,sys_call_table@h
389-
ori r10,r10,sys_call_table@l
390-
slwi r0,r0,2
391-
bge- 66f
392-
393-
barrier_nospec_asm
394-
/*
395-
* Prevent the load of the handler below (based on the user-passed
396-
* system call number) being speculatively executed until the test
397-
* against NR_syscalls and branch to .66f above has
398-
* committed.
399-
*/
339+
/* Calling convention has r9 = orig r0, r10 = regs */
340+
addi r10,r1,STACK_FRAME_OVERHEAD
341+
mr r9,r0
342+
stw r10,THREAD+PT_REGS(r2)
343+
bl system_call_exception
400344

401-
lwzx r10,r10,r0 /* Fetch system call handler [ptr] */
402-
mtlr r10
403-
addi r9,r1,STACK_FRAME_OVERHEAD
404-
PPC440EP_ERR42
405-
blrl /* Call handler */
406-
.globl ret_from_syscall
407345
ret_from_syscall:
408-
#ifdef CONFIG_DEBUG_RSEQ
409-
/* Check whether the syscall is issued inside a restartable sequence */
410-
stw r3,GPR3(r1)
411-
addi r3,r1,STACK_FRAME_OVERHEAD
412-
bl rseq_syscall
413-
lwz r3,GPR3(r1)
414-
#endif
415-
mr r6,r3
416-
/* disable interrupts so current_thread_info()->flags can't change */
417-
LOAD_REG_IMMEDIATE(r10,MSR_KERNEL) /* doesn't include MSR_EE */
418-
/* Note: We don't bother telling lockdep about it */
419-
mtmsr r10
420-
lwz r9,TI_FLAGS(r2)
421-
li r8,-MAX_ERRNO
422-
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
423-
bne- syscall_exit_work
424-
cmplw 0,r3,r8
425-
blt+ syscall_exit_cont
426-
lwz r11,_CCR(r1) /* Load CR */
427-
neg r3,r3
428-
oris r11,r11,0x1000 /* Set SO bit in CR */
429-
stw r11,_CCR(r1)
430-
syscall_exit_cont:
431-
lwz r8,_MSR(r1)
432-
#ifdef CONFIG_TRACE_IRQFLAGS
433-
/* If we are going to return from the syscall with interrupts
434-
* off, we trace that here. It shouldn't normally happen.
435-
*/
436-
andi. r10,r8,MSR_EE
437-
bne+ 1f
438-
stw r3,GPR3(r1)
439-
bl trace_hardirqs_off
440-
lwz r3,GPR3(r1)
441-
1:
442-
#endif /* CONFIG_TRACE_IRQFLAGS */
346+
addi r4,r1,STACK_FRAME_OVERHEAD
347+
li r5,0
348+
bl syscall_exit_prepare
443349
#if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
444350
/* If the process has its own DBCR0 value, load it up. The internal
445351
debug mode bit tells us that dbcr0 should be loaded. */
@@ -453,44 +359,50 @@ syscall_exit_cont:
453359
cmplwi cr0,r5,0
454360
bne- 2f
455361
#endif /* CONFIG_PPC_47x */
456-
1:
457-
BEGIN_FTR_SECTION
458-
lwarx r7,0,r1
459-
END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
460-
stwcx. r0,0,r1 /* to clear the reservation */
461-
ACCOUNT_CPU_USER_EXIT(r2, r5, r7)
462362
#ifdef CONFIG_PPC_BOOK3S_32
463363
kuep_unlock r5, r7
464364
#endif
465365
kuap_check r2, r4
466366
lwz r4,_LINK(r1)
467367
lwz r5,_CCR(r1)
468368
mtlr r4
469-
mtcr r5
470369
lwz r7,_NIP(r1)
471-
lwz r2,GPR2(r1)
472-
lwz r1,GPR1(r1)
370+
lwz r8,_MSR(r1)
371+
cmpwi r3,0
372+
lwz r3,GPR3(r1)
473373
syscall_exit_finish:
474-
#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
475-
mtspr SPRN_NRI, r0
476-
#endif
477374
mtspr SPRN_SRR0,r7
478375
mtspr SPRN_SRR1,r8
376+
377+
bne 3f
378+
mtcr r5
379+
380+
1: lwz r2,GPR2(r1)
381+
lwz r1,GPR1(r1)
479382
rfi
480383
#ifdef CONFIG_40x
481384
b . /* Prevent prefetch past rfi */
482385
#endif
483-
_ASM_NOKPROBE_SYMBOL(syscall_exit_finish)
386+
387+
3: mtcr r5
388+
lwz r4,_CTR(r1)
389+
lwz r5,_XER(r1)
390+
REST_NVGPRS(r1)
391+
mtctr r4
392+
mtxer r5
393+
lwz r0,GPR0(r1)
394+
lwz r3,GPR3(r1)
395+
REST_8GPRS(4,r1)
396+
lwz r12,GPR12(r1)
397+
b 1b
398+
484399
#ifdef CONFIG_44x
485400
2: li r7,0
486401
iccci r0,r0
487402
stw r7,icache_44x_need_flush@l(r4)
488403
b 1b
489404
#endif /* CONFIG_44x */
490405

491-
66: li r3,-ENOSYS
492-
b ret_from_syscall
493-
494406
.globl ret_from_fork
495407
ret_from_fork:
496408
REST_NVGPRS(r1)
@@ -509,82 +421,6 @@ ret_from_kernel_thread:
509421
li r3,0
510422
b ret_from_syscall
511423

512-
/* Traced system call support */
513-
syscall_dotrace:
514-
SAVE_NVGPRS(r1)
515-
li r0,0xc00
516-
stw r0,_TRAP(r1)
517-
addi r3,r1,STACK_FRAME_OVERHEAD
518-
bl do_syscall_trace_enter
519-
/*
520-
* Restore argument registers possibly just changed.
521-
* We use the return value of do_syscall_trace_enter
522-
* for call number to look up in the table (r0).
523-
*/
524-
mr r0,r3
525-
lwz r3,GPR3(r1)
526-
lwz r4,GPR4(r1)
527-
lwz r5,GPR5(r1)
528-
lwz r6,GPR6(r1)
529-
lwz r7,GPR7(r1)
530-
lwz r8,GPR8(r1)
531-
REST_NVGPRS(r1)
532-
533-
cmplwi r0,NR_syscalls
534-
/* Return code is already in r3 thanks to do_syscall_trace_enter() */
535-
bge- ret_from_syscall
536-
b syscall_dotrace_cont
537-
538-
syscall_exit_work:
539-
andi. r0,r9,_TIF_RESTOREALL
540-
beq+ 0f
541-
REST_NVGPRS(r1)
542-
b 2f
543-
0: cmplw 0,r3,r8
544-
blt+ 1f
545-
andi. r0,r9,_TIF_NOERROR
546-
bne- 1f
547-
lwz r11,_CCR(r1) /* Load CR */
548-
neg r3,r3
549-
oris r11,r11,0x1000 /* Set SO bit in CR */
550-
stw r11,_CCR(r1)
551-
552-
1: stw r6,RESULT(r1) /* Save result */
553-
stw r3,GPR3(r1) /* Update return value */
554-
2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
555-
beq 4f
556-
557-
/* Clear per-syscall TIF flags if any are set. */
558-
559-
li r11,_TIF_PERSYSCALL_MASK
560-
addi r12,r2,TI_FLAGS
561-
3: lwarx r8,0,r12
562-
andc r8,r8,r11
563-
stwcx. r8,0,r12
564-
bne- 3b
565-
566-
4: /* Anything which requires enabling interrupts? */
567-
andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
568-
beq ret_from_except
569-
570-
/* Re-enable interrupts. There is no need to trace that with
571-
* lockdep as we are supposed to have IRQs on at this point
572-
*/
573-
ori r10,r10,MSR_EE
574-
mtmsr r10
575-
576-
/* Save NVGPRS if they're not saved already */
577-
lwz r4,_TRAP(r1)
578-
andi. r4,r4,1
579-
beq 5f
580-
SAVE_NVGPRS(r1)
581-
li r4,0xc00
582-
stw r4,_TRAP(r1)
583-
5:
584-
addi r3,r1,STACK_FRAME_OVERHEAD
585-
bl do_syscall_trace_leave
586-
b ret_from_except_full
587-
588424
/*
589425
* System call was called from kernel. We get here with SRR1 in r9.
590426
* Mark the exception as recoverable once we have retrieved SRR0,

arch/powerpc/kernel/head_32.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,12 @@
154154
SAVE_GPR(0, r11)
155155
SAVE_4GPRS(3, r11)
156156
SAVE_2GPRS(7, r11)
157-
addi r11,r1,STACK_FRAME_OVERHEAD
158157
addi r2,r12,-THREAD
159-
stw r11,PT_REGS(r12)
160158
#if defined(CONFIG_40x)
161159
/* Check to see if the dbcr0 register is set up to debug. Use the
162160
internal debug mode bit to do this. */
163161
lwz r12,THREAD_DBCR0(r12)
164162
andis. r12,r12,DBCR0_IDM@h
165-
#endif
166-
ACCOUNT_CPU_USER_ENTRY(r2, r11, r12)
167-
#if defined(CONFIG_40x)
168163
beq+ 3f
169164
/* From user and task is ptraced - load up global dbcr0 */
170165
li r12,-1 /* clear all pending debug events */
@@ -176,21 +171,8 @@
176171
lwz r12,4(r11)
177172
addi r12,r12,-1
178173
stw r12,4(r11)
179-
#endif
180-
181174
3:
182-
#ifdef CONFIG_TRACE_IRQFLAGS
183-
/*
184-
* If MSR is changing we need to keep interrupts disabled at this point
185-
* otherwise we might risk taking an interrupt before we tell lockdep
186-
* they are enabled.
187-
*/
188-
LOAD_REG_IMMEDIATE(r10, MSR_KERNEL)
189-
rlwimi r10, r9, 0, MSR_EE
190-
#else
191-
LOAD_REG_IMMEDIATE(r10, MSR_KERNEL | MSR_EE)
192175
#endif
193-
mtmsr r10
194176
b transfer_to_syscall /* jump to handler */
195177
99: b ret_from_kernel_syscall
196178
.endm

arch/powerpc/kernel/head_booke.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
131131
SAVE_4GPRS(3, r11)
132132
SAVE_2GPRS(7, r11)
133133

134-
addi r11,r1,STACK_FRAME_OVERHEAD
135134
addi r2,r10,-THREAD
136-
stw r11,PT_REGS(r10)
137135
/* Check to see if the dbcr0 register is set up to debug. Use the
138136
internal debug mode bit to do this. */
139137
lwz r12,THREAD_DBCR0(r10)
140138
andis. r12,r12,DBCR0_IDM@h
141-
ACCOUNT_CPU_USER_ENTRY(r2, r11, r12)
142139
beq+ 3f
143140
/* From user and task is ptraced - load up global dbcr0 */
144141
li r12,-1 /* clear all pending debug events */
@@ -157,20 +154,6 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_EMB_HV)
157154
stw r12,4(r11)
158155

159156
3:
160-
#ifdef CONFIG_TRACE_IRQFLAGS
161-
/*
162-
* If MSR is changing we need to keep interrupts disabled at this point
163-
* otherwise we might risk taking an interrupt before we tell lockdep
164-
* they are enabled.
165-
*/
166-
lis r10, MSR_KERNEL@h
167-
ori r10, r10, MSR_KERNEL@l
168-
rlwimi r10, r9, 0, MSR_EE
169-
#else
170-
lis r10, (MSR_KERNEL | MSR_EE)@h
171-
ori r10, r10, (MSR_KERNEL | MSR_EE)@l
172-
#endif
173-
mtmsr r10
174157
b transfer_to_syscall /* jump to handler */
175158
99: b ret_from_kernel_syscall
176159
.endm

0 commit comments

Comments
 (0)