]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Merge tag 'rust-timekeeping-for-v7.1' of https://github.com/Rust-for-Linux/linux...
authorMiguel Ojeda <ojeda@kernel.org>
Wed, 8 Apr 2026 07:46:01 +0000 (09:46 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 8 Apr 2026 08:44:11 +0000 (10:44 +0200)
Pull timekeeping updates from Andreas Hindborg:

 - Expand the example section in the 'HrTimer' documentation.

 - Mark the 'ClockSource' trait as unsafe to ensure valid values for
   'ktime_get()'.

 - Add 'Delta::from_nanos()'.

This is a back merge since the pull request has a newer base -- we will
avoid that in the future.

And, given it is a back merge, it happens to resolve the "subtle" conflict
around '--remap-path-{prefix,scope}' that I discussed in linux-next [1],
plus a few other common conflicts. The result matches what we did for
next-20260407.

The actual diffstat (i.e. using a temporary merge of upstream first) is:

    rust/kernel/time.rs         |  32 ++++-
    rust/kernel/time/hrtimer.rs | 336 ++++++++++++++++++++++++++++++++++++++++++++
    2 files changed, 362 insertions(+), 6 deletions(-)

Link: https://lore.kernel.org/linux-next/CANiq72kdxB=W3_CV1U44oOK3SssztPo2wLDZt6LP94TEO+Kj4g@mail.gmail.com/
* tag 'rust-timekeeping-for-v7.1' of https://github.com/Rust-for-Linux/linux:
  hrtimer: add usage examples to documentation
  rust: time: make ClockSource unsafe trait
  rust/time: Add Delta::from_nanos()

1  2 
MAINTAINERS
Makefile
drivers/android/binder/page_range.rs
drivers/gpu/nova-core/gsp/cmdq.rs
rust/Makefile
rust/kernel/ptr.rs
rust/kernel/str.rs

diff --cc MAINTAINERS
Simple merge
diff --cc Makefile
Simple merge
Simple merge
Simple merge
diff --cc rust/Makefile
index 866f9afc1b7f8181bd09109d0ac5ed5e6f906fec,9801af2e1e027a720918284361b598ad846834f5..bfa1b77c9671d50cbc5b3d9d819dd8716b6fa267
@@@ -145,7 -144,12 +145,7 @@@ doctests_modifiers_workaround := $(rust
  quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
        cmd_rustdoc = \
        OBJTREE=$(abspath $(objtree)) \
-       $(RUSTDOC) $(filter-out $(skip_flags),$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
 -      $(RUSTDOC) $(filter-out $(skip_flags) --remap-path-prefix=% --remap-path-scope=%, \
 -                      $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
++      $(RUSTDOC) $(filter-out $(skip_flags) --remap-path-scope=%,$(if $(rustdoc_host),$(rust_common_flags),$(rust_flags))) \
                $(rustc_target_flags) -L$(objtree)/$(obj) \
                -Zunstable-options --generate-link-to-definition \
                --output $(rustdoc_output) \
@@@ -329,7 -335,7 +329,7 @@@ quiet_cmd_rustdoc_test_kernel = RUSTDO
        rm -rf $(objtree)/$(obj)/test/doctests/kernel; \
        mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
        OBJTREE=$(abspath $(objtree)) \
-       $(RUSTDOC) --test $(rust_flags) \
 -      $(RUSTDOC) --test $(filter-out --remap-path-prefix=% --remap-path-scope=%,$(rust_flags)) \
++      $(RUSTDOC) --test $(filter-out --remap-path-scope=%,$(rust_flags)) \
                -L$(objtree)/$(obj) --extern ffi --extern pin_init \
                --extern kernel --extern build_error --extern macros \
                --extern bindings --extern uapi \
index 91811f5e27de0d782a809ab8721e016cdb2a683b,bdc2d79ff6699d7583eeda4d75779dcfaacec94b..3f3e529e9f5822954d91ccc4de7cad7a860224c7
@@@ -2,11 -2,15 +2,17 @@@
  
  //! Types and functions to work with pointers and addresses.
  
- use core::mem::align_of;
+ pub mod projection;
+ pub use crate::project_pointer as project;
+ use core::mem::{
+     align_of,
+     size_of, //
+ };
  use core::num::NonZero;
  
 +use crate::const_assert;
 +
  /// Type representing an alignment, which is always a power of two.
  ///
  /// It is used to validate that a given value is a valid alignment, and to perform masking and
@@@ -225,31 -232,24 +231,53 @@@ macro_rules! impl_alignable_uint 
  
  impl_alignable_uint!(u8, u16, u32, u64, usize);
  
+ /// Trait to represent compile-time known size information.
+ ///
+ /// This is a generalization of [`size_of`] that works for dynamically sized types.
+ pub trait KnownSize {
+     /// Get the size of an object of this type in bytes, with the metadata of the given pointer.
+     fn size(p: *const Self) -> usize;
+ }
+ impl<T> KnownSize for T {
+     #[inline(always)]
+     fn size(_: *const Self) -> usize {
+         size_of::<T>()
+     }
+ }
+ impl<T> KnownSize for [T] {
+     #[inline(always)]
+     fn size(p: *const Self) -> usize {
+         p.len() * size_of::<T>()
+     }
+ }
++
 +/// Aligns `value` up to `align`.
 +///
 +/// This is the const-compatible equivalent of [`Alignable::align_up`].
 +///
 +/// Returns [`None`] on overflow.
 +///
 +/// # Examples
 +///
 +/// ```
 +/// use kernel::{
 +///     ptr::{
 +///         const_align_up,
 +///         Alignment, //
 +///     },
 +///     sizes::SZ_4K, //
 +/// };
 +///
 +/// assert_eq!(const_align_up(0x4f, Alignment::new::<16>()), Some(0x50));
 +/// assert_eq!(const_align_up(0x40, Alignment::new::<16>()), Some(0x40));
 +/// assert_eq!(const_align_up(1, Alignment::new::<SZ_4K>()), Some(SZ_4K));
 +/// ```
 +#[inline(always)]
 +pub const fn const_align_up(value: usize, align: Alignment) -> Option<usize> {
 +    match value.checked_add(align.as_usize() - 1) {
 +        Some(v) => Some(v & align.mask()),
 +        None => None,
 +    }
 +}
Simple merge