Skip to contentSkip to conversation

drm/amdgpu: Fix xGMI access P2P mapping failure on GFXIP 9.4.3

PATCH New Alex Deucher 3 participants 5 messages May 9, 2023 – May 10, 2023

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix xGMI access P2P mapping failure on GFXIP 9.4.3

From: Rajneesh Bhardwaj <[email protected]>

On GFXIP 9.4.3, we dont need to rely on xGMI hive info to determine P2P access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
index c6bf66c9377f..58a774647573 100644
@@ -813,7 +813,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 	 * if peer device has large BAR. In contrast, access over xGMI is
 	 * allowed for both small and large BAR configurations of peer device
 	 */
-	if ((adev != bo_adev) &&
+	if ((adev != bo_adev && !adev->gmc.is_app_apu) &&
 	    ((mem->domain == AMDGPU_GEM_DOMAIN_VRAM) ||
 	     (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL) ||
 	     (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP))) {
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 1/1 drm/amdkfd: Remove skiping userptr buffer mapping when mmu notifier marks it as invalid

From: Xiaogang Chen <[email protected]>

mmu notifier does not always hold mm->sem during call back. That causes a race condition between kfd userprt buffer mapping and mmu notifier which leds to gpu shadder or SDMA access userptr buffer before it has been mapped to gpu VM. Always map userptr buffer to avoid that though it may make some userprt buffers mapped two times.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ----------
 1 file changed, 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -10
index 58a774647573..40078c0a5585 100644
@@ -1942,16 +1942,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 	 */
 	mutex_lock(&mem->process_info->lock);
 
-	/* Lock notifier lock. If we find an invalid userptr BO, we can be
-	 * sure that the MMU notifier is no longer running
-	 * concurrently and the queues are actually stopped
-	 */
-	if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) {
-		mutex_lock(&mem->process_info->notifier_lock);
-		is_invalid_userptr = !!mem->invalid;
-		mutex_unlock(&mem->process_info->notifier_lock);
-	}
-
 	mutex_lock(&mem->lock);
 
 	domain = mem->domain;
Signature · 1 line
2.40.1
maintainer
#2 lore raw

Re: [PATCH] drm/amdkfd: Remove skiping userptr buffer mapping when mmu notifier marks it as invalid

Am 2023-05-09 um 18:17 schrieb Alex Deucher:

Quoted 8 lines

From: Xiaogang Chen <[email protected]>

mmu notifier does not always hold mm->sem during call back. That causes a race condition between kfd userprt buffer mapping and mmu notifier which leds to gpu shadder or SDMA access userptr buffer before it has been mapped to gpu VM. Always map userptr buffer to avoid that though it may make some userprt buffers mapped two times.

Quoted 4 lines

This patch is no longer needed and should not be applied. It was originally applied to amd-staging-drm-next as patch fcf00f8d29f2fc6bf00531a1447be28b99073cc3 in November 2022. This fixed a race condition due to incorrect assumptions about the mmap lock and MMU notifiers. This hunk was added back by my later patch f95f51a4c335 ("drm/amdgpu: Add notifier lock for KFD userptrs") in December, using our own notifier lock that doesn't suffer from those races.

Regards,
  Felix

Quoted 25 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ----------
  1 file changed, 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -10
index 58a774647573..40078c0a5585 100644
@@ -1942,16 +1942,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
  	 */
  	mutex_lock(&mem->process_info->lock);
 
-	/* Lock notifier lock. If we find an invalid userptr BO, we can be
-	 * sure that the MMU notifier is no longer running
-	 * concurrently and the queues are actually stopped
-	 */
-	if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) {
-		mutex_lock(&mem->process_info->notifier_lock);
-		is_invalid_userptr = !!mem->invalid;
-		mutex_unlock(&mem->process_info->notifier_lock);
-	}
-
  	mutex_lock(&mem->lock);
 
  	domain = mem->domain;
#3 lore raw

Re: [PATCH] drm/amdkfd: Remove skiping userptr buffer mapping when mmu notifier marks it as invalid

Quoted 15 lines · Felix Kuehling

Am 2023-05-09 um 18:17 schrieb Alex Deucher:

Quoted 8 lines

From: Xiaogang Chen <[email protected]>

mmu notifier does not always hold mm->sem during call back. That causes a race condition between kfd userprt buffer mapping and mmu notifier which leds to gpu shadder or SDMA access userptr buffer before it has been mapped to gpu VM. Always map userptr buffer to avoid that though it may make some userprt buffers mapped two times.

Quoted 4 lines
Quoted 8 lines

This patch is no longer needed and should not be applied. It was originally applied to amd-staging-drm-next as patch fcf00f8d29f2fc6bf00531a1447be28b99073cc3 in November 2022. This fixed a race condition due to incorrect assumptions about the mmap lock and MMU notifiers. This hunk was added back by my later patch f95f51a4c335 ("drm/amdgpu: Add notifier lock for KFD userptrs") in December, using our own notifier lock that doesn't suffer from those races.

Thanks. Dropped.

Alex

Quoted 29 lines

Regards,
Felix

Quoted 25 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ----------
  1 file changed, 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -10
index 58a774647573..40078c0a5585 100644
@@ -1942,16 +1942,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
       */
      mutex_lock(&mem->process_info->lock);
 
-     /* Lock notifier lock. If we find an invalid userptr BO, we can be
-      * sure that the MMU notifier is no longer running
-      * concurrently and the queues are actually stopped
-      */
-     if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) {
-             mutex_lock(&mem->process_info->notifier_lock);
-             is_invalid_userptr = !!mem->invalid;
-             mutex_unlock(&mem->process_info->notifier_lock);
-     }
-
      mutex_lock(&mem->lock);
 
      domain = mem->domain;
author maintainer
#4 lore raw

PATCH 1/1 drm/amdgpu: Fix unmapping of aperture

In reply to Alex Deucher

From: Lijo Lazar <[email protected]>

When aperture size is zero, there is no mapping done.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 7 ++++---
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
index d1dca02860b2..5d62e0d5cc11 100644
@@ -4120,7 +4120,7 @@ static void amdgpu_device_unmap_mmio(struct amdgpu_device *adev)
 	adev->mman.aper_base_kaddr = NULL;
 
 	/* Memory manager related */
-	if (!adev->gmc.xgmi.connected_to_cpu) {
+	if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) {
 		arch_phys_wc_del(adev->gmc.vram_mtrr);
 		arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -2
index a5c4f98f8cd1..c6214db42bda 100644
@@ -1080,8 +1080,7 @@ void amdgpu_bo_fini(struct amdgpu_device *adev)
 	amdgpu_ttm_fini(adev);
 
 	if (drm_dev_enter(adev_to_drm(adev), &idx)) {
-
-		if (!adev->gmc.xgmi.connected_to_cpu) {
+		if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) {
 			arch_phys_wc_del(adev->gmc.vram_mtrr);
 			arch_io_free_memtype_wc(adev->gmc.aper_base, adev->gmc.aper_size);
 		}
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -3
index 7885162b7368..254927c596ba 100644
@@ -1848,12 +1848,13 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 		adev->mman.aper_base_kaddr = ioremap_cache(adev->gmc.aper_base,
 				adev->gmc.visible_vram_size);
 
-	else if (!adev->gmc.is_app_apu)
+	else if (adev->gmc.is_app_apu)
+		DRM_DEBUG_DRIVER(
+			"No need to ioremap when real vram size is 0\n");
+	else
 #endif
 		adev->mman.aper_base_kaddr = ioremap_wc(adev->gmc.aper_base,
 				adev->gmc.visible_vram_size);
-	else
-		DRM_DEBUG_DRIVER("No need to ioremap when real vram size is 0\n");
 #endif
 
 	/*
Signature · 1 line
2.40.1