[PATCH] drm/amdkfd: Ignore user ctl_stack_size on queue creation on gfx9
Sunday Clement
Sunday.Clement at amd.com
Fri Jul 18 16:09:28 UTC 2025
For security reasons it is safer to have the kernel driver handle
calculating the sizing for the control stack on queue creation for
gfx9, rather than having it done in userspace where arbitrarily large
values can be passed in potentially wasting space in VMID0.
Signed-off-by: Sunday Clement <Sunday.Clement at amd.com>
---
.../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
index 97933d2a3803..8841411050a3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c
@@ -135,8 +135,25 @@ static struct kfd_mem_obj *allocate_mqd(struct kfd_node *node,
mqd_mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_KERNEL);
if (!mqd_mem_obj)
return NULL;
+
+ uint16_t xcc_mask = node->adev->gfx.xcc_mask;
+ uint32_t num_xccs = NUM_XCC(xcc_mask);
+ uint32_t num_cu = node->adev->gfx.cu_info.number;
+
+ if (num_xccs == 0) {
+ pr_err("Invalid XCC mask: %u\n", xcc_mask);
+ kfree(mqd_mem_obj);
+ return NULL;
+ }
+
+ num_cu /= num_xccs;
+
+ uint32_t num_waves = num_cu * 40;
+ /* Add Bytes to accommodate ContextSaveAreaHeader */
+ uint32_t ctl_stack_size = (num_waves * 8) + 8 + 42;
+
retval = amdgpu_amdkfd_alloc_gtt_mem(node->adev,
- (ALIGN(q->ctl_stack_size, PAGE_SIZE) +
+ (ALIGN(ctl_stack_size, PAGE_SIZE) +
ALIGN(sizeof(struct v9_mqd), PAGE_SIZE)) *
NUM_XCC(node->xcc_mask),
&(mqd_mem_obj->gtt_mem),
--
2.43.0
More information about the amd-gfx
mailing list