brintos

brintos / linux-shallow public Read only

0
0
Text · 2.9 KiB · 4a176e6 Raw
130 lines · c
1// SPDX-License-Identifier: GPL-2.02/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */3 4#include "vmlinux.h"5#include <bpf/bpf_helpers.h>6#include "bpf_misc.h"7 8struct bpf_iter_testmod_seq {9	u64 :64;10	u64 :64;11};12 13extern int bpf_iter_testmod_seq_new(struct bpf_iter_testmod_seq *it, s64 value, int cnt) __ksym;14extern s64 *bpf_iter_testmod_seq_next(struct bpf_iter_testmod_seq *it) __ksym;15extern s64 bpf_iter_testmod_seq_value(int blah, struct bpf_iter_testmod_seq *it) __ksym;16extern void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it) __ksym;17 18const volatile __s64 exp_empty = 0 + 1;19__s64 res_empty;20 21SEC("raw_tp/sys_enter")22__success __log_level(2)23__msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")24__msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")25__msg("call bpf_iter_testmod_seq_destroy")26int testmod_seq_empty(const void *ctx)27{28	__s64 sum = 0, *i;29 30	bpf_for_each(testmod_seq, i, 1000, 0) sum += *i;31	res_empty = 1 + sum;32 33	return 0;34}35 36const volatile __s64 exp_full = 1000000;37__s64 res_full;38 39SEC("raw_tp/sys_enter")40__success __log_level(2)41__msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")42__msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")43__msg("call bpf_iter_testmod_seq_destroy")44int testmod_seq_full(const void *ctx)45{46	__s64 sum = 0, *i;47 48	bpf_for_each(testmod_seq, i, 1000, 1000) sum += *i;49	res_full = sum;50 51	return 0;52}53 54const volatile __s64 exp_truncated = 10 * 1000000;55__s64 res_truncated;56 57static volatile int zero = 0;58 59SEC("raw_tp/sys_enter")60__success __log_level(2)61__msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")62__msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")63__msg("call bpf_iter_testmod_seq_destroy")64int testmod_seq_truncated(const void *ctx)65{66	__s64 sum = 0, *i;67	int cnt = zero;68 69	bpf_for_each(testmod_seq, i, 10, 2000000) {70		sum += *i;71		cnt++;72		if (cnt >= 1000000)73			break;74	}75	res_truncated = sum;76 77	return 0;78}79 80SEC("?raw_tp")81__failure82__msg("expected an initialized iter_testmod_seq as arg #2")83int testmod_seq_getter_before_bad(const void *ctx)84{85	struct bpf_iter_testmod_seq it;86 87	return bpf_iter_testmod_seq_value(0, &it);88}89 90SEC("?raw_tp")91__failure92__msg("expected an initialized iter_testmod_seq as arg #2")93int testmod_seq_getter_after_bad(const void *ctx)94{95	struct bpf_iter_testmod_seq it;96	s64 sum = 0, *v;97 98	bpf_iter_testmod_seq_new(&it, 100, 100);99 100	while ((v = bpf_iter_testmod_seq_next(&it))) {101		sum += *v;102	}103 104	bpf_iter_testmod_seq_destroy(&it);105 106	return sum + bpf_iter_testmod_seq_value(0, &it);107}108 109SEC("?socket")110__success __retval(1000000)111int testmod_seq_getter_good(const void *ctx)112{113	struct bpf_iter_testmod_seq it;114	s64 sum = 0, *v;115 116	bpf_iter_testmod_seq_new(&it, 100, 100);117 118	while ((v = bpf_iter_testmod_seq_next(&it))) {119		sum += *v;120	}121 122	sum *= bpf_iter_testmod_seq_value(0, &it);123 124	bpf_iter_testmod_seq_destroy(&it);125 126	return sum;127}128 129char _license[] SEC("license") = "GPL";130