Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751233AbcLEL1A (ORCPT ); Mon, 5 Dec 2016 06:27:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54674 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750951AbcLEL05 (ORCPT ); Mon, 5 Dec 2016 06:26:57 -0500 Date: Mon, 5 Dec 2016 12:26:36 +0100 From: Oleg Nesterov To: Peter Zijlstra Cc: Davidlohr Bueso , mingo@kernel.org, john.stultz@linaro.org, dimitrysh@google.com, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH v2 2/3] locking/percpu-rwsem: Rework writer block/wake to not use wait-queues Message-ID: <20161205112636.GA30280@redhat.com> References: <1479495277-9075-1-git-send-email-dave@stgolabs.net> <1479495277-9075-3-git-send-email-dave@stgolabs.net> <20161203021839.GB30078@linux-80c1.suse> <20161205083605.GQ3092@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161205083605.GQ3092@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Dec 2016 11:26:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1405 Lines: 53 Davidlohr, Peter, I'll try to read this patch later, just one note. On 12/05, Peter Zijlstra wrote: > > On Fri, Dec 02, 2016 at 06:18:39PM -0800, Davidlohr Bueso wrote: > > @@ -102,8 +103,13 @@ void __percpu_up_read(struct percpu_rw_semaphore *sem) > > */ > > __this_cpu_dec(*sem->read_count); > > > > + rcu_read_lock(); > > + writer = rcu_dereference(sem->writer); > > Don't think this is correct, I think Oleg suggested using > task_rcu_dereference(), which is a giant pile of magic. Yes, but on a second thought task_rcu_dereference() won't really help, but we can just use rcu_dereference(). > The problem is that task_struct isn't RCU protected as such. Yes. But percpu_down_write() should not be used after exit_notify(), so we can rely on rcu_read_lock(), release_task()->call_rcu(delayed_put_task_struct) can't be called until an exiting task passes exit_notify(). But then we probably need WARN_ON(current->exit_state) in percpu_down_write(). And personally I think this change should add the new helpers, they can have more users. Something like struct xxx { struct task_struct *task; }; xxx_wake_up(struct xxx *xxx) { rcu_read_lock(); task = rcu_dereference(xxx->task); if (task) wake_up_process(task); rcu_read_unlock(); } #define xxx_wait_event(xxx, event) { // comment to explain why WARN_ON(current->exit_state); xxx->task = current; ... } Oleg.