dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] drm/exynos: queue the IPP cleanup work before waking the caller
@ 2026-11-19  2:35 Yaohan Li
  2026-11-19  2:48 ` sashiko-bot
  2026-11-19  7:54 ` [RFC PATCH v2] drm/exynos: publish the IPP task completion after the last task access Yaohan Li
  0 siblings, 2 replies; 3+ messages in thread
From: Yaohan Li @ 2026-11-19  2:35 UTC (permalink / raw)
  To: inki.dae, sw0312.kim, kyungmin.park; +Cc: dri-devel, krzk, linux-kernel

exynos_drm_ipp_task_done() marks the task done, wakes the waiters and only
then decides whether the task has to be released by the cleanup work.  A
commit ioctl that waits for the task is woken by that wake_up() and frees
the task itself as soon as it sees the DONE flag, so the task->flags read
that follows touches memory that may already be gone.

Read the flag while the task is still guaranteed to be alive, together
with the other task state under ipp->lock, and queue the cleanup work
before the wakeup.  A task that is handed to the work is then always
queued while it still exists.

Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>

---
Prepared against v7.4-rc1-1969-g666539eecdf4.

Compile tested only: arm64 with aarch64-linux-gnu-gcc 11.4
and CONFIG_DRM_EXYNOS=m with the IPP drivers.  The affected hardware was not
available, so the teardown path was not exercised and no fault or
race injection was run.

AI assistance: the analysis, the change and its review notes were
prepared with Claude (Anthropic) as a coding assistant.  The author
reviewed the reasoning and takes responsibility for the content.
---
 drivers/gpu/drm/exynos/exynos_drm_ipp.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
index 43bc4f63bb84..49ae8ce9b95a 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
@@ -764,6 +764,7 @@ void exynos_drm_ipp_task_done(struct exynos_drm_ipp_task *task, int ret)
 {
 	struct exynos_drm_ipp *ipp = task->ipp;
 	unsigned long flags;
+	bool async;
 
 	DRM_DEV_DEBUG_DRIVER(task->dev, "ipp: %d, task %p done: %d\n",
 			     ipp->id, task, ret);
@@ -773,15 +774,22 @@ void exynos_drm_ipp_task_done(struct exynos_drm_ipp_task *task, int ret)
 		ipp->task = NULL;
 	task->flags |= DRM_EXYNOS_IPP_TASK_DONE;
 	task->ret = ret;
+	async = task->flags & DRM_EXYNOS_IPP_TASK_ASYNC;
 	spin_unlock_irqrestore(&ipp->lock, flags);
 
 	exynos_drm_ipp_next_task(ipp);
-	wake_up(&ipp->done_wq);
 
-	if (task->flags & DRM_EXYNOS_IPP_TASK_ASYNC) {
+	/*
+	 * Hand the task over to the cleanup work before a synchronous caller
+	 * is woken up: once wake_up() returns, that caller may have released
+	 * the task already.
+	 */
+	if (async) {
 		INIT_WORK(&task->cleanup_work, exynos_drm_ipp_cleanup_work);
 		schedule_work(&task->cleanup_work);
 	}
+
+	wake_up(&ipp->done_wq);
 }
 
 static void exynos_drm_ipp_next_task(struct exynos_drm_ipp *ipp)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-19  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  2:35 [RFC PATCH] drm/exynos: queue the IPP cleanup work before waking the caller Yaohan Li
2026-11-19  2:48 ` sashiko-bot
2026-11-19  7:54 ` [RFC PATCH v2] drm/exynos: publish the IPP task completion after the last task access Yaohan Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox