Skip to contentSkip to conversation

tracing: Move tracepoint callbacks into DEFINE

PATCH Superseded Josh Stone 8 participants 70 messages Aug 18, 2009 – Aug 28, 2009

Subsystems (6)
x86 Tracing s390 ABI/API +2 more subsystems
lore
Share & tools
lore

Josh Stone

author
#0 lore raw

PATCH 1/1 tracing: Move tracepoint callbacks into DEFINE

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_WITH_CALLBACK which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_WITH_CALLBACK, so those events can also provide callbacks if needed.

---
 arch/x86/kernel/ptrace.c     |    4 ++--
 include/linux/tracepoint.h   |   41 +++++++++++++++--------------------------
 include/trace/define_trace.h |    5 +++++
 include/trace/ftrace.h       |    9 +++++++++
 include/trace/syscall.h      |   12 ++++--------
 kernel/tracepoint.c          |   15 +++++++++------
 6 files changed, 44 insertions(+), 42 deletions(-)
arch/x86/kernel/ptrace.c +2 -2
index 34dd6f1..692fc14 100644
@@ -37,8 +37,8 @@
 
 #include <trace/syscall.h>
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 #include "tls.h"
 
include/linux/tracepoint.h +15 -26

87 lines not on this page · raw message

include/trace/define_trace.h +5 -0
index f7a7ae1..82c623a 100644
@@ -26,6 +26,11 @@
 #define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
 	DEFINE_TRACE(name)
 
+#undef TRACE_EVENT_WITH_CALLBACK
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, tstruct,	\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_WITH_CALLBACK(name, reg, unreg)
+
 #undef DECLARE_TRACE
 #define DECLARE_TRACE(name, proto, args)	\
 	DEFINE_TRACE(name)
include/trace/ftrace.h +9 -0
index b250b06..61ed0ab 100644
@@ -42,6 +42,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+/* Callbacks are meaningless to ftrace. */
+#undef TRACE_EVENT_WITH_CALLBACK
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, tstruct,	\
+		assign, print, reg, unreg)			\
+	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
+		TP_STRUCT__entry(tstruct),			\
+		TP_fast_assign(assign),				\
+		TP_printk(print))
+
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 
include/trace/syscall.h +4 -8
index 0cb0362..49e7ec2 100644
@@ -11,18 +11,14 @@
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
+DECLARE_TRACE(syscall_enter,
 	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, id)
 );
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
+DECLARE_TRACE(syscall_exit,
 	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, ret)
 );
 
 /*
kernel/tracepoint.c +9 -6
index 35dd27a..1865c09 100644
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -581,15 +589,13 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 
-static DEFINE_MUTEX(regfunc_mutex);
-static int sys_tracepoint_refcount;
+static int sys_tracepoint_refcount; /* guarded by tracepoints_mutex */
 
 void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -598,7 +604,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -606,7 +611,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -615,6 +619,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 7 lines · Josh Stone

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

Quoted 8 lines

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_WITH_CALLBACK which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_WITH_CALLBACK, so those events can also provide callbacks if needed.

this makes sense...Ingo also suggested having the two high level tracepoints be 'TRACE_EVENT' style. That is we should be able to register with the syscall entry and get the *all* the syscall numbers and arguments, and likewise on exit we should be able to get *all* syscall exit return values. see:

http://marc.info/?l=linux-kernel&m=125008740803571&w=2

does this patch allow/do that?

thanks,

-Jason

author
#2 lore raw
Quoted 9 lines · Jason Baron

this makes sense...Ingo also suggested having the two high level tracepoints be 'TRACE_EVENT' style. That is we should be able to register with the syscall entry and get the *all* the syscall numbers and arguments, and likewise on exit we should be able to get *all* syscall exit return values. see:

http://marc.info/?l=linux-kernel&m=125008740803571&w=2

does this patch allow/do that?

It does allow this, and I am working on a patch to do it. There are a few naming conflicts between trace_syscalls.c and the stuff that ftrace generates for "TRACE_EVENT(syscall_enter, ...)", but I will post soon with a patch to resolve this.

Thanks,

Josh

author
#3 lore raw

PATCH 1/1 tracing: Create generic syscall TRACE_EVENTs

In reply to Josh Stone

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values.

The existing event_syscall_enter/exit trace_event structs are renamed to event_sys_enter/exit, so they don't conflict with the names generated automatically by ftrace.

---
 arch/s390/kernel/ptrace.c       |    3 ++
 arch/x86/kernel/ptrace.c        |    8 ++---
 include/linux/syscalls.h        |    4 +-
 include/trace/events/syscalls.h |   66 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   17 +---------
 kernel/trace/trace_syscalls.c   |    5 ++-
 6 files changed, 79 insertions(+), 24 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +3 -0
index 05f57cd..8730fa7 100644
@@ -51,6 +51,9 @@
 #include "compat_ptrace.h"
 #endif
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum s390_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
arch/x86/kernel/ptrace.c +3 -5
index 692fc14..530ff6f 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
include/linux/syscalls.h +2 -2
index 87d06c1..19b49fd 100644
@@ -187,7 +187,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
 	  event_enter_##sname = {					\
 		.name                   = "sys_enter"#sname,		\
 		.system                 = "syscalls",			\
-		.event                  = &event_syscall_enter,		\
+		.event                  = &event_sys_enter,		\
 		.raw_init		= init_enter_##sname,		\
 		.show_format		= ftrace_format_syscall,	\
 		.regfunc		= reg_event_syscall_enter,	\
@@ -223,7 +223,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
 	  event_exit_##sname = {					\
 		.name                   = "sys_exit"#sname,		\
 		.system                 = "syscalls",			\
-		.event                  = &event_syscall_exit,		\
+		.event                  = &event_sys_exit,		\
 		.raw_init		= init_exit_##sname,		\
 		.regfunc		= reg_event_syscall_exit,	\
 		.unregfunc		= unreg_event_syscall_exit,	\
include/trace/events/syscalls.h new file +66 -0

66 lines not on this page · raw message

include/trace/syscall.h +2 -15
index 49e7ec2..5181893 100644
@@ -8,19 +8,6 @@
 #include <asm/ptrace.h>
 
 
-extern void syscall_regfunc(void);
-extern void syscall_unregfunc(void);
-
-DECLARE_TRACE(syscall_enter,
-	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id)
-);
-
-DECLARE_TRACE(syscall_exit,
-	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret)
-);
-
 /*
  * A syscall entry in the ftrace syscalls array.
  *
@@ -45,8 +32,8 @@ extern struct syscall_metadata *syscall_nr_to_meta(int nr);
 extern int syscall_name_to_nr(char *name);
 void set_syscall_enter_id(int num, int id);
 void set_syscall_exit_id(int num, int id);
-extern struct trace_event event_syscall_enter;
-extern struct trace_event event_syscall_exit;
+extern struct trace_event event_sys_enter;
+extern struct trace_event event_sys_exit;
 extern int reg_event_syscall_enter(void *ptr);
 extern void unreg_event_syscall_enter(void *ptr);
 extern int reg_event_syscall_exit(void *ptr);
kernel/trace/trace_syscalls.c +3 -2
index f130dac..b174169 100644
@@ -1,4 +1,5 @@
 #include <trace/syscall.h>
+#include <trace/events/syscalls.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/perf_counter.h>
@@ -277,11 +278,11 @@ void unreg_event_syscall_exit(void *ptr)
 	mutex_unlock(&syscall_trace_lock);
 }
 
-struct trace_event event_syscall_enter = {
+struct trace_event event_sys_enter = {
 	.trace			= print_syscall_enter,
 };
 
-struct trace_event event_syscall_exit = {
+struct trace_event event_sys_exit = {
 	.trace			= print_syscall_exit,
 };
 
Signature · 1 line
1.6.2.5
#4 lore raw

Re: [PATCH] tracing: Create generic syscall TRACE_EVENTs

Quoted 8 lines · Josh Stone

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values.

The existing event_syscall_enter/exit trace_event structs are renamed to event_sys_enter/exit, so they don't conflict with the names generated automatically by ftrace.

It would be much better to see a sample output of these TRACE_EVENTs,

...

Quoted 11 lines
include/trace/events/syscalls.h new file +11 -0
+TRACE_EVENT_WITH_CALLBACK(syscall_enter,
+
+	TP_PROTO(struct pt_regs *regs, long id),
+
+	TP_ARGS(regs, id),
+
+	TP_STRUCT__entry(
+		__field(	long,	id		)
+		__array(	long,	args,	6	)
+	),
+

include/trace/events/syscalls.h line 36

Quoted 10 lines
include/trace/events/syscalls.h new file +10 -0
+	TP_fast_assign(
+		__entry->id	= id;
+		syscall_get_arguments(current, regs, 0, 6, __entry->args);
+	),
+
+	TP_printk("NR %ld (%ld, %ld, %ld, %ld, %ld, %ld)",
+		  __entry->id,
+		  __entry->args[0], __entry->args[1], __entry->args[2],
+		  __entry->args[3], __entry->args[4], __entry->args[5]),
+

so we'll see the what's the output if a syscall has less than 6 args.

And I guess it should be "(%lx, %lx, ..., %lx)"? Otherwise I think we'll see some negative values.

Quoted 2 lines
(quoted diff) +2 -0
+	syscall_regfunc, syscall_unregfunc
+);
author
#5 lore raw

Re: [PATCH] tracing: Create generic syscall TRACE_EVENTs

Quoted 5 lines · Li Zefan

It would be much better to see a sample output of these TRACE_EVENTs, so we'll see the what's the output if a syscall has less than 6 args.

And I guess it should be "(%lx, %lx, ..., %lx)"? Otherwise I think we'll see some negative values.

Thanks, you're right -- the args should be unsigned long. Whether they are hex or decimal doesn't matter to me, but I guess that does make pointers easier to spot.

Here's some output that I get on x86_64:

Quoted 10 lines
# tail trace
            tail-1106  [000] 113218.474657: syscall_enter: NR 2 (7f2d34dd38f0, 0, 7f2d35009010, 5, 4, ffffffffffffffb0)
            tail-1106  [000] 113218.474809: syscall_enter: NR 5 (3, 7f2d35009040, 7f2d35009040, 5, 4, ffffffffffffffb0)

            tail-1106  [000] 113218.474855: syscall_enter: NR 9 (0, 50d3ad0, 1, 2, 3, 0)

            tail-1106  [000] 113218.474946: syscall_enter: NR 3 (3, 7f2d2f9a0000, 5e22, 2, 3, 0)

            tail-1106  [000] 113218.475673: syscall_enter: NR 2 (7fff5e42a654, 0, 0, 7fff5e429600, 80, 3)

It's very raw indeed, but that's what Ingo asked for. :) The extra args show up as whatever happened to be in those registers.

Josh

#6 lore raw

Re: [PATCH] tracing: Create generic syscall TRACE_EVENTs

Quoted 18 lines · Josh Stone
Quoted 5 lines · Li Zefan

It would be much better to see a sample output of these TRACE_EVENTs, so we'll see the what's the output if a syscall has less than 6 args.

And I guess it should be "(%lx, %lx, ..., %lx)"? Otherwise I think we'll see some negative values.

Thanks, you're right -- the args should be unsigned long. Whether they are hex or decimal doesn't matter to me, but I guess that does make pointers easier to spot.

Here's some output that I get on x86_64:

Quoted 5 lines
# tail trace
            tail-1106  [000] 113218.474657: syscall_enter: NR 2 (7f2d34dd38f0, 0, 7f2d35009010, 5, 4, ffffffffffffffb0)
            tail-1106  [000] 113218.474809: syscall_enter: NR 5 (3, 7f2d35009040, 7f2d35009040, 5, 4, ffffffffffffffb0)
Quoted 8 lines
Quoted 5 lines
            tail-1106  [000] 113218.474855: syscall_enter: NR 9 (0, 50d3ad0, 1, 2, 3, 0)

            tail-1106  [000] 113218.474946: syscall_enter: NR 3 (3, 7f2d2f9a0000, 5e22, 2, 3, 0)

            tail-1106  [000] 113218.475673: syscall_enter: NR 2 (7fff5e42a654, 0, 0, 7fff5e429600, 80, 3)

It's very raw indeed, but that's what Ingo asked for. :) The extra args show up as whatever happened to be in those registers.

If the syscalls are handled as a single tracepoint, then they cannot really have per syscall properties.

The per syscall tracepoints on the other hand give very finegrained information.

Note that via the use of filters one can limit the generic tracepoint to only output certain syscall NRs, and only with certain parameters.

Ingo

#7 lore raw

Re: [PATCH] tracing: Create generic syscall TRACE_EVENTs

Quoted 27 lines · * Ingo Molnar ([email protected]) wrote:
Quoted 24 lines · Josh Stone
Quoted 5 lines · Li Zefan

It would be much better to see a sample output of these TRACE_EVENTs, so we'll see the what's the output if a syscall has less than 6 args.

And I guess it should be "(%lx, %lx, ..., %lx)"? Otherwise I think we'll see some negative values.

Thanks, you're right -- the args should be unsigned long. Whether they are hex or decimal doesn't matter to me, but I guess that does make pointers easier to spot.

Here's some output that I get on x86_64:

Quoted 10 lines
# tail trace
            tail-1106  [000] 113218.474657: syscall_enter: NR 2 (7f2d34dd38f0, 0, 7f2d35009010, 5, 4, ffffffffffffffb0)
            tail-1106  [000] 113218.474809: syscall_enter: NR 5 (3, 7f2d35009040, 7f2d35009040, 5, 4, ffffffffffffffb0)

            tail-1106  [000] 113218.474855: syscall_enter: NR 9 (0, 50d3ad0, 1, 2, 3, 0)

            tail-1106  [000] 113218.474946: syscall_enter: NR 3 (3, 7f2d2f9a0000, 5e22, 2, 3, 0)

            tail-1106  [000] 113218.475673: syscall_enter: NR 2 (7fff5e42a654, 0, 0, 7fff5e429600, 80, 3)
Quoted 9 lines
Quoted 2 lines

It's very raw indeed, but that's what Ingo asked for. :) The extra args show up as whatever happened to be in those registers.

If the syscalls are handled as a single tracepoint, then they cannot really have per syscall properties.

The per syscall tracepoints on the other hand give very finegrained information.

Hi Ingo,

Aiming to identify the event payload type with the event ID alone, I would recommend either:

- one tracepoint per syscall argument set types (e.g. same syscall prototype)
or
- one tracepoint per syscall (seems to be more straightforward)

Otherwise getting to fit a struct sockaddr into an integer might be cumbersome.

Thanks,

Mathieu

Quoted 5 lines

Note that via the use of filters one can limit the generic tracepoint to only output certain syscall NRs, and only with certain parameters.

Ingo

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
Acked-by on v1 1/1
#8 lore raw

Re: [PATCH] tracing: Create generic syscall TRACE_EVENTs

In reply to Josh Stone
Quoted 25 lines · Josh Stone

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values.

The existing event_syscall_enter/exit trace_event structs are renamed to event_sys_enter/exit, so they don't conflict with the names generated automatically by ftrace.

---
 arch/s390/kernel/ptrace.c       |    3 ++
 arch/x86/kernel/ptrace.c        |    8 ++---
 include/linux/syscalls.h        |    4 +-
 include/trace/events/syscalls.h |   66 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   17 +---------
 kernel/trace/trace_syscalls.c   |    5 ++-
 6 files changed, 79 insertions(+), 24 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +0 -0
index 05f57cd..8730fa7 100644

arch/s390/kernel/ptrace.c line 59

Quoted 9 lines
arch/s390/kernel/ptrace.c +3 -0
@@ -51,6 +51,9 @@
 #include "compat_ptrace.h"
 #endif
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum s390_regset {
 	REGSET_GENERAL,
 	REGSET_FP,

this will have to be rebased to remove the new s390 DECLARE_TRACE() calls here like x86.

Quoted 56 lines
arch/x86/kernel/ptrace.c +3 -5
index 692fc14..530ff6f 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
include/linux/syscalls.h +2 -2
index 87d06c1..19b49fd 100644
@@ -187,7 +187,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
 	  event_enter_##sname = {					\
 		.name                   = "sys_enter"#sname,		\
 		.system                 = "syscalls",			\
-		.event                  = &event_syscall_enter,		\
+		.event                  = &event_sys_enter,		\
 		.raw_init		= init_enter_##sname,		\
 		.show_format		= ftrace_format_syscall,	\
 		.regfunc		= reg_event_syscall_enter,	\
@@ -223,7 +223,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
 	  event_exit_##sname = {					\
 		.name                   = "sys_exit"#sname,		\
 		.system                 = "syscalls",			\
-		.event                  = &event_syscall_exit,		\
+		.event                  = &event_sys_exit,		\
 		.raw_init		= init_exit_##sname,		\
 		.regfunc		= reg_event_syscall_exit,	\
 		.unregfunc		= unreg_event_syscall_exit,	\
include/trace/events/syscalls.h new file +7 -0
new file mode 100644
index 0000000..75ccc61
@@ -0,0 +1,66 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM syscalls
+
+#if !defined(_TRACE_EVENTS_SYSCALL_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_EVENTS_SYSCALL_H
+
+#include <linux/tracepoint.h>

include/trace/events/syscalls.h line 17

Quoted 10 lines
include/trace/events/syscalls.h new file +10 -0
+
+#include <asm/ptrace.h>
+#include <asm/syscall.h>
+
+extern void syscall_regfunc(void);
+extern void syscall_unregfunc(void);
+
+
+TRACE_EVENT_WITH_CALLBACK(syscall_enter,
+

do we want to call this something like, 'syscall_enter_generic'? to make it more clear this is the high level syscall tracepoint. similar for exit.

Quoted 111 lines
include/trace/events/syscalls.h new file +49 -0
+	TP_PROTO(struct pt_regs *regs, long id),
+
+	TP_ARGS(regs, id),
+
+	TP_STRUCT__entry(
+		__field(	long,	id		)
+		__array(	long,	args,	6	)
+	),
+
+	TP_fast_assign(
+		__entry->id	= id;
+		syscall_get_arguments(current, regs, 0, 6, __entry->args);
+	),
+
+	TP_printk("NR %ld (%ld, %ld, %ld, %ld, %ld, %ld)",
+		  __entry->id,
+		  __entry->args[0], __entry->args[1], __entry->args[2],
+		  __entry->args[3], __entry->args[4], __entry->args[5]),
+
+	syscall_regfunc, syscall_unregfunc
+);
+
+TRACE_EVENT_WITH_CALLBACK(syscall_exit,
+
+	TP_PROTO(struct pt_regs *regs, long ret),
+
+	TP_ARGS(regs, ret),
+
+	TP_STRUCT__entry(
+		__field(	long,	id		)
+		__field(	long,	ret		)
+	),
+
+	TP_fast_assign(
+		__entry->id	= syscall_get_nr(current, regs);
+		__entry->ret	= ret;
+	),
+
+	TP_printk("NR %ld = %ld",
+		  __entry->id, __entry->ret),
+
+	syscall_regfunc, syscall_unregfunc
+);
+
+#endif /* _TRACE_EVENTS_SYSCALL_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
+
include/trace/syscall.h +2 -15
index 49e7ec2..5181893 100644
@@ -8,19 +8,6 @@
 #include <asm/ptrace.h>
 
 
-extern void syscall_regfunc(void);
-extern void syscall_unregfunc(void);
-
-DECLARE_TRACE(syscall_enter,
-	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id)
-);
-
-DECLARE_TRACE(syscall_exit,
-	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret)
-);
-
 /*
  * A syscall entry in the ftrace syscalls array.
  *
@@ -45,8 +32,8 @@ extern struct syscall_metadata *syscall_nr_to_meta(int nr);
 extern int syscall_name_to_nr(char *name);
 void set_syscall_enter_id(int num, int id);
 void set_syscall_exit_id(int num, int id);
-extern struct trace_event event_syscall_enter;
-extern struct trace_event event_syscall_exit;
+extern struct trace_event event_sys_enter;
+extern struct trace_event event_sys_exit;
 extern int reg_event_syscall_enter(void *ptr);
 extern void unreg_event_syscall_enter(void *ptr);
 extern int reg_event_syscall_exit(void *ptr);
kernel/trace/trace_syscalls.c +3 -2
index f130dac..b174169 100644
@@ -1,4 +1,5 @@
 #include <trace/syscall.h>
+#include <trace/events/syscalls.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/perf_counter.h>
@@ -277,11 +278,11 @@ void unreg_event_syscall_exit(void *ptr)
 	mutex_unlock(&syscall_trace_lock);
 }
 
-struct trace_event event_syscall_enter = {
+struct trace_event event_sys_enter = {
 	.trace			= print_syscall_enter,
 };
 
-struct trace_event event_syscall_exit = {
+struct trace_event event_sys_exit = {
 	.trace			= print_syscall_exit,
 };
 
Signature · 1 line
1.6.2.5

looks good.

thanks,

-Jason

#9 lore raw

Re: [PATCH] tracing: Create generic syscall TRACE_EVENTs

Quoted 101 lines · Jason Baron
Quoted 25 lines · Josh Stone

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values.

The existing event_syscall_enter/exit trace_event structs are renamed to event_sys_enter/exit, so they don't conflict with the names generated automatically by ftrace.

---
 arch/s390/kernel/ptrace.c       |    3 ++
 arch/x86/kernel/ptrace.c        |    8 ++---
 include/linux/syscalls.h        |    4 +-
 include/trace/events/syscalls.h |   66 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   17 +---------
 kernel/trace/trace_syscalls.c   |    5 ++-
 6 files changed, 79 insertions(+), 24 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +0 -0
index 05f57cd..8730fa7 100644

arch/s390/kernel/ptrace.c line 59

Quoted 9 lines
arch/s390/kernel/ptrace.c +3 -0
@@ -51,6 +51,9 @@
 #include "compat_ptrace.h"
 #endif
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum s390_regset {
 	REGSET_GENERAL,
 	REGSET_FP,

this will have to be rebased to remove the new s390 DECLARE_TRACE() calls here like x86.

Quoted 62 lines
arch/x86/kernel/ptrace.c +3 -5
index 692fc14..530ff6f 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
include/linux/syscalls.h +2 -2
index 87d06c1..19b49fd 100644
@@ -187,7 +187,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
 	  event_enter_##sname = {					\
 		.name                   = "sys_enter"#sname,		\
 		.system                 = "syscalls",			\
-		.event                  = &event_syscall_enter,		\
+		.event                  = &event_sys_enter,		\
 		.raw_init		= init_enter_##sname,		\
 		.show_format		= ftrace_format_syscall,	\
 		.regfunc		= reg_event_syscall_enter,	\
@@ -223,7 +223,7 @@ static void prof_sysexit_disable_##sname(struct ftrace_event_call *event_call) \
 	  event_exit_##sname = {					\
 		.name                   = "sys_exit"#sname,		\
 		.system                 = "syscalls",			\
-		.event                  = &event_syscall_exit,		\
+		.event                  = &event_sys_exit,		\
 		.raw_init		= init_exit_##sname,		\
 		.regfunc		= reg_event_syscall_exit,	\
 		.unregfunc		= unreg_event_syscall_exit,	\
include/trace/events/syscalls.h new file +13 -0
new file mode 100644
index 0000000..75ccc61
@@ -0,0 +1,66 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM syscalls
+
+#if !defined(_TRACE_EVENTS_SYSCALL_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_EVENTS_SYSCALL_H
+
+#include <linux/tracepoint.h>
+
+#include <asm/ptrace.h>
+#include <asm/syscall.h>
+
+extern void syscall_regfunc(void);
+extern void syscall_unregfunc(void);
Quoted 8 lines

include/trace/events/syscalls.h line 17

Quoted 4 lines
include/trace/events/syscalls.h new file +4 -0
+
+
+TRACE_EVENT_WITH_CALLBACK(syscall_enter,
+

do we want to call this something like, 'syscall_enter_generic'? to make it more clear this is the high level syscall tracepoint. similar for exit.

Yeah, that would be indeed less confusing.

#10 lore raw
In reply to Josh Stone
Quoted 58 lines · Josh Stone
kernel/tracepoint.c +9 -5
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -581,15 +589,13 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 
-static DEFINE_MUTEX(regfunc_mutex);
-static int sys_tracepoint_refcount;
+static int sys_tracepoint_refcount; /* guarded by tracepoints_mutex */
 
 void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -598,7 +604,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -606,7 +611,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);

kernel/tracepoint.c void syscall_unregfunc(void) · line 623

Quoted 6 lines
kernel/tracepoint.c +0 -1
@@ -615,6 +619,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif

if we disable, CONFIG_FTRACE_SYSCALLS, then we get undefined references to syscall_regfunc, and syscall_unregfunc. So, i think we just need to remove the 'CONFIG_FTRACE_SYSCALLS' ifdef here.

thanks,

-Jason

author
#11 lore raw
Quoted 54 lines · Jason Baron
Quoted 53 lines · Josh Stone
kernel/tracepoint.c +9 -4
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -581,15 +589,13 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 
-static DEFINE_MUTEX(regfunc_mutex);
-static int sys_tracepoint_refcount;
+static int sys_tracepoint_refcount; /* guarded by tracepoints_mutex */
 
 void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -598,7 +604,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -606,7 +611,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
Quoted 15 lines

kernel/tracepoint.c void syscall_unregfunc(void) · line 623

Quoted 11 lines
kernel/tracepoint.c +0 -2
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -615,6 +619,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif

if we disable, CONFIG_FTRACE_SYSCALLS, then we get undefined references to syscall_regfunc, and syscall_unregfunc. So, i think we just need to remove the 'CONFIG_FTRACE_SYSCALLS' ifdef here.

This CONFIG check was added by commit 60d970c2 to deal with missing TIF_SYSCALL_FTRACE. Perhaps the functions should just have their bodies #ifdef'ed?

Josh

author
#12 lore raw

PATCH v2 1/2 tracing: Move tracepoint callbacks into DEFINE

In reply to Josh Stone

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_WITH_CALLBACK which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_WITH_CALLBACK, so those events can also provide callbacks if needed.

---
 arch/s390/kernel/ptrace.c    |    4 +-
 arch/x86/kernel/ptrace.c     |    4 +-
 include/linux/tracepoint.h   |   46 ++++++++++++++++-------------------------
 include/trace/define_trace.h |    5 ++++
 include/trace/ftrace.h       |    9 ++++++++
 include/trace/syscall.h      |   12 +++-------
 kernel/tracepoint.c          |   18 +++++++++++-----
 7 files changed, 52 insertions(+), 46 deletions(-)
arch/s390/kernel/ptrace.c +2 -2
index c5e87d8..26194b0 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 enum s390_regset {
 	REGSET_GENERAL,
arch/x86/kernel/ptrace.c +2 -2
index 34dd6f1..692fc14 100644
@@ -37,8 +37,8 @@
 
 #include <trace/syscall.h>
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 #include "tls.h"
 
include/linux/tracepoint.h +18 -28

97 lines not on this page · raw message

include/trace/define_trace.h +5 -0
index f7a7ae1..82c623a 100644
@@ -26,6 +26,11 @@
 #define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
 	DEFINE_TRACE(name)
 
+#undef TRACE_EVENT_WITH_CALLBACK
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, tstruct,	\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_WITH_CALLBACK(name, reg, unreg)
+
 #undef DECLARE_TRACE
 #define DECLARE_TRACE(name, proto, args)	\
 	DEFINE_TRACE(name)
include/trace/ftrace.h +9 -0
index 1274002..7b9738c 100644
@@ -42,6 +42,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+/* Callbacks are meaningless to ftrace. */
+#undef TRACE_EVENT_WITH_CALLBACK
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, tstruct,	\
+		assign, print, reg, unreg)			\
+	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
+		TP_STRUCT__entry(tstruct),			\
+		TP_fast_assign(assign),				\
+		TP_printk(print))
+
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 
include/trace/syscall.h +4 -8
index 9661dd4..c10e1f5 100644
@@ -11,18 +11,14 @@
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
+DECLARE_TRACE(syscall_enter,
 	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, id)
 );
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
+DECLARE_TRACE(syscall_exit,
 	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, ret)
 );
 
 /*
kernel/tracepoint.c +12 -6
index 35dd27a..98fc3ac 100644
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -581,15 +589,13 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 
-static DEFINE_MUTEX(regfunc_mutex);
-static int sys_tracepoint_refcount;
+static int sys_tracepoint_refcount; /* guarded by tracepoints_mutex */
 
 void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -598,7 +604,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -606,7 +611,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -615,6 +619,8 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
+#else
+void syscall_regfunc(void) {}
+void syscall_unregfunc(void) {}
 #endif
Signature · 1 line
1.6.2.5
author
#13 lore raw

PATCH v2 2/2 tracing: Create generic syscall TRACE_EVENTs

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values. These generic events are also renamed to sys_enter/exit, so they're more closely aligned to the specific sys_enter_foo events.

---
 arch/s390/kernel/ptrace.c       |    8 ++--
 arch/x86/kernel/ptrace.c        |   12 +++----
 include/trace/events/syscalls.h |   66 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   13 --------
 kernel/trace/trace_syscalls.c   |   17 +++++-----
 5 files changed, 84 insertions(+), 32 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +4 -4
index 26194b0..8e578a9 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
 
 enum s390_regset {
 	REGSET_GENERAL,
@@ -665,7 +665,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_enter(regs, regs->gprs[2]);
+		trace_sys_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
 		audit_syscall_entry(is_compat_task() ?
@@ -683,7 +683,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 				   regs->gprs[2]);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_exit(regs, regs->gprs[2]);
+		trace_sys_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
arch/x86/kernel/ptrace.c +5 -7
index 692fc14..dc87a04 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
@@ -1501,7 +1499,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 		ret = -1L;
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_enter(regs, regs->orig_ax);
+		trace_sys_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
 		if (IS_IA32)
@@ -1527,7 +1525,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_exit(regs, regs->ax);
+		trace_sys_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
include/trace/events/syscalls.h new file +66 -0

66 lines not on this page · raw message

include/trace/syscall.h +0 -13
index c10e1f5..5dc283b 100644
@@ -8,19 +8,6 @@
 #include <asm/ptrace.h>
 
 
-extern void syscall_regfunc(void);
-extern void syscall_unregfunc(void);
-
-DECLARE_TRACE(syscall_enter,
-	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id)
-);
-
-DECLARE_TRACE(syscall_exit,
-	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret)
-);
-
 /*
  * A syscall entry in the ftrace syscalls array.
  *
kernel/trace/trace_syscalls.c +9 -8
index 46c1b97..2698fe4 100644
@@ -1,4 +1,5 @@
 #include <trace/syscall.h>
+#include <trace/events/syscalls.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/perf_counter.h>
@@ -286,7 +287,7 @@ int reg_event_syscall_enter(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_enter)
-		ret = register_trace_syscall_enter(ftrace_syscall_enter);
+		ret = register_trace_sys_enter(ftrace_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -311,7 +312,7 @@ void unreg_event_syscall_enter(void *ptr)
 	sys_refcount_enter--;
 	clear_bit(num, enabled_enter_syscalls);
 	if (!sys_refcount_enter)
-		unregister_trace_syscall_enter(ftrace_syscall_enter);
+		unregister_trace_sys_enter(ftrace_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -327,7 +328,7 @@ int reg_event_syscall_exit(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_exit)
-		ret = register_trace_syscall_exit(ftrace_syscall_exit);
+		ret = register_trace_sys_exit(ftrace_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall exit trace point");
@@ -352,7 +353,7 @@ void unreg_event_syscall_exit(void *ptr)
 	sys_refcount_exit--;
 	clear_bit(num, enabled_exit_syscalls);
 	if (!sys_refcount_exit)
-		unregister_trace_syscall_exit(ftrace_syscall_exit);
+		unregister_trace_sys_exit(ftrace_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -418,7 +419,7 @@ int reg_prof_syscall_enter(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_enter)
-		ret = register_trace_syscall_enter(prof_syscall_enter);
+		ret = register_trace_sys_enter(prof_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -442,7 +443,7 @@ void unreg_prof_syscall_enter(char *name)
 	sys_prof_refcount_enter--;
 	clear_bit(num, enabled_prof_enter_syscalls);
 	if (!sys_prof_refcount_enter)
-		unregister_trace_syscall_enter(prof_syscall_enter);
+		unregister_trace_sys_enter(prof_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -479,7 +480,7 @@ int reg_prof_syscall_exit(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_exit)
-		ret = register_trace_syscall_exit(prof_syscall_exit);
+		ret = register_trace_sys_exit(prof_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -503,7 +504,7 @@ void unreg_prof_syscall_exit(char *name)
 	sys_prof_refcount_exit--;
 	clear_bit(num, enabled_prof_exit_syscalls);
 	if (!sys_prof_refcount_exit)
-		unregister_trace_syscall_exit(prof_syscall_exit);
+		unregister_trace_sys_exit(prof_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
Signature · 1 line
1.6.2.5
#14 lore raw

Re: [PATCH v2 2/2] tracing: Create generic syscall TRACE_EVENTs

Quoted 101 lines · Josh Stone

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values. These generic events are also renamed to sys_enter/exit, so they're more closely aligned to the specific sys_enter_foo events.

---
 arch/s390/kernel/ptrace.c       |    8 ++--
 arch/x86/kernel/ptrace.c        |   12 +++----
 include/trace/events/syscalls.h |   66 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   13 --------
 kernel/trace/trace_syscalls.c   |   17 +++++-----
 5 files changed, 84 insertions(+), 32 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +4 -4
index 26194b0..8e578a9 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
 
 enum s390_regset {
 	REGSET_GENERAL,
@@ -665,7 +665,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_enter(regs, regs->gprs[2]);
+		trace_sys_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
 		audit_syscall_entry(is_compat_task() ?
@@ -683,7 +683,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 				   regs->gprs[2]);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_exit(regs, regs->gprs[2]);
+		trace_sys_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
arch/x86/kernel/ptrace.c +5 -7
index 692fc14..dc87a04 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
@@ -1501,7 +1499,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 		ret = -1L;
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_enter(regs, regs->orig_ax);
+		trace_sys_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
 		if (IS_IA32)
@@ -1527,7 +1525,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
-		trace_syscall_exit(regs, regs->ax);
+		trace_sys_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
include/trace/events/syscalls.h new file +6 -0
new file mode 100644
index 0000000..9cd78fc
@@ -0,0 +1,66 @@
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM syscalls
+
+#if !defined(_TRACE_EVENTS_SYSCALLS_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_EVENTS_SYSCALLS_H
+

include/trace/events/syscalls.h line 16

Quoted 10 lines
include/trace/events/syscalls.h new file +10 -0
+#include <linux/tracepoint.h>
+
+#include <asm/ptrace.h>
+#include <asm/syscall.h>
+
+extern void syscall_regfunc(void);
+extern void syscall_unregfunc(void);
+
+
+TRACE_EVENT_WITH_CALLBACK(sys_enter,

don't we want to change this to something like 'sys_enter_generic'? otherwise, looks good.

thanks,

-Jason

author
#15 lore raw

Re: [PATCH v2 2/2] tracing: Create generic syscall TRACE_EVENTs

Quoted 4 lines · Jason Baron
Quoted 1 line

+TRACE_EVENT_WITH_CALLBACK(sys_enter,

don't we want to change this to something like 'sys_enter_generic'? otherwise, looks good.

Since all of the specific events are named "sys_enter_foo", I thought that it would be clear that an unadorned "sys_enter" was the more generic syscall event. Calling it "sys_enter_generic" seems to me by convention to mean a system call named "generic".

I don't want to bikeshed this though -- if you still think "sys_enter_generic" is better, then I'll change it.

Thanks,

Josh

#16 lore raw

Re: [PATCH v2 2/2] tracing: Create generic syscall TRACE_EVENTs

Quoted 6 lines · Josh Stone
Quoted 4 lines · Jason Baron
Quoted 1 line

+TRACE_EVENT_WITH_CALLBACK(sys_enter,

don't we want to change this to something like 'sys_enter_generic'? otherwise, looks good.

Quoted 8 lines

Since all of the specific events are named "sys_enter_foo", I thought that it would be clear that an unadorned "sys_enter" was the more generic syscall event. Calling it "sys_enter_generic" seems to me by convention to mean a system call named "generic".

I don't want to bikeshed this though -- if you still think "sys_enter_generic" is better, then I'll change it.

no I don't feel strongly about it...whatever the consensus is...

thanks,

-Jason

#17 lore raw
In reply to Josh Stone
Quoted 8 lines · Josh Stone

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

Quoted 8 lines

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_WITH_CALLBACK which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_WITH_CALLBACK, so those events can also provide callbacks if needed.

i think something shorter would be nicer, such as:

DECLARE_TRACE_FN
TRACE_EVENT_FN

Ingo

author
#18 lore raw
Quoted 17 lines · Ingo Molnar
Quoted 14 lines · Josh Stone

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_WITH_CALLBACK which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

Quoted 7 lines
Quoted 2 lines

This also introduces TRACE_EVENT_WITH_CALLBACK, so those events can also provide callbacks if needed.

i think something shorter would be nicer, such as:

DECLARE_TRACE_FN
TRACE_EVENT_FN

Well I took out the DECLARE_TRACE_ part, but sure, DEFINE_TRACE_FN and TRACE_EVENT_FN sound fine to me.

Josh

#19 lore raw
In reply to Josh Stone
Quoted 288 lines · Josh Stone

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_WITH_CALLBACK which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_WITH_CALLBACK, so those events can also provide callbacks if needed.

---
 arch/s390/kernel/ptrace.c    |    4 +-
 arch/x86/kernel/ptrace.c     |    4 +-
 include/linux/tracepoint.h   |   46 ++++++++++++++++-------------------------
 include/trace/define_trace.h |    5 ++++
 include/trace/ftrace.h       |    9 ++++++++
 include/trace/syscall.h      |   12 +++-------
 kernel/tracepoint.c          |   18 +++++++++++-----
 7 files changed, 52 insertions(+), 46 deletions(-)
arch/s390/kernel/ptrace.c +2 -2
index c5e87d8..26194b0 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 enum s390_regset {
 	REGSET_GENERAL,
arch/x86/kernel/ptrace.c +2 -2
index 34dd6f1..692fc14 100644
@@ -37,8 +37,8 @@
 
 #include <trace/syscall.h>
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_WITH_CALLBACK(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_WITH_CALLBACK(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 #include "tls.h"
 
include/linux/tracepoint.h +18 -28
index 5984ed0..3604b44 100644
@@ -23,6 +23,8 @@ struct tracepoint;
 struct tracepoint {
 	const char *name;		/* Tracepoint name */
 	int state;			/* State. */
+	void (*regfunc)(void);
+	void (*unregfunc)(void);
 	void **funcs;
 } __attribute__((aligned(32)));		/*
 					 * Aligned on 32 bytes because it is
@@ -60,10 +62,8 @@ struct tracepoint {
  * Make sure the alignment of the structure in the __tracepoints section will
  * not add unwanted padding between the beginning of the section and the
  * structure. Force alignment to the same alignment as the section start.
- * An optional set of (un)registration functions can be passed to perform any
- * additional (un)registration work.
  */
-#define DECLARE_TRACE_WITH_CALLBACK(name, proto, args, reg, unreg)	\
+#define DECLARE_TRACE(name, proto, args)				\
 	extern struct tracepoint __tracepoint_##name;			\
 	static inline void trace_##name(proto)				\
 	{								\
@@ -73,36 +73,23 @@ struct tracepoint {
 	}								\
 	static inline int register_trace_##name(void (*probe)(proto))	\
 	{								\
-		int ret;						\
-		void (*func)(void) = reg;				\
-									\
-		ret = tracepoint_probe_register(#name, (void *)probe);	\
-		if (func && !ret)					\
-			func();						\
-		return ret;						\
+		return tracepoint_probe_register(#name, (void *)probe);	\
 	}								\
 	static inline int unregister_trace_##name(void (*probe)(proto))	\
 	{								\
-		int ret;						\
-		void (*func)(void) = unreg;				\
-									\
-		ret = tracepoint_probe_unregister(#name, (void *)probe);\
-		if (func && !ret)					\
-			func();						\
-		return ret;						\
+		return tracepoint_probe_unregister(#name, (void *)probe);\
 	}
 
 
-#define DECLARE_TRACE(name, proto, args)				 \
-	DECLARE_TRACE_WITH_CALLBACK(name, TP_PROTO(proto), TP_ARGS(args),\
-					NULL, NULL);
-
-#define DEFINE_TRACE(name)						\
+#define DEFINE_TRACE_WITH_CALLBACK(name, reg, unreg)			\
 	static const char __tpstrtab_##name[]				\
 	__attribute__((section("__tracepoints_strings"))) = #name;	\
 	struct tracepoint __tracepoint_##name				\
 	__attribute__((section("__tracepoints"), aligned(32))) =	\
-		{ __tpstrtab_##name, 0, NULL }
+		{ __tpstrtab_##name, 0, reg, unreg, NULL }
+
+#define DEFINE_TRACE(name)						\
+	DEFINE_TRACE_WITH_CALLBACK(name, NULL, NULL);
 
 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)				\
 	EXPORT_SYMBOL_GPL(__tracepoint_##name)
@@ -113,7 +100,7 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
 	struct tracepoint *end);
 
 #else /* !CONFIG_TRACEPOINTS */
-#define DECLARE_TRACE_WITH_CALLBACK(name, proto, args, reg, unreg)	\
+#define DECLARE_TRACE(name, proto, args)				\
 	static inline void _do_trace_##name(struct tracepoint *tp, proto) \
 	{ }								\
 	static inline void trace_##name(proto)				\
@@ -127,10 +114,7 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
 		return -ENOSYS;						\
 	}
 
-#define DECLARE_TRACE(name, proto, args)				 \
-	DECLARE_TRACE_WITH_CALLBACK(name, TP_PROTO(proto), TP_ARGS(args),\
-					NULL, NULL);
-
+#define DEFINE_TRACE_WITH_CALLBACK(name, reg, unreg)
 #define DEFINE_TRACE(name)
 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
 #define EXPORT_TRACEPOINT_SYMBOL(name)
@@ -282,10 +266,16 @@ static inline void tracepoint_synchronize_unregister(void)
  * can also by used by generic instrumentation like SystemTap), and
  * it is also used to expose a structured trace record in
  * /sys/kernel/debug/tracing/events/.
+ *
+ * A set of (un)registration functions can be passed to the variant
+ * TRACE_EVENT_WITH_CALLBACK to perform any (un)registration work.
  */
 
 #define TRACE_EVENT(name, proto, args, struct, assign, print)	\
 	DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, struct,	\
+		assign, print, reg, unreg)			\
+	DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
 #endif
 
 #endif
include/trace/define_trace.h +5 -0
index f7a7ae1..82c623a 100644
@@ -26,6 +26,11 @@
 #define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
 	DEFINE_TRACE(name)
 
+#undef TRACE_EVENT_WITH_CALLBACK
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, tstruct,	\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_WITH_CALLBACK(name, reg, unreg)
+
 #undef DECLARE_TRACE
 #define DECLARE_TRACE(name, proto, args)	\
 	DEFINE_TRACE(name)
include/trace/ftrace.h +9 -0
index 1274002..7b9738c 100644
@@ -42,6 +42,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+/* Callbacks are meaningless to ftrace. */
+#undef TRACE_EVENT_WITH_CALLBACK
+#define TRACE_EVENT_WITH_CALLBACK(name, proto, args, tstruct,	\
+		assign, print, reg, unreg)			\
+	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
+		TP_STRUCT__entry(tstruct),			\
+		TP_fast_assign(assign),				\
+		TP_printk(print))
+
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 
include/trace/syscall.h +4 -8
index 9661dd4..c10e1f5 100644
@@ -11,18 +11,14 @@
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
+DECLARE_TRACE(syscall_enter,
 	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, id)
 );
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
+DECLARE_TRACE(syscall_exit,
 	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, ret)
 );
 
 /*
kernel/tracepoint.c +9 -5
index 35dd27a..98fc3ac 100644
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -581,15 +589,13 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 
-static DEFINE_MUTEX(regfunc_mutex);
-static int sys_tracepoint_refcount;
+static int sys_tracepoint_refcount; /* guarded by tracepoints_mutex */
 
 void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -598,7 +604,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -606,7 +611,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);

kernel/tracepoint.c void syscall_unregfunc(void) · line 626

Quoted 9 lines
kernel/tracepoint.c +3 -1
@@ -615,6 +619,8 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
+#else
+void syscall_regfunc(void) {}
+void syscall_unregfunc(void) {}
 #endif

hi,

this means that when CONFIG_EVENT_TRACING is set, the 'generic' syscall enter/exit will show up as events in the debugfs, but enabling them wouldn't do anything. I think we should simply drop the 'CONFIG_FTRACE_SYSCALLS' 'ifdef' and 'else' clause. That will give us what we want - tying these callbacks directly to tracepoint.

thanks,

-Jason

author
#20 lore raw
Quoted 5 lines · Jason Baron

this means that when CONFIG_EVENT_TRACING is set, the 'generic' syscall enter/exit will show up as events in the debugfs, but enabling them wouldn't do anything. I think we should simply drop the 'CONFIG_FTRACE_SYSCALLS' 'ifdef' and 'else' clause. That will give us what we want - tying these callbacks directly to tracepoint.

But only x86 and s390 have TIF_SYSCALL_FTRACE, while kernel/tracepoint.c must still compile everywhere that has CONFIG_TRACEPOINTS=y.

Maybe it would be better to make that #ifdef TIF_SYSCALL_FTRACE, and then also #ifdef the TRACE_EVENT declaration, so it will only show up on kernels that actually support it.

Also, since this event is now usable outside of ftrace, would you object to renaming the flag TIF_SYSCALL_TRACEPOINT?

Josh

#21 lore raw
Quoted 10 lines · Josh Stone
Quoted 5 lines · Jason Baron

this means that when CONFIG_EVENT_TRACING is set, the 'generic' syscall enter/exit will show up as events in the debugfs, but enabling them wouldn't do anything. I think we should simply drop the 'CONFIG_FTRACE_SYSCALLS' 'ifdef' and 'else' clause. That will give us what we want - tying these callbacks directly to tracepoint.

But only x86 and s390 have TIF_SYSCALL_FTRACE, while kernel/tracepoint.c must still compile everywhere that has CONFIG_TRACEPOINTS=y.

ok.

Quoted 4 lines

Maybe it would be better to make that #ifdef TIF_SYSCALL_FTRACE, and then also #ifdef the TRACE_EVENT declaration, so it will only show up on kernels that actually support it.

hmm...maybe then we move these functions to an arch specific file, such as arch/x86{s390}/kernel/ftrace.c, making the code contigent on CONFIG_TRACEPOINTS? (I think that required less ifdefs...).

Quoted 3 lines

Also, since this event is now usable outside of ftrace, would you object to renaming the flag TIF_SYSCALL_TRACEPOINT?

sure.

thanks,

-Jason

#22 lore raw
Quoted 14 lines · Jason Baron
Quoted 10 lines · Josh Stone
Quoted 5 lines · Jason Baron

this means that when CONFIG_EVENT_TRACING is set, the 'generic' syscall enter/exit will show up as events in the debugfs, but enabling them wouldn't do anything. I think we should simply drop the 'CONFIG_FTRACE_SYSCALLS' 'ifdef' and 'else' clause. That will give us what we want - tying these callbacks directly to tracepoint.

But only x86 and s390 have TIF_SYSCALL_FTRACE, while kernel/tracepoint.c must still compile everywhere that has CONFIG_TRACEPOINTS=y.

ok.

Quoted 8 lines
Quoted 4 lines

Maybe it would be better to make that #ifdef TIF_SYSCALL_FTRACE, and then also #ifdef the TRACE_EVENT declaration, so it will only show up on kernels that actually support it.

hmm...maybe then we move these functions to an arch specific file, such as arch/x86{s390}/kernel/ftrace.c, making the code contigent on CONFIG_TRACEPOINTS? (I think that required less ifdefs...).

But the code of these functions is generic and should then keep beeing factorized.

We could put them in kernel/trace/trace_syscalls.c and keep ftrace related things inside CONFIG_TRACE_SYSCALLS and the above inside CONFIG_TRACEPOINT + CONFIG_HAVE_SYSCALL_TRACING (then also change the Makefile).

Or if you find that too dirty, may be create a separate file in kernel/trace/.

Quoted 10 lines
Quoted 4 lines

Also, since this event is now usable outside of ftrace, would you object to renaming the flag TIF_SYSCALL_TRACEPOINT?

sure.

thanks,

-Jason

#23 lore raw
In reply to Josh Stone
Quoted 7 lines · Josh Stone
Quoted 5 lines · Jason Baron

this means that when CONFIG_EVENT_TRACING is set, the 'generic' syscall enter/exit will show up as events in the debugfs, but enabling them wouldn't do anything. I think we should simply drop the 'CONFIG_FTRACE_SYSCALLS' 'ifdef' and 'else' clause. That will give us what we want - tying these callbacks directly to tracepoint.

Quoted 6 lines

But only x86 and s390 have TIF_SYSCALL_FTRACE, while kernel/tracepoint.c must still compile everywhere that has CONFIG_TRACEPOINTS=y.

Maybe it would be better to make that #ifdef TIF_SYSCALL_FTRACE, and then also #ifdef the TRACE_EVENT declaration, so it will only show up on kernels that actually support it.

Instead of testing TIF_SYSCALL_FTRACE, I'd suggest testing HAVE_FTRACE_SYSCALLS. This makes more sense and is more verbose wrt its role in the conditionnal definition, given its macro name.

Quoted 4 lines

Also, since this event is now usable outside of ftrace, would you object to renaming the flag TIF_SYSCALL_TRACEPOINT?

Josh

author
#24 lore raw

v3 cover tracing: tweaks for generic syscall events

In reply to Josh Stone

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
---
 arch/s390/include/asm/thread_info.h |    4 +-
 arch/s390/kernel/entry.S            |    2 +-
 arch/s390/kernel/entry64.S          |    2 +-
 arch/s390/kernel/ptrace.c           |   51 +++++++++++++++++++++++---
 arch/x86/include/asm/thread_info.h  |   13 ++++---
 arch/x86/kernel/ptrace.c            |   53 +++++++++++++++++++++++----
 include/linux/tracepoint.h          |   46 +++++++++--------------
 include/trace/define_trace.h        |    5 +++
 include/trace/events/syscalls.h     |   68 +++++++++++++++++++++++++++++++++++
 include/trace/ftrace.h              |    9 +++++
 include/trace/syscall.h             |   17 ---------
 kernel/trace/trace_syscalls.c       |   17 +++++----
 kernel/tracepoint.c                 |   48 ++++--------------------
 13 files changed, 218 insertions(+), 117 deletions(-)
author
#25 lore raw

PATCH v3 1/4 tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 arch/s390/include/asm/thread_info.h |    4 ++--
 arch/s390/kernel/entry.S            |    2 +-
 arch/s390/kernel/entry64.S          |    2 +-
 arch/s390/kernel/ptrace.c           |    4 ++--
 arch/x86/include/asm/thread_info.h  |   13 +++++++------
 arch/x86/kernel/ptrace.c            |    4 ++--
 kernel/tracepoint.c                 |    4 ++--
 7 files changed, 17 insertions(+), 16 deletions(-)
arch/s390/include/asm/thread_info.h +2 -2
index ba1cab9..07eb61b 100644
@@ -92,7 +92,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SYSCALL_TRACE	8	/* syscall trace active */
 #define TIF_SYSCALL_AUDIT	9	/* syscall auditing active */
 #define TIF_SECCOMP		10	/* secure computing */
-#define TIF_SYSCALL_FTRACE	11	/* ftrace syscall instrumentation */
+#define TIF_SYSCALL_TRACEPOINT	11	/* syscall tracepoint instrumentation */
 #define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
 #define TIF_POLLING_NRFLAG	17	/* true if poll_idle() is polling 
 					   TIF_NEED_RESCHED */
@@ -111,7 +111,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
-#define _TIF_SYSCALL_FTRACE	(1<<TIF_SYSCALL_FTRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
 #define _TIF_USEDFPU		(1<<TIF_USEDFPU)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 #define _TIF_31BIT		(1<<TIF_31BIT)
arch/s390/kernel/entry.S +1 -1
index c4c80a2..5d40fce 100644
@@ -54,7 +54,7 @@ _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-		_TIF_SECCOMP>>8 | _TIF_SYSCALL_FTRACE>>8)
+		_TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
 
 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
 STACK_SIZE  = 1 << STACK_SHIFT
arch/s390/kernel/entry64.S +1 -1
index f6618e9..3ceb53c 100644
@@ -57,7 +57,7 @@ _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-		_TIF_SECCOMP>>8 | _TIF_SYSCALL_FTRACE>>8)
+		_TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
 
 #define BASED(name) name-system_call(%r13)
 
arch/s390/kernel/ptrace.c +2 -2
index c5e87d8..9d3dcfa 100644
@@ -664,7 +664,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 		ret = -1;
 	}
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
@@ -682,7 +682,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
 				   regs->gprs[2]);
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
arch/x86/include/asm/thread_info.h +7 -6
index fad7d40..6f7786a 100644
@@ -95,7 +95,7 @@ struct thread_info {
 #define TIF_DEBUGCTLMSR		25	/* uses thread_struct.debugctlmsr */
 #define TIF_DS_AREA_MSR		26      /* uses thread_struct.ds_area_msr */
 #define TIF_LAZY_MMU_UPDATES	27	/* task is updating the mmu lazily */
-#define TIF_SYSCALL_FTRACE	28	/* for ftrace syscall instrumentation */
+#define TIF_SYSCALL_TRACEPOINT	28	/* syscall tracepoint instrumentation */
 
 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
@@ -118,17 +118,17 @@ struct thread_info {
 #define _TIF_DEBUGCTLMSR	(1 << TIF_DEBUGCTLMSR)
 #define _TIF_DS_AREA_MSR	(1 << TIF_DS_AREA_MSR)
 #define _TIF_LAZY_MMU_UPDATES	(1 << TIF_LAZY_MMU_UPDATES)
-#define _TIF_SYSCALL_FTRACE	(1 << TIF_SYSCALL_FTRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 
 /* work to do in syscall_trace_enter() */
 #define _TIF_WORK_SYSCALL_ENTRY	\
-	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_FTRACE |	\
-	 _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | _TIF_SINGLESTEP)
+	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT |	\
+	 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
 
 /* work to do in syscall_trace_leave() */
 #define _TIF_WORK_SYSCALL_EXIT	\
 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP |	\
-	 _TIF_SYSCALL_FTRACE)
+	 _TIF_SYSCALL_TRACEPOINT)
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK							\
@@ -137,7 +137,8 @@ struct thread_info {
 	   _TIF_SINGLESTEP|_TIF_SECCOMP|_TIF_SYSCALL_EMU))
 
 /* work to do on any return to user space */
-#define _TIF_ALLWORK_MASK ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_FTRACE)
+#define _TIF_ALLWORK_MASK						\
+	((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
 
 /* Only used for 64 bit */
 #define _TIF_DO_NOTIFY_MASK						\
arch/x86/kernel/ptrace.c +2 -2
index 34dd6f1..a909afe 100644
@@ -1500,7 +1500,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 	    tracehook_report_syscall_entry(regs))
 		ret = -1L;
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
@@ -1526,7 +1526,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 	if (unlikely(current->audit_context))
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
kernel/tracepoint.c +2 -2
index 35dd27a..43bca1f 100644
@@ -593,7 +593,7 @@ void syscall_regfunc(void)
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
-			set_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
@@ -611,7 +611,7 @@ void syscall_unregfunc(void)
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
-			clear_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
Signature · 1 line
1.6.2.5
author
#26 lore raw

PATCH v3 2/4 tracing: Make syscall_(un)regfunc arch-specific

The bodies of syscall_regfunc and syscall_unregfunc need the arch-specific flag TIF_SYSCALL_TRACEPOINT, which only exists on x86 and s390, so they should live in arch-specific files.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 arch/s390/kernel/ptrace.c |   40 ++++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/ptrace.c  |   40 ++++++++++++++++++++++++++++++++++++++++
 kernel/tracepoint.c       |   40 ----------------------------------------
 3 files changed, 80 insertions(+), 40 deletions(-)
arch/s390/kernel/ptrace.c +40 -0
index 9d3dcfa..b6dcd72 100644
@@ -925,3 +925,43 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 #endif
 	return &user_s390_view;
 }
+
+#ifdef CONFIG_TRACEPOINTS
+
+static DEFINE_MUTEX(regfunc_mutex);
+static int sys_tracepoint_refcount;
+
+void syscall_regfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	sys_tracepoint_refcount++;
+	mutex_unlock(&regfunc_mutex);
+}
+
+void syscall_unregfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	sys_tracepoint_refcount--;
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	mutex_unlock(&regfunc_mutex);
+}
+#endif
arch/x86/kernel/ptrace.c +40 -0
index a909afe..c2adbed 100644
@@ -1549,3 +1549,43 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 	    tracehook_consider_fatal_signal(current, SIGTRAP))
 		send_sigtrap(current, regs, 0, TRAP_BRKPT);
 }
+
+#ifdef CONFIG_TRACEPOINTS
+
+static DEFINE_MUTEX(regfunc_mutex);
+static int sys_tracepoint_refcount;
+
+void syscall_regfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	sys_tracepoint_refcount++;
+	mutex_unlock(&regfunc_mutex);
+}
+
+void syscall_unregfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	sys_tracepoint_refcount--;
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	mutex_unlock(&regfunc_mutex);
+}
+#endif
kernel/tracepoint.c +0 -40
index 43bca1f..2ce4d38 100644
@@ -578,43 +578,3 @@ static int init_tracepoints(void)
 __initcall(init_tracepoints);
 
 #endif /* CONFIG_MODULES */
-
-#ifdef CONFIG_FTRACE_SYSCALLS
-
-static DEFINE_MUTEX(regfunc_mutex);
-static int sys_tracepoint_refcount;
-
-void syscall_regfunc(void)
-{
-	unsigned long flags;
-	struct task_struct *g, *t;
-
-	mutex_lock(&regfunc_mutex);
-	if (!sys_tracepoint_refcount) {
-		read_lock_irqsave(&tasklist_lock, flags);
-		do_each_thread(g, t) {
-			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
-		} while_each_thread(g, t);
-		read_unlock_irqrestore(&tasklist_lock, flags);
-	}
-	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
-}
-
-void syscall_unregfunc(void)
-{
-	unsigned long flags;
-	struct task_struct *g, *t;
-
-	mutex_lock(&regfunc_mutex);
-	sys_tracepoint_refcount--;
-	if (!sys_tracepoint_refcount) {
-		read_lock_irqsave(&tasklist_lock, flags);
-		do_each_thread(g, t) {
-			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
-		} while_each_thread(g, t);
-		read_unlock_irqrestore(&tasklist_lock, flags);
-	}
-	mutex_unlock(&regfunc_mutex);
-}
-#endif
Signature · 1 line
1.6.2.5
author
#27 lore raw

PATCH v3 3/4 tracing: Move tracepoint callbacks into DEFINE

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may no be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_FN which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_FN, so those events can also provide callbacks if needed.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 arch/s390/kernel/ptrace.c    |   17 +++++++--------
 arch/x86/kernel/ptrace.c     |   17 +++++++--------
 include/linux/tracepoint.h   |   46 ++++++++++++++++-------------------------
 include/trace/define_trace.h |    5 ++++
 include/trace/ftrace.h       |    9 ++++++++
 include/trace/syscall.h      |   15 +++----------
 kernel/tracepoint.c          |    8 +++++++
 7 files changed, 60 insertions(+), 57 deletions(-)
arch/s390/kernel/ptrace.c +8 -9
index b6dcd72..e515c8b 100644
@@ -51,8 +51,11 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+static void syscall_regfunc(void);
+static void syscall_unregfunc(void);
+
+DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 enum s390_regset {
 	REGSET_GENERAL,
@@ -928,15 +931,14 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 
 #ifdef CONFIG_TRACEPOINTS
 
-static DEFINE_MUTEX(regfunc_mutex);
+/* NB: reg/unreg are called while guarded with the tracepoints_mutex */
 static int sys_tracepoint_refcount;
 
-void syscall_regfunc(void)
+static void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -945,15 +947,13 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
-void syscall_unregfunc(void)
+static void syscall_unregfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -962,6 +962,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif
arch/x86/kernel/ptrace.c +8 -9
index c2adbed..cef009a 100644
@@ -37,8 +37,11 @@
 
 #include <trace/syscall.h>
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+static void syscall_regfunc(void);
+static void syscall_unregfunc(void);
+
+DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 #include "tls.h"
 
@@ -1552,15 +1555,14 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 
 #ifdef CONFIG_TRACEPOINTS
 
-static DEFINE_MUTEX(regfunc_mutex);
+/* NB: reg/unreg are called while guarded with the tracepoints_mutex */
 static int sys_tracepoint_refcount;
 
-void syscall_regfunc(void)
+static void syscall_regfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -1569,15 +1571,13 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
-void syscall_unregfunc(void)
+static void syscall_unregfunc(void)
 {
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -1586,6 +1586,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif
include/linux/tracepoint.h +18 -28

97 lines not on this page · raw message

include/trace/define_trace.h +5 -0
index f7a7ae1..2a96985 100644
@@ -26,6 +26,11 @@
 #define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
 	DEFINE_TRACE(name)
 
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_FN(name, reg, unreg)
+
 #undef DECLARE_TRACE
 #define DECLARE_TRACE(name, proto, args)	\
 	DEFINE_TRACE(name)
include/trace/ftrace.h +9 -0
index 1274002..3a0b44b 100644
@@ -42,6 +42,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+/* Callbacks are meaningless to ftrace. */
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
+		TP_STRUCT__entry(tstruct),			\
+		TP_fast_assign(assign),				\
+		TP_printk(print))
+
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 
include/trace/syscall.h +4 -11
index 9661dd4..f3d8555 100644
@@ -8,21 +8,14 @@
 #include <asm/ptrace.h>
 
 
-extern void syscall_regfunc(void);
-extern void syscall_unregfunc(void);
-
-DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
+DECLARE_TRACE(syscall_enter,
 	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, id)
 );
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
+DECLARE_TRACE(syscall_exit,
 	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, ret)
 );
 
 /*
kernel/tracepoint.c +8 -0
index 2ce4d38..5375e0f 100644
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
Signature · 1 line
1.6.2.5
author
#28 lore raw

PATCH v3 4/4 tracing: Create generic syscall TRACE_EVENTs

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values. These generic events are also renamed to sys_enter/exit, so they're more closely aligned to the specific sys_enter_foo events.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 arch/s390/kernel/ptrace.c       |    8 ++--
 arch/x86/kernel/ptrace.c        |   12 +++----
 include/trace/events/syscalls.h |   68 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   10 ------
 kernel/trace/trace_syscalls.c   |   17 +++++----
 5 files changed, 86 insertions(+), 29 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +4 -4
index e515c8b..7180ef8 100644
@@ -54,8 +54,8 @@
 static void syscall_regfunc(void);
 static void syscall_unregfunc(void);
 
-DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
 
 enum s390_regset {
 	REGSET_GENERAL,
@@ -668,7 +668,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_enter(regs, regs->gprs[2]);
+		trace_sys_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
 		audit_syscall_entry(is_compat_task() ?
@@ -686,7 +686,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 				   regs->gprs[2]);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_exit(regs, regs->gprs[2]);
+		trace_sys_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
arch/x86/kernel/ptrace.c +5 -7
index cef009a..81cce90 100644
@@ -35,15 +35,13 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
+#include "tls.h"
 
 static void syscall_regfunc(void);
 static void syscall_unregfunc(void);
 
-DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
-#include "tls.h"
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
 
 enum x86_regset {
 	REGSET_GENERAL,
@@ -1504,7 +1502,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 		ret = -1L;
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_enter(regs, regs->orig_ax);
+		trace_sys_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
 		if (IS_IA32)
@@ -1530,7 +1528,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_exit(regs, regs->ax);
+		trace_sys_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
include/trace/events/syscalls.h new file +68 -0

68 lines not on this page · raw message

include/trace/syscall.h +0 -10
index f3d8555..5dc283b 100644
@@ -8,16 +8,6 @@
 #include <asm/ptrace.h>
 
 
-DECLARE_TRACE(syscall_enter,
-	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id)
-);
-
-DECLARE_TRACE(syscall_exit,
-	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret)
-);
-
 /*
  * A syscall entry in the ftrace syscalls array.
  *
kernel/trace/trace_syscalls.c +9 -8
index 46c1b97..2698fe4 100644
@@ -1,4 +1,5 @@
 #include <trace/syscall.h>
+#include <trace/events/syscalls.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/perf_counter.h>
@@ -286,7 +287,7 @@ int reg_event_syscall_enter(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_enter)
-		ret = register_trace_syscall_enter(ftrace_syscall_enter);
+		ret = register_trace_sys_enter(ftrace_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -311,7 +312,7 @@ void unreg_event_syscall_enter(void *ptr)
 	sys_refcount_enter--;
 	clear_bit(num, enabled_enter_syscalls);
 	if (!sys_refcount_enter)
-		unregister_trace_syscall_enter(ftrace_syscall_enter);
+		unregister_trace_sys_enter(ftrace_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -327,7 +328,7 @@ int reg_event_syscall_exit(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_exit)
-		ret = register_trace_syscall_exit(ftrace_syscall_exit);
+		ret = register_trace_sys_exit(ftrace_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall exit trace point");
@@ -352,7 +353,7 @@ void unreg_event_syscall_exit(void *ptr)
 	sys_refcount_exit--;
 	clear_bit(num, enabled_exit_syscalls);
 	if (!sys_refcount_exit)
-		unregister_trace_syscall_exit(ftrace_syscall_exit);
+		unregister_trace_sys_exit(ftrace_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -418,7 +419,7 @@ int reg_prof_syscall_enter(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_enter)
-		ret = register_trace_syscall_enter(prof_syscall_enter);
+		ret = register_trace_sys_enter(prof_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -442,7 +443,7 @@ void unreg_prof_syscall_enter(char *name)
 	sys_prof_refcount_enter--;
 	clear_bit(num, enabled_prof_enter_syscalls);
 	if (!sys_prof_refcount_enter)
-		unregister_trace_syscall_enter(prof_syscall_enter);
+		unregister_trace_sys_enter(prof_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -479,7 +480,7 @@ int reg_prof_syscall_exit(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_exit)
-		ret = register_trace_syscall_exit(prof_syscall_exit);
+		ret = register_trace_sys_exit(prof_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -503,7 +504,7 @@ void unreg_prof_syscall_exit(char *name)
 	sys_prof_refcount_exit--;
 	clear_bit(num, enabled_prof_exit_syscalls);
 	if (!sys_prof_refcount_exit)
-		unregister_trace_syscall_exit(prof_syscall_exit);
+		unregister_trace_sys_exit(prof_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
Signature · 1 line
1.6.2.5
#29 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

In reply to Josh Stone
Quoted 3 lines · Josh Stone

The bodies of syscall_regfunc and syscall_unregfunc need the arch-specific flag TIF_SYSCALL_TRACEPOINT, which only exists on x86 and s390, so they should live in arch-specific files.

Sh also does, but currently in a seperate development branch. (Adding Paul Mundt in Cc to prevent from further linux-next breakage).

Quoted 78 lines
arch/s390/kernel/ptrace.c +40 -0
+
+#ifdef CONFIG_TRACEPOINTS
+
+static DEFINE_MUTEX(regfunc_mutex);
+static int sys_tracepoint_refcount;
+
+void syscall_regfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	sys_tracepoint_refcount++;
+	mutex_unlock(&regfunc_mutex);
+}
+
+void syscall_unregfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	sys_tracepoint_refcount--;
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	mutex_unlock(&regfunc_mutex);
+}
+#endif
arch/x86/kernel/ptrace.c +30 -0
index a909afe..c2adbed 100644
@@ -1549,3 +1549,43 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 	    tracehook_consider_fatal_signal(current, SIGTRAP))
 		send_sigtrap(current, regs, 0, TRAP_BRKPT);
 }
+
+#ifdef CONFIG_TRACEPOINTS
+
+static DEFINE_MUTEX(regfunc_mutex);
+static int sys_tracepoint_refcount;
+
+void syscall_regfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	sys_tracepoint_refcount++;
+	mutex_unlock(&regfunc_mutex);
+}
+
+void syscall_unregfunc(void)
+{
+	unsigned long flags;
+	struct task_struct *g, *t;
+
+	mutex_lock(&regfunc_mutex);
+	sys_tracepoint_refcount--;

arch/x86/kernel/ptrace.c asmregparm void syscall_trace_leave(struct pt_regs *regs) · line 1591

Quoted 10 lines
arch/x86/kernel/ptrace.c +10 -0
+	if (!sys_tracepoint_refcount) {
+		read_lock_irqsave(&tasklist_lock, flags);
+		do_each_thread(g, t) {
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
+		} while_each_thread(g, t);
+		read_unlock_irqrestore(&tasklist_lock, flags);
+	}
+	mutex_unlock(&regfunc_mutex);
+}
+#endif

I really don't like that.
See how the s390 and x86 version of the above code are completely identical?

Please put this in kernel/ptrace.c

Thanks.

#30 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 8 lines · Frederic Weisbecker
Quoted 3 lines · Josh Stone

The bodies of syscall_regfunc and syscall_unregfunc need the arch-specific flag TIF_SYSCALL_TRACEPOINT, which only exists on x86 and s390, so they should live in arch-specific files.

Sh also does, but currently in a seperate development branch. (Adding Paul Mundt in Cc to prevent from further linux-next breakage).

Thanks, I'll take care of this as well as the other ftrace syscalls breakage during the merge window. At the moment I don't have any good ideas on how to fix the workflow issues, and -tip likewise doesn't care about -next impact, so there's somewhat of an impasse.

#31 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 10 lines · Paul Mundt
Quoted 8 lines · Frederic Weisbecker
Quoted 3 lines · Josh Stone

The bodies of syscall_regfunc and syscall_unregfunc need the arch-specific flag TIF_SYSCALL_TRACEPOINT, which only exists on x86 and s390, so they should live in arch-specific files.

Sh also does, but currently in a seperate development branch. (Adding Paul Mundt in Cc to prevent from further linux-next breakage).

Quoted 5 lines

Thanks, I'll take care of this as well as the other ftrace syscalls breakage during the merge window. At the moment I don't have any good ideas on how to fix the workflow issues, and -tip likewise doesn't care about -next impact, so there's somewhat of an impasse.

Where did you take the nonsense from that '-tip likewise doesn't care about -next impact'? It's a false statement on several levels.

The thing is, there is just a single 'breakage' here (SH does not build if the tracing tree is mixed with the SH tree), and you inflicted it upon yourself: you mixed ftrace development into the SH tree (thinking that the syscall-tracing facility was a stable API - where did _that_ nonsense come from?), while the tracing tree did development of ftrace too (surprise), so when the two versions were mixed in linux-next it broke.

There's numerous ways to resolve this and i'm willing to help out with any of the solutions your chose (or with some other variant if it makes sense):

- Easiest: you can turn off the old-API based ftrace bits in the SH tree, in your for-next branch. This is the easiest, but keeps new SH ftrace bits untested in linux-next.

- Most conservative route: you wait with your new bits until the new tracing facilities hit upstream in the merge window. The disadvantage is that this delays your code and there's no guarantee that it cannot collide with new changes.

- The proper workflow: you can actually help out the development of tracing facilities by doing tracing development in the tracing tree. We merged a number of architecture ftrace improvements via the tracing tree already, as long as it's acked by the maintainer (which is a given here - you maintain SH) and as long as it does not touch non-ftrace bits of the architecture unreasonably.

This is the most natural workflow and the fastest one as well. The ftrace bits are well separated (or should be well separated). We didnt do ftrace development via the x86 tree either.

I'd favor the third one as it's the most intelligent variant and we used that in a number of other cases - but it's up to you.

Ingo

#32 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 20 lines · Ingo Molnar
Quoted 10 lines · Paul Mundt
Quoted 8 lines · Frederic Weisbecker
Quoted 3 lines · Josh Stone

The bodies of syscall_regfunc and syscall_unregfunc need the arch-specific flag TIF_SYSCALL_TRACEPOINT, which only exists on x86 and s390, so they should live in arch-specific files.

Sh also does, but currently in a seperate development branch. (Adding Paul Mundt in Cc to prevent from further linux-next breakage).

Quoted 5 lines

Thanks, I'll take care of this as well as the other ftrace syscalls breakage during the merge window. At the moment I don't have any good ideas on how to fix the workflow issues, and -tip likewise doesn't care about -next impact, so there's somewhat of an impasse.

Where did you take the nonsense from that '-tip likewise doesn't care about -next impact'? It's a false statement on several levels.

Quoted 8 lines

The thing is, there is just a single 'breakage' here (SH does not build if the tracing tree is mixed with the SH tree), and you inflicted it upon yourself: you mixed ftrace development into the SH tree (thinking that the syscall-tracing facility was a stable API - where did _that_ nonsense come from?), while the tracing tree did development of ftrace too (surprise), so when the two versions were mixed in linux-next it broke.

I think this is the source of confusion, given that I expected the interface would remain reasonable stable until all of the existing users had had a chance to catch up. As it is now it is impossible to make any changes to things that are taken over by -tip given that the first sign of there being any changes are failures introduced through -next, which would have been avoided if folks eagerly merging things in to -tip considered the implications for -next.

Pointing fingers however is rather pointless at this stage, and is not what I am trying to do. I've lost count of the number of times -tip has broken things in -next that were easily avoidable, and at this point I don't even care anymore (as I've stated before, it's not just -tip, people in general seem to be doing a lot of aggressive merging without even a cursory grep to check for the build implications). I fix them up as I encounter them, and try to keep my configs in general buildable shape. You call that nonsense, I call it statistics.

In any event, at least some of these issues are self-inflicted given that some feature implementation is done in my tree directly without passing through -tip first, but none of that changes the fact that -tip is merging things in to -next without any consideration of the impact it will have. This is what I have a fundamental issue with, given that there are a lot more trees than just -tip being merged, and at least some effort should be made to permit things to co-exist rather than just blaming it all on workflow.

Quoted 8 lines

There's numerous ways to resolve this and i'm willing to help out with any of the solutions your chose (or with some other variant if it makes sense):

- Easiest: you can turn off the old-API based ftrace bits in the SH tree, in your for-next branch. This is the easiest, but keeps new SH ftrace bits untested in linux-next.

I've already done this.

Quoted 7 lines

- The proper workflow: you can actually help out the development of tracing facilities by doing tracing development in the tracing tree. We merged a number of architecture ftrace improvements via the tracing tree already, as long as it's acked by the maintainer (which is a given here - you maintain SH) and as long as it does not touch non-ftrace bits of the architecture unreasonably.

Quoted 7 lines

This is the most natural workflow and the fastest one as well. The ftrace bits are well separated (or should be well separated). We didnt do ftrace development via the x86 tree either.

I'd favor the third one as it's the most intelligent variant and we used that in a number of other cases - but it's up to you.

Agreed, this is the way we will try to handle ftrace bits for sh from now on. There is not much to be done about the present mess other than waiting for things to sync up in the merge window, which I'm fine with at present given that it's not so far off.

#33 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 29 lines · Paul Mundt
Quoted 20 lines · Ingo Molnar
Quoted 10 lines · Paul Mundt
Quoted 8 lines · Frederic Weisbecker
Quoted 3 lines · Josh Stone

The bodies of syscall_regfunc and syscall_unregfunc need the arch-specific flag TIF_SYSCALL_TRACEPOINT, which only exists on x86 and s390, so they should live in arch-specific files.

Sh also does, but currently in a seperate development branch. (Adding Paul Mundt in Cc to prevent from further linux-next breakage).

Quoted 5 lines

Thanks, I'll take care of this as well as the other ftrace syscalls breakage during the merge window. At the moment I don't have any good ideas on how to fix the workflow issues, and -tip likewise doesn't care about -next impact, so there's somewhat of an impasse.

Where did you take the nonsense from that '-tip likewise doesn't care about -next impact'? It's a false statement on several levels.

Quoted 7 lines

The thing is, there is just a single 'breakage' here (SH does not build if the tracing tree is mixed with the SH tree), and you inflicted it upon yourself: you mixed ftrace development into the SH tree (thinking that the syscall-tracing facility was a stable API - where did _that_ nonsense come from?), while the tracing tree did development of ftrace too (surprise), so when the two versions were mixed in linux-next it broke.

Quoted 3 lines

I think this is the source of confusion, given that I expected the interface would remain reasonable stable until all of the existing users had had a chance to catch up. [...]

All existing upstream users of APIs were fixed up. Which was x86 and s390. (and yes, we initially missed s390)

Stable APIs are not how upstream Linux kernel development works - it would be way too inflexible.

Instead facility trees (such as the tracing tree) are either expected to convert all upstream API uses (which we did), or are supposed to provide different versions of APIs, if an API is so widespread (used by hundreds of callsites, etc.) that it's not reasonable to convert it in one go.

Quoted 5 lines

[...] As it is now it is impossible to make any changes to things that are taken over by -tip given that the first sign of there being any changes are failures introduced through -next, which would have been avoided if folks eagerly merging things in to -tip considered the implications for -next.

Paul, what you say is not making any sense to me. All those ftrace patches were sent to lkml multiple times (as all ftrace patches), so if you wanted you could have known about them.

If there's someone who failed to notify it was _you_. You might as well have Cc:-ed the guys who wrote the code you started using in SH.

Quoted 2 lines

Pointing fingers however is rather pointless at this stage, and is not what I am trying to do. [...]

( Hey what was the purpose of the previous 3 paragraphs then? ;-)

Quoted 2 lines

[...] I've lost count of the number of times -tip has broken things in -next that were easily avoidable, [...]

Do you realize that 1) what you say is false 2) we push thousands of commits so even if it was true it would be natural relative to the number of kernel developers who work on the various -tip based trees?

I know it as i always cross-build SH (too) before i push out to linux-next. I dont remember a _single_ SH breakage in the past few months, and we push thousands of commits. In fact the last time the ftrace tree broke linux-next was 8 months ago:

Date: Wed, 7 Jan 2009 10:55:05 +0100
From: Ingo Molnar <[email protected]>
To: Stephen Rothwell <[email protected]>
Subject: Re: linux-next: ftrace tree build failure

and that too was a breakage already fixed by the time it got reported.

So i'd really like you to back up your claims with facts. Your mail is basically unsubstantiated FUD right now and i'll just ignore you if you continue this pattern of unsubstantiated attacks and unconstructive behavior.

( Also, could you please fix your mailer so that it does not damage
threads? It generates such bogus headers:

Mail-Followup-To: Paul Mundt <[email protected]>,
Ingo Molnar <[email protected]>,
Frederic Weisbecker <[email protected]>,
Josh Stone <[email protected]>, [email protected], Jason Baron <[email protected]>, Li Zefan <[email protected]>, Steven Rostedt <[email protected]>,
Peter Zijlstra <[email protected]>,
Mathieu Desnoyers <[email protected]>, Jiaying Zhang <[email protected]>,
Martin Bligh <[email protected]>,
Lai Jiangshan <[email protected]>

which messes up replies. )

Thanks,

Ingo

#34 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 8 lines · Ingo Molnar
Quoted 3 lines · Paul Mundt

I think this is the source of confusion, given that I expected the interface would remain reasonable stable until all of the existing users had had a chance to catch up. [...]

All existing upstream users of APIs were fixed up. Which was x86 and s390. (and yes, we initially missed s390)

Quoted 9 lines

Stable APIs are not how upstream Linux kernel development works - it would be way too inflexible.

Instead facility trees (such as the tracing tree) are either expected to convert all upstream API uses (which we did), or are supposed to provide different versions of APIs, if an API is so widespread (used by hundreds of callsites, etc.) that it's not reasonable to convert it in one go.

No Ingo, this is not what you did, this is what you did after the breakage was pointed out to you. And before that, you had:

commit 60d970c254b95ec7a0fc4c590b510253987b64a0

Author: Ingo Molnar <[email protected]>
Date:   Thu Aug 13 23:37:26 2009 +0200

tracing: Fix syscall tracing on !HAVE_FTRACE_SYSCALLS architectures

The new syscall_regfunc()/unregfunc() functions rely on the existence of TIF_SYSCALL_FTRACE - but that TIF flag is only offered by HAVE_FTRACE_SYSCALLS.

Cc: Frederic Weisbecker <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <new-submission>

Which you at least managed to catch before it went in to -next.

At the time that this patch series was pulled in to -tip, it was basically broken for 21 out of 22 architectures. And while it's great that you caught this during your builds and so only a couple were broken instead, it still should never have made it in to the tree when it was clear it had had precisely zero testing. What happens if anyone is unfortunate enough to bisect in between these versions now? It's this sort of development methodology I take issue with, regardless of how you want to pass it off.

Quoted 6 lines
Quoted 5 lines

[...] As it is now it is impossible to make any changes to things that are taken over by -tip given that the first sign of there being any changes are failures introduced through -next, which would have been avoided if folks eagerly merging things in to -tip considered the implications for -next.

Quoted 8 lines

Paul, what you say is not making any sense to me. All those ftrace patches were sent to lkml multiple times (as all ftrace patches), so if you wanted you could have known about them.

If there's someone who failed to notify it was _you_. You might as well have Cc:-ed the guys who wrote the code you started using in SH.

And for what purpose? When has adding feature support to an architecture _ever_ worked that way? The expectation is that a new feature is added, folks add support for it, and as changes are made in the future, a reasonable attempt is made to keep folks using it aware of the changes being planned. Ok, in the future I will be more proactive with Ccing ftrace people on these changes, but it doesn't change the fact that _no one_ on the -tip side paid any attention at all to the impact it would have on -next. The s390 case also had to be pointed out to you, and you don't have the excuse that it was out of tree there.

If this doesn't make sense to you, I'm not sure how else to phrase it. Blindly merging crap in to -next with zero regard for the impact on others is simply unacceptable as far as I'm concerned. If enough people feel otherwise, then there's not much to be done about it.

Quoted 5 lines
Quoted 2 lines

Pointing fingers however is rather pointless at this stage, and is not what I am trying to do. [...]

( Hey what was the purpose of the previous 3 paragraphs then? ;-)

The purpose of the previous 3 paragraphs was pointing out that there is an issue with untested code being regularly merged in to -next, and that people are not doing even basic due diligence to ensure that things will not break before pushing to their trees. -tip is only the current case, my point is that I am not attempting to make an example of -tip specifically, only that this is a problem in general.

Quoted 5 lines

I know it as i always cross-build SH (too) before i push out to linux-next. I dont remember a _single_ SH breakage in the past few months, and we push thousands of commits. In fact the last time the ftrace tree broke linux-next was 8 months ago:

But you probably only build -tip and not -next. The point is that the end result in -next ends up broken, so whether -tip builds or not is not the issue (although of course I'm glad that you build sh for -tip too, that probably catches a lot more of these issues before they end up popping up in -next at least).

Quoted 5 lines

So i'd really like you to back up your claims with facts. Your mail is basically unsubstantiated FUD right now and i'll just ignore you if you continue this pattern of unsubstantiated attacks and unconstructive behavior.

I could sit here and itemize individual breakages all day long, but what would be the point? Is it likely to force -tip people to even do a cursory grep to check for what they are going to end up breaking? You obviously have your perspective on -tip and -next interaction which differs wildly for anyone on the receiving end. This doesn't seem likely to change, and I am growing weary of trying to even get you to acknowledge that there is a problem.

Rather than wasting any more of my time on this, I'll just go back to fixing up all of the breakage introduced in -next by others who likewise couldn't be bothered doing the bare minimum.

#35 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 12 lines · Paul Mundt
Quoted 11 lines · Ingo Molnar
Quoted 3 lines · Paul Mundt

I think this is the source of confusion, given that I expected the interface would remain reasonable stable until all of the existing users had had a chance to catch up. [...]

All existing upstream users of APIs were fixed up. Which was x86 and s390. (and yes, we initially missed s390)

Stable APIs are not how upstream Linux kernel development works - it would be way too inflexible.

Quoted 8 lines
Quoted 5 lines

Instead facility trees (such as the tracing tree) are either expected to convert all upstream API uses (which we did), or are supposed to provide different versions of APIs, if an API is so widespread (used by hundreds of callsites, etc.) that it's not reasonable to convert it in one go.

No Ingo, this is not what you did, this is what you did after the breakage was pointed out to you. [...]

As i explained it to you back then the s390 support was 1) a few weeks old 2) got masked due to an unrelated thing. In any case the bug was real and it was fixed very quickly within an hour or so of the report in the usual workflow and without any argument about it, and in total agreement with the s390 folks.

And the thing is, s390 was always a pleasure to deal with. I cannot say the same about anything SH. SH always was a huge PITA to deal with (to me at least), mainly because you seem to have a false sense of entitlement: you think everyone else must be perfect and must not affect you while you can sit on your own little island not worrying about the rest of the world - who develops and tests core kernel facilities for you. It doesnt work like that.

Quoted 12 lines

[...] And before that, you had:

commit 60d970c254b95ec7a0fc4c590b510253987b64a0

Author: Ingo Molnar <[email protected]>
Date:   Thu Aug 13 23:37:26 2009 +0200

tracing: Fix syscall tracing on !HAVE_FTRACE_SYSCALLS architectures

The new syscall_regfunc()/unregfunc() functions rely on the existence of TIF_SYSCALL_FTRACE - but that TIF flag is only offered by HAVE_FTRACE_SYSCALLS.

Quoted 8 lines

Cc: Frederic Weisbecker <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Peter Zijlstra <[email protected]>
LKML-Reference: <new-submission>

Which you at least managed to catch before it went in to -next.

See that LKML-Reference tag? That patch too went out to lkml. Had you chosen to participate instead of just complaining you could have.

Then you intentionally chose the wrong workflow and now you are complaining 1) about an easily fixed bug that got addressed within an hour of it reported 2) about a workflow situation you yourself created. [and to which i suggested several alternatives how to fix it.]

You are not being constructive at all.

Ingo

#36 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 8 lines · Ingo Molnar

And the thing is, s390 was always a pleasure to deal with. I cannot say the same about anything SH. SH always was a huge PITA to deal with (to me at least), mainly because you seem to have a false sense of entitlement: you think everyone else must be perfect and must not affect you while you can sit on your own little island not worrying about the rest of the world - who develops and tests core kernel facilities for you. It doesnt work like that.

If you had bothered to read any of my earlier mail you would realize that this is complete and utter nonsense. I expect there to be breakage, and I expect that I will be the one fixing it up (even when most of the time that breakage is not even in my own tree). Unsurprisingly, this is largely a result of SH being one of the first architectures testing these new core kernel facilities, which is something you seem intent on just writing off completely. I can imagine why s390 is a pleasure to deal with in a -tip context, when you break their tree, no one complains.

Where I take issue with -next is that this is not an isolated thing, and over time it has only become more frequent. In the case of -mm, releases were infrequent, but we did have this thing called quality control, something that is utterly lacking in -next and which the trees being sucked in seem unable to adhere to on their own.

Rather than wasting any more time on this, we can continue this at kernel summit during the -next session. If the consensus is that I'm just being unconstructive and my workflow is inherently broken, I can live with that.

Quoted 2 lines

You are not being constructive at all.

Nor have been any of your responses. At least we've found something to agree on!

#37 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 11 lines · Paul Mundt
Quoted 8 lines · Ingo Molnar

And the thing is, s390 was always a pleasure to deal with. I cannot say the same about anything SH. SH always was a huge PITA to deal with (to me at least), mainly because you seem to have a false sense of entitlement: you think everyone else must be perfect and must not affect you while you can sit on your own little island not worrying about the rest of the world - who develops and tests core kernel facilities for you. It doesnt work like that.

Quoted 2 lines

If you had bothered to read any of my earlier mail you would realize that this is complete and utter nonsense.

first you say it's nonsense, then you basically back up my points:

Quoted 6 lines

[...] I expect there to be breakage, and I expect that I will be the one fixing it up (even when most of the time that breakage is not even in my own tree). Unsurprisingly, this is largely a result of SH being one of the first architectures testing these new core kernel facilities, which is something you seem intent on just writing off completely. [...]

... the thing is, you didnt Cc: any of the tracing commits in the SH tree either to lkml or to the tracing folks who are developing those facilities:

c652d78: sh: Add ftrace syscall tracing support

From: Matt Fleming <[email protected]>
Date: Mon, 6 Jul 2009 20:16:33 +0900
Subject: [PATCH] sh: Add ftrace syscall tracing support

[...]

That 'could' have been Cc:-ed to Frederic and Steve, perhaps Jason and me as well.

You basically treat SH as your own private tree, with little need to communicate with anyone outside the SH hackers. Which is fine, as long as you are willing to deal with the other side of the coin:
that others wont be aware of your changes.

Or, at minimum, to not scream loudly when the flip side beats you.

Ingo

#38 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

In reply to Paul Mundt
Quoted 9 lines · Paul Mundt
Quoted 4 lines · Ingo Molnar

So i'd really like you to back up your claims with facts. Your mail is basically unsubstantiated FUD right now and i'll just ignore you if you continue this pattern of unsubstantiated attacks and unconstructive behavior.

I could sit here and itemize individual breakages all day long, but what would be the point? [...]

The point would be to prove your so far unsubstantiated (and IMO unfair) attacks.

Ingo

#39 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 9 lines · Ingo Molnar
Quoted 7 lines · Paul Mundt
Quoted 4 lines · Ingo Molnar

So i'd really like you to back up your claims with facts. Your mail is basically unsubstantiated FUD right now and i'll just ignore you if you continue this pattern of unsubstantiated attacks and unconstructive behavior.

Quoted 5 lines
Quoted 2 lines

I could sit here and itemize individual breakages all day long, but what would be the point? [...]

The point would be to prove your so far unsubstantiated (and IMO unfair) attacks.

Guys, can we get over this already.. really every linux developer runs x86, except the very few that don't. We all try to ensure we don't accidentally break things, shit happens, deal with it.

!x86 breaking more often than x86 is a simple consequence of statistics, if you don't like it, make your hardware sexy and send it to more devs ;-)

Build breakages aren't a big deal, they get sorted, life moves on. If they wouldn't get sorted there might be something to complain about, but afaict that doesn't happen.

Paul, you put a tracing patch into the sh tree, didn't cc the tracing folks and then found it broke when the tracing tree was added, *gosh*!?

That will happen with pretty much every other subsystem too, that's what we have subsystem tree's for, I think enough has been arranged to mitigate this issue in the future - lets go fix some real bugs now? :-)

#40 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

In reply to Ingo Molnar
Quoted 15 lines · Ingo Molnar

( Also, could you please fix your mailer so that it does not damage
threads? It generates such bogus headers:

Mail-Followup-To: Paul Mundt <[email protected]>,
Ingo Molnar <[email protected]>,
Frederic Weisbecker <[email protected]>,
Josh Stone <[email protected]>, [email protected], Jason Baron <[email protected]>, Li Zefan <[email protected]>, Steven Rostedt <[email protected]>,
Peter Zijlstra <[email protected]>,
Mathieu Desnoyers <[email protected]>, Jiaying Zhang <[email protected]>,
Martin Bligh <[email protected]>,
Lai Jiangshan <[email protected]>

Quoted 1 line

which messes up replies. )

Paul, you forgot to reply to this bit. Mail-Followup-To is quite a PITA on lkml.

Ingo

#41 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Ingo Molnar

( Also, could you please fix your mailer so that it does not damage
threads? It generates such bogus headers:

Mail-Followup-To: Paul Mundt <[email protected]>,
Ingo Molnar <[email protected]>,
Frederic Weisbecker <[email protected]>,
Josh Stone <[email protected]>, [email protected], Jason Baron <[email protected]>, Li Zefan <[email protected]>, Steven Rostedt <[email protected]>,
Peter Zijlstra <[email protected]>,
Mathieu Desnoyers <[email protected]>, Jiaying Zhang <[email protected]>,
Martin Bligh <[email protected]>,
Lai Jiangshan <[email protected]>

Quoted 5 lines
Quoted 1 line

which messes up replies. )

Paul, you forgot to reply to this bit. Mail-Followup-To is quite a PITA on lkml.

Yes, this is the first I realized it was doing this, I'll look in to it, thanks.

author
#42 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

In reply to Frederic Weisbecker
Quoted 5 lines · Frederic Weisbecker

I really don't like that.
See how the s390 and x86 version of the above code are completely identical?

Please put this in kernel/ptrace.c

Yes, I see your point, and I think kernel/ptrace.c is a fine place for it. Making it conditional on CONFIG_TRACEPOINTS and CONFIG_HAVE_FTRACE_SYSCALLS is probably best too, though I think the latter should now be HAVE_SYSCALL_TRACEPOINTS.

Thanks,

Josh

#43 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 11 lines · Josh Stone
Quoted 5 lines · Frederic Weisbecker

I really don't like that.
See how the s390 and x86 version of the above code are completely identical?

Please put this in kernel/ptrace.c

Yes, I see your point, and I think kernel/ptrace.c is a fine place for it. Making it conditional on CONFIG_TRACEPOINTS and CONFIG_HAVE_FTRACE_SYSCALLS is probably best too, though I think the latter should now be HAVE_SYSCALL_TRACEPOINTS.

As you prefer, this new name can be indeed more verbose.

Thanks.

Quoted 3 lines

Thanks,

Josh

author
#44 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 8 lines · Frederic Weisbecker
Quoted 7 lines · Josh Stone
Quoted 5 lines · Frederic Weisbecker

I really don't like that.
See how the s390 and x86 version of the above code are completely identical?

Please put this in kernel/ptrace.c

Quoted 7 lines
Quoted 4 lines

Yes, I see your point, and I think kernel/ptrace.c is a fine place for it. Making it conditional on CONFIG_TRACEPOINTS and CONFIG_HAVE_FTRACE_SYSCALLS is probably best too, though I think the latter should now be HAVE_SYSCALL_TRACEPOINTS.

As you prefer, this new name can be indeed more verbose.

Actually, now I'm second-guessing the need to move these at all. Since they only make sense for CONFIG_TRACEPOINTS, can't they stay in kernel/tracepoint.c and just be conditional on HAVE_SYSCALL_TRACEPOINTS?
The only real change needed is for the tracepoint declarations to also
be conditional.

Josh

#45 lore raw

Re: [PATCH v3 2/4] tracing: Make syscall_(un)regfunc arch-specific

Quoted 17 lines · Josh Stone
Quoted 8 lines · Frederic Weisbecker
Quoted 7 lines · Josh Stone
Quoted 5 lines · Frederic Weisbecker

I really don't like that.
See how the s390 and x86 version of the above code are completely identical?

Please put this in kernel/ptrace.c

Quoted 7 lines
Quoted 4 lines

Yes, I see your point, and I think kernel/ptrace.c is a fine place for it. Making it conditional on CONFIG_TRACEPOINTS and CONFIG_HAVE_FTRACE_SYSCALLS is probably best too, though I think the latter should now be HAVE_SYSCALL_TRACEPOINTS.

As you prefer, this new name can be indeed more verbose.

Quoted 8 lines

Actually, now I'm second-guessing the need to move these at all. Since they only make sense for CONFIG_TRACEPOINTS, can't they stay in kernel/tracepoint.c and just be conditional on HAVE_SYSCALL_TRACEPOINTS?
The only real change needed is for the tracepoint declarations to also
be conditional.

Josh

Both ways make sense to me, although I generally see the role of kernel/tracepoint.c to only host the general core tracepoints mechanism.

And here these two callbacks are more about specific tracepoints coverage, somewhat tied to the ptrace background because we are using a ptrace bridge to reach these tracepoints.

Well, either ways look good:

- tracepoint.c: to solve the lack of a functionnality in very specific cases.

- ptrace.c: because it's part of a ptrace mechanism.

I don't feel strongly about that :-)

#46 lore raw

Re: [PATCH v3 1/4] tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

In reply to Josh Stone
Quoted 2 lines · Josh Stone

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Adding Paul Mundt <[email protected]> in Cc, the sh tree also has the syscalls tracing support (in a seperate branch).

Thanks.

#47 lore raw

Re: [PATCH v3 1/4] tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

Quoted 7 lines · Frederic Weisbecker
Quoted 2 lines · Josh Stone

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Adding Paul Mundt <[email protected]> in Cc, the sh tree also has the syscalls tracing support (in a seperate branch).

Btw., is there an URI for that separate branch?

Ingo

#48 lore raw

Re: [PATCH v3 1/4] tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Frederic Weisbecker
Quoted 2 lines · Josh Stone

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Quoted 6 lines
Quoted 2 lines

Adding Paul Mundt <[email protected]> in Cc, the sh tree also has the syscalls tracing support (in a seperate branch).

Btw., is there an URI for that separate branch?

Ingo

I guess it's:

git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git \
sh/ftrace

#49 lore raw

Re: [PATCH v3 1/4] tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

Quoted 12 lines · Frederic Weisbecker
Quoted 11 lines · Ingo Molnar
Quoted 7 lines · Frederic Weisbecker
Quoted 2 lines · Josh Stone

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Adding Paul Mundt <[email protected]> in Cc, the sh tree also has the syscalls tracing support (in a seperate branch).

Quoted 8 lines
Quoted 3 lines

Btw., is there an URI for that separate branch?

Ingo

I guess it's:

git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git \
sh/ftrace

ok, i checked - this is not a pure topical tree, it's intermingled with other SH changes, so it cannot be pulled into the tracing tree.

Obviously only such trees can be pulled into the tracing tree that limit their role to tracing and are non-rebasing.

Ingo

#50 lore raw

Re: [PATCH v3 1/4] tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

Quoted 19 lines · Ingo Molnar
Quoted 18 lines · Frederic Weisbecker
Quoted 8 lines · Ingo Molnar
Quoted 5 lines · Frederic Weisbecker
Quoted 2 lines · Josh Stone

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Quoted 6 lines
Quoted 2 lines

Adding Paul Mundt <[email protected]> in Cc, the sh tree also has the syscalls tracing support (in a seperate branch).

Btw., is there an URI for that separate branch?

Ingo

I guess it's:

Quoted 9 lines
Quoted 2 lines

git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git \
sh/ftrace

ok, i checked - this is not a pure topical tree, it's intermingled with other SH changes, so it cannot be pulled into the tracing tree.

Obviously only such trees can be pulled into the tracing tree that limit their role to tracing and are non-rebasing.

Yes, post-2.6.32 merge window I'll keep the sh/ftrace branch isolated from the rest of the sh changes, at which point it should be possible to pull in to -tip directly. I generally do not rebase topic branches.

#51 lore raw

Re: [PATCH v3 1/4] tracing: Rename TIF_SYSCALL_FTRACE->_TRACEPOINT

Quoted 26 lines · Paul Mundt
Quoted 25 lines · Ingo Molnar
Quoted 12 lines · Frederic Weisbecker
Quoted 11 lines · Ingo Molnar
Quoted 7 lines · Frederic Weisbecker
Quoted 2 lines · Josh Stone

This thread flag is no longer specific to just ftrace, so TIF_SYSCALL_TRACEPOINT may be a more apt name.

Adding Paul Mundt <[email protected]> in Cc, the sh tree also has the syscalls tracing support (in a seperate branch).

Quoted 8 lines
Quoted 3 lines

Btw., is there an URI for that separate branch?

Ingo

I guess it's:

git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6.git \
sh/ftrace

ok, i checked - this is not a pure topical tree, it's intermingled with other SH changes, so it cannot be pulled into the tracing tree.

Quoted 7 lines
Quoted 2 lines

Obviously only such trees can be pulled into the tracing tree that limit their role to tracing and are non-rebasing.

Yes, post-2.6.32 merge window I'll keep the sh/ftrace branch isolated from the rest of the sh changes, at which point it should be possible to pull in to -tip directly. I generally do not rebase topic branches.

Next time we can accelerate it all and push it into linux-next as well and not limit anyone's workflow, by using the tracing tree as the point to merge tracing related changes. If it's acked by you then we can do tracing related SH changes too just fine.

Ingo

author
#52 lore raw

v4 cover tracing: tweaks for generic syscall events

In reply to Josh Stone

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

New in v4:
- Give the config flag a more generic name: HAVE_SYSCALL_TRACEPOINTS.
- Undo the arch reorg of the regfuncs, but conditionalize on above.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
---
 arch/s390/Kconfig                   |    2 +-
 arch/s390/defconfig                 |    2 +-
 arch/s390/include/asm/thread_info.h |    4 +-
 arch/s390/kernel/entry.S            |    2 +-
 arch/s390/kernel/entry64.S          |    2 +-
 arch/s390/kernel/ptrace.c           |   12 +++---
 arch/x86/Kconfig                    |    2 +-
 arch/x86/configs/i386_defconfig     |    2 +-
 arch/x86/configs/x86_64_defconfig   |    2 +-
 arch/x86/include/asm/thread_info.h  |   13 +++---
 arch/x86/kernel/ptrace.c            |   16 +++----
 include/linux/tracepoint.h          |   46 +++++++++--------------
 include/trace/define_trace.h        |    5 ++
 include/trace/events/syscalls.h     |   70 +++++++++++++++++++++++++++++++++++
 include/trace/ftrace.h              |    9 ++++
 include/trace/syscall.h             |   17 --------
 kernel/trace/Kconfig                |    4 +-
 kernel/trace/trace_syscalls.c       |   17 ++++----
 kernel/tracepoint.c                 |   20 ++++++----
author
#53 lore raw

PATCH v4 1/4 tracing: Rename FTRACE_SYSCALLS for tracepoints

s/HAVE_FTRACE_SYSCALLS/HAVE_SYSCALL_TRACEPOINTS/g
s/TIF_SYSCALL_FTRACE/TIF_SYSCALL_TRACEPOINT/g

The syscall enter/exit tracing is no longer specific to just ftrace, so they now have names that reflect their tie to tracepoints instead.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
---
 arch/s390/Kconfig                   |    2 +-
 arch/s390/defconfig                 |    2 +-
 arch/s390/include/asm/thread_info.h |    4 ++--
 arch/s390/kernel/entry.S            |    2 +-
 arch/s390/kernel/entry64.S          |    2 +-
 arch/s390/kernel/ptrace.c           |    4 ++--
 arch/x86/Kconfig                    |    2 +-
 arch/x86/configs/i386_defconfig     |    2 +-
 arch/x86/configs/x86_64_defconfig   |    2 +-
 arch/x86/include/asm/thread_info.h  |   13 +++++++------
 arch/x86/kernel/ptrace.c            |    4 ++--
 kernel/trace/Kconfig                |    4 ++--
 kernel/tracepoint.c                 |    4 ++--
 13 files changed, 24 insertions(+), 23 deletions(-)
arch/s390/Kconfig +1 -1
index 2ae5d72..7238ef4 100644
@@ -84,7 +84,7 @@ config S390
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_FTRACE_MCOUNT_RECORD
-	select HAVE_FTRACE_SYSCALLS
+	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_DEFAULT_NO_SPIN_MUTEXES
arch/s390/defconfig +1 -1
index fcba206..4e91a25 100644
@@ -900,7 +900,7 @@ CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
 CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
-CONFIG_HAVE_FTRACE_SYSCALLS=y
+CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
arch/s390/include/asm/thread_info.h +2 -2
index ba1cab9..07eb61b 100644
@@ -92,7 +92,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SYSCALL_TRACE	8	/* syscall trace active */
 #define TIF_SYSCALL_AUDIT	9	/* syscall auditing active */
 #define TIF_SECCOMP		10	/* secure computing */
-#define TIF_SYSCALL_FTRACE	11	/* ftrace syscall instrumentation */
+#define TIF_SYSCALL_TRACEPOINT	11	/* syscall tracepoint instrumentation */
 #define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
 #define TIF_POLLING_NRFLAG	17	/* true if poll_idle() is polling 
 					   TIF_NEED_RESCHED */
@@ -111,7 +111,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
-#define _TIF_SYSCALL_FTRACE	(1<<TIF_SYSCALL_FTRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
 #define _TIF_USEDFPU		(1<<TIF_USEDFPU)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 #define _TIF_31BIT		(1<<TIF_31BIT)
arch/s390/kernel/entry.S +1 -1
index c4c80a2..5d40fce 100644
@@ -54,7 +54,7 @@ _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-		_TIF_SECCOMP>>8 | _TIF_SYSCALL_FTRACE>>8)
+		_TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
 
 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
 STACK_SIZE  = 1 << STACK_SHIFT
arch/s390/kernel/entry64.S +1 -1
index f6618e9..3ceb53c 100644
@@ -57,7 +57,7 @@ _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-		_TIF_SECCOMP>>8 | _TIF_SYSCALL_FTRACE>>8)
+		_TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
 
 #define BASED(name) name-system_call(%r13)
 
arch/s390/kernel/ptrace.c +2 -2
index c5e87d8..9d3dcfa 100644
@@ -664,7 +664,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 		ret = -1;
 	}
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
@@ -682,7 +682,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
 				   regs->gprs[2]);
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
arch/x86/Kconfig +1 -1
index 738bdc6..d59cbf7 100644
@@ -37,7 +37,7 @@ config X86
 	select HAVE_FUNCTION_GRAPH_FP_TEST
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE
-	select HAVE_FTRACE_SYSCALLS
+	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KVM
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_TRACEHOOK
arch/x86/configs/i386_defconfig +1 -1
index edb992e..d28fad1 100644
@@ -2355,7 +2355,7 @@ CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
 CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_HW_BRANCH_TRACER=y
-CONFIG_HAVE_FTRACE_SYSCALLS=y
+CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
 CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
arch/x86/configs/x86_64_defconfig +1 -1
index cee1dd2..6c86acd 100644
@@ -2329,7 +2329,7 @@ CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
 CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_HW_BRANCH_TRACER=y
-CONFIG_HAVE_FTRACE_SYSCALLS=y
+CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
 CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
arch/x86/include/asm/thread_info.h +7 -6
index fad7d40..6f7786a 100644
@@ -95,7 +95,7 @@ struct thread_info {
 #define TIF_DEBUGCTLMSR		25	/* uses thread_struct.debugctlmsr */
 #define TIF_DS_AREA_MSR		26      /* uses thread_struct.ds_area_msr */
 #define TIF_LAZY_MMU_UPDATES	27	/* task is updating the mmu lazily */
-#define TIF_SYSCALL_FTRACE	28	/* for ftrace syscall instrumentation */
+#define TIF_SYSCALL_TRACEPOINT	28	/* syscall tracepoint instrumentation */
 
 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
@@ -118,17 +118,17 @@ struct thread_info {
 #define _TIF_DEBUGCTLMSR	(1 << TIF_DEBUGCTLMSR)
 #define _TIF_DS_AREA_MSR	(1 << TIF_DS_AREA_MSR)
 #define _TIF_LAZY_MMU_UPDATES	(1 << TIF_LAZY_MMU_UPDATES)
-#define _TIF_SYSCALL_FTRACE	(1 << TIF_SYSCALL_FTRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 
 /* work to do in syscall_trace_enter() */
 #define _TIF_WORK_SYSCALL_ENTRY	\
-	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_FTRACE |	\
-	 _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | _TIF_SINGLESTEP)
+	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT |	\
+	 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
 
 /* work to do in syscall_trace_leave() */
 #define _TIF_WORK_SYSCALL_EXIT	\
 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP |	\
-	 _TIF_SYSCALL_FTRACE)
+	 _TIF_SYSCALL_TRACEPOINT)
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK							\
@@ -137,7 +137,8 @@ struct thread_info {
 	   _TIF_SINGLESTEP|_TIF_SECCOMP|_TIF_SYSCALL_EMU))
 
 /* work to do on any return to user space */
-#define _TIF_ALLWORK_MASK ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_FTRACE)
+#define _TIF_ALLWORK_MASK						\
+	((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
 
 /* Only used for 64 bit */
 #define _TIF_DO_NOTIFY_MASK						\
arch/x86/kernel/ptrace.c +2 -2
index 34dd6f1..a909afe 100644
@@ -1500,7 +1500,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 	    tracehook_report_syscall_entry(regs))
 		ret = -1L;
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
@@ -1526,7 +1526,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 	if (unlikely(current->audit_context))
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
kernel/trace/Kconfig +2 -2
index 019f380..06be85a 100644
@@ -41,7 +41,7 @@ config HAVE_FTRACE_MCOUNT_RECORD
 config HAVE_HW_BRANCH_TRACER
 	bool
 
-config HAVE_FTRACE_SYSCALLS
+config HAVE_SYSCALL_TRACEPOINTS
 	bool
 
 config TRACER_MAX_TRACE
@@ -211,7 +211,7 @@ config ENABLE_DEFAULT_TRACERS
 
 config FTRACE_SYSCALLS
 	bool "Trace syscalls"
-	depends on HAVE_FTRACE_SYSCALLS
+	depends on HAVE_SYSCALL_TRACEPOINTS
 	select GENERIC_TRACER
 	select KALLSYMS
 	help
kernel/tracepoint.c +2 -2
index 35dd27a..43bca1f 100644
@@ -593,7 +593,7 @@ void syscall_regfunc(void)
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
-			set_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
@@ -611,7 +611,7 @@ void syscall_unregfunc(void)
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
-			clear_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
Signature · 1 line
1.6.2.5
author
#54 lore raw

PATCH v4 2/4 tracing: Make syscall tracepoints conditional

The syscall enter/exit tracepoints are only supported on archs that HAVE_SYSCALL_TRACEPOINTS, so the declarations should be #ifdef'ed. Also, the definition of syscall_regfunc and syscall_unregfunc need the should use this same flag, rather than the ftrace-specific one.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
---
 include/trace/syscall.h |    4 ++++
 kernel/tracepoint.c     |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)
include/trace/syscall.h +4 -0
index 9661dd4..5dcb7e3 100644
@@ -8,6 +8,8 @@
 #include <asm/ptrace.h>
 
 
+#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
+
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
@@ -25,6 +27,8 @@ DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
 	syscall_unregfunc
 );
 
+#endif
+
 /*
  * A syscall entry in the ftrace syscalls array.
  *
kernel/tracepoint.c +1 -1
index 43bca1f..6c2e12c 100644
@@ -579,7 +579,7 @@ __initcall(init_tracepoints);
 
 #endif /* CONFIG_MODULES */
 
-#ifdef CONFIG_FTRACE_SYSCALLS
+#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
 
 static DEFINE_MUTEX(regfunc_mutex);
 static int sys_tracepoint_refcount;
Signature · 1 line
1.6.2.5
author
#55 lore raw

PATCH v4 3/4 tracing: Move tracepoint callbacks into DEFINE

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may not be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_FN which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_FN, so those events can also provide callbacks if needed.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
---
 arch/s390/kernel/ptrace.c    |    4 +-
 arch/x86/kernel/ptrace.c     |    4 +-
 include/linux/tracepoint.h   |   46 ++++++++++++++++-------------------------
 include/trace/define_trace.h |    5 ++++
 include/trace/ftrace.h       |    9 ++++++++
 include/trace/syscall.h      |   12 +++-------
 kernel/tracepoint.c          |   14 ++++++++----
 7 files changed, 49 insertions(+), 45 deletions(-)
arch/s390/kernel/ptrace.c +2 -2
index 9d3dcfa..c05b44b 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 enum s390_regset {
 	REGSET_GENERAL,
arch/x86/kernel/ptrace.c +2 -2
index a909afe..31e9b97 100644
@@ -37,8 +37,8 @@
 
 #include <trace/syscall.h>
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 #include "tls.h"
 
include/linux/tracepoint.h +18 -28

97 lines not on this page · raw message

include/trace/define_trace.h +5 -0
index f7a7ae1..2a96985 100644
@@ -26,6 +26,11 @@
 #define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
 	DEFINE_TRACE(name)
 
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_FN(name, reg, unreg)
+
 #undef DECLARE_TRACE
 #define DECLARE_TRACE(name, proto, args)	\
 	DEFINE_TRACE(name)
include/trace/ftrace.h +9 -0
index 1274002..3a0b44b 100644
@@ -42,6 +42,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+/* Callbacks are meaningless to ftrace. */
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
+		TP_STRUCT__entry(tstruct),			\
+		TP_fast_assign(assign),				\
+		TP_printk(print))
+
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 
include/trace/syscall.h +4 -8
index 5dcb7e3..4e19430 100644
@@ -13,18 +13,14 @@
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
+DECLARE_TRACE(syscall_enter,
 	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, id)
 );
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
+DECLARE_TRACE(syscall_exit,
 	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, ret)
 );
 
 #endif
kernel/tracepoint.c +9 -5
index 6c2e12c..8ec0e26 100644
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -581,7 +589,7 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
 
-static DEFINE_MUTEX(regfunc_mutex);
+/* NB: reg/unreg are called while guarded with the tracepoints_mutex */
 static int sys_tracepoint_refcount;
 
 void syscall_regfunc(void)
@@ -589,7 +597,6 @@ void syscall_regfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -598,7 +605,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -606,7 +612,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -615,6 +620,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif
Signature · 1 line
1.6.2.5
author
#56 lore raw

PATCH v4 4/4 tracing: Create generic syscall TRACE_EVENTs

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values. These generic events are also renamed to sys_enter/exit, so they're more closely aligned to the specific sys_enter_foo events.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
---
 arch/s390/kernel/ptrace.c       |    8 ++--
 arch/x86/kernel/ptrace.c        |   12 +++----
 include/trace/events/syscalls.h |   70 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   17 ---------
 kernel/trace/trace_syscalls.c   |   17 +++++----
 5 files changed, 88 insertions(+), 36 deletions(-)
 create mode 100644 include/trace/events/syscalls.h
arch/s390/kernel/ptrace.c +4 -4
index c05b44b..f3ddd7a 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
 
 enum s390_regset {
 	REGSET_GENERAL,
@@ -665,7 +665,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_enter(regs, regs->gprs[2]);
+		trace_sys_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
 		audit_syscall_entry(is_compat_task() ?
@@ -683,7 +683,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 				   regs->gprs[2]);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_exit(regs, regs->gprs[2]);
+		trace_sys_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
arch/x86/kernel/ptrace.c +5 -7
index 31e9b97..8d7d5c9 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
@@ -1501,7 +1499,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 		ret = -1L;
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_enter(regs, regs->orig_ax);
+		trace_sys_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
 		if (IS_IA32)
@@ -1527,7 +1525,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_exit(regs, regs->ax);
+		trace_sys_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
include/trace/events/syscalls.h new file +70 -0

70 lines not on this page · raw message

include/trace/syscall.h +0 -17
index 4e19430..5dc283b 100644
@@ -8,23 +8,6 @@
 #include <asm/ptrace.h>
 
 
-#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
-
-extern void syscall_regfunc(void);
-extern void syscall_unregfunc(void);
-
-DECLARE_TRACE(syscall_enter,
-	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id)
-);
-
-DECLARE_TRACE(syscall_exit,
-	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret)
-);
-
-#endif
-
 /*
  * A syscall entry in the ftrace syscalls array.
  *
kernel/trace/trace_syscalls.c +9 -8
index 46c1b97..2698fe4 100644
@@ -1,4 +1,5 @@
 #include <trace/syscall.h>
+#include <trace/events/syscalls.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/perf_counter.h>
@@ -286,7 +287,7 @@ int reg_event_syscall_enter(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_enter)
-		ret = register_trace_syscall_enter(ftrace_syscall_enter);
+		ret = register_trace_sys_enter(ftrace_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -311,7 +312,7 @@ void unreg_event_syscall_enter(void *ptr)
 	sys_refcount_enter--;
 	clear_bit(num, enabled_enter_syscalls);
 	if (!sys_refcount_enter)
-		unregister_trace_syscall_enter(ftrace_syscall_enter);
+		unregister_trace_sys_enter(ftrace_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -327,7 +328,7 @@ int reg_event_syscall_exit(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_exit)
-		ret = register_trace_syscall_exit(ftrace_syscall_exit);
+		ret = register_trace_sys_exit(ftrace_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall exit trace point");
@@ -352,7 +353,7 @@ void unreg_event_syscall_exit(void *ptr)
 	sys_refcount_exit--;
 	clear_bit(num, enabled_exit_syscalls);
 	if (!sys_refcount_exit)
-		unregister_trace_syscall_exit(ftrace_syscall_exit);
+		unregister_trace_sys_exit(ftrace_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -418,7 +419,7 @@ int reg_prof_syscall_enter(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_enter)
-		ret = register_trace_syscall_enter(prof_syscall_enter);
+		ret = register_trace_sys_enter(prof_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -442,7 +443,7 @@ void unreg_prof_syscall_enter(char *name)
 	sys_prof_refcount_enter--;
 	clear_bit(num, enabled_prof_enter_syscalls);
 	if (!sys_prof_refcount_enter)
-		unregister_trace_syscall_enter(prof_syscall_enter);
+		unregister_trace_sys_enter(prof_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -479,7 +480,7 @@ int reg_prof_syscall_exit(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_exit)
-		ret = register_trace_syscall_exit(prof_syscall_exit);
+		ret = register_trace_sys_exit(prof_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -503,7 +504,7 @@ void unreg_prof_syscall_exit(char *name)
 	sys_prof_refcount_exit--;
 	clear_bit(num, enabled_prof_exit_syscalls);
 	if (!sys_prof_refcount_exit)
-		unregister_trace_syscall_exit(prof_syscall_exit);
+		unregister_trace_sys_exit(prof_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
Signature · 1 line
1.6.2.5
#57 lore raw

[tip:tracing/core] tracing: Create generic syscall TRACE_EVENTs

Commit-ID:  1c569f0264ea629c10bbab471dd0626ce4d3f19f
Gitweb:     http://git.kernel.org/tip/1c569f0264ea629c10bbab471dd0626ce4d3f19f
Author:     Josh Stone <[email protected]>
AuthorDate: Mon, 24 Aug 2009 14:43:14 -0700
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Wed, 26 Aug 2009 00:41:48 +0200

tracing: Create generic syscall TRACE_EVENTs

This converts the syscall_enter/exit tracepoints into TRACE_EVENTs, so you can have generic ftrace events that capture all system calls with arguments and return values. These generic events are also renamed to sys_enter/exit, so they're more closely aligned to the specific sys_enter_foo events.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/s390/kernel/ptrace.c       |    8 ++--
 arch/x86/kernel/ptrace.c        |   12 +++----
 include/trace/events/syscalls.h |   70 +++++++++++++++++++++++++++++++++++++++
 include/trace/syscall.h         |   17 ---------
 kernel/trace/trace_syscalls.c   |   17 +++++----
 5 files changed, 88 insertions(+), 36 deletions(-)
arch/s390/kernel/ptrace.c +4 -4
index c05b44b..f3ddd7a 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
 
 enum s390_regset {
 	REGSET_GENERAL,
@@ -665,7 +665,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 	}
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_enter(regs, regs->gprs[2]);
+		trace_sys_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
 		audit_syscall_entry(is_compat_task() ?
@@ -683,7 +683,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 				   regs->gprs[2]);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_exit(regs, regs->gprs[2]);
+		trace_sys_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
arch/x86/kernel/ptrace.c +5 -7
index 31e9b97..8d7d5c9 100644
@@ -35,13 +35,11 @@
 #include <asm/proto.h>
 #include <asm/ds.h>
 
-#include <trace/syscall.h>
-
-DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
-DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
-
 #include "tls.h"
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
 enum x86_regset {
 	REGSET_GENERAL,
 	REGSET_FP,
@@ -1501,7 +1499,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 		ret = -1L;
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_enter(regs, regs->orig_ax);
+		trace_sys_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
 		if (IS_IA32)
@@ -1527,7 +1525,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_syscall_exit(regs, regs->ax);
+		trace_sys_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
 		tracehook_report_syscall_exit(regs, 0);
include/trace/events/syscalls.h new file +70 -0

70 lines not on this page · raw message

include/trace/syscall.h +0 -17
index 4e19430..5dc283b 100644
@@ -8,23 +8,6 @@
 #include <asm/ptrace.h>
 
 
-#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
-
-extern void syscall_regfunc(void);
-extern void syscall_unregfunc(void);
-
-DECLARE_TRACE(syscall_enter,
-	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id)
-);
-
-DECLARE_TRACE(syscall_exit,
-	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret)
-);
-
-#endif
-
 /*
  * A syscall entry in the ftrace syscalls array.
  *
kernel/trace/trace_syscalls.c +9 -8
index 46c1b97..2698fe4 100644
@@ -1,4 +1,5 @@
 #include <trace/syscall.h>
+#include <trace/events/syscalls.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/perf_counter.h>
@@ -286,7 +287,7 @@ int reg_event_syscall_enter(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_enter)
-		ret = register_trace_syscall_enter(ftrace_syscall_enter);
+		ret = register_trace_sys_enter(ftrace_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -311,7 +312,7 @@ void unreg_event_syscall_enter(void *ptr)
 	sys_refcount_enter--;
 	clear_bit(num, enabled_enter_syscalls);
 	if (!sys_refcount_enter)
-		unregister_trace_syscall_enter(ftrace_syscall_enter);
+		unregister_trace_sys_enter(ftrace_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -327,7 +328,7 @@ int reg_event_syscall_exit(void *ptr)
 		return -ENOSYS;
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_refcount_exit)
-		ret = register_trace_syscall_exit(ftrace_syscall_exit);
+		ret = register_trace_sys_exit(ftrace_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall exit trace point");
@@ -352,7 +353,7 @@ void unreg_event_syscall_exit(void *ptr)
 	sys_refcount_exit--;
 	clear_bit(num, enabled_exit_syscalls);
 	if (!sys_refcount_exit)
-		unregister_trace_syscall_exit(ftrace_syscall_exit);
+		unregister_trace_sys_exit(ftrace_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -418,7 +419,7 @@ int reg_prof_syscall_enter(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_enter)
-		ret = register_trace_syscall_enter(prof_syscall_enter);
+		ret = register_trace_sys_enter(prof_syscall_enter);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -442,7 +443,7 @@ void unreg_prof_syscall_enter(char *name)
 	sys_prof_refcount_enter--;
 	clear_bit(num, enabled_prof_enter_syscalls);
 	if (!sys_prof_refcount_enter)
-		unregister_trace_syscall_enter(prof_syscall_enter);
+		unregister_trace_sys_enter(prof_syscall_enter);
 	mutex_unlock(&syscall_trace_lock);
 }
 
@@ -479,7 +480,7 @@ int reg_prof_syscall_exit(char *name)
 
 	mutex_lock(&syscall_trace_lock);
 	if (!sys_prof_refcount_exit)
-		ret = register_trace_syscall_exit(prof_syscall_exit);
+		ret = register_trace_sys_exit(prof_syscall_exit);
 	if (ret) {
 		pr_info("event trace: Could not activate"
 				"syscall entry trace point");
@@ -503,7 +504,7 @@ void unreg_prof_syscall_exit(char *name)
 	sys_prof_refcount_exit--;
 	clear_bit(num, enabled_prof_exit_syscalls);
 	if (!sys_prof_refcount_exit)
-		unregister_trace_syscall_exit(prof_syscall_exit);
+		unregister_trace_sys_exit(prof_syscall_exit);
 	mutex_unlock(&syscall_trace_lock);
 }
 
#58 lore raw

[tip:tracing/core] tracing: Move tracepoint callbacks from declaration to definition

In reply to Josh Stone
Commit-ID:  97419875865859fd2403e66266c02ce028e2f5ab
Gitweb:     http://git.kernel.org/tip/97419875865859fd2403e66266c02ce028e2f5ab
Author:     Josh Stone <[email protected]>
AuthorDate: Mon, 24 Aug 2009 14:43:13 -0700
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Wed, 26 Aug 2009 00:36:41 +0200

tracing: Move tracepoint callbacks from declaration to definition

It's not strictly correct for the tracepoint reg/unreg callbacks to occur when a client is hooking up, because the actual tracepoint may not be present yet. This happens to be fine for syscall, since that's in the core kernel, but it would cause problems for tracepoints defined in a module that hasn't been loaded yet. It also means the reg/unreg has to be EXPORTed for any modules to use the tracepoint (as in SystemTap).

This patch removes DECLARE_TRACE_WITH_CALLBACK, and instead introduces DEFINE_TRACE_FN which stores the callbacks in struct tracepoint. The callbacks are used now when the active state of the tracepoint changes in set_tracepoint & disable_tracepoint.

This also introduces TRACE_EVENT_FN, so ftrace events can also provide registration callbacks if needed.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/s390/kernel/ptrace.c    |    4 +-
 arch/x86/kernel/ptrace.c     |    4 +-
 include/linux/tracepoint.h   |   46 ++++++++++++++++-------------------------
 include/trace/define_trace.h |    5 ++++
 include/trace/ftrace.h       |    9 ++++++++
 include/trace/syscall.h      |   12 +++-------
 kernel/tracepoint.c          |   14 ++++++++----
 7 files changed, 49 insertions(+), 45 deletions(-)
arch/s390/kernel/ptrace.c +2 -2
index 9d3dcfa..c05b44b 100644
@@ -51,8 +51,8 @@
 #include "compat_ptrace.h"
 #endif
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 enum s390_regset {
 	REGSET_GENERAL,
arch/x86/kernel/ptrace.c +2 -2
index a909afe..31e9b97 100644
@@ -37,8 +37,8 @@
 
 #include <trace/syscall.h>
 
-DEFINE_TRACE(syscall_enter);
-DEFINE_TRACE(syscall_exit);
+DEFINE_TRACE_FN(syscall_enter, syscall_regfunc, syscall_unregfunc);
+DEFINE_TRACE_FN(syscall_exit, syscall_regfunc, syscall_unregfunc);
 
 #include "tls.h"
 
include/linux/tracepoint.h +18 -28

97 lines not on this page · raw message

include/trace/define_trace.h +5 -0
index f7a7ae1..2a96985 100644
@@ -26,6 +26,11 @@
 #define TRACE_EVENT(name, proto, args, tstruct, assign, print)	\
 	DEFINE_TRACE(name)
 
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_FN(name, reg, unreg)
+
 #undef DECLARE_TRACE
 #define DECLARE_TRACE(name, proto, args)	\
 	DEFINE_TRACE(name)
include/trace/ftrace.h +9 -0
index 1274002..3a0b44b 100644
@@ -42,6 +42,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+/* Callbacks are meaningless to ftrace. */
+#undef TRACE_EVENT_FN
+#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
+		assign, print, reg, unreg)			\
+	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
+		TP_STRUCT__entry(tstruct),			\
+		TP_fast_assign(assign),				\
+		TP_printk(print))
+
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
 
include/trace/syscall.h +4 -8
index 5dcb7e3..4e19430 100644
@@ -13,18 +13,14 @@
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_enter,
+DECLARE_TRACE(syscall_enter,
 	TP_PROTO(struct pt_regs *regs, long id),
-	TP_ARGS(regs, id),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, id)
 );
 
-DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
+DECLARE_TRACE(syscall_exit,
 	TP_PROTO(struct pt_regs *regs, long ret),
-	TP_ARGS(regs, ret),
-	syscall_regfunc,
-	syscall_unregfunc
+	TP_ARGS(regs, ret)
 );
 
 #endif
kernel/tracepoint.c +9 -5
index 9e0a36f..1a6a453 100644
@@ -243,6 +243,11 @@ static void set_tracepoint(struct tracepoint_entry **entry,
 {
 	WARN_ON(strcmp((*entry)->name, elem->name) != 0);
 
+	if (elem->regfunc && !elem->state && active)
+		elem->regfunc();
+	else if (elem->unregfunc && elem->state && !active)
+		elem->unregfunc();
+
 	/*
 	 * rcu_assign_pointer has a smp_wmb() which makes sure that the new
 	 * probe callbacks array is consistent before setting a pointer to it.
@@ -262,6 +267,9 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct tracepoint *elem)
 {
+	if (elem->unregfunc && elem->state)
+		elem->unregfunc();
+
 	elem->state = 0;
 	rcu_assign_pointer(elem->funcs, NULL);
 }
@@ -578,7 +586,7 @@ __initcall(init_tracepoints);
 
 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
 
-static DEFINE_MUTEX(regfunc_mutex);
+/* NB: reg/unreg are called while guarded with the tracepoints_mutex */
 static int sys_tracepoint_refcount;
 
 void syscall_regfunc(void)
@@ -586,7 +594,6 @@ void syscall_regfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
@@ -595,7 +602,6 @@ void syscall_regfunc(void)
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
 	sys_tracepoint_refcount++;
-	mutex_unlock(&regfunc_mutex);
 }
 
 void syscall_unregfunc(void)
@@ -603,7 +609,6 @@ void syscall_unregfunc(void)
 	unsigned long flags;
 	struct task_struct *g, *t;
 
-	mutex_lock(&regfunc_mutex);
 	sys_tracepoint_refcount--;
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
@@ -612,6 +617,5 @@ void syscall_unregfunc(void)
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
-	mutex_unlock(&regfunc_mutex);
 }
 #endif
#59 lore raw

PATCH 1/1 tracing: Fix double CPP substitution in TRACE_EVENT_FN

TRACE_EVENT_FN relays on TRACE_EVENT by reprocessing its parameters into the ftrace events CPP macro. This leads to a double substitution in some cases.

For example, a bad consequence is a format always prefixed by "%s, %s\n" for every TRACE_EVENT_FN based events.

Eg:

	cat /debug/tracing/events/syscalls/sys_enter/format
	[...]
	print fmt: "%s, %s\n", "\"NR %ld (%lx, %lx, %lx, %lx, %lx, %lx)\"",\
	"REC->id, REC->args[0], REC->args[1], REC->args[2], REC->args[3],\
	REC->args[4], REC->args[5]"

This creates a failure in post-processing tools such as perf trace or trace-cmd.

Then drop this double substitution and replace it by a new __cpparg() macro that relays CPP arguments containing commas.

Cc Josh Stone <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Jason Baron <[email protected]>
---
 include/trace/ftrace.h |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
include/trace/ftrace.h +7 -6
index 360a77a..57c56a9 100644
@@ -45,14 +45,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+#undef __cpparg
+#define __cpparg(arg...) arg
+
 /* Callbacks are meaningless to ftrace. */
 #undef TRACE_EVENT_FN
-#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
-		assign, print, reg, unreg)			\
-	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
-		TP_STRUCT__entry(tstruct),			\
-		TP_fast_assign(assign),				\
-		TP_printk(print))
+#define TRACE_EVENT_FN(name, proto, args, tstruct,			\
+		assign, print, reg, unreg)				\
+	TRACE_EVENT(name, __cpparg(proto), __cpparg(args),		\
+		__cpparg(tstruct), __cpparg(assign), __cpparg(print))	\
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
Signature · 1 line
1.6.2.3
author Reviewed-by on v1 1/1
#60 lore raw

Re: [PATCH] tracing: Fix double CPP substitution in TRACE_EVENT_FN

Quoted 8 lines · Frederic Weisbecker

TRACE_EVENT_FN relays on TRACE_EVENT by reprocessing its parameters into the ftrace events CPP macro. This leads to a double substitution in some cases.

For example, a bad consequence is a format always prefixed by "%s, %s\n" for every TRACE_EVENT_FN based events.

Eg:

Quoted 8 lines
	cat /debug/tracing/events/syscalls/sys_enter/format
	[...]
	print fmt: "%s, %s\n", "\"NR %ld (%lx, %lx, %lx, %lx, %lx, %lx)\"",\
	"REC->id, REC->args[0], REC->args[1], REC->args[2], REC->args[3],\
	REC->args[4], REC->args[5]"

This creates a failure in post-processing tools such as perf trace or trace-cmd.

Fun - I didn't think about TP_printk and friends doing anything beside passing their contents along.

Quoted 3 lines

Then drop this double substitution and replace it by a new __cpparg() macro that relays CPP arguments containing commas.

Looks good to me.

Quoted 6 lines
Cc Josh Stone <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Jason Baron <[email protected]>
#61 lore raw

[tip:tracing/core] tracing: Fix double CPP substitution in TRACE_EVENT_FN

In reply to Frederic Weisbecker
Commit-ID:  0dd7b74787eaf7858c6c573353a83c3e2766e674
Gitweb:     http://git.kernel.org/tip/0dd7b74787eaf7858c6c573353a83c3e2766e674
Author:     Frederic Weisbecker <[email protected]>
AuthorDate: Fri, 28 Aug 2009 00:50:06 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 28 Aug 2009 13:55:04 +0200

tracing: Fix double CPP substitution in TRACE_EVENT_FN

TRACE_EVENT_FN relays on TRACE_EVENT by reprocessing its parameters into the ftrace events CPP macro. This leads to a double substitution in some cases.

For example, a bad consequence is a format always prefixed by "%s, %s\n" for every TRACE_EVENT_FN based events.

Eg:

	cat /debug/tracing/events/syscalls/sys_enter/format
	[...]
	print fmt: "%s, %s\n", "\"NR %ld (%lx, %lx, %lx, %lx, %lx, %lx)\"",\
	"REC->id, REC->args[0], REC->args[1], REC->args[2], REC->args[3],\
	REC->args[4], REC->args[5]"

This creates a failure in post-processing tools such as perf trace or trace-cmd.

Then drop this double substitution and replace it by a new __cpparg() macro that relays CPP arguments containing commas.

Cc Josh Stone <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Jason Baron <[email protected]>

LKML-Reference: <[email protected]>

---
 include/trace/ftrace.h |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
include/trace/ftrace.h +7 -6
index 360a77a..57c56a9 100644
@@ -45,14 +45,15 @@
 	};							\
 	static struct ftrace_event_call event_##name
 
+#undef __cpparg
+#define __cpparg(arg...) arg
+
 /* Callbacks are meaningless to ftrace. */
 #undef TRACE_EVENT_FN
-#define TRACE_EVENT_FN(name, proto, args, tstruct,		\
-		assign, print, reg, unreg)			\
-	TRACE_EVENT(name, TP_PROTO(proto), TP_ARGS(args),	\
-		TP_STRUCT__entry(tstruct),			\
-		TP_fast_assign(assign),				\
-		TP_printk(print))
+#define TRACE_EVENT_FN(name, proto, args, tstruct,			\
+		assign, print, reg, unreg)				\
+	TRACE_EVENT(name, __cpparg(proto), __cpparg(args),		\
+		__cpparg(tstruct), __cpparg(assign), __cpparg(print))	\
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
#62 lore raw

[tip:tracing/core] tracing: Make syscall tracepoints conditional

In reply to Josh Stone
Commit-ID:  3d27d8cb34fc156beb86de2338ca4029873a5cc6
Gitweb:     http://git.kernel.org/tip/3d27d8cb34fc156beb86de2338ca4029873a5cc6
Author:     Josh Stone <[email protected]>
AuthorDate: Mon, 24 Aug 2009 14:43:12 -0700
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Wed, 26 Aug 2009 00:24:19 +0200

tracing: Make syscall tracepoints conditional

The syscall enter/exit tracepoints are only supported on archs that HAVE_SYSCALL_TRACEPOINTS, so the declarations should be #ifdef'ed. Also, the definition of syscall_regfunc and syscall_unregfunc should depend on this same config, rather than the ftrace-specific one.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>

LKML-Reference: <[email protected]>

---
 include/trace/syscall.h |    4 ++++
 kernel/tracepoint.c     |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)
include/trace/syscall.h +4 -0
index 9661dd4..5dcb7e3 100644
@@ -8,6 +8,8 @@
 #include <asm/ptrace.h>
 
 
+#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
+
 extern void syscall_regfunc(void);
 extern void syscall_unregfunc(void);
 
@@ -25,6 +27,8 @@ DECLARE_TRACE_WITH_CALLBACK(syscall_exit,
 	syscall_unregfunc
 );
 
+#endif
+
 /*
  * A syscall entry in the ftrace syscalls array.
  *
kernel/tracepoint.c +1 -1
index be86b9a..9e0a36f 100644
@@ -576,7 +576,7 @@ __initcall(init_tracepoints);
 
 #endif /* CONFIG_MODULES */
 
-#ifdef CONFIG_FTRACE_SYSCALLS
+#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
 
 static DEFINE_MUTEX(regfunc_mutex);
 static int sys_tracepoint_refcount;
#63 lore raw

[tip:tracing/core] tracing: Rename FTRACE_SYSCALLS for tracepoints

In reply to Josh Stone
Commit-ID:  667000011927b4fcc359beac4a2447889db6d349
Gitweb:     http://git.kernel.org/tip/667000011927b4fcc359beac4a2447889db6d349
Author:     Josh Stone <[email protected]>
AuthorDate: Mon, 24 Aug 2009 14:43:11 -0700
Committer:  Frederic Weisbecker <[email protected]>
CommitDate: Wed, 26 Aug 2009 00:17:35 +0200

tracing: Rename FTRACE_SYSCALLS for tracepoints

s/HAVE_FTRACE_SYSCALLS/HAVE_SYSCALL_TRACEPOINTS/g
s/TIF_SYSCALL_FTRACE/TIF_SYSCALL_TRACEPOINT/g

The syscall enter/exit tracing is no longer specific to just ftrace, so they now have names that reflect their tie to tracepoints instead.

Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Martin Schwidefsky <[email protected]>
Cc Heiko Carstens <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/s390/Kconfig                   |    2 +-
 arch/s390/defconfig                 |    2 +-
 arch/s390/include/asm/thread_info.h |    4 ++--
 arch/s390/kernel/entry.S            |    2 +-
 arch/s390/kernel/entry64.S          |    2 +-
 arch/s390/kernel/ptrace.c           |    4 ++--
 arch/x86/Kconfig                    |    2 +-
 arch/x86/configs/i386_defconfig     |    2 +-
 arch/x86/configs/x86_64_defconfig   |    2 +-
 arch/x86/include/asm/thread_info.h  |   13 +++++++------
 arch/x86/kernel/ptrace.c            |    4 ++--
 kernel/trace/Kconfig                |    4 ++--
 kernel/tracepoint.c                 |    4 ++--
 13 files changed, 24 insertions(+), 23 deletions(-)
arch/s390/Kconfig +1 -1
index 2ae5d72..7238ef4 100644
@@ -84,7 +84,7 @@ config S390
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_FTRACE_MCOUNT_RECORD
-	select HAVE_FTRACE_SYSCALLS
+	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_DEFAULT_NO_SPIN_MUTEXES
arch/s390/defconfig +1 -1
index fcba206..4e91a25 100644
@@ -900,7 +900,7 @@ CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
 CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
-CONFIG_HAVE_FTRACE_SYSCALLS=y
+CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
arch/s390/include/asm/thread_info.h +2 -2
index ba1cab9..07eb61b 100644
@@ -92,7 +92,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SYSCALL_TRACE	8	/* syscall trace active */
 #define TIF_SYSCALL_AUDIT	9	/* syscall auditing active */
 #define TIF_SECCOMP		10	/* secure computing */
-#define TIF_SYSCALL_FTRACE	11	/* ftrace syscall instrumentation */
+#define TIF_SYSCALL_TRACEPOINT	11	/* syscall tracepoint instrumentation */
 #define TIF_USEDFPU		16	/* FPU was used by this task this quantum (SMP) */
 #define TIF_POLLING_NRFLAG	17	/* true if poll_idle() is polling 
 					   TIF_NEED_RESCHED */
@@ -111,7 +111,7 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
 #define _TIF_SECCOMP		(1<<TIF_SECCOMP)
-#define _TIF_SYSCALL_FTRACE	(1<<TIF_SYSCALL_FTRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1<<TIF_SYSCALL_TRACEPOINT)
 #define _TIF_USEDFPU		(1<<TIF_USEDFPU)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 #define _TIF_31BIT		(1<<TIF_31BIT)
arch/s390/kernel/entry.S +1 -1
index c4c80a2..5d40fce 100644
@@ -54,7 +54,7 @@ _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-		_TIF_SECCOMP>>8 | _TIF_SYSCALL_FTRACE>>8)
+		_TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
 
 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
 STACK_SIZE  = 1 << STACK_SHIFT
arch/s390/kernel/entry64.S +1 -1
index f6618e9..3ceb53c 100644
@@ -57,7 +57,7 @@ _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
 		 _TIF_MCCK_PENDING)
 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
-		_TIF_SECCOMP>>8 | _TIF_SYSCALL_FTRACE>>8)
+		_TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
 
 #define BASED(name) name-system_call(%r13)
 
arch/s390/kernel/ptrace.c +2 -2
index c5e87d8..9d3dcfa 100644
@@ -664,7 +664,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
 		ret = -1;
 	}
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_enter(regs, regs->gprs[2]);
 
 	if (unlikely(current->audit_context))
@@ -682,7 +682,7 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)
 		audit_syscall_exit(AUDITSC_RESULT(regs->gprs[2]),
 				   regs->gprs[2]);
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_exit(regs, regs->gprs[2]);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
arch/x86/Kconfig +1 -1
index 738bdc6..d59cbf7 100644
@@ -37,7 +37,7 @@ config X86
 	select HAVE_FUNCTION_GRAPH_FP_TEST
 	select HAVE_FUNCTION_TRACE_MCOUNT_TEST
 	select HAVE_FTRACE_NMI_ENTER if DYNAMIC_FTRACE
-	select HAVE_FTRACE_SYSCALLS
+	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_KVM
 	select HAVE_ARCH_KGDB
 	select HAVE_ARCH_TRACEHOOK
arch/x86/configs/i386_defconfig +1 -1
index edb992e..d28fad1 100644
@@ -2355,7 +2355,7 @@ CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
 CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_HW_BRANCH_TRACER=y
-CONFIG_HAVE_FTRACE_SYSCALLS=y
+CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
 CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
arch/x86/configs/x86_64_defconfig +1 -1
index cee1dd2..6c86acd 100644
@@ -2329,7 +2329,7 @@ CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
 CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_HW_BRANCH_TRACER=y
-CONFIG_HAVE_FTRACE_SYSCALLS=y
+CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
 CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
arch/x86/include/asm/thread_info.h +7 -6
index fad7d40..6f7786a 100644
@@ -95,7 +95,7 @@ struct thread_info {
 #define TIF_DEBUGCTLMSR		25	/* uses thread_struct.debugctlmsr */
 #define TIF_DS_AREA_MSR		26      /* uses thread_struct.ds_area_msr */
 #define TIF_LAZY_MMU_UPDATES	27	/* task is updating the mmu lazily */
-#define TIF_SYSCALL_FTRACE	28	/* for ftrace syscall instrumentation */
+#define TIF_SYSCALL_TRACEPOINT	28	/* syscall tracepoint instrumentation */
 
 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
@@ -118,17 +118,17 @@ struct thread_info {
 #define _TIF_DEBUGCTLMSR	(1 << TIF_DEBUGCTLMSR)
 #define _TIF_DS_AREA_MSR	(1 << TIF_DS_AREA_MSR)
 #define _TIF_LAZY_MMU_UPDATES	(1 << TIF_LAZY_MMU_UPDATES)
-#define _TIF_SYSCALL_FTRACE	(1 << TIF_SYSCALL_FTRACE)
+#define _TIF_SYSCALL_TRACEPOINT	(1 << TIF_SYSCALL_TRACEPOINT)
 
 /* work to do in syscall_trace_enter() */
 #define _TIF_WORK_SYSCALL_ENTRY	\
-	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_FTRACE |	\
-	 _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | _TIF_SINGLESTEP)
+	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT |	\
+	 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
 
 /* work to do in syscall_trace_leave() */
 #define _TIF_WORK_SYSCALL_EXIT	\
 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP |	\
-	 _TIF_SYSCALL_FTRACE)
+	 _TIF_SYSCALL_TRACEPOINT)
 
 /* work to do on interrupt/exception return */
 #define _TIF_WORK_MASK							\
@@ -137,7 +137,8 @@ struct thread_info {
 	   _TIF_SINGLESTEP|_TIF_SECCOMP|_TIF_SYSCALL_EMU))
 
 /* work to do on any return to user space */
-#define _TIF_ALLWORK_MASK ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_FTRACE)
+#define _TIF_ALLWORK_MASK						\
+	((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
 
 /* Only used for 64 bit */
 #define _TIF_DO_NOTIFY_MASK						\
arch/x86/kernel/ptrace.c +2 -2
index 34dd6f1..a909afe 100644
@@ -1500,7 +1500,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
 	    tracehook_report_syscall_entry(regs))
 		ret = -1L;
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_enter(regs, regs->orig_ax);
 
 	if (unlikely(current->audit_context)) {
@@ -1526,7 +1526,7 @@ asmregparm void syscall_trace_leave(struct pt_regs *regs)
 	if (unlikely(current->audit_context))
 		audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
 
-	if (unlikely(test_thread_flag(TIF_SYSCALL_FTRACE)))
+	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
 		trace_syscall_exit(regs, regs->ax);
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE))
kernel/trace/Kconfig +2 -2
index 019f380..06be85a 100644
@@ -41,7 +41,7 @@ config HAVE_FTRACE_MCOUNT_RECORD
 config HAVE_HW_BRANCH_TRACER
 	bool
 
-config HAVE_FTRACE_SYSCALLS
+config HAVE_SYSCALL_TRACEPOINTS
 	bool
 
 config TRACER_MAX_TRACE
@@ -211,7 +211,7 @@ config ENABLE_DEFAULT_TRACERS
 
 config FTRACE_SYSCALLS
 	bool "Trace syscalls"
-	depends on HAVE_FTRACE_SYSCALLS
+	depends on HAVE_SYSCALL_TRACEPOINTS
 	select GENERIC_TRACER
 	select KALLSYMS
 	help
kernel/tracepoint.c +2 -2
index 06f165a..be86b9a 100644
@@ -590,7 +590,7 @@ void syscall_regfunc(void)
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
-			set_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
+			set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
@@ -608,7 +608,7 @@ void syscall_unregfunc(void)
 	if (!sys_tracepoint_refcount) {
 		read_lock_irqsave(&tasklist_lock, flags);
 		do_each_thread(g, t) {
-			clear_tsk_thread_flag(t, TIF_SYSCALL_FTRACE);
+			clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
 		} while_each_thread(g, t);
 		read_unlock_irqrestore(&tasklist_lock, flags);
 	}
Acked-by on the v4 series
#64 lore raw

Re: [PATCH v4 0/4] tracing: tweaks for generic syscall events

In reply to Josh Stone
Quoted 36 lines · Josh Stone

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

New in v4:
- Give the config flag a more generic name: HAVE_SYSCALL_TRACEPOINTS.
- Undo the arch reorg of the regfuncs, but conditionalize on above.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
Quoted 12 lines
Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>

Thanks!

#65 lore raw

Re: [PATCH v4 0/4] tracing: tweaks for generic syscall events

Quoted 51 lines · Frederic Weisbecker
Quoted 36 lines · Josh Stone

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

New in v4:
- Give the config flag a more generic name: HAVE_SYSCALL_TRACEPOINTS.
- Undo the arch reorg of the regfuncs, but conditionalize on above.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
Quoted 12 lines
Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
Quoted 1 line

How about compat syscalls? If we touch this code we better cover them as well.

Ingo

#66 lore raw

Re: [PATCH v4 0/4] tracing: tweaks for generic syscall events

Quoted 54 lines · Ingo Molnar
Quoted 51 lines · Frederic Weisbecker
Quoted 48 lines · Josh Stone

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

New in v4:
- Give the config flag a more generic name: HAVE_SYSCALL_TRACEPOINTS.
- Undo the arch reorg of the regfuncs, but conditionalize on above.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
Quoted 6 lines
Quoted 1 line

How about compat syscalls? If we touch this code we better cover them as well.

Ingo

They should be covered by these generic tracepoint I guess. The remaining bits that are necessary to cover individual compat syscall tracepoints are the missing DEFINE_SYSCALL() uses in fs/compat.c

Is someone willing to cover them?

Thanks,
Frederic.

#67 lore raw

Re: [PATCH v4 0/4] tracing: tweaks for generic syscall events

Quoted 58 lines · Frederic Weisbecker
Quoted 58 lines · Frederic Weisbecker
Quoted 52 lines · Josh Stone
Quoted 36 lines

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

New in v4:
- Give the config flag a more generic name: HAVE_SYSCALL_TRACEPOINTS.
- Undo the arch reorg of the regfuncs, but conditionalize on above.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
Quoted 12 lines
Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>
Quoted 1 line

How about compat syscalls? If we touch this code we better cover them as well.

Quoted 7 lines
Quoted 1 line

Ingo

They should be covered by these generic tracepoint I guess. The remaining bits that are necessary to cover individual compat syscall tracepoints are the missing DEFINE_SYSCALL() uses in fs/compat.c

right, the compat layer as well as the core kernel need additional DEFINE_SYSCALL() macros to catch all the the syscalls. However, I think the compat layer is a bit more involved in that it often makes use of the core kernel syscalls, but the mapping between syscall number is different. So, we need another array, or to augment the existing one, to cover the compat syscalls. We also need to detect 32-bit processes in the syscall entry path to determine which array to use, and we need to grab the arguments differently. So there is a bunch of work here.

Also, we have the question of whether we need separate entries in the events/syscalls directly for 32-bit process syscalls that call the same 64-bit syscall interfaces. Should they be parsed as 64-bit argument values event thought they are 32-bit? To reduce complexity, I would say the 32-bit syscall entries should be the same as the 64-bit ones. That said there will be a bunch of new "compat_sys*" etc. entries.

Quoted 2 lines

Is someone willing to cover them?

I can take a stab at it.

thanks,

-Jason

#68 lore raw

Re: [PATCH v4 0/4] tracing: tweaks for generic syscall events

Quoted 8 lines · Jason Baron

right, the compat layer as well as the core kernel need additional DEFINE_SYSCALL() macros to catch all the the syscalls. However, I think the compat layer is a bit more involved in that it often makes use of the core kernel syscalls, but the mapping between syscall number is different. So, we need another array, or to augment the existing one, to cover the compat syscalls. We also need to detect 32-bit processes in the syscall entry path to determine which array to use, and we need to grab the arguments differently. So there is a bunch of work here.

Hmm, indeed we may need a parallel compat_syscall_table for the metadata and other kind of special treatements.
I wonder how ptrace sort it out in syscall_trace_enter() to guess the origin of the syscall (ia32 or normal), since the table is not mapped with the same numbers.

Quoted 7 lines

Also, we have the question of whether we need separate entries in the events/syscalls directly for 32-bit process syscalls that call the same 64-bit syscall interfaces. Should they be parsed as 64-bit argument values event thought they are 32-bit? To reduce complexity, I would say the 32-bit syscall entries should be the same as the 64-bit ones. That said there will be a bunch of new "compat_sys*" etc. entries.

We could probably re-route the compat syscall tracing to their homologuous 64 bits tracepoints, but one may want to only trace the compat_syscalls, use filters only on them, activate only some of them, etc...

To do such routing, we could have a simple table that resolves a compat syscall number to its real 64 bits syscall number and we could then pass this number plus a flag that set its compat state in the ring buffer entry.
That would avoid the need of using the DEFINE_SYSCALLx() in fs/compat.c

But such ghost tracepoints would also complexify too much the filter processing, the individual tracepoints toggling, etc...
So I think having real compat tracepoints would actually be more simple.

We could still use shortcuts in userspace if we want to enable sys_enter_open and sys_enter_compat_open at the same time.

Hmm?

Quoted 4 lines
Quoted 2 lines

Is someone willing to cover them?

I can take a stab at it.

Thanks a lot!

Quoted 3 lines

thanks,

-Jason

#69 lore raw

Re: [PATCH v4 0/4] tracing: tweaks for generic syscall events

In reply to Josh Stone
Quoted 36 lines · Josh Stone

This patch series moves the callbacks for the syscall tracepoints to the definition site, and adds generic TRACE_EVENTs which capture all syscall arguments.

New in v3:
- Give the thread flag a more generic name: TIF_SYSCALL_TRACEPOINT.
- Move the regfuncs to arch-specific files, per Jason's suggestion.
- Change _WITH_CALLBACK to just _FN, per Ingo's suggestion.

New in v4:
- Give the config flag a more generic name: HAVE_SYSCALL_TRACEPOINTS.
- Undo the arch reorg of the regfuncs, but conditionalize on above.

Sample trace output:

        sendmail-974   [000] 55665.464492: sys_enter: NR 14 (1, 7fff60f3af40, 7fff60f3aec0, 8, 0, 7fb1b6a05161)

        sendmail-974   [000] 55665.464496: sys_exit: NR 14 = 0

        sendmail-974   [000] 55665.464507: sys_enter: NR 23 (5, 7fff60f3b0d0, 0, 0, 7fff60f3b150, 7fff60f3ef01)

            sshd-978   [000] 55667.845359: sys_exit: NR 23 = 1

            sshd-978   [000] 55667.845373: sys_enter: NR 14 (0, 7fffc645ce90, 7fffc645cf10, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845381: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845383: sys_enter: NR 14 (2, 7fffc645cf10, 0, 8, 0, 101010101010101)

            sshd-978   [000] 55667.845386: sys_exit: NR 14 = 0

            sshd-978   [000] 55667.845395: sys_enter: NR 0 (3, 7fffc6458f80, 4000, 1, 0, 0)

            sshd-978   [000] 55667.845478: sys_exit: NR 0 = 48
Quoted 12 lines
Cc Jason Baron <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Li Zefan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
Cc Jiaying Zhang <[email protected]>
Cc Martin Bligh <[email protected]>
Cc Lai Jiangshan <[email protected]>
Cc Paul Mundt <[email protected]>

Queued for .32, thanks!

Quoted 21 lines
---
 arch/s390/Kconfig                   |    2 +-
 arch/s390/defconfig                 |    2 +-
 arch/s390/include/asm/thread_info.h |    4 +-
 arch/s390/kernel/entry.S            |    2 +-
 arch/s390/kernel/entry64.S          |    2 +-
 arch/s390/kernel/ptrace.c           |   12 +++---
 arch/x86/Kconfig                    |    2 +-
 arch/x86/configs/i386_defconfig     |    2 +-
 arch/x86/configs/x86_64_defconfig   |    2 +-
 arch/x86/include/asm/thread_info.h  |   13 +++---
 arch/x86/kernel/ptrace.c            |   16 +++----
 include/linux/tracepoint.h          |   46 +++++++++--------------
 include/trace/define_trace.h        |    5 ++
 include/trace/events/syscalls.h     |   70 +++++++++++++++++++++++++++++++++++
 include/trace/ftrace.h              |    9 ++++
 include/trace/syscall.h             |   17 --------
 kernel/trace/Kconfig                |    4 +-
 kernel/trace/trace_syscalls.c       |   17 ++++----
 kernel/tracepoint.c                 |   20 ++++++----