]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
bpf, libbpf: use correct barriers in perf ring buffer walk
authorDaniel Borkmann <daniel@iogearbox.net>
Fri, 19 Oct 2018 13:51:03 +0000 (15:51 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 19 Oct 2018 20:43:08 +0000 (13:43 -0700)
commita64af0ef1c1dbd1e8be65a6ebbf5950305b27e48
treedce79eaf0705b6bc3eaf0c8592fb36893427246b
parent09d62154f61316f7e97eae3f31ef8770c7e4b386
bpf, libbpf: use correct barriers in perf ring buffer walk

Given libbpf is a generic library and not restricted to x86-64 only,
the compiler barrier in bpf_perf_event_read_simple() after fetching
the head needs to be replaced with smp_rmb() at minimum. Also, writing
out the tail we should use WRITE_ONCE() to avoid store tearing.

Now that we have the logic in place in ring_buffer_read_head() and
ring_buffer_write_tail() helper also used by perf tool which would
select the correct and best variant for a given architecture (e.g.
x86-64 can avoid CPU barriers entirely), make use of these in order
to fix bpf_perf_event_read_simple().

Fixes: d0cabbb021be ("tools: bpf: move the event reading loop to libbpf")
Fixes: 39111695b1b8 ("samples: bpf: add bpf_perf_event_output example")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/libbpf.c