• Daniel Borkmann's avatar
    bpf: provide a generic macro for percpu values for selftests · f3515b5d
    Daniel Borkmann authored
    To overcome bugs as described and fixed in 89087c45 ("bpf: Fix
    values type used in test_maps"), provide a generic BPF_DECLARE_PERCPU()
    and bpf_percpu() accessor macro for all percpu map values used in
    tests.
    
    Declaring variables works as follows (also works for structs):
    
      BPF_DECLARE_PERCPU(uint32_t, my_value);
    
    They can then be accessed normally as uint32_t type through:
    
      bpf_percpu(my_value, <cpu_nr>)
    
    For example:
    
      bpf_percpu(my_value, 0)++;
    
    Implicitly, we make sure that the passed type is allocated and aligned
    by gcc at least on a 8-byte boundary, so that it works together with
    the map lookup/update syscall for percpu maps. We use it as a usage
    example in test_maps, so that others are free to adapt this into their
    code when necessary.
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    f3515b5d
bpf_util.h 1.44 KB