Skip to content

Commit 0e0ffbc

Browse files
GnurouDanilo Krummrich
authored andcommitted
gpu: nova-core: falcon: pad firmware DMA object size to required block alignment
Commit a888315 ("gpu: nova-core: falcon: use dma::Coherent") dropped the nova-local `DmaObject` device memory type for the kernel-global `Coherent` one. This switch had a side-effect: `DmaObject` always aligned the requested size to `PAGE_SIZE`, and also reported that adjusted size when queried. `Coherent`, on the other hand, does page-align allocation sizes but only allows CPU access on the exact size provided by the caller. This change runs into a limitation of falcon DMA copies, namely that DMA accesses are done on blocks of exactly 256 bytes. If the provided data does not have a length that is a multiple of 256, `dma_wr` returns an error. It was expected that all firmwares would present the proper adjusted size, but this is not the case at least on my GA107: NovaCore 0000:08:00.0: DMA transfer goes beyond range of DMA object NovaCore 0000:08:00.0: Failed to load FWSEC firmware: EINVAL NovaCore 0000:08:00.0: probe with driver NovaCore failed with error -22 Fix this by padding the `Coherent`'s size to `MEM_BLOCK_ALIGNMENT` (i.e. 256) when allocating it and filling it with zeroes, before copying the firmware on top of it. Fixes: a888315 ("gpu: nova-core: falcon: use dma::Coherent") Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://patch.msgid.link/20260405-falcon-dma-roundup-v2-1-4af5b2ff9c16@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent 8e6c347 commit 0e0ffbc

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

drivers/gpu/nova-core/falcon.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use kernel::{
1111
},
1212
dma::{
1313
Coherent,
14+
CoherentBox,
1415
DmaAddress,
1516
DmaMask, //
1617
},
@@ -613,8 +614,24 @@ impl<E: FalconEngine + 'static> Falcon<E> {
613614
bar: &Bar0,
614615
fw: &F,
615616
) -> Result {
616-
// Create DMA object with firmware content as the source of the DMA engine.
617-
let dma_obj = Coherent::from_slice(dev, fw.as_slice(), GFP_KERNEL)?;
617+
// DMA object with firmware content as the source of the DMA engine.
618+
let dma_obj = {
619+
let fw_slice = fw.as_slice();
620+
621+
// DMA copies are done in chunks of `MEM_BLOCK_ALIGNMENT`, so pad the length
622+
// accordingly and fill with `0`.
623+
let mut dma_obj = CoherentBox::zeroed_slice(
624+
dev,
625+
fw_slice.len().next_multiple_of(MEM_BLOCK_ALIGNMENT),
626+
GFP_KERNEL,
627+
)?;
628+
629+
// PANIC: `dma_obj` has been created with a length equal to or larger than
630+
// `fw_slice.len()`, so the range `..fw_slice.len()` is valid.
631+
dma_obj[..fw_slice.len()].copy_from_slice(fw_slice);
632+
633+
dma_obj.into()
634+
};
618635

619636
self.dma_reset(bar);
620637
bar.update(regs::NV_PFALCON_FBIF_TRANSCFG::of::<E>().at(0), |v| {

0 commit comments

Comments
 (0)