]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf : make libbpf_num_possible_cpus function thread safe
authorTakshak Chahande <ctakshak@fb.com>
Wed, 31 Jul 2019 22:10:55 +0000 (15:10 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 1 Aug 2019 03:35:19 +0000 (20:35 -0700)
commit6988fd32241722174fedf17459e3f7e7485f23d8
tree17d137a6c297c88c4ad99dddf76b382ab9db9b42
parent9c380a89d0df7b848325f5899b9082bc8adfb1e4
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: 993c869fcaa3 ("bpf: add a new API libbpf_num_possible_cpus()")
Signed-off-by: Takshak Chahande <ctakshak@fb.com>
Acked-by: Andrey Ignatov <rdna@fb.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c