Skip to contentSkip to conversation

drm/amdgpu: Remove redundant call to priority_is_valid()

PATCH In review Luben Tuikov 3 participants 4 messages Oct 18, 2023 – Oct 22, 2023

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

PATCH 1/1 drm/amdgpu: Remove redundant call to priority_is_valid()

Remove a redundant call to amdgpu_ctx_priority_is_valid() from amdgpu_ctx_priority_permit(), which is called from amdgpu_ctx_init() which is called from amdgpu_ctx_alloc() which is called from amdgpu_ctx_ioctl(), where we've called amdgpu_ctx_priority_is_valid() already first thing in the function.

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -7
index 68db924161ef66..4c6ffca97c4512 100644
@@ -56,6 +56,10 @@ bool amdgpu_ctx_priority_is_valid(int32_t ctx_prio)
 		return true;
 	default:
 	case AMDGPU_CTX_PRIORITY_UNSET:
+		/* UNSET priority is not valid and we don't carry that
+		 * around, but set it to NORMAL in the only place this
+		 * function is called, amdgpu_ctx_ioctl().
+		 */
 		return false;
 	}
 }
@@ -96,9 +100,6 @@ amdgpu_ctx_to_drm_sched_prio(int32_t ctx_prio)
 static int amdgpu_ctx_priority_permit(struct drm_file *filp,
 				      int32_t priority)
 {
-	if (!amdgpu_ctx_priority_is_valid(priority))
-		return -EINVAL;
-
 	/* NORMAL and below are accessible by everyone */
 	if (priority <= AMDGPU_CTX_PRIORITY_NORMAL)
 		return 0;
@@ -625,8 +626,6 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
 	return 0;
 }
 
-
-
 static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
 				    struct amdgpu_fpriv *fpriv, uint32_t id,
 				    bool set, u32 *stable_pstate)
@@ -669,8 +668,10 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 	id = args->in.ctx_id;
 	priority = args->in.priority;
 
-	/* For backwards compatibility reasons, we need to accept
-	 * ioctls with garbage in the priority field */
+	/* For backwards compatibility, we need to accept ioctls with garbage
+	 * in the priority field. Garbage values in the priority field, result
+	 * in the priority being set to NORMAL.
+	 */
 	if (!amdgpu_ctx_priority_is_valid(priority))
 		priority = AMDGPU_CTX_PRIORITY_NORMAL;
 

base-commit: 915718484b8fa1eede4499a939e2e4fc0d85caa4
prerequisite-patch-id: a36f628997d923f66da5342e760e8b45ff959fb8
prerequisite-patch-id: f15148c302329c0c60d86040571c61d367bd05e7

Signature · 1 line
2.42.0
maintainer Acked-by on v1 1/1
#1 lore raw

Am 18.10.23 um 03:03 schrieb Luben Tuikov:

Quoted 9 lines

Remove a redundant call to amdgpu_ctx_priority_is_valid() from amdgpu_ctx_priority_permit(), which is called from amdgpu_ctx_init() which is called from amdgpu_ctx_alloc() which is called from amdgpu_ctx_ioctl(), where we've called amdgpu_ctx_priority_is_valid() already first thing in the function.

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Quoted 55 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 15 ++++++++-------
  1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -7
index 68db924161ef66..4c6ffca97c4512 100644
@@ -56,6 +56,10 @@ bool amdgpu_ctx_priority_is_valid(int32_t ctx_prio)
  		return true;
  	default:
  	case AMDGPU_CTX_PRIORITY_UNSET:
+		/* UNSET priority is not valid and we don't carry that
+		 * around, but set it to NORMAL in the only place this
+		 * function is called, amdgpu_ctx_ioctl().
+		 */
  		return false;
  	}
  }
@@ -96,9 +100,6 @@ amdgpu_ctx_to_drm_sched_prio(int32_t ctx_prio)
  static int amdgpu_ctx_priority_permit(struct drm_file *filp,
  				      int32_t priority)
  {
-	if (!amdgpu_ctx_priority_is_valid(priority))
-		return -EINVAL;
-
  	/* NORMAL and below are accessible by everyone */
  	if (priority <= AMDGPU_CTX_PRIORITY_NORMAL)
  		return 0;
@@ -625,8 +626,6 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
  	return 0;
  }
 
-
-
  static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
  				    struct amdgpu_fpriv *fpriv, uint32_t id,
  				    bool set, u32 *stable_pstate)
@@ -669,8 +668,10 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
  	id = args->in.ctx_id;
  	priority = args->in.priority;
 
-	/* For backwards compatibility reasons, we need to accept
-	 * ioctls with garbage in the priority field */
+	/* For backwards compatibility, we need to accept ioctls with garbage
+	 * in the priority field. Garbage values in the priority field, result
+	 * in the priority being set to NORMAL.
+	 */
  	if (!amdgpu_ctx_priority_is_valid(priority))
  		priority = AMDGPU_CTX_PRIORITY_NORMAL;
 

base-commit: 915718484b8fa1eede4499a939e2e4fc0d85caa4
prerequisite-patch-id: a36f628997d923f66da5342e760e8b45ff959fb8
prerequisite-patch-id: f15148c302329c0c60d86040571c61d367bd05e7

#2 lore raw
In reply to Luben Tuikov
Quoted 10 lines · Luben Tuikov

Remove a redundant call to amdgpu_ctx_priority_is_valid() from amdgpu_ctx_priority_permit(), which is called from amdgpu_ctx_init() which is called from amdgpu_ctx_alloc() which is called from amdgpu_ctx_ioctl(), where we've called amdgpu_ctx_priority_is_valid() already first thing in the function.

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>

Please push this to drm-misc since it depends on your previous patches.

Alex

Quoted 58 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -7
index 68db924161ef66..4c6ffca97c4512 100644
@@ -56,6 +56,10 @@ bool amdgpu_ctx_priority_is_valid(int32_t ctx_prio)
                return true;
        default:
        case AMDGPU_CTX_PRIORITY_UNSET:
+               /* UNSET priority is not valid and we don't carry that
+                * around, but set it to NORMAL in the only place this
+                * function is called, amdgpu_ctx_ioctl().
+                */
                return false;
        }
 }
@@ -96,9 +100,6 @@ amdgpu_ctx_to_drm_sched_prio(int32_t ctx_prio)
 static int amdgpu_ctx_priority_permit(struct drm_file *filp,
                                      int32_t priority)
 {
-       if (!amdgpu_ctx_priority_is_valid(priority))
-               return -EINVAL;
-
        /* NORMAL and below are accessible by everyone */
        if (priority <= AMDGPU_CTX_PRIORITY_NORMAL)
                return 0;
@@ -625,8 +626,6 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
        return 0;
 }
 
-
-
 static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
                                    struct amdgpu_fpriv *fpriv, uint32_t id,
                                    bool set, u32 *stable_pstate)
@@ -669,8 +668,10 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
        id = args->in.ctx_id;
        priority = args->in.priority;
 
-       /* For backwards compatibility reasons, we need to accept
-        * ioctls with garbage in the priority field */
+       /* For backwards compatibility, we need to accept ioctls with garbage
+        * in the priority field. Garbage values in the priority field, result
+        * in the priority being set to NORMAL.
+        */
        if (!amdgpu_ctx_priority_is_valid(priority))
                priority = AMDGPU_CTX_PRIORITY_NORMAL;
 

base-commit: 915718484b8fa1eede4499a939e2e4fc0d85caa4
prerequisite-patch-id: a36f628997d923f66da5342e760e8b45ff959fb8
prerequisite-patch-id: f15148c302329c0c60d86040571c61d367bd05e7 --
2.42.0

author Applied
#3 lore raw
Quoted 8 lines · Alex Deucher
Quoted 7 lines · Luben Tuikov

Remove a redundant call to amdgpu_ctx_priority_is_valid() from amdgpu_ctx_priority_permit(), which is called from amdgpu_ctx_init() which is called from amdgpu_ctx_alloc() which is called from amdgpu_ctx_ioctl(), where we've called amdgpu_ctx_priority_is_valid() already first thing in the function.

Quoted 5 lines
Quoted 3 lines
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>

Please push this to drm-misc since it depends on your previous patches.

Done!

Pushed to drm-misc-fixes, where the other two landed.

Regards,
Luben

Quoted 61 lines

Alex

Quoted 58 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +8 -7
index 68db924161ef66..4c6ffca97c4512 100644
@@ -56,6 +56,10 @@ bool amdgpu_ctx_priority_is_valid(int32_t ctx_prio)
                return true;
        default:
        case AMDGPU_CTX_PRIORITY_UNSET:
+               /* UNSET priority is not valid and we don't carry that
+                * around, but set it to NORMAL in the only place this
+                * function is called, amdgpu_ctx_ioctl().
+                */
                return false;
        }
 }
@@ -96,9 +100,6 @@ amdgpu_ctx_to_drm_sched_prio(int32_t ctx_prio)
 static int amdgpu_ctx_priority_permit(struct drm_file *filp,
                                      int32_t priority)
 {
-       if (!amdgpu_ctx_priority_is_valid(priority))
-               return -EINVAL;
-
        /* NORMAL and below are accessible by everyone */
        if (priority <= AMDGPU_CTX_PRIORITY_NORMAL)
                return 0;
@@ -625,8 +626,6 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev,
        return 0;
 }
 
-
-
 static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
                                    struct amdgpu_fpriv *fpriv, uint32_t id,
                                    bool set, u32 *stable_pstate)
@@ -669,8 +668,10 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
        id = args->in.ctx_id;
        priority = args->in.priority;
 
-       /* For backwards compatibility reasons, we need to accept
-        * ioctls with garbage in the priority field */
+       /* For backwards compatibility, we need to accept ioctls with garbage
+        * in the priority field. Garbage values in the priority field, result
+        * in the priority being set to NORMAL.
+        */
        if (!amdgpu_ctx_priority_is_valid(priority))
                priority = AMDGPU_CTX_PRIORITY_NORMAL;
 

base-commit: 915718484b8fa1eede4499a939e2e4fc0d85caa4
prerequisite-patch-id: a36f628997d923f66da5342e760e8b45ff959fb8
prerequisite-patch-id: f15148c302329c0c60d86040571c61d367bd05e7 --
2.42.0