Skip to contentSkip to conversation

rust: Enable the new_uninit feature for kernel and driver crates

PATCH Applied Asahi Lina 6 participants 9 messages Feb 24, 2023 – Apr 10, 2023

Subsystems (2)
lore
Share & tools
lore

Asahi Lina

author
#0 lore raw

PATCH 1/1 rust: Enable the new_uninit feature for kernel and driver crates

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

---
 rust/kernel/lib.rs     | 1 +
 scripts/Makefile.build | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
rust/kernel/lib.rs +1 -0
index 223564f9f0cc..1118cd3e0b5f 100644
@@ -17,6 +17,7 @@
 #![feature(core_ffi_c)]
 #![feature(dispatch_from_dyn)]
 #![feature(generic_associated_types)]
+#![feature(new_uninit)]
 #![feature(receiver_trait)]
 #![feature(unsize)]
 
scripts/Makefile.build +1 -1
index a0d5c6cca76d..0f637e1ca8dc 100644
@@ -277,7 +277,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
 # Compile Rust sources (.rs)
 # ---------------------------------------------------------------------------
 
-rust_allowed_features := core_ffi_c
+rust_allowed_features := core_ffi_c,new_uninit
 
 rust_common_cmd = \
 	RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \

---
base-commit: 83f978b63fa7ad474ca22d7e2772c5988101c9bd
change-id: 20230224-rust-new_uninit-a575d34987c3

Thank you,
~~ Lina

Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Asahi Lina

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

Very useful to me as some constructors in the USB bindings that I'm writting might make use of unitialized memory.

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Asahi Lina
Quoted 9 lines · On Fri, 24 Feb 2023 17:09:47 +0900 Asahi Lina <[email protected]> wrote:

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

Quoted 7 lines

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

Quoted 38 lines
---
 rust/kernel/lib.rs     | 1 +
 scripts/Makefile.build | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
rust/kernel/lib.rs +1 -0
index 223564f9f0cc..1118cd3e0b5f 100644
@@ -17,6 +17,7 @@
 #![feature(core_ffi_c)]
 #![feature(dispatch_from_dyn)]
 #![feature(generic_associated_types)]
+#![feature(new_uninit)]
 #![feature(receiver_trait)]
 #![feature(unsize)]
 
scripts/Makefile.build +1 -2
index a0d5c6cca76d..0f637e1ca8dc 100644
@@ -277,7 +277,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
 # Compile Rust sources (.rs)
 # ---------------------------------------------------------------------------
 
-rust_allowed_features := core_ffi_c
+rust_allowed_features := core_ffi_c,new_uninit
 
 rust_common_cmd = \
 	RUST_MODFILE=$(modfile) $(RUSTC_OR_CLIPPY) $(rust_flags) \
 
---

base-commit: 83f978b63fa7ad474ca22d7e2772c5988101c9bd
change-id: 20230224-rust-new_uninit-a575d34987c3

Thank you,
~~ Lina

#3 lore raw
In reply to Asahi Lina
Quoted 38 lines · Asahi Lina

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

---
 rust/kernel/lib.rs     | 1 +
 scripts/Makefile.build | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
rust/kernel/lib.rs +1 -0
index 223564f9f0cc..1118cd3e0b5f 100644
@@ -17,6 +17,7 @@
 #![feature(core_ffi_c)]
 #![feature(dispatch_from_dyn)]
 #![feature(generic_associated_types)]
+#![feature(new_uninit)]
 #![feature(receiver_trait)]
 #![feature(unsize)]
 
scripts/Makefile.build +0 -0
index a0d5c6cca76d..0f637e1ca8dc 100644

scripts/Makefile.build $(obj)/%.lst: $(src)/%.c FORCE · line 280

Quoted 5 lines
scripts/Makefile.build +1 -1
@@ -277,7 +277,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
 # Compile Rust sources (.rs)
 # ---------------------------------------------------------------------------
 
-rust_allowed_features := core_ffi_c
+rust_allowed_features := core_ffi_c,new_uninit

What is the purpose of adding the feature here? The kernel crate seems to compile fine without this.

BR Andreas

author
#4 lore raw
Quoted 44 lines · Andreas Hindborg
Quoted 41 lines · Asahi Lina

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

---
 rust/kernel/lib.rs     | 1 +
 scripts/Makefile.build | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
rust/kernel/lib.rs +1 -0
index 223564f9f0cc..1118cd3e0b5f 100644
@@ -17,6 +17,7 @@
 #![feature(core_ffi_c)]
 #![feature(dispatch_from_dyn)]
 #![feature(generic_associated_types)]
+#![feature(new_uninit)]
 #![feature(receiver_trait)]
 #![feature(unsize)]
 
scripts/Makefile.build +0 -0
index a0d5c6cca76d..0f637e1ca8dc 100644
@@ -277,7 +277,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
 # Compile Rust sources (.rs)
 # ---------------------------------------------------------------------------
 
Quoted 5 lines

scripts/Makefile.build $(obj)/%.lst: $(src)/%.c FORCE · line 280

Quoted 2 lines
scripts/Makefile.build +1 -1
-rust_allowed_features := core_ffi_c
+rust_allowed_features := core_ffi_c,new_uninit

What is the purpose of adding the feature here? The kernel crate seems to compile fine without this.

It's for the upcoming DRM abstractions, as I mentioned in the commit message. There's so many dependencies that I'm trying to get as much as I can early to avoid having to review very big patchsets down the line ^^

~~ Lina

Reviewed-by
#5 lore raw
Quoted 51 lines · Asahi Lina
Quoted 44 lines · Andreas Hindborg
Quoted 41 lines · Asahi Lina

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

---
 rust/kernel/lib.rs     | 1 +
 scripts/Makefile.build | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
rust/kernel/lib.rs +1 -0
index 223564f9f0cc..1118cd3e0b5f 100644
@@ -17,6 +17,7 @@
 #![feature(core_ffi_c)]
 #![feature(dispatch_from_dyn)]
 #![feature(generic_associated_types)]
+#![feature(new_uninit)]
 #![feature(receiver_trait)]
 #![feature(unsize)]
 
scripts/Makefile.build +0 -0
index a0d5c6cca76d..0f637e1ca8dc 100644
@@ -277,7 +277,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
 # Compile Rust sources (.rs)
 # ---------------------------------------------------------------------------
 
Quoted 5 lines

scripts/Makefile.build $(obj)/%.lst: $(src)/%.c FORCE · line 280

Quoted 2 lines
scripts/Makefile.build +1 -1
-rust_allowed_features := core_ffi_c
+rust_allowed_features := core_ffi_c,new_uninit

What is the purpose of adding the feature here? The kernel crate seems to compile fine without this.

Quoted 3 lines

It's for the upcoming DRM abstractions, as I mentioned in the commit message. There's so many dependencies that I'm trying to get as much as I can early to avoid having to review very big patchsets down the line ^^

I got confused on the different makefile rules used to build kernel crate vs module crates. Looks good 👍

#6 lore raw
In reply to Andreas Hindborg
Quoted 3 lines · Andreas Hindborg

What is the purpose of adding the feature here? The kernel crate seems to compile fine without this.

rust_allowed_features is the list of features that crates outside rust/ can use (e.g. drivers).

The goal is to control which unstable features are used outside the kernel crate and to avoid mistakenly relying on them.

Cheers,
Miguel

Reviewed-by on v1 1/1
#7 lore raw
In reply to Asahi Lina
Quoted 9 lines

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

Quoted 8 lines

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

---

Applied
#8 lore raw
In reply to Asahi Lina
Quoted 10 lines · Asahi Lina

The unstable new_uninit feature enables various library APIs to create uninitialized containers, such as Box::assume_init(). This is necessary to build abstractions that directly initialize memory at the target location, instead of doing copies through the stack.

Will be used by the DRM scheduler abstraction in the kernel crate, and by field-wise initialization (e.g. using place!() or a future replacement macro which may itself live in kernel) in driver crates.

Quoted 5 lines

See [1] [2] [3] for background information.

[1] https://github.com/Rust-for-Linux/linux/issues/879
[2] https://github.com/Rust-for-Linux/linux/issues/2
[3] https://github.com/rust-lang/rust/issues/63291

Applied to rust-next (reworded to use Link tags). Thanks!

Cheers,
Miguel