RE: [PATCH net-next 06/10] net/mlx4_core: Fix struct mlx4_vhcr_cmd to make implicit padding explicit

David Laight
2015-01-27T09:43:38Z

From: Amir Vadai
> From: Jack Morgenstein <jackm@dev.mellanox.co.il>
>
> Struct mlx4_vhcr was implicitly padded by the gcc compiler.
> This commit makes that padding explicit, to prevent issues with
> changing compilers. Note that we added the padding dword (rather
> than simply packing the structure) in order to maintain compatibility
> with previous kernels.

It isn't a 'compiler' option, but depends on the architecture.

> Reported-by: Alexander Schmidt <alexs@linux.vnet.ibm.com>
> Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
> Signed-off-by: Amir Vadai <amirv@mellanox.com>
> ---
> drivers/net/ethernet/mellanox/mlx4/mlx4.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/mlx4.h b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
> index 096a81c..595e18a 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/mlx4.h
> +++ b/drivers/net/ethernet/mellanox/mlx4/mlx4.h
> @@ -196,13 +196,14 @@ struct mlx4_vhcr {
> struct mlx4_vhcr_cmd {
> __be64 in_param;
> __be32 in_modifier;
> + u32 reserved1;

Adding a pad here changes the alignment on most 32bit architectures (eg i386)
where 64bit integers are only aligned to 4 byte boundaries.
So you are not 'maintaining compatibility with previous kernels'.

> __be64 out_param;
> __be16 token;
> u16 reserved;
> u8 status;
> u8 flags;
> __be16 opcode;
> -};
> +} __packed;

Don't add '__packed' unless you expect the structure to be misaligned
in memory.
On systems that fault mis-aligned memory requests you've requested the
compiler generate code to read/write everything using byte sized memory
accesses and a lot of shifting and masking.

David