Skip to content

Commit 367b81e

Browse files
committed
Merge tag 'rust-fixes-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust fixes from Miguel Ojeda: "Toolchain and infrastructure: - Trigger rebuilds of the newly added 'proc-macro2' crate (and its dependencies) when the Rust compiler version changes - Fix error in '.rsi' targets (macro expanding single targets) under 'O=' pointing to an external (not subdir) folder - Fix off-by-one line number in 'rustdoc' KUnit tests - Add '-fdiagnostics-show-context' to GCC flags skipped by 'bindgen' - Clean objtool warning by adding one more 'noreturn' function - Clean 'libpin_init_internal.{so,dylib}' in 'mrproper' 'kernel' crate: - Fix build error when using expressions in formatting arguments - Mark 'num::Bounded::__new()' as unsafe and clean documentation accordingly - Always inline functions using 'build_assert' with arguments - Fix 'rusttest' build error providing the right 'isize_atomic_repr' type for the host 'macros' crate: - Fix 'rusttest' build error by ignoring example rust-analyzer: - Remove assertion that was not true for distributions like NixOS - Add missing dependency edges and fix editions for 'quote' and sysroot crates to provide correct IDE support DRM Tyr: - Fix build error by adding missing dependency on 'CONFIG_COMMON_CLK' Plus clean a few typos in docs and comments" * tag 'rust-fixes-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (28 commits) rust: num: bounded: clean __new documentation and comments scripts: generate_rust_analyzer: fix resolution of #[pin_data] macros drm/tyr: depend on `COMMON_CLK` to fix build error rust: sync: atomic: Provide stub for `rusttest` 32-bit hosts kbuild: rust: clean libpin_init_internal in mrproper rust: proc-macro2: rebuild if the version text changes rust: num: bounded: add missing comment for always inlined function rust: sync: refcount: always inline functions using build_assert with arguments rust: bits: always inline functions using build_assert with arguments scripts: generate_rust_analyzer: compile sysroot with correct edition scripts: generate_rust_analyzer: compile quote with correct edition scripts: generate_rust_analyzer: quote: treat `core` and `std` as dependencies scripts: generate_rust_analyzer: syn: treat `std` as a dependency scripts: generate_rust_analyzer: remove sysroot assertion rust: kbuild: give `--config-path` to `rustfmt` in `.rsi` target scripts: generate_rust_analyzer: Add pin_init_internal deps scripts: generate_rust_analyzer: Add pin_init -> compiler_builtins dep scripts: generate_rust_analyzer: Add compiler_builtins -> core dep rust: macros: ignore example with module parameters rust: num: bounded: mark __new as unsafe ...
2 parents 03610bd + 5016cae commit 367b81e

16 files changed

Lines changed: 93 additions & 47 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,8 @@ MRPROPER_FILES += include/config include/generated \
16241624
certs/x509.genkey \
16251625
vmlinux-gdb.py \
16261626
rpmbuild \
1627-
rust/libmacros.so rust/libmacros.dylib
1627+
rust/libmacros.so rust/libmacros.dylib \
1628+
rust/libpin_init_internal.so rust/libpin_init_internal.dylib
16281629

16291630
# clean - Delete most, but leave enough to build external modules
16301631
#

drivers/gpu/drm/tyr/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ config DRM_TYR
66
depends on RUST
77
depends on ARM || ARM64 || COMPILE_TEST
88
depends on !GENERIC_ATOMIC64 # for IOMMU_IO_PGTABLE_LPAE
9+
depends on COMMON_CLK
910
default n
1011
help
1112
Rust DRM driver for ARM Mali CSF-based GPUs.

rust/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
383383
-fno-inline-functions-called-once -fsanitize=bounds-strict \
384384
-fstrict-flex-arrays=% -fmin-function-alignment=% \
385385
-fzero-init-padding-bits=% -mno-fdpic \
386+
-fdiagnostics-show-context -fdiagnostics-show-context=% \
386387
--param=% --param asan-% -fno-isolate-erroneous-paths-dereference
387388

388389
# Derived from `scripts/Makefile.clang`.

rust/kernel/bits.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ macro_rules! impl_bit_fn {
2727
///
2828
/// This version is the default and should be used if `n` is known at
2929
/// compile time.
30-
#[inline]
30+
// Always inline to optimize out error path of `build_assert`.
31+
#[inline(always)]
3132
pub const fn [<bit_ $ty>](n: u32) -> $ty {
3233
build_assert!(n < <$ty>::BITS);
3334
(1 as $ty) << n
@@ -75,7 +76,8 @@ macro_rules! impl_genmask_fn {
7576
/// This version is the default and should be used if the range is known
7677
/// at compile time.
7778
$(#[$genmask_ex])*
78-
#[inline]
79+
// Always inline to optimize out error path of `build_assert`.
80+
#[inline(always)]
7981
pub const fn [<genmask_ $ty>](range: RangeInclusive<u32>) -> $ty {
8082
let start = *range.start();
8183
let end = *range.end();

rust/kernel/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
pub use core::fmt::{Arguments, Debug, Error, Formatter, Result, Write};
88

9-
/// Internal adapter used to route allow implementations of formatting traits for foreign types.
9+
/// Internal adapter used to route and allow implementations of formatting traits for foreign types.
1010
///
1111
/// It is inserted automatically by the [`fmt!`] macro and is not meant to be used directly.
1212
///

rust/kernel/num/bounded.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ fn fits_within<T: Integer>(value: T, num_bits: u32) -> bool {
4040
fits_within!(value, T, num_bits)
4141
}
4242

43-
/// An integer value that requires only the `N` less significant bits of the wrapped type to be
43+
/// An integer value that requires only the `N` least significant bits of the wrapped type to be
4444
/// encoded.
4545
///
4646
/// This limits the number of usable bits in the wrapped integer type, and thus the stored value to
47-
/// a narrower range, which provides guarantees that can be useful when working with in e.g.
47+
/// a narrower range, which provides guarantees that can be useful when working within e.g.
4848
/// bitfields.
4949
///
5050
/// # Invariants
@@ -56,7 +56,7 @@ fn fits_within<T: Integer>(value: T, num_bits: u32) -> bool {
5656
/// # Examples
5757
///
5858
/// The preferred way to create values is through constants and the [`Bounded::new`] family of
59-
/// constructors, as they trigger a build error if the type invariants cannot be withheld.
59+
/// constructors, as they trigger a build error if the type invariants cannot be upheld.
6060
///
6161
/// ```
6262
/// use kernel::num::Bounded;
@@ -82,7 +82,7 @@ fn fits_within<T: Integer>(value: T, num_bits: u32) -> bool {
8282
/// ```
8383
/// use kernel::num::Bounded;
8484
///
85-
/// // This succeeds because `15` can be represented with 4 unsigned bits.
85+
/// // This succeeds because `15` can be represented with 4 unsigned bits.
8686
/// assert!(Bounded::<u8, 4>::try_new(15).is_some());
8787
///
8888
/// // This fails because `16` cannot be represented with 4 unsigned bits.
@@ -221,7 +221,7 @@ fn fits_within<T: Integer>(value: T, num_bits: u32) -> bool {
221221
/// let v: Option<Bounded<u16, 8>> = 128u32.try_into_bounded();
222222
/// assert_eq!(v.as_deref().copied(), Some(128));
223223
///
224-
/// // Fails because `128` doesn't fits into 6 bits.
224+
/// // Fails because `128` doesn't fit into 6 bits.
225225
/// let v: Option<Bounded<u16, 6>> = 128u32.try_into_bounded();
226226
/// assert_eq!(v, None);
227227
/// ```
@@ -259,9 +259,9 @@ macro_rules! impl_const_new {
259259
assert!(fits_within!(VALUE, $type, N));
260260
}
261261

262-
// INVARIANT: `fits_within` confirmed that `VALUE` can be represented within
262+
// SAFETY: `fits_within` confirmed that `VALUE` can be represented within
263263
// `N` bits.
264-
Self::__new(VALUE)
264+
unsafe { Self::__new(VALUE) }
265265
}
266266
}
267267
)*
@@ -282,9 +282,10 @@ where
282282
/// All instances of [`Bounded`] must be created through this method as it enforces most of the
283283
/// type invariants.
284284
///
285-
/// The caller remains responsible for checking, either statically or dynamically, that `value`
286-
/// can be represented as a `T` using at most `N` bits.
287-
const fn __new(value: T) -> Self {
285+
/// # Safety
286+
///
287+
/// The caller must ensure that `value` can be represented within `N` bits.
288+
const unsafe fn __new(value: T) -> Self {
288289
// Enforce the type invariants.
289290
const {
290291
// `N` cannot be zero.
@@ -293,6 +294,7 @@ where
293294
assert!(N <= T::BITS);
294295
}
295296

297+
// INVARIANT: The caller ensures `value` fits within `N` bits.
296298
Self(value)
297299
}
298300

@@ -328,8 +330,8 @@ where
328330
/// ```
329331
pub fn try_new(value: T) -> Option<Self> {
330332
fits_within(value, N).then(|| {
331-
// INVARIANT: `fits_within` confirmed that `value` can be represented within `N` bits.
332-
Self::__new(value)
333+
// SAFETY: `fits_within` confirmed that `value` can be represented within `N` bits.
334+
unsafe { Self::__new(value) }
333335
})
334336
}
335337

@@ -363,15 +365,16 @@ where
363365
/// assert_eq!(Bounded::<u8, 1>::from_expr(1).get(), 1);
364366
/// assert_eq!(Bounded::<u16, 8>::from_expr(0xff).get(), 0xff);
365367
/// ```
368+
// Always inline to optimize out error path of `build_assert`.
366369
#[inline(always)]
367370
pub fn from_expr(expr: T) -> Self {
368371
crate::build_assert!(
369372
fits_within(expr, N),
370373
"Requested value larger than maximal representable value."
371374
);
372375

373-
// INVARIANT: `fits_within` confirmed that `expr` can be represented within `N` bits.
374-
Self::__new(expr)
376+
// SAFETY: `fits_within` confirmed that `expr` can be represented within `N` bits.
377+
unsafe { Self::__new(expr) }
375378
}
376379

377380
/// Returns the wrapped value as the backing type.
@@ -410,9 +413,9 @@ where
410413
);
411414
}
412415

413-
// INVARIANT: The value did fit within `N` bits, so it will all the more fit within
416+
// SAFETY: The value did fit within `N` bits, so it will all the more fit within
414417
// the larger `M` bits.
415-
Bounded::__new(self.0)
418+
unsafe { Bounded::__new(self.0) }
416419
}
417420

418421
/// Attempts to shrink the number of bits usable for `self`.
@@ -466,9 +469,9 @@ where
466469
// `U` and `T` have the same sign, hence this conversion cannot fail.
467470
let value = unsafe { U::try_from(self.get()).unwrap_unchecked() };
468471

469-
// INVARIANT: Although the backing type has changed, the value is still represented within
472+
// SAFETY: Although the backing type has changed, the value is still represented within
470473
// `N` bits, and with the same signedness.
471-
Bounded::__new(value)
474+
unsafe { Bounded::__new(value) }
472475
}
473476
}
474477

@@ -501,7 +504,7 @@ where
501504
/// let v: Option<Bounded<u16, 8>> = 128u32.try_into_bounded();
502505
/// assert_eq!(v.as_deref().copied(), Some(128));
503506
///
504-
/// // Fails because `128` doesn't fits into 6 bits.
507+
/// // Fails because `128` doesn't fit into 6 bits.
505508
/// let v: Option<Bounded<u16, 6>> = 128u32.try_into_bounded();
506509
/// assert_eq!(v, None);
507510
/// ```
@@ -944,9 +947,9 @@ macro_rules! impl_from_primitive {
944947
Self: AtLeastXBits<{ <$type as Integer>::BITS as usize }>,
945948
{
946949
fn from(value: $type) -> Self {
947-
// INVARIANT: The trait bound on `Self` guarantees that `N` bits is
950+
// SAFETY: The trait bound on `Self` guarantees that `N` bits is
948951
// enough to hold any value of the source type.
949-
Self::__new(T::from(value))
952+
unsafe { Self::__new(T::from(value)) }
950953
}
951954
}
952955
)*
@@ -1051,8 +1054,8 @@ where
10511054
T: Integer + From<bool>,
10521055
{
10531056
fn from(value: bool) -> Self {
1054-
// INVARIANT: A boolean can be represented using a single bit, and thus fits within any
1057+
// SAFETY: A boolean can be represented using a single bit, and thus fits within any
10551058
// integer type for any `N` > 0.
1056-
Self::__new(T::from(value))
1059+
unsafe { Self::__new(T::from(value)) }
10571060
}
10581061
}

rust/kernel/rbtree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ impl<'a, K, V> CursorMut<'a, K, V> {
985985
self.peek(Direction::Prev)
986986
}
987987

988-
/// Access the previous node without moving the cursor.
988+
/// Access the next node without moving the cursor.
989989
pub fn peek_next(&self) -> Option<(&K, &V)> {
990990
self.peek(Direction::Next)
991991
}
@@ -1130,7 +1130,7 @@ pub struct IterMut<'a, K, V> {
11301130
}
11311131

11321132
// SAFETY: The [`IterMut`] has exclusive access to both `K` and `V`, so it is sufficient to require them to be `Send`.
1133-
// The iterator only gives out immutable references to the keys, but since the iterator has excusive access to those same
1133+
// The iterator only gives out immutable references to the keys, but since the iterator has exclusive access to those same
11341134
// keys, `Send` is sufficient. `Sync` would be okay, but it is more restrictive to the user.
11351135
unsafe impl<'a, K: Send, V: Send> Send for IterMut<'a, K, V> {}
11361136

rust/kernel/sync/atomic/predefine.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,23 @@ unsafe impl super::AtomicAdd<i64> for i64 {
3535
// as `isize` and `usize`, and `isize` and `usize` are always bi-directional transmutable to
3636
// `isize_atomic_repr`, which also always implements `AtomicImpl`.
3737
#[allow(non_camel_case_types)]
38+
#[cfg(not(testlib))]
3839
#[cfg(not(CONFIG_64BIT))]
3940
type isize_atomic_repr = i32;
4041
#[allow(non_camel_case_types)]
42+
#[cfg(not(testlib))]
4143
#[cfg(CONFIG_64BIT)]
4244
type isize_atomic_repr = i64;
4345

46+
#[allow(non_camel_case_types)]
47+
#[cfg(testlib)]
48+
#[cfg(target_pointer_width = "32")]
49+
type isize_atomic_repr = i32;
50+
#[allow(non_camel_case_types)]
51+
#[cfg(testlib)]
52+
#[cfg(target_pointer_width = "64")]
53+
type isize_atomic_repr = i64;
54+
4455
// Ensure size and alignment requirements are checked.
4556
static_assert!(size_of::<isize>() == size_of::<isize_atomic_repr>());
4657
static_assert!(align_of::<isize>() == align_of::<isize_atomic_repr>());

rust/kernel/sync/refcount.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl Refcount {
2323
/// Construct a new [`Refcount`] from an initial value.
2424
///
2525
/// The initial value should be non-saturated.
26-
#[inline]
26+
// Always inline to optimize out error path of `build_assert`.
27+
#[inline(always)]
2728
pub fn new(value: i32) -> Self {
2829
build_assert!(value >= 0, "initial value saturated");
2930
// SAFETY: There are no safety requirements for this FFI call.

rust/macros/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub(crate) fn fmt(input: TokenStream) -> TokenStream {
6767
}
6868
(None, acc)
6969
})();
70-
args.extend(quote_spanned!(first_span => #lhs #adapter(&#rhs)));
70+
args.extend(quote_spanned!(first_span => #lhs #adapter(&(#rhs))));
7171
}
7272
};
7373

0 commit comments

Comments
 (0)