From: Krzysztof Kozlowski <krzk@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Kevin Hilman <khilman@kernel.org>,
Ulf Hansson <ulf.hansson@linaro.org>,
Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Linux PM list <linux-pm@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Linux-Renesas <linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH v3 2/8] PM / Domains: Handle safely genpd_syscore_switch() call on non-genpd device
Date: Tue, 4 Jul 2017 22:20:14 +0200 [thread overview]
Message-ID: <20170704202014.fkpeahwyfddepens@kozik-lap> (raw)
In-Reply-To: <CAJZ5v0g6AoG5o+m4=p=k2Z=-tK-qGgFccJ2S2dx3D=6CfdnnzA@mail.gmail.com>
On Tue, Jul 04, 2017 at 10:12:13PM +0200, Rafael J. Wysocki wrote:
> On Tue, Jul 4, 2017 at 10:05 PM, Krzysztof Kozlowski <krzk@kernel.org> wrote:
>> >> > Thanks for report!
> >> >> >
> >> >> > Damn it, although I couldn't find this in the code, but I was fearing
> >> >> > that this ends up in atomic section. That would kind of explain why
> >> >> > mutex was not there [1].
> >> >> >
> >> >> > Anyway, the buggy code was there already. Instead of "sleeping in atomic
> >> >> > section" there was no locking at all... In this context this was
> >> >> > probably safe because it was executed *after* disabling non-boot CPUs
> >> >> > but then the function cannot be called in other contexts.
> >> >> >
> >> >> > I am not sure I will be capable of developing the proper fix as I do not
> >> >> > have the hardware and I do not know all stuff happening in sh suspend.
> >> >> > Probably reverting this and living with non-locked path would be the
> >> >> > safest choice.
> >> >> >
> >> >> > [1] https://patchwork.kernel.org/patch/9778903/
> >> >>
> >> >> AFAIU, all syscore stuff runs in atomic context.
> >> >
> >> > Indeed... The confusing part is that this code is syscore only from
> >> > the name, it is not hooked in to syscore_ops. Although going by call
> >> > chain (through sh clocksource drivers) we end up in
> >> > timekeeping_suspend() which is a syscore op.
> >> >
> >> > I wonder whether it would be useful - after reverting my commit - to add
> >> > an assert (which is a stronger API requirement than only documentation "may
> >> > only be called during the system core (syscore) suspend") like:
> >> > WARN_ON(num_online_cpus() > 1));
> >> > as without mutexes this should not be executed with more than one online
> >> > CPU.
> >>
> >> Or maybe WARN_ON_ONCE(!in_atomic())?
> >
> > You could be in atomic section on this CPU and still have other CPUs
> > online playing with gpd_list (without any protection from locking).
> > This function is safe only on non-SMP case.
>
> Well, not quite.
>
> It is safe if you can guarantee that no other CPUs will touch the data
> structure in question concurrently, which pretty much is the case for
> timekeeping_suspend() even though it may be invoked without taking the
> other CPUs offline (from the suspend-to-idle core path).
Right, that would work fine for that case.
However I was rather thinking that we have an in-kernel API (exported)
so someone might by mistake try to use it in different contexts. For
example in some atomic section but on a platform which offlines CPUs
later. Thus it would be called in some imaginary suspend path but with
CPUs still being online. Partially it is already mentioned in documentation
although I am not sure that on every possible architecture syscore ops
are called after disabling non-boot CPUs...
And anyway for in-kernel API having a explicit assert is a stronger way
of documenting requirement than a comment.
Best regards,
Krzysztof
next prev parent reply other threads:[~2017-07-04 20:20 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-28 14:56 [PATCH v3 0/8] PM / Domains: Bunch of small improvements and fixes Krzysztof Kozlowski
2017-06-28 14:56 ` [PATCH v3 1/8] PM / Domains: Constify genpd pointer Krzysztof Kozlowski
2017-06-28 14:56 ` [PATCH v3 2/8] PM / Domains: Handle safely genpd_syscore_switch() call on non-genpd device Krzysztof Kozlowski
2017-07-04 13:01 ` Geert Uytterhoeven
2017-07-04 18:10 ` Krzysztof Kozlowski
2017-07-04 18:19 ` Geert Uytterhoeven
2017-07-04 18:36 ` Krzysztof Kozlowski
2017-07-04 19:54 ` Rafael J. Wysocki
2017-07-04 20:05 ` Krzysztof Kozlowski
2017-07-04 20:12 ` Rafael J. Wysocki
2017-07-04 20:20 ` Krzysztof Kozlowski [this message]
2017-07-04 20:28 ` Rafael J. Wysocki
2017-06-28 14:56 ` [PATCH v3 3/8] PM / Domains: Fix unsafe iteration over modified list of device links Krzysztof Kozlowski
2017-06-28 14:56 ` [PATCH v3 4/8] PM / Domains: Fix unsafe iteration over modified list of domain providers Krzysztof Kozlowski
2017-06-28 14:56 ` [PATCH v3 5/8] PM / Domains: Fix unsafe iteration over modified list of domains Krzysztof Kozlowski
2017-06-28 14:56 ` [PATCH v3 6/8] PM / Domains: Fix missing default_power_down_ok comment Krzysztof Kozlowski
2017-06-28 14:56 ` [PATCH v3 7/8] PM / Domains: Add lockdep asserts for domains list mutex Krzysztof Kozlowski
2017-06-28 14:56 ` [RFC v3 8/8] PM / Domains: Add asserts for PM domain locks Krzysztof Kozlowski
2017-06-28 23:45 ` [PATCH v3 0/8] PM / Domains: Bunch of small improvements and fixes Rafael J. Wysocki
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=20170704202014.fkpeahwyfddepens@kozik-lap \
--to=krzk@kernel.org \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=khilman@kernel.org \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=ulf.hansson@linaro.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
all inboxes | Powered by JetHome®