Skip to contentSkip to conversation

drm/amdgpu: prevent BO_HANDLES error from being overwritten

PATCH Superseded Mohammed Anees 3 participants 4 messages Oct 4, 2024 – Oct 9, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: prevent BO_HANDLES error from being overwritten

Before this patch, if multiple BO_HANDLES chunks were submitted, the error -EINVAL would be correctly set but could be overwritten by the return value from amdgpu_cs_p1_bo_handles(). This patch ensures that once an error condition is detected, the function returns immediately, avoiding the overwriting of the error code.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
index 1e475eb01417..543db0df9a31 100644
@@ -266,8 +266,9 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
 			/* Only a single BO list is allowed to simplify handling. */
 			if (p->bo_list)
 				ret = -EINVAL;
+			else
+				ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);
 
-			ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);
 			if (ret)
 				goto free_partial_kdata;
 			break;
Signature · 1 line
2.46.0
#1 lore raw

Hi,

Le 05/10/2024 à 01:59, Mohammed Anees a écrit :

Quoted 16 lines

Before this patch, if multiple BO_HANDLES chunks were submitted, the error -EINVAL would be correctly set but could be overwritten by the return value from amdgpu_cs_p1_bo_handles(). This patch ensures that once an error condition is detected, the function returns immediately, avoiding the overwriting of the error code.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 1e475eb01417..543db0df9a31 100644

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

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -1
@@ -266,8 +266,9 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
  			/* Only a single BO list is allowed to simplify handling. */
  			if (p->bo_list)
  				ret = -EINVAL;
+			else
+				ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);
 
-			ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);

My bad, I've merged the wrong version of the patch.

That being said, I think it'd be nicer to follow the same pattern as the other checks and do:

if (p->bo_list)

      goto free_partial_kdata;

Since "ret" is initialized to -EINVAL already.

Also can you add a reference to the broken commit in the commit message? Something like:

Fixes fec5f8e8c6bcf83 ("drm/amdgpu: disallow multiple BO_HANDLES chunks in one submit")

Thanks,
Pierre-Eric

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
  			if (ret)
  				goto free_partial_kdata;
  			break;
maintainer
#2 lore raw

Am 09.10.24 um 10:22 schrieb Pierre-Eric Pelloux-Prayer:

Quoted 34 lines

Hi,

Le 05/10/2024 à 01:59, Mohammed Anees a écrit :

Quoted 16 lines

Before this patch, if multiple BO_HANDLES chunks were submitted, the error -EINVAL would be correctly set but could be overwritten by the return value from amdgpu_cs_p1_bo_handles(). This patch ensures that once an error condition is detected, the function returns immediately, avoiding the overwriting of the error code.

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

  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index 1e475eb01417..543db0df9a31 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_pass1(struct · line 272

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -0
@@ -266,8 +266,9 @@ static int amdgpu_cs_pass1(struct 
 amdgpu_cs_parser *p,
               /* Only a single BO list is allowed to simplify handling. */
               if (p->bo_list)
                   ret = -EINVAL;
+            else
+                ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);
   -            ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);

My bad, I've merged the wrong version of the patch.

That being said, I think it'd be nicer to follow the same pattern as the other checks and do:

   if (p->bo_list)
      goto free_partial_kdata;

Quoted 6 lines

Since "ret" is initialized to -EINVAL already.

Also can you add a reference to the broken commit in the commit message? Something like:

Fixes fec5f8e8c6bcf83 ("drm/amdgpu: disallow multiple BO_HANDLES chunks in one submit")

Yeah agree with Pierre-Eric and also please add the same CC stable tag the original patch had so that it gets backported ASAP.

Thanks,
Christian.

Quoted 7 lines

Thanks,
Pierre-Eric

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
               if (ret)
                   goto free_partial_kdata;

              break;