From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933573AbbIVNqN (ORCPT ); Tue, 22 Sep 2015 09:46:13 -0400 Received: from terminus.zytor.com ([198.137.202.10]:49652 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933287AbbIVNqL (ORCPT ); Tue, 22 Sep 2015 09:46:11 -0400 Date: Tue, 22 Sep 2015 06:45:56 -0700 From: tip-bot for Dmitry Vyukov Message-ID: Cc: dvyukov@google.com, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org Reply-To: dvyukov@google.com, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1442584463-69553-1-git-send-email-dvyukov@google.com> References: <1442584463-69553-1-git-send-email-dvyukov@google.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:timers/core] timers: Fix data race in timer_stats_account_timer() Git-Commit-ID: 3ed769bdb2a2484fd7f9f7f3047413053aacbe21 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 3ed769bdb2a2484fd7f9f7f3047413053aacbe21 Gitweb: http://git.kernel.org/tip/3ed769bdb2a2484fd7f9f7f3047413053aacbe21 Author: Dmitry Vyukov AuthorDate: Fri, 18 Sep 2015 15:54:23 +0200 Committer: Thomas Gleixner CommitDate: Tue, 22 Sep 2015 15:43:18 +0200 timers: Fix data race in timer_stats_account_timer() timer_stats_account_timer() reads timer->start_site, then checks it for NULL and then re-reads it again, while timer_stats_timer_clear_start_info() can concurrently reset timer->start_site to NULL. This should not lead to crashes, but can double number of entries in timer stats as start_site is used during comparison, the doubled entries will have unuseful NULL start_site. Read timer->start_site only once in timer_stats_account_timer(). The data race was found with KernelThreadSanitizer (KTSAN). Signed-off-by: Dmitry Vyukov Cc: andreyknvl@google.com Cc: glider@google.com Cc: kcc@google.com Cc: ktsan@googlegroups.com Cc: john.stultz@linaro.org Link: http://lkml.kernel.org/r/1442584463-69553-1-git-send-email-dvyukov@google.com Signed-off-by: Thomas Gleixner --- kernel/time/timer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 84190f0..d3f5e92 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -461,10 +461,17 @@ void __timer_stats_timer_set_start_info(struct timer_list *timer, void *addr) static void timer_stats_account_timer(struct timer_list *timer) { - if (likely(!timer->start_site)) + void *site; + + /* + * start_site can be concurrently reset by + * timer_stats_timer_clear_start_info() + */ + site = READ_ONCE(timer->start_site); + if (likely(!site)) return; - timer_stats_update_stats(timer, timer->start_pid, timer->start_site, + timer_stats_update_stats(timer, timer->start_pid, site, timer->function, timer->start_comm, timer->flags); }