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 7F4B7EC8759 for ; Thu, 7 Sep 2023 19:38:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA5DD6B0071; Thu, 7 Sep 2023 15:38:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C559B6B0072; Thu, 7 Sep 2023 15:38:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA8B08D0001; Thu, 7 Sep 2023 15:38:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 953C76B0071 for ; Thu, 7 Sep 2023 15:38:42 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6C8BF1CA57F for ; Thu, 7 Sep 2023 19:38:42 +0000 (UTC) X-FDA: 81210813684.16.008BC5C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id B033F100028 for ; Thu, 7 Sep 2023 19:38:40 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ZVZBOxkL; dmarc=none; spf=none (imf14.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694115520; a=rsa-sha256; cv=none; b=gZXYIUCb09Zjmff1Wg2oZqjN1tSs/c3tkC9+ZB5eqn3c/FoqGWCf+9WLc4nPvm6jx9C6b/ wae7kde9vZx/VU/mogzpTicEMXxZLAe1OaJjNwcgDr6P1m6aZRdCeOuFsB+EPSFHJar16H 2viKEtrTc/OazvBQ6/q0fzasxps4Z+A= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ZVZBOxkL; dmarc=none; spf=none (imf14.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694115520; 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=AwM1VwlwVIqM+B74AtASZ+ELYU+JQssLPAE0LrOcF/E=; b=21TWzNNVQCAzbRGPKgd2eiP4nSIQN7wICE5UXMfbqCvi3qF1ZCiEl6yNjUyO8WI7SjaiT2 9AI48K+0w68S0kItmy+Xvw0kCBelyeY7OD23ArQnViXfmAsyUwlFdglc9Te0aq4sJpq8B2 mVpLx0A1gXnPhptQ5d7zurk0+3s4jQo= 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=AwM1VwlwVIqM+B74AtASZ+ELYU+JQssLPAE0LrOcF/E=; b=ZVZBOxkLzTDNwduftx2feJdr/p ClCKXvMiMdqO9Xv57aM7SDVfJdMItDeRnmjJOuDhwWy9uIoaAWHsXN0Sl3DD9t9cyIflD517Hlxrv tTautZR2yS2w/xvPInpZA9+87k268fWTFbUAXN4YHNUF60eNef2UBsZvLfkNpnHLIK3lmi8ul/PqB WR3Y2sLgUGM9XqEMussOkvdUHSZCkC+5Xz092Ahu2oS/evQbKOoSR2RVU1Agj44veOdRnPkdmLsAV QcB72+bZf3iTkJoIaMWBRavKMdM8I4AgT7xpHdGmB4+o0PNNFMiRAztRIPPXiTXb3ZlYaxl0384O2 bqWcy83Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qeKpq-00D2qG-KL; Thu, 07 Sep 2023 19:38:38 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 32FC4300687; Thu, 7 Sep 2023 21:38:38 +0200 (CEST) Date: Thu, 7 Sep 2023 21:38:38 +0200 From: Peter Zijlstra To: Matthew Wilcox Cc: Ingo Molnar , Will Deacon , Waiman Long , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Chandan Babu R , "Darrick J . Wong" , linux-xfs@vger.kernel.org Subject: Re: [PATCH 1/5] locking: Add rwsem_is_write_locked() Message-ID: <20230907193838.GB14243@noisy.programming.kicks-ass.net> References: <20230907174705.2976191-1-willy@infradead.org> <20230907174705.2976191-2-willy@infradead.org> <20230907190810.GA14243@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B033F100028 X-Stat-Signature: ue6o6m5sfb3f7moo67m4shjaaxrk1biz X-HE-Tag: 1694115520-988029 X-HE-Meta: U2FsdGVkX1/xKT879Tdd9l2t/1WOZS/97tbLcUMPm+pK/6ekX0ad/R1oHgdl8T7bO1yy99a4KFA//ZJc+B+Og2LxkURkPI1fh8JVN2sbfo/cuTN81MFuIaoUy2P1hTYlaVCF/t4vdNI3oBn/PclkeTIvXenJf+9T5VM24O8+5Nfsvp7lJDuCnTP9Qs25JstVKD+G2Q5BnTnOINyJWzaTdcVf/X8mEeJY6LMfGN7J37N4TxdWYuxTou8inLQAjc1+rNIT8QCrSMffuUBUWlswvhxY5rgkd6JuOM+oK/cYv+HZ9wh/eWJeyemL4puBGIWBZjSh+gb8PsOLDL8rGaOjZAD01OLvZsw7cKZguHwj2XDfAIalAAeS446debtj0w97G4b4AcNtqNzf8wH0vQ7vD813bNpP3D/mbfXeiIgzvsczj3INCO15lKPoTLOlrghKUWh+47da+QHUWssSh5+iBD/XDIsapMAnE0taxYB1oFYiDjEZKfWqysSjw3v8NlFatNTu38ZvOo5qJ7Q06IW51HP6uYG2VD+v8ON12pfUVs/SCVYHTapdZwo4O50XUmPahEp0fhA7qEMzLYF1NHCT3OOaXEkmU2xY4jhkRIYkAW5FuIpa/dN33ylZa6LWlZk/eHYYhcOMuR5RSzfvEWBSURAriXRVlGOU4FGNPtk0iXdM+Vsy4UvyKeGrh2XDrgnlcSZnRXWmqqwKo4n3IFHI3/8uFb9cqrgWeVvau+qrmgyzFkmljbo82xjuOqZ+g0V8igjxf+JPFOdCu+46F8Ii6XPcTfp9kvwsa9nvCE/+6MyDiine3qS0LzddZNrQkO3QeS8nC/qLgBGpb6Ks7vorklD1SRnBbrCyWlK5zBFA8/F2Z6LkP+sTPCnuMAt+1/slX/405aevYlQf5JLI8/fteSGiezCvMq48th7h4IG5uYSRCyhbLNm7sMkmQ1k783SqEu/I72+zRIfqPubC2mu CmU9XC1H s3LBX9tlqY5D5CxF+zHBYQo5oyQ4m2ZVIpVLTCaTXMzlyClPy1UdOOWGSVj48n9fhOsjhGAQYeAvzte4vSQbMKqxRNNdfax9hQnUhxpBUFawJXMCZJOnU6GUILqg8FZWIDShUoGHDvM62PyxQZdbBHc1YdzqAHJXgKBkyXR55v1uSjQQmwwghZ+uTCg== 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: On Thu, Sep 07, 2023 at 08:20:30PM +0100, Matthew Wilcox wrote: > On Thu, Sep 07, 2023 at 09:08:10PM +0200, Peter Zijlstra wrote: > > On Thu, Sep 07, 2023 at 06:47:01PM +0100, Matthew Wilcox (Oracle) wrote: > > > Several places want to know whether the lock is held by a writer, instead > > > of just whether it's held. We can implement this for both normal and > > > rt rwsems. RWSEM_WRITER_LOCKED is declared in rwsem.c and exposing > > > it outside that file might tempt other people to use it, so just use > > > a comment to note that's what the 1 means, and help anybody find it if > > > they're looking to change the implementation. > > > > I'm presuming this is deep in a callchain where they know they hold the > > lock, but they lost in what capacity? > > No, it's just assertions. You can see that in patch 3 where it's > used in functions called things like "xfs_islocked". Right, but if you're not the lock owner, your answer to the question is a dice-roll, it might be locked, it might not be. > > In general I strongly dislike the whole _is_locked family, because it > > gives very poorly defined semantics if used by anybody but the owner. > > > > If these new functions are indeed to be used only by lock holders to > > determine what kind of lock they hold, could we please put: > > > > lockdep_assert_held() > > > > in them? > > Patch 2 shows it in use in the MM code. We already have a > lockdep_assert_held_write(), but most people don't enable lockdep, so Most devs should run with lockdep on when writing new code, and I know the sanitizer robots run with lockdep on. In general there seems to be a ton of lockdep on coverage. > we also have VM_BUG_ON_MM(!rwsem_is_write_locked(&mm->mmap_lock), mm) > to give us a good assertion when lockdep is disabled. Is that really worth it still? I mean, much of these assertions pre-date lockdep. > XFS has a problem with using lockdep in general, which is that a worker > thread can be spawned and use the fact that the spawner is holding the > lock. There's no mechanism for the worker thread to ask "Does struct > task_struct *p hold the lock?". Will be somewhat tricky to make happen -- but might be doable. It is however an interface that is *very* hard to use correctly. Basically I think you want to also assert that your target task 'p' is blocked, right? That is: assert @p is blocked and holds @lock.