Commit 82887c25 authored by Eduard Zingerman's avatar Eduard Zingerman Committed by Alexei Starovoitov

selftests/bpf: verifier/unpriv converted to inline assembly

Test verifier/unpriv semi-automatically converted to use inline assembly.

The verifier/unpriv.c had to be split in two parts:
- the bulk of the tests is in the progs/verifier_unpriv.c;
- the single test that needs `struct bpf_perf_event_data`
  definition is in the progs/verifier_unpriv_perf.c.

The tests above can't be in a single file because:
- first requires inclusion of the filter.h header
  (to get access to BPF_ST_MEM macro, inline assembler does
   not support this isntruction);
- the second requires vmlinux.h, which contains definitions
  conflicting with filter.h.
Signed-off-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20230421174234.2391278-23-eddyz87@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 81d1d6dd
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
#include "verifier_stack_ptr.skel.h" #include "verifier_stack_ptr.skel.h"
#include "verifier_subreg.skel.h" #include "verifier_subreg.skel.h"
#include "verifier_uninit.skel.h" #include "verifier_uninit.skel.h"
#include "verifier_unpriv.skel.h"
#include "verifier_unpriv_perf.skel.h"
#include "verifier_value_adj_spill.skel.h" #include "verifier_value_adj_spill.skel.h"
#include "verifier_value.skel.h" #include "verifier_value.skel.h"
#include "verifier_value_or_null.skel.h" #include "verifier_value_or_null.skel.h"
...@@ -150,6 +152,8 @@ void test_verifier_spin_lock(void) { RUN(verifier_spin_lock); } ...@@ -150,6 +152,8 @@ void test_verifier_spin_lock(void) { RUN(verifier_spin_lock); }
void test_verifier_stack_ptr(void) { RUN(verifier_stack_ptr); } void test_verifier_stack_ptr(void) { RUN(verifier_stack_ptr); }
void test_verifier_subreg(void) { RUN(verifier_subreg); } void test_verifier_subreg(void) { RUN(verifier_subreg); }
void test_verifier_uninit(void) { RUN(verifier_uninit); } void test_verifier_uninit(void) { RUN(verifier_uninit); }
void test_verifier_unpriv(void) { RUN(verifier_unpriv); }
void test_verifier_unpriv_perf(void) { RUN(verifier_unpriv_perf); }
void test_verifier_value_adj_spill(void) { RUN(verifier_value_adj_spill); } void test_verifier_value_adj_spill(void) { RUN(verifier_value_adj_spill); }
void test_verifier_value(void) { RUN(verifier_value); } void test_verifier_value(void) { RUN(verifier_value); }
void test_verifier_value_or_null(void) { RUN(verifier_value_or_null); } void test_verifier_value_or_null(void) { RUN(verifier_value_or_null); }
......
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/unpriv.c */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
SEC("perf_event")
__description("unpriv: spill/fill of different pointers ldx")
__failure __msg("same insn cannot be used with different pointers")
__naked void fill_of_different_pointers_ldx(void)
{
asm volatile (" \
r6 = r10; \
r6 += -8; \
if r1 == 0 goto l0_%=; \
r2 = r10; \
r2 += %[__imm_0]; \
*(u64*)(r6 + 0) = r2; \
l0_%=: if r1 != 0 goto l1_%=; \
*(u64*)(r6 + 0) = r1; \
l1_%=: r1 = *(u64*)(r6 + 0); \
r1 = *(u64*)(r1 + %[sample_period]); \
r0 = 0; \
exit; \
" :
: __imm_const(__imm_0,
-(__s32) offsetof(struct bpf_perf_event_data, sample_period) - 8),
__imm_const(sample_period,
offsetof(struct bpf_perf_event_data, sample_period))
: __clobber_all);
}
char _license[] SEC("license") = "GPL";
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment