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 C0DE0CA0EED for ; Tue, 12 Sep 2023 14:02:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34D366B00FC; Tue, 12 Sep 2023 10:02:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FD4E6B00FD; Tue, 12 Sep 2023 10:02:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1ED376B00FE; Tue, 12 Sep 2023 10:02:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0E1D46B00FC for ; Tue, 12 Sep 2023 10:02:37 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 580B2B3ED0 for ; Tue, 12 Sep 2023 14:02:36 +0000 (UTC) X-FDA: 81228110712.05.0C81D97 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf24.hostedemail.com (Postfix) with ESMTP id 3470E18003B for ; Tue, 12 Sep 2023 14:02:33 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pGzPWYu3; dmarc=none; spf=none (imf24.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694527354; 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=zUdtnDARSEGsaZV8teORBRcSM/T2JFV9fIyHbs3iVko=; b=YfsVrlr5l1os9V4bMBosp12oLiEzQlIXxKDMl6VHOLRvgXfZpTXMFhFbQqQadcdtCerEDe /XJnIbc1Atu9nIfELIGqjk2hdelrb48JVSKzEalCPo5qlvPjHdUTGm+ca6GMu81Qo8Xzky 9pcfAD2n/a0ePpfaYgZDwXmLA3jjGoc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=pGzPWYu3; dmarc=none; spf=none (imf24.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694527354; a=rsa-sha256; cv=none; b=dc6teeLox6HBpYHJhIdaMmB4PhlsMtOSQtiZ49YvHufLgrMGQHiur2K2IiLOVlTy0nn/OS iXrl7b9yY1qzwnlBkKLlG5p77NcTYlttjWqwK0U3FM4suTh6vRjjLUxEoKqbIAkvlg5V9z +zKvEeMlwn5tvaNUxnhaIACYgdxZbJE= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=zUdtnDARSEGsaZV8teORBRcSM/T2JFV9fIyHbs3iVko=; b=pGzPWYu3IcDq5RuGqivEEtVMUx bobaHOCtt0fDZZxDVgZo16iDnL1cYW548UAtPN9P2mBKKraGDG49XFG2Lehid8HS1mkIWvV+didNG gWn4lwWgbLG4PeeGlo6wIPpaXjzp3uD26m0TjSLQmEbKCMYgKORtH+MHZZP952KmEOzm65gqo3tx+ BaeUh+CB+8brMKPaP2LaRI63YQjol/Ef3SLtVlEO3zmkyyQBzWxY8UXYY8znTyMY6YL4YB61DFMVR e1uCqbNs1D1Jjf3Y9DrRvFXs4bUERKaVdyH8U209rU9OI39yLeQR7tadKTc2AGVTeHc1Gz7kY88yj iJEYg9wg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qg3yE-0069kM-36; Tue, 12 Sep 2023 14:02:28 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 1389B300348; Tue, 12 Sep 2023 16:02:28 +0200 (CEST) Date: Tue, 12 Sep 2023 16:02:28 +0200 From: Peter Zijlstra To: Matthew Wilcox Cc: Dave Chinner , Waiman Long , Ingo Molnar , Will Deacon , 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: <20230912140228.GA22248@noisy.programming.kicks-ass.net> References: <20230908104434.GB24372@noisy.programming.kicks-ass.net> <70d89bf4-708b-f131-f90e-5250b6804d48@redhat.com> <20230912090342.GC35261@noisy.programming.kicks-ass.net> <20230912135213.GA22127@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230912135213.GA22127@noisy.programming.kicks-ass.net> X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3470E18003B X-Stat-Signature: yz7bg9kjubf344fahd5quj4powhe4ctk X-Rspam-User: X-HE-Tag: 1694527353-598123 X-HE-Meta: U2FsdGVkX1/PBFTEQKDKKJQhSydl1ediOW4Iynvlhnxtx6upDy/RkZKtnm7sHdL5GssPT5wdqXOEKGHSUOI01qZdJl91t8yfYFeGaxvnNX0TcSpfaE56bujVO28yygSHt6bh3dsjx5fYtDEd9wW2LEvE0/ejHTE4og+8siH0EmSS04BgfnYAgS6TP0A4YXKaB71QM0w9Kj8qCyFQvM8T/mY9M9BCpfzx+7ha6kt5CvDL9KVekRtfZ1Marhcrv2YuU+xh8SXYqmzLBHbG7yGWB2uLxoV9Nw5iJVVV1LeOzfWJr6z0z7ZCoTxic2Lmhwvg3bzVOOKfuX9x4dpfJSx7HjPqk6/hKKO2KKk44vrWOeHfHQp8bcZQbgFVFY3DzgMVR7vlkn1nF4wYW+MC3nu6nvCpNxyfgLwQtRtGacecJap3x3R9Qazm5uSndvMqKdyllAq76H5/Z6zu3bMTQyI9Q/6SV9EU27XkZaE6+snmyKTZkfgrEBByRDa47q4RU0tI428W/HF+9/dW2xRWNEgFcuL7AoZv9PorGO2RoIdU72iCZoFoa19POqZRx8MfT0YBk5ERLbcMpFZzY5JIvB2bfeyZmRmFl6wwWIWE+dNYRKyMSdObrAFYJETD6MhqqK+NW7MHtJdsedD/cB+8/AKCIKsmWyDK8MGBaz8DAktzvjhSZzl7ExHwGW0bykdpXkOINrnhzRLbDW9rjMBjahk0F8u4665/M5rTdwm8SZ+akIGQs5cNd7ngF+7gsy/3W74Qp+DgOce0LpehhwvQirVFzIPru72zG/Xkm3v8BKLtPZcBk9AXtKU6seVNZeCmqC2br/N0gLsv4iR2jxvoKLL6C2KsE+vRQ1jLI4yA3gENrYrTCRV70O4PUB89DTVf9sxsx3RggOcmMoTy6Tyr/Z7U2I6Pl3tLmOaFznBlCaubUrIigAAheyK2aPDZvYslalodlIAf33KcoZ1fJVavIYk F8j+Wcky 8dcILY/ngA0gnAfIWhNS02M1n6FqJRfXu8a8+bthvjeCoOOFjJRBwb8jwXZrnL7oO9LjT7UfSaQZaxbDaOL9IAcUIP+NMJAr9bk+R88r6G4ZNd3AZXKGrRl9Vi4CTAdsHAlWV7pfOA1+f06VL9noVqzE0ZXNfylWZbynJkwxP0wm9UvUC1UAWr1aHeQ== 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 Tue, Sep 12, 2023 at 03:52:13PM +0200, Peter Zijlstra wrote: > On Tue, Sep 12, 2023 at 01:28:13PM +0100, Matthew Wilcox wrote: > > On Tue, Sep 12, 2023 at 11:03:42AM +0200, Peter Zijlstra wrote: > > > If not, then sure we can do this; it's not like I managed to get rid of > > > muteX_is_locked() -- and I actually tried at some point :/ > > > > > > And just now I grepped for it, and look what I find: > > > > > > drivers/hid/hid-nintendo.c: if (unlikely(mutex_is_locked(&ctlr->output_mutex))) { > > > drivers/nvdimm/btt.c: if (mutex_is_locked(&arena->err_lock) > > > > > > And there's more :-( > > > > Are these actually abuse? I looked at these two, and they both seem to > > be asking "Does somebody else currently have this mutex?" rather than > > "Do I have this mutex?". > > It's effectively a random number generator in that capacity. Someone > might have it or might have had it when you looked and no longer have > it, or might have it now but not when you asked. Also, there's more fun; the 'is_locked' store from spin_lock() (or mutex, or whatever) is not ordered vs any other write inside the critical section. So something like: bar = 0; CPU0 CPU1 spin_lock(&foo) bar = 1; x = READ_ONCE(bar) y = spin_is_locked(&foo); spin_unlock(&foo); can have x==1 && y==0, even though CPU0 is currently inside the critical section. Normally that doesn't matter, and for the program-order case where you ask 'am I holding the lock' this obviously cannot go wrong. But the moment you ask: 'is someone else holding the lock' it all goes sideways real fast. We've been there, done that, got a t-shirt etc..