[RFC PATCH 3/3] drm/sched: Prevent adding dependencies to an armed job

Matthew Brost posted 3 patches 18 hours ago
[RFC PATCH 3/3] drm/sched: Prevent adding dependencies to an armed job
Posted by Matthew Brost 18 hours ago
According to the DMA scheduler documentation, once a job is armed, it
must be pushed. Drivers should avoid calling the failing code path that
attempts to add dependencies after a job has been armed. This change
enforces that rule.

Cc: Christian König <christian.koenig@amd.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Philipp Stanner <phasta@kernel.org>
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/scheduler/sched_main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
index 676484dd3ea3..436cb2844161 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -873,7 +873,8 @@ EXPORT_SYMBOL(drm_sched_job_arm);
  * @job: scheduler job to add the dependencies to
  * @fence: the dma_fence to add to the list of dependencies.
  *
- * Note that @fence is consumed in both the success and error cases.
+ * Note that @fence is consumed in both the success and error cases. This
+ * function cannot be called if the job is armed.
  *
  * Returns:
  * 0 on success, or an error on failing to expand the array.
@@ -886,6 +887,10 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
 	u32 id = 0;
 	int ret;
 
+	/* Do not allow additional dependencies when job is armed */
+	if (WARN_ON_ONCE(job->sched))
+		return -EINVAL;
+
 	if (!fence)
 		return 0;
 
-- 
2.34.1