From: Masami Hiramatsu <mhiramat@kernel.org>
To: Will Deacon <will.deacon@arm.com>
Cc: linux-arm-kernel@lists.infradead.org,
Catalin Marinas <catalin.marinas@arm.com>,
Oleg Nesterov <oleg@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arm64: ptrace: Add function argument access API
Date: Mon, 8 Apr 2019 09:33:20 +0900 [thread overview]
Message-ID: <20190408093320.35f4050788937c995ca56a6b@kernel.org> (raw)
In-Reply-To: <20190403120649.GB29409@fuggles.cambridge.arm.com>
Hi Will,
On Wed, 3 Apr 2019 13:06:49 +0100
Will Deacon <will.deacon@arm.com> wrote:
> 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@kernel.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?
As far as I can read "Procedure Call Standard for the ARM 64-bit
Architecture(AArch64) 5.4.2 Parameter Passing Rules", it may not return
correct data if the target function has a parameter which is 16bytes
or bigger size. Of course that is just a limitation of this interface.
But anyway, it can return wrong data for the parameter after such big
parameters. I think, for func(data-struct-128bits p1, u64 p2), p1
is stored into r0 and r1, and p2 is stored r2, is that correct?
(Of course any SIMD/float parameter passed to the function, it also can
not correctly get, but in the kernel we can ignore it.)
> > +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.
Ah, right!
Thank you,
--
Masami Hiramatsu <mhiramat@kernel.org>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-04-08 0:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-18 7:59 [PATCH] arm64: ptrace: Add function argument access API Masami Hiramatsu
2019-04-03 12:06 ` Will Deacon
2019-04-08 0:33 ` Masami Hiramatsu [this message]
2019-04-11 17:22 ` Will Deacon
2019-04-12 13:49 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190408093320.35f4050788937c995ca56a6b@kernel.org \
--to=mhiramat@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).