Skip to contentSkip to conversation

First set of verifier/*.c migrated to inline assembly

PATCH In review Eduard Zingerman 6 participants 60 messages Mar 25, 2023 – Mar 29, 2023

Subsystems (4)
lore
Share & tools
lore

Eduard Zingerman

author maintainer
#0 lore raw

cover First set of verifier/*.c migrated to inline assembly

This is a follow up for RFC [1]. It migrates a first batch of 38 verifier/*.c tests to inline assembly and use of ./test_progs for actual execution. The migration is done by a python script (see [2]).

Each migrated verifier/xxx.c file is mapped to progs/verifier_xxx.c plus an entry in the prog_tests/verifier.c. One patch per each file.

A few patches at the beginning of the patch-set extend test_loader with necessary functionality, mainly:
- support for tests execution in unprivileged mode;
- support for test runs for test programs.

Migrated tests could be selected for execution using the following filter:

./test_progs -a verifier_*

An example of the migrated test:

  SEC("xdp")
  __description("XDP pkt read, pkt_data' > pkt_end, corner case, good access")
  __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
  __naked void end_corner_case_good_access_1(void)
  {
          asm volatile ("                                 \
          r2 = *(u32*)(r1 + %[xdp_md_data]);              \
          r3 = *(u32*)(r1 + %[xdp_md_data_end]);          \
          r1 = r2;                                        \
          r1 += 8;                                        \
          if r1 > r3 goto l0_%=;                          \
          r0 = *(u64*)(r1 - 8);                           \
  l0_%=:  r0 = 0;                                         \
          exit;                                           \
  "       :
          : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
            __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
          : __clobber_all);
  }

Changes compared to RFC:
- test_loader.c is extended to support test program runs;
- capabilities handling now matches behavior of test_verifier;
- BPF_ST_MEM instructions are automatically replaced by BPF_STX_MEM instructions to overcome current clang limitations;
- tests styling updates according to RFC feedback;
- 38 migrated files are included instead of 1.

I used the following means for testing:
- migration tool itself has a set of self-tests;
- migrated tests are passing;
- manually compared each old/new file side-by-side.

While doing side-by-side comparison I've noted a few defects in the original tests:
- and.c:
- One of the jump targets is off by one;
- BPF_ST_MEM wrong OFF/IMM ordering;
- array_access.c:
- BPF_ST_MEM wrong OFF/IMM ordering;
- value_or_null.c:
- BPF_ST_MEM wrong OFF/IMM ordering.

These defects would be addressed separately.

[1] RFC

    https://lore.kernel.org/bpf/[email protected]/

[2] Migration tool
https://github.com/eddyz87/verifier-tests-migrator

Eduard Zingerman (43):
selftests/bpf: Report program name on parse_test_spec error selftests/bpf: __imm_insn & __imm_const macro for bpf_misc.h selftests/bpf: Unprivileged tests for test_loader.c selftests/bpf: Tests execution support for test_loader.c selftests/bpf: prog_tests entry point for migrated test_verifier tests selftests/bpf: verifier/and.c converted to inline assembly selftests/bpf: verifier/array_access.c converted to inline assembly selftests/bpf: verifier/basic_stack.c converted to inline assembly selftests/bpf: verifier/bounds_deduction.c converted to inline
assembly
selftests/bpf: verifier/bounds_mix_sign_unsign.c converted to inline
assembly
selftests/bpf: verifier/cfg.c converted to inline assembly selftests/bpf: verifier/cgroup_inv_retcode.c converted to inline
assembly
selftests/bpf: verifier/cgroup_skb.c converted to inline assembly selftests/bpf: verifier/cgroup_storage.c converted to inline assembly selftests/bpf: verifier/const_or.c converted to inline assembly selftests/bpf: verifier/ctx_sk_msg.c converted to inline assembly selftests/bpf: verifier/direct_stack_access_wraparound.c converted to
inline assembly
selftests/bpf: verifier/div0.c converted to inline assembly selftests/bpf: verifier/div_overflow.c converted to inline assembly selftests/bpf: verifier/helper_access_var_len.c converted to inline
assembly
selftests/bpf: verifier/helper_packet_access.c converted to inline
assembly
selftests/bpf: verifier/helper_restricted.c converted to inline
assembly
selftests/bpf: verifier/helper_value_access.c converted to inline
assembly
selftests/bpf: verifier/int_ptr.c converted to inline assembly selftests/bpf: verifier/ld_ind.c converted to inline assembly selftests/bpf: verifier/leak_ptr.c converted to inline assembly selftests/bpf: verifier/map_ptr.c converted to inline assembly selftests/bpf: verifier/map_ret_val.c converted to inline assembly selftests/bpf: verifier/masking.c converted to inline assembly selftests/bpf: verifier/meta_access.c converted to inline assembly selftests/bpf: verifier/raw_stack.c converted to inline assembly selftests/bpf: verifier/raw_tp_writable.c converted to inline assembly selftests/bpf: verifier/ringbuf.c converted to inline assembly selftests/bpf: verifier/spill_fill.c converted to inline assembly selftests/bpf: verifier/stack_ptr.c converted to inline assembly selftests/bpf: verifier/uninit.c converted to inline assembly selftests/bpf: verifier/value_adj_spill.c converted to inline assembly selftests/bpf: verifier/value.c converted to inline assembly selftests/bpf: verifier/value_or_null.c converted to inline assembly selftests/bpf: verifier/var_off.c converted to inline assembly selftests/bpf: verifier/xadd.c converted to inline assembly selftests/bpf: verifier/xdp.c converted to inline assembly selftests/bpf: verifier/xdp_direct_packet_access.c converted to inline
assembly

 tools/testing/selftests/bpf/Makefile          |   10 +-
 tools/testing/selftests/bpf/autoconf_helper.h |    9 +
 .../selftests/bpf/prog_tests/verifier.c       |  106 +
 tools/testing/selftests/bpf/progs/bpf_misc.h  |   42 +
 .../selftests/bpf/progs/verifier_and.c        |  107 +
 .../bpf/progs/verifier_array_access.c         |  529 +++++
 .../bpf/progs/verifier_basic_stack.c          |  100 +
 .../bpf/progs/verifier_bounds_deduction.c     |  171 ++
 .../progs/verifier_bounds_mix_sign_unsign.c   |  554 ++++++
 .../selftests/bpf/progs/verifier_cfg.c        |  100 +
 .../bpf/progs/verifier_cgroup_inv_retcode.c   |   89 +
 .../selftests/bpf/progs/verifier_cgroup_skb.c |  227 +++
 .../bpf/progs/verifier_cgroup_storage.c       |  308 +++
 .../selftests/bpf/progs/verifier_const_or.c   |   82 +
 .../selftests/bpf/progs/verifier_ctx_sk_msg.c |  228 +++
 .../verifier_direct_stack_access_wraparound.c |   56 +
 .../selftests/bpf/progs/verifier_div0.c       |  213 ++
 .../bpf/progs/verifier_div_overflow.c         |  144 ++
 .../progs/verifier_helper_access_var_len.c    |  825 ++++++++
 .../bpf/progs/verifier_helper_packet_access.c |  550 ++++++
 .../bpf/progs/verifier_helper_restricted.c    |  279 +++
 .../bpf/progs/verifier_helper_value_access.c  | 1245 ++++++++++++
 .../selftests/bpf/progs/verifier_int_ptr.c    |  157 ++
 .../selftests/bpf/progs/verifier_ld_ind.c     |  110 ++
 .../selftests/bpf/progs/verifier_leak_ptr.c   |   92 +
 .../selftests/bpf/progs/verifier_map_ptr.c    |  159 ++
 .../bpf/progs/verifier_map_ret_val.c          |  110 ++
 .../selftests/bpf/progs/verifier_masking.c    |  410 ++++
 .../bpf/progs/verifier_meta_access.c          |  284 +++
 .../selftests/bpf/progs/verifier_raw_stack.c  |  371 ++++
 .../bpf/progs/verifier_raw_tp_writable.c      |   50 +
 .../selftests/bpf/progs/verifier_ringbuf.c    |  131 ++
 .../selftests/bpf/progs/verifier_spill_fill.c |  374 ++++
 .../selftests/bpf/progs/verifier_stack_ptr.c  |  484 +++++
 .../selftests/bpf/progs/verifier_uninit.c     |   61 +
 .../selftests/bpf/progs/verifier_value.c      |  158 ++
 .../bpf/progs/verifier_value_adj_spill.c      |   78 +
 .../bpf/progs/verifier_value_or_null.c        |  288 +++
 .../selftests/bpf/progs/verifier_var_off.c    |  349 ++++
 .../selftests/bpf/progs/verifier_xadd.c       |  124 ++
 .../selftests/bpf/progs/verifier_xdp.c        |   24 +
 .../progs/verifier_xdp_direct_packet_access.c | 1722 +++++++++++++++++
 tools/testing/selftests/bpf/test_loader.c     |  536 ++++-
 tools/testing/selftests/bpf/test_verifier.c   |   25 +-
 tools/testing/selftests/bpf/unpriv_helpers.c  |   26 +
 tools/testing/selftests/bpf/unpriv_helpers.h  |    7 +
 tools/testing/selftests/bpf/verifier/and.c    |   68 -
 .../selftests/bpf/verifier/array_access.c     |  379 ----
 .../selftests/bpf/verifier/basic_stack.c      |   64 -
 .../selftests/bpf/verifier/bounds_deduction.c |  136 --
 .../bpf/verifier/bounds_mix_sign_unsign.c     |  411 ----
 tools/testing/selftests/bpf/verifier/cfg.c    |   73 -
 .../bpf/verifier/cgroup_inv_retcode.c         |   72 -
 .../selftests/bpf/verifier/cgroup_skb.c       |  197 --
 .../selftests/bpf/verifier/cgroup_storage.c   |  220 ---
 .../testing/selftests/bpf/verifier/const_or.c |   60 -
 .../selftests/bpf/verifier/ctx_sk_msg.c       |  181 --
 .../verifier/direct_stack_access_wraparound.c |   40 -
 tools/testing/selftests/bpf/verifier/div0.c   |  184 --
 .../selftests/bpf/verifier/div_overflow.c     |  110 --
 .../bpf/verifier/helper_access_var_len.c      |  650 -------
 .../bpf/verifier/helper_packet_access.c       |  460 -----
 .../bpf/verifier/helper_restricted.c          |  196 --
 .../bpf/verifier/helper_value_access.c        |  953 ---------
 .../testing/selftests/bpf/verifier/int_ptr.c  |  161 --
 tools/testing/selftests/bpf/verifier/ld_ind.c |   72 -
 .../testing/selftests/bpf/verifier/leak_ptr.c |   67 -
 .../testing/selftests/bpf/verifier/map_ptr.c  |   99 -
 .../selftests/bpf/verifier/map_ret_val.c      |   65 -
 .../testing/selftests/bpf/verifier/masking.c  |  322 ---
 .../selftests/bpf/verifier/meta_access.c      |  235 ---
 .../selftests/bpf/verifier/raw_stack.c        |  305 ---
 .../selftests/bpf/verifier/raw_tp_writable.c  |   35 -
 .../testing/selftests/bpf/verifier/ringbuf.c  |   95 -
 .../selftests/bpf/verifier/spill_fill.c       |  345 ----
 .../selftests/bpf/verifier/stack_ptr.c        |  359 ----
 tools/testing/selftests/bpf/verifier/uninit.c |   39 -
 tools/testing/selftests/bpf/verifier/value.c  |  104 -
 .../selftests/bpf/verifier/value_adj_spill.c  |   43 -
 .../selftests/bpf/verifier/value_or_null.c    |  220 ---
 .../testing/selftests/bpf/verifier/var_off.c  |  291 ---
 tools/testing/selftests/bpf/verifier/xadd.c   |   97 -
 tools/testing/selftests/bpf/verifier/xdp.c    |   14 -
 .../bpf/verifier/xdp_direct_packet_access.c   | 1468 --------------
 84 files changed, 11994 insertions(+), 9000 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/autoconf_helper.h
 create mode 100644 tools/testing/selftests/bpf/prog_tests/verifier.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_and.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_array_access.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_basic_stack.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_bounds_deduction.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_bounds_mix_sign_unsign.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cfg.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup_inv_retcode.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup_skb.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup_storage.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_const_or.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_ctx_sk_msg.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_direct_stack_access_wraparound.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_div0.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_div_overflow.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_packet_access.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_restricted.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_value_access.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_int_ptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_ld_ind.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_leak_ptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_map_ptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_map_ret_val.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_masking.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_meta_access.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_raw_stack.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_ringbuf.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_spill_fill.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_stack_ptr.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_uninit.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_value.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_value_adj_spill.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_value_or_null.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_var_off.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_xadd.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_xdp.c
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
 create mode 100644 tools/testing/selftests/bpf/unpriv_helpers.c
 create mode 100644 tools/testing/selftests/bpf/unpriv_helpers.h
 delete mode 100644 tools/testing/selftests/bpf/verifier/and.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/array_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/basic_stack.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/bounds_deduction.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/bounds_mix_sign_unsign.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cfg.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_inv_retcode.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_skb.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_storage.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/const_or.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/ctx_sk_msg.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/direct_stack_access_wraparound.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/div0.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/div_overflow.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_access_var_len.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_packet_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_restricted.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_value_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/int_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/ld_ind.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/leak_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/map_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/map_ret_val.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/masking.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/meta_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/raw_stack.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/raw_tp_writable.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/ringbuf.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/spill_fill.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/stack_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/uninit.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/value.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/value_adj_spill.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/value_or_null.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/var_off.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/xadd.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/xdp.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/xdp_direct_packet_access.c
Signature · 1 line
2.40.0
author maintainer
#1 lore raw

PATCH 1/43 selftests/bpf: Report program name on parse_test_spec error

Change test_loader.c:run_subtest() behavior to show BPF program name when test spec for that program can't be parsed.

---
 tools/testing/selftests/bpf/test_loader.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/test_loader.c +4 -1
index bf41390157bf..8ca5121b5329 100644
@@ -232,8 +232,11 @@ void run_subtest(struct test_loader *tester,
 
 		/* if we can't derive test specification, go to the next test */
 		err = parse_test_spec(tester, obj, prog, &spec);
-		if (!ASSERT_OK(err, "parse_test_spec"))
+		if (err) {
+			PRINT_FAIL("Can't parse test spec for program '%s'\n",
+				   bpf_program__name(prog));
 			continue;
+		}
 
 		tobj = bpf_object__open_mem(obj_bytes, obj_byte_cnt, &open_opts);
 		if (!ASSERT_OK_PTR(tobj, "obj_open_mem")) /* shouldn't happen */
Signature · 1 line
2.40.0
author maintainer
#2 lore raw

PATCH 2/43 selftests/bpf: __imm_insn & __imm_const macro for bpf_misc.h

In reply to Eduard Zingerman

Add two convenience macro for BPF test cases,
allowing the following usage:

  #include <linux/filter.h>

...
asm volatile (
...
".8byte %[raw_insn];"
...
"r1 += %[st_foo_offset];"
...
:
: __imm_insn(raw_insn, BPF_RAW_INSN(...)),
__imm_const(st_foo_offset, offsetof(struct st, foo))
: __clobber_all);

---
 tools/testing/selftests/bpf/progs/bpf_misc.h | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/progs/bpf_misc.h +2 -0
index 3c03ec8056ce..8b4681a96f89 100644
@@ -35,8 +35,10 @@
 #define __clobber_all "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "memory"
 #define __clobber_common "r0", "r1", "r2", "r3", "r4", "r5", "memory"
 #define __imm(name) [name]"i"(name)
+#define __imm_const(name, expr) [name]"i"(expr)
 #define __imm_addr(name) [name]"i"(&name)
 #define __imm_ptr(name) [name]"p"(&name)
+#define __imm_insn(name, expr) [name]"i"(*(long *)&(expr))
 
 #if defined(__TARGET_ARCH_x86)
 #define SYSCALL_WRAPPER 1
Signature · 1 line
2.40.0
author maintainer
#3 lore raw

PATCH 3/43 selftests/bpf: Unprivileged tests for test_loader.c

In reply to Eduard Zingerman

Extends test_loader.c:test_loader__run_subtests() by allowing to execute tests in unprivileged mode, similar to test_verifier.c.

Adds the following new attributes controlling test_loader behavior:

__msg_unpriv
__success_unpriv
__failure_unpriv

* If any of these attributes is present the test would be loaded in unprivileged mode.
* If only "privileged" attributes are present the test would be loaded only in privileged mode.
* If both "privileged" and "unprivileged" attributes are present the test would be loaded in both modes.
* If test has to be executed in both modes, __msg(text) is specified and __msg_unpriv is not specified the behavior is the same as if __msg_unpriv(text) is specified.
* For test filtering purposes the name of the program loaded in unprivileged mode is derived from the usual program name by adding `@unpriv' suffix.

Also adds attribute '__description'. This attribute specifies text to be used instead of a program name for display and filtering purposes.

---
 tools/testing/selftests/bpf/Makefile          |  10 +-
 tools/testing/selftests/bpf/autoconf_helper.h |   9 +
 tools/testing/selftests/bpf/progs/bpf_misc.h  |  25 ++
 tools/testing/selftests/bpf/test_loader.c     | 394 ++++++++++++++----
 tools/testing/selftests/bpf/test_verifier.c   |  25 +-
 tools/testing/selftests/bpf/unpriv_helpers.c  |  26 ++
 tools/testing/selftests/bpf/unpriv_helpers.h  |   7 +
 7 files changed, 395 insertions(+), 101 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/autoconf_helper.h
 create mode 100644 tools/testing/selftests/bpf/unpriv_helpers.c
 create mode 100644 tools/testing/selftests/bpf/unpriv_helpers.h
tools/testing/selftests/bpf/Makefile +6 -4
index fc092582d16d..4a8ef118fd9d 100644
@@ -231,8 +231,9 @@ TEST_GEN_PROGS_EXTENDED += $(TRUNNER_BPFTOOL)
 
 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(BPFOBJ)
 
-CGROUP_HELPERS	:= $(OUTPUT)/cgroup_helpers.o
 TESTING_HELPERS	:= $(OUTPUT)/testing_helpers.o
+CGROUP_HELPERS	:= $(OUTPUT)/cgroup_helpers.o
+UNPRIV_HELPERS  := $(OUTPUT)/unpriv_helpers.o
 TRACE_HELPERS	:= $(OUTPUT)/trace_helpers.o
 JSON_WRITER		:= $(OUTPUT)/json_writer.o
 CAP_HELPERS	:= $(OUTPUT)/cap_helpers.o
@@ -252,7 +253,7 @@ $(OUTPUT)/test_lirc_mode2_user: $(TESTING_HELPERS)
 $(OUTPUT)/xdping: $(TESTING_HELPERS)
 $(OUTPUT)/flow_dissector_load: $(TESTING_HELPERS)
 $(OUTPUT)/test_maps: $(TESTING_HELPERS)
-$(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS)
+$(OUTPUT)/test_verifier: $(TESTING_HELPERS) $(CAP_HELPERS) $(UNPRIV_HELPERS)
 $(OUTPUT)/xsk.o: $(BPFOBJ)
 
 BPFTOOL ?= $(DEFAULT_BPFTOOL)
@@ -560,8 +561,9 @@ TRUNNER_BPF_PROGS_DIR := progs
 TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c	\
 			 network_helpers.c testing_helpers.c		\
 			 btf_helpers.c flow_dissector_load.h		\
-			 cap_helpers.c test_loader.c xsk.c disasm.c \
-			 json_writer.c
+			 cap_helpers.c test_loader.c xsk.c disasm.c	\
+			 json_writer.c unpriv_helpers.c
+
 TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko	\
 		       $(OUTPUT)/liburandom_read.so			\
 		       $(OUTPUT)/xdp_synproxy				\
tools/testing/selftests/bpf/autoconf_helper.h new file +9 -0
new file mode 100644
index 000000000000..5b243b9cdf8c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#ifdef HAVE_GENHDR
+# include "autoconf.h"
+#else
+# if defined(__i386) || defined(__x86_64) || defined(__s390x__) || defined(__aarch64__)
+#  define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 1
+# endif
+#endif
tools/testing/selftests/bpf/progs/bpf_misc.h +25 -0
index 8b4681a96f89..9defc217a5bd 100644
@@ -5,12 +5,33 @@
 /* This set of attributes controls behavior of the
  * test_loader.c:test_loader__run_subtests().
  *
+ * The test_loader sequentially loads each program in a skeleton.
+ * Programs could be loaded in privileged and unprivileged modes.
+ * - __success, __failure, __msg imply privileged mode;
+ * - __success_unpriv, __failure_unpriv, __msg_unpriv imply
+ *   unprivileged mode.
+ * If combination of privileged and unprivileged attributes is present
+ * both modes are used. If none are present privileged mode is implied.
+ *
+ * See test_loader.c:drop_capabilities() for exact set of capabilities
+ * that differ between privileged and unprivileged modes.
+ *
+ * For test filtering purposes the name of the program loaded in
+ * unprivileged mode is derived from the usual program name by adding
+ * `@unpriv' suffix.
+ *
  * __msg             Message expected to be found in the verifier log.
  *                   Multiple __msg attributes could be specified.
+ * __msg_unpriv      Same as __msg but for unprivileged mode.
  *
  * __success         Expect program load success in privileged mode.
+ * __success_unpriv  Expect program load success in unprivileged mode.
  *
  * __failure         Expect program load failure in privileged mode.
+ * __failure_unpriv  Expect program load failure in unprivileged mode.
+ *
+ * __description     Text to be used instead of a program name for display
+ *                   and filtering purposes.
  *
  * __log_level       Log level to use for the program, numeric value expected.
  *
@@ -27,6 +48,10 @@
 #define __msg(msg)		__attribute__((btf_decl_tag("comment:test_expect_msg=" msg)))
 #define __failure		__attribute__((btf_decl_tag("comment:test_expect_failure")))
 #define __success		__attribute__((btf_decl_tag("comment:test_expect_success")))
+#define __description(desc)	__attribute__((btf_decl_tag("comment:test_description=" desc)))
+#define __msg_unpriv(msg)	__attribute__((btf_decl_tag("comment:test_expect_msg_unpriv=" msg)))
+#define __failure_unpriv	__attribute__((btf_decl_tag("comment:test_expect_failure_unpriv")))
+#define __success_unpriv	__attribute__((btf_decl_tag("comment:test_expect_success_unpriv")))
 #define __log_level(lvl)	__attribute__((btf_decl_tag("comment:test_log_level="#lvl)))
 #define __flag(flag)		__attribute__((btf_decl_tag("comment:test_prog_flags="#flag)))
 
tools/testing/selftests/bpf/test_loader.c +320 -74

528 lines not on this page · raw message

tools/testing/selftests/bpf/test_verifier.c +2 -23
index 49a70d9beb0b..5b90eef09ade 100644
@@ -33,13 +33,8 @@
 #include <bpf/bpf.h>
 #include <bpf/libbpf.h>
 
-#ifdef HAVE_GENHDR
-# include "autoconf.h"
-#else
-# if defined(__i386) || defined(__x86_64) || defined(__s390x__) || defined(__aarch64__)
-#  define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS 1
-# endif
-#endif
+#include "autoconf_helper.h"
+#include "unpriv_helpers.h"
 #include "cap_helpers.h"
 #include "bpf_rand.h"
 #include "bpf_util.h"
@@ -1665,22 +1660,6 @@ static bool is_admin(void)
 	return (caps & ADMIN_CAPS) == ADMIN_CAPS;
 }
 
-static void get_unpriv_disabled()
-{
-	char buf[2];
-	FILE *fd;
-
-	fd = fopen("/proc/sys/"UNPRIV_SYSCTL, "r");
-	if (!fd) {
-		perror("fopen /proc/sys/"UNPRIV_SYSCTL);
-		unpriv_disabled = true;
-		return;
-	}
-	if (fgets(buf, 2, fd) == buf && atoi(buf))
-		unpriv_disabled = true;
-	fclose(fd);
-}
-
 static bool test_as_unpriv(struct bpf_test *test)
 {
 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
tools/testing/selftests/bpf/unpriv_helpers.c new file +26 -0
new file mode 100644
index 000000000000..2a6efbd0401e
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <error.h>
+#include <stdio.h>
+
+#include "unpriv_helpers.h"
+
+bool get_unpriv_disabled(void)
+{
+	bool disabled;
+	char buf[2];
+	FILE *fd;
+
+	fd = fopen("/proc/sys/" UNPRIV_SYSCTL, "r");
+	if (fd) {
+		disabled = (fgets(buf, 2, fd) == buf && atoi(buf));
+		fclose(fd);
+	} else {
+		perror("fopen /proc/sys/" UNPRIV_SYSCTL);
+		disabled = true;
+	}
+
+	return disabled;
+}
tools/testing/selftests/bpf/unpriv_helpers.h new file +7 -0
new file mode 100644
index 000000000000..151f67329665
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <stdbool.h>
+
+#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
+
+bool get_unpriv_disabled(void);
Signature · 1 line
2.40.0
author maintainer
#4 lore raw

PATCH 4/43 selftests/bpf: Tests execution support for test_loader.c

In reply to Eduard Zingerman

Extends test_loader.c:test_loader__run_subtests() by allowing to execute BPF_PROG_TEST_RUN bpf command for selected programs. This is similar to functionality provided by test_verifier.

Adds the following new attributes controlling test_loader behavior:

__retval(...)
__retval_unpriv(...)

* If any of these attributes is present, the annotated program would be executed using libbpf's bpf_prog_test_run_opts() function.
* If __retval is present, the test run would be done for program loaded in privileged mode.
* If __retval_unpriv is present, the test run would be done for program loaded in unprivileged mode.
* To mimic test_verifier behavior, the actual run is initiated in privileged mode.
* The value returned by a test run is compared against retval parameter.

The retval attribute takes one of the following parameters:
- a decimal number
- a hexadecimal number (must start from '0x')
- any of a three special literals (provided for compatibility with test_verifier):
- INT_MIN
- POINTER_VALUE
- TEST_DATA_LEN

An example of the attribute usage:

  SEC("socket")
  __description("return 42")
  __success __success_unpriv __retval(42)
  __naked void the_42_test(void)
  {
          asm volatile ("                                 \
          r0 = 42;                                        \
          exit;                                           \
  "       ::: __clobber_all);
  }
---
 tools/testing/selftests/bpf/progs/bpf_misc.h |  15 ++
 tools/testing/selftests/bpf/test_loader.c    | 149 +++++++++++++++++--
 2 files changed, 150 insertions(+), 14 deletions(-)
tools/testing/selftests/bpf/progs/bpf_misc.h +15 -0
index 9defc217a5bd..6e3b4903c541 100644
@@ -30,6 +30,15 @@
  * __failure         Expect program load failure in privileged mode.
  * __failure_unpriv  Expect program load failure in unprivileged mode.
  *
+ * __retval          Execute the program using BPF_PROG_TEST_RUN command,
+ *                   expect return value to match passed parameter:
+ *                   - a decimal number
+ *                   - a hexadecimal number, when starts from 0x
+ *                   - literal INT_MIN
+ *                   - literal POINTER_VALUE (see definition below)
+ *                   - literal TEST_DATA_LEN (see definition below)
+ * __retval_unpriv   Same, but load program in unprivileged mode.
+ *
  * __description     Text to be used instead of a program name for display
  *                   and filtering purposes.
  *
@@ -54,6 +63,8 @@
 #define __success_unpriv	__attribute__((btf_decl_tag("comment:test_expect_success_unpriv")))
 #define __log_level(lvl)	__attribute__((btf_decl_tag("comment:test_log_level="#lvl)))
 #define __flag(flag)		__attribute__((btf_decl_tag("comment:test_prog_flags="#flag)))
+#define __retval(val)		__attribute__((btf_decl_tag("comment:test_retval="#val)))
+#define __retval_unpriv(val)	__attribute__((btf_decl_tag("comment:test_retval_unpriv="#val)))
 
 /* Convenience macro for use with 'asm volatile' blocks */
 #define __naked __attribute__((naked))
@@ -65,6 +76,10 @@
 #define __imm_ptr(name) [name]"p"(&name)
 #define __imm_insn(name, expr) [name]"i"(*(long *)&(expr))
 
+/* Magic constants used with __retval() */
+#define POINTER_VALUE	0xcafe4all
+#define TEST_DATA_LEN	64
+
 #if defined(__TARGET_ARCH_x86)
 #define SYSCALL_WRAPPER 1
 #define SYS_PREFIX "__x64_"
tools/testing/selftests/bpf/test_loader.c +135 -14

219 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#5 lore raw

PATCH 5/43 selftests/bpf: prog_tests entry point for migrated test_verifier tests

In reply to Eduard Zingerman

prog_tests/verifier.c would be used as a host for verifier/*.c tests migrated to use inline assembly and run from test_progs.

The run_test_aux() function mimics the test_verifier behavior dropping CAP_SYS_ADMIN upon entry.

---
 .../selftests/bpf/prog_tests/verifier.c       | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/verifier.c
tools/testing/selftests/bpf/prog_tests/verifier.c new file +29 -0
new file mode 100644
index 000000000000..aa63f5d84d97
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <test_progs.h>
+
+#include "cap_helpers.h"
+
+__maybe_unused
+static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
+{
+	struct test_loader tester = {};
+	__u64 old_caps;
+	int err;
+
+	/* test_verifier tests are executed w/o CAP_SYS_ADMIN, do the same here */
+	err = cap_disable_effective(1ULL << CAP_SYS_ADMIN, &old_caps);
+	if (err) {
+		PRINT_FAIL("failed to drop CAP_SYS_ADMIN: %i, %s\n", err, strerror(err));
+		return;
+	}
+
+	test_loader__run_subtests(&tester, skel_name, elf_bytes_factory);
+	test_loader_fini(&tester);
+
+	err = cap_enable_effective(old_caps, NULL);
+	if (err)
+		PRINT_FAIL("failed to restore CAP_SYS_ADMIN: %i, %s\n", err, strerror(err));
+}
+
+#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes)
Signature · 1 line
2.40.0
author maintainer
#6 lore raw

PATCH 6/43 selftests/bpf: verifier/and.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/and.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   3 +
 .../selftests/bpf/progs/verifier_and.c        | 107 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/and.c    |  68 -----------
 3 files changed, 110 insertions(+), 68 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_and.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/and.c
tools/testing/selftests/bpf/prog_tests/verifier.c +3 -0
index aa63f5d84d97..34526f6d5ab1 100644
@@ -3,6 +3,7 @@
 #include <test_progs.h>
 
 #include "cap_helpers.h"
+#include "verifier_and.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -27,3 +28,5 @@ static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_fac
 }
 
 #define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes)
+
+void test_verifier_and(void)                  { RUN(verifier_and); }
tools/testing/selftests/bpf/progs/verifier_and.c new file +107 -0

107 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/and.c deleted +0 -68

68 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#7 lore raw

PATCH 7/43 selftests/bpf: verifier/array_access.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/array_access.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_array_access.c         | 529 ++++++++++++++++++
 .../selftests/bpf/verifier/array_access.c     | 379 -------------
 3 files changed, 531 insertions(+), 379 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_array_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/array_access.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 34526f6d5ab1..60eb0f38ed92 100644
@@ -4,6 +4,7 @@
 
 #include "cap_helpers.h"
 #include "verifier_and.skel.h"
+#include "verifier_array_access.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -30,3 +31,4 @@ static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_fac
 #define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes)
 
 void test_verifier_and(void)                  { RUN(verifier_and); }
+void test_verifier_array_access(void)         { RUN(verifier_array_access); }
tools/testing/selftests/bpf/progs/verifier_array_access.c new file +529 -0

529 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/array_access.c deleted +0 -379

379 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#8 lore raw

PATCH 8/43 selftests/bpf: verifier/basic_stack.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/basic_stack.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_basic_stack.c          | 100 ++++++++++++++++++
 .../selftests/bpf/verifier/basic_stack.c      |  64 -----------
 3 files changed, 102 insertions(+), 64 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_basic_stack.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/basic_stack.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 60eb0f38ed92..95a3151db052 100644
@@ -5,6 +5,7 @@
 #include "cap_helpers.h"
 #include "verifier_and.skel.h"
 #include "verifier_array_access.skel.h"
+#include "verifier_basic_stack.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -32,3 +33,4 @@ static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_fac
 
 void test_verifier_and(void)                  { RUN(verifier_and); }
 void test_verifier_array_access(void)         { RUN(verifier_array_access); }
+void test_verifier_basic_stack(void)          { RUN(verifier_basic_stack); }
tools/testing/selftests/bpf/progs/verifier_basic_stack.c new file +100 -0

100 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/basic_stack.c deleted +0 -64

64 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#9 lore raw

PATCH 9/43 selftests/bpf: verifier/bounds_deduction.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/bounds_deduction.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_bounds_deduction.c     | 171 ++++++++++++++++++
 .../selftests/bpf/verifier/bounds_deduction.c | 136 --------------
 3 files changed, 173 insertions(+), 136 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_bounds_deduction.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/bounds_deduction.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 95a3151db052..a8cfef92ed64 100644
@@ -6,6 +6,7 @@
 #include "verifier_and.skel.h"
 #include "verifier_array_access.skel.h"
 #include "verifier_basic_stack.skel.h"
+#include "verifier_bounds_deduction.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -34,3 +35,4 @@ static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_fac
 void test_verifier_and(void)                  { RUN(verifier_and); }
 void test_verifier_array_access(void)         { RUN(verifier_array_access); }
 void test_verifier_basic_stack(void)          { RUN(verifier_basic_stack); }
+void test_verifier_bounds_deduction(void)     { RUN(verifier_bounds_deduction); }
tools/testing/selftests/bpf/progs/verifier_bounds_deduction.c new file +171 -0

171 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/bounds_deduction.c deleted +0 -136

136 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#10 lore raw

PATCH 10/43 selftests/bpf: verifier/bounds_mix_sign_unsign.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/bounds_mix_sign_unsign.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../progs/verifier_bounds_mix_sign_unsign.c   | 554 ++++++++++++++++++
 .../bpf/verifier/bounds_mix_sign_unsign.c     | 411 -------------
 3 files changed, 556 insertions(+), 411 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_bounds_mix_sign_unsign.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/bounds_mix_sign_unsign.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index a8cfef92ed64..bbc39412fcd1 100644
@@ -7,6 +7,7 @@
 #include "verifier_array_access.skel.h"
 #include "verifier_basic_stack.skel.h"
 #include "verifier_bounds_deduction.skel.h"
+#include "verifier_bounds_mix_sign_unsign.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -36,3 +37,4 @@ void test_verifier_and(void)                  { RUN(verifier_and); }
 void test_verifier_array_access(void)         { RUN(verifier_array_access); }
 void test_verifier_basic_stack(void)          { RUN(verifier_basic_stack); }
 void test_verifier_bounds_deduction(void)     { RUN(verifier_bounds_deduction); }
+void test_verifier_bounds_mix_sign_unsign(void) { RUN(verifier_bounds_mix_sign_unsign); }
tools/testing/selftests/bpf/progs/verifier_bounds_mix_sign_unsign.c new file +554 -0

554 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/bounds_mix_sign_unsign.c deleted +0 -411

411 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#11 lore raw

PATCH 11/43 selftests/bpf: verifier/cfg.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/cfg.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_cfg.c        | 100 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/cfg.c    |  73 -------------
 3 files changed, 102 insertions(+), 73 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cfg.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cfg.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index bbc39412fcd1..46182abecabb 100644
@@ -8,6 +8,7 @@
 #include "verifier_basic_stack.skel.h"
 #include "verifier_bounds_deduction.skel.h"
 #include "verifier_bounds_mix_sign_unsign.skel.h"
+#include "verifier_cfg.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -38,3 +39,4 @@ void test_verifier_array_access(void)         { RUN(verifier_array_access); }
 void test_verifier_basic_stack(void)          { RUN(verifier_basic_stack); }
 void test_verifier_bounds_deduction(void)     { RUN(verifier_bounds_deduction); }
 void test_verifier_bounds_mix_sign_unsign(void) { RUN(verifier_bounds_mix_sign_unsign); }
+void test_verifier_cfg(void)                  { RUN(verifier_cfg); }
tools/testing/selftests/bpf/progs/verifier_cfg.c new file +100 -0

100 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/cfg.c deleted +0 -73

73 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#12 lore raw

PATCH 12/43 selftests/bpf: verifier/cgroup_inv_retcode.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/cgroup_inv_retcode.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../bpf/progs/verifier_cgroup_inv_retcode.c   | 89 +++++++++++++++++++
 .../bpf/verifier/cgroup_inv_retcode.c         | 72 ---------------
 3 files changed, 91 insertions(+), 72 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup_inv_retcode.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_inv_retcode.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 46182abecabb..b138c9894abb 100644
@@ -9,6 +9,7 @@
 #include "verifier_bounds_deduction.skel.h"
 #include "verifier_bounds_mix_sign_unsign.skel.h"
 #include "verifier_cfg.skel.h"
+#include "verifier_cgroup_inv_retcode.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -40,3 +41,4 @@ void test_verifier_basic_stack(void)          { RUN(verifier_basic_stack); }
 void test_verifier_bounds_deduction(void)     { RUN(verifier_bounds_deduction); }
 void test_verifier_bounds_mix_sign_unsign(void) { RUN(verifier_bounds_mix_sign_unsign); }
 void test_verifier_cfg(void)                  { RUN(verifier_cfg); }
+void test_verifier_cgroup_inv_retcode(void)   { RUN(verifier_cgroup_inv_retcode); }
tools/testing/selftests/bpf/progs/verifier_cgroup_inv_retcode.c new file +89 -0

89 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/cgroup_inv_retcode.c deleted +0 -72

72 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#13 lore raw

PATCH 13/43 selftests/bpf: verifier/cgroup_skb.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/cgroup_skb.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_cgroup_skb.c | 227 ++++++++++++++++++
 .../selftests/bpf/verifier/cgroup_skb.c       | 197 ---------------
 3 files changed, 229 insertions(+), 197 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup_skb.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_skb.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index b138c9894abb..53e41af90821 100644
@@ -10,6 +10,7 @@
 #include "verifier_bounds_mix_sign_unsign.skel.h"
 #include "verifier_cfg.skel.h"
 #include "verifier_cgroup_inv_retcode.skel.h"
+#include "verifier_cgroup_skb.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -42,3 +43,4 @@ void test_verifier_bounds_deduction(void)     { RUN(verifier_bounds_deduction);
 void test_verifier_bounds_mix_sign_unsign(void) { RUN(verifier_bounds_mix_sign_unsign); }
 void test_verifier_cfg(void)                  { RUN(verifier_cfg); }
 void test_verifier_cgroup_inv_retcode(void)   { RUN(verifier_cgroup_inv_retcode); }
+void test_verifier_cgroup_skb(void)           { RUN(verifier_cgroup_skb); }
tools/testing/selftests/bpf/progs/verifier_cgroup_skb.c new file +227 -0

227 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/cgroup_skb.c deleted +0 -197

197 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#14 lore raw

PATCH 14/43 selftests/bpf: verifier/cgroup_storage.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/cgroup_storage.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_cgroup_storage.c       | 308 ++++++++++++++++++
 .../selftests/bpf/verifier/cgroup_storage.c   | 220 -------------
 3 files changed, 310 insertions(+), 220 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup_storage.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_storage.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 53e41af90821..3b47620a1f42 100644
@@ -11,6 +11,7 @@
 #include "verifier_cfg.skel.h"
 #include "verifier_cgroup_inv_retcode.skel.h"
 #include "verifier_cgroup_skb.skel.h"
+#include "verifier_cgroup_storage.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -44,3 +45,4 @@ void test_verifier_bounds_mix_sign_unsign(void) { RUN(verifier_bounds_mix_sign_u
 void test_verifier_cfg(void)                  { RUN(verifier_cfg); }
 void test_verifier_cgroup_inv_retcode(void)   { RUN(verifier_cgroup_inv_retcode); }
 void test_verifier_cgroup_skb(void)           { RUN(verifier_cgroup_skb); }
+void test_verifier_cgroup_storage(void)       { RUN(verifier_cgroup_storage); }
tools/testing/selftests/bpf/progs/verifier_cgroup_storage.c new file +308 -0

308 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/cgroup_storage.c deleted +0 -220

220 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#15 lore raw

PATCH 15/43 selftests/bpf: verifier/const_or.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/const_or.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../selftests/bpf/progs/verifier_const_or.c   | 82 +++++++++++++++++++
 .../testing/selftests/bpf/verifier/const_or.c | 60 --------------
 3 files changed, 84 insertions(+), 60 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_const_or.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/const_or.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 3b47620a1f42..36fdede7dcab 100644
@@ -12,6 +12,7 @@
 #include "verifier_cgroup_inv_retcode.skel.h"
 #include "verifier_cgroup_skb.skel.h"
 #include "verifier_cgroup_storage.skel.h"
+#include "verifier_const_or.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -46,3 +47,4 @@ void test_verifier_cfg(void)                  { RUN(verifier_cfg); }
 void test_verifier_cgroup_inv_retcode(void)   { RUN(verifier_cgroup_inv_retcode); }
 void test_verifier_cgroup_skb(void)           { RUN(verifier_cgroup_skb); }
 void test_verifier_cgroup_storage(void)       { RUN(verifier_cgroup_storage); }
+void test_verifier_const_or(void)             { RUN(verifier_const_or); }
tools/testing/selftests/bpf/progs/verifier_const_or.c new file +82 -0

82 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/const_or.c deleted +0 -60

60 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#16 lore raw

PATCH 16/43 selftests/bpf: verifier/ctx_sk_msg.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/ctx_sk_msg.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_ctx_sk_msg.c | 228 ++++++++++++++++++
 .../selftests/bpf/verifier/ctx_sk_msg.c       | 181 --------------
 3 files changed, 230 insertions(+), 181 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_ctx_sk_msg.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/ctx_sk_msg.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 36fdede7dcab..29351c774ee2 100644
@@ -13,6 +13,7 @@
 #include "verifier_cgroup_skb.skel.h"
 #include "verifier_cgroup_storage.skel.h"
 #include "verifier_const_or.skel.h"
+#include "verifier_ctx_sk_msg.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -48,3 +49,4 @@ void test_verifier_cgroup_inv_retcode(void)   { RUN(verifier_cgroup_inv_retcode)
 void test_verifier_cgroup_skb(void)           { RUN(verifier_cgroup_skb); }
 void test_verifier_cgroup_storage(void)       { RUN(verifier_cgroup_storage); }
 void test_verifier_const_or(void)             { RUN(verifier_const_or); }
+void test_verifier_ctx_sk_msg(void)           { RUN(verifier_ctx_sk_msg); }
tools/testing/selftests/bpf/progs/verifier_ctx_sk_msg.c new file +228 -0

228 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/ctx_sk_msg.c deleted +0 -181

181 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#17 lore raw

PATCH 17/43 selftests/bpf: verifier/direct_stack_access_wraparound.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/direct_stack_access_wraparound.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../verifier_direct_stack_access_wraparound.c | 56 +++++++++++++++++++
 .../verifier/direct_stack_access_wraparound.c | 40 -------------
 3 files changed, 58 insertions(+), 40 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_direct_stack_access_wraparound.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/direct_stack_access_wraparound.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 29351c774ee2..8c33b8792a0a 100644
@@ -14,6 +14,7 @@
 #include "verifier_cgroup_storage.skel.h"
 #include "verifier_const_or.skel.h"
 #include "verifier_ctx_sk_msg.skel.h"
+#include "verifier_direct_stack_access_wraparound.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -50,3 +51,4 @@ void test_verifier_cgroup_skb(void)           { RUN(verifier_cgroup_skb); }
 void test_verifier_cgroup_storage(void)       { RUN(verifier_cgroup_storage); }
 void test_verifier_const_or(void)             { RUN(verifier_const_or); }
 void test_verifier_ctx_sk_msg(void)           { RUN(verifier_ctx_sk_msg); }
+void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
tools/testing/selftests/bpf/progs/verifier_direct_stack_access_wraparound.c new file +56 -0

56 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/direct_stack_access_wraparound.c deleted +0 -40
deleted file mode 100644
index 698e3779fdd2..000000000000
@@ -1,40 +0,0 @@
-{
-	"direct stack access with 32-bit wraparound. test1",
-	.insns = {
-	BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 0x7fffffff),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 0x7fffffff),
-	BPF_MOV32_IMM(BPF_REG_0, 0),
-	BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "fp pointer and 2147483647",
-	.result = REJECT
-},
-{
-	"direct stack access with 32-bit wraparound. test2",
-	.insns = {
-	BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 0x3fffffff),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 0x3fffffff),
-	BPF_MOV32_IMM(BPF_REG_0, 0),
-	BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "fp pointer and 1073741823",
-	.result = REJECT
-},
-{
-	"direct stack access with 32-bit wraparound. test3",
-	.insns = {
-	BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 0x1fffffff),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 0x1fffffff),
-	BPF_MOV32_IMM(BPF_REG_0, 0),
-	BPF_STX_MEM(BPF_B, BPF_REG_1, BPF_REG_0, 0),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "fp pointer offset 1073741822",
-	.errstr_unpriv = "R1 stack pointer arithmetic goes out of range",
-	.result = REJECT
-},
Signature · 1 line
2.40.0
author maintainer
#18 lore raw

PATCH 18/43 selftests/bpf: verifier/div0.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/div0.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_div0.c       | 213 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/div0.c   | 184 ---------------
 3 files changed, 215 insertions(+), 184 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_div0.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/div0.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 8c33b8792a0a..b172c41cdc61 100644
@@ -15,6 +15,7 @@
 #include "verifier_const_or.skel.h"
 #include "verifier_ctx_sk_msg.skel.h"
 #include "verifier_direct_stack_access_wraparound.skel.h"
+#include "verifier_div0.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -52,3 +53,4 @@ void test_verifier_cgroup_storage(void)       { RUN(verifier_cgroup_storage); }
 void test_verifier_const_or(void)             { RUN(verifier_const_or); }
 void test_verifier_ctx_sk_msg(void)           { RUN(verifier_ctx_sk_msg); }
 void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
+void test_verifier_div0(void)                 { RUN(verifier_div0); }
tools/testing/selftests/bpf/progs/verifier_div0.c new file +213 -0

213 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/div0.c deleted +0 -184

184 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#19 lore raw

PATCH 19/43 selftests/bpf: verifier/div_overflow.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/div_overflow.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_div_overflow.c         | 144 ++++++++++++++++++
 .../selftests/bpf/verifier/div_overflow.c     | 110 -------------
 3 files changed, 146 insertions(+), 110 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_div_overflow.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/div_overflow.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index b172c41cdc61..d92211b4c3af 100644
@@ -16,6 +16,7 @@
 #include "verifier_ctx_sk_msg.skel.h"
 #include "verifier_direct_stack_access_wraparound.skel.h"
 #include "verifier_div0.skel.h"
+#include "verifier_div_overflow.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -54,3 +55,4 @@ void test_verifier_const_or(void)             { RUN(verifier_const_or); }
 void test_verifier_ctx_sk_msg(void)           { RUN(verifier_ctx_sk_msg); }
 void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
 void test_verifier_div0(void)                 { RUN(verifier_div0); }
+void test_verifier_div_overflow(void)         { RUN(verifier_div_overflow); }
tools/testing/selftests/bpf/progs/verifier_div_overflow.c new file +144 -0

144 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/div_overflow.c deleted +0 -110

110 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#20 lore raw

PATCH 20/43 selftests/bpf: verifier/helper_access_var_len.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/helper_access_var_len.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../progs/verifier_helper_access_var_len.c    | 825 ++++++++++++++++++
 .../bpf/verifier/helper_access_var_len.c      | 650 --------------
 3 files changed, 827 insertions(+), 650 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_access_var_len.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index d92211b4c3af..22d7e152c05e 100644
@@ -17,6 +17,7 @@
 #include "verifier_direct_stack_access_wraparound.skel.h"
 #include "verifier_div0.skel.h"
 #include "verifier_div_overflow.skel.h"
+#include "verifier_helper_access_var_len.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -56,3 +57,4 @@ void test_verifier_ctx_sk_msg(void)           { RUN(verifier_ctx_sk_msg); }
 void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_stack_access_wraparound); }
 void test_verifier_div0(void)                 { RUN(verifier_div0); }
 void test_verifier_div_overflow(void)         { RUN(verifier_div_overflow); }
+void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_len); }
tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c new file +825 -0

825 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/helper_access_var_len.c deleted +0 -650

650 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#21 lore raw

PATCH 21/43 selftests/bpf: verifier/helper_packet_access.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/helper_packet_access.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_helper_packet_access.c | 550 ++++++++++++++++++
 .../bpf/verifier/helper_packet_access.c       | 460 ---------------
 3 files changed, 552 insertions(+), 460 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_packet_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_packet_access.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 22d7e152c05e..1cd162daf150 100644
@@ -18,6 +18,7 @@
 #include "verifier_div0.skel.h"
 #include "verifier_div_overflow.skel.h"
 #include "verifier_helper_access_var_len.skel.h"
+#include "verifier_helper_packet_access.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -58,3 +59,4 @@ void test_verifier_direct_stack_access_wraparound(void) { RUN(verifier_direct_st
 void test_verifier_div0(void)                 { RUN(verifier_div0); }
 void test_verifier_div_overflow(void)         { RUN(verifier_div_overflow); }
 void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_len); }
+void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
tools/testing/selftests/bpf/progs/verifier_helper_packet_access.c new file +550 -0

550 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/helper_packet_access.c deleted +0 -460

460 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#22 lore raw

PATCH 22/43 selftests/bpf: verifier/helper_restricted.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/helper_restricted.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_helper_restricted.c    | 279 ++++++++++++++++++
 .../bpf/verifier/helper_restricted.c          | 196 ------------
 3 files changed, 281 insertions(+), 196 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_restricted.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_restricted.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 1cd162daf150..02983d1de218 100644
@@ -19,6 +19,7 @@
 #include "verifier_div_overflow.skel.h"
 #include "verifier_helper_access_var_len.skel.h"
 #include "verifier_helper_packet_access.skel.h"
+#include "verifier_helper_restricted.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -60,3 +61,4 @@ void test_verifier_div0(void)                 { RUN(verifier_div0); }
 void test_verifier_div_overflow(void)         { RUN(verifier_div_overflow); }
 void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_len); }
 void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
+void test_verifier_helper_restricted(void)    { RUN(verifier_helper_restricted); }
tools/testing/selftests/bpf/progs/verifier_helper_restricted.c new file +279 -0

279 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/helper_restricted.c deleted +0 -196

196 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#23 lore raw

PATCH 23/43 selftests/bpf: verifier/helper_value_access.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/helper_value_access.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |    2 +
 .../bpf/progs/verifier_helper_value_access.c  | 1245 +++++++++++++++++
 .../bpf/verifier/helper_value_access.c        |  953 -------------
 3 files changed, 1247 insertions(+), 953 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_helper_value_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/helper_value_access.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 02983d1de218..2c3745a1fdcb 100644
@@ -20,6 +20,7 @@
 #include "verifier_helper_access_var_len.skel.h"
 #include "verifier_helper_packet_access.skel.h"
 #include "verifier_helper_restricted.skel.h"
+#include "verifier_helper_value_access.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -62,3 +63,4 @@ void test_verifier_div_overflow(void)         { RUN(verifier_div_overflow); }
 void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_len); }
 void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
 void test_verifier_helper_restricted(void)    { RUN(verifier_helper_restricted); }
+void test_verifier_helper_value_access(void)  { RUN(verifier_helper_value_access); }
tools/testing/selftests/bpf/progs/verifier_helper_value_access.c new file +1245 -0

1,245 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/helper_value_access.c deleted +0 -953

953 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#24 lore raw

PATCH 24/43 selftests/bpf: verifier/int_ptr.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/int_ptr.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_int_ptr.c    | 157 +++++++++++++++++
 .../testing/selftests/bpf/verifier/int_ptr.c  | 161 ------------------
 3 files changed, 159 insertions(+), 161 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_int_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/int_ptr.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 2c3745a1fdcb..d9180da30f1b 100644
@@ -21,6 +21,7 @@
 #include "verifier_helper_packet_access.skel.h"
 #include "verifier_helper_restricted.skel.h"
 #include "verifier_helper_value_access.skel.h"
+#include "verifier_int_ptr.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -64,3 +65,4 @@ void test_verifier_helper_access_var_len(void) { RUN(verifier_helper_access_var_
 void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_access); }
 void test_verifier_helper_restricted(void)    { RUN(verifier_helper_restricted); }
 void test_verifier_helper_value_access(void)  { RUN(verifier_helper_value_access); }
+void test_verifier_int_ptr(void)              { RUN(verifier_int_ptr); }
tools/testing/selftests/bpf/progs/verifier_int_ptr.c new file +157 -0

157 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/int_ptr.c deleted +0 -161

161 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#25 lore raw

PATCH 25/43 selftests/bpf: verifier/ld_ind.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/ld_ind.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_ld_ind.c     | 110 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/ld_ind.c |  72 ------------
 3 files changed, 112 insertions(+), 72 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_ld_ind.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/ld_ind.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index d9180da30f1b..d8d4464b6112 100644
@@ -22,6 +22,7 @@
 #include "verifier_helper_restricted.skel.h"
 #include "verifier_helper_value_access.skel.h"
 #include "verifier_int_ptr.skel.h"
+#include "verifier_ld_ind.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -66,3 +67,4 @@ void test_verifier_helper_packet_access(void) { RUN(verifier_helper_packet_acces
 void test_verifier_helper_restricted(void)    { RUN(verifier_helper_restricted); }
 void test_verifier_helper_value_access(void)  { RUN(verifier_helper_value_access); }
 void test_verifier_int_ptr(void)              { RUN(verifier_int_ptr); }
+void test_verifier_ld_ind(void)               { RUN(verifier_ld_ind); }
tools/testing/selftests/bpf/progs/verifier_ld_ind.c new file +110 -0

110 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/ld_ind.c deleted +0 -72

72 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#26 lore raw

PATCH 26/43 selftests/bpf: verifier/leak_ptr.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/leak_ptr.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../selftests/bpf/progs/verifier_leak_ptr.c   | 92 +++++++++++++++++++
 .../testing/selftests/bpf/verifier/leak_ptr.c | 67 --------------
 3 files changed, 94 insertions(+), 67 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_leak_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/leak_ptr.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index d8d4464b6112..f8b3b6beba3f 100644
@@ -23,6 +23,7 @@
 #include "verifier_helper_value_access.skel.h"
 #include "verifier_int_ptr.skel.h"
 #include "verifier_ld_ind.skel.h"
+#include "verifier_leak_ptr.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -68,3 +69,4 @@ void test_verifier_helper_restricted(void)    { RUN(verifier_helper_restricted);
 void test_verifier_helper_value_access(void)  { RUN(verifier_helper_value_access); }
 void test_verifier_int_ptr(void)              { RUN(verifier_int_ptr); }
 void test_verifier_ld_ind(void)               { RUN(verifier_ld_ind); }
+void test_verifier_leak_ptr(void)             { RUN(verifier_leak_ptr); }
tools/testing/selftests/bpf/progs/verifier_leak_ptr.c new file +92 -0

92 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/leak_ptr.c deleted +0 -67

67 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#27 lore raw

PATCH 27/43 selftests/bpf: verifier/map_ptr.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/map_ptr.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_map_ptr.c    | 159 ++++++++++++++++++
 .../testing/selftests/bpf/verifier/map_ptr.c  |  99 -----------
 3 files changed, 161 insertions(+), 99 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_map_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/map_ptr.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index f8b3b6beba3f..d2f3bff0e942 100644
@@ -24,6 +24,7 @@
 #include "verifier_int_ptr.skel.h"
 #include "verifier_ld_ind.skel.h"
 #include "verifier_leak_ptr.skel.h"
+#include "verifier_map_ptr.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -70,3 +71,4 @@ void test_verifier_helper_value_access(void)  { RUN(verifier_helper_value_access
 void test_verifier_int_ptr(void)              { RUN(verifier_int_ptr); }
 void test_verifier_ld_ind(void)               { RUN(verifier_ld_ind); }
 void test_verifier_leak_ptr(void)             { RUN(verifier_leak_ptr); }
+void test_verifier_map_ptr(void)              { RUN(verifier_map_ptr); }
tools/testing/selftests/bpf/progs/verifier_map_ptr.c new file +159 -0

159 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/map_ptr.c deleted +0 -99

99 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#28 lore raw

PATCH 28/43 selftests/bpf: verifier/map_ret_val.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/map_ret_val.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_map_ret_val.c          | 110 ++++++++++++++++++
 .../selftests/bpf/verifier/map_ret_val.c      |  65 -----------
 3 files changed, 112 insertions(+), 65 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_map_ret_val.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/map_ret_val.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index d2f3bff0e942..5131a73fd225 100644
@@ -25,6 +25,7 @@
 #include "verifier_ld_ind.skel.h"
 #include "verifier_leak_ptr.skel.h"
 #include "verifier_map_ptr.skel.h"
+#include "verifier_map_ret_val.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -72,3 +73,4 @@ void test_verifier_int_ptr(void)              { RUN(verifier_int_ptr); }
 void test_verifier_ld_ind(void)               { RUN(verifier_ld_ind); }
 void test_verifier_leak_ptr(void)             { RUN(verifier_leak_ptr); }
 void test_verifier_map_ptr(void)              { RUN(verifier_map_ptr); }
+void test_verifier_map_ret_val(void)          { RUN(verifier_map_ret_val); }
tools/testing/selftests/bpf/progs/verifier_map_ret_val.c new file +110 -0

110 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/map_ret_val.c deleted +0 -65

65 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#29 lore raw

PATCH 29/43 selftests/bpf: verifier/masking.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/masking.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_masking.c    | 410 ++++++++++++++++++
 .../testing/selftests/bpf/verifier/masking.c  | 322 --------------
 3 files changed, 412 insertions(+), 322 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_masking.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/masking.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 5131a73fd225..b23fcbe4f83b 100644
@@ -26,6 +26,7 @@
 #include "verifier_leak_ptr.skel.h"
 #include "verifier_map_ptr.skel.h"
 #include "verifier_map_ret_val.skel.h"
+#include "verifier_masking.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -74,3 +75,4 @@ void test_verifier_ld_ind(void)               { RUN(verifier_ld_ind); }
 void test_verifier_leak_ptr(void)             { RUN(verifier_leak_ptr); }
 void test_verifier_map_ptr(void)              { RUN(verifier_map_ptr); }
 void test_verifier_map_ret_val(void)          { RUN(verifier_map_ret_val); }
+void test_verifier_masking(void)              { RUN(verifier_masking); }
tools/testing/selftests/bpf/progs/verifier_masking.c new file +410 -0

410 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/masking.c deleted +0 -322

322 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#30 lore raw

PATCH 30/43 selftests/bpf: verifier/meta_access.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/meta_access.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_meta_access.c          | 284 ++++++++++++++++++
 .../selftests/bpf/verifier/meta_access.c      | 235 ---------------
 3 files changed, 286 insertions(+), 235 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_meta_access.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/meta_access.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index b23fcbe4f83b..bd48a584a356 100644
@@ -27,6 +27,7 @@
 #include "verifier_map_ptr.skel.h"
 #include "verifier_map_ret_val.skel.h"
 #include "verifier_masking.skel.h"
+#include "verifier_meta_access.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -76,3 +77,4 @@ void test_verifier_leak_ptr(void)             { RUN(verifier_leak_ptr); }
 void test_verifier_map_ptr(void)              { RUN(verifier_map_ptr); }
 void test_verifier_map_ret_val(void)          { RUN(verifier_map_ret_val); }
 void test_verifier_masking(void)              { RUN(verifier_masking); }
+void test_verifier_meta_access(void)          { RUN(verifier_meta_access); }
tools/testing/selftests/bpf/progs/verifier_meta_access.c new file +284 -0

284 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/meta_access.c deleted +0 -235

235 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#31 lore raw

PATCH 31/43 selftests/bpf: verifier/raw_stack.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/raw_stack.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_raw_stack.c  | 371 ++++++++++++++++++
 .../selftests/bpf/verifier/raw_stack.c        | 305 --------------
 3 files changed, 373 insertions(+), 305 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_raw_stack.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/raw_stack.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index bd48a584a356..4a73cac3f9ba 100644
@@ -28,6 +28,7 @@
 #include "verifier_map_ret_val.skel.h"
 #include "verifier_masking.skel.h"
 #include "verifier_meta_access.skel.h"
+#include "verifier_raw_stack.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -78,3 +79,4 @@ void test_verifier_map_ptr(void)              { RUN(verifier_map_ptr); }
 void test_verifier_map_ret_val(void)          { RUN(verifier_map_ret_val); }
 void test_verifier_masking(void)              { RUN(verifier_masking); }
 void test_verifier_meta_access(void)          { RUN(verifier_meta_access); }
+void test_verifier_raw_stack(void)            { RUN(verifier_raw_stack); }
tools/testing/selftests/bpf/progs/verifier_raw_stack.c new file +371 -0

371 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/raw_stack.c deleted +0 -305

305 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#32 lore raw

PATCH 32/43 selftests/bpf: verifier/raw_tp_writable.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/raw_tp_writable.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../bpf/progs/verifier_raw_tp_writable.c      | 50 +++++++++++++++++++
 .../selftests/bpf/verifier/raw_tp_writable.c  | 35 -------------
 3 files changed, 52 insertions(+), 35 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/raw_tp_writable.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 4a73cac3f9ba..f7488904f26e 100644
@@ -29,6 +29,7 @@
 #include "verifier_masking.skel.h"
 #include "verifier_meta_access.skel.h"
 #include "verifier_raw_stack.skel.h"
+#include "verifier_raw_tp_writable.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -80,3 +81,4 @@ void test_verifier_map_ret_val(void)          { RUN(verifier_map_ret_val); }
 void test_verifier_masking(void)              { RUN(verifier_masking); }
 void test_verifier_meta_access(void)          { RUN(verifier_meta_access); }
 void test_verifier_raw_stack(void)            { RUN(verifier_raw_stack); }
+void test_verifier_raw_tp_writable(void)      { RUN(verifier_raw_tp_writable); }
tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c new file +50 -0

50 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/raw_tp_writable.c deleted +0 -35
deleted file mode 100644
index 2978fb5a769d..000000000000
@@ -1,35 +0,0 @@
-{
-	"raw_tracepoint_writable: reject variable offset",
-	.insns = {
-		/* r6 is our tp buffer */
-		BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, 0),
-
-		BPF_LD_MAP_FD(BPF_REG_1, 0),
-		/* move the key (== 0) to r10-8 */
-		BPF_MOV32_IMM(BPF_REG_0, 0),
-		BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
-		BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
-		BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_0, 0),
-		/* lookup in the map */
-		BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0,
-			     BPF_FUNC_map_lookup_elem),
-
-		/* exit clean if null */
-		BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
-		BPF_EXIT_INSN(),
-
-		/* shift the buffer pointer to a variable location */
-		BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 0),
-		BPF_ALU64_REG(BPF_ADD, BPF_REG_6, BPF_REG_0),
-		/* clobber whatever's there */
-		BPF_MOV64_IMM(BPF_REG_7, 4242),
-		BPF_STX_MEM(BPF_DW, BPF_REG_6, BPF_REG_7, 0),
-
-		BPF_MOV64_IMM(BPF_REG_0, 0),
-		BPF_EXIT_INSN(),
-	},
-	.fixup_map_hash_8b = { 1, },
-	.prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
-	.errstr = "R6 invalid variable buffer offset: off=0, var_off=(0x0; 0xffffffff)",
-	.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
-},
Signature · 1 line
2.40.0
author maintainer
#33 lore raw

PATCH 33/43 selftests/bpf: verifier/ringbuf.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/ringbuf.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_ringbuf.c    | 131 ++++++++++++++++++
 .../testing/selftests/bpf/verifier/ringbuf.c  |  95 -------------
 3 files changed, 133 insertions(+), 95 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_ringbuf.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/ringbuf.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index f7488904f26e..df5fc6fe1647 100644
@@ -30,6 +30,7 @@
 #include "verifier_meta_access.skel.h"
 #include "verifier_raw_stack.skel.h"
 #include "verifier_raw_tp_writable.skel.h"
+#include "verifier_ringbuf.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -82,3 +83,4 @@ void test_verifier_masking(void)              { RUN(verifier_masking); }
 void test_verifier_meta_access(void)          { RUN(verifier_meta_access); }
 void test_verifier_raw_stack(void)            { RUN(verifier_raw_stack); }
 void test_verifier_raw_tp_writable(void)      { RUN(verifier_raw_tp_writable); }
+void test_verifier_ringbuf(void)              { RUN(verifier_ringbuf); }
tools/testing/selftests/bpf/progs/verifier_ringbuf.c new file +131 -0

131 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/ringbuf.c deleted +0 -95

95 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#34 lore raw

PATCH 34/43 selftests/bpf: verifier/spill_fill.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/spill_fill.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_spill_fill.c | 374 ++++++++++++++++++
 .../selftests/bpf/verifier/spill_fill.c       | 345 ----------------
 3 files changed, 376 insertions(+), 345 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_spill_fill.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/spill_fill.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index df5fc6fe1647..e2b131d2ba94 100644
@@ -31,6 +31,7 @@
 #include "verifier_raw_stack.skel.h"
 #include "verifier_raw_tp_writable.skel.h"
 #include "verifier_ringbuf.skel.h"
+#include "verifier_spill_fill.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -84,3 +85,4 @@ void test_verifier_meta_access(void)          { RUN(verifier_meta_access); }
 void test_verifier_raw_stack(void)            { RUN(verifier_raw_stack); }
 void test_verifier_raw_tp_writable(void)      { RUN(verifier_raw_tp_writable); }
 void test_verifier_ringbuf(void)              { RUN(verifier_ringbuf); }
+void test_verifier_spill_fill(void)           { RUN(verifier_spill_fill); }
tools/testing/selftests/bpf/progs/verifier_spill_fill.c new file +374 -0

374 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/spill_fill.c deleted +0 -345

345 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#35 lore raw

PATCH 35/43 selftests/bpf: verifier/stack_ptr.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/stack_ptr.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_stack_ptr.c  | 484 ++++++++++++++++++
 .../selftests/bpf/verifier/stack_ptr.c        | 359 -------------
 3 files changed, 486 insertions(+), 359 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_stack_ptr.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/stack_ptr.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index e2b131d2ba94..ce1ca8c0c02e 100644
@@ -32,6 +32,7 @@
 #include "verifier_raw_tp_writable.skel.h"
 #include "verifier_ringbuf.skel.h"
 #include "verifier_spill_fill.skel.h"
+#include "verifier_stack_ptr.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -86,3 +87,4 @@ void test_verifier_raw_stack(void)            { RUN(verifier_raw_stack); }
 void test_verifier_raw_tp_writable(void)      { RUN(verifier_raw_tp_writable); }
 void test_verifier_ringbuf(void)              { RUN(verifier_ringbuf); }
 void test_verifier_spill_fill(void)           { RUN(verifier_spill_fill); }
+void test_verifier_stack_ptr(void)            { RUN(verifier_stack_ptr); }
tools/testing/selftests/bpf/progs/verifier_stack_ptr.c new file +484 -0

484 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/stack_ptr.c deleted +0 -359

359 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#36 lore raw

PATCH 36/43 selftests/bpf: verifier/uninit.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/uninit.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../selftests/bpf/progs/verifier_uninit.c     | 61 +++++++++++++++++++
 tools/testing/selftests/bpf/verifier/uninit.c | 39 ------------
 3 files changed, 63 insertions(+), 39 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_uninit.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/uninit.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index ce1ca8c0c02e..c6e69b3827dc 100644
@@ -33,6 +33,7 @@
 #include "verifier_ringbuf.skel.h"
 #include "verifier_spill_fill.skel.h"
 #include "verifier_stack_ptr.skel.h"
+#include "verifier_uninit.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -88,3 +89,4 @@ void test_verifier_raw_tp_writable(void)      { RUN(verifier_raw_tp_writable); }
 void test_verifier_ringbuf(void)              { RUN(verifier_ringbuf); }
 void test_verifier_spill_fill(void)           { RUN(verifier_spill_fill); }
 void test_verifier_stack_ptr(void)            { RUN(verifier_stack_ptr); }
+void test_verifier_uninit(void)               { RUN(verifier_uninit); }
tools/testing/selftests/bpf/progs/verifier_uninit.c new file +61 -0

61 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/uninit.c deleted +0 -39
deleted file mode 100644
index 987a5871ff1d..000000000000
@@ -1,39 +0,0 @@
-{
-	"read uninitialized register",
-	.insns = {
-	BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "R2 !read_ok",
-	.result = REJECT,
-},
-{
-	"read invalid register",
-	.insns = {
-	BPF_MOV64_REG(BPF_REG_0, -1),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "R15 is invalid",
-	.result = REJECT,
-},
-{
-	"program doesn't init R0 before exit",
-	.insns = {
-	BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_1),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "R0 !read_ok",
-	.result = REJECT,
-},
-{
-	"program doesn't init R0 before exit in all branches",
-	.insns = {
-	BPF_JMP_IMM(BPF_JGE, BPF_REG_1, 0, 2),
-	BPF_MOV64_IMM(BPF_REG_0, 1),
-	BPF_ALU64_IMM(BPF_ADD, BPF_REG_0, 2),
-	BPF_EXIT_INSN(),
-	},
-	.errstr = "R0 !read_ok",
-	.errstr_unpriv = "R1 pointer comparison",
-	.result = REJECT,
-},
Signature · 1 line
2.40.0
author maintainer
#37 lore raw

PATCH 37/43 selftests/bpf: verifier/value_adj_spill.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/value_adj_spill.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 +
 .../bpf/progs/verifier_value_adj_spill.c      | 78 +++++++++++++++++++
 .../selftests/bpf/verifier/value_adj_spill.c  | 43 ----------
 3 files changed, 80 insertions(+), 43 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_value_adj_spill.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/value_adj_spill.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index c6e69b3827dc..825c8583fecf 100644
@@ -34,6 +34,7 @@
 #include "verifier_spill_fill.skel.h"
 #include "verifier_stack_ptr.skel.h"
 #include "verifier_uninit.skel.h"
+#include "verifier_value_adj_spill.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -90,3 +91,4 @@ void test_verifier_ringbuf(void)              { RUN(verifier_ringbuf); }
 void test_verifier_spill_fill(void)           { RUN(verifier_spill_fill); }
 void test_verifier_stack_ptr(void)            { RUN(verifier_stack_ptr); }
 void test_verifier_uninit(void)               { RUN(verifier_uninit); }
+void test_verifier_value_adj_spill(void)      { RUN(verifier_value_adj_spill); }
tools/testing/selftests/bpf/progs/verifier_value_adj_spill.c new file +78 -0

78 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/value_adj_spill.c deleted +0 -43

43 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#38 lore raw

PATCH 38/43 selftests/bpf: verifier/value.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/value.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_value.c      | 158 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/value.c  | 104 ------------
 3 files changed, 160 insertions(+), 104 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_value.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/value.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 825c8583fecf..c77df746d650 100644
@@ -35,6 +35,7 @@
 #include "verifier_stack_ptr.skel.h"
 #include "verifier_uninit.skel.h"
 #include "verifier_value_adj_spill.skel.h"
+#include "verifier_value.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -92,3 +93,4 @@ void test_verifier_spill_fill(void)           { RUN(verifier_spill_fill); }
 void test_verifier_stack_ptr(void)            { RUN(verifier_stack_ptr); }
 void test_verifier_uninit(void)               { RUN(verifier_uninit); }
 void test_verifier_value_adj_spill(void)      { RUN(verifier_value_adj_spill); }
+void test_verifier_value(void)                { RUN(verifier_value); }
tools/testing/selftests/bpf/progs/verifier_value.c new file +158 -0

158 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/value.c deleted +0 -104

104 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#39 lore raw

PATCH 39/43 selftests/bpf: verifier/value_or_null.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/value_or_null.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/verifier_value_or_null.c        | 288 ++++++++++++++++++
 .../selftests/bpf/verifier/value_or_null.c    | 220 -------------
 3 files changed, 290 insertions(+), 220 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_value_or_null.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/value_or_null.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index c77df746d650..54eb21ef9fad 100644
@@ -36,6 +36,7 @@
 #include "verifier_uninit.skel.h"
 #include "verifier_value_adj_spill.skel.h"
 #include "verifier_value.skel.h"
+#include "verifier_value_or_null.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -94,3 +95,4 @@ void test_verifier_stack_ptr(void)            { RUN(verifier_stack_ptr); }
 void test_verifier_uninit(void)               { RUN(verifier_uninit); }
 void test_verifier_value_adj_spill(void)      { RUN(verifier_value_adj_spill); }
 void test_verifier_value(void)                { RUN(verifier_value); }
+void test_verifier_value_or_null(void)        { RUN(verifier_value_or_null); }
tools/testing/selftests/bpf/progs/verifier_value_or_null.c new file +288 -0

288 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/value_or_null.c deleted +0 -220

220 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#40 lore raw

PATCH 40/43 selftests/bpf: verifier/var_off.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/var_off.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_var_off.c    | 349 ++++++++++++++++++
 .../testing/selftests/bpf/verifier/var_off.c  | 291 ---------------
 3 files changed, 351 insertions(+), 291 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_var_off.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/var_off.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 54eb21ef9fad..44350e328da2 100644
@@ -37,6 +37,7 @@
 #include "verifier_value_adj_spill.skel.h"
 #include "verifier_value.skel.h"
 #include "verifier_value_or_null.skel.h"
+#include "verifier_var_off.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -96,3 +97,4 @@ void test_verifier_uninit(void)               { RUN(verifier_uninit); }
 void test_verifier_value_adj_spill(void)      { RUN(verifier_value_adj_spill); }
 void test_verifier_value(void)                { RUN(verifier_value); }
 void test_verifier_value_or_null(void)        { RUN(verifier_value_or_null); }
+void test_verifier_var_off(void)              { RUN(verifier_var_off); }
tools/testing/selftests/bpf/progs/verifier_var_off.c new file +349 -0

349 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/var_off.c deleted +0 -291

291 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#41 lore raw

PATCH 41/43 selftests/bpf: verifier/xadd.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/xadd.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../selftests/bpf/progs/verifier_xadd.c       | 124 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/xadd.c   |  97 --------------
 3 files changed, 126 insertions(+), 97 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_xadd.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/xadd.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index 44350e328da2..cd56fe520145 100644
@@ -38,6 +38,7 @@
 #include "verifier_value.skel.h"
 #include "verifier_value_or_null.skel.h"
 #include "verifier_var_off.skel.h"
+#include "verifier_xadd.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -98,3 +99,4 @@ void test_verifier_value_adj_spill(void)      { RUN(verifier_value_adj_spill); }
 void test_verifier_value(void)                { RUN(verifier_value); }
 void test_verifier_value_or_null(void)        { RUN(verifier_value_or_null); }
 void test_verifier_var_off(void)              { RUN(verifier_var_off); }
+void test_verifier_xadd(void)                 { RUN(verifier_xadd); }
tools/testing/selftests/bpf/progs/verifier_xadd.c new file +124 -0

124 lines not on this page · raw message

tools/testing/selftests/bpf/verifier/xadd.c deleted +0 -97

97 lines not on this page · raw message

Signature · 1 line
2.40.0
author maintainer
#42 lore raw

PATCH 42/43 selftests/bpf: verifier/xdp.c converted to inline assembly

In reply to Eduard Zingerman

Test verifier/xdp.c automatically converted to use inline assembly.

---
 .../selftests/bpf/prog_tests/verifier.c       |  2 ++
 .../selftests/bpf/progs/verifier_xdp.c        | 24 +++++++++++++++++++
 tools/testing/selftests/bpf/verifier/xdp.c    | 14 -----------
 3 files changed, 26 insertions(+), 14 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_xdp.c
 delete mode 100644 tools/testing/selftests/bpf/verifier/xdp.c
tools/testing/selftests/bpf/prog_tests/verifier.c +2 -0
index cd56fe520145..a774d5b193f1 100644
@@ -39,6 +39,7 @@
 #include "verifier_value_or_null.skel.h"
 #include "verifier_var_off.skel.h"
 #include "verifier_xadd.skel.h"
+#include "verifier_xdp.skel.h"
 
 __maybe_unused
 static void run_tests_aux(const char *skel_name, skel_elf_bytes_fn elf_bytes_factory)
@@ -100,3 +101,4 @@ void test_verifier_value(void)                { RUN(verifier_value); }
 void test_verifier_value_or_null(void)        { RUN(verifier_value_or_null); }
 void test_verifier_var_off(void)              { RUN(verifier_var_off); }
 void test_verifier_xadd(void)                 { RUN(verifier_xadd); }
+void test_verifier_xdp(void)                  { RUN(verifier_xdp); }
tools/testing/selftests/bpf/progs/verifier_xdp.c new file +24 -0
new file mode 100644
index 000000000000..50768ed179b3
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Converted from tools/testing/selftests/bpf/verifier/xdp.c */
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+SEC("xdp")
+__description("XDP, using ifindex from netdev")
+__success __retval(1)
+__naked void xdp_using_ifindex_from_netdev(void)
+{
+	asm volatile ("					\
+	r0 = 0;						\
+	r2 = *(u32*)(r1 + %[xdp_md_ingress_ifindex]);	\
+	if r2 < 1 goto l0_%=;				\
+	r0 = 1;						\
+l0_%=:	exit;						\
+"	:
+	: __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex))
+	: __clobber_all);
+}
+
+char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/verifier/xdp.c deleted +0 -14
deleted file mode 100644
index 5ac390508139..000000000000
@@ -1,14 +0,0 @@
-{
-	"XDP, using ifindex from netdev",
-	.insns = {
-	BPF_MOV64_IMM(BPF_REG_0, 0),
-	BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1,
-		    offsetof(struct xdp_md, ingress_ifindex)),
-	BPF_JMP_IMM(BPF_JLT, BPF_REG_2, 1, 1),
-	BPF_MOV64_IMM(BPF_REG_0, 1),
-	BPF_EXIT_INSN(),
-	},
-	.result = ACCEPT,
-	.prog_type = BPF_PROG_TYPE_XDP,
-	.retval = 1,
-},
Signature · 1 line
2.40.0
#43 lore raw
In reply to Eduard Zingerman
Quoted 3 lines · Eduard Zingerman

This is a follow up for RFC [1]. It migrates a first batch of 38 verifier/*.c tests to inline assembly and use of ./test_progs for actual execution. The migration is done by a python script (see [2]).

Jesus Christ, 43 patches on a Friday night (^_^)
Unless I get bored on the weekend, will get to them Monday morning (or unless Alexei/Andrii beat me to it; I see they were commenting on the RFC).

Quoted 29 lines

Each migrated verifier/xxx.c file is mapped to progs/verifier_xxx.c plus an entry in the prog_tests/verifier.c. One patch per each file.

A few patches at the beginning of the patch-set extend test_loader with necessary functionality, mainly:
- support for tests execution in unprivileged mode;
- support for test runs for test programs.

Migrated tests could be selected for execution using the following filter:

./test_progs -a verifier_*

An example of the migrated test:

SEC("xdp")
__description("XDP pkt read, pkt_data' > pkt_end, corner case, good
access")
__success __retval(0) __flag(BPF_F_ANY_ALIGNMENT) __naked void end_corner_case_good_access_1(void)

   {
           asm volatile ("                                 \
           r2 = *(u32*)(r1 + %[xdp_md_data]);              \
           r3 = *(u32*)(r1 + %[xdp_md_data_end]);          \
           r1 = r2;                                        \
           r1 += 8;                                        \
           if r1 > r3 goto l0_%=;                          \
           r0 = *(u64*)(r1 - 8);                           \
   l0_%=:  r0 = 0;                                         \
           exit;                                           \
Quoted 6 lines

" :
: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
__imm_const(xdp_md_data_end, offsetof(struct xdp_md,
data_end))

           : __clobber_all);

}

Are those '\' at the end required? Can we do regular string coalescing like the following below?

asm volatile(

	"r2 = *(u32*)(r1 + %[xdp_md_data]);"
	"r3 = *(u32*)(r1 + %[xdp_md_data_end]);"
	"r1 = r2;"
	...

);

Or is asm directive somehow special?

Quoted 283 lines

Changes compared to RFC:
- test_loader.c is extended to support test program runs;
- capabilities handling now matches behavior of test_verifier;
- BPF_ST_MEM instructions are automatically replaced by BPF_STX_MEM instructions to overcome current clang limitations;
- tests styling updates according to RFC feedback;
- 38 migrated files are included instead of 1.

I used the following means for testing:
- migration tool itself has a set of self-tests;
- migrated tests are passing;
- manually compared each old/new file side-by-side.

While doing side-by-side comparison I've noted a few defects in the original tests:
- and.c:
- One of the jump targets is off by one;
- BPF_ST_MEM wrong OFF/IMM ordering;
- array_access.c:
- BPF_ST_MEM wrong OFF/IMM ordering;
- value_or_null.c:
- BPF_ST_MEM wrong OFF/IMM ordering.

These defects would be addressed separately.

[1] RFC

https://lore.kernel.org/bpf/[email protected]/
[2] Migration tool
https://github.com/eddyz87/verifier-tests-migrator

Eduard Zingerman (43):
selftests/bpf: Report program name on parse_test_spec error selftests/bpf: __imm_insn & __imm_const macro for bpf_misc.h selftests/bpf: Unprivileged tests for test_loader.c selftests/bpf: Tests execution support for test_loader.c selftests/bpf: prog_tests entry point for migrated test_verifier tests selftests/bpf: verifier/and.c converted to inline assembly selftests/bpf: verifier/array_access.c converted to inline assembly selftests/bpf: verifier/basic_stack.c converted to inline assembly selftests/bpf: verifier/bounds_deduction.c converted to inline
assembly
selftests/bpf: verifier/bounds_mix_sign_unsign.c converted to inline
assembly
selftests/bpf: verifier/cfg.c converted to inline assembly selftests/bpf: verifier/cgroup_inv_retcode.c converted to inline
assembly
selftests/bpf: verifier/cgroup_skb.c converted to inline assembly selftests/bpf: verifier/cgroup_storage.c converted to inline assembly selftests/bpf: verifier/const_or.c converted to inline assembly selftests/bpf: verifier/ctx_sk_msg.c converted to inline assembly selftests/bpf: verifier/direct_stack_access_wraparound.c converted to
inline assembly
selftests/bpf: verifier/div0.c converted to inline assembly selftests/bpf: verifier/div_overflow.c converted to inline assembly selftests/bpf: verifier/helper_access_var_len.c converted to inline
assembly
selftests/bpf: verifier/helper_packet_access.c converted to inline
assembly
selftests/bpf: verifier/helper_restricted.c converted to inline
assembly
selftests/bpf: verifier/helper_value_access.c converted to inline
assembly
selftests/bpf: verifier/int_ptr.c converted to inline assembly selftests/bpf: verifier/ld_ind.c converted to inline assembly selftests/bpf: verifier/leak_ptr.c converted to inline assembly selftests/bpf: verifier/map_ptr.c converted to inline assembly selftests/bpf: verifier/map_ret_val.c converted to inline assembly selftests/bpf: verifier/masking.c converted to inline assembly selftests/bpf: verifier/meta_access.c converted to inline assembly selftests/bpf: verifier/raw_stack.c converted to inline assembly selftests/bpf: verifier/raw_tp_writable.c converted to inline assembly selftests/bpf: verifier/ringbuf.c converted to inline assembly selftests/bpf: verifier/spill_fill.c converted to inline assembly selftests/bpf: verifier/stack_ptr.c converted to inline assembly selftests/bpf: verifier/uninit.c converted to inline assembly selftests/bpf: verifier/value_adj_spill.c converted to inline assembly selftests/bpf: verifier/value.c converted to inline assembly selftests/bpf: verifier/value_or_null.c converted to inline assembly selftests/bpf: verifier/var_off.c converted to inline assembly selftests/bpf: verifier/xadd.c converted to inline assembly selftests/bpf: verifier/xdp.c converted to inline assembly selftests/bpf: verifier/xdp_direct_packet_access.c converted to inline
assembly

  tools/testing/selftests/bpf/Makefile          |   10 +-
  tools/testing/selftests/bpf/autoconf_helper.h |    9 +
  .../selftests/bpf/prog_tests/verifier.c       |  106 +
  tools/testing/selftests/bpf/progs/bpf_misc.h  |   42 +
  .../selftests/bpf/progs/verifier_and.c        |  107 +
  .../bpf/progs/verifier_array_access.c         |  529 +++++
  .../bpf/progs/verifier_basic_stack.c          |  100 +
  .../bpf/progs/verifier_bounds_deduction.c     |  171 ++
  .../progs/verifier_bounds_mix_sign_unsign.c   |  554 ++++++
  .../selftests/bpf/progs/verifier_cfg.c        |  100 +
  .../bpf/progs/verifier_cgroup_inv_retcode.c   |   89 +
  .../selftests/bpf/progs/verifier_cgroup_skb.c |  227 +++
  .../bpf/progs/verifier_cgroup_storage.c       |  308 +++
  .../selftests/bpf/progs/verifier_const_or.c   |   82 +
  .../selftests/bpf/progs/verifier_ctx_sk_msg.c |  228 +++
  .../verifier_direct_stack_access_wraparound.c |   56 +
  .../selftests/bpf/progs/verifier_div0.c       |  213 ++
  .../bpf/progs/verifier_div_overflow.c         |  144 ++
  .../progs/verifier_helper_access_var_len.c    |  825 ++++++++
  .../bpf/progs/verifier_helper_packet_access.c |  550 ++++++
  .../bpf/progs/verifier_helper_restricted.c    |  279 +++
  .../bpf/progs/verifier_helper_value_access.c  | 1245 ++++++++++++
  .../selftests/bpf/progs/verifier_int_ptr.c    |  157 ++
  .../selftests/bpf/progs/verifier_ld_ind.c     |  110 ++
  .../selftests/bpf/progs/verifier_leak_ptr.c   |   92 +
  .../selftests/bpf/progs/verifier_map_ptr.c    |  159 ++
  .../bpf/progs/verifier_map_ret_val.c          |  110 ++
  .../selftests/bpf/progs/verifier_masking.c    |  410 ++++
  .../bpf/progs/verifier_meta_access.c          |  284 +++
  .../selftests/bpf/progs/verifier_raw_stack.c  |  371 ++++
  .../bpf/progs/verifier_raw_tp_writable.c      |   50 +
  .../selftests/bpf/progs/verifier_ringbuf.c    |  131 ++
  .../selftests/bpf/progs/verifier_spill_fill.c |  374 ++++
  .../selftests/bpf/progs/verifier_stack_ptr.c  |  484 +++++
  .../selftests/bpf/progs/verifier_uninit.c     |   61 +
  .../selftests/bpf/progs/verifier_value.c      |  158 ++
  .../bpf/progs/verifier_value_adj_spill.c      |   78 +
  .../bpf/progs/verifier_value_or_null.c        |  288 +++
  .../selftests/bpf/progs/verifier_var_off.c    |  349 ++++
  .../selftests/bpf/progs/verifier_xadd.c       |  124 ++
  .../selftests/bpf/progs/verifier_xdp.c        |   24 +
  .../progs/verifier_xdp_direct_packet_access.c | 1722 +++++++++++++++++
  tools/testing/selftests/bpf/test_loader.c     |  536 ++++-
  tools/testing/selftests/bpf/test_verifier.c   |   25 +-
  tools/testing/selftests/bpf/unpriv_helpers.c  |   26 +
  tools/testing/selftests/bpf/unpriv_helpers.h  |    7 +
  tools/testing/selftests/bpf/verifier/and.c    |   68 -
  .../selftests/bpf/verifier/array_access.c     |  379 ----
  .../selftests/bpf/verifier/basic_stack.c      |   64 -
  .../selftests/bpf/verifier/bounds_deduction.c |  136 --
  .../bpf/verifier/bounds_mix_sign_unsign.c     |  411 ----
  tools/testing/selftests/bpf/verifier/cfg.c    |   73 -
  .../bpf/verifier/cgroup_inv_retcode.c         |   72 -
  .../selftests/bpf/verifier/cgroup_skb.c       |  197 --
  .../selftests/bpf/verifier/cgroup_storage.c   |  220 ---
  .../testing/selftests/bpf/verifier/const_or.c |   60 -
  .../selftests/bpf/verifier/ctx_sk_msg.c       |  181 --
  .../verifier/direct_stack_access_wraparound.c |   40 -
  tools/testing/selftests/bpf/verifier/div0.c   |  184 --
  .../selftests/bpf/verifier/div_overflow.c     |  110 --
  .../bpf/verifier/helper_access_var_len.c      |  650 -------
  .../bpf/verifier/helper_packet_access.c       |  460 -----
  .../bpf/verifier/helper_restricted.c          |  196 --
  .../bpf/verifier/helper_value_access.c        |  953 ---------
  .../testing/selftests/bpf/verifier/int_ptr.c  |  161 --
  tools/testing/selftests/bpf/verifier/ld_ind.c |   72 -
  .../testing/selftests/bpf/verifier/leak_ptr.c |   67 -
  .../testing/selftests/bpf/verifier/map_ptr.c  |   99 -
  .../selftests/bpf/verifier/map_ret_val.c      |   65 -
  .../testing/selftests/bpf/verifier/masking.c  |  322 ---
  .../selftests/bpf/verifier/meta_access.c      |  235 ---
  .../selftests/bpf/verifier/raw_stack.c        |  305 ---
  .../selftests/bpf/verifier/raw_tp_writable.c  |   35 -
  .../testing/selftests/bpf/verifier/ringbuf.c  |   95 -
  .../selftests/bpf/verifier/spill_fill.c       |  345 ----
  .../selftests/bpf/verifier/stack_ptr.c        |  359 ----
  tools/testing/selftests/bpf/verifier/uninit.c |   39 -
  tools/testing/selftests/bpf/verifier/value.c  |  104 -
  .../selftests/bpf/verifier/value_adj_spill.c  |   43 -
  .../selftests/bpf/verifier/value_or_null.c    |  220 ---
  .../testing/selftests/bpf/verifier/var_off.c  |  291 ---
  tools/testing/selftests/bpf/verifier/xadd.c   |   97 -
  tools/testing/selftests/bpf/verifier/xdp.c    |   14 -
  .../bpf/verifier/xdp_direct_packet_access.c   | 1468 --------------
  84 files changed, 11994 insertions(+), 9000 deletions(-)

create mode 100644 tools/testing/selftests/bpf/autoconf_helper.h create mode 100644 tools/testing/selftests/bpf/prog_tests/verifier.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_and.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_array_access.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_basic_stack.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_bounds_deduction.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_bounds_mix_sign_unsign.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_cfg.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_cgroup_inv_retcode.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_cgroup_skb.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_cgroup_storage.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_const_or.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_ctx_sk_msg.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_direct_stack_access_wraparound.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_div0.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_div_overflow.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_helper_access_var_len.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_helper_packet_access.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_helper_restricted.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_helper_value_access.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_int_ptr.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_ld_ind.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_leak_ptr.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_map_ptr.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_map_ret_val.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_masking.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_meta_access.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_raw_stack.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_raw_tp_writable.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_ringbuf.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_spill_fill.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_stack_ptr.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_uninit.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_value.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_value_adj_spill.c
create mode 100644
tools/testing/selftests/bpf/progs/verifier_value_or_null.c
create mode 100644 tools/testing/selftests/bpf/progs/verifier_var_off.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_xadd.c create mode 100644 tools/testing/selftests/bpf/progs/verifier_xdp.c create mode 100644
tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
create mode 100644 tools/testing/selftests/bpf/unpriv_helpers.c create mode 100644 tools/testing/selftests/bpf/unpriv_helpers.h delete mode 100644 tools/testing/selftests/bpf/verifier/and.c delete mode 100644 tools/testing/selftests/bpf/verifier/array_access.c delete mode 100644 tools/testing/selftests/bpf/verifier/basic_stack.c delete mode 100644
tools/testing/selftests/bpf/verifier/bounds_deduction.c
delete mode 100644
tools/testing/selftests/bpf/verifier/bounds_mix_sign_unsign.c
delete mode 100644 tools/testing/selftests/bpf/verifier/cfg.c delete mode 100644
tools/testing/selftests/bpf/verifier/cgroup_inv_retcode.c
delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_skb.c delete mode 100644 tools/testing/selftests/bpf/verifier/cgroup_storage.c delete mode 100644 tools/testing/selftests/bpf/verifier/const_or.c delete mode 100644 tools/testing/selftests/bpf/verifier/ctx_sk_msg.c delete mode 100644
tools/testing/selftests/bpf/verifier/direct_stack_access_wraparound.c
delete mode 100644 tools/testing/selftests/bpf/verifier/div0.c delete mode 100644 tools/testing/selftests/bpf/verifier/div_overflow.c delete mode 100644
tools/testing/selftests/bpf/verifier/helper_access_var_len.c
delete mode 100644
tools/testing/selftests/bpf/verifier/helper_packet_access.c
delete mode 100644
tools/testing/selftests/bpf/verifier/helper_restricted.c
delete mode 100644
tools/testing/selftests/bpf/verifier/helper_value_access.c
delete mode 100644 tools/testing/selftests/bpf/verifier/int_ptr.c delete mode 100644 tools/testing/selftests/bpf/verifier/ld_ind.c delete mode 100644 tools/testing/selftests/bpf/verifier/leak_ptr.c delete mode 100644 tools/testing/selftests/bpf/verifier/map_ptr.c delete mode 100644 tools/testing/selftests/bpf/verifier/map_ret_val.c delete mode 100644 tools/testing/selftests/bpf/verifier/masking.c delete mode 100644 tools/testing/selftests/bpf/verifier/meta_access.c delete mode 100644 tools/testing/selftests/bpf/verifier/raw_stack.c delete mode 100644 tools/testing/selftests/bpf/verifier/raw_tp_writable.c delete mode 100644 tools/testing/selftests/bpf/verifier/ringbuf.c delete mode 100644 tools/testing/selftests/bpf/verifier/spill_fill.c delete mode 100644 tools/testing/selftests/bpf/verifier/stack_ptr.c delete mode 100644 tools/testing/selftests/bpf/verifier/uninit.c delete mode 100644 tools/testing/selftests/bpf/verifier/value.c delete mode 100644 tools/testing/selftests/bpf/verifier/value_adj_spill.c delete mode 100644 tools/testing/selftests/bpf/verifier/value_or_null.c delete mode 100644 tools/testing/selftests/bpf/verifier/var_off.c delete mode 100644 tools/testing/selftests/bpf/verifier/xadd.c delete mode 100644 tools/testing/selftests/bpf/verifier/xdp.c delete mode 100644
tools/testing/selftests/bpf/verifier/xdp_direct_packet_access.c

--
2.40.0

author maintainer
#44 lore raw
Quoted 9 lines · Stanislav Fomichev
Quoted 3 lines · Eduard Zingerman

This is a follow up for RFC [1]. It migrates a first batch of 38 verifier/*.c tests to inline assembly and use of ./test_progs for actual execution. The migration is done by a python script (see [2]).

Jesus Christ, 43 patches on a Friday night (^_^)
Unless I get bored on the weekend, will get to them Monday morning (or unless Alexei/Andrii beat me to it; I see they were commenting on the RFC).

Alexei and Andrii wanted this to be organized like one patch-set with patch per migrated file. I actually found the side-by-side comparison process to be quite painful, took me ~1.5 days to go through all migrated files. So, I can split this in smaller batches if that would make others life easier.

Also the last patch:

selftests/bpf: verifier/xdp_direct_packet_access.c converted to inline assembly

was blocked because it is too large. I'll split it in two in the v2 (but will wait for some feedback first).

[...]

Quoted 11 lines

Are those '\' at the end required? Can we do regular string coalescing like the following below?

asm volatile(

	"r2 = *(u32*)(r1 + %[xdp_md_data]);"
	"r3 = *(u32*)(r1 + %[xdp_md_data_end]);"
	"r1 = r2;"
	...

);

Or is asm directive somehow special?

Strings coalescing would work, I updated the script to support both modes, here is an example of verifier/and.c converted this way (caution, that test missuses BPF_ST_MEM and has a wrong jump, the
translation is fine):

https://gist.github.com/eddyz87/8725b9140098e1311ca5186c6ee73855

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Pros for '\':
- it indeed looks lighter;
- labels could be "inline", like in the example above "l0_%=: r0 = 0;". Cons for '\':
- harder to edit (although, at-least for emacs, I plan to solve this using https://github.com/twlz0ne/separedit.el);
- no syntax highlighting for comments.

Pros for string coalescing:
- easier to edit w/o special editor support;
- syntax highlighting for comments.
Cons for string coalescing:
- a bit harder to read;
- "inline" labels look super weird, so each labels takes a full line.

[...]

#45 lore raw
Quoted 18 lines · Eduard Zingerman
Quoted 9 lines · Stanislav Fomichev
Quoted 3 lines · Eduard Zingerman

This is a follow up for RFC [1]. It migrates a first batch of 38 verifier/*.c tests to inline assembly and use of ./test_progs for actual execution. The migration is done by a python script (see [2]).

Jesus Christ, 43 patches on a Friday night (^_^)
Unless I get bored on the weekend, will get to them Monday morning (or unless Alexei/Andrii beat me to it; I see they were commenting on the RFC).

Alexei and Andrii wanted this to be organized like one patch-set with patch per migrated file. I actually found the side-by-side comparison process to be quite painful, took me ~1.5 days to go through all migrated files. So, I can split this in smaller batches if that would make others life easier.

Quoted 6 lines

Also the last patch:

selftests/bpf: verifier/xdp_direct_packet_access.c converted to inline assembly

was blocked because it is too large. I'll split it in two in the v2 (but will wait for some feedback first).

Oh, sorry, I was joking and didn't mean this as a call to split it up. Was mostly trying to set the expectation that I'll be slacking off on the weekend :-)
(plus it seems like Alexei/Andrii would like a take a look anyway)

Quoted 19 lines

[...]

Quoted 11 lines

Are those '\' at the end required? Can we do regular string coalescing like the following below?

asm volatile(

      "r2 = *(u32*)(r1 + %[xdp_md_data]);"
      "r3 = *(u32*)(r1 + %[xdp_md_data_end]);"
      "r1 = r2;"
      ...

);

Or is asm directive somehow special?

Strings coalescing would work, I updated the script to support both modes, here is an example of verifier/and.c converted this way (caution, that test missuses BPF_ST_MEM and has a wrong jump, the
translation is fine):

Quoted 5 lines

https://gist.github.com/eddyz87/8725b9140098e1311ca5186c6ee73855

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

Quoted 16 lines

Pros for '\':
- it indeed looks lighter;
- labels could be "inline", like in the example above "l0_%=: r0 = 0;". Cons for '\':
- harder to edit (although, at-least for emacs, I plan to solve this using https://github.com/twlz0ne/separedit.el);
- no syntax highlighting for comments.

Pros for string coalescing:
- easier to edit w/o special editor support;
- syntax highlighting for comments.
Cons for string coalescing:
- a bit harder to read;
- "inline" labels look super weird, so each labels takes a full line.

[...]

#46 lore raw
Quoted 9 lines · Stanislav Fomichev
Quoted 5 lines

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

I still prefer the clean look of the tests, so I've applied this set.

But I'm not going to insist that this is the only style developers should use moving forward.
Whoever prefers "" style can use it in the future tests. I find them harder to read, but oh well.

Ed,
the only small nit I've noticed is that the tests are compiled for both test_progs and test_progs-no_alu32 though they're in asm. So we're wasting a bit of CI time running them in both flavors. Not a big deal and maybe not worth fixing, since they're pretty fast.

#47 lore raw
Quoted 12 lines · Alexei Starovoitov
Quoted 9 lines · Stanislav Fomichev
Quoted 5 lines

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

Quoted 5 lines

I still prefer the clean look of the tests, so I've applied this set.

But I'm not going to insist that this is the only style developers should use moving forward.
Whoever prefers "" style can use it in the future tests.

Great, because I found out in practice that inability to add comments to the manually written asm code is a pretty big limitation. I do like the lightweight feel of this unquoted style as well, but practically we'll probably have to live with both styles.

Quoted 7 lines

I find them harder to read, but oh well.

Ed,
the only small nit I've noticed is that the tests are compiled for both test_progs and test_progs-no_alu32 though they're in asm. So we're wasting a bit of CI time running them in both flavors. Not a big deal and maybe not worth fixing, since they're pretty fast.

#48 lore raw
Quoted 15 lines · Andrii Nakryiko
Quoted 12 lines · Alexei Starovoitov
Quoted 9 lines · Stanislav Fomichev
Quoted 5 lines

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

Quoted 8 lines
Quoted 5 lines

I still prefer the clean look of the tests, so I've applied this set.

But I'm not going to insist that this is the only style developers should use moving forward.
Whoever prefers "" style can use it in the future tests.

Great, because I found out in practice that inability to add comments to the manually written asm code is a pretty big limitation.

What do you mean by "inability" ?
The comments can be added. See verifier_and.c

        r0 &= 0xFFFF1234;                               \
        /* Upper bits are unknown but AND above masks out 1 zero'ing
lower bits */\
        if w0 < 1 goto l0_%=;                           \
author maintainer
#49 lore raw
Quoted 26 lines · Alexei Starovoitov
Quoted 15 lines · Andrii Nakryiko
Quoted 12 lines · Alexei Starovoitov
Quoted 9 lines · Stanislav Fomichev
Quoted 5 lines

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

Quoted 8 lines
Quoted 5 lines

I still prefer the clean look of the tests, so I've applied this set.

But I'm not going to insist that this is the only style developers should use moving forward.
Whoever prefers "" style can use it in the future tests.

Great, because I found out in practice that inability to add comments to the manually written asm code is a pretty big limitation.

Quoted 6 lines

What do you mean by "inability" ?
The comments can be added. See verifier_and.c

        r0 &= 0xFFFF1234;                               \
        /* Upper bits are unknown but AND above masks out 1 zero'ing
lower bits */\
        if w0 < 1 goto l0_%=;                           \

Yes, /* ... */ work as expected.
// work as well, but one has to be careful, because without \n the full string after first // would be a comment.

#50 lore raw
In reply to Alexei Starovoitov
Quoted 27 lines · Alexei Starovoitov
Quoted 15 lines · Andrii Nakryiko
Quoted 12 lines · Alexei Starovoitov
Quoted 9 lines · Stanislav Fomichev
Quoted 5 lines

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

Quoted 8 lines
Quoted 5 lines

I still prefer the clean look of the tests, so I've applied this set.

But I'm not going to insist that this is the only style developers should use moving forward.
Whoever prefers "" style can use it in the future tests.

Great, because I found out in practice that inability to add comments to the manually written asm code is a pretty big limitation.

Quoted 6 lines

What do you mean by "inability" ?
The comments can be added. See verifier_and.c

        r0 &= 0xFFFF1234;                               \
        /* Upper bits are unknown but AND above masks out 1 zero'ing
lower bits */\
        if w0 < 1 goto l0_%=;                           \

My bad. I remembered that there were problems with comments in Eduards previous revision and concluded that they don't work in this "\-delimited mode". Especially that online documentation for GCC or Clang didn't explicitly say that they support /* */ comments in asm blocks (as far as I could google that).

So now I know it's possible, thanks. I still find it very tedious to do manually, so I appreciate the flexibility in allowing to do ""-delimited style for new programs.

Just to explain where I'm coming from. I took one asm program I have locally and converted it to a new style. It was tedious with all the tab alignment. Then I realized that one comment block uses too long lines and wanted to use vim to reformat them, and that doesn't work with those '\' delimiters at the end (I didn't have such a problem with the original style). So that turned into more tedious work. So for something that needs iteration and adjustments, ""-delimited style gives more flexibility. See below for reference.

'#' comments are dangerous, btw, they silently ignore everything till the very end of asm block. No warning or error, just wrong and incomplete asm is generated, unfortunately.

SEC("?raw_tp")
__failure __log_level(2)
__msg("XXX")
__naked int subprog_result_precise(void)

{
        asm volatile (
                "r6 = 3;"
                /* pass r6 through r1 into subprog to get it back as r0;
                 * this whole chain will have to be marked as precise later
                 */
                "r1 = r6;"
                "call identity_subprog;"
                /* now use subprog's returned value (which is a
                 * r6 -> r1 -> r0 chain), as index into vals array, forcing
                 * all of that to be known precisely
                 */
                "r0 *= 4;"
                "r1 = %[vals];"
                "r1 += r0;"
                /* here r0->r1->r6 chain is forced to be precise and has to be
                 * propagated back to the beginning, including through the
                 * subprog call
                 */
                "r0 = *(u32 *)(r1 + 0);"
                "exit;"
                :
                : __imm_ptr(vals)
                : __clobber_common, "r6"
        );
}

SEC("?raw_tp")
__failure __log_level(2)
__msg("XXX")
__naked int subprog_result_precise2(void)

{
        asm volatile ("
         \
                r6 = 3;
         \
                /* pass r6 through r1 into subprog to get it back as
r0;        \
                 * this whole chain will have to be marked as precise
later     \
                 */
         \
                r1 = r6;
         \
                call identity_subprog;
         \
                /* now use subprog's returned value (which is a
         \
                 * r6 -> r1 -> r0 chain), as index into vals array,
forcing     \
                 * all of that to be known precisely
         \
                 */
         \
                r0 *= 4;
         \
                r1 = %[vals];
         \
                r1 += r0;
         \
                /* here r0->r1->r6 chain is forced to be precise and
has to be  \
                 * propagated back to the beginning, including through
the      \
                 * subprog call
         \
                 */
         \
                r0 = *(u32 *)(r1 + 0);
         \
                exit;
         \
                "
                :
                : __imm_ptr(vals)
                : __clobber_common, "r6"
        );
}
#51 lore raw
Quoted 129 lines · Andrii Nakryiko
Quoted 27 lines · Alexei Starovoitov
Quoted 15 lines · Andrii Nakryiko
Quoted 12 lines · Alexei Starovoitov
Quoted 9 lines · Stanislav Fomichev
Quoted 5 lines

It was my understanding from the RFC feedback that this "lighter" way is preferable and we already have some tests written like that. Don't have a strong opinion on this topic.

Ack, I'm obviously losing a bunch of context here :-(
I like coalescing better, but if the original suggestion was to use this lighter way, I'll keep that in mind while reviewing.

Quoted 8 lines
Quoted 5 lines

I still prefer the clean look of the tests, so I've applied this set.

But I'm not going to insist that this is the only style developers should use moving forward.
Whoever prefers "" style can use it in the future tests.

Great, because I found out in practice that inability to add comments to the manually written asm code is a pretty big limitation.

Quoted 6 lines

What do you mean by "inability" ?
The comments can be added. See verifier_and.c

        r0 &= 0xFFFF1234;                               \
        /* Upper bits are unknown but AND above masks out 1 zero'ing
lower bits */\
        if w0 < 1 goto l0_%=;                           \

My bad. I remembered that there were problems with comments in Eduards previous revision and concluded that they don't work in this "\-delimited mode". Especially that online documentation for GCC or Clang didn't explicitly say that they support /* */ comments in asm blocks (as far as I could google that).

So now I know it's possible, thanks. I still find it very tedious to do manually, so I appreciate the flexibility in allowing to do ""-delimited style for new programs.

Just to explain where I'm coming from. I took one asm program I have locally and converted it to a new style. It was tedious with all the tab alignment. Then I realized that one comment block uses too long lines and wanted to use vim to reformat them, and that doesn't work with those '\' delimiters at the end (I didn't have such a problem with the original style). So that turned into more tedious work. So for something that needs iteration and adjustments, ""-delimited style gives more flexibility. See below for reference.

'#' comments are dangerous, btw, they silently ignore everything till the very end of asm block. No warning or error, just wrong and incomplete asm is generated, unfortunately.

SEC("?raw_tp")
__failure __log_level(2)
__msg("XXX")
__naked int subprog_result_precise(void)

{
        asm volatile (
                "r6 = 3;"
                /* pass r6 through r1 into subprog to get it back as r0;
                 * this whole chain will have to be marked as precise later
                 */
                "r1 = r6;"
                "call identity_subprog;"
                /* now use subprog's returned value (which is a
                 * r6 -> r1 -> r0 chain), as index into vals array, forcing
                 * all of that to be known precisely
                 */
                "r0 *= 4;"
                "r1 = %[vals];"
                "r1 += r0;"
                /* here r0->r1->r6 chain is forced to be precise and has to be
                 * propagated back to the beginning, including through the
                 * subprog call
                 */
                "r0 = *(u32 *)(r1 + 0);"
                "exit;"
                :
                : __imm_ptr(vals)
                : __clobber_common, "r6"
        );
}

SEC("?raw_tp")
__failure __log_level(2)
__msg("XXX")
__naked int subprog_result_precise2(void)

{
        asm volatile ("
         \
                r6 = 3;
         \
                /* pass r6 through r1 into subprog to get it back as
r0;        \
                 * this whole chain will have to be marked as precise
later     \
                 */
         \
                r1 = r6;
         \
                call identity_subprog;
         \
                /* now use subprog's returned value (which is a
         \
                 * r6 -> r1 -> r0 chain), as index into vals array,
forcing     \
                 * all of that to be known precisely
         \
                 */
         \
                r0 *= 4;
         \
                r1 = %[vals];
         \
                r1 += r0;
         \
                /* here r0->r1->r6 chain is forced to be precise and
has to be  \
                 * propagated back to the beginning, including through
the      \
Quoted 8 lines
                 * subprog call
         \
                 */
         \
                r0 = *(u32 *)(r1 + 0);
         \
                exit;
         \

Great, Gmail doesn't like this style as well :( Sorry for the visual noise.

Quoted 6 lines
                "
                :
                : __imm_ptr(vals)
                : __clobber_common, "r6"
        );
}
#52 lore raw
In reply to Eduard Zingerman
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Sat, 25 Mar 2023 04:54:41 +0200 you wrote:

This is a follow up for RFC [1]. It migrates a first batch of 38 verifier/*.c tests to inline assembly and use of ./test_progs for actual execution. The migration is done by a python script (see [2]).

Each migrated verifier/xxx.c file is mapped to progs/verifier_xxx.c plus an entry in the prog_tests/verifier.c. One patch per each file.

[...]

Here is the summary with links:
- [bpf-next,01/43] selftests/bpf: Report program name on parse_test_spec error

    https://git.kernel.org/bpf/bpf-next/c/3e5329e193f4
  - [bpf-next,02/43] selftests/bpf: __imm_insn & __imm_const macro for bpf_misc.h
    https://git.kernel.org/bpf/bpf-next/c/207b1ba30191
  - [bpf-next,03/43] selftests/bpf: Unprivileged tests for test_loader.c
    https://git.kernel.org/bpf/bpf-next/c/1d56ade032a4
  - [bpf-next,04/43] selftests/bpf: Tests execution support for test_loader.c
    https://git.kernel.org/bpf/bpf-next/c/19a8e06f5f91
  - [bpf-next,05/43] selftests/bpf: prog_tests entry point for migrated test_verifier tests
    https://git.kernel.org/bpf/bpf-next/c/55108621a35e
  - [bpf-next,06/43] selftests/bpf: verifier/and.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/9d0f1568ad5b
  - [bpf-next,07/43] selftests/bpf: verifier/array_access.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/a3c830ae0209
  - [bpf-next,08/43] selftests/bpf: verifier/basic_stack.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/0ccbe4956d6c
  - [bpf-next,09/43] selftests/bpf: verifier/bounds_deduction.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/7605f94b3492
  - [bpf-next,10/43] selftests/bpf: verifier/bounds_mix_sign_unsign.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/b14a702afd0d
  - [bpf-next,11/43] selftests/bpf: verifier/cfg.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/2f2047c22cda
  - [bpf-next,12/43] selftests/bpf: verifier/cgroup_inv_retcode.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/047687a7f494
  - [bpf-next,13/43] selftests/bpf: verifier/cgroup_skb.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/b1b6372535c0
  - [bpf-next,14/43] selftests/bpf: verifier/cgroup_storage.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/8f16f3c07e46
  - [bpf-next,15/43] selftests/bpf: verifier/const_or.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/a2777eaad5d9
  - [bpf-next,16/43] selftests/bpf: verifier/ctx_sk_msg.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/a58475a98903
  - [bpf-next,17/43] selftests/bpf: verifier/direct_stack_access_wraparound.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/84988478fb2c
  - [bpf-next,18/43] selftests/bpf: verifier/div0.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/01a0925531a4
  - [bpf-next,19/43] selftests/bpf: verifier/div_overflow.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/9553de70a841
  - [bpf-next,20/43] selftests/bpf: verifier/helper_access_var_len.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/b37d776b431e
  - [bpf-next,21/43] selftests/bpf: verifier/helper_packet_access.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/fb179fe69e6a
  - [bpf-next,22/43] selftests/bpf: verifier/helper_restricted.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/77aa2563cb44
  - [bpf-next,23/43] selftests/bpf: verifier/helper_value_access.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/ecc424827b77
  - [bpf-next,24/43] selftests/bpf: verifier/int_ptr.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/01481e67dd4d
  - [bpf-next,25/43] selftests/bpf: verifier/ld_ind.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/e29787558066
  - [bpf-next,26/43] selftests/bpf: verifier/leak_ptr.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/583c7ce5be09
  - [bpf-next,27/43] selftests/bpf: verifier/map_ptr.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/caf345cf1207
  - [bpf-next,28/43] selftests/bpf: verifier/map_ret_val.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/05e474ecbb56
  - [bpf-next,29/43] selftests/bpf: verifier/masking.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/ade3f08fc236
  - [bpf-next,30/43] selftests/bpf: verifier/meta_access.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/65428312e38d
  - [bpf-next,31/43] selftests/bpf: verifier/raw_stack.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/5a77a01f3320
  - [bpf-next,32/43] selftests/bpf: verifier/raw_tp_writable.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/18cdc2b531fb
  - [bpf-next,33/43] selftests/bpf: verifier/ringbuf.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/b7e4203086eb
  - [bpf-next,34/43] selftests/bpf: verifier/spill_fill.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/f4fe3cfe6c3a
  - [bpf-next,35/43] selftests/bpf: verifier/stack_ptr.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/edff37b2f28f
  - [bpf-next,36/43] selftests/bpf: verifier/uninit.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/ab839a581946
  - [bpf-next,37/43] selftests/bpf: verifier/value_adj_spill.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/033914942da4
  - [bpf-next,38/43] selftests/bpf: verifier/value.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/8f59e87a3bc6
  - [bpf-next,39/43] selftests/bpf: verifier/value_or_null.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/d330528617b7
  - [bpf-next,40/43] selftests/bpf: verifier/var_off.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/d15f5b68b63a
  - [bpf-next,41/43] selftests/bpf: verifier/xadd.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/a8036aea2d4f
  - [bpf-next,42/43] selftests/bpf: verifier/xdp.c converted to inline assembly
    https://git.kernel.org/bpf/bpf-next/c/ffb515c933a9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
maintainer
#53 lore raw
In reply to Eduard Zingerman

Hi Eduard,

Quoted 61 lines · Eduard Zingerman

This is a follow up for RFC [1]. It migrates a first batch of 38 verifier/*.c tests to inline assembly and use of ./test_progs for actual execution. The migration is done by a python script (see [2]).

Each migrated verifier/xxx.c file is mapped to progs/verifier_xxx.c plus an entry in the prog_tests/verifier.c. One patch per each file.

A few patches at the beginning of the patch-set extend test_loader with necessary functionality, mainly:
- support for tests execution in unprivileged mode;
- support for test runs for test programs.

Migrated tests could be selected for execution using the following filter:

./test_progs -a verifier_*

An example of the migrated test:

   SEC("xdp")
   __description("XDP pkt read, pkt_data' > pkt_end, corner case, good access")
   __success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
   __naked void end_corner_case_good_access_1(void)
   {
           asm volatile ("                                 \
           r2 = *(u32*)(r1 + %[xdp_md_data]);              \
           r3 = *(u32*)(r1 + %[xdp_md_data_end]);          \
           r1 = r2;                                        \
           r1 += 8;                                        \
           if r1 > r3 goto l0_%=;                          \
           r0 = *(u64*)(r1 - 8);                           \
   l0_%=:  r0 = 0;                                         \
           exit;                                           \
   "       :
           : __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
             __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
           : __clobber_all);
   }

Changes compared to RFC:
- test_loader.c is extended to support test program runs;
- capabilities handling now matches behavior of test_verifier;
- BPF_ST_MEM instructions are automatically replaced by BPF_STX_MEM instructions to overcome current clang limitations;
- tests styling updates according to RFC feedback;
- 38 migrated files are included instead of 1.

I used the following means for testing:
- migration tool itself has a set of self-tests;
- migrated tests are passing;
- manually compared each old/new file side-by-side.

While doing side-by-side comparison I've noted a few defects in the original tests:
- and.c:
- One of the jump targets is off by one;
- BPF_ST_MEM wrong OFF/IMM ordering;
- array_access.c:
- BPF_ST_MEM wrong OFF/IMM ordering;
- value_or_null.c:
- BPF_ST_MEM wrong OFF/IMM ordering.

Quoted 1 line

These defects would be addressed separately.

The cover letter describes what this series does, but not /why/ we need it. Would be useful in future to also have the rationale in here. The migration of the verifier tests look ok, and probably simplifies things to some degree, it certainly makes the tests more readable. Is the goal to eventually get rid of test_verifier altogether? I don't think we fully can do that, e.g. what about verifier testing of invalid insn encodings or things like invalid jumps into the middle of double insns, invalid call offsets, etc?

Quoted 4 lines

[1] RFC

     https://lore.kernel.org/bpf/[email protected]/

[2] Migration tool
https://github.com/eddyz87/verifier-tests-migrator

Thanks,
Daniel

author maintainer
#54 lore raw

Hi Daniel,

[...]

Quoted 5 lines

The cover letter describes what this series does, but not /why/ we need it. Would be useful in future to also have the rationale in here. The migration of the verifier tests look ok, and probably simplifies things to some degree, it certainly makes the tests more readable. Is the goal to eventually get rid of test_verifier altogether?

In total there are 57 verifier/*.c files remaining. I've inspected each and came up with the following categories:
- tool limitation;
- simplistic;
- asm parser issue;
- pseudo-call instructions;
- custom macro;
- .fill_helper;
- libbpf discards junk;
- small log buffer.

Categories are described in the following sections, per-test summary is in the end.

The files that are not 'simplistic', not '.fill_helper' and not 'libbpf discards junk' could be migrated with some additional work.
This gives ~40 files to migrate and ~17 to leave as-is or migrate only partially.

Quoted 3 lines

I don't think we fully can do that, e.g. what about verifier testing of invalid insn encodings or things like invalid jumps into the middle of double insns, invalid call offsets, etc?

Looks like it is the case. E.g. for invalid instructions I can get away with some junk using the following trick:

    asm volatile (".8byte %[raw_insn];"
                  :
                  : __imm_insn(raw_insn, BPF_RAW_INSN(0, 0, 0, 0, 0))
                  : __clobber_all);

But some junk is still rejected by libbpf.

# Migration tool limitations (23 files)

The tool does not know how to migrate tests that use specific features:
- test description field .expected_attach_type;
- test description field .fixup_prog1, .fixup_prog2;
- test description field .retvals and .data, this also requires support on test_loader.c side;
- BPF_ENDIAN(BPF_TO_**, BPF_REG_0, 16) instruction;
- BPF_SK_LOOKUP macro;
- #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ blocks;

I will update migration tool to handle the cases above.

# Simplistic tests (14 files)

Some tests are just simplistic and it is not clear if moving those to inline assembly really makes sense, for example, here is basic_call.c:

    {
    	"invalid call insn1",
    	.insns = {
    	BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0),
    	BPF_EXIT_INSN(),
    	},
    	.errstr = "unknown opcode 8d",
    	.result = REJECT,
    },

# LLVM assembler parser issues (10 files)

There are parsing issues with some constructs, for example:

	r1 = atomic_fetch_xor((u64 *)(r10 - 8), r1);

Produces the following diagnostic:

    progs/verifier_b2_atomic_xor.c:45:1: error: unexpected token
           r1 = atomic_fetch_xor((u64 *)(r10 - 8), r1);    \n\
    ^
    <inline asm>:7:40: note: instantiated into assembly here
           r1 = atomic_fetch_xor((u64 *)(r10 - 8), r1); 
                                                 ^

I checked LLVM tests and the syntax seems to be correct (at-least this syntax is used by disassembler). So far I know that the following constructs are affected:
- atomic_fetch_and
- atomic_fetch_cmpxchg
- atomic_fetch_or
- atomic_fetch_xchg
- atomic_fetch_xor

Requires further investigation and a fix in LLVM.

# Pseudo-call instructions (9 files)

An object file might contain several BPF programs plus some functions used from different programs. In order to load a program from such file, libbpf creates a buffer and copies the program and all functions called from this program into that buffer. For each visited pseudo-call instruction libbpf requires it to point to a valid function described in ELF header.

However, this is not how verifier/*.c tests are written, for example here is a translated fragment from verifier/loops1.c:

    SEC("tracepoint")
    __description("bounded recursion")
    __failure __msg("back-edge")
    __naked void bounded_recursion(void)
    {
            asm volatile ("                                 \
            r1 = 0;                                         \
            call l0_%=;                                     \
            exit;                                           \
    l0_%=:  r1 += 1;                                        \
            r0 = r1;                                        \
            if r1 < 4 goto l1_%=;                           \
            exit;                                           \
    l1_%=:  call l0_%=;                                     \
            exit;                                           \
    "       ::: __clobber_all);
    }

There are several possibilities here:
- split such tests into several functions during migration;
- add a special flag for libbpf asking to allow such calls;
- Andrii also suggested to try using .section directives inside inline assembly block.

This requires further investigation, I'll discuss it with Andrii some time later this week or on Monday.

# Custom macro definitions (5 files)

Some tests define and use custom macro, e.g. atomic_fetch.c:

    #define __ATOMIC_FETCH_OP_TEST(src_reg, dst_reg, operand1, op, operand2, expect) ...
    
    __ATOMIC_FETCH_OP_TEST(BPF_REG_1, BPF_REG_2, 1, BPF_ADD | BPF_FETCH, 2, 3),
    __ATOMIC_FETCH_OP_TEST(BPF_REG_0, BPF_REG_1, 1, BPF_ADD | BPF_FETCH, 2, 3),
    // ...

Such tests would have to be migrated manually (the tool still can translate portions of the test).

# .fill_helper (5 files)

Programs for some tests are generated programmatically by specifying .fill_helper function in the test description, e.g. verifier/scale.c:

    {
    	"scale: scale test 1",
    	.insns = { },
    	.data = { },
    	.fill_helper = bpf_fill_scale,
    	.prog_type = BPF_PROG_TYPE_SCHED_CLS,
    	.result = ACCEPT,
    	.retval = 1,
    },

Such tests cannot be migrated
(but sometimes these are not the only tests in the file).

# libbpf does not like some junk code (3 files)

libbpf (and bpftool) reject some junk instructions intentionally encoded in the tests, e.g. empty program from verifier/basic.c:

    SEC("socket")
    __description("empty prog")
    __failure __msg("last insn is not an exit or jmp")
    __failure_unpriv
    __naked void empty_prog(void)
    {
            asm volatile ("" ::: __clobber_all);
    }

# Small log buffer (2 files)

Currently test_loader.c uses 1Mb log buffer, while test_verifier.c uses 16Mb log buffer. There are a few tests (like in verifier/bounds.c) that exit with -ESPC for 1Mb buffer.

I can either bump log buffer size for test_loader.c or wait until Andrii's rotating log implementation lands.

# Per-test summary

- atomic_and               - asm parser issue;
- atomic_bounds            - asm parser issue;
- atomic_cmpxchg           - asm parser issue;
- atomic_fetch             - asm parser issue, tool limitation;
- atomic_fetch_add         - asm parser issue, uses macro;
- atomic_invalid           - simplistic, uses macro;
- atomic_or                - asm parser issue;
- atomic_xchg              - asm parser issue;
- atomic_xor               - asm parser issue;
- basic                    - simplistic, libbpf discards junk;
- basic_call               - simplistic;
- basic_instr              - tool limitation;
- basic_stx_ldx            - simplistic;
- bounds                   - small log buffer;
- bpf_get_stack            - tool limitation;
- bpf_loop_inline          - uses macro, uses .fill_helper;
- bpf_st_mem               - asm parser issue;
- btf_ctx_access           - tool limitation;
- calls                    - tool limitation, pseudo call;
- ctx                      - simplistic, tool limitation;
- ctx_sk_lookup            - simplistic, tool limitation;
- ctx_skb                  - simplistic, tool limitation;
- d_path                   - tool limitation;
- dead_code                - pseudo call;
- direct_packet_access     - pseudo call;
- direct_value_access      - pseudo call;
- event_output             - uses macro;
- jeq_infer_not_null       - ok;
- jit                      - uses .fill_helper;
- jmp32                    - tool limitation;
- jset                     - asm parser issue, tool limitation;
- jump                     - pseudo call;
- junk_insn                - simplistic, libbpf discards junk;
- ld_abs                   - uses .fill_helper;
- ld_dw                    - simplistic, uses .fill_helper;
- ld_imm64                 - simplistic, junk rejected by bpftool
- loops1                   - small log buffer, pseudo call;
- lwt                      - tool limitation;
- map_in_map               - ok (needs __msg update because of BPF_ST_MEM rewrite);
- map_kptr                 - strange runtime issue, requires further investigation;
- map_ptr_mixing           - tool limitation;
- perf_event_sample_period - simplistic, tool limitation;
- precise                  - pseudo call, needs __msg update because of BPF_ST_MEM rewrite;
- prevent_map_lookup       - tool limitation;
- ref_tracking             - tool limitation;
- regalloc                 - pseudo call
- runtime_jit              - tool limitation;
- scale                    - simplistic, uses .fill_helper;
- search_pruning           - tool limitation;
- sleepable                - simplistic, tool limitation;
- sock                     - ok (needs __msg update because of BPF_ST_MEM rewrite);
- spin_lock                - pseudo call;
- subreg                   - tool limitation;
- unpriv                   - tool limitation;
- value_illegal_alu        - tool limitation;
- value_ptr_arith          - tool limitation;
- wide_access              - simplistic, uses macro;

Thanks,
Eduard

#55 lore raw
Quoted 52 lines · Eduard Zingerman

Hi Daniel,

[...]

Quoted 5 lines

The cover letter describes what this series does, but not /why/ we need it. Would be useful in future to also have the rationale in here. The migration of the verifier tests look ok, and probably simplifies things to some degree, it certainly makes the tests more readable. Is the goal to eventually get rid of test_verifier altogether?

In total there are 57 verifier/*.c files remaining. I've inspected each and came up with the following categories:
- tool limitation;
- simplistic;
- asm parser issue;
- pseudo-call instructions;
- custom macro;
- .fill_helper;
- libbpf discards junk;
- small log buffer.

Categories are described in the following sections, per-test summary is in the end.

The files that are not 'simplistic', not '.fill_helper' and not 'libbpf discards junk' could be migrated with some additional work.
This gives ~40 files to migrate and ~17 to leave as-is or migrate only partially.

Quoted 3 lines

I don't think we fully can do that, e.g. what about verifier testing of invalid insn encodings or things like invalid jumps into the middle of double insns, invalid call offsets, etc?

Looks like it is the case. E.g. for invalid instructions I can get away with some junk using the following trick:

    asm volatile (".8byte %[raw_insn];"
                  :
                  : __imm_insn(raw_insn, BPF_RAW_INSN(0, 0, 0, 0, 0))
                  : __clobber_all);

But some junk is still rejected by libbpf.

# Migration tool limitations (23 files)

The tool does not know how to migrate tests that use specific features:
- test description field .expected_attach_type;
- test description field .fixup_prog1, .fixup_prog2;
- test description field .retvals and .data, this also requires support on test_loader.c side;
- BPF_ENDIAN(BPF_TO_**, BPF_REG_0, 16) instruction;
- BPF_SK_LOOKUP macro;
- #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ blocks;

Quoted 2 lines

I will update migration tool to handle the cases above.

Great, this seems to be covered.

Quoted 5 lines

# Simplistic tests (14 files)

Some tests are just simplistic and it is not clear if moving those to inline assembly really makes sense, for example, here is basic_call.c:

Quoted 10 lines
    {
        "invalid call insn1",
        .insns = {
        BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0),
        BPF_EXIT_INSN(),
        },
        .errstr = "unknown opcode 8d",
        .result = REJECT,
    },

For tests like this we can have a simple ELF parser/loader that doesn't use bpf_object__open() functionality. It's not too hard to just find all the FUNC ELF symbols and fetch corresponding raw instructions. Assumption here is that we can take those assembly instructions as is, of course. If there are some map references and such, this won't work.

Quoted 23 lines

# LLVM assembler parser issues (10 files)

There are parsing issues with some constructs, for example:

        r1 = atomic_fetch_xor((u64 *)(r10 - 8), r1);

Produces the following diagnostic:

    progs/verifier_b2_atomic_xor.c:45:1: error: unexpected token
           r1 = atomic_fetch_xor((u64 *)(r10 - 8), r1);    \n\
    ^
    <inline asm>:7:40: note: instantiated into assembly here
           r1 = atomic_fetch_xor((u64 *)(r10 - 8), r1);
                                                 ^

I checked LLVM tests and the syntax seems to be correct (at-least this syntax is used by disassembler). So far I know that the following constructs are affected:
- atomic_fetch_and
- atomic_fetch_cmpxchg
- atomic_fetch_or
- atomic_fetch_xchg
- atomic_fetch_xor

Quoted 2 lines

Requires further investigation and a fix in LLVM.

+1

Quoted 29 lines

# Pseudo-call instructions (9 files)

An object file might contain several BPF programs plus some functions used from different programs. In order to load a program from such file, libbpf creates a buffer and copies the program and all functions called from this program into that buffer. For each visited pseudo-call instruction libbpf requires it to point to a valid function described in ELF header.

However, this is not how verifier/*.c tests are written, for example here is a translated fragment from verifier/loops1.c:

    SEC("tracepoint")
    __description("bounded recursion")
    __failure __msg("back-edge")
    __naked void bounded_recursion(void)
    {
            asm volatile ("                                 \
            r1 = 0;                                         \
            call l0_%=;                                     \
            exit;                                           \
    l0_%=:  r1 += 1;                                        \
            r0 = r1;                                        \
            if r1 < 4 goto l1_%=;                           \
            exit;                                           \
    l1_%=:  call l0_%=;                                     \
            exit;                                           \
    "       ::: __clobber_all);
    }
Quoted 8 lines

There are several possibilities here:
- split such tests into several functions during migration;
- add a special flag for libbpf asking to allow such calls;
- Andrii also suggested to try using .section directives inside inline assembly block.

This requires further investigation, I'll discuss it with Andrii some time later this week or on Monday.

So I did try this a few weeks ago, and yes, you can make this work with assembly directives. Except that DWARF (and thus .BTF and .BTF.ext) information won't be emitted, as it is emitted very painfully and manually by C compiler as explicit assembly directives. But we might work around that by clearing .BTF and .BTF.ext information for such object files, perhaps. So tentatively this should be doable.

Quoted 29 lines

# Custom macro definitions (5 files)

Some tests define and use custom macro, e.g. atomic_fetch.c:

    #define __ATOMIC_FETCH_OP_TEST(src_reg, dst_reg, operand1, op, operand2, expect) ...

    __ATOMIC_FETCH_OP_TEST(BPF_REG_1, BPF_REG_2, 1, BPF_ADD | BPF_FETCH, 2, 3),
    __ATOMIC_FETCH_OP_TEST(BPF_REG_0, BPF_REG_1, 1, BPF_ADD | BPF_FETCH, 2, 3),
    // ...

Such tests would have to be migrated manually (the tool still can translate portions of the test).

# .fill_helper (5 files)

Programs for some tests are generated programmatically by specifying .fill_helper function in the test description, e.g. verifier/scale.c:

    {
        "scale: scale test 1",
        .insns = { },
        .data = { },
        .fill_helper = bpf_fill_scale,
        .prog_type = BPF_PROG_TYPE_SCHED_CLS,
        .result = ACCEPT,
        .retval = 1,
    },
Quoted 2 lines

Such tests cannot be migrated
(but sometimes these are not the only tests in the file).

We can just write these as explicitly programmatically generated programs, probably. There are just a few of these, shouldn't be a big deal.

Quoted 6 lines
# libbpf does not like some junk code (3 files)

libbpf (and bpftool) reject some junk instructions intentionally encoded in the tests, e.g. empty program from verifier/basic.c:

Quoted 6 lines

SEC("socket")
__description("empty prog")
__failure __msg("last insn is not an exit or jmp") __failure_unpriv
__naked void empty_prog(void)
{

even if you add some random "r0 = 0" instruction? It won't change the meaning of the test, but should work with libbpf.

Quoted 11 lines
            asm volatile ("" ::: __clobber_all);
    }

# Small log buffer (2 files)

Currently test_loader.c uses 1Mb log buffer, while test_verifier.c uses 16Mb log buffer. There are a few tests (like in verifier/bounds.c) that exit with -ESPC for 1Mb buffer.

I can either bump log buffer size for test_loader.c or wait until Andrii's rotating log implementation lands.

Just bump to 16MB, no need to wait on anything.

Quoted 63 lines

# Per-test summary

- atomic_and               - asm parser issue;
- atomic_bounds            - asm parser issue;
- atomic_cmpxchg           - asm parser issue;
- atomic_fetch             - asm parser issue, tool limitation;
- atomic_fetch_add         - asm parser issue, uses macro;
- atomic_invalid           - simplistic, uses macro;
- atomic_or                - asm parser issue;
- atomic_xchg              - asm parser issue;
- atomic_xor               - asm parser issue;
- basic                    - simplistic, libbpf discards junk;
- basic_call               - simplistic;
- basic_instr              - tool limitation;
- basic_stx_ldx            - simplistic;
- bounds                   - small log buffer;
- bpf_get_stack            - tool limitation;
- bpf_loop_inline          - uses macro, uses .fill_helper;
- bpf_st_mem               - asm parser issue;
- btf_ctx_access           - tool limitation;
- calls                    - tool limitation, pseudo call;
- ctx                      - simplistic, tool limitation;
- ctx_sk_lookup            - simplistic, tool limitation;
- ctx_skb                  - simplistic, tool limitation;
- d_path                   - tool limitation;
- dead_code                - pseudo call;
- direct_packet_access     - pseudo call;
- direct_value_access      - pseudo call;
- event_output             - uses macro;
- jeq_infer_not_null       - ok;
- jit                      - uses .fill_helper;
- jmp32                    - tool limitation;
- jset                     - asm parser issue, tool limitation;
- jump                     - pseudo call;
- junk_insn                - simplistic, libbpf discards junk;
- ld_abs                   - uses .fill_helper;
- ld_dw                    - simplistic, uses .fill_helper;
- ld_imm64                 - simplistic, junk rejected by bpftool
- loops1                   - small log buffer, pseudo call;
- lwt                      - tool limitation;
- map_in_map               - ok (needs __msg update because of BPF_ST_MEM rewrite);
- map_kptr                 - strange runtime issue, requires further investigation;
- map_ptr_mixing           - tool limitation;
- perf_event_sample_period - simplistic, tool limitation;
- precise                  - pseudo call, needs __msg update because of BPF_ST_MEM rewrite;
- prevent_map_lookup       - tool limitation;
- ref_tracking             - tool limitation;
- regalloc                 - pseudo call
- runtime_jit              - tool limitation;
- scale                    - simplistic, uses .fill_helper;
- search_pruning           - tool limitation;
- sleepable                - simplistic, tool limitation;
- sock                     - ok (needs __msg update because of BPF_ST_MEM rewrite);
- spin_lock                - pseudo call;
- subreg                   - tool limitation;
- unpriv                   - tool limitation;
- value_illegal_alu        - tool limitation;
- value_ptr_arith          - tool limitation;
- wide_access              - simplistic, uses macro;

Thanks,
Eduard

author maintainer
#56 lore raw

On Tue, 2023-03-28 at 15:24 -0700, Andrii Nakryiko wrote:
[...]

Quoted 17 lines
Quoted 6 lines

# Simplistic tests (14 files)

Some tests are just simplistic and it is not clear if moving those to inline assembly really makes sense, for example, here is basic_call.c:

Quoted 10 lines
    {
        "invalid call insn1",
        .insns = {
        BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0),
        BPF_EXIT_INSN(),
        },
        .errstr = "unknown opcode 8d",
        .result = REJECT,
    },
Quoted 6 lines

For tests like this we can have a simple ELF parser/loader that doesn't use bpf_object__open() functionality. It's not too hard to just find all the FUNC ELF symbols and fetch corresponding raw instructions. Assumption here is that we can take those assembly instructions as is, of course. If there are some map references and such, this won't work.

Custom elf parser/loader is interesting. However, also consider how such tests look in assembly:

    SEC("socket")
    __description("invalid call insn1")
    __failure __msg("unknown opcode 8d")
    __failure_unpriv
    __naked void invalid_call_insn1(void)
    {
            asm volatile ("                                 \
            .8byte %[raw_insn];                             \
            exit;                                           \
    "       :
            : __imm_insn(raw_insn, BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0))
            : __clobber_all);
    }

I'd say that original is better.
Do you want to get rid of ./test_verifier binary?
If so, we can move such tests under ./test_progs w/o converting to inline assembly.

[...]

Quoted 39 lines
Quoted 30 lines

# Pseudo-call instructions (9 files)

An object file might contain several BPF programs plus some functions used from different programs. In order to load a program from such file, libbpf creates a buffer and copies the program and all functions called from this program into that buffer. For each visited pseudo-call instruction libbpf requires it to point to a valid function described in ELF header.

However, this is not how verifier/*.c tests are written, for example here is a translated fragment from verifier/loops1.c:

    SEC("tracepoint")
    __description("bounded recursion")
    __failure __msg("back-edge")
    __naked void bounded_recursion(void)
    {
            asm volatile ("                                 \
            r1 = 0;                                         \
            call l0_%=;                                     \
            exit;                                           \
    l0_%=:  r1 += 1;                                        \
            r0 = r1;                                        \
            if r1 < 4 goto l1_%=;                           \
            exit;                                           \
    l1_%=:  call l0_%=;                                     \
            exit;                                           \
    "       ::: __clobber_all);
    }
Quoted 8 lines

There are several possibilities here:
- split such tests into several functions during migration;
- add a special flag for libbpf asking to allow such calls;
- Andrii also suggested to try using .section directives inside inline assembly block.

This requires further investigation, I'll discuss it with Andrii some time later this week or on Monday.

Quoted 7 lines

So I did try this a few weeks ago, and yes, you can make this work with assembly directives. Except that DWARF (and thus .BTF and .BTF.ext) information won't be emitted, as it is emitted very painfully and manually by C compiler as explicit assembly directives. But we might work around that by clearing .BTF and .BTF.ext information for such object files, perhaps. So tentatively this should be doable.

Could you please share an example?

[...]

Quoted 15 lines
Quoted 15 lines

# .fill_helper (5 files)

Programs for some tests are generated programmatically by specifying .fill_helper function in the test description, e.g. verifier/scale.c:

    {
        "scale: scale test 1",
        .insns = { },
        .data = { },
        .fill_helper = bpf_fill_scale,
        .prog_type = BPF_PROG_TYPE_SCHED_CLS,
        .result = ACCEPT,
        .retval = 1,
    },
Quoted 6 lines
Quoted 2 lines

Such tests cannot be migrated
(but sometimes these are not the only tests in the file).

We can just write these as explicitly programmatically generated programs, probably. There are just a few of these, shouldn't be a big deal.

You mean move the generating function from test_verifier.c to some test under prog_tests/whatever.c, right?

Quoted 12 lines
Quoted 11 lines
# libbpf does not like some junk code (3 files)

libbpf (and bpftool) reject some junk instructions intentionally encoded in the tests, e.g. empty program from verifier/basic.c:

SEC("socket")
__description("empty prog")
__failure __msg("last insn is not an exit or jmp") __failure_unpriv
__naked void empty_prog(void)
{

Quoted 2 lines

even if you add some random "r0 = 0" instruction? It won't change the meaning of the test, but should work with libbpf.

Random instruction should work.

Quoted 6 lines
Quoted 6 lines
            asm volatile ("" ::: __clobber_all);
    }

# Small log buffer (2 files)

Quoted 8 lines
Quoted 6 lines

Currently test_loader.c uses 1Mb log buffer, while test_verifier.c uses 16Mb log buffer. There are a few tests (like in verifier/bounds.c) that exit with -ESPC for 1Mb buffer.

I can either bump log buffer size for test_loader.c or wait until Andrii's rotating log implementation lands.

Just bump to 16MB, no need to wait on anything.

Will do.

[...]

#57 lore raw
Quoted 44 lines · Eduard Zingerman

On Tue, 2023-03-28 at 15:24 -0700, Andrii Nakryiko wrote:
[...]

Quoted 17 lines
Quoted 6 lines

# Simplistic tests (14 files)

Some tests are just simplistic and it is not clear if moving those to inline assembly really makes sense, for example, here is basic_call.c:

Quoted 10 lines
    {
        "invalid call insn1",
        .insns = {
        BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0),
        BPF_EXIT_INSN(),
        },
        .errstr = "unknown opcode 8d",
        .result = REJECT,
    },
Quoted 6 lines

For tests like this we can have a simple ELF parser/loader that doesn't use bpf_object__open() functionality. It's not too hard to just find all the FUNC ELF symbols and fetch corresponding raw instructions. Assumption here is that we can take those assembly instructions as is, of course. If there are some map references and such, this won't work.

Custom elf parser/loader is interesting. However, also consider how such tests look in assembly:

    SEC("socket")
    __description("invalid call insn1")
    __failure __msg("unknown opcode 8d")
    __failure_unpriv
    __naked void invalid_call_insn1(void)
    {
            asm volatile ("                                 \
            .8byte %[raw_insn];                             \
            exit;                                           \
    "       :
            : __imm_insn(raw_insn, BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0))
            : __clobber_all);
    }
Quoted 1 line

I'd say that original is better.

+1

Quoted 1 line

Do you want to get rid of ./test_verifier binary?

All this work looks like a diminishing return.
It's ok to keep test_verifier around.
All new asm test can already go into test_progs and in some rare cases test_verifier will be a better home for them.

#58 lore raw
Quoted 48 lines · Alexei Starovoitov
Quoted 44 lines · Eduard Zingerman

On Tue, 2023-03-28 at 15:24 -0700, Andrii Nakryiko wrote:
[...]

Quoted 17 lines
Quoted 6 lines

# Simplistic tests (14 files)

Some tests are just simplistic and it is not clear if moving those to inline assembly really makes sense, for example, here is basic_call.c:

Quoted 10 lines
    {
        "invalid call insn1",
        .insns = {
        BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0),
        BPF_EXIT_INSN(),
        },
        .errstr = "unknown opcode 8d",
        .result = REJECT,
    },
Quoted 6 lines

For tests like this we can have a simple ELF parser/loader that doesn't use bpf_object__open() functionality. It's not too hard to just find all the FUNC ELF symbols and fetch corresponding raw instructions. Assumption here is that we can take those assembly instructions as is, of course. If there are some map references and such, this won't work.

Custom elf parser/loader is interesting. However, also consider how such tests look in assembly:

    SEC("socket")
    __description("invalid call insn1")
    __failure __msg("unknown opcode 8d")
    __failure_unpriv
    __naked void invalid_call_insn1(void)
    {
            asm volatile ("                                 \
            .8byte %[raw_insn];                             \
            exit;                                           \
    "       :
            : __imm_insn(raw_insn, BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0))
            : __clobber_all);
    }
Quoted 1 line

I'd say that original is better.

Quoted 8 lines

+1

Quoted 1 line

Do you want to get rid of ./test_verifier binary?

All this work looks like a diminishing return.
It's ok to keep test_verifier around.
All new asm test can already go into test_progs and in some rare cases test_verifier will be a better home for them.

I definitely don't want us to go crazy and just reimplement test_verifier.c inside test_progs, of course. But I do see value of getting rid of test_verifier as a separate test runner (and hopefully most of 1.7K lines of code in test_verifier.c). I do agree that these bad/raw instructions are not the most readable alternative, though.

But taking those few tests with invalid instructions and patterns (using BPF_RAW_INSN() macro and others) and writing them as explicit test_progs' test with bpf_prog_load() seems like a better alternative. test_progs has much better integration with BPF CI, and not having to remember to run test_verifier locally seems like a win.

#59 lore raw
In reply to Eduard Zingerman
Quoted 44 lines · Eduard Zingerman

On Tue, 2023-03-28 at 15:24 -0700, Andrii Nakryiko wrote:
[...]

Quoted 17 lines
Quoted 6 lines

# Simplistic tests (14 files)

Some tests are just simplistic and it is not clear if moving those to inline assembly really makes sense, for example, here is basic_call.c:

Quoted 10 lines
    {
        "invalid call insn1",
        .insns = {
        BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0),
        BPF_EXIT_INSN(),
        },
        .errstr = "unknown opcode 8d",
        .result = REJECT,
    },
Quoted 6 lines

For tests like this we can have a simple ELF parser/loader that doesn't use bpf_object__open() functionality. It's not too hard to just find all the FUNC ELF symbols and fetch corresponding raw instructions. Assumption here is that we can take those assembly instructions as is, of course. If there are some map references and such, this won't work.

Custom elf parser/loader is interesting. However, also consider how such tests look in assembly:

    SEC("socket")
    __description("invalid call insn1")
    __failure __msg("unknown opcode 8d")
    __failure_unpriv
    __naked void invalid_call_insn1(void)
    {
            asm volatile ("                                 \
            .8byte %[raw_insn];                             \
            exit;                                           \
    "       :
            : __imm_insn(raw_insn, BPF_RAW_INSN(BPF_JMP | BPF_CALL | BPF_X, 0, 0, 0, 0))
            : __clobber_all);
    }
Quoted 4 lines

I'd say that original is better.
Do you want to get rid of ./test_verifier binary?
If so, we can move such tests under ./test_progs w/o converting to inline assembly.

Ideally, both test_verifier as a separate test runner to unify everything in test_progs "framework", which is much better integrated into BPF CI. But it would also be nice to get rid of almost 2k lines of code in test_verifier.c. But it's "ideally", it depends on how much new hacky code would be necessary to achieve this. No strong feelings here.

Quoted 49 lines

[...]

Quoted 39 lines
Quoted 30 lines

# Pseudo-call instructions (9 files)

An object file might contain several BPF programs plus some functions used from different programs. In order to load a program from such file, libbpf creates a buffer and copies the program and all functions called from this program into that buffer. For each visited pseudo-call instruction libbpf requires it to point to a valid function described in ELF header.

However, this is not how verifier/*.c tests are written, for example here is a translated fragment from verifier/loops1.c:

    SEC("tracepoint")
    __description("bounded recursion")
    __failure __msg("back-edge")
    __naked void bounded_recursion(void)
    {
            asm volatile ("                                 \
            r1 = 0;                                         \
            call l0_%=;                                     \
            exit;                                           \
    l0_%=:  r1 += 1;                                        \
            r0 = r1;                                        \
            if r1 < 4 goto l1_%=;                           \
            exit;                                           \
    l1_%=:  call l0_%=;                                     \
            exit;                                           \
    "       ::: __clobber_all);
    }
Quoted 8 lines

There are several possibilities here:
- split such tests into several functions during migration;
- add a special flag for libbpf asking to allow such calls;
- Andrii also suggested to try using .section directives inside inline assembly block.

This requires further investigation, I'll discuss it with Andrii some time later this week or on Monday.

Quoted 7 lines

So I did try this a few weeks ago, and yes, you can make this work with assembly directives. Except that DWARF (and thus .BTF and .BTF.ext) information won't be emitted, as it is emitted very painfully and manually by C compiler as explicit assembly directives. But we might work around that by clearing .BTF and .BTF.ext information for such object files, perhaps. So tentatively this should be doable.

Quoted 1 line

Could you please share an example?

I don't think I saved that. But I just looked at what asm Clang produces from C code with -S argument.

Quoted 20 lines

[...]

Quoted 18 lines
Quoted 17 lines

# .fill_helper (5 files)

Programs for some tests are generated programmatically by specifying .fill_helper function in the test description, e.g. verifier/scale.c:

    {
        "scale: scale test 1",
        .insns = { },
        .data = { },
        .fill_helper = bpf_fill_scale,
        .prog_type = BPF_PROG_TYPE_SCHED_CLS,
        .result = ACCEPT,
        .retval = 1,
    },

Such tests cannot be migrated
(but sometimes these are not the only tests in the file).

Quoted 6 lines
Quoted 3 lines

We can just write these as explicitly programmatically generated programs, probably. There are just a few of these, shouldn't be a big deal.

You mean move the generating function from test_verifier.c to some test under prog_tests/whatever.c, right?

yes, generating function + add bpf_prog_load()-based test around them

Quoted 36 lines
Quoted 13 lines
Quoted 6 lines
# libbpf does not like some junk code (3 files)

libbpf (and bpftool) reject some junk instructions intentionally encoded in the tests, e.g. empty program from verifier/basic.c:

Quoted 6 lines

SEC("socket")
__description("empty prog")
__failure __msg("last insn is not an exit or jmp") __failure_unpriv
__naked void empty_prog(void)
{

Quoted 2 lines

even if you add some random "r0 = 0" instruction? It won't change the meaning of the test, but should work with libbpf.

Random instruction should work.

Quoted 6 lines
Quoted 6 lines
            asm volatile ("" ::: __clobber_all);
    }

# Small log buffer (2 files)

Quoted 8 lines
Quoted 6 lines

Currently test_loader.c uses 1Mb log buffer, while test_verifier.c uses 16Mb log buffer. There are a few tests (like in verifier/bounds.c) that exit with -ESPC for 1Mb buffer.

I can either bump log buffer size for test_loader.c or wait until Andrii's rotating log implementation lands.

Just bump to 16MB, no need to wait on anything.

Will do.

[...]