[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190403120649.GB29409@fuggles.cambridge.arm.com>
Date: Wed, 3 Apr 2019 13:06:49 +0100
From: Will Deacon <will.deacon@....com>
To: Masami Hiramatsu <mhiramat@...nel.org>
Cc: Catalin Marinas <catalin.marinas@....com>,
Steven Rostedt <rostedt@...dmis.org>,
Oleg Nesterov <oleg@...hat.com>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] arm64: ptrace: Add function argument access API
On Mon, Mar 18, 2019 at 04:59:02PM +0900, Masami Hiramatsu wrote:
> Add regs_get_argument() which returns N th argument of the function
> call. On arm64, it supports up to 8th argument.
> Note that this chooses most probably assignment, in some case
> it can be incorrect (e.g. passing data structure or floating
> point etc.)
>
> This enables ftrace kprobe events to access kernel function
> arguments via $argN syntax.
>
> Signed-off-by: Masami Hiramatsu <mhiramat@...nel.org>
> ---
> arch/arm64/Kconfig | 1 +
> arch/arm64/include/asm/ptrace.h | 18 ++++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 117b2541ef3d..6ba0da4be73c 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -148,6 +148,7 @@ config ARM64
> select HAVE_PERF_REGS
> select HAVE_PERF_USER_STACK_DUMP
> select HAVE_REGS_AND_STACK_ACCESS_API
> + select HAVE_FUNCTION_ARG_ACCESS_API
> select HAVE_RCU_TABLE_FREE
> select HAVE_RCU_TABLE_INVALIDATE
> select HAVE_RSEQ
> diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h
> index ec60174c8c18..cfa1bc9b8b70 100644
> --- a/arch/arm64/include/asm/ptrace.h
> +++ b/arch/arm64/include/asm/ptrace.h
> @@ -305,6 +305,24 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
> return regs->regs[0];
> }
>
> +/**
> + * regs_get_kernel_argument() - get Nth function argument in kernel
> + * @regs: pt_regs of that context
> + * @n: function argument number (start from 0)
> + *
> + * regs_get_argument() returns @n th argument of the function call.
> + * Note that this chooses most probably assignment, in some case
> + * it can be incorrect.
In which cases would it be incorrect? I can imagine varargs causing
problems, but are there others?
> +static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
> + unsigned int n)
> +{
> +#define NR_REG_ARGUMENTS 8
> + if (n < NR_REG_ARGUMENTS)
> + return regs_get_register(regs, n << 3);
You can use pt_regs_read_reg() to avoid the shift here.
Will
Powered by blists - more mailing lists