Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: Fix size validation for non-exclusive domains (v4)

Fix amdgpu_bo_validate_size() to check whether the TTM domain manager for the
requested memory exists, else we get a kernel oops when dereferencing "man".

v2: Make the patch standalone, i.e. not dependent on local patches.
v3: Preserve old behaviour and just check that the manager pointer is not
NULL.
v4: Complain if GTT domain requested and it is uninitialized--most likely a
bug.

Cc: Alex Deucher <Alexander.Deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: AMD Graphics <amd-gfx@lists.freedesktop.org>
Signed-off-by: Luben Tuikov <luben.tuikov@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Luben Tuikov and committed by
Alex Deucher
7554886d 28afcb0a

+8 -11
+8 -11
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
··· 448 448 449 449 /* 450 450 * If GTT is part of requested domains the check must succeed to 451 - * allow fall back to GTT 451 + * allow fall back to GTT. 452 452 */ 453 453 if (domain & AMDGPU_GEM_DOMAIN_GTT) { 454 454 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT); 455 455 456 - if (size < man->size) 456 + if (man && size < man->size) 457 457 return true; 458 - else 459 - goto fail; 460 - } 461 - 462 - if (domain & AMDGPU_GEM_DOMAIN_VRAM) { 458 + else if (!man) 459 + WARN_ON_ONCE("GTT domain requested but GTT mem manager uninitialized"); 460 + goto fail; 461 + } else if (domain & AMDGPU_GEM_DOMAIN_VRAM) { 463 462 man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM); 464 463 465 - if (size < man->size) 464 + if (man && size < man->size) 466 465 return true; 467 - else 468 - goto fail; 466 + goto fail; 469 467 } 470 - 471 468 472 469 /* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */ 473 470 return true;