mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Beau Belgrave <beaub@linux.microsoft.com>
Subject: [for-next][PATCH 08/16] user_events: Add basic perf and eBPF support
Date: Fri, 18 Feb 2022 19:54:38 -0500	[thread overview]
Message-ID: <20220219005513.718449233@goodmis.org> (raw)
In-Reply-To: <20220219005430.848118506@goodmis.org>

From: Beau Belgrave <beaub@linux.microsoft.com>

Adds support to write out user_event data to perf_probe/perf files as
well as to any attached eBPF program.

Link: https://lkml.kernel.org/r/20220118204326.2169-5-beaub@linux.microsoft.com

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace_events_user.c | 72 +++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index a6794cb1f586..371f31472156 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -551,6 +551,50 @@ static void user_event_ftrace(struct user_event *user, void *data, u32 datalen,
 	trace_event_buffer_commit(&event_buffer);
 }
 
+#ifdef CONFIG_PERF_EVENTS
+/*
+ * Writes the user supplied payload out to perf ring buffer or eBPF program.
+ */
+static void user_event_perf(struct user_event *user, void *data, u32 datalen,
+			    void *tpdata)
+{
+	struct hlist_head *perf_head;
+
+	if (bpf_prog_array_valid(&user->call)) {
+		struct user_bpf_context context = {0};
+
+		context.data_len = datalen;
+		context.data_type = USER_BPF_DATA_KERNEL;
+		context.kdata = data;
+
+		trace_call_bpf(&user->call, &context);
+	}
+
+	perf_head = this_cpu_ptr(user->call.perf_events);
+
+	if (perf_head && !hlist_empty(perf_head)) {
+		struct trace_entry *perf_entry;
+		struct pt_regs *regs;
+		size_t size = sizeof(*perf_entry) + datalen;
+		int context;
+
+		perf_entry = perf_trace_buf_alloc(ALIGN(size, 8),
+						  &regs, &context);
+
+		if (unlikely(!perf_entry))
+			return;
+
+		perf_fetch_caller_regs(regs);
+
+		memcpy(perf_entry + 1, data, datalen);
+
+		perf_trace_buf_submit(perf_entry, size, context,
+				      user->call.event.type, 1, regs,
+				      perf_head, NULL);
+	}
+}
+#endif
+
 /*
  * Update the register page that is shared between user processes.
  */
@@ -573,6 +617,10 @@ static void update_reg_page_for(struct user_event *user)
 
 				if (probe_func == user_event_ftrace)
 					status |= EVENT_STATUS_FTRACE;
+#ifdef CONFIG_PERF_EVENTS
+				else if (probe_func == user_event_perf)
+					status |= EVENT_STATUS_PERF;
+#endif
 				else
 					status |= EVENT_STATUS_OTHER;
 			} while ((++probe_func_ptr)->func);
@@ -612,8 +660,27 @@ static int user_event_reg(struct trace_event_call *call,
 					    data);
 		goto dec;
 
-	default:
+#ifdef CONFIG_PERF_EVENTS
+	case TRACE_REG_PERF_REGISTER:
+		ret = tracepoint_probe_register(call->tp,
+						call->class->perf_probe,
+						data);
+		if (!ret)
+			goto inc;
+		break;
+
+	case TRACE_REG_PERF_UNREGISTER:
+		tracepoint_probe_unregister(call->tp,
+					    call->class->perf_probe,
+					    data);
+		goto dec;
+
+	case TRACE_REG_PERF_OPEN:
+	case TRACE_REG_PERF_CLOSE:
+	case TRACE_REG_PERF_ADD:
+	case TRACE_REG_PERF_DEL:
 		break;
+#endif
 	}
 
 	return ret;
@@ -870,6 +937,9 @@ static int user_event_parse(char *name, char *args, char *flags,
 	user->class.get_fields = user_event_get_fields;
 	user->class.reg = user_event_reg;
 	user->class.probe = user_event_ftrace;
+#ifdef CONFIG_PERF_EVENTS
+	user->class.perf_probe = user_event_perf;
+#endif
 
 	mutex_lock(&event_mutex);
 	ret = user_event_trace_register(user);
-- 
2.34.1

  parent reply	other threads:[~2022-02-19  0:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-19  0:54 [for-next][PATCH 00/16] tracing: Updates for 5.18 Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 01/16] tracing: Remove size restriction on tracing_log_err cmd strings Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 02/16] tracing: Remove size restriction on hist trigger cmd error logging Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 03/16] tracing: Remove size restriction on synthetic event " Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 04/16] tracing: Save both wakee and current on wakeup events Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 05/16] user_events: Add minimal support for trace_event into ftrace Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 06/16] user_events: Add print_fmt generation support for basic types Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 07/16] user_events: Handle matching arguments from dyn_events Steven Rostedt
2022-02-19  0:54 ` Steven Rostedt [this message]
2022-02-19  0:54 ` [for-next][PATCH 09/16] user_events: Optimize writing events by only copying data once Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 10/16] user_events: Validate user payloads for size and null termination Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 11/16] user_events: Add self-test for ftrace integration Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 12/16] user_events: Add self-test for dynamic_events integration Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 13/16] user_events: Add self-test for perf_event integration Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 14/16] user_events: Add self-test for validator boundaries Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 15/16] user_events: Add sample code for typical usage Steven Rostedt
2022-02-19  0:54 ` [for-next][PATCH 16/16] user_events: Add documentation file Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220219005513.718449233@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=beaub@linux.microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®