Devicetree
 help / color / mirror / Atom feed
From: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
To: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Cc: sashiko-reviews@lists.linux.dev,
	Vikash Garodia <vikash.garodia@oss.qualcomm.com>,
	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: Fri, 9 Oct 2026 16:44:21 +0530	[thread overview]
Message-ID: <9b15a39a-eca2-d26e-e060-d32879179b00@oss.qualcomm.com> (raw)
In-Reply-To: <txowl3kctv2oca5gqqtiuabh3bffqbb5ntbsfeele5bclzaxrx@4pfvzkccpybj>


On 10/8/2026 3:48 PM, Dmitry Baryshkov wrote:
> On Sat, Sep 26, 2026 at 02:01:21PM +0530, Vishnu Reddy wrote:
>>
>> 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.
> I don't follow this comment. There is nothing about module removal.
> Sashiko here (and in several other comments) tells about using the
> `unbind` file in sysfs to unbind the driver from the device. The module
> is still present in the memory, the module refcount is not decremented.

Thanks for clarifying the comment. Detaching the driver from device at runtime
might leave the interaction with hardware unclosed.
Would prefer adding something like this
    .suppress_bind_attrs = true;

Again, this is not just applicable to sub-node devices, but to parent device
too. Sashiko should classify this as a pre-existing issue.

>>>>  	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.
>>

  reply	other threads:[~2026-10-09 11:14 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
2026-10-08 10:18       ` Dmitry Baryshkov
2026-10-09 11:14         ` Vishnu Reddy [this message]
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=9b15a39a-eca2-d26e-e060-d32879179b00@oss.qualcomm.com \
    --to=busanna.reddy@oss.qualcomm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --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