All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdkfd: Don't require a VM for the profiler PMC lock
@ 2026-11-20 21:49 Apurv Mishra
  2026-11-20 21:58 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Apurv Mishra @ 2026-11-20 21:49 UTC (permalink / raw)
  To: amd-gfx; +Cc: Bing.Ma, Benjamin.Welton, James.Zhu, Jason.Tang, Apurv Mishra

The profiler PMC requests now go through kfd_bind_process_to_device() for a
runtime PM reference, but that also requires a VM on the GPU. A process
that takes the lock before AMDKFD_IOC_ACQUIRE_VM, as rocprofiler-sdk can,
now gets -ENODEV.

Take only the runtime PM reference, through a new
kfd_process_device_runtime_get() method that kfd_bind_process_to_device()
uses as well.

Signed-off-by: Apurv Mishra <Apurv.Mishra@amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 17 ++++----
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 54 ++++++++++++++++--------
 3 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 3d2136adb62b..b48be5743381 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -3396,19 +3396,20 @@ static inline int profile_lock_device(struct kfd_process *p,
 	struct kfd_dev *kfd;
 	int status = -EINVAL;
 	struct amdgpu_ptl *ptl;
+	int r = 0;
 
 	if (!p)
 		return -EINVAL;
 
 	mutex_lock(&p->mutex);
 	pdd = kfd_process_device_data_by_id(p, gpu_id);
-	/* Bind for the runtime PM reference before programming the perfmon clock */
+	/* Runtime PM reference only: the caller may have no VM on this GPU yet */
 	if (pdd && op == 1)
-		pdd = kfd_bind_process_to_device(pdd->dev, p);
+		r = kfd_process_device_runtime_get(pdd);
 	mutex_unlock(&p->mutex);
 
-	if (IS_ERR(pdd))
-		return PTR_ERR(pdd);
+	if (r)
+		return r;
 	if (!pdd || !pdd->dev || !pdd->dev->kfd)
 		return -EINVAL;
 
@@ -3474,13 +3475,13 @@ static int kfd_profiler_perfmon_clk(struct kfd_process *p, uint32_t gpu_id,
 
 	mutex_lock(&p->mutex);
 	pdd = kfd_process_device_data_by_id(p, gpu_id);
-	/* Bind for the runtime PM reference before programming the perfmon clock */
+	/* Runtime PM reference only: the caller may have no VM on this GPU yet */
 	if (pdd && enable)
-		pdd = kfd_bind_process_to_device(pdd->dev, p);
+		r = kfd_process_device_runtime_get(pdd);
 	mutex_unlock(&p->mutex);
 
-	if (IS_ERR(pdd))
-		return PTR_ERR(pdd);
+	if (r)
+		return r;
 	if (!pdd || !pdd->dev || !pdd->dev->kfd)
 		return -EINVAL;
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 129363ad4e34..e6291e273599 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1152,6 +1152,7 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
 			       struct file *drm_file);
 struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,
 						struct kfd_process *p);
+int kfd_process_device_runtime_get(struct kfd_process_device *pdd);
 struct kfd_process_device *kfd_get_process_device_data(struct kfd_node *dev,
 							struct kfd_process *p);
 struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev,
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index f959f19d92d2..eb286279bba0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -2010,6 +2010,39 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
 	return ret;
 }
 
+/*
+ * Keep the device out of runtime suspend until the pdd is destroyed. Unlike
+ * kfd_bind_process_to_device(), this doesn't need a VM on the device.
+ *
+ * Assumes that the process lock is held.
+ */
+int kfd_process_device_runtime_get(struct kfd_process_device *pdd)
+{
+	struct device *dev = adev_to_drm(pdd->dev->adev)->dev;
+	int err;
+
+	/*
+	 * make sure that runtime_usage counter is incremented just once
+	 * per pdd
+	 */
+	if (pdd->runtime_inuse)
+		return 0;
+
+	/*
+	 * signal runtime-pm system to auto resume and prevent
+	 * further runtime suspend once device pdd is created until
+	 * pdd is destroyed.
+	 */
+	err = pm_runtime_get_sync(dev);
+	if (err < 0) {
+		pm_runtime_put_autosuspend(dev);
+		return err;
+	}
+	pdd->runtime_inuse = true;
+
+	return 0;
+}
+
 /*
  * Direct the IOMMU to bind the process (specifically the pasid->mm)
  * to the device.
@@ -2032,24 +2065,9 @@ struct kfd_process_device *kfd_bind_process_to_device(struct kfd_node *dev,
 	if (!pdd->drm_priv)
 		return ERR_PTR(-ENODEV);
 
-	/*
-	 * signal runtime-pm system to auto resume and prevent
-	 * further runtime suspend once device pdd is created until
-	 * pdd is destroyed.
-	 */
-	if (!pdd->runtime_inuse) {
-		err = pm_runtime_get_sync(adev_to_drm(dev->adev)->dev);
-		if (err < 0) {
-			pm_runtime_put_autosuspend(adev_to_drm(dev->adev)->dev);
-			return ERR_PTR(err);
-		}
-	}
-
-	/*
-	 * make sure that runtime_usage counter is incremented just once
-	 * per pdd
-	 */
-	pdd->runtime_inuse = true;
+	err = kfd_process_device_runtime_get(pdd);
+	if (err)
+		return ERR_PTR(err);
 
 	return pdd;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdkfd: Don't require a VM for the profiler PMC lock
  2026-11-20 21:49 [PATCH] drm/amdkfd: Don't require a VM for the profiler PMC lock Apurv Mishra
@ 2026-11-20 21:58 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-20 21:58 UTC (permalink / raw)
  To: Apurv Mishra, amd-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/amdkfd: missing Fixes trailer for commit 8a2a98891184
--

commit 28d61bf0c9928d470a0760fe0edf0322918e49c9
Author: Apurv Mishra <Apurv.Mishra@amd.com>

> drm/amdkfd: Don't require a VM for the profiler PMC lock
>
> The profiler PMC requests now go through kfd_bind_process_to_device() for a
> runtime PM reference, but that also requires a VM on the GPU. A process
> that takes the lock before AMDKFD_IOC_ACQUIRE_VM, as rocprofiler-sdk can,
> now gets -ENODEV.
>
> Take only the runtime PM reference, through a new
> kfd_process_device_runtime_get() method that kfd_bind_process_to_device()
> uses as well.
>
> Signed-off-by: Apurv Mishra <Apurv.Mishra@amd.com>

[Severity: Low]
This fixes the -ENODEV failure introduced when profile_lock_device() and
kfd_profiler_perfmon_clk() began calling kfd_bind_process_to_device().
Should the commit message include a Fixes tag?

  Fixes: 8a2a98891184 ("drm/amdkfd: Force perfmon clock on for profiler PMC requests")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120214925.211726-1-Apurv.Mishra@amd.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 21:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 21:49 [PATCH] drm/amdkfd: Don't require a VM for the profiler PMC lock Apurv Mishra
2026-11-20 21:58 ` sashiko-bot

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.