From: Alexandre Courbot <acourbot@nvidia.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Onur Özkan" <work@onurozkan.dev>
Cc: John Hubbard <jhubbard@nvidia.com>,
Alistair Popple <apopple@nvidia.com>,
Timur Tabi <ttabi@nvidia.com>,
Eliot Courtney <ecourtney@nvidia.com>,
Zhi Wang <zhiw@nvidia.com>,
nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev,
rust-for-linux@vger.kernel.org,
Alexandre Courbot <acourbot@nvidia.com>
Subject: [PATCH v2 3/3] gpu: nova-core: falcon: use I/O projection to check transfer bounds
Date: Wed, 05 Aug 2026 14:01:47 +0900 [thread overview]
Message-ID: <20260805-falcon-dma-projections-v2-3-4cc9f3f13ee9@nvidia.com> (raw)
In-Reply-To: <20260805-falcon-dma-projections-v2-0-4cc9f3f13ee9@nvidia.com>
The DMA transfer routine was computing the start of the DMA area by
taking the address of the coherent allocation, and then adding the
transfer's start offset. It then checked manually that the upper bound
was valid.
Convert this to an I/O projection of the same region, which returns
`ERANGE` if the passed range does not fit within the coherent
allocation. This removes the need to perform arithmetic on DMA addresses
and to explicitly check for the bounds' validity.
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
---
drivers/gpu/nova-core/falcon.rs | 55 +++++++++++++++++------------------------
1 file changed, 23 insertions(+), 32 deletions(-)
diff --git a/drivers/gpu/nova-core/falcon.rs b/drivers/gpu/nova-core/falcon.rs
index a281d316ebfd..65cb12d26e2b 100644
--- a/drivers/gpu/nova-core/falcon.rs
+++ b/drivers/gpu/nova-core/falcon.rs
@@ -12,6 +12,7 @@
DmaAddress, //
},
io::{
+ io_project,
poll::read_poll_timeout,
register::{
RegisterBase,
@@ -511,20 +512,31 @@ fn dma_wr(
) -> Result {
const DMA_LEN: u32 = num::usize_into_u32::<{ MEM_BLOCK_ALIGNMENT }>();
+ // DMA transfers can only be done in units of 256 bytes. Compute how many such transfers we
+ // need to perform.
+ let num_transfers = load_offsets.len.div_ceil(DMA_LEN);
+
// For IMEM, we want to use the start offset as a virtual address tag for each page, since
// code addresses in the firmware (and the boot vector) are virtual.
//
- // For DMEM we can fold the start offset into the DMA address.
+ // For DMEM, the start offset is folded into the DMA address.
let (src_start, dma_start) = match target_mem {
- FalconMem::ImemSecure | FalconMem::ImemNonSecure => {
- (load_offsets.src_start, dma_obj.dma_address())
- }
- FalconMem::Dmem => (
- 0,
- dma_obj.dma_address() + DmaAddress::from(load_offsets.src_start),
- ),
+ FalconMem::ImemSecure | FalconMem::ImemNonSecure => (load_offsets.src_start, 0),
+ FalconMem::Dmem => (0, usize::from_safe_cast(load_offsets.src_start)),
};
- if dma_start % DmaAddress::from(DMA_LEN) > 0 {
+
+ let dma_address = {
+ // Upper limit of transfer is `(num_transfers * DMA_LEN) + load_offsets.src_start`.
+ let dma_end = num_transfers
+ .checked_mul(DMA_LEN)
+ .and_then(|size| size.checked_add(load_offsets.src_start))
+ .map(usize::from_safe_cast)
+ .ok_or(EOVERFLOW)?;
+
+ io_project!(dma_obj, [try: dma_start..dma_end]).dma_address()
+ };
+
+ if dma_address % DmaAddress::from(DMA_LEN) > 0 {
dev_err!(
self.dev,
"DMA transfer start addresses must be a multiple of {}\n",
@@ -533,27 +545,6 @@ fn dma_wr(
return Err(EINVAL);
}
- // DMA transfers can only be done in units of 256 bytes. Compute how many such transfers we
- // need to perform.
- let num_transfers = load_offsets.len.div_ceil(DMA_LEN);
-
- // Check that the area we are about to transfer is within the bounds of the DMA object.
- // Upper limit of transfer is `(num_transfers * DMA_LEN) + load_offsets.src_start`.
- match num_transfers
- .checked_mul(DMA_LEN)
- .and_then(|size| size.checked_add(load_offsets.src_start))
- {
- None => {
- dev_err!(self.dev, "DMA transfer length overflow\n");
- return Err(EOVERFLOW);
- }
- Some(upper_bound) if usize::from_safe_cast(upper_bound) > dma_obj.size() => {
- dev_err!(self.dev, "DMA transfer goes beyond range of DMA object\n");
- return Err(EINVAL);
- }
- Some(_) => (),
- };
-
// Set up the base source DMA address.
self.bar.write(
@@ -561,12 +552,12 @@ fn dma_wr(
regs::NV_PFALCON_FALCON_DMATRFBASE::zeroed().with_base(
// CAST: `as u32` is used on purpose since we do want to strip the upper bits,
// which will be written to `NV_PFALCON_FALCON_DMATRFBASE1`.
- (dma_start >> 8) as u32,
+ (dma_address >> 8) as u32,
),
);
self.bar.write(
WithBase::of::<E>(),
- regs::NV_PFALCON_FALCON_DMATRFBASE1::zeroed().try_with_base(dma_start >> 40)?,
+ regs::NV_PFALCON_FALCON_DMATRFBASE1::zeroed().try_with_base(dma_address >> 40)?,
);
let cmd = regs::NV_PFALCON_FALCON_DMATRFCMD::zeroed()
--
2.55.0
next prev parent reply other threads:[~2026-08-05 5:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-05 5:01 [PATCH v2 0/3] gpu: nova-core: falcon: use I/O projections for DMA transfers Alexandre Courbot
2026-08-05 5:01 ` [PATCH v2 1/3] gpu: nova-core: falcon: remove unnecessary check Alexandre Courbot
2026-08-05 7:02 ` Ethan Plant
2026-08-05 5:01 ` [PATCH v2 2/3] rust: dma: rename dma_handle to dma_address Alexandre Courbot
2026-08-05 11:32 ` Robin Murphy
2026-08-05 20:39 ` Danilo Krummrich
2026-08-07 13:04 ` Gary Guo
2026-08-12 22:32 ` Danilo Krummrich
2026-08-12 23:51 ` Gary Guo
2026-08-06 21:16 ` Danilo Krummrich
2026-08-05 5:01 ` Alexandre Courbot [this message]
2026-08-06 21:25 ` [PATCH v2 0/3] gpu: nova-core: falcon: use I/O projections for DMA transfers Danilo Krummrich
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=20260805-falcon-dma-projections-v2-3-4cc9f3f13ee9@nvidia.com \
--to=acourbot@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=abdiel.janulgue@gmail.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=nova-gpu@lists.linux.dev \
--cc=ojeda@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=work@onurozkan.dev \
--cc=zhiw@nvidia.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
all inboxes | Powered by JetHome®