Skip to content

Commit

Permalink
net_sched: introduce eBPF based Qdisc
Browse files Browse the repository at this point in the history
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
  • Loading branch information
congwang authored and Cong Wang committed May 21, 2022
1 parent ef56eb8 commit 87b07af
Show file tree
Hide file tree
Showing 7 changed files with 546 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/linux/bpf_types.h
Expand Up @@ -8,6 +8,8 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_CLS, tc_cls_act,
struct __sk_buff, struct sk_buff)
BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_ACT, tc_cls_act,
struct __sk_buff, struct sk_buff)
BPF_PROG_TYPE(BPF_PROG_TYPE_SCHED_QDISC, tc_qdisc,
struct __sk_buff, struct sk_buff)
BPF_PROG_TYPE(BPF_PROG_TYPE_XDP, xdp,
struct xdp_md, struct xdp_buff)
#ifdef CONFIG_CGROUP_BPF
Expand Down
15 changes: 15 additions & 0 deletions include/uapi/linux/bpf.h
Expand Up @@ -953,6 +953,7 @@ enum bpf_prog_type {
BPF_PROG_TYPE_LSM,
BPF_PROG_TYPE_SK_LOOKUP,
BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
BPF_PROG_TYPE_SCHED_QDISC,
};

enum bpf_attach_type {
Expand Down Expand Up @@ -6679,4 +6680,18 @@ struct bpf_core_relo {
enum bpf_core_relo_kind kind;
};

struct sch_bpf_ctx {
struct __sk_buff *skb;
__u32 classid;
__u64 delay;
};

enum {
SCH_BPF_OK,
SCH_BPF_QUEUED,
SCH_BPF_DROP,
SCH_BPF_THROTTLE,
SCH_BPF_CONTINUE,
};

#endif /* _UAPI__LINUX_BPF_H__ */
17 changes: 17 additions & 0 deletions include/uapi/linux/pkt_sched.h
Expand Up @@ -1267,4 +1267,21 @@ enum {

#define TCA_ETS_MAX (__TCA_ETS_MAX - 1)

#define TCA_SCH_BPF_FLAG_DIRECT _BITUL(0)
enum {
TCA_SCH_BPF_UNSPEC,
TCA_SCH_BPF_FLAGS, /* u32 */
TCA_SCH_BPF_ENQUEUE_PROG_NAME, /* string */
TCA_SCH_BPF_ENQUEUE_PROG_FD, /* u32 */
TCA_SCH_BPF_ENQUEUE_PROG_ID, /* u32 */
TCA_SCH_BPF_ENQUEUE_PROG_TAG, /* data */
TCA_SCH_BPF_DEQUEUE_PROG_NAME, /* string */
TCA_SCH_BPF_DEQUEUE_PROG_FD, /* u32 */
TCA_SCH_BPF_DEQUEUE_PROG_ID, /* u32 */
TCA_SCH_BPF_DEQUEUE_PROG_TAG, /* data */
__TCA_SCH_BPF_MAX,
};

#define TCA_SCH_BPF_MAX (__TCA_SCH_BPF_MAX - 1)

#endif
25 changes: 25 additions & 0 deletions net/core/filter.c
Expand Up @@ -7813,6 +7813,19 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
}
}

static const struct bpf_func_proto *
tc_qdisc_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
switch (func_id) {
case BPF_FUNC_skb_map_push:
return &bpf_skb_map_push_proto;
case BPF_FUNC_skb_map_pop:
return &bpf_skb_map_pop_proto;
default:
return tc_cls_act_func_proto(func_id, prog);
}
}

static const struct bpf_func_proto *
xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
Expand Down Expand Up @@ -10476,6 +10489,18 @@ const struct bpf_prog_ops tc_cls_act_prog_ops = {
.test_run = bpf_prog_test_run_skb,
};

const struct bpf_verifier_ops tc_qdisc_verifier_ops = {
.get_func_proto = tc_qdisc_func_proto,
.is_valid_access = tc_cls_act_is_valid_access,
.convert_ctx_access = tc_cls_act_convert_ctx_access,
.gen_prologue = tc_cls_act_prologue,
.gen_ld_abs = bpf_gen_ld_abs,
};

const struct bpf_prog_ops tc_qdisc_prog_ops = {
.test_run = bpf_prog_test_run_skb,
};

const struct bpf_verifier_ops xdp_verifier_ops = {
.get_func_proto = xdp_func_proto,
.is_valid_access = xdp_is_valid_access,
Expand Down
15 changes: 15 additions & 0 deletions net/sched/Kconfig
Expand Up @@ -439,6 +439,21 @@ config NET_SCH_ETS

If unsure, say N.

config NET_SCH_BPF
tristate "eBPF based programmable queue discipline"
help
This eBPF based queue discipline offers a way to program your
own packet scheduling algorithm. This is a classful qdisc which
also allows you to decide the hierarchy.

Say Y here if you want to use the eBPF based programmable queue
discipline.

To compile this driver as a module, choose M here: the module
will be called sch_bpf.

If unsure, say N.

menuconfig NET_SCH_DEFAULT
bool "Allow override default queue discipline"
help
Expand Down
1 change: 1 addition & 0 deletions net/sched/Makefile
Expand Up @@ -65,6 +65,7 @@ obj-$(CONFIG_NET_SCH_FQ_PIE) += sch_fq_pie.o
obj-$(CONFIG_NET_SCH_CBS) += sch_cbs.o
obj-$(CONFIG_NET_SCH_ETF) += sch_etf.o
obj-$(CONFIG_NET_SCH_TAPRIO) += sch_taprio.o
obj-$(CONFIG_NET_SCH_BPF) += sch_bpf.o

obj-$(CONFIG_NET_CLS_U32) += cls_u32.o
obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
Expand Down

0 comments on commit 87b07af

Please sign in to comment.