Skip to contentSkip to conversation

amdkfd: Memory availability can never be negative

PATCH In review Daniel Phillips 2 participants 2 messages Mar 1, 2023 – Mar 2, 2023

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

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

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.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3 -0
index 6f236ded5f12..293f9b2292fa 100644
@@ -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;
+
 	return ALIGN_DOWN(available, VRAM_AVAILABLITY_ALIGN);
 }
 
Signature · 1 line
2.39.0
maintainer
#1 lore raw

Am 2023-03-01 um 18:46 schrieb Daniel Phillips:

Quoted 15 lines

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.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0
index 6f236ded5f12..293f9b2292fa 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev) · line 1587

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -0
@@ -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

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -0
+
  	return ALIGN_DOWN(available, VRAM_AVAILABLITY_ALIGN);
  }