1. Apr 02, 2022
  2. Apr 01, 2022
    • Xu Kuohai's avatar
      bpf, tests: Add load store test case for tail call · 38608ee7
      Xu Kuohai authored
      
      
      Add test case to enusre that the caller and callee's fp offsets are
      correct during tail call (mainly asserting for arm64 JIT).
      
      Tested on both big-endian and little-endian arm64 qemu, result:
      
       test_bpf: Summary: 1026 PASSED, 0 FAILED, [1014/1014 JIT'ed]
       test_bpf: test_tail_calls: Summary: 10 PASSED, 0 FAILED, [10/10 JIT'ed]
       test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED
      
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20220321152852.2334294-6-xukuohai@huawei.com
      38608ee7
    • Xu Kuohai's avatar
      bpf, tests: Add tests for BPF_LDX/BPF_STX with different offsets · f516420f
      Xu Kuohai authored
      
      
      This patch adds tests to verify the behavior of BPF_LDX/BPF_STX +
      BPF_B/BPF_H/BPF_W/BPF_DW with negative offset, small positive offset,
      large positive offset, and misaligned offset.
      
      Tested on both big-endian and little-endian arm64 qemu, result:
      
       test_bpf: Summary: 1026 PASSED, 0 FAILED, [1014/1014 JIT'ed]']
       test_bpf: test_tail_calls: Summary: 8 PASSED, 0 FAILED, [8/8 JIT'ed]
       test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED
      
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20220321152852.2334294-5-xukuohai@huawei.com
      f516420f
    • Xu Kuohai's avatar
      bpf, arm64: Adjust the offset of str/ldr(immediate) to positive number · 5b3d19b9
      Xu Kuohai authored
      
      
      The BPF STX/LDX instruction uses offset relative to the FP to address
      stack space. Since the BPF_FP locates at the top of the frame, the offset
      is usually a negative number. However, arm64 str/ldr immediate instruction
      requires that offset be a positive number.  Therefore, this patch tries to
      convert the offsets.
      
      The method is to find the negative offset furthest from the FP firstly.
      Then add it to the FP, calculate a bottom position, called FPB, and then
      adjust the offsets in other STR/LDX instructions relative to FPB.
      
      FPB is saved using the callee-saved register x27 of arm64 which is not
      used yet.
      
      Before adjusting the offset, the patch checks every instruction to ensure
      that the FP does not change in run-time. If the FP may change, no offset
      is adjusted.
      
      For example, for the following bpftrace command:
      
        bpftrace -e 'kprobe:do_sys_open { printf("opening: %s\n", str(arg1)); }'
      
      Without this patch, jited code(fragment):
      
         0:   bti     c
         4:   stp     x29, x30, [sp, #-16]!
         8:   mov     x29, sp
         c:   stp     x19, x20, [sp, #-16]!
        10:   stp     x21, x22, [sp, #-16]!
        14:   stp     x25, x26, [sp, #-16]!
        18:   mov     x25, sp
        1c:   mov     x26, #0x0                       // #0
        20:   bti     j
        24:   sub     sp, sp, #0x90
        28:   add     x19, x0, #0x0
        2c:   mov     x0, #0x0                        // #0
        30:   mov     x10, #0xffffffffffffff78        // #-136
        34:   str     x0, [x25, x10]
        38:   mov     x10, #0xffffffffffffff80        // #-128
        3c:   str     x0, [x25, x10]
        40:   mov     x10, #0xffffffffffffff88        // #-120
        44:   str     x0, [x25, x10]
        48:   mov     x10, #0xffffffffffffff90        // #-112
        4c:   str     x0, [x25, x10]
        50:   mov     x10, #0xffffffffffffff98        // #-104
        54:   str     x0, [x25, x10]
        58:   mov     x10, #0xffffffffffffffa0        // #-96
        5c:   str     x0, [x25, x10]
        60:   mov     x10, #0xffffffffffffffa8        // #-88
        64:   str     x0, [x25, x10]
        68:   mov     x10, #0xffffffffffffffb0        // #-80
        6c:   str     x0, [x25, x10]
        70:   mov     x10, #0xffffffffffffffb8        // #-72
        74:   str     x0, [x25, x10]
        78:   mov     x10, #0xffffffffffffffc0        // #-64
        7c:   str     x0, [x25, x10]
        80:   mov     x10, #0xffffffffffffffc8        // #-56
        84:   str     x0, [x25, x10]
        88:   mov     x10, #0xffffffffffffffd0        // #-48
        8c:   str     x0, [x25, x10]
        90:   mov     x10, #0xffffffffffffffd8        // #-40
        94:   str     x0, [x25, x10]
        98:   mov     x10, #0xffffffffffffffe0        // #-32
        9c:   str     x0, [x25, x10]
        a0:   mov     x10, #0xffffffffffffffe8        // #-24
        a4:   str     x0, [x25, x10]
        a8:   mov     x10, #0xfffffffffffffff0        // #-16
        ac:   str     x0, [x25, x10]
        b0:   mov     x10, #0xfffffffffffffff8        // #-8
        b4:   str     x0, [x25, x10]
        b8:   mov     x10, #0x8                       // #8
        bc:   ldr     x2, [x19, x10]
        [...]
      
      With this patch, jited code(fragment):
      
         0:   bti     c
         4:   stp     x29, x30, [sp, #-16]!
         8:   mov     x29, sp
         c:   stp     x19, x20, [sp, #-16]!
        10:   stp     x21, x22, [sp, #-16]!
        14:   stp     x25, x26, [sp, #-16]!
        18:   stp     x27, x28, [sp, #-16]!
        1c:   mov     x25, sp
        20:   sub     x27, x25, #0x88
        24:   mov     x26, #0x0                       // #0
        28:   bti     j
        2c:   sub     sp, sp, #0x90
        30:   add     x19, x0, #0x0
        34:   mov     x0, #0x0                        // #0
        38:   str     x0, [x27]
        3c:   str     x0, [x27, #8]
        40:   str     x0, [x27, #16]
        44:   str     x0, [x27, #24]
        48:   str     x0, [x27, #32]
        4c:   str     x0, [x27, #40]
        50:   str     x0, [x27, #48]
        54:   str     x0, [x27, #56]
        58:   str     x0, [x27, #64]
        5c:   str     x0, [x27, #72]
        60:   str     x0, [x27, #80]
        64:   str     x0, [x27, #88]
        68:   str     x0, [x27, #96]
        6c:   str     x0, [x27, #104]
        70:   str     x0, [x27, #112]
        74:   str     x0, [x27, #120]
        78:   str     x0, [x27, #128]
        7c:   ldr     x2, [x19, #8]
        [...]
      
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20220321152852.2334294-4-xukuohai@huawei.com
      5b3d19b9
    • Xu Kuohai's avatar
      bpf, arm64: Optimize BPF store/load using arm64 str/ldr(immediate offset) · 7db6c0f1
      Xu Kuohai authored
      
      
      The current BPF store/load instruction is translated by the JIT into two
      instructions. The first instruction moves the immediate offset into a
      temporary register. The second instruction uses this temporary register
      to do the real store/load.
      
      In fact, arm64 supports addressing with immediate offsets. So This patch
      introduces optimization that uses arm64 str/ldr instruction with immediate
      offset when the offset fits.
      
      Example of generated instuction for r2 = *(u64 *)(r1 + 0):
      
      without optimization:
      mov x10, 0
      ldr x1, [x0, x10]
      
      with optimization:
      ldr x1, [x0, 0]
      
      If the offset is negative, or is not aligned correctly, or exceeds max
      value, rollback to the use of temporary register.
      
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20220321152852.2334294-3-xukuohai@huawei.com
      7db6c0f1
    • Xu Kuohai's avatar
      arm64, insn: Add ldr/str with immediate offset · 30c90f67
      Xu Kuohai authored
      
      
      This patch introduces ldr/str with immediate offset support to simplify
      the JIT implementation of BPF LDX/STX instructions on arm64. Although
      arm64 ldr/str immediate is available in pre-index, post-index and
      unsigned offset forms, the unsigned offset form is sufficient for BPF,
      so this patch only adds this type.
      
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/20220321152852.2334294-2-xukuohai@huawei.com
      30c90f67
    • Linus Torvalds's avatar
      Merge tag 'net-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net · 2975dbdc
      Linus Torvalds authored
      Pull more networking updates from Jakub Kicinski:
       "Networking fixes and rethook patches.
      
        Features:
      
         - kprobes: rethook: x86: replace kretprobe trampoline with rethook
      
        Current release - regressions:
      
         - sfc: avoid null-deref on systems without NUMA awareness in the new
           queue sizing code
      
        Current release - new code bugs:
      
         - vxlan: do not feed vxlan_vnifilter_dump_dev with non-vxlan devices
      
         - eth: lan966x: fix null-deref on PHY pointer in timestamp ioctl when
           interface is down
      
        Previous releases - always broken:
      
         - openvswitch: correct neighbor discovery target mask field in the
           flow dump
      
         - wireguard: ignore v6 endpoints when ipv6 is disabled and fix a leak
      
         - rxrpc: fix call timer start racing with call destruction
      
         - rxrpc: fix null-deref when security type is rxrpc_no_security
      
         - can: fix UAF bugs around echo skbs in multiple drivers
      
        Misc:
      
         - docs: move netdev-FAQ to the 'process' section of the
           documentation"
      
      * tag 'net-5.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net: (57 commits)
        vxlan: do not feed vxlan_vnifilter_dump_dev with non vxlan devices
        openvswitch: Add recirc_id to recirc warning
        rxrpc: fix some null-ptr-deref bugs in server_key.c
        rxrpc: Fix call timer start racing with call destruction
        net: hns3: fix software vlan talbe of vlan 0 inconsistent with hardware
        net: hns3: fix the concurrency between functions reading debugfs
        docs: netdev: move the netdev-FAQ to the process pages
        docs: netdev: broaden the new vs old code formatting guidelines
        docs: netdev: call out the merge window in tag checking
        docs: netdev: add missing back ticks
        docs: netdev: make the testing requirement more stringent
        docs: netdev: add a question about re-posting frequency
        docs: netdev: rephrase the 'should I update patchwork' question
        docs: netdev: rephrase the 'Under review' question
        docs: netdev: shorten the name and mention msgid for patch status
        docs: netdev: note that RFC postings are allowed any time
        docs: netdev: turn the net-next closed into a Warning
        docs: netdev: move the patch marking section up
        docs: netdev: minor reword
        docs: netdev: replace references to old archives
        ...
      2975dbdc
    • Linus Torvalds's avatar
      Merge tag 'v5.18-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 · 93235e3d
      Linus Torvalds authored
      Pull crypto fixes from Herbert Xu:
      
       - Missing Kconfig dependency on arm that leads to boot failure
      
       - x86 SLS fixes
      
       - Reference leak in the stm32 driver
      
      * tag 'v5.18-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6:
        crypto: x86/sm3 - Fixup SLS
        crypto: x86/poly1305 - Fixup SLS
        crypto: x86/chacha20 - Avoid spurious jumps to other functions
        crypto: stm32 - fix reference leak in stm32_crc_remove
        crypto: arm/aes-neonbs-cbc - Select generic cbc and aes
      93235e3d
  3. Mar 31, 2022