Skip to content

Commit bc23d0e

Browse files
tohojoAlexei Starovoitov
authored andcommitted
cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
When the kernel is built with CONFIG_DEBUG_PER_CPU_MAPS, the cpumap code can trigger a spurious warning if CONFIG_CPUMASK_OFFSTACK is also set. This happens because in this configuration, NR_CPUS can be larger than nr_cpumask_bits, so the initial check in cpu_map_alloc() is not sufficient to guard against hitting the warning in cpumask_check(). Fix this by explicitly checking the supplied key against the nr_cpumask_bits variable before calling cpu_possible(). Fixes: 6710e11 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP") Reported-by: Xiumei Mu <[email protected]> Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Tested-by: Xiumei Mu <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent a460fc5 commit bc23d0e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/bpf/cpumap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static int cpu_map_update_elem(struct bpf_map *map, void *key, void *value,
469469
return -EOVERFLOW;
470470

471471
/* Make sure CPU is a valid possible cpu */
472-
if (!cpu_possible(key_cpu))
472+
if (key_cpu >= nr_cpumask_bits || !cpu_possible(key_cpu))
473473
return -ENODEV;
474474

475475
if (qsize == 0) {

0 commit comments

Comments
 (0)