Received: by 10.192.165.148 with SMTP id m20csp4425734imm; Tue, 24 Apr 2018 02:30:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/q5BX+tSPl5qoDohtsp5e8wwBDU/z3OhgCGhYrIzMzvn3c9UbClxZLSQ0lNKUukRPVcmSM X-Received: by 10.99.50.134 with SMTP id y128mr20221355pgy.419.1524562214579; Tue, 24 Apr 2018 02:30:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524562214; cv=none; d=google.com; s=arc-20160816; b=kBmH+8orQ1VgTrI1Aa13XYQveECqV5ZKKJKmH9sIKlAGZmCczZOubtE8sNWXzwPVh9 l168+YFbY39d1ZWk0TJdHld9r4JHp/sIqK2Htx2a5QP++0IsCQEKXOALQA8qC53ru/AC mk4tAE1c71yZX41YNh2iJTr8JvI6MET3uYcEYX29Uu8Bm1HV3rhX+8V1PJ42BPxuA0JZ ikaQeYjKCg+LbHbBZTbTbSifvAocMdiMTEU4rdAoYLgfwxmo8JoMiOEMr/27Mlojyk4e NpmmLwWZEdaMjnwNhlcAsP29yjgGUSmi9mSopJvcQV6E0HIAN5KctcNMdRW0YhoaxW14 b6lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=V8l1eCKZWI+Ia5ia5XWGUhm1FHFm4RI4bjfMZBUQRJI=; b=tEsUSjL8bzLs6EGMDnrVjd9mG5fTgmam/COfuJG+rFJqR+JZMi5li/DWl2IrzF+Oc4 fAoZ219liMAVTfC4g2/lFcg7p9xWIArzQMm89fcXLOsduvUJ/B1FvurlPQzVGboX+YQn MhR6HhRCYtmjt6JoNjigvVhmnDPU3kMh3+OBX/xM+fQQ4TCUl5p/Y+wsd62ZP5BM/Mts qx7Rkqj1qDZLBqxoOE7jGXCJJD12yJPvpltKD/rRU4q84fOGOKLe9pIWzyWDipJFdcg2 5enWHtn76mJSsz3YoxtqYKgjrXb7rddQtnH6LwfUqDinEYpk2VdgR/mEUklhEWDrVg8v 3ylA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=c+XiCL1B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b19si9547159pfh.358.2018.04.24.02.30.00; Tue, 24 Apr 2018 02:30:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=c+XiCL1B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755396AbeDXJPX (ORCPT + 99 others); Tue, 24 Apr 2018 05:15:23 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48278 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755258AbeDXJPQ (ORCPT ); Tue, 24 Apr 2018 05:15:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=V8l1eCKZWI+Ia5ia5XWGUhm1FHFm4RI4bjfMZBUQRJI=; b=c+XiCL1BnZehYldX5995OP2HR 21MO7ZXbKC9Wgwf/Tshvwrzo+7cCXOCgZKXxkPSHj57I6brThXlJuJcs83nviuaEgB90RjENHQGX7 pieB+bEQG3xiAAhO+Uw4Z79veSKoCbZvhsdU62Qlctnbovt0MHvzrfwFp6adZpNP3UfweKOuuRqL9 bvWG5/HANsbGfntzA0l5kV/lALBL6+Z2xaEiMEJtib7fxIOQ0c9adOnoxIABrdcjA8lGexJ3vBIfK WJjNfQSI/8e/cRwGRJMlui1NYM5AXgYbwuVWO8s/xFjWus0pm9TYNhpcWq18p4W70NKmXEqmDXJJV UphQZCZ0Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fAu2b-000412-LV; Tue, 24 Apr 2018 09:15:13 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C59D6203BFAF0; Tue, 24 Apr 2018 11:15:10 +0200 (CEST) Date: Tue, 24 Apr 2018 11:15:10 +0200 From: Peter Zijlstra To: Andrea Parri Cc: Waiman Long , Ingo Molnar , linux-kernel@vger.kernel.org, Dave Chinner , Eric Sandeen , "Paul E. McKenney" Subject: Re: [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers Message-ID: <20180424091510.GB4064@hirez.programming.kicks-ass.net> References: <1523380938-19462-1-git-send-email-longman@redhat.com> <6c112ecb-d662-b1fc-152a-32060ec46dae@redhat.com> <20180423205514.GA5876@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180423205514.GA5876@andrea> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 23, 2018 at 10:55:14PM +0200, Andrea Parri wrote: > > > + /* > > > + * To avoid missed wakeup of reader, we need to make sure > > > + * that task state and waiter->task are properly synchronized. > > > + * > > > + * wakeup sleep > > > + * ------ ----- > > > + * __rwsem_mark_wake: rwsem_down_read_failed*: > > > + * [S] waiter->task [S] set_current_state(state) > > > + * MB MB > > > + * try_to_wake_up: > > > + * [L] state [L] waiter->task > > > + * > > > + * For the wakeup path, the original lock release-acquire pair > > > + * does not provide enough guarantee of proper synchronization. > > > + */ > > > + smp_mb(); > > > + > > > adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment; > > > if (list_empty(&sem->wait_list)) { > > > /* hit end of list above */ > > > try_to_wake_up() does: > > raw_spin_lock_irqsave(&p->pi_lock, flags); > smp_mb__after_spinlock(); > if (!(p->state & state)) > > My understanding is that this smp_mb__after_spinlock() provides us with > the guarantee you described above. The smp_mb__after_spinlock() should > represent a 'cheaper way' to provide such a guarantee. Right, I don't see what problem is being fixed here either. The scenario in the comment is already closed by the smp_mb__after_spinlock() you mention. And it is fine to rely on that, we do in other places. > If this understanding is correct, the remaining question would be about > whether you want to rely on (and document) the smp_mb__after_spinlock() > in the callsite in question (the comment in wake_up_q() > > /* > * wake_up_process() implies a wmb() to pair with the queueing > * in wake_q_add() so as not to miss wakeups. > */ > So that comment is about the ordering required for wake_q_add() vs wake_up_q(). But yes, wmb is a little confusing. I suppose I was thinking of the NULL store vs the wakeup (store), but that doesn't really make much sense. And wake_up_process() being a mb means it also implies a wmb; if such is all that is required for the scenario at hand.