From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796334627; b=aiH3LkYaLcDZRpIBChqWuiNioKrbNsfi+8p6h1hyp7tk1qw7dZ3ptzTGnhk0N6m2VIY1 OTWkllftGtv/YQLub7Hr+sQ6dG7e1V6z14OvzRJtc2MgKCRHI9Wik2v6L17LdGfe9O9Da 7DrjRRnJpouLPPbt+fFkKgPf9+V0wKubj7FrQuU4JKwd9UFU1sguHnUYo7gHsqhQmi6TB Mf6V9x9AzNPAvFEh91NIP6txIM6L2UEJB7mPl28YBiBzOm1LOwhYFQyipLY0I7PuSX+D5 rnU/a4wbbyINdY1E6GtJLVYho5897C7DrDyB1dUXTZ0oMblzbL6pa8QiR4wCTydaPHQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796334627; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=rOBWyex052XAYeThI6k9YmqCmiD2mRw9OAvRvBP4MPI=; b=o6TV2lLCJJXsbMuej9V5Gof8Zrp2Zk0PxsIzjs51TZqkfJldheGSVnd3NY7NvQW1wfJi AmKcNuxU7syGoXD+fqbECW8fM0+WFvIdfbJO2zQcWmiheWVaxjikb03XKpgsP/noN/2Kn FHxkfmCquu+RszpFeB/HY3jmdpox87y8hAiLE91hrsSZFsTYDcLDqHy+sQibo2dWaZ8+J VWFlv5MDUYwr5/xTORbehMFwfphm8bRmaOgqgS+lJORDf4im5ZGQyjEu6Z9xmZ/tnmOGk OCY4jp9n9nbAH45gUSzwOiyFph1u1VXWWqVOh/A7+WvBioQ3It3pp/uyIACT7GwnWaQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dwL9huN+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87E56606A322; Thu, 3 Dec 2026 21:50:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dwL9huN+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id E160C1F000C2; Thu, 3 Dec 2026 21:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796334627; bh=rOBWyex052XAYeThI6k9YmqCmiD2mRw9OAvRvBP4MPI=; h=From:To:Cc:Subject:Date; b=dwL9huN+9ZTV6zodOdbD6KJE80YtfCbIf3ptU0CyO8xRyRUtkffh3b5D2Ds4lq4NS 05SFQh8c7tbgxS82Jgj384NhQzvdAFtvaIY5XdPmqzW6hK/yc1b1pwHjbDuuJquhvU 0hnwZjYLhCenefX2gmndMa3QD8Rk37zK3FbCcveQtz3RInt5qISB/Sgr03MrCIy5YE VjdZ5h/OaAo2pvY4uNGjUIGlnsScCJVgKnSUKDNKhnq1N5WFTyKdMl81UXftDsin6u 2YEVqesYyx3xMtSqhSP9lNeS1jRd/SXhhwjin8Zmy79cfJtXhb9+43/4RgXb+iCbWq UQEhnpEZ+TKXA== From: Danilo Krummrich To: dakr@kernel.org, acourbot@nvidia.com Cc: nova-gpu@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] gpu: nova-core: mm: document fence signalling lock dependencies Date: Thu, 3 Dec 2026 22:50:02 +0100 Message-ID: <20261203215019.2870117-1-dakr@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Expand the MM module documentation on locking and DMA fence signalling. Suggested-by: Alexandre Courbot Link: https://lore.kernel.org/all/DN6H2GAT9F0Y.2ZZRVU8FZCYZB@nvidia.com/ Signed-off-by: Danilo Krummrich --- 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(&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> { #[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