mbox series

[v1,bpf-next,0/9] BPF static branches

Message ID 20240202162813.4184616-1-aspsk@isovalent.com (mailing list archive)
Headers show
Series BPF static branches | expand

Message

Anton Protopopov Feb. 2, 2024, 4:28 p.m. UTC
This series adds support for mapping between xlated and original
instructions offsets, mapping between xlated and jitted instructions
offsets (x86), support for two new BPF instruction JA[SRC=1]
(goto[l]_or_nop) and JA[SRC=3] (nop_or_goto[l]), and a new syscall to
configure the jitted values of such instructions.

This a follow up to the previous attempt to add static keys support
(see [1], [2]) which implements lower-level functionality than what
was proposed before.

The first patch .
The second patch adds xlated -> original mapping.
The third patch adds .

The fourth patch adds support for new instructions.
And the fifth patch adds support for new syscall.

The following patches are included:
  Patch 1 is a formal bug fix
  Patch 2 adds the xlated -> original mapping
  Patch 3 adds the xlated -> jitted mapping
  Patch 4 adds tests for instructions mappings
  Patch 5 adds bpftool support for printing new instructions
  Patch 6 add support for an extended JA instruction
  Patch 7 add support for kernel/bpftool to display new instructions
  Patch 8 adds a new BPF_STATIC_BRANCH_UPDATE syscall
  Patch 9 adds tests for the new ja* instructions and the new syscall

Altogether this provides enough functionality to dynamically patch
programs and support simple static keys.

rfc -> v1:
- converted to v1 based on the feedback (there was none)
- bpftool support was added to dump new instructions
- self-tests were added
- minor fixes & checkpatch warnings

  [1] https://lpc.events/event/17/contributions/1608/attachments/1278/2578/bpf-static-keys.pdf
  [2] https://lore.kernel.org/bpf/20231206141030.1478753-1-aspsk@isovalent.com/
  [3] https://github.com/llvm/llvm-project/pull/75110

Anton Protopopov (9):
  bpf: fix potential error return
  bpf: keep track of and expose xlated insn offsets
  bpf: expose how xlated insns map to jitted insns
  selftests/bpf: Add tests for instructions mappings
  bpftool: dump new fields of bpf prog info
  bpf: add support for an extended JA instruction
  bpf: Add kernel/bpftool asm support for new instructions
  bpf: add BPF_STATIC_BRANCH_UPDATE syscall
  selftests/bpf: Add tests for new ja* instructions

 arch/x86/net/bpf_jit_comp.c                   |  73 ++++-
 include/linux/bpf.h                           |  11 +
 include/linux/bpf_verifier.h                  |   1 -
 include/linux/filter.h                        |   1 +
 include/uapi/linux/bpf.h                      |  26 ++
 kernel/bpf/core.c                             |  67 ++++-
 kernel/bpf/disasm.c                           |  33 ++-
 kernel/bpf/syscall.c                          | 115 ++++++++
 kernel/bpf/verifier.c                         |  58 +++-
 tools/bpf/bpftool/prog.c                      |  14 +
 tools/bpf/bpftool/xlated_dumper.c             |  18 ++
 tools/bpf/bpftool/xlated_dumper.h             |   2 +
 tools/include/uapi/linux/bpf.h                |  26 ++
 .../bpf/prog_tests/bpf_insns_mappings.c       | 156 ++++++++++
 .../bpf/prog_tests/bpf_static_branches.c      | 269 ++++++++++++++++++
 .../selftests/bpf/progs/bpf_insns_mappings.c  | 155 ++++++++++
 16 files changed, 1002 insertions(+), 23 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_insns_mappings.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_static_branches.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_insns_mappings.c

Comments

Andrii Nakryiko Feb. 2, 2024, 10:39 p.m. UTC | #1
On Fri, Feb 2, 2024 at 8:34 AM Anton Protopopov <aspsk@isovalent.com> wrote:
>
> This series adds support for mapping between xlated and original
> instructions offsets, mapping between xlated and jitted instructions
> offsets (x86), support for two new BPF instruction JA[SRC=1]
> (goto[l]_or_nop) and JA[SRC=3] (nop_or_goto[l]), and a new syscall to
> configure the jitted values of such instructions.
>
> This a follow up to the previous attempt to add static keys support
> (see [1], [2]) which implements lower-level functionality than what
> was proposed before.
>
> The first patch .
> The second patch adds xlated -> original mapping.
> The third patch adds .
>
> The fourth patch adds support for new instructions.
> And the fifth patch adds support for new syscall.
>
> The following patches are included:
>   Patch 1 is a formal bug fix
>   Patch 2 adds the xlated -> original mapping
>   Patch 3 adds the xlated -> jitted mapping
>   Patch 4 adds tests for instructions mappings
>   Patch 5 adds bpftool support for printing new instructions
>   Patch 6 add support for an extended JA instruction
>   Patch 7 add support for kernel/bpftool to display new instructions
>   Patch 8 adds a new BPF_STATIC_BRANCH_UPDATE syscall
>   Patch 9 adds tests for the new ja* instructions and the new syscall
>
> Altogether this provides enough functionality to dynamically patch
> programs and support simple static keys.
>
> rfc -> v1:
> - converted to v1 based on the feedback (there was none)
> - bpftool support was added to dump new instructions
> - self-tests were added
> - minor fixes & checkpatch warnings
>
>   [1] https://lpc.events/event/17/contributions/1608/attachments/1278/2578/bpf-static-keys.pdf
>   [2] https://lore.kernel.org/bpf/20231206141030.1478753-1-aspsk@isovalent.com/
>   [3] https://github.com/llvm/llvm-project/pull/75110
>
> Anton Protopopov (9):
>   bpf: fix potential error return
>   bpf: keep track of and expose xlated insn offsets
>   bpf: expose how xlated insns map to jitted insns
>   selftests/bpf: Add tests for instructions mappings
>   bpftool: dump new fields of bpf prog info
>   bpf: add support for an extended JA instruction
>   bpf: Add kernel/bpftool asm support for new instructions
>   bpf: add BPF_STATIC_BRANCH_UPDATE syscall
>   selftests/bpf: Add tests for new ja* instructions
>
>  arch/x86/net/bpf_jit_comp.c                   |  73 ++++-
>  include/linux/bpf.h                           |  11 +
>  include/linux/bpf_verifier.h                  |   1 -
>  include/linux/filter.h                        |   1 +
>  include/uapi/linux/bpf.h                      |  26 ++
>  kernel/bpf/core.c                             |  67 ++++-
>  kernel/bpf/disasm.c                           |  33 ++-
>  kernel/bpf/syscall.c                          | 115 ++++++++
>  kernel/bpf/verifier.c                         |  58 +++-
>  tools/bpf/bpftool/prog.c                      |  14 +
>  tools/bpf/bpftool/xlated_dumper.c             |  18 ++
>  tools/bpf/bpftool/xlated_dumper.h             |   2 +
>  tools/include/uapi/linux/bpf.h                |  26 ++
>  .../bpf/prog_tests/bpf_insns_mappings.c       | 156 ++++++++++
>  .../bpf/prog_tests/bpf_static_branches.c      | 269 ++++++++++++++++++
>  .../selftests/bpf/progs/bpf_insns_mappings.c  | 155 ++++++++++
>  16 files changed, 1002 insertions(+), 23 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_insns_mappings.c
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_static_branches.c
>  create mode 100644 tools/testing/selftests/bpf/progs/bpf_insns_mappings.c
>
> --
> 2.34.1
>

This fails to build in CI ([0]). I'll take a look at the patches next
week, sorry for the delay.

  [0] https://github.com/kernel-patches/bpf/actions/runs/7762232524/job/21172303431?pr=6380#step:11:77
Anton Protopopov Feb. 4, 2024, 4:05 p.m. UTC | #2
On Fri, Feb 02, 2024 at 02:39:24PM -0800, Andrii Nakryiko wrote:
> On Fri, Feb 2, 2024 at 8:34 AM Anton Protopopov <aspsk@isovalent.com> wrote:
> >
> > This series adds support for mapping between xlated and original
> > instructions offsets, mapping between xlated and jitted instructions
> > offsets (x86), support for two new BPF instruction JA[SRC=1]
> > (goto[l]_or_nop) and JA[SRC=3] (nop_or_goto[l]), and a new syscall to
> > configure the jitted values of such instructions.
> >
> > This a follow up to the previous attempt to add static keys support
> > (see [1], [2]) which implements lower-level functionality than what
> > was proposed before.
> >
> > The first patch .
> > The second patch adds xlated -> original mapping.
> > The third patch adds .
> >
> > The fourth patch adds support for new instructions.
> > And the fifth patch adds support for new syscall.
> >
> > The following patches are included:
> >   Patch 1 is a formal bug fix
> >   Patch 2 adds the xlated -> original mapping
> >   Patch 3 adds the xlated -> jitted mapping
> >   Patch 4 adds tests for instructions mappings
> >   Patch 5 adds bpftool support for printing new instructions
> >   Patch 6 add support for an extended JA instruction
> >   Patch 7 add support for kernel/bpftool to display new instructions
> >   Patch 8 adds a new BPF_STATIC_BRANCH_UPDATE syscall
> >   Patch 9 adds tests for the new ja* instructions and the new syscall
> >
> > Altogether this provides enough functionality to dynamically patch
> > programs and support simple static keys.
> >
> > rfc -> v1:
> > - converted to v1 based on the feedback (there was none)
> > - bpftool support was added to dump new instructions
> > - self-tests were added
> > - minor fixes & checkpatch warnings
> >
> >   [1] https://lpc.events/event/17/contributions/1608/attachments/1278/2578/bpf-static-keys.pdf
> >   [2] https://lore.kernel.org/bpf/20231206141030.1478753-1-aspsk@isovalent.com/
> >   [3] https://github.com/llvm/llvm-project/pull/75110
> >
> > Anton Protopopov (9):
> >   bpf: fix potential error return
> >   bpf: keep track of and expose xlated insn offsets
> >   bpf: expose how xlated insns map to jitted insns
> >   selftests/bpf: Add tests for instructions mappings
> >   bpftool: dump new fields of bpf prog info
> >   bpf: add support for an extended JA instruction
> >   bpf: Add kernel/bpftool asm support for new instructions
> >   bpf: add BPF_STATIC_BRANCH_UPDATE syscall
> >   selftests/bpf: Add tests for new ja* instructions
> >
> >  arch/x86/net/bpf_jit_comp.c                   |  73 ++++-
> >  include/linux/bpf.h                           |  11 +
> >  include/linux/bpf_verifier.h                  |   1 -
> >  include/linux/filter.h                        |   1 +
> >  include/uapi/linux/bpf.h                      |  26 ++
> >  kernel/bpf/core.c                             |  67 ++++-
> >  kernel/bpf/disasm.c                           |  33 ++-
> >  kernel/bpf/syscall.c                          | 115 ++++++++
> >  kernel/bpf/verifier.c                         |  58 +++-
> >  tools/bpf/bpftool/prog.c                      |  14 +
> >  tools/bpf/bpftool/xlated_dumper.c             |  18 ++
> >  tools/bpf/bpftool/xlated_dumper.h             |   2 +
> >  tools/include/uapi/linux/bpf.h                |  26 ++
> >  .../bpf/prog_tests/bpf_insns_mappings.c       | 156 ++++++++++
> >  .../bpf/prog_tests/bpf_static_branches.c      | 269 ++++++++++++++++++
> >  .../selftests/bpf/progs/bpf_insns_mappings.c  | 155 ++++++++++
> >  16 files changed, 1002 insertions(+), 23 deletions(-)
> >  create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_insns_mappings.c
> >  create mode 100644 tools/testing/selftests/bpf/prog_tests/bpf_static_branches.c
> >  create mode 100644 tools/testing/selftests/bpf/progs/bpf_insns_mappings.c
> >
> > --
> > 2.34.1
> >
> 
> This fails to build in CI ([0]). I'll take a look at the patches next
> week, sorry for the delay.

Thanks Andrii!

>   [0] https://github.com/kernel-patches/bpf/actions/runs/7762232524/job/21172303431?pr=6380#step:11:77

Thanks, I will push a fix for this and some more fixes in v2 (besides
this doc build failure there's a missing mutex for poking text and
one NULL deref).