Commit 256eab48 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

selftests/bpf: Stop using static variables for passing data to/from user-space



In preparation of skipping emitting static variables in BPF skeletons, switch
all current selftests uses of static variables to pass data between BPF and
user-space to use global variables.

All non-read-only `static volatile` variables become just plain global
variables by dropping `static volatile` part.

Read-only `static volatile const` variables, though, still require `volatile`
modifier, otherwise compiler will ignore whatever values are set from
user-space.

Few static linker tests are using name-conflicting static variables to
validate that static linker still properly handles static variables and
doesn't trip up on name conflicts.

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210507054119.270888-4-andrii@kernel.org
parent fdbf5dde
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#include <test_progs.h>
#include "test_send_signal_kern.skel.h"

static volatile int sigusr1_received = 0;
int sigusr1_received = 0;

static void sigusr1_handler(int signum)
{
+2 −4
Original line number Diff line number Diff line
@@ -82,10 +82,8 @@ void test_skeleton(void)
	CHECK(data->out2 != 2, "res2", "got %lld != exp %d\n", data->out2, 2);
	CHECK(bss->out3 != 3, "res3", "got %d != exp %d\n", (int)bss->out3, 3);
	CHECK(bss->out4 != 4, "res4", "got %lld != exp %d\n", bss->out4, 4);
	CHECK(bss->handler_out5.a != 5, "res5", "got %d != exp %d\n",
	      bss->handler_out5.a, 5);
	CHECK(bss->handler_out5.b != 6, "res6", "got %lld != exp %d\n",
	      bss->handler_out5.b, 6);
	CHECK(bss->out5.a != 5, "res5", "got %d != exp %d\n", bss->out5.a, 5);
	CHECK(bss->out5.b != 6, "res6", "got %lld != exp %d\n", bss->out5.b, 6);
	CHECK(bss->out6 != 14, "res7", "got %d != exp %d\n", bss->out6, 14);

	CHECK(bss->bpf_syscall != kcfg->CONFIG_BPF_SYSCALL, "ext1",
+0 −5
Original line number Diff line number Diff line
@@ -14,12 +14,7 @@ void test_static_linked(void)
		return;

	skel->rodata->rovar1 = 1;
	skel->bss->static_var1 = 2;
	skel->bss->static_var11 = 3;

	skel->rodata->rovar2 = 4;
	skel->bss->static_var2 = 5;
	skel->bss->static_var22 = 6;

	err = test_static_linked__load(skel);
	if (!ASSERT_OK(err, "skel_load"))
+2 −2
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@ __u32 map1_id = 0, map2_id = 0;
__u32 map1_accessed = 0, map2_accessed = 0;
__u64 map1_seqnum = 0, map2_seqnum1 = 0, map2_seqnum2 = 0;

static volatile const __u32 print_len;
static volatile const __u32 ret1;
volatile const __u32 print_len;
volatile const __u32 ret1;

SEC("iter/bpf_map")
int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
+2 −2
Original line number Diff line number Diff line
@@ -109,10 +109,10 @@ int BPF_PROG(trace_kfree_skb, struct sk_buff *skb, void *location)
	return 0;
}

static volatile struct {
struct {
	bool fentry_test_ok;
	bool fexit_test_ok;
} result;
} result = {};

SEC("fentry/eth_type_trans")
int BPF_PROG(fentry_eth_type_trans, struct sk_buff *skb, struct net_device *dev,
Loading