The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Daniel Almeida" <daniel.almeida@collabora.com>
Cc: "Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Philipp Stanner" <phasta@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] rust: dma_buf: dma_fence: add SignallingSection
Date: Fri, 27 Nov 2026 22:06:50 +0100	[thread overview]
Message-ID: <DN6ASNF6NW8Q.13GAZAC9LHRN3@kernel.org> (raw)
In-Reply-To: <20261127-dma-fence-signalling-v1-1-c44e8f4910ca@collabora.com>

On Fri Nov 27, 2026 at 7:30 PM CET, Daniel Almeida wrote:
> dma_fence_begin_signalling() and dma_fence_end_signalling() mark the
> code that the completion of a dma-fence depends on, so that lockdep can
> check it against the dma-fence rules. However, up until now, it was not
> possible to use the signalling tokens from Rust.
>
> Thus, add SignallingSection, a guard that begins a section when it is
> created and ends it when it is dropped. Code on the signalling path can
> take a &SignallingSection to require that its caller opened one.
>
> Use it in the DriverFence example, which has a TODO for it.
>
> A later patch in this series makes DriverFence::signal() require one.
>
> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
> ---
>  rust/kernel/dma_buf/dma_fence.rs | 70 +++++++++++++++++++++++++++++++++++++++-
>  rust/kernel/dma_buf/mod.rs       |  3 +-
>  2 files changed, 71 insertions(+), 2 deletions(-)
>
> diff --git a/rust/kernel/dma_buf/dma_fence.rs b/rust/kernel/dma_buf/dma_fence.rs
> index a1d851656562..7ee87935d3be 100644
> --- a/rust/kernel/dma_buf/dma_fence.rs
> +++ b/rust/kernel/dma_buf/dma_fence.rs
> @@ -17,6 +17,7 @@
>      error::to_result,
>      prelude::*,
>      types::ForeignOwnable,
> +    types::NotThreadSafe,
>      types::Opaque, //
>  };
>  
> @@ -589,6 +590,71 @@ unsafe fn dec_ref(ptr: NonNull<Self>) {
>      }
>  }
>  
> +/// A dma-fence signalling critical section on the current task.
> +///
> +/// All code needed to signal a [`DriverFence`] must run in such a section,

Hm...this makes an annotation policy sound like an unconditional prerequisite
for signalling any DriverFence.

It is clarified below with "Without `CONFIG_LOCKDEP`, the section has no
effect.", but I'd probably first explain the annotation mechanism and then
explain what drivers are expected to do.

> +/// from the point where its [`Fence`] becomes visible to other threads up to
> +/// the point where it is signalled. With `CONFIG_PROVE_LOCKING`, the section

I'd add a bit more detail on what cases we need to protect once the fence
becomes visible to other threads or is published.

Especially the more subtle parts, such as indirect dependencies on memory
reclaim.

> +/// is a [DMA Fence Signalling Annotation], which validates that code against
> +/// the [DMA Fence Cross-Driver Contract]. Without `CONFIG_LOCKDEP`, the
> +/// section has no effect.
> +///
> +/// A function that is part of the signalling path can take a
> +/// `&SignallingSection` to require that its caller opened one. Sections nest,
> +/// and only the outermost one is annotated.
> +///
> +/// [DMA Fence Signalling Annotation]: https://docs.kernel.org/driver-api/dma-buf.html#dma-fence-signalling-annotations
> +/// [DMA Fence Cross-Driver Contract]: https://docs.kernel.org/driver-api/dma-buf.html#dma-fence-cross-driver-contract
> +///
> +/// # Examples
> +///
> +/// ```
> +/// use kernel::dma_buf::SignallingSection;
> +///
> +/// // Code on the signalling path takes a section to require that its caller
> +/// // opened one.
> +/// fn on_signalling_path(_section: &SignallingSection) {}
> +///
> +/// let section = SignallingSection::begin();
> +/// on_signalling_path(&section);
> +/// ```

Hm...I'm not sure the example is overly useful. What about an example that shows
how it catches a violation? I'm usually not a fan of this, but in this case it
kinda makes sense.

> @@ -704,9 +771,10 @@ struct DriverFenceData<'a, T: Send + Sync + FenceContextOps> {
>  /// let cb_reg = unsafe { FenceCallbackRegistration::new(&waiting_fence, cb_data) };
>  /// let cb_reg = KBox::pin_init(cb_reg, GFP_KERNEL)?;
>  ///
> -/// // TODO signalling guards
> +/// let section = SignallingSection::begin();
>  /// assert_eq!(waiting_fence.is_signaled(), false);
>  /// fence.signal(Ok(()));
> +/// drop(section);
>  /// assert_eq!(waiting_fence.is_signaled(), true);

I think that's a separate patch, or actually the subsequent patch is a natural
fit.

  reply	other threads:[~2026-11-27 21:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 18:30 [PATCH 0/2] rust: dma_buf: add dma-fence signalling sections Daniel Almeida
2026-11-27 18:30 ` [PATCH 1/2] rust: dma_buf: dma_fence: add SignallingSection Daniel Almeida
2026-11-27 21:06   ` Danilo Krummrich [this message]
2026-11-27 18:30 ` [PATCH 2/2] rust: dma_buf: dma_fence: require a SignallingSection in signal() Daniel Almeida
2026-11-27 18:59 ` [PATCH 0/2] rust: dma_buf: add dma-fence signalling sections Gary Guo
2026-11-27 20:11   ` Danilo Krummrich
2026-11-27 20:26     ` Danilo Krummrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DN6ASNF6NW8Q.13GAZAC9LHRN3@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=christian.koenig@amd.com \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=phasta@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox