Received: by 10.213.65.68 with SMTP id h4csp4178471imn; Tue, 10 Apr 2018 10:26:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx48e0sUVQA13Ir+UHTC+d0dTrP/DZYNHS2y2NQtzcOWT0khbEEapGjg/a1rFdIWjJxyWPsJP X-Received: by 10.98.89.89 with SMTP id n86mr1110779pfb.158.1523381169649; Tue, 10 Apr 2018 10:26:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523381169; cv=none; d=google.com; s=arc-20160816; b=dUels3qKKSJWMjhMzbVEz9LPuExH3Yd0nsqGZiD1cGUPUnBiqvXXdtAYaWA7bR84+y PagXZ7t6yQn6vQeUZFweqICxcXEmifEqtHHlq3KPbsh1fdTD+TIHyGT91PvdRnCO9O+S ROgBJWeAoarWALYXCREygk8zgI4lJhjSxm3r88eMIz1fFKWxV3aDV7EpXFleIq6NAz84 ZfDlP9Gl+HeS3wiM/5tzPPN6XLLZg+wLYxaGXBramvozqOKrGNhA6kgqZ+ax31eAkY8e BTxUrFoKJpGwmKTQDVI/6QCqXhE3gqjJx2C7JMoKo6HXYqbgllXPBExh2381haGfejxY Fnbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wLaOjVyqfA+fEM/Tj1oj3nW+AKbMc8+v+r6TLPuNnQQ=; b=TjPkTfsLXhGTDdsCUVwkMNEh7RxuVS2RDaKpGYuz5VQeRKOl0loVkASlM4R684pP2f AoKEn8gGqRlL6DFGfoFTXTnDBCrH4Na6Nyz3G33JQ6yEOanrCKxIKAL7eJnpqAv7fSjm kGUci6xo9bU58xQL0zfGuHyM5swcyeroMMTwIGyDAMpKIIPILXZn8TfW4MqISiikd1rr TbNDesqyDsKbRNkwqNFjh+7/FiPE99QxVFXAdAiH0m9z6ipgQld1VUlPvlBZqf/7RHAa d7g2iECi3pYGH0E2HgBX+JNX90sLqNmIoF6hBi139SJSBmRcpHDEr2Tv3QFHsl5roPje D03A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t25si2125510pge.714.2018.04.10.10.25.31; Tue, 10 Apr 2018 10:26:09 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751820AbeDJRWq (ORCPT + 99 others); Tue, 10 Apr 2018 13:22:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54490 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751367AbeDJRWp (ORCPT ); Tue, 10 Apr 2018 13:22:45 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1B9A5722E9; Tue, 10 Apr 2018 17:22:45 +0000 (UTC) Received: from llong.com (dhcp-17-164.bos.redhat.com [10.18.17.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAEB72026DFD; Tue, 10 Apr 2018 17:22:44 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, Dave Chinner , Eric Sandeen , "Paul E. McKenney" , Waiman Long Subject: [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers Date: Tue, 10 Apr 2018 13:22:18 -0400 Message-Id: <1523380938-19462-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Apr 2018 17:22:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 10 Apr 2018 17:22:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'longman@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 */ -- 1.8.3.1