Patch "drm/amdkfd: Use dynamic allocation for CU occupancy array in 'kfd_get_cu_occupancy()'" has been added to the 6.12-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    drm/amdkfd: Use dynamic allocation for CU occupancy array in 'kfd_get_cu_occupancy()'

to the 6.12-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     drm-amdkfd-use-dynamic-allocation-for-cu-occupancy-a.patch
and it can be found in the queue-6.12 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit b599064a7f7cf76984c91e803f1992383d7817b3
Author: Srinivasan Shanmugam <srinivasan.shanmugam@xxxxxxx>
Date:   Fri Oct 4 09:12:39 2024 +0530

    drm/amdkfd: Use dynamic allocation for CU occupancy array in 'kfd_get_cu_occupancy()'
    
    [ Upstream commit 922f0e00017b09d9d47e3efac008c8b20ed546a0 ]
    
    The `kfd_get_cu_occupancy` function previously declared a large
    `cu_occupancy` array as a local variable, which could lead to stack
    overflows due to excessive stack usage. This commit replaces the static
    array allocation with dynamic memory allocation using `kcalloc`,
    thereby reducing the stack size.
    
    This change avoids the risk of stack overflows in kernel space,  in
    scenarios where `AMDGPU_MAX_QUEUES` is large. The  allocated memory is
    freed using `kfree` before the function returns  to prevent memory
    leaks.
    
    Fixes the below with gcc W=1:
    drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_process.c: In function ‘kfd_get_cu_occupancy’:
    drivers/gpu/drm/amd/amdgpu/../amdkfd/kfd_process.c:322:1: warning: the frame size of 1056 bytes is larger than 1024 bytes [-Wframe-larger-than=]
      322 | }
          | ^
    
    Fixes: 6ae9e1aba97e ("drm/amdkfd: Update logic for CU occupancy calculations")
    Cc: Harish Kasiviswanathan <Harish.Kasiviswanathan@xxxxxxx>
    Cc: Felix Kuehling <felix.kuehling@xxxxxxx>
    Cc: Christian König <christian.koenig@xxxxxxx>
    Cc: Alex Deucher <alexander.deucher@xxxxxxx>
    Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@xxxxxxx>
    Suggested-by: Mukul Joshi <mukul.joshi@xxxxxxx>
    Reviewed-by: Mukul Joshi <mukul.joshi@xxxxxxx>
    Signed-off-by: Alex Deucher <alexander.deucher@xxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index d4aa843aacfdd..6bab6fc6a35d6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -271,11 +271,9 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
 	struct kfd_process *proc = NULL;
 	struct kfd_process_device *pdd = NULL;
 	int i;
-	struct kfd_cu_occupancy cu_occupancy[AMDGPU_MAX_QUEUES];
+	struct kfd_cu_occupancy *cu_occupancy;
 	u32 queue_format;
 
-	memset(cu_occupancy, 0x0, sizeof(cu_occupancy));
-
 	pdd = container_of(attr, struct kfd_process_device, attr_cu_occupancy);
 	dev = pdd->dev;
 	if (dev->kfd2kgd->get_cu_occupancy == NULL)
@@ -293,6 +291,10 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
 	wave_cnt = 0;
 	max_waves_per_cu = 0;
 
+	cu_occupancy = kcalloc(AMDGPU_MAX_QUEUES, sizeof(*cu_occupancy), GFP_KERNEL);
+	if (!cu_occupancy)
+		return -ENOMEM;
+
 	/*
 	 * For GFX 9.4.3, fetch the CU occupancy from the first XCC in the partition.
 	 * For AQL queues, because of cooperative dispatch we multiply the wave count
@@ -318,6 +320,7 @@ static int kfd_get_cu_occupancy(struct attribute *attr, char *buffer)
 
 	/* Translate wave count to number of compute units */
 	cu_cnt = (wave_cnt + (max_waves_per_cu - 1)) / max_waves_per_cu;
+	kfree(cu_occupancy);
 	return snprintf(buffer, PAGE_SIZE, "%d\n", cu_cnt);
 }
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux