Skip to content

Commit 29d48b8

Browse files
PhilipYangAalexdeucher
authored andcommitted
drm/amdkfd: Fix kfd_process_device_init_vm error handling
Should only destroy the ib_mem and let process cleanup worker to free the outstanding BOs. Reset the pointer in pdd->qpd structure, to avoid NULL pointer access in process destroy worker. BUG: kernel NULL pointer dereference, address: 0000000000000010 Call Trace: amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel+0x46/0xb0 [amdgpu] kfd_process_device_destroy_cwsr_dgpu+0x40/0x70 [amdgpu] kfd_process_destroy_pdds+0x71/0x190 [amdgpu] kfd_process_wq_release+0x2a2/0x3b0 [amdgpu] process_one_work+0x2a1/0x600 worker_thread+0x39/0x3d0 Signed-off-by: Philip Yang <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 38624d2 commit 29d48b8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,13 +689,13 @@ void kfd_process_destroy_wq(void)
689689
}
690690

691691
static void kfd_process_free_gpuvm(struct kgd_mem *mem,
692-
struct kfd_process_device *pdd, void *kptr)
692+
struct kfd_process_device *pdd, void **kptr)
693693
{
694694
struct kfd_dev *dev = pdd->dev;
695695

696-
if (kptr) {
696+
if (kptr && *kptr) {
697697
amdgpu_amdkfd_gpuvm_unmap_gtt_bo_from_kernel(mem);
698-
kptr = NULL;
698+
*kptr = NULL;
699699
}
700700

701701
amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(dev->adev, mem, pdd->drm_priv);
@@ -795,7 +795,7 @@ static void kfd_process_device_destroy_ib_mem(struct kfd_process_device *pdd)
795795
if (!qpd->ib_kaddr || !qpd->ib_base)
796796
return;
797797

798-
kfd_process_free_gpuvm(qpd->ib_mem, pdd, qpd->ib_kaddr);
798+
kfd_process_free_gpuvm(qpd->ib_mem, pdd, &qpd->ib_kaddr);
799799
}
800800

801801
struct kfd_process *kfd_create_process(struct file *filep)
@@ -1277,7 +1277,7 @@ static void kfd_process_device_destroy_cwsr_dgpu(struct kfd_process_device *pdd)
12771277
if (!dev->cwsr_enabled || !qpd->cwsr_kaddr || !qpd->cwsr_base)
12781278
return;
12791279

1280-
kfd_process_free_gpuvm(qpd->cwsr_mem, pdd, qpd->cwsr_kaddr);
1280+
kfd_process_free_gpuvm(qpd->cwsr_mem, pdd, &qpd->cwsr_kaddr);
12811281
}
12821282

12831283
void kfd_process_set_trap_handler(struct qcm_process_device *qpd,
@@ -1598,8 +1598,8 @@ int kfd_process_device_init_vm(struct kfd_process_device *pdd,
15981598
return 0;
15991599

16001600
err_init_cwsr:
1601+
kfd_process_device_destroy_ib_mem(pdd);
16011602
err_reserve_ib_mem:
1602-
kfd_process_device_free_bos(pdd);
16031603
pdd->drm_priv = NULL;
16041604

16051605
return ret;

0 commit comments

Comments
 (0)