Skip to content

fix decoder corruption, stalls and seek issues

Jackson.lee linux-media lkml stable 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest9 patches 0 repliesNew
  2. v19 patches 2 repliesSuperseded

Changes in v2 from the cover letter

-------------
- 1/9: wave5_handle_src_buffer() peeks the head of the OUTPUT ready queue with v4l2_m2m_next_src_buf() instead of walking the queue, which raced with VIDIOC_QBUF adding to it under rdy_spinlock only.
- 4/9: Reworded the commit message and the comment: the firmware does not update W5_RET_QUEUE_CMD_DONE_INST until the interrupt is acknowledged through W5_VPU_VINT_REASON_CLR and W5_VPU_VINT_CLEAR. No code change.
- 5/9: job_abort() no longer ends a job that device_run() is still running or about to run, which released v4l2_m2m_cancel_job()'s wait early. A per-instance run_lock is held across device_run() and taken in job_abort(), which now finishes through the same ownership check. start_decode() leaves the finish to device_run() when it fails. Wrapped the oops line in the commit message (checkpatch).
- 6/9: release() disables the unstall timer instead of cancelling it, so a device_run() still executing at close cannot re-arm it on the freed instance.
- 8/9: Wrapped the oops line in the commit message (checkpatch).
- 2/9, 3/9, 7/9 and 9/9 are unchanged.
- Added Brandon's Tested-by to 2/9, 3/9, 4/9, 7/9 and 8/9. It is not carried on 5/9 and 6/9, whose code changed since v1.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9media: chips-media: wave5: Ensure Atomic Access to src_buf listdrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c+11 -60 replies
2/9media: chips-media: wave5: drop the consumed-byte tally on OUTPUT streamoffdrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c+12 -00 replies
3/9media: chips-media: wave5: wait before retrying a refused flushdrivers/media/platform/chips-media/wave5/wave5-vpuapi.c+16 -20 replies
4/9media: chips-media: wave5: ack the interrupt after dispatching itdrivers/media/platform/chips-media/wave5/wave5-vpu.c+18 -110 replies
5/9media: chips-media: wave5: finish a job only oncedrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c drivers/media/platform/chips-media/wave5/wave5-vpuapi.c drivers/media/platform/chips-media/wave5/wave5-vpuapi.h+73 -240 replies
6/9media: chips-media: wave5: decode only when the ring holds unclaimed bitstreamdrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c drivers/media/platform/chips-media/wave5/wave5-vpuapi.h+64 -40 replies
7/9media: chips-media: wave5: stamp decoded pictures from a decode-order queuedrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c drivers/media/platform/chips-media/wave5/wave5-vpuapi.h+78 -10 replies
8/9media: chips-media: wave5: restore the display flags after a flushdrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c+60 -170 replies
9/9media: chips-media: wave5: Stop FrameBuf Reset During Seekdrivers/media/platform/chips-media/wave5/wave5-vpu-dec.c+2 -00 replies

Reviews trailers per patch

None of the 9 patches has a Reviewed-by or Acked-by.

PatchBrandon Brnich
1/9
2/9T-b
3/9T-b
4/9T-b
5/9
6/9
7/9T-b
8/9T-b
9/9

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

Read the v2 thread

Cover letter [PATCH v2 0/9] fix decoder corruption, stalls and seek issues

From: Jackson Lee <[email protected]>

This series fixes a set of decoder problems in the wave5 driver that show up as corrupted output, stalled or crashed instances, and lost frames across seeks. All of them carry a Fixes: tag.

Locking and job ownership
1. Serialise removal of OUTPUT buffers between finish_decode(), streamoff_output() and the start_decode() error path.
4. Acknowledge the interrupt only after it has been dispatched, so a completion the VPU adds meanwhile is no longer dropped and does not leave an instance waiting forever.
5. Finish each m2m job exactly once. A second v4l2_m2m_job_finish() from the same context could clear curr_ctx under v4l2_m2m_try_run() and oops in the m2m worker.

Decode scheduling
6. Issue DEC_PIC only when the ring buffer holds bitstream that no queued command will consume. The current check compares two unrelated counters, which sends commands against an empty ring or duplicates one already in flight and corrupts the output. A delayed work restarts an instance left idle with data still buffered.

Seek / flush
2. Drop the consumed-byte tally on OUTPUT streamoff, so it is not credited to the first buffers queued after a seek.
3. Wait between FLUSH retries instead of spending the retry budget in microseconds, and ignore dec_info when reading it failed.
8. Re-establish the display flags from the vb2 buffer states after a flush, so buffers held by userspace are not decoded into.
9. Do not reset the frame buffers on a CAPTURE streamoff that is only part of a seek.

Timestamps
7. Hand OUTPUT timestamps to decoded pictures in decode order. One completion can consume several source buffers, and keeping only the last timestamp lost the others ("Too old frames, bug in decoder" in GStreamer).

Changes in v2
-------------
- 1/9: wave5_handle_src_buffer() peeks the head of the OUTPUT ready queue with v4l2_m2m_next_src_buf() instead of walking the queue, which raced with VIDIOC_QBUF adding to it under rdy_spinlock only.
- 4/9: Reworded the commit message and the comment: the firmware does not update W5_RET_QUEUE_CMD_DONE_INST until the interrupt is acknowledged through W5_VPU_VINT_REASON_CLR and W5_VPU_VINT_CLEAR. No code change.
- 5/9: job_abort() no longer ends a job that device_run() is still running or about to run, which released v4l2_m2m_cancel_job()'s wait early. A per-instance run_lock is held across device_run() and taken in job_abort(), which now finishes through the same ownership check. start_decode() leaves the finish to device_run() when it fails. Wrapped the oops line in the commit message (checkpatch).
- 6/9: release() disables the unstall timer instead of cancelling it, so a device_run() still executing at close cannot re-arm it on the freed instance.
- 8/9: Wrapped the oops line in the commit message (checkpatch).
- 2/9, 3/9, 7/9 and 9/9 are unchanged.
- Added Brandon's Tested-by to 2/9, 3/9, 4/9, 7/9 and 8/9. It is not carried on 5/9 and 6/9, whose code changed since v1.

Link to v1: https://lore.kernel.org/r/[email protected]

Testing
-------
Tested on a TI J721S2 EVM (Wave521C, product code 0x521c, firmware revision 363254) with GStreamer 1.24.13 and the v4l2h264dec/v4l2h265dec elements.

fluster (GStreamer-H.264-V4L2-Gst1.0 / GStreamer-H.265-V4L2-Gst1.0):

JVT-AVC_V1 77/135 (-j1 and -j3, identical per vector)
JCT-VC-HEVC_V1 133/147 (-j1 and -j3, identical per vector)

The pass/fail result of every vector is the same as with v1. The remaining AVC failures are interlaced, MBAFF/PAFF, FMO and SP slice streams. 11 of the 14 HEVC failures are Main10 streams, which this SoC does not decode ("no support for 10 bit depth"); the others are PICSIZE_A_Bossen_1, PICSIZE_B_Bossen_1 and DELTAQP_A_BRCM_4.

No oops, call trace, workqueue warning or "invalid display frame index" message was logged during the runs.

v4l2-compliance 1.28.1-5233, SHA: fc15e229d9d3:

Total for wave5-dec device /dev/video0: 47, Succeeded: 47, Failed: 0, Warnings: 2 Total for wave5-enc device /dev/video1: 47, Succeeded: 47, Failed: 0, Warnings: 0

For the job_abort() and release() changes, three concurrent v4l2h264dec pipelines were also run looping a 1 s clip with flushing seeks, seeking to random positions every 700 ms, and interrupted or killed 100 times. No stall, oops or hang was seen.

Brandon Brnich (2):
media: chips-media: wave5: Ensure Atomic Access to src_buf list
media: chips-media: wave5: Stop FrameBuf Reset During Seek

Jackson Lee (7):
media: chips-media: wave5: drop the consumed-byte tally on OUTPUT
streamoff
media: chips-media: wave5: wait before retrying a refused flush
media: chips-media: wave5: ack the interrupt after dispatching it
media: chips-media: wave5: finish a job only once
media: chips-media: wave5: decode only when the ring holds unclaimed
bitstream
media: chips-media: wave5: stamp decoded pictures from a decode-order
queue
media: chips-media: wave5: restore the display flags after a flush

 .../chips-media/wave5/wave5-vpu-dec.c         | 337 +++++++++++++++---
 .../platform/chips-media/wave5/wave5-vpu.c    |  29 +-
 .../platform/chips-media/wave5/wave5-vpuapi.c |  19 +-
 .../platform/chips-media/wave5/wave5-vpuapi.h |  14 +
 4 files changed, 334 insertions(+), 65 deletions(-)

base-commit: 58348f64125e9a3e44d3abb275ca7f4e6c9641e5 --
2.43.0