1. 11 Mar, 2020 2 commits
    • Alexei Starovoitov's avatar
      bpf: Fix trampoline generation for fmod_ret programs · 13fac1d8
      Alexei Starovoitov authored
      fmod_ret progs are emitted as:
      
      start = __bpf_prog_enter();
      call fmod_ret
      *(u64 *)(rbp - 8) = rax
      __bpf_prog_exit(, start);
      test eax, eax
      jne do_fexit
      
      That 'test eax, eax' is working by accident. The compiler is free to use rax
      inside __bpf_prog_exit() or inside functions that __bpf_prog_exit() is calling.
      Which caused "test_progs -t modify_return" to sporadically fail depending on
      compiler version and kconfig. Fix it by using 'cmp [rbp - 8], 0' instead of
      'test eax, eax'.
      
      Fixes: ae240823 ("bpf: Introduce BPF_MODIFY_RETURN")
      Reported-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Acked-by: default avatarKP Singh <kpsingh@google.com>
      Link: https://lore.kernel.org/bpf/20200311003906.3643037-1-ast@kernel.org
      13fac1d8
    • Andrii Nakryiko's avatar
      bpf: Add bpf_link_new_file that doesn't install FD · babf3164
      Andrii Nakryiko authored
      Add bpf_link_new_file() API for cases when we need to ensure anon_inode is
      successfully created before we proceed with expensive BPF program attachment
      procedure, which will require equally (if not more so) expensive and
      potentially failing compensation detachment procedure just because anon_inode
      creation failed. This API allows to simplify code by ensuring first that
      anon_inode is created and after BPF program is attached proceed with
      fd_install() that can't fail.
      
      After anon_inode file is created, link can't be just kfree()'d anymore,
      because its destruction will be performed by deferred file_operations->release
      call. For this, bpf_link API required specifying two separate operations:
      release() and dealloc(), former performing detachment only, while the latter
      frees memory used by bpf_link itself. dealloc() needs to be specified, because
      struct bpf_link is frequently embedded into link type-specific container
      struct (e.g., struct bpf_raw_tp_link), so bpf_link itself doesn't know how to
      properly free the memory. In case when anon_inode file was successfully
      created, but subsequent BPF attachment failed, bpf_link needs to be marked as
      "defunct", so that file's release() callback will perform only memory
      deallocation, but no detachment.
      
      Convert raw tracepoint and tracing attachment to new API and eliminate
      detachment from error handling path.
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/20200309231051.1270337-1-andriin@fb.com
      babf3164
  2. 09 Mar, 2020 16 commits
  3. 05 Mar, 2020 6 commits
  4. 04 Mar, 2020 16 commits