bpf, selftests: fix handling of sparse CPU allocations
authorMartynas Pumputis <m@lambda.lt>
Thu, 31 Jan 2019 09:19:33 +0000 (10:19 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Mar 2019 21:02:36 +0000 (14:02 -0700)
commit0ace0d28941b8dc91dac2edae754f48ac550ed40
tree6c02c16bf293a110fa671b0278289ecc72affc65
parent232bd90cf23844d7846bc57a049ec52c5d15269a
bpf, selftests: fix handling of sparse CPU allocations

[ Upstream commit 1bb54c4071f585ebef56ce8fdfe6026fa2cbcddd ]

Previously, bpf_num_possible_cpus() had a bug when calculating a
number of possible CPUs in the case of sparse CPU allocations, as
it was considering only the first range or element of
/sys/devices/system/cpu/possible.

E.g. in the case of "0,2-3" (CPU 1 is not available), the function
returned 1 instead of 3.

This patch fixes the function by making it parse all CPU ranges and
elements.

Signed-off-by: Martynas Pumputis <m@lambda.lt>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/bpf_util.h