Skip to contentSkip to conversation

drm/amdgpu: disallow multiple BO_HANDLES chunks in one submit

PATCH In review Pierre-Eric Pelloux-Prayer 3 participants 5 messages Jul 2, 2024 – Jul 4, 2024

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

PATCH 1/1 drm/amdgpu: disallow multiple BO_HANDLES chunks in one submit

Before this commit, only submits with both a BO_HANDLES chunk and a 'bo_list_handle' would be rejected (by amdgpu_cs_parser_bos).

But if UMD sent a multiple BO_HANDLES, what would happen is:
* only the last one would be really used
* all the others would leak memory as amdgpu_cs_p1_bo_handles would overwrite the previous p->bo_list value

This commit rejects submissions with multiple BO_HANDLES chunks to match the implementation of the parser.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -0
index c08dfffae262..69d168d6f35a 100644
@@ -154,6 +154,10 @@ static int amdgpu_cs_p1_bo_handles(struct amdgpu_cs_parser *p,
 	struct drm_amdgpu_bo_list_entry *info;
 	int r;
 
+	/* Disallow multiple BO_HANDLES chunks. */
+	if (p->bo_list)
+		return -EINVAL;
+
 	r = amdgpu_bo_create_list_entry_array(data, &info);
 	if (r)
 		return r;
Signature · 1 line
2.40.1
maintainer
#1 lore raw

Am 02.07.24 um 15:23 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 21 lines

Before this commit, only submits with both a BO_HANDLES chunk and a 'bo_list_handle' would be rejected (by amdgpu_cs_parser_bos).

But if UMD sent a multiple BO_HANDLES, what would happen is:
* only the last one would be really used
* all the others would leak memory as amdgpu_cs_p1_bo_handles would overwrite the previous p->bo_list value

This commit rejects submissions with multiple BO_HANDLES chunks to match the implementation of the parser.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index c08dfffae262..69d168d6f35a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_p1_bo_handles(struct amdgpu_cs_parser *p, · line 157

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
@@ -154,6 +154,10 @@ static int amdgpu_cs_p1_bo_handles(struct amdgpu_cs_parser *p,
  	struct drm_amdgpu_bo_list_entry *info;
  	int r;
 
+	/* Disallow multiple BO_HANDLES chunks. */

Describe why you do something, instead of what you do since that should be obvious from the code.

E.g. something like /* Only allow a single BO list to avoid memory leak. */

With that fixed Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -0
+	if (p->bo_list)
+		return -EINVAL;
+
  	r = amdgpu_bo_create_list_entry_array(data, &info);
  	if (r)
  		return r;
#2 lore raw

Le 02/07/2024 à 15:35, Christian König a écrit :

Quoted 29 lines

Am 02.07.24 um 15:23 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 21 lines

Before this commit, only submits with both a BO_HANDLES chunk and a 'bo_list_handle' would be rejected (by amdgpu_cs_parser_bos).

But if UMD sent a multiple BO_HANDLES, what would happen is:
* only the last one would be really used
* all the others would leak memory as amdgpu_cs_p1_bo_handles would overwrite the previous p->bo_list value

This commit rejects submissions with multiple BO_HANDLES chunks to match the implementation of the parser.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++++

  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index c08dfffae262..69d168d6f35a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_p1_bo_handles(struct · line 157

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
@@ -154,6 +154,10 @@ static int amdgpu_cs_p1_bo_handles(struct 
 amdgpu_cs_parser *p,
       struct drm_amdgpu_bo_list_entry *info;
       int r;
+    /* Disallow multiple BO_HANDLES chunks. */

Describe why you do something, instead of what you do since that should be obvious from the code.

Quoted 1 line

E.g. something like /* Only allow a single BO list to avoid memory leak. */

It's not really to avoid a memleak because the code below could be fixed
to not leak the list.
This change is really about only disallowing multiple BO_HANDLES since this is the de-facto API, except it was not validated until now.

I can rephrase the comment as /* Only a single BO list is allowed. */

Would that work?

Thanks,
Pierre-Eric

Quoted 13 lines

With that fixed Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -0
+    if (p->bo_list)
+        return -EINVAL;
+
       r = amdgpu_bo_create_list_entry_array(data, &info);
       if (r)
           return r;
maintainer
#3 lore raw

Am 03.07.24 um 14:48 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 32 lines

Le 02/07/2024 à 15:35, Christian König a écrit :

Quoted 29 lines

Am 02.07.24 um 15:23 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 21 lines

Before this commit, only submits with both a BO_HANDLES chunk and a 'bo_list_handle' would be rejected (by amdgpu_cs_parser_bos).

But if UMD sent a multiple BO_HANDLES, what would happen is:
* only the last one would be really used
* all the others would leak memory as amdgpu_cs_p1_bo_handles would overwrite the previous p->bo_list value

This commit rejects submissions with multiple BO_HANDLES chunks to match the implementation of the parser.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++++

  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index c08dfffae262..69d168d6f35a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_p1_bo_handles(struct · line 157

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
@@ -154,6 +154,10 @@ static int amdgpu_cs_p1_bo_handles(struct 
 amdgpu_cs_parser *p,
       struct drm_amdgpu_bo_list_entry *info;
       int r;
+    /* Disallow multiple BO_HANDLES chunks. */

Describe why you do something, instead of what you do since that should be obvious from the code.

Quoted 1 line

E.g. something like /* Only allow a single BO list to avoid memory leak. */

Quoted 7 lines

It's not really to avoid a memleak because the code below could be fixed
to not leak the list.
This change is really about only disallowing multiple BO_HANDLES since this is the de-facto API, except it was not validated until now.

I can rephrase the comment as /* Only a single BO list is allowed. */

Would that work?

Mhm, we still need to give a reason why only a single BO list is allowed.

Maybe "Only a single BO list is allowed to simplify handling".

I don't really see a use case for having more than one BO list, but who knows.

Regards,
Christian.

Quoted 17 lines

Thanks,
Pierre-Eric

Quoted 13 lines

With that fixed Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -0
+    if (p->bo_list)
+        return -EINVAL;
+
       r = amdgpu_bo_create_list_entry_array(data, &info);
       if (r)
           return r;
#4 lore raw

Le 03/07/2024 à 16:10, Christian König a écrit :

Quoted 37 lines

Am 03.07.24 um 14:48 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 36 lines

Le 02/07/2024 à 15:35, Christian König a écrit :

Quoted 29 lines

Am 02.07.24 um 15:23 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 21 lines

Before this commit, only submits with both a BO_HANDLES chunk and a 'bo_list_handle' would be rejected (by amdgpu_cs_parser_bos).

But if UMD sent a multiple BO_HANDLES, what would happen is:
* only the last one would be really used
* all the others would leak memory as amdgpu_cs_p1_bo_handles would overwrite the previous p->bo_list value

This commit rejects submissions with multiple BO_HANDLES chunks to match the implementation of the parser.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++++

  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index c08dfffae262..69d168d6f35a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_p1_bo_handles(struct · line 157

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
@@ -154,6 +154,10 @@ static int amdgpu_cs_p1_bo_handles(struct 
 amdgpu_cs_parser *p,
       struct drm_amdgpu_bo_list_entry *info;
       int r;
+    /* Disallow multiple BO_HANDLES chunks. */

Describe why you do something, instead of what you do since that should be obvious from the code.

Quoted 1 line

E.g. something like /* Only allow a single BO list to avoid memory leak. */

It's not really to avoid a memleak because the code below could be fixed
to not leak the list.
This change is really about only disallowing multiple BO_HANDLES since this is the de-facto API, except it was not validated until now.

Quoted 7 lines
Quoted 3 lines

I can rephrase the comment as /* Only a single BO list is allowed. */

Would that work?

Mhm, we still need to give a reason why only a single BO list is allowed.

Maybe "Only a single BO list is allowed to simplify handling".

Works for me. I'll push a version with this comment instead of the original one.

Thanks!
Pierre-Eric

Quoted 23 lines

I don't really see a use case for having more than one BO list, but who knows.

Regards,
Christian.

Quoted 17 lines

Thanks,
Pierre-Eric

Quoted 13 lines

With that fixed Reviewed-by: Christian König <[email protected]>

Regards,
Christian.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -0
+    if (p->bo_list)
+        return -EINVAL;
+
       r = amdgpu_bo_create_list_entry_array(data, &info);
       if (r)
           return r;