drm/xe: Take memory ref on kernel job creation
authorMatthew Brost <matthew.brost@intel.com>
Thu, 12 Jan 2023 22:25:14 +0000 (17:25 -0500)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 12 Dec 2023 19:06:00 +0000 (14:06 -0500)
When a job is inflight we may access memory to read the hardware seqno.
All user jobs have VM open which has a ref but kernel jobs do not
require VM so it is possible to not have memory ref. To avoid this, take
a memory ref on kernel job creation.

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_sched_job.c

index ab81bfe17e8a4f1e86c67dd19d64379c4ec6653f..d9add0370a9848fcc826358d9157adb712e55d7c 100644 (file)
@@ -8,7 +8,7 @@
 #include <linux/dma-fence-array.h>
 #include <linux/slab.h>
 
-#include "xe_device_types.h"
+#include "xe_device.h"
 #include "xe_engine.h"
 #include "xe_gt.h"
 #include "xe_hw_engine_types.h"
@@ -72,6 +72,11 @@ static void job_free(struct xe_sched_job *job)
                        xe_sched_job_parallel_slab : xe_sched_job_slab, job);
 }
 
+static struct xe_device *job_to_xe(struct xe_sched_job *job)
+{
+       return gt_to_xe(job->engine->gt);
+}
+
 struct xe_sched_job *xe_sched_job_create(struct xe_engine *e,
                                         u64 *batch_addr)
 {
@@ -149,6 +154,11 @@ struct xe_sched_job *xe_sched_job_create(struct xe_engine *e,
        for (i = 0; i < width; ++i)
                job->batch_addr[i] = batch_addr[i];
 
+       /* All other jobs require a VM to be open which has a ref */
+       if (unlikely(e->flags & ENGINE_FLAG_KERNEL))
+               xe_device_mem_access_get(job_to_xe(job));
+       xe_device_assert_mem_access(job_to_xe(job));
+
        trace_xe_sched_job_create(job);
        return job;
 
@@ -178,6 +188,8 @@ void xe_sched_job_destroy(struct kref *ref)
        struct xe_sched_job *job =
                container_of(ref, struct xe_sched_job, refcount);
 
+       if (unlikely(job->engine->flags & ENGINE_FLAG_KERNEL))
+               xe_device_mem_access_put(job_to_xe(job));
        xe_engine_put(job->engine);
        dma_fence_put(job->fence);
        drm_sched_job_cleanup(&job->drm);