Skip to content

Commit 5f46f5c

Browse files
author
Philipp Stanner
committed
drm/nouveau: Add new callback for scheduler teardown
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(). Acked-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Philipp Stanner <phasta@kernel.org> Link: https://lore.kernel.org/r/20250710125412.128476-9-phasta@kernel.org
1 parent 89b2675 commit 5f46f5c

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

drivers/gpu/drm/nouveau/nouveau_fence.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,21 @@ nouveau_fence_emit(struct nouveau_fence *fence)
240240
return ret;
241241
}
242242

243+
void
244+
nouveau_fence_cancel(struct nouveau_fence *fence)
245+
{
246+
struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
247+
unsigned long flags;
248+
249+
spin_lock_irqsave(&fctx->lock, flags);
250+
if (!dma_fence_is_signaled_locked(&fence->base)) {
251+
dma_fence_set_error(&fence->base, -ECANCELED);
252+
if (nouveau_fence_signal(fence))
253+
nvif_event_block(&fctx->event);
254+
}
255+
spin_unlock_irqrestore(&fctx->lock, flags);
256+
}
257+
243258
bool
244259
nouveau_fence_done(struct nouveau_fence *fence)
245260
{

drivers/gpu/drm/nouveau/nouveau_fence.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void nouveau_fence_unref(struct nouveau_fence **);
2929

3030
int nouveau_fence_emit(struct nouveau_fence *);
3131
bool nouveau_fence_done(struct nouveau_fence *);
32+
void nouveau_fence_cancel(struct nouveau_fence *fence);
3233
int nouveau_fence_wait(struct nouveau_fence *, bool lazy, bool intr);
3334
int nouveau_fence_sync(struct nouveau_bo *, struct nouveau_channel *, bool exclusive, bool intr);
3435

drivers/gpu/drm/nouveau/nouveau_sched.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "nouveau_exec.h"
1212
#include "nouveau_abi16.h"
1313
#include "nouveau_sched.h"
14+
#include "nouveau_chan.h"
1415

1516
#define NOUVEAU_SCHED_JOB_TIMEOUT_MS 10000
1617

@@ -393,10 +394,23 @@ nouveau_sched_free_job(struct drm_sched_job *sched_job)
393394
nouveau_job_fini(job);
394395
}
395396

397+
static void
398+
nouveau_sched_cancel_job(struct drm_sched_job *sched_job)
399+
{
400+
struct nouveau_fence *fence;
401+
struct nouveau_job *job;
402+
403+
job = to_nouveau_job(sched_job);
404+
fence = to_nouveau_fence(job->done_fence);
405+
406+
nouveau_fence_cancel(fence);
407+
}
408+
396409
static const struct drm_sched_backend_ops nouveau_sched_ops = {
397410
.run_job = nouveau_sched_run_job,
398411
.timedout_job = nouveau_sched_timedout_job,
399412
.free_job = nouveau_sched_free_job,
413+
.cancel_job = nouveau_sched_cancel_job,
400414
};
401415

402416
static int
@@ -482,7 +496,6 @@ nouveau_sched_create(struct nouveau_sched **psched, struct nouveau_drm *drm,
482496
return 0;
483497
}
484498

485-
486499
static void
487500
nouveau_sched_fini(struct nouveau_sched *sched)
488501
{

0 commit comments

Comments
 (0)