Skip to contentSkip to conversation

drm/amdkfd: relax checks for over allocation of save area

PATCH In review Jonathan Kim 2 participants 3 messages Nov 8, 2025 – Nov 10, 2025

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

PATCH 1/1 drm/amdkfd: relax checks for over allocation of save area

Over allocation of save area is not fatal, only under allocation is. ROCm has various components that independently claim authority over save area size.

Unless KFD decides to claim single authority, relax size checks.

v2: remove warning

---
 drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_queue.c +6 -6
index a65c67cf56ff..f1e7583650c4 100644
@@ -297,16 +297,16 @@ int kfd_queue_acquire_buffers(struct kfd_process_device *pdd, struct queue_prope
 		goto out_err_unreserve;
 	}
 
-	if (properties->ctx_save_restore_area_size != topo_dev->node_props.cwsr_size) {
-		pr_debug("queue cwsr size 0x%x not equal to node cwsr size 0x%x\n",
+	if (properties->ctx_save_restore_area_size < topo_dev->node_props.cwsr_size) {
+		pr_debug("queue cwsr size 0x%x not sufficient for node cwsr size 0x%x\n",
 			properties->ctx_save_restore_area_size,
 			topo_dev->node_props.cwsr_size);
 		err = -EINVAL;
 		goto out_err_unreserve;
 	}
 
-	total_cwsr_size = (topo_dev->node_props.cwsr_size + topo_dev->node_props.debug_memory_size)
-			  * NUM_XCC(pdd->dev->xcc_mask);
+	total_cwsr_size = (properties->ctx_save_restore_area_size +
+			   topo_dev->node_props.debug_memory_size) * NUM_XCC(pdd->dev->xcc_mask);
 	total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE);
 
 	err = kfd_queue_buffer_get(vm, (void *)properties->ctx_save_restore_area_address,
@@ -352,8 +352,8 @@ int kfd_queue_release_buffers(struct kfd_process_device *pdd, struct queue_prope
 	topo_dev = kfd_topology_device_by_id(pdd->dev->id);
 	if (!topo_dev)
 		return -EINVAL;
-	total_cwsr_size = (topo_dev->node_props.cwsr_size + topo_dev->node_props.debug_memory_size)
-			  * NUM_XCC(pdd->dev->xcc_mask);
+	total_cwsr_size = (properties->ctx_save_restore_area_size +
+			   topo_dev->node_props.debug_memory_size) * NUM_XCC(pdd->dev->xcc_mask);
 	total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE);
 
 	kfd_queue_buffer_svm_put(pdd, properties->ctx_save_restore_area_address, total_cwsr_size);
Signature · 1 line
2.34.1
#1 lore raw

[Public]

Ping

Quoted 73 lines

-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Friday, November 7, 2025 7:57 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Six, Lancelot <[email protected]>; Yang, Philip <[email protected]>; Kim, Jonathan <[email protected]>
Subject: [PATCH] drm/amdkfd: relax checks for over allocation of save area

Over allocation of save area is not fatal, only under allocation is. ROCm has various components that independently claim authority over save area size.

Unless KFD decides to claim single authority, relax size checks.

v2: remove warning

---
 drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_queue.c +0 -0
index a65c67cf56ff..f1e7583650c4 100644
@@ -297,16 +297,16 @@ int kfd_queue_acquire_buffers(struct

kfd_process_device *pdd, struct queue_prope

              goto out_err_unreserve;
      }

- if (properties->ctx_save_restore_area_size != topo_dev-

Quoted 1 line

node_props.cwsr_size) {

- pr_debug("queue cwsr size 0x%x not equal to node cwsr size
0x%x\n",
+ if (properties->ctx_save_restore_area_size < topo_dev-

Quoted 1 line

node_props.cwsr_size) {

+ pr_debug("queue cwsr size 0x%x not sufficient for node cwsr size
0x%x\n",

                      properties->ctx_save_restore_area_size,
                      topo_dev->node_props.cwsr_size);
              err = -EINVAL;
              goto out_err_unreserve;
      }

- total_cwsr_size = (topo_dev->node_props.cwsr_size + topo_dev-

Quoted 1 line

node_props.debug_memory_size)

drivers/gpu/drm/amd/amdkfd/kfd_queue.c +2 -1
-                       * NUM_XCC(pdd->dev->xcc_mask);
+     total_cwsr_size = (properties->ctx_save_restore_area_size +
+                        topo_dev->node_props.debug_memory_size) *

NUM_XCC(pdd->dev->xcc_mask);
total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE);

err = kfd_queue_buffer_get(vm, (void *)properties-

Quoted 1 line

ctx_save_restore_area_address,

drivers/gpu/drm/amd/amdkfd/kfd_queue.c +2 -2
@@ -352,8 +352,8 @@ int kfd_queue_release_buffers(struct kfd_process_device
 *pdd, struct queue_prope
      topo_dev = kfd_topology_device_by_id(pdd->dev->id);
      if (!topo_dev)
              return -EINVAL;
-     total_cwsr_size = (topo_dev->node_props.cwsr_size + topo_dev-
 >node_props.debug_memory_size)
-                       * NUM_XCC(pdd->dev->xcc_mask);
+     total_cwsr_size = (properties->ctx_save_restore_area_size +
+                        topo_dev->node_props.debug_memory_size) *
 NUM_XCC(pdd->dev->xcc_mask);
      total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE);

      kfd_queue_buffer_svm_put(pdd, properties-
Quoted 1 line

ctx_save_restore_area_address, total_cwsr_size);

--
2.34.1

Reviewed-by Philip.Yang
#2 lore raw

The size up-limit check is not needed because user buffer validation will fail if the size is larger than the cwsr_bo or cwsr svm range size allocated.

Quoted 77 lines · Jonathan

[Public]

Ping

Quoted 73 lines

-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Friday, November 7, 2025 7:57 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Six, Lancelot <[email protected]>; Yang, Philip <[email protected]>; Kim, Jonathan <[email protected]>
Subject: [PATCH] drm/amdkfd: relax checks for over allocation of save area

Over allocation of save area is not fatal, only under allocation is. ROCm has various components that independently claim authority over save area size.

Unless KFD decides to claim single authority, relax size checks.

v2: remove warning

---
  drivers/gpu/drm/amd/amdkfd/kfd_queue.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_queue.c +0 -0
index a65c67cf56ff..f1e7583650c4 100644
@@ -297,16 +297,16 @@ int kfd_queue_acquire_buffers(struct

kfd_process_device *pdd, struct queue_prope

               goto out_err_unreserve;
       }

- if (properties->ctx_save_restore_area_size != topo_dev-

Quoted 1 line

node_props.cwsr_size) {

- pr_debug("queue cwsr size 0x%x not equal to node cwsr size
0x%x\n",
+ if (properties->ctx_save_restore_area_size < topo_dev-

Quoted 1 line

node_props.cwsr_size) {

+ pr_debug("queue cwsr size 0x%x not sufficient for node cwsr size
0x%x\n",

                       properties->ctx_save_restore_area_size,
                       topo_dev->node_props.cwsr_size);
               err = -EINVAL;
               goto out_err_unreserve;
       }

- total_cwsr_size = (topo_dev->node_props.cwsr_size + topo_dev-

Quoted 1 line

node_props.debug_memory_size)

drivers/gpu/drm/amd/amdkfd/kfd_queue.c +2 -1
-                       * NUM_XCC(pdd->dev->xcc_mask);
+     total_cwsr_size = (properties->ctx_save_restore_area_size +
+                        topo_dev->node_props.debug_memory_size) *

NUM_XCC(pdd->dev->xcc_mask);
total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE);

err = kfd_queue_buffer_get(vm, (void *)properties-

Quoted 1 line

ctx_save_restore_area_address,

drivers/gpu/drm/amd/amdkfd/kfd_queue.c +2 -2
@@ -352,8 +352,8 @@ int kfd_queue_release_buffers(struct kfd_process_device
 *pdd, struct queue_prope
       topo_dev = kfd_topology_device_by_id(pdd->dev->id);
       if (!topo_dev)
               return -EINVAL;
-     total_cwsr_size = (topo_dev->node_props.cwsr_size + topo_dev-
 > node_props.debug_memory_size)
-                       * NUM_XCC(pdd->dev->xcc_mask);
+     total_cwsr_size = (properties->ctx_save_restore_area_size +
+                        topo_dev->node_props.debug_memory_size) *
 NUM_XCC(pdd->dev->xcc_mask);
       total_cwsr_size = ALIGN(total_cwsr_size, PAGE_SIZE);

       kfd_queue_buffer_svm_put(pdd, properties-
Quoted 1 line

ctx_save_restore_area_address, total_cwsr_size);

--
2.34.1