Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4284292pxy; Tue, 27 Apr 2021 00:58:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/CKKSdXNrBeYINLDajI7n2RWmZ8C0+Hsutl8MejOLAddFDsUV5hvhYogzzoZsGuSGZCSp X-Received: by 2002:a17:906:719a:: with SMTP id h26mr9729482ejk.135.1619510304433; Tue, 27 Apr 2021 00:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619510304; cv=none; d=google.com; s=arc-20160816; b=Y/MW9fEG8WC8GFEe1SfPeGFUb8uRLJNcR04qYvOAAepy1cnI0t5CSoI1NiWguSCp2H wg8Ui/0XN5PisLLQZrG8cr/9Xg5H3Nrr/BP4CRdTLiIQWDyDpM9e76XJl8AhFILCdv7H OpF4Iq4JFfLqaaQVnJesg4+uJ04adgt/BNSaKhV4jQBZx61qXNLf4JMGpGA7sQjEVywZ TCjyIHJyFsS5JnT8Uw1FzfVKxyENXWbLfHsskPpPdhxZ0hpU9lKLBCYbHEbc8mK+sbag 4/ozO91DmWOCTFjMhK7N4KPTtY9AKdwl0lKNE8Yx6mPsOwfRzW6oxmu8AfSVd4vNXI0U 1hSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CzSWjqe8TbYoNuzlk9gLFhbA9Gy2Em7Di5706CDoXf4=; b=IYKxuFVFjj5VLJGIULk/DsT6k5YRUpLJABVMLDwUrzH69m2bIuIX1ltujEh/IkcxAD AldKJtb6ooZt9nsdfiMNmrr9LbQkCejf8g0E3hfizwo/y3ylgGo/UVnyUv1gpcAwNzsg JE7Ph+sUBdV/eGAwajVrDC0905fBKxOSdlR4S7eH2gj1bx6UQai6DPLBpv5Al62EqSX9 e7kZCjLR/LaCvCPQ49R0vB/TUtTZrsgcRLpo9Rjet4zC0PrJIHNR0eTz3EX47Pe9QObf liLqa72CKVPNePuoOwQssmkiicyzLFRF3P6RFvpen/124ID0u229usDgw84M6vqn/taT d/Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DLyN9Lmb; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb8si2164396edb.49.2021.04.27.00.57.59; Tue, 27 Apr 2021 00:58:24 -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=@kernel.org header.s=k20201202 header.b=DLyN9Lmb; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234857AbhD0H5s (ORCPT + 99 others); Tue, 27 Apr 2021 03:57:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:41624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230255AbhD0H5r (ORCPT ); Tue, 27 Apr 2021 03:57:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 583ED613B2; Tue, 27 Apr 2021 07:57:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619510224; bh=bRHNZqpmvvRiQ6H9p8ANRgoi0Mwfrn+Q5Crphixp5Lo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DLyN9Lmb44e2uJ01/HCrO6LhwSGIBY2LirJw5a1OM/W1QsYIu3Gi7h3eklwSmJ3ak tyTxzoRDUnA7RDKSnVLkPr2SmqGlz9+uAbEHbx9vkW0DQQnbkJyY4TsWBruhHXhSYZ +xBh6SDnO7XRgOUUVYFi4RW5wdcEa4w0RZpkfrRBgmpIhfKBcwMtNUVT33eiBr2hYE r04lz3b80T1Z66MEBCR8aJ2GpFL4mn7delHQyMRyjI3E4ANLd6Df/w+KeGwEmmRL1/ 5MhnpbV+Um192T4n8eW7fMDKNOQnLAggfiWcSj06opKa5opDpxfdtgkySbJBjk7bk2 VjA4RazSoRgNA== Date: Tue, 27 Apr 2021 08:56:59 +0100 From: Will Deacon To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Boqun Feng , linux-kernel@vger.kernel.org, Borislav Petkov , Ali Saidi , Steve Capper Subject: Re: [PATCH] locking/qrwlock: queued_write_lock_slowpath() cleanup Message-ID: <20210427075659.GA6675@willie-the-truck> References: <20210426185017.19815-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210426185017.19815-1-longman@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 26, 2021 at 02:50:17PM -0400, Waiman Long wrote: > Make the code more readable by replacing the atomic_cmpxchg_acquire() > by an equivalent atomic_try_cmpxchg_acquire() and change atomic_add() > to atomic_or(). > > For architectures that use qrwlock, I do not find one that has an > atomic_add() defined but not an atomic_or(). I guess it should be fine > by changing atomic_add() to atomic_or(). > > Note that the previous use of atomic_add() isn't wrong as only one > writer that is the wait_lock owner can set the waiting flag and the > flag will be cleared later on when acquiring the write lock. Right, there's no functional change here. > Suggested-by: Linus Torvalds > Signed-off-by: Waiman Long > --- > kernel/locking/qrwlock.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/kernel/locking/qrwlock.c b/kernel/locking/qrwlock.c > index b94f3831e963..ec36b73f4733 100644 > --- a/kernel/locking/qrwlock.c > +++ b/kernel/locking/qrwlock.c > @@ -66,12 +66,12 @@ void queued_write_lock_slowpath(struct qrwlock *lock) > arch_spin_lock(&lock->wait_lock); > > /* Try to acquire the lock directly if no reader is present */ > - if (!atomic_read(&lock->cnts) && > - (atomic_cmpxchg_acquire(&lock->cnts, 0, _QW_LOCKED) == 0)) > + if (!(cnts = atomic_read(&lock->cnts)) && > + atomic_try_cmpxchg_acquire(&lock->cnts, &cnts, _QW_LOCKED)) > goto unlock; > > /* Set the waiting flag to notify readers that a writer is pending */ > - atomic_add(_QW_WAITING, &lock->cnts); > + atomic_or(_QW_WAITING, &lock->cnts); Acked-by: Will Deacon Will