<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/rust/macros/lib.rs, branch v6.18.21</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.18.21</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.18.21'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-05-27T18:09:59+00:00</updated>
<entry>
<title>rust: add `kunit_tests` to the prelude</title>
<updated>2025-05-27T18:09:59+00:00</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-05-02T21:51:28+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=897d1df6532f05814acd364af9055cd6628fd1b3'/>
<id>urn:sha1:897d1df6532f05814acd364af9055cd6628fd1b3</id>
<content type='text'>
It is convenient to have certain things in the `kernel` prelude, and
means kernel developers will find it even easier to start writing tests.

And, anyway, nobody should need to use this identifier for anything else.

Thus add it to the prelude.

Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20250502215133.1923676-4-ojeda@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: kunit: support KUnit-mapped `assert!` macros in `#[test]`s</title>
<updated>2025-05-27T18:07:09+00:00</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2025-05-02T21:51:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=36174d16f3ec072f9e07b6c6d59ba91b2d52f9e2'/>
<id>urn:sha1:36174d16f3ec072f9e07b6c6d59ba91b2d52f9e2</id>
<content type='text'>
The KUnit `#[test]` support that landed recently is very basic and does
not map the `assert*!` macros into KUnit like the doctests do, so they
panic at the moment.

Thus implement the custom mapping in a similar way to doctests, reusing
the infrastructure there.

In Rust 1.88.0, the `file()` method in `Span` may be stable [1]. However,
it was changed recently (from `SourceFile`), so we need to do something
different in previous versions. Thus create a helper for it and use it
to get the path.

With this, a failing test suite like:

    #[kunit_tests(my_test_suite)]
    mod tests {
        use super::*;

        #[test]
        fn my_first_test() {
            assert_eq!(42, 43);
        }

        #[test]
        fn my_second_test() {
            assert!(42 &gt;= 43);
        }
    }

will properly map back to KUnit, printing something like:

    [    1.924325]     KTAP version 1
    [    1.924421]     # Subtest: my_test_suite
    [    1.924506]     # speed: normal
    [    1.924525]     1..2
    [    1.926385]     # my_first_test: ASSERTION FAILED at rust/kernel/lib.rs:251
    [    1.926385]     Expected 42 == 43 to be true, but is false
    [    1.928026]     # my_first_test.speed: normal
    [    1.928075]     not ok 1 my_first_test
    [    1.928723]     # my_second_test: ASSERTION FAILED at rust/kernel/lib.rs:256
    [    1.928723]     Expected 42 &gt;= 43 to be true, but is false
    [    1.929834]     # my_second_test.speed: normal
    [    1.929868]     not ok 2 my_second_test
    [    1.930032] # my_test_suite: pass:0 fail:2 skip:0 total:2
    [    1.930153] # Totals: pass:0 fail:2 skip:0 total

Link: https://github.com/rust-lang/rust/pull/140514 [1]
Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Acked-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20250502215133.1923676-2-ojeda@kernel.org
[ Required `KUNIT=y` like for doctests. Used the `cfg_attr` from the
  TODO comment and clarified its comment now that the stabilization is
  in beta and thus quite likely stable in Rust 1.88.0. Simplified the
  `new_body` code by introducing a new variable. Added
  `#[allow(clippy::incompatible_msrv)]`. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: make section names plural</title>
<updated>2025-05-26T16:03:09+00:00</updated>
<author>
<name>Patrick Miller</name>
<email>paddymills@proton.me</email>
</author>
<published>2024-10-02T02:28:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=4bf7b97eb390f0a0730572101e0ce3367d31a770'/>
<id>urn:sha1:4bf7b97eb390f0a0730572101e0ce3367d31a770</id>
<content type='text'>
Clean Rust documentation section headers to use plural names.

Suggested-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Link: https://github.com/Rust-for-Linux/linux/issues/1110
Signed-off-by: Patrick Miller &lt;paddymills@proton.me&gt;
Link: https://lore.kernel.org/r/20241002022749.390836-1-paddymills@proton.me
[ Removed the `init` one that doesn't apply anymore and
  reworded slightly. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: use absolute paths in macros referencing core and kernel</title>
<updated>2025-05-22T22:12:14+00:00</updated>
<author>
<name>Igor Korotin</name>
<email>igor.korotin.linux@gmail.com</email>
</author>
<published>2025-05-19T16:45:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=de7cd3e4d6387df6a5ae8c4c32ff0479ebe0efb5'/>
<id>urn:sha1:de7cd3e4d6387df6a5ae8c4c32ff0479ebe0efb5</id>
<content type='text'>
Macros and auto-generated code should use absolute paths, `::core::...`
and `::kernel::...`, for core and kernel references.

This prevents issues where user-defined modules named `core` or `kernel`
could be picked up instead of the `core` or `kernel` crates.

Thus clean some references up.

Suggested-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Closes: https://github.com/Rust-for-Linux/linux/issues/1150
Signed-off-by: Igor Korotin &lt;igor.korotin.linux@gmail.com&gt;
Reviewed-by: Benno Lossin &lt;lossin@kernel.org&gt;
Acked-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Link: https://lore.kernel.org/r/20250519164615.3310844-1-igor.korotin.linux@gmail.com
[ Applied `rustfmt`. Reworded slightly. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: macros: add macro to easily run KUnit tests</title>
<updated>2025-03-20T11:26:54+00:00</updated>
<author>
<name>José Expósito</name>
<email>jose.exposito89@gmail.com</email>
</author>
<published>2025-03-07T09:00:57+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=c0010452893e07e032427e88f6b7b4bf7ac42e95'/>
<id>urn:sha1:c0010452893e07e032427e88f6b7b4bf7ac42e95</id>
<content type='text'>
Add a new procedural macro (`#[kunit_tests(kunit_test_suit_name)]`) to
run KUnit tests using a user-space like syntax.

The macro, that should be used on modules, transforms every `#[test]`
in a `kunit_case!` and adds a `kunit_unsafe_test_suite!` registering
all of them.

The only difference with user-space tests is that instead of using
`#[cfg(test)]`, `#[kunit_tests(kunit_test_suit_name)]` is used.

Note that `#[cfg(CONFIG_KUNIT)]` is added so the test module is not
compiled when `CONFIG_KUNIT` is set to `n`.

Reviewed-by: David Gow &lt;davidgow@google.com&gt;
Signed-off-by: José Expósito &lt;jose.exposito89@gmail.com&gt;
Co-developed-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Co-developed-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Reviewed-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Signed-off-by: David Gow &lt;davidgow@google.com&gt;
Link: https://lore.kernel.org/r/20250307090103.918788-3-davidgow@google.com
[ Removed spurious (in rendered form) newline in docs. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: make pin-init its own crate</title>
<updated>2025-03-16T20:59:19+00:00</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2025-03-08T11:05:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=dbd5058ba60c3499b24a7133a4e2e24dba6ea77b'/>
<id>urn:sha1:dbd5058ba60c3499b24a7133a4e2e24dba6ea77b</id>
<content type='text'>
Rename relative paths inside of the crate to still refer to the same
items, also rename paths inside of the kernel crate and adjust the build
system to build the crate.

[ Remove the `expect` (and thus the `lint_reasons` feature) since
  the tree now uses `quote!` from `rust/macros/export.rs`. Remove the
  `TokenStream` import removal, since it is now used as well.

  In addition, temporarily (i.e. just for this commit) use an `--extern
  force:alloc` to prevent an unknown `new_uninit` error in the `rustdoc`
  target. For context, please see a similar case in:

      https://lore.kernel.org/lkml/20240422090644.525520-1-ojeda@kernel.org/

  And adjusted the message above. - Miguel ]

Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250308110339.2997091-16-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: move pin-init API into its own directory</title>
<updated>2025-03-16T20:59:18+00:00</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2025-03-08T11:04:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=fbf8fb328d1bfe3bd17d5c5626cb485a1ca1a50d'/>
<id>urn:sha1:fbf8fb328d1bfe3bd17d5c5626cb485a1ca1a50d</id>
<content type='text'>
In preparation of splitting off the pin-init crate from the kernel
crate, move all pin-init API code (including proc-macros) into
`rust/pin-init`.

Moved modules have their import path adjusted via the `#[path = "..."]`
attribute. This allows the files to still be imported in the kernel
crate even though the files are in different directories.

Code that is moved out of files (but the file itself stays where it is)
is imported via the `include!` macro. This also allows the code to be
moved while still being part of the kernel crate.

Note that this commit moves the generics parsing code out of the GPL-2.0
file `rust/macros/helpers.rs` into the Apache-2.0 OR MIT file
`rust/pin_init/internal/src/helpers.rs`. I am the sole author of that
code and it already is available with that license at [1].
The same is true for the entry-points of the proc-macros `pin_data`,
`pinned_drop` and `derive_zeroable` in `rust/macros/lib.rs` that are
moved to `rust/pin_data/internal/src/lib.rs`. Although there are some
smaller patches that fix the doctests.

Link: https://github.com/Rust-for-Linux/pinned-init [1]
Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250308110339.2997091-3-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: init: disable doctests</title>
<updated>2025-03-16T20:59:18+00:00</updated>
<author>
<name>Benno Lossin</name>
<email>benno.lossin@proton.me</email>
</author>
<published>2025-03-08T11:03:51+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=206dea39e55968d8f3ad56771507361eb799dfc7'/>
<id>urn:sha1:206dea39e55968d8f3ad56771507361eb799dfc7</id>
<content type='text'>
The build system cannot handle doctests in the kernel crate in files
outside of `rust/kernel/`. Subsequent commits will move files out of
that directory, but will still compile them as part of the kernel crate.
Thus ignore all doctests in the to-be-moved files.

Leave tests disabled until they are separated into their own crate and
they stop causing breakage.

Signed-off-by: Benno Lossin &lt;benno.lossin@proton.me&gt;
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250308110339.2997091-2-benno.lossin@proton.me
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: module: introduce `authors` key</title>
<updated>2025-03-10T14:12:17+00:00</updated>
<author>
<name>Guilherme Giacomo Simoes</name>
<email>trintaeoitogc@gmail.com</email>
</author>
<published>2025-03-09T17:57:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=38559da6afb239e271e709588babe7f98195096b'/>
<id>urn:sha1:38559da6afb239e271e709588babe7f98195096b</id>
<content type='text'>
In the `module!` macro, the `author` field is currently of type `String`.

Since modules can have multiple authors, this limitation prevents
specifying more than one.

Add an `authors` field as `Option&lt;Vec&lt;String&gt;&gt;` to allow creating
modules with multiple authors, and change the documentation and all
current users to use it. Eventually, the single `author` field may
be removed.

[ The `modinfo` key needs to still be `author`; otherwise, tooling
  may not work properly, e.g.:

      $ modinfo --author samples/rust/rust_print.ko
      Rust for Linux Contributors

  I have also kept the original `author` field (undocumented), so
  that we can drop it more easily in a kernel cycle or two.

    - Miguel ]

Suggested-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
Link: https://github.com/Rust-for-Linux/linux/issues/244
Reviewed-by: Charalampos Mitrodimas &lt;charmitro@posteo.net&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Signed-off-by: Guilherme Giacomo Simoes &lt;trintaeoitogc@gmail.com&gt;
Link: https://lore.kernel.org/r/20250309175712.845622-2-trintaeoitogc@gmail.com
[ Fixed `modinfo` key. Kept `author` field. Reworded message
  accordingly. Updated my email. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: add #[export] macro</title>
<updated>2025-03-09T19:52:46+00:00</updated>
<author>
<name>Alice Ryhl</name>
<email>aliceryhl@google.com</email>
</author>
<published>2025-03-03T08:45:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=44e333fe464a253f703982f721c7155218f63d1f'/>
<id>urn:sha1:44e333fe464a253f703982f721c7155218f63d1f</id>
<content type='text'>
Rust has two different tools for generating function declarations to
call across the FFI boundary:

* bindgen. Generates Rust declarations from a C header.
* cbindgen. Generates C headers from Rust declarations.

However, we only use bindgen in the kernel. This means that when C code
calls a Rust function by name, its signature must be duplicated in both
Rust code and a C header, and the signature needs to be kept in sync
manually.

Introducing cbindgen as a mandatory dependency to build the kernel would
be a rather complex and large change, so we do not consider that at this
time. Instead, to eliminate this manual checking, introduce a new macro
that verifies at compile time that the two function declarations use the
same signature. The idea is to run the C declaration through bindgen,
and then have rustc verify that the function pointers have the same
type.

The signature must still be written twice, but at least you can no
longer get it wrong. If the signatures don't match, you will get errors
that look like this:

error[E0308]: `if` and `else` have incompatible types
  --&gt; &lt;linux&gt;/rust/kernel/print.rs:22:22
   |
21 | #[export]
   | --------- expected because of this
22 | unsafe extern "C" fn rust_fmt_argument(
   |                      ^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
   |
   = note: expected fn item `unsafe extern "C" fn(*mut u8, *mut u8, *mut c_void) -&gt; *mut u8 {bindings::rust_fmt_argument}`
              found fn item `unsafe extern "C" fn(*mut i8, *mut i8, *const c_void) -&gt; *mut i8 {print::rust_fmt_argument}`

It is unfortunate that the error message starts out by saying "`if` and
`else` have incompatible types", but I believe the rest of the error
message is reasonably clear and not too confusing.

Reviewed-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Acked-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Link: https://lore.kernel.org/r/20250303-export-macro-v3-3-41fbad85a27f@google.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
