Skip to contentSkip to conversation

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

PATCH In review Luben Tuikov 2 participants 2 messages Dec 14, 2022

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

PATCH v4 1/1 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 <[email protected]>
Cc Christian König <[email protected]>
Cc AMD Graphics <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -11
index fd3ab4b5e5bb1f..983a12cac329a7 100644
@@ -448,27 +448,25 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 
 	/*
 	 * If GTT is part of requested domains the check must succeed to
-	 * allow fall back to GTT
+	 * allow fall back to GTT.
 	 */
 	if (domain & AMDGPU_GEM_DOMAIN_GTT) {
 		man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 
-		if (size < man->size)
+		if (man && size < man->size)
 			return true;
-		else
-			goto fail;
-	}
-
-	if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
+		else if (!man)
+			pr_err_ratelimited("GTT domain requested but GTT mem manager uninitialized, for size: %lu\n",
+					   size);
+		goto fail;
+	} else if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
 		man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 
-		if (size < man->size)
+		if (man && size < man->size)
 			return true;
-		else
-			goto fail;
+		goto fail;
 	}
 
-
 	/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */
 	return true;
 

base-commit: 84abaa3a855571ebd4e57a7249b867a2fa3763da

Signature · 1 line
2.39.0
Reviewed-by on v4 1/1
#1 lore raw

Am 14.12.22 um 10:41 schrieb Luben Tuikov:

Quoted 9 lines

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.

Quoted 4 lines
Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc AMD Graphics <[email protected]>
Quoted 47 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 20 +++++++++-----------
  1 file changed, 9 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -11
index fd3ab4b5e5bb1f..983a12cac329a7 100644
@@ -448,27 +448,25 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 
  	/*
  	 * If GTT is part of requested domains the check must succeed to
-	 * allow fall back to GTT
+	 * allow fall back to GTT.
  	 */
  	if (domain & AMDGPU_GEM_DOMAIN_GTT) {
  		man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 
-		if (size < man->size)
+		if (man && size < man->size)
  			return true;
-		else
-			goto fail;
-	}
-
-	if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
+		else if (!man)
+			pr_err_ratelimited("GTT domain requested but GTT mem manager uninitialized, for size: %lu\n",
+					   size);
+		goto fail;
+	} else if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
  		man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 
-		if (size < man->size)
+		if (man && size < man->size)
  			return true;
-		else
-			goto fail;
+		goto fail;
  	}
 
-
  	/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU */
  	return true;
 

base-commit: 84abaa3a855571ebd4e57a7249b867a2fa3763da