public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function
@ 2026-04-15 14:49 Philipp Stanner
  2026-04-15 14:49 ` [PATCH v2 2/2] drm/nouveau: Fix double call to drm_sched_entity_fini() Philipp Stanner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Philipp Stanner @ 2026-04-15 14:49 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Matthew Brost,
	Philipp Stanner, Christian König, Dave Airlie,
	Tvrtko Ursulin
  Cc: dri-devel, nouveau, linux-kernel

Some drivers do not care on teardown whether the last jobs pending in an
entity are actually executed before teardown completed. For such
scenarios, drm_sched_entity_flush() is not the ideal function since it's
intended to wait for jobs to complete.

Make drm_sched_entity_kill() public for that use-case and update the
documentation.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
Changes in v2:
  - Improve wording, fix typo.
---
 drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++++--
 include/drm/gpu_scheduler.h              |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
index 61a4818cc87b..7be5811b90cd 100644
--- a/drivers/gpu/drm/scheduler/sched_entity.c
+++ b/drivers/gpu/drm/scheduler/sched_entity.c
@@ -267,8 +267,16 @@ static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f,
 	schedule_work(&job->work);
 }
 
-/* Remove the entity from the scheduler and kill all pending jobs */
-static void drm_sched_entity_kill(struct drm_sched_entity *entity)
+/**
+ * drm_sched_entity_kill - kill an entity's pending jobs and remove it
+ * @entity: the entity to remove
+ *
+ * Removes the entity from the scheduler's run queue and kills all pending jobs.
+ *
+ * This function should be used over drm_sched_entity_flush() if it is not
+ * desired to actually wait for all pending jobs to finish.
+ */
+void drm_sched_entity_kill(struct drm_sched_entity *entity)
 {
 	struct drm_sched_job *job;
 	struct dma_fence *prev;
@@ -306,6 +314,7 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)
 	}
 	dma_fence_put(prev);
 }
+EXPORT_SYMBOL(drm_sched_entity_kill);
 
 /**
  * drm_sched_entity_flush - Flush a context entity
diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
index 53417baebd49..d61c19e78182 100644
--- a/include/drm/gpu_scheduler.h
+++ b/include/drm/gpu_scheduler.h
@@ -693,6 +693,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,
 			  unsigned int num_sched_list,
 			  atomic_t *guilty);
 long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout);
+void drm_sched_entity_kill(struct drm_sched_entity *entity);
 void drm_sched_entity_fini(struct drm_sched_entity *entity);
 void drm_sched_entity_destroy(struct drm_sched_entity *entity);
 void drm_sched_entity_set_priority(struct drm_sched_entity *entity,
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] drm/nouveau: Fix double call to drm_sched_entity_fini()
  2026-04-15 14:49 [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Philipp Stanner
@ 2026-04-15 14:49 ` Philipp Stanner
  2026-04-16 20:12 ` [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Danilo Krummrich
  2026-04-17  4:35 ` Luben Tuikov
  2 siblings, 0 replies; 4+ messages in thread
From: Philipp Stanner @ 2026-04-15 14:49 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Matthew Brost,
	Philipp Stanner, Christian König, Dave Airlie,
	Tvrtko Ursulin
  Cc: dri-devel, nouveau, linux-kernel, stable

nouveau_abi16_chan_fini() does invoke drm_sched_entity_fini() twice:
Once directly, and a second time through nouveau_sched_destroy().

That's likely undesired behavior and might be a bug since
drm_sched_entity_fini() decrements reference counts.

Fix the issue by using the appropriate function,
drm_sched_entity_kill(), to kill all remaining jobs within the entity.

Cc: stable@kernel.vger.org
Fixes: 9a0c32d698c1 ("drm/nouveau: don't fini scheduler if not initialized")
Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
Changes in v2:
  - Fix commit message (wrong named function). (Guys on IRC, M Henning)
---
 drivers/gpu/drm/nouveau/nouveau_abi16.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c
index 7860877d909b..291203121f0c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_abi16.c
+++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c
@@ -176,7 +176,7 @@ nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16,
 
 	/* Cancel all jobs from the entity's queue. */
 	if (chan->sched)
-		drm_sched_entity_fini(&chan->sched->entity);
+		drm_sched_entity_kill(&chan->sched->entity);
 
 	if (chan->chan)
 		nouveau_channel_idle(chan->chan);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function
  2026-04-15 14:49 [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Philipp Stanner
  2026-04-15 14:49 ` [PATCH v2 2/2] drm/nouveau: Fix double call to drm_sched_entity_fini() Philipp Stanner
@ 2026-04-16 20:12 ` Danilo Krummrich
  2026-04-17  4:35 ` Luben Tuikov
  2 siblings, 0 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-04-16 20:12 UTC (permalink / raw)
  To: Philipp Stanner
  Cc: Lyude Paul, Danilo Krummrich, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Matthew Brost,
	Christian König, Dave Airlie, Tvrtko Ursulin, dri-devel,
	nouveau, linux-kernel

On Wed, 15 Apr 2026 16:49:56 +0200, Philipp Stanner wrote:
> [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function

Applied, thanks!

  Branch: drm-misc-next
  Tree:   https://gitlab.freedesktop.org/drm/misc/kernel.git

[1/2] drm/sched: Make drm_sched_entity_kill() a public function
      commit: 2f5f05633e22
[2/2] drm/nouveau: Fix double call to drm_sched_entity_fini()
      commit: cac96c8d93fa

The patches will appear in the next linux-next integration (typically within 24
hours on weekdays.)

The patches is queued up for the upcoming merge window for the next major kernel
release.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function
  2026-04-15 14:49 [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Philipp Stanner
  2026-04-15 14:49 ` [PATCH v2 2/2] drm/nouveau: Fix double call to drm_sched_entity_fini() Philipp Stanner
  2026-04-16 20:12 ` [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Danilo Krummrich
@ 2026-04-17  4:35 ` Luben Tuikov
  2 siblings, 0 replies; 4+ messages in thread
From: Luben Tuikov @ 2026-04-17  4:35 UTC (permalink / raw)
  To: Philipp Stanner, Lyude Paul, Danilo Krummrich, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Matthew Brost, Christian König, Dave Airlie, Tvrtko Ursulin
  Cc: dri-devel, nouveau, linux-kernel


[-- Attachment #1.1.1: Type: text/plain, Size: 2028 bytes --]

On 2026-04-15 10:49, Philipp Stanner wrote:
> Some drivers do not care on teardown whether the last jobs pending in an
> entity are actually executed before teardown completed. For such
> scenarios, drm_sched_entity_flush() is not the ideal function since it's
> intended to wait for jobs to complete.
> 
> Make drm_sched_entity_kill() public for that use-case and update the
> documentation.

This is a good patch and great suggestion by Danilo.

> 
> Suggested-by: Danilo Krummrich <dakr@kernel.org>
> Signed-off-by: Philipp Stanner <phasta@kernel.org>
> ---
> Changes in v2:
>   - Improve wording, fix typo.
> ---
>  drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++++--
>  include/drm/gpu_scheduler.h              |  1 +
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
> index 61a4818cc87b..7be5811b90cd 100644
> --- a/drivers/gpu/drm/scheduler/sched_entity.c
> +++ b/drivers/gpu/drm/scheduler/sched_entity.c
> @@ -267,8 +267,16 @@ static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f,
>  	schedule_work(&job->work);
>  }
>  
> -/* Remove the entity from the scheduler and kill all pending jobs */
> -static void drm_sched_entity_kill(struct drm_sched_entity *entity)
> +/**
> + * drm_sched_entity_kill - kill an entity's pending jobs and remove it
> + * @entity: the entity to remove
> + *
> + * Removes the entity from the scheduler's run queue and kills all pending jobs.
> + *
> + * This function should be used over drm_sched_entity_flush() if it is not
> + * desired to actually wait for all pending jobs to finish.
> + */

I felt that the email body above describing this patch was somewhat clearer. Perhaps something like:
(Notice the change "if" --> "when".)

"Use this function over drm_sched_entity_flush(), when the caller is not interested to wait
 for pending jobs to complete. This function kills any pending jobs."

-- 
Regards,
Luben

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 677 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-17  4:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-15 14:49 [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Philipp Stanner
2026-04-15 14:49 ` [PATCH v2 2/2] drm/nouveau: Fix double call to drm_sched_entity_fini() Philipp Stanner
2026-04-16 20:12 ` [PATCH v2 1/2] drm/sched: Make drm_sched_entity_kill() a public function Danilo Krummrich
2026-04-17  4:35 ` Luben Tuikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox