From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752170AbcAFQEw (ORCPT ); Wed, 6 Jan 2016 11:04:52 -0500 Received: from mx2.suse.de ([195.135.220.15]:60524 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751341AbcAFQEq (ORCPT ); Wed, 6 Jan 2016 11:04:46 -0500 Date: Wed, 6 Jan 2016 17:04:43 +0100 From: Jiri Bohac To: Prarit Bhargava 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() Message-ID: <20160106160443.GA16110@midget.suse.cz> References: <1452085234-10667-1-git-send-email-prarit@redhat.com> <1452085234-10667-2-git-send-email-prarit@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452085234-10667-2-git-send-email-prarit@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? I believe this is already unsafe, as explained in the commit log of 6d9bcb62 (timekeeping: use printk_deferred when holding timekeeping seqlock). So directly calling ktime_get() from printk would just turn a rare deadlock into a certain one - perhaps a good thing? -- Jiri Bohac SUSE Labs, SUSE CZ