From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbcEIHvA (ORCPT ); Mon, 9 May 2016 03:51:00 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:53320 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753320AbcEIHuz (ORCPT ); Mon, 9 May 2016 03:50:55 -0400 Date: Mon, 9 May 2016 09:50:51 +0200 From: Peter Zijlstra To: Davidlohr Bueso Cc: mingo@kernel.org, tglx@linutronix.de, Waiman.Long@hpe.com, jason.low2@hp.com, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH 4/4] locking/rwsem: Rework zeroing reader waiter->task Message-ID: <20160509075051.GE3430@twins.programming.kicks-ass.net> References: <1462769770-29363-1-git-send-email-dave@stgolabs.net> <1462769770-29363-5-git-send-email-dave@stgolabs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1462769770-29363-5-git-send-email-dave@stgolabs.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 08, 2016 at 09:56:10PM -0700, Davidlohr Bueso wrote: > Readers that are awoken will expect a nil ->task indicating > that a wakeup has occurred. There is a mismatch between the > smp_mb() and its documentation, in that the serialization is > done between reading the task and the nil store. Furthermore, > in addition to having the overlapping of loads and stores to > waiter->task guaranteed to be ordered within that CPU, both > wake_up_process() originally and now wake_q_add() already > imply barriers upon successful calls, which serves the comment. > > Just atomically do a xchg() and simplify the whole thing. We can > use relaxed semantics as before mentioned in addition to the > barrier provided by wake_q_add(), delaying there is no risk in > reordering with the actual wakeup. > @@ -190,24 +189,18 @@ __rwsem_mark_wake(struct rw_semaphore *sem, > next = sem->wait_list.next; > loop = woken; > do { > + struct task_struct *tsk; > + > 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; > + > + tsk = xchg_relaxed(&waiter->task, NULL); > wake_q_add(wake_q, tsk); Not a great fan of this patch; it again doesn't fix the race, and smp_store_release() is a cheaper option on x86.