Skip to contentSkip to conversation

rust / dma_buf: Add abstractions for dma_fence

PATCH Superseded Philipp Stanner 4 participants 7 messages Aug 12 – Sep 4

Subsystems (4)

v10 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Philipp Stanner

author maintainer
#0 lore raw

v10 cover rust / dma_buf: Add abstractions for dma_fence

Changes since v9:
- Rebase on rust-next, since Miguel has merged our prerequisites.
- Add R-b from Daniel.
All from Gary:
- Use an Atomic<usize> for nr_of_unsignaled_fences.
- Comment improvement / formatting.
- *const instead of *mut raw pointer.
- Make small public functions inline.
- Rename "called" callback to "on_signal".
- Improve the internal helper lock FenceGuard.
- Add needs_drop fastpath check in DriverFence::drop().

Changes since v8:
- Improve function naming. (Daniel)
- Panic in case of forgotten fences. (Alice)
(reason being that this cannot happen with the intended JobQueue design, it would be a fatal bug anyways and we can easily fix this up)
- Improve spelling and grammar. (Daniel)
- Add Daniel's Tested-by
- Improve Copyright notice to SPDX. (Daniel)

Changes since v7:
- Remove the forgotten-fences-tracking from FenceContext. Merely warn in this unlikely case, using an atomic integer.
- Be more verbose in warnings about what exactly the problem is.

Changes since v6:
- Add Timur's error code patch (just so that the series builds. Merge however you prefer). (Timur)
- Replace XArray with list, remove XArray patch.
- Detail the issue with core::mem::forget() in the commit message.
- Some code formatting etc.

Changes since v5:
- Because Rust can "forget" DriverFences, it could bypass the lifetime ensuring that DriverFences don't outlive a FenceContext. Mitigate this by having the FenceContext keep track of unsignaled fences. (Danilo)
- To support the point above, add support for memory reservations to XArray.
- To support the point above, have FenceContext::alloc_fence() increment the sequence number. This is necessary for the xarray index. It might become critical with fence seqno holes.. please review.
- Remove acronyms in declarations. (Daniel)
- Allow for providing initial seqno in FenceContext::new(). (Daniel)
- Flesh out documentation about DriverFence <-> Fence. (Daniel)
- Flesh out documentation about weirdness in C backend. (Daniel)
- Add new, purely internal locking helper / guard for dma_fence.
- Use the kernel atomics (Gary).
- Curse angrily at my computer.

Changes since v4:
- Fix an uninitialized memory bug for FenceCbRegistration with ManuallyDrop.
- Return FenceCtx as impl PinInit
- Make FenceCtx return an impl PinInit<T, Error> (Danilo)
- Reformat some comments

Changes since v3:
- Add a FIXME for an encountered Rust compiler bug. (Gary)
- Add new Rust files also to DRM drivers & common infrastructure MAINTAINERS file. (Danilo)
- Reposition ECANCELED error code. (Miguel)
- Replace refcounted FenceCtx in DriverFenceData with a reference plus life time. (Boris)
- Re-add rcu_barrier() patch, since we now can use it for dropping the fence context. (Danilo)
- Add forgotten R-b from Alice, and Acks for MAINTAINERS from Christian and Sumit.

Changes since v2:
- Don't drop DriverFenceData as a whole, but only the members we really want to drop. Gives more robustness. (Gary).
- Break apart large pin_init_from_closure(). (Danilo, Onur)
- Remove rcu_barrier() and synchronize_rcu() from FenceCtx::drop(). FenceCtx might drop in atomic context, where you must not perform those operations. With the current way C dma_fence is designed, the driver must wait for a grace period manually until it unloads.
- Repair the DriverFenceBorrow implementation, properly injecting a life time into it. (Danilo)
- Fix memory layout bug for rcu_head. (Onur)
- Drop RCU patches, since this series doesn't need them anymore.

Changes since v1:
- Remove unnecessary mutable references (Alice)
- Split up unsafe comments where possible (Danilo)
- Remove PhantomData + implement FenceCtx ops trait (Boris)
- Consistently call FenceCtx generic data T. FenceDataType is derived from that. (Boris)
- Add abstractions for call_rcu() and synchronize_rcu() (Danilo)
- Add ECANCELED error code in Rust (Alice)
- Remove the rcu_barrier() from FenceCtx::drop() – because we now use call_rcu(), there can be no UAF access to the FenceCtx anymore. In any case, it is illegal to use either call_rcu() or synchronize_rcu() in FenceCtx::drop(), because our new drop_driver_fence_data() can run in atomic context and might put the last fence_ctx reference.
So we now only have to guard against module unload, which it seems either the driver or Rust driver-core / module unload infrastructure must solve.
- Minor formatting etc. changes
- Add C helpers to MAINTAINERS. (Danilo)
- Ensure that Fence::is_signaled() is fully synchronized, i.e., all callbacks really have run. See [1] and [2]. (Myself, Christian König)

Changes since the RFCs:
- Include support for ForeignOwnable for ARef, so that a Fence can be stuffed into an XArray et al. (Code by Danilo)
- Implement ForeignOwnable (with new borrow type) for DriverFence, so that it can be stuffed into an XArray.
- Include the rcu::RcuBox data type to defer dropping data with RCU (Cody by Alice)
- Port DmaFence to RcuBox to make UAF bugs through later, new dma_fence callbacks (backend_ops) impossible.
- Force users to pass their fence data in an RcuBox (or have it not need drop()) through a Sealed trait.
- Document the rules for the user's DriverFence::data's drop implementation very clearly (deadlock danger).
- rustfmt, Clippy.
- Various style suggestions, safety comments, etc. (Önur)
- Add __rust_helper prefix to helper functions. (Önur)

Changes in RFC v3:
- Omit JobQueue patches for now
- Completely redesign the memory layout: Instead of a Fence refcounting a DriverFence, both now live in the same allocation to allow for future support the dma_fence backend_ops callbacks which need to do container_of. (mostly Boris's feedback)
- Allow for pre-allocating fences to avoid deadlocks when submitting jobs to a GPU. (Boris)
- Simultaneously, allow for pre-preparing fence callback objects, so the driver can allocate them when it sees fit. (code largely stolen and inspired by Daniel).
- Signal fences on drop, ensure synchronization.
- Force users to set an error code when signalling.
- Write more documentation
- A ton of minor other changes.

[1] https://lore.kernel.org/dri-devel/[email protected]/
[2] https://lore.kernel.org/dri-devel/[email protected]/

Alright, so since the last RFCs did not reveal significant design issues, I decided to transition this series to a v1 and hope that we can get it upstream.

This now includes code for more common infrastructure that dma_fence needs, contributed by Danilo and Alice.

---

Old cover letter for RFC:

So, this is the spiritual successor of the first / second RFC [1]. v2 also contained code for drm::JobQueue, but mostly to show how the fence code would be used. JobQueue is under heavy rework right now, so I don't want to bother your eyes with it. The docstring examples should show how Rust fences are supposed to be used, though.

This v3 contains a huge amount of highly valuable feedback from a variety of people, notably Boris, but also from Alice, Gary and Danilo.

There are some TODOs open (a better trait for fence backend_ops and RCU support), but my hope is that this effort is now finally approaching its end.

I would greatly appreciate feedback and especially more information about what might be missing to make this usable, which is obviously where Daniel's and Boris's feedback will be valuable once more.

Please regard this patch just as what it's titled: an RFC, to discuss a bit more and to inform a broader community about what the current state is and where this is heading at.

Many regards,
Philipp

[1] https://lore.kernel.org/rust-for-linux/[email protected]/

Philipp Stanner (2):
rust: Add dma_fence abstractions
MAINTAINERS: Add entry for Rust dma-buf

 MAINTAINERS                      |    5 +
 rust/bindings/bindings_helper.h  |    1 +
 rust/helpers/dma_fence.c         |   48 ++
 rust/helpers/helpers.c           |    1 +
 rust/kernel/dma_buf/dma_fence.rs | 1022 ++++++++++++++++++++++++++++++
 rust/kernel/dma_buf/mod.rs       |   14 +
 rust/kernel/lib.rs               |    1 +
 7 files changed, 1092 insertions(+)
 create mode 100644 rust/helpers/dma_fence.c
 create mode 100644 rust/kernel/dma_buf/dma_fence.rs
 create mode 100644 rust/kernel/dma_buf/mod.rs

base-commit: d8973c47544371613313ecb9a8c3e7b244aa9bbf

Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH v10 1/2 rust: Add dma_fence abstractions

C's dma_fence's are synchronisation primitives that will be needed by all Rust GPU drivers.

The dma_fence framework sets a number of rules, notably:
- fences must only be signaled once
- all fences must be signaled at some point
- fence error codes must only be set before signaling
- every pointer to a fence must be backed by a reference

All those rules are being addressed by these abstractions.

To cleanly decouple fence issuers and consumers, two types are provided:
- DriverFence: the only fence type that can be signaled and that carries driver-specific data.
- Fence: the fence type to be shared with other drivers and / or userspace. The only type callbacks can be registered on. Cannot be signaled.

Hereby, a Fence lives in the same chunk of memory as a DriverFence. Both share the refcount of the underlying C dma_fence. Since this implementation does not provide a custom dma_fence_backend_ops.release() function, the memory is freed by the dma_fence backend once the refcount drops to 0.

To create a DriverFence, the user must first allocate a DriverFenceAllocation, so that the creation of the DriverFence later on can always succeed. Otherwise, deadlocks could occur if fences need to be created in a GPU job submission path.

Synchronization is ensured by the dma_fence backend.

All DriverFence's created through this abstraction must be signaled by the creator with an error code. In case a DriverFence drops without being signaled beforehand, it is signaled with -ECANCELLED as its error and a warning is printed. This allows the Rust abstraction to very cleanly decouple fence issuer and consumer by relying on the decoupling mechanisms in the C backend, which ensures through RCU and the 'signaled' fence-flag that dma_fence_backend_ops functions cannot access the potentially unloaded driver code anymore.

Signalling fences on drop thus grants many advantages. Not signaling fences on drop would risk deadlock and does not grant real advantages:
By definition only the drivers can ensure that a fence always represents the hardware's state correctly.

This implementation models a DmaFenceContext object on which fences are to be created, thereby ensuring correct sequence numbering according to the timeline.

dma_fence supports a variety of callbacks. The mandatory callbacks (get_timeline_name() and get_driver_name()) are implemented in this patch. For convenience, they store those name parameters in the fence context, saving the driver from implementing these two callbacks.

Support for other callbacks (like for hardware signaling) is prepared for through the fact that both DriverFence and Fence live in the same allocation, allowing for usage of container_of from the callback to access the driver-specific data.

It is expected that other callbacks, added in the future, also mostly operate on the generic data in the FenceContext. To make this safe, the implementation ensures through a lifetime that a DriverFence cannot outlive its FenceContext.

Synchronization for dma_fence_ops callbacks is ensured by only running the Rust deconstructor delayed with call_rcu(), which prevents UAF-bugs should a DriverFence drop while a Fence callback is currently operating on the associated driver data. Since they can also operate on the FenceContext's data, its drop implementation also performs the necessary delay with rcu_barrier().

An additional issue discovered during the review process of this code is that there is (currently) no mechanism in Rust to prevent someone from circumventing the DriverFence's FenceContext-reference's lifetime by "forgetting" the fence, e.g. with core::mem::forget(). This would enable UAF bugs on the FenceContext. Throw a panic if this happens and document a path towards a more robust solution.

Add abstractions for dma_fence in Rust.

---
 rust/bindings/bindings_helper.h  |    1 +
 rust/helpers/dma_fence.c         |   48 ++
 rust/helpers/helpers.c           |    1 +
 rust/kernel/dma_buf/dma_fence.rs | 1022 ++++++++++++++++++++++++++++++
 rust/kernel/dma_buf/mod.rs       |   14 +
 rust/kernel/lib.rs               |    1 +
 6 files changed, 1087 insertions(+)
 create mode 100644 rust/helpers/dma_fence.c
 create mode 100644 rust/kernel/dma_buf/dma_fence.rs
 create mode 100644 rust/kernel/dma_buf/mod.rs
rust/bindings/bindings_helper.h +1 -0
index 1124785e210b..54b62d952e01 100644
@@ -53,6 +53,7 @@
 #include <linux/debugfs.h>
 #include <linux/device/faux.h>
 #include <linux/dma-direction.h>
+#include <linux/dma-fence.h>
 #include <linux/dma-mapping.h>
 #include <linux/dma-resv.h>
 #include <linux/errname.h>
rust/helpers/dma_fence.c new file +48 -0

48 lines not on this page · raw message

rust/helpers/helpers.c +1 -0
index 998e31052e66..4ab8aa9da7e7 100644
@@ -58,6 +58,7 @@
 #include "cred.c"
 #include "device.c"
 #include "dma.c"
+#include "dma_fence.c"
 #include "dma-resv.c"
 #include "drm.c"
 #include "drm_gpuvm.c"
rust/kernel/dma_buf/dma_fence.rs new file +1022 -0

1,022 lines not on this page · raw message

rust/kernel/dma_buf/mod.rs new file +14 -0
new file mode 100644
index 000000000000..4764a828642e
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+
+//! DMA-buf subsystem abstractions.
+
+pub mod dma_fence;
+
+pub use self::dma_fence::{
+    DriverFence,
+    Fence,
+    FenceCallback,
+    FenceCallbackRegistration,
+    FenceContext,
+    FenceContextOps, //
+};
rust/kernel/lib.rs +1 -0
index 9512af7156df..dc54d8af471f 100644
@@ -64,6 +64,7 @@
 pub mod device_id;
 pub mod devres;
 pub mod dma;
+pub mod dma_buf;
 pub mod driver;
 #[cfg(CONFIG_DRM = "y")]
 pub mod drm;
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH v10 1/2] rust: Add dma_fence abstractions

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Use-After-Free of FenceContext when a Fence outlives its DriverFence or when `!needs_drop`…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Use-After-Free of FenceContext when a Fence outlives its DriverFence or when !needs_drop bypasses RCU synchronization.
- [High] FenceContext will reliably trigger a kernel panic on drop if a DriverFence is signaled by external C code.
- [High] Fence::is_signaled() unconditionally acquires the fence spinlock, leading to spinlock recursion deadlocks if called from a callback. --

--- Patch [1]: [PATCH v10 1/2] rust: Add dma_fence abstractions --- commit 4a2030e75f6de53abe7df28e7314d4e3c4ae44a8
Author: Philipp Stanner <[email protected]>

rust: Add dma_fence abstractions

C's dma_fence's are synchronisation primitives that will be needed by all Rust GPU drivers.

Quoted 4 lines
rust/kernel/dma_buf/dma_fence.rs new file +0 -0
new file mode 100644

[ ... ]

rust/kernel/dma_buf/dma_fence.rs line 174

Quoted 10 lines
rust/kernel/dma_buf/dma_fence.rs new file +10 -0
+    extern "C" fn get_driver_name(ptr: *mut bindings::dma_fence) -> *const c_char {
+        // SAFETY: The C backend only invokes this callback with `ptr` pointing
+        // to a valid, unsignaled `bindings::dma_fence`. All fences created in
+        // this module always reside within `Fence` which always resides in a
+        // `DriverFenceData`, thus satisfying the function's safety
+        // requirements.
+        let fctx = unsafe { Self::from_raw_fence(ptr) };
+
+        fctx.driver_name.as_char_ptr()
+    }

[Severity: Critical]
Is it possible for the FenceContext to be accessed after it is freed here?

The C dma_fence API allows callbacks like get_driver_name() to be invoked at any time as long as the fence is alive (refcount > 0), even on signaled fences. Because the Rust abstraction explicitly allows a Fence to outlive its FenceContext, fctx can become a dangling pointer.

A userspace application calling SYNC_IOC_FILE_INFO or accessing debugfs could trigger this after the driver has unloaded and the FenceContext is dropped.

[ ... ]

Quoted 18 lines
rust/kernel/dma_buf/dma_fence.rs new file +18 -0
+    pub fn is_signaled(&self) -> bool {
+        // We should not use `dma_fence_is_signaled_locked()` here, because
+        // according to the C backend's recommendations, that function is
+        // problematic and we should avoid calling that function with a lock
+        // held.
+
+        // SAFETY: Inner `fence` is valid because `self` is valid.
+        let ret = unsafe { bindings::dma_fence_is_signaled(self.as_raw()) };
+
+        // To be as robust as possible for the future we guarantee that an API
+        // caller can 100% rely on the signalling being completed (i.e., all
+        // fence callbacks ran), so we have to take the lock.
+        //
+        // The reason is that the C dma_fence backend currently does not
+        // carefully synchronize the `dma_fence_is_signaled()` function with the
+        // proper spinlock. This can lead to the function returning `true` while
+        // fence callbacks are still being executed. This can be mitigated by
+        // guarding the entire function with the spinlock.

rust/kernel/dma_buf/dma_fence.rs line 523

Quoted 10 lines
rust/kernel/dma_buf/dma_fence.rs new file +10 -0
+        //
+        // The fundamental reason is that the C backend currently does guard
+        // setting of the fence's signaled-bit with the fence's spinlock, but
+        // reading is done locklessly.
+        //
+        // See commit c8a5d5ea3ba6a.
+        let _ = self.lock();
+
+        ret
+    }

[Severity: High]
Can this spinlock acquisition cause a recursion deadlock?

The C dma_fence_is_signaled() function is explicitly lockless. By acquiring the fence spinlock here, this wrapper introduces a blocking operation into what is supposed to be a lockless API.

If a user registers a FenceCallback that invokes is_signaled() on the same fence from within on_signal(), it will attempt to acquire the lock. Since dma_fence_signal executes these callbacks with the spinlock already held, this will result in an immediate deadlock.

[ ... ]

Quoted 14 lines
rust/kernel/dma_buf/dma_fence.rs new file +14 -0
+impl<'a, T: Send + Sync + FenceContextOps> Drop for DriverFence<'a, T> {
+    fn drop(&mut self) {
+        let guard = self.as_fence().lock();
+
+        // Use dma_fence_test_signaled_flag() instead of
+        // dma_fence_is_signaled_locked() because the C backend wants to get rid
+        // of the latter.
+
+        // SAFETY: `guard` is valid until the `call_rcu()` below.
+        let signaled: bool = unsafe { bindings::dma_fence_test_signaled_flag(guard.as_raw()) };
+        if !signaled {
+            pr_err!("DriverFence drops unsignaled. Danger of memory corruption!\n");
+            // SAFETY: `guard` is valid until the `call_rcu()` below. The fence
+            // must not have been signaled yet, which we check directly above.

rust/kernel/dma_buf/dma_fence.rs line 948

Quoted 10 lines
rust/kernel/dma_buf/dma_fence.rs new file +10 -0
+            unsafe { bindings::dma_fence_set_error(guard.as_raw(), ECANCELED.to_errno()) };
+            // SAFETY: `guard` is valid until the `call_rcu()` below. The lock
+            // must be held, which we acquired above.
+            unsafe { bindings::dma_fence_signal_locked(guard.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);
+        }
+        drop(guard);

[Severity: High]
Will this skip the counter decrement if the fence is signaled by external C code?

If a C subsystem (like the DRM scheduler or a software signaling debugfs hook) signals the DriverFence, the signaled variable will be true. If the driver subsequently drops the DriverFence without calling signal(), this block is skipped and the fetch_sub(1) decrement is permanently lost.

When the FenceContext is later dropped, it will unconditionally panic because the counter is imbalanced:

rust/kernel/dma_buf/dma_fence.rs:FenceContext::drop() {
    ...
    if self.nr_of_unsignaled_fences.load(Relaxed) != 0 {
        panic!("Forgotten fences in FenceContext.");
    }
    ...
}
Quoted 6 lines
rust/kernel/dma_buf/dma_fence.rs new file +6 -0
+
+        // `DriverFenceData` but could be accessed through some dma_fence
+        // callbacks right now. Access is being revoked in principle above by
+        // signalling the fence, but since the C backend does not guarantee
+        // perfect full synchronization, we have to wait for one grace period to
+        // ensure that all accessors of `DriverFenceData` (through the

rust/kernel/dma_buf/dma_fence.rs line 964

Quoted 10 lines
rust/kernel/dma_buf/dma_fence.rs new file +10 -0
+        // dma_fence_ops accessible through a `Fence`) are gone.
+
+        if !core::mem::needs_drop::<T::FenceDataType>() {
+            // SAFETY: Once a `DriverFence` is initialized, the inner `fence` is
+            // valid and initialized. It is valid until the refcount drops
+            // to 0, which can earliest happen once we drop the `DriverFence`'s reference
+            // here.
+            unsafe { bindings::dma_fence_put(self.as_raw()) };
+            return;
+        }

[Severity: Critical]
Does this optimization bypass the RCU synchronization required for safe teardown?

If this block returns early, no RCU callback is queued. Consequently, when the FenceContext drops, its rcu_barrier() call will not wait for a grace period because there are no callbacks pending.

This allows the FenceContext to be freed immediately while concurrent C readers holding RCU read locks might still be executing, leading to a use-after-free.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw

Re: [PATCH v10 1/2] rust: Add dma_fence abstractions

In reply to Philipp Stanner
Quoted 1 line · Philipp Stanner

Add abstractions for dma_fence in Rust.

I was about to pick this up, but ended up with too many things to tweak.

* Fix checkpatch.pl warnings,
* take &CStr instead of CString in FenceContext::new(),
* change DriverFenceAllocation::ops to &'static from *const,
* remove # Safety comment on AlwaysRefCounted::dec_ref() impl,
* use Opaque::zeroed() instead of __GFP_ZERO,
* use kernel vertical import style.

Here's the diff I suggest for a v11:

rust/helpers/dma_fence.c +2 -1
index 0e08411098fa..549f6b6a7171 100644
@@ -37,7 +37,8 @@ __rust_helper void rust_helper_dma_fence_lock_irqsave(struct dma_fence *f, unsig
 	dma_fence_lock_irqsave(f, *flags);
 }
 
-__rust_helper void rust_helper_dma_fence_unlock_irqrestore(struct dma_fence *f, unsigned long *flags)
+__rust_helper void rust_helper_dma_fence_unlock_irqrestore(struct dma_fence *f,
+							   unsigned long *flags)
 {
 	dma_fence_unlock_irqrestore(f, *flags);
 }
rust/kernel/dma_buf/dma_fence.rs +25 -26

117 lines not on this page · raw message

#4 lore raw

Re: [PATCH v10 1/2] rust: Add dma_fence abstractions

Quoted 4 lines · Danilo Krummrich
Quoted 1 line · Philipp Stanner

Add abstractions for dma_fence in Rust.

I was about to pick this up, but ended up with too many things to tweak.

:(

Quoted 2 lines

  * Fix checkpatch.pl warnings,

I get two, one of them being obsolete

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #114:
new file mode 100644

WARNING: line length of 101 exceeds 100 columns
#158: FILE: rust/helpers/dma_fence.c:40:
+__rust_helper void rust_helper_dma_fence_unlock_irqrestore(struct dma_fence *f, unsigned long *flags)

Quoted 2 lines

  * use Opaque::zeroed() instead of __GFP_ZERO,

That's literally what I had originally, but Alice objected and wanted GFP_ZERO, AFAIR because it's more efficient.

Maybe you two want to get to an agreement on what's better.

Quoted 2 lines

  * use kernel vertical import style.
Here's the diff I suggest for a v11:

Thx, I'll take it into account.

P.

maintainer
#5 lore raw

Re: [PATCH v10 1/2] rust: Add dma_fence abstractions

Quoted 4 lines · Philipp Stanner
Quoted 3 lines · Danilo Krummrich
Quoted 1 line · Philipp Stanner

Add abstractions for dma_fence in Rust.

Quoted 8 lines
Quoted 1 line

I was about to pick this up, but ended up with too many things to tweak.

:(

Quoted 2 lines

  * Fix checkpatch.pl warnings,

I get two, one of them being obsolete

I think the other one was a spelling mistake, do you run --codespell?

Quoted 10 lines

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #114:
new file mode 100644

WARNING: line length of 101 exceeds 100 columns
#158: FILE: rust/helpers/dma_fence.c:40:
+__rust_helper void rust_helper_dma_fence_unlock_irqrestore(struct dma_fence *f, unsigned long *flags)

Quoted 1 line
Quoted 4 lines
Quoted 1 line

  * use Opaque::zeroed() instead of __GFP_ZERO,

That's literally what I had originally, but Alice objected and wanted GFP_ZERO, AFAIR because it's more efficient.

I don't think you can say this in general, it depends e.g. on the size of T::FenceDataType, etc.

But struct dma_fence is pretty small, I doubt one can even measure the overhead. Besides that, fence context creation is a cold path with many *much* more expensive operations.

If we'd really care about that, you could also do neither as __dma_fence_init() should write all fields anyway.

Quoted 1 line

Maybe you two want to get to an agreement on what's better.

Nah, it doesn't really matter, anything is fine with me.

Quoted 4 lines
Quoted 2 lines

  * use kernel vertical import style.
Here's the diff I suggest for a v11:

Thx, I'll take it into account.

author maintainer
#6 lore raw

PATCH v10 2/2 MAINTAINERS: Add entry for Rust dma-buf

In reply to Philipp Stanner

Rust does now have abstractions for dma_fence. These abstractions are quite complicated and require expertise with both the C and the Rust side. Therefore, using the existing entry also for maintenance of the Rust code appears reasonable.

Philipp volunteers to help maintain the dma_fence abstractions. Add a corresponding MAINTAINERS entry.

---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 5114e6db7307..fd7689cf22ac 100644
@@ -7623,6 +7623,7 @@ F:	fs/dlm/
 DMA BUFFER SHARING FRAMEWORK
 M:	Sumit Semwal <[email protected]>
 M:	Christian König <[email protected]>
+M:	Philipp Stanner <[email protected]>
 L:	[email protected]
 L:	[email protected]
 L:	[email protected] (moderated for non-subscribers)
@@ -7636,6 +7637,8 @@ F:	include/linux/dma-buf.h
 F:	include/linux/dma-buf/
 F:	include/linux/dma-resv.h
 F:	rust/helpers/dma-resv.c
+F:	rust/helpers/dma_fence.c
+F:	rust/kernel/dma_buf/
 K:	\bdma_(?:buf|fence|resv)\b
 
 DMA GENERIC OFFLOAD ENGINE SUBSYSTEM
@@ -8622,7 +8625,9 @@ T:	git https://gitlab.freedesktop.org/drm/rust/kernel.git
 F:	drivers/gpu/drm/nova/
 F:	drivers/gpu/drm/tyr/
 F:	drivers/gpu/nova-core/
+F:	rust/helpers/dma_fence.c
 F:	rust/helpers/gpu.c
+F:	rust/kernel/dma_buf/
 F:	rust/kernel/drm/
 F:	rust/kernel/gpu.rs
 F:	rust/kernel/gpu/
Signature · 1 line
2.55.0