Skip to content

Commit ec7714e

Browse files
committed
Merge tag 'rust-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust updates from Miguel Ojeda: "Toolchain and infrastructure: - KUnit '#[test]'s: - Support KUnit-mapped 'assert!' macros. The support that landed last cycle was very basic, and the 'assert!' macros panicked since they were the standard library ones. Now, they are mapped to the KUnit ones in a similar way to how is done for doctests, reusing the infrastructure there. With this, a failing test like: #[test] fn my_first_test() { assert_eq!(42, 43); } will report: # my_first_test: ASSERTION FAILED at rust/kernel/lib.rs:251 Expected 42 == 43 to be true, but is false # my_first_test.speed: normal not ok 1 my_first_test - Support tests with checked 'Result' return types. The return value of test functions that return a 'Result' will be checked, thus one can now easily catch errors when e.g. using the '?' operator in tests. With this, a failing test like: #[test] fn my_test() -> Result { f()?; Ok(()) } will report: # my_test: ASSERTION FAILED at rust/kernel/lib.rs:321 Expected is_test_result_ok(my_test()) to be true, but is false # my_test.speed: normal not ok 1 my_test - Add 'kunit_tests' to the prelude. - Clarify the remaining language unstable features in use. - Compile 'core' with edition 2024 for Rust >= 1.87. - Workaround 'bindgen' issue with forward references to 'enum' types. - objtool: relax slice condition to cover more 'noreturn' functions. - Use absolute paths in macros referencing 'core' and 'kernel' crates. - Skip '-mno-fdpic' flag for bindgen in GCC 32-bit arm builds. - Clean some 'doc_markdown' lint hits -- we may enable it later on. 'kernel' crate: - 'alloc' module: - 'Box': support for type coercion, e.g. 'Box<T>' to 'Box<dyn U>' if 'T' implements 'U'. - 'Vec': implement new methods (prerequisites for nova-core and binder): 'truncate', 'resize', 'clear', 'pop', 'push_within_capacity' (with new error type 'PushError'), 'drain_all', 'retain', 'remove' (with new error type 'RemoveError'), insert_within_capacity' (with new error type 'InsertError'). In addition, simplify 'push' using 'spare_capacity_mut', split 'set_len' into 'inc_len' and 'dec_len', add type invariant 'len <= capacity' and simplify 'truncate' using 'dec_len'. - 'time' module: - Morph the Rust hrtimer subsystem into the Rust timekeeping subsystem, covering delay, sleep, timekeeping, timers. This new subsystem has all the relevant timekeeping C maintainers listed in the entry. - Replace 'Ktime' with 'Delta' and 'Instant' types to represent a duration of time and a point in time. - Temporarily add 'Ktime' to 'hrtimer' module to allow 'hrtimer' to delay converting to 'Instant' and 'Delta'. - 'xarray' module: - Add a Rust abstraction for the 'xarray' data structure. This abstraction allows Rust code to leverage the 'xarray' to store types that implement 'ForeignOwnable'. This support is a dependency for memory backing feature of the Rust null block driver, which is waiting to be merged. - Set up an entry in 'MAINTAINERS' for the XArray Rust support. Patches will go to the new Rust XArray tree and then via the Rust subsystem tree for now. - Allow 'ForeignOwnable' to carry information about the pointed-to type. This helps asserting alignment requirements for the pointer passed to the foreign language. - 'container_of!': retain pointer mut-ness and add a compile-time check of the type of the first parameter ('$field_ptr'). - Support optional message in 'static_assert!'. - Add C FFI types (e.g. 'c_int') to the prelude. - 'str' module: simplify KUnit tests 'format!' macro, convert 'rusttest' tests into KUnit, take advantage of the '-> Result' support in KUnit '#[test]'s. - 'list' module: add examples for 'List', fix path of 'assert_pinned!' (so far unused macro rule). - 'workqueue' module: remove 'HasWork::OFFSET'. - 'page' module: add 'inline' attribute. 'macros' crate: - 'module' macro: place 'cleanup_module()' in '.exit.text' section. 'pin-init' crate: - Add 'Wrapper<T>' trait for creating pin-initializers for wrapper structs with a structurally pinned value such as 'UnsafeCell<T>' or 'MaybeUninit<T>'. - Add 'MaybeZeroable' derive macro to try to derive 'Zeroable', but not error if not all fields implement it. This is needed to derive 'Zeroable' for all bindgen-generated structs. - Add 'unsafe fn cast_[pin_]init()' functions to unsafely change the initialized type of an initializer. These are utilized by the 'Wrapper<T>' implementations. - Add support for visibility in 'Zeroable' derive macro. - Add support for 'union's in 'Zeroable' derive macro. - Upstream dev news: streamline CI, fix some bugs. Add new workflows to check if the user-space version and the one in the kernel tree have diverged. Use the issues tab [1] to track them, which should help folks report and diagnose issues w.r.t. 'pin-init' better. [1] https://github.com/rust-for-linux/pin-init/issues Documentation: - Testing: add docs on the new KUnit '#[test]' tests. - Coding guidelines: explain that '///' vs. '//' applies to private items too. Add section on C FFI types. - Quick Start guide: update Ubuntu instructions and split them into "25.04" and "24.04 LTS and older". And a few other cleanups and improvements" * tag 'rust-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (78 commits) rust: list: Fix typo `much` in arc.rs rust: check type of `$ptr` in `container_of!` rust: workqueue: remove HasWork::OFFSET rust: retain pointer mut-ness in `container_of!` Documentation: rust: testing: add docs on the new KUnit `#[test]` tests Documentation: rust: rename `#[test]`s to "`rusttest` host tests" rust: str: take advantage of the `-> Result` support in KUnit `#[test]`'s rust: str: simplify KUnit tests `format!` macro rust: str: convert `rusttest` tests into KUnit rust: add `kunit_tests` to the prelude rust: kunit: support checked `-> Result`s in KUnit `#[test]`s rust: kunit: support KUnit-mapped `assert!` macros in `#[test]`s rust: make section names plural rust: list: fix path of `assert_pinned!` rust: compile libcore with edition 2024 for 1.87+ rust: dma: add missing Markdown code span rust: task: add missing Markdown code spans and intra-doc links rust: pci: fix docs related to missing Markdown code spans rust: alloc: add missing Markdown code span rust: alloc: add missing Markdown code spans ...
2 parents 6498044 + 7a17bbc commit ec7714e

Some content is hidden

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

69 files changed

+1973
-387
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Ben Widawsky <[email protected]> <[email protected]>
135135
136136
Benjamin Tissoires <[email protected]> <[email protected]>
137137
Benjamin Tissoires <[email protected]> <[email protected]>
138+
138139
139140
140141

Documentation/rust/coding-guidelines.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ written after the documentation, e.g.:
8585
// ...
8686
}
8787
88+
This applies to both public and private items. This increases consistency with
89+
public items, allows changes to visibility with less changes involved and will
90+
allow us to potentially generate the documentation for private items as well.
91+
In other words, if documentation is written for a private item, then ``///``
92+
should still be used. For instance:
93+
94+
.. code-block:: rust
95+
96+
/// My private function.
97+
// TODO: ...
98+
fn f() {}
99+
88100
One special kind of comments are the ``// SAFETY:`` comments. These must appear
89101
before every ``unsafe`` block, and they explain why the code inside the block is
90102
correct/sound, i.e. why it cannot trigger undefined behavior in any case, e.g.:
@@ -191,6 +203,23 @@ or:
191203
/// [`struct mutex`]: srctree/include/linux/mutex.h
192204
193205
206+
C FFI types
207+
-----------
208+
209+
Rust kernel code refers to C types, such as ``int``, using type aliases such as
210+
``c_int``, which are readily available from the ``kernel`` prelude. Please do
211+
not use the aliases from ``core::ffi`` -- they may not map to the correct types.
212+
213+
These aliases should generally be referred directly by their identifier, i.e.
214+
as a single segment path. For instance:
215+
216+
.. code-block:: rust
217+
218+
fn f(p: *const c_char) -> c_int {
219+
// ...
220+
}
221+
222+
194223
Naming
195224
------
196225

Documentation/rust/quick-start.rst

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,53 @@ they should generally work out of the box, e.g.::
9090
Ubuntu
9191
******
9292

93-
Ubuntu LTS and non-LTS (interim) releases provide recent Rust releases and thus
94-
they should generally work out of the box, e.g.::
93+
25.04
94+
~~~~~
95+
96+
The latest Ubuntu releases provide recent Rust releases and thus they should
97+
generally work out of the box, e.g.::
98+
99+
apt install rustc rust-src bindgen rustfmt rust-clippy
100+
101+
In addition, ``RUST_LIB_SRC`` needs to be set, e.g.::
102+
103+
RUST_LIB_SRC=/usr/src/rustc-$(rustc --version | cut -d' ' -f2)/library
104+
105+
For convenience, ``RUST_LIB_SRC`` can be exported to the global environment.
95106

96-
apt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 rust-1.80-clippy
107+
108+
24.04 LTS and older
109+
~~~~~~~~~~~~~~~~~~~
110+
111+
Though Ubuntu 24.04 LTS and older versions still provide recent Rust
112+
releases, they require some additional configuration to be set, using
113+
the versioned packages, e.g.::
114+
115+
apt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 \
116+
rust-1.80-clippy
117+
ln -s /usr/lib/rust-1.80/bin/rustfmt /usr/bin/rustfmt-1.80
118+
ln -s /usr/lib/rust-1.80/bin/clippy-driver /usr/bin/clippy-driver-1.80
119+
120+
None of these packages set their tools as defaults; therefore they should be
121+
specified explicitly, e.g.::
122+
123+
make LLVM=1 RUSTC=rustc-1.80 RUSTDOC=rustdoc-1.80 RUSTFMT=rustfmt-1.80 \
124+
CLIPPY_DRIVER=clippy-driver-1.80 BINDGEN=bindgen-0.65
125+
126+
Alternatively, modify the ``PATH`` variable to place the Rust 1.80 binaries
127+
first and set ``bindgen`` as the default, e.g.::
128+
129+
PATH=/usr/lib/rust-1.80/bin:$PATH
130+
update-alternatives --install /usr/bin/bindgen bindgen \
131+
/usr/bin/bindgen-0.65 100
132+
update-alternatives --set bindgen /usr/bin/bindgen-0.65
97133

98134
``RUST_LIB_SRC`` needs to be set when using the versioned packages, e.g.::
99135

100136
RUST_LIB_SRC=/usr/src/rustc-$(rustc-1.80 --version | cut -d' ' -f2)/library
101137

138+
For convenience, ``RUST_LIB_SRC`` can be exported to the global environment.
139+
102140
In addition, ``bindgen-0.65`` is available in newer releases (24.04 LTS and
103141
24.10), but it may not be available in older ones (20.04 LTS and 22.04 LTS),
104142
thus ``bindgen`` may need to be built manually (please see below).

Documentation/rust/testing.rst

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,85 @@ please see:
133133
The ``#[test]`` tests
134134
---------------------
135135

136-
Additionally, there are the ``#[test]`` tests. These can be run using the
137-
``rusttest`` Make target::
136+
Additionally, there are the ``#[test]`` tests. Like for documentation tests,
137+
these are also fairly similar to what you would expect from userspace, and they
138+
are also mapped to KUnit.
139+
140+
These tests are introduced by the ``kunit_tests`` procedural macro, which takes
141+
the name of the test suite as an argument.
142+
143+
For instance, assume we want to test the function ``f`` from the documentation
144+
tests section. We could write, in the same file where we have our function:
145+
146+
.. code-block:: rust
147+
148+
#[kunit_tests(rust_kernel_mymod)]
149+
mod tests {
150+
use super::*;
151+
152+
#[test]
153+
fn test_f() {
154+
assert_eq!(f(10, 20), 30);
155+
}
156+
}
157+
158+
And if we run it, the kernel log would look like::
159+
160+
KTAP version 1
161+
# Subtest: rust_kernel_mymod
162+
# speed: normal
163+
1..1
164+
# test_f.speed: normal
165+
ok 1 test_f
166+
ok 1 rust_kernel_mymod
167+
168+
Like documentation tests, the ``assert!`` and ``assert_eq!`` macros are mapped
169+
back to KUnit and do not panic. Similarly, the
170+
`? <https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator>`_
171+
operator is supported, i.e. the test functions may return either nothing (i.e.
172+
the unit type ``()``) or ``Result`` (i.e. any ``Result<T, E>``). For instance:
173+
174+
.. code-block:: rust
175+
176+
#[kunit_tests(rust_kernel_mymod)]
177+
mod tests {
178+
use super::*;
179+
180+
#[test]
181+
fn test_g() -> Result {
182+
let x = g()?;
183+
assert_eq!(x, 30);
184+
Ok(())
185+
}
186+
}
187+
188+
If we run the test and the call to ``g`` fails, then the kernel log would show::
189+
190+
KTAP version 1
191+
# Subtest: rust_kernel_mymod
192+
# speed: normal
193+
1..1
194+
# test_g: ASSERTION FAILED at rust/kernel/lib.rs:335
195+
Expected is_test_result_ok(test_g()) to be true, but is false
196+
# test_g.speed: normal
197+
not ok 1 test_g
198+
not ok 1 rust_kernel_mymod
199+
200+
If a ``#[test]`` test could be useful as an example for the user, then please
201+
use a documentation test instead. Even edge cases of an API, e.g. error or
202+
boundary cases, can be interesting to show in examples.
203+
204+
The ``rusttest`` host tests
205+
---------------------------
206+
207+
These are userspace tests that can be built and run in the host (i.e. the one
208+
that performs the kernel build) using the ``rusttest`` Make target::
138209

139210
make LLVM=1 rusttest
140211

141-
This requires the kernel ``.config``. It runs the ``#[test]`` tests on the host
142-
(currently) and thus is fairly limited in what these tests can test.
212+
This requires the kernel ``.config``.
213+
214+
Currently, they are mostly used for testing the ``macros`` crate's examples.
143215

144216
The Kselftests
145217
--------------

MAINTAINERS

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10719,20 +10719,23 @@ F: kernel/time/timer_list.c
1071910719
F: kernel/time/timer_migration.*
1072010720
F: tools/testing/selftests/timers/
1072110721

10722-
HIGH-RESOLUTION TIMERS [RUST]
10722+
DELAY, SLEEP, TIMEKEEPING, TIMERS [RUST]
1072310723
M: Andreas Hindborg <[email protected]>
1072410724
R: Boqun Feng <[email protected]>
10725+
R: FUJITA Tomonori <[email protected]>
1072510726
R: Frederic Weisbecker <[email protected]>
1072610727
R: Lyude Paul <[email protected]>
1072710728
R: Thomas Gleixner <[email protected]>
1072810729
R: Anna-Maria Behnsen <[email protected]>
10730+
R: John Stultz <[email protected]>
10731+
R: Stephen Boyd <[email protected]>
1072910732
1073010733
S: Supported
1073110734
W: https://rust-for-linux.com
1073210735
B: https://github.com/Rust-for-Linux/linux/issues
10733-
T: git https://github.com/Rust-for-Linux/linux.git hrtimer-next
10734-
F: rust/kernel/time/hrtimer.rs
10735-
F: rust/kernel/time/hrtimer/
10736+
T: git https://github.com/Rust-for-Linux/linux.git timekeeping-next
10737+
F: rust/kernel/time.rs
10738+
F: rust/kernel/time/
1073610739

1073710740
HIGH-SPEED SCC DRIVER FOR AX.25
1073810741
@@ -21588,7 +21591,7 @@ M: Alex Gaynor <[email protected]>
2158821591
R: Boqun Feng <[email protected]>
2158921592
R: Gary Guo <[email protected]>
2159021593
R: Björn Roy Baron <[email protected]>
21591-
R: Benno Lossin <benno.lossin@proton.me>
21594+
R: Benno Lossin <lossin@kernel.org>
2159221595
R: Andreas Hindborg <[email protected]>
2159321596
R: Alice Ryhl <[email protected]>
2159421597
R: Trevor Gross <[email protected]>
@@ -21618,7 +21621,7 @@ F: rust/kernel/alloc.rs
2161821621
F: rust/kernel/alloc/
2161921622

2162021623
RUST [PIN-INIT]
21621-
M: Benno Lossin <benno.lossin@proton.me>
21624+
M: Benno Lossin <lossin@kernel.org>
2162221625
2162321626
S: Maintained
2162421627
W: https://rust-for-linux.com/pin-init
@@ -26829,6 +26832,17 @@ F: lib/test_xarray.c
2682926832
F: lib/xarray.c
2683026833
F: tools/testing/radix-tree
2683126834

26835+
XARRAY API [RUST]
26836+
M: Tamir Duberstein <[email protected]>
26837+
M: Andreas Hindborg <[email protected]>
26838+
26839+
S: Supported
26840+
W: https://rust-for-linux.com
26841+
B: https://github.com/Rust-for-Linux/linux/issues
26842+
C: https://rust-for-linux.zulipchat.com
26843+
T: git https://github.com/Rust-for-Linux/linux.git xarray-next
26844+
F: rust/kernel/xarray.rs
26845+
2683226846
XBOX DVD IR REMOTE
2683326847
M: Benjamin Valentin <[email protected]>
2683426848
S: Maintained

init/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ config LD_CAN_USE_KEEP_IN_OVERLAY
136136
config RUSTC_HAS_COERCE_POINTEE
137137
def_bool RUSTC_VERSION >= 108400
138138

139+
config RUSTC_HAS_SPAN_FILE
140+
def_bool RUSTC_VERSION >= 108800
141+
139142
config RUSTC_HAS_UNNECESSARY_TRANSMUTES
140143
def_bool RUSTC_VERSION >= 108800
141144

rust/Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ endif
6060
core-cfgs = \
6161
--cfg no_fp_fmt_parse
6262

63+
core-edition := $(if $(call rustc-min-version,108700),2024,2021)
64+
6365
# `rustc` recognizes `--remap-path-prefix` since 1.26.0, but `rustdoc` only
6466
# since Rust 1.81.0. Moreover, `rustdoc` ICEs on out-of-tree builds since Rust
6567
# 1.82.0 (https://github.com/rust-lang/rust/issues/138520). Thus workaround both
@@ -106,8 +108,8 @@ rustdoc-macros: $(src)/macros/lib.rs FORCE
106108

107109
# Starting with Rust 1.82.0, skipping `-Wrustdoc::unescaped_backticks` should
108110
# not be needed -- see https://github.com/rust-lang/rust/pull/128307.
109-
rustdoc-core: private skip_flags = -Wrustdoc::unescaped_backticks
110-
rustdoc-core: private rustc_target_flags = $(core-cfgs)
111+
rustdoc-core: private skip_flags = --edition=2021 -Wrustdoc::unescaped_backticks
112+
rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs)
111113
rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
112114
+$(call if_changed,rustdoc)
113115

@@ -273,7 +275,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
273275
-fzero-call-used-regs=% -fno-stack-clash-protection \
274276
-fno-inline-functions-called-once -fsanitize=bounds-strict \
275277
-fstrict-flex-arrays=% -fmin-function-alignment=% \
276-
-fzero-init-padding-bits=% \
278+
-fzero-init-padding-bits=% -mno-fdpic \
277279
--param=% --param asan-%
278280

279281
# Derived from `scripts/Makefile.clang`.
@@ -402,7 +404,8 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
402404
-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
403405
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
404406
--crate-type proc-macro \
405-
--crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) $<
407+
--crate-name $(patsubst lib%.$(libmacros_extension),%,$(notdir $@)) \
408+
@$(objtree)/include/generated/rustc_cfg $<
406409

407410
# Procedural macros can only be used with the `rustc` that compiled it.
408411
$(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE
@@ -416,7 +419,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
416419
cmd_rustc_library = \
417420
OBJTREE=$(abspath $(objtree)) \
418421
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
419-
$(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
422+
$(filter-out $(skip_flags),$(rust_flags)) $(rustc_target_flags) \
420423
--emit=dep-info=$(depfile) --emit=obj=$@ \
421424
--emit=metadata=$(dir $@)$(patsubst %.o,lib%.rmeta,$(notdir $@)) \
422425
--crate-type rlib -L$(objtree)/$(obj) \
@@ -427,7 +430,7 @@ quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L
427430

428431
rust-analyzer:
429432
$(Q)MAKEFLAGS= $(srctree)/scripts/generate_rust_analyzer.py \
430-
--cfgs='core=$(core-cfgs)' \
433+
--cfgs='core=$(core-cfgs)' $(core-edition) \
431434
$(realpath $(srctree)) $(realpath $(objtree)) \
432435
$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
433436
> rust-project.json
@@ -483,9 +486,9 @@ $(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE
483486
$(obj)/exports.o: private skip_gendwarfksyms = 1
484487

485488
$(obj)/core.o: private skip_clippy = 1
486-
$(obj)/core.o: private skip_flags = -Wunreachable_pub
489+
$(obj)/core.o: private skip_flags = --edition=2021 -Wunreachable_pub
487490
$(obj)/core.o: private rustc_objcopy = $(foreach sym,$(redirect-intrinsics),--redefine-sym $(sym)=__rust$(sym))
488-
$(obj)/core.o: private rustc_target_flags = $(core-cfgs)
491+
$(obj)/core.o: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs)
489492
$(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \
490493
$(wildcard $(objtree)/include/config/RUSTC_VERSION_TEXT) FORCE
491494
+$(call if_changed_rule,rustc_library)

rust/bindings/bindings_helper.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66
* Sorted alphabetically.
77
*/
88

9+
/*
10+
* First, avoid forward references to `enum` types.
11+
*
12+
* This workarounds a `bindgen` issue with them:
13+
* <https://github.com/rust-lang/rust-bindgen/issues/3179>.
14+
*
15+
* Without this, the generated Rust type may be the wrong one (`i32`) or
16+
* the proper one (typically `c_uint`) depending on how the headers are
17+
* included, which in turn may depend on the particular kernel configuration
18+
* or the architecture.
19+
*
20+
* The alternative would be to use casts and likely an
21+
* `#[allow(clippy::unnecessary_cast)]` in the Rust source files. Instead,
22+
* this approach allows us to keep the correct code in the source files and
23+
* simply remove this section when the issue is fixed upstream and we bump
24+
* the minimum `bindgen` version.
25+
*
26+
* This workaround may not be possible in some cases, depending on how the C
27+
* headers are set up.
28+
*/
29+
#include <linux/hrtimer_types.h>
30+
931
#include <drm/drm_device.h>
1032
#include <drm/drm_drv.h>
1133
#include <drm/drm_file.h>
@@ -48,6 +70,7 @@
4870
#include <linux/tracepoint.h>
4971
#include <linux/wait.h>
5072
#include <linux/workqueue.h>
73+
#include <linux/xarray.h>
5174
#include <trace/events/rust_sample.h>
5275

5376
#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE)
@@ -67,3 +90,8 @@ const gfp_t RUST_CONST_HELPER___GFP_HIGHMEM = ___GFP_HIGHMEM;
6790
const gfp_t RUST_CONST_HELPER___GFP_NOWARN = ___GFP_NOWARN;
6891
const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ROTATIONAL = BLK_FEAT_ROTATIONAL;
6992
const fop_flags_t RUST_CONST_HELPER_FOP_UNSIGNED_OFFSET = FOP_UNSIGNED_OFFSET;
93+
94+
const xa_mark_t RUST_CONST_HELPER_XA_PRESENT = XA_PRESENT;
95+
96+
const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC = XA_FLAGS_ALLOC;
97+
const gfp_t RUST_CONST_HELPER_XA_FLAGS_ALLOC1 = XA_FLAGS_ALLOC1;

rust/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ macro_rules! alias {
1717

1818
// Check size compatibility with `core`.
1919
const _: () = assert!(
20-
core::mem::size_of::<$name>() == core::mem::size_of::<core::ffi::$name>()
20+
::core::mem::size_of::<$name>() == ::core::mem::size_of::<::core::ffi::$name>()
2121
);
2222
)*}
2323
}

0 commit comments

Comments
 (0)