drm/amdgpu: race issue when jobs on 2 ring timeout
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 7 lines · Horace Chen
Fix a racing issue when jobs on 2 rings timeout simultaneously.
If 2 rings timed out at the same time, the
amdgpu_device_gpu_recoverwill be reentered. Then theadev->gmc.xgmi.headwill be grabbed by 2 local linked list, which may cause wild pointer issue in iterating.
Quoted 6 lines
lock the device earily to prevent the node be added to 2 different lists.
for xgmi there is a hive lock which can promise there won't have 2 devices on same hive reenter the interation. So xgmi doesn't need to lock the device.
Note that amdgpu_device_lock_adev does bunch of other stuff besides taking the lock and I don't think we want to skip them for the other devices in case of XGMI.
Andrey
Quoted 28 lines
Signed-off-by Horace Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-0@@ -4591,19 +4591,20 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,list_rotate_to_front (&adev->gmc.xgmi.head, &hive->device_list); device_list_handle = &hive->device_list; }else { +/* if current dev is already in reset, skip adding list to prevent race issue */ +if (!amdgpu_device_lock_adev (adev, hive)) { +dev_info (adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , + job ? job->base.id :-1 ); + r =0 ; + goto skip_recovery; + } +list_add_tail (&adev->gmc.xgmi.head, &device_list); device_list_handle = &device_list; }/* block all schedulers and reset given job's ring */ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) {
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 4610
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-7-if (!amdgpu_device_lock_adev (tmp_adev, hive)) { -dev_info (tmp_adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , - job ? job->base.id :-1 ); - r =0 ; - goto skip_recovery; - } -/* * Try to put the audio codec into suspend state * before gpu reset started.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Andrey Grodzovsky
Reviewed-byRe: [PATCH 2/2] drm/amdgpu: set job guilty if reset skipped
Andrey
Quoted 27 lines · Horace Chen
If 2 jobs on 2 different ring timed out the at a very short period, the reset for second job will be skipped because the reset is already in progress.
But it doesn't mean the second job is not guilty since it also timed out and can be a bad job. So before skipped out from the reset, we need to increase karma for this job too.
Signed-off-by Horace Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -4572,6 +4572,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,if (atomic_cmpxchg (&hive->in_reset,0 ,1 ) !=0 ) {DRM_INFO ("Bailing on TDR for s_job:%llx, hive: %llx as another already in progress" , job ? job->base.id :-1 , hive->hive_id); +if (job) +drm_sched_increase_karma (&job->base);amdgpu_put_xgmi_hive (hive);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 4605
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0@@ -4596,6 +4598,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,dev_info (adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , job ? job->base.id :-1 ); r =0 ; +if (job) +drm_sched_increase_karma (&job->base); goto skip_recovery; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/2] drm/amdgpu: set job guilty if reset skipped
Quoted 19 lines · Andrey Grodzovsky
Reviewed-by Andrey Grodzovsky <[email protected]>Andrey
Quoted 13 lines · Horace Chen
If 2 jobs on 2 different ring timed out the at a very short period, the reset for second job will be skipped because the reset is already in progress.
But it doesn't mean the second job is not guilty since it also timed out and can be a bad job. So before skipped out from the reset, we need to increase karma for this job too.
Signed-off-by Horace Chen <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 4575
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -4572,6 +4572,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,if (atomic_cmpxchg (&hive->in_reset,0 ,1 ) !=0 ) {DRM_INFO ("Bailing on TDR for s_job:%llx, hive: %llx as another already in progress" , job ? job->base.id :-1 , hive->hive_id); +if (job)
space between the if and (. E.g.,
if (job)
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 4601
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0+drm_sched_increase_karma (&job->base);amdgpu_put_xgmi_hive (hive);return 0 ; }@@ -4596,6 +4598,8 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,dev_info (adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , job ? job->base.id :-1 ); r =0 ; +if (job)
Same here.
Alex
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 4605
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0+drm_sched_increase_karma (&job->base); goto skip_recovery; }_______________________________________________
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
Quan, Evan
Reviewed-by[AMD Official Use Only - Internal Distribution Only]
-----Original Message-----
From: Horace Chen <[email protected]>
Sent: Thursday, January 14, 2021 9:37 PM
To: [email protected]
Cc: Grodzovsky, Andrey <[email protected]>; Quan, Evan <[email protected]>; Chen, Horace <[email protected]>; Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Xiao, Jack <[email protected]>; Zhang, Hawking <[email protected]>; Liu, Monk <[email protected]>; Xu, Feifei <[email protected]>; Wang, Kevin(Yang) <[email protected]>; Xiaojie Yuan <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: race issue when jobs on 2 ring timeout
Fix a racing issue when jobs on 2 rings timeout simultaneously.
If 2 rings timed out at the same time, the amdgpu_device_gpu_recover will be reentered. Then the adev->gmc.xgmi.head will be grabbed by 2 local linked list,
which may cause wild pointer issue in iterating.
lock the device earily to prevent the node be added to 2 different lists.
for xgmi there is a hive lock which can promise there won't have
2 devices on same hive reenter the interation. So xgmi doesn't need to lock the device.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -7
@@ -4591,19 +4591,20 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,list_rotate_to_front (&adev->gmc.xgmi.head, &hive->device_list); device_list_handle = &hive->device_list; }else { +/* if current dev is already in reset, skip adding list to prevent race issue */ +if (!amdgpu_device_lock_adev (adev, hive)) { +dev_info (adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , +job ? job->base.id :-1 ); +r =0 ; +goto skip_recovery; +} +list_add_tail (&adev->gmc.xgmi.head, &device_list); device_list_handle = &device_list; }/* block all schedulers and reset given job's ring */ list_for_each_entry(tmp_adev, device_list_handle, gmc.xgmi.head) { -if (!amdgpu_device_lock_adev (tmp_adev, hive)) { -dev_info (tmp_adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , - job ? job->base.id :-1 ); -r =0 ; -goto skip_recovery; -} -/* * Try to put the audio codec into suspend state * before gpu reset started.
--
2.17.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx