1. 21 Aug, 2023 22 commits
  2. 18 Aug, 2023 18 commits
    • Yonghong Song's avatar
      selftests/bpf: Fix a selftest compilation error · 0a55264c
      Yonghong Song authored
      When building the kernel and selftest with clang compiler (llvm17 or llvm18),
      I hit the following compilation failure:
        In file included from progs/test_lwt_redirect.c:3:
        In file included from /usr/include/linux/ip.h:21:
        In file included from /usr/include/asm/byteorder.h:5:
        In file included from /usr/include/linux/byteorder/little_endian.h:13:
        /usr/include/linux/swab.h:136:8: error: unknown type name '__always_inline'
          136 | static __always_inline unsigned long __swab(const unsigned long y)
              |        ^
        /usr/include/linux/swab.h:171:8: error: unknown type name '__always_inline'
          171 | static __always_inline __u16 __swab16p(const __u16 *p)
        ...
      
      bpf_helpers.h file provided a definition for __always_inline.
      Putting 'ip.h' after 'bpf_helpers.h' fixed the issue.
      
      Fixes: 43a7c3ef ("selftests/bpf: Add lwt_xmit tests for BPF_REDIRECT")
      Signed-off-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Link: https://lore.kernel.org/r/20230818174312.1883381-1-yonghong.song@linux.devSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
      0a55264c
    • Dave Marchevsky's avatar
      selftests/bpf: Add CO-RE relocs kfunc flavors tests · 63ae8eb2
      Dave Marchevsky authored
      This patch adds selftests that exercise kfunc flavor relocation
      functionality added in the previous patch. The actual kfunc defined
      in kernel/bpf/helpers.c is:
      
        struct task_struct *bpf_task_acquire(struct task_struct *p)
      
      The following relocation behaviors are checked:
      
        struct task_struct *bpf_task_acquire___one(struct task_struct *name)
          * Should succeed despite differing param name
      
        struct task_struct *bpf_task_acquire___two(struct task_struct *p, void *ctx)
          * Should fail because there is no two-param bpf_task_acquire
      
        struct task_struct *bpf_task_acquire___three(void *ctx)
          * Should fail because, despite vmlinux's bpf_task_acquire having one param,
            the types don't match
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarDavid Vernet <void@manifault.com>
      Link: https://lore.kernel.org/bpf/20230817225353.2570845-2-davemarchevsky@fb.com
      63ae8eb2
    • Dave Marchevsky's avatar
      libbpf: Support triple-underscore flavors for kfunc relocation · 5964a223
      Dave Marchevsky authored
      The function signature of kfuncs can change at any time due to their
      intentional lack of stability guarantees. As kfuncs become more widely
      used, BPF program writers will need facilities to support calling
      different versions of a kfunc from a single BPF object. Consider this
      simplified example based on a real scenario we ran into at Meta:
      
        /* initial kfunc signature */
        int some_kfunc(void *ptr)
      
        /* Oops, we need to add some flag to modify behavior. No problem,
          change the kfunc. flags = 0 retains original behavior */
        int some_kfunc(void *ptr, long flags)
      
      If the initial version of the kfunc is deployed on some portion of the
      fleet and the new version on the rest, a fleetwide service that uses
      some_kfunc will currently need to load different BPF programs depending
      on which some_kfunc is available.
      
      Luckily CO-RE provides a facility to solve a very similar problem,
      struct definition changes, by allowing program writers to declare
      my_struct___old and my_struct___new, with ___suffix being considered a
      'flavor' of the non-suffixed name and being ignored by
      bpf_core_type_exists and similar calls.
      
      This patch extends the 'flavor' facility to the kfunc extern
      relocation process. BPF program writers can now declare
      
        extern int some_kfunc___old(void *ptr)
        extern int some_kfunc___new(void *ptr, int flags)
      
      then test which version of the kfunc exists with bpf_ksym_exists.
      Relocation and verifier's dead code elimination will work in concert as
      expected, allowing this pattern:
      
        if (bpf_ksym_exists(some_kfunc___old))
          some_kfunc___old(ptr);
        else
          some_kfunc___new(ptr, 0);
      Signed-off-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarDavid Vernet <void@manifault.com>
      Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
      Link: https://lore.kernel.org/bpf/20230817225353.2570845-1-davemarchevsky@fb.com
      5964a223
    • Helge Deller's avatar
      bpf/tests: Enhance output on error and fix typos · b6594a17
      Helge Deller authored
      If a testcase returns a wrong (unexpected) value, print the expected and
      returned value in hex notation in addition to the decimal notation.
      
      This is very useful in tests which bit-shift hex values left or right and
      helped me a lot while developing the JIT compiler for the hppa architecture.
      
      Additionally fix two typos: dowrd -> dword, tall calls -> tail calls.
      Signed-off-by: default avatarHelge Deller <deller@gmx.de>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/ZN6ZAAVoWZpsD1Jf@p100
      b6594a17
    • Yan Zhai's avatar
      selftests/bpf: Add lwt_xmit tests for BPF_REROUTE · 6c77997b
      Yan Zhai authored
      There is no lwt test case for BPF_REROUTE yet. Add test cases for both
      normal and abnormal situations. The abnormal situation is set up with an
      fq qdisc on the reroute target device. Without proper fixes, overflow
      this qdisc queue limit (to trigger a drop) would panic the kernel.
      Signed-off-by: default avatarYan Zhai <yan@cloudflare.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/62c8ddc1e924269dcf80d2e8af1a1e632cee0b3a.1692326837.git.yan@cloudflare.com
      6c77997b
    • Yan Zhai's avatar
      selftests/bpf: Add lwt_xmit tests for BPF_REDIRECT · 43a7c3ef
      Yan Zhai authored
      There is no lwt_xmit test case for BPF_REDIRECT yet. Add test cases for
      both normal and abnormal situations. For abnormal test cases, devices
      are set down or have its carrier set down. Without proper fixes,
      BPF_REDIRECT to either ingress or egress of such device would panic the
      kernel.
      Signed-off-by: default avatarYan Zhai <yan@cloudflare.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/96bf435243641939d9c9da329fab29cb45f7df22.1692326837.git.yan@cloudflare.com
      43a7c3ef
    • Yan Zhai's avatar
      lwt: Check LWTUNNEL_XMIT_CONTINUE strictly · a171fbec
      Yan Zhai authored
      LWTUNNEL_XMIT_CONTINUE is implicitly assumed in ip(6)_finish_output2,
      such that any positive return value from a xmit hook could cause
      unexpected continue behavior, despite that related skb may have been
      freed. This could be error-prone for future xmit hook ops. One of the
      possible errors is to return statuses of dst_output directly.
      
      To make the code safer, redefine LWTUNNEL_XMIT_CONTINUE value to
      distinguish from dst_output statuses and check the continue
      condition explicitly.
      
      Fixes: 3a0af8fd ("bpf: BPF for lightweight tunnel infrastructure")
      Suggested-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
      Signed-off-by: default avatarYan Zhai <yan@cloudflare.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/96b939b85eda00e8df4f7c080f770970a4c5f698.1692326837.git.yan@cloudflare.com
      a171fbec
    • Yan Zhai's avatar
      lwt: Fix return values of BPF xmit ops · 29b22bad
      Yan Zhai authored
      BPF encap ops can return different types of positive values, such like
      NET_RX_DROP, NET_XMIT_CN, NETDEV_TX_BUSY, and so on, from function
      skb_do_redirect and bpf_lwt_xmit_reroute. At the xmit hook, such return
      values would be treated implicitly as LWTUNNEL_XMIT_CONTINUE in
      ip(6)_finish_output2. When this happens, skbs that have been freed would
      continue to the neighbor subsystem, causing use-after-free bug and
      kernel crashes.
      
      To fix the incorrect behavior, skb_do_redirect return values can be
      simply discarded, the same as tc-egress behavior. On the other hand,
      bpf_lwt_xmit_reroute returns useful errors to local senders, e.g. PMTU
      information. Thus convert its return values to avoid the conflict with
      LWTUNNEL_XMIT_CONTINUE.
      
      Fixes: 3a0af8fd ("bpf: BPF for lightweight tunnel infrastructure")
      Reported-by: default avatarJordan Griege <jgriege@cloudflare.com>
      Suggested-by: default avatarMartin KaFai Lau <martin.lau@linux.dev>
      Suggested-by: default avatarStanislav Fomichev <sdf@google.com>
      Signed-off-by: default avatarYan Zhai <yan@cloudflare.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/0d2b878186cfe215fec6b45769c1cd0591d3628d.1692326837.git.yan@cloudflare.com
      29b22bad
    • Xu Kuohai's avatar
      selftests/bpf: Enable cpu v4 tests for arm64 · 5f6395fd
      Xu Kuohai authored
      Enable CPU v4 instruction tests for arm64. Below are the test results from
      BPF test_progs selftests:
      
        # ./test_progs -t ldsx_insn,verifier_sdiv,verifier_movsx,verifier_ldsx,verifier_gotol,verifier_bswap
        #115/1   ldsx_insn/map_val and probed_memory:OK
        #115/2   ldsx_insn/ctx_member_sign_ext:OK
        #115/3   ldsx_insn/ctx_member_narrow_sign_ext:OK
        #115     ldsx_insn:OK
        #302/1   verifier_bswap/BSWAP, 16:OK
        #302/2   verifier_bswap/BSWAP, 16 @unpriv:OK
        #302/3   verifier_bswap/BSWAP, 32:OK
        #302/4   verifier_bswap/BSWAP, 32 @unpriv:OK
        #302/5   verifier_bswap/BSWAP, 64:OK
        #302/6   verifier_bswap/BSWAP, 64 @unpriv:OK
        #302     verifier_bswap:OK
        #316/1   verifier_gotol/gotol, small_imm:OK
        #316/2   verifier_gotol/gotol, small_imm @unpriv:OK
        #316     verifier_gotol:OK
        #324/1   verifier_ldsx/LDSX, S8:OK
        #324/2   verifier_ldsx/LDSX, S8 @unpriv:OK
        #324/3   verifier_ldsx/LDSX, S16:OK
        #324/4   verifier_ldsx/LDSX, S16 @unpriv:OK
        #324/5   verifier_ldsx/LDSX, S32:OK
        #324/6   verifier_ldsx/LDSX, S32 @unpriv:OK
        #324/7   verifier_ldsx/LDSX, S8 range checking, privileged:OK
        #324/8   verifier_ldsx/LDSX, S16 range checking:OK
        #324/9   verifier_ldsx/LDSX, S16 range checking @unpriv:OK
        #324/10  verifier_ldsx/LDSX, S32 range checking:OK
        #324/11  verifier_ldsx/LDSX, S32 range checking @unpriv:OK
        #324     verifier_ldsx:OK
        #335/1   verifier_movsx/MOV32SX, S8:OK
        #335/2   verifier_movsx/MOV32SX, S8 @unpriv:OK
        #335/3   verifier_movsx/MOV32SX, S16:OK
        #335/4   verifier_movsx/MOV32SX, S16 @unpriv:OK
        #335/5   verifier_movsx/MOV64SX, S8:OK
        #335/6   verifier_movsx/MOV64SX, S8 @unpriv:OK
        #335/7   verifier_movsx/MOV64SX, S16:OK
        #335/8   verifier_movsx/MOV64SX, S16 @unpriv:OK
        #335/9   verifier_movsx/MOV64SX, S32:OK
        #335/10  verifier_movsx/MOV64SX, S32 @unpriv:OK
        #335/11  verifier_movsx/MOV32SX, S8, range_check:OK
        #335/12  verifier_movsx/MOV32SX, S8, range_check @unpriv:OK
        #335/13  verifier_movsx/MOV32SX, S16, range_check:OK
        #335/14  verifier_movsx/MOV32SX, S16, range_check @unpriv:OK
        #335/15  verifier_movsx/MOV32SX, S16, range_check 2:OK
        #335/16  verifier_movsx/MOV32SX, S16, range_check 2 @unpriv:OK
        #335/17  verifier_movsx/MOV64SX, S8, range_check:OK
        #335/18  verifier_movsx/MOV64SX, S8, range_check @unpriv:OK
        #335/19  verifier_movsx/MOV64SX, S16, range_check:OK
        #335/20  verifier_movsx/MOV64SX, S16, range_check @unpriv:OK
        #335/21  verifier_movsx/MOV64SX, S32, range_check:OK
        #335/22  verifier_movsx/MOV64SX, S32, range_check @unpriv:OK
        #335/23  verifier_movsx/MOV64SX, S16, R10 Sign Extension:OK
        #335/24  verifier_movsx/MOV64SX, S16, R10 Sign Extension @unpriv:OK
        #335     verifier_movsx:OK
        #347/1   verifier_sdiv/SDIV32, non-zero imm divisor, check 1:OK
        #347/2   verifier_sdiv/SDIV32, non-zero imm divisor, check 1 @unpriv:OK
        #347/3   verifier_sdiv/SDIV32, non-zero imm divisor, check 2:OK
        #347/4   verifier_sdiv/SDIV32, non-zero imm divisor, check 2 @unpriv:OK
        #347/5   verifier_sdiv/SDIV32, non-zero imm divisor, check 3:OK
        #347/6   verifier_sdiv/SDIV32, non-zero imm divisor, check 3 @unpriv:OK
        #347/7   verifier_sdiv/SDIV32, non-zero imm divisor, check 4:OK
        #347/8   verifier_sdiv/SDIV32, non-zero imm divisor, check 4 @unpriv:OK
        #347/9   verifier_sdiv/SDIV32, non-zero imm divisor, check 5:OK
        #347/10  verifier_sdiv/SDIV32, non-zero imm divisor, check 5 @unpriv:OK
        #347/11  verifier_sdiv/SDIV32, non-zero imm divisor, check 6:OK
        #347/12  verifier_sdiv/SDIV32, non-zero imm divisor, check 6 @unpriv:OK
        #347/13  verifier_sdiv/SDIV32, non-zero imm divisor, check 7:OK
        #347/14  verifier_sdiv/SDIV32, non-zero imm divisor, check 7 @unpriv:OK
        #347/15  verifier_sdiv/SDIV32, non-zero imm divisor, check 8:OK
        #347/16  verifier_sdiv/SDIV32, non-zero imm divisor, check 8 @unpriv:OK
        #347/17  verifier_sdiv/SDIV32, non-zero reg divisor, check 1:OK
        #347/18  verifier_sdiv/SDIV32, non-zero reg divisor, check 1 @unpriv:OK
        #347/19  verifier_sdiv/SDIV32, non-zero reg divisor, check 2:OK
        #347/20  verifier_sdiv/SDIV32, non-zero reg divisor, check 2 @unpriv:OK
        #347/21  verifier_sdiv/SDIV32, non-zero reg divisor, check 3:OK
        #347/22  verifier_sdiv/SDIV32, non-zero reg divisor, check 3 @unpriv:OK
        #347/23  verifier_sdiv/SDIV32, non-zero reg divisor, check 4:OK
        #347/24  verifier_sdiv/SDIV32, non-zero reg divisor, check 4 @unpriv:OK
        #347/25  verifier_sdiv/SDIV32, non-zero reg divisor, check 5:OK
        #347/26  verifier_sdiv/SDIV32, non-zero reg divisor, check 5 @unpriv:OK
        #347/27  verifier_sdiv/SDIV32, non-zero reg divisor, check 6:OK
        #347/28  verifier_sdiv/SDIV32, non-zero reg divisor, check 6 @unpriv:OK
        #347/29  verifier_sdiv/SDIV32, non-zero reg divisor, check 7:OK
        #347/30  verifier_sdiv/SDIV32, non-zero reg divisor, check 7 @unpriv:OK
        #347/31  verifier_sdiv/SDIV32, non-zero reg divisor, check 8:OK
        #347/32  verifier_sdiv/SDIV32, non-zero reg divisor, check 8 @unpriv:OK
        #347/33  verifier_sdiv/SDIV64, non-zero imm divisor, check 1:OK
        #347/34  verifier_sdiv/SDIV64, non-zero imm divisor, check 1 @unpriv:OK
        #347/35  verifier_sdiv/SDIV64, non-zero imm divisor, check 2:OK
        #347/36  verifier_sdiv/SDIV64, non-zero imm divisor, check 2 @unpriv:OK
        #347/37  verifier_sdiv/SDIV64, non-zero imm divisor, check 3:OK
        #347/38  verifier_sdiv/SDIV64, non-zero imm divisor, check 3 @unpriv:OK
        #347/39  verifier_sdiv/SDIV64, non-zero imm divisor, check 4:OK
        #347/40  verifier_sdiv/SDIV64, non-zero imm divisor, check 4 @unpriv:OK
        #347/41  verifier_sdiv/SDIV64, non-zero imm divisor, check 5:OK
        #347/42  verifier_sdiv/SDIV64, non-zero imm divisor, check 5 @unpriv:OK
        #347/43  verifier_sdiv/SDIV64, non-zero imm divisor, check 6:OK
        #347/44  verifier_sdiv/SDIV64, non-zero imm divisor, check 6 @unpriv:OK
        #347/45  verifier_sdiv/SDIV64, non-zero reg divisor, check 1:OK
        #347/46  verifier_sdiv/SDIV64, non-zero reg divisor, check 1 @unpriv:OK
        #347/47  verifier_sdiv/SDIV64, non-zero reg divisor, check 2:OK
        #347/48  verifier_sdiv/SDIV64, non-zero reg divisor, check 2 @unpriv:OK
        #347/49  verifier_sdiv/SDIV64, non-zero reg divisor, check 3:OK
        #347/50  verifier_sdiv/SDIV64, non-zero reg divisor, check 3 @unpriv:OK
        #347/51  verifier_sdiv/SDIV64, non-zero reg divisor, check 4:OK
        #347/52  verifier_sdiv/SDIV64, non-zero reg divisor, check 4 @unpriv:OK
        #347/53  verifier_sdiv/SDIV64, non-zero reg divisor, check 5:OK
        #347/54  verifier_sdiv/SDIV64, non-zero reg divisor, check 5 @unpriv:OK
        #347/55  verifier_sdiv/SDIV64, non-zero reg divisor, check 6:OK
        #347/56  verifier_sdiv/SDIV64, non-zero reg divisor, check 6 @unpriv:OK
        #347/57  verifier_sdiv/SMOD32, non-zero imm divisor, check 1:OK
        #347/58  verifier_sdiv/SMOD32, non-zero imm divisor, check 1 @unpriv:OK
        #347/59  verifier_sdiv/SMOD32, non-zero imm divisor, check 2:OK
        #347/60  verifier_sdiv/SMOD32, non-zero imm divisor, check 2 @unpriv:OK
        #347/61  verifier_sdiv/SMOD32, non-zero imm divisor, check 3:OK
        #347/62  verifier_sdiv/SMOD32, non-zero imm divisor, check 3 @unpriv:OK
        #347/63  verifier_sdiv/SMOD32, non-zero imm divisor, check 4:OK
        #347/64  verifier_sdiv/SMOD32, non-zero imm divisor, check 4 @unpriv:OK
        #347/65  verifier_sdiv/SMOD32, non-zero imm divisor, check 5:OK
        #347/66  verifier_sdiv/SMOD32, non-zero imm divisor, check 5 @unpriv:OK
        #347/67  verifier_sdiv/SMOD32, non-zero imm divisor, check 6:OK
        #347/68  verifier_sdiv/SMOD32, non-zero imm divisor, check 6 @unpriv:OK
        #347/69  verifier_sdiv/SMOD32, non-zero reg divisor, check 1:OK
        #347/70  verifier_sdiv/SMOD32, non-zero reg divisor, check 1 @unpriv:OK
        #347/71  verifier_sdiv/SMOD32, non-zero reg divisor, check 2:OK
        #347/72  verifier_sdiv/SMOD32, non-zero reg divisor, check 2 @unpriv:OK
        #347/73  verifier_sdiv/SMOD32, non-zero reg divisor, check 3:OK
        #347/74  verifier_sdiv/SMOD32, non-zero reg divisor, check 3 @unpriv:OK
        #347/75  verifier_sdiv/SMOD32, non-zero reg divisor, check 4:OK
        #347/76  verifier_sdiv/SMOD32, non-zero reg divisor, check 4 @unpriv:OK
        #347/77  verifier_sdiv/SMOD32, non-zero reg divisor, check 5:OK
        #347/78  verifier_sdiv/SMOD32, non-zero reg divisor, check 5 @unpriv:OK
        #347/79  verifier_sdiv/SMOD32, non-zero reg divisor, check 6:OK
        #347/80  verifier_sdiv/SMOD32, non-zero reg divisor, check 6 @unpriv:OK
        #347/81  verifier_sdiv/SMOD64, non-zero imm divisor, check 1:OK
        #347/82  verifier_sdiv/SMOD64, non-zero imm divisor, check 1 @unpriv:OK
        #347/83  verifier_sdiv/SMOD64, non-zero imm divisor, check 2:OK
        #347/84  verifier_sdiv/SMOD64, non-zero imm divisor, check 2 @unpriv:OK
        #347/85  verifier_sdiv/SMOD64, non-zero imm divisor, check 3:OK
        #347/86  verifier_sdiv/SMOD64, non-zero imm divisor, check 3 @unpriv:OK
        #347/87  verifier_sdiv/SMOD64, non-zero imm divisor, check 4:OK
        #347/88  verifier_sdiv/SMOD64, non-zero imm divisor, check 4 @unpriv:OK
        #347/89  verifier_sdiv/SMOD64, non-zero imm divisor, check 5:OK
        #347/90  verifier_sdiv/SMOD64, non-zero imm divisor, check 5 @unpriv:OK
        #347/91  verifier_sdiv/SMOD64, non-zero imm divisor, check 6:OK
        #347/92  verifier_sdiv/SMOD64, non-zero imm divisor, check 6 @unpriv:OK
        #347/93  verifier_sdiv/SMOD64, non-zero imm divisor, check 7:OK
        #347/94  verifier_sdiv/SMOD64, non-zero imm divisor, check 7 @unpriv:OK
        #347/95  verifier_sdiv/SMOD64, non-zero imm divisor, check 8:OK
        #347/96  verifier_sdiv/SMOD64, non-zero imm divisor, check 8 @unpriv:OK
        #347/97  verifier_sdiv/SMOD64, non-zero reg divisor, check 1:OK
        #347/98  verifier_sdiv/SMOD64, non-zero reg divisor, check 1 @unpriv:OK
        #347/99  verifier_sdiv/SMOD64, non-zero reg divisor, check 2:OK
        #347/100 verifier_sdiv/SMOD64, non-zero reg divisor, check 2 @unpriv:OK
        #347/101 verifier_sdiv/SMOD64, non-zero reg divisor, check 3:OK
        #347/102 verifier_sdiv/SMOD64, non-zero reg divisor, check 3 @unpriv:OK
        #347/103 verifier_sdiv/SMOD64, non-zero reg divisor, check 4:OK
        #347/104 verifier_sdiv/SMOD64, non-zero reg divisor, check 4 @unpriv:OK
        #347/105 verifier_sdiv/SMOD64, non-zero reg divisor, check 5:OK
        #347/106 verifier_sdiv/SMOD64, non-zero reg divisor, check 5 @unpriv:OK
        #347/107 verifier_sdiv/SMOD64, non-zero reg divisor, check 6:OK
        #347/108 verifier_sdiv/SMOD64, non-zero reg divisor, check 6 @unpriv:OK
        #347/109 verifier_sdiv/SMOD64, non-zero reg divisor, check 7:OK
        #347/110 verifier_sdiv/SMOD64, non-zero reg divisor, check 7 @unpriv:OK
        #347/111 verifier_sdiv/SMOD64, non-zero reg divisor, check 8:OK
        #347/112 verifier_sdiv/SMOD64, non-zero reg divisor, check 8 @unpriv:OK
        #347/113 verifier_sdiv/SDIV32, zero divisor:OK
        #347/114 verifier_sdiv/SDIV32, zero divisor @unpriv:OK
        #347/115 verifier_sdiv/SDIV64, zero divisor:OK
        #347/116 verifier_sdiv/SDIV64, zero divisor @unpriv:OK
        #347/117 verifier_sdiv/SMOD32, zero divisor:OK
        #347/118 verifier_sdiv/SMOD32, zero divisor @unpriv:OK
        #347/119 verifier_sdiv/SMOD64, zero divisor:OK
        #347/120 verifier_sdiv/SMOD64, zero divisor @unpriv:OK
        #347     verifier_sdiv:OK
        Summary: 6/166 PASSED, 0 SKIPPED, 0 FAILED
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarFlorent Revest <revest@chromium.org>
      Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
      Acked-by: default avatarFlorent Revest <revest@chromium.org>
      Link: https://lore.kernel.org/bpf/20230815154158.717901-8-xukuohai@huaweicloud.com
      5f6395fd
    • Xu Kuohai's avatar
    • Xu Kuohai's avatar
      bpf, arm64: Support 32-bit offset jmp instruction · c32b6ee5
      Xu Kuohai authored
      Add support for 32-bit offset jmp instructions. Given the arm64 direct jump
      range is +-128MB, which is large enough for BPF prog, jumps beyond this range
      are not supported.
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarFlorent Revest <revest@chromium.org>
      Acked-by: default avatarFlorent Revest <revest@chromium.org>
      Link: https://lore.kernel.org/bpf/20230815154158.717901-6-xukuohai@huaweicloud.com
      c32b6ee5
    • Xu Kuohai's avatar
      1104247f
    • Xu Kuohai's avatar
      bpf, arm64: Support sign-extension mov instructions · bb0a1d6b
      Xu Kuohai authored
      Add JIT support for BPF sign-extension mov instructions with arm64
      SXTB/SXTH/SXTW instructions.
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarFlorent Revest <revest@chromium.org>
      Acked-by: default avatarFlorent Revest <revest@chromium.org>
      Link: https://lore.kernel.org/bpf/20230815154158.717901-4-xukuohai@huaweicloud.com
      bb0a1d6b
    • Xu Kuohai's avatar
    • Xu Kuohai's avatar
      arm64: insn: Add encoders for LDRSB/LDRSH/LDRSW · 6c9f86d3
      Xu Kuohai authored
      To support BPF sign-extend load instructions, add encoders for
      LDRSB/LDRSH/LDRSW.
      
      LDRSB/LDRSH/LDRSW (immediate) is encoded as follows:
      
           3     2 2   2   2                       1         0         0
           0     7 6   4   2                       0         5         0
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        | sz|1 1 1|0|0 1|opc|        imm12          |    Rn   |    Rt   |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      
      LDRSB/LDRSH/LDRSW (register) is encoded as follows:
      
           3     2 2   2   2 2         1     1 1   1         0         0
           0     7 6   4   2 1         6     3 2   0         5         0
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
        | sz|1 1 1|0|0 0|opc|1|    Rm   | opt |S|1 0|    Rn   |    Rt   |
        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      
      where:
      
         - sz
           indicates whether 8-bit, 16-bit or 32-bit data is to be loaded
      
         - opc
           opc[1] (bit 23) is always 1 and opc[0] == 1 indicates regsize
           is 32-bit. Since BPF signed load instructions always exend the
           sign bit to bit 63 regardless of whether it loads an 8-bit,
           16-bit or 32-bit data. So only 64-bit register size is required.
           That is, it's sufficient to set field opc fixed to 0x2.
      
         - opt
           Indicates whether to sign extend the offset register Rm and the
           effective bits of Rm. We set opt to 0x7 (SXTX) since we'll use
           Rm as a sgined 64-bit value in BPF.
      
         - S
           Optional only when opt field is 0x3 (LSL)
      
      In short, the above fields are encoded to the values listed below.
      
                         sz   opc  opt   S
      LDRSB (immediate)  0x0  0x2  na    na
      LDRSH (immediate)  0x1  0x2  na    na
      LDRSW (immediate)  0x2  0x2  na    na
      LDRSB (register)   0x0  0x2  0x7   0
      LDRSH (register)   0x1  0x2  0x7   0
      LDRSW (register)   0x2  0x2  0x7   0
      Signed-off-by: default avatarXu Kuohai <xukuohai@huawei.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarFlorent Revest <revest@chromium.org>
      Acked-by: default avatarFlorent Revest <revest@chromium.org>
      Link: https://lore.kernel.org/bpf/20230815154158.717901-2-xukuohai@huaweicloud.com
      6c9f86d3
    • Jakub Kicinski's avatar
      Merge branch 'netconsole-enable-compile-time-configuration' · c2e5f4fd
      Jakub Kicinski authored
      Breno Leitao says:
      
      ====================
      netconsole: Enable compile time configuration
      
      Enable netconsole features to be set at compilation time. Create two
      Kconfig options that allow users to set extended logs and release
      prepending features at compilation time.
      
      The first patch de-duplicates the initialization code, and the second
      patch adds the support in the de-duplicated code, avoiding touching two
      different functions with the same change.
      ====================
      
      Link: https://lore.kernel.org/r/20230811093158.1678322-1-leitao@debian.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      c2e5f4fd
    • Breno Leitao's avatar
      netconsole: Enable compile time configuration · fad361a2
      Breno Leitao authored
      Enable netconsole features to be set at compilation time. Create two
      Kconfig options that allow users to set extended logs and release
      prepending features at compilation time.
      
      Right now, the user needs to pass command line parameters to netconsole,
      such as "+"/"r" to enable extended logs and version prepending features.
      
      With these two options, the user could set the default values for the
      features at compile time, and don't need to pass it in the command line
      to get them enabled, simplifying the command line.
      Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Link: https://lore.kernel.org/r/20230811093158.1678322-3-leitao@debian.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      fad361a2
    • Breno Leitao's avatar
      netconsole: Create a allocation helper · b0a9e2c9
      Breno Leitao authored
      De-duplicate the initialization and allocation code for struct
      netconsole_target.
      
      The same allocation and initialization code is duplicated in two
      different places in the netconsole subsystem, when the netconsole target
      is initialized by command line parameters (alloc_param_target()), and
      dynamically by sysfs (make_netconsole_target()).
      
      Create a helper function, and call it from the two different functions.
      Suggested-by: default avatarEric Dumazet <edumazet@google.com>
      Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
      Reviewed-by: default avatarSimon Horman <horms@kernel.org>
      Link: https://lore.kernel.org/r/20230811093158.1678322-2-leitao@debian.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
      b0a9e2c9