Received: by 10.192.165.156 with SMTP id m28csp883783imm; Tue, 17 Apr 2018 23:23:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+FUDeLKwP2ZfWvBZRWgL7GBo7SEP/OeoN743OWgHNLupi4GgTb259VOKxh1xCor3BvvYXN X-Received: by 2002:a17:902:8692:: with SMTP id g18-v6mr887953plo.152.1524032608921; Tue, 17 Apr 2018 23:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524032608; cv=none; d=google.com; s=arc-20160816; b=qk8n9A/vtjbt1qkZg6+rAv7PmVdNfeOIQAbTVHitcmoUJpQGtJAuH2mu1YfBFukejh RLn9yDLZAMXNPkWpQjx/p+2CtpvKZ8h2pJdU8FLX3PDKQIiwLgxUguspGFdrqVhv5yqF bgJbwr/PW9LU3ED55rPY8NEBtIci3NhWHsHuvsUak/X4ufewlf6PFLwCopi1dS6nube4 K5sWzx69WLx9ZTX/kPxotryqRf7t5HHX6hDPszYU5bSlDpQbpSgKGGG34juYMKAIdDWU ypP1Bi/4KC+2DzVl/dPe9LOjeXhD5rcVoECllr5AsywIsvYyHqFZgo9CRMwmAB3blgj+ o3qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=qC4BfNijH7dwclc5yxHpmbJY8Llu4v5CtcwfXCMgB5Q=; b=aapsIhwOfJB1sCBBS9yyapf+a7ySQBSdSsVIrDs5K82M7hjVkk6ayj09qeRYEmqH+H D4HWE1436fn1etwwIB6pWAE9BG8HpwSQ7FJJf+nhr0+WWgB39mgL5JdB1sMKl8DrS4lr p4YS4wGLnACBa3pYCUYOEtKytQ8DEMxvb6OkxujkqDrby6dFupz5qCgQDg4OcOoESdmf 99l3RP/jUsYKGzTnqNQQY07T6cRLPYSwIhsuLzKAKL0wp8/zoiOyCbqx3wvIrDZ24o0C 1jYwjc22eizAkJRV3GwErWKP4rJQO8sSVzCh4Y9wMJKUSjvdanSv4chbca7XGaEK3WpS pYSg== ARC-Authentication-Results: i=1; mx.google.com; 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 r9si534753pgn.244.2018.04.17.23.23.14; Tue, 17 Apr 2018 23:23:28 -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; 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 S1752707AbeDRGWD (ORCPT + 99 others); Wed, 18 Apr 2018 02:22:03 -0400 Received: from gate.crashing.org ([63.228.1.57]:58862 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752568AbeDRGWB (ORCPT ); Wed, 18 Apr 2018 02:22:01 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w3I6KwZ1011172; Wed, 18 Apr 2018 01:21:00 -0500 Message-ID: <1524032458.11062.323.camel@kernel.crashing.org> Subject: Re: [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers From: Benjamin Herrenschmidt To: Waiman Long , Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, Dave Chinner , Eric Sandeen , "Paul E. McKenney" Date: Wed, 18 Apr 2018 16:20:58 +1000 In-Reply-To: <1523380938-19462-1-git-send-email-longman@redhat.com> References: <1523380938-19462-1-git-send-email-longman@redhat.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 (3.26.6-1.fc27) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-04-10 at 13:22 -0400, 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. > > 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. So smp_store_mb() > is now used to set waiter->task to NULL to provide a proper memory > barrier for synchronization. > > Signed-off-by: Waiman Long That looks right... nothing in either lock or unlock will prevent a store going past a load. > --- > 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 */