Skip to content

RFC net_sched: introduce eBPF based Qdisc

Cong Wang bpf netdev 6 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 RFC Latest5 patches 3 repliesIn review
  2. v5 RFC5 patches 4 repliesSuperseded
  3. v4 RFC2 patches 0 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v3 RFC3 patches0 repliesSuperseded
v2 RFC1 patch10 repliesSuperseded
v1 RFC1 patch19 repliesSuperseded

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5bpf: Introduce rbtree mapinclude/linux/bpf_types.h include/uapi/linux/bpf.h kernel/bpf/Makefile +1 more+448 -12 replies
2/5bpf: Add map in map support to rbtreeinclude/linux/bpf.h include/linux/bpf_types.h include/uapi/linux/bpf.h +2 more+171 -00 replies
3/5net_sched: introduce eBPF based Qdiscinclude/linux/bpf_types.h include/uapi/linux/bpf.h include/uapi/linux/pkt_sched.h +4 more+548 -00 replies
4/5net_sched: Add kfuncs for storing skbnet/sched/sch_bpf.c+80 -10 replies
5/5net_sched: Introduce helper bpf_skb_tc_classify()include/uapi/linux/bpf.h net/core/filter.c net/sched/cls_api.c+86 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.

Read the v6 thread

Cover letter [RFC Patch v6 0/5] net_sched: introduce eBPF based Qdisc

From: Cong Wang <[email protected]>

This *incomplete* patchset introduces a programmable Qdisc with eBPF.

There are a few use cases:

1. Allow customizing Qdisc's in an easier way. So that people don't have to write a complete Qdisc kernel module just to experiment some new queuing theory.

2. Solve EDT's problem. EDT calcuates the "tokens" in clsact which is before enqueue, it is impossible to adjust those "tokens" after packets get dropped in enqueue. With eBPF Qdisc, it is easy to be solved with a shared map between clsact and sch_bpf.

3. Replace qevents, as now the user gains much more control over the skb and queues.

4. Provide a new way to reuse TC filters. Currently TC relies on filter chain and block to reuse the TC filters, but they are too complicated to understand. With eBPF helper bpf_skb_tc_classify(), we can invoke TC filters on _any_ Qdisc (even on a different netdev) to do the classification.

5. Potentially pave a way for ingress to queue packets, although current implementation is still only for egress.

6. Possibly pave a way for handling TCP protocol in TC, as rbtree itself is already used by TCP to handle TCP retransmission.

7. Potentially pave a way for implementing eBPF based CPU scheduler, because we already have task kptr and CFS is clearly based on rbtree too.

The goal here is to make this Qdisc as programmable as possible, that is, to replace as many existing Qdisc's as we can, no matter in tree or out of tree. This is why I give up on PIFO which has serious limitations on the programmablity. More importantly, with rbtree, it is easy to implement PIFO logic too.

Here is a summary of design decisions I made:

1. Avoid eBPF struct_ops, as it would be really hard to program a Qdisc with this approach, literally all the struct Qdisc_ops and struct Qdisc_class_ops are needed to implement. This is almost as hard as programming a Qdisc kernel module.

2. Introduce a generic rbtree map, which supports kptr, so that skb's can be stored inside.

a) As eBPF maps are not directly visible to the kernel, we have to dump the stats via eBPF map API's instead of netlink.

b) The user-space is not allowed to read the entire packets, only __sk_buff itself is readable, because we don't have such a use case yet and it would require a different API to read the data, as map values have fixed length.

c) Multi-queue support is implemented via map-in-map, in a similar push/pop fasion based on rbtree too.

d) Use the netdevice notifier to reset the packets inside skb map upon NETDEV_DOWN event. (TODO: need to recognize kptr type)

3. Integrate with existing TC infra. For example, if the user doesn't want to implement her own filters (e.g. a flow dissector), she should be able to re-use the existing TC filters. Another helper bpf_skb_tc_classify() is introduced for this purpose.

Any high-level feedback is welcome. Please kindly ignore any coding details until RFC tag is removed.

TODO:
1. actually test it
2. write a document for this Qdisc
3. add test cases and sample code

Cc Toke Høiland-Jørgensen <[email protected]>
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>

---
v6: switch to kptr based approach

v5: mv kernel/bpf/skb_map.c net/core/skb_map.c
implement flow map as map-in-map
rename bpf_skb_tc_classify() and move it to net/sched/cls_api.c clean up eBPF qdisc program context

v4: get rid of PIFO, use rbtree directly

v3: move priority queue from sch_bpf to skb map
introduce skb map and its helpers
introduce bpf_skb_classify()
use netdevice notifier to reset skb's
Rebase on latest bpf-next

v2: Rebase on latest net-next
Make the code more complete (but still incomplete)

Cong Wang (5):
bpf: Introduce rbtree map
bpf: Add map in map support to rbtree
net_sched: introduce eBPF based Qdisc
net_sched: Add kfuncs for storing skb
net_sched: Introduce helper bpf_skb_tc_classify()

 include/linux/bpf.h            |   4 +
 include/linux/bpf_types.h      |   4 +
 include/uapi/linux/bpf.h       |  19 ++
 include/uapi/linux/pkt_sched.h |  17 +
 kernel/bpf/Makefile            |   2 +-
 kernel/bpf/rbtree.c            | 603 +++++++++++++++++++++++++++++++++
 kernel/bpf/syscall.c           |   7 +
 net/core/filter.c              |  27 ++
 net/sched/Kconfig              |  15 +
 net/sched/Makefile             |   1 +
 net/sched/cls_api.c            |  69 ++++
 net/sched/sch_bpf.c            | 564 ++++++++++++++++++++++++++++++
 12 files changed, 1331 insertions(+), 1 deletion(-)
 create mode 100644 kernel/bpf/rbtree.c
 create mode 100644 net/sched/sch_bpf.c
Signature · 1 line
2.34.1