mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies
@ 2026-12-03 21:50 Danilo Krummrich
  2026-12-03 21:50 ` [PATCH 2/2] gpu: nova-core: mm: move TLB register access behind the mutex Danilo Krummrich
  2026-12-03 22:13 ` [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies Gary Guo
  0 siblings, 2 replies; 4+ messages in thread
From: Danilo Krummrich @ 2026-12-03 21:50 UTC (permalink / raw)
  To: dakr, acourbot; +Cc: nova-gpu, dri-devel, linux-kernel

Expand the MM module documentation on locking and DMA fence signalling.

Suggested-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://lore.kernel.org/all/DN6H2GAT9F0Y.2ZZRVU8FZCYZB@nvidia.com/
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-03 22:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 21:50 [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies Danilo Krummrich
2026-12-03 21:50 ` [PATCH 2/2] gpu: nova-core: mm: move TLB register access behind the mutex Danilo Krummrich
2026-12-03 22:13   ` Gary Guo
2026-12-03 22:13 ` [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies Gary Guo

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®