Commit 24d3ae2
perf/core: Fix the same task check in perf_event_set_output
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/[email protected]/
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 bd27568 ("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 c3f00c7
("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 50f16a8 ("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
c3f00c7. The patch may cannot be applied between the commit
c3f00c7 and commit 50f16a8. Anybody that wants to back-port
this at that period may have to find other solutions.
Fixes: c3f00c7 ("perf: Separate find_get_context() from event initialization")
Signed-off-by: Kan Liang <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Reviewed-by: Zhengjun Xing <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]1 parent b168098 commit 24d3ae2
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12173 | 12173 | | |
12174 | 12174 | | |
12175 | 12175 | | |
12176 | | - | |
| 12176 | + | |
12177 | 12177 | | |
12178 | 12178 | | |
12179 | 12179 | | |
| |||
0 commit comments