From: sashiko-bot@kernel.org
To: "Charvi Mehta" <charvi.mehta@arm.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [RFC PATCH 12/28] media: mali-vpu: prepare firmware address space
Date: Thu, 19 Nov 2026 15:57:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-223446@kernel.org> (raw)
In-Reply-To: <20261119153758.1426673-13-charvi.mehta@arm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] media: mali-vpu: rounded-up text_pages mapping in
mali_vpu_fw_map_one_core()
- [Medium] media: mali-vpu: unmapped core walk in
mali_vpu_fw_unmap_core_regions()
--
commit df911b80c99884b502e4cb4ba2acac413ae6c21d
Author: Charvi Mehta <charvi.mehta@arm.com>
media: mali-vpu: prepare firmware address space
This commit adds per-session firmware address space management, allocating
and mapping firmware text, BSS, shared BSS, and host communication protocol
pages across the hardware cores.
> diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c
> new file mode 100644
> index 0000000000000..3c552b5fb2d9b
> --- /dev/null
> +++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-firmware.c
[ ... ]
> +static int mali_vpu_fw_map_one_core(struct mali_vpu_fw *fw,
> + const struct mali_vpu_fw_bin *fw_bin,
> + u32 core)
> +{
> + /* Map pages for the text and BSS segments for one core. */
> + enum mali_vpu_fw_region region = MALI_VPU_FW_REGION_CORE_0 + core;
> + mali_vpu_mmu_va begin, end, va;
> + const struct mali_vpu_fw_header *hdr = fw_bin->header;
> + u32 bss_count = core * fw_bin->bss_page_count;
> + u32 shared_bss_count = 0;
> + u32 master_rw_start, master_rw_size, bss_bitmap_size, i;
> + bool is_shared;
> + int ret;
> +
> + /*
> + * Get the base address where the pages for this core should be
> + * mapped.
> + */
> + ret = mali_vpu_fw_get_region(region, &begin, &end);
> + if (ret)
> + return ret;
> +
> + /* Map text segment. */
> + ret = mali_vpu_mmu_map_pages(fw->mmu, begin + MALI_VPU_FW_TEXT_BASE_ADDR,
> + fw->text_pages, MALI_VPU_ATTR_PRIVATE,
> + MALI_VPU_ACCESS_EXECUTABLE);
> + if (ret)
> + return ret;
[Severity: Medium]
Can mali_vpu_mmu_map_pages() map trailing VPU subpages of fw->text_pages
into the BSS range or past the end of the core region on 16K/64K PAGE_SIZE
kernels?
mali_vpu_mmu_alloc_pages() rounds fw->text_pages->count up to a multiple of
MALI_VPU_PAGES_PER_LINUX_PAGE, whereas mali_vpu_fw_parse_header() validates
bss_start >= text_end and text_end <= region_size at 4 KB VPU page
granularity:
drivers/media/platform/arm/mali-vpu/mali-vpu-mmu.c:mali_vpu_mmu_alloc_pages() {
...
count = roundup(count, MALI_VPU_PAGES_PER_LINUX_PAGE);
capacity = roundup(capacity, MALI_VPU_PAGES_PER_LINUX_PAGE);
...
}
When fw_bin->text_page_count is not aligned to
MALI_VPU_PAGES_PER_LINUX_PAGE and the 4 KB-aligned bss_start falls within
the trailing subpages of the last Linux page, mali_vpu_mmu_map_dma() below
fails with -EAGAIN because the PTE is already occupied. If
fw_bin->text_page_count lies in the final MALI_VPU_PAGES_PER_LINUX_PAGE - 1
pages of the 256-page core region, the rounded-up mapping at
begin + MALI_VPU_FW_TEXT_BASE_ADDR also spills into begin + 0x100000
(outside [begin, end)), leaving dangling PTEs on teardown for cores
0 .. ncores - 2 because mali_vpu_fw_unmap_core_regions() only unmaps
[begin, end) and mali_vpu_mmu_free_pages() only unmaps the single
fw->text_pages->va recorded by the last core.
> +
> + bss_bitmap_size = le32_to_cpu(hdr->bss_bitmap_size);
> + master_rw_start = le32_to_cpu(hdr->master_rw_start_address);
> + master_rw_size = le32_to_cpu(hdr->master_rw_size);
> +
> + /* Map bss shared and private pages. */
> + va = le32_to_cpu(hdr->bss_start_address);
> + for (i = 0; i < bss_bitmap_size; i++) {
> + dma_addr_t dma;
> +
> + is_shared = (va >= master_rw_start &&
> + va < (master_rw_start + master_rw_size));
> +
> + if (is_shared) {
> + dma = fw->shared_bss_pages->pages[shared_bss_count++].dma;
> + } else if (mali_vpu_test_bit_le32(i, hdr->bss_bitmap)) {
> + dma = fw->bss_pages->pages[bss_count++].dma;
> + } else {
> + va += MALI_VPU_PAGE_SIZE;
> + continue;
> + }
> +
> + ret = mali_vpu_mmu_map_dma(fw->mmu, begin + va, dma, MALI_VPU_PAGE_SIZE,
> + MALI_VPU_ATTR_PRIVATE, MALI_VPU_ACCESS_READ_WRITE);
> + if (ret)
> + return ret;
> +
> + va += MALI_VPU_PAGE_SIZE;
> + }
> +
> + return 0;
> +}
> +
> +static void mali_vpu_fw_unmap_core_regions(struct mali_vpu_fw *fw)
> +{
> + enum mali_vpu_fw_region region;
> + mali_vpu_mmu_va begin, end;
> + u32 core;
> + int ret;
> +
> + if (!fw)
> + return;
> +
> + for (core = 0; core < fw->ncores; core++) {
> + region = MALI_VPU_FW_REGION_CORE_0 + core;
> + ret = mali_vpu_fw_get_region(region, &begin, &end);
> + if (!ret)
> + mali_vpu_mmu_unmap_va(fw->mmu, begin, end - begin);
> + }
> +
> + if (!IS_ERR_OR_NULL(fw->text_pages)) {
> + mali_vpu_mmu_free_pages(fw->text_pages);
> + fw->text_pages = NULL;
> + }
> +
> + if (!IS_ERR_OR_NULL(fw->bss_pages)) {
> + mali_vpu_mmu_free_pages(fw->bss_pages);
> + fw->bss_pages = NULL;
> + }
> +
> + if (!IS_ERR_OR_NULL(fw->shared_bss_pages)) {
> + mali_vpu_mmu_free_pages(fw->shared_bss_pages);
> + fw->shared_bss_pages = NULL;
> + }
> +}
[Severity: Medium]
Does calling mali_vpu_fw_unmap_core_regions() from the err_unmap path in
mali_vpu_fw_map_core_regions() walk unallocated L2 page tables for cores
that were never mapped?
mali_vpu_fw_construct() sets fw->ncores before calling
mali_vpu_fw_map_core_regions(), and each core's L2 page table is only
allocated on demand when mali_vpu_fw_map_one_core() maps its pages. If page
allocation or per-core mapping fails before all fw->ncores cores are mapped,
mali_vpu_mmu_unmap_va() walks 256 pages per unmapped core and
mali_vpu_page_table_walk() logs a dev_err() on every 4 KB page:
drivers/media/platform/arm/mali-vpu/mali-vpu-mmu.c:mali_vpu_page_table_walk() {
...
if (!l2->linux_page) {
if (!alloc) {
dev_err(mmu->dev, "missing L2 page in PTW. va=0x%x", va);
return ERR_PTR(-EFAULT);
}
...
}
Also, when mali_vpu_mmu_alloc_pages() fails, the !IS_ERR_OR_NULL() checks
above leave the ERR_PTR value stored in fw->text_pages, fw->bss_pages, or
fw->shared_bss_pages instead of clearing it to NULL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119153758.1426673-1-charvi.mehta@arm.com?part=12
next prev parent reply other threads:[~2026-11-19 15:57 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 15:37 [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 01/28] dt-bindings: media: add Arm Mali-V76 VPU Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 02/28] media: mali-vpu: add Mali VPU platform driver Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 03/28] media: mali-vpu: register V4L2 decoder device and add querycap ioctl Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 04/28] media: mali-vpu: initialize decoder format state Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 05/28] media: mali-vpu: add V4L2 mem2mem and VB2 queue support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 06/28] media: mali-vpu: implement format query ioctls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 07/28] media: mali-vpu: implement TRY_FMT and S_FMT ioctls Charvi Mehta
2026-11-19 15:55 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 08/28] media: mali-vpu: register V76 decoder controls and introduce UAPI controls Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 09/28] media: mali-vpu: add MMU software page table manager Charvi Mehta
2026-11-19 15:59 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 10/28] media: mali-vpu: add firmware cache infrastructure Charvi Mehta
2026-11-19 15:50 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 11/28] media: mali-vpu: load firmware for decoder sessions Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 12/28] media: mali-vpu: prepare firmware address space Charvi Mehta
2026-11-19 15:57 ` sashiko-bot [this message]
2026-11-19 15:37 ` [RFC PATCH 13/28] media: mali-vpu: add firmware message transport Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 14/28] media: mali-vpu: route decoder controls to firmware Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 15/28] media: mali-vpu: handle firmware RPC requests Charvi Mehta
2026-11-19 15:51 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 16/28] media: mali-vpu: add LSID hardware support Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 17/28] media: mali-vpu: add single session scheduler Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 18/28] media: mali-vpu: handle firmware interrupts Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 19/28] media: mali-vpu: start decoder firmware through LSID scheduling Charvi Mehta
2026-11-19 16:03 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 20/28] media: mali-vpu: implement vb2 buffer queue handling Charvi Mehta
2026-11-19 16:06 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 21/28] media: mali-vpu: handle firmware buffer exchange Charvi Mehta
2026-11-19 15:58 ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 22/28] media: mali-vpu: handle fatal firmware error Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 23/28] media: mali-vpu: propagate buffer metadata Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 24/28] media: mali-vpu: add decoder EOS and DRC handling Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 25/28] media: mali-vpu: handle firmware buffer parameters Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 26/28] media: mali-vpu: handle firmware event responses Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 27/28] media: mali-vpu: add stateful decoder state machine Charvi Mehta
2026-11-19 15:37 ` [RFC PATCH 28/28] media: MAINTAINERS: add Arm Mali-V76 VPU driver Charvi Mehta
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=sashiko-outbox-223446@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=charvi.mehta@arm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--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