• Daniel Borkmann's avatar
    bpf, libbpf: use correct barriers in perf ring buffer walk · a64af0ef
    Daniel Borkmann authored
    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: d0cabbb0 ("tools: bpf: move the event reading loop to libbpf")
    Fixes: 39111695 ("samples: bpf: add bpf_perf_event_output example")
    Signed-off-by: default avatarDaniel 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: default avatarAlexei Starovoitov <ast@kernel.org>
    a64af0ef
libbpf.c 57 KB