Skip to contentSkip to conversation

cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled

PATCH Applied Toke Høiland-Jørgensen 4 participants 4 messages Apr 16, 2020 – Apr 21, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
Cc Jesper Dangaard Brouer <[email protected]>

---
v2:
- Move check to cpu_map_update_elem() to not affect max size of map

 kernel/bpf/cpumap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/cpumap.c +1 -1
index 70f71b154fa5..3fe0b006d2d2 100644
@@ -469,7 +469,7 @@ static int cpu_map_update_elem(struct bpf_map *map, void *key, void *value,
 		return -EOVERFLOW;
 
 	/* Make sure CPU is a valid possible cpu */
-	if (!cpu_possible(key_cpu))
+	if (key_cpu >= nr_cpumask_bits || !cpu_possible(key_cpu))
 		return -ENODEV;
 
 	if (qsize == 0) {
Signature · 1 line
2.26.0
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · On Thu, 16 Apr 2020 10:31:20 +0200 Toke Høiland-Jørgensen <[email protected]>…

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().

Quoted 6 lines
Fixes 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
Cc Jesper Dangaard Brouer <[email protected]>

---

Quoted 11 lines

v2:
- Move check to cpu_map_update_elem() to not affect max size of map

 kernel/bpf/cpumap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/cpumap.c +0 -0
index 70f71b154fa5..3fe0b006d2d2 100644

kernel/bpf/cpumap.c static int cpu_map_update_elem(struct bpf_map *map, void *key, void *value, · line 472

Quoted 5 lines
kernel/bpf/cpumap.c +1 -1
@@ -469,7 +469,7 @@ static int cpu_map_update_elem(struct bpf_map *map, void *key, void *value,
 		return -EOVERFLOW;
 
 	/* Make sure CPU is a valid possible cpu */
-	if (!cpu_possible(key_cpu))
+	if (key_cpu >= nr_cpumask_bits || !cpu_possible(key_cpu))

Toke use 'nr_cpumask_bits' here, because cpumask_check() also uses it, which is the warning we are trying to avoid.

Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
reviewer Acked-by
#2 lore raw
Quoted 13 lines · Jesper Dangaard Brouer
Quoted 9 lines · On Thu, 16 Apr 2020 10:31:20 +0200 Toke Høiland-Jørgensen <[email protected]>…

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().

Quoted 8 lines
Quoted 6 lines
Fixes 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
Cc Jesper Dangaard Brouer <[email protected]>

---

#3 lore raw
In reply to Toke Høiland-Jørgensen
Quoted 7 lines · Toke Høiland-Jørgensen

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().

Quoted 8 lines

Fix this by explicitly checking the supplied key against the nr_cpumask_bits variable before calling cpu_possible().

Fixes 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
Cc Jesper Dangaard Brouer <[email protected]>

Applied. Thanks