Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v8 07/18] media: iris: add vpu op hook to disable ARP buffer
Date: Thu, 30 Jul 2026 15:41:49 +0000	[thread overview]
Message-ID: <20260730154150.302B91F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260730-iris-ar50lt-v8-7-6597c08cea6f@oss.qualcomm.com>

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

Pre-existing issues:
- [High] Race conditions and data races in `iris_core_init` state machine allow concurrent callers to bypass initialization wait and modify `core->state` unprotected.
- [High] The `iris_core_init()` function fails to clean up initialized resources (such as DMA memory for queues, firmware mappings, and VPU power) if the hardware fails to respond in time.
--

--- Patch [7]: [PATCH v8 07/18] media: iris: add vpu op hook to disable ARP buffer ---
commit 53560a9c747444f7e2c1b9214a99baec4904f498
Author: Dikshita Agarwal <dikshita.agarwal@oss.qualcomm.com>

media: iris: add vpu op hook to disable ARP buffer

This patch adds a disable_arp callback to the VPU operations for the iris
driver. This optional callback is invoked during core initialization and
resume paths to disable ARP routing on AR50LT platforms, allowing the
firmware to configure the ARP internal buffer as non-secure for encoder
usage.

> diff --git a/drivers/media/platform/qcom/iris/iris_core.c b/drivers/media/platform/qcom/iris/iris_core.c
> index 6dbe18be5b495..526f925752646 100644
> --- a/drivers/media/platform/qcom/iris/iris_core.c
> +++ b/drivers/media/platform/qcom/iris/iris_core.c
> @@ -46,6 +46,7 @@ static int iris_wait_for_system_response(struct iris_core *core)
>  
>  int iris_core_init(struct iris_core *core)
>  {
> +	const struct vpu_ops *vpu_ops = core->iris_platform_data->vpu_ops;
>  	int ret;
>  
>  	mutex_lock(&core->lock);

[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition in
the state machine of iris_core_init()?

If one thread calls iris_core_init(), it takes core->lock, sets
core->state = IRIS_CORE_INIT, drops the lock, and blocks in
iris_wait_for_system_response():

drivers/media/platform/qcom/iris/iris_core.c:iris_core_init() {
    ...
    core->state = IRIS_CORE_INIT;
    ...
    mutex_unlock(&core->lock);

    return iris_wait_for_system_response(core);
}

Concurrently, if another thread calls iris_core_init(), it can see
core->state == IRIS_CORE_INIT and return success immediately without waiting
for firmware readiness:

drivers/media/platform/qcom/iris/iris_core.c:iris_core_init() {
    mutex_lock(&core->lock);
    if (core->state == IRIS_CORE_INIT) {
        ret = 0;
        goto exit;
    }
    ...
}

Additionally, if the first thread's wait times out,
iris_wait_for_system_response() modifies core->state without holding
core->lock:

drivers/media/platform/qcom/iris/iris_core.c:iris_wait_for_system_response() {
    ...
    if (!ret) {
        core->state = IRIS_CORE_ERROR;
        return -ETIMEDOUT;
    }
    ...
}

Can this lead to a data race with other threads checking or modifying the
state, and allow threads to bypass initialization wait?

[Severity: High]
This is a pre-existing issue, but does iris_core_init() fail to clean up
initialized resources if the hardware fails to respond in time?

In iris_core_init(), if iris_wait_for_system_response() returns an error
(e.g., -ETIMEDOUT), it doesn't trigger the teardown labels:

drivers/media/platform/qcom/iris/iris_core.c:iris_core_init() {
    ...
    mutex_unlock(&core->lock);

    return iris_wait_for_system_response(core);
    ...
}

If wait_for_completion_timeout() expires, iris_wait_for_system_response()
returns -ETIMEDOUT and sets core->state to IRIS_CORE_ERROR:

drivers/media/platform/qcom/iris/iris_core.c:iris_wait_for_system_response() {
    ...
    if (!ret) {
        core->state = IRIS_CORE_ERROR;
        return -ETIMEDOUT;
    }
    ...
}

If user space retries, the next call to iris_core_init() sees
core->state == IRIS_CORE_ERROR, jumps to the error label, and sets the
state to IRIS_CORE_DEINIT without releasing the resources leaked in the
first attempt:

drivers/media/platform/qcom/iris/iris_core.c:iris_core_init() {
    ...
    } else if (core->state == IRIS_CORE_ERROR) {
        ret = -EINVAL;
        goto error;
    }
    ...
error:
    core->state = IRIS_CORE_DEINIT;
    ...
}

A third attempt would then see IRIS_CORE_DEINIT, re-run initialization,
allocate new DMA memory (via iris_hfi_queues_init), and overwrite the
previous pointers, resulting in a permanent memory leak.

Does this sequence cause a memory leak when the firmware hangs?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-iris-ar50lt-v8-0-6597c08cea6f@oss.qualcomm.com?part=7

  reply	other threads:[~2026-07-30 15:41 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <J0r-fdDYeS3FyqabzR_0wiwxC-2onZeePkUSfv0NavGV8KB3Anc-j8yKHqfY2I3X4VAiZpRkYSIZLaTwuyhKMA==@protonmail.internalid>
2026-07-30 15:20 ` [PATCH v8 00/18] media: iris: Add AR50LT core support and enable Agatti platform Dmitry Baryshkov
2026-07-30 15:20   ` [PATCH v8 01/18] media: iris: Add Gen2 firmware autodetect and fallback Dmitry Baryshkov
2026-07-30 15:37     ` sashiko-bot
2026-07-30 20:02     ` Bryan O'Donoghue
2026-07-30 15:20   ` [PATCH v8 02/18] media: iris: Skip UBWC configuration when not supported Dmitry Baryshkov
2026-07-30 15:32     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 03/18] media: iris: drop IRIS_FMT_foo enumeration Dmitry Baryshkov
2026-07-30 15:20   ` [PATCH v8 04/18] media: iris: Filter UBWC raw formats based on hardware capabilities Dmitry Baryshkov
2026-07-30 15:20   ` [PATCH v8 05/18] media: iris: Introduce set_preset_register as a vpu_op Dmitry Baryshkov
2026-07-30 15:20   ` [PATCH v8 06/18] media: iris: Introduce interrupt_init " Dmitry Baryshkov
2026-07-30 15:20   ` [PATCH v8 07/18] media: iris: add vpu op hook to disable ARP buffer Dmitry Baryshkov
2026-07-30 15:41     ` sashiko-bot [this message]
2026-07-30 15:20   ` [PATCH v8 08/18] media: iris: Add platform data field for watchdog interrupt mask Dmitry Baryshkov
2026-07-30 15:32     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 09/18] media: iris: Add platform flag for instantaneous bandwidth voting Dmitry Baryshkov
2026-07-30 15:20   ` [PATCH v8 10/18] media: iris: skip PIPE if it is not supported by the platform Dmitry Baryshkov
2026-07-30 15:56     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 11/18] media: iris: Add framework support for AR50_LITE video core Dmitry Baryshkov
2026-07-30 15:41     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 12/18] media: iris: add minimal GET_PROPERTY implementation Dmitry Baryshkov
2026-07-30 15:39     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 13/18] media: iris: update buffer requirements based on received info Dmitry Baryshkov
2026-07-30 15:52     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 14/18] media: iris: implement support for the Agatti platform Dmitry Baryshkov
2026-07-30 15:54     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 15/18] media: iris: Introduce buffer size calculations for AR50LT Dmitry Baryshkov
2026-07-30 15:47     ` sashiko-bot
2026-07-30 15:20   ` [PATCH v8 16/18] media: iris: add Gen2 firmware support on the Agatti platform Dmitry Baryshkov
2026-07-30 15:21   ` [PATCH v8 17/18] media: venus: skip QCM2290 if Iris driver is enabled Dmitry Baryshkov
2026-07-30 15:39     ` sashiko-bot
2026-07-30 15:21   ` [PATCH v8 18/18] media: iris: constify inst_fw_cap_sm8250_dec Dmitry Baryshkov
2026-07-30 20:09   ` [PATCH v8 00/18] media: iris: Add AR50LT core support and enable Agatti platform Bryan O'Donoghue

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=20260730154150.302B91F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --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 \
    /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