drm/amdgpu: Add userptr bo support for mGPUs when iommu is on
Subsystems (3)
PATCH 1/3 drm/amdgpu: Add userptr bo support for mGPUs when iommu is on
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both bo_adev and adev in identity mode or in the same iommu group.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -4
@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, va + bo_size, vm);if ((adev == bo_adev && !(mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) || - (amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && adev->ram_is_direct_mapped) || - same_hive) { + (amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && ((adev->ram_is_direct_mapped && bo_adev->ram_is_direct_mapped) || + adev->dev->iommu_group == bo_adev->dev->iommu_group)) || same_hive){/* Mappings on the local GPU, or VRAM mappings in the -* local hive, or userptr mapping IOMMU direct map mode -* share the original BO +* local hive, or userptr mapping in the same dma +* address space share the original BO */ attachment[i]->type =KFD_MEM_ATT_SHARED ; bo[i] = mem->bo;
Signature · 1 line
2.25.1
PATCH 2/3 amd/amdgpu: Inherit coherence flags base on original BO flags
For SG BO to DMA-map userptrs on other GPUs, the SG BO need inherit MTYPEs in PTEs from original BO.
If we set the flags, the device can be coherent with the CPUs and other GPUs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +9 -1
@@ -253,14 +253,22 @@ create_dmamap_sg_bo(struct amdgpu_device *adev, {struct drm_gem_object *gem_obj;int ret, align; +uint64_t flags =0 ; ret =amdgpu_bo_reserve (mem->bo, false);if (ret)return ret; align =1 ; +if (mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) + { + flags |= mem->bo->flags &(AMDGPU_GEM_CREATE_CPU_GTT_USWC | +AMDGPU_GEM_CREATE_COHERENT |AMDGPU_GEM_CREATE_UNCACHED ); + align =PAGE_SIZE ; + } + ret =amdgpu_gem_object_create (adev, mem->bo->tbo.base.size, align, -AMDGPU_GEM_DOMAIN_CPU ,AMDGPU_GEM_CREATE_PREEMPTIBLE , +AMDGPU_GEM_DOMAIN_CPU ,AMDGPU_GEM_CREATE_PREEMPTIBLE | flags, ttm_bo_type_sg, mem->bo->tbo.base.resv, &gem_obj);amdgpu_bo_unreserve (mem->bo);
Signature · 1 line
2.25.1
Felix Kuehling
maintainerRe: [PATCH 2/3] amd/amdgpu: Inherit coherence flags base on original BO flags
Am 2023-04-04 um 05:56 schrieb Shane Xiao:
Quoted 2 lines
For SG BO to DMA-map userptrs on other GPUs, the SG BO need inherit MTYPEs in PTEs from original BO.
Good catch. See two comments inline.
Quoted 16 lines
If we set the flags, the device can be coherent with the CPUs and other GPUs.
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -253,14 +253,22 @@ create_dmamap_sg_bo(struct amdgpu_device *adev, {struct drm_gem_object *gem_obj;int ret, align;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device *adev, · line 265
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-0+uint64_t flags =0 ; ret =amdgpu_bo_reserve (mem->bo, false);if (ret)return ret; align =1 ; +if (mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) + { + flags |= mem->bo->flags &(AMDGPU_GEM_CREATE_CPU_GTT_USWC |
I think userptrs never use USWC because the pages are not allocated by the driver. You can drop this flag.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device *adev, · line 267
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-0+ AMDGPU_GEM_CREATE_COHERENT | AMDGPU_GEM_CREATE_UNCACHED); + align =PAGE_SIZE ;
Isn't a page alignment implicit anyway? I don't see why we need to use a different alignment for userptrs. If PAGE_SIZE is needed for this case, we can use the same for all cases We don't even need a local variable for this.
Regards,
Felix
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-1+ } + ret =amdgpu_gem_object_create (adev, mem->bo->tbo.base.size, align, -AMDGPU_GEM_DOMAIN_CPU ,AMDGPU_GEM_CREATE_PREEMPTIBLE , +AMDGPU_GEM_DOMAIN_CPU ,AMDGPU_GEM_CREATE_PREEMPTIBLE | flags, ttm_bo_type_sg, mem->bo->tbo.base.resv, &gem_obj);amdgpu_bo_unreserve (mem->bo);
RE: [PATCH 2/3] amd/amdgpu: Inherit coherence flags base on original BO flags
[AMD Official Use Only - General]
Quoted 40 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, April 4, 2023 9:52 PM
To: Xiao, Shane <[email protected]>; [email protected]; Koenig, Christian <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 2/3] amd/amdgpu: Inherit coherence flags base on original BO flagsAm 2023-04-04 um 05:56 schrieb Shane Xiao:
Quoted 2 lines
For SG BO to DMA-map userptrs on other GPUs, the SG BO need inherit MTYPEs in PTEs from original BO.
Good catch. See two comments inline.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device
Quoted 14 lines
If we set the flags, the device can be coherent with the CPUs and other GPUs.
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -253,14 +253,22 @@ create_dmamap_sg_bo(struct amdgpu_device*adev,
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0{struct drm_gem_object *gem_obj;int ret, align; +uint64_t flags =0 ; ret =amdgpu_bo_reserve (mem->bo, false);if (ret)return ret;
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device *adev,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-0align =1 ; +if (mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_USERPTR ) + { + flags |= mem->bo->flags&(AMDGPU_GEM_CREATE_CPU_GTT_USWC |
I think userptrs never use USWC because the pages are not allocated by the driver. You can drop this flag.
OK. I will do it.
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device · line 266
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0+ AMDGPU_GEM_CREATE_COHERENT |
AMDGPU_GEM_CREATE_UNCACHED);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device *adev, · line 267
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0+ align =PAGE_SIZE ;Isn't a page alignment implicit anyway? I don't see why we need to use a different alignment for userptrs. If
PAGE_SIZEis needed for this case, we can use the same for all cases We don't even need a local variable for this.
Yes, a page alignment is implicit, and the local variable will be removed.
Best Regards,
Shane
Quoted 15 lines
Regards,
Felixdrivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device *adev,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1+ } + ret = amdgpu_gem_object_create(adev, mem->bo->tbo.base.size, align, - AMDGPU_GEM_DOMAIN_CPU,
AMDGPU_GEM_CREATE_PREEMPTIBLE,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c create_dmamap_sg_bo(struct amdgpu_device · line 271
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0+ AMDGPU_GEM_DOMAIN_CPU,
AMDGPU_GEM_CREATE_PREEMPTIBLE| flags,Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0ttm_bo_type_sg, mem->bo->tbo.base.resv, &gem_obj);amdgpu_bo_unreserve (mem->bo);
PATCH 3/3 drm/amdgpu: DROP redundant drm_prime_sg_to_dma_addr_array
In reply to Shane XiaoFor DMA-MAP userptr on other GPUs, the dma address array has been populated in amdgpu_ttm_backend_bind.
Remove the redundant call from the driver.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 --- 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -3
@@ -488,9 +488,6 @@ kfd_mem_dmamap_userptr(struct kgd_mem *mem,if (unlikely (ret)) goto release_sg; -drm_prime_sg_to_dma_addr_array (ttm->sg, ttm->dma_address, - ttm->num_pages); -amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);if (ret)
Signature · 1 line
2.25.1
Re: [PATCH 3/3] drm/amdgpu: DROP redundant drm_prime_sg_to_dma_addr_array
Am 2023-04-04 um 05:56 schrieb Shane Xiao:
Quoted 2 lines
For DMA-MAP userptr on other GPUs, the dma address array has been populated in
amdgpu_ttm_backend_bind.
OK. I think "has been populated" should be "will be populated", because amdgpu_ttm_backend_bind happens as a callback from the ttm_bo_validate call below. With that fixed in the patch description, the patch is
Quoted 22 lines
Remove the redundant call from the driver.
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 --- 1 file changed, 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-3@@ -488,9 +488,6 @@ kfd_mem_dmamap_userptr(struct kgd_mem *mem,if (unlikely (ret)) goto release_sg; -drm_prime_sg_to_dma_addr_array (ttm->sg, ttm->dma_address, - ttm->num_pages); -amdgpu_bo_placement_from_domain (bo,AMDGPU_GEM_DOMAIN_GTT ); ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);if (ret)
RE: [PATCH 3/3] drm/amdgpu: DROP redundant drm_prime_sg_to_dma_addr_array
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, April 4, 2023 9:59 PM
To: Xiao, Shane <[email protected]>; [email protected]; Koenig, Christian <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 3/3] drm/amdgpu: DROP redundantdrm_prime_sg_to_dma_addr_array
Quoted 7 lines
Am 2023-04-04 um 05:56 schrieb Shane Xiao:
Quoted 2 lines
For DMA-MAP userptr on other GPUs, the dma address array has been populated in
amdgpu_ttm_backend_bind.OK. I think "has been populated" should be "will be populated", because
amdgpu_ttm_backend_bindhappens as a callback from thettm_bo_validatecall below. With that fixed in the patch description, the patch is
Yes, I will fix the comment.
Best Regards,
Shane
Quoted 28 lines
Reviewed-by Felix Kuehling <[email protected]>Quoted 14 lines
Remove the redundant call from the driver.
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 --- 1 file changed, 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c kfd_mem_dmamap_userptr(struct kgd_mem *mem, · line 491
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-3@@ -488,9 +488,6 @@ kfd_mem_dmamap_userptr(struct kgd_mem *mem,if (unlikely (ret)) goto release_sg; -drm_prime_sg_to_dma_addr_array (ttm->sg, ttm->dma_address, - ttm->num_pages); - amdgpu_bo_placement_from_domain(bo,
AMDGPU_GEM_DOMAIN_GTT);Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0ret =ttm_bo_validate (&bo->tbo, &bo->placement, &ctx);if (ret)
Christian König
maintainerAm 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
So how can the same userptr BO be used on different GPUs?
Regards,
Christian.
Quoted 26 lines
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-4@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem, va + bo_size, vm);if ((adev == bo_adev && !(mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP )) || - (amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && adev->ram_is_direct_mapped) || - same_hive) { + (amdgpu_ttm_tt_get_usermm (mem->bo->tbo.ttm) && ((adev->ram_is_direct_mapped && bo_adev->ram_is_direct_mapped) || + adev->dev->iommu_group == bo_adev->dev->iommu_group)) || same_hive){/* Mappings on the local GPU, or VRAM mappings in the -* local hive, or userptr mapping IOMMU direct map mode -* share the original BO +* local hive, or userptr mapping in the same dma +* address space share the original BO */ attachment[i]->type =KFD_MEM_ATT_SHARED ; bo[i] = mem->bo;
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 4, 2023 6:27 PM
To: Xiao, Shane <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is on
Quoted 4 lines
Am 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.
Hi Christian,
Quoted 5 lines
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
So how can the same userptr BO be used on different GPUs?
If GPUs are all in iommu identity mode which means dma address are the same as physical address, all of the GPUs can see the system memory directly.
In such case, should we export/import the BO, then create a new SG BO for another GPU?
Best Regards,
Shane
Quoted 39 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device
Quoted 12 lines
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device*adev, struct
kgd_mem*mem,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0va + bo_size, vm); if ((adev == bo_adev && !(mem->alloc_flags &
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) ||drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device · line 807
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-1- (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) &&
adev->ram_is_direct_mapped) ||drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device · line 807
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1- same_hive) { + (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) &&((
adev->ram_is_direct_mapped&&bo_adev->ram_is_direct_mapped) ||Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0+ adev->dev->iommu_group == bo_adev->dev-
iommu_group)) ||
+same_hive){
/* Mappings on the local GPU, or VRAM mappings inthe
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-1-* local hive, or userptr mapping IOMMU direct map mode
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1-* share the original BO +* local hive, or userptr mapping in the same dma +* address space share the original BO */ attachment[i]->type =KFD_MEM_ATT_SHARED ; bo[i] = mem->bo;
Am 04.04.23 um 12:56 schrieb Xiao, Shane:
Quoted 17 lines
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 4, 2023 6:27 PM
To: Xiao, Shane <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is onQuoted 4 lines
Am 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.Hi Christian,
Quoted 7 lines
Quoted 4 lines
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
So how can the same userptr BO be used on different GPUs?
If GPUs are all in iommu identity mode which means dma address are the same as physical address, all of the GPUs can see the system memory directly.
In such case, should we export/import the BO, then create a new SG BO for another GPU?
Yes, absolutely. Each userptr BO is only meant to be used on one GPU.
Even if you could use the same BO for multiple GPUs it's not necessary a good idea since you then have live time problems for example.
E.g. what happens when one GPU is hot removed while the other one who imported the BO is still in use?
Felix can you comment on that? My recollection was that we rather improve the storage of DMA addresses instead of duplicating the BOs over different GPUs.
Regards,
Christian.
Quoted 42 lines
Best Regards,
ShaneQuoted 37 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device
Quoted 11 lines
Signed-off-by Shane Xiao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device*adev, struct
kgd_mem*mem,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0va + bo_size, vm); if ((adev == bo_adev && !(mem->alloc_flags &
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) ||drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device · line 807
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-1- (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) &&
adev->ram_is_direct_mapped) ||drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device · line 807
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1- same_hive) { + (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) &&((
adev->ram_is_direct_mapped&&bo_adev->ram_is_direct_mapped) ||Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0+ adev->dev->iommu_group == bo_adev->dev-
iommu_group)) ||+same_hive){ /* Mappings on the local GPU, or VRAM mappings inthe
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-1-* local hive, or userptr mapping IOMMU direct map mode
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1-* share the original BO +* local hive, or userptr mapping in the same dma +* address space share the original BO */ attachment[i]->type =KFD_MEM_ATT_SHARED ; bo[i] = mem->bo;
Felix Kuehling
maintainer[+Philip]
Am 2023-04-04 um 08:47 schrieb Christian König:
Quoted 26 lines
Am 04.04.23 um 12:56 schrieb Xiao, Shane:
Quoted 17 lines
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 4, 2023 6:27 PM
To: Xiao, Shane <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is onQuoted 4 lines
Am 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.Hi Christian,
Quoted 7 lines
Quoted 4 lines
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
So how can the same userptr BO be used on different GPUs?
If GPUs are all in iommu identity mode which means dma address are the same as physical address, all of the GPUs can see the system memory directly.
In such case, should we export/import the BO, then create a new SG BO for another GPU?
Quoted 7 lines
Yes, absolutely. Each userptr BO is only meant to be used on one GPU.
Even if you could use the same BO for multiple GPUs it's not necessary a good idea since you then have live time problems for example.
E.g. what happens when one GPU is hot removed while the other one who imported the BO is still in use?
Felix can you comment on that? My recollection was that we rather improve the storage of DMA addresses instead of duplicating the BOs over different GPUs.
For KFD we currently enable sharing of userptr BOs between multiple GPUs by creating a userptr BO for the first GPU, and creating additional SG BOs using the same page list for additional GPUs. That way we don't have to call hmm_range_fault N times and setup N MMU notifiers for the same address range on an N GPU system. But we do have to create N DMA mappings, which is facilitated by the SG BOs.
We have a further optimization to not even store separate DMA addresses per-GPU if they are a direct mapping. In that case we just increase the reference count on the original userptr BO. (I agree that we should also look into more efficient storage of DMA addresses. However, last time we talked about this, you basically told us that scatter gather tables are being deprecated, but I haven't seen the alternative yet.)
I think this patch fixes a potential issue with that optimization. There is an implicit assumption, that the DMA addresses stored in the original userptr BO are a direct mapping, so we can reuse them on other GPUs that also use a direct mapping. But, we didn't actually check that assumption. I think this patch fixes that for systems where system memory is direct mapped on some but not all GPUs.
This scenario should probably be called out explicitly in the patch description. The condition is also getting pretty hard to read and understand. Maybe move the both-direct-map-or-same-iommu-group conditions into a helper function, say "amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm) && reuse_dmamap(adev, bo_adev)".
Regards,
Felix
Quoted 47 lines
Regards,
Christian.Quoted 42 lines
Best Regards,
ShaneQuoted 37 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device
Quoted 11 lines
Signed-off-by Shane Xiao <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device*adev, struct
kgd_mem*mem,Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0va + bo_size, vm);if ((adev ==
bo_adev&& !(mem->alloc_flags &
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) ||Quoted 1 line
- (
amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&
adev->ram_is_direct_mapped) ||Quoted 2 lines
-
same_hive) {
+ (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&((
adev->ram_is_direct_mapped&&bo_adev->ram_is_direct_mapped) ||Quoted 4 lines
+
adev->dev->iommu_group== bo_adev->dev-iommu_group)) ||
+same_hive){
/* Mappings on the local GPU, or VRAM mappings inthe
Quoted 1 line
- * local hive, or userptr mapping IOMMU direct map
mode
Quoted 6 lines
- * share the original BO
+ * local hive, or userptr mapping in the same dma + * address space share the original BO */
attachment[i]->type =KFD_MEM_ATT_SHARED; bo[i] =mem->bo;
[AMD Official Use Only - General]
Quoted 69 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, April 4, 2023 9:45 PM
To: Christian König <[email protected]>; Xiao, Shane <[email protected]>; Koenig, Christian <[email protected]>; [email protected]; Yang, Philip <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is on[+Philip]
Am 2023-04-04 um 08:47 schrieb Christian König:
Quoted 34 lines
Am 04.04.23 um 12:56 schrieb Xiao, Shane:
Quoted 20 lines
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 4, 2023 6:27 PM
To: Xiao, Shane <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is onQuoted 4 lines
Am 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.Hi Christian,
Quoted 3 lines
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
Quoted 7 lines
Quoted 1 line
So how can the same userptr BO be used on different GPUs?
If GPUs are all in iommu identity mode which means dma address are the same as physical address, all of the GPUs can see the system memory directly.
In such case, should we export/import the BO, then create a new SG BO for another GPU?
Yes, absolutely. Each userptr BO is only meant to be used on one GPU.
Even if you could use the same BO for multiple GPUs it's not necessary a good idea since you then have live time problems for example.
Quoted 6 lines
E.g. what happens when one GPU is hot removed while the other one who imported the BO is still in use?
Felix can you comment on that? My recollection was that we rather improve the storage of DMA addresses instead of duplicating the BOs over different GPUs.
For KFD we currently enable sharing of userptr BOs between multiple GPUs by creating a userptr BO for the first GPU, and creating additional SG BOs using the same page list for additional GPUs. That way we don't have to call
hmm_range_faultN times and setup N MMU notifiers for the same address range on an N GPU system. But we do have to create N DMA mappings, which is facilitated by the SG BOs.We have a further optimization to not even store separate DMA addresses per- GPU if they are a direct mapping. In that case we just increase the reference count on the original userptr BO. (I agree that we should also look into more efficient storage of DMA addresses. However, last time we talked about this, you basically told us that scatter gather tables are being deprecated, but I haven't seen the alternative yet.)
Quoted 8 lines
I think this patch fixes a potential issue with that optimization. There is an implicit assumption, that the DMA addresses stored in the original userptr BO are a direct mapping, so we can reuse them on other GPUs that also use a direct mapping. But, we didn't actually check that assumption. I think this patch fixes that for systems where system memory is direct mapped on some but not all GPUs.
This scenario should probably be called out explicitly in the patch description.
Yes, I will add this scenario on the comment.
Quoted 5 lines
The condition is also getting pretty hard to read and understand. Maybe move the both-direct-map-or-same-iommu-group
conditions into a helper function, say "amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&reuse_dmamap(adev, bo_adev)".
It's a good suggestion. I will make the change.
Best Regards,
Shane
Quoted 53 lines
Regards,
FelixQuoted 48 lines
Regards,
Christian.Quoted 43 lines
Best Regards,
ShaneQuoted 38 lines
Regards,
Christian.Quoted 11 lines
Signed-off-by Shane Xiao <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -804,11 +804,11 @@ static int kfd_mem_attach(structQuoted 1 line
amdgpu_device*adev, struct
kgd_mem*mem,Quoted 3 lines
va +
bo_size, vm);if ((adev ==
bo_adev&& !(mem->alloc_flags &
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) ||Quoted 1 line
- (
amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&
adev->ram_is_direct_mapped) ||Quoted 2 lines
-
same_hive) {
+ (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&((
adev->ram_is_direct_mapped&&bo_adev->ram_is_direct_mapped) ||Quoted 4 lines
+
adev->dev->iommu_group== bo_adev->dev-iommu_group)) ||
+same_hive){
/* Mappings on the local GPU, or VRAM mappings inthe
Quoted 1 line
- * local hive, or userptr mapping IOMMU direct map
mode
Quoted 6 lines
- * share the original BO
+ * local hive, or userptr mapping in the same dma + * address space share the original BO */
attachment[i]->type =KFD_MEM_ATT_SHARED; bo[i] =mem->bo;
Quoted 36 lines · Felix Kuehling
[+Philip]
Am 2023-04-04 um 08:47 schrieb Christian König:
Quoted 32 lines
Am 04.04.23 um 12:56 schrieb Xiao, Shane:
Quoted 17 lines
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 4, 2023 6:27 PM
To: Xiao, Shane <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is onQuoted 4 lines
Am 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.Hi Christian,
Quoted 7 lines
Quoted 4 lines
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
So how can the same userptr BO be used on different GPUs?
If GPUs are all in iommu identity mode which means dma address are the same as physical address, all of the GPUs can see the system memory directly.
In such case, should we export/import the BO, then create a new SG BO for another GPU?
Yes, absolutely. Each userptr BO is only meant to be used on one GPU.
Even if you could use the same BO for multiple GPUs it's not necessary a good idea since you then have live time problems for example.
E.g. what happens when one GPU is hot removed while the other one who imported the BO is still in use?
Quoted 7 lines
Quoted 1 line
Felix can you comment on that? My recollection was that we rather improve the storage of DMA addresses instead of duplicating the BOs over different GPUs.
For KFD we currently enable sharing of userptr BOs between multiple GPUs by creating a userptr BO for the first GPU, and creating additional SG BOs using the same page list for additional GPUs. That way we don't have to call
hmm_range_faultN times and setup N MMU notifiers for the same address range on an N GPU system. But we do have to create N DMA mappings, which is facilitated by the SG BOs.We have a further optimization to not even store separate DMA addresses per-GPU if they are a direct mapping. In that case we just increase the reference count on the original userptr BO. (I agree that we should also look into more efficient storage of DMA addresses. However, last time we talked about this, you basically told us that scatter gather tables are being deprecated, but I haven't seen the alternative yet.)
I think this patch fixes a potential issue with that optimization. There is an implicit assumption, that the DMA addresses stored in the original userptr BO are a direct mapping, so we can reuse them on other GPUs that also use a direct mapping. But, we didn't actually check that assumption. I think this patch fixes that for systems where system memory is direct mapped on some but not all GPUs.
We will need similar optimization in svm_range_dma_map to reuse the prange->dma_addr for GPUs on same iommu group or direct mapping.
Regards,
Philip
Quoted 54 lines
This scenario should probably be called out explicitly in the patch description. The condition is also getting pretty hard to read and understand. Maybe move the both-direct-map-or-same-iommu-group conditions into a helper function, say "
amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&reuse_dmamap(adev, bo_adev)".Regards,
FelixQuoted 47 lines
Regards,
Christian.Quoted 42 lines
Best Regards,
ShaneQuoted 37 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device
Quoted 11 lines
Signed-off-by Shane Xiao <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device*adev, struct
kgd_mem*mem,Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0va + bo_size, vm);if ((adev ==
bo_adev&& !(mem->alloc_flags &
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) ||Quoted 1 line
- (
amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&
adev->ram_is_direct_mapped) ||Quoted 2 lines
-
same_hive) {
+ (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&((
adev->ram_is_direct_mapped&&bo_adev->ram_is_direct_mapped) ||Quoted 4 lines
+
adev->dev->iommu_group== bo_adev->dev-iommu_group)) ||
+same_hive){
/* Mappings on the local GPU, or VRAM mappings inthe
Quoted 1 line
- * local hive, or userptr mapping IOMMU direct map
mode
Quoted 6 lines
- * share the original BO
+ * local hive, or userptr mapping in the same dma + * address space share the original BO */
attachment[i]->type =KFD_MEM_ATT_SHARED; bo[i] =mem->bo;
Felix Kuehling
maintainerAm 2023-04-12 um 09:35 schrieb Philip Yang:
Quoted 40 lines · Felix Kuehling
Quoted 38 lines
[+Philip]
Am 2023-04-04 um 08:47 schrieb Christian König:
Quoted 33 lines
Am 04.04.23 um 12:56 schrieb Xiao, Shane:
Quoted 17 lines
[AMD Official Use Only - General]
Quoted 9 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, April 4, 2023 6:27 PM
To: Xiao, Shane <[email protected]>; [email protected]; Kuehling, Felix <[email protected]>
Cc: Liu, Aaron <[email protected]>; Guo, Shikai <[email protected]>
Subject: Re: [PATCH 1/3] drm/amdgpu: Add userptr bo support for mGPUs when iommu is onQuoted 4 lines
Am 04.04.23 um 11:56 schrieb Shane Xiao:
Quoted 3 lines
For userptr bo with iommu on, multiple GPUs use same system memory dma mapping address when both
bo_adevand adev in identity mode or in the same iommu group.Hi Christian,
Quoted 7 lines
Quoted 4 lines
WTF? Userptr BOs are not allowed to be exported/imported between different GPUs.
So how can the same userptr BO be used on different GPUs?
If GPUs are all in iommu identity mode which means dma address are the same as physical address, all of the GPUs can see the system memory directly.
In such case, should we export/import the BO, then create a new SG BO for another GPU?
Yes, absolutely. Each userptr BO is only meant to be used on one GPU.
Even if you could use the same BO for multiple GPUs it's not necessary a good idea since you then have live time problems for example.
E.g. what happens when one GPU is hot removed while the other one who imported the BO is still in use?
Felix can you comment on that? My recollection was that we rather improve the storage of DMA addresses instead of duplicating the BOs over different GPUs.
Quoted 7 lines
Quoted 5 lines
For KFD we currently enable sharing of userptr BOs between multiple GPUs by creating a userptr BO for the first GPU, and creating additional SG BOs using the same page list for additional GPUs. That way we don't have to call
hmm_range_faultN times and setup N MMU notifiers for the same address range on an N GPU system. But we do have to create N DMA mappings, which is facilitated by the SG BOs.We have a further optimization to not even store separate DMA addresses per-GPU if they are a direct mapping. In that case we just increase the reference count on the original userptr BO. (I agree that we should also look into more efficient storage of DMA addresses. However, last time we talked about this, you basically told us that scatter gather tables are being deprecated, but I haven't seen the alternative yet.)
I think this patch fixes a potential issue with that optimization. There is an implicit assumption, that the DMA addresses stored in the original userptr BO are a direct mapping, so we can reuse them on other GPUs that also use a direct mapping. But, we didn't actually check that assumption. I think this patch fixes that for systems where system memory is direct mapped on some but not all GPUs.
We will need similar optimization in
svm_range_dma_mapto reuse theprange->dma_addrfor GPUs on same iommu group or direct mapping.
Good point. Optimizing for direct mapping is easy: Just skip the dmamap. Reusing the same dmamapping for multiple GPUs in the same IOMMU group is a bit harder. First you need to identify all the GPUs that are in the same group and then check if one of them already has a DMA mapping that can be reused. I wonder how common this is, and whether it's worth the trouble.
Regards,
Felix
Quoted 59 lines
Regards,
Philip
Quoted 54 lines
This scenario should probably be called out explicitly in the patch description. The condition is also getting pretty hard to read and understand. Maybe move the both-direct-map-or-same-iommu-group conditions into a helper function, say "
amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&reuse_dmamap(adev, bo_adev)".Regards,
FelixQuoted 47 lines
Regards,
Christian.Quoted 42 lines
Best Regards,
ShaneQuoted 37 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int kfd_mem_attach(struct amdgpu_device
Quoted 11 lines
Signed-off-by Shane Xiao <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -804,11 +804,11 @@ static int kfd_mem_attach(struct amdgpu_device*adev, struct
kgd_mem*mem,Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0va + bo_size, vm);if ((adev ==
bo_adev&& !(mem->alloc_flags &
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) ||Quoted 1 line
- (
amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&
adev->ram_is_direct_mapped) ||Quoted 2 lines
-
same_hive) {
+ (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)&&((
adev->ram_is_direct_mapped&&bo_adev->ram_is_direct_mapped) ||Quoted 4 lines
+
adev->dev->iommu_group== bo_adev->dev-iommu_group)) ||
+same_hive){
/* Mappings on the local GPU, or VRAM mappings inthe
Quoted 1 line
- * local hive, or userptr mapping IOMMU direct map
mode
Quoted 6 lines
- * share the original BO
+ * local hive, or userptr mapping in the same dma + * address space share the original BO */
attachment[i]->type =KFD_MEM_ATT_SHARED; bo[i] =mem->bo;