From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756902AbcBQJ2g (ORCPT ); Wed, 17 Feb 2016 04:28:36 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:33400 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754242AbcBQJ2d (ORCPT ); Wed, 17 Feb 2016 04:28:33 -0500 Date: Wed, 17 Feb 2016 10:28:29 +0100 From: Ingo Molnar To: Byungchul Park 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: <20160217092828.GA19001@gmail.com> References: <1455700311-2308-1-git-send-email-byungchul.park@lge.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1455700311-2308-1-git-send-email-byungchul.park@lge.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * 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? Thanks, Ingo