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 BDF1CC4332F for ; Wed, 15 Nov 2023 01:17:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 28F1D6B031F; Tue, 14 Nov 2023 20:17:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23F576B0320; Tue, 14 Nov 2023 20:17:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12DF76B0321; Tue, 14 Nov 2023 20:17:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 03FE36B031F for ; Tue, 14 Nov 2023 20:17:46 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CC817140287 for ; Wed, 15 Nov 2023 01:17:45 +0000 (UTC) X-FDA: 81458426490.18.131EAD8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 090A9120007 for ; Wed, 15 Nov 2023 01:17:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fODL3SK+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700011064; a=rsa-sha256; cv=none; b=gCbgQqL//syNl5scS1BFQsP2FdvD0rNoLC7CbN+u97ZbzOZtNEmuEJrbl6GNznxfXy1ZLu wW7W/2hNxtVauVx8cBZs3UilH7+T5oHlUnJ/xOuFQ7fLN6c3omDtAnqMoC4KMggPWWIze2 tNJktdQA/kk9FeAgUyytv0KIH/cAlB8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fODL3SK+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700011064; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G8zRe28oF6jtVP3vKDfHeNYaGoB5DzE0yyoVf8SF7rs=; b=iejgk+b+5e1yM6XYAyRRDYFE8oFczSjERXU5MsOC9gIabZ5AlILst4zJd2zMR7PMIeOAbj EONhodVgomHyZWPE2SuOn+z3ZgleynV8xqHCZiGUzj7aQ42OUG2hAf1vkZBKuzJdythIKE hPzUry8Ui36rLSLvV3vN9sHzD8USb9o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700011061; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G8zRe28oF6jtVP3vKDfHeNYaGoB5DzE0yyoVf8SF7rs=; b=fODL3SK+FhSzmFIVBJIQW4GO4SE+td2q/2GgYAcDkW/+VD1Y5tZtxvtFH5pGbVjwXpMlgG 8q7VU0fXWIRuwmfrGDhPS08mfbIMyHB71FFMCC6Hy3IkXaefLo28LLbCI5yjlG1Sw41cqB yxob4Cr0MY6DH8EA7jqB7GzixRjmjHw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-344-5l5pOwjsPTGj_r350op2hw-1; Tue, 14 Nov 2023 20:17:34 -0500 X-MC-Unique: 5l5pOwjsPTGj_r350op2hw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 83DFF3C000A9; Wed, 15 Nov 2023 01:17:33 +0000 (UTC) Received: from [10.22.16.87] (unknown [10.22.16.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02F94C15983; Wed, 15 Nov 2023 01:17:32 +0000 (UTC) Message-ID: <72dced0f-6d49-4522-beeb-1a398d8f2557@redhat.com> Date: Tue, 14 Nov 2023 20:17:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/4] locking: Add rwsem_assert_held() and rwsem_assert_held_write() Content-Language: en-US To: Matthew Wilcox 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 References: <20231110204119.3692023-1-willy@infradead.org> <20231110204119.3692023-2-willy@infradead.org> <52f481a3-bf4f-85ae-9ae6-10a23b48c7c5@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 090A9120007 X-Stat-Signature: sbdfpqf4f4nkwnwije3i1xk5w3ayz9uh X-HE-Tag: 1700011061-775589 X-HE-Meta: U2FsdGVk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VGtKHXvS0nqDt5LcugH/3AT3nJ6tfst6YghaYDS1e5Qd3ktfPwyBrJLDCdIlPw2YwRwjK2aMxGdodhtHdfV1Vw1yz/c5/5yBp0+S97FtvT43fmwivCBOGPEDBRYSUiiYaiIUbg9LKCyrbrSy53g== 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 11/14/23 16:26, Matthew Wilcox wrote: > 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? You are right. I got confused too. > >> 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. The check for write lock ownership is accurate. OTOH, the locked check can have false positive and so is less reliable. > >> 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. > I see. Thanks for the explanation. Cheers, Longman