diff mbox series

[2/2] drm/amdgpu: raise error on incorrect mem_type

Message ID 20210629073629.3069-2-nirmoy.das@amd.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] drm/amdgpu: return early for non-TTM_PL_TT type BOs | expand

Commit Message

Das, Nirmoy June 29, 2021, 7:36 a.m. UTC
Be more defensive and raise error on wrong mem_type
argument in amdgpu_gtt_mgr_has_gart_addr().

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Christian König June 29, 2021, 11:06 a.m. UTC | #1
Am 29.06.21 um 09:36 schrieb Nirmoy Das:
> Be more defensive and raise error on wrong mem_type
> argument in amdgpu_gtt_mgr_has_gart_addr().
>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index 543000304a1c..0b0fa87b115c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -107,8 +107,12 @@ const struct attribute_group amdgpu_gtt_mgr_attr_group = {
>    */
>   bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *res)
>   {
> -	struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(res);
> +	struct amdgpu_gtt_node *node;
> +
> +	if (WARN_ON(res->mem_type != TTM_PL_TT))
> +		return false;

I'm not sure that is a good idea. The GTT manager itself shouldn't have 
to deal with incorrect usage of it's component.

Christian.

>   
> +	node = to_amdgpu_gtt_node(res);
>   	return drm_mm_node_allocated(&node->base.mm_nodes[0]);
>   }
>
Das, Nirmoy June 29, 2021, 11:43 a.m. UTC | #2
On 6/29/2021 1:06 PM, Christian König wrote:
>
>
> Am 29.06.21 um 09:36 schrieb Nirmoy Das:
>> Be more defensive and raise error on wrong mem_type
>> argument in amdgpu_gtt_mgr_has_gart_addr().
>>
>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
>> index 543000304a1c..0b0fa87b115c 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
>> @@ -107,8 +107,12 @@ const struct attribute_group 
>> amdgpu_gtt_mgr_attr_group = {
>>    */
>>   bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *res)
>>   {
>> -    struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(res);
>> +    struct amdgpu_gtt_node *node;
>> +
>> +    if (WARN_ON(res->mem_type != TTM_PL_TT))
>> +        return false;
>
> I'm not sure that is a good idea. The GTT manager itself shouldn't 
> have to deal with incorrect usage of it's component.


This is in-case we accidentally use amdgpu_gtt_mgr_has_gart_addr() for 
PREEMPT bo in future. I will drop it as the previous patch should give 
us enough hint.


Regards,

Nirmoy


>
> Christian.
>
>>   +    node = to_amdgpu_gtt_node(res);
>>       return drm_mm_node_allocated(&node->base.mm_nodes[0]);
>>   }
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 543000304a1c..0b0fa87b115c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -107,8 +107,12 @@  const struct attribute_group amdgpu_gtt_mgr_attr_group = {
  */
 bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *res)
 {
-	struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(res);
+	struct amdgpu_gtt_node *node;
+
+	if (WARN_ON(res->mem_type != TTM_PL_TT))
+		return false;
 
+	node = to_amdgpu_gtt_node(res);
 	return drm_mm_node_allocated(&node->base.mm_nodes[0]);
 }