The high keys in a rmapbt node block are only 4-byte aligned, but union xfs_btree_key is 8-byte aligned because of its 64-bit fields. xchk_rmapbt_check_unwritten_in_keyflags() reads rm_offset through the union. The compiler may use an 8-byte load, and on sparc64 each high key takes an unaligned access trap: Kernel unaligned access at TPC[105a54d8] xchk_rmapbt_check_unwritten_in_keyflags+0xb8/0x160 [xfs] Mark the union __packed __aligned(4). Every btree key in a block is at least 4-byte aligned. The compiler now reads the 64-bit fields with two 4-byte loads. A plain __packed would force byte loads for every key. Fixes: 38384569a2a8 ("xfs: detect unwritten bit set in rmapbt node block keys") Reported-by: Jan Engelhardt Closes: https://github.com/sparclinux/issues/issues/115 Suggested-by: Christoph Hellwig Cc: stable@vger.kernel.org # v6.4+ Signed-off-by: Stian Halseth --- Tested on sparc64 (T4-1, 7.3.7) with a 3-level rmapbt on a loop image. 200 rmapbt scrubs went from 23.7M alignment faults to none. Writing a file with 20000 extents took the same time as before. With a plain __packed it was 17% slower. When this reaches xfsprogs through the libxfs sync, it will need an __aligned() define, for example next to __packed in include/xfs.h. v4: mark the union instead of changing scrub (Christoph). v3: https://lore.kernel.org/all/20261111103047.604541-1-stian@itx.no/ v2: https://lore.kernel.org/all/20261110223927.558557-1-stian@itx.no/ v1: https://lore.kernel.org/all/20261109134853.1659991-1-stian@itx.no/ fs/xfs/libxfs/xfs_btree.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index c4337ab24..1fe1137a9 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -28,6 +28,11 @@ union xfs_btree_ptr { * The in-core btree key. Overlapping btrees actually store two keys * per pointer, so we reserve enough memory to hold both. The __*bigkey * items should never be accessed directly. + * + * Keys in a btree block may be only 4-byte aligned. Without the + * attributes, the 64-bit fields make the union 8-byte aligned. The + * compiler may then use 8-byte loads, which trap on strict-alignment + * architectures. __aligned(4) needs __packed to lower the alignment. */ union xfs_btree_key { struct xfs_bmbt_key bmbt; @@ -37,7 +42,7 @@ union xfs_btree_key { struct xfs_rmap_key rmap; struct xfs_rmap_key __rmap_bigkey[2]; struct xfs_refcount_key refc; -}; +} __packed __aligned(4); union xfs_btree_rec { struct xfs_bmbt_rec bmbt; -- 2.56.1