bpf: Fixes possible race in update_prog_stats() for 32bit arches

It seems update_prog_stats() suffers from same issue fixed
in the prior patch:

As it can run while interrupts are enabled, it could
be re-entered and the u64_stats syncp could be mangled.

Fixes: fec56f5890 ("bpf: Introduce BPF trampoline")
Signed-off-by: Eric Dumazet <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
This commit is contained in:
Eric Dumazet
2021-10-27 11:13:52 -07:00
committed by Alexei Starovoitov
parent f941eadd8d
commit d979617aa8
+4 -2
View File
@@ -586,11 +586,13 @@ static void notrace update_prog_stats(struct bpf_prog *prog,
* Hence check that 'start' is valid.
*/
start > NO_START_TIME) {
unsigned long flags;
stats = this_cpu_ptr(prog->stats);
u64_stats_update_begin(&stats->syncp);
flags = u64_stats_update_begin_irqsave(&stats->syncp);
stats->cnt++;
stats->nsecs += sched_clock() - start;
u64_stats_update_end(&stats->syncp);
u64_stats_update_end_irqrestore(&stats->syncp, flags);
}
}