From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754831Ab3IKPMF (ORCPT ); Wed, 11 Sep 2013 11:12:05 -0400 Received: from mail.openrapids.net ([64.15.138.104]:43245 "EHLO blackscsi.openrapids.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754052Ab3IKPMC (ORCPT ); Wed, 11 Sep 2013 11:12:02 -0400 Date: Wed, 11 Sep 2013 11:12:00 -0400 From: Mathieu Desnoyers To: Thomas Gleixner , Richard Cochran , Prarit Bhargava , John Stultz Cc: lttng-dev@lists.lttng.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Peter Zijlstra , Steven Rostedt , Ingo Molnar Subject: [RFC PATCH lttng-modules] Fix: use timekeeping_is_busy() to fix ktime_get() hard lockup Message-ID: <20130911151200.GB19800@Krystal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Editor: vi X-Info: http://www.efficios.com User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix an issue affecting lttng-modules with Linux kernels starting with 3.10. This patch depends on Linux kernel patch: "timekeeping: introduce timekeeping_is_busy()" Starting from Linux kernel commit 06c017fdd4dc48451a29ac37fc1db4a3f86b7f40 "timekeeping: Hold timekeepering locks in do_adjtimex and hardpps" (3.10 kernels), the xtime write seqlock is held across calls to __do_adjtimex(), which includes a call to notify_cmos_timer(), and hence schedule_delayed_work(). This introduces a side-effect for a set of tracepoints, including mainly the workqueue tracepoints: a tracer hooking on those tracepoints and reading current time with ktime_get() will cause hard system LOCKUP such as: WARNING: CPU: 6 PID: 2258 at kernel/watchdog.c:245 watchdog_overflow_callback+0x93/0x9e() Watchdog detected hard LOCKUP on cpu 6 Modules linked in: lttng_probe_workqueue(O) lttng_probe_vmscan(O) lttng_probe_udp(O) lttng_probe_timer(O) lttng_probe_s] CPU: 6 PID: 2258 Comm: ntpd Tainted: G O 3.11.0 #158 Hardware name: Supermicro X7DAL/X7DAL, BIOS 6.00 12/03/2007 0000000000000000 ffffffff814f83eb ffffffff813b206a ffff88042fd87c78 ffffffff8106a07c 0000000000000000 ffffffff810c94c2 0000000000000000 ffff88041f31bc00 0000000000000000 ffff88042fd87d68 ffff88042fd87ef8 Call Trace: [] ? dump_stack+0x41/0x51 [] ? warn_slowpath_common+0x79/0x92 [] ? watchdog_overflow_callback+0x93/0x9e [] ? warn_slowpath_fmt+0x45/0x4a [] ? watchdog_overflow_callback+0x93/0x9e [] ? watchdog_enable_all_cpus.part.2+0x31/0x31 [] ? __perf_event_overflow+0x12c/0x1ae [] ? perf_event_update_userpage+0x13/0xc2 [] ? intel_pmu_handle_irq+0x26a/0x2fd [] ? perf_event_nmi_handler+0x24/0x3d [] ? nmi_handle.isra.3+0x58/0x12f [] ? perf_ibs_nmi_handler+0x35/0x35 [] ? do_nmi+0x9e/0x2bc [] ? end_repeat_nmi+0x1e/0x2e [] ? read_seqcount_begin.constprop.4+0x8/0xf [] ? read_seqcount_begin.constprop.4+0x8/0xf [] ? read_seqcount_begin.constprop.4+0x8/0xf <> [] ? ktime_get+0x23/0x5e [] ? lib_ring_buffer_clock_read.isra.28+0x1f/0x21 [lttng_ring_buffer_client_discard] [] ? lttng_event_reserve+0x112/0x3f3 [lttng_ring_buffer_client_discard] [] ? __event_probe__workqueue_queue_work+0x72/0xe0 [lttng_probe_workqueue] [] ? sock_aio_read.part.10+0x110/0x124 [] ? do_sync_readv_writev+0x50/0x76 [] ? __queue_work+0x1ab/0x265 [] ? queue_delayed_work_on+0x3f/0x4e [] ? __do_adjtimex+0x408/0x413 [] ? do_adjtimex+0x98/0xee [] ? SYSC_adjtimex+0x32/0x5d [] ? tracesys+0xdd/0xe2 LTTng uses ktime to have the same time-base across kernel and user-space, so traces gathered from LTTng-modules and LTTng-UST can be correlated. We plan on using ktime until a fast, scalable, and fine-grained time-source for tracing that can be used across kernel and user-space, and which does not rely on read seqlock for kernel-level synchronization, makes its way into the kernel. Cc: Thomas Gleixner Cc: Richard Cochran Cc: Prarit Bhargava Cc: John Stultz Cc: Greg Kroah-Hartman Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Ingo Molnar Signed-off-by: Mathieu Desnoyers --- diff --git a/wrapper/trace-clock.h b/wrapper/trace-clock.h index bced61c..2f9df7a 100644 --- a/wrapper/trace-clock.h +++ b/wrapper/trace-clock.h @@ -32,6 +32,7 @@ #include #include #include +#include #include "random.h" static inline u64 trace_clock_monotonic_wrapper(void) @@ -45,6 +46,10 @@ static inline u64 trace_clock_monotonic_wrapper(void) if (in_nmi()) return (u64) -EIO; +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)) + if (timekeeping_is_busy()) + return (u64) -EIO; +#endif ktime = ktime_get(); return ktime_to_ns(ktime); } -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com