drm/amd: Simplify the size check funciton
Subsystems (2)
PATCH 1/1 drm/amd: Simplify the size check funciton
Simplify the code logic of size check function amdgpu_bo_validate_size
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +11 -17
@@ -480,7 +480,7 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, *cpu_addr =NULL ; } -/* Validate bo size is bit bigger then the request domain */ +/* Validate bo size is bit bigger than the request domain */ static bool amdgpu_bo_validate_size (struct amdgpu_device *adev,unsigned long size,u32 domain) {
@@ -490,29 +490,23 @@ 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. */ -if (domain &AMDGPU_GEM_DOMAIN_GTT ) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_TT ); - -if (man && size < man->size) -return true; -else if (!man) -WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); - goto fail; - }else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) { +else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM ); +else +return true; -if (man && size < man->size) -return true; - goto fail; +if (!man) { +WARN_ON_ONCE ("Mem mananger of mem domain %d is uninitialized" , domain); +return false; }/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU, _DOMAIN_DOORBELL */ -return true; +if (size < man->size) +return true; -fail: -if (man) -DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, - man->size); +DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, man->size);return false; }
Signature · 1 line
2.34.1
Christian König
maintainerAm 25.08.23 um 07:22 schrieb Ma Jun:
Quoted 36 lines
Simplify the code logic of size check function
amdgpu_bo_validate_sizeSigned-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-9@@ -480,7 +480,7 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, *cpu_addr =NULL ; } -/* Validate bo size is bit bigger then the request domain */ +/* Validate bo size is bit bigger than the request domain */ static bool amdgpu_bo_validate_size (struct amdgpu_device *adev,unsigned long size,u32 domain) {@@ -490,29 +490,23 @@ 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. */ -if (domain &AMDGPU_GEM_DOMAIN_GTT ) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_TT ); - -if (man && size < man->size) -return true; -else if (!man) -WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); - goto fail; - }else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) { +else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM );
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, · line 503
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-3+else +return true; -if (man && size < man->size) -return true; - goto fail; +if (!man) { +WARN_ON_ONCE ("Mem mananger of mem domain %d is uninitialized" , domain); +return false; }
That change here is not correct. It's perfectly valid for userspace to request VRAM even if VRAM isn't initialized.
Only the GTT manager is mandatory. That's why the code previously looked like it does.
regards,
Christian.
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-5/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU, _DOMAIN_DOORBELL */ -return true; +if (size < man->size) +return true; -fail: -if (man) -DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, - man->size); +DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, man->size);return false; }
Hi Christian,
Quoted 53 lines · Christian König
Am 25.08.23 um 07:22 schrieb Ma Jun:
Quoted 36 lines
Simplify the code logic of size check function
amdgpu_bo_validate_sizeSigned-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-9@@ -480,7 +480,7 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, *cpu_addr =NULL ; } -/* Validate bo size is bit bigger then the request domain */ +/* Validate bo size is bit bigger than the request domain */ static bool amdgpu_bo_validate_size (struct amdgpu_device *adev,unsigned long size,u32 domain) {@@ -490,29 +490,23 @@ 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. */ -if (domain &AMDGPU_GEM_DOMAIN_GTT ) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_TT ); - -if (man && size < man->size) -return true; -else if (!man) -WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); - goto fail; - }else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) { +else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM );drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, · line 503
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-3+else +return true; -if (man && size < man->size) -return true; - goto fail; +if (!man) { +WARN_ON_ONCE ("Mem mananger of mem domain %d is uninitialized" , domain); +return false; }That change here is not correct. It's perfectly valid for userspace to request VRAM even if VRAM isn't initialized.
Quoted 3 lines
Only the GTT manager is mandatory. That's why the code previously looked like it does.
Thanks for your explanation.
How about changing the code to the following?
+ if (!man) {
+ if (domain & AMDGPU_GEM_DOMAIN_GTT)
+ WARN_ON_ONCE("GTT domain requested but GTT mem manager uninitialized");
+ return false;
}Regards,
Ma Jun
Quoted 18 lines
regards,
Christian.Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-5/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU, _DOMAIN_DOORBELL */ -return true; +if (size < man->size) +return true; -fail: -if (man) -DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, - man->size); +DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, man->size);return false; }
Christian König
maintainerAm 28.08.23 um 07:09 schrieb Ma, Jun:
Quoted 60 lines
Hi Christian,
Quoted 51 lines · Christian König
Am 25.08.23 um 07:22 schrieb Ma Jun:
Quoted 36 lines
Simplify the code logic of size check function
amdgpu_bo_validate_sizeSigned-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-9@@ -480,7 +480,7 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, *cpu_addr =NULL ; } -/* Validate bo size is bit bigger then the request domain */ +/* Validate bo size is bit bigger than the request domain */ static bool amdgpu_bo_validate_size (struct amdgpu_device *adev,unsigned long size,u32 domain) {@@ -490,29 +490,23 @@ 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. */ -if (domain &AMDGPU_GEM_DOMAIN_GTT ) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_TT ); - -if (man && size < man->size) -return true; -else if (!man) -WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); - goto fail; - }else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) { +else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM );drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, · line 503
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-3+else +return true; -if (man && size < man->size) -return true; - goto fail; +if (!man) { +WARN_ON_ONCE ("Mem mananger of mem domain %d is uninitialized" , domain); +return false; }That change here is not correct. It's perfectly valid for userspace to request VRAM even if VRAM isn't initialized.
Quoted 3 lines
Only the GTT manager is mandatory. That's why the code previously looked like it does.
Thanks for your explanation.
How about changing the code to the following?
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, · line 503
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-0+if (!man) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) +WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); +return false; }
Of hand that looks like it should work, but I need to see the full patch.
Regards,
Christian.
Quoted 21 lines
Regards,
Ma JunQuoted 17 lines
regards,
Christian.Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-5/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU, _DOMAIN_DOORBELL */ -return true; +if (size < man->size) +return true; -fail: -if (man) -DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, - man->size); +DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, man->size);return false; }
Quoted 61 lines · Christian König
Am 28.08.23 um 07:09 schrieb Ma, Jun:
Quoted 60 lines
Hi Christian,
Quoted 51 lines · Christian König
Am 25.08.23 um 07:22 schrieb Ma Jun:
Quoted 36 lines
Simplify the code logic of size check function
amdgpu_bo_validate_sizeSigned-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-9@@ -480,7 +480,7 @@ void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, *cpu_addr =NULL ; } -/* Validate bo size is bit bigger then the request domain */ +/* Validate bo size is bit bigger than the request domain */ static bool amdgpu_bo_validate_size (struct amdgpu_device *adev,unsigned long size,u32 domain) {@@ -490,29 +490,23 @@ 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. */ -if (domain &AMDGPU_GEM_DOMAIN_GTT ) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_TT ); - -if (man && size < man->size) -return true; -else if (!man) -WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); - goto fail; - }else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) { +else if (domain &AMDGPU_GEM_DOMAIN_VRAM ) man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM );drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, · line 503
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-3+else +return true; -if (man && size < man->size) -return true; - goto fail; +if (!man) { +WARN_ON_ONCE ("Mem mananger of mem domain %d is uninitialized" , domain); +return false; }That change here is not correct. It's perfectly valid for userspace to request VRAM even if VRAM isn't initialized.
Quoted 3 lines
Only the GTT manager is mandatory. That's why the code previously looked like it does.
Thanks for your explanation.
How about changing the code to the following?
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_bo_validate_size(struct amdgpu_device *adev, · line 503
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4
-0+if (!man) { +if (domain &AMDGPU_GEM_DOMAIN_GTT ) +WARN_ON_ONCE ("GTT domain requested but GTT mem manager uninitialized" ); +return false; }Of hand that looks like it should work, but I need to see the full patch.
Thanks, I'll send v2 with this change.
Regards,
Ma Jun
Quoted 25 lines
Regards,
Christian.Quoted 21 lines
Regards,
Ma JunQuoted 17 lines
regards,
Christian.Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3
-5/* TODO add more domains checks, such as AMDGPU_GEM_DOMAIN_CPU, _DOMAIN_DOORBELL */ -return true; +if (size < man->size) +return true; -fail: -if (man) -DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, - man->size); +DRM_DEBUG ("BO size %lu > total memory in domain: %llu\n" , size, man->size);return false; }