mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Krischer <florian.krischer@fkr.dev>
To: Dmitry Osipenko <digetx@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Thierry Reding <thierry.reding@kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	linux-media@vger.kernel.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] media: tegra-vde: fix mutex ownership across decode completion
Date: Sun, 29 Nov 2026 18:13:58 +0100	[thread overview]
Message-ID: <20261129171358.3664181-1-florian.krischer@fkr.dev> (raw)

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

                 reply	other threads:[~2026-11-29 17:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261129171358.3664181-1-florian.krischer@fkr.dev \
    --to=florian.krischer@fkr.dev \
    --cc=digetx@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=thierry.reding@kernel.org \
    /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®