1. 19 Feb, 2020 7 commits
    • Alexei Starovoitov's avatar
      Merge branch 'bpf_read_branch_records' · 03aa3955
      Alexei Starovoitov authored
      Daniel Xu says:
      
      ====================
      Branch records are a CPU feature that can be configured to record
      certain branches that are taken during code execution. This data is
      particularly interesting for profile guided optimizations. perf has had
      branch record support for a while but the data collection can be a bit
      coarse grained.
      
      We (Facebook) have seen in experiments that associating metadata with
      branch records can improve results (after postprocessing). We generally
      use bpf_probe_read_*() to get metadata out of userspace. That's why bpf
      support for branch records is useful.
      
      Aside from this particular use case, having branch data available to bpf
      progs can be useful to get stack traces out of userspace applications
      that omit frame pointers.
      
      Changes in v8:
      - Use globals instead of perf buffer
      - Call test_perf_branches__detach() before destroying skeleton
      - Fix typo in docs
      
      Changes in v7:
      - Const-ify and static-ify local var
      - Documentation formatting
      
      Changes in v6:
      - Move #ifdef a little to avoid unused variable warnings on !x86
      - Test negative condition in selftest (-EINVAL on improperly configured
        perf event)
      - Skip positive condition selftest on setups that don't support branch
        records
      
      Changes in v5:
      - Rename bpf_perf_prog_read_branches() -> bpf_read_branch_records()
      - Rename BPF_F_GET_BR_SIZE -> BPF_F_GET_BRANCH_RECORDS_SIZE
      - Squash tools/ bpf.h sync into selftest commit
      
      Changes in v4:
      - Add BPF_F_GET_BR_SIZE flag
      - Return -ENOENT on unsupported architectures
      - Only accept initialized memory in helper
      - Check buffer size is multiple of sizeof(struct perf_branch_entry)
      - Use bpf skeleton in selftest
      - Add commit messages
      - Spelling and formatting
      
      Changes in v3:
      - Document filling unused buffer with zero
      - Formatting fixes
      - Rebase
      
      Changes in v2:
      - Change to a bpf helper instead of context access
      - Avoid mentioning Intel specific things
      ====================
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      03aa3955
    • Daniel Xu's avatar
      selftests/bpf: Add bpf_read_branch_records() selftest · 67306f84
      Daniel Xu authored
      Add a selftest to test:
      
      * default bpf_read_branch_records() behavior
      * BPF_F_GET_BRANCH_RECORDS_SIZE flag behavior
      * error path on non branch record perf events
      * using helper to write to stack
      * using helper to write to global
      
      On host with hardware counter support:
      
          # ./test_progs -t perf_branches
          #27/1 perf_branches_hw:OK
          #27/2 perf_branches_no_hw:OK
          #27 perf_branches:OK
          Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED
      
      On host without hardware counter support (VM):
      
          # ./test_progs -t perf_branches
          #27/1 perf_branches_hw:OK
          #27/2 perf_branches_no_hw:OK
          #27 perf_branches:OK
          Summary: 1/2 PASSED, 1 SKIPPED, 0 FAILED
      
      Also sync tools/include/uapi/linux/bpf.h.
      Signed-off-by: default avatarDaniel Xu <dxu@dxuuu.xyz>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200218030432.4600-3-dxu@dxuuu.xyz
      67306f84
    • Daniel Xu's avatar
      bpf: Add bpf_read_branch_records() helper · fff7b643
      Daniel Xu authored
      Branch records are a CPU feature that can be configured to record
      certain branches that are taken during code execution. This data is
      particularly interesting for profile guided optimizations. perf has had
      branch record support for a while but the data collection can be a bit
      coarse grained.
      
      We (Facebook) have seen in experiments that associating metadata with
      branch records can improve results (after postprocessing). We generally
      use bpf_probe_read_*() to get metadata out of userspace. That's why bpf
      support for branch records is useful.
      
      Aside from this particular use case, having branch data available to bpf
      progs can be useful to get stack traces out of userspace applications
      that omit frame pointers.
      Signed-off-by: default avatarDaniel Xu <dxu@dxuuu.xyz>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200218030432.4600-2-dxu@dxuuu.xyz
      fff7b643
    • Daniel Borkmann's avatar
      Merge branch 'bpf-skmsg-simplify-restore' · 2f14b2d9
      Daniel Borkmann authored
      Jakub Sitnicki says:
      
      ====================
      This series has been split out from "Extend SOCKMAP to store listening
      sockets" [0]. I think it stands on its own, and makes the latter series
      smaller, which will make the review easier, hopefully.
      
      The essence is that we don't need to do a complicated dance in
      sk_psock_restore_proto, if we agree that the contract with tcp_update_ulp
      is to restore callbacks even when the socket doesn't use ULP. This is what
      tcp_update_ulp currently does, and we just make use of it.
      
      Series is accompanied by a test for a particularly tricky case of restoring
      callbacks when we have both sockmap and tls callbacks configured in
      sk->sk_prot.
      
      [0] https://lore.kernel.org/bpf/20200127131057.150941-1-jakub@cloudflare.com/
      ====================
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      2f14b2d9
    • Jakub Sitnicki's avatar
      selftests/bpf: Test unhashing kTLS socket after removing from map · d1ba1204
      Jakub Sitnicki authored
      When a TCP socket gets inserted into a sockmap, its sk_prot callbacks get
      replaced with tcp_bpf callbacks built from regular tcp callbacks. If TLS
      gets enabled on the same socket, sk_prot callbacks get replaced once again,
      this time with kTLS callbacks built from tcp_bpf callbacks.
      
      Now, we allow removing a socket from a sockmap that has kTLS enabled. After
      removal, socket remains with kTLS configured. This is where things things
      get tricky.
      
      Since the socket has a set of sk_prot callbacks that are a mix of kTLS and
      tcp_bpf callbacks, we need to restore just the tcp_bpf callbacks to the
      original ones. At the moment, it comes down to the the unhash operation.
      
      We had a regression recently because tcp_bpf callbacks were not cleared in
      this particular scenario of removing a kTLS socket from a sockmap. It got
      fixed in commit 4da6a196 ("bpf: Sockmap/tls, during free we may call
      tcp_bpf_unhash() in loop").
      
      Add a test that triggers the regression so that we don't reintroduce it in
      the future.
      Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.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/20200217121530.754315-4-jakub@cloudflare.com
      d1ba1204
    • Jakub Sitnicki's avatar
      bpf, sk_msg: Don't clear saved sock proto on restore · a178b458
      Jakub Sitnicki authored
      There is no need to clear psock->sk_proto when restoring socket protocol
      callbacks in sk->sk_prot. The psock is about to get detached from the sock
      and eventually destroyed. At worst we will restore the protocol callbacks
      and the write callback twice.
      
      This makes reasoning about psock state easier. Once psock is initialized,
      we can count on psock->sk_proto always being set.
      Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.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/20200217121530.754315-3-jakub@cloudflare.com
      a178b458
    • Jakub Sitnicki's avatar
      bpf, sk_msg: Let ULP restore sk_proto and write_space callback · a4393861
      Jakub Sitnicki authored
      We don't need a fallback for when the socket is not using ULP.
      tcp_update_ulp handles this case exactly the same as we do in
      sk_psock_restore_proto. Get rid of the duplicated code.
      Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.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/20200217121530.754315-2-jakub@cloudflare.com
      a4393861
  2. 18 Feb, 2020 7 commits
  3. 17 Feb, 2020 26 commits