Check that autocreate flags of struct_ops map cause autoload of struct_ops corresponding programs: - when struct_ops program is referenced only from a map for which autocreate is set to false, that program should not be loaded; - when struct_ops program with autoload == false is set to be used from a map with autocreate == true using shadow var, that program should be loaded; - when struct_ops program is not referenced from any map object load should fail. Signed-off-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20240306104529.6453-10-eddyz87@gmail.com
32 lines
484 B
C
32 lines
484 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/bpf.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_tracing.h>
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
int test_1_result = 0;
|
|
|
|
SEC("?struct_ops/test_1")
|
|
int BPF_PROG(foo)
|
|
{
|
|
test_1_result = 42;
|
|
return 0;
|
|
}
|
|
|
|
SEC("?struct_ops/test_1")
|
|
int BPF_PROG(bar)
|
|
{
|
|
test_1_result = 24;
|
|
return 0;
|
|
}
|
|
|
|
struct bpf_testmod_ops {
|
|
int (*test_1)(void);
|
|
};
|
|
|
|
SEC(".struct_ops.link")
|
|
struct bpf_testmod_ops testmod_1 = {
|
|
.test_1 = (void *)bar
|
|
};
|