Re: linux-next: build failure after merge of the rust tree

Miguel Ojeda
2025-03-24T15:18:53Z

[-- Attachment #1: Type: text/plain, Size: 758 bytes --]

On Mon, Mar 24, 2025 at 2:43 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> It's the DMA commit that has a bug, that was revealed by the fix in the
> driver-core tree. So, the patch to drop is in the rust tree (not sure if Miguel
> changes history at this point though).

Just to double-check, the diff you show below is the combined one,
right? i.e. it is the one that Stephen already had the previous week +
the fix you posted above (`Send` `impl`), right?

If so, I think it is OK, and we could put the new `Send` impl on top
of `rust-next` -- given the trees on their own are OK until they
arrive to Linus, I am not sure if it counts as a fix.

i.e. something like the attached patch (crediting Danilo and Stephen).

Cheers,
Miguel

[-- Attachment #2: 0001-rust-dma-add-Send-implementation-for-CoherentAllocat.patch --]
[-- Type: text/x-patch, Size: 1795 bytes --]

From 6a152af23cb49a3bcbb8c4457a612ffa27d54693 Mon Sep 17 00:00:00 2001
From: Danilo Krummrich <dakr@kernel.org>
Date: Mon, 24 Mar 2025 16:01:00 +0100
Subject: [PATCH] rust: dma: add `Send` implementation for `CoherentAllocation`

Stephen found a future build failure in linux-next [1]:

error[E0277]: `*mut MyStruct` cannot be sent between threads safely
--> samples/rust/rust_dma.rs:47:22
|
47 | impl pci::Driver for DmaSampleDriver {
| ^^^^^^^^^^^^^^^ `*mut MyStruct` cannot be sent between threads safely

It is caused by the interaction between commit 935e1d90bf6f ("rust: pci:
require Send for Driver trait implementers") from the driver-core tree,
which fixes a missing concurrency requirement, and commit 9901addae63b
("samples: rust: add Rust dma test sample driver") which adds a sample
that does not satisfy that requirement.

Add a `Send` implementation to `CoherentAllocation`, which allows the
sample (and other future users) to satisfy it.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Link: https://lore.kernel.org/linux-next/20250324215702.1515ba92@canb.auug.org.au/
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
---
rust/kernel/dma.rs | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 9d00f9c49f47..18de693c4924 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -301,6 +301,10 @@ fn drop(&mut self) {
}
}

+// SAFETY: It is safe to send a `CoherentAllocation` to another thread if `T`
+// can be send to another thread.
+unsafe impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T> {}
+
/// Reads a field of an item from an allocated region of structs.
///
/// # Examples
--
2.49.0