amd/amdkfd: correct mem limit calculation for small APUs
authorYifan Zhang <yifan1.zhang@amd.com>
Wed, 20 Aug 2025 08:10:51 +0000 (16:10 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 9 Sep 2025 16:28:28 +0000 (12:28 -0400)
commit53503556273a5ead8b75534085e2dcb46e96f883
treefdc9a34d2a859e65b875f1e6efecc0b6cfd6763e
parentce42a3b581a9db10765eb835840b04dbe7972135
amd/amdkfd: correct mem limit calculation for small APUs

Current mem limit check leaks some GTT memory (reserved_for_pt
reserved_for_ras + adev->vram_pin_size) for small APUs.

Since carveout VRAM is tunable on APUs, there are three case
regarding the carveout VRAM size relative to GTT:

1. 0 < carveout < gtt
   apu_prefer_gtt = true, is_app_apu = false

2. carveout > gtt / 2
   apu_prefer_gtt = false, is_app_apu = false

3. 0 = carveout
   apu_prefer_gtt = true, is_app_apu = true

It doesn't make sense to check below limitation in case 1
(default case, small carveout) because the values in the below
expression are mixed with carveout and gtt.

adev->kfd.vram_used[xcp_id] + vram_needed >
    vram_size - reserved_for_pt - reserved_for_ras -
    atomic64_read(&adev->vram_pin_size)

gtt: kfd.vram_used, vram_needed, vram_size
carveout: reserved_for_pt, reserved_for_ras, adev->vram_pin_size

In case 1, vram allocation will go to gtt domain, skip vram check
since ttm_mem_limit check already cover this allocation.

Signed-off-by: Yifan Zhang <yifan1.zhang@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit fa7c99f04f6dd299388e9282812b14e95558ac8e)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c