mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: tegra-vde: fix mutex ownership across decode completion
@ 2026-11-29 17:13 Florian Krischer
  0 siblings, 0 replies; only message in thread
From: Florian Krischer @ 2026-11-29 17:13 UTC (permalink / raw)
  To: Dmitry Osipenko, Mauro Carvalho Chehab
  Cc: Thierry Reding, Jonathan Hunter, linux-media, linux-tegra, linux-kernel

VDE starts a mem2mem decode while holding vde->lock in the job callback,
but tegra_decode_complete() runs in a workqueue and releases it through
tegra_vde_decode_abort(). Unlocking a mutex from a different task violates
mutex ownership and triggers a DEBUG_MUTEXES warning.

Use a binary semaphore for decode and system-sleep serialization so the
completion worker can release it. Return the semaphore if forced runtime
suspend fails, allowing later decode or suspend operations to proceed.

Fixes: 24d5d2bafb46 ("media: staging: tegra-vde: Support V4L stateless video decoder API")
Signed-off-by: Florian Krischer <florian.krischer@fkr.dev>
---
 drivers/media/platform/nvidia/tegra-vde/h264.c |  6 +++---
 drivers/media/platform/nvidia/tegra-vde/vde.c  | 10 ++++++----
 drivers/media/platform/nvidia/tegra-vde/vde.h  |  3 ++-
 3 files changed, 11 insertions(+), 8 deletions(-)

Build-tested for ARM with W=1 against media-committers/next.
On ASUS SL101 with DEBUG_MUTEXES, the baseline and patched v7.4-rc4
kernels each completed 3/3 60-frame H.264 decodes with identical output
hashes. The baseline logged the cross-task mutex warning; the patched
kernel did not.
The patched kernel also completed one LP1 suspend/resume cycle; all
three post-resume decodes matched the baseline hashes.

Thanks for taking a look.

diff --git a/drivers/media/platform/nvidia/tegra-vde/h264.c b/drivers/media/platform/nvidia/tegra-vde/h264.c
index 2a2211671..f4e1ac8f4 100644
--- a/drivers/media/platform/nvidia/tegra-vde/h264.c
+++ b/drivers/media/platform/nvidia/tegra-vde/h264.c
@@ -539,7 +539,7 @@ static int tegra_vde_decode_begin(struct tegra_vde *vde,
 	unsigned int macroblocks_nb;
 	int err;
 
-	err = mutex_lock_interruptible(&vde->lock);
+	err = down_interruptible(&vde->lock);
 	if (err)
 		return err;
 
@@ -588,7 +588,7 @@ static int tegra_vde_decode_begin(struct tegra_vde *vde,
 	pm_runtime_put_autosuspend(dev);
 
 unlock:
-	mutex_unlock(&vde->lock);
+	up(&vde->lock);
 
 	return err;
 }
@@ -613,7 +613,7 @@ static void tegra_vde_decode_abort(struct tegra_vde *vde)
 
 	pm_runtime_put_autosuspend(dev);
 
-	mutex_unlock(&vde->lock);
+	up(&vde->lock);
 }
 
 static int tegra_vde_decode_end(struct tegra_vde *vde)
diff --git a/drivers/media/platform/nvidia/tegra-vde/vde.c b/drivers/media/platform/nvidia/tegra-vde/vde.c
index c3097085a..c4f953e67 100644
--- a/drivers/media/platform/nvidia/tegra-vde/vde.c
+++ b/drivers/media/platform/nvidia/tegra-vde/vde.c
@@ -333,7 +333,7 @@ static int tegra_vde_probe(struct platform_device *pdev)
 
 	INIT_LIST_HEAD(&vde->map_list);
 	mutex_init(&vde->map_lock);
-	mutex_init(&vde->lock);
+	sema_init(&vde->lock, 1);
 	init_completion(&vde->decode_completion);
 
 	err = tegra_vde_iommu_init(vde);
@@ -431,11 +431,13 @@ static __maybe_unused int tegra_vde_pm_suspend(struct device *dev)
 	struct tegra_vde *vde = dev_get_drvdata(dev);
 	int err;
 
-	mutex_lock(&vde->lock);
+	down(&vde->lock);
 
 	err = pm_runtime_force_suspend(dev);
-	if (err < 0)
+	if (err < 0) {
+		up(&vde->lock);
 		return err;
+	}
 
 	return 0;
 }
@@ -449,7 +451,7 @@ static __maybe_unused int tegra_vde_pm_resume(struct device *dev)
 	if (err < 0)
 		return err;
 
-	mutex_unlock(&vde->lock);
+	up(&vde->lock);
 
 	return 0;
 }
diff --git a/drivers/media/platform/nvidia/tegra-vde/vde.h b/drivers/media/platform/nvidia/tegra-vde/vde.h
index abac0221d..2e013c4f0 100644
--- a/drivers/media/platform/nvidia/tegra-vde/vde.h
+++ b/drivers/media/platform/nvidia/tegra-vde/vde.h
@@ -13,6 +13,7 @@
 #include <linux/iova.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/semaphore.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
 
@@ -102,7 +103,7 @@ struct tegra_vde {
 	void __iomem *vdma;
 	void __iomem *frameid;
 	struct device *dev;
-	struct mutex lock;
+	struct semaphore lock;
 	struct mutex map_lock;
 	struct list_head map_list;
 	struct reset_control *rst;

base-commit: fb8b2c10a588f1384b98280b1c32307da9db4747

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-29 17:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 17:13 [PATCH] media: tegra-vde: fix mutex ownership across decode completion Florian Krischer

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®