From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753723AbbBRRM1 (ORCPT ); Wed, 18 Feb 2015 12:12:27 -0500 Received: from terminus.zytor.com ([198.137.202.10]:39247 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752761AbbBRRMZ (ORCPT ); Wed, 18 Feb 2015 12:12:25 -0500 Date: Wed, 18 Feb 2015 09:11:38 -0800 From: tip-bot for Davidlohr Bueso Message-ID: Cc: tim.c.chen@linux.intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, jason.low2@hp.com, hpa@zytor.com, walken@google.com, torvalds@linux-foundation.org, paulmck@linux.vnet.ibm.com, dbueso@suse.de, peterz@infradead.org, tglx@linutronix.de, dave@stgolabs.net Reply-To: tim.c.chen@linux.intel.com, jason.low2@hp.com, mingo@kernel.org, linux-kernel@vger.kernel.org, hpa@zytor.com, walken@google.com, peterz@infradead.org, dbueso@suse.de, paulmck@linux.vnet.ibm.com, torvalds@linux-foundation.org, tglx@linutronix.de, dave@stgolabs.net In-Reply-To: <1422609267-15102-3-git-send-email-dave@stgolabs.net> References: <1422609267-15102-3-git-send-email-dave@stgolabs.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/rwsem: Document barrier need when waking tasks Git-Commit-ID: 49e4b2bcf7b812e985e65b6c8a0255b1520a6e7e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 49e4b2bcf7b812e985e65b6c8a0255b1520a6e7e Gitweb: http://git.kernel.org/tip/49e4b2bcf7b812e985e65b6c8a0255b1520a6e7e Author: Davidlohr Bueso AuthorDate: Fri, 30 Jan 2015 01:14:24 -0800 Committer: Ingo Molnar CommitDate: Wed, 18 Feb 2015 16:57:10 +0100 locking/rwsem: Document barrier need when waking tasks The need for the smp_mb() in __rwsem_do_wake() should be properly documented. Applies to both xadd and spinlock variants. Signed-off-by: Davidlohr Bueso Signed-off-by: Peter Zijlstra (Intel) Cc: Jason Low Cc: Linus Torvalds Cc: Michel Lespinasse Cc: Paul E. McKenney Cc: Tim Chen Link: http://lkml.kernel.org/r/1422609267-15102-3-git-send-email-dave@stgolabs.net Signed-off-by: Ingo Molnar --- kernel/locking/rwsem-spinlock.c | 7 +++++++ kernel/locking/rwsem-xadd.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c index 2555ae1..3a50485 100644 --- a/kernel/locking/rwsem-spinlock.c +++ b/kernel/locking/rwsem-spinlock.c @@ -85,6 +85,13 @@ __rwsem_do_wake(struct rw_semaphore *sem, int wakewrite) list_del(&waiter->list); tsk = waiter->task; + /* + * Make sure we do not wakeup the next reader before + * setting the nil condition to grant the next reader; + * otherwise we could miss the wakeup on the other + * side and end up sleeping again. See the pairing + * in rwsem_down_read_failed(). + */ smp_mb(); waiter->task = NULL; wake_up_process(tsk); diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index 2f7cc40..82aba46 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -186,6 +186,13 @@ __rwsem_do_wake(struct rw_semaphore *sem, enum rwsem_wake_type wake_type) waiter = list_entry(next, struct rwsem_waiter, list); next = waiter->list.next; tsk = waiter->task; + /* + * Make sure we do not wakeup the next reader before + * setting the nil condition to grant the next reader; + * otherwise we could miss the wakeup on the other + * side and end up sleeping again. See the pairing + * in rwsem_down_read_failed(). + */ smp_mb(); waiter->task = NULL; wake_up_process(tsk);