Skip to content

Commit 8f0e2d5

Browse files
erichuang22alexdeucher
authored andcommitted
Revert "Revert "drm/amdkfd: Make TLB flush conditional on mapping""
This reverts commit 7ed9876. Revert reason: The issue has been resolved. Signed-off-by: Eric Huang <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent e9949dd commit 8f0e2d5

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
271271
struct kgd_dev *kgd, struct kgd_mem *mem, void *drm_priv,
272272
uint64_t *size);
273273
int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
274-
struct kgd_dev *kgd, struct kgd_mem *mem, void *drm_priv);
274+
struct kgd_dev *kgd, struct kgd_mem *mem, void *drm_priv, bool *table_freed);
275275
int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(
276276
struct kgd_dev *kgd, struct kgd_mem *mem, void *drm_priv);
277277
int amdgpu_amdkfd_gpuvm_sync_memory(

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ static void unmap_bo_from_gpuvm(struct kgd_mem *mem,
10571057

10581058
static int update_gpuvm_pte(struct kgd_mem *mem,
10591059
struct kfd_mem_attachment *entry,
1060-
struct amdgpu_sync *sync)
1060+
struct amdgpu_sync *sync,
1061+
bool *table_freed)
10611062
{
10621063
struct amdgpu_bo_va *bo_va = entry->bo_va;
10631064
struct amdgpu_device *adev = entry->adev;
@@ -1068,7 +1069,7 @@ static int update_gpuvm_pte(struct kgd_mem *mem,
10681069
return ret;
10691070

10701071
/* Update the page tables */
1071-
ret = amdgpu_vm_bo_update(adev, bo_va, false);
1072+
ret = amdgpu_vm_bo_update(adev, bo_va, false, table_freed);
10721073
if (ret) {
10731074
pr_err("amdgpu_vm_bo_update failed\n");
10741075
return ret;
@@ -1080,7 +1081,8 @@ static int update_gpuvm_pte(struct kgd_mem *mem,
10801081
static int map_bo_to_gpuvm(struct kgd_mem *mem,
10811082
struct kfd_mem_attachment *entry,
10821083
struct amdgpu_sync *sync,
1083-
bool no_update_pte)
1084+
bool no_update_pte,
1085+
bool *table_freed)
10841086
{
10851087
int ret;
10861088

@@ -1097,7 +1099,7 @@ static int map_bo_to_gpuvm(struct kgd_mem *mem,
10971099
if (no_update_pte)
10981100
return 0;
10991101

1100-
ret = update_gpuvm_pte(mem, entry, sync);
1102+
ret = update_gpuvm_pte(mem, entry, sync, table_freed);
11011103
if (ret) {
11021104
pr_err("update_gpuvm_pte() failed\n");
11031105
goto update_gpuvm_pte_failed;
@@ -1605,7 +1607,8 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
16051607
}
16061608

16071609
int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
1608-
struct kgd_dev *kgd, struct kgd_mem *mem, void *drm_priv)
1610+
struct kgd_dev *kgd, struct kgd_mem *mem,
1611+
void *drm_priv, bool *table_freed)
16091612
{
16101613
struct amdgpu_device *adev = get_amdgpu_device(kgd);
16111614
struct amdgpu_vm *avm = drm_priv_to_vm(drm_priv);
@@ -1693,7 +1696,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
16931696
entry->va, entry->va + bo_size, entry);
16941697

16951698
ret = map_bo_to_gpuvm(mem, entry, ctx.sync,
1696-
is_invalid_userptr);
1699+
is_invalid_userptr, table_freed);
16971700
if (ret) {
16981701
pr_err("Failed to map bo to gpuvm\n");
16991702
goto out_unreserve;
@@ -2143,7 +2146,7 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
21432146
continue;
21442147

21452148
kfd_mem_dmaunmap_attachment(mem, attachment);
2146-
ret = update_gpuvm_pte(mem, attachment, &sync);
2149+
ret = update_gpuvm_pte(mem, attachment, &sync, NULL);
21472150
if (ret) {
21482151
pr_err("%s: update PTE failed\n", __func__);
21492152
/* make sure this gets validated again */
@@ -2349,7 +2352,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
23492352
continue;
23502353

23512354
kfd_mem_dmaunmap_attachment(mem, attachment);
2352-
ret = update_gpuvm_pte(mem, attachment, &sync_obj);
2355+
ret = update_gpuvm_pte(mem, attachment, &sync_obj, NULL);
23532356
if (ret) {
23542357
pr_debug("Memory eviction: update PTE failed. Try again\n");
23552358
goto validate_map_fail;

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
13931393
long err = 0;
13941394
int i;
13951395
uint32_t *devices_arr = NULL;
1396+
bool table_freed = false;
13961397

13971398
dev = kfd_device_by_id(GET_GPU_ID(args->handle));
13981399
if (!dev)
@@ -1450,7 +1451,8 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
14501451
goto get_mem_obj_from_handle_failed;
14511452
}
14521453
err = amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
1453-
peer->kgd, (struct kgd_mem *)mem, peer_pdd->drm_priv);
1454+
peer->kgd, (struct kgd_mem *)mem,
1455+
peer_pdd->drm_priv, &table_freed);
14541456
if (err) {
14551457
pr_err("Failed to map to gpu %d/%d\n",
14561458
i, args->n_devices);
@@ -1468,16 +1470,17 @@ static int kfd_ioctl_map_memory_to_gpu(struct file *filep,
14681470
}
14691471

14701472
/* Flush TLBs after waiting for the page table updates to complete */
1471-
for (i = 0; i < args->n_devices; i++) {
1472-
peer = kfd_device_by_id(devices_arr[i]);
1473-
if (WARN_ON_ONCE(!peer))
1474-
continue;
1475-
peer_pdd = kfd_get_process_device_data(peer, p);
1476-
if (WARN_ON_ONCE(!peer_pdd))
1477-
continue;
1478-
kfd_flush_tlb(peer_pdd, TLB_FLUSH_LEGACY);
1473+
if (table_freed) {
1474+
for (i = 0; i < args->n_devices; i++) {
1475+
peer = kfd_device_by_id(devices_arr[i]);
1476+
if (WARN_ON_ONCE(!peer))
1477+
continue;
1478+
peer_pdd = kfd_get_process_device_data(peer, p);
1479+
if (WARN_ON_ONCE(!peer_pdd))
1480+
continue;
1481+
kfd_flush_tlb(peer_pdd, TLB_FLUSH_LEGACY);
1482+
}
14791483
}
1480-
14811484
kfree(devices_arr);
14821485

14831486
return err;

drivers/gpu/drm/amd/amdkfd/kfd_process.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ static int kfd_process_alloc_gpuvm(struct kfd_process_device *pdd,
714714
if (err)
715715
goto err_alloc_mem;
716716

717-
err = amdgpu_amdkfd_gpuvm_map_memory_to_gpu(kdev->kgd, mem, pdd->drm_priv);
717+
err = amdgpu_amdkfd_gpuvm_map_memory_to_gpu(kdev->kgd, mem,
718+
pdd->drm_priv, NULL);
718719
if (err)
719720
goto err_map_mem;
720721

0 commit comments

Comments
 (0)