* [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
@ 2020-04-16 8:31 Toke Høiland-Jørgensen
2020-04-16 8:43 ` Jesper Dangaard Brouer
2020-04-21 1:40 ` Alexei Starovoitov
0 siblings, 2 replies; 4+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-04-16 8:31 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 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 <brouer@redhat.com>
Reported-by: Xiumei Mu <xmu@redhat.com>
Tested-by: Xiumei Mu <xmu@redhat.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
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(-)
diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 70f71b154fa5..3fe0b006d2d2 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -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) {
--
2.26.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
2020-04-16 8:31 [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Toke Høiland-Jørgensen
@ 2020-04-16 8:43 ` Jesper Dangaard Brouer
2020-04-16 21:45 ` Song Liu
2020-04-21 1:40 ` Alexei Starovoitov
1 sibling, 1 reply; 4+ messages in thread
From: Jesper Dangaard Brouer @ 2020-04-16 8:43 UTC (permalink / raw)
To: Toke Høiland-Jørgensen
Cc: daniel, ast, bpf, netdev, Xiumei Mu, brouer
On Thu, 16 Apr 2020 10:31:20 +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 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 <brouer@redhat.com>
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Tested-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
> 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(-)
>
> diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
> index 70f71b154fa5..3fe0b006d2d2 100644
> --- a/kernel/bpf/cpumap.c
> +++ b/kernel/bpf/cpumap.c
> @@ -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.
--
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] 4+ messages in thread
* Re: [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
2020-04-16 8:43 ` Jesper Dangaard Brouer
@ 2020-04-16 21:45 ` Song Liu
0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2020-04-16 21:45 UTC (permalink / raw)
To: Jesper Dangaard Brouer
Cc: Toke Høiland-Jørgensen, Daniel Borkmann,
Alexei Starovoitov, bpf, Networking, Xiumei Mu
On Thu, Apr 16, 2020 at 2:11 AM Jesper Dangaard Brouer
<brouer@redhat.com> wrote:
>
> On Thu, 16 Apr 2020 10:31:20 +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 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 <brouer@redhat.com>
> > Reported-by: Xiumei Mu <xmu@redhat.com>
> > Tested-by: Xiumei Mu <xmu@redhat.com>
> > Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> > ---
>
> Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Song Liu <songliubraving@fb.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled
2020-04-16 8:31 [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Toke Høiland-Jørgensen
2020-04-16 8:43 ` Jesper Dangaard Brouer
@ 2020-04-21 1:40 ` Alexei Starovoitov
1 sibling, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2020-04-21 1:40 UTC (permalink / raw)
To: Toke Høiland-Jørgensen
Cc: Daniel Borkmann, Alexei Starovoitov, bpf, Network Development,
Jesper Dangaard Brouer, Xiumei Mu
On Thu, Apr 16, 2020 at 1:33 AM 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 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 <brouer@redhat.com>
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Tested-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Applied. Thanks
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-04-21 1:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-16 8:31 [PATCH bpf v2] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Toke Høiland-Jørgensen
2020-04-16 8:43 ` Jesper Dangaard Brouer
2020-04-16 21:45 ` Song Liu
2020-04-21 1:40 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox