Skip to content

Commit 2190bba

Browse files
committed
Merge branch 'rust-device-v6.9-rc3' into rust-pci-v6.9-rc3
2 parents fec50db + 3f60bb1 commit 2190bba

28 files changed

+1585
-191
lines changed

arch/x86/tools/insn_decoder_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static void parse_args(int argc, char **argv)
106106
}
107107
}
108108

109-
#define BUFSIZE 256
109+
#define BUFSIZE 1024
110110

111111
int main(int argc, char **argv)
112112
{

rust/Makefile

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ rustdoc_output := $(objtree)/Documentation/output/rust/rustdoc
66
obj-$(CONFIG_RUST) += core.o compiler_builtins.o
77
always-$(CONFIG_RUST) += exports_core_generated.h
88

9-
# Missing prototypes are expected in the helpers since these are exported
10-
# for Rust only, thus there is no header nor prototypes.
11-
obj-$(CONFIG_RUST) += helpers.o
12-
CFLAGS_REMOVE_helpers.o = -Wmissing-prototypes -Wmissing-declarations
9+
RUST_HELPERS := \
10+
bug \
11+
build_assert \
12+
build_bug \
13+
device \
14+
err \
15+
kunit \
16+
mutex \
17+
rcu \
18+
refcount \
19+
signal \
20+
spinlock\
21+
task \
22+
wait \
23+
workqueue
24+
25+
export RUST_HELPERS
26+
obj-y += helpers/
1327

1428
always-$(CONFIG_RUST) += libmacros.so
1529
no-clean-files += libmacros.so
@@ -339,6 +353,10 @@ quiet_cmd_bindgen = BINDGEN $@
339353
-o $@ -- $(bindgen_c_flags_final) -DMODULE \
340354
$(bindgen_target_cflags) $(bindgen_target_extra)
341355

356+
quiet_cmd_cat = CAT $@
357+
cmd_cat = \
358+
cat $(patsubst %,$(srctree)/$(src)/helpers/%.c, $(RUST_HELPERS)) > $@
359+
342360
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
343361
$(shell grep -Ev '^#|^$$' $(srctree)/$(src)/bindgen_parameters)
344362
$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
@@ -353,9 +371,9 @@ $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
353371
$(src)/bindgen_parameters FORCE
354372
$(call if_changed_dep,bindgen)
355373

356-
# See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn
357-
# with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here
358-
# given it is `libclang`; but for consistency, future Clang changes and/or
374+
# See `ccflags-remove-y` in helpers/Makefile . In addition, Clang on C does not
375+
# warn with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed
376+
# here given it is `libclang`; but for consistency, future Clang changes and/or
359377
# a potential future GCC backend for `bindgen`, we disable it too.
360378
$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
361379
--blocklist-type '.*' --allowlist-var '' \
@@ -364,9 +382,13 @@ $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
364382
-I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
365383
$(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
366384
sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n pub fn \1/g' $@
367-
$(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
385+
$(obj)/bindings/bindings_helpers_generated.rs: $(obj)/helpers/helpers_combined.c FORCE
368386
$(call if_changed_dep,bindgen)
369387

388+
targets += helpers/helpers_combined.c
389+
$(obj)/helpers/helpers_combined.c: $(patsubst %,$(src)/helpers/%.c, $(RUST_HELPERS)) FORCE
390+
$(call if_changed,cat)
391+
370392
quiet_cmd_exports = EXPORTS $@
371393
cmd_exports = \
372394
$(NM) -p --defined-only $< \

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <kunit/test.h>
10+
#include <linux/device.h>
1011
#include <linux/errname.h>
1112
#include <linux/ethtool.h>
1213
#include <linux/jiffies.h>

rust/helpers.c

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

rust/helpers/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Note: `RUST_HELPERS` is defined in `../Makefile`
3+
4+
# Missing prototypes are expected in the helpers since these are exported
5+
# for Rust only, thus there is no header nor prototypes.
6+
obj-$(CONFIG_RUST) += $(patsubst %,%.o, $(RUST_HELPERS))
7+
ccflags-remove-y += -Wmissing-prototypes -Wmissing-declarations

rust/helpers/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Rust Helpers
2+
3+
Non-trivial C macros cannot be used in Rust. Similarly, inlined C functions
4+
cannot be called either. The files in this directory explicitly create functions
5+
("helpers") that wrap those so that they can be called from Rust.
6+
7+
Even though Rust kernel modules should never use directly the bindings, some
8+
of these helpers need to be exported because Rust generics and inlined
9+
functions may not get their code generated in the crate where they are
10+
defined. Other helpers, called from non-inline functions, may not be
11+
exported, in principle. However, in general, the Rust compiler does not
12+
guarantee codegen will be performed for a non-inline function either.
13+
Therefore, this file exports all the helpers. In the future, this may be
14+
revisited to reduce the number of exports after the compiler is informed
15+
about the places codegen is required.
16+
17+
All symbols are exported as GPL-only to guarantee no GPL-only feature is
18+
accidentally exposed.

rust/helpers/bug.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/bug.h>
4+
5+
__noreturn void rust_helper_BUG(void)
6+
{
7+
BUG();
8+
}
9+
EXPORT_SYMBOL_GPL(rust_helper_BUG);

rust/helpers/build_assert.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/build_bug.h>
4+
5+
/*
6+
* `bindgen` binds the C `size_t` type as the Rust `usize` type, so we can
7+
* use it in contexts where Rust expects a `usize` like slice (array) indices.
8+
* `usize` is defined to be the same as C's `uintptr_t` type (can hold any
9+
* pointer) but not necessarily the same as `size_t` (can hold the size of any
10+
* single object). Most modern platforms use the same concrete integer type for
11+
* both of them, but in case we find ourselves on a platform where
12+
* that's not true, fail early instead of risking ABI or
13+
* integer-overflow issues.
14+
*
15+
* If your platform fails this assertion, it means that you are in
16+
* danger of integer-overflow bugs (even if you attempt to add
17+
* `--no-size_t-is-usize`). It may be easiest to change the kernel ABI on
18+
* your platform such that `size_t` matches `uintptr_t` (i.e., to increase
19+
* `size_t`, because `uintptr_t` has to be at least as big as `size_t`).
20+
*/
21+
static_assert(
22+
sizeof(size_t) == sizeof(uintptr_t) &&
23+
__alignof__(size_t) == __alignof__(uintptr_t),
24+
"Rust code expects C `size_t` to match Rust `usize`"
25+
);

rust/helpers/build_bug.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/export.h>
4+
#include <linux/errname.h>
5+
6+
const char *rust_helper_errname(int err)
7+
{
8+
return errname(err);
9+
}
10+
EXPORT_SYMBOL_GPL(rust_helper_errname);

rust/helpers/device.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/device.h>
4+
5+
void *rust_helper_dev_get_drvdata(struct device *dev)
6+
{
7+
return dev_get_drvdata(dev);
8+
}
9+
EXPORT_SYMBOL_GPL(rust_helper_dev_get_drvdata);
10+
11+
const char *rust_helper_dev_name(const struct device *dev)
12+
{
13+
return dev_name(dev);
14+
}
15+
EXPORT_SYMBOL_GPL(rust_helper_dev_name);

0 commit comments

Comments
 (0)