diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2015-07-20 23:34:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-07-20 23:52:31 -0400 |
commit | 4e10df9a60d96ced321dd2af71da558c6b750078 (patch) | |
tree | 6a913ab31a28d48de3b3510470320220eb75e6eb /include | |
parent | f3120acc7851bffd1cd15acd044b7fa6fa520e75 (diff) |
bpf: introduce bpf_skb_vlan_push/pop() helpers
Allow eBPF programs attached to TC qdiscs call skb_vlan_push/pop via
helper functions. These functions may change skb->data/hlen which are
cached by some JITs to improve performance of ld_abs/ld_ind instructions.
Therefore JITs need to recognize bpf_skb_vlan_push/pop() calls,
re-compute header len and re-cache skb->data/hlen back into cpu registers.
Note, skb->data/hlen are not directly accessible from the programs,
so any changes to skb->data done either by these helpers or by other
TC actions are safe.
eBPF JIT supported by three architectures:
- arm64 JIT is using bpf_load_pointer() without caching, so it's ok as-is.
- x64 JIT re-caches skb->data/hlen unconditionally after vlan_push/pop calls
(experiments showed that conditional re-caching is slower).
- s390 JIT falls back to interpreter for now when bpf_skb_vlan_push() is present
in the program (re-caching is tbd).
These helpers allow more scalable handling of vlan from the programs.
Instead of creating thousands of vlan netdevs on top of eth0 and attaching
TC+ingress+bpf to all of them, the program can be attached to eth0 directly
and manipulate vlans as necessary.
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/bpf.h | 2 | ||||
-rw-r--r-- | include/linux/filter.h | 1 | ||||
-rw-r--r-- | include/uapi/linux/bpf.h | 2 |
3 files changed, 5 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 4383476a0d48..139d6d2e123f 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h | |||
@@ -192,5 +192,7 @@ extern const struct bpf_func_proto bpf_ktime_get_ns_proto; | |||
192 | extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto; | 192 | extern const struct bpf_func_proto bpf_get_current_pid_tgid_proto; |
193 | extern const struct bpf_func_proto bpf_get_current_uid_gid_proto; | 193 | extern const struct bpf_func_proto bpf_get_current_uid_gid_proto; |
194 | extern const struct bpf_func_proto bpf_get_current_comm_proto; | 194 | extern const struct bpf_func_proto bpf_get_current_comm_proto; |
195 | extern const struct bpf_func_proto bpf_skb_vlan_push_proto; | ||
196 | extern const struct bpf_func_proto bpf_skb_vlan_pop_proto; | ||
195 | 197 | ||
196 | #endif /* _LINUX_BPF_H */ | 198 | #endif /* _LINUX_BPF_H */ |
diff --git a/include/linux/filter.h b/include/linux/filter.h index 17724f6ea983..69d00555ce35 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h | |||
@@ -411,6 +411,7 @@ void sk_filter_uncharge(struct sock *sk, struct sk_filter *fp); | |||
411 | 411 | ||
412 | u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); | 412 | u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5); |
413 | void bpf_int_jit_compile(struct bpf_prog *fp); | 413 | void bpf_int_jit_compile(struct bpf_prog *fp); |
414 | bool bpf_helper_changes_skb_data(void *func); | ||
414 | 415 | ||
415 | #ifdef CONFIG_BPF_JIT | 416 | #ifdef CONFIG_BPF_JIT |
416 | typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size); | 417 | typedef void (*bpf_jit_fill_hole_t)(void *area, unsigned int size); |
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 2de87e58b12b..2f6c83d714e9 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h | |||
@@ -256,6 +256,8 @@ enum bpf_func_id { | |||
256 | * Return: classid if != 0 | 256 | * Return: classid if != 0 |
257 | */ | 257 | */ |
258 | BPF_FUNC_get_cgroup_classid, | 258 | BPF_FUNC_get_cgroup_classid, |
259 | BPF_FUNC_skb_vlan_push, /* bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) */ | ||
260 | BPF_FUNC_skb_vlan_pop, /* bpf_skb_vlan_pop(skb) */ | ||
259 | __BPF_FUNC_MAX_ID, | 261 | __BPF_FUNC_MAX_ID, |
260 | }; | 262 | }; |
261 | 263 | ||