From patchwork Tue Aug 23 23:08:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 74531 Delivered-To: patches@linaro.org Received: by 10.140.29.52 with SMTP id a49csp18552qga; Tue, 23 Aug 2016 16:08:29 -0700 (PDT) X-Received: by 10.98.144.144 with SMTP id q16mr58087948pfk.98.1471993709395; Tue, 23 Aug 2016 16:08:29 -0700 (PDT) Return-Path: Received: from mail-pf0-x22c.google.com (mail-pf0-x22c.google.com. [2607:f8b0:400e:c00::22c]) by mx.google.com with ESMTPS id x70si6072220pff.4.2016.08.23.16.08.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Aug 2016 16:08:29 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) client-ip=2607:f8b0:400e:c00::22c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x22c.google.com with SMTP id h186so47874196pfg.3 for ; Tue, 23 Aug 2016 16:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LsoqTrCyi+iqCo7jr/wfdbcRU5x05AIt5WDGTcOY4/E=; b=I3cpa35x2HRvb9NzqC3yY0zPg5k6enaEtWhF//GJyKCt1Kr/Fv8g68TcCsDRH64PYQ kuUgE9X6gXb697E6UR+KzQmME5ZTsT89zewhF1HY0g/xOjPPjvrHleH2XUAfTp27zsdq hZHx2GGZ8Ac2oHNO1fsIo7967O9vQTz7s0jwc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LsoqTrCyi+iqCo7jr/wfdbcRU5x05AIt5WDGTcOY4/E=; b=fRnk5wvWy6acmGnOUUmZARDzPc53PivoRrcdLlzMHn0hNRx931gstCwnFKtrgSog8M bIYdSN29GC9rX3Iz5V0sF8vZ8rtNJ2ZlUe5JEIER6UJuBGQglae7xywjyzsgDf1Fv7O9 8r+ezF5UQTEdDkvllXptePETQEhnut4SpYJfqCcsi88YkmgBbqb5ilWhIhgxXqd/09L2 I6v4nT7xPISdKNGba/yeMQNR4T1cadsOrw9p2URCFdXZndlMrcduZjgW7yNdLz+kRynN uflhCvLbNq6w4PBuTaTCXLl4RgTiEHVoRBwKWyM+uH1BQ3ywGrfrkpPfiEZp5cPqnI0H 73xA== X-Gm-Message-State: AEkooutja2vL7ffftIOCm36ImPF1CXpQBlVzl4v2nji6r9QXWTqeQvnOkD+oesmBCE5zWY/NGTM= X-Received: by 10.98.91.197 with SMTP id p188mr58254011pfb.101.1471993709134; Tue, 23 Aug 2016 16:08:29 -0700 (PDT) Return-Path: Received: from localhost.localdomain (c-73-67-244-238.hsd1.or.comcast.net. [73.67.244.238]) by smtp.gmail.com with ESMTPSA id i137sm8200194pfe.64.2016.08.23.16.08.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Aug 2016 16:08:28 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Steven Rostedt , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , stable Subject: [PATCH 1/2] timekeeping: Avoid taking lock in NMI path with CONFIG_DEBUG_TIMEKEEPING Date: Tue, 23 Aug 2016 16:08:21 -0700 Message-Id: <1471993702-29148-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471993702-29148-1-git-send-email-john.stultz@linaro.org> References: <1471993702-29148-1-git-send-email-john.stultz@linaro.org> When I added some extra sanity checking in timekeeping_get_ns() under CONFIG_DEBUG_TIMEKEEPING, I missed that the NMI safe __ktime_get_fast_ns() method was using timekeeping_get_ns(). Thus the locking added to the debug checks broke the NMI-safety of __ktime_get_fast_ns(). This patch open-codes the timekeeping_get_ns() logic for __ktime_get_fast_ns(), so can avoid any deadlocks in NMI. Cc: Steven Rostedt Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Thomas Gleixner Cc: stable # 4.1+ Reported-by: Steven Rostedt Reported-by: Peter Zijlstra Signed-off-by: John Stultz --- kernel/time/timekeeping.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 1.9.1 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 3b65746..e07fb09 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -401,7 +401,10 @@ static __always_inline u64 __ktime_get_fast_ns(struct tk_fast *tkf) do { seq = raw_read_seqcount_latch(&tkf->seq); tkr = tkf->base + (seq & 0x01); - now = ktime_to_ns(tkr->base) + timekeeping_get_ns(tkr); + now = ktime_to_ns(tkr->base); + + now += clocksource_delta(tkr->read(tkr->clock), + tkr->cycle_last, tkr->mask); } while (read_seqcount_retry(&tkf->seq, seq)); return now;