Re: [RFC PATCH V2 2/8] rust: Extend OPP bindings for the OPP table

From: Alice Ryhl
Date: Mon Jun 10 2024 - 04:30:36 EST


On Fri, Jun 7, 2024 at 1:04 PM Manos Pitsidianakis
<manos.pitsidianakis@xxxxxxxxxx> wrote:
>
> On Fri, 07 Jun 2024 12:12, Viresh Kumar <viresh.kumar@xxxxxxxxxx> wrote:
> >+/// OPP search types.
> >+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
> >+pub enum SearchType {
> >+ /// Search for exact value.
> >+ Exact,
> >+ /// Search for highest value less than equal to value.
> >+ Floor,
> >+ /// Search for lowest value greater than equal to value.
> >+ Ceil,
> >+}
>
> Seeing this enum made me think about memory layouts which are not stable
> in Rust and can change between compilations unless they have a specific
> `repr`.
>
> Not related to this series directly, has there been discussion about
> guaranteeing struct layouts in kernel APIs? It'd require a lot of things
> to happen to cause a problem (multiple users of an API in the kernel in
> separate compilation units maybe even compiled with different rustc
> versions).

If you have two compilation units A and B where A depends on B, then
part of the input to `rustc A` will be the metadata emitted by `rustc
B`, which contains enough information to ensure that they agree on the
layout of structs defined in B. The metadata format is unstable and
changes each rustc release, so you cannot mix different rustc
compilers.

Alice