Skip to content
Commit 56fbc241 authored by Takshak Chahande's avatar Takshak Chahande Committed by Alexei Starovoitov
Browse files

libbpf : make libbpf_num_possible_cpus function thread safe



Having static variable `cpus` in libbpf_num_possible_cpus function
without guarding it with mutex makes this function thread-unsafe.

If multiple threads accessing this function, in the current form; it
leads to incrementing the static variable value `cpus` in the multiple
of total available CPUs.

Used local stack variable to calculate the number of possible CPUs and
then updated the static variable using WRITE_ONCE().

Changes since v1:
 * added stack variable to calculate cpus
 * serialized static variable update using WRITE_ONCE()
 * fixed Fixes tag

Fixes: 6446b315 ("bpf: add a new API libbpf_num_possible_cpus()")
Signed-off-by: default avatarTakshak Chahande <ctakshak@fb.com>
Acked-by: default avatarAndrey Ignatov <rdna@fb.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 5d01ab7b
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment