Skip to contentSkip to conversation

drm/amdgpu: Add missing locking for MES API calls

PATCH In review Mukul Joshi 2 participants 4 messages Jun 6, 2024

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

PATCH 1/1 drm/amdgpu: Add missing locking for MES API calls

Add missing locking at a few places when calling MES APIs to ensure exclusive access to MES queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +12 -0
index 62edf6328566..df6c067b1dc9 100644
@@ -801,7 +801,9 @@ int amdgpu_mes_map_legacy_queue(struct amdgpu_device *adev,
 	queue_input.mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
 	queue_input.wptr_addr = ring->wptr_gpu_addr;
 
+	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->map_legacy_queue(&adev->mes, &queue_input);
+	amdgpu_mes_unlock(&adev->mes);
 	if (r)
 		DRM_ERROR("failed to map legacy queue\n");
 
@@ -824,7 +826,9 @@ int amdgpu_mes_unmap_legacy_queue(struct amdgpu_device *adev,
 	queue_input.trail_fence_addr = gpu_addr;
 	queue_input.trail_fence_data = seq;
 
+	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->unmap_legacy_queue(&adev->mes, &queue_input);
+	amdgpu_mes_unlock(&adev->mes);
 	if (r)
 		DRM_ERROR("failed to unmap legacy queue\n");
 
@@ -845,11 +849,13 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg)
 		goto error;
 	}
 
+	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
 	if (r)
 		DRM_ERROR("failed to read reg (0x%x)\n", reg);
 	else
 		val = *(adev->mes.read_val_ptr);
+	amdgpu_mes_unlock(&adev->mes);
 
 error:
 	return val;
@@ -871,7 +877,9 @@ int amdgpu_mes_wreg(struct amdgpu_device *adev,
 		goto error;
 	}
 
+	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+	amdgpu_mes_unlock(&adev->mes);
 	if (r)
 		DRM_ERROR("failed to write reg (0x%x)\n", reg);
 
@@ -898,7 +906,9 @@ int amdgpu_mes_reg_write_reg_wait(struct amdgpu_device *adev,
 		goto error;
 	}
 
+	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+	amdgpu_mes_unlock(&adev->mes);
 	if (r)
 		DRM_ERROR("failed to reg_write_reg_wait\n");
 
@@ -923,7 +933,9 @@ int amdgpu_mes_reg_wait(struct amdgpu_device *adev, uint32_t reg,
 		goto error;
 	}
 
+	amdgpu_mes_lock(&adev->mes);
 	r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+	amdgpu_mes_unlock(&adev->mes);
 	if (r)
 		DRM_ERROR("failed to reg_write_reg_wait\n");
 
Signature · 1 line
2.35.1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 47 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mukul Joshi
Sent: Thursday, June 6, 2024 12:51 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: [PATCH] drm/amdgpu: Add missing locking for MES API calls

Add missing locking at a few places when calling MES APIs to ensure exclusive access to MES queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +4 -0
index 62edf6328566..df6c067b1dc9 100644
@@ -801,7 +801,9 @@ int amdgpu_mes_map_legacy_queue(struct
 amdgpu_device *adev,
      queue_input.mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
      queue_input.wptr_addr = ring->wptr_gpu_addr;
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->map_legacy_queue(&adev->mes, &queue_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to map legacy queue\n");
@@ -824,7 +826,9 @@ int amdgpu_mes_unmap_legacy_queue(struct
 amdgpu_device *adev,
      queue_input.trail_fence_addr = gpu_addr;
      queue_input.trail_fence_data = seq;
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->unmap_legacy_queue(&adev->mes,
 &queue_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to unmap legacy queue\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +0 -0
@@ -845,11 +849,13 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device
 *adev, uint32_t reg)

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c uint32_t amdgpu_mes_rreg(struct amdgpu_device · line 859

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +2 -0
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
      if (r)
              DRM_ERROR("failed to read reg (0x%x)\n", reg);
      else
              val = *(adev->mes.read_val_ptr);
+     amdgpu_mes_unlock(&adev->mes);

If we're following the pattern, this should go before the if/else block

Kent

Quoted 37 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +6 -1
 error:
      return val;
@@ -871,7 +877,9 @@ int amdgpu_mes_wreg(struct amdgpu_device *adev,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to write reg (0x%x)\n", reg);
 
@@ -898,7 +906,9 @@ int amdgpu_mes_reg_write_reg_wait(struct
 amdgpu_device *adev,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to reg_write_reg_wait\n");
@@ -923,7 +933,9 @@ int amdgpu_mes_reg_wait(struct amdgpu_device *adev,
 uint32_t reg,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to reg_write_reg_wait\n");
 
--

2.35.1

#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 68 lines

-----Original Message-----
From: Russell, Kent <[email protected]>
Sent: Thursday, June 6, 2024 12:57 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Add missing locking for MES API calls

[AMD Official Use Only - AMD Internal Distribution Only]

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c uint32_t amdgpu_mes_rreg(struct

Quoted 46 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mukul Joshi
Sent: Thursday, June 6, 2024 12:51 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: [PATCH] drm/amdgpu: Add missing locking for MES API calls

Add missing locking at a few places when calling MES APIs to ensure exclusive access to MES queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +4 -0
index 62edf6328566..df6c067b1dc9 100644
@@ -801,7 +801,9 @@ int amdgpu_mes_map_legacy_queue(struct
 amdgpu_device *adev,
      queue_input.mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
      queue_input.wptr_addr = ring->wptr_gpu_addr;
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->map_legacy_queue(&adev->mes, &queue_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to map legacy queue\n");
@@ -824,7 +826,9 @@ int amdgpu_mes_unmap_legacy_queue(struct
 amdgpu_device *adev,
      queue_input.trail_fence_addr = gpu_addr;
      queue_input.trail_fence_data = seq;
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->unmap_legacy_queue(&adev->mes,
 &queue_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to unmap legacy queue\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +0 -0
@@ -845,11 +849,13 @@ uint32_t amdgpu_mes_rreg(struct

amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg) · line 858

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +2 -0
 *adev, uint32_t reg)
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
      if (r)
              DRM_ERROR("failed to read reg (0x%x)\n", reg);
      else
              val = *(adev->mes.read_val_ptr);
+     amdgpu_mes_unlock(&adev->mes);
Quoted 3 lines

If we're following the pattern, this should go before the if/else block

Kent

I wanted to make sure read_val_ptr wasn't updated before its value was read. That's the reason to put the unlock after fetching the read_val_ptr.

Mukul

Quoted 40 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c int amdgpu_mes_wreg(struct amdgpu_device

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +0 -0
 error:
      return val;
@@ -871,7 +877,9 @@ int amdgpu_mes_wreg(struct amdgpu_device

*adev,

Quoted 33 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +6 -1
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to write reg (0x%x)\n", reg);
 
@@ -898,7 +906,9 @@ int amdgpu_mes_reg_write_reg_wait(struct
 amdgpu_device *adev,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to reg_write_reg_wait\n");
@@ -923,7 +933,9 @@ int amdgpu_mes_reg_wait(struct amdgpu_device
 *adev, uint32_t reg,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to reg_write_reg_wait\n");
 
--

2.35.1

Reviewed-by
#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Perfect, thanks for explaining. It's fine then

Quoted 127 lines

-----Original Message-----
From: Joshi, Mukul <[email protected]>
Sent: Thursday, June 6, 2024 1:11 PM
To: Russell, Kent <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Add missing locking for MES API calls

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 68 lines

-----Original Message-----
From: Russell, Kent <[email protected]>
Sent: Thursday, June 6, 2024 12:57 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: Add missing locking for MES API calls

[AMD Official Use Only - AMD Internal Distribution Only]

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c uint32_t amdgpu_mes_rreg(struct

Quoted 46 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Mukul Joshi
Sent: Thursday, June 6, 2024 12:51 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Deucher, Alexander <[email protected]>; Joshi, Mukul <[email protected]>
Subject: [PATCH] drm/amdgpu: Add missing locking for MES API calls

Add missing locking at a few places when calling MES APIs to ensure exclusive access to MES queue.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +4 -0
index 62edf6328566..df6c067b1dc9 100644
@@ -801,7 +801,9 @@ int amdgpu_mes_map_legacy_queue(struct
 amdgpu_device *adev,
      queue_input.mqd_addr = amdgpu_bo_gpu_offset(ring->mqd_obj);
      queue_input.wptr_addr = ring->wptr_gpu_addr;
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->map_legacy_queue(&adev->mes, &queue_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to map legacy queue\n");
@@ -824,7 +826,9 @@ int amdgpu_mes_unmap_legacy_queue(struct
 amdgpu_device *adev,
      queue_input.trail_fence_addr = gpu_addr;
      queue_input.trail_fence_data = seq;
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->unmap_legacy_queue(&adev->mes,
 &queue_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to unmap legacy queue\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +0 -0
@@ -845,11 +849,13 @@ uint32_t amdgpu_mes_rreg(struct

amdgpu_device

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg) · line 858

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +2 -0
 *adev, uint32_t reg)
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
      if (r)
              DRM_ERROR("failed to read reg (0x%x)\n", reg);
      else
              val = *(adev->mes.read_val_ptr);
+     amdgpu_mes_unlock(&adev->mes);
Quoted 3 lines

If we're following the pattern, this should go before the if/else block

Kent

I wanted to make sure read_val_ptr wasn't updated before its value was read. That's the reason to put the unlock after fetching the read_val_ptr.

Mukul

Quoted 40 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c int amdgpu_mes_wreg(struct amdgpu_device

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +0 -0
 error:
      return val;
@@ -871,7 +877,9 @@ int amdgpu_mes_wreg(struct amdgpu_device

*adev,

Quoted 33 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +6 -1
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to write reg (0x%x)\n", reg);
 
@@ -898,7 +906,9 @@ int amdgpu_mes_reg_write_reg_wait(struct
 amdgpu_device *adev,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to reg_write_reg_wait\n");
@@ -923,7 +933,9 @@ int amdgpu_mes_reg_wait(struct amdgpu_device
 *adev, uint32_t reg,
              goto error;
      }
 
+     amdgpu_mes_lock(&adev->mes);
      r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
      if (r)
              DRM_ERROR("failed to reg_write_reg_wait\n");
 
--

2.35.1