[PATCH v4 09/12] powerpc/tracing: fix compat syscall handling
Adapt the code to make use of new syscall handling interface Signed-off-by: Marcin Nowakowski <marcin.nowakow...@imgtec.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org> Cc: Paul Mackerras <pau...@samba.org> Cc: Michael Ellerman <m...@ellerman.id.au> Cc: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/include/asm/ftrace.h | 13 + arch/powerpc/kernel/ftrace.c | 4 2 files changed, 17 insertions(+) diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h index f266051..c6c660d 100644 --- a/arch/powerpc/include/asm/ftrace.h +++ b/arch/powerpc/include/asm/ftrace.h @@ -72,4 +72,17 @@ struct dyn_arch_ftrace { #define ARCH_SYM_NAME_SKIP_CHARS 1 #endif +#if defined(CONFIG_FTRACE_SYSCALLS) && !defined(__ASSEMBLY__) +#if defined(CONFIG_COMPAT) +#include +#include + +#define ARCH_COMPAT_SYSCALL_NUMBERS_OVERLAP 1 +static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) +{ + return in_compat_syscall(); +} +#endif /* CONFIG_COMPAT */ +#endif /* CONFIG_FTRACE_SYSCALLS && !__ASSEMBLY__ */ + #endif /* _ASM_POWERPC_FTRACE */ diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c index 5bfb35f..12c00f7 100644 --- a/arch/powerpc/kernel/ftrace.c +++ b/arch/powerpc/kernel/ftrace.c @@ -606,6 +606,10 @@ unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip) #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_PPC64) unsigned long __init arch_syscall_addr(int nr, bool compat) { +#ifdef CONFIG_COMPAT + if (compat) + return sys_call_table[nr*2+1]; +#endif return sys_call_table[nr*2]; } #endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_PPC64 */ -- 2.7.4
[PATCH v4 04/12] tracing/syscalls: add compat syscall metadata
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 <marcin.nowakow...@imgtec.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org> Cc: Paul Mackerras <pau...@samba.org> Cc: Michael Ellerman <m...@ellerman.id.au> Cc: linuxppc-dev@lists.ozlabs.org --- include/linux/compat.h| 74 +++ kernel/trace/trace_syscalls.c | 10 -- 2 files changed, 82 insertions(+), 2 deletions(-) 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")))\ + *__event_exit_compat_##sname = _exit_compat_##sname; + +#define COMPAT_SYSCALL_METADATA(sname, nb, ...)\ + static const char *types_compat_##sname[] = { \ + __MAP(nb,__SC_STR_TDECL,__VA_ARGS__)\ + }; \ + static const char *args_compat_##sname[] = {\ + __MAP(nb,__SC_STR_ADECL,__VA_ARGS__)\ + }; \ + COMPAT_SYSCALL_TRACE_ENTER_EVENT(sname);\ + COMPAT_SYSCALL_TRACE_EXIT_EVENT(sname); \ + static struct syscall_metadata __used \ + __syscall_meta_compat_##sname = { \ + .name = "compat_sys"#sname, \ + .nb_args= nb, \ + .types = nb ? types_compat_##sname : NULL, \ + .args = nb ? args_compat_##sname : NULL, \ + .enter_event= _enter_compat_##sname, \ + .exit_event = _exit_compat_##sname,
Re: [PATCH v3 08/11] powerpc/tracing: fix compat syscall handling
On 12.10.2016 11:59, Michael Ellerman wrote: I went to test this and noticed the exit and enter events appear to be reversed in time? (your series on top of 24532f768121) thanks for testing the patch - I've found a bug that has sneaked in while cleaning up the patches before submission ... I'll fix it in the next iteration. Marcin
Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata
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
[PATCH v3 08/11] powerpc/tracing: fix compat syscall handling
Adapt the code to make use of new syscall handling interface Signed-off-by: Marcin Nowakowski <marcin.nowakow...@imgtec.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org> Cc: Paul Mackerras <pau...@samba.org> Cc: Michael Ellerman <m...@ellerman.id.au> Cc: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/include/asm/ftrace.h | 11 +++ arch/powerpc/kernel/ftrace.c | 4 2 files changed, 15 insertions(+) diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h index 9697a73..d2ea3b6 100644 --- a/arch/powerpc/include/asm/ftrace.h +++ b/arch/powerpc/include/asm/ftrace.h @@ -86,6 +86,17 @@ static inline bool arch_syscall_match_sym_name(const char *sym, const char *name return !strcmp(sym + prefix_len + 1, name + prefix_len); } #endif + +#if defined(CONFIG_COMPAT) +#include +#include + +#define ARCH_COMPAT_SYSCALL_NUMBERS_OVERLAP 1 +static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) +{ + return in_compat_syscall(); +} +#endif /* CONFIG_COMPAT */ #endif /* CONFIG_FTRACE_SYSCALLS && !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_FTRACE */ diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c index 5bfb35f..12c00f7 100644 --- a/arch/powerpc/kernel/ftrace.c +++ b/arch/powerpc/kernel/ftrace.c @@ -606,6 +606,10 @@ unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip) #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_PPC64) unsigned long __init arch_syscall_addr(int nr, bool compat) { +#ifdef CONFIG_COMPAT + if (compat) + return sys_call_table[nr*2+1]; +#endif return sys_call_table[nr*2]; } #endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_PPC64 */ -- 2.7.4
[PATCH v3 03/11] tracing/syscalls: add compat syscall metadata
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 <marcin.nowakow...@imgtec.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org> Cc: Paul Mackerras <pau...@samba.org> Cc: Michael Ellerman <m...@ellerman.id.au> 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 \ + _
[PATCH v2 03/11] tracing/syscalls: add compat syscall metadata
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 <marcin.nowakow...@imgtec.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org> Cc: Paul Mackerras <pau...@samba.org> Cc: Michael Ellerman <m...@ellerman.id.au> 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 f964ef7..9e84c92 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 \ + _
[PATCH v2 08/11] powerpc/tracing: fix compat syscall handling
Adapt the code to make use of new syscall handling interface Signed-off-by: Marcin Nowakowski <marcin.nowakow...@imgtec.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Ingo Molnar <mi...@redhat.com> Cc: Benjamin Herrenschmidt <b...@kernel.crashing.org> Cc: Paul Mackerras <pau...@samba.org> Cc: Michael Ellerman <m...@ellerman.id.au> Cc: linuxppc-dev@lists.ozlabs.org --- arch/powerpc/include/asm/ftrace.h | 11 +++ arch/powerpc/kernel/ftrace.c | 4 2 files changed, 15 insertions(+) diff --git a/arch/powerpc/include/asm/ftrace.h b/arch/powerpc/include/asm/ftrace.h index 9697a73..d2ea3b6 100644 --- a/arch/powerpc/include/asm/ftrace.h +++ b/arch/powerpc/include/asm/ftrace.h @@ -86,6 +86,17 @@ static inline bool arch_syscall_match_sym_name(const char *sym, const char *name return !strcmp(sym + prefix_len + 1, name + prefix_len); } #endif + +#if defined(CONFIG_COMPAT) +#include +#include + +#define ARCH_COMPAT_SYSCALL_NUMBERS_OVERLAP 1 +static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs) +{ + return in_compat_syscall(); +} +#endif /* CONFIG_COMPAT */ #endif /* CONFIG_FTRACE_SYSCALLS && !__ASSEMBLY__ */ #endif /* _ASM_POWERPC_FTRACE */ diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c index 71f4d07..0764fa5 100644 --- a/arch/powerpc/kernel/ftrace.c +++ b/arch/powerpc/kernel/ftrace.c @@ -605,6 +605,10 @@ out: #if defined(CONFIG_FTRACE_SYSCALLS) && defined(CONFIG_PPC64) unsigned long __init arch_syscall_addr(int nr, bool compat) { +#ifdef CONFIG_COMPAT + if (compat) + return sys_call_table[nr*2+1]; +#endif return sys_call_table[nr*2]; } #endif /* CONFIG_FTRACE_SYSCALLS && CONFIG_PPC64 */ -- 2.7.4