Expand the MM module documentation on locking and DMA fence signalling. Suggested-by: Alexandre Courbot <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Danilo Krummrich <[email protected]> --- drivers/gpu/nova-core/mm.rs | 25 +++++++++++++++++++++++-- drivers/gpu/nova-core/mm/tlb.rs | 8 ++++---- 2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/nova-core/mm.rs b/drivers/gpu/nova-core/mm.rs index 795939a5c8ab..0818358ab12c 100644 --- a/drivers/gpu/nova-core/mm.rs +++ b/drivers/gpu/nova-core/mm.rs @@ -2,6 +2,27 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. //! Memory management subsystems. +//! +//! # Locking +//! +//! A reclaimable allocation while holding a lock that may be acquired in the DMA +//! fence signalling critical path (such as the PRAMIN or TLB lock) can deadlock: +//! reclaim may wait for a DMA fence whose signalling path needs the same lock. +//! +//! The restriction is transitive: if code holding lock A can block acquiring +//! lock B, and fence signalling needs A, B must not be held across reclaimable +//! allocations on any path, even outside the signalling path (the same applies to +//! every lock in the dependency chain). Otherwise a holder of B can enter reclaim +//! and wait for a fence whose signalling is blocked on A or B. +//! +//! The allocation restriction also applies to work needed to signal a fence that +//! other threads can already wait on, even when no lock is held. If an allocation +//! in that work enters reclaim and waits for the same fence, the work cannot +//! reach the code that signals it. +//! +//! See the DMA-fence +//! [contract](https://docs.kernel.org/driver-api/dma-buf.html#dma-fence-cross-driver-contract) +//! for the full requirements. #![cfg_attr(not(CONFIG_NOVA_CORE_SELFTESTS), expect(dead_code))] @@ -116,8 +137,8 @@ pub(crate) fn buddy(&self) -> &GpuBuddy { /// Runs `f` with exclusive access to the PRAMIN window. /// - /// Do not perform reclaimable allocations in `f`: reclaim may wait for a DMA - /// fence whose signalling path needs the PRAMIN lock, causing a deadlock. + /// Do not perform reclaimable allocations in `f`; see the + /// [MM locking rules](crate::mm#locking). fn with_pramin_locked<R>(&self, f: impl FnOnce(&mut pramin::Pramin<'_>) -> R) -> R { self.with_pramin(|pramin| f(&mut pramin.lock())) } diff --git a/drivers/gpu/nova-core/mm/tlb.rs b/drivers/gpu/nova-core/mm/tlb.rs index cc862e8159a1..fff66dc03549 100644 --- a/drivers/gpu/nova-core/mm/tlb.rs +++ b/drivers/gpu/nova-core/mm/tlb.rs @@ -66,10 +66,10 @@ pub(crate) enum TlbAckMode with TryFrom<Bounded<u32, 2>> { #[pin_data] pub(crate) struct Tlb<'gpu> { bar: Bar0<'gpu>, - /// TLB flush serialization lock: This lock is designed to be acquired during - /// the DMA fence signalling critical path. It should NEVER be held across any - /// reclaimable CPU memory allocations because the memory reclaim path can - /// call `dma_fence_wait()` (when implemented), which would deadlock if lock held. + /// TLB flush serialization lock. + /// + /// Do not hold this lock across reclaimable memory allocations; see the + /// [MM locking rules](crate::mm#locking). #[pin] lock: Mutex<()>, } base-commit: d9da44362d77bcbf1f5bfd2ba1c514e776fdb07c -- 2.56.1
