All of lore.kernel.org
 help / color / mirror / Atom feed
* drm_sched with panfrost crash on T820
@ 2019-09-27  8:12 ` Neil Armstrong
  0 siblings, 0 replies; 55+ messages in thread
From: Neil Armstrong @ 2019-09-27  8:12 UTC (permalink / raw)
  To: daniel, airlied, Christian König
  Cc: Erico Nunes, Andrey Grodzovsky, linux-kernel, steven.price,
	dri-devel, Rob Herring, Tomeu Vizoso,
	open list:ARM/Amlogic Meson...

Hi Christian,

In v5.3, running dEQP triggers the following kernel crash :

[   20.224982] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000038
[...]
[   20.291064] Hardware name: Khadas VIM2 (DT)
[   20.295217] Workqueue: events drm_sched_job_timedout
[...]
[   20.304867] pc : drm_sched_increase_karma+0x5c/0xf0
[   20.309696] lr : drm_sched_increase_karma+0x44/0xf0
[...]
[   20.396720] Call trace:
[   20.399138]  drm_sched_increase_karma+0x5c/0xf0
[   20.403623]  panfrost_job_timedout+0x12c/0x1e0
[   20.408021]  drm_sched_job_timedout+0x48/0xa0
[   20.412336]  process_one_work+0x1e0/0x320
[   20.416300]  worker_thread+0x40/0x450
[   20.419924]  kthread+0x124/0x128
[   20.423116]  ret_from_fork+0x10/0x18
[   20.426653] Code: f9400001 540001c0 f9400a83 f9402402 (f9401c64)
[   20.432690] ---[ end trace bd02f890139096a7 ]---

Which never happens, at all, on v5.2.

I did a (very) long (7 days, ~100runs) bisect run using our LAVA lab (thanks tomeu !), but
bisecting was not easy since the bad commit landed on drm-misc-next after v5.1-rc6, and
then v5.2-rc1 was backmerged into drm-misc-next at:
[1] 374ed5429346 Merge drm/drm-next into drm-misc-next

Thus bisecting between [1] ang v5.2-rc1 leads to commit based on v5.2-rc1... where panfrost was
not enabled in the Khadas VIM2 DT.

Anyway, I managed to identify 3 possibly breaking commits :
[2] 290764af7e36 drm/sched: Keep s_fence->parent pointer
[3] 5918045c4ed4 drm/scheduler: rework job destruction
[4] a5343b8a2ca5 drm/scheduler: Add flag to hint the release of guilty job.

But [1] and [2] doesn't crash the same way :
[   16.257912] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000060
[...]
[   16.308307] CPU: 4 PID: 80 Comm: kworker/4:1 Not tainted 5.1.0-rc2-01185-g290764af7e36-dirty #378
[   16.317099] Hardware name: Khadas VIM2 (DT)
[...])
[   16.330907] pc : refcount_sub_and_test_checked+0x4/0xb0
[   16.336078] lr : refcount_dec_and_test_checked+0x14/0x20
[...]
[   16.423533] Process kworker/4:1 (pid: 80, stack limit = 0x(____ptrval____))
[   16.430431] Call trace:
[   16.432851]  refcount_sub_and_test_checked+0x4/0xb0
[   16.437681]  drm_sched_job_cleanup+0x24/0x58
[   16.441908]  panfrost_job_free+0x14/0x28
[   16.445787]  drm_sched_job_timedout+0x6c/0xa0
[   16.450102]  process_one_work+0x1e0/0x320
[   16.454067]  worker_thread+0x40/0x450
[   16.457690]  kthread+0x124/0x128
[   16.460882]  ret_from_fork+0x10/0x18
[   16.464421] Code: 52800000 d65f03c0 d503201f aa0103e3 (b9400021)
[   16.470456] ---[ end trace 39a67412ee1b64b5 ]---

and [3] fails like on v5.3 (in drm_sched_increase_karma):
[   33.830080] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000038
[...]
[   33.871946] Internal error: Oops: 96000004 [#1] PREEMPT SMP
[   33.877450] Modules linked in:
[   33.880474] CPU: 6 PID: 81 Comm: kworker/6:1 Not tainted 5.1.0-rc2-01186-ga5343b8a2ca5-dirty #380
[   33.889265] Hardware name: Khadas VIM2 (DT)
[   33.893419] Workqueue: events drm_sched_job_timedout
[...]
[   33.903069] pc : drm_sched_increase_karma+0x5c/0xf0
[   33.907898] lr : drm_sched_increase_karma+0x44/0xf0
[...]
[   33.994924] Process kworker/6:1 (pid: 81, stack limit = 0x(____ptrval____))
[   34.001822] Call trace:
[   34.004242]  drm_sched_increase_karma+0x5c/0xf0
[   34.008726]  panfrost_job_timedout+0x12c/0x1e0
[   34.013122]  drm_sched_job_timedout+0x48/0xa0
[   34.017438]  process_one_work+0x1e0/0x320
[   34.021402]  worker_thread+0x40/0x450
[   34.025026]  kthread+0x124/0x128
[   34.028218]  ret_from_fork+0x10/0x18
[   34.031755] Code: f9400001 540001c0 f9400a83 f9402402 (f9401c64)
[   34.037792] ---[ end trace be3fd6f77f4df267 ]---


When I revert [3] on [1], i get the same crash as [2], meaning
the commit [3] masks the failure [2] introduced.

Do you know how to solve this ?

Thanks,
Neil

^ permalink raw reply	[flat|nested] 55+ messages in thread
* Re: drm_sched with panfrost crash on T820
@ 2019-10-04 16:33 Koenig, Christian
  2019-10-07 12:47   ` Steven Price
  0 siblings, 1 reply; 55+ messages in thread
From: Koenig, Christian @ 2019-10-04 16:33 UTC (permalink / raw)
  To: Steven Price
  Cc: Hillf Danton, Tomeu Vizoso, Neil Armstrong, airlied,
	linux-kernel, dri-devel, open list:ARM/Amlogic Meson...,
	Erico Nunes


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



Am 04.10.2019 18:02 schrieb Steven Price <steven.price@arm.com>:
On 04/10/2019 16:34, Koenig, Christian wrote:
> Am 04.10.19 um 17:27 schrieb Steven Price:
>> On 04/10/2019 16:03, Neil Armstrong wrote:
>>> On 04/10/2019 16:53, Grodzovsky, Andrey wrote:
>>>> On 10/3/19 4:34 AM, Neil Armstrong wrote:
>>>>> Hi Andrey,
>>>>>
>>>>> Le 02/10/2019 à 16:40, Grodzovsky, Andrey a écrit :
>>>>>> On 9/30/19 10:52 AM, Hillf Danton wrote:
>>>>>>> On Mon, 30 Sep 2019 11:17:45 +0200 Neil Armstrong wrote:
>>>>>>>> Did a new run from 5.3:
>>>>>>>>
>>>>>>>> [   35.971972] Call trace:
>>>>>>>> [   35.974391]  drm_sched_increase_karma+0x5c/0xf0
>>>>>>>>                         ffff000010667f38        FFFF000010667F94
>>>>>>>>                         drivers/gpu/drm/scheduler/sched_main.c:335
>>>>>>>>
>>>>>>>> The crashing line is :
>>>>>>>>                                    if (bad->s_fence->scheduled.context ==
>>>>>>>>                                        entity->fence_context) {
>>>>>>>>
>>>>>>>> Doesn't seem related to guilty job.
>>>>>>> Bail out if s_fence is no longer fresh.
>>>>>>>
>>>>>>> --- a/drivers/gpu/drm/scheduler/sched_main.c
>>>>>>> +++ b/drivers/gpu/drm/scheduler/sched_main.c
>>>>>>> @@ -333,6 +333,10 @@ void drm_sched_increase_karma(struct drm
>>>>>>>
>>>>>>>                          spin_lock(&rq->lock);
>>>>>>>                          list_for_each_entry_safe(entity, tmp, &rq->entities, list) {
>>>>>>> +                               if (!smp_load_acquire(&bad->s_fence)) {
>>>>>>> +                                       spin_unlock(&rq->lock);
>>>>>>> +                                       return;
>>>>>>> +                               }
>>>>>>>                                  if (bad->s_fence->scheduled.context ==
>>>>>>>                                      entity->fence_context) {
>>>>>>>                                          if (atomic_read(&bad->karma) >
>>>>>>> @@ -543,7 +547,7 @@ EXPORT_SYMBOL(drm_sched_job_init);
>>>>>>>     void drm_sched_job_cleanup(struct drm_sched_job *job)
>>>>>>>     {
>>>>>>>          dma_fence_put(&job->s_fence->finished);
>>>>>>> -       job->s_fence = NULL;
>>>>>>> +       smp_store_release(&job->s_fence, 0);
>>>>>>>     }
>>>>>>>     EXPORT_SYMBOL(drm_sched_job_cleanup);
>>>>> This fixed the problem on the 10 CI runs.
>>>>>
>>>>> Neil
>>>>
>>>> These are good news but I still fail to see how this fixes the problem -
>>>> Hillf, do you mind explaining how you came up with this particular fix -
>>>> what was the bug you saw ?
>>> As Steven explained, seems the same job was submitted on both HW slots,
>>> and then when timeout occurs each thread calls panfrost_job_timedout
>>> which leads to drm_sched_stop() on the first call and on the
>>> second call the job was already freed.
>>>
>>> Steven proposed a working fix, and this one does the same but on
>>> the drm_sched side. This one looks cleaner, but panfrost should
>>> not call drm_sched_stop() twice for the same job.
>> I'm not sure that Hillf's fix is sufficient. In particular in
>> drm_sched_increase_karma() I don't understand how the smp_load_acquire()
>> call prevents bad->s_fence becoming NULL immediately afterwards (but
>> admittedly the window is much smaller). But really this is just a
>> Panfrost bug (calling drm_sched_stop() twice on the same job).
>>
>> The part of my change that I'd welcome feedback on is changing
>> cancel_delayed_work() to cancel_delayed_work_sync() in drm_sched_stop()
>> when called on different scheduler to the bad job. It's not clear to me
>> exactly what the semantics of the function should be, and I haven't
>> tested the effect of the change on drivers other than Panfrost.
>
> Yeah, at least of hand that change doesn't seem to make sense to me.

We need to ensure that any other timeouts that might have started
processing are complete before actually resetting the hardware.
Otherwise after the reset another thread could come along and attempt to
reset the hardware again (and cause a double free of a job).

This is intentional behaviour. If you don't want the double reset in Panfrost you should probably call the cancel_sync yourself.

Regards,
Christian.


My change
to use the _sync() variant prevents this happening.

> Multiple timeout workers can perfectly run in parallel, Panfrost needs
> to make sure that they don't affect each other.
>
> The simplest way of doing this is to have a mutex you trylock when
> starting the reset.
>
> The first one grabbing it wins, all other just silently return.

Ah that would simplify my change removing the need for the new variable.
I hadn't thought to use trylock. I'll give that a spin and post a new
simpler version.

Thanks,

Steve

> Regards,
> Christian.
>
>>
>> Steve
>>
>>> Neil
>>>
>>>> Andrey
>>>>
>>>>>> Does this change help the problem ? Note that drm_sched_job_cleanup is
>>>>>> called from scheduler thread which is stopped at all times when work_tdr
>>>>>> thread is running and anyway the 'bad' job is still in the
>>>>>> ring_mirror_list while it's being accessed from
>>>>>> drm_sched_increase_karma so I don't think drm_sched_job_cleanup can be
>>>>>> called for it BEFORE or while drm_sched_increase_karma is executed.
>>>>>>
>>>>>> Andrey
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>>
>>> _______________________________________________
>>> dri-devel mailing list
>>> dri-devel@lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/dri-devel
>>>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
>



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

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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2019-10-07 12:47 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27  8:12 drm_sched with panfrost crash on T820 Neil Armstrong
2019-09-27  8:12 ` Neil Armstrong
2019-09-27  9:55 ` Steven Price
2019-09-27  9:55   ` Steven Price
2019-09-27 10:48   ` Steven Price
2019-09-27 10:48     ` Steven Price
2019-09-27 10:48     ` Steven Price
2019-09-27 11:27     ` Neil Armstrong
2019-09-27 11:27       ` Neil Armstrong
2019-09-27 11:48       ` Neil Armstrong
2019-09-27 11:48         ` Neil Armstrong
2019-09-27 15:00         ` Steven Price
2019-09-27 15:00           ` Steven Price
2019-09-27 15:00           ` Steven Price
2019-09-27 15:20           ` Neil Armstrong
2019-09-27 15:20             ` Neil Armstrong
2019-09-30 13:18           ` Neil Armstrong
2019-09-30 13:18             ` Neil Armstrong
2019-09-30 13:18             ` Neil Armstrong
2019-09-27 20:55 ` Grodzovsky, Andrey
2019-09-27 20:55   ` Grodzovsky, Andrey
2019-09-27 20:55   ` Grodzovsky, Andrey
2019-09-30  9:17   ` Neil Armstrong
2019-09-30  9:17     ` Neil Armstrong
2019-09-30  9:17     ` Neil Armstrong
2019-10-02 16:53     ` Grodzovsky, Andrey
2019-10-02 16:53       ` Grodzovsky, Andrey
2019-10-03  8:36       ` Neil Armstrong
2019-10-03  8:36         ` Neil Armstrong
2019-09-30 14:52   ` Hillf Danton
2019-09-30 14:52     ` Hillf Danton
2019-10-02 14:40     ` Grodzovsky, Andrey
2019-10-02 14:40       ` Grodzovsky, Andrey
2019-10-02 14:40       ` Grodzovsky, Andrey
2019-10-02 14:44       ` Neil Armstrong
2019-10-02 14:44         ` Neil Armstrong
2019-10-02 14:44         ` Neil Armstrong
2019-10-03  8:34       ` Neil Armstrong
2019-10-03  8:34         ` Neil Armstrong
2019-10-03  8:34         ` Neil Armstrong
2019-10-04 14:53         ` Grodzovsky, Andrey
2019-10-04 14:53           ` Grodzovsky, Andrey
2019-10-04 15:03           ` Neil Armstrong
2019-10-04 15:03             ` Neil Armstrong
2019-10-04 15:03             ` Neil Armstrong
2019-10-04 15:27             ` Steven Price
2019-10-04 15:27               ` Steven Price
2019-10-04 15:34               ` Koenig, Christian
2019-10-04 15:34                 ` Koenig, Christian
2019-10-04 15:34                 ` Koenig, Christian
2019-10-04 16:02                 ` Steven Price
2019-10-04 16:02                   ` Steven Price
2019-10-04 16:33 Koenig, Christian
2019-10-07 12:47 ` Steven Price
2019-10-07 12:47   ` Steven Price

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.