Skip to contentSkip to conversation

drm/amdgpu: put ctx's ref count in amdgpu_ctx_mgr_entity_fini()

PATCH In review Lin.Cao 4 participants 5 messages Jun 24, 2025 – Jun 25, 2025

Subsystems (2)
lore
Share & tools
lore

Lin.Cao

author
#0 lore raw

PATCH 1/1 drm/amdgpu: put ctx's ref count in amdgpu_ctx_mgr_entity_fini()

patch "daf823f1d0cd drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
index 85567d0d9545..f5d5c45ddc0d 100644
@@ -944,6 +944,7 @@ static void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
 				drm_sched_entity_fini(entity);
 			}
 		}
+		kref_put(&ctx->refcount, amdgpu_ctx_fini);
 	}
 }
 
Signature · 1 line
2.46.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Lin.Cao

patch "daf823f1d0cd drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

Ouch I removed the wrong one. :( Probably misread kref_put as kref_read..

But is the SHA correct? I see it is dd64956685fa.

Which would mean adding:

Fixes dd64956685fa ("drm/amdgpu: Remove duplicated "context still alive" check")

Regards,

Tvrtko

Quoted 17 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
index 85567d0d9545..f5d5c45ddc0d 100644
@@ -944,6 +944,7 @@ static void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
  				drm_sched_entity_fini(entity);
  			}
  		}
+		kref_put(&ctx->refcount, amdgpu_ctx_fini);
  	}
  }
 
maintainer Acked-by
#2 lore raw
Quoted 10 lines · Tvrtko Ursulin
Quoted 4 lines · Lin.Cao

patch "daf823f1d0cd drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

Ouch I removed the wrong one. :( Probably misread kref_put as kref_read..

Quoted 2 lines

But is the SHA correct? I see it is dd64956685fa.

That could be because our internal branch is not yet rebased.

Quoted 4 lines

Which would mean adding:

Fixes dd64956685fa ("drm/amdgpu: Remove duplicated "context still alive" check")

And maybe CC stable? Or in which release is that patch upstream?

Regards,
Christian.

Quoted 23 lines

Regards,

Tvrtko

Quoted 17 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 1 +

  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
index 85567d0d9545..f5d5c45ddc0d 100644
@@ -944,6 +944,7 @@ static void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
                   drm_sched_entity_fini(entity);
               }
           }
+        kref_put(&ctx->refcount, amdgpu_ctx_fini);
       }
   }

Reviewed-by Tvrtko Ursulin Acked-by Christian König Acked-by Christian König
#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Ursulin, Christian,

I find the upstream patch: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=dd64956685fa48358c4152d952070c8c073e5f89

May I ask if I can modify the commit msg as:

drm/amdgpu: Fix memory leak in amdgpu_ctx_mgr_entity_fini

patch "dd64956685fa drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

Fixes dd64956685fa ("drm/amdgpu: Remove duplicated "context still alive" check")

Thanks,
Lin
________________________________
From: Koenig, Christian <[email protected]>
Sent: Tuesday, June 24, 2025 21:11
To: Tvrtko Ursulin <[email protected]>; cao, lin <[email protected]>; [email protected] <[email protected]>
Cc: Chang, HaiJun <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: put ctx's ref count in amdgpu_ctx_mgr_entity_fini()

Quoted 10 lines · Tvrtko Ursulin
Quoted 4 lines · Lin.Cao

patch "daf823f1d0cd drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

Ouch I removed the wrong one. :( Probably misread kref_put as kref_read..

Quoted 2 lines

But is the SHA correct? I see it is dd64956685fa.

That could be because our internal branch is not yet rebased.

Quoted 4 lines

Which would mean adding:

Fixes dd64956685fa ("drm/amdgpu: Remove duplicated "context still alive" check")

And maybe CC stable? Or in which release is that patch upstream?

Regards,
Christian.

Quoted 23 lines

Regards,

Tvrtko

Quoted 17 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
index 85567d0d9545..f5d5c45ddc0d 100644
@@ -944,6 +944,7 @@ static void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
                  drm_sched_entity_fini(entity);
              }
          }
+        kref_put(&ctx->refcount, amdgpu_ctx_fini);
      }
  }
 
#4 lore raw
Quoted 16 lines · lin

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Ursulin, Christian,

I find the upstream patch: https://git.kernel.org/pub/scm/linux/kernel/ git/torvalds/linux.git/commit/? id=dd64956685fa48358c4152d952070c8c073e5f89 <https://git.kernel.org/pub/ scm/linux/kernel/git/torvalds/linux.git/commit/? id=dd64956685fa48358c4152d952070c8c073e5f89>

May I ask if I can modify the commit msg as:

drm/amdgpu: Fix memory leak in amdgpu_ctx_mgr_entity_fini

patch "dd64956685fa drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

Quoted 4 lines
Fixes dd64956685fa ("drm/amdgpu: Remove duplicated "context still alive" check")

Looks good to me.

Regards,

Tvrtko

Quoted 59 lines

------------------------------------------------------------------------
*From:* Koenig, Christian <[email protected]>
*Sent:* Tuesday, June 24, 2025 21:11
*To:* Tvrtko Ursulin <[email protected]>; cao, lin <[email protected]>; [email protected] <[email protected]> *Cc:* Chang, HaiJun <[email protected]>
*Subject:* Re: [PATCH] drm/amdgpu: put ctx's ref count in amdgpu_ctx_mgr_entity_fini()

Quoted 10 lines · Tvrtko Ursulin
Quoted 4 lines · Lin.Cao

patch "daf823f1d0cd drm/amdgpu: Remove duplicated "context still alive" check" removed ctx put, which will cause amdgpu_ctx_fini() cannot be called and then cause some finished fence that added by amdgpu_ctx_add_fence() cannot be released and cause memleak.

Ouch I removed the wrong one. :( Probably misread kref_put as kref_read..

Quoted 2 lines

But is the SHA correct? I see it is dd64956685fa.

That could be because our internal branch is not yet rebased.

Quoted 4 lines

Which would mean adding:

Fixes dd64956685fa ("drm/amdgpu: Remove duplicated "context still alive" check")

And maybe CC stable? Or in which release is that patch upstream?

Regards,
Christian.

Quoted 23 lines

Regards,

Tvrtko

Quoted 17 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 1 +

  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -0
index 85567d0d9545..f5d5c45ddc0d 100644
@@ -944,6 +944,7 @@ static void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr)
                   drm_sched_entity_fini(entity);
               }
           }
+        kref_put(&ctx->refcount, amdgpu_ctx_fini);
       }
   }