Commit 15669e1d authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

selftests/bpf: Normalize all the rest SEC() uses



Normalize all the other non-conforming SEC() usages across all
selftests. This is in preparation for libbpf to start to enforce
stricter SEC() rules in libbpf 1.0 mode.

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarDave Marchevsky <davemarchevsky@fb.com>
Link: https://lore.kernel.org/bpf/20210928161946.2512801-5-andrii@kernel.org
parent c22bdd28
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -458,9 +458,9 @@ static int init_prog_array(struct bpf_object *obj, struct bpf_map *prog_array)
		return -1;

	for (i = 0; i < bpf_map__def(prog_array)->max_entries; i++) {
		snprintf(prog_name, sizeof(prog_name), "flow_dissector/%i", i);
		snprintf(prog_name, sizeof(prog_name), "flow_dissector_%d", i);

		prog = bpf_object__find_program_by_title(obj, prog_name);
		prog = bpf_object__find_program_by_name(obj, prog_name);
		if (!prog)
			return -1;

+15 −15
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
#include <test_progs.h>
#include "cgroup_helpers.h"

static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title)
static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title, const char *name)
{
	enum bpf_attach_type attach_type;
	enum bpf_prog_type prog_type;
@@ -15,23 +15,23 @@ static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title)
		return -1;
	}

	prog = bpf_object__find_program_by_title(obj, title);
	prog = bpf_object__find_program_by_name(obj, name);
	if (!prog) {
		log_err("Failed to find %s BPF program", title);
		log_err("Failed to find %s BPF program", name);
		return -1;
	}

	err = bpf_prog_attach(bpf_program__fd(prog), cgroup_fd,
			      attach_type, BPF_F_ALLOW_MULTI);
	if (err) {
		log_err("Failed to attach %s BPF program", title);
		log_err("Failed to attach %s BPF program", name);
		return -1;
	}

	return 0;
}

static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title)
static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title, const char *name)
{
	enum bpf_attach_type attach_type;
	enum bpf_prog_type prog_type;
@@ -42,7 +42,7 @@ static int prog_detach(struct bpf_object *obj, int cgroup_fd, const char *title)
	if (err)
		return -1;

	prog = bpf_object__find_program_by_title(obj, title);
	prog = bpf_object__find_program_by_name(obj, name);
	if (!prog)
		return -1;

@@ -89,7 +89,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
	 * - child:  0x80 -> 0x90
	 */

	err = prog_attach(obj, cg_child, "cgroup/getsockopt/child");
	err = prog_attach(obj, cg_child, "cgroup/getsockopt", "_getsockopt_child");
	if (err)
		goto detach;

@@ -113,7 +113,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
	 * - parent: 0x90 -> 0xA0
	 */

	err = prog_attach(obj, cg_parent, "cgroup/getsockopt/parent");
	err = prog_attach(obj, cg_parent, "cgroup/getsockopt", "_getsockopt_parent");
	if (err)
		goto detach;

@@ -157,7 +157,7 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
	 * - parent: unexpected 0x40, EPERM
	 */

	err = prog_detach(obj, cg_child, "cgroup/getsockopt/child");
	err = prog_detach(obj, cg_child, "cgroup/getsockopt", "_getsockopt_child");
	if (err) {
		log_err("Failed to detach child program");
		goto detach;
@@ -198,8 +198,8 @@ static int run_getsockopt_test(struct bpf_object *obj, int cg_parent,
	}

detach:
	prog_detach(obj, cg_child, "cgroup/getsockopt/child");
	prog_detach(obj, cg_parent, "cgroup/getsockopt/parent");
	prog_detach(obj, cg_child, "cgroup/getsockopt", "_getsockopt_child");
	prog_detach(obj, cg_parent, "cgroup/getsockopt", "_getsockopt_parent");

	return err;
}
@@ -236,7 +236,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,

	/* Attach child program and make sure it adds 0x10. */

	err = prog_attach(obj, cg_child, "cgroup/setsockopt");
	err = prog_attach(obj, cg_child, "cgroup/setsockopt", "_setsockopt");
	if (err)
		goto detach;

@@ -263,7 +263,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,

	/* Attach parent program and make sure it adds another 0x10. */

	err = prog_attach(obj, cg_parent, "cgroup/setsockopt");
	err = prog_attach(obj, cg_parent, "cgroup/setsockopt", "_setsockopt");
	if (err)
		goto detach;

@@ -289,8 +289,8 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,
	}

detach:
	prog_detach(obj, cg_child, "cgroup/setsockopt");
	prog_detach(obj, cg_parent, "cgroup/setsockopt");
	prog_detach(obj, cg_child, "cgroup/setsockopt", "_setsockopt");
	prog_detach(obj, cg_parent, "cgroup/setsockopt", "_setsockopt");

	return err;
}
+1 −2
Original line number Diff line number Diff line
@@ -19,9 +19,8 @@
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

int _version SEC("version") = 1;
#define PROG(F) PROG_(F, _##F)
#define PROG_(NUM, NAME) SEC("flow_dissector/"#NUM) int bpf_func##NAME
#define PROG_(NUM, NAME) SEC("flow_dissector") int flow_dissector_##NUM

/* These are the identifiers of the BPF programs that will be used in tail
 * calls. Name is limited to 16 characters, with the terminating character and
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ struct {

__u32 invocations = 0;

SEC("cgroup_skb/egress/1")
SEC("cgroup_skb/egress")
int egress1(struct __sk_buff *skb)
{
	struct cgroup_value *ptr_cg_storage =
@@ -32,7 +32,7 @@ int egress1(struct __sk_buff *skb)
	return 1;
}

SEC("cgroup_skb/egress/2")
SEC("cgroup_skb/egress")
int egress2(struct __sk_buff *skb)
{
	struct cgroup_value *ptr_cg_storage =
+2 −2
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ struct {

__u32 invocations = 0;

SEC("cgroup_skb/egress/1")
SEC("cgroup_skb/egress")
int egress1(struct __sk_buff *skb)
{
	struct cgroup_value *ptr_cg_storage =
@@ -32,7 +32,7 @@ int egress1(struct __sk_buff *skb)
	return 1;
}

SEC("cgroup_skb/egress/2")
SEC("cgroup_skb/egress")
int egress2(struct __sk_buff *skb)
{
	struct cgroup_value *ptr_cg_storage =
Loading