From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425187AbcBRIBP (ORCPT ); Thu, 18 Feb 2016 03:01:15 -0500 Received: from LGEAMRELO13.lge.com ([156.147.23.53]:55499 "EHLO lgeamrelo13.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1425102AbcBRIBO (ORCPT ); Thu, 18 Feb 2016 03:01:14 -0500 X-Original-SENDERIP: 156.147.1.125 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com Date: Thu, 18 Feb 2016 17:00:31 +0900 From: Byungchul Park To: Ingo Molnar Cc: willy@linux.intel.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, akinobu.mita@gmail.com, jack@suse.cz, sergey.senozhatsky.work@gmail.com, peter@hurleysoftware.com Subject: Re: [PATCH v3] lock/semaphore: Avoid an unnecessary deadlock within up() Message-ID: <20160218080031.GE5972@X58A-UD3R> References: <1455700311-2308-1-git-send-email-byungchul.park@lge.com> <20160217092828.GA19001@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160217092828.GA19001@gmail.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, Feb 17, 2016 at 10:28:29AM +0100, Ingo Molnar wrote: > > * Byungchul Park wrote: > > > diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c > > index b8120ab..6634b68 100644 > > --- a/kernel/locking/semaphore.c > > +++ b/kernel/locking/semaphore.c > > @@ -130,13 +130,14 @@ EXPORT_SYMBOL(down_killable); > > int down_trylock(struct semaphore *sem) > > { > > unsigned long flags; > > - int count; > > + int count = -1; > > > > - raw_spin_lock_irqsave(&sem->lock, flags); > > - count = sem->count - 1; > > - if (likely(count >= 0)) > > - sem->count = count; > > - raw_spin_unlock_irqrestore(&sem->lock, flags); > > + if (raw_spin_trylock_irqsave(&sem->lock, flags)) { > > + count = sem->count - 1; > > + if (likely(count >= 0)) > > + sem->count = count; > > + raw_spin_unlock_irqrestore(&sem->lock, flags); > > + } > > I still don't really like it: two parallel trylocks will cause one of them to fail > - while with the previous code they would both succeed. > > None of these changes are necessary with all the printk robustification > changes/enhancements we talked about, right? Right. I expect that Jan's patch which Sergey informed can make printk robuster. Actually I'm waiting for the patch done. And I thought that it's also a problem that a trylock implementation can make a system deadlock. Don't you think it need to make a trylock only either acquire or fail in any case? IMHO, waiting something within trylock is wrong. I'm just curious. Thanks, Byungchul > > Thanks, > > Ingo