drm/scheduler: Remove priority macro INVALID (v2)
authorLuben Tuikov <luben.tuikov@amd.com>
Wed, 12 Aug 2020 00:56:58 +0000 (20:56 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 18 Aug 2020 22:20:26 +0000 (18:20 -0400)
Remove DRM_SCHED_PRIORITY_INVALID. We no longer
carry around an invalid priority and cut it off
at the source.

Backwards compatibility behaviour of AMDGPU CTX
IOCTL passing in garbage for context priority
from user space and then mapping that to
DRM_SCHED_PRIORITY_NORMAL is preserved.

v2: Revert "res"  --> "r" and
           "prio" --> "priority".

Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.h
include/drm/gpu_scheduler.h

index fc695126b6e75441627b346eceb37e75a0cdde65..ba243cc8f5850c2503ac43d7d4f5bd582c4e0933 100644 (file)
@@ -388,13 +388,12 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
        struct amdgpu_device *adev = dev->dev_private;
        struct amdgpu_fpriv *fpriv = filp->driver_priv;
 
-       r = 0;
        id = args->in.ctx_id;
-       priority = amdgpu_to_sched_priority(args->in.priority);
+       r = amdgpu_to_sched_priority(args->in.priority, &priority);
 
        /* For backwards compatibility reasons, we need to accept
         * ioctls with garbage in the priority field */
-       if (priority == DRM_SCHED_PRIORITY_INVALID)
+       if (r == -EINVAL)
                priority = DRM_SCHED_PRIORITY_NORMAL;
 
        switch (args->in.op) {
index 17661ede948857890cba69f7e7bd36cca400ca2a..9581283a4c7857b56e1cee00b70df5f3f59f8a13 100644 (file)
 
 #include "amdgpu_vm.h"
 
-enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority)
+int amdgpu_to_sched_priority(int amdgpu_priority,
+                            enum drm_sched_priority *prio)
 {
        switch (amdgpu_priority) {
        case AMDGPU_CTX_PRIORITY_VERY_HIGH:
-               return DRM_SCHED_PRIORITY_HIGH;
+               *prio = DRM_SCHED_PRIORITY_HIGH;
+               break;
        case AMDGPU_CTX_PRIORITY_HIGH:
-               return DRM_SCHED_PRIORITY_HIGH;
+               *prio = DRM_SCHED_PRIORITY_HIGH;
+               break;
        case AMDGPU_CTX_PRIORITY_NORMAL:
-               return DRM_SCHED_PRIORITY_NORMAL;
+               *prio = DRM_SCHED_PRIORITY_NORMAL;
+               break;
        case AMDGPU_CTX_PRIORITY_LOW:
        case AMDGPU_CTX_PRIORITY_VERY_LOW:
-               return DRM_SCHED_PRIORITY_MIN;
+               *prio = DRM_SCHED_PRIORITY_MIN;
+               break;
        case AMDGPU_CTX_PRIORITY_UNSET:
-               return DRM_SCHED_PRIORITY_UNSET;
+               *prio = DRM_SCHED_PRIORITY_UNSET;
+               break;
        default:
                WARN(1, "Invalid context priority %d\n", amdgpu_priority);
-               return DRM_SCHED_PRIORITY_INVALID;
+               return -EINVAL;
        }
+
+       return 0;
 }
 
 static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
@@ -119,9 +127,20 @@ int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
        enum drm_sched_priority priority;
        int r;
 
-       priority = amdgpu_to_sched_priority(args->in.priority);
-       if (priority == DRM_SCHED_PRIORITY_INVALID)
+       /* First check the op, then the op's argument.
+        */
+       switch (args->in.op) {
+       case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
+       case AMDGPU_SCHED_OP_CONTEXT_PRIORITY_OVERRIDE:
+               break;
+       default:
+               DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
                return -EINVAL;
+       }
+
+       r = amdgpu_to_sched_priority(args->in.priority, &priority);
+       if (r)
+               return r;
 
        switch (args->in.op) {
        case AMDGPU_SCHED_OP_PROCESS_PRIORITY_OVERRIDE:
@@ -136,7 +155,8 @@ int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
                                                           priority);
                break;
        default:
-               DRM_ERROR("Invalid sched op specified: %d\n", args->in.op);
+               /* Impossible.
+                */
                r = -EINVAL;
                break;
        }
index 12299fd95691cb2845fd6c4f9bb8c2b1bebd194b..67e5b2472f6a84a740a626fb3c60c525f8affec0 100644 (file)
@@ -30,7 +30,8 @@ enum drm_sched_priority;
 struct drm_device;
 struct drm_file;
 
-enum drm_sched_priority amdgpu_to_sched_priority(int amdgpu_priority);
+int amdgpu_to_sched_priority(int amdgpu_priority,
+                            enum drm_sched_priority *prio);
 int amdgpu_sched_ioctl(struct drm_device *dev, void *data,
                       struct drm_file *filp);
 
index b30026ccd564bcdcad07c401bc68fae8b903b14d..a33590e621086b5dd4114c1c211b16e97fe626e8 100644 (file)
@@ -43,7 +43,6 @@ enum drm_sched_priority {
        DRM_SCHED_PRIORITY_KERNEL,
 
        DRM_SCHED_PRIORITY_COUNT,
-       DRM_SCHED_PRIORITY_INVALID = -1,
        DRM_SCHED_PRIORITY_UNSET = -2
 };