All of lore.kernel.org
 help / color / mirror / Atom feed
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 09/28] media: mali-vpu: add MMU software page table manager
Date: Thu, 19 Nov 2026 15:59:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-223455@kernel.org> (raw)
In-Reply-To: <20261119153758.1426673-10-charvi.mehta@arm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] media: mali-vpu: tautological VA range check and 32-bit VA
  truncation
- [Medium] media: mali-vpu: devm_kzalloc() lifetime and size mismatch
  for MMU pages
--

commit 635e5f0a32c7b907a3a802ff85c63c68b877a3e5
Author: Rath Sankaralingam <rath.sankaralingam@arm.com>

media: mali-vpu: add MMU software page table manager

This commit adds the software MMU two-level page table manager for the
Mali VPU driver and configures the 40-bit DMA mask and maximum DMA
segment size.

> diff --git a/drivers/media/platform/arm/mali-vpu/mali-vpu-mmu.c b/drivers/media/platform/arm/mali-vpu/mali-vpu-mmu.c
> new file mode 100644
> index 0000000000000..00cf5251eff5e
> --- /dev/null
> +++ b/drivers/media/platform/arm/mali-vpu/mali-vpu-mmu.c
> @@ -0,0 +1,693 @@

[ ... ]

> +/* Number of bits for the virtual address space. */
> +#define MALI_VPU_VA_BITS		32
> +#define MALI_VPU_VA_MASK		GENMASK(MALI_VPU_VA_BITS - 1, 0)

[ ... ]

> +static int mali_vpu_map_page(struct mali_vpu_mmu *mmu,
> +			     mali_vpu_mmu_va va,
> +			     dma_addr_t dma,
> +			     enum mali_vpu_mmu_attr attr,
> +			     enum mali_vpu_mmu_access access)
> +{
> +	struct mali_vpu_mmu_pt_page *l2;
> +	mali_vpu_mmu_pte *pte;
> +
> +	/* Check that both VA and DMA address are page aligned. */
> +	if ((va | dma) & MALI_VPU_PAGE_MASK) {
> +		dev_err(mmu->dev, "VA and DMA address must be page aligned. va=0x%x, dma=%pad",
> +			va, &dma);
> +		return -EFAULT;
> +	}
> +
> +	/* Check that VA is within valid address range. */
> +	if (va & ~MALI_VPU_VA_MASK) {
> +		dev_err(mmu->dev, "VA out of valid range. va=0x%x", va);
> +		return -EFAULT;
> +	}

[Severity: Medium]
Can (va & ~MALI_VPU_VA_MASK) ever evaluate to true here?  mali_vpu_mmu_va
is a u32 and MALI_VPU_VA_MASK is GENMASK(31, 0), so the check is always
zero, and 64-bit address arithmetic in callers such as
mali_vpu_mmu_map_pages() (va + i * MALI_VPU_PAGE_SIZE) and
mali_vpu_mmu_map_dma() (va + offset) is truncated to u32 before reaching
mali_vpu_map_page(), wrapping around to address 0 if a mapping crosses
4 GiB.

[ ... ]

> +struct mali_vpu_mmu_pages *mali_vpu_mmu_alloc_pages(struct device *dev,
> +						    size_t count,
> +						    size_t capacity)
> +{
> +	struct mali_vpu_mmu_pages *pages;
> +	int ret;
> +
> +	count = roundup(count, MALI_VPU_PAGES_PER_LINUX_PAGE);
> +	capacity = roundup(capacity, MALI_VPU_PAGES_PER_LINUX_PAGE);
> +	capacity = max(count, capacity);
> +
> +	pages = devm_kzalloc(dev,
> +			     sizeof(*pages) + sizeof(pages->pages[0]) * capacity,
> +			     GFP_KERNEL);
> +	if (!pages)
> +		return ERR_PTR(-ENOMEM);

[ ... ]

> +void mali_vpu_mmu_free_pages(struct mali_vpu_mmu_pages *pages)
> +{
> +	unsigned int i;
> +
> +	mali_vpu_mmu_unmap_pages(pages);
> +
> +	if (!pages->is_external)
> +		for (i = 0; i < pages->count; i += MALI_VPU_PAGES_PER_LINUX_PAGE)
> +			mali_vpu_mmu_free_page(pages->dev, pages->pages[i].dma,
> +					       pages->pages[i].linux_page,
> +					       DMA_BIDIRECTIONAL);
> +
> +	devm_kfree(pages->dev, pages);
> +}

[Severity: Medium]
Should mali_vpu_mmu_alloc_pages() and mali_vpu_mmu_alloc_pages_sg() use
kvzalloc(struct_size(pages, pages, capacity), GFP_KERNEL) and kvfree()
instead of devm_kzalloc() and devm_kfree()?

Because the backing pages and DMA mappings are not devres-managed,
unbinding the platform device while a V4L2 session fd is open frees the
struct mali_vpu_mmu_pages container in devres_release_all() (leaking the
backing pages), and when the fd is later closed, mali_vpu_mmu_free_pages()
reads the freed pages struct and hits WARN_ON(rc) in devm_kfree().  In
addition, devm_kzalloc() requires physically contiguous slab memory and
will fail above KMALLOC_MAX_SIZE for large buffer capacities.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119153758.1426673-1-charvi.mehta@arm.com?part=9

  reply	other threads:[~2026-11-19 15:59 UTC|newest]

Thread overview: 48+ 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 20:04   ` Nicolas Dufresne
2026-11-20 11:48   ` Uwe Kleine-König
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 20:10   ` Nicolas Dufresne
2026-11-19 15:37 ` [RFC PATCH 04/28] media: mali-vpu: initialize decoder format state Charvi Mehta
2026-11-19 20:30   ` Nicolas Dufresne
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 20:44   ` Nicolas Dufresne
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 21:06   ` Nicolas Dufresne
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 [this message]
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 21:34   ` Nicolas Dufresne
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
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 16:07   ` sashiko-bot
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 16:18   ` sashiko-bot
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 16:10   ` sashiko-bot
2026-11-19 15:37 ` [RFC PATCH 28/28] media: MAINTAINERS: add Arm Mali-V76 VPU driver Charvi Mehta
2026-11-19 19:44 ` [RFC PATCH 00/28] media: add arm Mali-V76 video decoder driver Nicolas Dufresne

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-223455@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 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.