BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 00/13] Enhance BPF global subprogs with argument tags
@ 2023-12-04 23:39 Andrii Nakryiko
  2023-12-04 23:39 ` [PATCH bpf-next 01/13] bpf: log PTR_TO_MEM memory size in verifier log Andrii Nakryiko
                   ` (12 more replies)
  0 siblings, 13 replies; 40+ messages in thread
From: Andrii Nakryiko @ 2023-12-04 23:39 UTC (permalink / raw)
  To: bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team

This patch set adds verifier support for annotating user's global BPF subprog
arguments with few commonly requested annotations, to improve global subprog
verification experience.

These tags are:
  - ability to annotate a special PTR_TO_CTX argument;
  - ability to annotate a generic PTR_TO_MEM as non-null;
  - ability to annotate special PTR_TO_PACKET, PTR_TO_PACKET_END, and
    PTR_TO_PACKET_META pointers for networking programs;
  - ability to annotate argument as CONST_PTR_TO_DYNPTR to pass generic
    dynptrs into global subprogs, for use cases that deal with variable-sized
    generic memory pointers.

We utilize btf_decl_tag attribute for this and provide few helper macros as
part of bpf_helpers.h in libbpf (patch #12).

Patches #1 and #2 are tiny improvements to verifier log, printing relevant
information for PTR_TO_MEM and dynptr. Those missing pieces came up during
development of this patch set.

Big chunk of the patch set (patches #3 through #9) are various refactorings to
make verifier internals around global subprog validation logic easier to
extend and support long term, eliminating BTF parsing logic duplication,
factoring out argument expectation definitions from BTF parsing, etc.

New functionality is added in patch #10 (ctx, non-null, pkt pointers) and
patch #11 (dynptr), extending global subprog checks with awareness for arg
tags.

Patch #12 adds simple macro helpers for arg tags to standardize their usage
across BPF code base.

Patch #13 adds simple tests validating each of the added tags.

Andrii Nakryiko (13):
  bpf: log PTR_TO_MEM memory size in verifier log
  bpf: emit more dynptr information in verifier log
  bpf: tidy up exception callback management a bit
  bpf: use bitfields for simple per-subprog bool flags
  bpf: abstract away global subprog arg preparation logic from reg state
    setup
  bpf: remove unnecessary and (mostly) ignored BTF check for main
    program
  bpf: prepare btf_prepare_func_args() for handling static subprogs
  bpf: move subprog call logic back to verifier.c
  bpf: reuse subprog argument parsing logic for subprog call checks
  bpf: support 'arg:xxx' btf_decl_tag-based hints for global subprog
    args
  bpf: add dynptr global subprog arg tag support
  libbpf: add __arg_xxx macros for annotating global func args
  selftests/bpf: add global subprog annotation tests

 include/linux/bpf.h                           |  12 +-
 include/linux/bpf_verifier.h                  |  41 ++-
 kernel/bpf/btf.c                              | 291 +++++-------------
 kernel/bpf/log.c                              |  29 +-
 kernel/bpf/verifier.c                         | 221 +++++++++++--
 tools/lib/bpf/bpf_helpers.h                   |   9 +
 .../selftests/bpf/prog_tests/log_fixup.c      |   4 +-
 .../selftests/bpf/progs/cgrp_kfunc_failure.c  |   2 +-
 .../selftests/bpf/progs/task_kfunc_failure.c  |   2 +-
 .../selftests/bpf/progs/test_global_func5.c   |   2 +-
 .../bpf/progs/verifier_global_subprogs.c      | 134 +++++++-
 11 files changed, 459 insertions(+), 288 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2023-12-06 18:47 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04 23:39 [PATCH bpf-next 00/13] Enhance BPF global subprogs with argument tags Andrii Nakryiko
2023-12-04 23:39 ` [PATCH bpf-next 01/13] bpf: log PTR_TO_MEM memory size in verifier log Andrii Nakryiko
2023-12-05 23:23   ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 02/13] bpf: emit more dynptr information " Andrii Nakryiko
2023-12-05 23:24   ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 03/13] bpf: tidy up exception callback management a bit Andrii Nakryiko
2023-12-05 23:25   ` Eduard Zingerman
2023-12-06 17:59   ` Andrii Nakryiko
2023-12-04 23:39 ` [PATCH bpf-next 04/13] bpf: use bitfields for simple per-subprog bool flags Andrii Nakryiko
2023-12-05 23:25   ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 05/13] bpf: abstract away global subprog arg preparation logic from reg state setup Andrii Nakryiko
2023-12-05 23:21   ` Eduard Zingerman
2023-12-06 17:59     ` Andrii Nakryiko
2023-12-04 23:39 ` [PATCH bpf-next 06/13] bpf: remove unnecessary and (mostly) ignored BTF check for main program Andrii Nakryiko
2023-12-05 23:21   ` Eduard Zingerman
2023-12-06 17:59     ` Andrii Nakryiko
2023-12-06 18:05       ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 07/13] bpf: prepare btf_prepare_func_args() for handling static subprogs Andrii Nakryiko
2023-12-05 23:26   ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 08/13] bpf: move subprog call logic back to verifier.c Andrii Nakryiko
2023-12-05  8:01   ` kernel test robot
2023-12-05 18:57     ` Andrii Nakryiko
2023-12-05  9:04   ` kernel test robot
2023-12-05 11:46   ` kernel test robot
2023-12-05 23:27   ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 09/13] bpf: reuse subprog argument parsing logic for subprog call checks Andrii Nakryiko
2023-12-05 10:21   ` kernel test robot
2023-12-05 11:25   ` kernel test robot
2023-12-05 23:21   ` Eduard Zingerman
2023-12-06 18:05     ` Andrii Nakryiko
2023-12-04 23:39 ` [PATCH bpf-next 10/13] bpf: support 'arg:xxx' btf_decl_tag-based hints for global subprog args Andrii Nakryiko
2023-12-05 23:22   ` Eduard Zingerman
2023-12-06 18:15     ` Andrii Nakryiko
2023-12-06 18:47       ` Eduard Zingerman
2023-12-04 23:39 ` [PATCH bpf-next 11/13] bpf: add dynptr global subprog arg tag support Andrii Nakryiko
2023-12-05 23:22   ` Eduard Zingerman
2023-12-06 18:17     ` Andrii Nakryiko
2023-12-04 23:39 ` [PATCH bpf-next 12/13] libbpf: add __arg_xxx macros for annotating global func args Andrii Nakryiko
2023-12-04 23:39 ` [PATCH bpf-next 13/13] selftests/bpf: add global subprog annotation tests Andrii Nakryiko
2023-12-05 23:29   ` Eduard Zingerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox