Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 203e284

Browse files
ojedagregkh
authored andcommittedFeb 13, 2024
rust: upgrade to Rust 1.72.1
commit ae6df65 upstream. This is the third upgrade to the Rust toolchain, from 1.71.1 to 1.72.1 (i.e. the latest) [1]. See the upgrade policy [2] and the comments on the first upgrade in commit 3ed03f4 ("rust: upgrade to Rust 1.68.2"). # Unstable features No unstable features (that we use) were stabilized. Therefore, the only unstable feature allowed to be used outside the `kernel` crate is still `new_uninit`, though other code to be upstreamed may increase the list. Please see [3] for details. # Other improvements Previously, the compiler could incorrectly generate a `.eh_frame` section under `-Cpanic=abort`. We were hitting this bug when debug assertions were enabled (`CONFIG_RUST_DEBUG_ASSERTIONS=y`) [4]: LD .tmp_vmlinux.kallsyms1 ld.lld: error: <internal>:(.eh_frame) is being placed in '.eh_frame' Gary fixed the issue in Rust 1.72.0 [5]. # Required changes For the upgrade, the following changes are required: - A call to `Box::from_raw` in `rust/kernel/sync/arc.rs` now requires an explicit `drop()` call. See previous patch for details. # `alloc` upgrade and reviewing The vast majority of changes are due to our `alloc` fork being upgraded at once. There are two kinds of changes to be aware of: the ones coming from upstream, which we should follow as closely as possible, and the updates needed in our added fallible APIs to keep them matching the newer infallible APIs coming from upstream. Instead of taking a look at the diff of this patch, an alternative approach is reviewing a diff of the changes between upstream `alloc` and the kernel's. This allows to easily inspect the kernel additions only, especially to check if the fallible methods we already have still match the infallible ones in the new version coming from upstream. Another approach is reviewing the changes introduced in the additions in the kernel fork between the two versions. This is useful to spot potentially unintended changes to our additions. To apply these approaches, one may follow steps similar to the following to generate a pair of patches that show the differences between upstream Rust and the kernel (for the subset of `alloc` we use) before and after applying this patch: # Get the difference with respect to the old version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > old.patch git -C linux restore rust/alloc # Apply this patch. git -C linux am rust-upgrade.patch # Get the difference with respect to the new version. git -C rust checkout $(linux/scripts/min-tool-version.sh rustc) git -C linux ls-tree -r --name-only HEAD -- rust/alloc | cut -d/ -f3- | grep -Fv README.md | xargs -IPATH cp rust/library/alloc/src/PATH linux/rust/alloc/PATH git -C linux diff --patch-with-stat --summary -R > new.patch git -C linux restore rust/alloc Now one may check the `new.patch` to take a look at the additions (first approach) or at the difference between those two patches (second approach). For the latter, a side-by-side tool is recommended. Link: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1721-2023-09-19 [1] Link: https://rust-for-linux.com/rust-version-policy [2] Link: Rust-for-Linux/linux#2 [3] Closes: Rust-for-Linux/linux#1012 [4] Link: rust-lang/rust#112403 [5] Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Björn Roy Baron <bjorn3_gh@protonmail.com> Link: https://lore.kernel.org/r/20230823160244.188033-3-ojeda@kernel.org [ Used 1.72.1 instead of .0 (no changes in `alloc`) and reworded to mention that we hit the `.eh_frame` bug under debug assertions. ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0d17c19 commit 203e284

File tree

8 files changed

+187
-266
lines changed

8 files changed

+187
-266
lines changed
 

‎Documentation/process/changes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ you probably needn't concern yourself with pcmciautils.
3131
====================== =============== ========================================
3232
GNU C 5.1 gcc --version
3333
Clang/LLVM (optional) 11.0.0 clang --version
34-
Rust (optional) 1.71.1 rustc --version
34+
Rust (optional) 1.72.1 rustc --version
3535
bindgen (optional) 0.65.1 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version

‎rust/alloc/alloc.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
#[cfg(not(test))]
88
use core::intrinsics;
9+
#[cfg(all(bootstrap, not(test)))]
910
use core::intrinsics::{min_align_of_val, size_of_val};
1011

12+
#[cfg(all(bootstrap, not(test)))]
1113
use core::ptr::Unique;
1214
#[cfg(not(test))]
1315
use core::ptr::{self, NonNull};
@@ -40,7 +42,6 @@ extern "Rust" {
4042
#[rustc_nounwind]
4143
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
4244

43-
#[cfg(not(bootstrap))]
4445
static __rust_no_alloc_shim_is_unstable: u8;
4546
}
4647

@@ -98,7 +99,6 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
9899
unsafe {
99100
// Make sure we don't accidentally allow omitting the allocator shim in
100101
// stable code until it is actually stabilized.
101-
#[cfg(not(bootstrap))]
102102
core::ptr::read_volatile(&__rust_no_alloc_shim_is_unstable);
103103

104104
__rust_alloc(layout.size(), layout.align())
@@ -339,14 +339,15 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
339339
}
340340
}
341341

342-
#[cfg_attr(not(test), lang = "box_free")]
342+
#[cfg(all(bootstrap, not(test)))]
343+
#[lang = "box_free"]
343344
#[inline]
344345
// This signature has to be the same as `Box`, otherwise an ICE will happen.
345346
// When an additional parameter to `Box` is added (like `A: Allocator`), this has to be added here as
346347
// well.
347348
// For example if `Box` is changed to `struct Box<T: ?Sized, A: Allocator>(Unique<T>, A)`,
348349
// this function has to be changed to `fn box_free<T: ?Sized, A: Allocator>(Unique<T>, A)` as well.
349-
pub(crate) unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A) {
350+
unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A) {
350351
unsafe {
351352
let size = size_of_val(ptr.as_ref());
352353
let align = min_align_of_val(ptr.as_ref());

‎rust/alloc/boxed.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,16 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12151215

12161216
#[stable(feature = "rust1", since = "1.0.0")]
12171217
unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
1218+
#[inline]
12181219
fn drop(&mut self) {
1219-
// FIXME: Do nothing, drop is currently performed by compiler.
1220+
// the T in the Box is dropped by the compiler before the destructor is run
1221+
1222+
let ptr = self.0;
1223+
1224+
unsafe {
1225+
let layout = Layout::for_value_raw(ptr.as_ptr());
1226+
self.1.deallocate(From::from(ptr.cast()), layout)
1227+
}
12201228
}
12211229
}
12221230

‎rust/alloc/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
//! [`Rc`]: rc
5959
//! [`RefCell`]: core::cell
6060
61+
// To run alloc tests without x.py without ending up with two copies of alloc, Miri needs to be
62+
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
63+
// rustc itself never sets the feature, so this line has no affect there.
64+
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
65+
//
6166
#![allow(unused_attributes)]
6267
#![stable(feature = "alloc", since = "1.36.0")]
6368
#![doc(
@@ -77,11 +82,6 @@
7782
))]
7883
#![no_std]
7984
#![needs_allocator]
80-
// To run alloc tests without x.py without ending up with two copies of alloc, Miri needs to be
81-
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
82-
// rustc itself never sets the feature, so this line has no affect there.
83-
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
84-
//
8585
// Lints:
8686
#![deny(unsafe_op_in_unsafe_fn)]
8787
#![deny(fuzzy_provenance_casts)]

‎rust/alloc/vec/drain_filter.rs

-199
This file was deleted.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.