From: sashiko-bot@kernel.org
To: "Thierry Reding" <thierry.reding@kernel.org>
Cc: robh@kernel.org, linux-s390@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, media-ci@linuxtv.org,
conor+dt@kernel.org, devicetree@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
dri-devel@lists.freedesktop.org,
"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v6 11/12] arm64: tegra: Hook up VPR to host1x
Date: Fri, 04 Sep 2026 11:49:36 +0000 [thread overview]
Message-ID: <20260904114936.DAA891F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904-tegra-vpr-v6-11-79042cfa8de5@nvidia.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The VPR driver assumes `set_direct_map_invalid_noflush()` successfully unmaps memory from the linear map if it returns 0. However, on arm64 with `rodata_full` disabled, the function is a silent no-op (returns 0 without modifying PTEs).
- [High] For static VPR allocations without page-backing, `dma_map_sgtable()` is unconditionally called with a NULL page pointer, which will generate a bogus DMA address and corrupt the mapping.
- [High] Memory allocated with `kvmalloc_array()` is incorrectly freed with `kfree()`, which will cause a kernel panic if the allocation fell back to vmalloc.
- [Medium] The `vpr->active` bitmap leaks on the error path if `dma_heap_add()` fails.
--
commit 41cac70cac0869723195f2732d0c1395995f6880
Author: Thierry Reding <treding@nvidia.com>
arm64: tegra: Hook up VPR to host1x
The host1x needs access to the VPR region, so make sure to reference it
via the memory-region property.
> diff --git a/arch/arm64/boot/dts/nvidia/tegra234.dtsi b/arch/arm64/boot/dts/nvidia/tegra234.dtsi
> index 6c4739efc8a5d..c6a5ced069e79 100644
> --- a/arch/arm64/boot/dts/nvidia/tegra234.dtsi
> +++ b/arch/arm64/boot/dts/nvidia/tegra234.dtsi
> @@ -4479,6 +4479,9 @@ vic@15340000 {
> interconnect-names = "dma-mem", "write";
> iommus = <&smmu_niso1 TEGRA234_SID_VIC>;
> dma-coherent;
> +
> + memory-region = <&vpr>;
> + memory-region-names = "protected";
[Severity: High]
Does hooking up the VPR driver here expose an issue where
set_direct_map_invalid_noflush() is assumed to invalidate memory, but silently
fails on arm64?
In drivers/dma-buf/heaps/tegra-vpr.c:tegra_vpr_chunk_activate():
err = set_direct_map_invalid_noflush(chunk->start_page,
chunk->num_pages);
if (err)
return err;
On arm64, if rodata_full is disabled, can_set_direct_map() returns false,
causing set_direct_map_invalid_noflush() to return 0 without actually
modifying PTEs. Since this returns 0, the driver assumes success and continues.
If the CPU speculatively accesses memory that is supposed to be protected by
the VPR, could the hardware memory controller block the access and fault?
[Severity: High]
Does enabling VPR also trigger an issue where dma_map_sgtable() overwrites
manually crafted SG entries containing NULL page pointers?
In drivers/dma-buf/heaps/tegra-vpr.c:tegra_vpr_map_dma_buf():
err = dma_map_sgtable(attachment->dev, sgt, direction,
DMA_ATTR_SKIP_CPU_SYNC);
For static VPR allocations without page-backing, the driver creates an SG table
and explicitly sets sg_set_page() to NULL in tegra_vpr_attach(), manually
populating sg_dma_address.
However, the unconditional call to dma_map_sgtable() will iterate over the SG
table, extract the physical address via sg_page() (which resolves to PA 0),
and map it, overwriting the driver's manually populated sg_dma_address.
Can this corrupt the DMA mapping and potentially cause an IOMMU fault?
[Severity: High]
Is it safe to free memory allocated with kvmalloc_array() using kfree()?
In drivers/dma-buf/heaps/tegra-vpr.c:tegra_vpr_buffer_allocate():
buffer->pages = kvmalloc_array(buffer->num_pages,
sizeof(*buffer->pages),
GFP_KERNEL);
...
err = tegra_vpr_activate_chunks(vpr, buffer);
if (err < 0) {
kfree(buffer->pages);
goto free;
}
And also in tegra_vpr_buffer_release():
bitmap_clear(vpr->bitmap, buffer->pageno, buffer->num_pages);
list_del(&buffer->list);
kfree(buffer->pages);
kfree(buffer);
If the kvmalloc_array() allocation falls back to vmalloc(), calling kfree()
on a vmalloc address will trigger a kernel bug. Since video buffers are
typically large, isn't the vmalloc() fallback highly likely?
[Severity: Medium]
Does the vpr->active bitmap leak on the error path if dma_heap_add() fails?
In drivers/dma-buf/heaps/tegra-vpr.c:tegra_vpr_add_heap(), if dma_heap_add()
fails, it jumps to cleanup:
cleanup:
if (vpr->resizable)
tegra_vpr_free_chunks(vpr);
But tegra_vpr_free_chunks() fails to clean up the bitmap allocated in
tegra_vpr_setup_chunks():
vpr->active = bitmap_zalloc(vpr->num_chunks, GFP_KERNEL);
Should there be a corresponding bitmap_free(vpr->active) in
tegra_vpr_free_chunks()?
> };
>
> nvdec@15480000 {
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-tegra-vpr-v6-0-79042cfa8de5@nvidia.com?part=11
next prev parent reply other threads:[~2026-09-04 11:49 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 10:44 [PATCH v6 00/12] dma-buf: heaps: Add support for Tegra VPR Thierry Reding
2026-09-04 10:44 ` [PATCH v6 01/12] dt-bindings: reserved-memory: Document " Thierry Reding
2026-09-04 10:59 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 02/12] dt-bindings: display: tegra: Document memory regions Thierry Reding
2026-09-04 10:56 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 03/12] dt-bindings: gpu: host1x: Document memory-regions for NVDEC Thierry Reding
2026-09-04 11:03 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 04/12] arm64/mm: Export set_direct_map_*_noflush() APIs Thierry Reding
2026-09-04 11:13 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 05/12] bitmap: Add bitmap_allocate() function Thierry Reding
2026-09-04 11:13 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 06/12] of: Export of_node_to_nid() Thierry Reding
2026-09-04 11:21 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 07/12] mm/cma: Introduce cma_alloc_at() API Thierry Reding
2026-09-04 11:22 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 08/12] dma-buf: heaps: Add debugfs support Thierry Reding
2026-09-04 11:34 ` sashiko-bot
2026-09-04 10:45 ` [PATCH v6 09/12] dma-buf: heaps: Add support for Tegra VPR Thierry Reding
2026-09-04 11:38 ` sashiko-bot
2026-09-04 10:45 ` [PATCH v6 10/12] arm64: tegra: Add VPR placeholder node on Tegra234 Thierry Reding
2026-09-04 11:54 ` sashiko-bot
2026-09-04 10:45 ` [PATCH v6 11/12] arm64: tegra: Hook up VPR to host1x Thierry Reding
2026-09-04 11:49 ` sashiko-bot [this message]
2026-09-04 10:45 ` [PATCH v6 12/12] arm64: tegra: Add VPR placeholder node on Tegra264 Thierry Reding
2026-09-04 11:53 ` sashiko-bot
2026-09-04 11:41 ` [PATCH v6 00/12] dma-buf: heaps: Add support for Tegra VPR Will Deacon
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=20260904114936.DAA891F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=thierry.reding@kernel.org \
/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