From patchwork Wed Apr 23 03:36:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 28845 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 08CB6203AC for ; Wed, 23 Apr 2014 03:37:13 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id oy12sf1543638veb.3 for ; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=P39kED6vzVQxmhAweh/tPlnxsJVTpg2kkrzJj87yfTc=; b=Arvtia12WuW0W4gO6XCI+Ru5InrL5TgU047TErHZKDq2bApMpQ4MKAmnBXy0Qt1LX2 At7ZKvzRq2VJZsu4ZwmghPVnh8Aj2klopNs+8cpW37vQNRyWIpuYECYrcUXRYIbYevez /qIKYtHg5mC74HJ9YhNfBzse9fTaZy+ojyJGCaM5/GhoXuz70bQ+3JTxH4zlQESG+f5h a0RSLh9eTzkS7fOEbv7ga9NO6+wNDp/22b6YGw5nFVlA6vDHjWtdaHUVVzvKbchAsnhO cWoJbb7MUbgBzGDltKjVZyjag2o9yZA2gH3F/T5kwer8C6cd/O7yFO3PRTF8v7jScTlK ClnQ== X-Gm-Message-State: ALoCoQmOLGLMn8mtLbaq02BQIlJ5ZOv40KjF/QG/9vnRf3qlfNyeWYB60SJw28UiD+IEyhdVG6hd X-Received: by 10.236.4.201 with SMTP id 49mr22140651yhj.47.1398224233759; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.213 with SMTP id 79ls417749qgl.35.gmail; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr12486432veb.21.1398224233669; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id sc12si7215270veb.187.2014.04.22.20.37.13 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 20:37:13 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id ib6so432551vcb.41 for ; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) X-Received: by 10.221.4.66 with SMTP id ob2mr455021vcb.28.1398224233564; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp72973vcb; Tue, 22 Apr 2014 20:37:13 -0700 (PDT) X-Received: by 10.68.212.10 with SMTP id ng10mr50133929pbc.95.1398224232834; Tue, 22 Apr 2014 20:37:12 -0700 (PDT) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by mx.google.com with ESMTPS id ps18si23887328pab.255.2014.04.22.20.37.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 20:37:12 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.52 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.52; Received: by mail-pa0-f52.google.com with SMTP id kx10so313535pab.11 for ; Tue, 22 Apr 2014 20:37:12 -0700 (PDT) X-Received: by 10.68.218.3 with SMTP id pc3mr15275101pbc.71.1398224232424; Tue, 22 Apr 2014 20:37:12 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id yx3sm88266665pbb.6.2014.04.22.20.37.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 20:37:11 -0700 (PDT) From: John Stultz To: LKML Cc: John Stultz , Jan Kara , Peter Zijlstra , Jiri Bohac , Thomas Gleixner , Ingo Molnar , Andrew Morton Subject: [RFC][PATCH 3/3] timekeeping: Use printk_deferred when holding timekeeping seqlock Date: Tue, 22 Apr 2014 20:36:58 -0700 Message-Id: <1398224218-4429-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398224218-4429-1-git-send-email-john.stultz@linaro.org> References: <1398224218-4429-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Jiri Bohac pointed out that there are rare but potential deadlock possibilities when calling printk while holding the timekeeping seqlock. This is due to printk() triggering console sem wakeup, which can cause scheduling code to trigger hrtimers which may try to read the time. Specifically, as Jiri pointed out, that path is: printk vprintk_emit console_unlock up(&console_sem) __up wake_up_process try_to_wake_up ttwu_do_activate ttwu_activate activate_task enqueue_task enqueue_task_fair hrtick_update hrtick_start_fair hrtick_start_fair get_time ktime_get --> endless loop on read_seqcount_retry(&timekeeper_seq, ...) This patch tries to avoid this issue by using printk_deferred (previously named printk_sched) which should defer printing via a irq_work_queue. Cc: Jan Kara Cc: Peter Zijlstra Cc: Jiri Bohac Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Andrew Morton Reported-by: Jiri Bohac Signed-off-by: John Stultz --- kernel/time/ntp.c | 15 +++++++++------ kernel/time/timekeeping.c | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index 419a52c..5b0ac4d 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -786,8 +786,9 @@ static long hardpps_update_freq(struct pps_normtime freq_norm) time_status |= STA_PPSERROR; pps_errcnt++; pps_dec_freq_interval(); - pr_err("hardpps: PPSERROR: interval too long - %ld s\n", - freq_norm.sec); + printk_deferred(KERN_ERR + "hardpps: PPSERROR: interval too long - %ld s\n", + freq_norm.sec); return 0; } @@ -800,7 +801,8 @@ static long hardpps_update_freq(struct pps_normtime freq_norm) delta = shift_right(ftemp - pps_freq, NTP_SCALE_SHIFT); pps_freq = ftemp; if (delta > PPS_MAXWANDER || delta < -PPS_MAXWANDER) { - pr_warning("hardpps: PPSWANDER: change=%ld\n", delta); + printk_deferred(KERN_WARNING + "hardpps: PPSWANDER: change=%ld\n", delta); time_status |= STA_PPSWANDER; pps_stbcnt++; pps_dec_freq_interval(); @@ -844,8 +846,9 @@ static void hardpps_update_phase(long error) * the time offset is updated. */ if (jitter > (pps_jitter << PPS_POPCORN)) { - pr_warning("hardpps: PPSJITTER: jitter=%ld, limit=%ld\n", - jitter, (pps_jitter << PPS_POPCORN)); + printk_deferred(KERN_WARNING + "hardpps: PPSJITTER: jitter=%ld, limit=%ld\n", + jitter, (pps_jitter << PPS_POPCORN)); time_status |= STA_PPSJITTER; pps_jitcnt++; } else if (time_status & STA_PPSTIME) { @@ -902,7 +905,7 @@ void __hardpps(const struct timespec *phase_ts, const struct timespec *raw_ts) time_status |= STA_PPSJITTER; /* restart the frequency calibration interval */ pps_fbase = *raw_ts; - pr_err("hardpps: PPSJITTER: bad pulse\n"); + printk_deferred(KERN_ERR "hardpps: PPSJITTER: bad pulse\n"); return; } diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index f7df8ea..ffd3113 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -852,8 +852,9 @@ static void __timekeeping_inject_sleeptime(struct timekeeper *tk, struct timespec *delta) { if (!timespec_valid_strict(delta)) { - printk(KERN_WARNING "__timekeeping_inject_sleeptime: Invalid " - "sleep delta value!\n"); + printk_deferred(KERN_WARNING + "__timekeeping_inject_sleeptime: Invalid " + "sleep delta value!\n"); return; } tk_xtime_add(tk, delta); @@ -1157,7 +1158,7 @@ static void timekeeping_adjust(struct timekeeper *tk, s64 offset) if (unlikely(tk->clock->maxadj && (tk->mult + adj > tk->clock->mult + tk->clock->maxadj))) { - printk_once(KERN_WARNING + printk_once_deferred(KERN_WARNING "Adjusting %s more than 11%% (%ld vs %ld)\n", tk->clock->name, (long)tk->mult + adj, (long)tk->clock->mult + tk->clock->maxadj);