Skip to content

Commit 4b91130

Browse files
edumazetborkmann
authored andcommitted
bpf: fix u64_stats_init() usage in bpf_prog_alloc()
We need to iterate through all possible cpus. Fixes: 492ecee ("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> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 3860d38 commit 4b91130

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

kernel/bpf/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
109109
{
110110
gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
111111
struct bpf_prog *prog;
112+
int cpu;
112113

113114
prog = bpf_prog_alloc_no_stats(size, gfp_extra_flags);
114115
if (!prog)
@@ -121,7 +122,12 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
121122
return NULL;
122123
}
123124

124-
u64_stats_init(&prog->aux->stats->syncp);
125+
for_each_possible_cpu(cpu) {
126+
struct bpf_prog_stats *pstats;
127+
128+
pstats = per_cpu_ptr(prog->aux->stats, cpu);
129+
u64_stats_init(&pstats->syncp);
130+
}
125131
return prog;
126132
}
127133
EXPORT_SYMBOL_GPL(bpf_prog_alloc);

0 commit comments

Comments
 (0)