bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] bpf: fix u64_stats_init() usage in bpf_prog_alloc()
@ 2019-03-01 22:33 Eric Dumazet
  2019-03-01 23:31 ` Song Liu
  2019-03-01 23:37 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2019-03-01 22:33 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Daniel Borkmann, netdev, Eric Dumazet, Eric Dumazet,
	Martin KaFai Lau, Song Liu, Yonghong Song, bpf, Guenter Roeck

We need to iterate through all possible cpus.

Fixes: 492ecee892c2 ("bpf: enable program stats")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Guenter Roeck <linux@roeck-us.net>
---
 kernel/bpf/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 1c14c347f3cfe1f7c0cf8a7eccff8135b16df81f..3f08c257858e1570339cd64a6351824bcc332ee3 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -109,6 +109,7 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
 {
 	gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
 	struct bpf_prog *prog;
+	int cpu;
 
 	prog = bpf_prog_alloc_no_stats(size, gfp_extra_flags);
 	if (!prog)
@@ -121,7 +122,12 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
 		return NULL;
 	}
 
-	u64_stats_init(&prog->aux->stats->syncp);
+	for_each_possible_cpu(cpu) {
+		struct bpf_prog_stats *pstats;
+
+		pstats = per_cpu_ptr(prog->aux->stats, cpu);
+		u64_stats_init(&pstats->syncp);
+	}
 	return prog;
 }
 EXPORT_SYMBOL_GPL(bpf_prog_alloc);
-- 
2.21.0.352.gf09ad66450-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] bpf: fix u64_stats_init() usage in bpf_prog_alloc()
  2019-03-01 22:33 [PATCH net] bpf: fix u64_stats_init() usage in bpf_prog_alloc() Eric Dumazet
@ 2019-03-01 23:31 ` Song Liu
  2019-03-01 23:37 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2019-03-01 23:31 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Alexei Starovoitov, Daniel Borkmann, netdev, Eric Dumazet,
	Martin KaFai Lau, Song Liu, Yonghong Song, bpf, Guenter Roeck

On Fri, Mar 1, 2019 at 2:34 PM Eric Dumazet <edumazet@google.com> wrote:
>
> We need to iterate through all possible cpus.
>
> Fixes: 492ecee892c2 ("bpf: enable program stats")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Tested-by: Guenter Roeck <linux@roeck-us.net>

Acked-by: Song Liu <songliubraving@fb.com>

> ---
>  kernel/bpf/core.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 1c14c347f3cfe1f7c0cf8a7eccff8135b16df81f..3f08c257858e1570339cd64a6351824bcc332ee3 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -109,6 +109,7 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
>  {
>         gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
>         struct bpf_prog *prog;
> +       int cpu;
>
>         prog = bpf_prog_alloc_no_stats(size, gfp_extra_flags);
>         if (!prog)
> @@ -121,7 +122,12 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
>                 return NULL;
>         }
>
> -       u64_stats_init(&prog->aux->stats->syncp);
> +       for_each_possible_cpu(cpu) {
> +               struct bpf_prog_stats *pstats;
> +
> +               pstats = per_cpu_ptr(prog->aux->stats, cpu);
> +               u64_stats_init(&pstats->syncp);
> +       }
>         return prog;
>  }
>  EXPORT_SYMBOL_GPL(bpf_prog_alloc);
> --
> 2.21.0.352.gf09ad66450-goog
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] bpf: fix u64_stats_init() usage in bpf_prog_alloc()
  2019-03-01 22:33 [PATCH net] bpf: fix u64_stats_init() usage in bpf_prog_alloc() Eric Dumazet
  2019-03-01 23:31 ` Song Liu
@ 2019-03-01 23:37 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-03-01 23:37 UTC (permalink / raw)
  To: Eric Dumazet, Alexei Starovoitov
  Cc: netdev, Eric Dumazet, Martin KaFai Lau, Song Liu, Yonghong Song,
	bpf, Guenter Roeck

On 03/01/2019 11:33 PM, Eric Dumazet wrote:
> We need to iterate through all possible cpus.
> 
> Fixes: 492ecee892c2 ("bpf: enable program stats")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Tested-by: Guenter Roeck <linux@roeck-us.net>

Applied, thanks! Issue is only in bpf-next, not net, therefore
I've applied it there.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-01 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01 22:33 [PATCH net] bpf: fix u64_stats_init() usage in bpf_prog_alloc() Eric Dumazet
2019-03-01 23:31 ` Song Liu
2019-03-01 23:37 ` Daniel Borkmann

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