Skip to contentSkip to conversation

drm/amdkfd: remove unnecessary cpu domain validation

PATCH In review James Zhu 3 participants 5 messages Mar 3, 2025 – Mar 4, 2025

Subsystems (3)
lore
Share & tools
lore

James Zhu

author
#0 lore raw

PATCH 1/1 drm/amdkfd: remove unnecessary cpu domain validation

before move to GTT domain.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -6
index 62ca12e94581..2ac6d4fa0601 100644
@@ -595,12 +595,6 @@ kfd_mem_dmamap_dmabuf(struct kfd_mem_attachment *attachment)
 {
 	struct ttm_operation_ctx ctx = {.interruptible = true};
 	struct amdgpu_bo *bo = attachment->bo_va->base.bo;
-	int ret;
-
-	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
-	ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-	if (ret)
-		return ret;
 
 	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 	return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Am 03.03.25 um 19:45 schrieb James Zhu:

Quoted 1 line

before move to GTT domain.

That might not be unnecessary. We sometimes intentionally move BOs to the CPU domain to invalidate all VM mappings.

Christian.

Quoted 23 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -6
index 62ca12e94581..2ac6d4fa0601 100644
@@ -595,12 +595,6 @@ kfd_mem_dmamap_dmabuf(struct kfd_mem_attachment *attachment)
 {
 	struct ttm_operation_ctx ctx = {.interruptible = true};
 	struct amdgpu_bo *bo = attachment->bo_va->base.bo;
-	int ret;
-
-	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
-	ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-	if (ret)
-		return ret;
 
 	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 	return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
maintainer
#2 lore raw
Quoted 3 lines · Christian König

Am 03.03.25 um 19:45 schrieb James Zhu:

Quoted 1 line

before move to GTT domain.

That might not be unnecessary. We sometimes intentionally move BOs to the CPU domain to invalidate all VM mappings.

We discussed this in our VM sync meeting this morning, and I wasn't 100% sure either. In this case it's causing a nearly live-lock of mutual evictions when two processes share the same BO and have both their eviction fences on the shared reservation object.

I was thinking the VM invalidation should be taken care of by the DMABuf move notifier, so this explicit invalidation seemed redundant. Is there a way we can test or otherwise verify that we're not missing anything?

Thanks,
  Felix

Quoted 25 lines

Christian.

Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -6
index 62ca12e94581..2ac6d4fa0601 100644
@@ -595,12 +595,6 @@ kfd_mem_dmamap_dmabuf(struct kfd_mem_attachment *attachment)
 {
 	struct ttm_operation_ctx ctx = {.interruptible = true};
 	struct amdgpu_bo *bo = attachment->bo_va->base.bo;
-	int ret;
-
-	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
-	ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-	if (ret)
-		return ret;
 
 	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 	return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
maintainer
#3 lore raw

Am 03.03.25 um 22:01 schrieb Felix Kuehling:

Quoted 7 lines · Christian König
Quoted 3 lines

Am 03.03.25 um 19:45 schrieb James Zhu:

Quoted 1 line

before move to GTT domain.

That might not be unnecessary. We sometimes intentionally move BOs to the CPU domain to invalidate all VM mappings.

We discussed this in our VM sync meeting this morning, and I wasn't 100% sure either. In this case it's causing a nearly live-lock of mutual evictions when two processes share the same BO and have both their eviction fences on the shared reservation object.

I was thinking the VM invalidation should be taken care of by the DMABuf move notifier, so this explicit invalidation seemed redundant. Is there a way we can test or otherwise verify that we're not missing anything?

We used this hack to validate into system domain and then GTT for userptrs, but I can't think of any reason to do this for DMA-buf imports.

Regards,
Christian.

Quoted 29 lines

Thanks,
  Felix

Quoted 24 lines

Christian.

Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -6
index 62ca12e94581..2ac6d4fa0601 100644
@@ -595,12 +595,6 @@ kfd_mem_dmamap_dmabuf(struct kfd_mem_attachment *attachment)
 {
 	struct ttm_operation_ctx ctx = {.interruptible = true};
 	struct amdgpu_bo *bo = attachment->bo_va->base.bo;
-	int ret;
-
-	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
-	ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-	if (ret)
-		return ret;
 
 	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 	return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
maintainer Reviewed-by
#4 lore raw
Quoted 10 lines · Christian König

Am 03.03.25 um 22:01 schrieb Felix Kuehling:

Quoted 7 lines · Christian König
Quoted 3 lines

Am 03.03.25 um 19:45 schrieb James Zhu:

Quoted 1 line

before move to GTT domain.

That might not be unnecessary. We sometimes intentionally move BOs to the CPU domain to invalidate all VM mappings.

We discussed this in our VM sync meeting this morning, and I wasn't 100% sure either. In this case it's causing a nearly live-lock of mutual evictions when two processes share the same BO and have both their eviction fences on the shared reservation object.

I was thinking the VM invalidation should be taken care of by the DMABuf move notifier, so this explicit invalidation seemed redundant. Is there a way we can test or otherwise verify that we're not missing anything?

We used this hack to validate into system domain and then GTT for userptrs, but I can't think of any reason to do this for DMA-buf imports.

OK, I had the same intuition. In that case the patch is

Quoted 32 lines

Regards,
Christian.

Quoted 28 lines

Thanks,
  Felix

Quoted 24 lines

Christian.

Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -6
index 62ca12e94581..2ac6d4fa0601 100644
@@ -595,12 +595,6 @@ kfd_mem_dmamap_dmabuf(struct kfd_mem_attachment *attachment)
 {
 	struct ttm_operation_ctx ctx = {.interruptible = true};
 	struct amdgpu_bo *bo = attachment->bo_va->base.bo;
-	int ret;
-
-	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
-	ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
-	if (ret)
-		return ret;
 
 	amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
 	return ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);