mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marcin Nowakowski <marcin.nowakowski@imgtec.com>
To: <linux-kernel@vger.kernel.org>
Cc: Marcin Nowakowski <marcin.nowakowski@imgtec.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	<linuxppc-dev@lists.ozlabs.org>
Subject: [PATCH v2 03/11] tracing/syscalls: add compat syscall metadata
Date: Fri, 16 Sep 2016 09:11:19 +0200	[thread overview]
Message-ID: <1474009887-7225-4-git-send-email-marcin.nowakowski@imgtec.com> (raw)
In-Reply-To: <1474009887-7225-1-git-send-email-marcin.nowakowski@imgtec.com>

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 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			= &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 fdda4af..8dd0fbf 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

  parent reply	other threads:[~2016-09-16  7:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-16  7:11 [PATCH v2 00/11] syscall/tracing: compat syscall support Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 01/11] tracing/syscalls: remove syscall_nr from syscall metadata Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 02/11] tracing/syscalls: add handling for compat tasks Marcin Nowakowski
2016-09-16  7:11 ` Marcin Nowakowski [this message]
2016-09-16  7:11 ` [PATCH v2 04/11] syscall/tracing: allow arch to override syscall_get_nr for ftrace Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 05/11] x86/tracing: fix compat syscall handling Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 06/11] s390/tracing: " Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 07/11] arm64/tracing: " Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 08/11] powerpc/tracing: " Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 09/11] tile/tracing: " Marcin Nowakowski
2016-09-16 10:42   ` kbuild test robot
2016-09-20 18:49   ` Chris Metcalf
2016-09-16  7:11 ` [PATCH v2 10/11] sparc/tracing: " Marcin Nowakowski
2016-09-16  7:11 ` [PATCH v2 11/11] parisc/tracing: " Marcin Nowakowski

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=1474009887-7225-4-git-send-email-marcin.nowakowski@imgtec.com \
    --to=marcin.nowakowski@imgtec.com \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=rostedt@goodmis.org \
    /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

all inboxes | Powered by JetHome®