From: Brajesh Gupta <Brajesh.Gupta@imgtec.com>
To: Luigi Santivetti <Luigi.Santivetti@imgtec.com>,
"palmer@dabbelt.com" <palmer@dabbelt.com>,
"tzimmermann@suse.de" <tzimmermann@suse.de>,
"simona@ffwll.ch" <simona@ffwll.ch>,
"dlan@kernel.org" <dlan@kernel.org>,
"troy.mitchell@linux.spacemit.com"
<troy.mitchell@linux.spacemit.com>,
"liangbaihui@linux.spacemit.com" <liangbaihui@linux.spacemit.com>,
"airlied@gmail.com" <airlied@gmail.com>,
"aou@eecs.berkeley.edu" <aou@eecs.berkeley.edu>,
Alessio Belle <Alessio.Belle@imgtec.com>,
"maarten.lankhorst@linux.intel.com"
<maarten.lankhorst@linux.intel.com>,
"pjw@kernel.org" <pjw@kernel.org>,
"alex@ghiti.fr" <alex@ghiti.fr>,
"mripard@kernel.org" <mripard@kernel.org>
Cc: "dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-riscv@lists.infradead.org"
<linux-riscv@lists.infradead.org>,
"gye976@gmail.com" <gye976@gmail.com>,
"imagination@lists.freedesktop.org"
<imagination@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"spacemit@lists.linux.dev" <spacemit@lists.linux.dev>
Subject: Re: [EXTERNAL] Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend
Date: Tue, 1 Dec 2026 08:30:01 +0000 [thread overview]
Message-ID: <d4b0c3136af2d17ac77a718799f9b0cd1dbd6f30.camel@imgtec.com> (raw)
In-Reply-To: <DN91Y65ZK8JR.11KRIFRFF04PT@linux.spacemit.com>
On Tue, 2026-12-01 at 10:48 +0800, Baihui Liang wrote:
Hi Baihui,
> *** CAUTION: This email originates from a source not known to Imagination Technologies. Think before you click a link or open an attachment ***
>
> Hi Brajesh,
>
> Thanks for the review.
>
> On Mon Nov 30, 2026 at 4:20 PM CST, Brajesh Gupta wrote:
> [...]
> > > diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c
> > > index 5c965ef0274..bf70cd5c6df 100644
> > > --- a/drivers/gpu/drm/imagination/pvr_drv.c
> > > +++ b/drivers/gpu/drm/imagination/pvr_drv.c
> > > @@ -1469,19 +1469,24 @@ static void pvr_remove(struct platform_device *plat_dev)
> > > struct drm_device *drm_dev = platform_get_drvdata(plat_dev);
> > > struct pvr_device *pvr_dev = to_pvr_device(drm_dev);
> > >
> > > + pm_runtime_disable(drm_dev->dev);
> > > +
> > > WARN_ON(!xa_empty(&pvr_dev->job_ids));
> > > WARN_ON(!xa_empty(&pvr_dev->free_list_ids));
> > >
> > > + pvr_power_device_shutdown(pvr_dev);
> > > +
> > We could potentially drop the interface pvr_power_device_shutdown by rearranging
> > code as follows (please check my other comments first for this one):
> >
> > pm_runtime_disable(drm_dev->dev);
> >
> > if (!pm_runtime_status_suspended(dev)) {
> > int err = pvr_power_device_off(pvr_dev);
> > if (!err)
> > pm_runtime_set_suspended(dev);
> > else
> > drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
> > }
> > pm_runtime_enable(drm_dev->dev);
>
> Agreed, will inline it, and keep the drm_dev_enter()/drm_dev_exit() pair
> inside pvr_power_device_off() as suggested below.
>
> > Please add following comment from the description to the code as well.
> > "Power off before destroying the job and free-list ID arrays, since
> > the IRQ handler can still process firmware commands during shutdown
> > and look up free-list IDs."
>
> Will add.
>
> > > xa_destroy(&pvr_dev->job_ids);
> > > xa_destroy(&pvr_dev->free_list_ids);
> > >
> [...]
> > > +{
> > > + struct drm_device *drm_dev = from_pvr_device(pvr_dev);
> > > + struct device *dev = drm_dev->dev;
> > > + int idx;
> > > + int err;
> > > +
> > > + if (pm_runtime_status_suspended(dev))
> > > + return;
> > > +
> > > + if (!drm_dev_enter(drm_dev, &idx)) {
> > > + drm_err(drm_dev, "Device is unplugged, cannot power it off\n");
> > > + return;
> > > + }
> > > +
> > > + err = pvr_power_device_off(pvr_dev);
> > > + drm_dev_exit(idx);
> > > + if (!err)
> > > + err = pm_runtime_set_suspended(dev);
> > > +
> > > + if (err)
> > Change to 'else' part of the if condition.
> >
>
> This one goes away with the inlining above — the function is removed.
>
> > > + drm_err(drm_dev, "Failed to power the device off (%d)\n", err);
> > > +}
> > > +
> > > int
> > > pvr_power_device_suspend(struct device *dev)
> > > {
> > > @@ -378,15 +422,19 @@ pvr_power_device_suspend(struct device *dev)
> > > if (!drm_dev_enter(drm_dev, &idx))
> > > return -EIO;
> > >
> > > - if (READ_ONCE(pvr_dev->fw_dev.initialised)) {
> > > - err = pvr_power_fw_disable(pvr_dev, false, true);
> > > - if (err)
> > > - goto err_drm_dev_exit;
> > > - }
> > > + if (READ_ONCE(pvr_dev->fw_dev.initialised) && !pvr_power_is_idle(pvr_dev)) {
> > Check for READ_ONCE(pvr_dev->fw_dev.initialised) can be dropped from the
> > condition.
>
> I'd rather not drop it as-is: pvr_fw_fini() clears initialised and then frees
> fwif_sysdata (pvr_fw.c:566,593) without NULLing the pointer, so on the probe
> failure path (pvr_device_init() -> err_pm_runtime_put -> pm_runtime_put_sync_suspend())
> this would be a NULL deref or a use-after-free.
>
> How about moving the guard into pvr_power_is_idle() instead?
That's one option. Another one is to set pointer to NULL after calling interface
pvr_fw_object_destroy or pvr_fw_object_unmap_and_destroy.
Thanks,
Brajesh
>
> > > + /*
> > > + * The firmware has not drained the GPU yet. Refresh last_busy so
> > > + * the PM core reschedules the autosuspend and retries this callback
> > > + * until the firmware becomes idle.
> > > + */
> > > + pm_runtime_mark_last_busy(dev);
> > > + drm_dev_exit(idx);
> > >
> > > - err = pvr_dev->device_data->pwr_ops->power_off(pvr_dev);
> > > + return -EBUSY;
> > > + }
> > >
> > > -err_drm_dev_exit:
> > > + err = pvr_power_device_off(pvr_dev);
> > drm_dev_enter and drm_dev_exit can be moved under the interface
> > pvr_power_device_off to simplify pvr_power_device_suspend interface.
>
> Will do, together with the inlining above.
>
> Thanks,
> Baihui
prev parent reply other threads:[~2026-12-01 8:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 3:39 Baihui Liang
2026-11-29 6:27 ` Gyeyoung Baek
2026-11-29 13:40 ` Troy Mitchell
2026-12-01 1:46 ` Baihui Liang
2026-11-30 8:20 ` Brajesh Gupta
2026-12-01 2:48 ` Baihui Liang
2026-12-01 8:30 ` Brajesh Gupta [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=d4b0c3136af2d17ac77a718799f9b0cd1dbd6f30.camel@imgtec.com \
--to=brajesh.gupta@imgtec.com \
--cc=Alessio.Belle@imgtec.com \
--cc=Luigi.Santivetti@imgtec.com \
--cc=airlied@gmail.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=dlan@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gye976@gmail.com \
--cc=imagination@lists.freedesktop.org \
--cc=liangbaihui@linux.spacemit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=simona@ffwll.ch \
--cc=spacemit@lists.linux.dev \
--cc=troy.mitchell@linux.spacemit.com \
--cc=tzimmermann@suse.de \
/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®