Skip to contentSkip to conversation

Reduce scope address-of-packed-member warning

PATCH Superseded Bruce Richardson 7 participants 42 messages Oct 17, 2024 – Oct 30, 2024 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover Reduce scope address-of-packed-member warning

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 60 insertions(+), 154 deletions(-)

--
2.43.0

#1 lore raw

PATCH 1/6 ip_frag: remove use of unaligned variable

If compiling with -Waddress-of-packed-member, we get a warning about the use of the unaligned uint64_t value which is used to copy 8 bytes from ip_hdr to the key. Replace this unaligned assignment with an equivalent 8-byte constant-sized memcpy, allowing the compiler to choose optimal instructions to do the assignment.

---
 lib/ip_frag/rte_ipv4_reassembly.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/ip_frag/rte_ipv4_reassembly.c +1 -3
index 4a89a5f536..5818f50f40 100644
@@ -101,7 +101,6 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
 {
 	struct ip_frag_pkt *fp;
 	struct ip_frag_key key;
-	const unaligned_uint64_t *psd;
 	uint16_t flag_offset, ip_ofs, ip_flag;
 	int32_t ip_len;
 	int32_t trim;
@@ -110,9 +109,8 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
 	ip_ofs = (uint16_t)(flag_offset & RTE_IPV4_HDR_OFFSET_MASK);
 	ip_flag = (uint16_t)(flag_offset & RTE_IPV4_HDR_MF_FLAG);
 
-	psd = (unaligned_uint64_t *)&ip_hdr->src_addr;
 	/* use first 8 bytes only */
-	key.src_dst[0] = psd[0];
+	memcpy(&key.src_dst[0], &ip_hdr->src_addr, 8);
 	key.id = ip_hdr->packet_id;
 	key.key_len = IPV4_KEYLEN;
 
Signature · 1 line
2.43.0
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] ip_frag: remove use of unaligned variable

Quoted 7 lines · On Thu, 17 Oct 2024 15:22:08 +0100 Bruce Richardson…

If compiling with -Waddress-of-packed-member, we get a warning about the use of the unaligned uint64_t value which is used to copy 8 bytes from ip_hdr to the key. Replace this unaligned assignment with an equivalent 8-byte constant-sized memcpy, allowing the compiler to choose optimal instructions to do the assignment.

Acked-by on v1 1/6
#3 lore raw

RE: [PATCH 1/6] ip_frag: remove use of unaligned variable

In reply to Bruce Richardson
Quoted 27 lines

If compiling with -Waddress-of-packed-member, we get a warning about the use of the unaligned uint64_t value which is used to copy 8 bytes from ip_hdr to the key. Replace this unaligned assignment with an equivalent 8-byte constant-sized memcpy, allowing the compiler to choose optimal instructions to do the assignment.

---
 lib/ip_frag/rte_ipv4_reassembly.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/ip_frag/rte_ipv4_reassembly.c +0 -1
index 4a89a5f536..5818f50f40 100644
@@ -101,7 +101,6 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
 {
 	struct ip_frag_pkt *fp;
 	struct ip_frag_key key;
-	const unaligned_uint64_t *psd;
 	uint16_t flag_offset, ip_ofs, ip_flag;
 	int32_t ip_len;
 	int32_t trim;
@@ -110,9 +109,8 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
 	ip_ofs = (uint16_t)(flag_offset & RTE_IPV4_HDR_OFFSET_MASK);

lib/ip_frag/rte_ipv4_reassembly.c rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,

Quoted 10 lines
lib/ip_frag/rte_ipv4_reassembly.c +1 -3
 	ip_flag = (uint16_t)(flag_offset & RTE_IPV4_HDR_MF_FLAG);
 
-	psd = (unaligned_uint64_t *)&ip_hdr->src_addr;
 	/* use first 8 bytes only */
-	key.src_dst[0] = psd[0];
+	memcpy(&key.src_dst[0], &ip_hdr->src_addr, 8);
 	key.id = ip_hdr->packet_id;
 	key.key_len = IPV4_KEYLEN;
 
--

As a small nit, might be better:
memcpy(&key.src_dst[0], &ip_hdr->src_addr, sizeof(key.src_dst[0]));

Quoted 1 line

2.43.0

#4 lore raw

PATCH 2/6 efd: remove unnecessary packed attributes

In reply to Bruce Richardson

The structure "efd_online_group_entry" only consists of values which are typedefs of "uint16_t", so packing the structure has no effect. The "efd_online_chunk" structure has a mix of "uint8_t" and the "efd_online_group_entry" struct, i.e. uint16_t values, but since the first, uint8_t, member array is of even size, the packed attribute does not affect the structure layout.

Removing these packed attributes allows the library to compile cleanly without "-Wno-address-of-packed-member" compiler flag.

---
 lib/efd/rte_efd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/efd/rte_efd.c +2 -2
index d3b732f2e8..3cbb3c2719 100644
@@ -212,7 +212,7 @@ struct efd_offline_chunk_rules {
 struct efd_online_group_entry {
 	efd_hashfunc_t hash_idx[RTE_EFD_VALUE_NUM_BITS];
 	efd_lookuptbl_t lookup_table[RTE_EFD_VALUE_NUM_BITS];
-} __rte_packed;
+};
 
 /**
  * A single chunk record, containing EFD_TARGET_CHUNK_NUM_RULES rules.
@@ -228,7 +228,7 @@ struct efd_online_chunk {
 
 	struct efd_online_group_entry groups[EFD_CHUNK_NUM_GROUPS];
 	/**< Array of all the groups in the chunk. */
-} __rte_packed;
+};
 
 /**
  * EFD table structure
Signature · 1 line
2.43.0
Acked-by on v1 2/6
#5 lore raw

Re: [PATCH 2/6] efd: remove unnecessary packed attributes

Quoted 7 lines · On Thu, 17 Oct 2024 15:22:09 +0100 Bruce Richardson…

The structure "efd_online_group_entry" only consists of values which are typedefs of "uint16_t", so packing the structure has no effect. The "efd_online_chunk" structure has a mix of "uint8_t" and the "efd_online_group_entry" struct, i.e. uint16_t values, but since the first, uint8_t, member array is of even size, the packed attribute does not affect the structure layout.

Quoted 5 lines

Removing these packed attributes allows the library to compile cleanly without "-Wno-address-of-packed-member" compiler flag.

---

#6 lore raw

PATCH 3/6 bus/ifpga: remove packed attribute

In reply to Bruce Richardson

The struct rte_afu_device does not need to be packed, so remove the packed attribute from it.

---
 drivers/bus/ifpga/bus_ifpga_driver.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/ifpga/bus_ifpga_driver.h +1 -1
index 5bbe36d6e0..557e8fd08d 100644
@@ -77,7 +77,7 @@ struct rte_afu_device {
 	struct rte_intr_handle *intr_handle;     /**< Interrupt handle */
 	struct rte_afu_driver *driver;          /**< Associated driver */
 	char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
-} __rte_packed;
+};
 
 /**
  * @internal
Signature · 1 line
2.43.0
Acked-by on v1 3/6
#7 lore raw

RE: [PATCH 3/6] bus/ifpga: remove packed attribute

Hi,

Quoted 31 lines

-----Original Message-----
From: Richardson, Bruce <[email protected]>
Sent: Thursday, October 17, 2024 10:22 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>; Xu, Rosen <[email protected]>
Subject: [PATCH 3/6] bus/ifpga: remove packed attribute

The struct rte_afu_device does not need to be packed, so remove the packed attribute from it.

---
 drivers/bus/ifpga/bus_ifpga_driver.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/ifpga/bus_ifpga_driver.h +1 -2
index 5bbe36d6e0..557e8fd08d 100644
@@ -77,7 +77,7 @@ struct rte_afu_device {
 	struct rte_intr_handle *intr_handle;     /**< Interrupt handle */
 	struct rte_afu_driver *driver;          /**< Associated driver */
 	char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
-} __rte_packed;
+};
 
 /**
  * @internal
--
Quoted 1 line

2.43.0

#9 lore raw

PATCH 4/6 pipeline: remove packed attribute

In reply to Bruce Richardson

The rte_trtcm_data structure, and its substructures, only consist of uint64_t types. This makes packing unnecessary to remove the packed attribute from the structure.

---
 lib/pipeline/rte_table_action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pipeline/rte_table_action.c +1 -1
index 87c3e0e2c9..b3c77dbf66 100644
@@ -109,7 +109,7 @@ mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
 struct mtr_trtcm_data {
 	struct rte_meter_trtcm trtcm;
 	uint64_t stats[RTE_COLORS];
-} __rte_packed;
+};
 
 #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data)          \
 	(((data)->stats[RTE_COLOR_GREEN] & 0xF8LLU) >> 3)
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 4/6] pipeline: remove packed attribute

Quoted 2 lines · Bruce Richardson

The rte_trtcm_data structure, and its substructures, only consist of uint64_t types. This makes packing unnecessary to remove the packed

s/to/, so/

Quoted 23 lines

attribute from the structure.

---
 lib/pipeline/rte_table_action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pipeline/rte_table_action.c +1 -1
index 87c3e0e2c9..b3c77dbf66 100644
@@ -109,7 +109,7 @@ mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
 struct mtr_trtcm_data {
 	struct rte_meter_trtcm trtcm;
 	uint64_t stats[RTE_COLORS];
-} __rte_packed;
+};
 
 #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data)          \
 	(((data)->stats[RTE_COLOR_GREEN] & 0xF8LLU) >> 3)
Signature · 1 line
2.43.0
#12 lore raw

PATCH 5/6 net: add smaller IPv4 cksum function for simple cases

In reply to Bruce Richardson

There are multiple instances in the DPDK app folder where we set up an IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than necessary here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Within that new function, we can adjust slightly how the typecasting to uint16_t is done, and thereby ensure that the app can all be compiled without -Wno-address-of-packed-member compiler flag.

---
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 6 files changed, 39 insertions(+), 142 deletions(-)
app/test-eventdev/test_pipeline_common.c +1 -24
index b111690b7c..204117ef7f 100644
@@ -74,8 +74,6 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 			 struct rte_udp_hdr *udp_hdr, uint16_t pkt_data_len,
 			 uint8_t port, uint8_t flow)
 {
-	uint16_t *ptr16;
-	uint32_t ip_cksum;
 	uint16_t pkt_len;
 
 	/*
@@ -104,28 +102,7 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 	/*
 	 * Compute IP header checksum.
 	 */
-	ptr16 = (unaligned_uint16_t *)ip_hdr;
-	ip_cksum = 0;
-	ip_cksum += ptr16[0];
-	ip_cksum += ptr16[1];
-	ip_cksum += ptr16[2];
-	ip_cksum += ptr16[3];
-	ip_cksum += ptr16[4];
-	ip_cksum += ptr16[6];
-	ip_cksum += ptr16[7];
-	ip_cksum += ptr16[8];
-	ip_cksum += ptr16[9];
-
-	/*
-	 * Reduce 32 bit checksum to 16 bits and complement it.
-	 */
-	ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) + (ip_cksum & 0x0000FFFF);
-	if (ip_cksum > 65535)
-		ip_cksum -= 65535;
-	ip_cksum = (~ip_cksum) & 0x0000FFFF;
-	if (ip_cksum == 0)
-		ip_cksum = 0xFFFF;
-	ip_hdr->hdr_checksum = (uint16_t)ip_cksum;
+	ip_hdr->hdr_checksum = rte_ipv4_cksum_simple(ip_hdr);
 }
 
 static void
app/test-pmd/icmpecho.c +1 -22
index 68524484e3..754a3bc758 100644
@@ -241,27 +241,6 @@ ipv4_addr_dump(const char *what, uint32_t be_ipv4_addr)
 	printf("%s", buf);
 }
 
-static uint16_t
-ipv4_hdr_cksum(struct rte_ipv4_hdr *ip_h)
-{
-	uint16_t *v16_h;
-	uint32_t ip_cksum;
-
-	/*
-	 * Compute the sum of successive 16-bit words of the IPv4 header,
-	 * skipping the checksum field of the header.
-	 */
-	v16_h = (unaligned_uint16_t *) ip_h;
-	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
-		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
-
-	/* reduce 32 bit checksum to 16 bits and complement it */
-	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
-	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
-	ip_cksum = (~ip_cksum) & 0x0000FFFF;
-	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;
-}
-
 #define is_multicast_ipv4_addr(ipv4_addr) \
 	(((rte_be_to_cpu_32((ipv4_addr)) >> 24) & 0x000000FF) == 0xE0)
 
@@ -458,7 +437,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 				ip_src = (ip_src & 0xFFFFFFFC) | 0x00000001;
 			ip_h->src_addr = rte_cpu_to_be_32(ip_src);
 			ip_h->dst_addr = ip_addr;
-			ip_h->hdr_checksum = ipv4_hdr_cksum(ip_h);
+			ip_h->hdr_checksum = rte_ipv4_cksum_simple(ip_h);
 		} else {
 			ip_h->src_addr = ip_h->dst_addr;
 			ip_h->dst_addr = ip_addr;
app/test-pmd/txonly.c +1 -21
index c2b88764be..59d821a22d 100644
@@ -106,8 +106,6 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 			 struct rte_udp_hdr *udp_hdr,
 			 uint16_t pkt_data_len)
 {
-	uint16_t *ptr16;
-	uint32_t ip_cksum;
 	uint16_t pkt_len;
 
 	/*
@@ -136,25 +134,7 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 	/*
 	 * Compute IP header checksum.
 	 */
-	ptr16 = (unaligned_uint16_t*) ip_hdr;
-	ip_cksum = 0;
-	ip_cksum += ptr16[0]; ip_cksum += ptr16[1];
-	ip_cksum += ptr16[2]; ip_cksum += ptr16[3];
-	ip_cksum += ptr16[4];
-	ip_cksum += ptr16[6]; ip_cksum += ptr16[7];
-	ip_cksum += ptr16[8]; ip_cksum += ptr16[9];
-
-	/*
-	 * Reduce 32 bit checksum to 16 bits and complement it.
-	 */
-	ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) +
-		(ip_cksum & 0x0000FFFF);
-	if (ip_cksum > 65535)
-		ip_cksum -= 65535;
-	ip_cksum = (~ip_cksum) & 0x0000FFFF;
-	if (ip_cksum == 0)
-		ip_cksum = 0xFFFF;
-	ip_hdr->hdr_checksum = (uint16_t) ip_cksum;
+	ip_hdr->hdr_checksum = rte_ipv4_cksum_simple(ip_hdr);
 }
 
 static inline void
app/test/packet_burst_generator.c +2 -47

73 lines not on this page · raw message

app/test/test_reassembly_perf.c +1 -28
index 3912179022..32fee984a0 100644
@@ -136,9 +136,7 @@ ipv4_frag_fill_data(struct rte_mbuf **mbuf, uint8_t nb_frags, uint32_t flow_id,
 	for (i = 0; i < nb_frags; i++) {
 		struct rte_mbuf *frag = mbuf[i];
 		uint16_t frag_offset = 0;
-		uint32_t ip_cksum;
 		uint16_t pkt_len;
-		uint16_t *ptr16;
 
 		frag_offset = i * (frag_len / 8);
 
@@ -189,32 +187,7 @@ ipv4_frag_fill_data(struct rte_mbuf **mbuf, uint8_t nb_frags, uint32_t flow_id,
 		ip_hdr->src_addr = rte_cpu_to_be_32(IP_SRC_ADDR(flow_id));
 		ip_hdr->dst_addr = rte_cpu_to_be_32(IP_DST_ADDR(flow_id));
 
-		/*
-		 * Compute IP header checksum.
-		 */
-		ptr16 = (unaligned_uint16_t *)ip_hdr;
-		ip_cksum = 0;
-		ip_cksum += ptr16[0];
-		ip_cksum += ptr16[1];
-		ip_cksum += ptr16[2];
-		ip_cksum += ptr16[3];
-		ip_cksum += ptr16[4];
-		ip_cksum += ptr16[6];
-		ip_cksum += ptr16[7];
-		ip_cksum += ptr16[8];
-		ip_cksum += ptr16[9];
-
-		/*
-		 * Reduce 32 bit checksum to 16 bits and complement it.
-		 */
-		ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) +
-			   (ip_cksum & 0x0000FFFF);
-		if (ip_cksum > 65535)
-			ip_cksum -= 65535;
-		ip_cksum = (~ip_cksum) & 0x0000FFFF;
-		if (ip_cksum == 0)
-			ip_cksum = 0xFFFF;
-		ip_hdr->hdr_checksum = (uint16_t)ip_cksum;
+		ip_hdr->hdr_checksum = (uint16_t)rte_ipv4_cksum_simple(ip_hdr);
 
 		frag->data_len = sizeof(struct rte_ether_hdr) + pkt_len;
 		frag->pkt_len = frag->data_len;
lib/net/rte_ip.h +33 -0
index 0d103d4127..9980be8a2d 100644
@@ -309,6 +309,39 @@ rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
 	return (uint16_t)~cksum;
 }
 
+/**
+ * Process the IPv4 checksum of an IPv4 header without any extensions.
+ *
+ * The checksum field does NOT have to be set by the caller, the field
+ * is skipped by the calculation.
+ *
+ * @param ipv4_hdr
+ *   The pointer to the contiguous IPv4 header.
+ * @return
+ *   The complemented checksum to set in the IP packet.
+ */
+__rte_experimental
+static inline uint16_t
+rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
+{
+	const uint16_t *v16_h;
+	uint32_t ip_cksum;
+
+	/*
+	 * Compute the sum of successive 16-bit words of the IPv4 header,
+	 * skipping the checksum field of the header.
+	 */
+	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
+		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
+
+	/* reduce 32 bit checksum to 16 bits and complement it */
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (~ip_cksum) & 0x0000FFFF;
+	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;
+}
+
 /**
  * Process the pseudo-header checksum of an IPv4 header.
  *
Signature · 1 line
2.43.0
Acked-by on v1 5/6
#13 lore raw

Re: [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 12 lines · On Thu, 17 Oct 2024 15:22:12 +0100 Bruce Richardson…

There are multiple instances in the DPDK app folder where we set up an IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than necessary here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Quoted 5 lines

Within that new function, we can adjust slightly how the typecasting to uint16_t is done, and thereby ensure that the app can all be compiled without -Wno-address-of-packed-member compiler flag.

DPDK should use the same optimization as FreeBSD and Linux and use 32 bit add's here.

#14 lore raw

Re: [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 15 lines · Stephen Hemminger
Quoted 12 lines · On Thu, 17 Oct 2024 15:22:12 +0100 Bruce Richardson…

There are multiple instances in the DPDK app folder where we set up an IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than necessary here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Quoted 9 lines
Quoted 5 lines

Within that new function, we can adjust slightly how the typecasting to uint16_t is done, and thereby ensure that the app can all be compiled without -Wno-address-of-packed-member compiler flag.

DPDK should use the same optimization as FreeBSD and Linux and use 32 bit add's here.

Yep. And if we get this patch applied, there is only one place to optimize, not a dozen! :-)

Acked-by on v1 5/6
#15 lore raw

RE: [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases

In reply to Bruce Richardson
Quoted 21 lines
lib/net/rte_ip.h +21 -0
+/**
+ * Process the IPv4 checksum of an IPv4 header without any extensions.
+ *
+ * The checksum field does NOT have to be set by the caller, the field
+ * is skipped by the calculation.
+ *
+ * @param ipv4_hdr
+ *   The pointer to the contiguous IPv4 header.
+ * @return
+ *   The complemented checksum to set in the IP packet.
+ */
+__rte_experimental
+static inline uint16_t
+rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
+{
+	const uint16_t *v16_h;
+	uint32_t ip_cksum;
+
+	/*
+	 * Compute the sum of successive 16-bit words of the IPv4 header,
+	 * skipping the checksum field of the header.

lib/net/rte_ip.h rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr) · line 342

Quoted 10 lines
lib/net/rte_ip.h +10 -0
+	 */
+	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
+		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
+
+	/* reduce 32 bit checksum to 16 bits and complement it */
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (~ip_cksum) & 0x0000FFFF;
+	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;

The zero exception does not apply to the checksum stored in the IP header, only to the checksum in the UDP header.

Quoted 1 line

+}

Besides that, for the series,

#16 lore raw

Re: [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 25 lines · Morten Brørup
Quoted 25 lines
lib/net/rte_ip.h +25 -0
+/**
+ * Process the IPv4 checksum of an IPv4 header without any extensions.
+ *
+ * The checksum field does NOT have to be set by the caller, the field
+ * is skipped by the calculation.
+ *
+ * @param ipv4_hdr
+ *   The pointer to the contiguous IPv4 header.
+ * @return
+ *   The complemented checksum to set in the IP packet.
+ */
+__rte_experimental
+static inline uint16_t
+rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
+{
+	const uint16_t *v16_h;
+	uint32_t ip_cksum;
+
+	/*
+	 * Compute the sum of successive 16-bit words of the IPv4 header,
+	 * skipping the checksum field of the header.
+	 */
+	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
+		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
Quoted 9 lines

lib/net/rte_ip.h rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr) · line 342

Quoted 6 lines
lib/net/rte_ip.h +6 -0
+
+	/* reduce 32 bit checksum to 16 bits and complement it */
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (~ip_cksum) & 0x0000FFFF;
+	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;

The zero exception does not apply to the checksum stored in the IP header, only to the checksum in the UDP header.

I was wondering about that, because I didn't see it mentioned anywhere in the RFCs I consulted, but on the other hand all the implementations in the code seemed to have the check for zero.

Quoted 3 lines
Quoted 1 line

+}

Besides that, for the series,

So, just to confirm, the zero check at the end of the new ip_cksum_simple function should be removed and we always return the computed value directly?

Quoted 2 lines
#17 lore raw

Re: [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 40 lines · On Thu, 17 Oct 2024 20:03:13 +0100 Bruce Richardson…
Quoted 25 lines · Morten Brørup
Quoted 25 lines
lib/net/rte_ip.h +25 -0
+/**
+ * Process the IPv4 checksum of an IPv4 header without any extensions.
+ *
+ * The checksum field does NOT have to be set by the caller, the field
+ * is skipped by the calculation.
+ *
+ * @param ipv4_hdr
+ *   The pointer to the contiguous IPv4 header.
+ * @return
+ *   The complemented checksum to set in the IP packet.
+ */
+__rte_experimental
+static inline uint16_t
+rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
+{
+	const uint16_t *v16_h;
+	uint32_t ip_cksum;
+
+	/*
+	 * Compute the sum of successive 16-bit words of the IPv4 header,
+	 * skipping the checksum field of the header.
+	 */
+	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
+		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
Quoted 9 lines

lib/net/rte_ip.h rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr) · line 342

Quoted 6 lines
lib/net/rte_ip.h +6 -0
+
+	/* reduce 32 bit checksum to 16 bits and complement it */
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (~ip_cksum) & 0x0000FFFF;
+	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;  

The zero exception does not apply to the checksum stored in the IP header, only to the checksum in the UDP header.

I was wondering about that, because I didn't see it mentioned anywhere in the RFCs I consulted, but on the other hand all the implementations in the code seemed to have the check for zero.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+}

Besides that, for the series,

So, just to confirm, the zero check at the end of the new ip_cksum_simple function should be removed and we always return the computed value directly?

Depends on usage.
- if the computed value is zero, then 0xffff should be placed in the IP header.
- often code use ip checksum code to see if incoming checksum is good. in that case zero means the checksum is valid.

#18 lore raw

RE: [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 43 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Thursday, 17 October 2024 21.35

Quoted 3 lines · On Thu, 17 Oct 2024 20:03:13 +0100 Bruce Richardson…
Quoted 2 lines · Morten Brørup
Quoted 2 lines

+/**
+ * Process the IPv4 checksum of an IPv4 header without any

extensions.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+ *
+ * The checksum field does NOT have to be set by the caller, the

field

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+ * is skipped by the calculation.
+ *
+ * @param ipv4_hdr
+ * The pointer to the contiguous IPv4 header.
+ * @return
+ * The complemented checksum to set in the IP packet.
+ */
+__rte_experimental

Quoted 8 lines
Quoted 8 lines

lib/net/rte_ip.h rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)

Quoted 8 lines
lib/net/rte_ip.h +8 -0
+static inline uint16_t
+rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
+{
+	const uint16_t *v16_h;
+	uint32_t ip_cksum;
+
+	/*
+	 * Compute the sum of successive 16-bit words of the IPv4

header,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
lib/net/rte_ip.h +5 -0
+	 * skipping the checksum field of the header.
+	 */
+	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
+		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
Quoted 8 lines
Quoted 8 lines

lib/net/rte_ip.h rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr) · line 342

Quoted 6 lines
lib/net/rte_ip.h +6 -0
+
+	/* reduce 32 bit checksum to 16 bits and complement it */
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (~ip_cksum) & 0x0000FFFF;
+	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;

The zero exception does not apply to the checksum stored in the IP

Quoted 8 lines

header, only to the checksum in the UDP header.

Quoted 3 lines
Quoted 1 line

I was wondering about that, because I didn't see it mentioned

anywhere in

Quoted 1 line

the RFCs I consulted, but on the other hand all the implementations

in the

Quoted 1 line

code seemed to have the check for zero.

Copy-pasted including the bug from the originating code.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

+}

Besides that, for the series,

So, just to confirm, the zero check at the end of the new

ip_cksum_simple

Quoted 2 lines

function should be removed and we always return the computed value directly?

Agree.

Quoted 4 lines

Depends on usage.
- if the computed value is zero, then 0xffff should be placed in the IP header.

Not for the IP header, no.
For the UDP header, yes.

The Linux kernel doesn't do it to the IP header:
https://elixir.bootlin.com/linux/v6.12-rc3/source/net/ipv4/ip_output.c#L96
https://elixir.bootlin.com/linux/v6.12-rc3/source/lib/checksum.c#L108

Quoted 3 lines

- often code use ip checksum code to see if incoming checksum is
good.
in that case zero means the checksum is valid.

I don't remember all the details, but when checking the checksum, there's something about adding 0xffff or 0x0000 yields the same result. E.g.

1 + 0xffff = 0x10000, and then 0x1 + 0x0000 = 0x0001. 1 + 0x0000 = 0x0001.

So, when checking, it doesn't matter if the header checksum field is 0xffff or 0x0000.

There are other rules for the UDP header's checksum field, because 0x0000 there has the special meaning that the UDP checksum is not present/valid. (And AFAIR, not for IPv6, because the checksum is not optional for IPv6 UDP packets.)

The above calculation is also the reason why it is safe to substitute 0x0000 by 0xffff in the UDP header; it will still yield the same result when checking the checksum.

#19 lore raw

PATCH 6/6 build: limit scope of packed member warning disabling

In reply to Bruce Richardson

The flag '-Wno-address-of-packed-member' is a global warning flag in DPDK. Rather than disabling this warning globally, it is better to just have it enabled for components that may need it. This patch limits the scope of it in the following ways:

* limit the use of the flag to the drivers subfolder only - all libs and apps should be buildable without the warning.
* exception is made for the vhost library and the ipsec-secgw example for now, as making them buildable with the warning enabled is more complicated. This exception can hopefully be removed in future.

Limiting the scope further within the drivers directory is also left for future consideration. However, since HW drivers often have to use packed structures to align with hardware-implemented data layouts, it may be more practical to keep the warning disabled in the longer term.

---
 config/meson.build               | 1 -
 drivers/meson.build              | 9 ++++++---
 examples/ipsec-secgw/meson.build | 6 ++++++
 lib/vhost/meson.build            | 5 ++++-
 4 files changed, 16 insertions(+), 5 deletions(-)
config/meson.build +0 -1
index 6a6b56a27e..8b1a0fe779 100644
@@ -325,7 +325,6 @@ warning_flags = [
         '-Wwrite-strings',
 
         # globally disabled warnings
-        '-Wno-address-of-packed-member',
         '-Wno-packed-not-aligned',
         '-Wno-missing-field-initializers',
 ]
drivers/meson.build +6 -3
index 2733306698..1653990f3b 100644
@@ -59,9 +59,12 @@ default_cflags = machine_args
 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
 default_cflags += ['-DALLOW_INTERNAL_API']
 
-if cc.has_argument('-Wno-format-truncation')
-    default_cflags += '-Wno-format-truncation'
-endif
+warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member']
+foreach cflag:warning_disable_cflags
+    if cc.has_argument(cflag)
+        default_cflags += cflag
+    endif
+endforeach
 
 dpdk_drivers_build_dir = meson.current_build_dir()
 
examples/ipsec-secgw/meson.build +6 -0
index ccdaef1c4d..023d9cf039 100644
@@ -23,3 +23,9 @@ sources = files(
         'sp4.c',
         'sp6.c',
 )
+app_cflags = ['-Wno-address-of-packed-member']
+foreach flag:app_cflags
+    if cc.has_argument(flag)
+        cflags += flag
+    endif
+endforeach
lib/vhost/meson.build +4 -1
index 41b622a9be..51bcf17244 100644
@@ -16,7 +16,10 @@ elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0'))
     cflags += '-DVHOST_ICC_UNROLL_PRAGMA'
 endif
 dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
-cflags += '-fno-strict-aliasing'
+cflags += [
+        '-fno-strict-aliasing',
+        '-Wno-address-of-packed-member',
+]
 
 sources = files(
         'fd_man.c',
Signature · 1 line
2.43.0
Acked-by on v1 6/6
#20 lore raw

Re: [PATCH 6/6] build: limit scope of packed member warning disabling

Quoted 16 lines · On Thu, 17 Oct 2024 15:22:13 +0100 Bruce Richardson…

The flag '-Wno-address-of-packed-member' is a global warning flag in DPDK. Rather than disabling this warning globally, it is better to just have it enabled for components that may need it. This patch limits the scope of it in the following ways:

* limit the use of the flag to the drivers subfolder only - all libs and apps should be buildable without the warning.
* exception is made for the vhost library and the ipsec-secgw example for now, as making them buildable with the warning enabled is more complicated. This exception can hopefully be removed in future.

Limiting the scope further within the drivers directory is also left for future consideration. However, since HW drivers often have to use packed structures to align with hardware-implemented data layouts, it may be more practical to keep the warning disabled in the longer term.

Quoted 7 lines
---
 config/meson.build               | 1 -
 drivers/meson.build              | 9 ++++++---
 examples/ipsec-secgw/meson.build | 6 ++++++
 lib/vhost/meson.build            | 5 ++++-
 4 files changed, 16 insertions(+), 5 deletions(-)

Good first step, followups can fix ipsec and vhost later.

#21 lore raw
In reply to Bruce Richardson
Quoted 19 lines · On Thu, 17 Oct 2024 15:22:07 +0100 Bruce Richardson…

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

Quoted 15 lines
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 60 insertions(+), 154 deletions(-)

Any chance to just fix all the places and have it enabled globally?

#22 lore raw
Quoted 39 lines · Stephen Hemminger
Quoted 19 lines · On Thu, 17 Oct 2024 15:22:07 +0100 Bruce Richardson…

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

Quoted 15 lines
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 60 insertions(+), 154 deletions(-)
Quoted 1 line

Any chance to just fix all the places and have it enabled globally?

Not any time soon (at least for me). There are a huge number of drivers with lots of errors if we turn back on the warning. We should look at all our common structures first to ensure none of them are unnecessarily packed.

/Bruce

#23 lore raw
In reply to Bruce Richardson
Quoted 20 lines · Bruce Richardson

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

Quoted 15 lines
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 60 insertions(+), 154 deletions(-)

Recheck-request: rebase=main,iol-unit-amd64-testing,iol-unit-arm64-testing

Signature · 1 line
David Marchand
#24 lore raw
Quoted 39 lines · David Marchand
Quoted 20 lines · Bruce Richardson

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

Quoted 15 lines
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 60 insertions(+), 154 deletions(-)
Quoted 1 line

Recheck-request: rebase=main,iol-unit-amd64-testing,iol-unit-arm64-testing

Unfortunately, there is a small conflict and the CI can't retest this series. Bruce, can you send a v2 please?

Signature · 1 line
David Marchand
#25 lore raw
Quoted 41 lines · David Marchand
Quoted 39 lines · David Marchand
Quoted 35 lines · Bruce Richardson

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip.h                         | 33 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 60 insertions(+), 154 deletions(-)
Quoted 5 lines
Quoted 1 line

Recheck-request: rebase=main,iol-unit-amd64-testing,iol-unit-arm64-testing

Unfortunately, there is a small conflict and the CI can't retest this series. Bruce, can you send a v2 please?

Done. V2 is rebased and also includes the checksum calc adjustment reported by Morten.

/Bruce

#26 lore raw

v2 cover Reduce scope address-of-packed-member warning

In reply to Bruce Richardson

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

v2:
* rebase on latest main (rte_ip.h -> rte_ip4.h)
* remove unnecessary 0-check in IP checksum calc

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip4.h                        | 32 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 59 insertions(+), 154 deletions(-)

--
2.43.0

#27 lore raw

PATCH v2 1/6 ip_frag: remove use of unaligned variable

If compiling with -Waddress-of-packed-member, we get a warning about the use of the unaligned uint64_t value which is used to copy 8 bytes from ip_hdr to the key. Replace this unaligned assignment with an equivalent 8-byte constant-sized memcpy, allowing the compiler to choose optimal instructions to do the assignment.

---
 lib/ip_frag/rte_ipv4_reassembly.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
lib/ip_frag/rte_ipv4_reassembly.c +1 -3
index 4a89a5f536..5818f50f40 100644
@@ -101,7 +101,6 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
 {
 	struct ip_frag_pkt *fp;
 	struct ip_frag_key key;
-	const unaligned_uint64_t *psd;
 	uint16_t flag_offset, ip_ofs, ip_flag;
 	int32_t ip_len;
 	int32_t trim;
@@ -110,9 +109,8 @@ rte_ipv4_frag_reassemble_packet(struct rte_ip_frag_tbl *tbl,
 	ip_ofs = (uint16_t)(flag_offset & RTE_IPV4_HDR_OFFSET_MASK);
 	ip_flag = (uint16_t)(flag_offset & RTE_IPV4_HDR_MF_FLAG);
 
-	psd = (unaligned_uint64_t *)&ip_hdr->src_addr;
 	/* use first 8 bytes only */
-	key.src_dst[0] = psd[0];
+	memcpy(&key.src_dst[0], &ip_hdr->src_addr, 8);
 	key.id = ip_hdr->packet_id;
 	key.key_len = IPV4_KEYLEN;
 
Signature · 1 line
2.43.0
#28 lore raw

PATCH v2 2/6 efd: remove unnecessary packed attributes

In reply to Bruce Richardson

The structure "efd_online_group_entry" only consists of values which are typedefs of "uint16_t", so packing the structure has no effect. The "efd_online_chunk" structure has a mix of "uint8_t" and the "efd_online_group_entry" struct, i.e. uint16_t values, but since the first, uint8_t, member array is of even size, the packed attribute does not affect the structure layout.

Removing these packed attributes allows the library to compile cleanly without "-Wno-address-of-packed-member" compiler flag.

---
 lib/efd/rte_efd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/efd/rte_efd.c +2 -2
index d3b732f2e8..3cbb3c2719 100644
@@ -212,7 +212,7 @@ struct efd_offline_chunk_rules {
 struct efd_online_group_entry {
 	efd_hashfunc_t hash_idx[RTE_EFD_VALUE_NUM_BITS];
 	efd_lookuptbl_t lookup_table[RTE_EFD_VALUE_NUM_BITS];
-} __rte_packed;
+};
 
 /**
  * A single chunk record, containing EFD_TARGET_CHUNK_NUM_RULES rules.
@@ -228,7 +228,7 @@ struct efd_online_chunk {
 
 	struct efd_online_group_entry groups[EFD_CHUNK_NUM_GROUPS];
 	/**< Array of all the groups in the chunk. */
-} __rte_packed;
+};
 
 /**
  * EFD table structure
Signature · 1 line
2.43.0
#29 lore raw

PATCH v2 3/6 bus/ifpga: remove packed attribute

In reply to Bruce Richardson

The struct rte_afu_device does not need to be packed, so remove the packed attribute from it.

---
 drivers/bus/ifpga/bus_ifpga_driver.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/bus/ifpga/bus_ifpga_driver.h +1 -1
index a42afc7d75..af151ffd4b 100644
@@ -77,7 +77,7 @@ struct rte_afu_device {
 	struct rte_intr_handle *intr_handle;     /**< Interrupt handle */
 	struct rte_afu_driver *driver;          /**< Associated driver */
 	char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
-} __rte_packed;
+};
 
 /**
  * @internal
Signature · 1 line
2.43.0
#30 lore raw

PATCH v2 4/6 pipeline: remove packed attribute

In reply to Bruce Richardson

The rte_trtcm_data structure, and its substructures, only consist of uint64_t types. This makes packing unnecessary to remove the packed attribute from the structure.

---
 lib/pipeline/rte_table_action.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/pipeline/rte_table_action.c +1 -1
index a7e63b9846..a431f8f128 100644
@@ -109,7 +109,7 @@ mtr_cfg_check(struct rte_table_action_mtr_config *mtr)
 struct mtr_trtcm_data {
 	struct rte_meter_trtcm trtcm;
 	uint64_t stats[RTE_COLORS];
-} __rte_packed;
+};
 
 #define MTR_TRTCM_DATA_METER_PROFILE_ID_GET(data)          \
 	(((data)->stats[RTE_COLOR_GREEN] & 0xF8LLU) >> 3)
Signature · 1 line
2.43.0
#31 lore raw

PATCH v2 5/6 net: add smaller IPv4 cksum function for simple cases

In reply to Bruce Richardson

There are multiple instances in the DPDK app folder where we set up an IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than necessary here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Within that new function, we can adjust slightly how the typecasting to uint16_t is done, and thereby ensure that the app can all be compiled without -Wno-address-of-packed-member compiler flag.

---
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 lib/net/rte_ip4.h                        | 32 ++++++++++++++++
 6 files changed, 38 insertions(+), 142 deletions(-)
app/test-eventdev/test_pipeline_common.c +1 -24
index b111690b7c..204117ef7f 100644
@@ -74,8 +74,6 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 			 struct rte_udp_hdr *udp_hdr, uint16_t pkt_data_len,
 			 uint8_t port, uint8_t flow)
 {
-	uint16_t *ptr16;
-	uint32_t ip_cksum;
 	uint16_t pkt_len;
 
 	/*
@@ -104,28 +102,7 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 	/*
 	 * Compute IP header checksum.
 	 */
-	ptr16 = (unaligned_uint16_t *)ip_hdr;
-	ip_cksum = 0;
-	ip_cksum += ptr16[0];
-	ip_cksum += ptr16[1];
-	ip_cksum += ptr16[2];
-	ip_cksum += ptr16[3];
-	ip_cksum += ptr16[4];
-	ip_cksum += ptr16[6];
-	ip_cksum += ptr16[7];
-	ip_cksum += ptr16[8];
-	ip_cksum += ptr16[9];
-
-	/*
-	 * Reduce 32 bit checksum to 16 bits and complement it.
-	 */
-	ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) + (ip_cksum & 0x0000FFFF);
-	if (ip_cksum > 65535)
-		ip_cksum -= 65535;
-	ip_cksum = (~ip_cksum) & 0x0000FFFF;
-	if (ip_cksum == 0)
-		ip_cksum = 0xFFFF;
-	ip_hdr->hdr_checksum = (uint16_t)ip_cksum;
+	ip_hdr->hdr_checksum = rte_ipv4_cksum_simple(ip_hdr);
 }
 
 static void
app/test-pmd/icmpecho.c +1 -22
index 4ef23ae67a..c87b7a80df 100644
@@ -241,27 +241,6 @@ ipv4_addr_dump(const char *what, uint32_t be_ipv4_addr)
 	printf("%s", buf);
 }
 
-static uint16_t
-ipv4_hdr_cksum(struct rte_ipv4_hdr *ip_h)
-{
-	uint16_t *v16_h;
-	uint32_t ip_cksum;
-
-	/*
-	 * Compute the sum of successive 16-bit words of the IPv4 header,
-	 * skipping the checksum field of the header.
-	 */
-	v16_h = (unaligned_uint16_t *) ip_h;
-	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
-		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
-
-	/* reduce 32 bit checksum to 16 bits and complement it */
-	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
-	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
-	ip_cksum = (~ip_cksum) & 0x0000FFFF;
-	return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;
-}
-
 #define is_multicast_ipv4_addr(ipv4_addr) \
 	(((rte_be_to_cpu_32((ipv4_addr)) >> 24) & 0x000000FF) == 0xE0)
 
@@ -458,7 +437,7 @@ reply_to_icmp_echo_rqsts(struct fwd_stream *fs)
 				ip_src = (ip_src & 0xFFFFFFFC) | 0x00000001;
 			ip_h->src_addr = rte_cpu_to_be_32(ip_src);
 			ip_h->dst_addr = ip_addr;
-			ip_h->hdr_checksum = ipv4_hdr_cksum(ip_h);
+			ip_h->hdr_checksum = rte_ipv4_cksum_simple(ip_h);
 		} else {
 			ip_h->src_addr = ip_h->dst_addr;
 			ip_h->dst_addr = ip_addr;
app/test-pmd/txonly.c +1 -21
index c2b88764be..59d821a22d 100644
@@ -106,8 +106,6 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 			 struct rte_udp_hdr *udp_hdr,
 			 uint16_t pkt_data_len)
 {
-	uint16_t *ptr16;
-	uint32_t ip_cksum;
 	uint16_t pkt_len;
 
 	/*
@@ -136,25 +134,7 @@ setup_pkt_udp_ip_headers(struct rte_ipv4_hdr *ip_hdr,
 	/*
 	 * Compute IP header checksum.
 	 */
-	ptr16 = (unaligned_uint16_t*) ip_hdr;
-	ip_cksum = 0;
-	ip_cksum += ptr16[0]; ip_cksum += ptr16[1];
-	ip_cksum += ptr16[2]; ip_cksum += ptr16[3];
-	ip_cksum += ptr16[4];
-	ip_cksum += ptr16[6]; ip_cksum += ptr16[7];
-	ip_cksum += ptr16[8]; ip_cksum += ptr16[9];
-
-	/*
-	 * Reduce 32 bit checksum to 16 bits and complement it.
-	 */
-	ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) +
-		(ip_cksum & 0x0000FFFF);
-	if (ip_cksum > 65535)
-		ip_cksum -= 65535;
-	ip_cksum = (~ip_cksum) & 0x0000FFFF;
-	if (ip_cksum == 0)
-		ip_cksum = 0xFFFF;
-	ip_hdr->hdr_checksum = (uint16_t) ip_cksum;
+	ip_hdr->hdr_checksum = rte_ipv4_cksum_simple(ip_hdr);
 }
 
 static inline void
app/test/packet_burst_generator.c +2 -47

73 lines not on this page · raw message

app/test/test_reassembly_perf.c +1 -28
index 245ab3fa7d..69cf029468 100644
@@ -136,9 +136,7 @@ ipv4_frag_fill_data(struct rte_mbuf **mbuf, uint8_t nb_frags, uint32_t flow_id,
 	for (i = 0; i < nb_frags; i++) {
 		struct rte_mbuf *frag = mbuf[i];
 		uint16_t frag_offset = 0;
-		uint32_t ip_cksum;
 		uint16_t pkt_len;
-		uint16_t *ptr16;
 
 		frag_offset = i * (frag_len / 8);
 
@@ -189,32 +187,7 @@ ipv4_frag_fill_data(struct rte_mbuf **mbuf, uint8_t nb_frags, uint32_t flow_id,
 		ip_hdr->src_addr = rte_cpu_to_be_32(IP_SRC_ADDR(flow_id));
 		ip_hdr->dst_addr = rte_cpu_to_be_32(IP_DST_ADDR(flow_id));
 
-		/*
-		 * Compute IP header checksum.
-		 */
-		ptr16 = (unaligned_uint16_t *)ip_hdr;
-		ip_cksum = 0;
-		ip_cksum += ptr16[0];
-		ip_cksum += ptr16[1];
-		ip_cksum += ptr16[2];
-		ip_cksum += ptr16[3];
-		ip_cksum += ptr16[4];
-		ip_cksum += ptr16[6];
-		ip_cksum += ptr16[7];
-		ip_cksum += ptr16[8];
-		ip_cksum += ptr16[9];
-
-		/*
-		 * Reduce 32 bit checksum to 16 bits and complement it.
-		 */
-		ip_cksum = ((ip_cksum & 0xFFFF0000) >> 16) +
-			   (ip_cksum & 0x0000FFFF);
-		if (ip_cksum > 65535)
-			ip_cksum -= 65535;
-		ip_cksum = (~ip_cksum) & 0x0000FFFF;
-		if (ip_cksum == 0)
-			ip_cksum = 0xFFFF;
-		ip_hdr->hdr_checksum = (uint16_t)ip_cksum;
+		ip_hdr->hdr_checksum = (uint16_t)rte_ipv4_cksum_simple(ip_hdr);
 
 		frag->data_len = sizeof(struct rte_ether_hdr) + pkt_len;
 		frag->pkt_len = frag->data_len;
lib/net/rte_ip4.h +32 -0
index d9840b3cff..3dc0c5a017 100644
@@ -163,6 +163,38 @@ rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
 	return (uint16_t)~cksum;
 }
 
+/**
+ * Process the IPv4 checksum of an IPv4 header without any extensions.
+ *
+ * The checksum field does NOT have to be set by the caller, the field
+ * is skipped by the calculation.
+ *
+ * @param ipv4_hdr
+ *   The pointer to the contiguous IPv4 header.
+ * @return
+ *   The complemented checksum to set in the IP packet.
+ */
+__rte_experimental
+static inline uint16_t
+rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
+{
+	const uint16_t *v16_h;
+	uint32_t ip_cksum;
+
+	/*
+	 * Compute the sum of successive 16-bit words of the IPv4 header,
+	 * skipping the checksum field of the header.
+	 */
+	v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+	ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
+		v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
+
+	/* reduce 32 bit checksum to 16 bits and complement it */
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
+	return (uint16_t)(~ip_cksum);
+}
+
 /**
  * Process the pseudo-header checksum of an IPv4 header.
  *
Signature · 1 line
2.43.0
#32 lore raw

Re: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

Hello Bruce,

Quoted 13 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we set up an IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than necessary here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Quoted 7 lines

Within that new function, we can adjust slightly how the typecasting to uint16_t is done, and thereby ensure that the app can all be compiled without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -Wcast-align:
https://github.com/david-marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64 -target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1 -D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1 -DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter -Wbad-function-cast -Wcast-align -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool -Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare -Wshift-negative-value -Wduplicated-cond -Wshadow -Wmultistatement-macros -Wcast-align=strict -mssse3 -I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h -mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo -MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip.h:9, from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,
from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
cast increases required alignment of target type [-Werror=cast-align] 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^
cc1: all warnings being treated as errors
make[1]: *** [Makefile:4736: lib/ofp-packet.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
cc1: all warnings being treated as errors
make[1]: *** [Makefile:4736: lib/ofp-print.lo] Error 1
make[1]: Leaving directory '/home/runner/work/ovs/ovs'
make: *** [Makefile:3110: all] Error 2

Signature · 1 line
David Marchand
#33 lore raw

Re: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 49 lines · David Marchand

Hello Bruce,

Quoted 13 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we set up an IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than necessary here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Quoted 7 lines

Within that new function, we can adjust slightly how the typecasting to uint16_t is done, and thereby ensure that the app can all be compiled without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -Wcast-align:
https://github.com/david-marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64

(quoted diff) +0 -14
-target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
-D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
-DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
-Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
-Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
-Wshift-negative-value -Wduplicated-cond -Wshadow
-Wmultistatement-macros -Wcast-align=strict -mssse3
-I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h
-mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo
-MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o

lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip.h:9, from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,

Quoted 8 lines

from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
cast increases required alignment of target type [-Werror=cast-align] 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^

Ok, I'll see if I can rework it to avoid issues.

/Bruce

#34 lore raw

RE: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 68 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 30 October 2024 12.28

Quoted 6 lines · David Marchand

Hello Bruce,

Quoted 2 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we set up

an

Quoted 3 lines
Quoted 3 lines

IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than

necessary

Quoted 9 lines
Quoted 9 lines

here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Within that new function, we can adjust slightly how the

typecasting to

Quoted 1 line
Quoted 1 line

uint16_t is done, and thereby ensure that the app can all be

compiled

Quoted 7 lines
Quoted 5 lines

without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -

Wcast-align:

Quoted 1 line

https://github.com/david-

marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

Quoted 18 lines

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64

(quoted diff) +0 -14
-target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
-D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
-DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
-Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
-Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
-Wshift-negative-value -Wduplicated-cond -Wshadow
-Wmultistatement-macros -Wcast-align=strict -mssse3
-I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h
-mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo
-MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o
Quoted 2 lines

lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-

dir/include/rte_ip.h:9,

Quoted 10 lines

from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,
from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
cast increases required alignment of target type [-Werror=cast-align] 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^

Quoted 1 line

Ok, I'll see if I can rework it to avoid issues.

Would be easier if IP(v4/v6) headers were 2-byte aligned, like the Ethernet header. Just saying. ;-)

#35 lore raw

Re: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 68 lines · Morten Brørup
Quoted 68 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 30 October 2024 12.28

Quoted 6 lines · David Marchand

Hello Bruce,

Quoted 2 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we set up

an

Quoted 3 lines
Quoted 3 lines

IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than

necessary

Quoted 9 lines
Quoted 9 lines

here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Within that new function, we can adjust slightly how the

typecasting to

Quoted 1 line
Quoted 1 line

uint16_t is done, and thereby ensure that the app can all be

compiled

Quoted 7 lines
Quoted 5 lines

without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -

Wcast-align:

Quoted 1 line

https://github.com/david-

marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

Quoted 18 lines

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64

(quoted diff) +0 -14
-target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
-D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
-DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
-Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
-Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
-Wshift-negative-value -Wduplicated-cond -Wshadow
-Wmultistatement-macros -Wcast-align=strict -mssse3
-I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h
-mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo
-MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o
Quoted 2 lines

lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-

dir/include/rte_ip.h:9,

Quoted 10 lines

from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,
from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
cast increases required alignment of target type [-Werror=cast-align] 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^

Quoted 5 lines
Quoted 1 line

Ok, I'll see if I can rework it to avoid issues.

Would be easier if IP(v4/v6) headers were 2-byte aligned, like the Ethernet header. Just saying. ;-)

I agree. Would adding that alignment constraint cause us any issues, does anyone know?

/Bruce

#36 lore raw

RE: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 85 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 30 October 2024 13.28

Quoted 10 lines · Morten Brørup
Quoted 10 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 30 October 2024 12.28

Quoted 6 lines · David Marchand

Hello Bruce,

Quoted 2 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we

set up

Quoted 2 lines
Quoted 2 lines

an

Quoted 1 line
Quoted 1 line

IP header and then compute the checksum field by direct

addition of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

nine uint16_t values in the header (20 bytes less the cksum

field).

Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line

The existing rte_ip.h checksum function is more general than

necessary

Quoted 1 line
Quoted 1 line

here and requires that the checksum field is already set to

zero -

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the

existing

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

testpmd icmpecho.c file - and using that in app/test, testpmd

and

Quoted 17 lines
Quoted 17 lines
Quoted 3 lines
Quoted 3 lines

testeventdev.

Within that new function, we can adjust slightly how the

typecasting to

Quoted 1 line
Quoted 1 line

uint16_t is done, and thereby ensure that the app can all be

compiled

Quoted 7 lines
Quoted 5 lines

without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -

Wcast-align:

Quoted 1 line

https://github.com/david-

marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

Quoted 1 line
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64

(quoted diff) +0 -4
-target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
-D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
-DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
-Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-

arith

Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +0 -8
-Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
-Wshift-negative-value -Wduplicated-cond -Wshadow
-Wmultistatement-macros -Wcast-align=strict -mssse3
-I/home/runner/work/ovs/ovs/dpdk-dir/include -include

rte_config.h

Quoted 1 line
Quoted 1 line
Quoted 1 line

-mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-

protocol.lo

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines

-MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-

dir/include/rte_ip.h:9,

Quoted 7 lines

from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,
from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17:

error:

Quoted 1 line
Quoted 1 line
Quoted 1 line

cast increases required alignment of target type [-Werror=cast-

align]

Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^

Ok, I'll see if I can rework it to avoid issues.

Quoted 7 lines
Quoted 1 line

Would be easier if IP(v4/v6) headers were 2-byte aligned, like the

Ethernet header.

Quoted 2 lines

Just saying. ;-)

I agree. Would adding that alignment constraint cause us any issues, does
anyone know?

No issues according to the CI:
https://patchwork.dpdk.org/project/dpdk/patch/[email protected]/

The single failure is not related to the patch.

#37 lore raw

Re: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

In reply to Morten Brørup
Quoted 69 lines · Morten Brørup
Quoted 69 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 30 October 2024 12.28

Quoted 6 lines · David Marchand

Hello Bruce,

Quoted 2 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we set up

an

Quoted 3 lines
Quoted 3 lines

IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than

necessary

Quoted 9 lines
Quoted 9 lines

here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Within that new function, we can adjust slightly how the

typecasting to

Quoted 1 line
Quoted 1 line

uint16_t is done, and thereby ensure that the app can all be

compiled

Quoted 7 lines
Quoted 5 lines

without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -

Wcast-align:

Quoted 1 line

https://github.com/david-

marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

Quoted 18 lines

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64

(quoted diff) +0 -14
-target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
-D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
-DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
-Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
-Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
-Wshift-negative-value -Wduplicated-cond -Wshadow
-Wmultistatement-macros -Wcast-align=strict -mssse3
-I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h
-mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo
-MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o
Quoted 2 lines

lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-

dir/include/rte_ip.h:9,

Quoted 10 lines

from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,
from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
cast increases required alignment of target type [-Werror=cast-align] 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^

Quoted 4 lines
Quoted 1 line

Ok, I'll see if I can rework it to avoid issues.

Would be easier if IP(v4/v6) headers were 2-byte aligned, like the Ethernet header. Just saying. ;-)

Aligning rte_ipv4_hdr is not enough.
Pointing at a uint8_t triggers a warning (with clang at least).

I guess we need something like:

lib/net/rte_ip4.h +2 -2
index 4dd0058cc5..f9b8333332 100644
@@ -39,7 +39,7 @@ extern "C" {
 /**
  * IPv4 Header
  */
-struct rte_ipv4_hdr {
+struct __rte_aligned(2) rte_ipv4_hdr {
        __extension__
        union {
                uint8_t version_ihl;    /**< version and header length */
@@ -188,7 +188,7 @@ rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
         * Compute the sum of successive 16-bit words of the IPv4 header,
         * skipping the checksum field of the header.
         */
-       v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+       v16_h = (const uint16_t *)ipv4_hdr;
        ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
                v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
 
Signature · 1 line
David Marchand
#38 lore raw

Re: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases

Quoted 95 lines · David Marchand
Quoted 69 lines · Morten Brørup
Quoted 69 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Wednesday, 30 October 2024 12.28

Quoted 6 lines · David Marchand

Hello Bruce,

Quoted 2 lines · Bruce Richardson

There are multiple instances in the DPDK app folder where we set up

an

Quoted 3 lines
Quoted 3 lines

IP header and then compute the checksum field by direct addition of nine uint16_t values in the header (20 bytes less the cksum field). The existing rte_ip.h checksum function is more general than

necessary

Quoted 9 lines
Quoted 9 lines

here and requires that the checksum field is already set to zero - rather than having it skipped.

Fix the code duplication present in the apps by creating a new rte_ipv4_cksum_simple function - taking the code from the existing testpmd icmpecho.c file - and using that in app/test, testpmd and testeventdev.

Within that new function, we can adjust slightly how the

typecasting to

Quoted 1 line
Quoted 1 line

uint16_t is done, and thereby ensure that the app can all be

compiled

Quoted 7 lines
Quoted 5 lines

without -Wno-address-of-packed-member compiler flag.

This added function triggers a build error with OVS because of -

Wcast-align:

Quoted 1 line

https://github.com/david-

marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514

Quoted 18 lines

libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I ./include/sparse -I ./include -m64 -I /usr/local/include -I /usr/include/x86_64-linux-gnu " cgcc -target=x86_64

(quoted diff) +0 -14
-target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
-D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
-DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
-Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
-Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
-Wbad-function-cast -Wcast-align -Wstrict-prototypes
-Wold-style-definition -Wmissing-prototypes
-Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
-Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
-Wshift-negative-value -Wduplicated-cond -Wshadow
-Wmultistatement-macros -Wcast-align=strict -mssse3
-I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h
-mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo
-MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o
Quoted 2 lines

lib/ofp-protocol.o
In file included from /home/runner/work/ovs/ovs/dpdk-

dir/include/rte_ip.h:9,

Quoted 10 lines

from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25, from lib/netdev-dpdk.h:30,
from lib/dp-packet.h:30,
from lib/ofp-print.c:34:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function ‘rte_ipv4_cksum_simple’:
/home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
cast increases required alignment of target type [-Werror=cast-align] 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl; | ^

Quoted 4 lines
Quoted 1 line

Ok, I'll see if I can rework it to avoid issues.

Would be easier if IP(v4/v6) headers were 2-byte aligned, like the Ethernet header. Just saying. ;-)

Aligning rte_ipv4_hdr is not enough.
Pointing at a uint8_t triggers a warning (with clang at least).

I guess we need something like:

lib/net/rte_ip4.h +1 -1
index 4dd0058cc5..f9b8333332 100644
@@ -39,7 +39,7 @@ extern "C" {
 /**
  * IPv4 Header
  */
-struct rte_ipv4_hdr {
+struct __rte_aligned(2) rte_ipv4_hdr {
        __extension__
        union {
                uint8_t version_ihl;    /**< version and header length */

lib/net/rte_ip4.h rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr) · line 194

Quoted 8 lines
lib/net/rte_ip4.h +1 -1
@@ -188,7 +188,7 @@ rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
         * Compute the sum of successive 16-bit words of the IPv4 header,
         * skipping the checksum field of the header.
         */
-       v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
+       v16_h = (const uint16_t *)ipv4_hdr;
        ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
                v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
 

Yes.
For the latter assignment part, the original code use ipv4_hdr, but that triggered other warnings in DPDK build. With properly aligning the structure, I think it should be fine. Therefore, what you have above looks the best solution to me.

/Bruce

#39 lore raw

PATCH v2 6/6 build: limit scope of packed member warning disabling

In reply to Bruce Richardson

The flag '-Wno-address-of-packed-member' is a global warning flag in DPDK. Rather than disabling this warning globally, it is better to just have it enabled for components that may need it. This patch limits the scope of it in the following ways:

* limit the use of the flag to the drivers subfolder only - all libs and apps should be buildable without the warning.
* exception is made for the vhost library and the ipsec-secgw example for now, as making them buildable with the warning enabled is more complicated. This exception can hopefully be removed in future.

Limiting the scope further within the drivers directory is also left for future consideration. However, since HW drivers often have to use packed structures to align with hardware-implemented data layouts, it may be more practical to keep the warning disabled in the longer term.

---
 config/meson.build               | 1 -
 drivers/meson.build              | 9 ++++++---
 examples/ipsec-secgw/meson.build | 6 ++++++
 lib/vhost/meson.build            | 5 ++++-
 4 files changed, 16 insertions(+), 5 deletions(-)
config/meson.build +0 -1
index 8dae811378..5095d2fbcb 100644
@@ -325,7 +325,6 @@ warning_flags = [
         '-Wwrite-strings',
 
         # globally disabled warnings
-        '-Wno-address-of-packed-member',
         '-Wno-packed-not-aligned',
         '-Wno-missing-field-initializers',
 ]
drivers/meson.build +6 -3
index 5270160c56..4a27f197a8 100644
@@ -59,9 +59,12 @@ default_cflags = machine_args
 default_cflags += ['-DALLOW_EXPERIMENTAL_API']
 default_cflags += ['-DALLOW_INTERNAL_API']
 
-if cc.has_argument('-Wno-format-truncation')
-    default_cflags += '-Wno-format-truncation'
-endif
+warning_disable_cflags = ['-Wno-format-truncation', '-Wno-address-of-packed-member']
+foreach cflag:warning_disable_cflags
+    if cc.has_argument(cflag)
+        default_cflags += cflag
+    endif
+endforeach
 
 dpdk_drivers_build_dir = meson.current_build_dir()
 
examples/ipsec-secgw/meson.build +6 -0
index ccdaef1c4d..023d9cf039 100644
@@ -23,3 +23,9 @@ sources = files(
         'sp4.c',
         'sp6.c',
 )
+app_cflags = ['-Wno-address-of-packed-member']
+foreach flag:app_cflags
+    if cc.has_argument(flag)
+        cflags += flag
+    endif
+endforeach
lib/vhost/meson.build +4 -1
index 41b622a9be..51bcf17244 100644
@@ -16,7 +16,10 @@ elif (toolchain == 'icc' and cc.version().version_compare('>=16.0.0'))
     cflags += '-DVHOST_ICC_UNROLL_PRAGMA'
 endif
 dpdk_conf.set('RTE_LIBRTE_VHOST_POSTCOPY', cc.has_header('linux/userfaultfd.h'))
-cflags += '-fno-strict-aliasing'
+cflags += [
+        '-fno-strict-aliasing',
+        '-Wno-address-of-packed-member',
+]
 
 sources = files(
         'fd_man.c',
Signature · 1 line
2.43.0
#40 lore raw
In reply to Bruce Richardson

LGTM

Quoted 42 lines · Bruce Richardson

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

v2:
* rebase on latest main (rte_ip.h -> rte_ip4.h)
* remove unnecessary 0-check in IP checksum calc

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip4.h                        | 32 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 59 insertions(+), 154 deletions(-)

--
2.43.0

#41 lore raw
In reply to Bruce Richardson
Quoted 24 lines · Bruce Richardson

The warning for address-of-packed-member was being disabled globally in DPDK. While for drivers which need to access hardware-defined data-structures the use of packed may make sense, for normal libs and applications the use of packed data should be generally avoided.

This patchset initially applies some fixes for cases where we are unnecessarily causing the warning to trigger. Thereafter the 6th patch removes the global enabling of the warning and replaces it with more selective disabling for drivers and for a couple of other components which have not yet been fixed.

v2:
* rebase on latest main (rte_ip.h -> rte_ip4.h)
* remove unnecessary 0-check in IP checksum calc

Bruce Richardson (6):
ip_frag: remove use of unaligned variable
efd: remove unnecessary packed attributes bus/ifpga: remove packed attribute
pipeline: remove packed attribute
net: add smaller IPv4 cksum function for simple cases
build: limit scope of packed member warning disabling

Quoted 15 lines
 app/test-eventdev/test_pipeline_common.c | 25 +-----------
 app/test-pmd/icmpecho.c                  | 23 +----------
 app/test-pmd/txonly.c                    | 22 +----------
 app/test/packet_burst_generator.c        | 49 +-----------------------
 app/test/test_reassembly_perf.c          | 29 +-------------
 config/meson.build                       |  1 -
 drivers/bus/ifpga/bus_ifpga_driver.h     |  2 +-
 drivers/meson.build                      |  9 +++--
 examples/ipsec-secgw/meson.build         |  6 +++
 lib/efd/rte_efd.c                        |  4 +-
 lib/ip_frag/rte_ipv4_reassembly.c        |  4 +-
 lib/net/rte_ip4.h                        | 32 ++++++++++++++++
 lib/pipeline/rte_table_action.c          |  2 +-
 lib/vhost/meson.build                    |  5 ++-
 14 files changed, 59 insertions(+), 154 deletions(-)

Series applied, thanks Bruce.

Signature · 1 line
David Marchand