[PATCH] add missing mutex lock to amdgpu_get_xgmi_hive()

StDenis, Tom Tom.StDenis at amd.com
Mon Jan 7 15:02:38 UTC 2019


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


On 2019-01-07 10:00 a.m., StDenis, Tom wrote:
> Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
> index 8a8bc60cb6b4..587a5f73ae8c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
> @@ -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;
>   }
>   
> 



More information about the amd-gfx mailing list