Skip to content

Commit cd3a56a

Browse files
committed
Merge tag 'rust-fixes-6.14-3' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull rust fixes from Miguel Ojeda: "Toolchain and infrastructure: - Disallow BTF generation with Rust + LTO - Improve rust-analyzer support 'kernel' crate: - 'init' module: remove 'Zeroable' implementation for a couple types that should not have it - 'alloc' module: fix macOS failure in host test by satisfying POSIX alignment requirement - Add missing '\n's to 'pr_*!()' calls And a couple other minor cleanups" * tag 'rust-fixes-6.14-3' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: scripts: generate_rust_analyzer: add uapi crate scripts: generate_rust_analyzer: add missing include_dirs scripts: generate_rust_analyzer: add missing macros deps rust: Disallow BTF generation with Rust + LTO rust: task: fix `SAFETY` comment in `Task::wake_up` rust: workqueue: add missing newline to pr_info! examples rust: sync: add missing newline in locked_by log example rust: init: add missing newline to pr_info! calls rust: error: add missing newline to pr_warn! calls rust: docs: add missing newline to printing macro examples rust: alloc: satisfy POSIX alignment requirement rust: init: fix `Zeroable` implementation for `Option<NonNull<T>>` and `Option<KBox<T>>` rust: remove leftover mentions of the `alloc` crate
2 parents eb88e6b + a1eb95d commit cd3a56a

File tree

13 files changed

+85
-57
lines changed

13 files changed

+85
-57
lines changed

Documentation/rust/quick-start.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Rust standard library source
145145
****************************
146146

147147
The Rust standard library source is required because the build system will
148-
cross-compile ``core`` and ``alloc``.
148+
cross-compile ``core``.
149149

150150
If ``rustup`` is being used, run::
151151

Documentation/rust/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ operator are also supported as usual, e.g.:
9797
9898
/// ```
9999
/// # use kernel::{spawn_work_item, workqueue};
100-
/// spawn_work_item!(workqueue::system(), || pr_info!("x"))?;
100+
/// spawn_work_item!(workqueue::system(), || pr_info!("x\n"))?;
101101
/// # Ok::<(), Error>(())
102102
/// ```
103103

init/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,7 @@ config RUST
19731973
depends on !MODVERSIONS || GENDWARFKSYMS
19741974
depends on !GCC_PLUGIN_RANDSTRUCT
19751975
depends on !RANDSTRUCT
1976-
depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
1976+
depends on !DEBUG_INFO_BTF || (PAHOLE_HAS_LANG_EXCLUDE && !LTO)
19771977
depends on !CFI_CLANG || HAVE_CFI_ICALL_NORMALIZE_INTEGERS_RUSTC
19781978
select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG
19791979
depends on !CALL_PADDING || RUSTC_VERSION >= 108100

rust/kernel/alloc/allocator_test.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ unsafe impl Allocator for Cmalloc {
6262
));
6363
}
6464

65+
// ISO C (ISO/IEC 9899:2011) defines `aligned_alloc`:
66+
//
67+
// > The value of alignment shall be a valid alignment supported by the implementation
68+
// [...].
69+
//
70+
// As an example of the "supported by the implementation" requirement, POSIX.1-2001 (IEEE
71+
// 1003.1-2001) defines `posix_memalign`:
72+
//
73+
// > The value of alignment shall be a power of two multiple of sizeof (void *).
74+
//
75+
// and POSIX-based implementations of `aligned_alloc` inherit this requirement. At the time
76+
// of writing, this is known to be the case on macOS (but not in glibc).
77+
//
78+
// Satisfy the stricter requirement to avoid spurious test failures on some platforms.
79+
let min_align = core::mem::size_of::<*const crate::ffi::c_void>();
80+
let layout = layout.align_to(min_align).map_err(|_| AllocError)?;
81+
let layout = layout.pad_to_align();
82+
6583
// SAFETY: Returns either NULL or a pointer to a memory allocation that satisfies or
6684
// exceeds the given size and alignment requirements.
6785
let dst = unsafe { libc_aligned_alloc(layout.align(), layout.size()) } as *mut u8;

rust/kernel/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Error {
107107
} else {
108108
// TODO: Make it a `WARN_ONCE` once available.
109109
crate::pr_warn!(
110-
"attempted to create `Error` with out of range `errno`: {}",
110+
"attempted to create `Error` with out of range `errno`: {}\n",
111111
errno
112112
);
113113
code::EINVAL

rust/kernel/init.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pub mod macros;
259259
/// },
260260
/// }));
261261
/// let foo: Pin<&mut Foo> = foo;
262-
/// pr_info!("a: {}", &*foo.a.lock());
262+
/// pr_info!("a: {}\n", &*foo.a.lock());
263263
/// ```
264264
///
265265
/// # Syntax
@@ -319,7 +319,7 @@ macro_rules! stack_pin_init {
319319
/// }, GFP_KERNEL)?,
320320
/// }));
321321
/// let foo = foo.unwrap();
322-
/// pr_info!("a: {}", &*foo.a.lock());
322+
/// pr_info!("a: {}\n", &*foo.a.lock());
323323
/// ```
324324
///
325325
/// ```rust,ignore
@@ -352,7 +352,7 @@ macro_rules! stack_pin_init {
352352
/// x: 64,
353353
/// }, GFP_KERNEL)?,
354354
/// }));
355-
/// pr_info!("a: {}", &*foo.a.lock());
355+
/// pr_info!("a: {}\n", &*foo.a.lock());
356356
/// # Ok::<_, AllocError>(())
357357
/// ```
358358
///
@@ -882,7 +882,7 @@ pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
882882
///
883883
/// impl Foo {
884884
/// fn setup(self: Pin<&mut Self>) {
885-
/// pr_info!("Setting up foo");
885+
/// pr_info!("Setting up foo\n");
886886
/// }
887887
/// }
888888
///
@@ -986,7 +986,7 @@ pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
986986
///
987987
/// impl Foo {
988988
/// fn setup(&mut self) {
989-
/// pr_info!("Setting up foo");
989+
/// pr_info!("Setting up foo\n");
990990
/// }
991991
/// }
992992
///
@@ -1336,7 +1336,7 @@ impl<T> InPlaceWrite<T> for UniqueArc<MaybeUninit<T>> {
13361336
/// #[pinned_drop]
13371337
/// impl PinnedDrop for Foo {
13381338
/// fn drop(self: Pin<&mut Self>) {
1339-
/// pr_info!("Foo is being dropped!");
1339+
/// pr_info!("Foo is being dropped!\n");
13401340
/// }
13411341
/// }
13421342
/// ```
@@ -1418,17 +1418,14 @@ impl_zeroable! {
14181418
// SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`.
14191419
{<T: ?Sized + Zeroable>} UnsafeCell<T>,
14201420

1421-
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
1421+
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
1422+
// https://doc.rust-lang.org/stable/std/option/index.html#representation).
14221423
Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
14231424
Option<NonZeroU128>, Option<NonZeroUsize>,
14241425
Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
14251426
Option<NonZeroI128>, Option<NonZeroIsize>,
1426-
1427-
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
1428-
//
1429-
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
1430-
{<T: ?Sized>} Option<NonNull<T>>,
1431-
{<T: ?Sized>} Option<KBox<T>>,
1427+
{<T>} Option<NonNull<T>>,
1428+
{<T>} Option<KBox<T>>,
14321429

14331430
// SAFETY: `null` pointer is valid.
14341431
//

rust/kernel/init/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
//! #[pinned_drop]
4646
//! impl PinnedDrop for Foo {
4747
//! fn drop(self: Pin<&mut Self>) {
48-
//! pr_info!("{self:p} is getting dropped.");
48+
//! pr_info!("{self:p} is getting dropped.\n");
4949
//! }
5050
//! }
5151
//!
@@ -412,7 +412,7 @@
412412
//! #[pinned_drop]
413413
//! impl PinnedDrop for Foo {
414414
//! fn drop(self: Pin<&mut Self>) {
415-
//! pr_info!("{self:p} is getting dropped.");
415+
//! pr_info!("{self:p} is getting dropped.\n");
416416
//! }
417417
//! }
418418
//! ```
@@ -423,7 +423,7 @@
423423
//! // `unsafe`, full path and the token parameter are added, everything else stays the same.
424424
//! unsafe impl ::kernel::init::PinnedDrop for Foo {
425425
//! fn drop(self: Pin<&mut Self>, _: ::kernel::init::__internal::OnlyCallFromDrop) {
426-
//! pr_info!("{self:p} is getting dropped.");
426+
//! pr_info!("{self:p} is getting dropped.\n");
427427
//! }
428428
//! }
429429
//! ```

rust/kernel/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! usage by Rust code in the kernel and is shared by all of them.
77
//!
88
//! In other words, all the rest of the Rust code in the kernel (e.g. kernel
9-
//! modules written in Rust) depends on [`core`], [`alloc`] and this crate.
9+
//! modules written in Rust) depends on [`core`] and this crate.
1010
//!
1111
//! If you need a kernel C API that is not ported or wrapped yet here, then
1212
//! do so first instead of bypassing this crate.

rust/kernel/sync/locked_by.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use core::{cell::UnsafeCell, mem::size_of, ptr};
5555
/// fn print_bytes_used(dir: &Directory, file: &File) {
5656
/// let guard = dir.inner.lock();
5757
/// let inner_file = file.inner.access(&guard);
58-
/// pr_info!("{} {}", guard.bytes_used, inner_file.bytes_used);
58+
/// pr_info!("{} {}\n", guard.bytes_used, inner_file.bytes_used);
5959
/// }
6060
///
6161
/// /// Increments `bytes_used` for both the directory and file.

rust/kernel/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl Task {
320320

321321
/// Wakes up the task.
322322
pub fn wake_up(&self) {
323-
// SAFETY: It's always safe to call `signal_pending` on a valid task, even if the task
323+
// SAFETY: It's always safe to call `wake_up_process` on a valid task, even if the task
324324
// running.
325325
unsafe { bindings::wake_up_process(self.as_ptr()) };
326326
}

0 commit comments

Comments
 (0)