1. 05 Mar, 2020 2 commits
    • Luke Nelson's avatar
      riscv, bpf: Add RV32G eBPF JIT · 5f316b65
      Luke Nelson authored
      This is an eBPF JIT for RV32G, adapted from the JIT for RV64G and
      the 32-bit ARM JIT.
      
      There are two main changes required for this to work compared to
      the RV64 JIT.
      
      First, eBPF registers are 64-bit, while RV32G registers are 32-bit.
      BPF registers either map directly to 2 RISC-V registers, or reside
      in stack scratch space and are saved and restored when used.
      
      Second, many 64-bit ALU operations do not trivially map to 32-bit
      operations. Operations that move bits between high and low words,
      such as ADD, LSH, MUL, and others must emulate the 64-bit behavior
      in terms of 32-bit instructions.
      
      This patch also makes related changes to bpf_jit.h, such
      as adding RISC-V instructions required by the RV32 JIT.
      
      Supported features:
      
      The RV32 JIT supports the same features and instructions as the
      RV64 JIT, with the following exceptions:
      
      - ALU64 DIV/MOD: Requires loops to implement on 32-bit hardware.
      
      - BPF_XADD | BPF_DW: There's no 8-byte atomic instruction in RV32.
      
      These features are also unsupported on other BPF JITs for 32-bit
      architectures.
      
      Testing:
      
      - lib/test_bpf.c
      test_bpf: Summary: 378 PASSED, 0 FAILED, [349/366 JIT'ed]
      test_bpf: test_skb_segment: Summary: 2 PASSED, 0 FAILED
      
      The tests that are not JITed are all due to use of 64-bit div/mod
      or 64-bit xadd.
      
      - tools/testing/selftests/bpf/test_verifier.c
      Summary: 1415 PASSED, 122 SKIPPED, 43 FAILED
      
      Tested both with and without BPF JIT hardening.
      
      This is the same set of tests that pass using the BPF interpreter
      with the JIT disabled.
      
      Verification and synthesis:
      
      We developed the RV32 JIT using our automated verification tool,
      Serval. We have used Serval in the past to verify patches to the
      RV64 JIT. We also used Serval to superoptimize the resulting code
      through program synthesis.
      
      You can find the tool and a guide to the approach and results here:
      https://github.com/uw-unsat/serval-bpf/tree/rv32-jit-v5Co-developed-by: default avatarXi Wang <xi.wang@gmail.com>
      Signed-off-by: default avatarXi Wang <xi.wang@gmail.com>
      Signed-off-by: default avatarLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Acked-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Link: https://lore.kernel.org/bpf/20200305050207.4159-3-luke.r.nels@gmail.com
      5f316b65
    • Luke Nelson's avatar
      riscv, bpf: Factor common RISC-V JIT code · ca6cb544
      Luke Nelson authored
      This patch factors out code that can be used by both the RV64 and RV32
      BPF JITs to a common bpf_jit.h and bpf_jit_core.c.
      
      Move struct definitions and macro-like functions to header. Rename
      rv_sb_insn/rv_uj_insn to rv_b_insn/rv_j_insn to match the RISC-V
      specification.
      
      Move reusable functions emit_body() and bpf_int_jit_compile() to
      bpf_jit_core.c with minor simplifications. Rename emit_insn() and
      build_{prologue,epilogue}() to be prefixed with "bpf_jit_" as they are
      no longer static.
      
      Rename bpf_jit_comp.c to bpf_jit_comp64.c to be more explicit.
      Co-developed-by: default avatarXi Wang <xi.wang@gmail.com>
      Signed-off-by: default avatarXi Wang <xi.wang@gmail.com>
      Signed-off-by: default avatarLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Acked-by: default avatarBjörn Töpel <bjorn.topel@gmail.com>
      Link: https://lore.kernel.org/bpf/20200305050207.4159-2-luke.r.nels@gmail.com
      ca6cb544
  2. 04 Mar, 2020 19 commits
  3. 03 Mar, 2020 11 commits
  4. 02 Mar, 2020 8 commits
    • Jesper Dangaard Brouer's avatar
      mvneta: add XDP ethtool errors stats for TX to driver · 15070919
      Jesper Dangaard Brouer authored
      Adding ethtool stats for when XDP transmitted packets overrun the TX
      queue. This is recorded separately for XDP_TX and ndo_xdp_xmit. This
      is an important aid for troubleshooting XDP based setups.
      
      It is currently a known weakness and property of XDP that there isn't
      any push-back or congestion feedback when transmitting frames via XDP.
      It's easy to realise when redirecting from a higher speed link into a
      slower speed link, or simply two ingress links into a single egress.
      The situation can also happen when Ethernet flow control is active.
      
      For testing the patch and provoking the situation to occur on my
      Espressobin board, I configured the TX-queue to be smaller (434) than
      RX-queue (512) and overload network with large MTU size frames (as a
      larger frame takes longer to transmit).
      
      Hopefully the upcoming XDP TX hook can be extended to provide insight
      into these TX queue overflows, to allow programmable adaptation
      strategies.
      Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
      Acked-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      15070919
    • David S. Miller's avatar
      Merge branch 'net-zl-array' · 0b56a29f
      David S. Miller authored
      More zero-length array transformations from Gustavo A. R. Silva.
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0b56a29f
    • Gustavo A. R. Silva's avatar
      tehuti: Replace zero-length array with flexible-array member · 23640d64
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      23640d64
    • Gustavo A. R. Silva's avatar
      r8152: Replace zero-length array with flexible-array member · ee3bc9c2
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      ee3bc9c2
    • Gustavo A. R. Silva's avatar
      net: atlantic: Replace zero-length array with flexible-array member · 0fcf4666
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0fcf4666
    • Gustavo A. R. Silva's avatar
      bna: bnad: Replace zero-length array with flexible-array member · 8f5c69f9
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      8f5c69f9
    • Gustavo A. R. Silva's avatar
      net: inet_sock: Replace zero-length array with flexible-array member · 48b77df6
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      48b77df6
    • Gustavo A. R. Silva's avatar
      net: ip6_fib: Replace zero-length array with flexible-array member · 6e68f499
      Gustavo A. R. Silva authored
      The current codebase makes use of the zero-length array language
      extension to the C90 standard, but the preferred mechanism to declare
      variable-length types such as these ones is a flexible array member[1][2],
      introduced in C99:
      
      struct foo {
              int stuff;
              struct boo array[];
      };
      
      By making use of the mechanism above, we will get a compiler warning
      in case the flexible array does not occur last in the structure, which
      will help us prevent some kind of undefined behavior bugs from being
      inadvertently introduced[3] to the codebase from now on.
      
      Also, notice that, dynamic memory allocations won't be affected by
      this change:
      
      "Flexible array members have incomplete type, and so the sizeof operator
      may not be applied. As a quirk of the original implementation of
      zero-length arrays, sizeof evaluates to zero."[1]
      
      This issue was found with the help of Coccinelle.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
      [2] https://github.com/KSPP/linux/issues/21
      [3] commit 76497732 ("cxgb3/l2t: Fix undefined behaviour")
      Signed-off-by: default avatarGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      6e68f499