Skip to contentSkip to conversation

drm/amd/amdgpu: fix missed lock in amdgpu_gfx_profile_ring_begin_use()

PATCH In review Yang Wang 2 participants 4 messages Oct 16, 2025 – Oct 17, 2025

Subsystems (2)
lore
Share & tools
lore

Yang Wang

author
#0 lore raw

PATCH 1/1 drm/amd/amdgpu: fix missed lock in amdgpu_gfx_profile_ring_begin_use()

the gfx driver need to hold lock (adev->gfx.workload_profile_mutex) before access "adev->gfx.workload_profile_active" varible.

Fixes 9e34d8d1a1abe ("drm/amdgpu/gfx: adjust workload profile handling")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +5 -4
index 7f02e36ccc1e..59329e8ffb86 100644
@@ -2249,11 +2249,10 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
 	 * the delayed work so there is no one else to set it to false
 	 * and we don't care if someone else sets it to true.
 	 */
-	if (adev->gfx.workload_profile_active)
-		return;
-
 	mutex_lock(&adev->gfx.workload_profile_mutex);
-	if (!adev->gfx.workload_profile_active) {
+	if (adev->gfx.workload_profile_active) {
+		goto out_unlock;
+	} else {
 		r = amdgpu_dpm_switch_power_profile(adev, profile, true);
 		if (r)
 			dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
@@ -2261,6 +2260,8 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
 				 "fullscreen 3D" : "compute");
 		adev->gfx.workload_profile_active = true;
 	}
+
+out_unlock:
 	mutex_unlock(&adev->gfx.workload_profile_mutex);
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 16 lines · Yang Wang

the gfx driver need to hold lock (adev->gfx.workload_profile_mutex) before access "adev->gfx.workload_profile_active" varible.

Fixes 9e34d8d1a1abe ("drm/amdgpu/gfx: adjust workload profile handling")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index 7f02e36ccc1e..59329e8ffb86 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring) · line 2253

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -2
@@ -2249,11 +2249,10 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
         * the delayed work so there is no one else to set it to false
         * and we don't care if someone else sets it to true.
         */
-       if (adev->gfx.workload_profile_active)
-               return;

Per the comment above, this should be safe.

Alex

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +5 -3
-
        mutex_lock(&adev->gfx.workload_profile_mutex);
-       if (!adev->gfx.workload_profile_active) {
+       if (adev->gfx.workload_profile_active) {
+               goto out_unlock;
+       } else {
                r = amdgpu_dpm_switch_power_profile(adev, profile, true);
                if (r)
                        dev_warn(adev->dev, "(%d) failed to disable %s power profile mode\n", r,
@@ -2261,6 +2260,8 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
                                 "fullscreen 3D" : "compute");
                adev->gfx.workload_profile_active = true;
        }
+
+out_unlock:
        mutex_unlock(&adev->gfx.workload_profile_mutex);
 }
 
--

2.34.1

#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, October 17, 2025 2:55 AM
To: Wang, Yang(Kevin) <[email protected]>
Cc: [email protected]; Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix missed lock in amdgpu_gfx_profile_ring_begin_use()

Quoted 18 lines · Yang Wang

the gfx driver need to hold lock (adev->gfx.workload_profile_mutex) before access "adev->gfx.workload_profile_active" varible.

Fixes 9e34d8d1a1abe ("drm/amdgpu/gfx: adjust workload profile

handling")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index 7f02e36ccc1e..59329e8ffb86 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring) · line 2253

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -2
@@ -2249,11 +2249,10 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
         * the delayed work so there is no one else to set it to false
         * and we don't care if someone else sets it to true.
         */
-       if (adev->gfx.workload_profile_active)
-               return;

Per the comment above, this should be safe.

Alex

[Kevin]:
All gfx/compute kernel ring->begin_use/end_use() callback functions will be called at the same time from different threads (such as drm sched thread and ioctl user thread) there may still be some contention here, holding this lock can ensure safe access in different scenarios.

Best Regards,
Kevin

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -2
-
        mutex_lock(&adev->gfx.workload_profile_mutex);
-       if (!adev->gfx.workload_profile_active) {
+       if (adev->gfx.workload_profile_active) {
+               goto out_unlock;
+       } else {
                r = amdgpu_dpm_switch_power_profile(adev, profile, true);
                if (r)
                        dev_warn(adev->dev, "(%d) failed to disable %s

power profile mode\n", r, @@ -2261,6 +2260,8 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)

                                 "fullscreen 3D" : "compute");
                adev->gfx.workload_profile_active = true;
        }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -1
+
+out_unlock:
        mutex_unlock(&adev->gfx.workload_profile_mutex);
 }
 
--

2.34.1

#3 lore raw
Quoted 37 lines · Yang(Kevin)

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, October 17, 2025 2:55 AM
To: Wang, Yang(Kevin) <[email protected]>
Cc: [email protected]; Zhang, Hawking <[email protected]>; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amd/amdgpu: fix missed lock in amdgpu_gfx_profile_ring_begin_use()

Quoted 18 lines · Yang Wang

the gfx driver need to hold lock (adev->gfx.workload_profile_mutex) before access "adev->gfx.workload_profile_active" varible.

Fixes 9e34d8d1a1abe ("drm/amdgpu/gfx: adjust workload profile

handling")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index 7f02e36ccc1e..59329e8ffb86 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring) · line 2253

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -2
@@ -2249,11 +2249,10 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)
         * the delayed work so there is no one else to set it to false
         * and we don't care if someone else sets it to true.
         */
-       if (adev->gfx.workload_profile_active)
-               return;

Per the comment above, this should be safe.

Quoted 5 lines

Alex

[Kevin]:
All gfx/compute kernel ring->begin_use/end_use() callback functions will be called at the same time from different threads (such as drm sched thread and ioctl user thread) there may still be some contention here, holding this lock can ensure safe access in different scenarios.

There's only one worker thread and that is the only place this gets set to false. That worker is always cancelled just before this check so there should be no race. All of the places where the value is changed are locked.

Alex

Quoted 25 lines

Best Regards,
Kevin

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +3 -2
-
        mutex_lock(&adev->gfx.workload_profile_mutex);
-       if (!adev->gfx.workload_profile_active) {
+       if (adev->gfx.workload_profile_active) {
+               goto out_unlock;
+       } else {
                r = amdgpu_dpm_switch_power_profile(adev, profile, true);
                if (r)
                        dev_warn(adev->dev, "(%d) failed to disable %s

power profile mode\n", r, @@ -2261,6 +2260,8 @@ void amdgpu_gfx_profile_ring_begin_use(struct amdgpu_ring *ring)

                                 "fullscreen 3D" : "compute");
                adev->gfx.workload_profile_active = true;
        }
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -1
+
+out_unlock:
        mutex_unlock(&adev->gfx.workload_profile_mutex);
 }
 
--

2.34.1