netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] idpf: avoid compiler padding in virtchnl2_ptype struct
@ 2024-01-29 18:41 Tony Nguyen
  2024-01-31  2:34 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Tony Nguyen @ 2024-01-29 18:41 UTC (permalink / raw)
  To: davem, kuba, pabeni, edumazet, netdev
  Cc: Pavan Kumar Linga, anthony.l.nguyen, willemb, David.Laight,
	kernel test robot, Przemek Kitszel, Paul Menzel, Simon Horman

From: Pavan Kumar Linga <pavan.kumar.linga@intel.com>

In the arm random config file, kconfig option 'CONFIG_AEABI' is
disabled which results in adding the compiler flag '-mabi=apcs-gnu'.
This causes the compiler to add padding in virtchnl2_ptype
structure to align it to 8 bytes, resulting in the following
size check failure:

include/linux/build_bug.h:78:41: error: static assertion failed: "(6) == sizeof(struct virtchnl2_ptype)"
      78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
         |                                         ^~~~~~~~~~~~~~
include/linux/build_bug.h:77:34: note: in expansion of macro '__static_assert'
      77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
         |                                  ^~~~~~~~~~~~~~~
drivers/net/ethernet/intel/idpf/virtchnl2.h:26:9: note: in expansion of macro 'static_assert'
      26 |         static_assert((n) == sizeof(struct X))
         |         ^~~~~~~~~~~~~
drivers/net/ethernet/intel/idpf/virtchnl2.h:982:1: note: in expansion of macro 'VIRTCHNL2_CHECK_STRUCT_LEN'
     982 | VIRTCHNL2_CHECK_STRUCT_LEN(6, virtchnl2_ptype);
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~

Avoid the compiler padding by using "__packed" structure
attribute for the virtchnl2_ptype struct. Also align the
structure by using "__aligned(2)" for better code optimization.
While at it, swap the static_assert conditional statement
variables.

Fixes: 0d7502a9b4a7 ("virtchnl: add virtchnl version 2 ops")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312220250.ufEm8doQ-lkp@intel.com
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
---
v2:
- swap the static_assert conditional statement variables

v1: https://lore.kernel.org/netdev/20240122175202.512762-1-anthony.l.nguyen@intel.com/

 drivers/net/ethernet/intel/idpf/virtchnl2.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/virtchnl2.h b/drivers/net/ethernet/intel/idpf/virtchnl2.h
index 8dc837889723..506036e7df06 100644
--- a/drivers/net/ethernet/intel/idpf/virtchnl2.h
+++ b/drivers/net/ethernet/intel/idpf/virtchnl2.h
@@ -23,7 +23,7 @@
  * is not exactly the correct length.
  */
 #define VIRTCHNL2_CHECK_STRUCT_LEN(n, X)	\
-	static_assert((n) == sizeof(struct X))
+	static_assert(sizeof(struct X) == (n))
 
 /* New major set of opcodes introduced and so leaving room for
  * old misc opcodes to be added in future. Also these opcodes may only
@@ -978,7 +978,7 @@ struct virtchnl2_ptype {
 	u8 proto_id_count;
 	__le16 pad;
 	__le16 proto_id[];
-};
+} __packed __aligned(2);
 VIRTCHNL2_CHECK_STRUCT_LEN(6, virtchnl2_ptype);
 
 /**
-- 
2.41.0


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

* Re: [PATCH net v2] idpf: avoid compiler padding in virtchnl2_ptype struct
  2024-01-29 18:41 [PATCH net v2] idpf: avoid compiler padding in virtchnl2_ptype struct Tony Nguyen
@ 2024-01-31  2:34 ` Jakub Kicinski
  2024-01-31 21:46   ` Tony Nguyen
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2024-01-31  2:34 UTC (permalink / raw)
  To: Tony Nguyen
  Cc: davem, pabeni, edumazet, netdev, Pavan Kumar Linga, willemb,
	David.Laight, kernel test robot, Przemek Kitszel, Paul Menzel,
	Simon Horman

On Mon, 29 Jan 2024 10:41:14 -0800 Tony Nguyen wrote:
> While at it, swap the static_assert conditional statement
> variables.

Sorry but there should be no "while at it"s in a fix.
There's hardly any relation between the two changes.
-- 
pw-bot: cr

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

* Re: [PATCH net v2] idpf: avoid compiler padding in virtchnl2_ptype struct
  2024-01-31  2:34 ` Jakub Kicinski
@ 2024-01-31 21:46   ` Tony Nguyen
  0 siblings, 0 replies; 3+ messages in thread
From: Tony Nguyen @ 2024-01-31 21:46 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, pabeni, edumazet, netdev, Pavan Kumar Linga, willemb,
	David.Laight, kernel test robot, Przemek Kitszel, Paul Menzel,
	Simon Horman

On 1/30/2024 6:34 PM, Jakub Kicinski wrote:
> On Mon, 29 Jan 2024 10:41:14 -0800 Tony Nguyen wrote:
>> While at it, swap the static_assert conditional statement
>> variables.
> 
> Sorry but there should be no "while at it"s in a fix.
> There's hardly any relation between the two changes.

Will split these out and send the swap via net-next.

Thanks,
Tony

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

end of thread, other threads:[~2024-01-31 21:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-29 18:41 [PATCH net v2] idpf: avoid compiler padding in virtchnl2_ptype struct Tony Nguyen
2024-01-31  2:34 ` Jakub Kicinski
2024-01-31 21:46   ` Tony Nguyen

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).