Skip to contentSkip to conversation

drm/amdgpu: rework runtime_pm for GPU ioctl access

PATCH In review Shahyan Soltani 2 participants 18 messages Sep 23 – Sep 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover drm/amdgpu: rework runtime_pm for GPU ioctl access

This patch series reworks the runtime_pm system for ioctls, cs, and open/close calls to allow a few tools such as AMD-SMI to function without waking up the GPU.

v2:
Refactor patch "drm/amdgpu: use pm_runtime_resume_and_get amdgpu_gem_create_ioctl" to use a conditional guard instead as suggested by Kevin and Christian.

Change the descriptions for several patches to fit kernel conventions as suggested by Christian.

v3:
Fixed the typo in drm/amdgpu: use pm_runtime_resume_and_get for ctx ioctl.

Reworked patch "drm/amdgpu: rework runtime pm management for cs" to take the pm_ref on a cs_ioctl instead of a job.

Reworked patch "drm/amdgpu: push down runtime pm handling in amdgpu_gem_create_ioctl" to use a conditional guard.

Reworked patch "drm/amdgpu: handle runtime pm in amdgpu_gem_userptr_ioctl" to call the pm_runtime_resume before the BO is reserved.

Split patch "drm/amdgpu: defer GPU resume from open/close to first use" into 3 different patches:

drm/amdgpu: drop vm->generation initalization and root PD clearing drm/amdgpu: remove redundant amdgpu_vm_bo_update() call drm/amdgpu: defer GPU resume from open/close to first use

Removed redundant amdgpu_vm_bo_update() call in amdgpu_seq64_map as amdgpu_cs_vm_handling() already handles it.

Editted patch "drm/amdgpu: defer GPU resume from open/close to first use" to change the pm_ref parameter into !!pm_ref so that it would be converted into a boolean.

Set the preferred_domains and allowed_domains after the root PD is created in amdgpu_vm_pt_create(). This is to ensure later on in stack, the kernel will notice the root PD is not in its preferred domain and will set it to evicted. Setting the root PD to evicted will move it back into its preferred domain on the next best possible iteration.

All changes were suggested by Christian.

Pierre-Eric Pelloux-Prayer (7):
drm/amdgpu: use pm_runtime_resume_and_get amdgpu_gem_create_ioctl drm/amdgpu: use pm_runtime_resume_and_get for ctx ioctl drm/amdgpu: rework runtime pm management for cs drm/amdgpu: push down runtime pm handling in amdgpu_gem_create_ioctl drm/amdgpu: handle runtime pm in amdgpu_gem_userptr_ioctl drm/amdgpu: prevent suspend in fault handler
drm/amdgpu: get rid of amdgpu_drm_ioctl

Shahyan Soltani (3):
drm/amdgpu: drop vm->generation initalization and root PD clearing drm/amdgpu: remove redundant amdgpu_vm_bo_update() call drm/amdgpu: defer GPU resume from open/close to first use

 drivers/gpu/drm/amd/amdgpu/Makefile        |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     |  7 ++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c    | 10 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 23 +----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h    |  6 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c    | 24 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c  | 45 ----------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 16 ++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c  |  7 ----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     |  8 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  5 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c  |  7 +++-
 13 files changed, 61 insertions(+), 100 deletions(-)
 delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH v3 1/10 drm/amdgpu: use pm_runtime_resume_and_get amdgpu_gem_create_ioctl

From: Pierre-Eric Pelloux-Prayer <[email protected]>

This ioctl might trigger GPU work through ttm so make sure the GPU is awake.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +7 -0
index 0d579517c03c..4e4814caf61a 100644
@@ -33,6 +33,7 @@
 #include <linux/dma-buf.h>
 #include <linux/dma-fence-unwrap.h>
 #include <linux/uaccess.h>
+#include <linux/pm_runtime.h>
 
 #include <drm/amdgpu_drm.h>
 #include <drm/drm_drv.h>
@@ -442,6 +443,12 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
 	uint32_t handle, initial_domain;
 	int r;
 
+	PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(dev->dev, lock);
+
+	r = PM_RUNTIME_ACQUIRE_ERR(&lock);
+	if (r)
+		return r;
+
 	/* reject invalid gem flags */
 	if (flags & ~AMDGPU_GEM_CREATE_SETTABLE_MASK)
 		return -EINVAL;
Signature · 1 line
2.55.0
#2 lore raw

PATCH v3 2/10 drm/amdgpu: use pm_runtime_resume_and_get for ctx ioctl

In reply to Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Only amdgpu_ctx_set_stable_pstate() communicates with the hw.

v3 (Shahyan): fixxed typo in commit description

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -2
index b15ed4a534f1..a87f26139496 100644
@@ -28,6 +28,7 @@
 #include "amdgpu_sched.h"
 #include "amdgpu_ras.h"
 #include <linux/nospec.h>
+#include <linux/pm_runtime.h>
 
 #define to_amdgpu_ctx_entity(e)	\
 	container_of((e), struct amdgpu_ctx_entity, entity)
@@ -643,10 +644,15 @@ static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
 	 * context id.
 	 */
 
-	if (set)
+	if (set) {
+		r = pm_runtime_resume_and_get(adev->dev);
+		if (r < 0)
+			return r;
 		r = amdgpu_ctx_set_stable_pstate(ctx, *stable_pstate);
-	else
+		pm_runtime_put_autosuspend(adev->dev);
+	} else {
 		*stable_pstate = amdgpu_get_stable_pstate(adev);
+	}
 
 	amdgpu_ctx_put(ctx);
 	return r;
Signature · 1 line
2.55.0
maintainer Acked-by on v3 2/10
#3 lore raw

Re: [PATCH v3 02/10] drm/amdgpu: use pm_runtime_resume_and_get for ctx ioctl

Quoted 7 lines · Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Only amdgpu_ctx_set_stable_pstate() communicates with the hw.

v3 (Shahyan): fixxed typo in commit description

Quoted 34 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -2
index b15ed4a534f1..a87f26139496 100644
@@ -28,6 +28,7 @@
 #include "amdgpu_sched.h"
 #include "amdgpu_ras.h"
 #include <linux/nospec.h>
+#include <linux/pm_runtime.h>
 
 #define to_amdgpu_ctx_entity(e)	\
 	container_of((e), struct amdgpu_ctx_entity, entity)
@@ -643,10 +644,15 @@ static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
 	 * context id.
 	 */
 
-	if (set)
+	if (set) {
+		r = pm_runtime_resume_and_get(adev->dev);
+		if (r < 0)
+			return r;
 		r = amdgpu_ctx_set_stable_pstate(ctx, *stable_pstate);
-	else
+		pm_runtime_put_autosuspend(adev->dev);
+	} else {
 		*stable_pstate = amdgpu_get_stable_pstate(adev);
+	}
 
 	amdgpu_ctx_put(ctx);
 	return r;
#4 lore raw

PATCH v3 3/10 drm/amdgpu: rework runtime pm management for cs

In reply to Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Submitting a cs ioctl will now wake up the GPU. The guard will automatically drop the rpm ref when the cs ioctl goes out of scope.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7 -0
index 87ccef153073..e2a715c04208 100644
@@ -29,6 +29,7 @@
 #include <linux/pagemap.h>
 #include <linux/sync_file.h>
 #include <linux/dma-buf.h>
+#include <linux/pm_runtime.h>
 
 #include <drm/amdgpu_drm.h>
 #include <drm/drm_syncobj.h>
@@ -1445,6 +1446,12 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	if (!adev->accel_working)
 		return -EBUSY;
 
+	PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(dev->dev, lock);
+
+	r = PM_RUNTIME_ACQUIRE_ERR(&lock);
+	if (r)
+		return r;
+
 	r = amdgpu_cs_parser_init(&parser, adev, filp, data);
 	if (r) {
 		drm_err_ratelimited(dev, "Failed to initialize parser %d!\n", r);
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 3/10
#5 lore raw

Re: [PATCH v3 03/10] drm/amdgpu: rework runtime pm management for cs

Quoted 8 lines · Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Submitting a cs ioctl will now wake up the GPU. The guard will automatically drop the rpm ref when the cs ioctl goes out of scope.

Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +7 -0
index 87ccef153073..e2a715c04208 100644
@@ -29,6 +29,7 @@
 #include <linux/pagemap.h>
 #include <linux/sync_file.h>
 #include <linux/dma-buf.h>
+#include <linux/pm_runtime.h>
 
 #include <drm/amdgpu_drm.h>
 #include <drm/drm_syncobj.h>
@@ -1445,6 +1446,12 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 	if (!adev->accel_working)
 		return -EBUSY;
 
+	PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(dev->dev, lock);
+
+	r = PM_RUNTIME_ACQUIRE_ERR(&lock);
+	if (r)
+		return r;
+
 	r = amdgpu_cs_parser_init(&parser, adev, filp, data);
 	if (r) {
 		drm_err_ratelimited(dev, "Failed to initialize parser %d!\n", r);
#6 lore raw

PATCH v3 4/10 drm/amdgpu: push down runtime pm handling in amdgpu_gem_create_ioctl

In reply to Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

For now use the same logic as the existing one, but it's not 100% correct since:
1) most operations don't need the GPUs
2) some operations that need it are actually deferred

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6 -0
index 4e4814caf61a..5d2802009cd9 100644
@@ -929,6 +929,12 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 		abo = NULL;
 	}
 
+	PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(dev->dev, lock);
+
+	r = PM_RUNTIME_ACQUIRE_ERR(&lock);
+	if (r)
+		goto error_put_gobj;
+
 	/* Add input syncobj fences (if any) for synchronization. */
 	r = amdgpu_gem_add_input_fence(filp,
 				       args->input_fence_syncobj_handles,
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 4/10
#7 lore raw

Re: [PATCH v3 04/10] drm/amdgpu: push down runtime pm handling in amdgpu_gem_create_ioctl

Quoted 10 lines · Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

For now use the same logic as the existing one, but it's not 100% correct since:
1) most operations don't need the GPUs
2) some operations that need it are actually deferred

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +6 -0
index 4e4814caf61a..5d2802009cd9 100644
@@ -929,6 +929,12 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 		abo = NULL;
 	}
 
+	PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(dev->dev, lock);
+
+	r = PM_RUNTIME_ACQUIRE_ERR(&lock);
+	if (r)
+		goto error_put_gobj;
+
 	/* Add input syncobj fences (if any) for synchronization. */
 	r = amdgpu_gem_add_input_fence(filp,
 				       args->input_fence_syncobj_handles,
#8 lore raw

PATCH v3 5/10 drm/amdgpu: handle runtime pm in amdgpu_gem_userptr_ioctl

In reply to Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Wake up the GPU while setting up user pages and validating the buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8 -0
index 5d2802009cd9..e1760e112ec0 100644
@@ -590,6 +590,11 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 			amdgpu_hmm_range_free(range);
 			goto release_object;
 		}
+
+		r = pm_runtime_resume_and_get(adev->dev);
+		if (r < 0)
+			goto user_pages_done;
+
 		r = amdgpu_bo_reserve(bo, true);
 		if (r)
 			goto user_pages_done;
@@ -599,6 +604,9 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 		amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 		r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
 		amdgpu_bo_unreserve(bo);
+
+		pm_runtime_put_autosuspend(adev->dev);
+
 		if (r)
 			goto user_pages_done;
 	}
Signature · 1 line
2.55.0
maintainer Reviewed-by on v3 5/10
#9 lore raw

Re: [PATCH v3 05/10] drm/amdgpu: handle runtime pm in amdgpu_gem_userptr_ioctl

Quoted 7 lines · Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Wake up the GPU while setting up user pages and validating the buffer.

Quoted 30 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +8 -0
index 5d2802009cd9..e1760e112ec0 100644
@@ -590,6 +590,11 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 			amdgpu_hmm_range_free(range);
 			goto release_object;
 		}
+
+		r = pm_runtime_resume_and_get(adev->dev);
+		if (r < 0)
+			goto user_pages_done;
+
 		r = amdgpu_bo_reserve(bo, true);
 		if (r)
 			goto user_pages_done;
@@ -599,6 +604,9 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 		amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 		r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
 		amdgpu_bo_unreserve(bo);
+
+		pm_runtime_put_autosuspend(adev->dev);
+
 		if (r)
 			goto user_pages_done;
 	}
#10 lore raw

PATCH v3 6/10 drm/amdgpu: prevent suspend in fault handler

In reply to Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Temporarily increment the PM reference count during page handling to ensure the GPU does not enter a sleep state.

v2 (Shahyan): Added commit description

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -0
index e1760e112ec0..1f5b9c77dec5 100644
@@ -129,6 +129,8 @@ static vm_fault_t amdgpu_gem_fault(struct vm_fault *vmf)
 		return ret;
 
 	if (drm_dev_enter(ddev, &idx)) {
+		pm_runtime_get_noresume(ddev->dev);
+
 		ret = amdgpu_bo_fault_reserve_notify(bo);
 		if (ret) {
 			drm_dev_exit(idx);
@@ -138,6 +140,7 @@ static vm_fault_t amdgpu_gem_fault(struct vm_fault *vmf)
 		ret = ttm_bo_vm_fault_reserved(vmf, vmf->vma->vm_page_prot,
 					       TTM_BO_VM_NUM_PREFAULT);
 
+		pm_runtime_put_noidle(ddev->dev);
 		drm_dev_exit(idx);
 	} else {
 		ret = ttm_bo_vm_dummy_page(vmf, vmf->vma->vm_page_prot);
Signature · 1 line
2.55.0
#11 lore raw

PATCH v3 7/10 drm/amdgpu: get rid of amdgpu_drm_ioctl

In reply to Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Remove the entire amdgpu_drm_ioctl handler system in favor of drm_ioctl.

v2 (Shahyan): Added commit description

---
 drivers/gpu/drm/amd/amdgpu/Makefile       |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   | 23 +-----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h   |  6 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c | 45 -----------------------
 4 files changed, 2 insertions(+), 73 deletions(-)
 delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c
drivers/gpu/drm/amd/amdgpu/Makefile +0 -1
index 7b08814a24da..d5ddf236a6f9 100644
@@ -321,7 +321,6 @@ include $(FULL_AMD_PATH)/acp/Makefile
 amdgpu-y += $(AMD_ACP_FILES)
 endif
 
-amdgpu-$(CONFIG_COMPAT) += amdgpu_ioc32.o
 amdgpu-$(CONFIG_VGA_SWITCHEROO) += amdgpu_atpx_handler.o
 amdgpu-$(CONFIG_ACPI) += amdgpu_acpi.o
 amdgpu-$(CONFIG_HMM_MIRROR) += amdgpu_hmm.o
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -21
index 9c5e93cd3ee6..f51f03ae5241 100644
@@ -3019,25 +3019,6 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp)
 	return drm_release(inode, filp);
 }
 
-long amdgpu_drm_ioctl(struct file *filp,
-		      unsigned int cmd, unsigned long arg)
-{
-	struct drm_file *file_priv = filp->private_data;
-	struct drm_device *dev;
-	long ret;
-
-	dev = file_priv->minor->dev;
-	ret = pm_runtime_get_sync(dev->dev);
-	if (ret < 0)
-		goto out;
-
-	ret = drm_ioctl(filp, cmd, arg);
-
-out:
-	pm_runtime_put_autosuspend(dev->dev);
-	return ret;
-}
-
 static const struct dev_pm_ops amdgpu_pm_ops = {
 	.prepare = pm_sleep_ptr(amdgpu_pmops_prepare),
 	.complete = pm_sleep_ptr(amdgpu_pmops_complete),
@@ -3070,12 +3051,12 @@ static const struct file_operations amdgpu_driver_kms_fops = {
 	.open = drm_open,
 	.flush = amdgpu_flush,
 	.release = amdgpu_drm_release,
-	.unlocked_ioctl = amdgpu_drm_ioctl,
+	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
-	.compat_ioctl = amdgpu_kms_compat_ioctl,
+	.compat_ioctl = drm_compat_ioctl,
 #endif
 #ifdef CONFIG_PROC_FS
 	.show_fdinfo = drm_show_fdinfo,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h +0 -6
index 2d86cc6f7f4d..6b06c0956e48 100644
@@ -43,10 +43,4 @@
 
 extern const struct drm_driver amdgpu_partition_driver;
 
-long amdgpu_drm_ioctl(struct file *filp,
-		      unsigned int cmd, unsigned long arg);
-
-long amdgpu_kms_compat_ioctl(struct file *filp,
-			     unsigned int cmd, unsigned long arg);
-
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
2.55.0
maintainer
#12 lore raw

Re: [PATCH v3 07/10] drm/amdgpu: get rid of amdgpu_drm_ioctl

Quoted 3 lines · Shahyan Soltani

From: Pierre-Eric Pelloux-Prayer <[email protected]>

Remove the entire amdgpu_drm_ioctl handler system in favor of drm_ioctl.

Please add a bit more commit message, something like:

Each individual IOCTL should now handle runtime PM itself. Fingers crossed that we haven't missed anything.

With that done please push patches #1-#7 to amd-staging-drm-next, I think they are ready to land now.

Thanks,
Christian.

Quoted 136 lines

v2 (Shahyan): Added commit description

---
 drivers/gpu/drm/amd/amdgpu/Makefile       |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c   | 23 +-----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h   |  6 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c | 45 -----------------------
 4 files changed, 2 insertions(+), 73 deletions(-)
 delete mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c
drivers/gpu/drm/amd/amdgpu/Makefile +0 -1
index 7b08814a24da..d5ddf236a6f9 100644
@@ -321,7 +321,6 @@ include $(FULL_AMD_PATH)/acp/Makefile
 amdgpu-y += $(AMD_ACP_FILES)
 endif
 
-amdgpu-$(CONFIG_COMPAT) += amdgpu_ioc32.o
 amdgpu-$(CONFIG_VGA_SWITCHEROO) += amdgpu_atpx_handler.o
 amdgpu-$(CONFIG_ACPI) += amdgpu_acpi.o
 amdgpu-$(CONFIG_HMM_MIRROR) += amdgpu_hmm.o
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -21
index 9c5e93cd3ee6..f51f03ae5241 100644
@@ -3019,25 +3019,6 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp)
 	return drm_release(inode, filp);
 }
 
-long amdgpu_drm_ioctl(struct file *filp,
-		      unsigned int cmd, unsigned long arg)
-{
-	struct drm_file *file_priv = filp->private_data;
-	struct drm_device *dev;
-	long ret;
-
-	dev = file_priv->minor->dev;
-	ret = pm_runtime_get_sync(dev->dev);
-	if (ret < 0)
-		goto out;
-
-	ret = drm_ioctl(filp, cmd, arg);
-
-out:
-	pm_runtime_put_autosuspend(dev->dev);
-	return ret;
-}
-
 static const struct dev_pm_ops amdgpu_pm_ops = {
 	.prepare = pm_sleep_ptr(amdgpu_pmops_prepare),
 	.complete = pm_sleep_ptr(amdgpu_pmops_complete),
@@ -3070,12 +3051,12 @@ static const struct file_operations amdgpu_driver_kms_fops = {
 	.open = drm_open,
 	.flush = amdgpu_flush,
 	.release = amdgpu_drm_release,
-	.unlocked_ioctl = amdgpu_drm_ioctl,
+	.unlocked_ioctl = drm_ioctl,
 	.mmap = drm_gem_mmap,
 	.poll = drm_poll,
 	.read = drm_read,
 #ifdef CONFIG_COMPAT
-	.compat_ioctl = amdgpu_kms_compat_ioctl,
+	.compat_ioctl = drm_compat_ioctl,
 #endif
 #ifdef CONFIG_PROC_FS
 	.show_fdinfo = drm_show_fdinfo,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.h +0 -6
index 2d86cc6f7f4d..6b06c0956e48 100644
@@ -43,10 +43,4 @@
 
 extern const struct drm_driver amdgpu_partition_driver;
 
-long amdgpu_drm_ioctl(struct file *filp,
-		      unsigned int cmd, unsigned long arg);
-
-long amdgpu_kms_compat_ioctl(struct file *filp,
-			     unsigned int cmd, unsigned long arg);
-
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_ioc32.c deleted +0 -45
deleted file mode 100644
index a1cbd7c3deb2..000000000000
@@ -1,45 +0,0 @@
-/*
- * \file amdgpu_ioc32.c
- *
- * 32-bit ioctl compatibility routines for the AMDGPU DRM.
- *
- * \author Paul Mackerras <[email protected]>
- *
- * Copyright (C) Paul Mackerras 2005
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-#include <linux/compat.h>
-
-#include <drm/amdgpu_drm.h>
-#include <drm/drm_ioctl.h>
-
-#include "amdgpu_drv.h"
-
-long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-	unsigned int nr = DRM_IOCTL_NR(cmd);
-
-	if (nr < DRM_COMMAND_BASE)
-		return drm_compat_ioctl(filp, cmd, arg);
-
-	return amdgpu_drm_ioctl(filp, cmd, arg);
-}
#13 lore raw

PATCH v3 8/10 drm/amdgpu: drop vm->generation initalization and root PD clearing

In reply to Shahyan Soltani

Dropping these should allow the GPU to clear the root PD only when it is required. Further testing may be required to verify this.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -5
index 47cde5459469..1c3d3603af60 100644
@@ -2640,7 +2640,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	vm->last_update = dma_fence_get_stub();
 	vm->last_unlocked = dma_fence_get_stub();
 	vm->last_tlb_flush = dma_fence_get_stub();
-	vm->generation = amdgpu_vm_generation(adev, NULL);
 
 	mutex_init(&vm->eviction_lock);
 	vm->evicting = false;
@@ -2663,10 +2662,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (r)
 		goto error_free_root;
 
-	r = amdgpu_vm_pt_clear(adev, vm, root, false);
-	if (r)
-		goto error_free_root;
-
 	r = amdgpu_vm_create_task_info(vm);
 	if (r)
 		dev_dbg(adev->dev, "Failed to create task info for VM\n");
Signature · 1 line
2.55.0
maintainer
#14 lore raw

Re: [PATCH v3 08/10] drm/amdgpu: drop vm->generation initalization and root PD clearing

Quoted 2 lines · Shahyan Soltani

Dropping these should allow the GPU to clear the root PD only when it is required. Further testing may be required to verify this.

How familiar are you with trace points on Linux?

We have the amdgpu_vm_update_ptes, amdgpu_vm_copy_ptes and amdgpu_vm_set_ptes trace points which allows you to observe if the root PD is cleared or not.

Please double check if that patch here really works. My educated guess is that it doesn't and we need to improve the vm->generation handling quite a bit for this be correct.

Regards,
Christian.

Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -5
index 47cde5459469..1c3d3603af60 100644
@@ -2640,7 +2640,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	vm->last_update = dma_fence_get_stub();
 	vm->last_unlocked = dma_fence_get_stub();
 	vm->last_tlb_flush = dma_fence_get_stub();
-	vm->generation = amdgpu_vm_generation(adev, NULL);
 
 	mutex_init(&vm->eviction_lock);
 	vm->evicting = false;
@@ -2663,10 +2662,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (r)
 		goto error_free_root;
 
-	r = amdgpu_vm_pt_clear(adev, vm, root, false);
-	if (r)
-		goto error_free_root;
-
 	r = amdgpu_vm_create_task_info(vm);
 	if (r)
 		dev_dbg(adev->dev, "Failed to create task info for VM\n");
#15 lore raw

PATCH v3 9/10 drm/amdgpu: remove redundant amdgpu_vm_bo_update() call

In reply to Shahyan Soltani

This is already handled in amdgpu_cs_vm_handling() and calling it this early is unnecessary. Removing it is required to allow the vm to initialize without waking up sleep.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c +0 -7
index 21a225b0116a..fbf9ec7d467b 100644
@@ -103,13 +103,6 @@ int amdgpu_seq64_map(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		goto error;
 	}
 
-	r = amdgpu_vm_bo_update(adev, *bo_va, false);
-	if (r) {
-		DRM_ERROR("failed to do vm_bo_update on userq sem\n");
-		amdgpu_vm_bo_del(adev, *bo_va);
-		goto error;
-	}
-
 error:
 	drm_exec_fini(&exec);
 	return r;
Signature · 1 line
2.55.0
maintainer
#16 lore raw

Re: [PATCH v3 09/10] drm/amdgpu: remove redundant amdgpu_vm_bo_update() call

Quoted 1 line · Shahyan Soltani

This is already handled in amdgpu_cs_vm_handling()

Actually it isn't handled there yet, but we need to add this.

Otherwise the CS after a GPU reset might be broken.

Regards,
Christian.

Quoted 27 lines

and calling it this
early is unnecessary. Removing it is required to allow the vm to initialize without waking up sleep.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c | 7 -------
 1 file changed, 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_seq64.c +0 -7
index 21a225b0116a..fbf9ec7d467b 100644
@@ -103,13 +103,6 @@ int amdgpu_seq64_map(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		goto error;
 	}
 
-	r = amdgpu_vm_bo_update(adev, *bo_va, false);
-	if (r) {
-		DRM_ERROR("failed to do vm_bo_update on userq sem\n");
-		amdgpu_vm_bo_del(adev, *bo_va);
-		goto error;
-	}
-
 error:
 	drm_exec_fini(&exec);
 	return r;
#17 lore raw

PATCH v3 10/10 drm/amdgpu: defer GPU resume from open/close to first use

In reply to Shahyan Soltani

Drop pm_runtime_get_sync() from open/close KMS to prevent unnecessary resumes. Instead, the PM reference will only be held if the GPU is currently awake.

Introduce delayed virtual memory hardware initialization through a powered_init flag to skip page table setup if the GPU is suspended.

If the GPU is suspended, pagetables will instead be initialized upon first use, such as when a cs_ioctl is called.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 16 +++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  5 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c  |  7 ++++++-
 5 files changed, 20 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -9
index f2f179421c4d..202e7313c8df 100644
@@ -1483,9 +1483,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
 	file_priv->driver_priv = NULL;
 
-	r = pm_runtime_get_sync(dev->dev);
-	if (r < 0)
-		goto pm_put;
+	int pm_ref = pm_runtime_get_if_active(dev->dev);
 
 	fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
 	if (unlikely(!fpriv)) {
@@ -1499,7 +1497,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
 	amdgpu_debugfs_vm_init(file_priv);
 
-	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id);
+	r = amdgpu_vm_init(adev, &fpriv->vm, fpriv->xcp_id, !!pm_ref);
 	if (r)
 		goto error_pasid;
 
@@ -1564,9 +1562,8 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	kfree(fpriv);
 
 out_suspend:
-pm_put:
-	pm_runtime_put_autosuspend(dev->dev);
-
+	if (pm_ref > 0)
+		pm_runtime_put_autosuspend(dev->dev);
 	return r;
 }
 
@@ -1591,7 +1588,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 	if (!fpriv)
 		return;
 
-	pm_runtime_get_sync(dev->dev);
+	int pm_ref = pm_runtime_get_if_active(dev->dev);
 
 	if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_UVD) != NULL)
 		amdgpu_uvd_free_handles(adev, file_priv);
@@ -1630,7 +1627,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 	kfree(fpriv);
 	file_priv->driver_priv = NULL;
 
-	pm_runtime_put_autosuspend(dev->dev);
+	if (pm_ref > 0)
+		pm_runtime_put_autosuspend(dev->dev);
 }
 
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +1 -1
index ab564202f550..6022ec6cf1b4 100644
@@ -4071,7 +4071,7 @@ int amdgpu_ualink_manager_start(struct amdgpu_device *adev)
 {
 	int i, r;
 
-	r = amdgpu_vm_init(adev, &adev->ualink.npa_vm, 0);
+	r = amdgpu_vm_init(adev, &adev->ualink.npa_vm, 0, true);
 	if (r)
 		goto out;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -1
index 1c3d3603af60..a03000db3c36 100644
@@ -2596,7 +2596,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm)
  * 0 for success, error for failure.
  */
 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-		   int32_t xcp_id)
+		   int32_t xcp_id, int device_active)
 {
 	struct amdgpu_bo *root_bo;
 	struct amdgpu_bo_vm *root;
@@ -2620,6 +2620,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 	ttm_lru_bulk_move_init(&vm->lru_bulk_move);
 
+	vm->powered_init = device_active;
 	vm->is_compute_context = false;
 	vm->need_tlb_fence = amdgpu_userq_enabled(&adev->ddev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4 -1
index 0f6634b74974..b422a5f394a1 100644
@@ -373,6 +373,8 @@ struct amdgpu_vm {
 	bool			is_npa;
 	/* Flag to indicate if VM needs a TLB fence (KFD or KGD) */
 	bool			need_tlb_fence;
+	/* Flag to indicate if VM during initialization holds a runtime reference */
+	bool			powered_init;
 
 	/* Memory partition number, -1 means any partition */
 	int8_t			mem_id;
@@ -429,7 +431,8 @@ void amdgpu_vm_manager_init(struct amdgpu_device *adev);
 void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
 
 long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout);
-int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id);
+int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, int32_t xcp_id,
+		   int device_active);
 int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 int amdgpu_vm_make_npa(struct amdgpu_device *adev, struct amdgpu_vm *vm);
 void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +6 -1
index 1cdf2b854f26..7afc6887b8e6 100644
@@ -456,7 +456,7 @@ int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	bp.size = amdgpu_vm_pt_size(adev, level);
 	bp.byte_align = AMDGPU_GPU_PAGE_SIZE;
 
-	if (!adev->gmc.is_app_apu)
+	if (!adev->gmc.is_app_apu && vm->powered_init)
 		bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
 	else
 		bp.domain = AMDGPU_GEM_DOMAIN_GTT;
@@ -486,6 +486,11 @@ int amdgpu_vm_pt_create(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (r)
 		return r;
 
+	if (bp.domain == AMDGPU_GEM_DOMAIN_GTT && !adev->gmc.is_app_apu) {
+		(*vmbo)->bo.preferred_domains = AMDGPU_GEM_DOMAIN_VRAM;
+		(*vmbo)->bo.allowed_domains = AMDGPU_GEM_DOMAIN_GTT | AMDGPU_GEM_DOMAIN_VRAM;
+	}
+
 	/* Assumes that reservation is shared with the VM root and that the
 	 * reservation is locked
 	 */
Signature · 1 line
2.55.0