]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
Fixes for 5.4
authorSasha Levin <sashal@kernel.org>
Mon, 10 Apr 2023 12:34:54 +0000 (08:34 -0400)
committerSasha Levin <sashal@kernel.org>
Mon, 10 Apr 2023 12:34:54 +0000 (08:34 -0400)
Signed-off-by: Sasha Levin <sashal@kernel.org>
queue-5.4/perf-core-fix-the-same-task-check-in-perf_event_set_.patch [new file with mode: 0644]
queue-5.4/series

diff --git a/queue-5.4/perf-core-fix-the-same-task-check-in-perf_event_set_.patch b/queue-5.4/perf-core-fix-the-same-task-check-in-perf_event_set_.patch
new file mode 100644 (file)
index 0000000..c498f23
--- /dev/null
@@ -0,0 +1,73 @@
+From b0597ed12dc19bbb7cfdb5b531c060303b29d138 Mon Sep 17 00:00:00 2001
+From: Sasha Levin <sashal@kernel.org>
+Date: Wed, 22 Mar 2023 13:24:49 -0700
+Subject: perf/core: Fix the same task check in perf_event_set_output
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+From: Kan Liang <kan.liang@linux.intel.com>
+
+[ Upstream commit 24d3ae2f37d8bc3c14b31d353c5d27baf582b6a6 ]
+
+The same task check in perf_event_set_output has some potential issues
+for some usages.
+
+For the current perf code, there is a problem if using of
+perf_event_open() to have multiple samples getting into the same mmap’d
+memory when they are both attached to the same process.
+https://lore.kernel.org/all/92645262-D319-4068-9C44-2409EF44888E@gmail.com/
+Because the event->ctx is not ready when the perf_event_set_output() is
+invoked in the perf_event_open().
+
+Besides the above issue, before the commit bd2756811766 ("perf: Rewrite
+core context handling"), perf record can errors out when sampling with
+a hardware event and a software event as below.
+ $ perf record -e cycles,dummy --per-thread ls
+ failed to mmap with 22 (Invalid argument)
+That's because that prior to the commit a hardware event and a software
+event are from different task context.
+
+The problem should be a long time issue since commit c3f00c70276d
+("perk: Separate find_get_context() from event initialization").
+
+The task struct is stored in the event->hw.target for each per-thread
+event. It is a more reliable way to determine whether two events are
+attached to the same task.
+
+The event->hw.target was also introduced several years ago by the
+commit 50f16a8bf9d7 ("perf: Remove type specific target pointers"). It
+can not only be used to fix the issue with the current code, but also
+back port to fix the issues with an older kernel.
+
+Note: The event->hw.target was introduced later than commit
+c3f00c70276d. The patch may cannot be applied between the commit
+c3f00c70276d and commit 50f16a8bf9d7. Anybody that wants to back-port
+this at that period may have to find other solutions.
+
+Fixes: c3f00c70276d ("perf: Separate find_get_context() from event initialization")
+Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
+Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
+Reviewed-by: Zhengjun Xing <zhengjun.xing@linux.intel.com>
+Link: https://lkml.kernel.org/r/20230322202449.512091-1-kan.liang@linux.intel.com
+Signed-off-by: Sasha Levin <sashal@kernel.org>
+---
+ kernel/events/core.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/kernel/events/core.c b/kernel/events/core.c
+index a1c89b675b0b9..1ef924d6a385e 100644
+--- a/kernel/events/core.c
++++ b/kernel/events/core.c
+@@ -10798,7 +10798,7 @@ perf_event_set_output(struct perf_event *event, struct perf_event *output_event)
+       /*
+        * 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->hw.target != event->hw.target)
+               goto out;
+       /*
+-- 
+2.39.2
+
index 66f4536f1ff7c022823b14d10ab8d1ab75beb5ba..a335af764fdc6e07bad04c88311dcd93b1782fac 100644 (file)
@@ -15,3 +15,4 @@ gpio-davinci-add-irq-chip-flag-to-skip-set-wake.patch
 sunrpc-only-free-unix-grouplist-after-rcu-settles.patch
 nfsd-callback-request-does-not-use-correct-credentia.patch
 xhci-also-avoid-the-xhci_zero_64b_regs-quirk-with-a-passthrough-iommu.patch
+perf-core-fix-the-same-task-check-in-perf_event_set_.patch