From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795905802; b=ihbskiYswPZzAiLyikGBfqxL+IdLd+4uQqs4pHcgAVjDj3FmFZplsV97IrxAlJzpmlze tAlw1IyzEf7MgIof81oMOjfM6L+1uyM9l2Kqc5l9bkt0aoPoAvpg1zOT1yIpevgUADLId dRR1kp32ViIZ7CcJHbqvda3QCOYBm67w73Zf++9bZoDMlioFrd57TYq5Uepq+RLk3E603 rYxCOeFJIRhl9HC44yTDsNceJ5KCqugXxKu7qehq5k7iPhs59nVdEpGsmxBBhVVg4TdO4 zttS0hFQKo40ra0IuOf3isvm8izpA4ayNFACkyX0/nXTH/zA91+xtxkKUfqViQ/oqiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795905802; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=bEBas73uzaIP90P97j0+t6H9+4rOSt+2u098HS27bZ8=; b=3aXfDGXBnFqlX+3hCbHTnQdnN5gVDMghMQ7GBvCAQn674cpgVTYPinT6Rp+u0eXI31Ce zVVLOwwWdrbjD+zmi60o+dwPUtrF3dI4s1TVgAQ7wmBh8k0/ILBX7tb1WZlSSdfvJYrKV xSl24YKiybgxHEjpR2p45daMPSss9PvPbgpl0aJGzK61T9gR8pVpsoMcpdKL1qs3R+/NA wSrJcGQT73MtEjjN/kXzhT+ZzwOlwjkGRW+j8Gok7lS/jshmFO0GgYqlm8s0u7RForHnd 87ZYVXaNgzligxnKYBisy3SyOkxR6HFnhUBspr7Iec5CGYMPZ7+yy3KJWWylzDH6AIg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gTy56gko; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C28E606A31C for ; Sat, 28 Nov 2026 22:43:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gTy56gko Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7874D1F00893; Sat, 28 Nov 2026 22:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795905802; bh=bEBas73uzaIP90P97j0+t6H9+4rOSt+2u098HS27bZ8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gTy56gko/GaQ9tU9O70G6o5DuIYcAjQZ3wjwMe7cLIJIOKkH8uMweoxfG/snKfmZh BmXXvTLsbbCqPVTYEwM9SV61Yf1UmhabllfpN4u+uM8FRTeNKF+Av6RRIp3yTb7XZQ khkcckZPl8RGpXB7bqloCy7A7tzDX/zy6E1QpUBu8SfgYSiweaEEb/piEdRwJGnEo/ jco0rZzaqkJ+I6jfZI9PkGoaB3nWpo97UF0AmobjU5ZS0go8bA00bYYEJ7tdKsPv2R IAsavkHsdk2ieZkVq8B/0R/xZh211/U75OZHl5MbIgY3kyy97G+dwc9auK/b1LAlpr CAXyV1Gvzc5SQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 07/17] media: apple: avd: add h264 support Reply-To: sashiko-reviews@lists.linux.dev To: "Sofus Forstreuter" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org In-Reply-To: <20261128-avd-v4-7-35ad7d52c842@icloud.com> References: <20261128-avd-v4-0-35ad7d52c842@icloud.com> <20261128-avd-v4-7-35ad7d52c842@icloud.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 28 Nov 2026 22:43:21 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 12 potential issues to consider: - [High] media: apple: avd: missing SPS bounds checks in avd_h264_validate_sps() - [High] media: apple: avd: stale ctx->job.segments left by avd_h264_stop() - [Medium] media: apple: avd: DPB active vs valid flag and index mismatch in stream_refs() - [Medium] media: apple: avd: slice state not reset on error or new frame in avd_h264_run() - [Medium] media: apple: avd: header_bit_size overflow and silent return in stream_slice() - [Medium] media: apple: avd: off-by-one emulation byte scan in stream_slice() - [Medium] media: apple: avd: implicit B-slice weights enabled on P slices in stream_weights() - [Medium] media: apple: avd: race between avd_submit_job() IRQ and avd_run_postamble() - [Medium] media: apple: avd: per-slice coherent DMA alloc/free churn and uncached scan - [Low] media: apple: avd: uncommitted ctrl->p_new read in avd_h264_start() - [Low] media: apple: avd: stale job->num_alloc in avd_h264_realloc_slices() - [Low] media: apple: avd: unused reference lists built per slice in avd_h264_run() -- commit 96734a8ed59f9431c4f708b792e9ab433ee539a0 Author: Sofus Forstreuter media: apple: avd: add h264 support This commit adds V4L2 stateless H.264 slice-based decoding support to the Apple Video Decoder (AVD) driver. > diff --git a/drivers/media/platform/apple/avd/avd-h264.c b/drivers/media/= platform/apple/avd/avd-h264.c > new file mode 100644 > index 0000000000000..cfa32d551b9df > --- /dev/null > +++ b/drivers/media/platform/apple/avd/avd-h264.c > @@ -0,0 +1,849 @@ [ ... ] > +static void stream_refs(struct avd_ctx *ctx, struct avd_h264_run *run) > +{ > + const struct v4l2_ctrl_h264_decode_params *decode =3D run->decode_param= s; > + const struct v4l2_h264_dpb_entry *dpb =3D decode->dpb; > + struct avd_h264_ctx *h264_ctx =3D ctx->priv; > + struct avd_decoded_buffer *dst, *ref; > + > + dst =3D vb2_to_avd_decoded_buf(&run->base.bufs.dst->vb2_buf); > + > + push(0, ""); > + pusha(h264_ctx->bufs.mv_above_info.addr, "mv_above_info", 7); > + pusha(run->base.dst->dma.aux_start, "mv_color", 0); > + > + push(0, ""); > + push(0, ""); > + push(0, ""); > + push(0, ""); > + > + for (int i =3D 0; i < ARRAY_SIZE(decode->dpb); i++) { > + if (!(dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_VALID)) > + continue; > + > + ref =3D avd_get_ref_buf(ctx, &dst->base.vb, dpb[i].reference_ts); > + > + push(AVD_REF_NUM(run->num_valid - 1) | AVD_REF_FLAG_CONST | > + AVD_REF_FLAG_LONG( > + dpb[i].flags & > + V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM) | > + AVD_REF_DELTA_POC(run->cur_poc - > + dpb[i].top_field_order_cnt), > + "hdr_d0_ref_hdr"); > + > + push_comp(ctx, ref); > + } > +} [Severity: Medium] Can stream_refs() push a different number of reference descriptors than AVD_REF_NUM(run->num_valid - 1) declares? v4l2_h264_init_reflist_builder() sets reflist_builder.num_valid by counting entries with V4L2_H264_DPB_ENTRY_FLAG_ACTIVE set, whereas stream_refs() filters decode->dpb[] by V4L2_H264_DPB_ENTRY_FLAG_VALID. Whenever a DPB entry is valid for display reordering but no longer active for reference, stream_refs() pushes extra reference headers and desynchronizes the fixed header command stream. Also, if run->num_valid is 0 on a non-IDR picture, run->num_valid - 1 underflows the 4-bit AVD_REF_NUM field to 15. In addition, stream_refs() compacts non-contiguous DPB slots as it pushes them, while stream_slice() passes raw sl->ref_pic_list0[i].index and sl->ref_pic_list1[i].index values to AVD_OP_REF_DBP_IDX(), which expects the sequential submission index from stream_refs() and selects the wrong reference frame whenever decode->dpb[] has holes. [ ... ] > +static void stream_weights(struct avd_ctx *ctx, struct avd_h264_run *run) > +{ > + int luma_denom, chroma_denom; > + struct v4l2_h264_weight_factors factors; > + const struct v4l2_ctrl_h264_pred_weights *weights =3D run->pred_weights; > + const struct v4l2_ctrl_h264_pps *pps =3D run->pps; > + const struct v4l2_ctrl_h264_slice_params *sl =3D run->slice_params; > + > + bool pred_weight_req =3D V4L2_H264_CTRL_PRED_WEIGHTS_REQUIRED(pps, sl); > + bool default_weights =3D pps->weighted_bipred_idc =3D=3D 2 && > + !pred_weight_req; [Severity: Medium] Does default_weights enable implicit B-slice weights on P slices when pps->weighted_bipred_idc =3D=3D 2 and V4L2_H264_PPS_FLAG_WEIGHTED_PRED is n= ot set? stream_slice() calls stream_weights() for both P and B slices, and weighted_bipred_idc only applies to B slices, so P slices in streams with weighted_bipred_idc =3D=3D 2 and unweighted P prediction will be decoded wi= th AVD_OP_WEIGHTS_HDR_FLAG1(1) and corrupted. Should default_weights also check sl->slice_type =3D=3D V4L2_H264_SLICE_TYPE_B? [ ... ] > +static void stream_slice(struct avd_ctx *ctx, struct avd_h264_run *run) > +{ > + const struct v4l2_ctrl_h264_decode_params *decode =3D run->decode_param= s; > + const struct v4l2_ctrl_h264_pps *pps =3D run->pps; > + const struct v4l2_ctrl_h264_sps *sps =3D run->sps; > + const struct v4l2_ctrl_h264_slice_params *sl =3D run->slice_params; > + struct avd_h264_ctx *h264_ctx =3D ctx->priv; > + u32 payload_len =3D h264_ctx->active_slice->size; > + bool en_mode =3D (pps->flags & V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE) = =3D=3D > + 0; > + const u8 *data =3D h264_ctx->active_slice->cpu; > + u32 min_off =3D (sl->header_bit_size + (en_mode ? 0 : 7)) / 8; > + u32 off =3D 2; > + u32 num_ref_idx_active, bytes_read =3D 2; > + dma_addr_t coded_in; > + struct avd_decoded_buffer *dst, *ref; > + > + dst =3D run->base.dst; > + > + if (off > payload_len || payload_len < min_off) > + return; > + > + /* include emulation byte in offset to slice header */ > + while (bytes_read < min_off && off < payload_len) { > + if (data[off - 2] !=3D 0x00 || data[off - 1] !=3D 0x00 || > + data[off] !=3D 0x03) > + bytes_read++; > + off++; > + } > + > + coded_in =3D h264_ctx->active_slice->addr + off; [Severity: Medium] Can this loop stop on a 0x03 emulation prevention byte right at the slice header boundary? The loop terminates as soon as bytes_read reaches min_off without checking data[off]. If the last two RBSP bytes of the slice header are 0x00, 0x00 and an emulation prevention byte 0x03 sits at data[off] before RBSP byte min_off, coded_in will point at that 0x03 byte instead of the start of slice data. [ ... ] > + push(AVD_OP_SL_REF | AVD_OP_SL_REF_FLAG_CABAC(sl->cabac_init_idc =3D=3D= 1) | > + AVD_OP_SL_REF_FLAG1(sl->cabac_init_idc =3D=3D 2) | > + AVD_OP_SL_REF_FLAG2( > + !(sl->flags & > + V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED)) | > + AVD_OP_SL_REF_NUM_L0(sl->num_ref_idx_l0_active_minus1) | > + AVD_OP_SL_REF_NUM_L1(sl->num_ref_idx_l1_active_minus1) | > + AVD_OP_SL_REF_SLICE_P(sl->slice_type =3D=3D > + V4L2_H264_SLICE_TYPE_P) | > + AVD_OP_SL_REF_SLICE_I(sl->slice_type =3D=3D > + V4L2_H264_SLICE_TYPE_I) | > + AVD_OP_SL_REF_SLICE_B(sl->slice_type =3D=3D > + V4L2_H264_SLICE_TYPE_B) > + > + , > + "slc_6e4_cmd_ref_type"); > + > + if (sl->slice_type =3D=3D V4L2_H264_SLICE_TYPE_B && > + sl->ref_pic_list1[0].index < ARRAY_SIZE(decode->dpb)) { > + /* bidirectional reference of previous mv */ > + ref =3D avd_get_ref_buf( > + ctx, &dst->base.vb, > + decode->dpb[sl->ref_pic_list1[0].index].reference_ts); > + > + pusha(ref->dma.aux_start, "slc_a78_sps_tile_addr2_lsb8", 0); > + } > +} [Severity: Medium] What happens when stream_slice() returns early on `off > payload_len || payload_len < min_off`, or when a B-slice has `sl->ref_pic_list1[0].index >=3D ARRAY_SIZE(decode->dpb)`? Because stream_slice() returns void, avd_h264_run() still calls avd_end_segment() and avd_submit_job(), submitting an empty segment to the hardware instead of failing the request. In CABAC mode, `sl->header_bit_size + 7` can also overflow u32 when computing min_off, wrapping min_off to 0 and bypassing the length check. Finally, on a B-slice with `sl->ref_pic_list1[0].index >=3D ARRAY_SIZE(decode->dpb)`, AVD_OP_SL_REF_SLICE_B(1) is emitted without the following aux_start address operand that the opcode requires, faulting or hanging the decoder. [ ... ] > +static int avd_h264_validate_sps(struct avd_ctx *ctx, > + const struct v4l2_ctrl_h264_sps *sps) > +{ > + if (sps->chroma_format_idc > 2) > + /* Only 4:0:0, 4:2:0 and 4:2:2 are supported */ > + return -EINVAL; > + if (sps->bit_depth_luma_minus8 !=3D sps->bit_depth_chroma_minus8) > + /* Luma and chroma bit depth mismatch */ > + return -EINVAL; > + if (!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY)) > + /* no interlaced support */ > + return -EINVAL; > + > + return 0; > +} [Severity: High] Can an SPS with dimensions larger than ctx->coded_fmt or an unsupported bit depth cause out-of-bounds DMA writes? avd_h264_alloc_bufs() sizes the internal scratch DMA buffers from fmt_width(ctx) and 8-bit or 10-bit depth, and the capture buffers are sized from ctx->decoded_fmt. However, stream_hdr() programs the hardware with `width =3D (sps->pic_width_in_mbs_minus1 + 1) * 16`, `height =3D (sps->pic_height_in_map_units_minus1 + 1) * 16`, and sps->bit_depth_luma_minus8 directly from V4L2_CID_STATELESS_H264_SPS. Without checking in avd_h264_validate_sps() that the SPS macroblock dimensions fit within fmt_width(ctx) and fmt_height(ctx) and that sps->bit_depth_luma_minus8 is 0 or 2, the hardware can DMA-write past the end of the scratch and capture buffers. > + > +static void avd_h264_stop(struct avd_ctx *ctx) > +{ > + struct avd_h264_ctx *h264_ctx =3D ctx->priv; > + struct avd_dev *dev =3D ctx->dev; > + int i; > + > + if (!h264_ctx) > + return; > + > + avd_buf_free(dev, &h264_ctx->bufs.above_info); > + avd_buf_free(dev, &h264_ctx->bufs.lf_above_info); > + avd_buf_free(dev, &h264_ctx->bufs.lf_above); > + avd_buf_free(dev, &h264_ctx->bufs.ip_above); > + avd_buf_free(dev, &h264_ctx->bufs.mv_above_info); > + > + for (i =3D 0; i < h264_ctx->slice_num; i++) > + avd_buf_free(dev, &h264_ctx->slices[i]); > + > + kfree(h264_ctx->slices); > + kfree(h264_ctx); > + > + ctx->priv =3D NULL; > +} [Severity: High] Does avd_h264_stop() leave ctx->job.segments and ctx->job.num populated after freeing the scratch and slice DMA buffers? If userspace queues slice(s) with V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF, stops and restarts streaming, and then queues a slice with `first_mb_in_slice !=3D 0`, avd_h264_run() skips avd_init_job() while ctx->job.segments is still non-NULL. It then appends segments past ctx->job.num_alloc (writing out of bounds of ctx->job.buf.cpu) and submits the pre-STREAMOFF segments containing the freed DMA addresses of the previous stream's scratch and slice buffers. > + > +static int avd_h264_start(struct avd_ctx *ctx) > +{ > + struct avd_h264_ctx *h264_ctx; > + struct v4l2_ctrl *ctrl; > + int ret; > + > + ctrl =3D v4l2_ctrl_find(&ctx->ctrl_hdl, V4L2_CID_STATELESS_H264_SPS); > + if (!ctrl) > + return -EINVAL; > + > + ret =3D avd_h264_validate_sps(ctx, ctrl->p_cur.p_h264_sps); > + if (ret) > + return ret; > + > + h264_ctx =3D kzalloc_obj(*h264_ctx, GFP_KERNEL); > + if (!h264_ctx) > + return -ENOMEM; > + > + ctx->priv =3D h264_ctx; > + > + /* assume one slice per row */ > + h264_ctx->alloc_slice_num =3D > + ctrl->p_new.p_h264_sps->pic_height_in_map_units_minus1 + 1; [Severity: Low] Should alloc_slice_num read ctrl->p_cur.p_h264_sps instead of ctrl->p_new.p_h264_sps to match the committed SPS validated right above? ctrl->p_new is the V4L2 control scratch buffer and can hold uncommitted values from VIDIOC_TRY_EXT_CTRLS or staged requests. [ ... ] > +static int avd_h264_realloc_slices(struct avd_ctx *ctx) > +{ > + struct avd_h264_ctx *h264_ctx =3D ctx->priv; > + struct avd_job *job =3D &ctx->job; > + struct avd_buf tmp_buf =3D {}; > + size_t alloc_slice_num; > + void *tmp; > + int ret; > + > + tmp =3D h264_ctx->slices; > + alloc_slice_num =3D (h264_ctx->alloc_slice_num * 3) / 2 + 1; > + h264_ctx->slices =3D > + kzalloc_objs(*h264_ctx->slices, alloc_slice_num, GFP_KERNEL); > + if (!h264_ctx->slices) > + goto err_revert_slices; > + > + /* we could already have the correct size */ > + if ((alloc_slice_num + 1) * sizeof(*job->segments) < job->buf.size) > + goto commit_slices; > + > + ret =3D avd_buf_alloc(ctx->dev, &tmp_buf, > + (alloc_slice_num + 1) * sizeof(*job->segments)); > + if (ret) > + goto err_free_slices; > + > + job->segments =3D tmp_buf.cpu; > + job->num_alloc =3D (alloc_slice_num + 1); [Severity: Low] When the existing job->buf is large enough and this jumps to commit_slices, is job->num_alloc left at its smaller value? avd_init_job() resets job->num_alloc to the initial slice count while retaining the larger job->buf.size, so taking the commit_slices branch on a later frame updates h264_ctx->alloc_slice_num without updating job->num_alloc, causing avd_end_segment() to fail once job->num reaches the old job->num_alloc. [ ... ] > +static int avd_h264_run(struct avd_ctx *ctx) > +{ > + struct avd_h264_ctx *h264_ctx =3D ctx->priv; > + struct v4l2_h264_reflist_builder reflist_builder; > + struct avd_h264_run run; > + struct vb2_v4l2_buffer *src; > + void *slice; > + int ret; > + > + avd_h264_run_preamble(ctx, &run); > + > + src =3D v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); > + slice =3D vb2_plane_vaddr(&src->vb2_buf, 0); > + if (!slice) { > + dev_err_ratelimited(ctx->dev->dev, "could not get slice vaddr"); > + ret =3D -EINVAL; > + goto postamble; > + } > + > + if (ctx->job.segments && > + h264_ctx->slice_num >=3D h264_ctx->alloc_slice_num) { > + ret =3D avd_h264_realloc_slices(ctx); > + if (ret) > + goto postamble; > + } else if (h264_ctx->slice_num >=3D h264_ctx->alloc_slice_num) { > + ret =3D -EINVAL; > + goto postamble; > + } > + > + h264_ctx->active_slice =3D &h264_ctx->slices[h264_ctx->slice_num]; > + ret =3D avd_buf_alloc(ctx->dev, h264_ctx->active_slice, > + vb2_get_plane_payload(&src->vb2_buf, 0)); > + if (ret) > + goto postamble; > + > + memcpy(h264_ctx->active_slice->cpu, slice, > + h264_ctx->active_slice->size); > + h264_ctx->slice_num++; [Severity: Medium] Does incrementing h264_ctx->slice_num before validating the slice and frame state wedge the context after errors on held buffers? When an error occurs in avd_h264_run() on a buffer with V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF set (for example, `first_mb_in_slice !=3D 0` when ctx->job.segments is NULL), avd_h264_done() skips resetting h264_ctx->slice_num because it checks only `!(src_buf->flags & V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF)` and ignores `result =3D=3D VB2_BUF_STATE_ERROR`. Once h264_ctx->slice_num reaches h264_ctx->alloc_slice_num with ctx->job.segments still NULL, the `else if (h264_ctx->slice_num >=3D h264_ctx->alloc_slice_num)` branch permanently rejects every subsequent buffer with -EINVAL. Similarly, starting a new frame (`first_mb_in_slice =3D=3D 0`) after an unsubmitted multi-slice frame resets ctx->job.num in avd_init_job() without resetting h264_ctx->slice_num. > + > + /* Build the P/B{0,1} ref lists. */ > + v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params, > + run.sps, run.decode_params->dpb); > + > + run.num_valid =3D reflist_builder.num_valid; > + run.cur_poc =3D reflist_builder.cur_pic_order_count; > + > + v4l2_h264_build_p_ref_list(&reflist_builder, h264_ctx->reflists.p); > + v4l2_h264_build_b_ref_lists(&reflist_builder, h264_ctx->reflists.b0, > + h264_ctx->reflists.b1); [Severity: Low] h264_ctx->reflists is populated on every slice here, but it is never read anywhere in the driver because stream_slice() uses sl->ref_pic_list0 and sl->ref_pic_list1 directly. Can h264_ctx->reflists and the v4l2_h264_build_{p,b}_ref_list*() calls be dropped, and v4l2_h264_init_reflist_builder() moved under is_new_frame()? [ ... ] > + ret =3D avd_submit_job(ctx); > + > +postamble: > + avd_run_postamble(ctx, &run.base); > + return ret; > +} [Severity: Medium] Can the decode completion interrupt race with avd_run_postamble() after avd_submit_job() kicks the hardware? CPU0 CPU1 (threaded IRQ) avd_h264_run() avd_submit_job(ctx) writel(..., AVD_REG_MBOX1_SUBMIT) avd_irq_handler() avd_job_finish() ... vb2_buffer_done(&src->vb2_buf, = ...) media_request_object_unbind() req_obj->req =3D NULL avd_run_postamble(ctx, &run.base) src_req =3D src->vb2_buf.req_obj.req if (src_req) <-- NULL, request never completed v4l2_ctrl_request_complete(...) If the IRQ handler finishes the job before avd_run_postamble() runs, vb2_buffer_done() unbinds src->vb2_buf.req_obj and clears req_obj.req to NULL, so v4l2_ctrl_request_complete() is skipped and userspace polling on the media_request fd hangs. Calling avd_run_postamble() before avd_submit_job() avoids this race. > + > +static void avd_h264_done(struct avd_ctx *ctx, struct vb2_v4l2_buffer *s= rc_buf, > + struct vb2_v4l2_buffer *dst_buf, > + enum vb2_buffer_state result) > +{ > + struct avd_dev *avd =3D ctx->dev; > + struct avd_h264_ctx *h264_ctx =3D ctx->priv; > + int i; > + > + if (!(src_buf->flags & V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF)) { > + for (i =3D 0; i < h264_ctx->slice_num; i++) > + avd_buf_free(avd, &h264_ctx->slices[i]); > + h264_ctx->slice_num =3D 0; > + ctx->job.segments =3D NULL; > + } > +} [Severity: Medium] Does freeing every slice buffer in avd_h264_done() force a dma_alloc_coherent() and dma_free_coherent() (with DART IOMMU map/unmap and IOTLB flush) on every slice of every frame? avd_buf_alloc() already reuses an existing allocation when `buf->cpu && size <=3D buf->size`, but avd_h264_done() frees all h264_ctx->slices[i] buffers after each frame because stream_slice() uses h264_ctx->active_slice->size as the slice payload length. Also, stream_slice() scans for emulation prevention bytes byte-by-byte through the non-cacheable h264_ctx->active_slice->cpu coherent mapping instead of scanning the cacheable vb2_plane_vaddr() buffer before copying. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261128-avd-v4-0-3= 5ad7d52c842@icloud.com?part=3D7