From nobody Tue Dec 2 02:20:22 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FBE91F5617 for ; Thu, 20 Nov 2025 11:04:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763636684; cv=none; b=ozjWvhrq0wgMxL2kRpVt1tC3FJceLwxddBbs3+dMzFzvf5SUCZMV75yumyyPww0fIx/IstUstHUEqZwoZKUE6mDeLt6N4jt3Xg99iGO9ksILJ5Snt5U6eKM5XJFgi0Z4yGLC9MjoCoLs7yto7WRU0Nx4+1OkaQC1q/Fg+bcFLi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763636684; c=relaxed/simple; bh=cJ9+AHKcuOWPh52l0sFwdJo0i/z7RcPFiHsIZr076JA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y8llYJYcPVWYEUith1FTVMbR5vHD4mq1Sm5lsCXAQ/MNEZmpyJvXwRwBEgVSiKoD5maIv+llvpfGsS4zSP2RIeTzPSqLDt52DH+RJQG74FMo4AbdrmP20RPoPFwF2o/17m/2CIoSlOr0W4GNn1u4Up9tS+hZC9ZVInNPEklgJNM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Cz/YSM+G; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Cz/YSM+G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1763636682; x=1795172682; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cJ9+AHKcuOWPh52l0sFwdJo0i/z7RcPFiHsIZr076JA=; b=Cz/YSM+G2SYBY2/tabAXjsp7GoYWHIHy1QA8iLns0eD/r61dl1CYsLMY RPfvaRWeIOZNOu11U1WIuoJBE+MdnPPwgzcC73BKdbhfvLzUo/hrgsiX2 QHRtZBhn495T2txTOzWLDkOBdrNRcTQwO/wXMk5VPmhtdYjakiRffMFT+ N3LWNlGHZMX7dDr1MAKSWUlhbkI/xNZh4ccyvabQT5lB+IhDRfONTLseS 6//sTXP0KkZ1YHPNe9xoKBXPEcSmk4L3qKoZzFcpLcF78U3J6iE0T2jzc t+RCnmeTIsJwU+OG4px40mQW6tW3SvtK0Kwme4ejT3TcNZKvA9eHwUamP g==; X-CSE-ConnectionGUID: bF+vzTxTQXCe82HZm5ITxg== X-CSE-MsgGUID: tGOKbbh2Q1aCD7mHVyKKQA== X-IronPort-AV: E=McAfee;i="6800,10657,11618"; a="68308021" X-IronPort-AV: E=Sophos;i="6.19,317,1754982000"; d="scan'208";a="68308021" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2025 03:04:41 -0800 X-CSE-ConnectionGUID: +0IbbpFWSYGhstTHsbJhsQ== X-CSE-MsgGUID: Zv9oplZMR/ml0fWkFf0Mvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,317,1754982000"; d="scan'208";a="228643711" Received: from agladkov-desk.ger.corp.intel.com (HELO fedora) ([10.245.244.142]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2025 03:04:34 -0800 From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= To: intel-xe@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Matthew Auld , Matthew Brost , Maarten Lankhorst , Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , Waiman Long , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , LKML , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Subject: [RFC PATCH 1/2] kernel/locking/ww_mutex: Add per-lock lock-check helpers Date: Thu, 20 Nov 2025 12:03:40 +0100 Message-ID: <20251120110341.2425-2-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251120110341.2425-1-thomas.hellstrom@linux.intel.com> References: <20251120110341.2425-1-thomas.hellstrom@linux.intel.com> 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="utf-8" Content-Transfer-Encoding: quoted-printable Code using ww_mutexes typically by design have a number of such mutexes sharing the same ww_class, and within a ww transaction they are all lockdep annotated using a nest_lock which means that multiple ww_mutexes of the same lockdep class may be locked at the same time. That means that lock_is_held() returns true and lockdep_assert_held() doesn't fire as long as there is a *single* ww_mutex held of the same class. IOW within a WW transaction. Code using these mutexes typically want to assert that individual ww_mutexes are held. Not that any ww_mutex of the same class is held. Introduce functions that can be used for that. RFC: Placement of the functions? lockdep.c? Are the #ifdefs testing for the correct config? Signed-off-by: Thomas Hellstr=C3=B6m --- include/linux/ww_mutex.h | 18 ++++++++++++++++++ kernel/locking/mutex.c | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h index 45ff6f7a872b..7bc0f533dea6 100644 --- a/include/linux/ww_mutex.h +++ b/include/linux/ww_mutex.h @@ -380,4 +380,22 @@ static inline bool ww_mutex_is_locked(struct ww_mutex = *lock) return ww_mutex_base_is_locked(&lock->base); } =20 +#ifdef CONFIG_PROVE_LOCKING + +bool ww_mutex_held(struct ww_mutex *lock); + +#else /* CONFIG_PROVE_LOCKING */ + +static inline bool ww_mutex_held(struct ww_mutex *lock) +{ + return true; +} + +#endif /* CONFIG_PROVE_LOCKING */ + +static inline void ww_mutex_assert_held(struct ww_mutex *lock) +{ + lockdep_assert(ww_mutex_held(lock)); +} + #endif diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index de7d6702cd96..37868b739efd 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -1174,3 +1174,13 @@ int atomic_dec_and_mutex_lock(atomic_t *cnt, struct = mutex *lock) return 1; } EXPORT_SYMBOL(atomic_dec_and_mutex_lock); + +#ifdef CONFIG_PROVE_LOCKING + +bool ww_mutex_held(struct ww_mutex *lock) +{ + return __ww_mutex_owner(&lock->base) =3D=3D current; +} +EXPORT_SYMBOL(ww_mutex_held); + +#endif /* CONFIG_PROVE_LOCKING */ --=20 2.51.1