All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] bcachefs: omit alignment attribute on big endian struct bkey
@ 2024-02-16  2:44 Thomas Bertschinger
  2024-02-16  2:54 ` Kent Overstreet
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Bertschinger @ 2024-02-16  2:44 UTC (permalink / raw)
  To: kent.overstreet, linux-bcachefs, bfoster; +Cc: Thomas Bertschinger

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 in the big endian case. 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, 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.

The little endian version can have the "align" attribute because the
"packed" attr is redundant, and rust-bindgen will omit the "packed" attr
when an "align" attr is present and it can do so without changing a
type's layout

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
---
v2: add comment explaining why this is needed

 fs/bcachefs/bcachefs_format.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 1bb24aa73528..00060bc6128f 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -222,7 +222,17 @@ struct bkey {
 
 	__u8		pad[1];
 #endif
-} __packed __aligned(8);
+} __packed
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+/*
+ * The big-endian version of bkey can't be compiled by rustc with the "aligned"
+ * attr since it doesn't allow types to have both "packed" and "aligned" attrs.
+ * So for Rust compatibility, don't include this. It can be included in the LE
+ * version because the "packed" attr is redundant in that case.
+ */
+__aligned(8)
+#endif
+;
 
 struct bkey_packed {
 	__u64		_data[0];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] bcachefs: omit alignment attribute on big endian struct bkey
  2024-02-16  2:44 [PATCH v2] bcachefs: omit alignment attribute on big endian struct bkey Thomas Bertschinger
@ 2024-02-16  2:54 ` Kent Overstreet
  0 siblings, 0 replies; 2+ messages in thread
From: Kent Overstreet @ 2024-02-16  2:54 UTC (permalink / raw)
  To: Thomas Bertschinger; +Cc: linux-bcachefs, bfoster

On Thu, Feb 15, 2024 at 07:44:21PM -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 in the big endian case. 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, 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.
> 
> The little endian version can have the "align" attribute because the
> "packed" attr is redundant, and rust-bindgen will omit the "packed" attr
> when an "align" attr is present and it can do so without changing a
> type's layout
> 
> Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>

Thanks, applied

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-16  2:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-16  2:44 [PATCH v2] bcachefs: omit alignment attribute on big endian struct bkey Thomas Bertschinger
2024-02-16  2:54 ` Kent Overstreet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.