linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: atlantic: fix ring buffer alignment
@ 2023-06-16  9:26 Arnd Bergmann
  2023-06-16 13:10 ` Simon Horman
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2023-06-16  9:26 UTC (permalink / raw)
  To: Igor Russkikh, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	netdev, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

clang warns about conflicting packing annotations:

drivers/net/ethernet/aquantia/atlantic/aq_ring.h:72:2: error: field  within 'struct aq_ring_buff_s' is less aligned than 'union aq_ring_buff_s::(anonymous at drivers/net/ethernet/aquantia/atlantic/aq_ring.h:72:2)' and is usually due to 'struct aq_ring_buff_s' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]

This was originally intended to ensure the structure fits exactly into
32 bytes on 64-bit architectures, but apparently never did, and instead
just produced misaligned pointers as well as forcing byte-wise access
on hardware without unaligned load/store instructions.

Update the comment to more closely reflect the layout and remove the
broken __packed annotation.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 .../net/ethernet/aquantia/atlantic/aq_ring.h  | 26 +++++++++++--------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.h b/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
index 0a6c34438c1d0..a9cc5a1c4c479 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
@@ -26,19 +26,23 @@ struct aq_rxpage {
 	unsigned int pg_off;
 };
 
-/*           TxC       SOP        DX         EOP
- *         +----------+----------+----------+-----------
- *   8bytes|len l3,l4 | pa       | pa       | pa
- *         +----------+----------+----------+-----------
- * 4/8bytes|len pkt   |len pkt   |          | skb
- *         +----------+----------+----------+-----------
- * 4/8bytes|is_gso    |len,flags |len       |len,is_eop
- *         +----------+----------+----------+-----------
+/*           TxC       SOP        DX         EOP	RX
+ *         +----------+----------+----------+----------+-------
+ *   8bytes|len l3,l4 | pa       | pa       | pa       | hash
+ *         +----------+----------+----------+----------+-------
+ * 4/8bytes|len pkt   |len pkt   |          | skb      | page
+ *         +----------+----------+----------+----------+-------
+ * 4/8bytes|is_gso    |len,flags |len       |len,is_eop| daddr
+ *         +----------+----------+----------+----------+-------
+ * 4/8bytes|          |          |          |          | order,pgoff
+ *         +----------+----------+----------+----------+-------
+ * 2bytes  |          |          |          |          | vlan_rx_tag
+ *         +----------+----------+----------+----------+-------
+ * 8bytes  +                   flags
+ *         +----------+----------+----------+----------+-------
  *
- *  This aq_ring_buff_s doesn't have endianness dependency.
- *  It is __packed for cache line optimizations.
  */
-struct __packed aq_ring_buff_s {
+struct aq_ring_buff_s {
 	union {
 		/* RX/TX */
 		dma_addr_t pa;
-- 
2.39.2


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

* Re: [PATCH] net: atlantic: fix ring buffer alignment
  2023-06-16  9:26 [PATCH] net: atlantic: fix ring buffer alignment Arnd Bergmann
@ 2023-06-16 13:10 ` Simon Horman
  2023-06-20 19:00   ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Horman @ 2023-06-16 13:10 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Igor Russkikh, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
	Tom Rix, netdev, linux-kernel, llvm

On Fri, Jun 16, 2023 at 11:26:32AM +0200, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang warns about conflicting packing annotations:
> 
> drivers/net/ethernet/aquantia/atlantic/aq_ring.h:72:2: error: field  within 'struct aq_ring_buff_s' is less aligned than 'union aq_ring_buff_s::(anonymous at drivers/net/ethernet/aquantia/atlantic/aq_ring.h:72:2)' and is usually due to 'struct aq_ring_buff_s' being packed, which can lead to unaligned accesses [-Werror,-Wunaligned-access]

FWIIW, I was able to reproduce this (warning) with clang-16 on ARM (32bit).
And I agree with the approach you have taken here.

> This was originally intended to ensure the structure fits exactly into
> 32 bytes on 64-bit architectures, but apparently never did, and instead
> just produced misaligned pointers as well as forcing byte-wise access
> on hardware without unaligned load/store instructions.
> 
> Update the comment to more closely reflect the layout and remove the
> broken __packed annotation.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  .../net/ethernet/aquantia/atlantic/aq_ring.h  | 26 +++++++++++--------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.h b/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
> index 0a6c34438c1d0..a9cc5a1c4c479 100644
> --- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
> +++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.h
> @@ -26,19 +26,23 @@ struct aq_rxpage {
>  	unsigned int pg_off;
>  };
>  
> -/*           TxC       SOP        DX         EOP
> - *         +----------+----------+----------+-----------
> - *   8bytes|len l3,l4 | pa       | pa       | pa
> - *         +----------+----------+----------+-----------
> - * 4/8bytes|len pkt   |len pkt   |          | skb
> - *         +----------+----------+----------+-----------
> - * 4/8bytes|is_gso    |len,flags |len       |len,is_eop
> - *         +----------+----------+----------+-----------
> +/*           TxC       SOP        DX         EOP	RX
> + *         +----------+----------+----------+----------+-------
> + *   8bytes|len l3,l4 | pa       | pa       | pa       | hash
> + *         +----------+----------+----------+----------+-------
> + * 4/8bytes|len pkt   |len pkt   |          | skb      | page
> + *         +----------+----------+----------+----------+-------
> + * 4/8bytes|is_gso    |len,flags |len       |len,is_eop| daddr
> + *         +----------+----------+----------+----------+-------
> + * 4/8bytes|          |          |          |          | order,pgoff
> + *         +----------+----------+----------+----------+-------
> + * 2bytes  |          |          |          |          | vlan_rx_tag
> + *         +----------+----------+----------+----------+-------
> + * 8bytes  +                   flags
> + *         +----------+----------+----------+----------+-------

Perhaps it just me.  But I do have trouble reconciling the description
above with the structure below. As such, my suggest would be to simply
delete it.

>   *
> - *  This aq_ring_buff_s doesn't have endianness dependency.
> - *  It is __packed for cache line optimizations.
>   */
> -struct __packed aq_ring_buff_s {
> +struct aq_ring_buff_s {
>  	union {
>  		/* RX/TX */
>  		dma_addr_t pa;

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

* Re: [PATCH] net: atlantic: fix ring buffer alignment
  2023-06-16 13:10 ` Simon Horman
@ 2023-06-20 19:00   ` Jakub Kicinski
  2023-06-22  5:49     ` [EXT] " Igor Russkikh
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2023-06-20 19:00 UTC (permalink / raw)
  To: Simon Horman, Igor Russkikh
  Cc: Arnd Bergmann, David S. Miller, Eric Dumazet, Paolo Abeni,
	Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	netdev, linux-kernel, llvm

On Fri, 16 Jun 2023 15:10:03 +0200 Simon Horman wrote:
> Perhaps it just me.  But I do have trouble reconciling the description
> above with the structure below. As such, my suggest would be to simply
> delete it.

Agreed that the comment is confusing seems to be incorrect post-change.
Flags for instance are overlapped with len, is_gso etc. so they can't be
a separate 8B at the end.

Igor, please advise how you want to proceed.

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

* Re: [EXT] Re: [PATCH] net: atlantic: fix ring buffer alignment
  2023-06-20 19:00   ` Jakub Kicinski
@ 2023-06-22  5:49     ` Igor Russkikh
  2023-06-22 16:36       ` Jakub Kicinski
  0 siblings, 1 reply; 5+ messages in thread
From: Igor Russkikh @ 2023-06-22  5:49 UTC (permalink / raw)
  To: Jakub Kicinski, Simon Horman
  Cc: Arnd Bergmann, David S. Miller, Eric Dumazet, Paolo Abeni,
	Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	netdev, linux-kernel, llvm


Hi Jakub, Arnd,

> On Fri, 16 Jun 2023 15:10:03 +0200 Simon Horman wrote:
>> Perhaps it just me.  But I do have trouble reconciling the description
>> above with the structure below. As such, my suggest would be to simply
>> delete it.
> 
> Agreed that the comment is confusing seems to be incorrect post-change.
> Flags for instance are overlapped with len, is_gso etc. so they can't be
> a separate 8B at the end.
> 
> Igor, please advise how you want to proceed.

I do agree better to remove the comment at all - it explains almost nothing.

Thats not a hardware related structure, so explicit pack is for sure not required.

Acked-by: Igor Russkikh <irusskikh@marvell.com>

Regards,
  Igor

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

* Re: [EXT] Re: [PATCH] net: atlantic: fix ring buffer alignment
  2023-06-22  5:49     ` [EXT] " Igor Russkikh
@ 2023-06-22 16:36       ` Jakub Kicinski
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2023-06-22 16:36 UTC (permalink / raw)
  To: Igor Russkikh, Arnd Bergmann
  Cc: Simon Horman, David S. Miller, Eric Dumazet, Paolo Abeni,
	Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	netdev, linux-kernel, llvm

On Thu, 22 Jun 2023 07:49:52 +0200 Igor Russkikh wrote:
> > Agreed that the comment is confusing seems to be incorrect post-change.
> > Flags for instance are overlapped with len, is_gso etc. so they can't be
> > a separate 8B at the end.
> > 
> > Igor, please advise how you want to proceed.  
> 
> I do agree better to remove the comment at all - it explains almost nothing.
> 
> Thats not a hardware related structure, so explicit pack is for sure not required.
> 
> Acked-by: Igor Russkikh <irusskikh@marvell.com>

Thanks Igor! 
Arnd, could you respin with the comment removed?

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

end of thread, other threads:[~2023-06-22 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16  9:26 [PATCH] net: atlantic: fix ring buffer alignment Arnd Bergmann
2023-06-16 13:10 ` Simon Horman
2023-06-20 19:00   ` Jakub Kicinski
2023-06-22  5:49     ` [EXT] " Igor Russkikh
2023-06-22 16:36       ` Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).