1. 26 May, 2023 2 commits
  2. 25 May, 2023 3 commits
  3. 24 May, 2023 3 commits
    • Andrii Nakryiko's avatar
      Merge branch 'libbpf: capability for resizing datasec maps' · fcf1fa29
      Andrii Nakryiko authored
      JP Kobryn says:
      
      ====================
      Due to the way the datasec maps like bss, data, rodata are memory
      mapped, they cannot be resized with bpf_map__set_value_size() like
      non-datasec maps can. This series offers a way to allow the resizing of
      datasec maps, by having the mapped regions resized as needed and also
      adjusting associated BTF info if possible.
      
      The thought behind this is to allow for use cases where a given datasec
      needs to scale to for example the number of CPU's present. A bpf program
      can have a global array in a data section with an initial length and
      before loading the bpf program, the array length could be extended to
      match the CPU count. The selftests included in this series perform this
      scaling to an arbitrary value to demonstrate how it can work.
      ====================
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      fcf1fa29
    • JP Kobryn's avatar
      libbpf: Selftests for resizing datasec maps · 08b08956
      JP Kobryn authored
      This patch adds test coverage for resizing datasec maps. The first two
      subtests resize the bss and custom data sections. In both cases, an
      initial array (of length one) has its element set to one. After resizing
      the rest of the array is filled with ones as well. A BPF program is then
      run to sum the respective arrays and back on the userspace side the sum
      is checked to be equal to the number of elements.
      The third subtest attempts to perform resizing under conditions that
      will result in either the resize failing or the BTF info being cleared.
      Signed-off-by: default avatarJP Kobryn <inwardvessel@gmail.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarStanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/bpf/20230524004537.18614-3-inwardvessel@gmail.com
      08b08956
    • JP Kobryn's avatar
      libbpf: Add capability for resizing datasec maps · 9d0a2331
      JP Kobryn authored
      This patch updates bpf_map__set_value_size() so that if the given map is
      memory mapped, it will attempt to resize the mapped region. Initial
      contents of the mapped region are preserved. BTF is not required, but
      after the mapping is resized an attempt is made to adjust the associated
      BTF information if the following criteria is met:
       - BTF info is present
       - the map is a datasec
       - the final variable in the datasec is an array
      
      ... the resulting BTF info will be updated so that the final array
      variable is associated with a new BTF array type sized to cover the
      requested size.
      
      Note that the initial resizing of the memory mapped region can succeed
      while the subsequent BTF adjustment can fail. In this case, BTF info is
      dropped from the map by clearing the key and value type.
      Signed-off-by: default avatarJP Kobryn <inwardvessel@gmail.com>
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Acked-by: default avatarStanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/bpf/20230524004537.18614-2-inwardvessel@gmail.com
      9d0a2331
  4. 23 May, 2023 7 commits
  5. 20 May, 2023 10 commits
  6. 19 May, 2023 3 commits
  7. 17 May, 2023 12 commits
    • Yonghong Song's avatar
      selftests/bpf: Make bpf_dynptr_is_rdonly() prototyype consistent with kernel · effcf624
      Yonghong Song authored
      Currently kernel kfunc bpf_dynptr_is_rdonly() has prototype ...
      
        __bpf_kfunc bool bpf_dynptr_is_rdonly(struct bpf_dynptr_kern *ptr)
      
      ... while selftests bpf_kfuncs.h has:
      
        extern int bpf_dynptr_is_rdonly(const struct bpf_dynptr *ptr) __ksym;
      
      Such a mismatch might cause problems although currently it is okay in
      selftests. Fix it to prevent future potential surprise.
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20230517040409.4024618-1-yhs@fb.com
      effcf624
    • Yonghong Song's avatar
      selftests/bpf: Fix dynptr/test_dynptr_is_null · 12852f8e
      Yonghong Song authored
      With latest llvm17, dynptr/test_dynptr_is_null subtest failed in my testing
      VM. The failure log looks like below:
      
        All error logs:
        tester_init:PASS:tester_log_buf 0 nsec
        process_subtest:PASS:obj_open_mem 0 nsec
        process_subtest:PASS:Can't alloc specs array 0 nsec
        verify_success:PASS:dynptr_success__open 0 nsec
        verify_success:PASS:bpf_object__find_program_by_name 0 nsec
        verify_success:PASS:dynptr_success__load 0 nsec
        verify_success:PASS:bpf_program__attach 0 nsec
        verify_success:FAIL:err unexpected err: actual 4 != expected 0
        #65/9    dynptr/test_dynptr_is_null:FAIL
      
      The error happens for bpf prog test_dynptr_is_null in dynptr_success.c:
      
              if (bpf_dynptr_is_null(&ptr2)) {
                      err = 4;
                      goto exit;
              }
      
      The bpf_dynptr_is_null(&ptr) unexpectedly returned a non-zero value and
      the control went to the error path. Digging further, I found the root cause
      is due to function signature difference between kernel and user space.
      
      In kernel, we have ...
      
        __bpf_kfunc bool bpf_dynptr_is_null(struct bpf_dynptr_kern *ptr)
      
      ... while in bpf_kfuncs.h we have:
      
        extern int bpf_dynptr_is_null(const struct bpf_dynptr *ptr) __ksym;
      
      The kernel bpf_dynptr_is_null disasm code:
      
        ffffffff812f1a90 <bpf_dynptr_is_null>:
        ffffffff812f1a90: f3 0f 1e fa           endbr64
        ffffffff812f1a94: 0f 1f 44 00 00        nopl    (%rax,%rax)
        ffffffff812f1a99: 53                    pushq   %rbx
        ffffffff812f1a9a: 48 89 fb              movq    %rdi, %rbx
        ffffffff812f1a9d: e8 ae 29 17 00        callq   0xffffffff81464450 <__asan_load8_noabort>
        ffffffff812f1aa2: 48 83 3b 00           cmpq    $0x0, (%rbx)
        ffffffff812f1aa6: 0f 94 c0              sete    %al
        ffffffff812f1aa9: 5b                    popq    %rbx
        ffffffff812f1aaa: c3                    retq
      
      Note that only 1-byte register %al is set and the other 7-bytes are not
      touched. In bpf program, the asm code for the above bpf_dynptr_is_null(&ptr2):
      
             266:       85 10 00 00 ff ff ff ff call -0x1
             267:       b4 01 00 00 04 00 00 00 w1 = 0x4
             268:       16 00 03 00 00 00 00 00 if w0 == 0x0 goto +0x3 <LBB9_8>
      
      Basically, 4-byte subregister is tested. This might cause error as the value
      other than the lowest byte might not be 0.
      
      This patch fixed the issue by using the identical func prototype across kernel
      and selftest user space. The fixed bpf asm code:
      
             267:       85 10 00 00 ff ff ff ff call -0x1
             268:       54 00 00 00 01 00 00 00 w0 &= 0x1
             269:       b4 01 00 00 04 00 00 00 w1 = 0x4
             270:       16 00 03 00 00 00 00 00 if w0 == 0x0 goto +0x3 <LBB9_8>
      Signed-off-by: default avatarYonghong Song <yhs@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20230517040404.4023912-1-yhs@fb.com
      12852f8e
    • Dave Thaler's avatar
      bpf, docs: Shift operations are defined to use a mask · 8819495a
      Dave Thaler authored
      Update the documentation regarding shift operations to explain the
      use of a mask, since otherwise shifting by a value out of range
      (like negative) is undefined.
      Signed-off-by: default avatarDave Thaler <dthaler@microsoft.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarYonghong Song <yhs@fb.com>
      Link: https://lore.kernel.org/bpf/20230509180845.1236-1-dthaler1968@googlemail.com
      8819495a
    • Pengcheng Yang's avatar
      bpftool: Support bpffs mountpoint as pin path for prog loadall · 2a36c26f
      Pengcheng Yang authored
      Currently, when using prog loadall and the pin path is a bpffs mountpoint,
      bpffs will be repeatedly mounted to the parent directory of the bpffs
      mountpoint path. For example, a `bpftool prog loadall test.o /sys/fs/bpf`
      will trigger this.
      Signed-off-by: default avatarPengcheng Yang <yangpc@wangsu.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
      Link: https://lore.kernel.org/bpf/1683342439-3677-1-git-send-email-yangpc@wangsu.com
      2a36c26f
    • Alexey Gladkov's avatar
      selftests/bpf: Do not use sign-file as testcase · f04a32b2
      Alexey Gladkov authored
      The sign-file utility (from scripts/) is used in prog_tests/verify_pkcs7_sig.c,
      but the utility should not be called as a test. Executing this utility produces
      the following error:
      
        selftests: /linux/tools/testing/selftests/bpf: urandom_read
        ok 16 selftests: /linux/tools/testing/selftests/bpf: urandom_read
      
        selftests: /linux/tools/testing/selftests/bpf: sign-file
        not ok 17 selftests: /linux/tools/testing/selftests/bpf: sign-file # exit=2
      
      Also, urandom_read is mistakenly used as a test. It does not lead to an error,
      but should be moved over to TEST_GEN_FILES as well. The empty TEST_CUSTOM_PROGS
      can then be removed.
      
      Fixes: fc975906 ("selftests/bpf: Add test for bpf_verify_pkcs7_signature() kfunc")
      Signed-off-by: default avatarAlexey Gladkov <legion@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Acked-by: default avatarStanislav Fomichev <sdf@google.com>
      Link: https://lore.kernel.org/bpf/ZEuWFk3QyML9y5QQ@example.org
      Link: https://lore.kernel.org/bpf/88e3ab23029d726a2703adcf6af8356f7a2d3483.1684316821.git.legion@kernel.org
      f04a32b2
    • Andrii Nakryiko's avatar
      bpf: drop unnecessary user-triggerable WARN_ONCE in verifierl log · cff36398
      Andrii Nakryiko authored
      It's trivial for user to trigger "verifier log line truncated" warning,
      as verifier has a fixed-sized buffer of 1024 bytes (as of now), and there are at
      least two pieces of user-provided information that can be output through
      this buffer, and both can be arbitrarily sized by user:
        - BTF names;
        - BTF.ext source code lines strings.
      
      Verifier log buffer should be properly sized for typical verifier state
      output. But it's sort-of expected that this buffer won't be long enough
      in some circumstances. So let's drop the check. In any case code will
      work correctly, at worst truncating a part of a single line output.
      
      Reported-by: syzbot+8b2a08dfbd25fd933d75@syzkaller.appspotmail.com
      Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
      Link: https://lore.kernel.org/r/20230516180409.3549088-1-andrii@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      cff36398
    • Alexei Starovoitov's avatar
      Merge branch 'seltests/xsk: prepare for AF_XDP multi-buffer testing' · 34e78bab
      Alexei Starovoitov authored
      Magnus Karlsson says:
      
      ====================
      Prepare the AF_XDP selftests test framework code for the upcoming
      multi-buffer support in AF_XDP. This so that the multi-buffer patch
      set does not become way too large. In that upcoming patch set, we are
      only including the multi-buffer tests together with any framework
      code that depends on the new options bit introduced in the AF_XDP
      multi-buffer implementation itself.
      
      Currently, the test framework is based on the premise that a packet
      consists of a single fragment and thus occupies a single buffer and a
      single descriptor. Multi-buffer breaks this assumption, as that is the
      whole purpose of it. Now, a packet can consist of multiple buffers and
      therefore consume multiple descriptors.
      
      The patch set starts with some clean-ups and simplifications followed
      by patches that make sure that the current code works even when a
      packet occupies multiple buffers. The actual code for sending and
      receiving multi-buffer packets will be included in the AF_XDP
      multi-buffer patch set as it depends on a new bit being used in the
      options field of the descriptor.
      
      Patch set anatomy:
      1: The XDP program was unnecessarily changed many times. Fixes this.
      
      2: There is no reason to generate a full UDP/IPv4 packet as it is
         never used. Simplify the code by just generating a valid Ethernet
         frame.
      
      3: Introduce a more complicated payload pattern that can detect
         fragments out of bounds in a multi-buffer packet and other errors
         found in single-fragment packets.
      
      4: As a convenience, dump the content of the faulty packet at error.
      
      5: To simplify the code, make the usage of the packet stream for Tx
         and Rx more similar.
      
      6: Store the offset of the packet in the buffer in the struct pkt
         definition instead of the address in the umem itself and introduce
         a simple buffer allocator. The address only made sense when all
         packets consumed a single buffer. Now, we do not know beforehand
         how many buffers a packet will consume, so we instead just allocate
         a buffer from the allocator and specify the offset within that
         buffer.
      
      7: Test for huge pages only once instead of before each test that needs it.
      
      8: Populate the fill ring based on how many frags are needed for each
         packet.
      
      9: Change the data generation code so it can generate data for
         multi-buffer packets too.
      
      10: Adjust the packet pacing algorithm so that it can cope with
          multi-buffer packets. The pacing algorithm is present so that Tx
          does not send too many packets/frames to Rx that it starts to drop
          packets. That would ruin the tests.
      
      v1 -> v2:
      * Fixed spelling error in patch #6 [Simon]
      * Fixed compilation error with llvm in patch #7 [Daniel]
      
      Thanks: Magnus
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      34e78bab
    • Magnus Karlsson's avatar
      selftests/xsk: adjust packet pacing for multi-buffer support · 7cd6df4f
      Magnus Karlsson authored
      Modify the packet pacing algorithm so that it works with multi-buffer
      packets. This algorithm makes sure we do not send too many buffers to
      the receiving thread so that packets have to be dropped. The previous
      algorithm made the assumption that each packet only consumes one
      buffer, but that is not true anymore when multi-buffer support gets
      added. Instead, we find out what the largest packet size is in the
      packet stream and assume that each packet will consume this many
      buffers. This is conservative and overly cautious as there might be
      smaller packets in the stream that need fewer buffers per packet. But
      it keeps the algorithm simple.
      
      Also simplify it by removing the pthread conditional and just test if
      there is enough space in the Rx thread before trying to send one more
      batch. Also makes the tests run faster.
      Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
      Link: https://lore.kernel.org/r/20230516103109.3066-11-magnus.karlsson@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      7cd6df4f
    • Magnus Karlsson's avatar
      selftests/xsk: generate data for multi-buffer packets · 2f6eae0d
      Magnus Karlsson authored
      Add the ability to generate data in the packets that are correct for
      multi-buffer packets. The ethernet header should only go into the
      first fragment followed by data and the others should only have
      data. We also need to modify the pkt_dump function so that it knows
      what fragment has an ethernet header so it can print this.
      Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
      Link: https://lore.kernel.org/r/20230516103109.3066-10-magnus.karlsson@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      2f6eae0d
    • Magnus Karlsson's avatar
      selftests/xsk: populate fill ring based on frags needed · 86e41755
      Magnus Karlsson authored
      Populate the fill ring based on the number of frags a packet
      needs. With multi-buffer support, a packet might require more than a
      single fragment/buffer, so the function xsk_populate_fill_ring() needs
      to consider how many buffers a packet will consume, and put that many
      buffers on the fill ring for each packet it should receive. As we are
      still not sending any multi-buffer packets, the function will only
      produce one buffer per packet at the moment.
      Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
      Link: https://lore.kernel.org/r/20230516103109.3066-9-magnus.karlsson@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      86e41755
    • Magnus Karlsson's avatar
      selftests/xsx: test for huge pages only once · 041b68f6
      Magnus Karlsson authored
      Test for hugepages only once at the beginning of the execution of the
      whole test suite, instead of before each test that needs huge
      pages. These are the tests that use unaligned mode. As more unaligned
      tests will be added, so the current system just does not scale.
      
      With this change, there are now three possible outcomes of a test run:
      fail, pass, or skip. To simplify the handling of this, the function
      testapp_validate_traffic() now returns this value to the main loop. As
      this function is used by nearly all tests, it meant a small change to
      most of them.
      Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
      Link: https://lore.kernel.org/r/20230516103109.3066-8-magnus.karlsson@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      041b68f6
    • Magnus Karlsson's avatar
      selftests/xsk: store offset in pkt instead of addr · d9f6d970
      Magnus Karlsson authored
      Store the offset in struct pkt instead of the address. This is
      important since address is only meaningful in the context of a packet
      that is stored in a single umem buffer and thus a single Tx
      descriptor. If the packet, in contrast need to be represented by
      multiple buffers in the umem, storing the address makes no sense since
      the packet will consist of multiple buffers in the umem at various
      addresses. This change is in preparation for the upcoming
      multi-buffer support in AF_XDP and the corresponding tests.
      
      So instead of indicating the address, we instead indicate the offset
      of the packet in the first buffer. The actual address of the buffer is
      allocated from the umem with a new function called
      umem_alloc_buffer(). This also means we can get rid of the
      use_fill_for_addr flag as the addresses fed into the fill ring will
      always be the offset from the pkt specification in the packet stream
      plus the address of the allocated buffer from the umem. No special
      casing needed.
      Signed-off-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
      Link: https://lore.kernel.org/r/20230516103109.3066-7-magnus.karlsson@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      d9f6d970