From: Nicholas Piggin <npiggin@gmail.com>
To: benh@kernel.crashing.org, Laurent Dufour <ldufour@linux.ibm.com>,
mpe@ellerman.id.au, paulus@samba.org
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 1/2] powerpc/watchdog: prevent printk and send IPI while holding the wd lock
Date: Wed, 27 Oct 2021 18:51:16 +1000 [thread overview]
Message-ID: <1635324001.1tf9yz448t.astroid@bobo.none> (raw)
In-Reply-To: <33e15005-d342-5270-9b9d-64750f8794a7@linux.ibm.com>
Excerpts from Laurent Dufour's message of October 27, 2021 6:14 pm:
> Le 27/10/2021 à 05:29, Nicholas Piggin a écrit :
>> Excerpts from Laurent Dufour's message of October 27, 2021 2:27 am:
>>> When handling the Watchdog interrupt, long processing should not be done
>>> while holding the __wd_smp_lock. This prevents the other CPUs to grab it
>>> and to process Watchdog timer interrupts. Furhtermore, this could lead to
>>> the following situation:
>>>
>>> CPU x detect lockup on CPU y and grab the __wd_smp_lock
>>> in watchdog_smp_panic()
>>> CPU y caught the watchdog interrupt and try to grab the __wd_smp_lock
>>> in soft_nmi_interrupt()
>>> CPU x wait for CPU y to catch the IPI for 1s in __smp_send_nmi_ipi()
>>
>> CPU y should get the IPI here if it's a NMI IPI (which will be true for
>>> = POWER9 64s).
>>
>> That said, not all platforms support it and the console lock problem
>> seems real, so okay.
>>
>>> CPU x will timeout and so has spent 1s waiting while holding the
>>> __wd_smp_lock.
>>>
>>> A deadlock may also happen between the __wd_smp_lock and the console_owner
>>> 'lock' this way:
>>> CPU x grab the console_owner
>>> CPU y grab the __wd_smp_lock
>>> CPU x catch the watchdog timer interrupt and needs to grab __wd_smp_lock
>>> CPU y wants to print something and wait for console_owner
>>> -> deadlock
>>>
>>> Doing all the long processing without holding the _wd_smp_lock prevents
>>> these situations.
>>
>> The intention was to avoid logs getting garbled e.g., if multiple
>> different CPUs fire at once.
>>
>> I wonder if instead we could deal with that by protecting the IPI
>> sending and printing stuff with a trylock, and if you don't get the
>> trylock then just return, and you'll come back with the next timer
>> interrupt.
>
> That sounds a bit risky to me, especially on large system when system goes
> wrong, all the CPU may try lock here.
That should be okay though, one will get through and the others will
skip.
> Furthermore, now operation done under the lock protection are quite fast, there
> is no more spinning like the delay loop done when sending an IPI.
>
> Protecting the IPI sending is a nightmare, if the target CPU is later play with
> the lock we are taking during the IPI processing, furthermore, if the target CPU
> is not responding the sending CPU is waiting for 1s, which slows all the system
> due to the lock held.
> Since I do a copy of the pending CPU mask and clear it under the lock
> protection, the IPI sending is safe while done without holding the lock.
Protecting IPI sending basically has all the same issues in the NMI
IPI layer.
>
> Regarding the interleaved traces, I don't think this has to be managed down
> here, but rather in the printk/console path.
It can't necessarily be because some of the problem is actually that a
NMI handler can be interrupted by another NMI IPI because the caller
can return only after handlers start running rather than complete.
I don't think it would be an additional nightmare to trylock.
Thanks,
Nick
next prev parent reply other threads:[~2021-10-27 8:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 16:27 [PATCH 0/2] powerpc prevents deadlock in the watchdog path Laurent Dufour
2021-10-26 16:27 ` [PATCH 1/2] powerpc/watchdog: prevent printk and send IPI while holding the wd lock Laurent Dufour
2021-10-27 3:29 ` Nicholas Piggin
2021-10-27 8:14 ` Laurent Dufour
2021-10-27 8:51 ` Nicholas Piggin [this message]
2021-10-27 9:49 ` Nicholas Piggin
2021-10-28 15:45 ` Laurent Dufour
2021-10-26 16:27 ` [PATCH 2/2] powerpc/watchdog: ensure watchdog data accesses are protected Laurent Dufour
2021-10-27 3:48 ` Nicholas Piggin
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=1635324001.1tf9yz448t.astroid@bobo.none \
--to=npiggin@gmail.com \
--cc=benh@kernel.crashing.org \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.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