Skip to content

Commit b35f549

Browse files
committed
syscalls: Remove start and number from syscall_get_arguments() args
At Linux Plumbers, Andy Lutomirski approached me and pointed out that the function call syscall_get_arguments() implemented in x86 was horribly written and not optimized for the standard case of passing in 0 and 6 for the starting index and the number of system calls to get. When looking at all the users of this function, I discovered that all instances pass in only 0 and 6 for these arguments. Instead of having this function handle different cases that are never used, simply rewrite it to return the first 6 arguments of a system call. This should help out the performance of tracing system calls by ptrace, ftrace and perf. Link: http://lkml.kernel.org/r/20161107213233.754809394@goodmis.org Cc: Oleg Nesterov <oleg@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Dominik Brodowski <linux@dominikbrodowski.net> Cc: Dave Martin <dave.martin@arm.com> Cc: "Dmitry V. Levin" <ldv@altlinux.org> Cc: x86@kernel.org Cc: linux-snps-arc@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-c6x-dev@linux-c6x.org Cc: uclinux-h8-devel@lists.sourceforge.jp Cc: linux-hexagon@vger.kernel.org Cc: linux-ia64@vger.kernel.org Cc: linux-mips@vger.kernel.org Cc: nios2-dev@lists.rocketboards.org Cc: openrisc@lists.librecores.org Cc: linux-parisc@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-riscv@lists.infradead.org Cc: linux-s390@vger.kernel.org Cc: linux-sh@vger.kernel.org Cc: sparclinux@vger.kernel.org Cc: linux-um@lists.infradead.org Cc: linux-xtensa@linux-xtensa.org Cc: linux-arch@vger.kernel.org Acked-by: Paul Burton <paul.burton@mips.com> # MIPS parts Acked-by: Max Filippov <jcmvbkbc@gmail.com> # For xtensa changes Acked-by: Will Deacon <will.deacon@arm.com> # For the arm64 bits Reviewed-by: Thomas Gleixner <tglx@linutronix.de> # for x86 Reviewed-by: Dmitry V. Levin <ldv@altlinux.org> Reported-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent ed3bb00 commit b35f549

29 files changed

Lines changed: 113 additions & 378 deletions

File tree

‎arch/arc/include/asm/syscall.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
5555
*/
5656
static inline void
5757
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
58-
unsigned int i, unsigned int n, unsigned long *args)
58+
unsigned long *args)
5959
{
6060
unsigned long *inside_ptregs = &(regs->r0);
61-
inside_ptregs -= i;
62-
63-
BUG_ON((i + n) > 6);
61+
unsigned int n = 6;
62+
unsigned int i = 0;
6463

6564
while (n--) {
6665
args[i++] = (*inside_ptregs);

‎arch/arm/include/asm/syscall.h‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,12 @@ static inline void syscall_set_return_value(struct task_struct *task,
5555

5656
static inline void syscall_get_arguments(struct task_struct *task,
5757
struct pt_regs *regs,
58-
unsigned int i, unsigned int n,
5958
unsigned long *args)
6059
{
61-
if (n == 0)
62-
return;
63-
64-
if (i + n > SYSCALL_MAX_ARGS) {
65-
unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
66-
unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
67-
pr_warn("%s called with max args %d, handling only %d\n",
68-
__func__, i + n, SYSCALL_MAX_ARGS);
69-
memset(args_bad, 0, n_bad * sizeof(args[0]));
70-
n = SYSCALL_MAX_ARGS - i;
71-
}
72-
73-
if (i == 0) {
74-
args[0] = regs->ARM_ORIG_r0;
75-
args++;
76-
i++;
77-
n--;
78-
}
60+
args[0] = regs->ARM_ORIG_r0;
61+
args++;
7962

80-
memcpy(args, &regs->ARM_r0 + i, n * sizeof(args[0]));
63+
memcpy(args, &regs->ARM_r0 + 1, 5 * sizeof(args[0]));
8164
}
8265

8366
static inline void syscall_set_arguments(struct task_struct *task,

‎arch/arm64/include/asm/syscall.h‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,12 @@ static inline void syscall_set_return_value(struct task_struct *task,
6565

6666
static inline void syscall_get_arguments(struct task_struct *task,
6767
struct pt_regs *regs,
68-
unsigned int i, unsigned int n,
6968
unsigned long *args)
7069
{
71-
if (n == 0)
72-
return;
73-
74-
if (i + n > SYSCALL_MAX_ARGS) {
75-
unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
76-
unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
77-
pr_warning("%s called with max args %d, handling only %d\n",
78-
__func__, i + n, SYSCALL_MAX_ARGS);
79-
memset(args_bad, 0, n_bad * sizeof(args[0]));
80-
}
81-
82-
if (i == 0) {
83-
args[0] = regs->orig_x0;
84-
args++;
85-
i++;
86-
n--;
87-
}
70+
args[0] = regs->orig_x0;
71+
args++;
8872

89-
memcpy(args, &regs->regs[i], n * sizeof(args[0]));
73+
memcpy(args, &regs->regs[1], 5 * sizeof(args[0]));
9074
}
9175

9276
static inline void syscall_set_arguments(struct task_struct *task,

‎arch/c6x/include/asm/syscall.h‎

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,40 +46,15 @@ static inline void syscall_set_return_value(struct task_struct *task,
4646
}
4747

4848
static inline void syscall_get_arguments(struct task_struct *task,
49-
struct pt_regs *regs, unsigned int i,
50-
unsigned int n, unsigned long *args)
49+
struct pt_regs *regs,
50+
unsigned long *args)
5151
{
52-
switch (i) {
53-
case 0:
54-
if (!n--)
55-
break;
56-
*args++ = regs->a4;
57-
case 1:
58-
if (!n--)
59-
break;
60-
*args++ = regs->b4;
61-
case 2:
62-
if (!n--)
63-
break;
64-
*args++ = regs->a6;
65-
case 3:
66-
if (!n--)
67-
break;
68-
*args++ = regs->b6;
69-
case 4:
70-
if (!n--)
71-
break;
72-
*args++ = regs->a8;
73-
case 5:
74-
if (!n--)
75-
break;
76-
*args++ = regs->b8;
77-
case 6:
78-
if (!n--)
79-
break;
80-
default:
81-
BUG();
82-
}
52+
*args++ = regs->a4;
53+
*args++ = regs->b4;
54+
*args++ = regs->a6;
55+
*args++ = regs->b6;
56+
*args++ = regs->a8;
57+
*args = regs->b8;
8358
}
8459

8560
static inline void syscall_set_arguments(struct task_struct *task,

‎arch/csky/include/asm/syscall.h‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,11 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
4343

4444
static inline void
4545
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
46-
unsigned int i, unsigned int n, unsigned long *args)
46+
unsigned long *args)
4747
{
48-
BUG_ON(i + n > 6);
49-
if (i == 0) {
50-
args[0] = regs->orig_a0;
51-
args++;
52-
n--;
53-
} else {
54-
i--;
55-
}
56-
memcpy(args, &regs->a1 + i, n * sizeof(args[0]));
48+
args[0] = regs->orig_a0;
49+
args++;
50+
memcpy(args, &regs->a1, 5 * sizeof(args[0]));
5751
}
5852

5953
static inline void

‎arch/h8300/include/asm/syscall.h‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,14 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
1717

1818
static inline void
1919
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
20-
unsigned int i, unsigned int n, unsigned long *args)
20+
unsigned long *args)
2121
{
22-
BUG_ON(i + n > 6);
23-
24-
while (n > 0) {
25-
switch (i) {
26-
case 0:
27-
*args++ = regs->er1;
28-
break;
29-
case 1:
30-
*args++ = regs->er2;
31-
break;
32-
case 2:
33-
*args++ = regs->er3;
34-
break;
35-
case 3:
36-
*args++ = regs->er4;
37-
break;
38-
case 4:
39-
*args++ = regs->er5;
40-
break;
41-
case 5:
42-
*args++ = regs->er6;
43-
break;
44-
}
45-
i++;
46-
n--;
47-
}
22+
*args++ = regs->er1;
23+
*args++ = regs->er2;
24+
*args++ = regs->er3;
25+
*args++ = regs->er4;
26+
*args++ = regs->er5;
27+
*args = regs->er6;
4828
}
4929

5030

‎arch/hexagon/include/asm/syscall.h‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ static inline long syscall_get_nr(struct task_struct *task,
3737

3838
static inline void syscall_get_arguments(struct task_struct *task,
3939
struct pt_regs *regs,
40-
unsigned int i, unsigned int n,
4140
unsigned long *args)
4241
{
43-
BUG_ON(i + n > 6);
44-
memcpy(args, &(&regs->r00)[i], n * sizeof(args[0]));
42+
memcpy(args, &(&regs->r00)[0], 6 * sizeof(args[0]));
4543
}
4644
#endif

‎arch/ia64/include/asm/syscall.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,9 @@ extern void ia64_syscall_get_set_arguments(struct task_struct *task,
6363
unsigned long *args, int rw);
6464
static inline void syscall_get_arguments(struct task_struct *task,
6565
struct pt_regs *regs,
66-
unsigned int i, unsigned int n,
6766
unsigned long *args)
6867
{
69-
BUG_ON(i + n > 6);
70-
71-
ia64_syscall_get_set_arguments(task, regs, i, n, args, 0);
68+
ia64_syscall_get_set_arguments(task, regs, 0, 6, args, 0);
7269
}
7370

7471
static inline void syscall_set_arguments(struct task_struct *task,

‎arch/microblaze/include/asm/syscall.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ static inline void microblaze_set_syscall_arg(struct pt_regs *regs,
8282

8383
static inline void syscall_get_arguments(struct task_struct *task,
8484
struct pt_regs *regs,
85-
unsigned int i, unsigned int n,
8685
unsigned long *args)
8786
{
87+
unsigned int i = 0;
88+
unsigned int n = 6;
89+
8890
while (n--)
8991
*args++ = microblaze_get_syscall_arg(regs, i++);
9092
}

‎arch/mips/include/asm/syscall.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ static inline void syscall_set_return_value(struct task_struct *task,
116116

117117
static inline void syscall_get_arguments(struct task_struct *task,
118118
struct pt_regs *regs,
119-
unsigned int i, unsigned int n,
120119
unsigned long *args)
121120
{
121+
unsigned int i = 0;
122+
unsigned int n = 6;
122123
int ret;
123124

124125
/* O32 ABI syscall() */

0 commit comments

Comments
 (0)