Skip to contentSkip to conversation

drm/amdgpu/userq: Fix error codes in mes_userq_mqd_create()

PATCH In review Dan Carpenter 3 participants 4 messages Sep 18, 2025 – Sep 29, 2025

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

PATCH 1/1 drm/amdgpu/userq: Fix error codes in mes_userq_mqd_create()

Return the error code if amdgpu_userq_input_va_validate() fails. Don't return success.

Fixes 9e46b8bb0539 ("drm/amdgpu: validate userq buffer virtual address and size")
---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +9 -6
index 2db9b2c63693..775b0bd5d6c4 100644
@@ -298,8 +298,9 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 			goto free_mqd;
 		}
 
-		if (amdgpu_userq_input_va_validate(queue->vm, compute_mqd->eop_va,
-		    max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE)))
+		r = amdgpu_userq_input_va_validate(queue->vm, compute_mqd->eop_va,
+		    max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE));
+		if (r)
 			goto free_mqd;
 
 		userq_props->eop_gpu_addr = compute_mqd->eop_va;
@@ -330,8 +331,9 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 		userq_props->tmz_queue =
 			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
 
-		if (amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11->shadow_va,
-		    shadow_info.shadow_size))
+		r = amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11->shadow_va,
+		    shadow_info.shadow_size);
+		if (r)
 			goto free_mqd;
 
 		kfree(mqd_gfx_v11);
@@ -351,8 +353,9 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 			goto free_mqd;
 		}
 
-		if (amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11->csa_va,
-		    shadow_info.csa_size))
+		r = amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11->csa_va,
+		    shadow_info.csa_size);
+		if (r)
 			goto free_mqd;
 
 		userq_props->csa_addr = mqd_sdma_v11->csa_va;
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 14 lines · Dan Carpenter

Return the error code if amdgpu_userq_input_va_validate() fails. Don't return success.

Fixes 9e46b8bb0539 ("drm/amdgpu: validate userq buffer virtual address and size")
---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -0
index 2db9b2c63693..775b0bd5d6c4 100644

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, · line 302

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -2
@@ -298,8 +298,9 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 			goto free_mqd;
 		}
 
-		if (amdgpu_userq_input_va_validate(queue->vm, compute_mqd->eop_va,
-		    max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE)))
+		r = amdgpu_userq_input_va_validate(queue->vm, compute_mqd->eop_va,
+		    max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE));

That code is nonsense to begin with, AMDGPU_GPU_PAGE_SIZE is always <= PAGE_SIZE or otherwise the whole driver stack doesn't work.

We should probably drop the max_t() as well.

Regards,
Christian.

Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +7 -4
+		if (r)
 			goto free_mqd;
 
 		userq_props->eop_gpu_addr = compute_mqd->eop_va;
@@ -330,8 +331,9 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 		userq_props->tmz_queue =
 			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
 
-		if (amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11->shadow_va,
-		    shadow_info.shadow_size))
+		r = amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11->shadow_va,
+		    shadow_info.shadow_size);
+		if (r)
 			goto free_mqd;
 
 		kfree(mqd_gfx_v11);
@@ -351,8 +353,9 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 			goto free_mqd;
 		}
 
-		if (amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11->csa_va,
-		    shadow_info.csa_size))
+		r = amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11->csa_va,
+		    shadow_info.csa_size);
+		if (r)
 			goto free_mqd;
 
 		userq_props->csa_addr = mqd_sdma_v11->csa_va;
#2 lore raw

[Public]

Regards,
Prike

Quoted 45 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, September 18, 2025 5:57 PM
To: Dan Carpenter <[email protected]>; Liang, Prike <[email protected]>
Cc: Deucher, Alexander <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; Sharma, Shashank <[email protected]>; Arvind Yadav <[email protected]>; Khatri, Sunil <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Paneer Selvam, Arunpravin <[email protected]>; amd- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH next] drm/amdgpu/userq: Fix error codes in mes_userq_mqd_create()

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct

Quoted 16 lines · Dan Carpenter

Return the error code if amdgpu_userq_input_va_validate() fails. Don't return success.

Fixes 9e46b8bb0539 ("drm/amdgpu: validate userq buffer virtual

address and size")

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -0
index 2db9b2c63693..775b0bd5d6c4 100644
@@ -298,8 +298,9 @@ static int mes_userq_mqd_create(struct

amdgpu_userq_mgr *uq_mgr,

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, · line 302

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -2
                    goto free_mqd;
            }
 
-           if (amdgpu_userq_input_va_validate(queue->vm, compute_mqd-
 eop_va,
-               max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE)))
+           r = amdgpu_userq_input_va_validate(queue->vm, compute_mqd-
 eop_va,
+               max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE));
Quoted 4 lines

That code is nonsense to begin with, AMDGPU_GPU_PAGE_SIZE is always <= PAGE_SIZE or otherwise the whole driver stack doesn't work.

We should probably drop the max_t() as well.

The userq EOP buffer size is determined by the Mesa driver using dev_info->gart_page_size. Accordingly, we align the expected userq EOP size with dev_info->gart_page_size and use it to verify that the EOP buffer whether is resident within a valid mapping range.

Thanks,
Prike

Quoted 38 lines

Regards,
Christian.

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
+           if (r)
                    goto free_mqd;
            userq_props->eop_gpu_addr = compute_mqd->eop_va; @@ -330,8

+331,9

Quoted 3 lines

@@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,

            userq_props->tmz_queue =
                    mqd_user->flags &

AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct

Quoted 12 lines

- if (amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11-
shadow_va,

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -1
-               shadow_info.shadow_size))
+           r = amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11-

shadow_va,

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
+               shadow_info.shadow_size);
+           if (r)
                    goto free_mqd;
 
            kfree(mqd_gfx_v11);
@@ -351,8 +353,9 @@ static int mes_userq_mqd_create(struct

amdgpu_userq_mgr *uq_mgr,

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -2
                    goto free_mqd;
            }
 
-           if (amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11-
 csa_va,
-               shadow_info.csa_size))
+           r = amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11-
 csa_va,
+               shadow_info.csa_size);
+           if (r)
                    goto free_mqd;
            userq_props->csa_addr = mqd_sdma_v11->csa_va;
#3 lore raw

[Public]

Regards,
Prike

Quoted 69 lines

-----Original Message-----
From: Liang, Prike
Sent: Friday, September 19, 2025 10:51 AM
To: Koenig, Christian <[email protected]>; Dan Carpenter <[email protected]>
Cc: Deucher, Alexander <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; Sharma, Shashank <[email protected]>; Arvind Yadav <[email protected]>; Khatri, Sunil <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Paneer Selvam, Arunpravin <[email protected]>; amd- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: RE: [PATCH next] drm/amdgpu/userq: Fix error codes in mes_userq_mqd_create()

Regards,
Prike

Quoted 49 lines

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, September 18, 2025 5:57 PM
To: Dan Carpenter <[email protected]>; Liang, Prike <[email protected]>
Cc: Deucher, Alexander <[email protected]>; David Airlie <[email protected]>; Simona Vetter <[email protected]>; Sharma, Shashank <[email protected]>; Arvind Yadav <[email protected]>; Khatri, Sunil <[email protected]>; Zhang, Jesse(Jie) <[email protected]>; Paneer Selvam, Arunpravin <[email protected]>; amd- [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH next] drm/amdgpu/userq: Fix error codes in mes_userq_mqd_create()

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct

Quoted 16 lines · Dan Carpenter

Return the error code if amdgpu_userq_input_va_validate() fails. Don't return success.

Fixes 9e46b8bb0539 ("drm/amdgpu: validate userq buffer virtual

address and size")

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -0
index 2db9b2c63693..775b0bd5d6c4 100644
@@ -298,8 +298,9 @@ static int mes_userq_mqd_create(struct

amdgpu_userq_mgr *uq_mgr,

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr, · line 302

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -2
                  goto free_mqd;
          }
 
-         if (amdgpu_userq_input_va_validate(queue->vm, compute_mqd-
 eop_va,
-             max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE)))
+         r = amdgpu_userq_input_va_validate(queue->vm, compute_mqd-
 eop_va,
+             max_t(u32, PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE));

That code is nonsense to begin with, AMDGPU_GPU_PAGE_SIZE is always <= PAGE_SIZE or otherwise the whole driver stack doesn't work.

Quoted 7 lines
Quoted 1 line

We should probably drop the max_t() as well.

The userq EOP buffer size is determined by the Mesa driver using dev_info-

Quoted 1 line

gart_page_size.

Accordingly, we align the expected userq EOP size with dev_info->gart_page_size and use it to verify that the EOP buffer whether is resident within a valid mapping range.

We could assign the return code inline in the if() condition. I’ll incorporate this and make it explicit in the following VA track patch sets.

Regards,
Prike

Quoted 40 lines

Thanks,
Prike

Quoted 38 lines

Regards,
Christian.

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
+         if (r)
                  goto free_mqd;
          userq_props->eop_gpu_addr = compute_mqd->eop_va; @@ -330,8

+331,9

Quoted 3 lines

@@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,

          userq_props->tmz_queue =
                  mqd_user->flags &

AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct

Quoted 12 lines

- if (amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11-
shadow_va,

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -1
-             shadow_info.shadow_size))
+         r = amdgpu_userq_input_va_validate(queue->vm, mqd_gfx_v11-

shadow_va,

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -0
+             shadow_info.shadow_size);
+         if (r)
                  goto free_mqd;
 
          kfree(mqd_gfx_v11);
@@ -351,8 +353,9 @@ static int mes_userq_mqd_create(struct

amdgpu_userq_mgr *uq_mgr,

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -2
                  goto free_mqd;
          }
 
-         if (amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11-
 csa_va,
-             shadow_info.csa_size))
+         r = amdgpu_userq_input_va_validate(queue->vm, mqd_sdma_v11-
 csa_va,
+             shadow_info.csa_size);
+         if (r)
                  goto free_mqd;
          userq_props->csa_addr = mqd_sdma_v11->csa_va;