Skip to content

Commit 352af6a

Browse files
committed
Merge tag 'rust-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust updates from Miguel Ojeda: "Toolchain and infrastructure: - Enable a set of Clippy lints: 'ptr_as_ptr', 'ptr_cast_constness', 'as_ptr_cast_mut', 'as_underscore', 'cast_lossless' and 'ref_as_ptr' These are intended to avoid type casts with the 'as' operator, which are quite powerful, into restricted variants that are less powerful and thus should help to avoid mistakes - Remove the 'author' key now that most instances were moved to the plural one in the previous cycle 'kernel' crate: - New 'bug' module: add 'warn_on!' macro which reuses the existing 'BUG'/'WARN' infrastructure, i.e. it respects the usual sysctls and kernel parameters: warn_on!(value == 42); To avoid duplicating the assembly code, the same strategy is followed as for the static branch code in order to share the assembly between both C and Rust This required a few rearrangements on C arch headers -- the existing C macros should still generate the same outputs, thus no functional change expected there - 'workqueue' module: add delayed work items, including a 'DelayedWork' struct, a 'impl_has_delayed_work!' macro and an 'enqueue_delayed' method, e.g.: /// Enqueue the struct for execution on the system workqueue, /// where its value will be printed 42 jiffies later. fn print_later(value: Arc<MyStruct>) { let _ = workqueue::system().enqueue_delayed(value, 42); } - New 'bits' module: add support for 'bit' and 'genmask' functions, with runtime- and compile-time variants, e.g.: static_assert!(0b00010000 == bit_u8(4)); static_assert!(0b00011110 == genmask_u8(1..=4)); assert!(checked_bit_u32(u32::BITS).is_none()); - 'uaccess' module: add 'UserSliceReader::strcpy_into_buf', which reads NUL-terminated strings from userspace into a '&CStr' Introduce 'UserPtr' newtype, similar in purpose to '__user' in C, to minimize mistakes handling userspace pointers, including mixing them up with integers and leaking them via the 'Debug' trait. Add it to the prelude, too - Start preparations for the replacement of our custom 'CStr' type with the analogous type in the 'core' standard library. This will take place across several cycles to make it easier. For this one, it includes a new 'fmt' module, using upstream method names and some other cleanups Replace 'fmt!' with a re-export, which helps Clippy lint properly, and clean up the found 'uninlined-format-args' instances - 'dma' module: - Clarify wording and be consistent in 'coherent' nomenclature - Convert the 'read!()' and 'write!()' macros to return a 'Result' - Add 'as_slice()', 'write()' methods in 'CoherentAllocation' - Expose 'count()' and 'size()' in 'CoherentAllocation' and add the corresponding type invariants - Implement 'CoherentAllocation::dma_handle_with_offset()' - 'time' module: - Make 'Instant' generic over clock source. This allows the compiler to assert that arithmetic expressions involving the 'Instant' use 'Instants' based on the same clock source - Make 'HrTimer' generic over the timer mode. 'HrTimer' timers take a 'Duration' or an 'Instant' when setting the expiry time, depending on the timer mode. With this change, the compiler can check the type matches the timer mode - Add an abstraction for 'fsleep'. 'fsleep' is a flexible sleep function that will select an appropriate sleep method depending on the requested sleep time - Avoid 64-bit divisions on 32-bit hardware when calculating timestamps - Seal the 'HrTimerMode' trait. This prevents users of the 'HrTimerMode' from implementing the trait on their own types - Pass the correct timer mode ID to 'hrtimer_start_range_ns()' - 'list' module: remove 'OFFSET' constants, allowing to remove pointer arithmetic; now 'impl_list_item!' invokes 'impl_has_list_links!' or 'impl_has_list_links_self_ptr!'. Other simplifications too - 'types' module: remove 'ForeignOwnable::PointedTo' in favor of a constant, which avoids exposing the type of the opaque pointer, and require 'into_foreign' to return non-null Remove the 'Either<L, R>' type as well. It is unused, and we want to encourage the use of custom enums for concrete use cases - 'sync' module: implement 'Borrow' and 'BorrowMut' for 'Arc' types to allow them to be used in generic APIs - 'alloc' module: implement 'Borrow' and 'BorrowMut' for 'Box<T, A>'; and 'Borrow', 'BorrowMut' and 'Default' for 'Vec<T, A>' - 'Opaque' type: add 'cast_from' method to perform a restricted cast that cannot change the inner type and use it in callers of 'container_of!'. Rename 'raw_get' to 'cast_into' to match it - 'rbtree' module: add 'is_empty' method - 'sync' module: new 'aref' submodule to hold 'AlwaysRefCounted' and 'ARef', which are moved from the too general 'types' module which we want to reduce or eventually remove. Also fix a safety comment in 'static_lock_class' 'pin-init' crate: - Add 'impl<T, E> [Pin]Init<T, E> for Result<T, E>', so results are now (pin-)initializers - Add 'Zeroable::init_zeroed()' that delegates to 'init_zeroed()' - New 'zeroed()', a safe version of 'mem::zeroed()' and also provide it via 'Zeroable::zeroed()' - Implement 'Zeroable' for 'Option<&T>', 'Option<&mut T>' and for 'Option<[unsafe] [extern "abi"] fn(...args...) -> ret>' for '"Rust"' and '"C"' ABIs and up to 20 arguments - Changed blanket impls of 'Init' and 'PinInit' from 'impl<T, E> [Pin]Init<T, E> for T' to 'impl<T> [Pin]Init<T> for T' - Renamed 'zeroed()' to 'init_zeroed()' - Upstream dev news: improve CI more to deny warnings, use '--all-targets'. Check the synchronization status of the two '-next' branches in upstream and the kernel MAINTAINERS: - Add Vlastimil Babka, Liam R. Howlett, Uladzislau Rezki and Lorenzo Stoakes as reviewers (thanks everyone) And a few other cleanups and improvements" * tag 'rust-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (76 commits) rust: Add warn_on macro arm64/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust riscv/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust x86/bug: Add ARCH_WARN_ASM macro for BUG/WARN asm code sharing with Rust rust: kernel: move ARef and AlwaysRefCounted to sync::aref rust: sync: fix safety comment for `static_lock_class` rust: types: remove `Either<L, R>` rust: kernel: use `core::ffi::CStr` method names rust: str: add `CStr` methods matching `core::ffi::CStr` rust: str: remove unnecessary qualification rust: use `kernel::{fmt,prelude::fmt!}` rust: kernel: add `fmt` module rust: kernel: remove `fmt!`, fix clippy::uninlined-format-args scripts: rust: emit path candidates in panic message scripts: rust: replace length checks with match rust: list: remove nonexistent generic parameter in link rust: bits: add support for bits/genmask macros rust: list: remove OFFSET constants rust: list: add `impl_list_item!` examples rust: list: use fully qualified path ...
2 parents 186f3ed + dff64b0 commit 352af6a

Some content is hidden

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

94 files changed

+2562
-988
lines changed

MAINTAINERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22032,6 +22032,10 @@ K: \b(?i:rust)\b
2203222032

2203322033
RUST [ALLOC]
2203422034
M: Danilo Krummrich <[email protected]>
22035+
R: Lorenzo Stoakes <[email protected]>
22036+
R: Vlastimil Babka <[email protected]>
22037+
R: Liam R. Howlett <[email protected]>
22038+
R: Uladzislau Rezki <[email protected]>
2203522039
2203622040
S: Maintained
2203722041
T: git https://github.com/Rust-for-Linux/linux.git alloc-next

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,17 @@ export rust_common_flags := --edition=2021 \
479479
-Wrust_2018_idioms \
480480
-Wunreachable_pub \
481481
-Wclippy::all \
482+
-Wclippy::as_ptr_cast_mut \
483+
-Wclippy::as_underscore \
484+
-Wclippy::cast_lossless \
482485
-Wclippy::ignored_unit_patterns \
483486
-Wclippy::mut_mut \
484487
-Wclippy::needless_bitwise_bool \
485488
-Aclippy::needless_lifetimes \
486489
-Wclippy::no_mangle_with_rust_abi \
490+
-Wclippy::ptr_as_ptr \
491+
-Wclippy::ptr_cast_constness \
492+
-Wclippy::ref_as_ptr \
487493
-Wclippy::undocumented_unsafe_blocks \
488494
-Wclippy::unnecessary_safety_comment \
489495
-Wclippy::unnecessary_safety_doc \

arch/arm64/include/asm/asm-bug.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@
2121
#endif
2222

2323
#ifdef CONFIG_GENERIC_BUG
24-
25-
#define __BUG_ENTRY(flags) \
24+
#define __BUG_ENTRY_START \
2625
.pushsection __bug_table,"aw"; \
2726
.align 2; \
2827
14470: .long 14471f - .; \
29-
_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \
30-
.short flags; \
28+
29+
#define __BUG_ENTRY_END \
3130
.align 2; \
3231
.popsection; \
3332
14471:
33+
34+
#define __BUG_ENTRY(flags) \
35+
__BUG_ENTRY_START \
36+
_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \
37+
.short flags; \
38+
__BUG_ENTRY_END
3439
#else
3540
#define __BUG_ENTRY(flags)
3641
#endif
@@ -41,4 +46,24 @@ _BUGVERBOSE_LOCATION(__FILE__, __LINE__) \
4146

4247
#define ASM_BUG() ASM_BUG_FLAGS(0)
4348

49+
#ifdef CONFIG_DEBUG_BUGVERBOSE
50+
#define __BUG_LOCATION_STRING(file, line) \
51+
".long " file "- .;" \
52+
".short " line ";"
53+
#else
54+
#define __BUG_LOCATION_STRING(file, line)
55+
#endif
56+
57+
#define __BUG_ENTRY_STRING(file, line, flags) \
58+
__stringify(__BUG_ENTRY_START) \
59+
__BUG_LOCATION_STRING(file, line) \
60+
".short " flags ";" \
61+
__stringify(__BUG_ENTRY_END)
62+
63+
#define ARCH_WARN_ASM(file, line, flags, size) \
64+
__BUG_ENTRY_STRING(file, line, flags) \
65+
__stringify(brk BUG_BRK_IMM)
66+
67+
#define ARCH_WARN_REACHABLE
68+
4469
#endif /* __ASM_ASM_BUG_H */

arch/riscv/include/asm/bug.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,45 @@ typedef u32 bug_insn_t;
3131

3232
#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
3333
#define __BUG_ENTRY_ADDR RISCV_INT " 1b - ."
34-
#define __BUG_ENTRY_FILE RISCV_INT " %0 - ."
34+
#define __BUG_ENTRY_FILE(file) RISCV_INT " " file " - ."
3535
#else
3636
#define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
37-
#define __BUG_ENTRY_FILE RISCV_PTR " %0"
37+
#define __BUG_ENTRY_FILE(file) RISCV_PTR " " file
3838
#endif
3939

4040
#ifdef CONFIG_DEBUG_BUGVERBOSE
41-
#define __BUG_ENTRY \
41+
#define __BUG_ENTRY(file, line, flags) \
4242
__BUG_ENTRY_ADDR "\n\t" \
43-
__BUG_ENTRY_FILE "\n\t" \
44-
RISCV_SHORT " %1\n\t" \
45-
RISCV_SHORT " %2"
43+
__BUG_ENTRY_FILE(file) "\n\t" \
44+
RISCV_SHORT " " line "\n\t" \
45+
RISCV_SHORT " " flags
4646
#else
47-
#define __BUG_ENTRY \
48-
__BUG_ENTRY_ADDR "\n\t" \
49-
RISCV_SHORT " %2"
47+
#define __BUG_ENTRY(file, line, flags) \
48+
__BUG_ENTRY_ADDR "\n\t" \
49+
RISCV_SHORT " " flags
5050
#endif
5151

5252
#ifdef CONFIG_GENERIC_BUG
53-
#define __BUG_FLAGS(flags) \
54-
do { \
55-
__asm__ __volatile__ ( \
53+
54+
#define ARCH_WARN_ASM(file, line, flags, size) \
5655
"1:\n\t" \
5756
"ebreak\n" \
5857
".pushsection __bug_table,\"aw\"\n\t" \
5958
"2:\n\t" \
60-
__BUG_ENTRY "\n\t" \
61-
".org 2b + %3\n\t" \
59+
__BUG_ENTRY(file, line, flags) "\n\t" \
60+
".org 2b + " size "\n\t" \
6261
".popsection" \
62+
63+
#define __BUG_FLAGS(flags) \
64+
do { \
65+
__asm__ __volatile__ ( \
66+
ARCH_WARN_ASM("%0", "%1", "%2", "%3") \
6367
: \
6468
: "i" (__FILE__), "i" (__LINE__), \
6569
"i" (flags), \
6670
"i" (sizeof(struct bug_entry))); \
6771
} while (0)
72+
6873
#else /* CONFIG_GENERIC_BUG */
6974
#define __BUG_FLAGS(flags) do { \
7075
__asm__ __volatile__ ("ebreak\n"); \
@@ -78,6 +83,8 @@ do { \
7883

7984
#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
8085

86+
#define ARCH_WARN_REACHABLE
87+
8188
#define HAVE_ARCH_BUG
8289

8390
#include <asm-generic/bug.h>

arch/x86/include/asm/bug.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,42 @@
3232
#ifdef CONFIG_GENERIC_BUG
3333

3434
#ifdef CONFIG_X86_32
35-
# define __BUG_REL(val) ".long " __stringify(val)
35+
# define __BUG_REL(val) ".long " val
3636
#else
37-
# define __BUG_REL(val) ".long " __stringify(val) " - ."
37+
# define __BUG_REL(val) ".long " val " - ."
3838
#endif
3939

4040
#ifdef CONFIG_DEBUG_BUGVERBOSE
41+
#define __BUG_ENTRY(file, line, flags) \
42+
"2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \
43+
"\t" __BUG_REL(file) "\t# bug_entry::file\n" \
44+
"\t.word " line "\t# bug_entry::line\n" \
45+
"\t.word " flags "\t# bug_entry::flags\n"
46+
#else
47+
#define __BUG_ENTRY(file, line, flags) \
48+
"2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \
49+
"\t.word " flags "\t# bug_entry::flags\n"
50+
#endif
51+
52+
#define _BUG_FLAGS_ASM(ins, file, line, flags, size, extra) \
53+
"1:\t" ins "\n" \
54+
".pushsection __bug_table,\"aw\"\n" \
55+
__BUG_ENTRY(file, line, flags) \
56+
"\t.org 2b + " size "\n" \
57+
".popsection\n" \
58+
extra
4159

4260
#define _BUG_FLAGS(ins, flags, extra) \
4361
do { \
44-
asm_inline volatile("1:\t" ins "\n" \
45-
".pushsection __bug_table,\"aw\"\n" \
46-
"2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
47-
"\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
48-
"\t.word %c1" "\t# bug_entry::line\n" \
49-
"\t.word %c2" "\t# bug_entry::flags\n" \
50-
"\t.org 2b+%c3\n" \
51-
".popsection\n" \
52-
extra \
62+
asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c0", \
63+
"%c1", "%c2", "%c3", extra) \
5364
: : "i" (__FILE__), "i" (__LINE__), \
5465
"i" (flags), \
5566
"i" (sizeof(struct bug_entry))); \
5667
} while (0)
5768

58-
#else /* !CONFIG_DEBUG_BUGVERBOSE */
59-
60-
#define _BUG_FLAGS(ins, flags, extra) \
61-
do { \
62-
asm_inline volatile("1:\t" ins "\n" \
63-
".pushsection __bug_table,\"aw\"\n" \
64-
"2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
65-
"\t.word %c0" "\t# bug_entry::flags\n" \
66-
"\t.org 2b+%c1\n" \
67-
".popsection\n" \
68-
extra \
69-
: : "i" (flags), \
70-
"i" (sizeof(struct bug_entry))); \
71-
} while (0)
72-
73-
#endif /* CONFIG_DEBUG_BUGVERBOSE */
69+
#define ARCH_WARN_ASM(file, line, flags, size) \
70+
_BUG_FLAGS_ASM(ASM_UD2, file, line, flags, size, "")
7471

7572
#else
7673

@@ -92,11 +89,14 @@ do { \
9289
* were to trigger, we'd rather wreck the machine in an attempt to get the
9390
* message out than not know about it.
9491
*/
92+
93+
#define ARCH_WARN_REACHABLE ANNOTATE_REACHABLE(1b)
94+
9595
#define __WARN_FLAGS(flags) \
9696
do { \
9797
__auto_type __flags = BUGFLAG_WARNING|(flags); \
9898
instrumentation_begin(); \
99-
_BUG_FLAGS(ASM_UD2, __flags, ANNOTATE_REACHABLE(1b)); \
99+
_BUG_FLAGS(ASM_UD2, __flags, ARCH_WARN_REACHABLE); \
100100
instrumentation_end(); \
101101
} while (0)
102102

drivers/cpufreq/rcpufreq_dt.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use kernel::{
99
cpumask::CpumaskVar,
1010
device::{Core, Device},
1111
error::code::*,
12-
fmt,
1312
macros::vtable,
1413
module_platform_driver, of, opp, platform,
1514
prelude::*,
@@ -19,7 +18,7 @@ use kernel::{
1918

2019
/// Finds exact supply name from the OF node.
2120
fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
22-
let prop_name = CString::try_from_fmt(fmt!("{}-supply", name)).ok()?;
21+
let prop_name = CString::try_from_fmt(fmt!("{name}-supply")).ok()?;
2322
dev.fwnode()?
2423
.property_present(&prop_name)
2524
.then(|| CString::try_from_fmt(fmt!("{name}")).ok())
@@ -221,7 +220,7 @@ impl platform::Driver for CPUFreqDTDriver {
221220
module_platform_driver! {
222221
type: CPUFreqDTDriver,
223222
name: "cpufreq-dt",
224-
author: "Viresh Kumar <[email protected]>",
223+
authors: ["Viresh Kumar <[email protected]>"],
225224
description: "Generic CPUFreq DT driver",
226225
license: "GPL v2",
227226
}

drivers/gpu/drm/drm_panic_qr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl DecFifo {
404404
let mut out = 0;
405405
let mut exp = 1;
406406
for i in 0..poplen {
407-
out += self.decimals[self.len + i] as u16 * exp;
407+
out += u16::from(self.decimals[self.len + i]) * exp;
408408
exp *= 10;
409409
}
410410
Some((out, NUM_CHARS_BITS[poplen]))
@@ -425,7 +425,7 @@ impl Iterator for SegmentIterator<'_> {
425425
match self.segment {
426426
Segment::Binary(data) => {
427427
if self.offset < data.len() {
428-
let byte = data[self.offset] as u16;
428+
let byte = u16::from(data[self.offset]);
429429
self.offset += 1;
430430
Some((byte, 8))
431431
} else {

drivers/gpu/drm/nova/nova.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::driver::NovaDriver;
1212
kernel::module_auxiliary_driver! {
1313
type: NovaDriver,
1414
name: "Nova",
15-
author: "Danilo Krummrich",
15+
authors: ["Danilo Krummrich"],
1616
description: "Nova GPU driver",
1717
license: "GPL v2",
1818
}

drivers/gpu/nova-core/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kernel::pci_device_table!(
1919
MODULE_PCI_TABLE,
2020
<NovaCore as pci::Driver>::IdInfo,
2121
[(
22-
pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as _),
22+
pci::DeviceId::from_id(bindings::PCI_VENDOR_ID_NVIDIA, bindings::PCI_ANY_ID as u32),
2323
()
2424
)]
2525
);

drivers/gpu/nova-core/firmware.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ pub(crate) struct Firmware {
3030

3131
impl Firmware {
3232
pub(crate) fn new(dev: &device::Device, chipset: Chipset, ver: &str) -> Result<Firmware> {
33-
let mut chip_name = CString::try_from_fmt(fmt!("{}", chipset))?;
33+
let mut chip_name = CString::try_from_fmt(fmt!("{chipset}"))?;
3434
chip_name.make_ascii_lowercase();
35+
let chip_name = &*chip_name;
3536

3637
let request = |name_| {
37-
CString::try_from_fmt(fmt!("nvidia/{}/gsp/{}-{}.bin", &*chip_name, name_, ver))
38+
CString::try_from_fmt(fmt!("nvidia/{chip_name}/gsp/{name_}-{ver}.bin"))
3839
.and_then(|path| firmware::Firmware::request(&path, dev))
3940
};
4041

0 commit comments

Comments
 (0)