Commit b35f549d authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Steven Rostedt (VMware)
Browse files

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: default avatarDmitry V. Levin <ldv@altlinux.org>
Reported-by: default avatarAndy Lutomirski <luto@amacapital.net>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent ed3bb007
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -55,12 +55,11 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
 */
static inline void
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
		      unsigned int i, unsigned int n, unsigned long *args)
		      unsigned long *args)
{
	unsigned long *inside_ptregs = &(regs->r0);
	inside_ptregs -= i;

	BUG_ON((i + n) > 6);
	unsigned int n = 6;
	unsigned int i = 0;

	while (n--) {
		args[i++] = (*inside_ptregs);
+3 −20
Original line number Diff line number Diff line
@@ -55,29 +55,12 @@ static inline void syscall_set_return_value(struct task_struct *task,

static inline void syscall_get_arguments(struct task_struct *task,
					 struct pt_regs *regs,
					 unsigned int i, unsigned int n,
					 unsigned long *args)
{
	if (n == 0)
		return;

	if (i + n > SYSCALL_MAX_ARGS) {
		unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
		unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
		pr_warn("%s called with max args %d, handling only %d\n",
			__func__, i + n, SYSCALL_MAX_ARGS);
		memset(args_bad, 0, n_bad * sizeof(args[0]));
		n = SYSCALL_MAX_ARGS - i;
	}

	if (i == 0) {
	args[0] = regs->ARM_ORIG_r0;
	args++;
		i++;
		n--;
	}

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

static inline void syscall_set_arguments(struct task_struct *task,
+3 −19
Original line number Diff line number Diff line
@@ -65,28 +65,12 @@ static inline void syscall_set_return_value(struct task_struct *task,

static inline void syscall_get_arguments(struct task_struct *task,
					 struct pt_regs *regs,
					 unsigned int i, unsigned int n,
					 unsigned long *args)
{
	if (n == 0)
		return;

	if (i + n > SYSCALL_MAX_ARGS) {
		unsigned long *args_bad = args + SYSCALL_MAX_ARGS - i;
		unsigned int n_bad = n + i - SYSCALL_MAX_ARGS;
		pr_warning("%s called with max args %d, handling only %d\n",
			   __func__, i + n, SYSCALL_MAX_ARGS);
		memset(args_bad, 0, n_bad * sizeof(args[0]));
	}

	if (i == 0) {
	args[0] = regs->orig_x0;
	args++;
		i++;
		n--;
	}

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

static inline void syscall_set_arguments(struct task_struct *task,
+8 −33
Original line number Diff line number Diff line
@@ -46,40 +46,15 @@ static inline void syscall_set_return_value(struct task_struct *task,
}

static inline void syscall_get_arguments(struct task_struct *task,
					 struct pt_regs *regs, unsigned int i,
					 unsigned int n, unsigned long *args)
					 struct pt_regs *regs,
					 unsigned long *args)
{
	switch (i) {
	case 0:
		if (!n--)
			break;
	*args++ = regs->a4;
	case 1:
		if (!n--)
			break;
	*args++ = regs->b4;
	case 2:
		if (!n--)
			break;
	*args++ = regs->a6;
	case 3:
		if (!n--)
			break;
	*args++ = regs->b6;
	case 4:
		if (!n--)
			break;
	*args++ = regs->a8;
	case 5:
		if (!n--)
			break;
		*args++ = regs->b8;
	case 6:
		if (!n--)
			break;
	default:
		BUG();
	}
	*args   = regs->b8;
}

static inline void syscall_set_arguments(struct task_struct *task,
+4 −10
Original line number Diff line number Diff line
@@ -43,17 +43,11 @@ syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,

static inline void
syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
		      unsigned int i, unsigned int n, unsigned long *args)
		      unsigned long *args)
{
	BUG_ON(i + n > 6);
	if (i == 0) {
	args[0] = regs->orig_a0;
	args++;
		n--;
	} else {
		i--;
	}
	memcpy(args, &regs->a1 + i, n * sizeof(args[0]));
	memcpy(args, &regs->a1, 5 * sizeof(args[0]));
}

static inline void
Loading