From c2b33a97db1f7ef48e88520dee2d8d0ee6057643 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 6 Jun 2016 09:37:36 -0400 Subject: [PATCH] tracing: instrument restartable sequences Signed-off-by: Mathieu Desnoyers CC: Thomas Gleixner CC: Paul Turner CC: Andrew Hunter CC: Peter Zijlstra CC: Andy Lutomirski CC: Andi Kleen CC: Dave Watson CC: Chris Lameter CC: Ingo Molnar CC: "H. Peter Anvin" CC: Ben Maurer CC: Steven Rostedt CC: "Paul E. McKenney" CC: Josh Triplett CC: Linus Torvalds CC: Andrew Morton CC: Russell King CC: Catalin Marinas CC: Will Deacon CC: Michael Kerrisk CC: Boqun Feng CC: linux-api@vger.kernel.org --- include/trace/events/rseq.h | 64 +++++++++++++++++++++++++++++++++++++ kernel/rseq.c | 11 ++++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 include/trace/events/rseq.h diff --git a/include/trace/events/rseq.h b/include/trace/events/rseq.h new file mode 100644 index 000000000000..63a8eb7d553d --- /dev/null +++ b/include/trace/events/rseq.h @@ -0,0 +1,64 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM rseq + +#if !defined(_TRACE_RSEQ_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_RSEQ_H + +#include +#include + +TRACE_EVENT(rseq_update, + + TP_PROTO(struct task_struct *t), + + TP_ARGS(t), + + TP_STRUCT__entry( + __field(s32, cpu_id) + __field(u32, event_counter) + ), + + TP_fast_assign( + __entry->cpu_id = raw_smp_processor_id(); + __entry->event_counter = t->rseq_event_counter; + ), + + TP_printk("cpu_id=%d event_counter=%u", + __entry->cpu_id, __entry->event_counter) +); + +TRACE_EVENT(rseq_ip_fixup, + + TP_PROTO(void __user *regs_ip, void __user *start_ip, + void __user *post_commit_ip, void __user *abort_ip, + u32 kevcount, int ret), + + TP_ARGS(regs_ip, start_ip, post_commit_ip, abort_ip, kevcount, ret), + + TP_STRUCT__entry( + __field(void __user *, regs_ip) + __field(void __user *, start_ip) + __field(void __user *, post_commit_ip) + __field(void __user *, abort_ip) + __field(u32, kevcount) + __field(int, ret) + ), + + TP_fast_assign( + __entry->regs_ip = regs_ip; + __entry->start_ip = start_ip; + __entry->post_commit_ip = post_commit_ip; + __entry->abort_ip = abort_ip; + __entry->kevcount = kevcount; + __entry->ret = ret; + ), + + TP_printk("regs_ip=%p start_ip=%p post_commit_ip=%p abort_ip=%p kevcount=%u ret=%d", + __entry->regs_ip, __entry->start_ip, __entry->post_commit_ip, + __entry->abort_ip, __entry->kevcount, __entry->ret) +); + +#endif /* _TRACE_SOCK_H */ + +/* This part must be outside protection */ +#include diff --git a/kernel/rseq.c b/kernel/rseq.c index 32bc1d27a6b1..a102fcc9994e 100644 --- a/kernel/rseq.c +++ b/kernel/rseq.c @@ -32,6 +32,9 @@ #include #include +#define CREATE_TRACE_POINTS +#include + /* * The restartable sequences mechanism is the overlap of two distinct * restart mechanisms: a sequence counter tracking preemption and signal @@ -137,6 +140,7 @@ static bool rseq_update_cpu_id_event_counter(struct task_struct *t) u.e.event_counter = ++t->rseq_event_counter; if (__put_user(u.v, &t->rseq->u.v)) return false; + trace_rseq_update(t); return true; } @@ -168,8 +172,13 @@ static bool rseq_ip_fixup(struct pt_regs *regs) void __user *start_ip = NULL; void __user *post_commit_ip = NULL; void __user *abort_ip = NULL; + bool ret; - if (!rseq_get_rseq_cs(t, &start_ip, &post_commit_ip, &abort_ip)) + ret = rseq_get_rseq_cs(t, &start_ip, &post_commit_ip, &abort_ip); + trace_rseq_ip_fixup((void __user *)instruction_pointer(regs), + start_ip, post_commit_ip, abort_ip, t->rseq_event_counter, + ret); + if (!ret) return false; /* Handle potentially not being within a critical section. */ -- 2.34.1