All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
To: Linus Walleij <linusw@kernel.org>
Cc: Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
	 Li Youhong <dayou5941@163.com>,
	Daniel Scally <dan.scally@ideasonboard.com>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	 Nayden Kanchev <nayden.kanchev@arm.com>,
	linux-media@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] media: mali-c55: Keep IRQ requested during suspend
Date: Mon, 23 Nov 2026 12:12:39 +0100	[thread overview]
Message-ID: <awQYXLhEd2royiLw@zed> (raw)
In-Reply-To: <CAD++jLnTCEPKG5hNtfQ8rbijxF8nsk3H_K+R4H+f1HJak3Dhvw@mail.gmail.com>

Hi Linus

On Mon, Nov 23, 2026 at 11:38:26AM +0100, Linus Walleij wrote:
> Hi Jacopo,
>
> On Mon, Nov 23, 2026 at 9:28 AM Jacopo Mondi
> <jacopo.mondi@ideasonboard.com> wrote:
>
> > So yeah, maybe Sashiko would tell you this is possible but I hardly
> > believe it is.
> > Anyway, there is a remote possibility for a window here, so let's
> > increase the pm runtime counter.
>
> I'm honestly not sure. The framework should ideally stop this
> from ever happening but I'm not good enough with the media
> framework to have even a vaguest idea of how to fix this.

The only way for this to happen is that all devices in the capture
pipeline probe before the ISP and when we register a notifier in
mali_c55_media_frameworks_init() the v4l2-async framework notices all
dependencies are there and calls mali_c55_notifier_complete() which
registers all device nodes. At this point we should have userspace
operating the pipeline before we get to installing the irq handlers
(which happens just after calling mali_c55_media_frameworks_init()).

Yes, there is a window there, but its so tiny I wonder if it we can
really ever hit it. But as we know the most unlikely things can
happen, let's take it into account even if unlikely ? What do you
think ?
>
> What happened is that I asked an LLM to review the code
> using the Sashiko scripts and it complains about this risk.
>

Exactly, this is one of the very far fetched issues bots tend to
report and for which we're receiving an increasing number of
not-really-required fixes for.

This is not your case of course, I'm just complaining about the
current state of affairs and the overload it imposes on reviewers and
maintainers :)

> > > PM reference. The probe reference keeps the ISP active until the IRQ is
> > > installed, so runtime suspend cannot call disable_irq() on an IRQ we
> > > haven’t requested yet. I’ll add a comment.
> >
> > A suspend will always follow a resume, and if a resume tries to enable
> > an irq before it is installed we'll have problems as well.
> >
> > If that's a real concern to you, shouldn't we install the irq handler
> > before enabling pm runtime and powering the device up ?
>
> Often that is not a good idea, because the IRQ line can
> be in an undefined state and give rise to interrupt storms
> if you do that. As soon as the irq handler is installed it gets
> unmasked by enable_irq().

Right, and those are probably the spurious IRQs I had seen when I first
tried to install irq handlers in probe(). I still question the idea of
having the irq vector being fully unmasked in POR state, but it's
probably a bit late to complain to hardware designers.

>
> Also right now the device is powered up
> by directly calling __mali_c55_power_on() in probe() maybe
> we should just let the PM runtime resume power it up
> for clarity?

The thing is that the driver doesn't depend on PM.

Honestly, I would just depend on PM everywhere these days.

>
> It's quite common to power up a device (enable clocks
> and de-assert resets) before enabling
> runtime PM though, that's what I usually do.

Isn't it happening here as well ? I see a call to
__mali_c55_power_on() before pm_runtime_enable().

>
> Remove problems:
>
> > > > > +     pm_runtime_disable(&pdev->dev);
> > > > > +     free_irq(mali_c55->irqnum, &pdev->dev);
>
> Note: here we disable runtime PM and free the IRQ and this will
> make sure no further IRQs appear from this point.
>
> But clocks can still be running and resets can still be
> de-asserted because there is no guarantee that runtime
> suspend has executed just because we disable pm_runtime.
>
> > > > >       mali_c55_media_frameworks_deinit(mali_c55);
> > > > > -     if (!pm_runtime_suspended(&pdev->dev)) {
> > > > > +     if (!pm_runtime_status_suspended(&pdev->dev)) {
> > > >
> > > > I guess this is required because you moved pm_runtime_disable() up
> > >
> > > The remove ordering is part of the IRQ lifetime change. Both runtime
> > > PM callbacks now assume the IRQ is installed, so we need to drain
> > > them befor free_irq(). Then free_irq() waits for the threaded handler
> > > before we unregister the media entities it uses.
> >
> > I'm sorry, this is certainly me missing some pm_runtime internals,
> > but where is this happening ?
>
> It's not a pm runtime thing more of a free_irq() thing,
> it will wait for outstanding threaded handlers to complete.

I see

>
> When we get here we know no further IRQs can happen, but we
> have no guarantee that runtime suspend has been called,
> so we check just like the old code did to make sure it
> gets de-clocked and resets are asserted.
>
> Compare with the old code:
>
> static void mali_c55_remove(struct platform_device *pdev)
> {
>         struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
>
>         mali_c55_media_frameworks_deinit(mali_c55);
>         if (!pm_runtime_suspended(&pdev->dev)) {
>                 __mali_c55_power_off(mali_c55);
>                 pm_runtime_set_suspended(&pdev->dev);
>         }
>         pm_runtime_disable(&pdev->dev);
>         kfree(mali_c55->context.registers);
> }
>
> Since IRQs are unregistered in the runtime suspend callback,
> this is not a problem here.
>
> > > That’s also why I switched to pm_runtime_status_suspended().
> > > It reports the actual status after pm_runtime_disable(), so we only
> > > power off the ISP if it’s still active.
> >
> > It seems to me pm_runtime_status_suspended() ignores the runtime
> > counter and is only there because you pm_runtime_disable() earlier ?
>
> Kind of, I guess it's a bad idea to free_irq() before disabling
> runtime PM?
>
> An alternative is to call pm_runtime_force_suspend() before
> free_irq() so you know for sure the device is powered off,
> I can try this if you like it better.

Reading the pm_runtime_force_suspend() documentation

 * Typically this function may be invoked from a system suspend callback to make
 * sure the device is put into low power state and it should only be used during
 * system-wide PM transitions to sleep states.  It assumes that the analogous
 * pm_runtime_force_resume() will be used to resume the device.

Do you think it is appropriate at remove() ?


>
> Hm actually that would probably be better... shall I try that?

Is pm_runtime_force_suspend() different than open coding

        pm_runtime_disable(&pdev->dev);
        if (pm_runtime_status_suspended(&pdev->dev) {
                __mali_c55_power_off(mali_c55);
                pm_runtime_set_suspended(&pdev->dev);
        }
        free_irq(mali_c55->irqnum, &pdev->dev);


Is it different because of the dev_pm_enable_wake_irq_check() (which I
don't the purpose of) ?

Anyway the implementation of pm_runtime_force_suspend() calls
pm_runtime_disable() first as your patch does, and we're really
looking at details here. Also, I'm a bit out of my experties area
here, so whatever seems appropriate to you should be fine with me as
well.

Thanks
  j

>
> Yours,
> Linus Walleij

      reply	other threads:[~2026-11-23 11:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 14:08 [PATCH v2] media: mali-c55: Keep IRQ requested during suspend Linus Walleij
2026-11-05  8:07 ` Linus Walleij
2026-11-10 12:51 ` Jacopo Mondi
2026-11-23  0:29   ` Linus Walleij
2026-11-23  8:28     ` Jacopo Mondi
2026-11-23 10:38       ` Linus Walleij
2026-11-23 11:12         ` Jacopo Mondi [this message]

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=awQYXLhEd2royiLw@zed \
    --to=jacopo.mondi@ideasonboard.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=dayou5941@163.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nayden.kanchev@arm.com \
    --cc=stable@vger.kernel.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 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.