1. 09 10月, 2021 5 次提交
    • Q
      selftests/bpf: Better clean up for runqslower in test_bpftool_build.sh · 87ee33bf
      Quentin Monnet 提交于
      The script test_bpftool_build.sh attempts to build bpftool in the
      various supported ways, to make sure nothing breaks.
      
      One of those ways is to run "make tools/bpf" from the root of the kernel
      repository. This command builds bpftool, along with the other tools
      under tools/bpf, and runqslower in particular. After running the
      command and upon a successful bpftool build, the script attempts to
      cleanup the generated objects. However, after building with this target
      and in the case of runqslower, the files are not cleaned up as expected.
      
      This is because the "tools/bpf" target sets $(OUTPUT) to
      .../tools/bpf/runqslower/ when building the tool, causing the object
      files to be placed directly under the runqslower directory. But when
      running "cd tools/bpf; make clean", the value for $(OUTPUT) is set to
      ".output" (relative to the runqslower directory) by runqslower's
      Makefile, and this is where the Makefile looks for files to clean up.
      
      We cannot easily fix in the root Makefile (where "tools/bpf" is defined)
      or in tools/scripts/Makefile.include (setting $(OUTPUT)), where changing
      the way the output variables are passed would likely have consequences
      elsewhere. We could change runqslower's Makefile to build in the
      repository instead of in a dedicated ".output/", but doing so just to
      accommodate a test script doesn't sound great. Instead, let's just make
      sure that we clean up runqslower properly by adding the correct command
      to the script.
      
      This will attempt to clean runqslower twice: the first try with command
      "cd tools/bpf; make clean" will search for tools/bpf/runqslower/.output
      and fail to clean it (but will still clean the other tools, in
      particular bpftool), the second one (added in this commit) sets the
      $(OUTPUT) variable like for building with the "tool/bpf" target and
      should succeed.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211007194438.34443-12-quentin@isovalent.com
      87ee33bf
    • Q
      tools/runqslower: Install libbpf headers when building · be79505c
      Quentin Monnet 提交于
      API headers from libbpf should not be accessed directly from the
      library's source directory. Instead, they should be exported with "make
      install_headers". Let's make sure that runqslower installs the
      headers properly when building.
      
      We use a libbpf_hdrs target to mark the logical dependency on libbpf's
      headers export for a number of object files, even though the headers
      should have been exported at this time (since bpftool needs them, and is
      required to generate the skeleton or the vmlinux.h).
      
      When descending from a parent Makefile, the specific output directories
      for building the library and exporting the headers are configurable with
      BPFOBJ_OUTPUT and BPF_DESTDIR, respectively. This is in addition to
      OUTPUT, on top of which those variables are constructed by default.
      
      Also adjust the Makefile for the BPF selftests. We pass a number of
      variables to the "make" invocation, because we want to point runqslower
      to the (target) libbpf shared with other tools, instead of building its
      own version. In addition, runqslower relies on (target) bpftool, and we
      also want to pass the proper variables to its Makefile so that bpftool
      itself reuses the same libbpf.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211007194438.34443-6-quentin@isovalent.com
      be79505c
    • Q
      tools/resolve_btfids: Install libbpf headers when building · 1478994a
      Quentin Monnet 提交于
      API headers from libbpf should not be accessed directly from the
      library's source directory. Instead, they should be exported with "make
      install_headers". Let's make sure that resolve_btfids installs the
      headers properly when building.
      
      When descending from a parent Makefile, the specific output directories
      for building the library and exporting the headers are configurable with
      LIBBPF_OUT and LIBBPF_DESTDIR, respectively. This is in addition to
      OUTPUT, on top of which those variables are constructed by default.
      
      Also adjust the Makefile for the BPF selftests in order to point to the
      (target) libbpf shared with other tools, instead of building a version
      specific to resolve_btfids. Remove libbpf's order-only dependencies on
      the include directories (they are created by libbpf and don't need to
      exist beforehand).
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211007194438.34443-5-quentin@isovalent.com
      1478994a
    • Q
      bpftool: Install libbpf headers instead of including the dir · f012ade1
      Quentin Monnet 提交于
      Bpftool relies on libbpf, therefore it relies on a number of headers
      from the library and must be linked against the library. The Makefile
      for bpftool exposes these objects by adding tools/lib as an include
      directory ("-I$(srctree)/tools/lib"). This is a working solution, but
      this is not the cleanest one. The risk is to involuntarily include
      objects that are not intended to be exposed by the libbpf.
      
      The headers needed to compile bpftool should in fact be "installed" from
      libbpf, with its "install_headers" Makefile target. In addition, there
      is one header which is internal to the library and not supposed to be
      used by external applications, but that bpftool uses anyway.
      
      Adjust the Makefile in order to install the header files properly before
      compiling bpftool. Also copy the additional internal header file
      (nlattr.h), but call it out explicitly. Build (and install headers) in a
      subdirectory under bpftool/ instead of tools/lib/bpf/. When descending
      from a parent Makefile, this is configurable by setting the OUTPUT,
      LIBBPF_OUTPUT and LIBBPF_DESTDIR variables.
      
      Also adjust the Makefile for BPF selftests, so as to reuse the (host)
      libbpf compiled earlier and to avoid compiling a separate version of the
      library just for bpftool.
      Signed-off-by: NQuentin Monnet <quentin@isovalent.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Acked-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211007194438.34443-4-quentin@isovalent.com
      f012ade1
    • Y
      selftests/bpf: Fix btf_dump test under new clang · 7e3cbd34
      Yucong Sun 提交于
      New clang version changed ([0]) type name in dwarf from "long int" to "long",
      this is causing btf_dump tests to fail.
      
        [0] https://github.com/llvm/llvm-project/commit/f6a561c4d6754b13165a49990e8365d819f64c86Signed-off-by: NYucong Sun <sunyucong@gmail.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/bpf/20211008173139.1457407-1-fallentree@fb.com
      7e3cbd34
  2. 08 10月, 2021 2 次提交
  3. 07 10月, 2021 2 次提交
  4. 06 10月, 2021 5 次提交
  5. 04 10月, 2021 1 次提交
  6. 02 10月, 2021 4 次提交
  7. 01 10月, 2021 1 次提交
  8. 30 9月, 2021 1 次提交
  9. 29 9月, 2021 5 次提交
  10. 28 9月, 2021 9 次提交
  11. 27 9月, 2021 3 次提交
    • P
      selftests: net: fib_nexthops: Wait before checking reported idle time · b69c9946
      Petr Machata 提交于
      The purpose of this test is to verify that after a short activity passes,
      the reported time is reasonable: not zero (which could be reported by
      mistake), and not something outrageous (which would be indicative of an
      issue in used units).
      
      However, the idle time is reported in units of clock_t, or hundredths of
      second. If the initial sequence of commands is very quick, it is possible
      that the idle time is reported as just flat-out zero. When this test was
      recently enabled in our nightly regression, we started seeing spurious
      failures for exactly this reason.
      
      Therefore buffer the delay leading up to the test with a sleep, to make
      sure there is no legitimate way of reporting 0.
      Signed-off-by: NPetr Machata <petrm@nvidia.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b69c9946
    • M
      bpf: selftest: Add verifier tests for <8-byte scalar spill and refill · ef979017
      Martin KaFai Lau 提交于
      This patch adds a few verifier tests for <8-byte spill and refill.
      Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210922004953.627183-1-kafai@fb.com
      ef979017
    • M
      bpf: selftest: A bpf prog that has a 32bit scalar spill · 54ea6079
      Martin KaFai Lau 提交于
      It is a simplified example that can trigger a 32bit scalar spill.
      The const scalar is refilled and added to a skb->data later.
      Since the reg state of the 32bit scalar spill is not saved now,
      adding the refilled reg to skb->data and then comparing it with
      skb->data_end cannot verify the skb->data access.
      
      With the earlier verifier patch and the llvm patch [1].  The verifier
      can correctly verify the bpf prog.
      
      Here is the snippet of the verifier log that leads to verifier conclusion
      that the packet data is unsafe to read.  The log is from the kerne
      without the previous verifier patch to save the <8-byte scalar spill.
      67: R0=inv1 R1=inv17 R2=invP2 R3=inv1 R4=pkt(id=0,off=68,r=102,imm=0) R5=inv102 R6=pkt(id=0,off=62,r=102,imm=0) R7=pkt(id=0,off=0,r=102,imm=0) R8=pkt_end(id=0,off=0,imm=0) R9=inv17 R10=fp0
      67: (63) *(u32 *)(r10 -12) = r5
      68: R0=inv1 R1=inv17 R2=invP2 R3=inv1 R4=pkt(id=0,off=68,r=102,imm=0) R5=inv102 R6=pkt(id=0,off=62,r=102,imm=0) R7=pkt(id=0,off=0,r=102,imm=0) R8=pkt_end(id=0,off=0,imm=0) R9=inv17 R10=fp0 fp-16=mmmm????
      ...
      101: R0_w=map_value_or_null(id=2,off=0,ks=16,vs=1,imm=0) R6_w=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=0,off=0,r=102,imm=0) R8=pkt_end(id=0,off=0,imm=0) R9=inv17 R10=fp0 fp-16=mmmmmmmm
      101: (61) r1 = *(u32 *)(r10 -12)
      102: R0_w=map_value_or_null(id=2,off=0,ks=16,vs=1,imm=0) R1_w=inv(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6_w=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=0,off=0,r=102,imm=0) R8=pkt_end(id=0,off=0,imm=0) R9=inv17 R10=fp0 fp-16=mmmmmmmm
      102: (bc) w1 = w1
      103: R0_w=map_value_or_null(id=2,off=0,ks=16,vs=1,imm=0) R1_w=inv(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6_w=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=0,off=0,r=102,imm=0) R8=pkt_end(id=0,off=0,imm=0) R9=inv17 R10=fp0 fp-16=mmmmmmmm
      103: (0f) r7 += r1
      last_idx 103 first_idx 67
      regs=2 stack=0 before 102: (bc) w1 = w1
      regs=2 stack=0 before 101: (61) r1 = *(u32 *)(r10 -12)
      104: R0_w=map_value_or_null(id=2,off=0,ks=16,vs=1,imm=0) R1_w=invP(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6_w=pkt(id=0,off=70,r=102,imm=0) R7_w=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9=inv17 R10=fp0 fp-16=mmmmmmmm
      ...
      127: R0_w=inv1 R1=invP(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9_w=invP17 R10=fp0 fp-16=mmmmmmmm
      127: (bf) r1 = r7
      128: R0_w=inv1 R1_w=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9_w=invP17 R10=fp0 fp-16=mmmmmmmm
      128: (07) r1 += 8
      129: R0_w=inv1 R1_w=pkt(id=3,off=8,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9_w=invP17 R10=fp0 fp-16=mmmmmmmm
      129: (b4) w0 = 1
      130: R0=inv1 R1=pkt(id=3,off=8,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9=invP17 R10=fp0 fp-16=mmmmmmmm
      130: (2d) if r1 > r8 goto pc-66
       R0=inv1 R1=pkt(id=3,off=8,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9=invP17 R10=fp0 fp-16=mmmmmmmm
      131: R0=inv1 R1=pkt(id=3,off=8,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R6=pkt(id=0,off=70,r=102,imm=0) R7=pkt(id=3,off=0,r=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R8=pkt_end(id=0,off=0,imm=0) R9=invP17 R10=fp0 fp-16=mmmmmmmm
      131: (69) r6 = *(u16 *)(r7 +0)
      invalid access to packet, off=0 size=2, R7(id=3,off=0,r=0)
      R7 offset is outside of the packet
      
      [1]: https://reviews.llvm.org/D109073Signed-off-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20210922004947.626286-1-kafai@fb.com
      54ea6079
  12. 25 9月, 2021 1 次提交
    • Y
      selftests/bpf: Fix btf_dump __int128 test failure with clang build kernel · 091037fb
      Yonghong Song 提交于
      With clang build kernel (adding LLVM=1 to kernel and selftests/bpf build
      command line), I hit the following test failure:
      
        $ ./test_progs -t btf_dump
        ...
        btf_dump_data:PASS:ensure expected/actual match 0 nsec
        btf_dump_data:FAIL:find type id unexpected find type id: actual -2 < expected 0
        btf_dump_data:FAIL:find type id unexpected find type id: actual -2 < expected 0
        test_btf_dump_int_data:FAIL:dump __int128 unexpected error: -2 (errno 2)
        #15/9 btf_dump/btf_dump: int_data:FAIL
      
      Further analysis showed gcc build kernel has type "__int128" in dwarf/BTF
      and it doesn't exist in clang build kernel. Code searching for kernel code
      found the following:
        arch/s390/include/asm/types.h:  unsigned __int128 pair;
        crypto/ecc.c:   unsigned __int128 m = (unsigned __int128)left * right;
        include/linux/math64.h: return (u64)(((unsigned __int128)a * mul) >> shift);
        include/linux/math64.h: return (u64)(((unsigned __int128)a * mul) >> shift);
        lib/ubsan.h:typedef __int128 s_max;
        lib/ubsan.h:typedef unsigned __int128 u_max;
      
      In my case, CONFIG_UBSAN is not enabled. Even if we only have "unsigned __int128"
      in the code, somehow gcc still put "__int128" in dwarf while clang didn't.
      Hence current test works fine for gcc but not for clang.
      
      Enabling CONFIG_UBSAN is an option to provide __int128 type into dwarf
      reliably for both gcc and clang, but not everybody enables CONFIG_UBSAN
      in their kernel build. So the best choice is to use "unsigned __int128" type
      which is available in both clang and gcc build kernels. But clang and gcc
      dwarf encoded names for "unsigned __int128" are different:
      
        [$ ~] cat t.c
        unsigned __int128 a;
        [$ ~] gcc -g -c t.c && llvm-dwarfdump t.o | grep __int128
                        DW_AT_type      (0x00000031 "__int128 unsigned")
                        DW_AT_name      ("__int128 unsigned")
        [$ ~] clang -g -c t.c && llvm-dwarfdump t.o | grep __int128
                        DW_AT_type      (0x00000033 "unsigned __int128")
                        DW_AT_name      ("unsigned __int128")
      
      The test change in this patch tries to test type name before
      doing actual test.
      Signed-off-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NAndrii Nakryiko <andrii@kernel.org>
      Reviewed-by: NAlan Maguire <alan.maguire@oracle.com>
      Link: https://lore.kernel.org/bpf/20210924025856.2192476-1-yhs@fb.com
      091037fb
  13. 24 9月, 2021 1 次提交
    • O
      selftests: KVM: Explicitly use movq to read xmm registers · 386ca9d7
      Oliver Upton 提交于
      Compiling the KVM selftests with clang emits the following warning:
      
      >> include/x86_64/processor.h:297:25: error: variable 'xmm0' is uninitialized when used here [-Werror,-Wuninitialized]
      >>                return (unsigned long)xmm0;
      
      where xmm0 is accessed via an uninitialized register variable.
      
      Indeed, this is a misuse of register variables, which really should only
      be used for specifying register constraints on variables passed to
      inline assembly. Rather than attempting to read xmm registers via
      register variables, just explicitly perform the movq from the desired
      xmm register.
      
      Fixes: 783e9e51 ("kvm: selftests: add API testing infrastructure")
      Signed-off-by: NOliver Upton <oupton@google.com>
      Message-Id: <20210924005147.1122357-1-oupton@google.com>
      Reviewed-by: NRicardo Koller <ricarkol@google.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      386ca9d7