Received: by 10.192.165.148 with SMTP id m20csp3865942imm; Mon, 23 Apr 2018 13:57:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/NtsLb/fcHblNIN/YTbuVyM74NiNcuoaLLILZdgzA4LLj8N8YMnONVXVOsMwbEMG3SGjRv X-Received: by 10.99.97.139 with SMTP id v133mr17688351pgb.285.1524517063128; Mon, 23 Apr 2018 13:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524517063; cv=none; d=google.com; s=arc-20160816; b=Z4OhOo314gmAo7cafTSailsi7GkZlskBdU0nQ33x3B0g9Ky4mORV3Jrb06pA3bI9ex bPOQNacjzmWq/OF9ItRGEb3gW/++DCRntAyp0s1yCtWUgeyngp0mntBZCka8FW1/qaJZ Ho3qYP820iwmcCzKiCioaOvwlCH7H2kujdn7sn05VF5+pN4WxHP6h3SuUOVI2xS85CUT lk6xclOCYmViWs9zuQ8T6Rupr5kSk2jarLE0KOVSb6QIjWsJKhvTN3jtXe/voTxoGFcU SArn4UGWUF8dB49aOHG0c0QBbzbXJTjIYdWc0a0g5Jte8bffp9r7feP+zBlT6g3hTpLv tHMw== 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=p5ufqgsPwqHH5me10w1lkOCwY3JWkVrSftwqhpGjHts=; b=RoNLQRstgqS43VElt9yszrdHcEycxdQgVdrMMkWHwyuZgFdsY75zjiqgOiHIHVvoWn ZQzOyixLU9tSR2oOmXke+2QIGZ6FY25T5XDjtXQ8JDkM5N5ovpfceY0kaKfwT/t3xyXy lmwq8Jrb2LhiCZ95jxsyp7TVsYerP2hiZLJGLB/eGK0FT6ZgRfLoL3zmSiLDrmJlZGGV eLxnkAUXq5W0q0W0/zBzQ0AELEqEPSlWrEj+Y9vvpN94BxKdaktW3ZzXGRzaSGqzOE0d 8kmtV4Uf4AmrjgtMBiBzP30Fs8sRdy7HvR0B28/HE5QPsb+qMNjs+BhoNHAPtZ7FXHOu HTQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ZEb/BGkC; 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 b14-v6si12219926pll.116.2018.04.23.13.57.14; Mon, 23 Apr 2018 13:57:43 -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=pass header.i=@amarulasolutions.com header.s=google header.b=ZEb/BGkC; 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 S932254AbeDWUzZ (ORCPT + 99 others); Mon, 23 Apr 2018 16:55:25 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43970 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbeDWUzW (ORCPT ); Mon, 23 Apr 2018 16:55:22 -0400 Received: by mail-wr0-f193.google.com with SMTP id v15-v6so26791122wrm.10 for ; Mon, 23 Apr 2018 13:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=p5ufqgsPwqHH5me10w1lkOCwY3JWkVrSftwqhpGjHts=; b=ZEb/BGkCDtOTCfrVz9G7aLmsrY0h0sbnLxcyY6Sp51lP9p9yxYonDhW3t4EYaBlRJM spyeahIcIDmZsEk2o4jpbWWhD9dzrlcBuyuuFQRo3M6vz/qpL3PWTTqBg5ikn93Np/BY RhkHBPCHpDgiFmfeiUwTSEOD0/VYmL6Nqd1tM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=p5ufqgsPwqHH5me10w1lkOCwY3JWkVrSftwqhpGjHts=; b=WDly0faRdp9gDLhpTI9P8mh0X8DMKDpxAgHBlWFEy5UGhr9OUXOu/+OT5uIxESlamw JWWwgq2ebmUwXfuxKGqMp1EaFjHHRfN6elSQWXAh1LY+Y+PXTEy+pXYE61L5wsnhR3qE GawbIr1J/W9czl5SnGI7sO9hr6Saj19SQWkC2eftY57eMAk+3SQcLScH2xyzx+oRyEjO KQfTTGkJkpRhLGB+pPvBIqDCBuGRp/NLE5sx1tyem0Oookb1JLGhsAmBeaSg53xJoNmv nUSUj6ObKWXbkSea+07ZVPjW9SK//Y/fw29tnhf1sxbKjaluoLNGPlAioarTZqfGKRot ZbPw== X-Gm-Message-State: ALQs6tBblVsegH+YHnU0mKft3ANPswTywj/T5QUXNt2yCbWHSNXJ3u67 zpBsITapnN5oaGmcDDIn10EKRw== X-Received: by 10.28.32.132 with SMTP id g126mr11460970wmg.52.1524516921023; Mon, 23 Apr 2018 13:55:21 -0700 (PDT) Received: from andrea ([94.230.152.15]) by smtp.gmail.com with ESMTPSA id k89sm9754736wmc.15.2018.04.23.13.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 13:55:20 -0700 (PDT) Date: Mon, 23 Apr 2018 22:55:14 +0200 From: Andrea Parri To: Waiman Long Cc: Peter Zijlstra , 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: <20180423205514.GA5876@andrea> References: <1523380938-19462-1-git-send-email-longman@redhat.com> <6c112ecb-d662-b1fc-152a-32060ec46dae@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6c112ecb-d662-b1fc-152a-32060ec46dae@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Waiman, On Mon, Apr 23, 2018 at 12:46:12PM -0400, Waiman Long wrote: > On 04/10/2018 01:22 PM, Waiman Long wrote: > > It was observed occasionally in PowerPC systems that there was reader > > who had not been woken up but that its waiter->task had been cleared. Can you provide more details about these observations? (links to LKML posts, traces, applications used/micro-benchmarks, ...) > > > > One probable cause of this missed wakeup may be the fact that the > > waiter->task and the task state have not been properly synchronized as > > the lock release-acquire pair of different locks in the wakeup code path > > does not provide a full memory barrier guarantee. I guess that by the "pair of different locks" you mean (sem->wait_lock, p->pi_lock), right? BTW, __rwsem_down_write_failed_common() is calling wake_up_q() _before_ releasing the wait_lock: did you intend to exclude this callsite? (why?) > So smp_store_mb() > > is now used to set waiter->task to NULL to provide a proper memory > > barrier for synchronization. Mmh; the patch is not introducing an smp_store_mb()... My guess is that you are thinking at the sequence: smp_store_release(&waiter->task, NULL); [...] smp_mb(); /* added with your patch */ or what am I missing? > > > > Signed-off-by: Waiman Long > > --- > > kernel/locking/rwsem-xadd.c | 17 +++++++++++++++++ > > 1 file changed, 17 insertions(+) > > > > diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c > > index e795908..b3c588c 100644 > > --- a/kernel/locking/rwsem-xadd.c > > +++ b/kernel/locking/rwsem-xadd.c > > @@ -209,6 +209,23 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, > > smp_store_release(&waiter->task, NULL); > > } > > > > + /* > > + * 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 */ > > Ping! > > Any thought on this patch? > > I am wondering if there is a cheaper way to apply the memory barrier > just on architectures that need it. 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. 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. */ does not appear to be suffient...). Andrea > > Cheers, > Longman >