From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) (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 36ED92DA75C for ; Wed, 21 Jan 2026 13:07:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.67 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769000860; cv=none; b=Ars9ngKU9TJkWyzzsvKS3IDMbeabXFcfVgsv+sOivtHFPccrUFLmAyH4msI4AlzuxJl3ILY9VSHDLn/FX1YHU9dx8EuzpbHCOIkhP/YQNElsEyBFRbQPWOZYQvjrQI36kO5m7ISdYnj+4UWQdLD7yQf+1AykYIkICypuO+UeUzY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769000860; c=relaxed/simple; bh=/He7XkJuMD2GHxpy8ngilXXjP86qi/hHg6QMOo5hvwo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qpXfyTVLJxjTZGTq/pAghS0cGSwrgGpCBUpHYD6EbG9+PVxtm5FfFg9IYmmA/NR28E8a2LYgI3aUq5ao7xcn+GnBKSjo9uEWhqm8CfFuJzZQ18dMInGftB/UaBhPQxPB1FNwiFGXZriUymCn8XKJJ40GxbFj5ELU3V+6HI9eAtQ= 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=mJmIHNc1; arc=none smtp.client-ip=209.85.128.67 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="mJmIHNc1" Received: by mail-wm1-f67.google.com with SMTP id 5b1f17b1804b1-47d63594f7eso47696535e9.0 for ; Wed, 21 Jan 2026 05:07:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769000855; x=1769605655; 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=+18IqaYiahx1d0Sw+3yYUAKVk+CC0tUKgi49oNi4j+c=; b=mJmIHNc1lwk3UZZdZICLfECLUlA3QC8TInBlwkRidJAuMgD0a0X3BELS2Yd1H8JfSe bzPPq28TGTjILUEaZnwRZaihmZpBGSx2SbP0h973YfTTdrDtc/yQcLB76WxzFZsNQh5Y LWpLB4WYl5l2k1pJAZXesdj/QGFFLVKfx9+vOevOaFnBoPqynx0MipSUWoTT+N4m16Mc zZiDIhUAOstqhZ+VWRpW+oH14WGI4Wcdbi4dLA1XuMSUC9DXXc5WLkFiCGrIYsV2jaUS hGjM5AUkvsjNXkUz205SGhm39xwU1/KwQ56bbiOBwiKPE+wm83j+kphEW0HyiARPM2tZ kQLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769000855; x=1769605655; 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=+18IqaYiahx1d0Sw+3yYUAKVk+CC0tUKgi49oNi4j+c=; b=d7IqCqWE0Itpng1X/nsE/tM0Ui3jJyCrzF4IYbSmZFNWWj921oziqZRUT6/GZhmEhh JTft8BmJlQD+TUl/PA3vMPnX+rzSSWodUlWaPkBvr9m7uFg/GrGYIY/qrGY7PqKcB9Se EBeKma8heOwUesWnklPwzGlByauuoHFZoX9Ovj1/NjAMGm4880LhulSyw+Si51uuaXxn w+IHJCkQsZHA6QlahBw9ZKlmKPPAnf57lh57u2B5k31UZ00Gttb8wjKr7bITBeGDSLxh ouOl+SCozJBFW1Htg0D6qRm9UBjcvaQmP1zxvcJtMKVzqhHBtQo5dJmKX2eUb9lmy6DD rtNA== X-Gm-Message-State: AOJu0YwFZ//W6YMf71CO92Di86ZO2welEw0i02B5ImmYE6/c9s6/hX1a Hnnvv973IPeudxP3Xc1zRjmvP1dq2OUhstjTjzRgrfeDNE6o8tMnD1gJuWWo2YEEmw== X-Gm-Gg: AZuq6aK0DG+9Dd/Qz50jjSVBSY6Nfyucjwy+ClQjLW/2yXJq9qrXXGe9fumFWKZU4aD LSpkYxz75k/gcozYuY29XgxnVvrbnPYCN8Aai/TsICrRCWEJTanGn6dFw+d2CevDbKJsIlYyK/B yaWpjEmDYhdaPcFrpoir8B8CR2W22XloP/IrD5uB+lh2LCux/BK+cQB308ZedbcqaVHgHPYyffV rLgMfhgj0JgRcTKfK8T4D2pmvqDeFFBTer/HJtqgwb1T2ziCZp1QQ+IGm/q4RcnTmPjknsGu5SR Q38jc7YUZYYWFc3umLYZSOfUpjyLSz23AyAJGnsrZq6KO6++ldsloK1vmzCa3QVwWu0tIaRcqba +CffTIGXY0iHBuQyj7zD9dS07jPqk6rykCZ2pk1jNZeN+5Y5+vA+3ZdR5Gv7CzY6gwKxfYvddVs yNjexLdtFJTA+dCWMacmP8wI543GwvYvpAENBledXWfA39AOwSqqCbngbPLSY= X-Received: by 2002:a05:600c:4586:b0:477:6d96:b3c8 with SMTP id 5b1f17b1804b1-48026040621mr166827695e9.23.1769000855326; Wed, 21 Jan 2026 05:07:35 -0800 (PST) Received: from elver.google.com ([2a00:79e0:2834:9:2bba:cbd4:de42:72d5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4801e8c9cbcsm307957095e9.12.2026.01.21.05.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jan 2026 05:07:34 -0800 (PST) Date: Wed, 21 Jan 2026 14:07:28 +0100 From: Marco Elver To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, bigeasy@linutronix.de, mingo@kernel.org, tglx@linutronix.de, will@kernel.org, boqun.feng@gmail.com, longman@redhat.com, hch@lst.de, rostedt@goodmis.org, bvanassche@acm.org, llvm@lists.linux.dev Subject: Re: [RFC][PATCH 0/4] locking: Add/convert context analysis bits Message-ID: References: <20260121110704.221498346@infradead.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: <20260121110704.221498346@infradead.org> User-Agent: Mutt/2.2.13 (2024-03-09) On Wed, Jan 21, 2026 at 12:07PM +0100, Peter Zijlstra wrote: > Hai > > This is on top of tip/locking/core with these patches on: > > https://lkml.kernel.org/r/20260119094029.1344361-1-elver@google.com > > and converts mutex, rtmutex, ww_mutex and futex to use the new context analysis > bits. > > There is one snafu: > > ww_mutex_set_context_fastpath()'s data_race() usage doesn't stop the compiler > from complaining when building a defconfig+PREEMPT_RT+LOCKDEP build: > > ../kernel/locking/ww_mutex.h:439:24: error: calling function '__ww_mutex_has_waiters' requires holding raw_spinlock 'lock->base.rtmutex.wait_lock' exclusively [-Werror,-Wthread-safety-analysis] > 439 | if (likely(!data_race(__ww_mutex_has_waiters(&lock->base)))) > | ^ > 1 error generated. This works: diff --git a/kernel/locking/ww_mutex.h b/kernel/locking/ww_mutex.h index 73eed6b7f24e..561e2475954d 100644 --- a/kernel/locking/ww_mutex.h +++ b/kernel/locking/ww_mutex.h @@ -436,7 +436,8 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) * __ww_mutex_add_waiter() and makes sure we either observe ww->ctx * and/or !empty list. */ - if (likely(!data_race(__ww_mutex_has_waiters(&lock->base)))) + bool has_waiters = data_race(__ww_mutex_has_waiters(&lock->base)); + if (likely(!has_waiters)) return; /* It appears that the _Pragma are ignored when the expression is inside __builtin_expect(...). That's a bit inconvenient. Another option is this given its exclusively used without holding this lock: diff --git a/kernel/locking/ww_mutex.h b/kernel/locking/ww_mutex.h index 73eed6b7f24e..45a9c394fe91 100644 --- a/kernel/locking/ww_mutex.h +++ b/kernel/locking/ww_mutex.h @@ -71,7 +71,7 @@ __ww_mutex_owner(struct mutex *lock) } static inline bool -__ww_mutex_has_waiters(struct mutex *lock) +__ww_mutex_has_waiters_lockless(struct mutex *lock) { return atomic_long_read(&lock->owner) & MUTEX_FLAG_WAITERS; } @@ -151,10 +151,9 @@ __ww_mutex_owner(struct rt_mutex *lock) } static inline bool -__ww_mutex_has_waiters(struct rt_mutex *lock) - __must_hold(&lock->rtmutex.wait_lock) +__ww_mutex_has_waiters_lockless(struct rt_mutex *lock) { - return rt_mutex_has_waiters(&lock->rtmutex); + return data_race(rt_mutex_has_waiters(&lock->rtmutex)); } static inline void lock_wait_lock(struct rt_mutex *lock, unsigned long *flags) @@ -436,7 +435,7 @@ ww_mutex_set_context_fastpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) * __ww_mutex_add_waiter() and makes sure we either observe ww->ctx * and/or !empty list. */ - if (likely(!data_race(__ww_mutex_has_waiters(&lock->base)))) + if (likely(!__ww_mutex_has_waiters_lockless(&lock->base))) return; /*