linux/drivers/gpu/nova-core
Danilo Krummrich 0073a17b46 gpu: nova-core: gsp: fix UB in DmaGspMem pointer accessors
The DmaGspMem pointer accessor methods (gsp_write_ptr, gsp_read_ptr,
cpu_read_ptr, cpu_write_ptr, advance_cpu_read_ptr,
advance_cpu_write_ptr) dereference a raw pointer to DMA memory, creating
an intermediate reference before calling volatile read/write methods.

This is undefined behavior since DMA memory can be concurrently modified
by the device.

Fix this by moving the implementations into a gsp_mem module in fw.rs
that uses the dma_read!() / dma_write!() macros, making the original
methods on DmaGspMem thin forwarding wrappers.

An alternative approach would have been to wrap the shared memory in
Opaque, but that would have required even more unsafe code.

Since the gsp_mem module lives in fw.rs (to access firmware-specific
binding field names), GspMem, Msgq and their relevant fields are
temporarily widened to pub(super). This will be reverted once IoView
projections are available.

Cc: Gary Guo <gary@garyguo.net>
Closes: https://lore.kernel.org/nouveau/DGUT14ILG35P.1UMNRKU93JUM1@kernel.org/
Fixes: 75f6b1de81 ("gpu: nova-core: gsp: Add GSP command queue bindings and handling")
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://patch.msgid.link/20260309225408.27714-1-dakr@kernel.org
[ Use pub(super) where possible; replace bitwise-and with modulo
  operator analogous to [1]. - Danilo ]
Link: https://lore.kernel.org/all/20260129-nova-core-cmdq1-v3-1-2ede85493a27@nvidia.com/ [1]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2026-03-11 16:24:15 +01:00
..
falcon gpu: nova-core: add Falcon HAL method load_method() 2026-01-24 10:48:59 +09:00
fb gpu: nova-core: justify remaining uses of `as` 2025-11-08 08:22:51 +09:00
firmware drm for 7.0-rc1 2026-02-11 12:55:44 -08:00
gsp gpu: nova-core: gsp: fix UB in DmaGspMem pointer accessors 2026-03-11 16:24:15 +01:00
regs rust: io: separate generic I/O helpers from MMIO implementation 2026-01-23 21:20:11 +01:00
Kconfig gpu: nova-core: select RUST_FW_LOADER_ABSTRACTIONS 2025-12-16 21:56:44 +09:00
Makefile
bitfield.rs gpu: nova-core: bitfield: remove BitOr implementation 2025-10-25 13:16:31 +09:00
dma.rs gpu: nova-core: Simplify `DmaObject::from_data` in nova-core/dma.rs 2025-11-07 23:10:44 +09:00
driver.rs gpu: nova: replace `kernel::c_str!` with C-Strings 2025-12-22 17:56:04 +01:00
falcon.rs gpu: nova-core: add Falcon HAL method load_method() 2026-01-24 10:48:59 +09:00
fb.rs gpu: nova-core: add missing newlines to several print strings 2026-01-12 14:44:06 +01:00
firmware.rs gpu: nova-core: add FalconUCodeDescV2 support 2026-01-24 10:48:59 +09:00
gfw.rs gpu: nova-core: apply the one "use" item per line policy 2025-11-07 23:10:44 +09:00
gpu.rs gpu: nova-core: add missing newlines to several print strings 2026-01-12 14:44:06 +01:00
gsp.rs gpu: nova-core: fix stack overflow in GSP memory allocation 2026-03-10 18:29:14 +01:00
nova_core.rs gpu: nova-core: use CStr::from_bytes_until_nul() and remove util.rs 2026-01-07 19:36:11 +01:00
num.rs gpu: nova-core: num: add functions to safely convert a const value to a smaller type 2025-11-14 20:25:15 +09:00
regs.rs gpu: nova-core: add NV_PFALCON_FALCON_ENGINE::reset_engine() 2026-01-24 08:45:13 +09:00
sbuffer.rs gpu: nova-core: remove imports available via prelude 2026-01-30 02:42:42 +01:00
vbios.rs Driver core changes for 7.0-rc1 2026-02-11 17:43:59 -08:00