[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAKmqyKO+O6H8+Y2ybz+qiAtgGbLeHMzswo9weWbg0Wc--gEiMA@mail.gmail.com>
Date: Tue, 14 Jan 2025 16:02:16 +1000
From: Alistair Francis <alistair23@...il.com>
To: Andreas Hindborg <a.hindborg@...nel.org>
Cc: Alistair Francis <alistair@...stair23.me>, bhelgaas@...gle.com,
rust-for-linux@...r.kernel.org, lukas@...ner.de, gary@...yguo.net,
akpm@...ux-foundation.org, tmgross@...ch.edu, boqun.feng@...il.com,
ojeda@...nel.org, linux-cxl@...r.kernel.org, bjorn3_gh@...tonmail.com,
me@...enk.dev, linux-kernel@...r.kernel.org, aliceryhl@...gle.com,
alistair.francis@....com, linux-pci@...r.kernel.org, benno.lossin@...ton.me,
alex.gaynor@...il.com, Jonathan.Cameron@...wei.com, wilfred.mallawa@....com
Subject: Re: [PATCH v5 00/11] rust: bindings: Auto-generate inline static functions
On Tue, Jan 7, 2025 at 9:48 PM Andreas Hindborg <a.hindborg@...nel.org> wrote:
>
> "Alistair Francis" <alistair@...stair23.me> writes:
>
> > 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.
> >
> > v5:
> > - Rebase on latest rust-next on top of v6.13-rc6
> > - Allow support for LTO inlining (not in this series, see
> > https://github.com/alistair23/linux/commit/e6b847324b4f5e904e007c0e288c88d2483928a8)
>
> Thanks! Since Gary just sent v2 of the LTO patch [1], could you rebase
> on that and list it as a dependency? If you are using b4 there is a nice
I can't get Gary's series to apply on rust-next (it does apply on
master though).
I might just wait until Gary's series gets picked up to rust-next as
there is already a lot of manual rebasing going on and my series
currently applies on rust-next.
Unfortunately there are just constant conflicts as the number of
manual C helpers are continually growing.
Obviously when/if this series is approved I can do a final rebase, I
would just like to avoid unnecessary churn in the meantime
Alistair
> feature for that [2].
>
>
> Best regards,
> Andreas Hindborg
>
>
> [1] https://lore.kernel.org/all/20250105194054.545201-1-gary@garyguo.net/
> [2] https://b4.docs.kernel.org/en/latest/contributor/prep.html#working-with-series-dependencies
>
Powered by blists - more mailing lists