drm/amdgpu: fix a potential circular locking dependency
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix a potential circular locking dependency
[ 653.902305] ======================================================
[ 653.902928] WARNING: possible circular locking dependency detected
[ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE
[ 653.904098] ------------------------------------------------------
[ 653.904675] amdgpu_test/3975 is trying to acquire lock:
[ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu]
[ 653.905953]
but task is already holding lock:
[ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.}, at: ttm_eu_reserve_buffers+0x1ae/0x520 [ttm]
[ 653.907694]
which lock already depends on the new lock.[ 653.909423]
the existing dependency chain (in reverse order) is:
[ 653.910594]
-> #1 (reservation_ww_class_mutex){+.+.}:
[ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120
[ 653.912350] ww_mutex_lock+0x73/0x80
[ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu]
[ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu]
[ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu]
[ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu]
[ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu]
[ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu]
[ 653.916959] local_pci_probe+0x47/0xa0
[ 653.917570] work_for_cpu_fn+0x1a/0x30
[ 653.918184] process_one_work+0x29e/0x630
[ 653.918803] worker_thread+0x22b/0x3f0
[ 653.919427] kthread+0x12f/0x150
[ 653.920047] ret_from_fork+0x3a/0x50
[ 653.920661]
-> #0 (&adev->reset_sem){.+.+}:
[ 653.921893] __lock_acquire+0x13ec/0x16e0
[ 653.922531] lock_acquire+0xb8/0x1c0
[ 653.923174] down_read+0x48/0x230
[ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu]
[ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm]
[ 653.925283] drm_ioctl+0x389/0x450 [drm]
[ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu]
[ 653.926686] ksys_ioctl+0x98/0xb0
[ 653.927357] __x64_sys_ioctl+0x1a/0x20
[ 653.928030] do_syscall_64+0x5f/0x250
[ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe
[ 653.929373]
other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:
[ 653.932647] CPU0 CPU1
[ 653.933287] ---- ----
[ 653.933911] lock(reservation_ww_class_mutex);
[ 653.934530] lock(&adev->reset_sem);
[ 653.935154] lock(reservation_ww_class_mutex);
[ 653.935766] lock(&adev->reset_sem);
[ 653.936360]
*** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975:
[ 653.938574] #0: ffffb2a862d6bcd0 (reservation_ww_class_acquire){+.+.}, at: amdgpu_gem_va_ioctl+0x39b/0x4f0 [amdgpu]
[ 653.939233] #1: ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.}, at: ttm_eu_reserve_buffers+0x1ae/0x520 [ttm]change the order of reservation_ww_class_mutex and adev->reset_sem in amdgpu_gem_va_ioctl the same as ones in amdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3 -4
@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);
@@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags =amdgpu_gem_va_map_flags (adev, args->flags);
@@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,amdgpu_gem_va_update_vm (adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list); error_unref: +up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 57 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.}, at: ttm_eu_reserve_buffers+0x1ae/0x520 [ttm] [ 653.907694] which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***
Quoted 7 lines
[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0 (reservation_ww_class_acquire){+.+.}, at: amdgpu_gem_va_ioctl+0x39b/0x4f0 [amdgpu] [ 653.939233] #1: ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.}, at: ttm_eu_reserve_buffers+0x1ae/0x520 [ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.
It may be better to fix it the other way around in amdgpu_amdkfd_alloc_gtt_mem. Always take the reset_sem inside the reservation. Otherwise you will never be able to take the reset_sem while any BOs are reserved. That's probably going to cause you other problems later.
That makes me wonder, why do you need the reset_sem in amdgpu_amdkfd_alloc_gtt_mem in the first place? There is no obvious hardware access in that function. Is it for amdgpu_ttm_alloc_gart updating the GART table through HDP?
Regards,
Felix
Quoted 29 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-2@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);@@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags =amdgpu_gem_va_map_flags (adev, args->flags);@@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,amdgpu_gem_va_update_vm (adev, &fpriv->vm, bo_va, args->operation);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-2-up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list); error_unref: +up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 71 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 57 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.}, at: ttm_eu_reserve_buffers+0x1ae/0x520 [ttm] [ 653.907694] which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***Quoted 7 lines
[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0 (reservation_ww_class_acquire){+.+.}, at: amdgpu_gem_va_ioctl+0x39b/0x4f0 [amdgpu] [ 653.939233] #1: ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.}, at: ttm_eu_reserve_buffers+0x1ae/0x520 [ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.
Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?
I was wondering the same thing for the amdgpu_gem_va_ioctl() as well.
We shouldn't have any hardware access here, so taking the reset_sem looks like overkill to me.
Christian.
Quoted 38 lines
Regards,
FelixQuoted 33 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-4@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);@@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags =amdgpu_gem_va_map_flags (adev, args->flags);@@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,amdgpu_gem_va_update_vm (adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0error_unref: +up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Re: I was wondering the same thing for the amdgpu_gem_va_ioctl() as well. We shouldn't have any hardware access here, so taking the reset_sem looks like overkill to me.
[Dennis Li] amdgpu_vm_bo_unmap, amdgpu_vm_bo_clear_mappings, amdgpu_vm_bo_replace_map and amdgpu_gem_va_update_vm all a chance to access hardware.
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependency
Am 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 74 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 59 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.
Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?
I was wondering the same thing for the amdgpu_gem_va_ioctl() as well.
We shouldn't have any hardware access here, so taking the reset_sem looks like overkill to me.
Christian.
Quoted 39 lines
Regards,
FelixQuoted 34 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-5@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates); @@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 12.08.20 um 03:33 schrieb Li, Dennis:
Quoted 7 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Re: I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well. We shouldn't have any hardware access here, so taking thereset_semlooks like overkill to me.[Dennis Li]
amdgpu_vm_bo_unmap,amdgpu_vm_bo_clear_mappings,amdgpu_vm_bo_replace_mapandamdgpu_gem_va_update_vmall a chance to access hardware.
This is complete nonsense. The functions intentionally work through the scheduler to avoid accessing the hardware directly for exactly that reason.
The only hardware access we have here is the HDP flush and that can fail in the case of a GPU reset without causing problems.
Regards,
Christian.
Quoted 132 lines
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 74 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 59 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well.We shouldn't have any hardware access here, so taking the
reset_semlooks like overkill to me.Christian.
Quoted 38 lines
Regards,
FelixQuoted 34 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-5@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates); @@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 03:33 schrieb Li, Dennis:
Quoted 7 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Re: I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well. We shouldn't have any hardware access here, so taking thereset_semlooks like overkill to me.[Dennis Li]
amdgpu_vm_bo_unmap,amdgpu_vm_bo_clear_mappings,amdgpu_vm_bo_replace_mapandamdgpu_gem_va_update_vmall a chance to access hardware.
This is complete nonsense. The functions intentionally work through the scheduler to avoid accessing the hardware directly for exactly that reason.
The only hardware access we have here is the HDP flush and that can fail in the case of a GPU reset without causing problems.
[Dennis Li] amdgpu_vm_bo_clear_mappings -> amdgpu_vm_prt_get -> amdgpu_vm_update_prt_state -> gmc_v8_0_set_prt
Regards,
Christian.
Quoted 140 lines
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 76 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 61 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well.We shouldn't have any hardware access here, so taking the
reset_semlooks like overkill to me.Christian.
Quoted 41 lines
Regards,
FelixQuoted 37 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);@@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,bo_va = NULL; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-5-down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void +*data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 12.08.20 um 11:23 schrieb Li, Dennis:
Quoted 7 lines
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 03:33 schrieb Li, Dennis:
Quoted 4 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Quoted 8 lines
Quoted 3 lines
Re: I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well. We shouldn't have any hardware access here, so taking thereset_semlooks like overkill to me.[Dennis Li]
amdgpu_vm_bo_unmap,amdgpu_vm_bo_clear_mappings,amdgpu_vm_bo_replace_mapandamdgpu_gem_va_update_vmall a chance to access hardware.This is complete nonsense. The functions intentionally work through the scheduler to avoid accessing the hardware directly for exactly that reason.
The only hardware access we have here is the HDP flush and that can fail in the case of a GPU reset without causing problems.
[Dennis Li]
amdgpu_vm_bo_clear_mappings->amdgpu_vm_prt_get->amdgpu_vm_update_prt_state->gmc_v8_0_set_prt
That is for pre gfx9 hardware and only called once during initial enabling of the feature.
Please remove that locking again since it is clearly completely against the driver design.
Christian.
Quoted 143 lines
Regards,
Christian.Quoted 139 lines
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 76 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 61 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well.We shouldn't have any hardware access here, so taking the
reset_semlooks like overkill to me.Christian.
Quoted 41 lines
Regards,
FelixQuoted 37 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);@@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,bo_va = NULL; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-5-down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void +*data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 11:23 schrieb Li, Dennis:
Quoted 9 lines
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 03:33 schrieb Li, Dennis:
Quoted 6 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Re: I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well. We shouldn't have any hardware access here, so taking thereset_semlooks like overkill to me.
Quoted 7 lines
Quoted 1 line
[Dennis Li]
amdgpu_vm_bo_unmap,amdgpu_vm_bo_clear_mappings,amdgpu_vm_bo_replace_mapandamdgpu_gem_va_update_vmall a chance to access hardware.This is complete nonsense. The functions intentionally work through the scheduler to avoid accessing the hardware directly for exactly that reason.
The only hardware access we have here is the HDP flush and that can fail in the case of a GPU reset without causing problems.
[Dennis Li]
amdgpu_vm_bo_clear_mappings->amdgpu_vm_prt_get->amdgpu_vm_update_prt_state->gmc_v8_0_set_prt
That is for pre gfx9 hardware and only called once during initial enabling of the feature.
Please remove that locking again since it is clearly completely against the driver design.
[Dennis Li] okay, if you agree, I will change to only protect amdgpu_gem_va_update_vm in this function.
Christian.
Quoted 144 lines
Regards,
Christian.Quoted 140 lines
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 76 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 61 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well.We shouldn't have any hardware access here, so taking the
reset_semlooks like overkill to me.Christian.
Quoted 41 lines
Regards,
FelixQuoted 37 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);@@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,bo_va = NULL; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-5-down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void +*data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 12.08.20 um 12:02 schrieb Li, Dennis:
Quoted 17 lines
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 11:23 schrieb Li, Dennis:
Quoted 14 lines
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 03:33 schrieb Li, Dennis:
Quoted 7 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Re: I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well. We shouldn't have any hardware access here, so taking thereset_semlooks like overkill to me.[Dennis Li]
amdgpu_vm_bo_unmap,amdgpu_vm_bo_clear_mappings,amdgpu_vm_bo_replace_mapandamdgpu_gem_va_update_vmall a chance to access hardware.This is complete nonsense. The functions intentionally work through the scheduler to avoid accessing the hardware directly for exactly that reason.
The only hardware access we have here is the HDP flush and that can fail in the case of a GPU reset without causing problems.
Quoted 7 lines
Quoted 2 lines
[Dennis Li]
amdgpu_vm_bo_clear_mappings->amdgpu_vm_prt_get->amdgpu_vm_update_prt_state->gmc_v8_0_set_prtThat is for pre gfx9 hardware and only called once during initial enabling of the feature.
Please remove that locking again since it is clearly completely against the driver design.
[Dennis Li] okay, if you agree, I will change to only protect
amdgpu_gem_va_update_vmin this function.
Better even only protect the amdgpu_vm_update_prt_state() function.
Christian.
Quoted 146 lines
Christian.
Quoted 143 lines
Regards,
Christian.Quoted 140 lines
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 76 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 61 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well.We shouldn't have any hardware access here, so taking the
reset_semlooks like overkill to me.Christian.
Quoted 41 lines
Regards,
FelixQuoted 37 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r =ttm_eu_reserve_buffers (&ticket, &list, true, &duplicates);@@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,bo_va = NULL; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-5-down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void +*data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 12:02 schrieb Li, Dennis:
Quoted 17 lines
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 11:23 schrieb Li, Dennis:
Quoted 14 lines
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 03:33 schrieb Li, Dennis:
Quoted 7 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Christian,
Re: I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well. We shouldn't have any hardware access here, so taking thereset_semlooks like overkill to me.[Dennis Li]
amdgpu_vm_bo_unmap,amdgpu_vm_bo_clear_mappings,amdgpu_vm_bo_replace_mapandamdgpu_gem_va_update_vmall a chance to access hardware.This is complete nonsense. The functions intentionally work through the scheduler to avoid accessing the hardware directly for exactly that reason.
The only hardware access we have here is the HDP flush and that can fail in the case of a GPU reset without causing problems.
Quoted 7 lines
Quoted 2 lines
[Dennis Li]
amdgpu_vm_bo_clear_mappings->amdgpu_vm_prt_get->amdgpu_vm_update_prt_state->gmc_v8_0_set_prtThat is for pre gfx9 hardware and only called once during initial enabling of the feature.
Please remove that locking again since it is clearly completely against the driver design.
[Dennis Li] okay, if you agree, I will change to only protect
amdgpu_gem_va_update_vmin this function.
Better even only protect the amdgpu_vm_update_prt_state() function.
[Dennis Li] Got it. According to your suggestion, I will also narrow down the scope of reset_sem in other functions.
Christian.
Quoted 147 lines
Christian.
Quoted 144 lines
Regards,
Christian.Quoted 141 lines
Best Regards
Dennis Li
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, August 12, 2020 12:15 AM
To: Kuehling, Felix <[email protected]>; Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 11.08.20 um 15:57 schrieb Felix Kuehling:
Quoted 77 lines
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 62 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8(reservation_ww_class_mutex){+.+.},
at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.Quoted 4 lines
That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?I was wondering the same thing for the
amdgpu_gem_va_ioctl()as well.We shouldn't have any hardware access here, so taking the
reset_semlooks like overkill to me.Christian.
Quoted 41 lines
Regards,
FelixQuoted 37 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true,&duplicates); @@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,bo_va = NULL; }drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-5-down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void +*data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Hi, Felix,
Re: It may be better to fix it the other way around in amdgpu_amdkfd_alloc_gtt_mem. Always take the reset_sem inside the reservation. Otherwise you will never be able to take the reset_sem while any BOs are reserved. That's probably going to cause you other problems later. [Dennis Li] Thanks that you find the potential issue, I will change it in version 2.
Re: That makes me wonder, why do you need the reset_sem in amdgpu_amdkfd_alloc_gtt_mem in the first place? There is no obvious hardware access in that function. Is it for amdgpu_ttm_alloc_gart updating the GART table through HDP?
[Dennis Li] Yes, amdgpu_gart_bind will flush HDP and TLB. I have considered to only protect amdgpu_ttm_alloc_gart before. But I worry other functions will access hardware in the future. Therefore I select an aggressive approach which lock reset_sem at the beginning of entry functions of amdgpu driver.
Best Regards
Dennis Li
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, August 11, 2020 9:57 PM
To: Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependency
Am 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 59 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0
Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.
It may be better to fix it the other way around in amdgpu_amdkfd_alloc_gtt_mem. Always take the reset_sem inside the reservation. Otherwise you will never be able to take the reset_sem while any BOs are reserved. That's probably going to cause you other problems later.
That makes me wonder, why do you need the reset_sem in amdgpu_amdkfd_alloc_gtt_mem in the first place? There is no obvious hardware access in that function. Is it for amdgpu_ttm_alloc_gart updating the GART table through HDP?
Regards,
Felix
Quoted 30 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-3@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates); @@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-2-up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list); error_unref: +up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 12.08.20 um 03:19 schrieb Li, Dennis:
Quoted 9 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Felix,
Re: It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later. [Dennis Li] Thanks that you find the potential issue, I will change it in version 2.Re: That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP? [Dennis Li] Yes,amdgpu_gart_bindwill flush HDP and TLB. I have considered to only protectamdgpu_ttm_alloc_gartbefore.
That access is irrelevant and the lock should be removed or changed into a trylock.
See we need the HDP flush only because the hardware could have accessed the data before.
But after a GPU reset the HDP is known to be clean, so this doesn't need any protection.
Quoted 1 line
But I worry other functions will access hardware in the future. Therefore I select an aggressive approach which lock
reset_semat the beginning of entry functions of amdgpu driver.
This is not a good idea. We used to have such a global lock before and removed it because it caused all kind of problems.
When was this added? Looks like it slipped under my radar or I wasn't awake enough at that moment.
Christian.
Quoted 119 lines
Best Regards
Dennis Li
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, August 11, 2020 9:57 PM
To: Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 59 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?Regards,
FelixQuoted 34 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +3
-5@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates); @@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Am 12.08.20 um 03:19 schrieb Li, Dennis:
Quoted 9 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Felix,
Re: It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later. [Dennis Li] Thanks that you find the potential issue, I will change it in version 2.Re: That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP? [Dennis Li] Yes,amdgpu_gart_bindwill flush HDP and TLB. I have considered to only protectamdgpu_ttm_alloc_gartbefore.
That access is irrelevant and the lock should be removed or changed into a trylock.
See we need the HDP flush only because the hardware could have accessed the data before.
But after a GPU reset the HDP is known to be clean, so this doesn't need any protection.
Quoted 1 line
But I worry other functions will access hardware in the future. Therefore I select an aggressive approach which lock
reset_semat the beginning of entry functions of amdgpu driver.
This is not a good idea. We used to have such a global lock before and removed it because it caused all kind of problems.
[Dennis Li] okay. If you don't agree this aggressive approach. I will change to protect amdgpu_ttm_alloc_gart only.
When was this added? Looks like it slipped under my radar or I wasn't awake enough at that moment.
Christian.
Quoted 123 lines
Best Regards
Dennis Li
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, August 11, 2020 9:57 PM
To: Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 59 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted: G OE [ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock: [ 653.905241] ffff97848f8647a0 (&adev->reset_sem){.+.+}, at: amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock: [ 653.907087] ffff9744adbee1f8 (reservation_ww_class_mutex){+.+.},at:
ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423] the existing dependency chain (in reverse order) is: [ 653.910594] -> #1 (reservation_ww_class_mutex){+.+.}: [ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350] ww_mutex_lock+0x73/0x80 [ 653.913044] amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380 [amdgpu] [ 653.913724] kgd2kfd_device_init+0x13f/0x5e0 [amdgpu] [ 653.914388] amdgpu_amdkfd_device_init+0x155/0x190 [amdgpu] [ 653.915033] amdgpu_device_init+0x1303/0x1e10 [amdgpu] [ 653.915685] amdgpu_driver_load_kms+0x5c/0x2c0 [amdgpu] [ 653.916349] amdgpu_pci_probe+0x11d/0x200 [amdgpu] [ 653.916959] local_pci_probe+0x47/0xa0 [ 653.917570] work_for_cpu_fn+0x1a/0x30 [ 653.918184] process_one_work+0x29e/0x630 [ 653.918803] worker_thread+0x22b/0x3f0 [ 653.919427] kthread+0x12f/0x150 [ 653.920047] ret_from_fork+0x3a/0x50 [ 653.920661] -> #0 (&adev->reset_sem){.+.+}: [ 653.921893] __lock_acquire+0x13ec/0x16e0 [ 653.922531] lock_acquire+0xb8/0x1c0 [ 653.923174] down_read+0x48/0x230 [ 653.923886] amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.924588] drm_ioctl_kernel+0xb6/0x100 [drm] [ 653.925283] drm_ioctl+0x389/0x450 [drm] [ 653.926013] amdgpu_drm_ioctl+0x4f/0x80 [amdgpu] [ 653.926686] ksys_ioctl+0x98/0xb0 [ 653.927357] __x64_sys_ioctl+0x1a/0x20 [ 653.928030] do_syscall_64+0x5f/0x250 [ 653.928697] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 653.929373] other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:[ 653.932647] CPU0 CPU1 [ 653.933287] ---- ---- [ 653.933911] lock(reservation_ww_class_mutex); [ 653.934530] lock(&adev->reset_sem); [ 653.935154] lock(reservation_ww_class_mutex); [ 653.935766] lock(&adev->reset_sem); [ 653.936360] *** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975: [ 653.938574] #0: ffffb2a862d6bcd0Quoted 8 lines
(reservation_ww_class_acquire){+.+.}, at:
amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?Regards,
FelixQuoted 35 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +4
-5@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, abo =NULL ; } +down_read (&adev->reset_sem); +amdgpu_vm_get_pd_bo (&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates); @@ -670,8 +672,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, bo_va =NULL ; } -down_read (&adev->reset_sem); -switch (args->operation) {case AMDGPU_VA_OP_MAP : va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void +*data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); -up_read (&adev->reset_sem); - error_backoff:ttm_eu_backoff_reservation (&ticket, &list);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, · line 711
Quoted 5 lines
error_unref:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0+up_read (&adev->reset_sem);drm_gem_object_put_unlocked (gobj);return r; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 2020-08-12 um 4:53 a.m. schrieb Christian König:
Quoted 29 lines
Am 12.08.20 um 03:19 schrieb Li, Dennis:
Quoted 12 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Felix,
Re: It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.
[Dennis Li] Thanks that you find the potential issue, I will change it in version 2.Quoted 6 lines
Re: That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?
[Dennis Li] Yes,amdgpu_gart_bindwill flush HDP and TLB. I have considered to only protectamdgpu_ttm_alloc_gartbefore.That access is irrelevant and the lock should be removed or changed into a trylock.
See we need the HDP flush only because the hardware could have accessed the data before.
But after a GPU reset the HDP is known to be clean, so this doesn't need any protection.
Quoted 6 lines
Quoted 3 lines
But I worry other functions will access hardware in the future. Therefore I select an aggressive approach which lock
reset_semat the beginning of entry functions of amdgpu driver.This is not a good idea. We used to have such a global lock before and removed it because it caused all kind of problems.
In most cases it's a global read-lock, so most of the time it should not impact concurrency. The only "writer" that blocks all readers is the GPU reset.
Quoted 3 lines
When was this added? Looks like it slipped under my radar or I wasn't awake enough at that moment.
The change that added the reset_sem added read-locks in about 70 places. I'm still concerned that this will be hard to maintain, to make sure future HW access will do the necessary locking. I guess that's the motivation for doing the locking more coarse-grained. Taking the lock higher up the call chains means fewer places that take the lock and new low-level code may not need its own locking in the future because it's already covered by higher-level callers.
On the other hand, it needs to be low enough in the call chains to avoid recursive locking or circular dependencies with other locks.
Regards,
Felix
Quoted 130 lines
Christian.
Quoted 127 lines
Best Regards
Dennis Li
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, August 11, 2020 9:57 PM
To: Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 66 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted:
G OE
[ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock:
[ 653.905241]ffff97848f8647a0(&adev->reset_sem){.+.+}, at:amdgpu_gem_va_ioctl+0x286/0x4f0[amdgpu] [ 653.905953] but task is already holding lock:
[ 653.907087]ffff9744adbee1f8(reservation_ww_class_mutex){+.+.},
at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694] which lock already depends on the new lock.[ 653.909423]
the existing dependency chain (in reverse order) is:
[ 653.910594]
-> #1 (reservation_ww_class_mutex){+.+.}:
[ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350]ww_mutex_lock+0x73/0x80
[ 653.913044]amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380[amdgpu] [ 653.913724]kgd2kfd_device_init+0x13f/0x5e0[amdgpu] [ 653.914388]amdgpu_amdkfd_device_init+0x155/0x190[amdgpu] [ 653.915033]amdgpu_device_init+0x1303/0x1e10[amdgpu] [ 653.915685]amdgpu_driver_load_kms+0x5c/0x2c0[amdgpu] [ 653.916349]amdgpu_pci_probe+0x11d/0x200[amdgpu] [ 653.916959]local_pci_probe+0x47/0xa0
[ 653.917570]work_for_cpu_fn+0x1a/0x30
[ 653.918184]process_one_work+0x29e/0x630
[ 653.918803]worker_thread+0x22b/0x3f0
[ 653.919427]kthread+0x12f/0x150
[ 653.920047]ret_from_fork+0x3a/0x50
[ 653.920661]
-> #0 (&adev->reset_sem){.+.+}:
[ 653.921893]__lock_acquire+0x13ec/0x16e0
[ 653.922531]lock_acquire+0xb8/0x1c0
[ 653.923174]down_read+0x48/0x230
[ 653.923886]amdgpu_gem_va_ioctl+0x286/0x4f0[amdgpu] [ 653.924588]drm_ioctl_kernel+0xb6/0x100[drm]
[ 653.925283]drm_ioctl+0x389/0x450[drm]
[ 653.926013]amdgpu_drm_ioctl+0x4f/0x80[amdgpu] [ 653.926686]ksys_ioctl+0x98/0xb0
[ 653.927357]__x64_sys_ioctl+0x1a/0x20
[ 653.928030]do_syscall_64+0x5f/0x250
[ 653.928697]entry_SYSCALL_64_after_hwframe+0x49/0xbe[ 653.929373]
other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:
[ 653.932647] CPU0 CPU1
[ 653.933287] ---- ----
[ 653.933911]lock(reservation_ww_class_mutex);
[ 653.934530]lock(&adev->reset_sem); [ 653.935154]lock(reservation_ww_class_mutex);
[ 653.935766]lock(&adev->reset_sem);
[ 653.936360]
*** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975:
[ 653.938574] #0:ffffb2a862d6bcd0(reservation_ww_class_acquire){+.+.}, at:amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]Quoted 3 lines
change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?Regards,
FelixQuoted 30 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev,void *data, abo = NULL; } + down_read(&adev->reset_sem); + amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true,&duplicates); @@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,
bo_va= NULL;
}
-down_read(&adev->reset_sem);
-
switch (args->operation) {
caseAMDGPU_VA_OP_MAP:
va_flags=amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12
+701,11 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation);
-up_read(&adev->reset_sem);
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
-
error_backoff:
ttm_eu_backoff_reservation(&ticket, &list);
error_unref:
+up_read(&adev->reset_sem);
drm_gem_object_put_unlocked(gobj);
return r;
}
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 12.08.20 um 17:07 schrieb Felix Kuehling:
Quoted 49 lines
Am 2020-08-12 um 4:53 a.m. schrieb Christian König:
Quoted 25 lines
Am 12.08.20 um 03:19 schrieb Li, Dennis:
Quoted 12 lines
[AMD Official Use Only - Internal Distribution Only]
Hi, Felix,
Re: It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.
[Dennis Li] Thanks that you find the potential issue, I will change it in version 2.Quoted 6 lines
Re: That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?
[Dennis Li] Yes,amdgpu_gart_bindwill flush HDP and TLB. I have considered to only protectamdgpu_ttm_alloc_gartbefore.That access is irrelevant and the lock should be removed or changed into a trylock.
See we need the HDP flush only because the hardware could have accessed the data before.
Quoted 8 lines
But after a GPU reset the HDP is known to be clean, so this doesn't need any protection.
Quoted 3 lines
But I worry other functions will access hardware in the future.
Therefore I select an aggressive approach which lockreset_semat the beginning of entry functions of amdgpu driver.This is not a good idea. We used to have such a global lock before and removed it because it caused all kind of problems.
In most cases it's a global read-lock, so most of the time it should not impact concurrency. The only "writer" that blocks all readers is the GPU reset.
Quoted 2 lines
When was this added? Looks like it slipped under my radar or I wasn't awake enough at that moment.
The change that added the
reset_semadded read-locks in about 70 places. I'm still concerned that this will be hard to maintain, to make sure future HW access will do the necessary locking. I guess that's the motivation for doing the locking more coarse-grained. Taking the lock higher up the call chains means fewer places that take the lock and new low-level code may not need its own locking in the future because it's already covered by higher-level callers.
Quoted 2 lines
On the other hand, it needs to be low enough in the call chains to avoid recursive locking or circular dependencies with other locks.
Well the whole approach is a NAK. We already tried this and it didn't worked at all.
See how much effort it was to remove the global reset rwsem again in the past.
We have only minimal functions accessing the hardware directly which can run concurrently with a GPU reset.
Everything else works through ring buffers where the processing is stopped before we reset the GPU.
So the whole thing is just a bad idea as far as I can see.
Regards,
Christian.
Quoted 137 lines
Regards,
FelixQuoted 132 lines
Christian.
Quoted 130 lines
Best Regards
Dennis Li
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, August 11, 2020 9:57 PM
To: Li, Dennis <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix a potential circular locking dependencyAm 2020-08-11 um 5:32 a.m. schrieb Dennis Li:
Quoted 66 lines
[ 653.902305] ====================================================== [ 653.902928] WARNING: possible circular locking dependency detected [ 653.903517] 5.6.0-deli-v5.6-2848-g3f3109b0e75f #1 Tainted:
G OE
[ 653.904098] ------------------------------------------------------ [ 653.904675] amdgpu_test/3975 is trying to acquire lock:
[ 653.905241]ffff97848f8647a0(&adev->reset_sem){.+.+}, at:amdgpu_gem_va_ioctl+0x286/0x4f0 [amdgpu] [ 653.905953] but task is already holding lock:[ 653.907087]
ffff9744adbee1f8(reservation_ww_class_mutex){+.+.},
at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm] [ 653.907694]
which lock already depends on the new lock.[ 653.909423]
the existing dependency chain (in reverse order) is:
[ 653.910594]
-> #1 (reservation_ww_class_mutex){+.+.}:
[ 653.911759] __ww_mutex_lock.constprop.15+0xca/0x1120 [ 653.912350]ww_mutex_lock+0x73/0x80
[ 653.913044]amdgpu_amdkfd_alloc_gtt_mem+0xde/0x380[amdgpu] [ 653.913724]kgd2kfd_device_init+0x13f/0x5e0[amdgpu] [ 653.914388]amdgpu_amdkfd_device_init+0x155/0x190[amdgpu] [ 653.915033]amdgpu_device_init+0x1303/0x1e10[amdgpu] [ 653.915685]amdgpu_driver_load_kms+0x5c/0x2c0[amdgpu] [ 653.916349]amdgpu_pci_probe+0x11d/0x200[amdgpu] [ 653.916959]local_pci_probe+0x47/0xa0
[ 653.917570]work_for_cpu_fn+0x1a/0x30
[ 653.918184]process_one_work+0x29e/0x630
[ 653.918803]worker_thread+0x22b/0x3f0
[ 653.919427]kthread+0x12f/0x150
[ 653.920047]ret_from_fork+0x3a/0x50
[ 653.920661]
-> #0 (&adev->reset_sem){.+.+}:
[ 653.921893]__lock_acquire+0x13ec/0x16e0
[ 653.922531]lock_acquire+0xb8/0x1c0
[ 653.923174]down_read+0x48/0x230
[ 653.923886]amdgpu_gem_va_ioctl+0x286/0x4f0[amdgpu] [ 653.924588]drm_ioctl_kernel+0xb6/0x100[drm]
[ 653.925283]drm_ioctl+0x389/0x450[drm]
[ 653.926013]amdgpu_drm_ioctl+0x4f/0x80[amdgpu] [ 653.926686]ksys_ioctl+0x98/0xb0
[ 653.927357]__x64_sys_ioctl+0x1a/0x20
[ 653.928030]do_syscall_64+0x5f/0x250
[ 653.928697]entry_SYSCALL_64_after_hwframe+0x49/0xbe[ 653.929373]
other info that might help us debug this:[ 653.931356] Possible unsafe locking scenario:
[ 653.932647] CPU0 CPU1
[ 653.933287] ---- ----
[ 653.933911]lock(reservation_ww_class_mutex);
[ 653.934530]lock(&adev->reset_sem); [ 653.935154]lock(reservation_ww_class_mutex);
[ 653.935766]lock(&adev->reset_sem);
[ 653.936360]
*** DEADLOCK ***[ 653.938028] 2 locks held by amdgpu_test/3975:
[ 653.938574] #0:ffffb2a862d6bcd0(reservation_ww_class_acquire){+.+.}, at:amdgpu_gem_va_ioctl+0x39b/0x4f0[amdgpu] [ 653.939233] #1:ffff9744adbee1f8(reservation_ww_class_mutex){+.+.}, at:ttm_eu_reserve_buffers+0x1ae/0x520[ttm]Quoted 3 lines
change the order of
reservation_ww_class_mutexandadev->reset_seminamdgpu_gem_va_ioctlthe same as ones inamdgpu_amdkfd_alloc_gtt_mem, to avoid potential dead lock.It may be better to fix it the other way around in
amdgpu_amdkfd_alloc_gtt_mem. Always take thereset_seminside the reservation. Otherwise you will never be able to take thereset_semwhile any BOs are reserved. That's probably going to cause you other problems later.That makes me wonder, why do you need the
reset_seminamdgpu_amdkfd_alloc_gtt_memin the first place? There is no obvious hardware access in that function. Is it foramdgpu_ttm_alloc_gartupdating the GART table through HDP?Regards,
FelixQuoted 34 lines
Signed-off-by Dennis Li <[email protected]>drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-0@@ -652,6 +652,8 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev,void *data, abo = NULL; } + down_read(&adev->reset_sem); + amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd); r = ttm_eu_reserve_buffers(&ticket, &list, true,&duplicates); @@
-670,8 +672,6 @@ int amdgpu_gem_va_ioctl(structdrm_device*dev, void *data,
bo_va= NULL;
}
-down_read(&adev->reset_sem);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1
-3- switch (args->operation) { case AMDGPU_VA_OP_MAP: va_flags = amdgpu_gem_va_map_flags(adev, args->flags); @@ -701,12 +701,11 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data, amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, args->operation); - up_read(&adev->reset_sem); - error_backoff: ttm_eu_backoff_reservation(&ticket, &list); error_unref:
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
+
up_read(&adev->reset_sem);
drm_gem_object_put_unlocked(gobj);
return r;
}_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx