Pull rust fixes from Miguel Ojeda: "Toolchain and infrastructure: - Fix missing KASAN LLVM flags on first build (and fix spurious rebuilds) by skipping '--target' - Fix Make < 4.3 build error by using '$(pound)' - Fix UML build error by removing 'volatile' qualifier from io helpers - Fix UML build error by adding 'dma_{alloc,free}_attrs()' helpers - Clean gendwarfksyms warnings by avoiding to export '__pfx' symbols - Clean objtool warning by adding a new 'noreturn' function for 1.86.0 - Disable 'needless_continue' Clippy lint due to new 1.86.0 warnings - Add missing 'ffi' crate to 'generate_rust_analyzer.py' 'pin-init' crate: - Import a couple fixes from upstream" * tag 'rust-fixes-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: rust: helpers: Add dma_alloc_attrs() and dma_free_attrs() rust: helpers: Remove volatile qualifier from io helpers rust: kbuild: use `pound` to support GNU Make < 4.3 objtool/rust: add one more `noreturn` Rust function for Rust 1.86.0 rust: kasan/kbuild: fix missing flags on first build rust: disable `clippy::needless_continue` rust: kbuild: Don't export __pfx symbols rust: pin-init: use Markdown autolinks in Rust comments rust: pin-init: alloc: restrict `impl ZeroableOption` for `Box` to `T: Sized` scripts: generate_rust_analyzer: Add ffi crate
Unified · Split
| @@ -7021,6 +7021,7 @@ L: rust-for-linux@vger.kernel.org · 7020 unmodified lines | |||
| 7021 | S: Supported | 7021 | S: Supported |
| 7022 | W: https://rust-for-linux.com | 7022 | W: https://rust-for-linux.com |
| 7023 | T: git https://github.com/Rust-for-Linux/linux.git alloc-next | 7023 | T: git https://github.com/Rust-for-Linux/linux.git alloc-next |
| 7024 | F: rust/helpers/dma.c | ||
| 7024 | F: rust/kernel/dma.rs | 7025 | F: rust/kernel/dma.rs |
| 7025 | F: samples/rust/rust_dma.rs | 7026 | F: samples/rust/rust_dma.rs |
| 7026 | 7027 | ||
| @@ -477,7 +477,6 @@ export rust_common_flags := --edition=2021 \ · 476 unmodified lines | |||
| 477 | -Wclippy::ignored_unit_patterns \ | 477 | -Wclippy::ignored_unit_patterns \ |
| 478 | -Wclippy::mut_mut \ | 478 | -Wclippy::mut_mut \ |
| 479 | -Wclippy::needless_bitwise_bool \ | 479 | -Wclippy::needless_bitwise_bool \ |
| 480 | -Wclippy::needless_continue \ | ||
| 481 | -Aclippy::needless_lifetimes \ | 480 | -Aclippy::needless_lifetimes \ |
| 482 | -Wclippy::no_mangle_with_rust_abi \ | 481 | -Wclippy::no_mangle_with_rust_abi \ |
| 483 | -Wclippy::undocumented_unsafe_blocks \ | 482 | -Wclippy::undocumented_unsafe_blocks \ |
| @@ -368,7 +368,7 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · 367 unmodified lines | |||
| 368 | $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE | 368 | $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE |
| 369 | $(call if_changed_dep,bindgen) | 369 | $(call if_changed_dep,bindgen) |
| 370 | 370 | ||
| 371 | rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ && $$3!~/__odr_asan/ { printf $(2),$$3 }' | 371 | rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(pfx|cfi|odr_asan)/ { printf $(2),$$3 }' |
| 372 | 372 | ||
| 373 | quiet_cmd_exports = EXPORTS $@ | 373 | quiet_cmd_exports = EXPORTS $@ |
| 374 | cmd_exports = \ | 374 | cmd_exports = \ |
| @@ -0,0 +1,16 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | |||
| 3 | #include <linux/dma-mapping.h> | ||
| 4 | |||
| 5 | void *rust_helper_dma_alloc_attrs(struct device *dev, size_t size, | ||
| 6 | dma_addr_t *dma_handle, gfp_t flag, | ||
| 7 | unsigned long attrs) | ||
| 8 | { | ||
| 9 | return dma_alloc_attrs(dev, size, dma_handle, flag, attrs); | ||
| 10 | } | ||
| 11 | |||
| 12 | void rust_helper_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, | ||
| 13 | dma_addr_t dma_handle, unsigned long attrs) | ||
| 14 | { | ||
| 15 | dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs); | ||
| 16 | } | ||
| @@ -14,6 +14,7 @@ · 13 unmodified lines | |||
| 14 | #include "cpumask.c" | 14 | #include "cpumask.c" |
| 15 | #include "cred.c" | 15 | #include "cred.c" |
| 16 | #include "device.c" | 16 | #include "device.c" |
| 17 | #include "dma.c" | ||
| 17 | #include "err.c" | 18 | #include "err.c" |
| 18 | #include "fs.c" | 19 | #include "fs.c" |
| 19 | #include "io.c" | 20 | #include "io.c" |
| @@ -7,94 +7,94 @@ void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size) · 6 unmodified lines | |||
| 7 | return ioremap(offset, size); | 7 | return ioremap(offset, size); |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | void rust_helper_iounmap(volatile void __iomem *addr) | 10 | void rust_helper_iounmap(void __iomem *addr) |
| 11 | { | 11 | { |
| 12 | iounmap(addr); | 12 | iounmap(addr); |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | u8 rust_helper_readb(const volatile void __iomem *addr) | 15 | u8 rust_helper_readb(const void __iomem *addr) |
| 16 | { | 16 | { |
| 17 | return readb(addr); | 17 | return readb(addr); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | u16 rust_helper_readw(const volatile void __iomem *addr) | 20 | u16 rust_helper_readw(const void __iomem *addr) |
| 21 | { | 21 | { |
| 22 | return readw(addr); | 22 | return readw(addr); |
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | u32 rust_helper_readl(const volatile void __iomem *addr) | 25 | u32 rust_helper_readl(const void __iomem *addr) |
| 26 | { | 26 | { |
| 27 | return readl(addr); | 27 | return readl(addr); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | #ifdef CONFIG_64BIT | 30 | #ifdef CONFIG_64BIT |
| 31 | u64 rust_helper_readq(const volatile void __iomem *addr) | 31 | u64 rust_helper_readq(const void __iomem *addr) |
| 32 | { | 32 | { |
| 33 | return readq(addr); | 33 | return readq(addr); |
| 34 | } | 34 | } |
| 35 | #endif | 35 | #endif |
| 36 | 36 | ||
| 37 | void rust_helper_writeb(u8 value, volatile void __iomem *addr) | 37 | void rust_helper_writeb(u8 value, void __iomem *addr) |
| 38 | { | 38 | { |
| 39 | writeb(value, addr); | 39 | writeb(value, addr); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | void rust_helper_writew(u16 value, volatile void __iomem *addr) | 42 | void rust_helper_writew(u16 value, void __iomem *addr) |
| 43 | { | 43 | { |
| 44 | writew(value, addr); | 44 | writew(value, addr); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | void rust_helper_writel(u32 value, volatile void __iomem *addr) | 47 | void rust_helper_writel(u32 value, void __iomem *addr) |
| 48 | { | 48 | { |
| 49 | writel(value, addr); | 49 | writel(value, addr); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | #ifdef CONFIG_64BIT | 52 | #ifdef CONFIG_64BIT |
| 53 | void rust_helper_writeq(u64 value, volatile void __iomem *addr) | 53 | void rust_helper_writeq(u64 value, void __iomem *addr) |
| 54 | { | 54 | { |
| 55 | writeq(value, addr); | 55 | writeq(value, addr); |
| 56 | } | 56 | } |
| 57 | #endif | 57 | #endif |
| 58 | 58 | ||
| 59 | u8 rust_helper_readb_relaxed(const volatile void __iomem *addr) | 59 | u8 rust_helper_readb_relaxed(const void __iomem *addr) |
| 60 | { | 60 | { |
| 61 | return readb_relaxed(addr); | 61 | return readb_relaxed(addr); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | u16 rust_helper_readw_relaxed(const volatile void __iomem *addr) | 64 | u16 rust_helper_readw_relaxed(const void __iomem *addr) |
| 65 | { | 65 | { |
| 66 | return readw_relaxed(addr); | 66 | return readw_relaxed(addr); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | u32 rust_helper_readl_relaxed(const volatile void __iomem *addr) | 69 | u32 rust_helper_readl_relaxed(const void __iomem *addr) |
| 70 | { | 70 | { |
| 71 | return readl_relaxed(addr); | 71 | return readl_relaxed(addr); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | #ifdef CONFIG_64BIT | 74 | #ifdef CONFIG_64BIT |
| 75 | u64 rust_helper_readq_relaxed(const volatile void __iomem *addr) | 75 | u64 rust_helper_readq_relaxed(const void __iomem *addr) |
| 76 | { | 76 | { |
| 77 | return readq_relaxed(addr); | 77 | return readq_relaxed(addr); |
| 78 | } | 78 | } |
| 79 | #endif | 79 | #endif |
| 80 | 80 | ||
| 81 | void rust_helper_writeb_relaxed(u8 value, volatile void __iomem *addr) | 81 | void rust_helper_writeb_relaxed(u8 value, void __iomem *addr) |
| 82 | { | 82 | { |
| 83 | writeb_relaxed(value, addr); | 83 | writeb_relaxed(value, addr); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | void rust_helper_writew_relaxed(u16 value, volatile void __iomem *addr) | 86 | void rust_helper_writew_relaxed(u16 value, void __iomem *addr) |
| 87 | { | 87 | { |
| 88 | writew_relaxed(value, addr); | 88 | writew_relaxed(value, addr); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | void rust_helper_writel_relaxed(u32 value, volatile void __iomem *addr) | 91 | void rust_helper_writel_relaxed(u32 value, void __iomem *addr) |
| 92 | { | 92 | { |
| 93 | writel_relaxed(value, addr); | 93 | writel_relaxed(value, addr); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | #ifdef CONFIG_64BIT | 96 | #ifdef CONFIG_64BIT |
| 97 | void rust_helper_writeq_relaxed(u64 value, volatile void __iomem *addr) | 97 | void rust_helper_writeq_relaxed(u64 value, void __iomem *addr) |
| 98 | { | 98 | { |
| 99 | writeq_relaxed(value, addr); | 99 | writeq_relaxed(value, addr); |
| 100 | } | 100 | } |
| @@ -1,6 +1,6 @@ | |||
| 1 | // SPDX-License-Identifier: Apache-2.0 OR MIT | 1 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
| 2 | 2 | ||
| 3 | // inspired by https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs | 3 | // inspired by <https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs> |
| 4 | #![allow(clippy::undocumented_unsafe_blocks)] | 4 | #![allow(clippy::undocumented_unsafe_blocks)] |
| 5 | #![cfg_attr(feature = "alloc", feature(allocator_api))] | 5 | #![cfg_attr(feature = "alloc", feature(allocator_api))] |
| 6 | #[cfg(not(windows))] | 6 | #[cfg(not(windows))] |
| @@ -17,11 +17,9 @@ use crate::{ · 16 unmodified lines | |||
| 17 | 17 | ||
| 18 | pub extern crate alloc; | 18 | pub extern crate alloc; |
| 19 | 19 | ||
| 20 | // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee). | 20 | // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee: |
| 21 | // | 21 | // <https://doc.rust-lang.org/stable/std/option/index.html#representation>). |
| 22 | // In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant and there | 22 | unsafe impl<T> ZeroableOption for Box<T> {} |
| 23 | // is no problem with a VTABLE pointer being null. | ||
| 24 | unsafe impl<T: ?Sized> ZeroableOption for Box<T> {} | ||
| 25 | 23 | ||
| 26 | /// Smart pointer that can initialize memory in-place. | 24 | /// Smart pointer that can initialize memory in-place. |
| 27 | pub trait InPlaceInit<T>: Sized { | 25 | pub trait InPlaceInit<T>: Sized { |
| @@ -1447,7 +1447,7 @@ impl_zeroable! { · 1446 unmodified lines | |||
| 1447 | {<T: ?Sized + Zeroable>} UnsafeCell<T>, | 1447 | {<T: ?Sized + Zeroable>} UnsafeCell<T>, |
| 1448 | 1448 | ||
| 1449 | // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee: | 1449 | // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee: |
| 1450 | // https://doc.rust-lang.org/stable/std/option/index.html#representation). | 1450 | // <https://doc.rust-lang.org/stable/std/option/index.html#representation>). |
| 1451 | Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>, | 1451 | Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>, |
| 1452 | Option<NonZeroU128>, Option<NonZeroUsize>, | 1452 | Option<NonZeroU128>, Option<NonZeroUsize>, |
| 1453 | Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>, | 1453 | Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>, |
| @@ -79,8 +79,8 @@ ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) · 78 unmodified lines | |||
| 79 | # Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage) | 79 | # Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage) |
| 80 | # TODO: remove RUSTC_BOOTSTRAP=1 when we raise the minimum GNU Make version to 4.4 | 80 | # TODO: remove RUSTC_BOOTSTRAP=1 when we raise the minimum GNU Make version to 4.4 |
| 81 | __rustc-option = $(call try-run,\ | 81 | __rustc-option = $(call try-run,\ |
| 82 | echo '#![allow(missing_docs)]#![feature(no_core)]#![no_core]' | RUSTC_BOOTSTRAP=1\ | 82 | echo '$(pound)![allow(missing_docs)]$(pound)![feature(no_core)]$(pound)![no_core]' | RUSTC_BOOTSTRAP=1\ |
| 83 | $(1) --sysroot=/dev/null $(filter-out --sysroot=/dev/null,$(2)) $(3)\ | 83 | $(1) --sysroot=/dev/null $(filter-out --sysroot=/dev/null --target=%,$(2)) $(3)\ |
| 84 | --crate-type=rlib --out-dir=$(TMPOUT) --emit=obj=- - >/dev/null,$(3),$(4)) | 84 | --crate-type=rlib --out-dir=$(TMPOUT) --emit=obj=- - >/dev/null,$(3),$(4)) |
| 85 | 85 | ||
| 86 | # rustc-option | 86 | # rustc-option |
| @@ -112,6 +112,12 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): · 111 unmodified lines | |||
| 112 | cfg=["kernel"], | 112 | cfg=["kernel"], |
| 113 | ) | 113 | ) |
| 114 | 114 | ||
| 115 | append_crate( | ||
| 116 | "ffi", | ||
| 117 | srctree / "rust" / "ffi.rs", | ||
| 118 | ["core", "compiler_builtins"], | ||
| 119 | ) | ||
| 120 | |||
| 115 | def append_crate_with_generated( | 121 | def append_crate_with_generated( |
| 116 | display_name, | 122 | display_name, |
| 117 | deps, | 123 | deps, |
| @@ -131,9 +137,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): · 13 unmodified lines | |||
| 131 | "exclude_dirs": [], | 137 | "exclude_dirs": [], |
| 132 | } | 138 | } |
| 133 | 139 | ||
| 134 | append_crate_with_generated("bindings", ["core"]) | 140 | append_crate_with_generated("bindings", ["core", "ffi"]) |
| 135 | append_crate_with_generated("uapi", ["core"]) | 141 | append_crate_with_generated("uapi", ["core", "ffi"]) |
| 136 | append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "bindings", "uapi"]) | 142 | append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "ffi", "bindings", "uapi"]) |
| 137 | 143 | ||
| 138 | def is_root_crate(build_file, target): | 144 | def is_root_crate(build_file, target): |
| 139 | try: | 145 | try: |
| @@ -225,6 +225,7 @@ static bool is_rust_noreturn(const struct symbol *func) · 224 unmodified lines | |||
| 225 | str_ends_with(func->name, "_4core9panicking14panic_nounwind") || | 225 | str_ends_with(func->name, "_4core9panicking14panic_nounwind") || |
| 226 | str_ends_with(func->name, "_4core9panicking18panic_bounds_check") || | 226 | str_ends_with(func->name, "_4core9panicking18panic_bounds_check") || |
| 227 | str_ends_with(func->name, "_4core9panicking19assert_failed_inner") || | 227 | str_ends_with(func->name, "_4core9panicking19assert_failed_inner") || |
| 228 | str_ends_with(func->name, "_4core9panicking30panic_null_pointer_dereference") || | ||
| 228 | str_ends_with(func->name, "_4core9panicking36panic_misaligned_pointer_dereference") || | 229 | str_ends_with(func->name, "_4core9panicking36panic_misaligned_pointer_dereference") || |
| 229 | strstr(func->name, "_4core9panicking13assert_failed") || | 230 | strstr(func->name, "_4core9panicking13assert_failed") || |
| 230 | strstr(func->name, "_4core9panicking11panic_const24panic_const_") || | 231 | strstr(func->name, "_4core9panicking11panic_const24panic_const_") || |