Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1498752 > unrolled thread
| Started by | Marcin Nowakowski <marcin.nowakowski@imgtec.com> |
|---|---|
| First post | 2016-10-11 12:50 +0200 |
| Last post | 2016-10-11 12:50 +0200 |
| Articles | 7 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v3 00/11] syscall/tracing: compat syscall support Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-10-11 12:50 +0200
[PATCH v3 03/11] tracing/syscalls: add compat syscall metadata Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-10-11 12:50 +0200
Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata Michael Ellerman <mpe@ellerman.id.au> - 2016-10-12 11:00 +0200
Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-10-12 15:20 +0200
Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata Michael Ellerman <mpe@ellerman.id.au> - 2016-10-13 11:50 +0200
[PATCH v3 04/11] syscall/tracing: allow arch to override syscall_get_nr for ftrace Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-10-11 12:50 +0200
[PATCH v3 01/11] tracing/syscalls: remove syscall_nr from syscall metadata Marcin Nowakowski <marcin.nowakowski@imgtec.com> - 2016-10-11 12:50 +0200
| From | Marcin Nowakowski <marcin.nowakowski@imgtec.com> |
|---|---|
| Date | 2016-10-11 12:50 +0200 |
| Subject | [PATCH v3 00/11] syscall/tracing: compat syscall support |
| Message-ID | <sr2Nb-5Cj-3@gated-at.bofh.it> |
This patchset adds support syscall event tracing for compat syscalls.
Second patchset revision has received very little response - so I'm hoping
to get either acks from syscall/trace and arch maintainers or more feedback
on what else needs to be changed.
Patch 1 removes the unnecessary syscall_nr field from syscall metadata,
which was one of the obstacles for adding proper support for compat syscalls.
Patch 2 adds a method to distinguish handling of syscalls for compat tasks
if an arch requires that. In disussions about an earlier version of these
patches (http://marc.info/?l=linux-mips&m=147259973128606&w=2) it was suggested
to use audit arch for detecting syscall type. After analysing the code
for various arches it seemed to me that this would add an unnecessary
complexity (as would require extra APIs to enumerate and map all audit
arch types) and I've just simply used compat task status to determine call
type. I cannot see any added value from using the audit arch type in this
context.
Patch 3 add compat syscall metadata - this is mostly a copy of a set of macros
for generating metadata for standard syscalls.
Further patches add arch-specific methods required for differentiating between
standard and compat syscalls as well as for finding syscall addresses from
inside syscall tables.
I have tried to keep the tracing system working for bisections - and most
things work as previously until arch-specific patch is applied. The only
exception here is x86 which had extra methods to prevent incorrect syscall
reporting for compat tasks - this may happen after patch 2 is applied and
without x86/tracing patch.
version 3:
- rebase on top of linux-next-20161011
- tile: change in_compat_syscall to is_compat_task (suggested and signed-off by
Chris Metcalf)
Marcin Nowakowski (11):
tracing/syscalls: remove syscall_nr from syscall metadata
tracing/syscalls: add handling for compat tasks
tracing/syscalls: add compat syscall metadata
syscall/tracing: allow arch to override syscall_get_nr for ftrace
x86/tracing: fix compat syscall handling
s390/tracing: fix compat syscall handling
arm64/tracing: fix compat syscall handling
powerpc/tracing: fix compat syscall handling
tile/tracing: fix compat syscall handling
sparc/tracing: fix compat syscall handling
parisc/tracing: fix compat syscall handling
arch/arm64/include/asm/ftrace.h | 12 +-
arch/arm64/include/asm/unistd.h | 1 +
arch/arm64/kernel/Makefile | 1 +
arch/arm64/kernel/ftrace.c | 16 +++
arch/mips/kernel/ftrace.c | 4 +-
arch/parisc/include/asm/ftrace.h | 10 ++
arch/parisc/kernel/Makefile | 1 +
arch/parisc/kernel/ftrace.c | 15 +++
arch/powerpc/include/asm/ftrace.h | 26 +++-
arch/powerpc/kernel/ftrace.c | 6 +-
arch/s390/include/asm/ftrace.h | 11 ++
arch/s390/include/asm/syscall.h | 1 +
arch/s390/kernel/Makefile | 1 +
arch/s390/kernel/ftrace.c | 12 ++
arch/sparc/include/asm/ftrace.h | 10 ++
arch/sparc/kernel/Makefile | 1 +
arch/sparc/kernel/ftrace.c | 14 ++
arch/tile/include/asm/ftrace.h | 10 ++
arch/tile/kernel/Makefile | 1 +
arch/tile/kernel/ftrace.c | 13 ++
arch/x86/include/asm/ftrace.h | 14 +-
arch/x86/include/asm/syscall.h | 9 ++
arch/x86/kernel/ftrace.c | 15 +++
include/linux/compat.h | 74 +++++++++++
include/linux/ftrace.h | 2 +-
include/linux/syscalls.h | 1 -
include/trace/syscall.h | 2 -
kernel/trace/trace.h | 17 ++-
kernel/trace/trace_syscalls.c | 260 +++++++++++++++++++++++---------------
29 files changed, 421 insertions(+), 139 deletions(-)
--
2.7.4
[toc] | [next] | [standalone]
| From | Marcin Nowakowski <marcin.nowakowski@imgtec.com> |
|---|---|
| Date | 2016-10-11 12:50 +0200 |
| Subject | [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata |
| Message-ID | <sr2Nc-5Cj-27@gated-at.bofh.it> |
| In reply to | #1498752 |
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.nowakowski@imgtec.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@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 = &event_class_syscall_enter, \
+ { \
+ .name = "compat_sys_enter"#sname, \
+ }, \
+ .event.funcs = &enter_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 = &event_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 = &event_class_syscall_exit, \
+ { \
+ .name = "compat_sys_exit"#sname, \
+ }, \
+ .event.funcs = &exit_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 = &event_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 = &event_enter_compat_##sname, \
+ .exit_event = &event_exit_compat_##sname, \
+ .enter_fields = LIST_HEAD_INIT(__syscall_meta_compat_##sname.enter_fields), \
+ }; \
+ static struct syscall_metadata __used \
+ __attribute__((section("__syscalls_metadata"))) \
+ *__p_syscall_meta_compat_##sname = &__syscall_meta_compat_##sname;
+#else
+#define COMPAT_SYSCALL_METADATA(sname, nb, ...)
+#endif
+
#define COMPAT_SYSCALL_DEFINE0(name) \
+ COMPAT_SYSCALL_METADATA(_##name, 0); \
asmlinkage long compat_sys_##name(void)
#define COMPAT_SYSCALL_DEFINE1(name, ...) \
@@ -47,6 +120,7 @@
COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
#define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
+ COMPAT_SYSCALL_METADATA(name, x, __VA_ARGS__) \
asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
__attribute__((alias(__stringify(compat_SyS##name)))); \
static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index fe7fc33..409f83e 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -35,12 +35,16 @@ static struct syscall_metadata **syscalls_metadata;
static inline bool arch_syscall_match_sym_name(const char *sym, const char *name)
{
/*
- * Only compare after the "sys" prefix. Archs that use
+ * Only compare after the "sys" or "compat_sys" prefix. Archs that use
* syscall wrappers may have syscalls symbols aliases prefixed
* with ".SyS" or ".sys" instead of "sys", leading to an unwanted
* mismatch.
*/
- return !strcmp(sym + 3, name + 3);
+ int prefix_len = 3;
+
+ if (!strncasecmp(sym, "compat_", 7))
+ prefix_len = 10;
+ return !strcmp(sym + prefix_len, name + prefix_len);
}
#endif
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2016-10-12 11:00 +0200 |
| Subject | Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata |
| Message-ID | <srnyi-1Vk-13@gated-at.bofh.it> |
| In reply to | #1498753 |
Marcin Nowakowski <marcin.nowakowski@imgtec.com> 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 <marcin.nowakowski@imgtec.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Michael Ellerman <mpe@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);
> }
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 inline bool syscall_match_sym_name(const char *sym, const char *name)
{
/*
* Only compare after the "sys" prefix. Archs that use
@@ -40,9 +43,8 @@ static inline bool arch_syscall_match_sym_name(const char *sym, const char *name
* with ".SyS" or ".sys" instead of "sys", leading to an unwanted
* mismatch.
*/
- return !strcmp(sym + 3, name + 3);
+ return !strcmp(sym + 3 + ARCH_SYM_NAME_SKIP_CHARS, name + 3);
}
-#endif
#ifdef ARCH_TRACE_IGNORE_COMPAT_SYSCALLS
/*
@@ -88,11 +90,11 @@ find_syscall_meta(unsigned long syscall)
stop = __stop_syscalls_metadata;
kallsyms_lookup(syscall, NULL, NULL, NULL, str);
- if (arch_syscall_match_sym_name(str, "sys_ni_syscall"))
+ if (syscall_match_sym_name(str, "sys_ni_syscall"))
return NULL;
for ( ; start < stop; start++) {
- if ((*start)->name && arch_syscall_match_sym_name(str, (*start)->name))
+ if ((*start)->name && syscall_match_sym_name(str, (*start)->name))
return *start;
}
return NULL;
[toc] | [prev] | [next] | [standalone]
| From | Marcin Nowakowski <marcin.nowakowski@imgtec.com> |
|---|---|
| Date | 2016-10-12 15:20 +0200 |
| Subject | Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata |
| Message-ID | <srrBT-4SP-35@gated-at.bofh.it> |
| In reply to | #1499435 |
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
[toc] | [prev] | [next] | [standalone]
| From | Michael Ellerman <mpe@ellerman.id.au> |
|---|---|
| Date | 2016-10-13 11:50 +0200 |
| Subject | Re: [PATCH v3 03/11] tracing/syscalls: add compat syscall metadata |
| Message-ID | <srKOe-1Ic-15@gated-at.bofh.it> |
| In reply to | #1499675 |
Marcin Nowakowski <marcin.nowakowski@imgtec.com> 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 <mpe@ellerman.id.au> cheers
[toc] | [prev] | [next] | [standalone]
| From | Marcin Nowakowski <marcin.nowakowski@imgtec.com> |
|---|---|
| Date | 2016-10-11 12:50 +0200 |
| Subject | [PATCH v3 04/11] syscall/tracing: allow arch to override syscall_get_nr for ftrace |
| Message-ID | <sr2Nc-5Cj-33@gated-at.bofh.it> |
| In reply to | #1498752 |
Some architectures modify syscall numbers to indicate ABI used
and as a result syscall number as returned by syscall_get_nr
does not correspond to the syscall number used inside the kernel.
Allow an arch to provide a separate implementation for ftrace
that returns the 'real' syscall number from the regs provided.
This will be used by x86 in a follow-up change.
Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
---
kernel/trace/trace_syscalls.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 409f83e..0ab9b90 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -74,7 +74,11 @@ static inline bool trace_is_compat_syscall(struct pt_regs *regs)
static inline int
trace_get_syscall_nr(struct task_struct *task, struct pt_regs *regs)
{
+#ifdef arch_trace_syscall_get_nr
+ return arch_trace_syscall_get_nr(task, regs);
+#else
return syscall_get_nr(task, regs);
+#endif
}
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Marcin Nowakowski <marcin.nowakowski@imgtec.com> |
|---|---|
| Date | 2016-10-11 12:50 +0200 |
| Subject | [PATCH v3 01/11] tracing/syscalls: remove syscall_nr from syscall metadata |
| Message-ID | <sr2Nc-5Cj-31@gated-at.bofh.it> |
| In reply to | #1498752 |
Some architectures map multiple syscall numbers to a single syscall.
This meant that on those platforms, some system calls could not be
properly traced using syscall event tracing mechanism, as a different
number of a syscall was used for registration to the one used by
applications.
We can use syscall lookup together with the syscall metadata table
traversal to register for appropriate events instead. This slightly
increases the overhead during event (un)registration, but does not
impact the trace events themselves, which still use syscall numbers
directly.
Signed-off-by: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@redhat.com>
---
include/linux/syscalls.h | 1 -
include/trace/syscall.h | 2 -
kernel/trace/trace_syscalls.c | 127 ++++++++++++++++++++++++------------------
3 files changed, 73 insertions(+), 57 deletions(-)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 0d7abb8..88324cc 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -160,7 +160,6 @@ extern struct trace_event_functions exit_syscall_print_funcs;
static struct syscall_metadata __used \
__syscall_meta_##sname = { \
.name = "sys"#sname, \
- .syscall_nr = -1, /* Filled in at boot */ \
.nb_args = nb, \
.types = nb ? types_##sname : NULL, \
.args = nb ? args_##sname : NULL, \
diff --git a/include/trace/syscall.h b/include/trace/syscall.h
index 7434f0f..b5fbebe 100644
--- a/include/trace/syscall.h
+++ b/include/trace/syscall.h
@@ -13,7 +13,6 @@
* A syscall entry in the ftrace syscalls array.
*
* @name: name of the syscall
- * @syscall_nr: number of the syscall
* @nb_args: number of parameters it takes
* @types: list of types as strings
* @args: list of args as strings (args[i] matches types[i])
@@ -23,7 +22,6 @@
*/
struct syscall_metadata {
const char *name;
- int syscall_nr;
int nb_args;
const char **types;
const char **args;
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 5e10395..07887b4 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -405,16 +405,21 @@ static int reg_event_syscall_enter(struct trace_event_file *file,
int ret = 0;
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
- if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
- return -ENOSYS;
mutex_lock(&syscall_trace_lock);
- if (!tr->sys_refcount_enter)
+ if (!tr->sys_refcount_enter) {
ret = register_trace_sys_enter(ftrace_syscall_enter, tr);
- if (!ret) {
- rcu_assign_pointer(tr->enter_syscall_files[num], file);
- tr->sys_refcount_enter++;
+ if (ret)
+ goto out_unlock;
+ }
+
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ rcu_assign_pointer(tr->enter_syscall_files[num], file);
}
+ tr->sys_refcount_enter++;
+
+out_unlock:
mutex_unlock(&syscall_trace_lock);
return ret;
}
@@ -425,12 +430,13 @@ static void unreg_event_syscall_enter(struct trace_event_file *file,
struct trace_array *tr = file->tr;
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
- if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
- return;
mutex_lock(&syscall_trace_lock);
tr->sys_refcount_enter--;
- RCU_INIT_POINTER(tr->enter_syscall_files[num], NULL);
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ RCU_INIT_POINTER(tr->enter_syscall_files[num], NULL);
+ }
if (!tr->sys_refcount_enter)
unregister_trace_sys_enter(ftrace_syscall_enter, tr);
mutex_unlock(&syscall_trace_lock);
@@ -443,16 +449,21 @@ static int reg_event_syscall_exit(struct trace_event_file *file,
int ret = 0;
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
- if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
- return -ENOSYS;
mutex_lock(&syscall_trace_lock);
- if (!tr->sys_refcount_exit)
- ret = register_trace_sys_exit(ftrace_syscall_exit, tr);
- if (!ret) {
- rcu_assign_pointer(tr->exit_syscall_files[num], file);
- tr->sys_refcount_exit++;
+ if (!tr->sys_refcount_exit) {
+ ret = register_trace_sys_enter(ftrace_syscall_exit, tr);
+ if (ret)
+ goto out_unlock;
}
+
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ rcu_assign_pointer(tr->exit_syscall_files[num], file);
+ }
+ tr->sys_refcount_exit++;
+
+out_unlock:
mutex_unlock(&syscall_trace_lock);
return ret;
}
@@ -463,12 +474,13 @@ static void unreg_event_syscall_exit(struct trace_event_file *file,
struct trace_array *tr = file->tr;
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
- if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
- return;
mutex_lock(&syscall_trace_lock);
tr->sys_refcount_exit--;
- RCU_INIT_POINTER(tr->exit_syscall_files[num], NULL);
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ RCU_INIT_POINTER(tr->exit_syscall_files[num], NULL);
+ }
if (!tr->sys_refcount_exit)
unregister_trace_sys_exit(ftrace_syscall_exit, tr);
mutex_unlock(&syscall_trace_lock);
@@ -477,14 +489,6 @@ static void unreg_event_syscall_exit(struct trace_event_file *file,
static int __init init_syscall_trace(struct trace_event_call *call)
{
int id;
- int num;
-
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
- if (num < 0 || num >= NR_syscalls) {
- pr_debug("syscall %s metadata not mapped, disabling ftrace event\n",
- ((struct syscall_metadata *)call->data)->name);
- return -ENOSYS;
- }
if (set_syscall_print_fmt(call) < 0)
return -ENOMEM;
@@ -547,7 +551,6 @@ void __init init_ftrace_syscalls(void)
if (!meta)
continue;
- meta->syscall_nr = i;
syscalls_metadata[i] = meta;
}
}
@@ -604,17 +607,23 @@ static int perf_sysenter_enable(struct trace_event_call *call)
int ret = 0;
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
-
mutex_lock(&syscall_trace_lock);
- if (!sys_perf_refcount_enter)
+ if (!sys_perf_refcount_enter) {
ret = register_trace_sys_enter(perf_syscall_enter, NULL);
- if (ret) {
- pr_info("event trace: Could not activate syscall entry trace point");
- } else {
- set_bit(num, enabled_perf_enter_syscalls);
- sys_perf_refcount_enter++;
+ if (ret) {
+ pr_info("event trace: Could not activate syscall entry trace point");
+ goto out_unlock;
+ }
+ }
+
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ set_bit(num, enabled_perf_enter_syscalls);
}
+ sys_perf_refcount_enter++;
+
+out_unlock:
mutex_unlock(&syscall_trace_lock);
return ret;
}
@@ -623,11 +632,13 @@ static void perf_sysenter_disable(struct trace_event_call *call)
{
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
-
mutex_lock(&syscall_trace_lock);
sys_perf_refcount_enter--;
- clear_bit(num, enabled_perf_enter_syscalls);
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ clear_bit(num, enabled_perf_enter_syscalls);
+ }
if (!sys_perf_refcount_enter)
unregister_trace_sys_enter(perf_syscall_enter, NULL);
mutex_unlock(&syscall_trace_lock);
@@ -675,17 +686,23 @@ static int perf_sysexit_enable(struct trace_event_call *call)
int ret = 0;
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
-
mutex_lock(&syscall_trace_lock);
- if (!sys_perf_refcount_exit)
+ if (!sys_perf_refcount_exit) {
ret = register_trace_sys_exit(perf_syscall_exit, NULL);
- if (ret) {
- pr_info("event trace: Could not activate syscall exit trace point");
- } else {
- set_bit(num, enabled_perf_exit_syscalls);
- sys_perf_refcount_exit++;
+ if (ret) {
+ pr_info("event trace: Could not activate syscall exit trace point");
+ goto out_unlock;
+ }
+ }
+
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ set_bit(num, enabled_perf_exit_syscalls);
}
+ sys_perf_refcount_exit++;
+
+out_unlock:
mutex_unlock(&syscall_trace_lock);
return ret;
}
@@ -694,11 +711,13 @@ static void perf_sysexit_disable(struct trace_event_call *call)
{
int num;
- num = ((struct syscall_metadata *)call->data)->syscall_nr;
-
mutex_lock(&syscall_trace_lock);
sys_perf_refcount_exit--;
- clear_bit(num, enabled_perf_exit_syscalls);
+ for (num = 0; num < NR_syscalls; num++) {
+ if (syscalls_metadata[num] &&
+ (syscalls_metadata[num] == call->data))
+ clear_bit(num, enabled_perf_exit_syscalls);
+ }
if (!sys_perf_refcount_exit)
unregister_trace_sys_exit(perf_syscall_exit, NULL);
mutex_unlock(&syscall_trace_lock);
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web