From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9175C4332F for ; Tue, 14 Nov 2023 21:26:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1F3B6B02FF; Tue, 14 Nov 2023 16:26:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BCFBA6B0301; Tue, 14 Nov 2023 16:26:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A97296B0303; Tue, 14 Nov 2023 16:26:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 96FCA6B02FF for ; Tue, 14 Nov 2023 16:26:46 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4BBE640526 for ; Tue, 14 Nov 2023 21:26:46 +0000 (UTC) X-FDA: 81457844412.09.497320E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id AE8AAC001B for ; Tue, 14 Nov 2023 21:26:43 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sv3IZklU; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699997203; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Y22DQC8Lsmp2Azl/1OW9hvIgtyMMXTeICc25wGhveAU=; b=CBLz4BrWbs0nc2SLiSGsg8hSYJT7RRDO3tfTcDR6/dpNKbz+4vOSN8GMwEYOgjW8E+BLl+ SSnFXu0K7X/r6LIQtmU1wrrC/uUppyDU4Ped28xLWJ3AhS+qHxFn3tISK318mR4N1coLy0 KtCyG/I80iWLTeAUDB3HsoRlv8fCYIs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699997203; a=rsa-sha256; cv=none; b=1cjp6HLn+f+FVnIFOgFviXM4Zp2I1gO9JOxKLSQ1P+SMeVM9VtatLQaTlDl67hmH5M4pMJ Z8+0QyhQ70NAaEtYzGh284ELxz//fsmQulQL9uF/o69Ewd38RnAgXyuAoWAC0fFR4oOEwr BNM7TRPp91Owod0I6DNW6x7/0aCvcGo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sv3IZklU; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Y22DQC8Lsmp2Azl/1OW9hvIgtyMMXTeICc25wGhveAU=; b=sv3IZklUAfVpOdArpL3vBg5u4z nU4X8iSmDNVmMH+vX5s2MRxtujH5Rc6XAZJRYfJSPrR6UaJzZhl+rz+wiLgBYyVt9h+2DfLtJDrm+ S8CERw9AGfh+nnfoatywmSz7OJWEjRkzud4TJlU0fH0Nhs+mQBGR+zh9q/OTHuabvuEWy+G6nJ9EP oWNb6T5wYMEJnsWmOtK4flkmqzJX15sMuLKcZ2t1wsJuOFC2x0dxpfNPm1SGl0QxM+GvqxA8uyepQ yM4ZQicSOLXD8zhDcla4X9ZvYv/ZVZlCya8kKpHwoC+AtyUUlXS1Bvzn+YR0ToksugZKO3pRKNrpx r16DH0VQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1r30va-00AHdF-MR; Tue, 14 Nov 2023 21:26:34 +0000 Date: Tue, 14 Nov 2023 21:26:34 +0000 From: Matthew Wilcox To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chandan Babu R , "Darrick J . Wong" , linux-xfs@vger.kernel.org, Mateusz Guzik Subject: Re: [PATCH v3 1/4] locking: Add rwsem_assert_held() and rwsem_assert_held_write() Message-ID: References: <20231110204119.3692023-1-willy@infradead.org> <20231110204119.3692023-2-willy@infradead.org> <52f481a3-bf4f-85ae-9ae6-10a23b48c7c5@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52f481a3-bf4f-85ae-9ae6-10a23b48c7c5@redhat.com> X-Rspamd-Queue-Id: AE8AAC001B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: w8yt1wwcgo7ktjsycpbb8i5a9kqzddoj X-HE-Tag: 1699997203-512383 X-HE-Meta: U2FsdGVkX19zXIslse10yLyLGZZWE/pO0GSGSLV4e8BOL9QfllNXxZEg7Qdkf+IM96kAWdC4mt60UV/YxwxdjNCl3nyDQADM4zzFbudFs++2lxwP38XdKk0NbR9Ml4gUHzD+K9JvoywVvG9TUAOjFUe6Ts2rtU3lceQBorhEfM+vKkVodrCbfXvPohXyNw2FmPmj93Y9EhRXK7zb8UyBOzkSBQHFDqDW5q3Whvfdlv9k7VmlXURAO6rPoGlxGKthVea8d2gblmSdWHtwQVpidkEJL0mKOB2+GWk6gZtfXURyTPTZGVXncneN+ojlzHjVWPylxcs/4VdBlktQYZofemtb6vA+Njb9KWJUHuPrw0VKOHycC+pSDa8vx8Idq5iBfahAA8SzTxi/RyZp+TBlC0FfrqL1L8+RqF+C627kttxiRzbdQu3IJVR0xMrkBdcvviKR9X0Ym8A7vllRDdqxYL/q63gFksN4vSK8mraFp0FNQJBXmofYbqcXKmT624cF49YwN+aiv9nAp8DYZ3XiziSxTG1QRUMyeT1j6B+XKOqVANMy+UI9KcbPY9n8+BuRbI6VEfqiC5C4s9g2ODnnqpKifnLMFmLQvBUKxCz1rRHrJ0kdwGjJrO4TGLEsFZcU7NnLrBc3RL/W8UUaccqycliXqqxxlbRONcR0pCAksNSJYUPCZrdbIURk/7dPSJ+wdJ66OvW0IAxHaLqihCleAcsrkEW06s5oRarT6VtiarPxEaHVLEVhAu59rndWlc5yIfe9kUFrAME48JunFYb4LXmO3QUXJCjZFaDRS9D4Qn6ulZeJB8HmBImLrE6V+F0J/zzht+1POe3q7PZSLrxLFhuGlKdf+o24Hb/lPpmY0pOKxlsyOSiqjdeuVUB9q4GuWNPrlEoPe7rGgwDf9j/TyU1ElH87/BzJxEN5Ie/GSIN+z853wP+7qIYv35QUqr+tJ9sQM54qTG1M5PKJJ94 JFOChpbh FHxO+Qi/LTGPFXjXw3KTpsHqoN2KiYPchUZKFbAU86vsFHVCMzFkt9yo0I70kzHBL/prkEsiKQyHfRvRclyAdZnyrpHp+af3QFZGFrpoPlvCJY28PorERQmK1x6j03+IwBnUrRzZ5aSzGs1XBhLYQ+AlYXwinGWkOxkrsXxLAxV48MgO7jU01xxT3lQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, Nov 10, 2023 at 05:21:22PM -0500, Waiman Long wrote: > On 11/10/23 15:41, Matthew Wilcox (Oracle) wrote: > > static inline int rwsem_is_locked(struct rw_semaphore *sem) > > { > > - return atomic_long_read(&sem->count) != 0; > > + return atomic_long_read(&sem->count) != RWSEM_UNLOCKED_VALUE; > > } > > -#define RWSEM_UNLOCKED_VALUE 0L > > -#define __RWSEM_COUNT_INIT(name) .count = ATOMIC_LONG_INIT(RWSEM_UNLOCKED_VALUE) > > +static inline void rwsem_assert_held_nolockdep(const struct rw_semaphore *sem) > > +{ > > + WARN_ON(atomic_long_read(&sem->count) == RWSEM_UNLOCKED_VALUE); > > +} > That is not correct. You mean "!= RWSEM_UNLOCKED_VALUE". Right? Uhhh ... I always get confused between assert and BUG_ON being opposite polarity, but I think it's correct. We are asserting that the rwsem is locked (either for read or write). That is, it is a bug if the rwsem is unlocked. So WARN_ON(sem->count == UNLOCKED_VALUE) is correct. No? > There are some inconsistency in the use of WARN_ON() and BUG_ON() in the > assertions. For PREEMPT_RT, held_write is a BUG_ON. For non-PREEMPT_RT, held > is a BUG_ON. It is not clear why one is BUG_ON and other one is WARN_ON. Is > there a rationale for that? I'll fix that up. > BTW, we can actually check if the current process is the write-lock owner of > a rwsem, but not for a reader-owned rwsem. We actually don't want to do that. See patches 3/4 where I explain how XFS takes the XFS_ILOCK for write, then passes control to a workqueue which asserts that the XFS_ILOCK is held for write. The thread which took the rwsem for write waits for the workqueue and unlocks the rwsem.