Skip to contentSkip to conversation

fix compilation on Fedora 22

PATCH Superseded Bruce Richardson 3 participants 14 messages May 29, 2015 – Jun 3, 2015 Network drivers

lore
Share & tools
lore
#0 lore raw

cover fix compilation on Fedora 22

GCC version 5.1 included with Fedora 22 is running stricter array bounds checks which are throwing up errors in a number of components in the DPDK code. This patchset fixes these errors to allow compilation with GCC on Fedora 22.

Example error:
== Build lib/librte_eal/linuxapp/eal
CC eal_memory.o
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c: In function 'rte_eal_hugepage_init':
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c:1193:35: error: array subscript is above array bounds [-Werror=array-bounds]

      internal_config.hugepage_info[j].hugepage_sz) {
                                   ^

compilation terminated due to -Wfatal-errors.

Bruce Richardson (4):
eal: fix compile on Fedora 22 (GCC 5.1)
ip_frag: fix compile on Fedora 22 (GCC 5.1)
i40e: fix compile on Fedora 22 (GCC 5.1)
null: fix compile on Fedora 22 (GCC 5.1)

 drivers/net/i40e/i40e_fdir.c             |  2 +-
 drivers/net/null/rte_eth_null.c          | 12 ++++++++----
 lib/librte_eal/linuxapp/eal/eal_memory.c |  3 ++-
 lib/librte_ip_frag/ip_frag_common.h      |  2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)
Signature · 1 line
2.4.1
#1 lore raw

PATCH 1/4 eal: fix compile on Fedora 22 (GCC 5.1)

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_memory.c +2 -1
index 5f9f92e..744635f 100644
@@ -1188,7 +1188,8 @@ rte_eal_hugepage_init(void)
 		int socket = tmp_hp[i].socket_id;
 
 		/* find a hugepage info with right size and increment num_pages */
-		for (j = 0; j < (int) internal_config.num_hugepage_sizes; j++) {
+		for (j = 0; j < (int) internal_config.num_hugepage_sizes &&
+				j < MAX_HUGEPAGE_SIZES; j++) {
 			if (tmp_hp[i].size ==
 					internal_config.hugepage_info[j].hugepage_sz) {
 #ifdef RTE_EAL_SINGLE_FILE_SEGMENTS
Signature · 1 line
2.4.1
#2 lore raw

Re: [PATCH 1/4] eal: fix compile on Fedora 22 (GCC 5.1)

Quoted 14 lines · Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_memory.c +0 -0
index 5f9f92e..744635f 100644

lib/librte_eal/linuxapp/eal/eal_memory.c rte_eal_hugepage_init(void) · line 1193

Quoted 7 lines
lib/librte_eal/linuxapp/eal/eal_memory.c +2 -1
@@ -1188,7 +1188,8 @@ rte_eal_hugepage_init(void)
 		int socket = tmp_hp[i].socket_id;
 
 		/* find a hugepage info with right size and increment num_pages */
-		for (j = 0; j < (int) internal_config.num_hugepage_sizes; j++) {
+		for (j = 0; j < (int) internal_config.num_hugepage_sizes &&
+				j < MAX_HUGEPAGE_SIZES; j++) {
 			if (tmp_hp[i].size ==

Use RTE_MIN here, it will look alot cleaner I think Neil

Quoted 6 lines
lib/librte_eal/linuxapp/eal/eal_memory.c +0 -0
 					internal_config.hugepage_info[j].hugepage_sz) {
 #ifdef RTE_EAL_SINGLE_FILE_SEGMENTS
Signature · 1 line
2.4.1
#3 lore raw

PATCH 2/4 ip_frag: fix compile on Fedora 22 (GCC 5.1)

In reply to Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 lib/librte_ip_frag/ip_frag_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_ip_frag/ip_frag_common.h +1 -1
index 210f409..e37073b 100644
@@ -90,7 +90,7 @@ static inline int
 ip_frag_key_is_empty(const struct ip_frag_key * key)
 {
 	uint32_t i;
-	for (i = 0; i < key->key_len; i++)
+	for (i = 0; i < key->key_len && i < RTE_DIM(key->src_dst); i++)
 		if (key->src_dst[i] != 0)
 			return 0;
 	return 1;
Signature · 1 line
2.4.1
#4 lore raw

Re: [PATCH 2/4] ip_frag: fix compile on Fedora 22 (GCC 5.1)

Quoted 26 lines · Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 lib/librte_ip_frag/ip_frag_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_ip_frag/ip_frag_common.h +1 -1
index 210f409..e37073b 100644
@@ -90,7 +90,7 @@ static inline int
 ip_frag_key_is_empty(const struct ip_frag_key * key)
 {
 	uint32_t i;
-	for (i = 0; i < key->key_len; i++)
+	for (i = 0; i < key->key_len && i < RTE_DIM(key->src_dst); i++)
 		if (key->src_dst[i] != 0)
 			return 0;
 	return 1;
Signature · 1 line
2.4.1

RTE_MIN again
Neil

#5 lore raw

PATCH 3/4 i40e: fix compile on Fedora 22 (GCC 5.1)

In reply to Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 drivers/net/i40e/i40e_fdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/i40e/i40e_fdir.c +1 -1
index e688b4f..55cf2cf 100644
@@ -551,7 +551,7 @@ i40e_set_flx_pld_cfg(struct i40e_pf *pf,
 	memset(flex_pit, 0, sizeof(flex_pit));
 	num = i40e_srcoff_to_flx_pit(cfg->src_offset, flex_pit);
 
-	for (i = 0; i < num; i++) {
+	for (i = 0; i < num && i < RTE_DIM(flex_pit); i++) {
 		field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
 		/* record the info in fdir structure */
 		pf->fdir.flex_set[field_idx].src_offset =
Signature · 1 line
2.4.1
#6 lore raw

PATCH 4/4 null: fix compile on Fedora 22 (GCC 5.1)

In reply to Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 drivers/net/null/rte_eth_null.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/null/rte_eth_null.c +8 -4
index 5895065..4ca7f09 100644
@@ -298,7 +298,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 	internal = dev->data->dev_private;
 	memset(igb_stats, 0, sizeof(*igb_stats));
 	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
-					internal->nb_rx_queues);
+			RTE_MIN(internal->nb_rx_queues,
+				RTE_DIM(internal->rx_null_queues)));
 	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_ipackets[i] =
 			internal->rx_null_queues[i].rx_pkts.cnt;
@@ -306,7 +307,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 	}
 
 	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
-					internal->nb_tx_queues);
+			RTE_MIN(internal->nb_tx_queues,
+				RTE_DIM(internal->tx_null_queues)));
 	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_opackets[i] =
 			internal->tx_null_queues[i].tx_pkts.cnt;
@@ -331,9 +333,11 @@ eth_stats_reset(struct rte_eth_dev *dev)
 		return;
 
 	internal = dev->data->dev_private;
-	for (i = 0; i < internal->nb_rx_queues; i++)
+	for (i = 0; i < internal->nb_rx_queues &&
+			i < RTE_DIM(internal->rx_null_queues); i++)
 		internal->rx_null_queues[i].rx_pkts.cnt = 0;
-	for (i = 0; i < internal->nb_tx_queues; i++) {
+	for (i = 0; i < internal->nb_tx_queues &&
+			i < RTE_DIM(internal->tx_null_queues); i++) {
 		internal->tx_null_queues[i].tx_pkts.cnt = 0;
 		internal->tx_null_queues[i].err_pkts.cnt = 0;
 	}
Signature · 1 line
2.4.1
#7 lore raw

v2 cover fix compilation on Fedora 22

In reply to Bruce Richardson

V2 Changes:
* use RTE_MIN instead of additional comparison checks in some loops, as suggested by Neil.
* For stats reset in null PMD, just use the size of the array [which is 1] in place of the used queue counts.

GCC version 5.1 included with Fedora 22 is running stricter array bounds checks which are throwing up errors in a number of components in the DPDK code. This patchset fixes these errors to allow compilation with GCC on Fedora 22.

Example error:
== Build lib/librte_eal/linuxapp/eal
CC eal_memory.o
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c: In function 'rte_eal_hugepage_init':
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c:1193:35: error: array subscript is above array bounds [-Werror=array-bounds]

      internal_config.hugepage_info[j].hugepage_sz) {
                                   ^

compilation terminated due to -Wfatal-errors.

Bruce Richardson (4):
eal: fix compile on Fedora 22 (GCC 5.1)
ip_frag: fix compile on Fedora 22 (GCC 5.1)
i40e: fix compile on Fedora 22 (GCC 5.1)
null: fix compile on Fedora 22 (GCC 5.1)

 drivers/net/i40e/i40e_fdir.c             |  2 +-
 drivers/net/null/rte_eth_null.c          | 12 ++++++++----
 lib/librte_eal/linuxapp/eal/eal_memory.c |  4 +++-
 lib/librte_ip_frag/ip_frag_common.h      |  2 +-
 4 files changed, 13 insertions(+), 7 deletions(-)
Signature · 1 line
2.4.1
#8 lore raw

PATCH v2 1/4 eal: fix compile on Fedora 22 (GCC 5.1)

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by ensuring the bounds check in the loop takes account of the array size.

---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_eal/linuxapp/eal/eal_memory.c +3 -1
index 5f9f92e..9b8d946 100644
@@ -1188,7 +1188,9 @@ rte_eal_hugepage_init(void)
 		int socket = tmp_hp[i].socket_id;
 
 		/* find a hugepage info with right size and increment num_pages */
-		for (j = 0; j < (int) internal_config.num_hugepage_sizes; j++) {
+		const int nb_hpsizes = RTE_MIN(MAX_HUGEPAGE_SIZES,
+				(int)internal_config.num_hugepage_sizes);
+		for (j = 0; j < nb_hpsizes; j++) {
 			if (tmp_hp[i].size ==
 					internal_config.hugepage_info[j].hugepage_sz) {
 #ifdef RTE_EAL_SINGLE_FILE_SEGMENTS
Signature · 1 line
2.4.1
#9 lore raw

PATCH v2 2/4 ip_frag: fix compile on Fedora 22 (GCC 5.1)

In reply to Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 lib/librte_ip_frag/ip_frag_common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_ip_frag/ip_frag_common.h +1 -1
index 210f409..6b2acee 100644
@@ -90,7 +90,7 @@ static inline int
 ip_frag_key_is_empty(const struct ip_frag_key * key)
 {
 	uint32_t i;
-	for (i = 0; i < key->key_len; i++)
+	for (i = 0; i < RTE_MIN(key->key_len, RTE_DIM(key->src_dst)); i++)
 		if (key->src_dst[i] != 0)
 			return 0;
 	return 1;
Signature · 1 line
2.4.1
#10 lore raw

PATCH v2 3/4 i40e: fix compile on Fedora 22 (GCC 5.1)

In reply to Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counter.

---
 drivers/net/i40e/i40e_fdir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/i40e/i40e_fdir.c +1 -1
index e688b4f..4bf98d0 100644
@@ -551,7 +551,7 @@ i40e_set_flx_pld_cfg(struct i40e_pf *pf,
 	memset(flex_pit, 0, sizeof(flex_pit));
 	num = i40e_srcoff_to_flx_pit(cfg->src_offset, flex_pit);
 
-	for (i = 0; i < num; i++) {
+	for (i = 0; i < RTE_MIN(num, RTE_DIM(flex_pit)); i++) {
 		field_idx = layer_idx * I40E_MAX_FLXPLD_FIED + i;
 		/* record the info in fdir structure */
 		pf->fdir.flex_set[field_idx].src_offset =
Signature · 1 line
2.4.1
#11 lore raw

PATCH v2 4/4 null: fix compile on Fedora 22 (GCC 5.1)

In reply to Bruce Richardson

On Fedora 22, with GCC 5.1, errors are reported due to array accesses being potentially out of bounds. This commit fixes this by adding in an extra bounds check to the loop counters, or, in the case of stats reset, by blindly zeroing the whole array, rather than just the part that is in use.

---
 drivers/net/null/rte_eth_null.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/null/rte_eth_null.c +6 -4
index 5895065..7792315 100644
@@ -298,7 +298,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 	internal = dev->data->dev_private;
 	memset(igb_stats, 0, sizeof(*igb_stats));
 	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
-					internal->nb_rx_queues);
+			RTE_MIN(internal->nb_rx_queues,
+				RTE_DIM(internal->rx_null_queues)));
 	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_ipackets[i] =
 			internal->rx_null_queues[i].rx_pkts.cnt;
@@ -306,7 +307,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 	}
 
 	num_stats = RTE_MIN((unsigned)RTE_ETHDEV_QUEUE_STAT_CNTRS,
-					internal->nb_tx_queues);
+			RTE_MIN(internal->nb_tx_queues,
+				RTE_DIM(internal->tx_null_queues)));
 	for (i = 0; i < num_stats; i++) {
 		igb_stats->q_opackets[i] =
 			internal->tx_null_queues[i].tx_pkts.cnt;
@@ -331,9 +333,9 @@ eth_stats_reset(struct rte_eth_dev *dev)
 		return;
 
 	internal = dev->data->dev_private;
-	for (i = 0; i < internal->nb_rx_queues; i++)
+	for (i = 0; i < RTE_DIM(internal->rx_null_queues); i++)
 		internal->rx_null_queues[i].rx_pkts.cnt = 0;
-	for (i = 0; i < internal->nb_tx_queues; i++) {
+	for (i = 0; i < RTE_DIM(internal->tx_null_queues); i++) {
 		internal->tx_null_queues[i].tx_pkts.cnt = 0;
 		internal->tx_null_queues[i].err_pkts.cnt = 0;
 	}
Signature · 1 line
2.4.1
Acked-by on the v2 series
#12 lore raw
In reply to Bruce Richardson
Quoted 26 lines · Bruce Richardson

V2 Changes:
* use RTE_MIN instead of additional comparison checks in some loops, as suggested by Neil.
* For stats reset in null PMD, just use the size of the array [which is 1] in place of the used queue counts.

GCC version 5.1 included with Fedora 22 is running stricter array bounds checks which are throwing up errors in a number of components in the DPDK code. This patchset fixes these errors to allow compilation with GCC on Fedora 22.

Example error:
== Build lib/librte_eal/linuxapp/eal
CC eal_memory.o
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c: In function 'rte_eal_hugepage_init':
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c:1193:35: error: array subscript is above array bounds [-Werror=array-bounds]

      internal_config.hugepage_info[j].hugepage_sz) {
                                   ^

compilation terminated due to -Wfatal-errors.

Bruce Richardson (4):
eal: fix compile on Fedora 22 (GCC 5.1)
ip_frag: fix compile on Fedora 22 (GCC 5.1)
i40e: fix compile on Fedora 22 (GCC 5.1)
null: fix compile on Fedora 22 (GCC 5.1)

Quoted 10 lines
 drivers/net/i40e/i40e_fdir.c             |  2 +-
 drivers/net/null/rte_eth_null.c          | 12 ++++++++----
 lib/librte_eal/linuxapp/eal/eal_memory.c |  4 +++-
 lib/librte_ip_frag/ip_frag_common.h      |  2 +-
 4 files changed, 13 insertions(+), 7 deletions(-)
Signature · 1 line
2.4.1

Series

#13 lore raw

2015-05-29 12:57, Neil Horman:

Quoted 21 lines · Bruce Richardson
Quoted 20 lines

V2 Changes:
* use RTE_MIN instead of additional comparison checks in some loops, as suggested by Neil.
* For stats reset in null PMD, just use the size of the array [which is 1] in place of the used queue counts.

GCC version 5.1 included with Fedora 22 is running stricter array bounds checks which are throwing up errors in a number of components in the DPDK code. This patchset fixes these errors to allow compilation with GCC on Fedora 22.

Example error:
== Build lib/librte_eal/linuxapp/eal
CC eal_memory.o
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c: In function 'rte_eal_hugepage_init':
/home/bruce/dpdk.org/lib/librte_eal/linuxapp/eal/eal_memory.c:1193:35: error: array subscript is above array bounds [-Werror=array-bounds]

      internal_config.hugepage_info[j].hugepage_sz) {
                                   ^

compilation terminated due to -Wfatal-errors.

Quoted 8 lines
Quoted 5 lines

Bruce Richardson (4):
eal: fix compile on Fedora 22 (GCC 5.1)
ip_frag: fix compile on Fedora 22 (GCC 5.1)
i40e: fix compile on Fedora 22 (GCC 5.1)
null: fix compile on Fedora 22 (GCC 5.1)

Series

Applied, thanks