From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 418A1606A322 for ; Thu, 3 Dec 2026 10:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=H/UhM9+y Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FEA4112799; Thu, 3 Dec 2026 10:45:27 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 111AE112799 for ; Thu, 3 Dec 2026 10:45:22 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id BDF2541114; Thu, 3 Dec 2026 10:45:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F4CE1F000C1; Thu, 3 Dec 2026 10:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796294721; bh=JahyzSUOI64xdTdZVvozp/fzJIGCiJrOno2552Kc35I=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=H/UhM9+ydFc07G/fgE/ykTRhNpQdGu1F2BHd0O0k8cdpWsL6mr2hu5ElGLbGBDPte t/k7hWE8ZxNEBQSq1fen1/qjrvcHU+sfqrIiLK2BHWjZOLiQU++r7ib9+jzMjR55gt eGt2T6ZjqyY7vOoGd43jAHpUGcsnYkvQblpG0bOAco4buJaia9PngGKv0pn89Uih7s jKM6+qBMJrnTc3PpVwfgT+h+BKjY9tZiDC59EquzQCnmIarn4tqccbULvPURyoUACA N4zhfo0xgctHTnCD2y3YJ76wiOzMXagDhtsvVwM9e/Dg5af8C90Uf3mdyGLW/PsC+x 5grNY1w82TEug== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4] drm/imagination: re-check firmware idle state before runtime suspend To: "Baihui Liang" Cc: dri-devel@lists.freedesktop.org In-Reply-To: <20261203-img-pm-autosuspend-v4-1-dfc0874198e5@linux.spacemit.com> References: <20261203-img-pm-autosuspend-v4-1-dfc0874198e5@linux.spacemit.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 10:45:21 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, T_PDS_OTHER_BAD_TLD autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/imagination: unsynchronized power-off race and deadlock in pvr_remove() - [Medium] drm/imagination: infinite autosuspend retry loop on lost GPU -- commit 07c0fd1fa75337c7be88e0e0451b0831ac6bfbeb Author: Baihui Liang drm/imagination: re-check firmware idle state before runtime suspend This commit moves the firmware idle check from the runtime_idle callback into pvr_power_device_suspend(), returning -EBUSY after refreshing last_busy so the PM core retries autosuspend. It also extracts pvr_power_device_off() and calls it directly from pvr_remove() with runtime PM disabled. > diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imag= ination/pvr_drv.c > index 5c965ef0274ff..36ba30f859be1 100644 > --- a/drivers/gpu/drm/imagination/pvr_drv.c > +++ b/drivers/gpu/drm/imagination/pvr_drv.c [ ... ] > @@ -1469,19 +1470,38 @@ static void pvr_remove(struct platform_device *pl= at_dev) > struct drm_device *drm_dev =3D platform_get_drvdata(plat_dev); > struct pvr_device *pvr_dev =3D to_pvr_device(drm_dev); > =20 > + pm_runtime_disable(drm_dev->dev); > + > WARN_ON(!xa_empty(&pvr_dev->job_ids)); > WARN_ON(!xa_empty(&pvr_dev->free_list_ids)); > =20 > - xa_destroy(&pvr_dev->job_ids); > - xa_destroy(&pvr_dev->free_list_ids); > + /* > + * Power the device off before teardown. If this fails the IRQ may rema= in > + * enabled and its handler can still process firmware commands and look > + * up free-list IDs, so the ID arrays must outlive pvr_device_fini(), > + * which releases the IRQ. > + */ > + if (!pm_runtime_status_suspended(drm_dev->dev)) { > + int err =3D pvr_power_device_off(pvr_dev); > + > + if (!err) > + pm_runtime_set_suspended(drm_dev->dev); > + else > + drm_err(drm_dev, "Failed to power the device off (%d)\n", err); > + } > =20 > - pm_runtime_suspend(drm_dev->dev); > pvr_device_fini(pvr_dev); > drm_dev_unplug(drm_dev); > pvr_watchdog_fini(pvr_dev); > pvr_queue_device_fini(pvr_dev); [Severity: High] Can calling pvr_power_device_off() directly in pvr_remove() deadlock with a concurrent GPU reset or power off the hardware while it is still in use? Previously, pm_runtime_suspend() refused to power off the device while usage_count was non-zero. pm_runtime_disable() only waits for in-flight PM callbacks, and pvr_remove() now calls pvr_power_device_off() without holding reset_sem and before freeing the IRQ or unplugging the DRM device. Because __device_release_driver() resumes the device right before calling pvr_remove(), IRQs and watchdog.work can be active even with no open DRM FDs. If the threaded IRQ handler (on a firmware restart request) enters pvr_power_reset() and hits err_device_lost, it deadlocks: CPU0 CPU1 pvr_remove() pvr_device_irq_thread_handler() pm_runtime_disable() pvr_power_reset() pvr_power_device_off() pvr_power_get_clear() -> -EACCES drm_dev_enter() ... pvr_power_fw_disable() err_device_lost: disable_irq() pvr_device_lost() (waits for IRQ thread) drm_dev_unplug() synchronize_srcu() <-- deadlock Without reset_sem, pvr_remove() can also race with a hard reset in pvr_power_reset() and run power_off() twice while runtime status stays RPM_ACTIVE, underflowing clock or pwrseq refcounts, or leave the GPU powered back on after pm_runtime_set_suspended(). During sysfs unbind with active workloads, pvr_power_device_off() can also gate clocks and assert reset while pvr_queue_run_job() or an ioctl holds a runtime PM reference and performs MMIO writes, risking an external abort. [ ... ] > diff --git a/drivers/gpu/drm/imagination/pvr_power.c b/drivers/gpu/drm/im= agination/pvr_power.c > index eb4b6ecdf4f4d..857e0c5cc0e2a 100644 > --- a/drivers/gpu/drm/imagination/pvr_power.c > +++ b/drivers/gpu/drm/imagination/pvr_power.c [ ... ] > @@ -367,12 +371,10 @@ const struct pvr_power_sequence_ops pvr_power_seque= nce_ops_pwrseq =3D { > }; > =20 > int > -pvr_power_device_suspend(struct device *dev) > +pvr_power_device_off(struct pvr_device *pvr_dev) > { > - struct platform_device *plat_dev =3D to_platform_device(dev); > - struct drm_device *drm_dev =3D platform_get_drvdata(plat_dev); > - struct pvr_device *pvr_dev =3D to_pvr_device(drm_dev); > - int err =3D 0; > + struct drm_device *drm_dev =3D from_pvr_device(pvr_dev); > + int err; > int idx; > =20 > if (!drm_dev_enter(drm_dev, &idx)) > @@ -381,17 +383,38 @@ pvr_power_device_suspend(struct device *dev) > if (READ_ONCE(pvr_dev->fw_dev.initialised)) { > err =3D pvr_power_fw_disable(pvr_dev, false, true); > if (err) > - goto err_drm_dev_exit; > + goto out; > } > =20 > err =3D pvr_dev->device_data->pwr_ops->power_off(pvr_dev); > =20 > -err_drm_dev_exit: > +out: > drm_dev_exit(idx); > =20 > return err; > } > =20 > +int > +pvr_power_device_suspend(struct device *dev) > +{ > + struct platform_device *plat_dev =3D to_platform_device(dev); > + struct drm_device *drm_dev =3D platform_get_drvdata(plat_dev); > + struct pvr_device *pvr_dev =3D to_pvr_device(drm_dev); > + > + if (!pvr_power_is_idle(pvr_dev)) { > + /* > + * 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); > + > + return -EBUSY; > + } > + > + return pvr_power_device_off(pvr_dev); > +} [Severity: Medium] Does checking pvr_power_is_idle() before drm_dev_enter() put a lost GPU into an infinite autosuspend retry loop? pvr_device_lost() unplugs the DRM device without clearing fw_dev.initialised or disabling runtime PM. If pvr_power_reset() fails after pvr_fw_hard_reset() zeroes fwif_sysdata, fw_dev.initialised stays true while pow_state remains ROGUE_FWIF_POW_OFF (not ROGUE_FWIF_POW_IDLE). Once usage_count hits zero, pvr_power_is_idle() stays false, so this refreshes last_busy and returns -EBUSY before drm_dev_enter() runs. rpm_suspend() leaves runtime_error clear on -EBUSY and re-arms the 50 ms autosuspend timer, spinning in a permanent 20 Hz wakeup loop. Checking drm_dev_is_unplugged() (or drm_dev_enter()) before pvr_power_is_idle() in pvr_power_device_suspend() would return -EIO immediately as before and stop retries. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-img-pm-aut= osuspend-v4-1-dfc0874198e5@linux.spacemit.com?part=3D1