summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/struct_ops_private_stack_large.c
blob: 94a25a2cff6ec6c55b94eecdf7d460004c807688 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: GPL-2.0

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "../test_kmods/bpf_testmod.h"
#include "bpf_misc.h"

char _license[] SEC("license") = "GPL";

long val;

/* On a private stack every frame gets the whole 2 KiB budget. */
__used __naked
static long frame_2048_leaf(void)
{
	asm volatile ("					\
	r1 = 30;					\
	*(u64 *)(r10 - 2048) = r1;			\
	r1 = 12;					\
	*(u64 *)(r10 - 8) = r1;				\
	r0 = *(u64 *)(r10 - 2048);			\
	r1 = *(u64 *)(r10 - 8);				\
	r0 += r1;					\
	exit;						\
"	::: __clobber_all);
}

/* test_1 is the member bpf_testmod requests a private stack for */
SEC("struct_ops")
__naked int test_1(void)
{
	asm volatile ("					\
	r1 = 100;					\
	*(u64 *)(r10 - 2048) = r1;			\
	call frame_2048_leaf;				\
	r1 = *(u64 *)(r10 - 2048);			\
	r0 += r1;					\
	r1 = %[val] ll;					\
	*(u64 *)(r1 + 0) = r0;				\
	r0 = 0;						\
	exit;						\
"	:
	: __imm_addr(val)
	: __clobber_all);
}

SEC(".struct_ops")
struct bpf_testmod_ops3 testmod_1 = {
	.test_1 = (void *)test_1,
};