From: Brian Foster <bfoster@redhat.com>
To: Thomas Bertschinger <tahbertschinger@gmail.com>
Cc: linux-bcachefs@vger.kernel.org, kent.overstreet@linux.dev
Subject: Re: [PATCH] bcachefs: omit alignment attribute on big endian struct bkey
Date: Thu, 15 Feb 2024 12:23:12 -0500 [thread overview]
Message-ID: <Zc5IgMloeK/XkXR+@bfoster> (raw)
In-Reply-To: <20240215161957.112262-1-tahbertschinger@gmail.com>
On Thu, Feb 15, 2024 at 09:19:57AM -0700, Thomas Bertschinger wrote:
> This is needed for building Rust bindings on big endian architectures
> like s390x. Currently this is only done in userspace, but it might
> happen in-kernel in the future. When creating a Rust binding for struct
> bkey, the "packed" attribute is needed to get a type with the correct
> member offsets. However, rustc does not allow types to have both a
> "packed" and "align" attribute. Thus, in order to get a Rust type
> compatible with the C type, on big endian systems we must omit the
> "aligned" attribute in C.
>
> This does not affect the struct's size or member offsets, only its
> toplevel alignment, which should be an acceptable impact.
>
> Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
> ---
> fs/bcachefs/bcachefs_format.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
> index 1bb24aa73528..fc12efe8f8cd 100644
> --- a/fs/bcachefs/bcachefs_format.h
> +++ b/fs/bcachefs/bcachefs_format.h
> @@ -222,7 +222,11 @@ struct bkey {
>
> __u8 pad[1];
> #endif
> -} __packed __aligned(8);
> +} __packed
I can't really comment on the Rust context, but could you add a comment
to explain why the ifdef is here? I.e., even something as simple as
"Rust disallows packed and aligned on ..." is useful.
Also out of curiosity, is there some reason these two attributes
together presumably isn't a problem for LE?
Brian
> +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> +__aligned(8)
> +#endif
> +;
>
> struct bkey_packed {
> __u64 _data[0];
> --
> 2.43.0
>
next prev parent reply other threads:[~2024-02-15 17:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 16:19 [PATCH] bcachefs: omit alignment attribute on big endian struct bkey Thomas Bertschinger
2024-02-15 17:23 ` Brian Foster [this message]
2024-02-15 18:02 ` Thomas Bertschinger
2024-02-16 0:12 ` Kent Overstreet
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=Zc5IgMloeK/XkXR+@bfoster \
--to=bfoster@redhat.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--cc=tahbertschinger@gmail.com \
/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