From: Greg KH <gregkh@linuxfoundation.org>
To: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Cc: evgreen@chromium.org, arnd@arndb.de, linux-efi@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel@gpiccoli.net,
ardb@kernel.org, davidgow@google.com, jwerner@chromium.org,
Petr Mladek <pmladek@suse.com>
Subject: Re: [PATCH V3] firmware: google: Test spinlock on panic path to avoid lockups
Date: Thu, 1 Sep 2022 20:59:21 +0200 [thread overview]
Message-ID: <YxEBCVRgWE8VTZaf@kroah.com> (raw)
In-Reply-To: <b050f00b-6c3a-a0d9-a3c1-175a724faf1c@igalia.com>
On Thu, Sep 01, 2022 at 03:46:17PM -0300, Guilherme G. Piccoli wrote:
> On 01/09/2022 15:28, Greg KH wrote:
> > [...]
> >> I honestly didn't understand exactly what you're suggesting Greg...
> >> Mind clarifying?
> >
> > Something like this totally untested code:
> >
> > diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c
> > index adaa492c3d2d..6ad41b22671c 100644
> > --- a/drivers/firmware/google/gsmi.c
> > +++ b/drivers/firmware/google/gsmi.c
> > @@ -19,6 +19,7 @@
> > #include <linux/dma-mapping.h>
> > #include <linux/fs.h>
> > #include <linux/slab.h>
> > +#include <linux/panic.h>
> > #include <linux/panic_notifier.h>
> > #include <linux/ioctl.h>
> > #include <linux/acpi.h>
> > @@ -611,6 +612,11 @@ static const struct attribute *gsmi_attrs[] = {
> > NULL,
> > };
> >
> > +static bool panic_in_progress(void)
> > +{
> > + return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
> > +}
> > +
> > static int gsmi_shutdown_reason(int reason)
> > {
> > struct gsmi_log_entry_type_1 entry = {
> > @@ -629,7 +635,8 @@ static int gsmi_shutdown_reason(int reason)
> > if (saved_reason & (1 << reason))
> > return 0;
> >
> > - spin_lock_irqsave(&gsmi_dev.lock, flags);
> > + if (!panic_in_progress())
> > + spin_lock_irqsave(&gsmi_dev.lock, flags);
> >
> > saved_reason |= (1 << reason);
> >
> > @@ -644,7 +651,8 @@ static int gsmi_shutdown_reason(int reason)
> >
> > rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_EVENT_LOG);
> >
> > - spin_unlock_irqrestore(&gsmi_dev.lock, flags);
> > + if (!panic_in_progress())
> > + spin_unlock_irqrestore(&gsmi_dev.lock, flags);
> >
> > if (rc < 0)
> > printk(KERN_ERR "gsmi: Log Shutdown Reason failed\n");
> >
> >
> >
>
> Thanks! Personally, I feel the approach a bit more complex than mine,
> and...racy!
> Imagine CPU0 runs your tests, right after the if (!panic_in_progress())
> is done, spinlock is taken and boom - panic on CPU1. This would cause
> the same issue...
True, it would, but so would yours if the unlock happens and then your
test passes and then this lock is taken and then a panic happens.
There's no "race free" way here perhaps. The joys of notifier chains (I
hate the things...)
> My approach is zero racy, since it checks if spinlock was taken in a
> moment that the machine is like a no-SMP, only a single CPU running...
Ah, I missed that this path is only called if an panic is happening.
Well, also a reboot.
Ick, I don't know, this all feels odd. I want someone else to review
this and give their ack on the patch before I'll take it so someone else
can share in the blame :)
thanks,
greg k-h
next prev parent reply other threads:[~2022-09-01 18:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 15:50 [PATCH V3] firmware: google: Test spinlock on panic path to avoid lockups Guilherme G. Piccoli
2022-09-01 15:52 ` Greg KH
2022-09-01 15:59 ` Guilherme G. Piccoli
2022-09-01 16:04 ` Greg KH
2022-09-01 16:24 ` Guilherme G. Piccoli
2022-09-01 16:44 ` Greg KH
2022-09-01 17:46 ` Guilherme G. Piccoli
2022-09-01 18:28 ` Greg KH
2022-09-01 18:46 ` Guilherme G. Piccoli
2022-09-01 18:59 ` Greg KH [this message]
2022-09-01 19:02 ` Guilherme G. Piccoli
2022-09-01 22:13 ` Andrew Morton
2022-09-06 17:09 ` Evan Green
2022-09-08 0:35 ` Guilherme G. Piccoli
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=YxEBCVRgWE8VTZaf@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=davidgow@google.com \
--cc=evgreen@chromium.org \
--cc=gpiccoli@igalia.com \
--cc=jwerner@chromium.org \
--cc=kernel@gpiccoli.net \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
/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