Skip to contentSkip to conversation

drm/amdgpu: ensure all userq VAs mapped before restore

PATCH In review Zhu Lingshan 3 participants 4 messages Jul 23 – Aug 12

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

PATCH 1/1 drm/amdgpu: ensure all userq VAs mapped before restore

amdgpu_userq_buffer_vas_mapped() checks whether all VAs of a queue are mapped before restoring it.
So that HW won't access any invalid addresses.

Currently, this function assumes all VAs are mapped if any VA of a queue has been mapped, which is wrong.

This commit fixes this problem by examining all VAs of a queue and reporting false if any of them is not mapped.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +9 -7
index 3fe10d6af757..2b3cb4ec4835 100644
@@ -280,22 +280,24 @@ static bool amdgpu_userq_buffer_va_mapped(struct amdgpu_vm *vm, u64 addr)
 
 static bool amdgpu_userq_buffer_vas_mapped(struct amdgpu_usermode_queue *queue)
 {
-	int i, r = 0;
+	int i;
+	bool mapped;
 
 	for (i = 0; i < ARRAY_SIZE(queue->userq_vas.va_array); i++) {
 		if (!queue->userq_vas.va_array[i])
 			continue;
-		r += amdgpu_userq_buffer_va_mapped(queue->vm,
+
+		mapped = amdgpu_userq_buffer_va_mapped(queue->vm,
 						   queue->userq_vas.va_array[i]);
 		dev_dbg(queue->userq_mgr->adev->dev,
 			"validate the userq mapping:%p va:%llx r:%d\n",
-			queue, queue->userq_vas.va_array[i], r);
-	}
+			queue, queue->userq_vas.va_array[i], mapped);
 
-	if (r != 0)
-		return true;
+		if (!mapped)
+			return false;
+	}
 
-	return false;
+	return true;
 }
 
 
Signature · 1 line
2.53.0
Reviewed-by Sunil Khatri on v1 1/1
#1 lore raw
Quoted 51 lines · Zhu Lingshan

amdgpu_userq_buffer_vas_mapped() checks whether all VAs of a queue are mapped before restoring it.
So that HW won't access any invalid addresses.

Currently, this function assumes all VAs are mapped if any VA of a queue has been mapped, which is wrong.

This commit fixes this problem by examining all VAs of a queue and reporting false if any of them is not mapped.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +9 -7
index 3fe10d6af757..2b3cb4ec4835 100644
@@ -280,22 +280,24 @@ static bool amdgpu_userq_buffer_va_mapped(struct amdgpu_vm *vm, u64 addr)
 
  static bool amdgpu_userq_buffer_vas_mapped(struct amdgpu_usermode_queue *queue)
  {
-	int i, r = 0;
+	int i;
+	bool mapped;
 
  	for (i = 0; i < ARRAY_SIZE(queue->userq_vas.va_array); i++) {
  		if (!queue->userq_vas.va_array[i])
  			continue;
-		r += amdgpu_userq_buffer_va_mapped(queue->vm,
+
+		mapped = amdgpu_userq_buffer_va_mapped(queue->vm,
  						   queue->userq_vas.va_array[i]);
  		dev_dbg(queue->userq_mgr->adev->dev,
  			"validate the userq mapping:%p va:%llx r:%d\n",
-			queue, queue->userq_vas.va_array[i], r);
-	}
+			queue, queue->userq_vas.va_array[i], mapped);
 
-	if (r != 0)
-		return true;
+		if (!mapped)
+			return false;
+	}
 
-	return false;
+	return true;
  }
 
 
#2 lore raw

Ping Christian and Alex

I may still need the maintainer's comments to merge this patch.

Thanks
Lingshan

Quoted 52 lines · Sunil
Quoted 49 lines · Zhu Lingshan

amdgpu_userq_buffer_vas_mapped() checks whether all VAs of a queue are mapped before restoring it.
So that HW won't access any invalid addresses.

Currently, this function assumes all VAs are mapped if any VA of a queue has been mapped, which is wrong.

This commit fixes this problem by examining all VAs of a queue and reporting false if any of them is not mapped.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 +++++++++-------

  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0 -0
index 3fe10d6af757..2b3cb4ec4835 100644
@@ -280,22 +280,24 @@ static bool
 amdgpu_userq_buffer_va_mapped(struct amdgpu_vm *vm, u64 addr)

    static bool amdgpu_userq_buffer_vas_mapped(struct amdgpu_usermode_queue *queue)
  {
-    int i, r = 0;
+    int i;
+    bool mapped;
        for (i = 0; i < ARRAY_SIZE(queue->userq_vas.va_array); i++) { if (!queue->userq_vas.va_array[i])
              continue;
-        r += amdgpu_userq_buffer_va_mapped(queue->vm,
+
+        mapped = amdgpu_userq_buffer_va_mapped(queue->vm, queue->userq_vas.va_array[i]); dev_dbg(queue->userq_mgr->adev->dev,
              "validate the userq mapping:%p va:%llx r:%d\n", -            queue, queue->userq_vas.va_array[i], r);
-    }
+            queue, queue->userq_vas.va_array[i], mapped); -    if (r != 0)
-        return true;
+        if (!mapped)
+            return false;
+    }
  -    return false;
+    return true;
  }

#3 lore raw
Quoted 4 lines · Lingshan

Ping Christian and Alex

I may still need the maintainer's comments to merge this patch.

You can go ahead with Sunil's RB.

Thanks!

Alex

Quoted 56 lines

Thanks
Lingshan

On 7/23/2026 7:17 PM, Khatri, Sunil wrote:

On 23-07-2026 01:53 pm, Zhu Lingshan wrote:

amdgpu_userq_buffer_vas_mapped() checks whether all VAs of a queue are mapped before restoring it.
So that HW won't access any invalid addresses.

Currently, this function assumes all VAs are mapped if any VA of a queue has been mapped, which is wrong.

This commit fixes this problem by examining all VAs of a queue and reporting false if any of them is not mapped.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 +++++++++-------
  1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +9 -5
index 3fe10d6af757..2b3cb4ec4835 100644
@@ -280,22 +280,24 @@ static bool amdgpu_userq_buffer_va_mapped(struct amdgpu_vm *vm, u64 addr)
    static bool amdgpu_userq_buffer_vas_mapped(struct amdgpu_usermode_queue *queue)
  {
-    int i, r = 0;
+    int i;
+    bool mapped;
        for (i = 0; i < ARRAY_SIZE(queue->userq_vas.va_array); i++) {
          if (!queue->userq_vas.va_array[i])
              continue;
-        r += amdgpu_userq_buffer_va_mapped(queue->vm,
+
+        mapped = amdgpu_userq_buffer_va_mapped(queue->vm,
                             queue->userq_vas.va_array[i]);
          dev_dbg(queue->userq_mgr->adev->dev,
              "validate the userq mapping:%p va:%llx r:%d\n",
-            queue, queue->userq_vas.va_array[i], r);
-    }
+            queue, queue->userq_vas.va_array[i], mapped);
  -    if (r != 0)
-        return true;
+        if (!mapped)
+            return false;
+    }
  -    return false;
+    return true;
  }