Whamcloud - gitweb
LU-12822 uapi: properly pack data structures 98/36798/11
authorJames Simmons <jsimmons@infradead.org>
Sat, 18 Jan 2020 15:12:38 +0000 (10:12 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 28 Jan 2020 06:02:04 +0000 (06:02 +0000)
commit4751e4a951975e7fa5fa8de893224f9cc03f4165
treeef5f91fd11e775df8197dcfefdd84599d36d4361
parent7fff052c930da4822c3b2a13d130da7473a20a58
LU-12822 uapi: properly pack data structures

Linux UAPI headers use the gcc attributre __packed__ to ensure
that the data structures are the exact same size on all platforms.
This comes at the cost of potential misaligned accesses to these
data structures which at best cost performance and at worst cause
a bus error on some platforms. To detect potential misaligned
access starting with gcc version 9 a new compile flags was
introduced which is now impacting builds with Lustre.

Examining the build failures shows most of the problems are due to
packed data structures in the Lustre UAPI header containing
unpacked data structure fields. Packing those missed structures
resolved many of the build issues. The second problem is that the
lustre utilities tend to cast some of its UAPI data structure.
A good example is struct lov_user_md being cast to
struct lov_user_md_v3. To ensure this is properly handled with
packed data structures we need to use the __may_alias__ compiler
attribute. The one exception is struct statx which is defined out
side of Lustre and its unpacked. This requires extra special
handling in user land code due to the described issues in this
comment.

Fixing this problem exposed an incorrect wiretest for
struct update_op

Last problem address is the use of __swabXXp() on packed data
structure fields. Because of the potential alignment issues we
have to use __swabXX() functions instead.

Change-Id: I149c55d3361e893bd890f9c5e9c77c15f81acc1b
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/36798
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Quentin Bouget <quentin.bouget@cea.fr>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
contrib/scripts/checkpatch.pl
lustre/include/uapi/linux/lustre/lustre_idl.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/ptlrpc/wiretest.c
lustre/utils/liblustreapi.c
lustre/utils/liblustreapi_layout.c
lustre/utils/wiretest.c