From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752162AbcAFQ16 (ORCPT ); Wed, 6 Jan 2016 11:27:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54206 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751595AbcAFQ14 (ORCPT ); Wed, 6 Jan 2016 11:27:56 -0500 Message-ID: <568D408A.3080101@redhat.com> Date: Wed, 06 Jan 2016 11:27:54 -0500 From: Prarit Bhargava User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Jiri Bohac CC: linux-kernel@vger.kernel.org, John Stultz , Thomas Gleixner , Ingo Molnar , Xunlei Pang , Peter Zijlstra , Baolin Wang , Arnd Bergmann Subject: Re: [PATCH 1/2] kernel, timekeeping, add trylock option to ktime_get_with_offset() References: <1452085234-10667-1-git-send-email-prarit@redhat.com> <1452085234-10667-2-git-send-email-prarit@redhat.com> <20160106160443.GA16110@midget.suse.cz> In-Reply-To: <20160106160443.GA16110@midget.suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/06/2016 11:04 AM, Jiri Bohac wrote: > On Wed, Jan 06, 2016 at 08:00:33AM -0500, Prarit Bhargava wrote: >> -ktime_t ktime_get_with_offset(enum tk_offsets offs) >> +ktime_t ktime_get_with_offset(enum tk_offsets offs, int trylock) >> { >> struct timekeeper *tk = &tk_core.timekeeper; >> unsigned int seq; >> ktime_t base, *offset = offsets[offs]; >> s64 nsecs; >> + unsigned long flags = 0; >> + >> + if (unlikely(!timekeeping_initialized)) >> + return ktime_set(0, 0); >> >> WARN_ON(timekeeping_suspended); >> >> + if (trylock && !raw_spin_trylock_irqsave(&timekeeper_lock, flags)) >> + return ktime_set(KTIME_MAX, 0); >> + > > Are you trying to avoid a deadlock caused by calling printk() with > timekeeper_lock locked? Not exactly. When I initially sent this as a RFE to jstultz he pointed out that if CPU A had acquired the timekeeper_lock (and therefore incremented tk_core.seq for a write), and CPU B panicked, no output would occur because the reads of tk_core.seq would spin indefinitely. > > I believe this is already unsafe, as explained in the commit log > of 6d9bcb62 (timekeeping: use printk_deferred when holding > timekeeping seqlock). Hmm ... John Stultz, any suggestions here? P. > > So directly calling ktime_get() from printk would just turn a > rare deadlock into a certain one - perhaps a good thing? > >