All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] perf: Copy perf_event_attr::sig_data on modification
@ 2022-01-31 10:34 Marco Elver
  2022-01-31 10:34 ` [PATCH 2/3] selftests/perf_events: Test modification of perf_event_attr::sig_data Marco Elver
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Marco Elver @ 2022-01-31 10:34 UTC (permalink / raw)
  To: elver, Peter Zijlstra
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Dmitry Vyukov,
	linux-perf-users, kasan-dev, linux-kernel

The intent has always been that perf_event_attr::sig_data should also be
modifiable along with PERF_EVENT_IOC_MODIFY_ATTRIBUTES, because it is
observable by user space if SIGTRAP on events is requested.

Currently only PERF_TYPE_BREAKPOINT is modifiable, and explicitly copies
relevant breakpoint-related attributes in hw_breakpoint_copy_attr().
This misses copying perf_event_attr::sig_data.

Since sig_data is not specific to PERF_TYPE_BREAKPOINT, introduce a
helper to copy generic event-type-independent attributes on
modification.

Fixes: 97ba62b27867 ("perf: Add support for SIGTRAP on perf events")
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Marco Elver <elver@google.com>
---
 kernel/events/core.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index fc18664f49b0..db0d85a85f1b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3197,6 +3197,15 @@ static int perf_event_modify_breakpoint(struct perf_event *bp,
 	return err;
 }
 
+/*
+ * Copy event-type-independent attributes that may be modified.
+ */
+static void perf_event_modify_copy_attr(struct perf_event_attr *to,
+					const struct perf_event_attr *from)
+{
+	to->sig_data = from->sig_data;
+}
+
 static int perf_event_modify_attr(struct perf_event *event,
 				  struct perf_event_attr *attr)
 {
@@ -3219,10 +3228,17 @@ static int perf_event_modify_attr(struct perf_event *event,
 	WARN_ON_ONCE(event->ctx->parent_ctx);
 
 	mutex_lock(&event->child_mutex);
+	/*
+	 * Event-type-independent attributes must be copied before event-type
+	 * modification, which will validate that final attributes match the
+	 * source attributes after all relevant attributes have been copied.
+	 */
+	perf_event_modify_copy_attr(&event->attr, attr);
 	err = func(event, attr);
 	if (err)
 		goto out;
 	list_for_each_entry(child, &event->child_list, child_list) {
+		perf_event_modify_copy_attr(&child->attr, attr);
 		err = func(child, attr);
 		if (err)
 			goto out;
-- 
2.35.0.rc2.247.g8bbb082509-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-02-03 14:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-31 10:34 [PATCH 1/3] perf: Copy perf_event_attr::sig_data on modification Marco Elver
2022-01-31 10:34 ` [PATCH 2/3] selftests/perf_events: Test modification of perf_event_attr::sig_data Marco Elver
2022-02-01  7:33   ` Dmitry Vyukov
2022-02-03 14:33   ` [tip: perf/urgent] " tip-bot2 for Marco Elver
2022-01-31 10:34 ` [PATCH 3/3] perf: uapi: Document perf_event_attr::sig_data truncation on 32 bit architectures Marco Elver
2022-02-01  7:33   ` Dmitry Vyukov
2022-02-03 14:33   ` [tip: perf/urgent] " tip-bot2 for Marco Elver
2022-02-01  7:32 ` [PATCH 1/3] perf: Copy perf_event_attr::sig_data on modification Dmitry Vyukov
2022-02-01 11:07   ` Peter Zijlstra
2022-02-03 14:33 ` [tip: perf/urgent] " tip-bot2 for Marco Elver

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.