Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1293749ybi; Wed, 17 Jul 2019 12:42:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoTaq7Dmi7xwU+1ONNrHrH/g+YAvIb1M2lDoAeuQv0+k+H/QREtlml3Y5BvTvpTK4wCAwn X-Received: by 2002:a17:902:7686:: with SMTP id m6mr45226059pll.239.1563392548212; Wed, 17 Jul 2019 12:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563392548; cv=none; d=google.com; s=arc-20160816; b=OXY0dOcntFRoUm1MYagUuB5GLta47lALScwhH+8LISNNGlP8xW20Mj3is2dZPDQEFv JVTBsy3GRv28g/1haPkKa9vl4jgjWLuc6eoyssvySAL+yd2YTnU9o7+cLfhSgErbBiXH wpibyZjPSEXwXYf9LhtyJhp8Q0lgJnikvbTvtpyOLPLkztHaNeZQltabFwbmEz0V6TfI OKyOBaloL8a9swXmhHoKLeiRGinf8Cj9cTFCBJODAz0SBYgNAvgLhL/axASTAJWonRB5 PoIIDbsRsDVP1SFJLTjAxnJjNU+2deTQxqyKjgxKB0y6c7Hkpeqw+MsUPc2KaFIulpeJ 6srw== 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; bh=ecfQAUakUEjS1O8+9fK2L5yIbjqtp/GpBtwSKD/jW1g=; b=imp5JN/7xgghq9tgKsPIuZnG25mQzrCyDSK9JnAbYiIASVH99tHheMl1FXus2RRtct 1viZm8GymzFEmU8z3TKjA8iL29LX2yddSlcEKi2Au4zrIaMsGBDtH5eHYyhVQtLTPTc5 U6mogE6ZSNLIlLATGxCXQUWWOwy++y5xXBB/RAqzaj7L5kyc/WS3A5c4+xUiQjMmubq6 Cfv+ZuJr2DCsjuP8vC529m4WfDTda0A7d6+bmvNcgihKUVHu2oXybEluYuwHluCDsaGk b1K9JxfGma2PrrHQfISpCZXX/gUIh+UiqQk3UVcMX8CafZL5aM8YoSAU4wNqqZdoZNZn w6rA== 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 f25si9637425pfd.157.2019.07.17.12.42.03; Wed, 17 Jul 2019 12:42: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbfGQTji (ORCPT + 99 others); Wed, 17 Jul 2019 15:39:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45606 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbfGQTji (ORCPT ); Wed, 17 Jul 2019 15:39:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53D59300C728; Wed, 17 Jul 2019 19:39:38 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-160.bos.redhat.com [10.18.17.160]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD72760922; Wed, 17 Jul 2019 19:39:37 +0000 (UTC) Subject: Re: [PATCH v2] locking/rwsem: add acquire barrier to read_slowpath exit when queue is empty To: Jan Stancek Cc: Will Deacon , linux-kernel@vger.kernel.org, dbueso@suse.de, peterz@infradead.org, mingo@redhat.com References: <20190716185807.GJ3402@hirez.programming.kicks-ass.net> <20190717131335.b2ry43t2ov7ba4t4@willie-the-truck> <21ff5905-198b-6ea5-6c2a-9fb10cb48ea7@redhat.com> <20190717192200.GA17687@dustball.usersys.redhat.com> From: Waiman Long Organization: Red Hat Message-ID: <1950f8bd-e0f4-9b65-fee6-701ecf531d1c@redhat.com> Date: Wed, 17 Jul 2019 15:39:37 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190717192200.GA17687@dustball.usersys.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 17 Jul 2019 19:39:38 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/17/19 3:22 PM, Jan Stancek wrote: > On Wed, Jul 17, 2019 at 10:19:04AM -0400, Waiman Long wrote: >>> If you add a comment to the code outlining the issue (preferably as >>> a litmus >>> test involving sem->count and some shared data which happens to be >>> vmacache_seqnum in your test)), then: >>> >>> Reviewed-by: Will Deacon >>> >>> Thanks, >>> >>> Will >> >> Agreed. A comment just above smp_acquire__after_ctrl_dep() on why this >> is needed will be great. >> >> Other than that, >> >> Acked-by: Waiman Long >> > > litmus test looks a bit long, would following be acceptable? > > diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c > index 37524a47f002..d9c96651bfc7 100644 > --- a/kernel/locking/rwsem.c > +++ b/kernel/locking/rwsem.c > @@ -1032,6 +1032,13 @@ static inline bool > rwsem_reader_phase_trylock(struct rw_semaphore *sem, >           */ >          if (adjustment && !(atomic_long_read(&sem->count) & >               (RWSEM_WRITER_MASK | RWSEM_FLAG_HANDOFF))) { > +            /* > +             * down_read() issued ACQUIRE on enter, but we can race > +             * with writer who did RELEASE only after us. > +             * ACQUIRE here makes sure reader operations happen only > +             * after all writer ones. > +             */ How about that?                 /*                  * Add an acquire barrier here to make sure no stale data                  * acquired before the above test where the writer may still                  * be holding the lock will be reused in the reader critical                  * section.                  */ Thanks, Longman