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=1796211631; b=YEiSgNKEAzlBRpRM41YX8Cyy20qAWlwKJ6PMTni/B15ApIr2JAGYkkvQaKk31enqk/+5 28OnDifSMWjIvTbcDwHBFiJA0Mmr5SSf4oYI+2LsJrvw3QmvLOGvfO0JENPrWDAEMPoDE bUvILa8XxRtGO6D5CrlbzF/MbkJdtSA9BZZ2+ZEZjg7UXIv0Hn4TNVuWHPh/LpPBvasr+ GLMvUb/N/H+sbk7B+auuYtD8NOlOXvxN5UqMTOpKyCOY7bgwVV4H+l7rcfJsDuVvb85fG LRziboUuWpua8Gdw5MVxDVD7QTs+Q3V62upSR0gmPfKryCcOzzutjm03+1AEil1oSsQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796211631; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=SCU/DvMkSxwxIfic3xBnQP84VqPgPVXH8KbJhUsz/5k=; b=jA15oIkHZhVMEhD1euIKAMBIkBx+RVhG7u65W2dYzddUwWyvgsBx7Ygc1E8W/9B00Rky 8r/6HxWLGobdNRgHpMdrQcTeaq0GTBtDz4xd+1vAmiTBNSG+IZdrh3g1LQK4kKTu36l6x Kh4He3XUX1zGMA0lsB0HxHF9Z0w2wC1lEaEuaPpCnvxFOSj9ECYSE/wBpYSUTdGiDz499 n57h02uRNyX6gE6hG3RfO2x+X6pKbEGV8l8+5FNljcgiSRVGxHEJDUlEB/LsUNabX5Yml +8Y6LjxCyeDH92g6xGMlMftFf0NkKYCbwDmPexKhofYWrMZxJIKAFB+wRr2+okZDTaw== 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=Cc9r09wm; 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 B086B606A322; Wed, 2 Dec 2026 11:40:31 +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=Cc9r09wm Received: by smtp.kernel.org (Postfix) with ESMTPSA id A303C1F0089C; Wed, 2 Dec 2026 11:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796211631; bh=SCU/DvMkSxwxIfic3xBnQP84VqPgPVXH8KbJhUsz/5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Cc9r09wmn25YYG6n9qUAeiwYuQ15qqmxtC1egtg2rh6CYvcodu8s+I+vLXI1Oid2a s54cIAHvGl5rHHGP3N5nxLMBeI+uH4kM5g17NofgDZvNg1Nbg4vQnOtFe8SdLvcN6Y 2QrCxvOxRiz+/xYzFE2pe7MlmaSeTlpZ5hAQmSHOgwQYjPjQaIP4KTufn5jGJ04z9p 7uzvWqDCrAKCv+kT8+FVY2QHzze7SOEWxIU2C6Sa/3Cg/fQLMcTR+BVMK0W26DyNmg +SHRyl76/vsUurEMrjX37DMNtNfNfzuPou+LDUUOnzclAKXtb49xsUk/GgIUixr0xu wTVvjxk+lcLrQ== From: Philipp Stanner To: Miguel Ojeda , Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?UTF-8?q?Onur=20=C3=96zkan?= , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= , Philipp Stanner , Matthew Brost , David Airlie , Simona Vetter , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Lyude Paul , "Joel Fernandes (NVIDIA)" , Boris Brezillon , Yuvan Shen Cc: rust-for-linux@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, rcu@vger.kernel.org Subject: [PATCH v3 4/9] rust: DmaFence: Don't drop on signal Date: Wed, 2 Dec 2026 12:39:10 +0100 Message-ID: <20261202113914.1660411-6-phasta@kernel.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261202113914.1660411-2-phasta@kernel.org> References: <20261202113914.1660411-2-phasta@kernel.org> X-Mailing-List: linux-media@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 The original design for DmaFence intended to comply as strictly as possible with the "dma_fence contract", which, according to some, says that a fence must only be signaled once. Thus, the implementation was made so that a DriverFence drops on signal. While extending JobQueue's capabilities, it was discovered that this characteristic causes - unnecessary - trouble: fence-data must be dropped in an RCU-deferred manner because the C backend demands that. However, fences are often signaled in atomic context (e.g., interrupt handler) where you don't want to drop, but signal as quickly as possible. Actually, there is no real hard reason to enforce that a fence can only get signaled once, because the C backend is robust against multiple signal attempts. What is decisive is that a) all fences signal and b) they only drop no earlier than 1 RCU grace period after signaling. Don't drop a DriverFence on signal(). Signed-off-by: Philipp Stanner --- rust/kernel/dma_buf/dma_fence.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs index 897308f60dd3..c04b68fe67fe 100644 --- a/rust/kernel/dma_buf/dma_fence.rs +++ b/rust/kernel/dma_buf/dma_fence.rs @@ -820,7 +820,7 @@ pub fn as_fence(&self) -> &Fence { } /// Signal the fence. This will invoke all registered callbacks. - pub fn signal(self, res: Result) { + pub fn signal(&self, res: Result) { let fence = self.as_fence().lock(); // SAFETY: `fence` is valid because `self` is valid. The lock must be @@ -831,14 +831,15 @@ pub fn signal(self, res: Result) { // must not have been signaled yet, which we check directly above. unsafe { bindings::dma_fence_set_error(fence.as_raw(), err.to_errno()) }; } + + // SAFETY: `self.data` is valid because `self` is valid. + let fctx = unsafe { self.data.as_ref().fctx }; + let _ = fctx.nr_of_unsignaled_fences.fetch_sub(1, Relaxed); + // SAFETY: `fence` is valid because `self` is valid. The lock must // be held, which we acquired above. unsafe { bindings::dma_fence_signal_locked(fence.as_raw()) }; } - - // SAFETY: `self.data` is valid because `self` is valid. - let fctx = unsafe { self.data.as_ref().fctx }; - let _ = fctx.nr_of_unsignaled_fences.fetch_sub(1, Relaxed); } } -- 2.56.0