Skip to content

Commit d0774cf

Browse files
James-A-Clarkgregkh
authored andcommitted
perf: Always wake the parent event
[ Upstream commit 961c391 ] When using per-process mode and event inheritance is set to true, forked processes will create a new perf events via inherit_event() -> perf_event_alloc(). But these events will not have ring buffers assigned to them. Any call to wakeup will be dropped if it's called on an event with no ring buffer assigned because that's the object that holds the wakeup list. If the child event is disabled due to a call to perf_aux_output_begin() or perf_aux_output_end(), the wakeup is dropped leaving userspace hanging forever on the poll. Normally the event is explicitly re-enabled by userspace after it wakes up to read the aux data, but in this case it does not get woken up so the event remains disabled. This can be reproduced when using Arm SPE and 'stress' which forks once before running the workload. By looking at the list of aux buffers read, it's apparent that they stop after the fork: perf record -e arm_spe// -vvv -- stress -c 1 With this patch applied they continue to be printed. This behaviour doesn't happen when using systemwide or per-cpu mode. Reported-by: Ruben Ayrapetyan <Ruben.Ayrapetyan@arm.com> Signed-off-by: James Clark <james.clark@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20211206113840.130802-2-james.clark@arm.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a117e98 commit d0774cf

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎kernel/events/core.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5877,6 +5877,8 @@ static void ring_buffer_attach(struct perf_event *event,
58775877
struct perf_buffer *old_rb = NULL;
58785878
unsigned long flags;
58795879

5880+
WARN_ON_ONCE(event->parent);
5881+
58805882
if (event->rb) {
58815883
/*
58825884
* Should be impossible, we set this when removing
@@ -5934,6 +5936,9 @@ static void ring_buffer_wakeup(struct perf_event *event)
59345936
{
59355937
struct perf_buffer *rb;
59365938

5939+
if (event->parent)
5940+
event = event->parent;
5941+
59375942
rcu_read_lock();
59385943
rb = rcu_dereference(event->rb);
59395944
if (rb) {
@@ -5947,6 +5952,9 @@ struct perf_buffer *ring_buffer_get(struct perf_event *event)
59475952
{
59485953
struct perf_buffer *rb;
59495954

5955+
if (event->parent)
5956+
event = event->parent;
5957+
59505958
rcu_read_lock();
59515959
rb = rcu_dereference(event->rb);
59525960
if (rb) {
@@ -6618,7 +6626,7 @@ static unsigned long perf_prepare_sample_aux(struct perf_event *event,
66186626
if (WARN_ON_ONCE(READ_ONCE(sampler->oncpu) != smp_processor_id()))
66196627
goto out;
66206628

6621-
rb = ring_buffer_get(sampler->parent ? sampler->parent : sampler);
6629+
rb = ring_buffer_get(sampler);
66226630
if (!rb)
66236631
goto out;
66246632

@@ -6684,7 +6692,7 @@ static void perf_aux_sample_output(struct perf_event *event,
66846692
if (WARN_ON_ONCE(!sampler || !data->aux_size))
66856693
return;
66866694

6687-
rb = ring_buffer_get(sampler->parent ? sampler->parent : sampler);
6695+
rb = ring_buffer_get(sampler);
66886696
if (!rb)
66896697
return;
66906698

0 commit comments

Comments
 (0)