Skip to contentSkip to conversation

idpf: avoid compiler introduced padding in virtchnl2_rss_key struct

PATCH In review Pavan Kumar Linga 3 participants 3 messages Dec 15, 2023 – Dec 22, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 idpf: avoid compiler introduced padding in virtchnl2_rss_key struct

Size of the virtchnl2_rss_key struct should be 7 bytes but the compiler introduces a padding byte for the structure alignment. This results in idpf sending an additional byte of memory to the device control plane than the expected buffer size. As the control plane enforces virtchnl message size checks to validate the message, set RSS key message fails resulting in the driver load failure.

Remove implicit compiler padding by using "__packed" structure attribute for the virtchnl2_rss_key struct.

Also there is no need to use __DECLARE_FLEX_ARRAY macro for the 'key_flex' struct field. So drop it.

Fixes 0d7502a9b4a7 ("virtchnl: add virtchnl version 2 ops")
---
 drivers/net/ethernet/intel/idpf/virtchnl2.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/idpf/virtchnl2.h +3 -3
index 07e72c72d15..8dc83788972 100644
@@ -1104,9 +1104,9 @@ struct virtchnl2_rss_key {
 	__le32 vport_id;
 	__le16 key_len;
 	u8 pad;
-	__DECLARE_FLEX_ARRAY(u8, key_flex);
-};
-VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_rss_key);
+	u8 key_flex[];
+} __packed;
+VIRTCHNL2_CHECK_STRUCT_LEN(7, virtchnl2_rss_key);
 
 /**
  * struct virtchnl2_queue_chunk - chunk of contiguous queues
Signature · 1 line
2.38.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Pavan Kumar Linga

Size of the virtchnl2_rss_key struct should be 7 bytes but the compiler introduces a padding byte for the structure alignment. This results in idpf sending an additional byte of memory to the device control plane than the expected buffer size. As the control plane enforces virtchnl message size checks to validate the message, set RSS key message fails resulting in the driver load failure.

Remove implicit compiler padding by using "__packed" structure attribute for the virtchnl2_rss_key struct.

Quoted 6 lines

Also there is no need to use __DECLARE_FLEX_ARRAY macro for the 'key_flex' struct field. So drop it.

Fixes 0d7502a9b4a7 ("virtchnl: add virtchnl version 2 ops")
Tested-by on v1 1/1
#2 lore raw
In reply to Pavan Kumar Linga
Quoted 26 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Pavan Kumar Linga
Sent: Friday, December 15, 2023 3:48 PM
To: [email protected]
Cc: [email protected]; Lobakin, Aleksander <[email protected]>; Linga, Pavan Kumar <[email protected]>; Kitszel, Przemyslaw <[email protected]>; Zaremba, Larysa <[email protected]>
Subject: [Intel-wired-lan] [PATCH iwl-net] idpf: avoid compiler introduced padding in virtchnl2_rss_key struct

Size of the virtchnl2_rss_key struct should be 7 bytes but the compiler introduces a padding byte for the structure alignment. This results in idpf sending an additional byte of memory to the device control plane than the expected buffer size. As the control plane enforces virtchnl message size checks to validate the message, set RSS key message fails resulting in the driver load failure.

Remove implicit compiler padding by using "__packed" structure attribute for the virtchnl2_rss_key struct.

Also there is no need to use __DECLARE_FLEX_ARRAY macro for the 'key_flex' struct field. So drop it.

Quoted 6 lines
Fixes 0d7502a9b4a7 ("virtchnl: add virtchnl version 2 ops")
---
 drivers/net/ethernet/intel/idpf/virtchnl2.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)