Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhentao Guo" <zhentao.guo@amlogic.com>
Cc: robh@kernel.org, linux-amlogic@lists.infradead.org,
	conor+dt@kernel.org, devicetree@vger.kernel.org,
	neil.armstrong@linaro.org, media-ci@linuxtv.org
Subject: Re: [PATCH v7 1/6] firmware: meson: sm: video firmware loading via secure monitor
Date: Wed, 12 Aug 2026 02:50:07 +0000	[thread overview]
Message-ID: <20260812025007.AA2E71F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260812-b4-s4-vdec-upstream-v7-1-3fae085861bd@amlogic.com>

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

New issues:
- [High] The `SM_LOAD_VIDEO_FW` command is added to the enum but lacks the required SMC ID mapping in the secure monitor command table, making it entirely unusable.

Pre-existing issues:
- [High] Missing synchronization in `meson_sm_call_read` and `meson_sm_call_write` leads to shared memory corruption and race conditions.
- [High] Object lifetime mismanagement in `meson_sm_get` returns a dangling pointer.
--

--- Patch [1]: [PATCH v7 1/6] firmware: meson: sm: video firmware loading via secure monitor ---
commit ee0d9a884be177be69f150b77b1f3503c328edfa
Author: Zhentao Guo <zhentao.guo@amlogic.com>

firmware: meson: sm: video firmware loading via secure monitor

Add SM_LOAD_VIDEO_FW to the secure monitor command enum to allow decoder
drivers to load firmware through the meson_sm interface.

> diff --git a/include/linux/firmware/meson/meson_sm.h b/include/linux/firmware/meson/meson_sm.h
> index 3ebc2bd9a9760..3b90b49d05529 100644
> --- a/include/linux/firmware/meson/meson_sm.h
> +++ b/include/linux/firmware/meson/meson_sm.h
> @@ -15,6 +15,7 @@ enum {
>  	SM_THERMAL_CALIB_READ,
>  	SM_A1_PWRC_SET,
>  	SM_A1_PWRC_GET,
> +	SM_LOAD_VIDEO_FW,

[Severity: High]
Does this new command also need an SMC ID mapping in the gxbb_chip command
table in drivers/firmware/meson/meson_sm.c?

If drivers attempt to call meson_sm_call() with SM_LOAD_VIDEO_FW, it looks
like meson_sm_get_cmd() might return 0 because the command is not mapped,
causing meson_sm_call() to return -EINVAL:

drivers/firmware/meson/meson_sm.c:meson_sm_call() {
    ...
    cmd = meson_sm_get_cmd(fw->chip, cmd_index);
    if (!cmd)
        return -EINVAL;
    ...
}

[Severity: High]
This is a pre-existing issue, but will drivers loading video firmware
concurrently through this interface encounter data corruption?

Looking at drivers/firmware/meson/meson_sm.c, meson_sm_call_write() copies
data to the globally shared memory region and invokes the SMC without any
locking:

drivers/firmware/meson/meson_sm.c:meson_sm_call_write() {
    ...
    memcpy(fw->sm_shmem_in_base, buffer, size);
    if (meson_sm_call(fw, cmd_index, &written, arg0, arg1, ...) < 0)
        return -EINVAL;
    ...
}

A similar lack of synchronization exists in meson_sm_call_read(). Could
multiple kernel threads executing these functions clobber each other's data
mid-operation?

[Severity: High]
This is a pre-existing issue, but is there an object lifetime mismanagement
issue for drivers obtaining the meson_sm context to make these firmware
calls?

In drivers/firmware/meson/meson_sm.c, meson_sm_get() retrieves the fw
structure but drops the device reference before returning it:

drivers/firmware/meson/meson_sm.c:meson_sm_get() {
    ...
    fw = platform_get_drvdata(pdev);
    put_device(&pdev->dev);
    return fw;
}

If the meson-sm device is unbound via sysfs, devres cleanup frees fw,
leaving consumer drivers with a dangling pointer that will be dereferenced
during subsequent operations. Does this require a fix?

>  };
>  
>  struct meson_sm_firmware;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812-b4-s4-vdec-upstream-v7-0-3fae085861bd@amlogic.com?part=1

  reply	other threads:[~2026-08-12  2:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12  2:41 [PATCH v7 0/6] Add Amlogic stateless H.264 video decoder for S4 Zhentao Guo via B4 Relay
2026-08-12  2:41 ` [PATCH v7 1/6] firmware: meson: sm: video firmware loading via secure monitor Zhentao Guo via B4 Relay
2026-08-12  2:50   ` sashiko-bot [this message]
2026-08-12  2:41 ` [PATCH v7 2/6] firmware: meson: sm: Add video firmware loading SMC call Zhentao Guo via B4 Relay
2026-08-12  2:51   ` sashiko-bot
2026-08-12  2:41 ` [PATCH v7 3/6] media: dt-bindings: Add Amlogic V4L2 video decoder Zhentao Guo via B4 Relay
2026-08-12  2:41 ` [PATCH v7 4/6] decoder: Add V4L2 stateless H.264 decoder driver Zhentao Guo via B4 Relay
2026-08-12  3:04   ` sashiko-bot
2026-08-12  2:41 ` [PATCH v7 5/6] arm64: dts: amlogic: Add video decoder driver support for S4 SOCs Zhentao Guo via B4 Relay
2026-08-12  2:41 ` [PATCH v7 6/6] arm64: defconfig: Enable CONFIG_VIDEO_AMLOGIC_VDEC Zhentao Guo via B4 Relay

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=20260812025007.AA2E71F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=media-ci@linuxtv.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhentao.guo@amlogic.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