Skip to contentSkip to conversation

drm/amdgpu: Let KFD sync with VM fences

PATCH In review Felix Kuehling 2 participants 3 messages Dec 18, 2023 – Dec 19, 2023

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

PATCH 1/1 drm/amdgpu: Let KFD sync with VM fences

Change the rules for amdgpu_sync_resv to let KFD synchronize with VM fences on page table reservations. This fixes intermittent memory corruption after evictions when using amdgpu_vm_handle_moved to update page tables for VM mappings managed through render nodes.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2 -1
index dcd8c066bc1f..1b013a44ca99 100644
@@ -191,7 +191,8 @@ static bool amdgpu_sync_test_fence(struct amdgpu_device *adev,
 
 	/* Never sync to VM updates either. */
 	if (fence_owner == AMDGPU_FENCE_OWNER_VM &&
-	    owner != AMDGPU_FENCE_OWNER_UNDEFINED)
+	    owner != AMDGPU_FENCE_OWNER_UNDEFINED &&
+	    owner != AMDGPU_FENCE_OWNER_KFD)
 		return false;
 
 	/* Ignore fences depending on the sync mode */
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 18.12.23 um 22:21 schrieb Felix Kuehling:

Quoted 6 lines

Change the rules for amdgpu_sync_resv to let KFD synchronize with VM fences on page table reservations. This fixes intermittent memory corruption after evictions when using amdgpu_vm_handle_moved to update page tables for VM mappings managed through render nodes.

Quoted 18 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +2 -1
index dcd8c066bc1f..1b013a44ca99 100644
@@ -191,7 +191,8 @@ static bool amdgpu_sync_test_fence(struct amdgpu_device *adev,
 
  	/* Never sync to VM updates either. */
  	if (fence_owner == AMDGPU_FENCE_OWNER_VM &&
-	    owner != AMDGPU_FENCE_OWNER_UNDEFINED)
+	    owner != AMDGPU_FENCE_OWNER_UNDEFINED &&
+	    owner != AMDGPU_FENCE_OWNER_KFD)
  		return false;
 
  	/* Ignore fences depending on the sync mode */
maintainer
#2 lore raw

Am 19.12.23 um 08:51 schrieb Christian König:

Quoted 9 lines

Am 18.12.23 um 22:21 schrieb Felix Kuehling:

Quoted 6 lines

Change the rules for amdgpu_sync_resv to let KFD synchronize with VM fences on page table reservations. This fixes intermittent memory corruption after evictions when using amdgpu_vm_handle_moved to update page tables for VM mappings managed through render nodes.

In the long term we should probably handle this by changing how VM fences are added to the resv object.

Implicit fences should be added with DMA_RESV_USAGE_KERNEL and explicit updates with DMA_RESV_USAGE_BOOKKEEP.

Regards,
Christian.

Quoted 19 lines
Quoted 18 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c +0 -0
index dcd8c066bc1f..1b013a44ca99 100644
@@ -191,7 +191,8 @@ static bool amdgpu_sync_test_fence(struct 
 amdgpu_device *adev,
         /* Never sync to VM updates either. */

      if (fence_owner == AMDGPU_FENCE_OWNER_VM && -        owner != AMDGPU_FENCE_OWNER_UNDEFINED) +        owner != AMDGPU_FENCE_OWNER_UNDEFINED && +        owner != AMDGPU_FENCE_OWNER_KFD) return false;
        /* Ignore fences depending on the sync mode */