Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata

2016-10-13 Thread Michael Ellerman
Marcin Nowakowski  writes:

> On 12.10.2016 10:50, Michael Ellerman wrote:
>> <...>
>> It's annoying that we have to duplicate all that just to do a + 1.
>>
>> How about this as a precursor?
>  > <...>
>
> Thanks for the suggestion - unless anyone sees a reason to keep the 
> current solution I'll change it.

Thanks. I forgot to add my SOB so here it is:

Signed-off-by: Michael Ellerman 

cheers


Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata

2016-10-12 Thread Marcin Nowakowski

On 12.10.2016 10:50, Michael Ellerman wrote:

<...>
It's annoying that we have to duplicate all that just to do a + 1.

How about this as a precursor?

> <...>

Thanks for the suggestion - unless anyone sees a reason to keep the 
current solution I'll change it.


Marcin


Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata

2016-10-12 Thread Michael Ellerman
Marcin Nowakowski  writes:

> Now that compat syscalls are properly distinguished from native calls,
> we can add metadata for compat syscalls as well.
> All the macros used to generate the metadata are the same as for
> standard syscalls, but with a compat_ prefix to distinguish them easily.
>
> Signed-off-by: Marcin Nowakowski 
> Cc: Steven Rostedt 
> Cc: Ingo Molnar 
> Cc: Benjamin Herrenschmidt 
> Cc: Paul Mackerras 
> Cc: Michael Ellerman 
> Cc: linuxppc-dev@lists.ozlabs.org
> ---
>  arch/powerpc/include/asm/ftrace.h | 15 +---
>  include/linux/compat.h| 74 
> +++
>  kernel/trace/trace_syscalls.c |  8 +++--
>  3 files changed, 90 insertions(+), 7 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/ftrace.h 
> b/arch/powerpc/include/asm/ftrace.h
> index 686c5f7..9697a73 100644
> --- a/arch/powerpc/include/asm/ftrace.h
> +++ b/arch/powerpc/include/asm/ftrace.h
> @@ -73,12 +73,17 @@ struct dyn_arch_ftrace {
>  static inline bool arch_syscall_match_sym_name(const char *sym, const char 
> *name)
>  {
>   /*
> -  * Compare the symbol name with the system call name. Skip the .sys or 
> .SyS
> -  * prefix from the symbol name and the sys prefix from the system call 
> name and
> -  * just match the rest. This is only needed on ppc64 since symbol names 
> on
> -  * 32bit do not start with a period so the generic function will work.
> +  * Compare the symbol name with the system call name. Skip the .sys,
> +  * .SyS or .compat_sys prefix from the symbol name and the sys prefix
> +  * from the system call name and just match the rest. This is only
> +  * needed on ppc64 since symbol names on 32bit do not start with a
> +  * period so the generic function will work.
>*/
> - return !strcmp(sym + 4, name + 3);
> + int prefix_len = 3;
> +
> + if (!strncasecmp(name, "compat_", 7))
> + prefix_len = 10;
> + return !strcmp(sym + prefix_len + 1, name + prefix_len);
>  }

It's annoying that we have to duplicate all that just to do a + 1.

How about this as a precursor?

cheers


diff --git a/Documentation/trace/ftrace-design.txt 
b/Documentation/trace/ftrace-design.txt
index dd5f916b351d..bd65f2adeb09 100644
--- a/Documentation/trace/ftrace-design.txt
+++ b/Documentation/trace/ftrace-design.txt
@@ -226,10 +226,6 @@ You need very few things to get the syscalls tracing in an 
arch.
 - If the system call table on this arch is more complicated than a simple array
   of addresses of the system calls, implement an arch_syscall_addr to return
   the address of a given system call.
-- If the symbol names of the system calls do not match the function names on
-  this arch, define ARCH_HAS_SYSCALL_MATCH_SYM_NAME in asm/ftrace.h and
-  implement arch_syscall_match_sym_name with the appropriate logic to return
-  true if the function name corresponds with the symbol name.
 - Tag this arch as HAVE_SYSCALL_TRACEPOINTS.
 
 
diff --git a/arch/powerpc/include/asm/ftrace.h 
b/arch/powerpc/include/asm/ftrace.h
index 686c5f70eb84..dc48f5b2878d 100644
--- a/arch/powerpc/include/asm/ftrace.h
+++ b/arch/powerpc/include/asm/ftrace.h
@@ -60,6 +60,12 @@ struct dyn_arch_ftrace {
struct module *mod;
 };
 #endif /*  CONFIG_DYNAMIC_FTRACE */
+
+#ifdef PPC64_ELF_ABI_v1
+/* On ppc64 ABIv1 (BE) we have to skip the leading '.' in the symbol name */
+#define ARCH_SYM_NAME_SKIP_CHARS 1
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
@@ -67,20 +73,4 @@ struct dyn_arch_ftrace {
 #endif
 #endif
 
-#if defined(CONFIG_FTRACE_SYSCALLS) && !defined(__ASSEMBLY__)
-#ifdef PPC64_ELF_ABI_v1
-#define ARCH_HAS_SYSCALL_MATCH_SYM_NAME
-static inline bool arch_syscall_match_sym_name(const char *sym, const char 
*name)
-{
-   /*
-* Compare the symbol name with the system call name. Skip the .sys or 
.SyS
-* prefix from the symbol name and the sys prefix from the system call 
name and
-* just match the rest. This is only needed on ppc64 since symbol names 
on
-* 32bit do not start with a period so the generic function will work.
-*/
-   return !strcmp(sym + 4, name + 3);
-}
-#endif
-#endif /* CONFIG_FTRACE_SYSCALLS && !__ASSEMBLY__ */
-
 #endif /* _ASM_POWERPC_FTRACE */
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index b2b6efc083a4..91a7315dbe43 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -31,8 +31,11 @@ extern struct syscall_metadata *__stop_syscalls_metadata[];
 
 static struct syscall_metadata **syscalls_metadata;
 
-#ifndef ARCH_HAS_SYSCALL_MATCH_SYM_NAME
-static inline bool arch_syscall_match_sym_name(const char *sym, const char 
*name)
+#ifndef ARCH_SYM_NAME_SKIP_CHARS
+#define ARCH_SYM_NAME_SKIP_CHARS 0
+#endif
+
+static 

[PATCH v3 03/11] tracing/syscalls: add compat syscall metadata

2016-10-11 Thread Marcin Nowakowski
Now that compat syscalls are properly distinguished from native calls,
we can add metadata for compat syscalls as well.
All the macros used to generate the metadata are the same as for
standard syscalls, but with a compat_ prefix to distinguish them easily.

Signed-off-by: Marcin Nowakowski 
Cc: Steven Rostedt 
Cc: Ingo Molnar 
Cc: Benjamin Herrenschmidt 
Cc: Paul Mackerras 
Cc: Michael Ellerman 
Cc: linuxppc-dev@lists.ozlabs.org
---
 arch/powerpc/include/asm/ftrace.h | 15 +---
 include/linux/compat.h| 74 +++
 kernel/trace/trace_syscalls.c |  8 +++--
 3 files changed, 90 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/ftrace.h 
b/arch/powerpc/include/asm/ftrace.h
index 686c5f7..9697a73 100644
--- a/arch/powerpc/include/asm/ftrace.h
+++ b/arch/powerpc/include/asm/ftrace.h
@@ -73,12 +73,17 @@ struct dyn_arch_ftrace {
 static inline bool arch_syscall_match_sym_name(const char *sym, const char 
*name)
 {
/*
-* Compare the symbol name with the system call name. Skip the .sys or 
.SyS
-* prefix from the symbol name and the sys prefix from the system call 
name and
-* just match the rest. This is only needed on ppc64 since symbol names 
on
-* 32bit do not start with a period so the generic function will work.
+* Compare the symbol name with the system call name. Skip the .sys,
+* .SyS or .compat_sys prefix from the symbol name and the sys prefix
+* from the system call name and just match the rest. This is only
+* needed on ppc64 since symbol names on 32bit do not start with a
+* period so the generic function will work.
 */
-   return !strcmp(sym + 4, name + 3);
+   int prefix_len = 3;
+
+   if (!strncasecmp(name, "compat_", 7))
+   prefix_len = 10;
+   return !strcmp(sym + prefix_len + 1, name + prefix_len);
 }
 #endif
 #endif /* CONFIG_FTRACE_SYSCALLS && !__ASSEMBLY__ */
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 6360939..ef2a70f 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -30,7 +30,80 @@
 #define __SC_DELOUSE(t,v) ((t)(unsigned long)(v))
 #endif
 
+#ifdef CONFIG_FTRACE_SYSCALLS
+#ifndef __SC_STR_ADECL
+#define __SC_STR_ADECL(t, a)   #a
+#endif
+
+#ifndef __SC_STR_TDECL
+#define __SC_STR_TDECL(t, a)   #t
+#endif
+
+extern struct trace_event_class event_class_syscall_enter;
+extern struct trace_event_class event_class_syscall_exit;
+extern struct trace_event_functions enter_syscall_print_funcs;
+extern struct trace_event_functions exit_syscall_print_funcs;
+
+#define COMPAT_SYSCALL_TRACE_ENTER_EVENT(sname)
\
+   static struct syscall_metadata __syscall_meta_compat_##sname;   
\
+   static struct trace_event_call __used   \
+ event_enter_compat_##sname = {
\
+   .class  = _class_syscall_enter,   \
+   {   \
+   .name   = "compat_sys_enter"#sname, 
\
+   },  \
+   .event.funcs= _syscall_print_funcs,   \
+   .data   = (void 
*)&__syscall_meta_compat_##sname,\
+   .flags  = TRACE_EVENT_FL_CAP_ANY,   \
+   };  \
+   static struct trace_event_call __used   \
+ __attribute__((section("_ftrace_events")))\
+*__event_enter_compat_##sname = _enter_compat_##sname;
+
+#define COMPAT_SYSCALL_TRACE_EXIT_EVENT(sname) 
\
+   static struct syscall_metadata __syscall_meta_compat_##sname;   
\
+   static struct trace_event_call __used   \
+ event_exit_compat_##sname = { \
+   .class  = _class_syscall_exit,\
+   {   \
+   .name   = "compat_sys_exit"#sname,  
\
+   },  \
+   .event.funcs= _syscall_print_funcs,\
+   .data   = (void 
*)&__syscall_meta_compat_##sname,\
+   .flags  = TRACE_EVENT_FL_CAP_ANY,   \
+   };  \
+   static struct trace_event_call __used   \
+ __attribute__((section("_ftrace_events")))\
+