From: Pierre-Eric Pelloux-Prayer <[email protected]>
This ioctl might trigger GPU work through ttm so make sure the GPU is awake. Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]> [[email protected]: Applied the same logic to !amdgpu_gem_are_domains_valid(args->in.domains)] Signed-off-by: Shahyan Soltani <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 43 ++++++++++++++++++------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c index 0d579517c03c..7b92e7b9fbb8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c @@ -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,19 +443,31 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, uint32_t handle, initial_domain; int r; + r = pm_runtime_resume_and_get(dev->dev); + if (r < 0) + return r; + /* reject invalid gem flags */ - if (flags & ~AMDGPU_GEM_CREATE_SETTABLE_MASK) - return -EINVAL; + if (flags & ~AMDGPU_GEM_CREATE_SETTABLE_MASK) { + r = -EINVAL; + goto pm_out; + } /* reject invalid gem domains */ - if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK) - return -EINVAL; - if (!amdgpu_gem_are_domains_valid(args->in.domains)) - return -EINVAL; + if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK) { + r = -EINVAL; + goto pm_out; + } + + if (!amdgpu_gem_are_domains_valid(args->in.domains)) { + r = -EINVAL; + goto pm_out; + } if (!amdgpu_is_tmz(adev) && (flags & AMDGPU_GEM_CREATE_ENCRYPTED)) { DRM_NOTE_ONCE("Cannot allocate secure buffer since TMZ is disabled\n"); - return -EINVAL; + r = -EINVAL; + goto pm_out; } /* always clear VRAM */ @@ -468,7 +481,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, * passed to bo list */ DRM_ERROR("GDS bo cannot be per-vm-bo\n"); - return -EINVAL; + r = -EINVAL; + goto pm_out; } flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS; } @@ -476,7 +490,7 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) { r = amdgpu_bo_reserve(vm->root.bo, false); if (r) - return r; + goto pm_out; resv = vm->root.bo->tbo.base.resv; } @@ -509,17 +523,22 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, amdgpu_bo_unreserve(vm->root.bo); } if (r) - return r; + goto pm_out; r = drm_gem_handle_create(filp, gobj, &handle); /* drop reference from allocate - handle holds it now */ drm_gem_object_put(gobj); if (r) - return r; + goto pm_out; + r = 0; memset(args, 0, sizeof(*args)); args->out.handle = handle; - return 0; + +pm_out: + pm_runtime_put_autosuspend(dev->dev); + + return r; } int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, -- 2.55.0
