From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2133C27FB2A for ; Tue, 17 Mar 2026 13:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773755417; cv=none; b=tAUgKN+VZJQIBtY4V/ziqJFMlpxD3BDtLIfJ7d18fS4I+xQt/24S3VpryRJMZknOYcossm7Rax4HFu+v2bH+o63OIAI5FWW+gLgpvq5ZIyLkKXEniiZ/hyZUKyZP4bmjRV6/MhVYzO4CDqHtgYay7El45e3QrNP+SZ1R8OTN3BM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773755417; c=relaxed/simple; bh=G87NVCVJAKe3E/dO71wuzjFoLu/EbajPqvzF9SDlVEo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dQG1xmUWFd51uqsscLH1nPiwUoWC52Xbfs0c8XObXn872sBUitaHTHhLxr+wf1fLDxuNkoc2J3J4uVr8BlkbNGIoU1PYWo+3ePjRnllO4jPacJGChZ1qcl3u6bWMX90RC6OgJnEfrWz6osGsXzJt3fXBrMx5juI5n6YQ+lz9Kuc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LZqz6uk3; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LZqz6uk3" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-486b96760easo6269845e9.2 for ; Tue, 17 Mar 2026 06:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1773755414; x=1774360214; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=GQO2So+R3RUvp1cXmsEmeD/RusTpIBQ8ROOmd3oIRYE=; b=LZqz6uk3g1kBSJ+iY54uJArD7ezMdfjzW9E+4G49umOPWih0uB+TYUGOtROMShC+9J oEd5WckKyHij+lpQf69FbkYI7kfCBxDkFYtB81AuH6XSYfCT32FuVTZsCepAp6Oxh4L9 3Ok0JdJjKbtUnp+qxyjAvkvGcjoH5WHn3Y/shfWYZSAkbAWmNeJCDkRVDzz4EjEfVh/0 o9XtSJhPcxBJ9hZW8AYxmE66TJAkMcTmGfPSD/rWL+Zjnn4mB4BnOINlY6R8D06wSGXb cEvMFc7HSI92svikoGXIS/1Q7KFckF35Iv3mLFtUEhfi5X/DsTOWK0EXfDgckZG+FMt0 ZKxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773755414; x=1774360214; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=GQO2So+R3RUvp1cXmsEmeD/RusTpIBQ8ROOmd3oIRYE=; b=nkMu2BoEAU4rqJXbzW3bAZcSCIkUYigrkQJigM3OQcX6mIqj+SDHOInpTQbgfL2QeV Hek/MCy7XEK5tMQBMv1COdmYKBDPfz7Zvps2z6UCxraXXoVggBApy7d8rXTqzWsZojo3 zCd7cINJsF0RHHyq5IwJ05rT3Mn13xzvlA8mVFycOSkBGDVgmN2E2LYhCWa6yIQ4rTF5 +OulNIhn46sOt9j3v+zWMOSL0ewm+RoiFaToBQjCpRBLjmx4hTifLieYZXQkrzS5Lz1M aTSiU+FCpMi/sTC8mvq2Ote3/OEVNso/cBpqgjjSd7JqnLLYynmOxHPsEcf8m1mtX93K Z52Q== X-Forwarded-Encrypted: i=1; AJvYcCXXU9IPqE9S9OvQxuwhfEEmVomPzNifbK3juGs5iBQL98WmugRsbIg81BCB90rUftCpOrD4FNw4N/RWPck=@vger.kernel.org X-Gm-Message-State: AOJu0YyGnm9Oh7nLpXhsz/aETXiulTXmS64Ih2AaIzTWAPzh3z3mojBe LTZYapc2jweCz3kCCrtp2u7drY5Sz6fwfVpouFvfdAb6A++nrow3XXS/kALcdqDTmg== X-Gm-Gg: ATEYQzyPtIwCLD+pYWVVgyqExP1hPgmEV/SoXtOBU0kCaA8leiX95eJSzjsNLwoK+aZ 2F+FJuTUvPWowC83mLY2dOBLSMfeq0U6rB4Mu6RZu6bBykLpWgUKiR83CGW+mBesVxRqvdbtKUw B3BPzN5WhfHF3G8VxCcP71IexiGP4yHmsWzhZtFuMW4fvvShZBKqHr7EO1EGDg6apfh8ZHCzlqI 1hUeZcJJCM4RUEtY8P2CY8qjglsTxf9xBC7rPI72CfuktgQM+0TYtrIFkSqT/CxZi7mKGnCABBm lmZXEPf3k1MljOifw0Ti22N6lQ3Ha9u0MZ+Alezo3nOHRIROhGVEY5Am7exSS0VNuSUS98StW0A FWTCfPhYeyY04qbJjiXDQ05mU4pD8EeMpDAxNkbMmez2Irku0AwRVYH9Hkos2KZYk8XbLCh1fO2 4Z4wIhE2ecOVA9fJ1RnJ07LTPz/bGICFqEbFMaiCRHim9L1mp/SpZzEUdbHbB4 X-Received: by 2002:a05:600c:45d5:b0:477:7bca:8b34 with SMTP id 5b1f17b1804b1-485566d3104mr279551085e9.6.1773755413738; Tue, 17 Mar 2026 06:50:13 -0700 (PDT) Received: from elver.google.com ([2a00:79e0:2834:9:4231:51a3:64bc:c9b8]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4856eab0504sm66950395e9.13.2026.03.17.06.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 06:50:12 -0700 (PDT) Date: Tue, 17 Mar 2026 14:49:51 +0100 From: Marco Elver To: Bart Van Assche Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] locking: Add lock context support in do_raw_{read,write}_trylock() Message-ID: References: <20260313171510.230998-1-bvanassche@acm.org> <20260313171510.230998-3-bvanassche@acm.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260313171510.230998-3-bvanassche@acm.org> User-Agent: Mutt/2.2.13 (2024-03-09) On Fri, Mar 13, 2026 at 10:15AM -0700, Bart Van Assche wrote: > Convert do_raw_{read,write}_trylock() from macros into inline functions > and annotate these inline functions with __cond_acquires_shared() or > __cond_acquires() as appropriate. This change is necessary to build > kernel drivers or subsystems that use rwlock synchronization objects with > lock context analysis enabled. The return type 'int' matches the return > type for CONFIG_DEBUG_SPINLOCK=y. > > Signed-off-by: Bart Van Assche > --- > include/linux/rwlock.h | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h > index 21ceefc4a49f..4e67cd934d8f 100644 > --- a/include/linux/rwlock.h > +++ b/include/linux/rwlock.h > @@ -37,10 +37,20 @@ extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock); > extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock); > #else > # define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0) > -# define do_raw_read_trylock(rwlock) arch_read_trylock(&(rwlock)->raw_lock) > +static inline int do_raw_read_trylock(rwlock_t *rwlock) > + __cond_acquires_shared(true, rwlock) > + __no_context_analysis > +{ > + return arch_read_trylock(&(rwlock)->raw_lock); > +} > # define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0) > # define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0) > -# define do_raw_write_trylock(rwlock) arch_write_trylock(&(rwlock)->raw_lock) > +static inline int do_raw_write_trylock(rwlock_t *rwlock) > + __cond_acquires(true, rwlock) > + __no_context_analysis > +{ > + return arch_write_trylock(&(rwlock)->raw_lock); > +} > # define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0) > #endif The pre-existing annotations were wrong (from Sparse era, introduced in b97c4bc16734a) - I think you need to include this to build with CONFIG_DEBUG_SPINLOCK=n now: diff --git a/include/linux/rwlock.h b/include/linux/rwlock.h index 3d1834ef15d5..9e577e649bf9 100644 --- a/include/linux/rwlock.h +++ b/include/linux/rwlock.h @@ -36,22 +36,22 @@ do { \ extern int do_raw_write_trylock(rwlock_t *lock); extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock); #else -# define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0) +# define do_raw_read_lock(rwlock) do {__acquire_shared(rwlock); arch_read_lock(&(rwlock)->raw_lock); } while (0) static inline int do_raw_read_trylock(rwlock_t *rwlock) __cond_acquires_shared(true, rwlock) __no_context_analysis { return arch_read_trylock(&(rwlock)->raw_lock); } -# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0) -# define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0) +# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(rwlock); } while (0) +# define do_raw_write_lock(rwlock) do {__acquire(rwlock); arch_write_lock(&(rwlock)->raw_lock); } while (0) static inline int do_raw_write_trylock(rwlock_t *rwlock) __cond_acquires(true, rwlock) __no_context_analysis { return arch_write_trylock(&(rwlock)->raw_lock); } -# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0) +# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(rwlock); } while (0) #endif /* diff --git a/include/linux/rwlock_api_smp.h b/include/linux/rwlock_api_smp.h index 61a852609eab..25dfee624cf1 100644 --- a/include/linux/rwlock_api_smp.h +++ b/include/linux/rwlock_api_smp.h @@ -116,6 +116,7 @@ _raw_write_unlock_irqrestore(rwlock_t *lock, unsigned long flags) #endif static inline int __raw_read_trylock(rwlock_t *lock) + __cond_acquires_shared(true, lock) { preempt_disable(); if (do_raw_read_trylock(lock)) { @@ -127,6 +128,7 @@ static inline int __raw_read_trylock(rwlock_t *lock) } static inline int __raw_write_trylock(rwlock_t *lock) + __cond_acquires(true, lock) { preempt_disable(); if (do_raw_write_trylock(lock)) {