* [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 01/11] rust: bindings: Support some " Alistair Francis
` (12 more replies)
0 siblings, 13 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis
The kernel includes a large number of static inline functions that are
defined in header files. One example is the crypto_shash_descsize()
function which is defined in hash.h as
```
static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm)
{
return tfm->descsize;
}
```
bindgen is currently unable to generate bindings to these functions as
they are not publically exposed (they are static after all).
The Rust code currently uses rust_helper_* functions, such as
rust_helper_alloc_pages() for example to call the static inline
functions. But this is a hassle as someone needs to write a C helper
function.
Instead we can use the bindgen wrap-static-fns feature. The feature
is marked as experimental, but has recently been promoted to
non-experimental (depending on your version of bindgen).
By supporting wrap-static-fns we automatically generate a C file called
extern.c that exposes the static inline functions, for example like this
```
unsigned int crypto_shash_descsize__extern(struct crypto_shash *tfm) { return crypto_shash_descsize(tfm); }
```
The nice part is that this is auto-generated.
We then also get a bindings_generate_static.rs file with the Rust
binding, like this
```
extern "C" {
#[link_name = "crypto_shash_descsize__extern"]
pub fn crypto_shash_descsize(tfm: *mut crypto_shash) -> core::ffi::c_uint;
}
```
So now we can use the static inline functions just like normal
functions.
There are a bunch of static inline functions that don't work though, because
the C compiler fails to build extern.c:
* functions with inline asm generate "operand probably does not match constraints"
errors (rip_rel_ptr() for example)
* functions with bit masks (u32_encode_bits() and friends) result in
"call to ‘__bad_mask’ declared with attribute error: bad bitfield mask"
errors
As well as that any static inline function that calls a function that has been
kconfig-ed out will fail to link as the function being called isn't built
(mdio45_ethtool_gset_npage for example)
Due to these failures we use a allow-list system (where functions must
be manually enabled).
This series adds support for bindgen generating wrappers for inline statics and
then converts the existing helper functions to this new method. This doesn't
work for C macros, so we can't reamove all of the helper functions, but we
can remove most.
v4:
- Fix out of tree builds
v3:
- Change SoB email address to match from address
- Fixup kunit test build failure
- Update Rust binding documentation
v2:
- Fixup build failures report by test bots
- Rebase on rust-next (ae7851c29747fa376)
Alistair Francis (11):
rust: bindings: Support some inline static functions
rust: helpers: Remove blk helper
rust: helpers: Remove err helper
rust: helpers: Remove kunit helper
rust: helpers: Remove some page helpers
rust: helpers: Remove rbtree helper
rust: helpers: Remove some refcount helpers
rust: helpers: Remove signal helper
rust: helpers: Remove some spinlock helpers
rust: helpers: Remove some task helpers
rust: helpers: Remove uaccess helpers
Documentation/rust/general-information.rst | 10 +++---
rust/.gitignore | 2 ++
rust/Makefile | 37 ++++++++++++++++++++--
rust/bindgen_static_functions | 32 +++++++++++++++++++
rust/bindings/bindings_helper.h | 6 ++++
rust/bindings/lib.rs | 4 +++
rust/exports.c | 1 +
rust/helpers/blk.c | 14 --------
rust/helpers/err.c | 18 -----------
rust/helpers/helpers.c | 11 ++-----
rust/helpers/kunit.c | 8 -----
rust/helpers/page.c | 5 ---
rust/helpers/rbtree.c | 9 ------
rust/helpers/refcount.c | 10 ------
rust/helpers/signal.c | 8 -----
rust/helpers/spinlock.c | 15 ---------
rust/helpers/task.c | 10 ------
rust/helpers/uaccess.c | 15 ---------
18 files changed, 87 insertions(+), 128 deletions(-)
create mode 100644 rust/bindgen_static_functions
delete mode 100644 rust/helpers/blk.c
delete mode 100644 rust/helpers/err.c
delete mode 100644 rust/helpers/kunit.c
delete mode 100644 rust/helpers/rbtree.c
delete mode 100644 rust/helpers/signal.c
delete mode 100644 rust/helpers/uaccess.c
--
2.47.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v4 01/11] rust: bindings: Support some inline static functions
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 02/11] rust: helpers: Remove blk helper Alistair Francis
` (11 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
The kernel includes a large number of static inline functions that are
defined in header files. One example is the crypto_shash_descsize()
function which is defined in hash.h as
static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm)
{
return tfm->descsize;
}
bindgen is currently unable to generate bindings to these functions as
they are not publically exposed (they are static after all).
The Rust code currently uses rust_helper_* functions, such as
rust_helper_alloc_pages() for example to call the static inline
functions. But this is a hassle as someone needs to write a C helper
function.
Instead we can use the bindgen wrap-static-fns feature. The feature
is marked as experimental, but has recently been promoted to
non-experimental (depending on your version of bindgen).
By supporting wrap-static-fns we automatically generate a C file called
extern.c that exposes the static inline functions, for example like this
```
unsigned int crypto_shash_descsize__extern(struct crypto_shash *tfm) { return crypto_shash_descsize(tfm); }
```
The nice part is that this is auto-generated.
We then also get a bindings_generate_static.rs file with the Rust
binding, like this
```
extern "C" {
#[link_name = "crypto_shash_descsize__extern"]
pub fn crypto_shash_descsize(tfm: *mut crypto_shash) -> core::ffi::c_uint;
}
```
So now we can use the static inline functions just like normal
functions.
There are a bunch of static inline functions that don't work though, because
the C compiler fails to build extern.c:
* functions with inline asm generate "operand probably does not match constraints"
errors (rip_rel_ptr() for example)
* functions with bit masks (u32_encode_bits() and friends) result in
"call to ‘__bad_mask’ declared with attribute error: bad bitfield mask"
errors
As well as that any static inline function that calls a function that has been
kconfig-ed out will fail to link as the function being called isn't built
(mdio45_ethtool_gset_npage for example)
Due to these failures we use a allow-list system (where functions must
be manually enabled).
Link: https://github.com/rust-lang/rust-bindgen/discussions/2405
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
Documentation/rust/general-information.rst | 10 +++---
rust/.gitignore | 2 ++
rust/Makefile | 37 ++++++++++++++++++++--
rust/bindgen_static_functions | 6 ++++
rust/bindings/lib.rs | 4 +++
rust/exports.c | 1 +
6 files changed, 53 insertions(+), 7 deletions(-)
create mode 100644 rust/bindgen_static_functions
diff --git a/Documentation/rust/general-information.rst b/Documentation/rust/general-information.rst
index 6146b49b6a98..632a60703c96 100644
--- a/Documentation/rust/general-information.rst
+++ b/Documentation/rust/general-information.rst
@@ -119,10 +119,12 @@ By including a C header from ``include/`` into
bindings for the included subsystem. After building, see the ``*_generated.rs``
output files in the ``rust/bindings/`` directory.
-For parts of the C header that ``bindgen`` does not auto generate, e.g. C
-``inline`` functions or non-trivial macros, it is acceptable to add a small
-wrapper function to ``rust/helpers/`` to make it available for the Rust side as
-well.
+C ``inline`` functions will only be generated if the function name is
+specified in ``rust/bindgen_static_functions``.
+
+For parts of the C header that ``bindgen`` does not auto generate, e.g.
+non-trivial macros, it is acceptable to add a small wrapper function
+to ``rust/helpers/`` to make it available for the Rust side as well.
Abstractions
~~~~~~~~~~~~
diff --git a/rust/.gitignore b/rust/.gitignore
index d3829ffab80b..741a18023801 100644
--- a/rust/.gitignore
+++ b/rust/.gitignore
@@ -1,10 +1,12 @@
# SPDX-License-Identifier: GPL-2.0
bindings_generated.rs
+bindings_generated_static.rs
bindings_helpers_generated.rs
doctests_kernel_generated.rs
doctests_kernel_generated_kunit.c
uapi_generated.rs
exports_*_generated.h
+extern.c
doc/
test/
diff --git a/rust/Makefile b/rust/Makefile
index 6daaa4dc21db..2d91160dcc69 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -10,14 +10,17 @@ always-$(CONFIG_RUST) += exports_core_generated.h
# for Rust only, thus there is no header nor prototypes.
obj-$(CONFIG_RUST) += helpers/helpers.o
CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations
+CFLAGS_REMOVE_extern.o = -Wmissing-prototypes -Wmissing-declarations -Wdiscarded-qualifiers
always-$(CONFIG_RUST) += libmacros.so
no-clean-files += libmacros.so
-always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
-obj-$(CONFIG_RUST) += bindings.o kernel.o
+always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs \
+ bindings/bindings_generated_static.rs
+obj-$(CONFIG_RUST) += bindings.o kernel.o extern.o
always-$(CONFIG_RUST) += exports_helpers_generated.h \
- exports_bindings_generated.h exports_kernel_generated.h
+ exports_bindings_generated.h exports_bindings_static_generated.h \
+ exports_kernel_generated.h
always-$(CONFIG_RUST) += uapi/uapi_generated.rs
obj-$(CONFIG_RUST) += uapi.o
@@ -274,6 +277,21 @@ quiet_cmd_bindgen = BINDGEN $@
-o $@ -- $(bindgen_c_flags_final) -DMODULE \
$(bindgen_target_cflags) $(bindgen_target_extra)
+quiet_cmd_bindgen_static = BINDGEN $@
+ cmd_bindgen_static = \
+ $(BINDGEN) $< $(bindgen_target_flags) \
+ --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
+ --no-debug '.*' --enable-function-attribute-detection \
+ --experimental --wrap-static-fns \
+ --wrap-static-fns-path $(src)/extern.c \
+ $(bindgen_static_functions) \
+ -o $@ -- $(bindgen_c_flags_final) -DMODULE \
+ $(bindgen_target_cflags) $(bindgen_target_extra)
+
+$(src)/extern.c: $(obj)/bindings/bindings_generated_static.rs \
+ $(src)/bindings/bindings_helper.h
+ @sed -i 's|#include ".*|#include "bindings/bindings_helper.h"|g' $@
+
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
$(obj)/bindings/bindings_generated.rs: private bindgen_target_extra = ; \
@@ -282,6 +300,15 @@ $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
$(src)/bindgen_parameters FORCE
$(call if_changed_dep,bindgen)
+$(obj)/bindings/bindings_generated_static.rs: private bindgen_target_flags = \
+ $(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
+$(obj)/bindings/bindings_generated_static.rs: private bindgen_static_functions = \
+ $(shell grep -Ev '^#|^$$' $(src)/bindgen_static_functions)
+$(obj)/bindings/bindings_generated_static.rs: $(src)/bindings/bindings_helper.h \
+ $(src)/bindgen_static_functions \
+ $(src)/bindgen_parameters FORCE
+ $(call if_changed_dep,bindgen_static)
+
$(obj)/uapi/uapi_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
$(obj)/uapi/uapi_generated.rs: $(src)/uapi/uapi_helper.h \
@@ -325,6 +352,9 @@ $(obj)/exports_helpers_generated.h: $(obj)/helpers/helpers.o FORCE
$(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
$(call if_changed,exports)
+$(obj)/exports_bindings_static_generated.h: $(obj)/extern.o FORCE
+ $(call if_changed,exports)
+
$(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
$(call if_changed,exports)
@@ -400,6 +430,7 @@ $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
$(obj)/bindings.o: $(src)/bindings/lib.rs \
$(obj)/compiler_builtins.o \
$(obj)/bindings/bindings_generated.rs \
+ $(obj)/bindings/bindings_generated_static.rs \
$(obj)/bindings/bindings_helpers_generated.rs FORCE
+$(call if_changed_rule,rustc_library)
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
new file mode 100644
index 000000000000..1f24360daeb3
--- /dev/null
+++ b/rust/bindgen_static_functions
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+
+# Don't generate structs
+--blocklist-type '.*'
+
+--allowlist-function blk_mq_rq_to_pdu
diff --git a/rust/bindings/lib.rs b/rust/bindings/lib.rs
index d6da3011281a..c991bcf607ec 100644
--- a/rust/bindings/lib.rs
+++ b/rust/bindings/lib.rs
@@ -34,6 +34,10 @@ mod bindings_raw {
env!("OBJTREE"),
"/rust/bindings/bindings_generated.rs"
));
+ include!(concat!(
+ env!("OBJTREE"),
+ "/rust/bindings/bindings_generated_static.rs"
+ ));
}
// When both a directly exposed symbol and a helper exists for the same function,
diff --git a/rust/exports.c b/rust/exports.c
index 587f0e776aba..288958d2ebea 100644
--- a/rust/exports.c
+++ b/rust/exports.c
@@ -18,6 +18,7 @@
#include "exports_core_generated.h"
#include "exports_helpers_generated.h"
#include "exports_bindings_generated.h"
+#include "exports_bindings_static_generated.h"
#include "exports_kernel_generated.h"
// For modules using `rust/build_error.rs`.
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 02/11] rust: helpers: Remove blk helper
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
2024-11-14 0:56 ` [PATCH v4 01/11] rust: bindings: Support some " Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 03/11] rust: helpers: Remove err helper Alistair Francis
` (10 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helper.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 1 +
rust/helpers/blk.c | 14 --------------
rust/helpers/helpers.c | 1 -
3 files changed, 1 insertion(+), 15 deletions(-)
delete mode 100644 rust/helpers/blk.c
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 1f24360daeb3..42e45ce34221 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -4,3 +4,4 @@
--blocklist-type '.*'
--allowlist-function blk_mq_rq_to_pdu
+--allowlist-function blk_mq_rq_from_pdu
diff --git a/rust/helpers/blk.c b/rust/helpers/blk.c
deleted file mode 100644
index cc9f4e6a2d23..000000000000
--- a/rust/helpers/blk.c
+++ /dev/null
@@ -1,14 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/blk-mq.h>
-#include <linux/blkdev.h>
-
-void *rust_helper_blk_mq_rq_to_pdu(struct request *rq)
-{
- return blk_mq_rq_to_pdu(rq);
-}
-
-struct request *rust_helper_blk_mq_rq_from_pdu(void *pdu)
-{
- return blk_mq_rq_from_pdu(pdu);
-}
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 20a0c69d5cc7..426b0d7f6587 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -7,7 +7,6 @@
* Sorted alphabetically.
*/
-#include "blk.c"
#include "bug.c"
#include "build_assert.c"
#include "build_bug.c"
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 03/11] rust: helpers: Remove err helper
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
2024-11-14 0:56 ` [PATCH v4 01/11] rust: bindings: Support some " Alistair Francis
2024-11-14 0:56 ` [PATCH v4 02/11] rust: helpers: Remove blk helper Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 04/11] rust: helpers: Remove kunit helper Alistair Francis
` (9 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helper.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 4 ++++
rust/helpers/err.c | 18 ------------------
rust/helpers/helpers.c | 1 -
3 files changed, 4 insertions(+), 19 deletions(-)
delete mode 100644 rust/helpers/err.c
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 42e45ce34221..0269efa83c61 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -5,3 +5,7 @@
--allowlist-function blk_mq_rq_to_pdu
--allowlist-function blk_mq_rq_from_pdu
+
+--allowlist-function ERR_PTR
+--allowlist-function IS_ERR
+--allowlist-function PTR_ERR
diff --git a/rust/helpers/err.c b/rust/helpers/err.c
deleted file mode 100644
index 544c7cb86632..000000000000
--- a/rust/helpers/err.c
+++ /dev/null
@@ -1,18 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/err.h>
-
-__force void *rust_helper_ERR_PTR(long err)
-{
- return ERR_PTR(err);
-}
-
-bool rust_helper_IS_ERR(__force const void *ptr)
-{
- return IS_ERR(ptr);
-}
-
-long rust_helper_PTR_ERR(__force const void *ptr)
-{
- return PTR_ERR(ptr);
-}
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 426b0d7f6587..e089ecdf091f 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -10,7 +10,6 @@
#include "bug.c"
#include "build_assert.c"
#include "build_bug.c"
-#include "err.c"
#include "kunit.c"
#include "mutex.c"
#include "page.c"
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 04/11] rust: helpers: Remove kunit helper
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (2 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 03/11] rust: helpers: Remove err helper Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 05/11] rust: helpers: Remove some page helpers Alistair Francis
` (8 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helper.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 2 ++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 -
rust/helpers/kunit.c | 8 --------
4 files changed, 3 insertions(+), 9 deletions(-)
delete mode 100644 rust/helpers/kunit.c
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 0269efa83c61..b4032d277e72 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -9,3 +9,5 @@
--allowlist-function ERR_PTR
--allowlist-function IS_ERR
--allowlist-function PTR_ERR
+
+--allowlist-function kunit_get_current_test
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index a80783fcbe04..00b1c1c3ab76 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -14,6 +14,7 @@
#include <linux/ethtool.h>
#include <linux/firmware.h>
#include <linux/jiffies.h>
+#include <kunit/test-bug.h>
#include <linux/mdio.h>
#include <linux/phy.h>
#include <linux/refcount.h>
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index e089ecdf091f..60b3fdc5c2de 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -10,7 +10,6 @@
#include "bug.c"
#include "build_assert.c"
#include "build_bug.c"
-#include "kunit.c"
#include "mutex.c"
#include "page.c"
#include "rbtree.c"
diff --git a/rust/helpers/kunit.c b/rust/helpers/kunit.c
deleted file mode 100644
index b85a4d394c11..000000000000
--- a/rust/helpers/kunit.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <kunit/test-bug.h>
-
-struct kunit *rust_helper_kunit_get_current_test(void)
-{
- return kunit_get_current_test();
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 05/11] rust: helpers: Remove some page helpers
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (3 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 04/11] rust: helpers: Remove kunit helper Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 06/11] rust: helpers: Remove rbtree helper Alistair Francis
` (7 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helpers.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 2 ++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/page.c | 5 -----
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index b4032d277e72..ded5b816f304 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -11,3 +11,5 @@
--allowlist-function PTR_ERR
--allowlist-function kunit_get_current_test
+
+--allowlist-function kmap_local_page
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 00b1c1c3ab76..452f8afc9b09 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -13,6 +13,7 @@
#include <linux/errname.h>
#include <linux/ethtool.h>
#include <linux/firmware.h>
+#include <linux/highmem.h>
#include <linux/jiffies.h>
#include <kunit/test-bug.h>
#include <linux/mdio.h>
diff --git a/rust/helpers/page.c b/rust/helpers/page.c
index b3f2b8fbf87f..52ebec9d7186 100644
--- a/rust/helpers/page.c
+++ b/rust/helpers/page.c
@@ -8,11 +8,6 @@ struct page *rust_helper_alloc_pages(gfp_t gfp_mask, unsigned int order)
return alloc_pages(gfp_mask, order);
}
-void *rust_helper_kmap_local_page(struct page *page)
-{
- return kmap_local_page(page);
-}
-
void rust_helper_kunmap_local(const void *addr)
{
kunmap_local(addr);
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 06/11] rust: helpers: Remove rbtree helper
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (4 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 05/11] rust: helpers: Remove some page helpers Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 07/11] rust: helpers: Remove some refcount helpers Alistair Francis
` (6 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helper.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 2 ++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 -
rust/helpers/rbtree.c | 9 ---------
4 files changed, 3 insertions(+), 10 deletions(-)
delete mode 100644 rust/helpers/rbtree.c
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index ded5b816f304..e464dc1f5682 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -13,3 +13,5 @@
--allowlist-function kunit_get_current_test
--allowlist-function kmap_local_page
+
+--allowlist-function rb_link_node
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 452f8afc9b09..d7591b709407 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -18,6 +18,7 @@
#include <kunit/test-bug.h>
#include <linux/mdio.h>
#include <linux/phy.h>
+#include <linux/rbtree.h>
#include <linux/refcount.h>
#include <linux/sched.h>
#include <linux/slab.h>
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 60b3fdc5c2de..39adea78a647 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -12,7 +12,6 @@
#include "build_bug.c"
#include "mutex.c"
#include "page.c"
-#include "rbtree.c"
#include "refcount.c"
#include "signal.c"
#include "slab.c"
diff --git a/rust/helpers/rbtree.c b/rust/helpers/rbtree.c
deleted file mode 100644
index 6d404b84a9b5..000000000000
--- a/rust/helpers/rbtree.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/rbtree.h>
-
-void rust_helper_rb_link_node(struct rb_node *node, struct rb_node *parent,
- struct rb_node **rb_link)
-{
- rb_link_node(node, parent, rb_link);
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 07/11] rust: helpers: Remove some refcount helpers
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (5 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 06/11] rust: helpers: Remove rbtree helper Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 08/11] rust: helpers: Remove signal helper Alistair Francis
` (5 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helpers.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 3 +++
rust/helpers/refcount.c | 10 ----------
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index e464dc1f5682..9c40a867a64d 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -15,3 +15,6 @@
--allowlist-function kmap_local_page
--allowlist-function rb_link_node
+
+--allowlist-function refcount_inc
+--allowlist-function refcount_dec_and_test
diff --git a/rust/helpers/refcount.c b/rust/helpers/refcount.c
index d6adbd2e45a1..ed13236246d8 100644
--- a/rust/helpers/refcount.c
+++ b/rust/helpers/refcount.c
@@ -6,13 +6,3 @@ refcount_t rust_helper_REFCOUNT_INIT(int n)
{
return (refcount_t)REFCOUNT_INIT(n);
}
-
-void rust_helper_refcount_inc(refcount_t *r)
-{
- refcount_inc(r);
-}
-
-bool rust_helper_refcount_dec_and_test(refcount_t *r)
-{
- return refcount_dec_and_test(r);
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 08/11] rust: helpers: Remove signal helper
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (6 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 07/11] rust: helpers: Remove some refcount helpers Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 09/11] rust: helpers: Remove some spinlock helpers Alistair Francis
` (4 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helper.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 2 ++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 1 -
rust/helpers/signal.c | 8 --------
4 files changed, 3 insertions(+), 9 deletions(-)
delete mode 100644 rust/helpers/signal.c
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 9c40a867a64d..407dd091ddec 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -18,3 +18,5 @@
--allowlist-function refcount_inc
--allowlist-function refcount_dec_and_test
+
+--allowlist-function signal_pending
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index d7591b709407..e21a5f260e3c 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -21,6 +21,7 @@
#include <linux/rbtree.h>
#include <linux/refcount.h>
#include <linux/sched.h>
+#include <linux/sched/signal.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 39adea78a647..ebe3a85c7210 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -13,7 +13,6 @@
#include "mutex.c"
#include "page.c"
#include "refcount.c"
-#include "signal.c"
#include "slab.c"
#include "spinlock.c"
#include "task.c"
diff --git a/rust/helpers/signal.c b/rust/helpers/signal.c
deleted file mode 100644
index 1a6bbe9438e2..000000000000
--- a/rust/helpers/signal.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/sched/signal.h>
-
-int rust_helper_signal_pending(struct task_struct *t)
-{
- return signal_pending(t);
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 09/11] rust: helpers: Remove some spinlock helpers
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (7 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 08/11] rust: helpers: Remove signal helper Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 10/11] rust: helpers: Remove some task helpers Alistair Francis
` (3 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helpers.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 4 ++++
rust/helpers/spinlock.c | 15 ---------------
2 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 407dd091ddec..9d6c44e277b5 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -20,3 +20,7 @@
--allowlist-function refcount_dec_and_test
--allowlist-function signal_pending
+
+--allowlist-function spin_lock
+--allowlist-function spin_unlock
+--allowlist-function spin_trylock
diff --git a/rust/helpers/spinlock.c b/rust/helpers/spinlock.c
index b7b0945e8b3c..1c47608c42ed 100644
--- a/rust/helpers/spinlock.c
+++ b/rust/helpers/spinlock.c
@@ -11,18 +11,3 @@ void rust_helper___spin_lock_init(spinlock_t *lock, const char *name,
spin_lock_init(lock);
#endif
}
-
-void rust_helper_spin_lock(spinlock_t *lock)
-{
- spin_lock(lock);
-}
-
-void rust_helper_spin_unlock(spinlock_t *lock)
-{
- spin_unlock(lock);
-}
-
-int rust_helper_spin_trylock(spinlock_t *lock)
-{
- return spin_trylock(lock);
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 10/11] rust: helpers: Remove some task helpers
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (8 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 09/11] rust: helpers: Remove some spinlock helpers Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-11-14 0:56 ` [PATCH v4 11/11] rust: helpers: Remove uaccess helpers Alistair Francis
` (2 subsequent siblings)
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helpers.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 3 +++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/task.c | 10 ----------
3 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 9d6c44e277b5..8bc291a7a799 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -24,3 +24,6 @@
--allowlist-function spin_lock
--allowlist-function spin_unlock
--allowlist-function spin_trylock
+
+--allowlist-function get_task_struct
+--allowlist-function put_task_struct
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index e21a5f260e3c..63b78a833303 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -22,6 +22,7 @@
#include <linux/refcount.h>
#include <linux/sched.h>
#include <linux/sched/signal.h>
+#include <linux/sched/task.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
diff --git a/rust/helpers/task.c b/rust/helpers/task.c
index 190fdb2c8e2f..788865464134 100644
--- a/rust/helpers/task.c
+++ b/rust/helpers/task.c
@@ -6,13 +6,3 @@ struct task_struct *rust_helper_get_current(void)
{
return current;
}
-
-void rust_helper_get_task_struct(struct task_struct *t)
-{
- get_task_struct(t);
-}
-
-void rust_helper_put_task_struct(struct task_struct *t)
-{
- put_task_struct(t);
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v4 11/11] rust: helpers: Remove uaccess helpers
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (9 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 10/11] rust: helpers: Remove some task helpers Alistair Francis
@ 2024-11-14 0:56 ` Alistair Francis
2024-12-02 7:14 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
2024-12-04 13:13 ` Andreas Hindborg
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-11-14 0:56 UTC (permalink / raw)
To: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
Cc: alistair23, Alistair Francis, Dirk Behme
Now that we support wrap-static-fns we no longer need the custom helper.
Signed-off-by: Alistair Francis <alistair@alistair23.me>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
---
rust/bindgen_static_functions | 3 +++
rust/bindings/bindings_helper.h | 1 +
rust/helpers/helpers.c | 6 ++----
rust/helpers/uaccess.c | 15 ---------------
4 files changed, 6 insertions(+), 19 deletions(-)
delete mode 100644 rust/helpers/uaccess.c
diff --git a/rust/bindgen_static_functions b/rust/bindgen_static_functions
index 8bc291a7a799..ec48ad2e8c78 100644
--- a/rust/bindgen_static_functions
+++ b/rust/bindgen_static_functions
@@ -27,3 +27,6 @@
--allowlist-function get_task_struct
--allowlist-function put_task_struct
+
+--allowlist-function copy_from_user
+--allowlist-function copy_to_user
diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index 63b78a833303..7847b2b3090b 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -24,6 +24,7 @@
#include <linux/sched/signal.h>
#include <linux/sched/task.h>
#include <linux/slab.h>
+#include <linux/uaccess.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index ebe3a85c7210..42c28222f6c2 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Non-trivial C macros cannot be used in Rust. Similarly, inlined C functions
- * cannot be called either. This file explicitly creates functions ("helpers")
- * that wrap those so that they can be called from Rust.
+ * Non-trivial C macros cannot be used in Rust. This file explicitly creates
+ * functions ("helpers") that wrap those so that they can be called from Rust.
*
* Sorted alphabetically.
*/
@@ -16,7 +15,6 @@
#include "slab.c"
#include "spinlock.c"
#include "task.c"
-#include "uaccess.c"
#include "vmalloc.c"
#include "wait.c"
#include "workqueue.c"
diff --git a/rust/helpers/uaccess.c b/rust/helpers/uaccess.c
deleted file mode 100644
index f49076f813cd..000000000000
--- a/rust/helpers/uaccess.c
+++ /dev/null
@@ -1,15 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/uaccess.h>
-
-unsigned long rust_helper_copy_from_user(void *to, const void __user *from,
- unsigned long n)
-{
- return copy_from_user(to, from, n);
-}
-
-unsigned long rust_helper_copy_to_user(void __user *to, const void *from,
- unsigned long n)
-{
- return copy_to_user(to, from, n);
-}
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (10 preceding siblings ...)
2024-11-14 0:56 ` [PATCH v4 11/11] rust: helpers: Remove uaccess helpers Alistair Francis
@ 2024-12-02 7:14 ` Alistair Francis
2024-12-04 13:13 ` Andreas Hindborg
12 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2024-12-02 7:14 UTC (permalink / raw)
To: Alistair Francis, Miguel Ojeda
Cc: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor,
a.hindborg, gary, aliceryhl, alistair.francis, bjorn3_gh, tmgross,
rust-for-linux, ojeda
On Thu, Nov 14, 2024 at 9:56 AM Alistair Francis <alistair@alistair23.me> wrote:
>
> The kernel includes a large number of static inline functions that are
> defined in header files. One example is the crypto_shash_descsize()
> function which is defined in hash.h as
>
> ```
> static inline unsigned int crypto_shash_descsize(struct crypto_shash *tfm)
> {
> return tfm->descsize;
> }
> ```
>
> bindgen is currently unable to generate bindings to these functions as
> they are not publically exposed (they are static after all).
>
> The Rust code currently uses rust_helper_* functions, such as
> rust_helper_alloc_pages() for example to call the static inline
> functions. But this is a hassle as someone needs to write a C helper
> function.
>
> Instead we can use the bindgen wrap-static-fns feature. The feature
> is marked as experimental, but has recently been promoted to
> non-experimental (depending on your version of bindgen).
>
> By supporting wrap-static-fns we automatically generate a C file called
> extern.c that exposes the static inline functions, for example like this
>
> ```
> unsigned int crypto_shash_descsize__extern(struct crypto_shash *tfm) { return crypto_shash_descsize(tfm); }
> ```
>
> The nice part is that this is auto-generated.
>
> We then also get a bindings_generate_static.rs file with the Rust
> binding, like this
>
> ```
> extern "C" {
> #[link_name = "crypto_shash_descsize__extern"]
> pub fn crypto_shash_descsize(tfm: *mut crypto_shash) -> core::ffi::c_uint;
> }
> ```
>
> So now we can use the static inline functions just like normal
> functions.
>
> There are a bunch of static inline functions that don't work though, because
> the C compiler fails to build extern.c:
> * functions with inline asm generate "operand probably does not match constraints"
> errors (rip_rel_ptr() for example)
> * functions with bit masks (u32_encode_bits() and friends) result in
> "call to ‘__bad_mask’ declared with attribute error: bad bitfield mask"
> errors
>
> As well as that any static inline function that calls a function that has been
> kconfig-ed out will fail to link as the function being called isn't built
> (mdio45_ethtool_gset_npage for example)
>
> Due to these failures we use a allow-list system (where functions must
> be manually enabled).
>
> This series adds support for bindgen generating wrappers for inline statics and
> then converts the existing helper functions to this new method. This doesn't
> work for C macros, so we can't reamove all of the helper functions, but we
> can remove most.
Any more comments?
Alistair
>
> v4:
> - Fix out of tree builds
> v3:
> - Change SoB email address to match from address
> - Fixup kunit test build failure
> - Update Rust binding documentation
> v2:
> - Fixup build failures report by test bots
> - Rebase on rust-next (ae7851c29747fa376)
>
> Alistair Francis (11):
> rust: bindings: Support some inline static functions
> rust: helpers: Remove blk helper
> rust: helpers: Remove err helper
> rust: helpers: Remove kunit helper
> rust: helpers: Remove some page helpers
> rust: helpers: Remove rbtree helper
> rust: helpers: Remove some refcount helpers
> rust: helpers: Remove signal helper
> rust: helpers: Remove some spinlock helpers
> rust: helpers: Remove some task helpers
> rust: helpers: Remove uaccess helpers
>
> Documentation/rust/general-information.rst | 10 +++---
> rust/.gitignore | 2 ++
> rust/Makefile | 37 ++++++++++++++++++++--
> rust/bindgen_static_functions | 32 +++++++++++++++++++
> rust/bindings/bindings_helper.h | 6 ++++
> rust/bindings/lib.rs | 4 +++
> rust/exports.c | 1 +
> rust/helpers/blk.c | 14 --------
> rust/helpers/err.c | 18 -----------
> rust/helpers/helpers.c | 11 ++-----
> rust/helpers/kunit.c | 8 -----
> rust/helpers/page.c | 5 ---
> rust/helpers/rbtree.c | 9 ------
> rust/helpers/refcount.c | 10 ------
> rust/helpers/signal.c | 8 -----
> rust/helpers/spinlock.c | 15 ---------
> rust/helpers/task.c | 10 ------
> rust/helpers/uaccess.c | 15 ---------
> 18 files changed, 87 insertions(+), 128 deletions(-)
> create mode 100644 rust/bindgen_static_functions
> delete mode 100644 rust/helpers/blk.c
> delete mode 100644 rust/helpers/err.c
> delete mode 100644 rust/helpers/kunit.c
> delete mode 100644 rust/helpers/rbtree.c
> delete mode 100644 rust/helpers/signal.c
> delete mode 100644 rust/helpers/uaccess.c
>
> --
> 2.47.0
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
` (11 preceding siblings ...)
2024-12-02 7:14 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
@ 2024-12-04 13:13 ` Andreas Hindborg
2024-12-18 6:32 ` Alistair Francis
12 siblings, 1 reply; 18+ messages in thread
From: Andreas Hindborg @ 2024-12-04 13:13 UTC (permalink / raw)
To: Alistair Francis
Cc: linux-kernel, benno.lossin, boqun.feng, me, alex.gaynor, gary,
aliceryhl, alistair.francis, bjorn3_gh, tmgross, rust-for-linux,
ojeda, alistair23
Hi Alistair,
"Alistair Francis" <alistair@alistair23.me> writes:
>
> This series adds support for bindgen generating wrappers for inline statics and
> then converts the existing helper functions to this new method. This doesn't
> work for C macros, so we can't reamove all of the helper functions, but we
> can remove most.
Are you aware of the helper LTO patches by Gary [1]? Can you tell if
this series will compose with the LTO patches?
Also see this Zulip thread for discussion on the LTO patches [2].
Best regards,
Andreas Hindborg
[1] https://github.com/nbdd0121/linux/tree/thin-lto
[2] https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/LTO.20Rust.20modules.20with.20C.20helpers
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
2024-12-04 13:13 ` Andreas Hindborg
@ 2024-12-18 6:32 ` Alistair Francis
2024-12-18 9:45 ` Andreas Hindborg
0 siblings, 1 reply; 18+ messages in thread
From: Alistair Francis @ 2024-12-18 6:32 UTC (permalink / raw)
To: Andreas Hindborg
Cc: Alistair Francis, linux-kernel, benno.lossin, boqun.feng, me,
alex.gaynor, gary, aliceryhl, alistair.francis, bjorn3_gh,
tmgross, rust-for-linux, ojeda
On Wed, Dec 4, 2024 at 11:14 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
>
> Hi Alistair,
>
> "Alistair Francis" <alistair@alistair23.me> writes:
> >
> > This series adds support for bindgen generating wrappers for inline statics and
> > then converts the existing helper functions to this new method. This doesn't
> > work for C macros, so we can't reamove all of the helper functions, but we
> > can remove most.
>
> Are you aware of the helper LTO patches by Gary [1]? Can you tell if
I was not, but that's exciting to see
> this series will compose with the LTO patches?
I think it will still work, although it might take some extra effort.
I assume my series isn't going to be accepted though, so I'm not going
to try and get the LTO series to work on top of it. It's a lot of work
to rebase this series as every new binding causes a conflict and it
seems to have stalled
Alistair
>
> Also see this Zulip thread for discussion on the LTO patches [2].
>
>
> Best regards,
> Andreas Hindborg
>
>
>
> [1] https://github.com/nbdd0121/linux/tree/thin-lto
> [2] https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/LTO.20Rust.20modules.20with.20C.20helpers
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
2024-12-18 6:32 ` Alistair Francis
@ 2024-12-18 9:45 ` Andreas Hindborg
2024-12-20 2:55 ` Alistair Francis
0 siblings, 1 reply; 18+ messages in thread
From: Andreas Hindborg @ 2024-12-18 9:45 UTC (permalink / raw)
To: Alistair Francis
Cc: Alistair Francis, linux-kernel, benno.lossin, boqun.feng, me,
alex.gaynor, gary, aliceryhl, alistair.francis, bjorn3_gh,
tmgross, rust-for-linux, ojeda
"Alistair Francis" <alistair23@gmail.com> writes:
> On Wed, Dec 4, 2024 at 11:14 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>>
>>
>> Hi Alistair,
>>
>> "Alistair Francis" <alistair@alistair23.me> writes:
>> >
>> > This series adds support for bindgen generating wrappers for inline statics and
>> > then converts the existing helper functions to this new method. This doesn't
>> > work for C macros, so we can't reamove all of the helper functions, but we
>> > can remove most.
>>
>> Are you aware of the helper LTO patches by Gary [1]? Can you tell if
>
> I was not, but that's exciting to see
>
>> this series will compose with the LTO patches?
>
> I think it will still work, although it might take some extra effort.
>
> I assume my series isn't going to be accepted though, so I'm not going
> to try and get the LTO series to work on top of it. It's a lot of work
> to rebase this series as every new binding causes a conflict and it
> seems to have stalled
I would assume that it _will_ be merged in some form. Why not? It's just
a matter of getting it reviewed and making sure that it is going to work
with the LTO inlining.
The less boiler plate code we have to write by hand, the better!
Best regards,
Andreas Hindborg
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
2024-12-18 9:45 ` Andreas Hindborg
@ 2024-12-20 2:55 ` Alistair Francis
2025-01-03 11:21 ` Alistair Francis
0 siblings, 1 reply; 18+ messages in thread
From: Alistair Francis @ 2024-12-20 2:55 UTC (permalink / raw)
To: Andreas Hindborg
Cc: Alistair Francis, linux-kernel, benno.lossin, boqun.feng, me,
alex.gaynor, gary, aliceryhl, alistair.francis, bjorn3_gh,
tmgross, rust-for-linux, ojeda
On Wed, Dec 18, 2024 at 7:45 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
> "Alistair Francis" <alistair23@gmail.com> writes:
>
> > On Wed, Dec 4, 2024 at 11:14 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
> >>
> >>
> >> Hi Alistair,
> >>
> >> "Alistair Francis" <alistair@alistair23.me> writes:
> >> >
> >> > This series adds support for bindgen generating wrappers for inline statics and
> >> > then converts the existing helper functions to this new method. This doesn't
> >> > work for C macros, so we can't reamove all of the helper functions, but we
> >> > can remove most.
> >>
> >> Are you aware of the helper LTO patches by Gary [1]? Can you tell if
> >
> > I was not, but that's exciting to see
> >
> >> this series will compose with the LTO patches?
> >
> > I think it will still work, although it might take some extra effort.
> >
> > I assume my series isn't going to be accepted though, so I'm not going
> > to try and get the LTO series to work on top of it. It's a lot of work
> > to rebase this series as every new binding causes a conflict and it
> > seems to have stalled
>
> I would assume that it _will_ be merged in some form. Why not? It's just
> a matter of getting it reviewed and making sure that it is going to work
> with the LTO inlining.
Ah, I just haven't heard a lot of feedback, which seems like there
isn't interest in this.
I tried to apply the LTO patches, but I do see build failures, I get
errors like this:
ld.lld: error: duplicate symbol: RUST_CONST_HELPER_ARCH_SLAB_MINALIGN
>>> defined at llvm-link
>>> rust/kernel.o:(RUST_CONST_HELPER_ARCH_SLAB_MINALIGN) in archive vmlinux.a
>>> defined at llvm-link
>>> drivers/b
It seems like all of the const's in rust/bindings/bindings_helper.h
are failing to link, but I'm not sure why
Alistair
>
> The less boiler plate code we have to write by hand, the better!
>
>
> Best regards,
> Andreas Hindborg
>
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions
2024-12-20 2:55 ` Alistair Francis
@ 2025-01-03 11:21 ` Alistair Francis
0 siblings, 0 replies; 18+ messages in thread
From: Alistair Francis @ 2025-01-03 11:21 UTC (permalink / raw)
To: Andreas Hindborg
Cc: Alistair Francis, linux-kernel, benno.lossin, boqun.feng, me,
alex.gaynor, gary, aliceryhl, alistair.francis, bjorn3_gh,
tmgross, rust-for-linux, ojeda
On Fri, Dec 20, 2024 at 12:55 PM Alistair Francis <alistair23@gmail.com> wrote:
>
> On Wed, Dec 18, 2024 at 7:45 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
> >
> > "Alistair Francis" <alistair23@gmail.com> writes:
> >
> > > On Wed, Dec 4, 2024 at 11:14 PM Andreas Hindborg <a.hindborg@kernel.org> wrote:
> > >>
> > >>
> > >> Hi Alistair,
> > >>
> > >> "Alistair Francis" <alistair@alistair23.me> writes:
> > >> >
> > >> > This series adds support for bindgen generating wrappers for inline statics and
> > >> > then converts the existing helper functions to this new method. This doesn't
> > >> > work for C macros, so we can't reamove all of the helper functions, but we
> > >> > can remove most.
> > >>
> > >> Are you aware of the helper LTO patches by Gary [1]? Can you tell if
> > >
> > > I was not, but that's exciting to see
> > >
> > >> this series will compose with the LTO patches?
> > >
> > > I think it will still work, although it might take some extra effort.
> > >
> > > I assume my series isn't going to be accepted though, so I'm not going
> > > to try and get the LTO series to work on top of it. It's a lot of work
> > > to rebase this series as every new binding causes a conflict and it
> > > seems to have stalled
> >
> > I would assume that it _will_ be merged in some form. Why not? It's just
> > a matter of getting it reviewed and making sure that it is going to work
> > with the LTO inlining.
I have my patches building with the LTO inlining work. The kernel
still boots and it seems like the inlining is working
You can see it here if you are interested in testing:
https://github.com/alistair23/linux/commit/e6b847324b4f5e904e007c0e288c88d2483928a8
Alistair
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2025-01-03 11:22 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <yZdXTg82eCLGHsaNBfAwwYZTGa63yzxI2YXoaTndUyJzyVN60hPrWoeQoXdrrh2hnRIeugFXvrb3nbq2bpD6Ag==@protonmail.internalid>
2024-11-14 0:56 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
2024-11-14 0:56 ` [PATCH v4 01/11] rust: bindings: Support some " Alistair Francis
2024-11-14 0:56 ` [PATCH v4 02/11] rust: helpers: Remove blk helper Alistair Francis
2024-11-14 0:56 ` [PATCH v4 03/11] rust: helpers: Remove err helper Alistair Francis
2024-11-14 0:56 ` [PATCH v4 04/11] rust: helpers: Remove kunit helper Alistair Francis
2024-11-14 0:56 ` [PATCH v4 05/11] rust: helpers: Remove some page helpers Alistair Francis
2024-11-14 0:56 ` [PATCH v4 06/11] rust: helpers: Remove rbtree helper Alistair Francis
2024-11-14 0:56 ` [PATCH v4 07/11] rust: helpers: Remove some refcount helpers Alistair Francis
2024-11-14 0:56 ` [PATCH v4 08/11] rust: helpers: Remove signal helper Alistair Francis
2024-11-14 0:56 ` [PATCH v4 09/11] rust: helpers: Remove some spinlock helpers Alistair Francis
2024-11-14 0:56 ` [PATCH v4 10/11] rust: helpers: Remove some task helpers Alistair Francis
2024-11-14 0:56 ` [PATCH v4 11/11] rust: helpers: Remove uaccess helpers Alistair Francis
2024-12-02 7:14 ` [PATCH v4 00/11] rust: bindings: Auto-generate inline static functions Alistair Francis
2024-12-04 13:13 ` Andreas Hindborg
2024-12-18 6:32 ` Alistair Francis
2024-12-18 9:45 ` Andreas Hindborg
2024-12-20 2:55 ` Alistair Francis
2025-01-03 11:21 ` Alistair Francis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).