Skip to content

Commit 4e82c87

Browse files
committed
Merge tag 'rust-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust updates from Miguel Ojeda: "Toolchain and infrastructure: - Extract the 'pin-init' API from the 'kernel' crate and make it into a standalone crate. In order to do this, the contents are rearranged so that they can easily be kept in sync with the version maintained out-of-tree that other projects have started to use too (or plan to, like QEMU). This will reduce the maintenance burden for Benno, who will now have his own sub-tree, and will simplify future expected changes like the move to use 'syn' to simplify the implementation. - Add '#[test]'-like support based on KUnit. We already had doctests support based on KUnit, which takes the examples in our Rust documentation and runs them under KUnit. Now, we are adding the beginning of the support for "normal" tests, similar to those the '#[test]' tests in userspace Rust. For instance: #[kunit_tests(my_suite)] mod tests { #[test] fn my_test() { assert_eq!(1 + 1, 2); } } Unlike with doctests, the 'assert*!'s do not map to the KUnit assertion APIs yet. - Check Rust signatures at compile time for functions called from C by name. In particular, introduce a new '#[export]' macro that can be placed in the Rust function definition. It will ensure that the function declaration on the C side matches the signature on the Rust function: #[export] pub unsafe extern "C" fn my_function(a: u8, b: i32) -> usize { // ... } The macro essentially forces the compiler to compare the types of the actual Rust function and the 'bindgen'-processed C signature. These cases are rare so far. In the future, we may consider introducing another tool, 'cbindgen', to generate C headers automatically. Even then, having these functions explicitly marked may be a good idea anyway. - Enable the 'raw_ref_op' Rust feature: it is already stable, and allows us to use the new '&raw' syntax, avoiding a couple macros. After everyone has migrated, we will disallow the macros. - Pass the correct target to 'bindgen' on Usermode Linux. - Fix 'rusttest' build in macOS. 'kernel' crate: - New 'hrtimer' module: add support for setting up intrusive timers without allocating when starting the timer. Add support for 'Pin<Box<_>>', 'Arc<_>', 'Pin<&_>' and 'Pin<&mut _>' as pointer types for use with timer callbacks. Add support for setting clock source and timer mode. - New 'dma' module: add a simple DMA coherent allocator abstraction and a test sample driver. - 'list' module: make the linked list 'Cursor' point between elements, rather than at an element, which is more convenient to us and allows for cursors to empty lists; and document it with examples of how to perform common operations with the provided methods. - 'str' module: implement a few traits for 'BStr' as well as the 'strip_prefix()' method. - 'sync' module: add 'Arc::as_ptr'. - 'alloc' module: add 'Box::into_pin'. - 'error' module: extend the 'Result' documentation, including a few examples on different ways of handling errors, a warning about using methods that may panic, and links to external documentation. 'macros' crate: - 'module' macro: add the 'authors' key to support multiple authors. The original key will be kept until everyone has migrated. Documentation: - Add error handling sections. MAINTAINERS: - Add Danilo Krummrich as reviewer of the Rust "subsystem". - Add 'RUST [PIN-INIT]' entry with Benno Lossin as maintainer. It has its own sub-tree. - Add sub-tree for 'RUST [ALLOC]'. - Add 'DMA MAPPING HELPERS DEVICE DRIVER API [RUST]' entry with Abdiel Janulgue as primary maintainer. It will go through the sub-tree of the 'RUST [ALLOC]' entry. - Add 'HIGH-RESOLUTION TIMERS [RUST]' entry with Andreas Hindborg as maintainer. It has its own sub-tree. And a few other cleanups and improvements" * tag 'rust-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (71 commits) rust: dma: add `Send` implementation for `CoherentAllocation` rust: macros: fix `make rusttest` build on macOS rust: block: refactor to use `&raw mut` rust: enable `raw_ref_op` feature rust: uaccess: name the correct function rust: rbtree: fix comments referring to Box instead of KBox rust: hrtimer: add maintainer entry rust: hrtimer: add clocksource selection through `ClockId` rust: hrtimer: add `HrTimerMode` rust: hrtimer: implement `HrTimerPointer` for `Pin<Box<T>>` rust: alloc: add `Box::into_pin` rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>` rust: hrtimer: add `hrtimer::ScopedHrTimerPointer` rust: hrtimer: add `UnsafeHrTimerPointer` rust: hrtimer: allow timer restart from timer handler rust: str: implement `strip_prefix` for `BStr` rust: str: implement `AsRef<BStr>` for `[u8]` and `BStr` rust: str: implement `Index` for `BStr` rust: str: implement `PartialEq` for `BStr` ...
2 parents 01d5b16 + e6ea10d commit 4e82c87

Some content is hidden

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

85 files changed

+5999
-1845
lines changed

Documentation/rust/coding-guidelines.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,11 @@ triggered due to non-local changes (such as ``dead_code``).
373373
For more information about diagnostics in Rust, please see:
374374

375375
https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html
376+
377+
Error handling
378+
--------------
379+
380+
For some background and guidelines about Rust for Linux specific error handling,
381+
please see:
382+
383+
https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust

Documentation/rust/testing.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ A current limitation is that KUnit does not support assertions in other tasks.
123123
Thus, we presently simply print an error to the kernel log if an assertion
124124
actually failed. Additionally, doctests are not run for nonpublic functions.
125125

126+
Since these tests are examples, i.e. they are part of the documentation, they
127+
should generally be written like "real code". Thus, for example, instead of
128+
using ``unwrap()`` or ``expect()``, use the ``?`` operator. For more background,
129+
please see:
130+
131+
https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
132+
126133
The ``#[test]`` tests
127134
---------------------
128135

MAINTAINERS

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6981,6 +6981,19 @@ F: include/linux/dma-mapping.h
69816981
F: include/linux/swiotlb.h
69826982
F: kernel/dma/
69836983

6984+
DMA MAPPING HELPERS DEVICE DRIVER API [RUST]
6985+
M: Abdiel Janulgue <abdiel.janulgue@gmail.com>
6986+
M: Danilo Krummrich <dakr@kernel.org>
6987+
R: Daniel Almeida <daniel.almeida@collabora.com>
6988+
R: Robin Murphy <robin.murphy@arm.com>
6989+
R: Andreas Hindborg <a.hindborg@kernel.org>
6990+
L: rust-for-linux@vger.kernel.org
6991+
S: Supported
6992+
W: https://rust-for-linux.com
6993+
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
6994+
F: rust/kernel/dma.rs
6995+
F: samples/rust/rust_dma.rs
6996+
69846997
DMA-BUF HEAPS FRAMEWORK
69856998
M: Sumit Semwal <sumit.semwal@linaro.org>
69866999
R: Benjamin Gaignard <benjamin.gaignard@collabora.com>
@@ -10539,6 +10552,21 @@ F: kernel/time/timer_list.c
1053910552
F: kernel/time/timer_migration.*
1054010553
F: tools/testing/selftests/timers/
1054110554

10555+
HIGH-RESOLUTION TIMERS [RUST]
10556+
M: Andreas Hindborg <a.hindborg@kernel.org>
10557+
R: Boqun Feng <boqun.feng@gmail.com>
10558+
R: Frederic Weisbecker <frederic@kernel.org>
10559+
R: Lyude Paul <lyude@redhat.com>
10560+
R: Thomas Gleixner <tglx@linutronix.de>
10561+
R: Anna-Maria Behnsen <anna-maria@linutronix.de>
10562+
L: rust-for-linux@vger.kernel.org
10563+
S: Supported
10564+
W: https://rust-for-linux.com
10565+
B: https://github.com/Rust-for-Linux/linux/issues
10566+
T: git https://github.com/Rust-for-Linux/linux.git hrtimer-next
10567+
F: rust/kernel/time/hrtimer.rs
10568+
F: rust/kernel/time/hrtimer/
10569+
1054210570
HIGH-SPEED SCC DRIVER FOR AX.25
1054310571
L: linux-hams@vger.kernel.org
1054410572
S: Orphan
@@ -12902,6 +12930,7 @@ F: Documentation/dev-tools/kunit/
1290212930
F: include/kunit/
1290312931
F: lib/kunit/
1290412932
F: rust/kernel/kunit.rs
12933+
F: rust/macros/kunit.rs
1290512934
F: scripts/rustdoc_test_*
1290612935
F: tools/testing/kunit/
1290712936

@@ -20993,6 +21022,7 @@ R: Benno Lossin <benno.lossin@proton.me>
2099321022
R: Andreas Hindborg <a.hindborg@kernel.org>
2099421023
R: Alice Ryhl <aliceryhl@google.com>
2099521024
R: Trevor Gross <tmgross@umich.edu>
21025+
R: Danilo Krummrich <dakr@kernel.org>
2099621026
L: rust-for-linux@vger.kernel.org
2099721027
S: Supported
2099821028
W: https://rust-for-linux.com
@@ -21013,9 +21043,23 @@ RUST [ALLOC]
2101321043
M: Danilo Krummrich <dakr@kernel.org>
2101421044
L: rust-for-linux@vger.kernel.org
2101521045
S: Maintained
21046+
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
2101621047
F: rust/kernel/alloc.rs
2101721048
F: rust/kernel/alloc/
2101821049

21050+
RUST [PIN-INIT]
21051+
M: Benno Lossin <benno.lossin@proton.me>
21052+
L: rust-for-linux@vger.kernel.org
21053+
S: Maintained
21054+
W: https://rust-for-linux.com/pin-init
21055+
B: https://github.com/Rust-for-Linux/pin-init/issues
21056+
C: zulip://rust-for-linux.zulipchat.com
21057+
P: rust/pin-init/CONTRIBUTING.md
21058+
T: git https://github.com/Rust-for-Linux/linux.git pin-init-next
21059+
F: rust/kernel/init.rs
21060+
F: rust/pin-init/
21061+
K: \bpin-init\b|pin_init\b|PinInit
21062+
2101921063
RXRPC SOCKETS (AF_RXRPC)
2102021064
M: David Howells <dhowells@redhat.com>
2102121065
M: Marc Dionne <marc.dionne@auristor.com>

drivers/block/rnull.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use kernel::{
2727
module! {
2828
type: NullBlkModule,
2929
name: "rnull_mod",
30-
author: "Andreas Hindborg",
30+
authors: ["Andreas Hindborg"],
3131
description: "Rust implementation of the C null block driver",
3232
license: "GPL v2",
3333
}

drivers/gpu/drm/drm_panic.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,6 @@ static void drm_panic_qr_exit(void)
486486
stream.workspace = NULL;
487487
}
488488

489-
extern size_t drm_panic_qr_max_data_size(u8 version, size_t url_len);
490-
491-
extern u8 drm_panic_qr_generate(const char *url, u8 *data, size_t data_len, size_t data_size,
492-
u8 *tmp, size_t tmp_size);
493-
494489
static int drm_panic_get_qr_code_url(u8 **qr_image)
495490
{
496491
struct kmsg_dump_iter iter;

drivers/gpu/drm/drm_panic_qr.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! * <https://github.com/erwanvivien/fast_qr>
2828
//! * <https://github.com/bjguillot/qr>
2929
30-
use kernel::str::CStr;
30+
use kernel::{prelude::*, str::CStr};
3131

3232
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
3333
struct Version(usize);
@@ -891,7 +891,7 @@ impl QrImage<'_> {
891891
/// * `tmp` must be valid for reading and writing for `tmp_size` bytes.
892892
///
893893
/// They must remain valid for the duration of the function call.
894-
#[no_mangle]
894+
#[export]
895895
pub unsafe extern "C" fn drm_panic_qr_generate(
896896
url: *const kernel::ffi::c_char,
897897
data: *mut u8,
@@ -942,8 +942,13 @@ pub unsafe extern "C" fn drm_panic_qr_generate(
942942
/// * If `url_len` > 0, remove the 2 segments header/length and also count the
943943
/// conversion to numeric segments.
944944
/// * If `url_len` = 0, only removes 3 bytes for 1 binary segment.
945-
#[no_mangle]
946-
pub extern "C" fn drm_panic_qr_max_data_size(version: u8, url_len: usize) -> usize {
945+
///
946+
/// # Safety
947+
///
948+
/// Always safe to call.
949+
// Required to be unsafe due to the `#[export]` annotation.
950+
#[export]
951+
pub unsafe extern "C" fn drm_panic_qr_max_data_size(version: u8, url_len: usize) -> usize {
947952
#[expect(clippy::manual_range_contains)]
948953
if version < 1 || version > 40 {
949954
return 0;

drivers/net/phy/ax88796b_rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kernel::module_phy_driver! {
1919
DeviceId::new_with_driver::<PhyAX88796B>()
2020
],
2121
name: "rust_asix_phy",
22-
author: "FUJITA Tomonori <fujita.tomonori@gmail.com>",
22+
authors: ["FUJITA Tomonori <fujita.tomonori@gmail.com>"],
2323
description: "Rust Asix PHYs driver",
2424
license: "GPL",
2525
}

drivers/net/phy/qt2025.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ kernel::module_phy_driver! {
2626
phy::DeviceId::new_with_driver::<PhyQT2025>(),
2727
],
2828
name: "qt2025_phy",
29-
author: "FUJITA Tomonori <fujita.tomonori@gmail.com>",
29+
authors: ["FUJITA Tomonori <fujita.tomonori@gmail.com>"],
3030
description: "AMCC QT2025 PHY driver",
3131
license: "GPL",
3232
firmware: ["qt2025-2.0.3.3.fw"],

include/drm/drm_panic.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,11 @@ static inline void drm_panic_unlock(struct drm_device *dev, unsigned long flags)
163163

164164
#endif
165165

166+
#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE)
167+
size_t drm_panic_qr_max_data_size(u8 version, size_t url_len);
168+
169+
u8 drm_panic_qr_generate(const char *url, u8 *data, size_t data_len, size_t data_size,
170+
u8 *tmp, size_t tmp_size);
171+
#endif
172+
166173
#endif /* __DRM_PANIC_H__ */

include/linux/sprintf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ __scanf(2, 0) int vsscanf(const char *, const char *, va_list);
2424
extern bool no_hash_pointers;
2525
int no_hash_pointers_enable(char *str);
2626

27+
/* Used for Rust formatting ('%pA') */
28+
char *rust_fmt_argument(char *buf, char *end, const void *ptr);
29+
2730
#endif /* _LINUX_KERNEL_SPRINTF_H */

0 commit comments

Comments
 (0)