From nobody Sat Feb 7 10:08:18 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 0C70A16B3A6 for ; Fri, 9 Aug 2024 22:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242467; cv=none; b=fowNyTLg7FNO6M65XzbsVxLm9vzYBzVqOjNPKe1tE8BV+fQugu1azNz4iQsX8IhESSCZwomdcnHzCbbgkHONHpXQ/jnxCStI85SRoOZWT00hpolSAddEOWyQySIEh2hNwYg/qZk4mFYx4IDyqJVSwF3t5IHZOGVSEWyDTEPgaDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242467; c=relaxed/simple; bh=ZTr6JyEn1nSzgdfSh1QuqS59D0zZxggT3OqlXoJsrlE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tcIcjzhn859yvbFpZripyQzQMnrZzFmOwg9W1x3GqhGL9IhcX2ih/8430rauDEj8XBxeZsOzYJNhjJxXyR8tZbRNKHnr44YTHRyhjsYSbwyOTPwZXxuIhDbUNHZNmDjydJ5a7RKiZJEI+j/DhCvhUHByczrDSIg9ZdRz1x1SKqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dJ7o0y5j; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dJ7o0y5j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723242466; x=1754778466; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZTr6JyEn1nSzgdfSh1QuqS59D0zZxggT3OqlXoJsrlE=; b=dJ7o0y5jzwE0eUxlpsnY4NwvilBn8c7ZguIfFI1DYAsqTCANuiPb17fk 8knjDXO3BkRH/DWiEmYqKGMtTRQ2jdVG4giILdMsKR296AEPjALtSZ8R0 sQy8X81epBI1LOnW+DfsW39djx7PY2Y1Hjq2IFIhjncphu/thglJI3I1s GSeGsrwdlry75QQrbYv4R8hPJ3EOq7aqSjMfOeBRnsmPoG42vRixezN5z 7y2x5KfDJV0ylyL+2Pdv557fqvIi+RN+5s+EgYzDi2tyE/J6mIfHEl5Qa o6KqE72Cvpe7f++Kk2LbKgROqs6G0tyzsXOq10tG8nV9YorR/0Lxs5+In A==; X-CSE-ConnectionGUID: h9BZz1xvQw6EYpf6SLOyqA== X-CSE-MsgGUID: Mx7okzGbQoOy/6499idxlA== X-IronPort-AV: E=McAfee;i="6700,10204,11159"; a="25229641" X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="25229641" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 X-CSE-ConnectionGUID: LScDgSonScyBM7vJaVgrww== X-CSE-MsgGUID: N+9j/irpR96KLJvRSuTSWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="62641782" Received: from lstrano-desk.jf.intel.com ([10.54.39.91]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: tj@kernel.org, jiangshanlai@gmail.com, christian.koenig@amd.com, ltuikov89@gmail.com, daniel@ffwll.ch Subject: [PATCH v3 1/5] workqueue: Split alloc_workqueue into internal function and lockdep init Date: Fri, 9 Aug 2024 15:28:23 -0700 Message-Id: <20240809222827.3211998-2-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809222827.3211998-1-matthew.brost@intel.com> References: <20240809222827.3211998-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Will help enable user-defined lockdep maps for workqueues. Cc: Tejun Heo Cc: Lai Jiangshan Signed-off-by: Matthew Brost --- kernel/workqueue.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 1745ca788ede..90a98c9b0ac6 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5612,9 +5612,9 @@ static void wq_adjust_max_active(struct workqueue_str= uct *wq) } =20 __printf(1, 4) -struct workqueue_struct *alloc_workqueue(const char *fmt, - unsigned int flags, - int max_active, ...) +static struct workqueue_struct *__alloc_workqueue(const char *fmt, + unsigned int flags, + int max_active, ...) { va_list args; struct workqueue_struct *wq; @@ -5680,12 +5680,11 @@ struct workqueue_struct *alloc_workqueue(const char= *fmt, INIT_LIST_HEAD(&wq->flusher_overflow); INIT_LIST_HEAD(&wq->maydays); =20 - wq_init_lockdep(wq); INIT_LIST_HEAD(&wq->list); =20 if (flags & WQ_UNBOUND) { if (alloc_node_nr_active(wq->node_nr_active) < 0) - goto err_unreg_lockdep; + goto err_free_wq; } =20 /* @@ -5724,9 +5723,6 @@ struct workqueue_struct *alloc_workqueue(const char *= fmt, kthread_flush_worker(pwq_release_worker); free_node_nr_active(wq->node_nr_active); } -err_unreg_lockdep: - wq_unregister_lockdep(wq); - wq_free_lockdep(wq); err_free_wq: free_workqueue_attrs(wq->unbound_attrs); kfree(wq); @@ -5737,6 +5733,25 @@ struct workqueue_struct *alloc_workqueue(const char = *fmt, destroy_workqueue(wq); return NULL; } + +__printf(1, 4) +struct workqueue_struct *alloc_workqueue(const char *fmt, + unsigned int flags, + int max_active, ...) +{ + struct workqueue_struct *wq; + va_list args; + + va_start(args, max_active); + wq =3D __alloc_workqueue(fmt, flags, max_active, args); + va_end(args); + if (!wq) + return NULL; + + wq_init_lockdep(wq); + + return wq; +} EXPORT_SYMBOL_GPL(alloc_workqueue); =20 static bool pwq_busy(struct pool_workqueue *pwq) --=20 2.34.1 From nobody Sat Feb 7 10:08:18 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 6295A16C861 for ; Fri, 9 Aug 2024 22:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242469; cv=none; b=ZlXTVqMJMMmyx/5dkkmoTZt9T7tJulotv71GQfWfrF133fR+uudg85CH4gW+7szgtaeJ2m3tvjUvPrTWYACik62d7ICU35KcSA4/GuTVNRhOdDXTB3yrQgVt/vF2okFParAJLOb8U+pdsI6p7MO5Yea6crYcrUmsTSBQNryzBWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242469; c=relaxed/simple; bh=5NsFxeHz5H781GU70fSvGb8d+biJ1SrQI5t3Iz1xhm4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eD0FNQ5qVaEvtoFca3gi/Ip6VJQxC/DA3NYdxhKkhOqLvrJSWRxW50+C/afkS57qYACks/hbcaw0rsTz1fHr/gDHcfGdNr+kLq830Tnd1i2jo/vZRQBILZnh6CwQcOwu3/ic9bGP2xkD7b4RNnGO3D4X+jsilDeSpPWyQmSjFkI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ghUO1NiO; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ghUO1NiO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723242468; x=1754778468; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5NsFxeHz5H781GU70fSvGb8d+biJ1SrQI5t3Iz1xhm4=; b=ghUO1NiOIpXLRchriMO1l2Te5ZK6ROME6qQXItK1jRQo8W9z7XmcSN5I P3CKt/YZVAUjkcgIXJDIZHfn7ykqV6mJCIq/0NFpdZSoqym3HNLRJ1lIF qjsLVL1z+H1wG2wFyGLXAOrrtHC+kSOkJciRHZ1WkejcObHHHaL3TGKQs 1A2/gZMsS06fles3OB1DzU4ertDUrXSVBHXEt+hPtsKBAVwfcahXae3r7 bhRpjalFGs71z3KSCG6MLNYg8BTKIbOmUwMXzuZYAXCWaPyVdt4DXBalh obt9KDzIKHlmP0ppm5L2X1D+UpK5ADM0dItbrKRzzPNI+YNhmZ6jySO+o A==; X-CSE-ConnectionGUID: 28QRXm80SDCtjjbK339EsQ== X-CSE-MsgGUID: V6m187ZbSk6DNP6stEHlDQ== X-IronPort-AV: E=McAfee;i="6700,10204,11159"; a="25229647" X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="25229647" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 X-CSE-ConnectionGUID: FOR7/2yKRCiAdYThcoZIyA== X-CSE-MsgGUID: gVoIWKkETiKThh1mDYVCPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="62641783" Received: from lstrano-desk.jf.intel.com ([10.54.39.91]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: tj@kernel.org, jiangshanlai@gmail.com, christian.koenig@amd.com, ltuikov89@gmail.com, daniel@ffwll.ch Subject: [PATCH v3 2/5] workqueue: Change workqueue lockdep map to pointer Date: Fri, 9 Aug 2024 15:28:24 -0700 Message-Id: <20240809222827.3211998-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809222827.3211998-1-matthew.brost@intel.com> References: <20240809222827.3211998-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Will help enable user-defined lockdep maps for workqueues. Cc: Tejun Heo Cc: Lai Jiangshan Signed-off-by: Matthew Brost --- kernel/workqueue.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 90a98c9b0ac6..24df85589dc0 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -364,7 +364,8 @@ struct workqueue_struct { #ifdef CONFIG_LOCKDEP char *lock_name; struct lock_class_key key; - struct lockdep_map lockdep_map; + struct lockdep_map __lockdep_map; + struct lockdep_map *lockdep_map; #endif char name[WQ_NAME_LEN]; /* I: workqueue name */ =20 @@ -3203,7 +3204,7 @@ __acquires(&pool->lock) lockdep_start_depth =3D lockdep_depth(current); /* see drain_dead_softirq_workfn() */ if (!bh_draining) - lock_map_acquire(&pwq->wq->lockdep_map); + lock_map_acquire(pwq->wq->lockdep_map); lock_map_acquire(&lockdep_map); /* * Strictly speaking we should mark the invariant state without holding @@ -3237,7 +3238,7 @@ __acquires(&pool->lock) pwq->stats[PWQ_STAT_COMPLETED]++; lock_map_release(&lockdep_map); if (!bh_draining) - lock_map_release(&pwq->wq->lockdep_map); + lock_map_release(pwq->wq->lockdep_map); =20 if (unlikely((worker->task && in_atomic()) || lockdep_depth(current) !=3D lockdep_start_depth || @@ -3873,8 +3874,8 @@ static void touch_wq_lockdep_map(struct workqueue_str= uct *wq) if (wq->flags & WQ_BH) local_bh_disable(); =20 - lock_map_acquire(&wq->lockdep_map); - lock_map_release(&wq->lockdep_map); + lock_map_acquire(wq->lockdep_map); + lock_map_release(wq->lockdep_map); =20 if (wq->flags & WQ_BH) local_bh_enable(); @@ -3908,7 +3909,7 @@ void __flush_workqueue(struct workqueue_struct *wq) struct wq_flusher this_flusher =3D { .list =3D LIST_HEAD_INIT(this_flusher.list), .flush_color =3D -1, - .done =3D COMPLETION_INITIALIZER_ONSTACK_MAP(this_flusher.done, wq->lock= dep_map), + .done =3D COMPLETION_INITIALIZER_ONSTACK_MAP(this_flusher.done, (*wq->lo= ckdep_map)), }; int next_color; =20 @@ -4768,7 +4769,8 @@ static void wq_init_lockdep(struct workqueue_struct *= wq) lock_name =3D wq->name; =20 wq->lock_name =3D lock_name; - lockdep_init_map(&wq->lockdep_map, lock_name, &wq->key, 0); + wq->lockdep_map =3D &wq->__lockdep_map; + lockdep_init_map(wq->lockdep_map, lock_name, &wq->key, 0); } =20 static void wq_unregister_lockdep(struct workqueue_struct *wq) --=20 2.34.1 From nobody Sat Feb 7 10:08:18 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 0DAAE16C683 for ; Fri, 9 Aug 2024 22:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242469; cv=none; b=VNz9KXA7Av+7uwv/eGujI5DT0lDrNx+59Ws/Wjs5BZgK4gcqqxQsBqSle0hiJapLzg3g9vITeI+mn8sY+enIWNn2c5Bq5bvcH2z9fphyQxI9/TNwZ3aP1OKn6418S5KFbG6vly95Yg4Kf/6g8WyaEQcV8e/vP8n4PdpLaj+ymTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242469; c=relaxed/simple; bh=vBcSLoAHnTlPr0DGOVnoBXIz4sPiLaWiqyEvFFFmiIY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=efUScLReSRqYr66QjEDOsfs6vRZBS/kP5R6A2Bk0ss/m+EQorqko62fhNDfo6m2d2fJB+XAxkvhHpi674VFRzZ7QoFOWKONNLQmNbErFnJk7OSLxfPDM+L4BWi3tollpP8WGWGPa+aKLU1cQ5Nah7/oohd9LJJC2yOngHEfY6Ks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jTF1t9l2; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jTF1t9l2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723242468; x=1754778468; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vBcSLoAHnTlPr0DGOVnoBXIz4sPiLaWiqyEvFFFmiIY=; b=jTF1t9l2LRbvMCQxSFqmdJ97nGZEhiX2p8JVQDsTUSvQ97iyNE9bzEOO VIWc2r690+c2BjCiasaajQ7zhjkNgSlC34Ctymdkg4iimQpJRgEZAJBl9 LkGM4yrBUk8qYrzn/1qnq9/9qBggp0B2jSAd3sLgBsqBd/sXtQf6xkmMs EfOR1wfiVSscGkP5E22JMcmD/Hoc/rj4LzCn1URkZzDEQyP7ML/KeDYFZ FvRMIM6ew6oENaej/JpTBZOYiD7pVs1LiY5aZpvbAijejJZLfYdOmIOz8 WnEsGBnfi429Dj9JFRqEofXC4JG6ZLaMl8HaGSujpkp38jLxgo+z/3gmR Q==; X-CSE-ConnectionGUID: Z80eygzRSl6bgZKLJMqfsQ== X-CSE-MsgGUID: E6WhIum/QvCoYcmR4YnVnA== X-IronPort-AV: E=McAfee;i="6700,10204,11159"; a="25229653" X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="25229653" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 X-CSE-ConnectionGUID: qsRtHUBhTtW4Cm8kiOMtUA== X-CSE-MsgGUID: GHxpiMNHT+OIgHLHQyakJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="62641784" Received: from lstrano-desk.jf.intel.com ([10.54.39.91]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: tj@kernel.org, jiangshanlai@gmail.com, christian.koenig@amd.com, ltuikov89@gmail.com, daniel@ffwll.ch Subject: [PATCH v3 3/5] workqueue: Add interface for user-defined workqueue lockdep map Date: Fri, 9 Aug 2024 15:28:25 -0700 Message-Id: <20240809222827.3211998-4-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809222827.3211998-1-matthew.brost@intel.com> References: <20240809222827.3211998-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an interface for a user-defined workqueue lockdep map, which is helpful when multiple workqueues are created for the same purpose. This also helps avoid leaking lockdep maps on each workqueue creation. v2: - Add alloc_workqueue_lockdep_map (Tejun) v3: - Drop __WQ_USER_OWNED_LOCKDEP (Tejun) - static inline alloc_ordered_workqueue_lockdep_map (Tejun) Cc: Tejun Heo Cc: Lai Jiangshan Signed-off-by: Matthew Brost --- include/linux/workqueue.h | 52 +++++++++++++++++++++++++++++++++++++++ kernel/workqueue.c | 28 +++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 4eb8f9563136..8ccbf510880b 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -507,6 +507,58 @@ void workqueue_softirq_dead(unsigned int cpu); __printf(1, 4) struct workqueue_struct * alloc_workqueue(const char *fmt, unsigned int flags, int max_active, ...); =20 +#ifdef CONFIG_LOCKDEP +/** + * alloc_workqueue_lockdep_map - allocate a workqueue with user-defined lo= ckdep_map + * @fmt: printf format for the name of the workqueue + * @flags: WQ_* flags + * @max_active: max in-flight work items, 0 for default + * @lockdep_map: user-defined lockdep_map + * @...: args for @fmt + * + * Same as alloc_workqueue but with the a user-define lockdep_map. Useful = for + * workqueues created with the same purpose and to avoid leaking a lockdep= _map + * on each workqueue creation. + * + * RETURNS: + * Pointer to the allocated workqueue on success, %NULL on failure. + */ +__printf(1, 5) struct workqueue_struct * +alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, int max_a= ctive, + struct lockdep_map *lockdep_map, ...); + +/** + * alloc_ordered_workqueue_lockdep_map - allocate an ordered workqueue with + * user-defined lockdep_map + * + * @fmt: printf format for the name of the workqueue + * @flags: WQ_* flags (only WQ_FREEZABLE and WQ_MEM_RECLAIM are meaningful) + * @lockdep_map: user-defined lockdep_map + * @args: args for @fmt + * + * Same as alloc_ordered_workqueue but with the a user-define lockdep_map. + * Useful for workqueues created with the same purpose and to avoid leakin= g a + * lockdep_map on each workqueue creation. + * + * RETURNS: + * Pointer to the allocated workqueue on success, %NULL on failure. + */ +__printf(1, 4) static inline struct workqueue_struct * +alloc_ordered_workqueue_lockdep_map(const char *fmt, unsigned int flags, + struct lockdep_map *lockdep_map, ...) +{ + struct workqueue_struct *wq; + va_list args; + + va_start(args, lockdep_map); + wq =3D alloc_workqueue_lockdep_map(fmt, WQ_UNBOUND | __WQ_ORDERED | flags, + 1, lockdep_map, args); + va_end(args); + + return wq; +} +#endif + /** * alloc_ordered_workqueue - allocate an ordered workqueue * @fmt: printf format for the name of the workqueue diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 24df85589dc0..f4b50a995e99 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4775,11 +4775,17 @@ static void wq_init_lockdep(struct workqueue_struct= *wq) =20 static void wq_unregister_lockdep(struct workqueue_struct *wq) { + if (wq->lockdep_map !=3D &wq->__lockdep_map) + return; + lockdep_unregister_key(&wq->key); } =20 static void wq_free_lockdep(struct workqueue_struct *wq) { + if (wq->lockdep_map !=3D &wq->__lockdep_map) + return; + if (wq->lock_name !=3D wq->name) kfree(wq->lock_name); } @@ -5756,6 +5762,28 @@ struct workqueue_struct *alloc_workqueue(const char = *fmt, } EXPORT_SYMBOL_GPL(alloc_workqueue); =20 +#ifdef CONFIG_LOCKDEP +__printf(1, 5) +struct workqueue_struct * +alloc_workqueue_lockdep_map(const char *fmt, unsigned int flags, + int max_active, struct lockdep_map *lockdep_map, ...) +{ + struct workqueue_struct *wq; + va_list args; + + va_start(args, lockdep_map); + wq =3D __alloc_workqueue(fmt, flags, max_active, args); + va_end(args); + if (!wq) + return NULL; + + wq->lockdep_map =3D lockdep_map; + + return wq; +} +EXPORT_SYMBOL_GPL(alloc_workqueue_lockdep_map); +#endif + static bool pwq_busy(struct pool_workqueue *pwq) { int i; --=20 2.34.1 From nobody Sat Feb 7 10:08:18 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 8644116A957 for ; Fri, 9 Aug 2024 22:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242468; cv=none; b=dBPHa3s6pfRHIEZg6QZvA+VWiYExAQw3Dc3Ctu697WGG5bEntVQBD1VO0Oj+EJ7PARnYfwRUKsA6gpHP5Pqb9lSEZxFNZbkcn0UWcEIffqIWUwwW7lXfcOMXvMVArQ8+ay+4t8k1AAIHExaKtd5cUyThlTLL7F1oSXB4TWisbCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242468; c=relaxed/simple; bh=ptiJFpcxcUokqaP9PdFq+FGJm+jDe2svhscYd8NXJ0M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Vu7xK0BVSUkePUgmuJUymFPG3grBEAPiYVarUQPGAle1IiRP5KE2S9afdQnhEf4NTSjqJ2YhWKAVKXmRQfoEwlsDzH7dzgGx74HXrOWCb8i6OStQeb4AM3BMfoTcN8HAyhM1wB1/gFvN40KkWLjkO5lkHEcILGrUeZS90cBsrqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AhRYautH; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AhRYautH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723242467; x=1754778467; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ptiJFpcxcUokqaP9PdFq+FGJm+jDe2svhscYd8NXJ0M=; b=AhRYautH4xvkv/vioes3LNNdwIfSIYUQAKVkaN8Ld1c5nDFjwG+sgVhE YZfriy0A6ocDkaESxKALNHPdF/D+61lpMyPBktS8NEUYR91wrUFvkuDjZ 1VLE0lrbZ4b44a5dSsJo8NMQMjhyZu4M06mXRttNyRkwAF5rMuN28LcwT 6X+OlECWha2EAXLR0Y0YbJca5vOLA3Z96r9dK9GjGSqE786GDgt8fQ15y GjqWWjgTAmx4JTJAs4m02kSXojnxZFxaFmRx+8A9cpz8I45blSkqcQORU 25IXNYEnRY4w7KxniDQTWkpOQn0C1V2eTkP5g7e+/Ts3izAHv6N02Z3xw A==; X-CSE-ConnectionGUID: PXxUshVaRdS2pUM+QTovmQ== X-CSE-MsgGUID: 4OCspbBNTsepapYQd4+5Ow== X-IronPort-AV: E=McAfee;i="6700,10204,11159"; a="25229659" X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="25229659" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 X-CSE-ConnectionGUID: s8KxR0Z2R42/B+NEObfnew== X-CSE-MsgGUID: PT9E3ignQ3m6u8bx2QvGBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="62641785" Received: from lstrano-desk.jf.intel.com ([10.54.39.91]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: tj@kernel.org, jiangshanlai@gmail.com, christian.koenig@amd.com, ltuikov89@gmail.com, daniel@ffwll.ch Subject: [PATCH v3 4/5] drm/sched: Use drm sched lockdep map for submit_wq Date: Fri, 9 Aug 2024 15:28:26 -0700 Message-Id: <20240809222827.3211998-5-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809222827.3211998-1-matthew.brost@intel.com> References: <20240809222827.3211998-1-matthew.brost@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 Avoid leaking a lockdep map on each drm sched creation and destruction by using a single lockdep map for all drm sched allocated submit_wq. v2: - Use alloc_ordered_workqueue_lockdep_map (Tejun) Cc: Luben Tuikov Cc: Christian K=C3=B6nig Signed-off-by: Matthew Brost --- drivers/gpu/drm/scheduler/sched_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/sched= uler/sched_main.c index ab53ab486fe6..cf79d348cb32 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -87,6 +87,12 @@ #define CREATE_TRACE_POINTS #include "gpu_scheduler_trace.h" =20 +#ifdef CONFIG_LOCKDEP +static struct lockdep_map drm_sched_lockdep_map =3D { + .name =3D "drm_sched_lockdep_map" +}; +#endif + #define to_drm_sched_job(sched_job) \ container_of((sched_job), struct drm_sched_job, queue_node) =20 @@ -1272,7 +1278,12 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, sched->submit_wq =3D submit_wq; sched->own_submit_wq =3D false; } else { +#ifdef CONFIG_LOCKDEP + sched->submit_wq =3D alloc_ordered_workqueue_lockdep_map(name, 0, + &drm_sched_lockdep_map); +#else sched->submit_wq =3D alloc_ordered_workqueue(name, 0); +#endif if (!sched->submit_wq) return -ENOMEM; =20 --=20 2.34.1 From nobody Sat Feb 7 10:08:18 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 94E2B16C87C for ; Fri, 9 Aug 2024 22:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242470; cv=none; b=Tt+5J5xntelJelsFQ6zq8eLthDEQ+l2wcSMaCqEl/PsbUBmLQ/rgRYLOsaYdgBUWdvjHAmuiaHwL6Or42uwAmmicvM15aUa85+EmzYX2erUIh7etWOiB3M4nW93fksTvGCFss+sdvhHDVH6sda9Uizl30NzZShmrmtYJIURXfPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723242470; c=relaxed/simple; bh=ND0M1O/b09cO9CGWjH0eDAueXMZa8J6c/uYozl9G1ZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PtPZOYm0JUabAVO5eGH87/HH/Y5G/xElNBOxuHMffxFsc7PeLsT0Ebx//TI47ih6lXzR9IJUhfVylQzlUKpoi9IHsAoodaOWQfIxxsEBa6Tj2X8tIcV9exLnD8Gby8yDvyPQHtdYNeQSojWBo+PaQ/0wCsdD05SGamvSQXFh5uA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TlyzpZVh; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TlyzpZVh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723242469; x=1754778469; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ND0M1O/b09cO9CGWjH0eDAueXMZa8J6c/uYozl9G1ZY=; b=TlyzpZVhnlM+/soAFMAIAhSJdI0wmNeDdnnOS61oWLHKGtVcE6VclXv/ vsKcebKI628dm07lqaOULKbsS01HVt2DVsqlhZeNo23FMMNGLsz4xP8+/ r5PQVLE5EX3p+yLyAnjScbINq1vvDr7XGuiNOFsdxJZTgaArptdjOwaPq StUIIqN5ERRHcB0zIOFnTPxMiX2sJYhxskrsHOyKPhqFn6gqwjUJjGjzl t3vC/47u9niRbNYiLweGt5RTAtcEMuJ8k4O12nmYpVyqkLCXL10tTm8qJ sjm2aoXk4hwopoRVUOhja/5uUxQszFdPXDWGajP7eS0357S2e4SAYZGTU g==; X-CSE-ConnectionGUID: iTrGtzDUS46qMsQmEVq8QQ== X-CSE-MsgGUID: OyhXeE+7TbCM13DDbS+CWA== X-IronPort-AV: E=McAfee;i="6700,10204,11159"; a="25229665" X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="25229665" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 X-CSE-ConnectionGUID: yRHSFi7BSbGkYELLDEK/cg== X-CSE-MsgGUID: EgBTSnGNTRGaGrfbQGCDLw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,277,1716274800"; d="scan'208";a="62641786" Received: from lstrano-desk.jf.intel.com ([10.54.39.91]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2024 15:27:43 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: tj@kernel.org, jiangshanlai@gmail.com, christian.koenig@amd.com, ltuikov89@gmail.com, daniel@ffwll.ch Subject: [PATCH v3 5/5] drm/xe: Drop GuC submit_wq pool Date: Fri, 9 Aug 2024 15:28:27 -0700 Message-Id: <20240809222827.3211998-6-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240809222827.3211998-1-matthew.brost@intel.com> References: <20240809222827.3211998-1-matthew.brost@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that drm sched uses a single lockdep map for all submit_wq, drop the GuC submit_wq pool hack. Signed-off-by: Matthew Brost --- drivers/gpu/drm/xe/xe_guc_submit.c | 60 +----------------------------- drivers/gpu/drm/xe/xe_guc_types.h | 7 ---- 2 files changed, 1 insertion(+), 66 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc= _submit.c index 460808507947..882cef3a10dc 100644 --- a/drivers/gpu/drm/xe/xe_guc_submit.c +++ b/drivers/gpu/drm/xe/xe_guc_submit.c @@ -224,64 +224,11 @@ static bool exec_queue_killed_or_banned_or_wedged(str= uct xe_exec_queue *q) EXEC_QUEUE_STATE_BANNED)); } =20 -#ifdef CONFIG_PROVE_LOCKING -static int alloc_submit_wq(struct xe_guc *guc) -{ - int i; - - for (i =3D 0; i < NUM_SUBMIT_WQ; ++i) { - guc->submission_state.submit_wq_pool[i] =3D - alloc_ordered_workqueue("submit_wq", 0); - if (!guc->submission_state.submit_wq_pool[i]) - goto err_free; - } - - return 0; - -err_free: - while (i) - destroy_workqueue(guc->submission_state.submit_wq_pool[--i]); - - return -ENOMEM; -} - -static void free_submit_wq(struct xe_guc *guc) -{ - int i; - - for (i =3D 0; i < NUM_SUBMIT_WQ; ++i) - destroy_workqueue(guc->submission_state.submit_wq_pool[i]); -} - -static struct workqueue_struct *get_submit_wq(struct xe_guc *guc) -{ - int idx =3D guc->submission_state.submit_wq_idx++ % NUM_SUBMIT_WQ; - - return guc->submission_state.submit_wq_pool[idx]; -} -#else -static int alloc_submit_wq(struct xe_guc *guc) -{ - return 0; -} - -static void free_submit_wq(struct xe_guc *guc) -{ - -} - -static struct workqueue_struct *get_submit_wq(struct xe_guc *guc) -{ - return NULL; -} -#endif - static void guc_submit_fini(struct drm_device *drm, void *arg) { struct xe_guc *guc =3D arg; =20 xa_destroy(&guc->submission_state.exec_queue_lookup); - free_submit_wq(guc); } =20 static void guc_submit_wedged_fini(struct drm_device *drm, void *arg) @@ -337,10 +284,6 @@ int xe_guc_submit_init(struct xe_guc *guc, unsigned in= t num_ids) if (err) return err; =20 - err =3D alloc_submit_wq(guc); - if (err) - return err; - gt->exec_queue_ops =3D &guc_exec_queue_ops; =20 xa_init(&guc->submission_state.exec_queue_lookup); @@ -1445,8 +1388,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *= q) timeout =3D (q->vm && xe_vm_in_lr_mode(q->vm)) ? MAX_SCHEDULE_TIMEOUT : msecs_to_jiffies(q->sched_props.job_timeout_ms); err =3D xe_sched_init(&ge->sched, &drm_sched_ops, &xe_sched_ops, - get_submit_wq(guc), - q->lrc[0]->ring.size / MAX_JOB_SIZE_BYTES, 64, + NULL, q->lrc[0]->ring.size / MAX_JOB_SIZE_BYTES, 64, timeout, guc_to_gt(guc)->ordered_wq, NULL, q->name, gt_to_xe(q->gt)->drm.dev); if (err) diff --git a/drivers/gpu/drm/xe/xe_guc_types.h b/drivers/gpu/drm/xe/xe_guc_= types.h index 546ac6350a31..585f5c274f09 100644 --- a/drivers/gpu/drm/xe/xe_guc_types.h +++ b/drivers/gpu/drm/xe/xe_guc_types.h @@ -72,13 +72,6 @@ struct xe_guc { atomic_t stopped; /** @submission_state.lock: protects submission state */ struct mutex lock; -#ifdef CONFIG_PROVE_LOCKING -#define NUM_SUBMIT_WQ 256 - /** @submission_state.submit_wq_pool: submission ordered workqueues pool= */ - struct workqueue_struct *submit_wq_pool[NUM_SUBMIT_WQ]; - /** @submission_state.submit_wq_idx: submission ordered workqueue index = */ - int submit_wq_idx; -#endif /** @submission_state.enabled: submission is enabled */ bool enabled; } submission_state; --=20 2.34.1