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 DE746EC8754 for ; Thu, 7 Sep 2023 19:20:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2615F6B0072; Thu, 7 Sep 2023 15:20:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20FE76B0074; Thu, 7 Sep 2023 15:20:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 089CE6B0075; Thu, 7 Sep 2023 15:20:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E98DB6B0072 for ; Thu, 7 Sep 2023 15:20:41 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A8E73B44E9 for ; Thu, 7 Sep 2023 19:20:41 +0000 (UTC) X-FDA: 81210768282.11.A510665 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id 758E614001B for ; Thu, 7 Sep 2023 19:20:39 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=A8ak4gnH; spf=none (imf26.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=1694114440; 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=jyPg3Zf+xWA86GrJDQxcoZElUyTYcGm8zB+eX1nJcNo=; b=I47Wd8o64y/4yYZsBPNWHlLVNf2UTEEK6tfkjocxyJr5PUN7VZTxhq9o51QRZyRNbgeYyJ kbf0+bwAFkAr2eZhOz3QYaBhOv8B1QzgmIP1FVubAwyBbHRzS7ZMZTUdOeKI1e4gI/iIrF XivcbSlXMvaaVIg8wl8lBubsHL1wKyU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694114440; a=rsa-sha256; cv=none; b=N6WVAwCYE+AyDuyAeyzSEOGR2Hy3IKEk2+rNWyv5dhf8NUzGn1Zr6PnibBheH8yAzFqCOP vDeuS8lr0caYOtJLBJPX0zmqvr2ZGGS9Gl4cPs6GoVprJGkwqCUuz5QAjrpj6MJnADuUHH OvNXanLUAN9JsNgziPifg/GtKWXs3sM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=A8ak4gnH; spf=none (imf26.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=jyPg3Zf+xWA86GrJDQxcoZElUyTYcGm8zB+eX1nJcNo=; b=A8ak4gnHSQ4167ncLrhIfEvOU+ a57iCkTDWTNV4MAZodsa022rI8szEnY5V2/B+QHeo/q6B5Yo/SNC5qiRr4zGdxRSAPPI8ZsSi4Snt EgjBHEqzhbury8HNqUefbkI32Ut7rc12e4A1vT92JjNPnz7MAonKdcOrF9IKpJdhJmUgXkIJsr0Y2 F8AvqhIzCdHFebKKwu+oNmstk64bi8NL0aatFwFXQJbQeAY2l6Hzwfc9UXj6Qvz/u9o8nD9ss2Rdk 6zevCTRZ8pC2FVh6XPZw1grQZm/5l9ATc6KJEA/kvu97F1xgKKKEbis2GsMIxcw01Vvh+6inJr3az QFdvpYtg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qeKYI-00Cwsk-7k; Thu, 07 Sep 2023 19:20:30 +0000 Date: Thu, 7 Sep 2023 20:20:30 +0100 From: Matthew Wilcox To: Peter Zijlstra 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: 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: <20230907190810.GA14243@noisy.programming.kicks-ass.net> X-Rspamd-Queue-Id: 758E614001B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dh8nheztp7tpftmxx3q9ewefrjaadze4 X-HE-Tag: 1694114439-614517 X-HE-Meta: U2FsdGVkX19520ntK/x4/IWI3j0KvxZe32Rfej4iVRQpgag9c3ZMK2WWceFUhSDZ0g6u82qrDVY/uxJrsd6p4lblHEUo+eoERfR60Ql6IbIyXDovgdoIDjcUK2St8uuI3rSqGxCxewyzdVaOHN9vuq2cIE19t1YybOgq26b05DD0Jo+n2kvi24bZw0bEA7+sKOztscezM6JLZYhUrzW6xXonwEnZByWQ0tJU4Cx31AEYlrZD9kNuhBjrk3FzZc1ouU98gjJlUqsoNFQTxNsAwTuP7Aq/M9S/u1FlICuJBXJgB7sNlciy4DroEyTmxr2qcSP/sc+sXHEK5Z2qbUTULXdeGdbpe7x4bebEIrlBFJjmB1rfFzmvWOMJo9TZmExZ5VdyOFwSG1YInAGHh/k56Zg3U/LJl8xoAw3kBu2f03OrooWOfMMiDtaE4MaE7V1zNeazoDdnDASKmtD/ilt/L+cYbZPfBpYxDBmKln+cknabSCSnPa8ZUq2SNXW7pfZudAeNaGK1LzzU7roulrR2qHxMCieOlYwtj4sHI/+V/onZjIHhaBHAm+wOrx7ZYHtWhke1/yWMo7MC40qmhJKs0nmnZZ93TZ8IqKl4hGwxx0QRvTQQ/2J6nxn2hC1XU+Y61LdMUdetsmxg3rqg3EkfEZcsmj9gK+0vF7G8n1jgJOTAXRUxk4xz27xWi/MoGMXQbeE5MHmc1g96Y3jyZsOFIS/6sTFdyeddQHl5qaK4ZQvahAjUv5+M+7Cla0OpDNuPPyCZjLizCa/muxBccrg1SpE2X5k5cxIDCOwitY97NFgDBzNX8dQmM22/RnKOUaVE50Bm6g3EJXd3br1VKC5Wak3yzfVAZQ/EpW1o+GOYJNDeKxyFJL8Tc8RKRoWBdEY9FRgRUBwB34g9l+D4e9u2seSVQOPbnhI/Zf9y+jb+vf1BFrLy+LetF7gLiv+DtF+EU63eFQMtnIbxCbyhbLS 9eGG7uow XozXvRcuwzCabp8b242tOQNgRlFt9Kne6vOPVCiJnTk/w3h7s5HTLQqLMg4rmQ2REypFj4ws9LDy5raTon0d+FmmpVM1j4/mqWyeYSL49pZjk/VYwyWQUOgo2skWPetwmDjqGL+jFaWnHEq73E5i4sCTsIjcUvX6EFDZ2ySG5y6IykCfmiujZ5a3bXw== 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 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". > 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 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. 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?".