Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vikash Garodia" <vikash.garodia@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [RFC PATCH 02/11] media: iris: Add hooks to initialize and tear down context banks
Date: Thu, 09 Jul 2026 12:57:41 +0000	[thread overview]
Message-ID: <20260709125742.41F821F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709-vpu_iommu_iova_handling-v1-2-72bb62cb2dfd@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Pre-existing issues:
- [High] The `iris_core` structure is allocated with `devm_kzalloc` but referenced by video devices that can outlive the device unbind process.
- [High] Missing cancellation of the `sys_error_handler` delayed work in `iris_remove`.
- [High] Hardware and queues are deinitialized before userspace access is revoked in `iris_remove`.
--

--- Patch [2]: [RFC PATCH 02/11] media: iris: Add hooks to initialize and tear down context banks ---
commit 746928806b2d799681dddbd3d539730ff7f9d31a
Author: Vikash Garodia <vikash.garodia@oss.qualcomm.com>

media: iris: Add hooks to initialize and tear down context banks

This commit adds platform hooks to set up and tear down context bank
devices. It updates the platform data structure to include these hooks
and modifies the probe and remove functions to call them.

> diff --git a/drivers/media/platform/qcom/iris/iris_probe.c b/drivers/media/platform/qcom/iris/iris_probe.c
> index c2dcb50a27824..0bce4fb1786bc 100644
> --- a/drivers/media/platform/qcom/iris/iris_probe.c
> +++ b/drivers/media/platform/qcom/iris/iris_probe.c
[ ... ]
> @@ -207,6 +221,8 @@ static void iris_remove(struct platform_device *pdev)
>  
>  	v4l2_device_unregister(&core->v4l2_dev);
>  
> +	iris_deinit_cb_devs(core);
> +

[Severity: High]
This is a pre-existing issue, but are the hardware and queues deinitialized
before userspace access is revoked?

iris_core_deinit(core) is called before video_unregister_device() (higher up
in this function). Because the video device is still registered, userspace
can concurrently call open().

iris_open() calls iris_core_init(), which sees IRIS_CORE_DEINIT and
re-allocates the DMA queues and powers on the hardware. When iris_remove()
completes, devres frees core, but the newly allocated DMA memory is leaked.

Furthermore, the successfully opened file descriptor will now operate on a
freed core structure, leading to a use-after-free.

[Severity: High]
This is a pre-existing issue, but should the sys_error_handler delayed work
be canceled here?

The delayed work sys_error_handler is scheduled by the HFI interrupt handler
when a system error occurs. Because the interrupt is devm-managed, it
remains active throughout iris_remove().

If the interrupt fires and schedules the work during unbind, the work will
execute asynchronously after iris_remove() completes and devres frees core.
The work handler iris_sys_error_handler() will then dereference the freed
core structure.

>  	mutex_destroy(&core->lock);
>  }
>  
> @@ -273,10 +289,14 @@ static int iris_probe(struct platform_device *pdev)
>  
>  	iris_session_init_caps(core);
>  
> -	ret = v4l2_device_register(dev, &core->v4l2_dev);
> +	ret = iris_init_cb_devs(core);
>  	if (ret)
>  		return ret;
>  
> +	ret = v4l2_device_register(dev, &core->v4l2_dev);
> +	if (ret)
> +		goto err_cb_deinit;
> +
>  	ret = iris_register_video_device(core, DECODER);

[Severity: High]
This is a pre-existing issue, but can the core structure outlive its
allocation?

The core structure is allocated with devm_kzalloc() earlier in probe, which
ties its lifetime to the device unbind process. However,
video_unregister_device() does not force-close active file descriptors.

If a user-space application holds the video node open while the driver is
unbound, devres will free the core structure. When the user application later
calls close(), V4L2 invokes iris_close():

drivers/media/platform/qcom/iris/iris_vidc.c:iris_close() {
    struct iris_inst *inst = iris_get_inst(filp);
    ...
    iris_remove_session(inst);
}

This path attempts to acquire core->lock on the already freed core object.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709-vpu_iommu_iova_handling-v1-0-72bb62cb2dfd@oss.qualcomm.com?part=2

  reply	other threads:[~2026-07-09 12:57 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7GAZnP6jPoRrcDnaVzeaB98cONLhtvbiEXV1yD5MJJrA9pCnC9lmlSiCGA8vlDezSXADjmFiqo3ZdClO5SxCFA==@protonmail.internalid>
2026-07-09 12:35 ` [RFC PATCH 00/11] : media: iris: Migrate iommus to iris sub nodes Vikash Garodia
2026-07-09 12:35   ` [RFC PATCH 01/11] dt-bindings: media: qcom,sm8550-iris: Add vpu " Vikash Garodia
2026-07-09 12:46     ` sashiko-bot
2026-07-09 12:50     ` Dmitry Baryshkov
2026-07-10  6:02       ` Vikash Garodia
2026-07-10 15:53         ` Dmitry Baryshkov
2026-07-11  5:46           ` Vikash Garodia
2026-07-10 22:02     ` Bryan O'Donoghue
2026-07-09 12:35   ` [RFC PATCH 02/11] media: iris: Add hooks to initialize and tear down context banks Vikash Garodia
2026-07-09 12:57     ` sashiko-bot [this message]
2026-07-09 12:35   ` [RFC PATCH 03/11] media: iris: Add helper to create a context bank device Vikash Garodia
2026-07-09 13:10     ` sashiko-bot
2026-07-09 12:35   ` [RFC PATCH 04/11] media: iris: Add helper to select relevant " Vikash Garodia
2026-07-09 12:35   ` [RFC PATCH 05/11] media: iris: Skip DMA mask setting to core device when IOMMU is not mapped Vikash Garodia
2026-07-09 13:10     ` Dmitry Baryshkov
2026-07-09 13:43     ` sashiko-bot
2026-07-09 12:35   ` [RFC PATCH 06/11] media: iris: Add hooks for pixel and non-pixel context banks Vikash Garodia
2026-07-09 13:14     ` Dmitry Baryshkov
2026-07-10  6:32       ` Vikash Garodia
2026-07-10 16:03         ` Dmitry Baryshkov
2026-07-09 13:54     ` sashiko-bot
2026-07-10 16:12       ` Dmitry Baryshkov
2026-07-09 12:35   ` [RFC PATCH 07/11] arm64: dts: qcom: hamoa: Move Iris IOMMUs to sub nodes Vikash Garodia
2026-07-09 13:03     ` Dmitry Baryshkov
2026-07-10  6:05       ` Vikash Garodia
2026-07-10 21:05         ` Dmitry Baryshkov
2026-07-09 14:10     ` sashiko-bot
2026-07-10 10:48     ` Bryan O'Donoghue
2026-07-10 22:46     ` Bryan O'Donoghue
2026-07-09 12:35   ` [RFC PATCH 08/11] arm64: dts: qcom: sm8550: Move Iris IOMMUs to child nodes Vikash Garodia
2026-07-09 14:30     ` sashiko-bot
2026-07-09 12:35   ` [RFC PATCH 09/11] arm64: dts: qcom: lemans: " Vikash Garodia
2026-07-09 14:44     ` sashiko-bot
2026-07-09 12:35   ` [RFC PATCH 10/11] arm64: dts: qcom: monaco: " Vikash Garodia
2026-07-09 15:03     ` sashiko-bot
2026-07-09 12:35   ` [RFC PATCH 11/11] arm64: dts: qcom: sm8650: " Vikash Garodia
2026-07-09 15:29     ` sashiko-bot
2026-07-10 10:35   ` [RFC PATCH 00/11] : media: iris: Migrate iommus to iris sub nodes Bryan O'Donoghue
2026-07-10 13:36     ` Vikash Garodia
2026-07-10 13:38       ` Bryan O'Donoghue
2026-07-10 14:02         ` Vikash Garodia

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=20260709125742.41F821F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.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