From: Dirk Behme <dirk.behme@de.bosch.com>
To: Alistair Francis <alistair23@gmail.com>, <alex.gaynor@gmail.com>,
<benno.lossin@proton.me>, <gary@garyguo.net>,
<linux-kernel@vger.kernel.org>, <ojeda@kernel.org>,
<rust-for-linux@vger.kernel.org>, <bjorn3_gh@protonmail.com>,
<alistair.francis@wdc.com>, <me@kloenk.dev>,
<a.hindborg@kernel.org>, <tmgross@umich.edu>,
<boqun.feng@gmail.com>, <aliceryhl@google.com>
Subject: Re: [PATCH 00/13] rust: bindings: Auto-generate inline static functions
Date: Thu, 7 Nov 2024 08:01:21 +0100 [thread overview]
Message-ID: <3d898bd0-315d-4e3d-a500-5605e9047946@de.bosch.com> (raw)
In-Reply-To: <20241107020831.1561063-1-alistair.francis@wdc.com>
On 07.11.2024 03:08, Alistair Francis 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 (dependig 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.
Maybe this should be re-done against rust-next which at least contains
https://github.com/Rust-for-Linux/linux/commit/d4d7c05f9656fd8e14c6977a54986264eb296ec8
which seems to conflict with the removal of some helpers file in this
series.
Thanks!
Dirk
prev parent reply other threads:[~2024-11-07 7:01 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 2:08 Alistair Francis
2024-11-07 2:08 ` [PATCH 01/13] rust: bindings: Support some " Alistair Francis
2024-11-07 9:25 ` kernel test robot
2024-11-07 2:08 ` [PATCH 02/13] rust: helpers: Remove blk helper Alistair Francis
2024-11-07 2:08 ` [PATCH 03/13] rust: helpers: Remove build_bug helper Alistair Francis
2024-11-07 13:46 ` kernel test robot
2024-11-07 2:08 ` [PATCH 04/13] rust: helpers: Remove err helper Alistair Francis
2024-11-07 2:08 ` [PATCH 05/13] rust: helpers: Remove kunit helper Alistair Francis
2024-11-07 2:08 ` [PATCH 06/13] rust: helpers: Remove mutex helper Alistair Francis
2024-11-07 11:20 ` kernel test robot
2024-11-07 2:08 ` [PATCH 07/13] rust: helpers: Remove some page helpers Alistair Francis
2024-11-07 2:08 ` [PATCH 08/13] rust: helpers: Remove rbtree helper Alistair Francis
2024-11-07 2:08 ` [PATCH 09/13] rust: helpers: Remove some refcount helpers Alistair Francis
2024-11-07 2:08 ` [PATCH 10/13] rust: helpers: Remove signal helper Alistair Francis
2024-11-07 2:08 ` [PATCH 11/13] rust: helpers: Remove some spinlock helpers Alistair Francis
2024-11-07 2:08 ` [PATCH 12/13] rust: helpers: Remove some task helpers Alistair Francis
2024-11-07 2:08 ` [PATCH 13/13] rust: helpers: Remove uaccess helpers Alistair Francis
2024-11-07 7:01 ` Dirk Behme [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3d898bd0-315d-4e3d-a500-5605e9047946@de.bosch.com \
--to=dirk.behme@de.bosch.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=alistair.francis@wdc.com \
--cc=alistair23@gmail.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=me@kloenk.dev \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®