mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Edward Cree <ecree.xilinx@gmail.com>
To: Arnd Bergmann <arnd@kernel.org>,
	Martin Habets <habetsm.xilinx@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	netdev@vger.kernel.org, linux-net-drivers@amd.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] sfc: selftest: fix struct packing
Date: Mon, 19 Jun 2023 11:25:49 +0100	[thread overview]
Message-ID: <7c448f02-4031-0a90-97e2-0cc663b0cff9@gmail.com> (raw)
In-Reply-To: <20230619091215.2731541-3-arnd@kernel.org>

On 19/06/2023 10:12, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> Three of the sfc drivers define a packed loopback_payload structure with an
> ethernet header followed by an IP header. However, the kernel definition
> of iphdr specifies that this is 4-byte aligned, causing a W=1 warning:
> 
> net/ethernet/sfc/siena/selftest.c:46:15: error: field ip within 'struct efx_loopback_payload' is less aligned than 'struct iphdr' and is usually due to 'struct efx_loopback_payload' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]
>         struct iphdr ip;
> 
> As the iphdr packing is not easily changed without breaking other code,
> change the three structures to use a local definition instead.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Duplicating the definition isn't the prettiest thing in the world; it'd
 do for a quick fix if needed but I assume W=1 warnings aren't blocking
 anyone, so maybe defer this one for now and I'll follow up soon with a
 rewrite that fixes this more cleanly?  My idea is to drop the __packed
 from the containing struct, make efx_begin_loopback() copy the layers
 separately, and efx_loopback_rx_packet() similarly do something less
 direct than casting the packet data to the struct.

But I don't insist on it; if you want this fix in immediately then I'm
 okay with that too.

> ---
>  drivers/net/ethernet/sfc/falcon/selftest.c | 21 ++++++++++++++++++++-
>  drivers/net/ethernet/sfc/selftest.c        | 21 ++++++++++++++++++++-
>  drivers/net/ethernet/sfc/siena/selftest.c  | 21 ++++++++++++++++++++-
>  3 files changed, 60 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sfc/falcon/selftest.c b/drivers/net/ethernet/sfc/falcon/selftest.c
> index 6a454ac6f8763..fb7fcd27a33a5 100644
> --- a/drivers/net/ethernet/sfc/falcon/selftest.c
> +++ b/drivers/net/ethernet/sfc/falcon/selftest.c
> @@ -40,7 +40,26 @@
>   */
>  struct ef4_loopback_payload {
>  	struct ethhdr header;
> -	struct iphdr ip;
> +	struct {
> +#if defined(__LITTLE_ENDIAN_BITFIELD)
> +		__u8	ihl:4,
> +			version:4;
> +#elif defined (__BIG_ENDIAN_BITFIELD)
> +		__u8	version:4,
> +			ihl:4;
> +#else
> +#error	"Please fix <asm/byteorder.h>"
> +#endif
> +		__u8	tos;
> +		__be16	tot_len;
> +		__be16	id;
> +		__be16	frag_off;
> +		__u8	ttl;
> +		__u8	protocol;
> +		__sum16	check;
> +		__be32	saddr;
> +		__be32	daddr;
> +	} __packed ip; /* unaligned struct iphdr */
>  	struct udphdr udp;
>  	__be16 iteration;
>  	char msg[64];
> diff --git a/drivers/net/ethernet/sfc/selftest.c b/drivers/net/ethernet/sfc/selftest.c
> index 3c5227afd4977..440a57953779c 100644
> --- a/drivers/net/ethernet/sfc/selftest.c
> +++ b/drivers/net/ethernet/sfc/selftest.c
> @@ -43,7 +43,26 @@
>   */
>  struct efx_loopback_payload {
>  	struct ethhdr header;
> -	struct iphdr ip;
> +	struct {
> +#if defined(__LITTLE_ENDIAN_BITFIELD)
> +		__u8	ihl:4,
> +			version:4;
> +#elif defined (__BIG_ENDIAN_BITFIELD)
> +		__u8	version:4,
> +			ihl:4;
> +#else
> +#error	"Please fix <asm/byteorder.h>"
> +#endif
> +		__u8	tos;
> +		__be16	tot_len;
> +		__be16	id;
> +		__be16	frag_off;
> +		__u8	ttl;
> +		__u8	protocol;
> +		__sum16	check;
> +		__be32	saddr;
> +		__be32	daddr;
> +	} __packed ip; /* unaligned struct iphdr */
>  	struct udphdr udp;
>  	__be16 iteration;
>  	char msg[64];
> diff --git a/drivers/net/ethernet/sfc/siena/selftest.c b/drivers/net/ethernet/sfc/siena/selftest.c
> index 07715a3d6beab..b8a8b0495f661 100644
> --- a/drivers/net/ethernet/sfc/siena/selftest.c
> +++ b/drivers/net/ethernet/sfc/siena/selftest.c
> @@ -43,7 +43,26 @@
>   */
>  struct efx_loopback_payload {
>  	struct ethhdr header;
> -	struct iphdr ip;
> +	struct {
> +#if defined(__LITTLE_ENDIAN_BITFIELD)
> +		__u8	ihl:4,
> +			version:4;
> +#elif defined (__BIG_ENDIAN_BITFIELD)
> +		__u8	version:4,
> +			ihl:4;
> +#else
> +#error	"Please fix <asm/byteorder.h>"
> +#endif
> +		__u8	tos;
> +		__be16	tot_len;
> +		__be16	id;
> +		__be16	frag_off;
> +		__u8	ttl;
> +		__u8	protocol;
> +		__sum16	check;
> +		__be32	saddr;
> +		__be32	daddr;
> +	} __packed ip; /* unaligned struct iphdr */
>  	struct udphdr udp;
>  	__be16 iteration;
>  	char msg[64];
> 


  reply	other threads:[~2023-06-19 10:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-19  9:12 [PATCH 1/3] [v2] sfc: add CONFIG_INET dependency for TC offload Arnd Bergmann
2023-06-19  9:12 ` [PATCH 2/3] [v2] sfc: fix uninitialized variable use Arnd Bergmann
2023-06-19 10:06   ` Edward Cree
2023-06-19  9:12 ` [PATCH 3/3] sfc: selftest: fix struct packing Arnd Bergmann
2023-06-19 10:25   ` Edward Cree [this message]
2023-06-19 13:04     ` Arnd Bergmann
2023-06-19 14:55     ` Arnd Bergmann
2023-06-23 10:52     ` David Laight
2023-06-23 12:57       ` Edward Cree
2023-06-19 10:04 ` [PATCH 1/3] [v2] sfc: add CONFIG_INET dependency for TC offload Edward Cree
2023-06-21  3:40 ` patchwork-bot+netdevbpf

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=7c448f02-4031-0a90-97e2-0cc663b0cff9@gmail.com \
    --to=ecree.xilinx@gmail.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=habetsm.xilinx@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-net-drivers@amd.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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

Powered by JetHome