Skip to content

Commit f8971c6

Browse files
rohanmclurempe
authored andcommitted
powerpc: Change system_call_exception calling convention
Change system_call_exception arguments to pass a pointer to a stack frame container caller state, as well as the original r0, which determines the number of the syscall. This has been observed to yield improved performance to passing them by registers, circumventing the need to allocate a stack frame. Signed-off-by: Rohan McLure <rmclure@linux.ibm.com> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> [mpe: Retain clearing of high bits of args for compat tasks] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220921065605.1051927-21-rmclure@linux.ibm.com
1 parent 8640de0 commit f8971c6

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

arch/powerpc/include/asm/interrupt.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,7 @@ static inline void interrupt_cond_local_irq_enable(struct pt_regs *regs)
665665
local_irq_enable();
666666
}
667667

668-
long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8,
669-
unsigned long r0, struct pt_regs *regs);
668+
long system_call_exception(struct pt_regs *regs, unsigned long r0);
670669
notrace unsigned long syscall_exit_prepare(unsigned long r3, struct pt_regs *regs, long scv);
671670
notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs);
672671
notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs);

arch/powerpc/kernel/entry_32.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ transfer_to_syscall:
122122
SAVE_NVGPRS(r1)
123123
kuep_lock
124124

125-
/* Calling convention has r9 = orig r0, r10 = regs */
126-
addi r10,r1,STACK_FRAME_OVERHEAD
127-
mr r9,r0
125+
/* Calling convention has r3 = regs, r4 = orig r0 */
126+
addi r3,r1,STACK_FRAME_OVERHEAD
127+
mr r4,r0
128128
bl system_call_exception
129129

130130
ret_from_syscall:

arch/powerpc/kernel/interrupt_64.S

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _ASM_NOKPROBE_SYMBOL(system_call_vectored_\name)
6060
ld r2,PACATOC(r13)
6161
mfcr r12
6262
li r11,0
63-
/* Can we avoid saving r3-r8 in common case? */
63+
/* Save syscall parameters in r3-r8 */
6464
SAVE_GPRS(3, 8, r1)
6565
/* Zero r9-r12, this should only be required when restoring all GPRs */
6666
std r11,GPR9(r1)
@@ -77,9 +77,11 @@ _ASM_NOKPROBE_SYMBOL(system_call_vectored_\name)
7777
std r11,_TRAP(r1)
7878
std r12,_CCR(r1)
7979
std r3,ORIG_GPR3(r1)
80-
addi r10,r1,STACK_FRAME_OVERHEAD
80+
/* Calling convention has r3 = regs, r4 = orig r0 */
81+
addi r3,r1,STACK_FRAME_OVERHEAD
82+
mr r4,r0
8183
ld r11,exception_marker@toc(r2)
82-
std r11,-16(r10) /* "regshere" marker */
84+
std r11,-16(r3) /* "regshere" marker */
8385

8486
BEGIN_FTR_SECTION
8587
HMT_MEDIUM
@@ -94,8 +96,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
9496
* but this is the best we can do.
9597
*/
9698

97-
/* Calling convention has r9 = orig r0, r10 = regs */
98-
mr r9,r0
9999
bl system_call_exception
100100

101101
.Lsyscall_vectored_\name\()_exit:
@@ -227,7 +227,7 @@ END_BTB_FLUSH_SECTION
227227
ld r2,PACATOC(r13)
228228
mfcr r12
229229
li r11,0
230-
/* Can we avoid saving r3-r8 in common case? */
230+
/* Save syscall parameters in r3-r8 */
231231
SAVE_GPRS(3, 8, r1)
232232
/* Zero r9-r12, this should only be required when restoring all GPRs */
233233
std r11,GPR9(r1)
@@ -250,9 +250,11 @@ END_BTB_FLUSH_SECTION
250250
std r11,_TRAP(r1)
251251
std r12,_CCR(r1)
252252
std r3,ORIG_GPR3(r1)
253-
addi r10,r1,STACK_FRAME_OVERHEAD
253+
/* Calling convention has r3 = regs, r4 = orig r0 */
254+
addi r3,r1,STACK_FRAME_OVERHEAD
255+
mr r4,r0
254256
ld r11,exception_marker@toc(r2)
255-
std r11,-16(r10) /* "regshere" marker */
257+
std r11,-16(r3) /* "regshere" marker */
256258

257259
#ifdef CONFIG_PPC_BOOK3S
258260
li r11,1
@@ -273,8 +275,6 @@ END_BTB_FLUSH_SECTION
273275
wrteei 1
274276
#endif
275277

276-
/* Calling convention has r9 = orig r0, r10 = regs */
277-
mr r9,r0
278278
bl system_call_exception
279279

280280
.Lsyscall_exit:

arch/powerpc/kernel/syscall.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313

1414

1515
/* Has to run notrace because it is entered not completely "reconciled" */
16-
notrace long system_call_exception(long r3, long r4, long r5,
17-
long r6, long r7, long r8,
18-
unsigned long r0, struct pt_regs *regs)
16+
notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
1917
{
18+
unsigned long r3, r4, r5, r6, r7, r8;
2019
long ret;
2120
syscall_fn f;
2221

@@ -136,12 +135,6 @@ notrace long system_call_exception(long r3, long r4, long r5,
136135
r0 = do_syscall_trace_enter(regs);
137136
if (unlikely(r0 >= NR_syscalls))
138137
return regs->gpr[3];
139-
r3 = regs->gpr[3];
140-
r4 = regs->gpr[4];
141-
r5 = regs->gpr[5];
142-
r6 = regs->gpr[6];
143-
r7 = regs->gpr[7];
144-
r8 = regs->gpr[8];
145138

146139
} else if (unlikely(r0 >= NR_syscalls)) {
147140
if (unlikely(trap_is_unsupported_scv(regs))) {
@@ -152,6 +145,13 @@ notrace long system_call_exception(long r3, long r4, long r5,
152145
return -ENOSYS;
153146
}
154147

148+
r3 = regs->gpr[3];
149+
r4 = regs->gpr[4];
150+
r5 = regs->gpr[5];
151+
r6 = regs->gpr[6];
152+
r7 = regs->gpr[7];
153+
r8 = regs->gpr[8];
154+
155155
/* May be faster to do array_index_nospec? */
156156
barrier_nospec();
157157

0 commit comments

Comments
 (0)