From nobody Sun Dec 14 19:28:16 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 78B6C26AA9B for ; Thu, 22 May 2025 08:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747902493; cv=none; b=a0xpjjprPfB69mGOA7inH9ZMHs3bXRT94C45D6e12odhLhkTbUnh/HmkT9RgAeXlE8rBZ/u3XZgT3BerSX1DJ1INmLfcg+FizGX+DBodtdD+CFXouZbxCDGbEE+QdblVXWOgFBbnremtlrmarcRm9Mwjuohh6G03hMLCdVRYd8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747902493; c=relaxed/simple; bh=rnC+iWAxQZV8/eK2peQIVBFSEZ98f6paoI2fDz9f89c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cbUr3nAnP1gMoyTcg1UBqPDQHXHx1kO4RMBcbjf+o+nk4kIshdSPuZAkrb010x/zONsLI8eDTA8ASv7XB1v22K61ZmS6gLTl+cO4ohPsOwBzjuLg5SM6cyILE2nxKLob3FwMsmqpwbj9O/skhZfGkdhtB1KzcEe5I5SwxKxD1c8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LlchIuSb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LlchIuSb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A58D2C4CEE4; Thu, 22 May 2025 08:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747902492; bh=rnC+iWAxQZV8/eK2peQIVBFSEZ98f6paoI2fDz9f89c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LlchIuSb/NZKPyb7dDLFNILVoWbpFPmX3gFZntv51aTAO9HiODmiZA8tQeS4S2bNm My6P4S++7Q+/cM/is10fs8/Z8qp0ES9k1mq0DwdhccoUUxis7a72EZU4VUhV9JV8t7 irpbVNH0ZyJCuRJJQkIvB785B8tua/2Xhk2JqgYZeOxBA15er8+2DsODxo2Dwt6c2V E0+090oBJIvL79SvMei5u7lHKKU2l5e+k6+Hi2xUBr2f/F6VVvuDPRwwTHt4YTOoLr igpPXG6k+nrwsF5zKuSw4bVsslJlrYplENEXBJ90hmcNoYhPI5G7VFKtXYQ0+yn8xe NBl9FnnqqyQIQ== From: Philipp Stanner To: Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , Matthew Brost , Philipp Stanner , =?UTF-8?q?Christian=20K=C3=B6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Tvrtko Ursulin Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/5] drm/nouveau: Add new callback for scheduler teardown Date: Thu, 22 May 2025 10:27:42 +0200 Message-ID: <20250522082742.148191-6-phasta@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250522082742.148191-2-phasta@kernel.org> References: <20250522082742.148191-2-phasta@kernel.org> 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" There is a new callback for always tearing the scheduler down in a leak-free, deadlock-free manner. Port Nouveau as its first user by providing the scheduler with a callback that ensures the fence context gets killed in drm_sched_fini(). Signed-off-by: Philipp Stanner --- drivers/gpu/drm/nouveau/nouveau_abi16.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_drm.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.c | 19 +++++++++++++++++-- drivers/gpu/drm/nouveau/nouveau_sched.h | 3 +++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouv= eau/nouveau_abi16.c index 2a0617e5fe2a..53b8a85a8adb 100644 --- a/drivers/gpu/drm/nouveau/nouveau_abi16.c +++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c @@ -415,8 +415,8 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) * The client lock is already acquired by nouveau_abi16_get(). */ if (nouveau_cli_uvmm(cli)) { - ret =3D nouveau_sched_create(&chan->sched, drm, drm->sched_wq, - chan->chan->dma.ib_max); + ret =3D nouveau_sched_create(&chan->sched, drm, chan->chan, + drm->sched_wq, chan->chan->dma.ib_max); if (ret) goto done; } diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouvea= u/nouveau_drm.c index c69139701056..2a2b319dca5f 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -313,7 +313,7 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *s= name, * locks which indirectly or directly are held for allocations * elsewhere. */ - ret =3D nouveau_sched_create(&cli->sched, drm, NULL, 1); + ret =3D nouveau_sched_create(&cli->sched, drm, NULL, NULL, 1); if (ret) goto done; =20 diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.c b/drivers/gpu/drm/nouv= eau/nouveau_sched.c index d326e55d2d24..de14883ee4c8 100644 --- a/drivers/gpu/drm/nouveau/nouveau_sched.c +++ b/drivers/gpu/drm/nouveau/nouveau_sched.c @@ -11,6 +11,7 @@ #include "nouveau_exec.h" #include "nouveau_abi16.h" #include "nouveau_sched.h" +#include "nouveau_chan.h" =20 #define NOUVEAU_SCHED_JOB_TIMEOUT_MS 10000 =20 @@ -392,10 +393,22 @@ nouveau_sched_free_job(struct drm_sched_job *sched_jo= b) nouveau_job_fini(job); } =20 +static void +nouveau_sched_fence_context_kill(struct drm_gpu_scheduler *sched) +{ + struct nouveau_sched *nsched; + + nsched =3D container_of(sched, struct nouveau_sched, base); + + if (nsched->chan) + nouveau_channel_kill(nsched->chan); +} + static const struct drm_sched_backend_ops nouveau_sched_ops =3D { .run_job =3D nouveau_sched_run_job, .timedout_job =3D nouveau_sched_timedout_job, .free_job =3D nouveau_sched_free_job, + .cancel_pending_fences =3D nouveau_sched_fence_context_kill, }; =20 static int @@ -461,7 +474,8 @@ nouveau_sched_init(struct nouveau_sched *sched, struct = nouveau_drm *drm, =20 int nouveau_sched_create(struct nouveau_sched **psched, struct nouveau_drm *dr= m, - struct workqueue_struct *wq, u32 credit_limit) + struct nouveau_channel *chan, struct workqueue_struct *wq, + u32 credit_limit) { struct nouveau_sched *sched; int ret; @@ -470,6 +484,8 @@ nouveau_sched_create(struct nouveau_sched **psched, str= uct nouveau_drm *drm, if (!sched) return -ENOMEM; =20 + sched->chan =3D chan; + ret =3D nouveau_sched_init(sched, drm, wq, credit_limit); if (ret) { kfree(sched); @@ -481,7 +497,6 @@ nouveau_sched_create(struct nouveau_sched **psched, str= uct nouveau_drm *drm, return 0; } =20 - static void nouveau_sched_fini(struct nouveau_sched *sched) { diff --git a/drivers/gpu/drm/nouveau/nouveau_sched.h b/drivers/gpu/drm/nouv= eau/nouveau_sched.h index 20cd1da8db73..e6e2016a3569 100644 --- a/drivers/gpu/drm/nouveau/nouveau_sched.h +++ b/drivers/gpu/drm/nouveau/nouveau_sched.h @@ -9,6 +9,7 @@ #include =20 #include "nouveau_drv.h" +#include "nouveau_chan.h" =20 #define to_nouveau_job(sched_job) \ container_of((sched_job), struct nouveau_job, base) @@ -101,6 +102,7 @@ struct nouveau_sched { struct drm_sched_entity entity; struct workqueue_struct *wq; struct mutex mutex; + struct nouveau_channel *chan; =20 struct { struct { @@ -112,6 +114,7 @@ struct nouveau_sched { }; =20 int nouveau_sched_create(struct nouveau_sched **psched, struct nouveau_drm= *drm, + struct nouveau_channel *chan, struct workqueue_struct *wq, u32 credit_limit); void nouveau_sched_destroy(struct nouveau_sched **psched); =20 --=20 2.49.0