Skip to content

Commit 126be9b

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: sync to KFD fences before clearing PTEs
This patch tries to solve the basic problem we also need to sync to the KFD fences of the BO because otherwise it can be that we clear PTEs while the KFD queues are still running. Signed-off-by: Christian König <[email protected]> Acked-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 4771d2e commit 126be9b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,36 @@ int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
260260
return 0;
261261
}
262262

263+
/**
264+
* amdgpu_sync_kfd - sync to KFD fences
265+
*
266+
* @sync: sync object to add KFD fences to
267+
* @resv: reservation object with KFD fences
268+
*
269+
* Extract all KFD fences and add them to the sync object.
270+
*/
271+
int amdgpu_sync_kfd(struct amdgpu_sync *sync, struct dma_resv *resv)
272+
{
273+
struct dma_resv_iter cursor;
274+
struct dma_fence *f;
275+
int r = 0;
276+
277+
dma_resv_iter_begin(&cursor, resv, DMA_RESV_USAGE_BOOKKEEP);
278+
dma_resv_for_each_fence_unlocked(&cursor, f) {
279+
void *fence_owner = amdgpu_sync_get_owner(f);
280+
281+
if (fence_owner != AMDGPU_FENCE_OWNER_KFD)
282+
continue;
283+
284+
r = amdgpu_sync_fence(sync, f);
285+
if (r)
286+
break;
287+
}
288+
dma_resv_iter_end(&cursor);
289+
290+
return r;
291+
}
292+
263293
/* Free the entry back to the slab */
264294
static void amdgpu_sync_entry_free(struct amdgpu_sync_entry *e)
265295
{

drivers/gpu/drm/amd/amdgpu/amdgpu_sync.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int amdgpu_sync_fence(struct amdgpu_sync *sync, struct dma_fence *f);
5151
int amdgpu_sync_resv(struct amdgpu_device *adev, struct amdgpu_sync *sync,
5252
struct dma_resv *resv, enum amdgpu_sync_mode mode,
5353
void *owner);
54+
int amdgpu_sync_kfd(struct amdgpu_sync *sync, struct dma_resv *resv);
5455
struct dma_fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
5556
struct amdgpu_ring *ring);
5657
struct dma_fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,12 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
11691169
AMDGPU_SYNC_EQ_OWNER, vm);
11701170
if (r)
11711171
goto error_free;
1172+
if (bo) {
1173+
r = amdgpu_sync_kfd(&sync, bo->tbo.base.resv);
1174+
if (r)
1175+
goto error_free;
1176+
}
1177+
11721178
} else {
11731179
struct drm_gem_object *obj = &bo->tbo.base;
11741180

0 commit comments

Comments
 (0)