* [PATCH bpf] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
@ 2020-04-15 14:01 Toke Høiland-Jørgensen
2020-04-16 6:55 ` Jesper Dangaard Brouer
0 siblings, 1 reply; 3+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-04-15 14:01 UTC (permalink / raw)
To: daniel, ast
Cc: Toke Høiland-Jørgensen, bpf, netdev,
Jesper Dangaard Brouer, Xiumei Mu
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 using the nr_cpumask_bits variable in the map creation code
instead of the NR_CPUS constant.
Fixes: 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Reported-by: Xiumei Mu <xmu@redhat.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
kernel/bpf/cpumap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 70f71b154fa5..23902afb3bba 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -99,8 +99,8 @@ static struct bpf_map *cpu_map_alloc(union bpf_attr *attr)
bpf_map_init_from_attr(&cmap->map, attr);
- /* Pre-limit array size based on NR_CPUS, not final CPU check */
- if (cmap->map.max_entries > NR_CPUS) {
+ /* Pre-limit array size based on nr_cpumask_bits, not final CPU check */
+ if (cmap->map.max_entries > nr_cpumask_bits) {
err = -E2BIG;
goto free_cmap;
}
--
2.26.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
2020-04-15 14:01 [PATCH bpf] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Toke Høiland-Jørgensen
@ 2020-04-16 6:55 ` Jesper Dangaard Brouer
2020-04-16 8:23 ` Toke Høiland-Jørgensen
0 siblings, 1 reply; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2020-04-16 6:55 UTC (permalink / raw)
To: Toke Høiland-Jørgensen
Cc: daniel, ast, bpf, netdev, Xiumei Mu, brouer
On Wed, 15 Apr 2020 16:01:51 +0200
Toke Høiland-Jørgensen <toke@redhat.com> wrote:
> 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 using the nr_cpumask_bits variable in the map creation code
> instead of the NR_CPUS constant.
Shouldn't you use 'nr_cpu_ids' instead of 'nr_cpumask_bits' ?
Else this will still fail on systems with CONFIG_CPUMASK_OFFSTACK=n.
>
> Fixes: 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP")
> Cc: Jesper Dangaard Brouer <brouer@redhat.com>
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
> kernel/bpf/cpumap.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
> index 70f71b154fa5..23902afb3bba 100644
> --- a/kernel/bpf/cpumap.c
> +++ b/kernel/bpf/cpumap.c
> @@ -99,8 +99,8 @@ static struct bpf_map *cpu_map_alloc(union bpf_attr *attr)
>
> bpf_map_init_from_attr(&cmap->map, attr);
>
> - /* Pre-limit array size based on NR_CPUS, not final CPU check */
> - if (cmap->map.max_entries > NR_CPUS) {
> + /* Pre-limit array size based on nr_cpumask_bits, not final CPU check */
> + if (cmap->map.max_entries > nr_cpumask_bits) {
Shouldn't you use 'nr_cpu_ids' instead of 'nr_cpumask_bits' ?
> err = -E2BIG;
> goto free_cmap;
> }
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
2020-04-16 6:55 ` Jesper Dangaard Brouer
@ 2020-04-16 8:23 ` Toke Høiland-Jørgensen
0 siblings, 0 replies; 3+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-04-16 8:23 UTC (permalink / raw)
To: Jesper Dangaard Brouer; +Cc: daniel, ast, bpf, netdev, Xiumei Mu, brouer
Jesper Dangaard Brouer <brouer@redhat.com> writes:
> On Wed, 15 Apr 2020 16:01:51 +0200
> Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
>> 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 using the nr_cpumask_bits variable in the map creation code
>> instead of the NR_CPUS constant.
>
> Shouldn't you use 'nr_cpu_ids' instead of 'nr_cpumask_bits' ?
>
> Else this will still fail on systems with CONFIG_CPUMASK_OFFSTACK=n.
Jesper and I had an offlist discussion about this, and decided that it's
actually better to keep the check in cpu_map_alloc as-is, and instead
just check against nr_cpumask_bits in cpu_map_update_elem(). Otherwise,
the max-size of the map can vary between machines which can affect BPF
program portability.
I'll send a v2.
-Toke
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-16 8:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 14:01 [PATCH bpf] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Toke Høiland-Jørgensen
2020-04-16 6:55 ` Jesper Dangaard Brouer
2020-04-16 8:23 ` Toke Høiland-Jørgensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).