Received: by 10.192.165.148 with SMTP id m20csp4748655imm; Tue, 24 Apr 2018 07:50:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx49VRAJZA8AaCjV+MpGmQ+jeXbUuruVGfB2QkTiSiOra6yVKZORNjKZ0pa/TKEA5LpSiS2R2 X-Received: by 10.98.95.198 with SMTP id t189mr23746226pfb.244.1524581440171; Tue, 24 Apr 2018 07:50:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524581440; cv=none; d=google.com; s=arc-20160816; b=dbvuF//xDrkNUQwyF8FR5Hxq4nHl9SwWMP2PfJYJpsPplJnysC3s3DdLhTC7AE/hVO wwbwiShuYBYiL5kqUfqezhNaq7NgGLxvRsv4mZZyLeR2tcM+2U5GBee9OIJRzbXnrSn4 3Rw/1PWXttfYwgAE4eA5DKAGglJNOqvtymLWpPDNQOKXxdRM3wGCFiTSZZnaSLY7Qe3P BILqjgvYVPji48/urMqbnDp6f4Ds935T4ITG+EiSW3kH1PZCOE/v6dzDi13yUUTY3l4N ZUG7+M35vwpeBVdQmQhErAhXDeLlOFUd8fJTyw9v9mYiWRqWctynA83Yz0b8Bo3Mx8lh G98g== 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=N/YyYdD0WZpkC2KPhv3RITjvSJgTC9cbY7nbJfYZqSU=; b=0G7m1hRPnxmsrq5tM4w5GxzlmMOIuGBR2XL6WHU7Pw2nvVFk3Q4qRS1AS1edUoGbHY x2UqQqUJ+DzFWL+QqDfL/gPvHMdAeNwaC8LOnRVmbvXw1BWIxisq6GoQtidsTU3hcvuE MD1BgD+qwuFem4nRTy7H9kA/PxVm2KM5Rq2xniAF+iAxRD8+36WRiqlUKcvY+EDr1bKO eqE3NA5LIPjhm9g7quEclSI2mzC6L7+fTivoUx/Ny6WQkUW3te+anKGd/hbZGkS8xQgG ulc10mtYa/+KNlgZohsoZSb0zDnSUYXttMQKY0bM4f84WqDtoP8Dpi6h55Dwrl2FYgn1 +eIw== 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 g123si11733849pgc.108.2018.04.24.07.50.25; Tue, 24 Apr 2018 07:50:40 -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 S1751245AbeDXOtP (ORCPT + 99 others); Tue, 24 Apr 2018 10:49:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49022 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751117AbeDXOtM (ORCPT ); Tue, 24 Apr 2018 10:49:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD34F407574E; Tue, 24 Apr 2018 14:49:11 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-130.bos.redhat.com [10.18.17.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA8961C707; Tue, 24 Apr 2018 14:49:08 +0000 (UTC) Subject: Re: [PATCH] locking/rwsem: Synchronize task state & waiter->task of readers To: Peter Zijlstra , Andrea Parri Cc: Ingo Molnar , linux-kernel@vger.kernel.org, Dave Chinner , Eric Sandeen , "Paul E. McKenney" References: <1523380938-19462-1-git-send-email-longman@redhat.com> <6c112ecb-d662-b1fc-152a-32060ec46dae@redhat.com> <20180423205514.GA5876@andrea> <20180424091510.GB4064@hirez.programming.kicks-ass.net> From: Waiman Long Organization: Red Hat Message-ID: <801fea56-90f3-4965-b24b-fa88ac8d16ce@redhat.com> Date: Tue, 24 Apr 2018 10:49:08 -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: <20180424091510.GB4064@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 24 Apr 2018 14:49:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 24 Apr 2018 14:49:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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/24/2018 05:15 AM, Peter Zijlstra wrote: > 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. Right, I missed the smp_mb__after_spinlock(). So the upstream code is fine after all. Sorry for the noise. Cheers, Longman