DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: return -1 if rte_lcore_index called from non-DPDK thread
@ 2020-04-08 20:24 Stephen Hemminger
  2020-07-07 11:46 ` David Marchand
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2020-04-08 20:24 UTC (permalink / raw)
  To: dev; +Cc: 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.

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
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/librte_eal/common/eal_common_lcore.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c
index 5404922a87d2..1d05234192ba 100644
--- a/lib/librte_eal/common/eal_common_lcore.c
+++ b/lib/librte_eal/common/eal_common_lcore.c
@@ -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;
 }
-- 
2.20.1


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

end of thread, other threads:[~2020-07-07 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08 20:24 [dpdk-dev] [PATCH] eal: return -1 if rte_lcore_index called from non-DPDK thread Stephen Hemminger
2020-07-07 11:46 ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).