From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85E0A446BFC for ; Thu, 13 Aug 2026 10:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786618632; cv=none; b=d11ekzEMVrpLBqK+Lbt4SCNJgZXnRP6qUihMlrzgNd4PfFJfsw0KwPOXbYE9rvChdmjEQLrqcyj7ZDXUwlHrf/ZyxG52MdaX9div30laaasWCLD4dfd130VAZsW0OJuW3hW5XTvv4oYDsaFHQvEv8+hooQEGX4tedJVL5fZYIAo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786618632; c=relaxed/simple; bh=xI8I0lr4pGuzLdwHDJZn57UgsOKNKdZVy3qzaWJ4aSY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TfihZao0QogZz01Sw/FZ4FmVlr5JdA+oFrtxyJPPU+//5RxHkcrLFjCD6GibtewEu/I8Lqo1wVgLAw9be6EcLKFV7kg1dCmiTeglkZHzlXZD0Wuuhn/xuVkASksuqt5MVm1JrgX8rIkuFVCITOGj5LYradbVKFlgHq1ncVJcchg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=HI5Hesp2; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="HI5Hesp2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1786618623; bh=xI8I0lr4pGuzLdwHDJZn57UgsOKNKdZVy3qzaWJ4aSY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HI5Hesp2TywEI3909E1KMKOn8lfeYfeVfVA1Fldrdl2LPFFSkRury58LPU4qHAqbV TlUnDxhMoPC2UdFFqWzNh5avDT2bLOwDnNg0Ft/irn/NbxJalrRY/uUiVp8UPLw0ku A37OLW9b81DQfe8WZhV8p+s2sYwtxVOgp9TdoouOSVOJOo8B9YghLSOlL/xzkeQ39B FbQcoSE5W0zDkmTvsNHZJ/vVZvOVgS4jMgP8hfSG+OJ6uBz35PrGTaN7ASy7NGEHAM MIbB/v8jzdYrqnRK4hj5486wGYyc3cn+s5cXywCVcHx3rTFJqiGHszwEqD1/Eha7/w XT9URLcWHIn+Q== Received: from fedora-21.home (unknown [100.64.0.11]) (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 086A917E074F; Thu, 13 Aug 2026 12:57:02 +0200 (CEST) From: Boris Brezillon Date: Thu, 13 Aug 2026 12:56:59 +0200 Subject: [PATCH v3 01/17] drm/panthor: Disable reset work before unplug Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260813-panthor-unplug-fixes-v3-1-3ed4e961bbe7@collabora.com> References: <20260813-panthor-unplug-fixes-v3-0-3ed4e961bbe7@collabora.com> In-Reply-To: <20260813-panthor-unplug-fixes-v3-0-3ed4e961bbe7@collabora.com> To: Steven Price , Liviu Dudau Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Boris Brezillon X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786618621; l=3456; i=boris.brezillon@collabora.com; s=20260429; h=from:subject:message-id; bh=xI8I0lr4pGuzLdwHDJZn57UgsOKNKdZVy3qzaWJ4aSY=; b=oYx8CxgnoOGDmQYptPXUEpQ5xQ+hZOP054vXJAXqipDwRXznpRk6+M4rj5SPBYTGR6GCY+qNv 67sElHkScPEB6xj4Yl0+sA6DJhGMNKiV5GA3P3V3x+DhL5fRYVQNire X-Developer-Key: i=boris.brezillon@collabora.com; a=ed25519; pk=eN+ORdOgQY7d5U+0kA8h5bf67XdD8bhKbjD/TCHexSY= Unplug is supposed to be the end of the road, so we need to make sure reset works won't execute while we're cleaning up everything as part of the unplug, otherwise it would mess up the internal state. In order to be able to call disable_work_sync() in the unplug path, we need to defer the unplug triggered by the reset logic, otherwise we would deadlock. Fixes: 5fe909cae118 ("drm/panthor: Add the device logical block") Signed-off-by: Boris Brezillon --- drivers/gpu/drm/panthor/panthor_device.c | 21 ++++++++++++++++++++- drivers/gpu/drm/panthor/panthor_device.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c index 0b25abebb803..7c55d0c45cfd 100644 --- a/drivers/gpu/drm/panthor/panthor_device.c +++ b/drivers/gpu/drm/panthor/panthor_device.c @@ -79,6 +79,9 @@ void panthor_device_unplug(struct panthor_device *ptdev) return; } + /* Make sure we're not interrupted by resets while we're unplugging. */ + disable_work_sync(&ptdev->reset.work); + drm_WARN_ON(&ptdev->base, pm_runtime_get_sync(ptdev->base.dev) < 0); /* Call drm_dev_unplug() so any access to HW blocks happening after @@ -91,6 +94,13 @@ void panthor_device_unplug(struct panthor_device *ptdev) */ mutex_unlock(&ptdev->unplug.lock); + /* Unplug triggered by a device removal might race with the deferred + * one queued by the reset work. The function covers this concurrent + * unplug situation, but if we can disable the work before its + * execution, that's still better. + */ + disable_work(&ptdev->unplug.work); + /* Now, try to cleanly shutdown the GPU before the device resources * get reclaimed. */ @@ -114,6 +124,13 @@ void panthor_device_unplug(struct panthor_device *ptdev) complete_all(&ptdev->unplug.done); } +static void panthor_device_unplug_work(struct work_struct *work) +{ + struct panthor_device *ptdev = container_of(work, struct panthor_device, unplug.work); + + panthor_device_unplug(ptdev); +} + static void panthor_device_reset_cleanup(struct drm_device *ddev, void *data) { struct panthor_device *ptdev = container_of(ddev, struct panthor_device, base); @@ -148,8 +165,9 @@ static void panthor_device_reset_work(struct work_struct *work) drm_dev_exit(cookie); if (ret) { - panthor_device_unplug(ptdev); + disable_work(&ptdev->reset.work); drm_err(&ptdev->base, "Failed to boot MCU after reset, making device unusable."); + queue_work(ptdev->reset.wq, &ptdev->unplug.work); } } @@ -206,6 +224,7 @@ int panthor_device_init(struct panthor_device *ptdev) */ *dummy_page_virt = 1; + INIT_WORK(&ptdev->unplug.work, panthor_device_unplug_work); INIT_WORK(&ptdev->reset.work, panthor_device_reset_work); disable_work(&ptdev->reset.work); ptdev->reset.wq = alloc_ordered_workqueue("panthor-reset-wq", 0); diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h index 0fda64fbe5f2..ea23dde90fea 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -264,6 +264,9 @@ struct panthor_device { * operation is done. */ struct completion done; + + /** @work: Unplug work. */ + struct work_struct work; } unplug; /** @reset: Reset related fields. */ -- 2.55.0