Skip to content

Commit

Permalink
Merge tag 'rust-fixes-6.15' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/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
  • Loading branch information
Linus Torvalds committed Apr 19, 2025
2 parents 51c7960 + c1b4071 commit 0bd2f26
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 31 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -7021,6 +7021,7 @@ L: rust-for-linux@vger.kernel.org
S: Supported
W: https://rust-for-linux.com
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
F: rust/helpers/dma.c
F: rust/kernel/dma.rs
F: samples/rust/rust_dma.rs

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ export rust_common_flags := --edition=2021 \
-Wclippy::ignored_unit_patterns \
-Wclippy::mut_mut \
-Wclippy::needless_bitwise_bool \
-Wclippy::needless_continue \
-Aclippy::needless_lifetimes \
-Wclippy::no_mangle_with_rust_abi \
-Wclippy::undocumented_unsafe_blocks \
Expand Down
2 changes: 1 addition & 1 deletion rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ;
$(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE
$(call if_changed_dep,bindgen)

rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ && $$3!~/__odr_asan/ { printf $(2),$$3 }'
rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__(pfx|cfi|odr_asan)/ { printf $(2),$$3 }'

quiet_cmd_exports = EXPORTS $@
cmd_exports = \
Expand Down
16 changes: 16 additions & 0 deletions rust/helpers/dma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-2.0

#include <linux/dma-mapping.h>

void *rust_helper_dma_alloc_attrs(struct device *dev, size_t size,
dma_addr_t *dma_handle, gfp_t flag,
unsigned long attrs)
{
return dma_alloc_attrs(dev, size, dma_handle, flag, attrs);
}

void rust_helper_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr,
dma_addr_t dma_handle, unsigned long attrs)
{
dma_free_attrs(dev, size, cpu_addr, dma_handle, attrs);
}
1 change: 1 addition & 0 deletions rust/helpers/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "cpumask.c"
#include "cred.c"
#include "device.c"
#include "dma.c"
#include "err.c"
#include "fs.c"
#include "io.c"
Expand Down
34 changes: 17 additions & 17 deletions rust/helpers/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,94 +7,94 @@ void __iomem *rust_helper_ioremap(phys_addr_t offset, size_t size)
return ioremap(offset, size);
}

void rust_helper_iounmap(volatile void __iomem *addr)
void rust_helper_iounmap(void __iomem *addr)
{
iounmap(addr);
}

u8 rust_helper_readb(const volatile void __iomem *addr)
u8 rust_helper_readb(const void __iomem *addr)
{
return readb(addr);
}

u16 rust_helper_readw(const volatile void __iomem *addr)
u16 rust_helper_readw(const void __iomem *addr)
{
return readw(addr);
}

u32 rust_helper_readl(const volatile void __iomem *addr)
u32 rust_helper_readl(const void __iomem *addr)
{
return readl(addr);
}

#ifdef CONFIG_64BIT
u64 rust_helper_readq(const volatile void __iomem *addr)
u64 rust_helper_readq(const void __iomem *addr)
{
return readq(addr);
}
#endif

void rust_helper_writeb(u8 value, volatile void __iomem *addr)
void rust_helper_writeb(u8 value, void __iomem *addr)
{
writeb(value, addr);
}

void rust_helper_writew(u16 value, volatile void __iomem *addr)
void rust_helper_writew(u16 value, void __iomem *addr)
{
writew(value, addr);
}

void rust_helper_writel(u32 value, volatile void __iomem *addr)
void rust_helper_writel(u32 value, void __iomem *addr)
{
writel(value, addr);
}

#ifdef CONFIG_64BIT
void rust_helper_writeq(u64 value, volatile void __iomem *addr)
void rust_helper_writeq(u64 value, void __iomem *addr)
{
writeq(value, addr);
}
#endif

u8 rust_helper_readb_relaxed(const volatile void __iomem *addr)
u8 rust_helper_readb_relaxed(const void __iomem *addr)
{
return readb_relaxed(addr);
}

u16 rust_helper_readw_relaxed(const volatile void __iomem *addr)
u16 rust_helper_readw_relaxed(const void __iomem *addr)
{
return readw_relaxed(addr);
}

u32 rust_helper_readl_relaxed(const volatile void __iomem *addr)
u32 rust_helper_readl_relaxed(const void __iomem *addr)
{
return readl_relaxed(addr);
}

#ifdef CONFIG_64BIT
u64 rust_helper_readq_relaxed(const volatile void __iomem *addr)
u64 rust_helper_readq_relaxed(const void __iomem *addr)
{
return readq_relaxed(addr);
}
#endif

void rust_helper_writeb_relaxed(u8 value, volatile void __iomem *addr)
void rust_helper_writeb_relaxed(u8 value, void __iomem *addr)
{
writeb_relaxed(value, addr);
}

void rust_helper_writew_relaxed(u16 value, volatile void __iomem *addr)
void rust_helper_writew_relaxed(u16 value, void __iomem *addr)
{
writew_relaxed(value, addr);
}

void rust_helper_writel_relaxed(u32 value, volatile void __iomem *addr)
void rust_helper_writel_relaxed(u32 value, void __iomem *addr)
{
writel_relaxed(value, addr);
}

#ifdef CONFIG_64BIT
void rust_helper_writeq_relaxed(u64 value, volatile void __iomem *addr)
void rust_helper_writeq_relaxed(u64 value, void __iomem *addr)
{
writeq_relaxed(value, addr);
}
Expand Down
2 changes: 1 addition & 1 deletion rust/pin-init/examples/pthread_mutex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

// inspired by https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs
// inspired by <https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs>
#![allow(clippy::undocumented_unsafe_blocks)]
#![cfg_attr(feature = "alloc", feature(allocator_api))]
#[cfg(not(windows))]
Expand Down
8 changes: 3 additions & 5 deletions rust/pin-init/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ use crate::{

pub extern crate alloc;

// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
//
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant and there
// is no problem with a VTABLE pointer being null.
unsafe impl<T: ?Sized> ZeroableOption for Box<T> {}
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>).
unsafe impl<T> ZeroableOption for Box<T> {}

/// Smart pointer that can initialize memory in-place.
pub trait InPlaceInit<T>: Sized {
Expand Down
2 changes: 1 addition & 1 deletion rust/pin-init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ impl_zeroable! {
{<T: ?Sized + Zeroable>} UnsafeCell<T>,

// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
// https://doc.rust-lang.org/stable/std/option/index.html#representation).
// <https://doc.rust-lang.org/stable/std/option/index.html#representation>).
Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
Option<NonZeroU128>, Option<NonZeroUsize>,
Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
Expand Down
4 changes: 2 additions & 2 deletions scripts/Makefile.compiler
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
# Usage: MY_RUSTFLAGS += $(call __rustc-option,$(RUSTC),$(MY_RUSTFLAGS),-Cinstrument-coverage,-Zinstrument-coverage)
# TODO: remove RUSTC_BOOTSTRAP=1 when we raise the minimum GNU Make version to 4.4
__rustc-option = $(call try-run,\
echo '#![allow(missing_docs)]#![feature(no_core)]#![no_core]' | RUSTC_BOOTSTRAP=1\
$(1) --sysroot=/dev/null $(filter-out --sysroot=/dev/null,$(2)) $(3)\
echo '$(pound)![allow(missing_docs)]$(pound)![feature(no_core)]$(pound)![no_core]' | RUSTC_BOOTSTRAP=1\
$(1) --sysroot=/dev/null $(filter-out --sysroot=/dev/null --target=%,$(2)) $(3)\
--crate-type=rlib --out-dir=$(TMPOUT) --emit=obj=- - >/dev/null,$(3),$(4))

# rustc-option
Expand Down
12 changes: 9 additions & 3 deletions scripts/generate_rust_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ def append_sysroot_crate(
cfg=["kernel"],
)

append_crate(
"ffi",
srctree / "rust" / "ffi.rs",
["core", "compiler_builtins"],
)

def append_crate_with_generated(
display_name,
deps,
Expand All @@ -131,9 +137,9 @@ def append_crate_with_generated(
"exclude_dirs": [],
}

append_crate_with_generated("bindings", ["core"])
append_crate_with_generated("uapi", ["core"])
append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "bindings", "uapi"])
append_crate_with_generated("bindings", ["core", "ffi"])
append_crate_with_generated("uapi", ["core", "ffi"])
append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "ffi", "bindings", "uapi"])

def is_root_crate(build_file, target):
try:
Expand Down
1 change: 1 addition & 0 deletions tools/objtool/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ static bool is_rust_noreturn(const struct symbol *func)
str_ends_with(func->name, "_4core9panicking14panic_nounwind") ||
str_ends_with(func->name, "_4core9panicking18panic_bounds_check") ||
str_ends_with(func->name, "_4core9panicking19assert_failed_inner") ||
str_ends_with(func->name, "_4core9panicking30panic_null_pointer_dereference") ||
str_ends_with(func->name, "_4core9panicking36panic_misaligned_pointer_dereference") ||
strstr(func->name, "_4core9panicking13assert_failed") ||
strstr(func->name, "_4core9panicking11panic_const24panic_const_") ||
Expand Down

0 comments on commit 0bd2f26

Please sign in to comment.