All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vishnu Reddy" <busanna.reddy@oss.qualcomm.com>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v8 09/12] media: iris: Add support to select core for dual core platforms
Date: Wed, 10 Jun 2026 06:53:09 +0000	[thread overview]
Message-ID: <20260610065310.416351F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260610-glymur-v8-9-1c79b9d51fc0@oss.qualcomm.com>

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

New issues:
- [High] Independent evaluation of MBPF and MBPS loads overwrites core selection, allowing sessions to bypass hardware capacity limits.
- [High] Dynamically altering stream parameters via `VIDIOC_S_PARM` mutates the session's assigned hardware core in software, corrupting load tracking and miscalculating frequency requirements.
- [High] `iris_vpu36_check_core_load()` permanently unassigns a session's `core_id` if the load check fails, dropping it from future hardware load accounting.
- [High] The macroblocks-per-second (MBPS) hardware limit is never checked at stream-on, allowing sessions to bypass MBPS constraints and contradicting the commit message.

Pre-existing issues:
- [Critical] Race condition between asynchronous firmware message handlers and file closing causes a Use-After-Free on `inst`.
--

commit 6d93c47ec9e78218d02741995430e7d85a3d1c7a
Author: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>

media: iris: Add support to select core for dual core platforms

> On platforms with two video codec cores, select the hardware core for
> a new session based on the current Macroblocks Per Frame (MBPF) and
> Macroblocks Per Second (MBPS) load on each core. The selected core is
> communicated to the firmware via the HFI_PROP_CORE_ID property at
> stream-on time.

[Severity: High]
The commit message states the core is selected based on both MBPF and
MBPS load. However, looking at the stream-on path:

iris_vb2_start_streaming()
  iris_check_session_supported()

Does iris_check_session_supported() only check MBPF at stream-on? If the
MBPS check is omitted, could a session with an excessively high frame rate
bypass MBPS constraints and be incorrectly admitted based solely on its
MBPF footprint?

[ ... ]

> diff --git a/drivers/media/platform/qcom/iris/iris_utils.c b/drivers/media/platform/qcom/iris/iris_utils.c
> index ba5c8dc1280c2..4608e3f288326 100644
> --- a/drivers/media/platform/qcom/iris/iris_utils.c
> +++ b/drivers/media/platform/qcom/iris/iris_utils.c

[ ... ]

> @@ -101,40 +109,52 @@ struct iris_inst *iris_get_instance(struct iris_core *core, u32 session_id)
>  	return NULL;
>  }

[Severity: Critical]
This isn't a bug introduced by this patch, but does dropping core->lock
without taking a reference count in iris_get_instance() allow a
use-after-free?

If a userspace close() runs concurrently:

CPU1
close()
  iris_remove_session()
  kfree(inst)

Could CPU2 then resume in iris_hfi_gen2_handle_session_response() and
execute mutex_lock(&inst->lock) on the freed memory?

[ ... ]

> diff --git a/drivers/media/platform/qcom/iris/iris_vpu3x.c b/drivers/media/platform/qcom/iris/iris_vpu3x.c
> index bafa2ab645b17..dc491a5aecf52 100644
> --- a/drivers/media/platform/qcom/iris/iris_vpu3x.c
> +++ b/drivers/media/platform/qcom/iris/iris_vpu3x.c

[ ... ]

> +static int iris_vpu36_check_core_load(struct iris_inst *inst, bool mbpf)
> +{
> +	const struct iris_platform_data *platform_data = inst->core->iris_platform_data;
> +	u32 max_load = mbpf ? platform_data->max_core_mbpf : platform_data->max_core_mbps;
> +	u32 max_session_cnt = platform_data->max_session_count;
> +	u32 core0_session_cnt = 0, core1_session_cnt = 0;
> +	u32 core0_load = 0, core1_load = 0;
> +	bool select_core0, select_core1;
> +	struct iris_inst *instance;
> +	u32 load, new_load;
> +
> +	inst->core_id = 0;

[Severity: High]
If the load exceeds hardware limits and we return -ENOMEM below, does this
leave inst->core_id as 0? When VIDIOC_S_PARM handles this error and
gracefully reverts the frame rate, does the session remain active on the
hardware with core_id == 0? Could this cause its load to be silently
ignored in future core assignments, and its frequency requirements
misattributed to VCODEC1 via the fallback else logic?

> +
> +	list_for_each_entry(instance, &inst->core->instances, list) {
> +		load = mbpf ? iris_get_mbpf(instance) : iris_get_mbps(instance);
> +
> +		if (instance->core_id == IRIS_VCODEC0) {
> +			core0_load += load;
> +			core0_session_cnt++;
> +		} else if (instance->core_id == IRIS_VCODEC1) {
> +			core1_load += load;
> +			core1_session_cnt++;
> +		}
> +	}
> +
> +	new_load = mbpf ? iris_get_mbpf(inst) : iris_get_mbps(inst);
> +
> +	select_core0 = core0_load + new_load <= max_load && core0_session_cnt < max_session_cnt;
> +	select_core1 = core1_load + new_load <= max_load && core1_session_cnt < max_session_cnt;
> +
> +	if (select_core0 && select_core1)
> +		inst->core_id = (core0_load <= core1_load) ? IRIS_VCODEC0 : IRIS_VCODEC1;
> +	else if (select_core0)
> +		inst->core_id = IRIS_VCODEC0;
> +	else if (select_core1)
> +		inst->core_id = IRIS_VCODEC1;
> +	else
> +		return -ENOMEM;

[Severity: High]
When iris_check_core_mbpf() and iris_check_core_mbps() are called
sequentially (for example, in iris_venc_s_param()), does the second call
unconditionally overwrite the inst->core_id assigned by the first call?
Could this allow a session to be assigned to a core that has sufficient
MBPS capacity but violates its maximum MBPF capacity?

[Severity: High]
If a session is actively streaming and the frame rate is changed via
VIDIOC_S_PARM, this recalculates and mutates inst->core_id here. Is any
command sent to the firmware to migrate the active session to the new
core? If not, will the hardware continue running on the original core
while the software incorrectly redirects required clock frequencies to
the newly assigned core, potentially underclocking the active core?

> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260610-glymur-v8-0-1c79b9d51fc0@oss.qualcomm.com?part=9

  reply	other threads:[~2026-06-10  6:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10  6:29 [PATCH v8 00/12] media: iris: Add support for glymur platform Vishnu Reddy
2026-06-10  6:29 ` [PATCH v8 01/12] media: iris: Add iris vpu bus support Vishnu Reddy
2026-06-10  6:46   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 02/12] iommu: Add iris-vpu-bus to iommu_buses Vishnu Reddy
2026-06-10  6:29 ` [PATCH v8 03/12] dt-bindings: media: qcom,glymur-iris: Add glymur video codec Vishnu Reddy
2026-06-10  6:29 ` [PATCH v8 04/12] media: iris: Add context bank hooks for platform specific initialization Vishnu Reddy
2026-06-10  6:40   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 05/12] media: iris: Enable Secure PAS support with IOMMU managed by Linux Vishnu Reddy
2026-06-10  6:45   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 06/12] media: iris: Replace enum-indexed clock and power domain tables with per-block structures Vishnu Reddy
2026-06-10  6:49   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 07/12] media: iris: Add power sequence for glymur Vishnu Reddy
2026-06-10  6:46   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 08/12] media: iris: Handle CPU_CS_SCIACMDARG3 register write via program bootup registers hook Vishnu Reddy
2026-06-10  6:40   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 09/12] media: iris: Add support to select core for dual core platforms Vishnu Reddy
2026-06-10  6:53   ` sashiko-bot [this message]
2026-06-10  6:29 ` [PATCH v8 10/12] media: iris: Add platform data for glymur Vishnu Reddy
2026-06-10  6:54   ` sashiko-bot
2026-06-10  6:29 ` [PATCH v8 11/12] arm64: dts: qcom: glymur: Add iris video node Vishnu Reddy
2026-06-10  8:44   ` Bryan O'Donoghue
2026-06-10  6:29 ` [PATCH v8 12/12] arm64: dts: qcom: glymur-crd: Enable iris video codec node Vishnu Reddy

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=20260610065310.416351F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=busanna.reddy@oss.qualcomm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.