All of lore.kernel.org
 help / color / mirror / Atom feed
From: Perry Yuan <perry.yuan@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>, <Christian.Koenig@amd.com>,
	<Yifan1.Zhang@amd.com>, <perry.yuan@amd.com>
Subject: [PATCH 2/3] drm/amdkfd: Fix leaked PTL disable request on process exit
Date: Tue, 1 Dec 2026 17:00:27 +0800	[thread overview]
Message-ID: <20261201090028.86494-2-perry.yuan@amd.com> (raw)
In-Reply-To: <20261201090028.86494-1-perry.yuan@amd.com>

When the last profiler releases its PTL disable request, KFD tries to
enable PTL. If that fails, KFD restores the request so the owner can
retry. At process teardown, however, kfd_process_destroy_pdds() frees
the owner immediately after the release. The restored request then has
no owner. Subsequent profiler sessions never drop the reference count
to zero, and the profiler bit blocks attempts to enable PTL via sysfs.

On the final release, report the enable error but do not restore the
request. The next profiler release or sysfs enable can then retry the
hardware operation. Keep the existing rollback for explicit releases.

Fixes: dd61e27535a6 ("drm/amdkfd: Add PTL control IOCTL Option and unify refcount logic")
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 16 +++++++++-------
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  3 +--
 drivers/gpu/drm/amd/amdkfd/kfd_process.c |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index ae5b430a0031..43cb0af5e527 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1882,8 +1882,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd,
 	return ret;
 }
 
-int kfd_ptl_disable_release(struct kfd_process_device *pdd,
-		struct kfd_process *p)
+int kfd_ptl_disable_release(struct kfd_process_device *pdd, bool final)
 {
 	struct amdgpu_device *adev = pdd->dev->adev;
 	struct amdgpu_ptl *ptl = &adev->psp.ptl;
@@ -1901,10 +1900,13 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd,
 		clear_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap);
 		ret = kfd_ptl_control(pdd, true);
 		if (ret) {
-			atomic_inc(&ptl->disable_ref);
-			set_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap);
 			dev_warn(adev->dev, "Failed to enable PTL on release: %d\n", ret);
-			goto out;
+			/* Only a live pdd can retry the release. */
+			if (!final) {
+				atomic_inc(&ptl->disable_ref);
+				set_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap);
+				goto out;
+			}
 		}
 	}
 	pdd->ptl_disable_req = false;
@@ -1930,7 +1932,7 @@ static int kfd_profiler_ptl_control(struct kfd_process *p,
 	if (args->enable == 0)
 		ret = kfd_ptl_disable_request(pdd, p);
 	else
-		ret = kfd_ptl_disable_release(pdd, p);
+		ret = kfd_ptl_disable_release(pdd, false);
 
 	return ret;
 }
@@ -3444,7 +3446,7 @@ static inline int profile_lock_device(struct kfd_process *p,
 		up_read(&kfd->adev->reset_domain->sem);
 
 		if (ptl->hw_supported_state == AMDGPU_PTL_HW_SUPPORTED) {
-			status = kfd_ptl_disable_release(pdd, p);
+			status = kfd_ptl_disable_release(pdd, false);
 			if (status)
 				dev_err(kfd_device,
 						"Failed to unlock device %d for profiling, error %d\n",
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 8eac086aa108..4950a8b9d162 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1661,8 +1661,7 @@ static inline bool kfd_is_first_node(struct kfd_node *node)
 /* PTL support */
 int kfd_ptl_disable_request(struct kfd_process_device *pdd,
 		struct kfd_process *p);
-int kfd_ptl_disable_release(struct kfd_process_device *pdd,
-		struct kfd_process *p);
+int kfd_ptl_disable_release(struct kfd_process_device *pdd, bool final);
 
 /* Debugfs */
 #if defined(CONFIG_DEBUG_FS)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index 5dc657f32d38..a5ec822077b6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -1258,7 +1258,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
 		kfd_process_profiler_release(p, pdd);
 
 		if (pdd->ptl_disable_req)
-			kfd_ptl_disable_release(pdd, p);
+			kfd_ptl_disable_release(pdd, true);
 
 		kfd_process_device_destroy_cwsr_dgpu(pdd);
 		kfd_process_device_destroy_ib_mem(pdd);
-- 
2.34.1


  reply	other threads:[~2026-12-01  9:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  9:00 [PATCH 1/3] drm/amdgpu: keep PTL disable requests across GPU reset and resume Perry Yuan
2026-12-01  9:00 ` Perry Yuan [this message]
2026-12-01  9:00 ` [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences Perry Yuan
2026-12-01  9:07   ` sashiko-bot
2026-12-01 13:40   ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201090028.86494-2-perry.yuan@amd.com \
    --to=perry.yuan@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Yifan1.Zhang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.