Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp500906pxb; Wed, 8 Sep 2021 06:11:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8jDnHNSx0wtJp9PAHgxH4KMJ8ZBDI5nFEiQdmBBcJIhNEF7AcO2GYRCRdArrCzRmNPE3m X-Received: by 2002:a05:6602:3c5:: with SMTP id g5mr3315278iov.42.1631106698948; Wed, 08 Sep 2021 06:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631106698; cv=none; d=google.com; s=arc-20160816; b=skHpeoC/7c47k9BaIKRDACeUTU4iYVrKayvZNXgW9HA7Q6xNyjq06h+OkYjus5QgAq sbSeWtjgadT+20v4X31u2MPxeYbI9BgQ0f3QehHvHfTsbW1yPgtYAwj36jHRIIBaznJk Z2fUU/zKFkbR6x30feHxV82uQub/68aEFN5fQzMwnkjUj/EVsf9BZYs4/4E19yYJhBgS F8a27adOsQGaqHp/FRgYwCLX3Ro4LEBMxi3nhzgL/Qdn5QOAgM2OC0U2yDoopfaT1RS8 NFf/QwSZjMCZxZxt5DKySLRCyiVmhHqYffXczJe9brwh24QznxROq2JkEzEkhhh3F5ha zG9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QzJ9eKQ/myUbNaLBbfRbOXpOoTfzAwm+YkiwW5sHVTc=; b=I86zxztBsQpBnfL3fwKatokB7tmijjjCWTf/MwDlQtoVNeBVzodz7BG4C05Y1MT/x/ RFNBqmFwI+FATLUPNIyN/81H7uQSSTFJiYohiOfRa0ubIwf6vyqW1CtZDQOxhXWlVQxQ nLpzFZKCpn0QPlL5wwGsxyAYPXfvZA0+tuLggIriooO2LKdmNSfgNmlzTruQP46QvhYm +U64Upqe5Pu1M3Dv9u1A9Y/PLi5bZM7eCSOZcRspcZ8/x0i+xNwuoFW0Q8QZKvgbxUoN jztxw2rdt/EAa3A+pz3ulCeu6aKuJoX+5QAzQtmjARqkaLTRsYJteGt4sKWilMd5qjdB hT4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lxAwaoqn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i6si2244487ilq.174.2021.09.08.06.11.26; Wed, 08 Sep 2021 06:11:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lxAwaoqn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343914AbhIHNLc (ORCPT + 99 others); Wed, 8 Sep 2021 09:11:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbhIHNLc (ORCPT ); Wed, 8 Sep 2021 09:11:32 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0172C061575 for ; Wed, 8 Sep 2021 06:10:23 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id z2so2391805iln.0 for ; Wed, 08 Sep 2021 06:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QzJ9eKQ/myUbNaLBbfRbOXpOoTfzAwm+YkiwW5sHVTc=; b=lxAwaoqnnquOUKXRVvuA00G0Hnwt0byFDzuJtwPtJtPv10DvTDFKx6V33V3fi52JU5 YHlldH0o2pZ036zai/nXhC+Vp2lYJWGOjqIydEpHoF7Ij1LVeOfYPSg6+S3Yh2e7p5zk SDBxnlyq/OfXJ2MsVgkSNIA8vg1HMGpa0qOSi1HEgpYjXyvmluR9qi6vp6nmSeEI4z2O T/xQ9SknUmKXmG3q+ksAij6f298J3kA1xtaT8rnJBg50JGxYptwVV7RaNx90E9WiW6zz xNoGIUzBSVr8xiGXo/wh/A7+9mucBRjcW2FGft9sSmgh24g1dY3n0QE7kr3ZP2MrYdIa z2JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QzJ9eKQ/myUbNaLBbfRbOXpOoTfzAwm+YkiwW5sHVTc=; b=2vO02sxoL/bqGtkgIaLT2maoFvnh/NGXKkx2rk3zGIMs3/xlJehuZ42aLI6D4iuH3O 1sEdQtFctj1aF2RmGIckO/XY07tf2ngqxju/Ooe1XrIMaEwq8YuOooE/EAWIKjaF/mDm TqDZx/wJDKBDXCrioPZyHHRpFLyUpLv1xzVTeXHCnEDBhlNTHBNiSqVc1GnbxqMpmbK6 sfEaumYCk2sJzDedaIw08NfBrhPWAvKKGwhk3jB2I4FwZz6tqtl7p0RzcpTbvbhlgopU GcqWyLb4Qy076wowA1PMkoPUZ++R703OS7dkkQ8UDwiZq02n246NZxRrYiS+HxN6sML3 IQMg== X-Gm-Message-State: AOAM533Bs1ifihugyza6LGLnOEIsNggrgTgKfpWEOxDZieXW9q8LjBdl DxLjEa2NLvlN+54xWbuGQVnc+tFvZhLLrw== X-Received: by 2002:a92:6802:: with SMTP id d2mr2763479ilc.40.1631106623354; Wed, 08 Sep 2021 06:10:23 -0700 (PDT) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id a17sm1096964ilp.75.2021.09.08.06.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 06:10:22 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id EA36C27C0054; Wed, 8 Sep 2021 09:10:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 08 Sep 2021 09:10:21 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudefjedgiedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepvdelieegudfggeevjefhjeevueevieetjeeikedvgfejfeduheefhffggedv geejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsg hoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieeg qddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigi hmvgdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 Sep 2021 09:10:20 -0400 (EDT) Date: Wed, 8 Sep 2021 21:08:52 +0800 From: Boqun Feng To: Peter Zijlstra Cc: Thomas Gleixner , Ingo Molnar , Juri Lelli , Steven Rostedt , Davidlohr Bueso , Will Deacon , Waiman Long , Sebastian Andrzej Siewior , Mike Galbraith , Daniel Bristot de Oliveira , LKML Subject: Re: [RFC] locking: rwbase: Take care of ordering guarantee for fastpath reader Message-ID: References: <20210901150627.620830-1-boqun.feng@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 08, 2021 at 01:51:24PM +0200, Peter Zijlstra wrote: [...] > @@ -201,23 +207,30 @@ static int __sched rwbase_write_lock(struct rwbase_rt *rwb, > { > struct rt_mutex_base *rtm = &rwb->rtmutex; > unsigned long flags; > + int readers; > > /* Take the rtmutex as a first step */ > if (rwbase_rtmutex_lock_state(rtm, state)) > return -EINTR; > > /* Force readers into slow path */ > - atomic_sub(READER_BIAS, &rwb->readers); > + readers = atomic_sub_return_relaxed(READER_BIAS, &rwb->readers); > > - raw_spin_lock_irqsave(&rtm->wait_lock, flags); > /* > * set_current_state() for rw_semaphore > * current_save_and_set_rtlock_wait_state() for rwlock > */ > rwbase_set_and_save_current_state(state); rwbase_set_and_save_current_state() may eventually call current_save_and_set_rtlock_wait_state(), which requires being called with irq-off, while rwbase_write_lock() may be called with irq-on. I guess we can change the raw_spin_lock() to raw_spin_lock_irqsave() in current_save_and_set_rtlock_wait_state() to solve this. Regards, Boqun > + raw_spin_lock_irqsave(&rtm->wait_lock, flags); > > - /* Block until all readers have left the critical section. */ > - for (; atomic_read(&rwb->readers);) { > + /* > + * Block until all readers have left the critical section. > + * > + * In the case of !readers, the above implies TSO ordering > + * at the very least and hence provides ACQUIRE vs the earlier > + * atomic_sub_return_relaxed(). > + */ > + while (readers) { > /* Optimized out for rwlocks */ > if (rwbase_signal_pending_state(state, current)) { > __set_current_state(TASK_RUNNING); [...]