From mboxrd@z Thu Jan 1 00:00:00 1970 From: Steven Rostedt Subject: Re: [PATCH 04/18] tracing/x86: Add arch_get_func_args() function Date: Mon, 5 Feb 2018 12:06:12 -0500 Message-ID: <20180205120612.5d7c97b0@gandalf.local.home> References: <20180202230458.840252014@goodmis.org> <20180202231017.612058326@goodmis.org> <20180206013322.754e66a4c956383174418953@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: linux-kernel@vger.kernel.org, Linus Torvalds , Ingo Molnar , Andrew Morton , Thomas Gleixner , Peter Zijlstra , Tom Zanussi , linux-rt-users@vger.kernel.org, linux-trace-users@vger.kernel.org, Arnaldo Carvalho de Melo , Clark Williams , Jiri Olsa , Daniel Bristot de Oliveira , Juri Lelli , Jonathan Corbet , Mathieu Desnoyers , Namhyung Kim , Alexei Starovoitov To: Masami Hiramatsu Return-path: In-Reply-To: <20180206013322.754e66a4c956383174418953@kernel.org> Sender: linux-trace-users-owner@vger.kernel.org List-Id: linux-rt-users.vger.kernel.org On Tue, 6 Feb 2018 01:33:22 +0900 Masami Hiramatsu wrote: > On Fri, 02 Feb 2018 18:05:02 -0500 > Steven Rostedt wrote: > > > From: "Steven Rostedt (VMware)" > > > > Add function to get the function arguments from pt_regs. > > > > Can we make it an independent feature in asm/ptrace.h so that > other components (like kprobe-event) share it? Most definitely! > E.g. > > static inline unsigned long regs_get_func_arg(struct pt_regs *regs, > unsigned int n) > { > unsigned int offs[] = { > #ifdef CONFIG_X86_64 > offsetof(typeof(regs),di), > offsetof(typeof(regs),si), > offsetof(typeof(regs),dx), > offsetof(typeof(regs),cx), > offsetof(typeof(regs),r8), > offsetof(typeof(regs),r9), > #else > offsetof(typeof(regs),ax), > offsetof(typeof(regs),dx), > offsetof(typeof(regs),cx), > #endif > }; > > if (unlikely(n >= ARRAY_SIZE(offs)) > return 0; > return *(unsigned long *)((unsigned long)regs + offs[n]); I like having the function I used, because it could also handle arguments in the stack (although I didn't implement that yet). But this would still be a nice helper function. -- Steve > } > > And HAVE_REGS_GET_FUNC_ARG indicates this is defined on that arch. > > Thank you, > > > Signed-off-by: Steven Rostedt (VMware) > > --- > > arch/x86/kernel/ftrace.c | 28 ++++++++++++++++++++++++++++ > > 1 file changed, 28 insertions(+) > > > > diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c > > index 01ebcb6f263e..5e845c8cf89d 100644 > > --- a/arch/x86/kernel/ftrace.c > > +++ b/arch/x86/kernel/ftrace.c > > @@ -46,6 +46,34 @@ int ftrace_arch_code_modify_post_process(void) > > return 0; > > } > > > > +int arch_get_func_args(struct pt_regs *regs, > > + int start, int end, long *args) > > +{ > > +#ifdef CONFIG_X86_64 > > +# define MAX_ARGS 6 > > +# define INIT_REGS \ > > + { regs->di, regs->si, regs->dx, \ > > + regs->cx, regs->r8, regs->r9 \ > > + } > > +#else > > +# define MAX_ARGS 3 > > +# define INIT_REGS \ > > + { regs->ax, regs->dx, regs->cx } > > +#endif > > + if (!regs) > > + return MAX_ARGS; > > + > > + { > > + long pt_args[] = INIT_REGS; > > + int i; > > + > > + for (i = start; i <= end && i < MAX_ARGS; i++) > > + args[i - start] = pt_args[i]; > > + > > + return i - start; > > + } > > +} > > + > > union ftrace_code_union { > > char code[MCOUNT_INSN_SIZE]; > > struct { > > -- > > 2.15.1 > > > > > >