Skip to content

Commit f4e0ff7

Browse files
committed
Merge tag 'rust-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull rust updates from Miguel Ojeda: "Toolchain and infrastructure: - Derive 'Zeroable' for all structs and unions generated by 'bindgen' where possible and corresponding cleanups. To do so, add the 'pin-init' crate as a dependency to 'bindings' and 'uapi'. It also includes its first use in the 'cpufreq' module, with more to come in the next cycle. - Add warning to the 'rustdoc' target to detect broken 'srctree/' links and fix existing cases. - Remove support for unused (since v6.16) host '#[test]'s, simplifying the 'rusttest' target. Tests should generally run within KUnit. 'kernel' crate: - Add 'ptr' module with a new 'Alignment' type, which is always a power of two and is used to validate that a given value is a valid alignment and to perform masking and alignment operations: // Checked at build time. assert_eq!(Alignment::new::<16>().as_usize(), 16); // Checked at runtime. assert_eq!(Alignment::new_checked(15), None); assert_eq!(Alignment::of::<u8>().log2(), 0); assert_eq!(0x25u8.align_down(Alignment::new::<0x10>()), 0x20); assert_eq!(0x5u8.align_up(Alignment::new::<0x10>()), Some(0x10)); assert_eq!(u8::MAX.align_up(Alignment::new::<0x10>()), None); It also includes its first use in Nova. - Add 'core::mem::{align,size}_of{,_val}' to the prelude, matching Rust 1.80.0. - Keep going with the steps on our migration to the standard library 'core::ffi::CStr' type (use 'kernel::{fmt, prelude::fmt!}' and use upstream method names). - 'error' module: improve 'Error::from_errno' and 'to_result' documentation, including examples/tests. - 'sync' module: extend 'aref' submodule documentation now that it exists, and more updates to complete the ongoing move of 'ARef' and 'AlwaysRefCounted' to 'sync::aref'. - 'list' module: add an example/test for 'ListLinksSelfPtr' usage. - 'alloc' module: - Implement 'Box::pin_slice()', which constructs a pinned slice of elements. - Provide information about the minimum alignment guarantees of 'Kmalloc', 'Vmalloc' and 'KVmalloc'. - Take minimum alignment guarantees of allocators for 'ForeignOwnable' into account. - Remove the 'allocator_test' (including 'Cmalloc'). - Add doctest for 'Vec::as_slice()'. - Constify various methods. - 'time' module: - Add methods on 'HrTimer' that can only be called with exclusive access to an unarmed timer, or from timer callback context. - Add arithmetic operations to 'Instant' and 'Delta'. - Add a few convenience and access methods to 'HrTimer' and 'Instant'. 'macros' crate: - Reduce collections in 'quote!' macro. And a few other cleanups and improvements" * tag 'rust-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (58 commits) gpu: nova-core: use Alignment for alignment-related operations rust: add `Alignment` type rust: macros: reduce collections in `quote!` macro rust: acpi: use `core::ffi::CStr` method names rust: of: use `core::ffi::CStr` method names rust: net: use `core::ffi::CStr` method names rust: miscdevice: use `core::ffi::CStr` method names rust: kunit: use `core::ffi::CStr` method names rust: firmware: use `core::ffi::CStr` method names rust: drm: use `core::ffi::CStr` method names rust: cpufreq: use `core::ffi::CStr` method names rust: configfs: use `core::ffi::CStr` method names rust: auxiliary: use `core::ffi::CStr` method names drm/panic: use `core::ffi::CStr` method names rust: device: use `kernel::{fmt,prelude::fmt!}` rust: sync: use `kernel::{fmt,prelude::fmt!}` rust: seq_file: use `kernel::{fmt,prelude::fmt!}` rust: kunit: use `kernel::{fmt,prelude::fmt!}` rust: file: use `kernel::{fmt,prelude::fmt!}` rust: device: use `kernel::{fmt,prelude::fmt!}` ...
2 parents ae28ed4 + f3f6b36 commit f4e0ff7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1054
-315
lines changed

Documentation/gpu/nova/core/todo.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ Numerical operations [NUMM]
147147
Nova uses integer operations that are not part of the standard library (or not
148148
implemented in an optimized way for the kernel). These include:
149149

150-
- Aligning up and down to a power of two,
151150
- The "Find Last Set Bit" (`fls` function of the C part of the kernel)
152151
operation.
153152

drivers/block/rnull.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl kernel::InPlaceModule for NullBlkModule {
5151
.logical_block_size(4096)?
5252
.physical_block_size(4096)?
5353
.rotational(false)
54-
.build(format_args!("rnullb{}", 0), tagset)
54+
.build(fmt!("rnullb{}", 0), tagset)
5555
})();
5656

5757
try_pin_init!(Self {

drivers/gpu/drm/drm_panic_qr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ pub unsafe extern "C" fn drm_panic_qr_generate(
968968
// nul-terminated string.
969969
let url_cstr: &CStr = unsafe { CStr::from_char_ptr(url) };
970970
let segments = &[
971-
&Segment::Binary(url_cstr.as_bytes()),
971+
&Segment::Binary(url_cstr.to_bytes()),
972972
&Segment::Numeric(&data_slice[0..data_len]),
973973
];
974974
match EncodedMsg::new(segments, tmp_slice) {

drivers/gpu/nova-core/fb.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use core::ops::Range;
44

55
use kernel::prelude::*;
6+
use kernel::ptr::{Alignable, Alignment};
67
use kernel::sizes::*;
78
use kernel::types::ARef;
89
use kernel::{dev_warn, device};
@@ -130,10 +131,9 @@ impl FbLayout {
130131
};
131132

132133
let frts = {
133-
const FRTS_DOWN_ALIGN: u64 = SZ_128K as u64;
134+
const FRTS_DOWN_ALIGN: Alignment = Alignment::new::<SZ_128K>();
134135
const FRTS_SIZE: u64 = SZ_1M as u64;
135-
// TODO[NUMM]: replace with `align_down` once it lands.
136-
let frts_base = (vga_workspace.start & !(FRTS_DOWN_ALIGN - 1)) - FRTS_SIZE;
136+
let frts_base = vga_workspace.start.align_down(FRTS_DOWN_ALIGN) - FRTS_SIZE;
137137

138138
frts_base..frts_base + FRTS_SIZE
139139
};

drivers/gpu/nova-core/gpu.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3-
use kernel::{device, devres::Devres, error::code::*, pci, prelude::*, sync::Arc};
3+
use kernel::{device, devres::Devres, error::code::*, fmt, pci, prelude::*, sync::Arc};
44

55
use crate::driver::Bar0;
66
use crate::falcon::{gsp::Gsp, sec2::Sec2, Falcon};
@@ -12,7 +12,6 @@ use crate::gfw;
1212
use crate::regs;
1313
use crate::util;
1414
use crate::vbios::Vbios;
15-
use core::fmt;
1615

1716
macro_rules! define_chipset {
1817
({ $($variant:ident = $value:expr),* $(,)* }) =>

drivers/gpu/nova-core/regs/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ macro_rules! register {
149149

150150
// TODO[REGA]: display the raw hex value, then the value of all the fields. This requires
151151
// matching the fields, which will complexify the syntax considerably...
152-
impl ::core::fmt::Debug for $name {
153-
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
152+
impl ::kernel::fmt::Debug for $name {
153+
fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kernel::fmt::Result {
154154
f.debug_tuple(stringify!($name))
155-
.field(&format_args!("0x{0:x}", &self.0))
155+
.field(&::kernel::prelude::fmt!("0x{0:x}", &self.0))
156156
.finish()
157157
}
158158
}

drivers/gpu/nova-core/vbios.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use kernel::device;
1010
use kernel::error::Result;
1111
use kernel::pci;
1212
use kernel::prelude::*;
13+
use kernel::ptr::{Alignable, Alignment};
1314

1415
/// The offset of the VBIOS ROM in the BAR0 space.
1516
const ROM_OFFSET: usize = 0x300000;
@@ -177,8 +178,7 @@ impl<'a> Iterator for VbiosIterator<'a> {
177178

178179
// Advance to next image (aligned to 512 bytes).
179180
self.current_offset += image_size;
180-
// TODO[NUMM]: replace with `align_up` once it lands.
181-
self.current_offset = self.current_offset.next_multiple_of(512);
181+
self.current_offset = self.current_offset.align_up(Alignment::new::<512>())?;
182182

183183
Some(Ok(full_image))
184184
}

rust/Makefile

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
9898
# and then retouch the generated files.
9999
rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
100100
rustdoc-kernel rustdoc-pin_init
101+
$(Q)grep -Ehro '<a href="srctree/([^"]+)"' $(rustdoc_output) | \
102+
cut -d'"' -f2 | cut -d/ -f2- | while read f; do \
103+
if [ ! -e "$(srctree)/$$f" ]; then \
104+
echo "warning: srctree/ link to $$f does not exist"; \
105+
fi \
106+
done
101107
$(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/
102108
$(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/
103109
$(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
@@ -193,12 +199,12 @@ rusttestlib-kernel: $(src)/kernel/lib.rs rusttestlib-bindings rusttestlib-uapi \
193199
$(obj)/bindings.o FORCE
194200
+$(call if_changed,rustc_test_library)
195201

196-
rusttestlib-bindings: private rustc_target_flags = --extern ffi
197-
rusttestlib-bindings: $(src)/bindings/lib.rs rusttestlib-ffi FORCE
202+
rusttestlib-bindings: private rustc_target_flags = --extern ffi --extern pin_init
203+
rusttestlib-bindings: $(src)/bindings/lib.rs rusttestlib-ffi rusttestlib-pin_init FORCE
198204
+$(call if_changed,rustc_test_library)
199205

200-
rusttestlib-uapi: private rustc_target_flags = --extern ffi
201-
rusttestlib-uapi: $(src)/uapi/lib.rs rusttestlib-ffi FORCE
206+
rusttestlib-uapi: private rustc_target_flags = --extern ffi --extern pin_init
207+
rusttestlib-uapi: $(src)/uapi/lib.rs rusttestlib-ffi rusttestlib-pin_init FORCE
202208
+$(call if_changed,rustc_test_library)
203209

204210
quiet_cmd_rustdoc_test = RUSTDOC T $<
@@ -248,7 +254,7 @@ quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T $<
248254
$(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
249255
$(rustc_test_run_flags)
250256

251-
rusttest: rusttest-macros rusttest-kernel
257+
rusttest: rusttest-macros
252258

253259
rusttest-macros: private rustc_target_flags = --extern proc_macro \
254260
--extern macros --extern kernel --extern pin_init
@@ -258,13 +264,6 @@ rusttest-macros: $(src)/macros/lib.rs \
258264
+$(call if_changed,rustc_test)
259265
+$(call if_changed,rustdoc_test)
260266

261-
rusttest-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
262-
--extern build_error --extern macros --extern bindings --extern uapi
263-
rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \
264-
rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
265-
rusttestlib-uapi rusttestlib-pin_init FORCE
266-
+$(call if_changed,rustc_test)
267-
268267
ifdef CONFIG_CC_IS_CLANG
269268
bindgen_c_flags = $(c_flags)
270269
else
@@ -531,17 +530,19 @@ $(obj)/ffi.o: private skip_gendwarfksyms = 1
531530
$(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE
532531
+$(call if_changed_rule,rustc_library)
533532

534-
$(obj)/bindings.o: private rustc_target_flags = --extern ffi
533+
$(obj)/bindings.o: private rustc_target_flags = --extern ffi --extern pin_init
535534
$(obj)/bindings.o: $(src)/bindings/lib.rs \
536535
$(obj)/ffi.o \
536+
$(obj)/pin_init.o \
537537
$(obj)/bindings/bindings_generated.rs \
538538
$(obj)/bindings/bindings_helpers_generated.rs FORCE
539539
+$(call if_changed_rule,rustc_library)
540540

541-
$(obj)/uapi.o: private rustc_target_flags = --extern ffi
541+
$(obj)/uapi.o: private rustc_target_flags = --extern ffi --extern pin_init
542542
$(obj)/uapi.o: private skip_gendwarfksyms = 1
543543
$(obj)/uapi.o: $(src)/uapi/lib.rs \
544544
$(obj)/ffi.o \
545+
$(obj)/pin_init.o \
545546
$(obj)/uapi/uapi_generated.rs FORCE
546547
+$(call if_changed_rule,rustc_library)
547548

rust/bindgen_parameters

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@
3434
# We use const helpers to aid bindgen, to avoid conflicts when constants are
3535
# recognized, block generation of the non-helper constants.
3636
--blocklist-item ARCH_SLAB_MINALIGN
37+
--blocklist-item ARCH_KMALLOC_MINALIGN
38+
39+
# Structs should implement `Zeroable` when all of their fields do.
40+
--with-derive-custom-struct .*=MaybeZeroable
41+
--with-derive-custom-union .*=MaybeZeroable

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484

8585
/* `bindgen` gets confused at certain things. */
8686
const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
87+
const size_t RUST_CONST_HELPER_ARCH_KMALLOC_MINALIGN = ARCH_KMALLOC_MINALIGN;
8788
const size_t RUST_CONST_HELPER_PAGE_SIZE = PAGE_SIZE;
8889
const gfp_t RUST_CONST_HELPER_GFP_ATOMIC = GFP_ATOMIC;
8990
const gfp_t RUST_CONST_HELPER_GFP_KERNEL = GFP_KERNEL;

0 commit comments

Comments
 (0)