[PATCH 1/1] amdkfd: Memory availability can never be negative

Felix Kuehling felix.kuehling at amd.com
Thu Mar 2 00:21:56 UTC 2023


Am 2023-03-01 um 18:46 schrieb Daniel Phillips:
> 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 at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 6f236ded5f12..293f9b2292fa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -1583,6 +1583,9 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev)
>   		- reserved_for_pt;
>   	spin_unlock(&kfd_mem_limit.mem_limit_lock);
>   
> +	if ((int64_t)available < 0)
> +		available = 0;

Instead of casting avaliable to a signed type here, you could define it 
with a signed type in the first place. ssize_t would be appropriate.

Regards,
   Felix


> +
>   	return ALIGN_DOWN(available, VRAM_AVAILABLITY_ALIGN);
>   }
>   


More information about the amd-gfx mailing list