From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=54.206.16.166 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796093438; b=UcNJ1YeJ3WePBlLcwmYjMR9ql9IUb9BW2mpfmgF2NFi3QzJqRhrIo+qSD2JY26/s0Q1i nyww8AQAvmaMIQyXqFlAPhcRHyliWazyybLAa90Wzp5vmUktm1ehNf+HSKKRlZsd77Nli fp7SP02AowLWkXOSN+Kq84V1+95XpoSwDcMhA0W0bIPGg9FvgMyjZg83gWIDdgyugDBNC jNkRIkAvcbvj2JPuI9qjtljfm8PEzYZiC9VWfqetcE+qg97Yduo7G+IPMr2vrbgq3drve gGJDexwXoJEJJw0bF/xRigkE3O3EeQOOAd4s6o8YgM4aaK/EggQLr2Ub1ccCLADjJvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796093438; h=DMARC-Filter:DKIM-Signature:X-QQ-mid:X-QQ-Originating-IP:Received: X-QQ-SSF:X-QQ-GoodBg:X-BIZMAIL-ID:EX-QQ-RecipientCnt:Mime-Version: Content-Transfer-Encoding:Content-Type:Date:Message-Id:Cc:Subject: From:To:X-Mailer:References:In-Reply-To:X-QQ-SENDSIZE:Feedback-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:X-QQ-RECHKSPAM; bh=ZxCwrONesqWSkEoVHZGLW4PrbNuIoGZEUWjzfoOSzPw=; b=WOkpua5LBWFDnmoPiUgZw4C9B64XgyqWc9zP4G8qC7TumCxqRuJXRPeAUqyx7t4OVVoI jSle0A14G/crc/TRaQjnJ6y3MyNJUVCpiiq0qhUwRnRJBzJq2KU4oqHuZEHGY9RpQzNSH Eqf8fU3WZl3HlOg7U7B2tZOQrU/8Kf4ztSw43U06bFltXo0tOs86/vehqNJLLb7Cswq9q 1N4CKbYGOC5btVX4RgUu9O6zy96ZcdgkkI4GIFhIFLZFcuFhT7lVqqKiU5Rx3xPJZBUqP a+yieaHmGvcB2VmBBJfcc+WeBJV94vSNFsBbd6tGkf+/N8CqqKy9W/3VSOsAFoX9OoQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=linux.spacemit.com; spf=none smtp.mailfrom=linux.spacemit.com; dkim=pass header.d=linux.spacemit.com header.i=@linux.spacemit.com header.a=rsa-sha256 header.s=mxsw2412 header.b=Muas9AWp; arc=none smtp.remote-ip=54.206.16.166 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00404606A31A for ; Tue, 1 Dec 2026 02:50:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 00404606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux.spacemit.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.spacemit.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.spacemit.com header.i=@linux.spacemit.com header.a=rsa-sha256 header.s=mxsw2412 header.b=Muas9AWp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.spacemit.com; s=mxsw2412; t=1796093337; bh=ZxCwrONesqWSkEoVHZGLW4PrbNuIoGZEUWjzfoOSzPw=; h=Mime-Version:Date:Message-Id:Subject:From:To; b=Muas9AWpzpWE6SS1i5qMv0I/7RweV5f46sUR7LD0FTkGMRMxD8xq45fGwBVNVwnBa IpY5M4ZsAR2K0WsyQYVg60eqUMxBTYrtqdOiqwC2x1qmgtIiKhAzobPMzFKn3ZNxtd jYPBh/iS8frK/7g8QWQm+M1of8Cd077ZoSlhcC/A= X-QQ-mid: zesmtpsz9t1796093335ta36a2332 X-QQ-Originating-IP: tq+zlmjfgwGP4NDbLUJ/NHjbrswkHJfXErswEEzis5A= Received: from localhost ( [120.237.158.181]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 01 Dec 2026 10:48:52 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5746957857323035285 EX-QQ-RecipientCnt: 20 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 10:48:52 +0800 Message-Id: Cc: "dri-devel" , "linux-riscv" , "gye976" , "imagination" , "linux-kernel" , "spacemit" Subject: Re: [PATCH v3] drm/imagination: re-check firmware idle state before runtime suspend From: "Baihui Liang" To: "Brajesh Gupta" , "Luigi.Santivetti" , "aou" , "tzimmermann" , "simona" , "dlan" , "troy.mitchell" , "airlied" , "Alessio.Belle" , "alex" , "maarten.lankhorst" , "pjw" , "mripard" , "palmer" X-Mailer: aerc 0.17.0 References: <20261127-img-pm-autosuspend-v3-1-3a65ee22d9b2@linux.spacemit.com> In-Reply-To: X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpsz:linux.spacemit.com:qybglogicsvrgz:qybglogicsvrgz6b-0 X-QQ-XMAILINFO: Odky5wNUcHo/qa0XbxzhqGsEK3ASLILb44psMHdy2ZbR7G3vB+GuNdxk QG6dt53ArTtAxGDq1DJvGy63qz150vTmriwsqzsOUvY9s+MbdK9Hwjl+XIFFEmGHeO/+Y8a AluGMfl9KQH7JBgnx0dXEH70zrPu3zjcBQNJu63wPbDqOOSxXZvjVVPnbsI9oIC4mzIZvFH RC7dSgJ5vJfQ9VDpecIXHRO8uEdrk4+JVNBgbIMVKo5Thaql5+xi/VK2FhzC1yaFa3M/OZh DVBokrWbY7sPuwDExNKLqnQD92jeM4v04SWBov4qclIa9U4+HKZUlG+EuRoInUgrvO+bX/v 8dE1tC4gJ7JxMD/eL0vTNqIALCjG4HpiDHgRa/U0WLlnn3Bre85rg/IPJ2A7qMfUrTAM5VR +H12lMV085ihN57pFQ5Fi9/k9Wf6xU5jNsS2KyUA3QCv2ytTkUHv2i46rIihzsEcM6gnZ95 UvDy1AgnTzb5l98jcqJOyP9CDwvxMo9tsdFLxcFEfBS4rP857+tLLW6T+K+wVLfH014cAtd 2EmdjqpktYtKhGYkDZi+puDPXOcl03fPhN1v/+5LXilh8Yditj5oh/9efvV/4QBn6YhrUvp bLVjOjg0DMasBraF7KsVB2vbhjZ32zNCi5BS416mfBOmJ3eSgwqjZ0JNRck6z8R2ESw3gTH PCoP7Kd8wHQs72YTFldUxobuOe590A4j35uKZy+UZUjVOxBns+qT5nRAWXyxIAquCly3C+P l/d88R3tbCVnphdsII1q0YB4EskgjsIpV0f8w/1ug9WZq8e1lBS9SLyKu4CkfyELGpn8+dt Kosuz8gXUDVJf5b6MmWN2Vqbu+ksty/Dphm6g24h4XhOx9ampG4shjQQvV06WnzPaYpmOwT pJuYpRkndw6hvfGchaPRCSpKMeJiTM3KvAbapWPl3sbVgYHLzjM/RXzNnuewn2TkIGz21mV s38avzdyHMv1JnfyUFhDTTESea8thi5ibDRggzK68dCeHmm01R3tCQeAK1v0iZL3VR5cjpc mfJ0yo6Ot59YP9g6e03jrBxVVDes1oo7GAeI1GiA== X-QQ-XMRINFO: MPJ6Tf5t3I/ylTmHUqvI8+Wpn+Gzalws3A== X-QQ-RECHKSPAM: 0 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/im= agination/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 =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 > > + pvr_power_device_shutdown(pvr_dev); > > + > We could potentially drop the interface pvr_power_device_shutdown by rear= ranging > 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 =3D 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.=20 > 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); > > =20 [...] > > +{ > > + struct drm_device *drm_dev =3D from_pvr_device(pvr_dev); > > + struct device *dev =3D 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 =3D pvr_power_device_off(pvr_dev); > > + drm_dev_exit(idx); > > + if (!err) > > + err =3D pm_runtime_set_suspended(dev); > > + > > + if (err) > Change to 'else' part of the if condition. > This one goes away with the inlining above =E2=80=94 the function is remove= d. > > + 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; > > =20 > > - 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; > > - } > > + 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 fre= es fwif_sysdata (pvr_fw.c:566,593) without NULLing the pointer, so on the prob= e failure path (pvr_device_init() -> err_pm_runtime_put -> pm_runtime_put_syn= c_suspend()) this would be a NULL deref or a use-after-free. How about moving the guard into pvr_power_is_idle() instead? > > + /* > > + * 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); > > =20 > > - err =3D pvr_dev->device_data->pwr_ops->power_off(pvr_dev); > > + return -EBUSY; > > + } > > =20 > > -err_drm_dev_exit: > > + err =3D 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