From: Boris Brezillon <boris.brezillon@collabora.com>
To: Steven Price <steven.price@arm.com>, Liviu Dudau <liviu.dudau@arm.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Boris Brezillon <boris.brezillon@collabora.com>
Subject: [PATCH 12/12] drm/panthor: Fix unplug in the reset path
Date: Tue, 04 Aug 2026 12:09:51 +0200 [thread overview]
Message-ID: <20260804-panthor-unplug-fixes-v1-12-abbbd2d41b13@collabora.com> (raw)
In-Reply-To: <20260804-panthor-unplug-fixes-v1-0-abbbd2d41b13@collabora.com>
We can't use disable_work_sync() if panthor_device_unplug() is called
from the reset work or we'll deadlock. Pass a from_reset_work bool to
the panthor_device_unplug() function and lower the disable_work_sync()
to a disable_work() in that case.
We also add debugfs knobs to simulate this situation.
Maybe we should use a separate work and call device_release_driver()
instead of calling panthor_device_unplug() directly. This would allow
us to actually detach the device from panthor so it can later be
re-attached without an explicit unbind/bind or rmmod/modprobe sequence.
The problem is, this gets racy if the device is manually
unbound/rebound, and it's hard to fix that race, so let's keep this
for later.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/panthor/panthor_device.c | 54 +++++++++++++++++++++++++++++---
drivers/gpu/drm/panthor/panthor_device.h | 10 +++++-
drivers/gpu/drm/panthor/panthor_drv.c | 2 +-
3 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
index 425990369b99..d350bda58bb3 100644
--- a/drivers/gpu/drm/panthor/panthor_device.c
+++ b/drivers/gpu/drm/panthor/panthor_device.c
@@ -93,7 +93,7 @@ static int panthor_device_stop_before_unplug(struct panthor_device *ptdev)
return ret;
}
-void panthor_device_unplug(struct panthor_device *ptdev)
+void panthor_device_unplug(struct panthor_device *ptdev, bool from_reset_work)
{
int ret;
@@ -121,7 +121,10 @@ void panthor_device_unplug(struct panthor_device *ptdev)
drm_dev_unplug(&ptdev->base);
/* Make sure we're not interrupted by resets while we're unplugging. */
- disable_work_sync(&ptdev->reset.work);
+ if (!from_reset_work)
+ disable_work_sync(&ptdev->reset.work);
+ else
+ disable_work(&ptdev->reset.work);
/* Do anything we can to stop the HW. If we can't guarantee that the HW
* is fully stopped, we also can't guarantee the resources it had access
@@ -189,13 +192,16 @@ static void panthor_device_reset_work(struct work_struct *work)
panthor_hw_soft_reset(ptdev);
panthor_hw_l2_power_on(ptdev);
panthor_mmu_post_reset(ptdev);
- ret = panthor_fw_post_reset(ptdev);
+ if (ptdev->reset.fake_failure)
+ ret = -EIO;
+ else
+ ret = panthor_fw_post_reset(ptdev);
atomic_set(&ptdev->reset.pending, 0);
panthor_sched_post_reset(ptdev, ret != 0);
drm_dev_exit(cookie);
if (ret) {
- panthor_device_unplug(ptdev);
+ panthor_device_unplug(ptdev, true);
drm_err(&ptdev->base, "Failed to boot MCU after reset, making device unusable.");
}
}
@@ -694,6 +700,40 @@ DEFINE_DEBUGFS_ATTRIBUTE(panthor_device_fake_unplug_failure_fops,
panthor_device_fake_unplug_failure_get,
panthor_device_fake_unplug_failure_set, "%llu\n");
+static int panthor_device_fake_fw_reset_failure_get(void *data, u64 *val)
+{
+ struct panthor_device *ptdev = data;
+
+ *val = ptdev->reset.fake_failure ? 1 : 0;
+ return 0;
+}
+
+static int panthor_device_fake_fw_reset_failure_set(void *data, u64 val)
+{
+ struct panthor_device *ptdev = data;
+
+ ptdev->reset.fake_failure = val ? true : false;
+ return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(panthor_device_fake_fw_reset_failure_fops,
+ panthor_device_fake_fw_reset_failure_get,
+ panthor_device_fake_fw_reset_failure_set, "%llu\n");
+
+static ssize_t panthor_device_reset_file_write(struct file *file,
+ const char __user *, size_t size,
+ loff_t *)
+{
+ struct panthor_device *ptdev = file_inode(file)->i_private;
+
+ panthor_device_schedule_reset(ptdev);
+ return size;
+}
+
+static const struct debugfs_short_fops panthor_device_reset_fops = {
+ .write = panthor_device_reset_file_write,
+};
+
void panthor_device_debugfs_init(struct drm_minor *minor)
{
struct panthor_device *ptdev = container_of(minor->dev, struct panthor_device, base);
@@ -701,6 +741,12 @@ void panthor_device_debugfs_init(struct drm_minor *minor)
debugfs_create_file("fake_unplug_failure", 0644,
minor->debugfs_root, ptdev,
&panthor_device_fake_unplug_failure_fops);
+ debugfs_create_file("fake_fw_reset_failure", 0644,
+ minor->debugfs_root, ptdev,
+ &panthor_device_fake_fw_reset_failure_fops);
+ debugfs_create_file("reset", 0200,
+ minor->debugfs_root, ptdev,
+ &panthor_device_reset_fops);
panthor_mmu_debugfs_init(minor);
panthor_gem_debugfs_init(minor);
}
diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
index f960109f4b5b..7d3db80fdfb6 100644
--- a/drivers/gpu/drm/panthor/panthor_device.h
+++ b/drivers/gpu/drm/panthor/panthor_device.h
@@ -310,6 +310,14 @@ struct panthor_device {
* all FW sections to make sure we start from a fresh state.
*/
bool fast;
+
+ /**
+ * @fake_failure: When true, pretend the FW boot in the reset path failed.
+ *
+ * This is important to check that we're doing the right thing in this very
+ * unlikely case.
+ */
+ bool fake_failure;
} reset;
/** @pm: Power management related data. */
@@ -398,7 +406,7 @@ struct panthor_file {
};
int panthor_device_init(struct panthor_device *ptdev);
-void panthor_device_unplug(struct panthor_device *ptdev);
+void panthor_device_unplug(struct panthor_device *ptdev, bool from_reset_work);
/**
* panthor_device_schedule_reset() - Schedules a reset operation
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 924a7ecd3733..730f7996985c 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -1827,7 +1827,7 @@ static void panthor_remove(struct platform_device *pdev)
{
struct panthor_device *ptdev = platform_get_drvdata(pdev);
- panthor_device_unplug(ptdev);
+ panthor_device_unplug(ptdev, false);
}
static ssize_t profiling_show(struct device *dev,
--
2.55.0
prev parent reply other threads:[~2026-08-04 10:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 10:09 [PATCH 00/12] drm/panthor: Fix the unplug logic Boris Brezillon
2026-08-04 10:09 ` [PATCH 01/12] drm/panthor: Disable reset work before unplug Boris Brezillon
2026-08-04 10:46 ` Boris Brezillon
2026-08-04 10:09 ` [PATCH 02/12] drm/panthor: Further delay reset work enablement Boris Brezillon
2026-08-04 10:09 ` [PATCH 03/12] drm/panthor: Move the debugfs initialization to panthor_device.c Boris Brezillon
2026-08-04 12:50 ` Liviu Dudau
2026-08-04 10:09 ` [PATCH 04/12] drm/panthor: Flush the cleanup_wq before destroying the drm_device Boris Brezillon
2026-08-04 10:09 ` [PATCH 05/12] drm/panthor: Drop unused vm argument passed to panthor_vm_prepare_sync_only_op_ctx() Boris Brezillon
2026-08-04 10:09 ` [PATCH 06/12] drm/panthor: Split panthor_vm Boris Brezillon
2026-08-04 10:09 ` [PATCH 07/12] drm/panthor: Add fine-grained restrictions on VMs Boris Brezillon
2026-08-04 10:09 ` [PATCH 08/12] drm/panthor: Check AS state before disabling Boris Brezillon
2026-08-04 10:09 ` [PATCH 09/12] drm/panthor: Don't pre-allocate VMAs or page tables when preparing a full VM unmap Boris Brezillon
2026-08-04 10:09 ` [PATCH 10/12] drm/panthor: Make the VM cleanup path more robust against UAF Boris Brezillon
2026-08-04 10:09 ` [PATCH 11/12] drm/panthor: Make the unplug logic more robust Boris Brezillon
2026-08-04 10:09 ` Boris Brezillon [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=20260804-panthor-unplug-fixes-v1-12-abbbd2d41b13@collabora.com \
--to=boris.brezillon@collabora.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liviu.dudau@arm.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=steven.price@arm.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®