AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Grodzovsky <Andrey.Grodzovsky@amd.com>
To: "Chen, Horace" <Horace.Chen@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>
Cc: "Xiao, Jack" <Jack.Xiao@amd.com>,
	"Xu, Feifei" <Feifei.Xu@amd.com>,
	"Wang, Kevin\(Yang\)" <Kevin1.Wang@amd.com>,
	"Tuikov, Luben" <Luben.Tuikov@amd.com>,
	"Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Quan, Evan" <Evan.Quan@amd.com>,
	"Koenig, Christian" <Christian.Koenig@amd.com>,
	"Liu, Monk" <Monk.Liu@amd.com>,
	"Zhang, Hawking" <Hawking.Zhang@amd.com>
Subject: Re: 回复: 回复: [PATCH 1/2] drm/amdgpu: race issue when jobs on 2 ring timeout
Date: Tue, 19 Jan 2021 12:15:28 -0500	[thread overview]
Message-ID: <ad87c326-9df3-db9e-0c83-3a417f09f5d4@amd.com> (raw)
In-Reply-To: <CY4PR12MB1573CFBA40A3D36BF69C32FFE1A30@CY4PR12MB1573.namprd12.prod.outlook.com>


[-- Attachment #1.1: Type: text/plain, Size: 9893 bytes --]

Well, it shouldn't happen with the hive locked as I am browsing the code but 
then your code should
reflect that and if you do fail to lock particular adev AFTER the hive is locked 
you should not silently break
iteration but throw an error, WARN_ON or BUG_ON then. Or alternatively bail out 
with unlocking all already
locked devices.


Andrey


On 1/19/21 12:09 PM, Chen, Horace wrote:
>
> [AMD Official Use Only - Internal Distribution Only]
>
>
> OK, I understand. You mean one device in the hive may be locked up 
> independently without locking up the whole hive.
>
> It could happen, I'll change my code.
>
> Thanks & Regards,
> Horace.
>
> --------------------------------------------------------------------------------
> *发件人:* Grodzovsky, Andrey <Andrey.Grodzovsky@amd.com>
> *发送时间:* 2021年1月20日 0:58
> *收件人:* Chen, Horace <Horace.Chen@amd.com>; amd-gfx@lists.freedesktop.org 
> <amd-gfx@lists.freedesktop.org>
> *抄送:* Quan, Evan <Evan.Quan@amd.com>; Tuikov, Luben <Luben.Tuikov@amd.com>; 
> Koenig, Christian <Christian.Koenig@amd.com>; Deucher, Alexander 
> <Alexander.Deucher@amd.com>; Xiao, Jack <Jack.Xiao@amd.com>; Zhang, Hawking 
> <Hawking.Zhang@amd.com>; Liu, Monk <Monk.Liu@amd.com>; Xu, Feifei 
> <Feifei.Xu@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; Xiaojie Yuan 
> <xiaojie.yuan@amd.com>
> *主题:* Re: 回复: [PATCH 1/2] drm/amdgpu: race issue when jobs on 2 ring timeout
>
>
> On 1/19/21 11:39 AM, Chen, Horace wrote:
>>
>> [AMD Official Use Only - Internal Distribution Only]
>>
>>
>> Hi Andrey,
>>
>> I think the list in the XGMI hive won't be break in the middle if we lock the 
>> device before we change the list. Because if 2 devices in 1 hive went into 
>> the function, it will follow the same sequence to lock the devices. So one of 
>> them will definately break at the first device. I add iterate devices here is 
>> just to lock all device in the hive since we will change the device sequence 
>> in the hive soon after.
>
>
> I didn't mean break in a sense of breaking the list itself, I just meant the 
> literal 'break' instruction
> to terminate the iteration once you failed to lock a particular device.
>
>
>>
>> The reason to break the interation in the middle is that the list is changed 
>> during the iteration without taking any lock. It is quite bad since I'm 
>> fixing one of this issue. And for XGMI hive, there are 2 locks protecting the 
>> list, one is the device lock I changed here, the other one is in front of my 
>> change, there is a hive->lock to protect the hive.
>>
>> Even the bad thing really happened, I think moving back through the list is 
>> also very dengerous since we don't know what the list finally be, Unless we 
>> stack the devices we have iterated through a mirrored list. That can be a big 
>> change.
>
>
> Not sure we are on the same page, my concern is let's sat your XGMI hive 
> consists of 2 devices, you manged to call successfully do
> amdgpu_device_lock_adev for dev1 but then failed for dev2, in this case you 
> will bail out without releasing dev1, no ?
>
>
> Andrey
>
>
>>
>>
>> I'm ok to seperate the locking in amdgpu_device_lock_adev here, I'll do some 
>> test and update the code later.
>>
>> Thanks & Regards,
>> Horace.
>> --------------------------------------------------------------------------------
>> *发件人:* Grodzovsky, Andrey <Andrey.Grodzovsky@amd.com> 
>> <mailto:Andrey.Grodzovsky@amd.com>
>> *发送时间:* 2021年1月19日 22:33
>> *收件人:* Chen, Horace <Horace.Chen@amd.com> <mailto:Horace.Chen@amd.com>; 
>> amd-gfx@lists.freedesktop.org <mailto:amd-gfx@lists.freedesktop.org> 
>> <amd-gfx@lists.freedesktop.org> <mailto:amd-gfx@lists.freedesktop.org>
>> *抄送:* Quan, Evan <Evan.Quan@amd.com> <mailto:Evan.Quan@amd.com>; Tuikov, 
>> Luben <Luben.Tuikov@amd.com> <mailto:Luben.Tuikov@amd.com>; Koenig, Christian 
>> <Christian.Koenig@amd.com> <mailto:Christian.Koenig@amd.com>; Deucher, 
>> Alexander <Alexander.Deucher@amd.com> <mailto:Alexander.Deucher@amd.com>; 
>> Xiao, Jack <Jack.Xiao@amd.com> <mailto:Jack.Xiao@amd.com>; Zhang, Hawking 
>> <Hawking.Zhang@amd.com> <mailto:Hawking.Zhang@amd.com>; Liu, Monk 
>> <Monk.Liu@amd.com> <mailto:Monk.Liu@amd.com>; Xu, Feifei <Feifei.Xu@amd.com> 
>> <mailto:Feifei.Xu@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com> 
>> <mailto:Kevin1.Wang@amd.com>; Xiaojie Yuan <xiaojie.yuan@amd.com> 
>> <mailto:xiaojie.yuan@amd.com>
>> *主题:* Re: [PATCH 1/2] drm/amdgpu: race issue when jobs on 2 ring timeout
>>
>> On 1/19/21 7:22 AM, Horace Chen wrote:
>> > 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.
>> >
>> > Signed-off-by: Horace Chen <horace.chen@amd.com> <mailto:horace.chen@amd.com>
>> > ---
>> > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 42 +++++++++++++++-------
>> >   1 file changed, 30 insertions(+), 12 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> > index 4d434803fb49..9574da3abc32 100644
>> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
>> > @@ -4540,6 +4540,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
>> >        int i, r = 0;
>> >        bool need_emergency_restart = false;
>> >        bool audio_suspended = false;
>> > +     bool get_dev_lock = false;
>> >
>> >        /*
>> >         * Special case: RAS triggered and full reset isn't supported
>> > @@ -4582,28 +4583,45 @@ int amdgpu_device_gpu_recover(struct amdgpu_device 
>> *adev,
>> >         * Build list of devices to reset.
>> >         * In case we are in XGMI hive mode, resort the device list
>> >         * to put adev in the 1st position.
>> > +      *
>> > +      * lock the device before we try to operate the linked list
>> > +      * if didn't get the device lock, don't touch the linked list since
>> > +      * others may iterating it.
>> >         */
>> >        INIT_LIST_HEAD(&device_list);
>> >        if (adev->gmc.xgmi.num_physical_nodes > 1) {
>> >                if (!hive)
>> >                        return -ENODEV;
>> > -             if (!list_is_first(&adev->gmc.xgmi.head, &hive->device_list))
>> > - list_rotate_to_front(&adev->gmc.xgmi.head, &hive->device_list);
>> > -             device_list_handle = &hive->device_list;
>> > +
>> > + list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
>> > +                     get_dev_lock = amdgpu_device_lock_adev(tmp_adev, hive);
>> > +                     if (!get_dev_lock)
>> > +                             break;
>>
>>
>> What about unlocking back all the devices you already locked if the break
>> happens in the middle of the iteration ?
>> Note that at skip_recovery: we don't do it. BTW, i see this issue is already in
>> the current code.
>>
>> Also, maybe now it's better to separate the actual locking in
>> amdgpu_device_lock_adev
>> from the other stuff going on there since I don't think you would wont to toggle
>> stuff
>> like adev->mp1_state back and forth and also the function name is not
>> descriptive of
>> the other stuff going on there anyway.
>>
>> Andrey
>>
>>
>> > +             }
>> > +             if (get_dev_lock) {
>> > +                     if (!list_is_first(&adev->gmc.xgmi.head, 
>> &hive->device_list))
>> > + list_rotate_to_front(&adev->gmc.xgmi.head, &hive->device_list);
>> > +                     device_list_handle = &hive->device_list;
>> > +             }
>> >        } else {
>> > - list_add_tail(&adev->gmc.xgmi.head, &device_list);
>> > -             device_list_handle = &device_list;
>> > +             get_dev_lock = amdgpu_device_lock_adev(adev, hive);
>> > +             tmp_adev = adev;
>> > +             if (get_dev_lock) {
>> > + list_add_tail(&adev->gmc.xgmi.head, &device_list);
>> > +                     device_list_handle = &device_list;
>> > +             }
>> > +     }
>> > +
>> > +     if (!get_dev_lock) {
>> > +             dev_info(tmp_adev->dev, "Bailing on TDR for s_job:%llx, as 
>> another already in progress",
>> > +                                     job ? job->base.id : -1);
>> > +             r = 0;
>> > +             /* even we skipped this reset, still need to set the job to 
>> guilty */
>> > +             goto skip_recovery;
>> >        }
>> >
>> >        /* 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.

[-- Attachment #1.2: Type: text/html, Size: 27641 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  reply	other threads:[~2021-01-19 19:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210119122236.8039-1-horace.chen@amd.com>
2021-01-19 14:33 ` [PATCH 1/2] drm/amdgpu: race issue when jobs on 2 ring timeout Andrey Grodzovsky
2021-01-19 16:39   ` 回复: " Chen, Horace
2021-01-19 16:58     ` Andrey Grodzovsky
2021-01-19 17:09       ` 回复: " Chen, Horace
2021-01-19 17:15         ` Andrey Grodzovsky [this message]
2021-01-19 17:22           ` Lazar, Lijo
     [not found] ` <20210119122236.8039-2-horace.chen@amd.com>
2021-01-19 14:55   ` [PATCH 2/2] drm/amdgpu: set job guilty if reset skipped Andrey Grodzovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad87c326-9df3-db9e-0c83-3a417f09f5d4@amd.com \
    --to=andrey.grodzovsky@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Christian.Koenig@amd.com \
    --cc=Evan.Quan@amd.com \
    --cc=Feifei.Xu@amd.com \
    --cc=Hawking.Zhang@amd.com \
    --cc=Horace.Chen@amd.com \
    --cc=Jack.Xiao@amd.com \
    --cc=Kevin1.Wang@amd.com \
    --cc=Luben.Tuikov@amd.com \
    --cc=Monk.Liu@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox