Skip to contentSkip to conversation

drm/sched: revert "drm_sched_job_cleanup(): correct false doc"

PATCH In review Christian König 4 participants 9 messages Mar 10, 2025

Subsystems (3)
lore
Share & tools
lore

Christian König

author reviewer
#0 lore raw

PATCH 1/1 drm/sched: revert "drm_sched_job_cleanup(): correct false doc"

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

Sorry for the delayed response, I only stumbled over this now while going over old mails and then re-thinking my reviewed by for this change.

The function drm_sched_job_arm() is indeed the point of no return. The background is that it is nearly impossible for the driver to correctly retract the fence and signal it in the order enforced by the dma_fence framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

The correct approach for error handling in this situation is to set the error on the fences and then push to the entity anyway. We can certainly improve the documentation, but removing the warning is clearly not a good idea.

---
 drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +5 -7
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
  * Cleans up the resources allocated with drm_sched_job_init().
  *
  * Drivers should call this from their error unwind code if @job is aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job)
 {
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job *job)
 		/* drm_sched_job_arm() has been called */
 		dma_fence_put(&job->s_fence->finished);
 	} else {
-		/* aborted job before arming */
+		/* aborted job before committing to run it */
 		drm_sched_fence_free(job->s_fence);
 	}
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Christian König

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

The function drm_sched_job_arm() is indeed the point of no return.

So would you say that the comment in the function's body, "drm_sched_job_arm() has been called" actually means / should mean "job had been submitted with drm_sched_entity_push_job()"?

Quoted 7 lines

The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

Quoted 8 lines

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway.

You expect the driver to set an error on scheduled and finished fence? I think this would be very likely to explode. AFAICS the scheduler code has no awareness for anyone else having touched those fences.

If at all, if this is really a problem, we should tell the driver that it must enforce that there will be no failure between drm_sched_job_arm() and drm_sched_job_entity_push_job(). That's how Nouveau does it.

Let's set our understanding straight before reverting. What drm_sched_job_arm() does is:

1. Pick scheduler, rq and priority for the job
2. Atomically increment the job_id_count and assign to job
3. Call drm_sched_fence_init() and therefore:
4. Set the fence's scheduler
5. Set the fences seq nr atomically
6. Initialize scheduled and finished fence

What of the above precisely is the problem?

You say the driver cannot "correctly retract the fence and signal it in the order enforced by the dma_fence framework". You mean that the finished_fences have to be signalled in an order only the scheduler knows? I assume you're referring to set dependencies?

P.

Quoted 50 lines

We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

---
 drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------

 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
   * Cleans up the resources allocated with drm_sched_job_init().
   *
   * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job)
 {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
   /* drm_sched_job_arm() has been called */
   dma_fence_put(&job->s_fence->finished);
   } else {
- /* aborted job before arming */
+ /* aborted job before committing to run it */
   drm_sched_fence_free(job->s_fence);
   }

#2 lore raw
Quoted 29 lines · Philipp Stanner
Quoted 7 lines · Christian König

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

The function drm_sched_job_arm() is indeed the point of no return.

So would you say that the comment in the function's body, "drm_sched_job_arm() has been called" actually means / should mean "job had been submitted with drm_sched_entity_push_job()"?

Quoted 7 lines

The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

Quoted 8 lines

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway.

Quoted 8 lines

You expect the driver to set an error on scheduled and finished fence? I think this would be very likely to explode. AFAICS the scheduler code has no awareness for anyone else having touched those fences.

If at all, if this is really a problem, we should tell the driver that it must enforce that there will be no failure between drm_sched_job_arm() and drm_sched_job_entity_push_job(). That's how Nouveau does it.

On top of Philipp's questions - I just want to raise that amdgpu_cs_submit then also needs explaining. I always take amdgpu as kind of almost reference, since that is where scheduler originated from. And in there there is definitely the path of drm_sched_job_cleanup() called after drm_sched_job_arm() when adding gang dependencies fails.

Regards,

Tvrtko

Quoted 71 lines

Let's set our understanding straight before reverting. What drm_sched_job_arm() does is:

1. Pick scheduler, rq and priority for the job
2. Atomically increment the job_id_count and assign to job
3. Call drm_sched_fence_init() and therefore:
4. Set the fence's scheduler
5. Set the fences seq nr atomically
6. Initialize scheduled and finished fence

What of the above precisely is the problem?

You say the driver cannot "correctly retract the fence and signal it in the order enforced by the dma_fence framework". You mean that the finished_fences have to be signalled in an order only the scheduler knows? I assume you're referring to set dependencies?

P.

Quoted 50 lines

We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

---
  drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
   * Cleans up the resources allocated with drm_sched_job_init().
   *
   * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job)
 {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
   /* drm_sched_job_arm() has been called */
   dma_fence_put(&job->s_fence->finished);
   } else {
- /* aborted job before arming */
+ /* aborted job before committing to run it */
   drm_sched_fence_free(job->s_fence);
   }
author reviewer
#3 lore raw

Am 10.03.25 um 10:30 schrieb Tvrtko Ursulin:

Quoted 9 lines · Philipp Stanner
Quoted 7 lines · Christian König
Quoted 6 lines

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

The function drm_sched_job_arm() is indeed the point of no return.

So would you say that the comment in the function's body, "drm_sched_job_arm() has been called" actually means / should mean "job had been submitted with drm_sched_entity_push_job()"?

Yes, probably. The problem is simply that we need to guarantee correct order of signaling for the dma_fence.

Otherwise functions like dma_fence_is_later()/dma_fence_later() start to blow up and we run into potential use after free problems.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway.

You expect the driver to set an error on scheduled and finished fence?

Ideally we would avoid that as well. In general drivers should be coded so that after calling drm_sched_job_arm() nothing can go wrong any more.

Setting an error on either the scheduler or the finished fence is basically just the last resort if we can't really avoid any error handling.

Quoted 2 lines
Quoted 2 lines

I think this would be very likely to explode. AFAICS the scheduler code has no awareness for anyone else having touched those fences.

Yeah that is probably not well handled today.

Quoted 7 lines
Quoted 5 lines

If at all, if this is really a problem, we should tell the driver that it must enforce that there will be no failure between drm_sched_job_arm() and drm_sched_job_entity_push_job(). That's how Nouveau does it.

On top of Philipp's questions - I just want to raise that amdgpu_cs_submit then also needs explaining. I always take amdgpu as kind of almost reference, since that is where scheduler originated from. And in there there is definitely the path of drm_sched_job_cleanup() called after drm_sched_job_arm() when adding gang dependencies fails.

Oh shit, yeah that doesn't work correctly at all. The user pages handling is completely broken as well.

Thanks for pointing that out.

Regards,
Christian.

Quoted 77 lines

Regards,

Tvrtko

Quoted 71 lines

Let's set our understanding straight before reverting. What drm_sched_job_arm() does is:

    1. Pick scheduler, rq and priority for the job
    2. Atomically increment the job_id_count and assign to job
    3. Call drm_sched_fence_init() and therefore:
    4. Set the fence's scheduler
    5. Set the fences seq nr atomically
    6. Initialize scheduled and finished fence

What of the above precisely is the problem?

You say the driver cannot "correctly retract the fence and signal it in the order enforced by the dma_fence framework". You mean that the finished_fences have to be signalled in an order only the scheduler knows? I assume you're referring to set dependencies?

P.

Quoted 50 lines

We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

---
  drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------

  1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
    * Cleans up the resources allocated with drm_sched_job_init().
    *
    * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
   *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
   */
  void drm_sched_job_cleanup(struct drm_sched_job *job)
  {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
    /* drm_sched_job_arm() has been called */
    dma_fence_put(&job->s_fence->finished);
    } else {
- /* aborted job before arming */
+ /* aborted job before committing to run it */
    drm_sched_fence_free(job->s_fence);
    }

#4 lore raw
In reply to Christian König
Quoted 1 line · Christian König

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

OK, your arguments with fence ordering are strong. Please update the commit message according to our discussion:

Quoted 4 lines

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

Your RB hadn't even been applied (I merged before you gave it), so you can remove this first paragraph from the commit message

Quoted 14 lines

The function drm_sched_job_arm() is indeed the point of no return. The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

Quoted 7 lines

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway. We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

This last paragraph, as per our discussion, seems invalid. We shouldn't have that in the commit log, so that it won't give later hackers browsing it wrong ideas and we end up with someone actually mengling with those fences.

Thx
P.

Quoted 46 lines

---
 drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------

 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
   * Cleans up the resources allocated with drm_sched_job_init().
   *
   * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job)
 {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
  		/* drm_sched_job_arm() has been called */
  		dma_fence_put(&job->s_fence->finished);
  	} else {
-		/* aborted job before arming */
+		/* aborted job before committing to run it */
  		drm_sched_fence_free(job->s_fence);
  	}

#5 lore raw

Am 10.03.25 um 13:11 schrieb Philipp Stanner:

Quoted 31 lines · Christian König
Quoted 1 line

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

OK, your arguments with fence ordering are strong. Please update the commit message according to our discussion:

Quoted 3 lines

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

Your RB hadn't even been applied (I merged before you gave it), so you can remove this first paragraph from the commit message

Quoted 13 lines

The function drm_sched_job_arm() is indeed the point of no return. The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

Quoted 7 lines

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway. We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

Quoted 4 lines

This last paragraph, as per our discussion, seems invalid. We shouldn't have that in the commit log, so that it won't give later hackers browsing it wrong ideas and we end up with someone actually mengling with those fences.

Sure, going to make those updates. I just wanted to give people a possible direction to look into when they really run into a situation where they need to abort some submission very late.

Should I also clarify the comment in drm_sched_job_cleanup()?

Regards,
Christian.

Quoted 49 lines

Thx
P.

Quoted 45 lines

---
 drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------

 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
   * Cleans up the resources allocated with drm_sched_job_init().
   *
   * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job)
 {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
  		/* drm_sched_job_arm() has been called */
  		dma_fence_put(&job->s_fence->finished);
  	} else {
-		/* aborted job before arming */
+		/* aborted job before committing to run it */
  		drm_sched_fence_free(job->s_fence);
  	}

#6 lore raw
Quoted 47 lines · Christian König

Am 10.03.25 um 13:11 schrieb Philipp Stanner:

Quoted 39 lines · Christian König
Quoted 1 line

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

OK, your arguments with fence ordering are strong. Please update the
commit message according to our discussion:

Quoted 5 lines

Sorry for the delayed response, I only stumbled over this now while
going
over old mails and then re-thinking my reviewed by for this change.

Your RB hadn't even been applied (I merged before you gave it), so you
can remove this first paragraph from the commit message

Quoted 15 lines

The function drm_sched_job_arm() is indeed the point of no return.
The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the
scheduler.

Quoted 9 lines

The correct approach for error handling in this situation is to set
the
error on the fences and then push to the entity anyway. We can certainly
improve the documentation, but removing the warning is clearly not a
good
idea.

Quoted 6 lines

This last paragraph, as per our discussion, seems invalid. We shouldn't
have that in the commit log, so that it won't give later hackers browsing it wrong ideas and we end up with someone actually mengling
with those fences.

Quoted 5 lines

Sure, going to make those updates. I just wanted to give people a possible direction to look into when they really run into a situation where they need to abort some submission very late.

Should I also clarify the comment in drm_sched_job_cleanup()?

Shouldn't be done in a revert-commit I think.

I'd say we revert for now (it's not a big loss, just a bit of docu) and then you (or maybe I) submit a new patch where we discuss Tvrtko's questions and then write down the rules and issues precisely in both commit message and the function's comments.

P.

Quoted 60 lines

Regards,
Christian.

Quoted 55 lines

Thx
P.

Quoted 51 lines

---
 drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------

 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@
 EXPORT_SYMBOL(drm_sched_job_has_dependency);
   * Cleans up the resources allocated with drm_sched_job_init().
   *
   * Drivers should call this from their error unwind code if @job

is
aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be
initialized,
- * it is up to the driver to ensure that fences that were exposed to
external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by
the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job) {

drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct

drm_sched_job
*job)
  /* drm_sched_job_arm() has been called */ dma_fence_put(&job->s_fence->finished); } else {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
-		/* aborted job before arming */
+		/* aborted job before committing to run it */

  drm_sched_fence_free(job->s_fence); }

#7 lore raw
In reply to Philipp Stanner
Quoted 5 lines · Philipp Stanner
Quoted 1 line · Christian König

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

OK, your arguments with fence ordering are strong. Please update the commit message according to our discussion:

Could that argument please be explained in more concrete terms?

Are we talking here about skipping one seqno has potential to cause a problem, or there is more to it?

Because if it is just skipping I don't immediately see that breaks the monotonic/unique seqno ordering.

Only if we are worried about some code somewhere making assumptions "if N got completed, that means N-1 got completed too". That generally isn't anything new and can happen with GPU resets, albeit in the latter case the fence error is I think always set.

Regards,

Tvrtko

Quoted 84 lines
Quoted 3 lines

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

Your RB hadn't even been applied (I merged before you gave it), so you can remove this first paragraph from the commit message

Quoted 14 lines

The function drm_sched_job_arm() is indeed the point of no return. The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

Quoted 7 lines

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway. We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

This last paragraph, as per our discussion, seems invalid. We shouldn't have that in the commit log, so that it won't give later hackers browsing it wrong ideas and we end up with someone actually mengling with those fences.

Thx
P.

Quoted 46 lines
---
  drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
   * Cleans up the resources allocated with drm_sched_job_init().
   *
   * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
  *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
  */
 void drm_sched_job_cleanup(struct drm_sched_job *job)
 {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
  		/* drm_sched_job_arm() has been called */
  		dma_fence_put(&job->s_fence->finished);
  	} else {
-		/* aborted job before arming */
+		/* aborted job before committing to run it */
  		drm_sched_fence_free(job->s_fence);
  	}
#8 lore raw

Am 10.03.25 um 13:27 schrieb Tvrtko Ursulin:

Quoted 8 lines · Philipp Stanner
Quoted 5 lines · Christian König
Quoted 1 line

This reverts commit 44d2f310f008613c1dbe5e234c2cf2be90cbbfab.

OK, your arguments with fence ordering are strong. Please update the commit message according to our discussion:

Quoted 7 lines

Could that argument please be explained in more concrete terms?

Are we talking here about skipping one seqno has potential to cause a problem, or there is more to it?

Because if it is just skipping I don't immediately see that breaks the monotonic/unique seqno ordering.

Only if we are worried about some code somewhere making assumptions  "if N got completed, that means N-1 got completed too". That generally isn't anything new and can happen with GPU resets, albeit in the latter case the fence error is I think always set.

Exactly that is highly problematic.

In a case of a reset and all pending work canceled it doesn't matter if fences are signaled A,B,C or C,B,A.

But when you can make fence C signal while A is still running it can be that we start to cleanup the VM and free memory etc.. while the shaders from A are still able to access resources.

That's a security hole you can push an elephant through. Virtual memory on GPUs mitigates that on modern hardware quite a bit, but we still have a bunch of use cases which rely on getting this right.

Regards,
Christian.

Quoted 90 lines

Regards,

Tvrtko

Quoted 84 lines
Quoted 3 lines

Sorry for the delayed response, I only stumbled over this now while going
over old mails and then re-thinking my reviewed by for this change.

Your RB hadn't even been applied (I merged before you gave it), so you can remove this first paragraph from the commit message

Quoted 14 lines

The function drm_sched_job_arm() is indeed the point of no return. The
background is that it is nearly impossible for the driver to correctly
retract the fence and signal it in the order enforced by the dma_fence
framework.

The code in drm_sched_job_cleanup() is for the purpose to cleanup after
the job was armed through drm_sched_job_arm() *and* processed by the scheduler.

Quoted 7 lines

The correct approach for error handling in this situation is to set the
error on the fences and then push to the entity anyway. We can certainly
improve the documentation, but removing the warning is clearly not a good
idea.

This last paragraph, as per our discussion, seems invalid. We shouldn't have that in the commit log, so that it won't give later hackers browsing it wrong ideas and we end up with someone actually mengling with those fences.

Thx
P.

Quoted 46 lines

---
  drivers/gpu/drm/scheduler/sched_main.c | 12 +++++-------

  1 file changed, 5 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index 53e6aec37b46..4d4219fbe49d 100644
@@ -1015,13 +1015,11 @@ EXPORT_SYMBOL(drm_sched_job_has_dependency);
    * Cleans up the resources allocated with drm_sched_job_init().
    *
    * Drivers should call this from their error unwind code if @job is

aborted
- * before it was submitted to an entity with drm_sched_entity_push_job().
+ * before drm_sched_job_arm() is called.
   *
- * Since calling drm_sched_job_arm() causes the job's fences to be initialized,
- * it is up to the driver to ensure that fences that were exposed to external
- * parties get signaled. drm_sched_job_cleanup() does not ensure this.
- *
- * This function must also be called in &struct drm_sched_backend_ops.free_job
+ * After that point of no return @job is committed to be executed by the
+ * scheduler, and this function should be called from the
+ * &drm_sched_backend_ops.free_job callback.
   */
  void drm_sched_job_cleanup(struct drm_sched_job *job)
  {

drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -1032,7 +1030,7 @@ void drm_sched_job_cleanup(struct drm_sched_job
 *job)
           /* drm_sched_job_arm() has been called */
           dma_fence_put(&job->s_fence->finished);
       } else {
-        /* aborted job before arming */
+        /* aborted job before committing to run it */
           drm_sched_fence_free(job->s_fence);
       }