perf/core: Fix __perf_read_group_add() locking
authorPeter Zijlstra <peterz@infradead.org>
Tue, 5 Sep 2017 11:38:24 +0000 (13:38 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 10 Dec 2017 12:40:40 +0000 (13:40 +0100)
[ Upstream commit a9cd8194e1e6bd09619954721dfaf0f94fe2003e ]

Event timestamps are serialized using ctx->lock, make sure to hold it
over reading all values.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/events/core.c

index 10cdb9c26b5d12d41ddacda43e335a9d635c66a7..4f1d4bfc607a32abea623af2736310103a9c305d 100644 (file)
@@ -4433,6 +4433,8 @@ static int __perf_read_group_add(struct perf_event *leader,
        if (ret)
                return ret;
 
+       raw_spin_lock_irqsave(&ctx->lock, flags);
+
        /*
         * Since we co-schedule groups, {enabled,running} times of siblings
         * will be identical to those of the leader, so we only publish one
@@ -4455,8 +4457,6 @@ static int __perf_read_group_add(struct perf_event *leader,
        if (read_format & PERF_FORMAT_ID)
                values[n++] = primary_event_id(leader);
 
-       raw_spin_lock_irqsave(&ctx->lock, flags);
-
        list_for_each_entry(sub, &leader->sibling_list, group_entry) {
                values[n++] += perf_event_count(sub);
                if (read_format & PERF_FORMAT_ID)