History

Merge tag 'rust-fixes-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux

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

Linus Torvalds committed 1 year ago

Commit 0bd2f262 parents 51c7960 c1b407112 files · +53 −31Browse files

Unified · Split

12 files
  1. MAINTAINERS +1 −0
  2. Makefile +0 −1
  3. rust/Makefile +1 −1
  4. rust/helpers/dma.c +16 −0
  5. rust/helpers/helpers.c +1 −0
  6. rust/helpers/io.c +17 −17
  7. rust/pin-init/examples/pthread_mutex.rs +1 −1
  8. rust/pin-init/src/alloc.rs +3 −5
  9. rust/pin-init/src/lib.rs +1 −1
  10. scripts/Makefile.compiler +2 −2
  11. scripts/generate_rust_analyzer.py +9 −3
  12. tools/objtool/check.c +1 −0
MAINTAINERS+1−0
@@ -7021,6 +7021,7 @@ L: rust-for-linux@vger.kernel.org · 7020 unmodified lines
70217021 S: Supported
70227022 W: https://rust-for-linux.com
70237023 T: git https://github.com/Rust-for-Linux/linux.git alloc-next
7024+F: rust/helpers/dma.c
70247025 F: rust/kernel/dma.rs
70257026 F: samples/rust/rust_dma.rs
70267027
Makefile+0−1
@@ -477,7 +477,6 @@ export rust_common_flags := --edition=2021 \ · 476 unmodified lines
477477 -Wclippy::ignored_unit_patterns \
478478 -Wclippy::mut_mut \
479479 -Wclippy::needless_bitwise_bool \
480− -Wclippy::needless_continue \
481480 -Aclippy::needless_lifetimes \
482481 -Wclippy::no_mangle_with_rust_abi \
483482 -Wclippy::undocumented_unsafe_blocks \
rust/Makefile+1−1
@@ -368,7 +368,7 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; · 367 unmodified lines
368368 $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
369369 $(call if_changed_dep,bindgen)
370370
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 }'
372372
373373 quiet_cmd_exports = EXPORTS $@
374374 cmd_exports = \
rust/helpers/dma.c+16−0
@@ -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+}
rust/helpers/helpers.c+1−0
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include "cpumask.c"
1515 #include "cred.c"
1616 #include "device.c"
17+#include "dma.c"
1718 #include "err.c"
1819 #include "fs.c"
1920 #include "io.c"
rust/helpers/io.c+17−17
@@ -7,94 +7,94 @@ void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size) · 6 unmodified lines
77 return ioremap(offset, size);
88 }
99
10−void rust_helper_iounmap(volatile void __iomem *addr)
10+void rust_helper_iounmap(void __iomem *addr)
1111 {
1212 iounmap(addr);
1313 }
1414
15−u8 rust_helper_readb(const volatile void __iomem *addr)
15+u8 rust_helper_readb(const void __iomem *addr)
1616 {
1717 return readb(addr);
1818 }
1919
20−u16 rust_helper_readw(const volatile void __iomem *addr)
20+u16 rust_helper_readw(const void __iomem *addr)
2121 {
2222 return readw(addr);
2323 }
2424
25−u32 rust_helper_readl(const volatile void __iomem *addr)
25+u32 rust_helper_readl(const void __iomem *addr)
2626 {
2727 return readl(addr);
2828 }
2929
3030 #ifdef CONFIG_64BIT
31−u64 rust_helper_readq(const volatile void __iomem *addr)
31+u64 rust_helper_readq(const void __iomem *addr)
3232 {
3333 return readq(addr);
3434 }
3535 #endif
3636
37−void rust_helper_writeb(u8 value, volatile void __iomem *addr)
37+void rust_helper_writeb(u8 value, void __iomem *addr)
3838 {
3939 writeb(value, addr);
4040 }
4141
42−void rust_helper_writew(u16 value, volatile void __iomem *addr)
42+void rust_helper_writew(u16 value, void __iomem *addr)
4343 {
4444 writew(value, addr);
4545 }
4646
47−void rust_helper_writel(u32 value, volatile void __iomem *addr)
47+void rust_helper_writel(u32 value, void __iomem *addr)
4848 {
4949 writel(value, addr);
5050 }
5151
5252 #ifdef CONFIG_64BIT
53−void rust_helper_writeq(u64 value, volatile void __iomem *addr)
53+void rust_helper_writeq(u64 value, void __iomem *addr)
5454 {
5555 writeq(value, addr);
5656 }
5757 #endif
5858
59−u8 rust_helper_readb_relaxed(const volatile void __iomem *addr)
59+u8 rust_helper_readb_relaxed(const void __iomem *addr)
6060 {
6161 return readb_relaxed(addr);
6262 }
6363
64−u16 rust_helper_readw_relaxed(const volatile void __iomem *addr)
64+u16 rust_helper_readw_relaxed(const void __iomem *addr)
6565 {
6666 return readw_relaxed(addr);
6767 }
6868
69−u32 rust_helper_readl_relaxed(const volatile void __iomem *addr)
69+u32 rust_helper_readl_relaxed(const void __iomem *addr)
7070 {
7171 return readl_relaxed(addr);
7272 }
7373
7474 #ifdef CONFIG_64BIT
75−u64 rust_helper_readq_relaxed(const volatile void __iomem *addr)
75+u64 rust_helper_readq_relaxed(const void __iomem *addr)
7676 {
7777 return readq_relaxed(addr);
7878 }
7979 #endif
8080
81−void rust_helper_writeb_relaxed(u8 value, volatile void __iomem *addr)
81+void rust_helper_writeb_relaxed(u8 value, void __iomem *addr)
8282 {
8383 writeb_relaxed(value, addr);
8484 }
8585
86−void rust_helper_writew_relaxed(u16 value, volatile void __iomem *addr)
86+void rust_helper_writew_relaxed(u16 value, void __iomem *addr)
8787 {
8888 writew_relaxed(value, addr);
8989 }
9090
91−void rust_helper_writel_relaxed(u32 value, volatile void __iomem *addr)
91+void rust_helper_writel_relaxed(u32 value, void __iomem *addr)
9292 {
9393 writel_relaxed(value, addr);
9494 }
9595
9696 #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)
9898 {
9999 writeq_relaxed(value, addr);
100100 }
rust/pin-init/examples/pthread_mutex.rs+1−1
@@ -1,6 +1,6 @@
11 // SPDX-License-Identifier: Apache-2.0 OR MIT
22
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>
44 #![allow(clippy::undocumented_unsafe_blocks)]
55 #![cfg_attr(feature = "alloc", feature(allocator_api))]
66 #[cfg(not(windows))]
rust/pin-init/src/alloc.rs+3−5
@@ -17,11 +17,9 @@ use crate::{ · 16 unmodified lines
1717
1818 pub extern crate alloc;
1919
20−// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
21−//
22−// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant and there
23−// is no problem with a VTABLE pointer being null.
24−unsafe impl<T: ?Sized> ZeroableOption for Box<T> {}
20+// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
21+// <https://doc.rust-lang.org/stable/std/option/index.html#representation>).
22+unsafe impl<T> ZeroableOption for Box<T> {}
2523
2624 /// Smart pointer that can initialize memory in-place.
2725 pub trait InPlaceInit<T>: Sized {
rust/pin-init/src/lib.rs+1−1
@@ -1447,7 +1447,7 @@ impl_zeroable! { · 1446 unmodified lines
14471447 {<T: ?Sized + Zeroable>} UnsafeCell<T>,
14481448
14491449 // 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>).
14511451 Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
14521452 Option<NonZeroU128>, Option<NonZeroUsize>,
14531453 Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
scripts/Makefile.compiler+2−2
@@ -79,8 +79,8 @@ ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) · 78 unmodified lines
7979 # Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage)
8080 # TODO: remove RUSTC_BOOTSTRAP=1 when we raise the minimum GNU Make version to 4.4
8181 __rustc-option = $(call try-run,\
82− echo '#![allow(missing_docs)]#![feature(no_core)]#![no_core]' | RUSTC_BOOTSTRAP=1\
83− $(1) --sysroot=/dev/null $(filter-out --sysroot=/dev/null,$(2)) $(3)\
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 --target=%,$(2)) $(3)\
8484 --crate-type=rlib --out-dir=$(TMPOUT) --emit=obj=- - >/dev/null,$(3),$(4))
8585
8686 # rustc-option
scripts/generate_rust_analyzer.py+9−3
@@ -112,6 +112,12 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): · 111 unmodified lines
112112 cfg=["kernel"],
113113 )
114114
115+ append_crate(
116+ "ffi",
117+ srctree / "rust" / "ffi.rs",
118+ ["core", "compiler_builtins"],
119+ )
120+
115121 def append_crate_with_generated(
116122 display_name,
117123 deps,
@@ -131,9 +137,9 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): · 13 unmodified lines
131137 "exclude_dirs": [],
132138 }
133139
134− append_crate_with_generated("bindings", ["core"])
135− append_crate_with_generated("uapi", ["core"])
136− append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "bindings", "uapi"])
140+ append_crate_with_generated("bindings", ["core", "ffi"])
141+ append_crate_with_generated("uapi", ["core", "ffi"])
142+ append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "ffi", "bindings", "uapi"])
137143
138144 def is_root_crate(build_file, target):
139145 try:
tools/objtool/check.c+1−0
@@ -225,6 +225,7 @@ static bool is_rust_noreturn(const struct symbol *func) · 224 unmodified lines
225225 str_ends_with(func->name, "_4core9panicking14panic_nounwind") ||
226226 str_ends_with(func->name, "_4core9panicking18panic_bounds_check") ||
227227 str_ends_with(func->name, "_4core9panicking19assert_failed_inner") ||
228+ str_ends_with(func->name, "_4core9panicking30panic_null_pointer_dereference") ||
228229 str_ends_with(func->name, "_4core9panicking36panic_misaligned_pointer_dereference") ||
229230 strstr(func->name, "_4core9panicking13assert_failed") ||
230231 strstr(func->name, "_4core9panicking11panic_const24panic_const_") ||