From: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
To: sashiko-reviews@lists.linux.dev,
Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Cc: media-ci@linuxtv.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device
Date: Sat, 26 Sep 2026 14:01:21 +0530 [thread overview]
Message-ID: <4befec0d-2e6e-ede6-64d7-58e1123eb1b5@oss.qualcomm.com> (raw)
In-Reply-To: <20260926064921.976721F000FF@smtp.kernel.org>
On 9/26/2026 12:19 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] media: use-after-free of context bank devices during deferred V4L2 cleanup
> --
>
> commit 720de65140e46882c5d0651161ef771fcb1189a2
> Author: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
>
> media: iris: Route buffers to the matching context bank device
>
> The VPU issues DMA through several SMMU streams, and the hardware does
> not give every stream the same addressable range. The non-pixel stream
> cannot address the low 600MB of IOVA space, while the pixel stream can
> address the full range.
> Add iris_get_cb_dev(), which maps a buffer type to the owning context
> bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE,
> NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed
> buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device.
> BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from
> inst->domain: for a decoder the input is non-pixel and the output pixel,
> and the other way round for an encoder.
> Fall back to core->dev whenever the relevant context bank device is
> absent, so platforms still describing "iommus" on the parent iris node
> behave exactly as before to maintain backward compatibility.
>
>> diff --git a/drivers/media/platform/qcom/iris/iris_buffer.c b/drivers/media/platform/qcom/iris/iris_buffer.c
>> index eb8de60c1177f..6e03d13ac1a79 100644
>> --- a/drivers/media/platform/qcom/iris/iris_buffer.c
>> +++ b/drivers/media/platform/qcom/iris/iris_buffer.c
>> @@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
>> enum iris_buffer_type buffer_type, u32 index)
>> {
>> struct iris_buffers *buffers = &inst->buffers[buffer_type];
>> - struct iris_core *core = inst->core;
>> + struct device *dev = iris_get_cb_dev(inst, buffer_type);
>
> [Severity: High]
> Does this acquire the context bank device for DMA mapping without taking a
> reference to guarantee its lifetime matches the buffer?
>
> If iris_remove() explicitly calls platform_device_unregister() on these
> devices upon sysfs driver unbind, and no standard buffers are active, their
> refcount can drop to 0 and they will be freed.
This is not true. Remove callback cannot complete if driver module->refcnt,
refcounted during open, and not decremented with corresponding close call.
iris_close() would call iris_destroy_internal_buffers() to free up the buffers
before un-registering the device.
>
>> struct iris_buffer *buffer;
>>
>> if (!buffers->size)
>
> [ ... ]
>
>> @@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
>>
>> void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
>> {
>> - struct iris_core *core = inst->core;
>> + struct device *dev = iris_get_cb_dev(inst, buffer->type);
>>
>> list_del(&buffer->list);
>> - dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
>> + dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,
>
> [Severity: High]
> Can this result in a use-after-free of the context bank device during
> deferred V4L2 cleanup?
>
> If standard buffers are active, videobuf2 holds a reference. However, during
> deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard
> buffers before iris_destroy_all_internal_buffers() runs. This drops the
> final refcount, freeing the devices.
iris_destroy_all_internal_buffers() frees the internal buffers which is managed
within the driver outside the scope of v4l2_m2m_ctx_release().
>
> Will this fetch and dereference the freed device pointer, passing it to
> dma_free_attrs()? Additionally, does the devm-allocated core also get freed
> on unbind, making inst->core a dangling pointer here?
Unbind will not happen until iris_close() completes(explained above), which
avoids this scenario.
>
> [ ... ]
>
>> diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
>> index fcbc60016beec..064cf0a80748d 100644
>> --- a/drivers/media/platform/qcom/iris/iris_vidc.c
>> +++ b/drivers/media/platform/qcom/iris/iris_vidc.c
>> @@ -108,7 +108,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
>> src_vq->drv_priv = inst;
>> src_vq->buf_struct_size = sizeof(struct iris_buffer);
>> src_vq->min_reqbufs_allocation = MIN_BUFFERS;
>> - src_vq->dev = inst->core->dev;
>> + src_vq->dev = iris_get_cb_dev(inst, BUF_INPUT);
>
> [Severity: High]
> Does this assign a manually lifetime-managed, short-lived device to the
> long-lived vb2_queue context?
>
>> src_vq->lock = &inst->ctx_q_lock;
>> ret = vb2_queue_init(src_vq);
>> if (ret)
>> @@ -122,7 +122,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
>> dst_vq->drv_priv = inst;
>> dst_vq->buf_struct_size = sizeof(struct iris_buffer);
>> dst_vq->min_reqbufs_allocation = MIN_BUFFERS;
>> - dst_vq->dev = inst->core->dev;
>> + dst_vq->dev = iris_get_cb_dev(inst, BUF_OUTPUT);
>
> [Severity: High]
> Does this also assign a manually lifetime-managed, short-lived device to the
> long-lived vb2_queue context?
These devices are long-lived when compare to vb2_queue and are freed only in
iris_remove().
>
next prev parent reply other threads:[~2026-09-26 8:31 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 6:33 [PATCH v5 00/13] media: iris: Migrate iommus to iris sub nodes Vikash Garodia
2026-09-26 6:34 ` [PATCH v5 01/13] dt-bindings: media: qcom,venus: Add context bank subnodes to common schema Vikash Garodia
2026-10-08 6:46 ` Zhangfei Gao
2026-10-08 9:34 ` Vikash Garodia
2026-10-08 12:02 ` Zhangfei Gao
2026-10-08 22:58 ` Bryan O'Donoghue
2026-09-26 6:34 ` [PATCH v5 02/13] dt-bindings: media: qcom,sm8550-iris: Add context bank subnodes Vikash Garodia
2026-10-08 22:58 ` Bryan O'Donoghue
2026-09-26 6:34 ` [PATCH v5 03/13] dt-bindings: media: qcom,sm8750-iris: " Vikash Garodia
2026-09-26 6:34 ` [PATCH v5 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node Vikash Garodia
2026-09-26 6:47 ` sashiko-bot
2026-09-26 7:53 ` Vishnu Reddy
2026-10-08 10:00 ` Dmitry Baryshkov
2026-10-09 10:41 ` Vishnu Reddy
2026-10-09 9:27 ` bod
2026-09-26 6:34 ` [PATCH v5 05/13] media: iris: Add non-pixel and pixel context bank devices Vikash Garodia
2026-09-26 6:34 ` [PATCH v5 06/13] media: iris: Route buffers to the matching context bank device Vikash Garodia
2026-09-26 6:49 ` sashiko-bot
2026-09-26 8:31 ` Vishnu Reddy [this message]
2026-10-08 10:18 ` Dmitry Baryshkov
2026-10-09 11:14 ` Vishnu Reddy
2026-09-26 6:34 ` [PATCH v5 07/13] media: iris: Skip DMA mask setup when the core device has no IOMMU Vikash Garodia
2026-09-26 6:34 ` [PATCH v5 08/13] arm64: dts: qcom: hamoa: Add Iris context bank subnodes Vikash Garodia
2026-09-30 10:32 ` Konrad Dybcio
2026-10-08 10:18 ` Dmitry Baryshkov
2026-09-26 6:34 ` [PATCH v5 09/13] arm64: dts: qcom: sm8550: " Vikash Garodia
2026-09-30 10:32 ` Konrad Dybcio
2026-10-08 10:19 ` Dmitry Baryshkov
2026-09-26 6:34 ` [PATCH v5 10/13] arm64: dts: qcom: lemans: " Vikash Garodia
2026-09-30 10:33 ` Konrad Dybcio
2026-10-08 10:19 ` Dmitry Baryshkov
2026-09-26 6:34 ` [PATCH v5 11/13] arm64: dts: qcom: monaco: " Vikash Garodia
2026-09-30 10:33 ` Konrad Dybcio
2026-10-08 10:19 ` Dmitry Baryshkov
2026-09-26 6:34 ` [PATCH v5 12/13] arm64: dts: qcom: sm8650: " Vikash Garodia
2026-09-30 10:33 ` Konrad Dybcio
2026-10-08 10:19 ` Dmitry Baryshkov
2026-09-26 6:34 ` [PATCH v5 13/13] arm64: dts: qcom: sm8750: " Vikash Garodia
2026-09-30 10:33 ` Konrad Dybcio
2026-10-08 10:19 ` Dmitry Baryshkov
2026-09-30 10:33 ` [PATCH v5 00/13] media: iris: Migrate iommus to iris sub nodes Konrad Dybcio
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=4befec0d-2e6e-ede6-64d7-58e1123eb1b5@oss.qualcomm.com \
--to=busanna.reddy@oss.qualcomm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vikash.garodia@oss.qualcomm.com \
/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