Commit f3422f4a authored by Roman Gushchin's avatar Roman Gushchin Committed by Cheng Yu
Browse files

libbpf: add support for scheduler bpf programs

maillist inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5F6X6
CVE: NA

Reference: https://lore.kernel.org/all/20210916162451.709260-1-guro@fb.com/



-------------------

This patch adds a support for loading and attaching scheduler bpf
programs.

Fixes: 82c25c3e ("sched: basic infrastructure for scheduler bpf")
Signed-off-by: default avatarRoman Gushchin <guro@fb.com>
Signed-off-by: default avatarChen Hui <judy.chenhui@huawei.com>
Signed-off-by: default avatarGuan Jing <guanjing6@huawei.com>
Signed-off-by: default avatarHui Tang <tanghui20@huawei.com>
parent c9048e25
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -3030,7 +3030,8 @@ static int bpf_object_fixup_btf(struct bpf_object *obj)
static bool prog_needs_vmlinux_btf(struct bpf_program *prog)
{
	if (prog->type == BPF_PROG_TYPE_STRUCT_OPS ||
	    prog->type == BPF_PROG_TYPE_LSM)
	    prog->type == BPF_PROG_TYPE_LSM ||
	    prog->type == BPF_PROG_TYPE_SCHED)
		return true;

	/* BPF_PROG_TYPE_TRACING programs which do not attach to other programs
@@ -8770,6 +8771,7 @@ static int attach_kprobe_multi(const struct bpf_program *prog, long cookie, stru
static int attach_uprobe_multi(const struct bpf_program *prog, long cookie, struct bpf_link **link);
static int attach_lsm(const struct bpf_program *prog, long cookie, struct bpf_link **link);
static int attach_iter(const struct bpf_program *prog, long cookie, struct bpf_link **link);
static int attach_sched(const struct bpf_program *prog, long cookie, struct bpf_link **link);

static const struct bpf_sec_def section_defs[] = {
	SEC_DEF("socket",		SOCKET_FILTER, 0, SEC_NONE),
@@ -8864,6 +8866,7 @@ static const struct bpf_sec_def section_defs[] = {
	SEC_DEF("struct_ops.s+",	STRUCT_OPS, 0, SEC_SLEEPABLE),
	SEC_DEF("sk_lookup",		SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE),
	SEC_DEF("netfilter",		NETFILTER, BPF_NETFILTER, SEC_NONE),
	SEC_DEF("sched/",			SCHED, BPF_SCHED, SEC_ATTACH_BTF, attach_sched),
};

int libbpf_register_prog_handler(const char *sec,
@@ -9243,6 +9246,7 @@ static int bpf_object__collect_st_ops_relos(struct bpf_object *obj,
#define BTF_TRACE_PREFIX "btf_trace_"
#define BTF_LSM_PREFIX "bpf_lsm_"
#define BTF_ITER_PREFIX "bpf_iter_"
#define BTF_SCHED_PREFIX "bpf_sched_"
#define BTF_MAX_NAME_SIZE 128

void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,
@@ -9262,6 +9266,10 @@ void btf_get_kernel_prefix_kind(enum bpf_attach_type attach_type,
		*prefix = BTF_ITER_PREFIX;
		*kind = BTF_KIND_FUNC;
		break;
	case BPF_SCHED:
		*prefix = BTF_SCHED_PREFIX;
		*kind = BTF_KIND_FUNC;
		break;
	default:
		*prefix = "";
		*kind = BTF_KIND_FUNC;
@@ -12119,6 +12127,17 @@ struct bpf_link *bpf_program__attach_netfilter(const struct bpf_program *prog,
	return link;
}

struct bpf_link *bpf_program__attach_sched(const struct bpf_program *prog)
{
	return bpf_program__attach_btf_id(prog, NULL);
}

static int attach_sched(const struct bpf_program *prog, long cookie, struct bpf_link **link)
{
	*link = bpf_program__attach_sched(prog);
	return libbpf_get_error(*link);
}

struct bpf_link *bpf_program__attach(const struct bpf_program *prog)
{
	struct bpf_link *link = NULL;
+2 −0
Original line number Diff line number Diff line
@@ -769,6 +769,8 @@ bpf_program__attach_xdp(const struct bpf_program *prog, int ifindex);
LIBBPF_API struct bpf_link *
bpf_program__attach_freplace(const struct bpf_program *prog,
			     int target_fd, const char *attach_func_name);
LIBBPF_API struct bpf_link *
bpf_program__attach_sched(const struct bpf_program *prog);

struct bpf_netfilter_opts {
	/* size of this struct, for forward/backward compatibility */
+1 −0
Original line number Diff line number Diff line
@@ -236,6 +236,7 @@ LIBBPF_0.2.0 {
		perf_buffer__buffer_fd;
		perf_buffer__epoll_fd;
		perf_buffer__consume_buffer;
		bpf_program__attach_sched;
} LIBBPF_0.1.0;

LIBBPF_0.3.0 {