[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <162245764385.29796.9800747748903959917.tip-bot2@tip-bot2>
Date: Mon, 31 May 2021 10:40:43 -0000
From: "tip-bot2 for Marco Elver" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: syzbot+142c9018f5962db69c7e@...kaller.appspotmail.com,
Marco Elver <elver@...gle.com>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [tip: perf/urgent] perf: Fix data race between pin_count increment/decrement
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 6c605f8371159432ec61cbb1488dcf7ad24ad19a
Gitweb: https://git.kernel.org/tip/6c605f8371159432ec61cbb1488dcf7ad24ad19a
Author: Marco Elver <elver@...gle.com>
AuthorDate: Thu, 27 May 2021 12:47:11 +02:00
Committer: Peter Zijlstra <peterz@...radead.org>
CommitterDate: Mon, 31 May 2021 10:14:51 +02:00
perf: Fix data race between pin_count increment/decrement
KCSAN reports a data race between increment and decrement of pin_count:
write to 0xffff888237c2d4e0 of 4 bytes by task 15740 on cpu 1:
find_get_context kernel/events/core.c:4617
__do_sys_perf_event_open kernel/events/core.c:12097 [inline]
__se_sys_perf_event_open kernel/events/core.c:11933
...
read to 0xffff888237c2d4e0 of 4 bytes by task 15743 on cpu 0:
perf_unpin_context kernel/events/core.c:1525 [inline]
__do_sys_perf_event_open kernel/events/core.c:12328 [inline]
__se_sys_perf_event_open kernel/events/core.c:11933
...
Because neither read-modify-write here is atomic, this can lead to one
of the operations being lost, resulting in an inconsistent pin_count.
Fix it by adding the missing locking in the CPU-event case.
Fixes: fe4b04fa31a6 ("perf: Cure task_oncpu_function_call() races")
Reported-by: syzbot+142c9018f5962db69c7e@...kaller.appspotmail.com
Signed-off-by: Marco Elver <elver@...gle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Link: https://lkml.kernel.org/r/20210527104711.2671610-1-elver@google.com
---
kernel/events/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 6fee4a7..fe88d6e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4609,7 +4609,9 @@ find_get_context(struct pmu *pmu, struct task_struct *task,
cpuctx = per_cpu_ptr(pmu->pmu_cpu_context, cpu);
ctx = &cpuctx->ctx;
get_ctx(ctx);
+ raw_spin_lock_irqsave(&ctx->lock, flags);
++ctx->pin_count;
+ raw_spin_unlock_irqrestore(&ctx->lock, flags);
return ctx;
}
Powered by blists - more mailing lists