Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37F53E7717F for ; Tue, 17 Dec 2024 11:07:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 842AE10E927; Tue, 17 Dec 2024 11:07:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=collabora.com header.i=@collabora.com header.b="RccE558S"; dkim-atps=neutral Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6838010E91B for ; Tue, 17 Dec 2024 11:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1734433624; bh=GYpNztzscaOel7EGBkpBeabOkRhfqmxnLr4VcHzhuBE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RccE558Sxi5Xm0IW8RrjG4oanw6wJYNvlHgd7z6dwFn0L6T4ZBWmGmTZV3mmwF1qo cqzhITmheFqKehcbh/kURXk5HFeU0VDsr1BpbRcFjtKtN63/4shhVBC2YUriV0dgX1 zqMGdXxnzEZ7yrgbPp0u16zVaLkdx+K3Tv0fwfd82Z1ZY7OYlFPXAVKO1Y1MLZah0L vH3t3bd+ny2KLDZGno4Z/ylJjfQbmVywFAF0ASEmRPJzOGmkfAdy+LEn3GPYEjdw1U eYUpsVxr+UJdpOicot+2y6O/Xf8j6zKE4vhmlBxESjtvmXt2zyAxz91L7lSIzytpbk bm+DaGNWO0rNQ== Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id 65AD417E09AF; Tue, 17 Dec 2024 12:07:04 +0100 (CET) Date: Tue, 17 Dec 2024 12:06:59 +0100 From: Boris Brezillon To: Liviu Dudau Cc: Steven Price , =?UTF-8?B?QWRyacOhbg==?= Larumbe , dri-devel@lists.freedesktop.org, Christopher Healy , kernel@collabora.com Subject: Re: [PATCH] drm/panthor: Fix a race between the reset and suspend path Message-ID: <20241217120659.6b05ddb8@collabora.com> In-Reply-To: References: <20241217092457.1582053-1-boris.brezillon@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.3.0 (GTK 3.24.43; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, 17 Dec 2024 10:56:14 +0000 Liviu Dudau wrote: > On Tue, Dec 17, 2024 at 10:24:57AM +0100, Boris Brezillon wrote: > > If a reset is scheduled when the suspend happens, we drop the > > reset-pending info on the floor assuming the resume will fix things, > > but the resume logic might try a fast reset. If we're lucky, the > > fast reset fails and we fallback to a slow reset, but if the FW was > > corrupted in a way that makes it partially functional (it boots but > > doesn't quite do what it's expected to do), we won't notice immediately > > that things are not working correctly, leading to a new reset further > > down the road. > > > > Fixes: 5fe909cae118 ("drm/panthor: Add the device logical block") > > Signed-off-by: Boris Brezillon > > --- > > drivers/gpu/drm/panthor/panthor_device.c | 22 ++++++++++++---------- > > 1 file changed, 12 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c > > index 2c817e65e6be..3285ac42d2cd 100644 > > --- a/drivers/gpu/drm/panthor/panthor_device.c > > +++ b/drivers/gpu/drm/panthor/panthor_device.c > > @@ -128,14 +128,11 @@ static void panthor_device_reset_work(struct work_struct *work) > > struct panthor_device *ptdev = container_of(work, struct panthor_device, reset.work); > > int ret = 0, cookie; > > > > - if (atomic_read(&ptdev->pm.state) != PANTHOR_DEVICE_PM_STATE_ACTIVE) { > > - /* > > - * No need for a reset as the device has been (or will be) > > - * powered down > > - */ > > - atomic_set(&ptdev->reset.pending, 0); > > + /* If the device is entering suspend, we don't reset. A slow reset will > > + * be forced at resume time instead. > > + */ > > + if (atomic_read(&ptdev->pm.state) != PANTHOR_DEVICE_PM_STATE_ACTIVE) > > return; > > - } > > > > if (!drm_dev_enter(&ptdev->base, &cookie)) > > return; > > @@ -473,6 +470,14 @@ int panthor_device_resume(struct device *dev) > > > > if (panthor_device_is_initialized(ptdev) && > > drm_dev_enter(&ptdev->base, &cookie)) { > > + /* If there was a reset pending at the time we suspended the > > + * device, we force a slow reset. > > + */ > > + if (atomic_read(&ptdev->reset.pending)) { > > + ptdev->reset.fast = false; > > + atomic_set(&ptdev->reset.pending, 0); > > + } > > + > > ret = panthor_device_resume_hw_components(ptdev); > > if (ret && ptdev->reset.fast) { > > drm_err(&ptdev->base, "Fast reset failed, trying a slow reset"); > > @@ -489,9 +494,6 @@ int panthor_device_resume(struct device *dev) > > goto err_suspend_devfreq; > > } > > > > - if (atomic_read(&ptdev->reset.pending)) > > - queue_work(ptdev->reset.wq, &ptdev->reset.work); > > - > > If you remove this, why do we need a reset workqueue at all? Nothing gets scheduled in it. git grep reset\.wq drivers/gpu/drm/panthor/ reports a few users ;-). > > Best regards, > Liviu > > > /* Clear all IOMEM mappings pointing to this device after we've > > * resumed. This way the fake mappings pointing to the dummy pages > > * are removed and the real iomem mapping will be restored on next > > -- > > 2.47.0 > > >