Skip to contentSkip to conversation

add missing mutex lock to amdgpu_get_xgmi_hive()

PATCH In review StDenis, Tom 1 participant 2 messages Jan 7, 2019 1 message not in the archive

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

PATCH 1/1 add missing mutex lock to amdgpu_get_xgmi_hive()

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +11 -2
index 8a8bc60cb6b4..587a5f73ae8c 100644
@@ -47,13 +47,20 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 
 	if (!adev->gmc.xgmi.hive_id)
 		return NULL;
+
+	mutex_lock(&xgmi_mutex);
+
 	for (i = 0 ; i < hive_count; ++i) {
 		tmp = &xgmi_hives[i];
-		if (tmp->hive_id == adev->gmc.xgmi.hive_id)
+		if (tmp->hive_id == adev->gmc.xgmi.hive_id) {
+			mutex_unlock(&xgmi_mutex);
 			return tmp;
+		}
 	}
-	if (i >= AMDGPU_MAX_XGMI_HIVE)
+	if (i >= AMDGPU_MAX_XGMI_HIVE) {
+		mutex_unlock(&xgmi_mutex);
 		return NULL;
+	}
 
 	/* initialize new hive if not exist */
 	tmp = &xgmi_hives[hive_count++];
@@ -61,6 +68,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 	INIT_LIST_HEAD(&tmp->device_list);
 	mutex_init(&tmp->hive_lock);
 
+	mutex_unlock(&xgmi_mutex);
+
 	return tmp;
 }
 
Signature · 6 lines
2.17.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Self NAK this ... calling functions take the same lock....

We should remove the locks from the callers so this function is thread safe on its own...

Tom

Quoted 34 lines · Tom
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +9 -2
index 8a8bc60cb6b4..587a5f73ae8c 100644
@@ -47,13 +47,20 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
 
  	if (!adev->gmc.xgmi.hive_id)
  		return NULL;
+
+	mutex_lock(&xgmi_mutex);
+
  	for (i = 0 ; i < hive_count; ++i) {
  		tmp = &xgmi_hives[i];
-		if (tmp->hive_id == adev->gmc.xgmi.hive_id)
+		if (tmp->hive_id == adev->gmc.xgmi.hive_id) {
+			mutex_unlock(&xgmi_mutex);
  			return tmp;
+		}
  	}
-	if (i >= AMDGPU_MAX_XGMI_HIVE)
+	if (i >= AMDGPU_MAX_XGMI_HIVE) {
+		mutex_unlock(&xgmi_mutex);
  		return NULL;
+	}
 
  	/* initialize new hive if not exist */
  	tmp = &xgmi_hives[hive_count++];

drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) · line 75

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +2 -0
@@ -61,6 +68,8 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
  	INIT_LIST_HEAD(&tmp->device_list);
  	mutex_init(&tmp->hive_lock);
 
+	mutex_unlock(&xgmi_mutex);
+
  	return tmp;
  }
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx