Skip to contentSkip to conversation

drm/amdgpu: return early for non-TTM_PL_TT type BOs

PATCH Superseded Nirmoy Das 2 participants 6 messages Jun 29, 2021

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH v2 1/2 drm/amdgpu: return early for non-TTM_PL_TT type BOs

Return early for non-TTM_PL_TT BOs so that we don't pass wrong pointer to amdgpu_gtt_mgr_has_gart_addr() which assumes ttm_resource argument to be TTM_PL_TT type BO's.

v2: merge if-conditions

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index b46726e47bce..208bc3ec1aff 100644
@@ -926,7 +926,8 @@ static int amdgpu_ttm_backend_bind(struct ttm_device *bdev,
 	    bo_mem->mem_type == AMDGPU_PL_OA)
 		return -EINVAL;
 
-	if (!amdgpu_gtt_mgr_has_gart_addr(bo_mem)) {
+	if ((bo_mem->mem_type != TTM_PL_TT) ||
+	    !amdgpu_gtt_mgr_has_gart_addr(bo_mem)) {
 		gtt->offset = AMDGPU_BO_INVALID_OFFSET;
 		return 0;
 	}

--
2.32.0

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

author
#1 lore raw

PATCH 2/2 drm/amdgpu: raise error on incorrect mem_type

Be more defensive and raise error on wrong mem_type argument in amdgpu_gtt_mgr_has_gart_addr().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +5 -1
index 543000304a1c..0b0fa87b115c 100644
@@ -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]);
 }
 
Signature · 6 lines
2.32.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#2 lore raw

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

Am 29.06.21 um 09:36 schrieb Nirmoy Das:

Quoted 13 lines

Be more defensive and raise error on wrong mem_type argument in amdgpu_gtt_mgr_has_gart_addr().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +0 -0
index 543000304a1c..0b0fa87b115c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c const struct attribute_group amdgpu_gtt_mgr_attr_group = { · line 113

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +4 -1
@@ -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.

drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c const struct attribute_group amdgpu_gtt_mgr_attr_group = { · line 118

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +1 -0
+	node = to_amdgpu_gtt_node(res);
  	return drm_mm_node_allocated(&node->base.mm_nodes[0]);
  }
 

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

#3 lore raw

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

Quoted 11 lines · Christian König

Am 29.06.21 um 09:36 schrieb Nirmoy Das:

Quoted 8 lines

Be more defensive and raise error on wrong mem_type argument in amdgpu_gtt_mgr_has_gart_addr().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +0 -0
index 543000304a1c..0b0fa87b115c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c const struct attribute_group · line 114

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +4 -1
@@ -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

Quoted 7 lines

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +0 -0
   +    node = to_amdgpu_gtt_node(res);
       return drm_mm_node_allocated(&node->base.mm_nodes[0]);
   }
maintainer
#4 lore raw
In reply to Nirmoy Das

Am 29.06.21 um 09:36 schrieb Nirmoy Das:

Quoted 17 lines

Return early for non-TTM_PL_TT BOs so that we don't pass wrong pointer to amdgpu_gtt_mgr_has_gart_addr() which assumes ttm_resource argument to be TTM_PL_TT type BO's.

v2: merge if-conditions

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index b46726e47bce..208bc3ec1aff 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_backend_bind(struct ttm_device *bdev, · line 929

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
@@ -926,7 +926,8 @@ static int amdgpu_ttm_backend_bind(struct ttm_device *bdev,
  	    bo_mem->mem_type == AMDGPU_PL_OA)
  		return -EINVAL;
 
-	if (!amdgpu_gtt_mgr_has_gart_addr(bo_mem)) {
+	if ((bo_mem->mem_type != TTM_PL_TT) ||

Please drop the extra (), apart from that the patch is Reviewed-by: Christian König <[email protected]>

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
+	    !amdgpu_gtt_mgr_has_gart_addr(bo_mem)) {
  		gtt->offset = AMDGPU_BO_INVALID_OFFSET;
  		return 0;
  	}
--

2.32.0

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

#5 lore raw
Quoted 22 lines · Christian König

Am 29.06.21 um 09:36 schrieb Nirmoy Das:

Quoted 21 lines

Return early for non-TTM_PL_TT BOs so that we don't pass wrong pointer to amdgpu_gtt_mgr_has_gart_addr() which assumes ttm_resource argument to be TTM_PL_TT type BO's.

v2: merge if-conditions

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index b46726e47bce..208bc3ec1aff 100644
@@ -926,7 +926,8 @@ static int amdgpu_ttm_backend_bind(struct 
 ttm_device *bdev,
           bo_mem->mem_type == AMDGPU_PL_OA)
           return -EINVAL;
 
Quoted 4 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_backend_bind(struct ttm_device *bdev, · line 929

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
-    if (!amdgpu_gtt_mgr_has_gart_addr(bo_mem)) {
+    if ((bo_mem->mem_type != TTM_PL_TT) ||

Please drop the extra (), apart from that the patch is Reviewed-by: Christian König <[email protected]>

Thanks, I will send a next revision.

Nirmoy

Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
+ !amdgpu_gtt_mgr_has_gart_addr(bo_mem)) {
           gtt->offset = AMDGPU_BO_INVALID_OFFSET;
           return 0;

      }

Signature · 1 line
2.32.0

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