Skip to content

Commit 8f5b5f7

Browse files
committed
Merge tag 'rust-6.10' of https://github.com/Rust-for-Linux/linux
Pull Rust updates from Miguel Ojeda: "The most notable change is the drop of the 'alloc' in-tree fork. This is nicely reflected in the diffstat as a ~10k lines drop. In turn, this makes the version upgrades way simpler and smaller in the future, e.g. the latest one in commit 56f64b3 ("rust: upgrade to Rust 1.78.0"). More importantly, this increases the chances that a newer compiler version just works, which in turn means supporting several compiler versions is easier now. Thus we will look into finally setting a minimum version in the near future. Toolchain and infrastructure: - Upgrade to Rust 1.78.0 This time around, due to how the kernel and Rust schedules have aligned, there are two upgrades in fact. These allow us to remove one more unstable feature ('offset_of') from the list, among other improvements - Drop 'alloc' in-tree fork of the standard library crate, which means all the unstable features used by 'alloc' (~30 language ones, ~60 library ones) are not a concern anymore - Support DWARFv5 via the '-Zdwarf-version' flag - Support zlib and zstd debuginfo compression via the '-Zdebuginfo-compression' flag 'kernel' crate: - Support allocation flags ('GFP_*'), particularly in 'Box' (via 'BoxExt'), 'Vec' (via 'VecExt'), 'Arc' and 'UniqueArc', as well as in the 'init' module APIs - Remove usage of the 'allocator_api' unstable feature - Remove 'try_' prefix in allocation APIs' names - Add 'VecExt' (an extension trait) to be able to drop the 'alloc' fork - Add the '{make,to}_{upper,lower}case()' methods to 'CStr'/'CString' - Add the 'as_ptr' method to 'ThisModule' - Add the 'from_raw' method to 'ArcBorrow' - Add the 'into_unique_or_drop' method to 'Arc' - Display column number in the 'dbg!' macro output by applying the equivalent change done to the standard library one - Migrate 'Work' to '#[pin_data]' thanks to the changes in the 'macros' crate, which allows to remove an unsafe call in its 'new' associated function - Prevent namespacing issues when using the '[try_][pin_]init!' macros by changing the generated name of guard variables - Make the 'get' method in 'Opaque' const - Implement the 'Default' trait for 'LockClassKey' - Remove unneeded 'kernel::prelude' imports from doctests - Remove redundant imports 'macros' crate: - Add 'decl_generics' to 'parse_generics()' to support default values, and use that to allow them in '#[pin_data]' Helpers: - Trivial English grammar fix Documentation: - Add section on Rust Kselftests to the 'Testing' document - Expand the 'Abstractions vs. bindings' section of the 'General Information' document" * tag 'rust-6.10' of https://github.com/Rust-for-Linux/linux: (31 commits) rust: alloc: fix dangling pointer in VecExt<T>::reserve() rust: upgrade to Rust 1.78.0 rust: kernel: remove redundant imports rust: sync: implement `Default` for `LockClassKey` docs: rust: extend abstraction and binding documentation docs: rust: Add instructions for the Rust kselftest rust: remove unneeded `kernel::prelude` imports from doctests rust: update `dbg!()` to format column number rust: helpers: Fix grammar in comment rust: init: change the generated name of guard variables rust: sync: add `Arc::into_unique_or_drop` rust: sync: add `ArcBorrow::from_raw` rust: types: Make Opaque::get const rust: kernel: remove usage of `allocator_api` unstable feature rust: init: update `init` module to take allocation flags rust: sync: update `Arc` and `UniqueArc` to take allocation flags rust: alloc: update `VecExt` to take allocation flags rust: alloc: introduce the `BoxExt` trait rust: alloc: introduce allocation flags rust: alloc: remove our fork of the `alloc` crate ...
2 parents 84c7d76 + 97ab3e8 commit 8f5b5f7

Some content is hidden

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

53 files changed

+878
-10043
lines changed

Documentation/process/changes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ you probably needn't concern yourself with pcmciautils.
3131
====================== =============== ========================================
3232
GNU C 5.1 gcc --version
3333
Clang/LLVM (optional) 13.0.1 clang --version
34-
Rust (optional) 1.76.0 rustc --version
34+
Rust (optional) 1.78.0 rustc --version
3535
bindgen (optional) 0.65.1 bindgen --version
3636
GNU make 3.82 make --version
3737
bash 4.2 bash --version

Documentation/rust/general-information.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,63 @@ but it is intended that coverage is expanded as time goes on. "Leaf" modules
6464
(e.g. drivers) should not use the C bindings directly. Instead, subsystems
6565
should provide as-safe-as-possible abstractions as needed.
6666

67+
.. code-block::
68+
69+
rust/bindings/
70+
(rust/helpers.c)
71+
72+
include/ -----+ <-+
73+
| |
74+
drivers/ rust/kernel/ +----------+ <-+ |
75+
fs/ | bindgen | |
76+
.../ +-------------------+ +----------+ --+ |
77+
| Abstractions | | |
78+
+---------+ | +------+ +------+ | +----------+ | |
79+
| my_foo | -----> | | foo | | bar | | -------> | Bindings | <-+ |
80+
| driver | Safe | | sub- | | sub- | | Unsafe | | |
81+
+---------+ | |system| |system| | | bindings | <-----+
82+
| | +------+ +------+ | | crate | |
83+
| | kernel crate | +----------+ |
84+
| +-------------------+ |
85+
| |
86+
+------------------# FORBIDDEN #--------------------------------+
87+
88+
The main idea is to encapsulate all direct interaction with the kernel's C APIs
89+
into carefully reviewed and documented abstractions. Then users of these
90+
abstractions cannot introduce undefined behavior (UB) as long as:
91+
92+
#. The abstractions are correct ("sound").
93+
#. Any ``unsafe`` blocks respect the safety contract necessary to call the
94+
operations inside the block. Similarly, any ``unsafe impl``\ s respect the
95+
safety contract necessary to implement the trait.
96+
97+
Bindings
98+
~~~~~~~~
99+
100+
By including a C header from ``include/`` into
101+
``rust/bindings/bindings_helper.h``, the ``bindgen`` tool will auto-generate the
102+
bindings for the included subsystem. After building, see the ``*_generated.rs``
103+
output files in the ``rust/bindings/`` directory.
104+
105+
For parts of the C header that ``bindgen`` does not auto generate, e.g. C
106+
``inline`` functions or non-trivial macros, it is acceptable to add a small
107+
wrapper function to ``rust/helpers.c`` to make it available for the Rust side as
108+
well.
109+
110+
Abstractions
111+
~~~~~~~~~~~~
112+
113+
Abstractions are the layer between the bindings and the in-kernel users. They
114+
are located in ``rust/kernel/`` and their role is to encapsulate the unsafe
115+
access to the bindings into an as-safe-as-possible API that they expose to their
116+
users. Users of the abstractions include things like drivers or file systems
117+
written in Rust.
118+
119+
Besides the safety aspect, the abstractions are supposed to be "ergonomic", in
120+
the sense that they turn the C interfaces into "idiomatic" Rust code. Basic
121+
examples are to turn the C resource acquisition and release into Rust
122+
constructors and destructors or C integer error codes into Rust's ``Result``\ s.
123+
67124

68125
Conditional compilation
69126
-----------------------

Documentation/rust/testing.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ Testing
66
This document contains useful information how to test the Rust code in the
77
kernel.
88

9-
There are two sorts of tests:
9+
There are three sorts of tests:
1010

1111
- The KUnit tests.
1212
- The ``#[test]`` tests.
13+
- The Kselftests.
1314

1415
The KUnit tests
1516
---------------
@@ -133,3 +134,25 @@ Additionally, there are the ``#[test]`` tests. These can be run using the
133134
This requires the kernel ``.config`` and downloads external repositories. It
134135
runs the ``#[test]`` tests on the host (currently) and thus is fairly limited in
135136
what these tests can test.
137+
138+
The Kselftests
139+
--------------
140+
141+
Kselftests are also available in the ``tools/testing/selftests/rust`` folder.
142+
143+
The kernel config options required for the tests are listed in the
144+
``tools/testing/selftests/rust/config`` file and can be included with the aid
145+
of the ``merge_config.sh`` script::
146+
147+
./scripts/kconfig/merge_config.sh .config tools/testing/selftests/rust/config
148+
149+
The kselftests are built within the kernel source tree and are intended to
150+
be executed on a system that is running the same kernel.
151+
152+
Once a kernel matching the source tree has been installed and booted, the
153+
tests can be compiled and executed using the following command::
154+
155+
make TARGETS="rust" kselftest
156+
157+
Refer to Documentation/dev-tools/kselftest.rst for the general Kselftest
158+
documentation.

rust/Makefile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,9 @@ core-cfgs = \
6161
--cfg no_fp_fmt_parse
6262

6363
alloc-cfgs = \
64-
--cfg no_borrow \
65-
--cfg no_fmt \
6664
--cfg no_global_oom_handling \
67-
--cfg no_macros \
6865
--cfg no_rc \
69-
--cfg no_str \
70-
--cfg no_string \
71-
--cfg no_sync \
72-
--cfg no_thin
66+
--cfg no_sync
7367

7468
quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
7569
cmd_rustdoc = \
@@ -123,7 +117,7 @@ rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
123117
# due to things that are "configured out" vs. entirely non-existing ones.
124118
rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
125119
-Arustdoc::broken_intra_doc_links
126-
rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
120+
rustdoc-alloc: $(RUST_LIB_SRC)/alloc/src/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
127121
+$(call if_changed,rustdoc)
128122

129123
rustdoc-kernel: private rustc_target_flags = --extern alloc \
@@ -218,8 +212,6 @@ rusttest: rusttest-macros rusttest-kernel
218212
# - `cargo` only considers the use case of building the standard library
219213
# to use it in a given package. Thus we need to create a dummy package
220214
# and pick the generated libraries from there.
221-
# - Since we only keep a subset of upstream `alloc` in-tree, we need
222-
# to recreate it on the fly by putting our sources on top.
223215
# - The usual ways of modifying the dependency graph in `cargo` do not seem
224216
# to apply for the `-Zbuild-std` steps, thus we have to mislead it
225217
# by modifying the sources in the sysroot.
@@ -238,8 +230,6 @@ quiet_cmd_rustsysroot = RUSTSYSROOT
238230
rm -rf $(objtree)/$(obj)/test; \
239231
mkdir -p $(objtree)/$(obj)/test; \
240232
cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
241-
cp -r $(srctree)/$(src)/alloc/* \
242-
$(objtree)/$(obj)/test/sysroot/lib/rustlib/src/rust/library/alloc/src; \
243233
echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
244234
echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
245235
>> $(objtree)/$(obj)/test/rustc_sysroot; \
@@ -447,7 +437,7 @@ $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
447437
$(obj)/alloc.o: private skip_clippy = 1
448438
$(obj)/alloc.o: private skip_flags = -Dunreachable_pub
449439
$(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
450-
$(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
440+
$(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib.rs $(obj)/compiler_builtins.o FORCE
451441
+$(call if_changed_dep,rustc_library)
452442

453443
$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE

rust/alloc/README.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)