]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
amdkfd: Memory availability can never be negative
authorDaniel Phillips <daniel.phillips@amd.com>
Wed, 1 Mar 2023 22:28:26 +0000 (14:28 -0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 7 Mar 2023 19:21:56 +0000 (14:21 -0500)
Our assumptions about how much KFD memory is currently available for
allocation may be violated by various complexities so we define the
reported value as advisory, however we should never report negative
availability.

Signed-off-by: Daniel Phillips <daniel.phillips@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

index a4ee9f0378c1d67213b0f0ed411313e9147a25b6..c87515210c4f47d4c906194a54f5f37cf7356e27 100644 (file)
@@ -1583,7 +1583,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)
 {
        uint64_t reserved_for_pt =
                ESTIMATE_PT_SIZE(amdgpu_amdkfd_total_mem_size);
-       size_t available;
+       ssize_t available;
 
        spin_lock(&kfd_mem_limit.mem_limit_lock);
        available = adev->gmc.real_vram_size
@@ -1592,6 +1592,9 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)
                - reserved_for_pt;
        spin_unlock(&kfd_mem_limit.mem_limit_lock);
 
+       if (available < 0)
+               available = 0;
+
        return ALIGN_DOWN(available, VRAM_AVAILABLITY_ALIGN);
 }