Skip to contentSkip to conversation

eal: return -1 if rte_lcore_index called from non-DPDK thread

PATCH Applied Stephen Hemminger 2 participants 2 messages Apr 8, 2020 – Jul 7, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: return -1 if rte_lcore_index called from non-DPDK thread

If rte_lcore_index() is asked to give the index of the current lcore (argument -1) and is called from a non-DPDK thread then it would invalid result. The result would come lcore_config[-1].core_index which is some other data in the per-thread area.

The resolution is to return -1 which is what rte_lcore_index() returns if handed an invalid lcore.

Same issue existed with rte_lcore_to_cpu_id().

Bugzilla ID: 446

---
 lib/librte_eal/common/eal_common_lcore.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
lib/librte_eal/common/eal_common_lcore.c +10 -2
index 5404922a87d2..1d05234192ba 100644
@@ -31,8 +31,12 @@ int rte_lcore_index(int lcore_id)
 	if (unlikely(lcore_id >= RTE_MAX_LCORE))
 		return -1;
 
-	if (lcore_id < 0)
+	if (lcore_id < 0) {
+		if (rte_lcore_id() == LCORE_ID_ANY)
+			return -1;
+
 		lcore_id = (int)rte_lcore_id();
+	}
 
 	return lcore_config[lcore_id].core_index;
 }
@@ -42,8 +46,12 @@ int rte_lcore_to_cpu_id(int lcore_id)
 	if (unlikely(lcore_id >= RTE_MAX_LCORE))
 		return -1;
 
-	if (lcore_id < 0)
+	if (lcore_id < 0) {
+		if (rte_lcore_id() == LCORE_ID_ANY)
+			return -1;
+
 		lcore_id = (int)rte_lcore_id();
+	}
 
 	return lcore_config[lcore_id].core_id;
 }
Signature · 1 line
2.20.1
Acked-by on v1 1/1 Applied
#1 lore raw
Quoted 7 lines · Stephen Hemminger

If rte_lcore_index() is asked to give the index of the current lcore (argument -1) and is called from a non-DPDK thread then it would invalid result. The result would come lcore_config[-1].core_index which is some other data in the per-thread area.

Quoted 7 lines

The resolution is to return -1 which is what rte_lcore_index() returns if handed an invalid lcore.

Same issue existed with rte_lcore_to_cpu_id().

Bugzilla ID: 446

Applied, thanks.

Signature · 1 line
David Marchand