1. 05 3月, 2020 2 次提交
    • L
      riscv, bpf: Add RV32G eBPF JIT · 5f316b65
      Luke Nelson 提交于
      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: NXi Wang <xi.wang@gmail.com>
      Signed-off-by: NXi Wang <xi.wang@gmail.com>
      Signed-off-by: NLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: NBjörn Töpel <bjorn.topel@gmail.com>
      Acked-by: NBjörn Töpel <bjorn.topel@gmail.com>
      Link: https://lore.kernel.org/bpf/20200305050207.4159-3-luke.r.nels@gmail.com
      5f316b65
    • L
      riscv, bpf: Factor common RISC-V JIT code · ca6cb544
      Luke Nelson 提交于
      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: NXi Wang <xi.wang@gmail.com>
      Signed-off-by: NXi Wang <xi.wang@gmail.com>
      Signed-off-by: NLuke Nelson <luke.r.nels@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Reviewed-by: NBjörn Töpel <bjorn.topel@gmail.com>
      Acked-by: NBjörn Töpel <bjorn.topel@gmail.com>
      Link: https://lore.kernel.org/bpf/20200305050207.4159-2-luke.r.nels@gmail.com
      ca6cb544
  2. 25 2月, 2020 2 次提交
  3. 20 2月, 2020 1 次提交
  4. 19 2月, 2020 2 次提交
  5. 04 2月, 2020 2 次提交
  6. 29 1月, 2020 1 次提交
  7. 24 1月, 2020 1 次提交
    • Z
      riscv: mm: add support for CONFIG_DEBUG_VIRTUAL · 6435f773
      Zong Li 提交于
      This patch implements CONFIG_DEBUG_VIRTUAL to do additional checks on
      virt_to_phys and __pa_symbol calls. virt_to_phys used for linear mapping
      check, and __pa_symbol used for kernel symbol check. In current RISC-V,
      kernel image maps to linear mapping area. If CONFIG_DEBUG_VIRTUAL is
      disable, these two functions calculate the offset on the address feded
      directly without any checks.
      
      The result of test_debug_virtual as follows:
      
      [    0.358456] ------------[ cut here ]------------
      [    0.358738] virt_to_phys used for non-linear address: (____ptrval____) (0xffffffd000000000)
      [    0.359174] WARNING: CPU: 0 PID: 1 at arch/riscv/mm/physaddr.c:16 __virt_to_phys+0x3c/0x50
      [    0.359409] Modules linked in:
      [    0.359630] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.5.0-rc3-00002-g5133c5c0ca13 #57
      [    0.359861] epc: ffffffe000253d1a ra : ffffffe000253d1a sp : ffffffe03aa87da0
      [    0.360019]  gp : ffffffe000ae03b0 tp : ffffffe03aa88000 t0 : ffffffe000af2660
      [    0.360175]  t1 : 0000000000000064 t2 : 00000000000000b7 s0 : ffffffe03aa87dc0
      [    0.360330]  s1 : ffffffd000000000 a0 : 000000000000004f a1 : 0000000000000000
      [    0.360492]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : ffffffe000a84358
      [    0.360672]  a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000
      [    0.360876]  s2 : ffffffe000ae0600 s3 : ffffffe00000fc7c s4 : ffffffe0000224b0
      [    0.361067]  s5 : ffffffe000030890 s6 : ffffffe000022470 s7 : 0000000000000008
      [    0.361267]  s8 : ffffffe0000002c4 s9 : ffffffe000ae0640 s10: ffffffe000ae0630
      [    0.361453]  s11: 0000000000000000 t3 : 0000000000000000 t4 : 000000000001e6d0
      [    0.361636]  t5 : ffffffe000ae0a18 t6 : ffffffe000aee54e
      [    0.361806] status: 0000000000000120 badaddr: 0000000000000000 cause: 0000000000000003
      [    0.362056] ---[ end trace aec0bf78d4978122 ]---
      [    0.362404] PA: 0xfffffff080200000 for VA: 0xffffffd000000000
      [    0.362607] PA: 0x00000000baddd2d0 for VA: 0xffffffe03abdd2d0
      Signed-off-by: NZong Li <zong.li@sifive.com>
      Reviewed-by: NPaul Walmsley <paul.walmsley@sifive.com>
      Tested-by: NPaul Walmsley <paul.walmsley@sifive.com>
      Signed-off-by: NPalmer Dabbelt <palmerdabbelt@google.com>
      6435f773
  8. 23 1月, 2020 2 次提交
    • O
      riscv: keep 32-bit kernel to 32-bit phys_addr_t · fc76324f
      Olof Johansson 提交于
      While rv32 technically has 34-bit physical addresses, no current platforms
      use it and it's likely to shake out driver bugs.
      
      Let's keep 64-bit phys_addr_t off on 32-bit builds until one shows up,
      since other work will be needed to make such a system useful anyway.
      
      PHYS_ADDR_T_64BIT is def_bool 64BIT, so just remove the select.
      Signed-off-by: NOlof Johansson <olof@lixom.net>
      Signed-off-by: NPalmer Dabbelt <palmerdabbelt@google.com>
      fc76324f
    • N
      riscv: Add KASAN support · 8ad8b727
      Nick Hu 提交于
      This patch ports the feature Kernel Address SANitizer (KASAN).
      
      Note: The start address of shadow memory is at the beginning of kernel
      space, which is 2^64 - (2^39 / 2) in SV39. The size of the kernel space is
      2^38 bytes so the size of shadow memory should be 2^38 / 8. Thus, the
      shadow memory would not overlap with the fixmap area.
      
      There are currently two limitations in this port,
      
      1. RV64 only: KASAN need large address space for extra shadow memory
      region.
      
      2. KASAN can't debug the modules since the modules are allocated in VMALLOC
      area. We mapped the shadow memory, which corresponding to VMALLOC area, to
      the kasan_early_shadow_page because we don't have enough physical space for
      all the shadow memory corresponding to VMALLOC area.
      Signed-off-by: NNick Hu <nickhu@andestech.com>
      Reported-by: NGreentime Hu <green.hu@gmail.com>
      Signed-off-by: NPalmer Dabbelt <palmerdabbelt@google.com>
      8ad8b727
  9. 19 1月, 2020 2 次提交
  10. 16 1月, 2020 1 次提交
  11. 14 1月, 2020 1 次提交
  12. 13 1月, 2020 2 次提交
  13. 07 1月, 2020 1 次提交
  14. 05 1月, 2020 1 次提交
  15. 03 1月, 2020 4 次提交
  16. 28 12月, 2019 3 次提交
    • O
      riscv: export flush_icache_all to modules · 1833e327
      Olof Johansson 提交于
      This is needed by LKDTM (crash dump test module), it calls
      flush_icache_range(), which on RISC-V turns into flush_icache_all(). On
      other architectures, the actual implementation is exported, so follow
      that precedence and export it here too.
      
      Fixes build of CONFIG_LKDTM that fails with:
      ERROR: "flush_icache_all" [drivers/misc/lkdtm/lkdtm.ko] undefined!
      Signed-off-by: NOlof Johansson <olof@lixom.net>
      Signed-off-by: NPaul Walmsley <paul.walmsley@sifive.com>
      1833e327
    • D
      riscv: reject invalid syscalls below -1 · 556f47ac
      David Abdurachmanov 提交于
      Running "stress-ng --enosys 4 -t 20 -v" showed a large number of kernel oops
      with "Unable to handle kernel paging request at virtual address" message. This
      happens when enosys stressor starts testing random non-valid syscalls.
      
      I forgot to redirect any syscall below -1 to sys_ni_syscall.
      
      With the patch kernel oops messages are gone while running stress-ng enosys
      stressor.
      Signed-off-by: NDavid Abdurachmanov <david.abdurachmanov@sifive.com>
      Fixes: 5340627e ("riscv: add support for SECCOMP and SECCOMP_FILTER")
      Signed-off-by: NPaul Walmsley <paul.walmsley@sifive.com>
      556f47ac
    • L
      riscv: fix compile failure with EXPORT_SYMBOL() & !MMU · 4d47ce15
      Luc Van Oostenryck 提交于
      When support for !MMU was added, the declaration of
      __asm_copy_to_user() & __asm_copy_from_user() were #ifdefed
      out hence their EXPORT_SYMBOL() give an error message like:
        .../riscv_ksyms.c:13:15: error: '__asm_copy_to_user' undeclared here
        .../riscv_ksyms.c:14:15: error: '__asm_copy_from_user' undeclared here
      
      Since these symbols are not defined with !MMU it's wrong to export them.
      Same for __clear_user() (even though this one is also declared in
      include/asm-generic/uaccess.h and thus doesn't give an error message).
      
      Fix this by doing the EXPORT_SYMBOL() directly where these symbols
      are defined: inside lib/uaccess.S itself.
      
      Fixes: 6bd33e1e ("riscv: fix compile failure with EXPORT_SYMBOL() & !MMU")
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Palmer Dabbelt <palmer@dabbelt.com>
      Cc: Paul Walmsley <paul.walmsley@sifive.com>
      Signed-off-by: NLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
      Signed-off-by: NPaul Walmsley <paul.walmsley@sifive.com>
      4d47ce15
  17. 20 12月, 2019 5 次提交
  18. 19 12月, 2019 7 次提交