1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/testing/selftests/bpf/progs/jit_probe_mem.c
Jiri Olsa 8e9af82171 selftests/bpf: Move kfunc exports to bpf_testmod/bpf_testmod_kfunc.h
Move all kfunc exports into separate bpf_testmod_kfunc.h header file
and include it in tests that need it.

We will move all test kfuncs into bpf_testmod in following change,
so it's convenient to have declarations in single place.

The bpf_testmod_kfunc.h is included by both bpf_testmod and bpf
programs that use test kfuncs.

As suggested by David, the bpf_testmod_kfunc.h includes vmlinux.h
and bpf/bpf_helpers.h for bpf programs build, so the declarations
have proper __ksym attribute and we can resolve all the structs.

Note in kfunc_call_test_subprog.c we can no longer use the sk_state
define from bpf_tcp_helpers.h (because it clashed with vmlinux.h)
and we need to address __sk_common.skc_state field directly.

Acked-by: David Vernet <void@manifault.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20230515133756.1658301-3-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-05-16 22:09:23 -07:00

59 lines
1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#include "../bpf_testmod/bpf_testmod_kfunc.h"
static struct prog_test_ref_kfunc __kptr *v;
long total_sum = -1;
SEC("tc")
int test_jit_probe_mem(struct __sk_buff *ctx)
{
struct prog_test_ref_kfunc *p;
unsigned long zero = 0, sum;
p = bpf_kfunc_call_test_acquire(&zero);
if (!p)
return 1;
p = bpf_kptr_xchg(&v, p);
if (p)
goto release_out;
/* Direct map value access of kptr, should be PTR_UNTRUSTED */
p = v;
if (!p)
return 1;
asm volatile (
"r9 = %[p];"
"%[sum] = 0;"
/* r8 = p->a */
"r8 = *(u32 *)(r9 + 0);"
"%[sum] += r8;"
/* r8 = p->b */
"r8 = *(u32 *)(r9 + 4);"
"%[sum] += r8;"
"r9 += 8;"
/* r9 = p->a */
"r9 = *(u32 *)(r9 - 8);"
"%[sum] += r9;"
: [sum] "=r"(sum)
: [p] "r"(p)
: "r8", "r9"
);
total_sum = sum;
return 0;
release_out:
bpf_kfunc_call_test_release(p);
return 1;
}
char _license[] SEC("license") = "GPL";