eal: fix lcore accessors for non-EAL threads
If rte_lcore_index() is asked to give the index of the
current lcore (argument -1) and is called from a non-EAL 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
Fixes: 26cc3bbe4d
("eal: add lcore accessors")
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: David Marchand <david.marchand@redhat.com>
This commit is contained in:
parent
e1c9850f55
commit
67ae5936c4
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user