Skip to content

media: meson: vdec: Fix lifecycles, race conditions, and stability bugs

Anand Moon dri-devel linux-amlogic linux-arm-kernel linux-media linux-staging lkml 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest19 patches 3 repliesIn review
  2. v68 patches 0 repliesSuperseded
  3. v56 patches 1 replySuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v43 patches1 replySuperseded
v31 patch1 replySuperseded
v21 patch2 repliesSuperseded
v11 patch2 repliesSuperseded

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/19media: meson: vdec: Fix m2m device lifetime and cleanup pathdrivers/staging/media/meson/vdec/vdec.c drivers/staging/media/meson/vdec/vdec.h+21 -190 replies
2/19media: meson: vdec: Fix STREAMON / STREAMOFF race conditions and session teardowndrivers/staging/media/meson/vdec/vdec.c+95 -410 replies
3/19media: meson: vdec: Fix lifecycle leaks and race conditions in recycle_threaddrivers/staging/media/meson/vdec/vdec.c+45 -30 replies
4/19media: meson: vdec: Fix use-after-free race between teardown and ISR routinesdrivers/staging/media/meson/vdec/vdec.c drivers/staging/media/meson/vdec/vdec.h+22 -20 replies
5/19media: meson: vdec: Fix race condition and synchronize esparser IRQdrivers/staging/media/meson/vdec/esparser.c drivers/staging/media/meson/vdec/vdec.c drivers/staging/media/meson/vdec/vdec.h+14 -00 replies
6/19media: meson: vdec: Fix race condition by canceling work syncdrivers/staging/media/meson/vdec/vdec.c+6 -00 replies
7/19media: meson: vdec: Refactor esparser work queue and fix teardown racedrivers/staging/media/meson/vdec/esparser.c+49 -200 replies
8/19media: meson: vdec: Fix concurrent execution races and unsafe teardowndrivers/staging/media/meson/vdec/esparser.c drivers/staging/media/meson/vdec/vdec.c+59 -310 replies
9/19media: meson: vdec: Fix vp9 header update failure on invalid payloadsdrivers/staging/media/meson/vdec/esparser.c+13 -60 replies
10/19media: meson: vdec: Fix race conditions and leaks in esparser pipelinedrivers/staging/media/meson/vdec/esparser.c+25 -40 replies
11/19media: meson: vdec: Update core m2m stream state during transitionsdrivers/staging/media/meson/vdec/vdec.c+4 -00 replies
12/19media: meson: vdec: Coordinate m2m task execution inside async loopdrivers/staging/media/meson/vdec/esparser.c drivers/staging/media/meson/vdec/vdec.c+15 -00 replies
13/19media: meson: vdec: Fix race conditions in job abort sequencedrivers/staging/media/meson/vdec/vdec.c+11 -00 replies
14/19media: meson: vdec: Correct atomic counter placement in dst_buf_donedrivers/staging/media/meson/vdec/vdec_helpers.c+3 -00 replies
15/19media: meson: vdec: Fix concurrent firmware loading race and hardware timeoutdrivers/staging/media/meson/vdec/vdec_1.c+8 -80 replies
16/19media: meson: vdec: Configure DMA mask and segment size in probedrivers/staging/media/meson/vdec/vdec.c+10 -00 replies
17/19media: meson: canvas: Fix Use-After-Free by linking canvas provider devicedrivers/soc/amlogic/meson-canvas.c+12 -20 replies
18/19media: meson: vdec: Increase VIFIFO buffer size to 32 MiBdrivers/staging/media/meson/vdec/vdec.c+2 -20 replies
19/19gpu: drm: meson: Fix DMA segment size limits and maximize allocation boundariesdrivers/gpu/drm/meson/meson_drv.c+6 -01 reply

Reviews trailers per patch

1 of 19 patches has a Reviewed-by or Acked-by.

PatchNicolas Dufresne
1/19
2/19
3/19
4/19
5/19
6/19
7/19
8/19
9/19
10/19
11/19
12/19
13/19
14/19
15/19
16/19
17/19
18/19
19/19A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 00/19] media: meson: vdec: Fix lifecycles, race conditions, and stability bugs

This patch series addresses a collection of critical race conditions, memory leaks, use-after-free bugs, and resource management issues within the Amlogic Meson video decoder (meson-vdec) driver and associated components.

The primary focus is tightening session lifecycles, safely synchronising the V4L2 m2m framework callbacks, hardening work queue operations (esparser_queue_work), and correcting buffer validations to prevent stability issues like KASAN out-of-bounds errors or stream-on timeouts.

Summary of Changes:
* Race Conditions & Synchronisation: Fixes multi-threading and execution races across stream-on, stream-off, job abort, and teardown pathways.
* Memory Lifecycle: Eliminates memory leaks and use-after-free vulnerabilities by safely pinning, canceling, and sequencing device removals.
* VP9 & Buffer Hardening: Addresses payload handling bugs in the ES parser, properly tracks ongoing buffers via atomic counters, and prevents invalid memory writes.
* Platform/DMA Adjustments: Adjusts DMA segment configurations, canvas handling, and buffer sizes to match modern hardware demands.

Note on an outstanding issue:
An execution deadlock occurs in the driver workqueue path during high stress or long playback sessions. This stall is triggered when the Amlogic hardware internal video FIFO buffer becomes completely full. When esparser_queue_all_src runs, the capacity validation check is tripped due to a design limitation in how buffer exhaustion is handled. This blocks progress and leaves the workqueue worker waiting indefinitely on a core mutex lock.

The resulting hung task call trace shows the worker thread blocking on the internal lock:

Workqueue: events esparser_queue_all_src [meson_vdec]

...
__mutex_lock
mutex_lock_nested
esparser_queue_all_src

I have tried to address this issue, but the underlying deadlock persists under extreme conditions.

Any feedback on this new appock is welcome.

Testing was done using v4l2-compliance and active decoding pipelines on Meson platforms (like Hardkernel ODROID-N2+ and ODROID-C4) SBCs.

The v4l2-compliance tests passed successfully via:

$ v4l2-compliance -s -v -d /dev/video0

Pipelines were validated using the following GStreamer script.

[1] https://gist.github.com/moonlinux/08295ba1f17ce7155550773f2d2cb6e5

Previous changes:
v6: https://lore.kernel.org/all/[email protected]/

Thanks
-Annad

Anand Moon (19):
media: meson: vdec: Fix m2m device lifetime and cleanup path
media: meson: vdec: Fix STREAMON / STREAMOFF race conditions and
session teardown
media: meson: vdec: Fix lifecycle leaks and race conditions in
recycle_thread
media: meson: vdec: Fix use-after-free race between teardown and ISR
routines
media: meson: vdec: Fix race condition and synchronize esparser IRQ
media: meson: vdec: Fix race condition by canceling work sync
media: meson: vdec: Refactor esparser work queue and fix teardown race
media: meson: vdec: Fix concurrent execution races and unsafe teardown
media: meson: vdec: Fix vp9 header update failure on invalid payloads
media: meson: vdec: Fix race conditions and leaks in esparser pipeline
media: meson: vdec: Update core m2m stream state during transitions
media: meson: vdec: Coordinate m2m task execution inside async loop
media: meson: vdec: Fix race conditions in job abort sequence
media: meson: vdec: Correct atomic counter placement in dst_buf_done
media: meson: vdec: Fix concurrent firmware loading race and hardware
timeout
media: meson: vdec: Configure DMA mask and segment size in probe
media: meson: canvas: Fix Use-After-Free by linking canvas provider
device
media: meson: vdec: Increase VIFIFO buffer size to 32 MiB
gpu: drm: meson: Fix DMA segment size limits and maximize allocation
boundaries

 drivers/gpu/drm/meson/meson_drv.c             |   6 +
 drivers/soc/amlogic/meson-canvas.c            |  14 +-
 drivers/staging/media/meson/vdec/esparser.c   | 127 +++++--
 drivers/staging/media/meson/vdec/vdec.c       | 320 ++++++++++++++----
 drivers/staging/media/meson/vdec/vdec.h       |   8 +-
 drivers/staging/media/meson/vdec/vdec_1.c     |  16 +-
 .../staging/media/meson/vdec/vdec_helpers.c   |   3 +
 7 files changed, 388 insertions(+), 106 deletions(-)

base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa

Signature · 1 line
2.50.1