Received: by 10.192.165.148 with SMTP id m20csp3639315imm; Mon, 23 Apr 2018 09:47:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+PZrugY+xhMkAFiWIsgdmyWbxvAzm+OCyjrqfF2wCpuimDCrWaVB+fCl6ILZaK0eF63IC X-Received: by 2002:a17:902:8342:: with SMTP id z2-v6mr21175545pln.311.1524502072121; Mon, 23 Apr 2018 09:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524502072; cv=none; d=google.com; s=arc-20160816; b=u0kOKhuTDdz/NoosYXTowOyVqsV6hckhiyR3DsmK4Fqry2XWXoDh08XwVFtOw30EXv dkNluf1vF4W7bKlMQim5wvfCxOccmgUM7yon4pdWwD2E+6UO1w4/z7auCsApneKLd5iJ CRKTmBsfxCkUvSCbGCBZwdHABfEsvfI1oNVFmqH7RVqaCAj0w3q/jbEZJ+kboxQNNf83 +mvpXTKDGJGXZqrPRX1aoWRUVruosKDgByowDCTpqs3mRNqVxp+6OgsV20T8zkDqjvon IZVvDuNuFzbvCQcXD19nObd7y9Av2/x7ehnZ+JKbZudekY01fCgLQb+XWyCR58T+5/lO GMdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=5tLxBUN0P3vBqq9bTjnFegTvgbAi5EqZY+8p8PO4S9M=; b=UMGMUZIZm4/jf1Po4tURT9C/F4Ty/wpveuGP/80JugHhLcdz1s8p8pDfOFzUAKUTKo ZNw+RTyGpfzhCe/U29n8Y40mxI63RF0IQu3IfBytktYwOFOoLlFvmB4fPN13E5R4fj/Q MrRtqbCSIw8AJDENgFQNkJu19wTqR1840h9nyMnNr4c0k8mrWstOwI2SYsyJPVtmfntw 7v3Z89p7BSkAih/z60oNnccft/akOHXd/Zecn+tChUPyM8/0ALhQxkGDqx3dTeyONV29 1EKjW/OBXxAX4ARJAip9PgKAVm2lZBF3IPvvnPpjs+uC3rizk5Kkr+xw4uRgZIm0ZL7q 4V5A== 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 n136si4931662pfd.312.2018.04.23.09.47.37; Mon, 23 Apr 2018 09:47:52 -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 S932254AbeDWQqO (ORCPT + 99 others); Mon, 23 Apr 2018 12:46:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37548 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755253AbeDWQqN (ORCPT ); Mon, 23 Apr 2018 12:46:13 -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 AC7C0E44B5; Mon, 23 Apr 2018 16:46:12 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-164.bos.redhat.com [10.18.17.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 584132026DFD; Mon, 23 Apr 2018 16:46:12 +0000 (UTC) Subject: Re: [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers To: Peter Zijlstra , Ingo Molnar Cc: linux-kernel@vger.kernel.org, Dave Chinner , Eric Sandeen , "Paul E. McKenney" References: <1523380938-19462-1-git-send-email-longman@redhat.com> From: Waiman Long Organization: Red Hat Message-ID: <6c112ecb-d662-b1fc-152a-32060ec46dae@redhat.com> Date: Mon, 23 Apr 2018 12:46:12 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <1523380938-19462-1-git-send-email-longman@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US 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.1]); Mon, 23 Apr 2018 16:46:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 23 Apr 2018 16:46:12 +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 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. > > 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 */ 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. Cheers, Longman