From patchwork Fri May 2 22:09:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 29601 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f197.google.com (mail-pd0-f197.google.com [209.85.192.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 07F54202E7 for ; Fri, 2 May 2014 22:09:36 +0000 (UTC) Received: by mail-pd0-f197.google.com with SMTP id g10sf12557140pdj.0 for ; Fri, 02 May 2014 15:09:36 -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=qIiDWiJ2xqt4iADRYAC3warfjDVewbrHpr+XV8MoT9Y=; b=GzxqVTnPm0LGteZkOgtnw4AuhCqH0EwriMCfRGMMV96z3dvSdmKYEA/jXyyrMNVg9Y coQPOhHn9l4JtUdKAiYDfszUOXl7lGDt85B4g8KeOFRNfNxAYy2KJdQrG7G5tYSfPagN ci8GCJdw3WmNq2xFt6andSpxwA5qgzW22ZADVAgq5rNp0crlYcd+v1jXUpTX1LNU6wEI Fywy8GuKbQsJ7sCXtJslsiJ+108BRUpVDEpc8FJbVYUo958mI2/MJWUwXYbZTlQz1Hpz 0/QuufzLiu/jAOzuNlgWFTqdAG/zT05lZsmF1kgg7lmerpTf5fMgHbvgIDlASzXNbPD7 sNmA== X-Gm-Message-State: ALoCoQl57r7zxSlhJ8++g/nGSkJVJTHg8UJp2hE4W/y9/AikYFG8KEtdK/x2JEo6Czyq94cea1yE X-Received: by 10.66.139.9 with SMTP id qu9mr10140094pab.41.1399068575916; Fri, 02 May 2014 15:09:35 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.72 with SMTP id k66ls1604338qgd.96.gmail; Fri, 02 May 2014 15:09:35 -0700 (PDT) X-Received: by 10.52.2.229 with SMTP id 5mr12385748vdx.24.1399068575751; Fri, 02 May 2014 15:09:35 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id w15si54560vcz.181.2014.05.02.15.09.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 May 2014 15:09:35 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lc6so1209789vcb.16 for ; Fri, 02 May 2014 15:09:35 -0700 (PDT) X-Received: by 10.220.147.16 with SMTP id j16mr14897562vcv.14.1399068575674; Fri, 02 May 2014 15:09:35 -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 ib8csp134365vcb; Fri, 2 May 2014 15:09:35 -0700 (PDT) X-Received: by 10.66.141.109 with SMTP id rn13mr39896847pab.117.1399068574983; Fri, 02 May 2014 15:09:34 -0700 (PDT) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by mx.google.com with ESMTPS id hi3si227812pac.410.2014.05.02.15.09.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 May 2014 15:09:34 -0700 (PDT) Received-SPF: none (google.com: john.stultz@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.54; Received: by mail-pa0-f54.google.com with SMTP id lf10so6127108pab.27 for ; Fri, 02 May 2014 15:09:34 -0700 (PDT) X-Received: by 10.67.15.42 with SMTP id fl10mr40277710pad.30.1399068574380; Fri, 02 May 2014 15:09:34 -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 nw13sm1693724pab.37.2014.05.02.15.09.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 May 2014 15:09:33 -0700 (PDT) From: John Stultz To: LKML Cc: John Stultz , Jan Kara , Peter Zijlstra , Jiri Bohac , Thomas Gleixner , Ingo Molnar , Andrew Morton , Steven Rostedt Subject: [PATCH 4/4] timekeeping: Use printk_deferred when holding timekeeping seqlock Date: Fri, 2 May 2014 15:09:18 -0700 Message-Id: <1399068558-2373-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399068558-2373-1-git-send-email-john.stultz@linaro.org> References: <1399068558-2373-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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 Cc: Steven Rostedt 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);