HACK: perf: Allow set-output for task contexts of different types

Set-output must be limited to events that cannot be active on different
cpus at the same time.  Thus either the event cpu must be the same, or
the event task must be the same.  Current logic does not check the task
directly but checks whether the perf_event_context is the same, however
there are separate contexts for hardware and software events so in that
case the perf_event_context is different even though the task is the same.
This patch changes the logic to check the task directly.

HACK WARNING: since set_output() can be called from perf_event_open() to
attach to another event's buffer, we need to take into account that the
new event doesn't have a context at that point, so hack around that. This
will need a better fix.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6a2f8b7..faee8e5 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -9917,7 +9917,8 @@
 	 * If its not a per-cpu rb, it must be the same task.
-	if (output_event->cpu == -1 && output_event->ctx != event->ctx)
+	if (output_event->cpu == -1 &&
+	    output_event->ctx->task != event->ctx->task)
 		goto out;
@@ -10290,7 +10291,9 @@
 	if (output_event) {
+		event->ctx = ctx; /* XXX XXX XXX */
 		err = perf_event_set_output(event, output_event);
+		event->ctx = NULL; /* XXX XXX XXX */
 		if (err)
 			goto err_context;