• Hao Luo's avatar
    selftests/bpf: Add a test for btf_type_tag "percpu" · 50c6b8a9
    Hao Luo authored
    Add test for percpu btf_type_tag. Similar to the "user" tag, we test
    the following cases:
    
     1. __percpu struct field.
     2. __percpu as function parameter.
     3. per_cpu_ptr() accepts dynamically allocated __percpu memory.
    
    Because the test for "user" and the test for "percpu" are very similar,
    a little bit of refactoring has been done in btf_tag.c. Basically, both
    tests share the same function for loading vmlinux and module btf.
    
    Example output from log:
    
     > ./test_progs -v -t btf_tag
    
     libbpf: prog 'test_percpu1': BPF program load failed: Permission denied
     libbpf: prog 'test_percpu1': -- BEGIN PROG LOAD LOG --
     ...
     ; g = arg->a;
     1: (61) r1 = *(u32 *)(r1 +0)
     R1 is ptr_bpf_testmod_btf_type_tag_1 access percpu memory: off=0
     ...
     test_btf_type_tag_mod_percpu:PASS:btf_type_tag_percpu 0 nsec
     #26/6 btf_tag/btf_type_tag_percpu_mod1:OK
    
     libbpf: prog 'test_percpu2': BPF program load failed: Permission denied
     libbpf: prog 'test_percpu2': -- BEGIN PROG LOAD LOG --
     ...
     ; g = arg->p->a;
     2: (61) r1 = *(u32 *)(r1 +0)
     R1 is ptr_bpf_testmod_btf_type_tag_1 access percpu memory: off=0
     ...
     test_btf_type_tag_mod_percpu:PASS:btf_type_tag_percpu 0 nsec
     #26/7 btf_tag/btf_type_tag_percpu_mod2:OK
    
     libbpf: prog 'test_percpu_load': BPF program load failed: Permission denied
     libbpf: prog 'test_percpu_load': -- BEGIN PROG LOAD LOG --
     ...
     ; g = (__u64)cgrp->rstat_cpu->updated_children;
     2: (79) r1 = *(u64 *)(r1 +48)
     R1 is ptr_cgroup_rstat_cpu access percpu memory: off=48
     ...
     test_btf_type_tag_vmlinux_percpu:PASS:btf_type_tag_percpu_load 0 nsec
     #26/8 btf_tag/btf_type_tag_percpu_vmlinux_load:OK
    
     load_btfs:PASS:could not load vmlinux BTF 0 nsec
     test_btf_type_tag_vmlinux_percpu:PASS:btf_type_tag_percpu 0 nsec
     test_btf_type_tag_vmlinux_percpu:PASS:btf_type_tag_percpu_helper 0 nsec
     #26/9 btf_tag/btf_type_tag_percpu_vmlinux_helper:OK
    Signed-off-by: default avatarHao Luo <haoluo@google.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarYonghong Song <yhs@fb.com>
    Link: https://lore.kernel.org/bpf/20220304191657.981240-5-haoluo@google.com
    50c6b8a9
bpf_testmod.c 4.59 KB