bpf: more flexible support for kernel helpers
authorJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 6 Aug 2020 12:13:59 +0000 (14:13 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 6 Aug 2020 12:13:59 +0000 (14:13 +0200)
commitaf30b83b50953fbbe671d93d44ea6ac2f7a50ce9
tree49c8cc99ceff9546981f0e421b32d7461255edec
parent89b84cd794f984038984c10b03c3b0ab582f49cc
bpf: more flexible support for kernel helpers

This patch changes the existing support for BPF kernel helpers to be
more flexible, in two main ways.

First, there is no longer a hardcoded list of kernel helpers defined
in the compiler internals.  This is replaced by a new target-specific
attribute `kernel_helper' that the user can use to define her own
helpers, annotating function prototypes.

Second, following feedback from the kernel hackers, the pre-defined
helpers in the distributed bpf-helpers.h are no longer available
conditionally depending on the kernel version used in -mkernel.  The
command-line option stays for now, as it may be useful for other
things.

Target tests and documentation updated.

2020-08-06  Jose E. Marchesi  <jose.marchesi@oracle.com>

gcc/
* config/bpf/bpf-helpers.h (KERNEL_HELPER): Define.
(KERNEL_VERSION): Remove.
* config/bpf/bpf-helpers.def: Delete.
* config/bpf/bpf.c (bpf_handle_fndecl_attribute): New function.
(bpf_attribute_table): Define.
(bpf_helper_names): Delete.
(bpf_helper_code): Likewise.
(enum bpf_builtins): Adjust to new helpers mechanism.
(bpf_output_call): Likewise.
(bpf_init_builtins): Likewise.
(bpf_init_builtins): Likewise.
* doc/extend.texi (BPF Function Attributes): New section.
(BPF Kernel Helpers): Delete section.

gcc/testsuite/
* gcc.target/bpf/helper-bind.c: Adjust to new kernel helpers
mechanism.
* gcc.target/bpf/helper-bpf-redirect.c: Likewise.
* gcc.target/bpf/helper-clone-redirect.c: Likewise.
* gcc.target/bpf/helper-csum-diff.c: Likewise.
* gcc.target/bpf/helper-csum-update.c: Likewise.
* gcc.target/bpf/helper-current-task-under-cgroup.c: Likewise.
* gcc.target/bpf/helper-fib-lookup.c: Likewise.
* gcc.target/bpf/helper-get-cgroup-classid.c: Likewise.
* gcc.target/bpf/helper-get-current-cgroup-id.c: Likewise.
* gcc.target/bpf/helper-get-current-comm.c: Likewise.
* gcc.target/bpf/helper-get-current-pid-tgid.c: Likewise.
* gcc.target/bpf/helper-get-current-task.c: Likewise.
* gcc.target/bpf/helper-get-current-uid-gid.c: Likewise.
* gcc.target/bpf/helper-get-hash-recalc.c: Likewise.
* gcc.target/bpf/helper-get-listener-sock.c: Likewise.
* gcc.target/bpf/helper-get-local-storage.c: Likewise.
* gcc.target/bpf/helper-get-numa-node-id.c: Likewise.
* gcc.target/bpf/helper-get-prandom-u32.c: Likewise.
* gcc.target/bpf/helper-get-route-realm.c: Likewise.
* gcc.target/bpf/helper-get-smp-processor-id.c: Likewise.
* gcc.target/bpf/helper-get-socket-cookie.c: Likewise.
* gcc.target/bpf/helper-get-socket-uid.c: Likewise.
* gcc.target/bpf/helper-get-stack.c: Likewise.
* gcc.target/bpf/helper-get-stackid.c: Likewise.
* gcc.target/bpf/helper-getsockopt.c: Likewise.
* gcc.target/bpf/helper-ktime-get-ns.c: Likewise.
* gcc.target/bpf/helper-l3-csum-replace.c: Likewise.
* gcc.target/bpf/helper-l4-csum-replace.c: Likewise.
* gcc.target/bpf/helper-lwt-push-encap.c: Likewise.
* gcc.target/bpf/helper-lwt-seg6-action.c: Likewise.
* gcc.target/bpf/helper-lwt-seg6-adjust-srh.c: Likewise.
* gcc.target/bpf/helper-lwt-seg6-store-bytes.c: Likewise.
* gcc.target/bpf/helper-map-delete-elem.c: Likewise.
* gcc.target/bpf/helper-map-lookup-elem.c: Likewise.
* gcc.target/bpf/helper-map-peek-elem.c: Likewise.
* gcc.target/bpf/helper-map-pop-elem.c: Likewise.
* gcc.target/bpf/helper-map-push-elem.c: Likewise.
* gcc.target/bpf/helper-map-update-elem.c: Likewise.
* gcc.target/bpf/helper-msg-apply-bytes.c: Likewise.
* gcc.target/bpf/helper-msg-cork-bytes.c: Likewise.
* gcc.target/bpf/helper-msg-pop-data.c: Likewise.
* gcc.target/bpf/helper-msg-pull-data.c: Likewise.
* gcc.target/bpf/helper-msg-push-data.c: Likewise.
* gcc.target/bpf/helper-msg-redirect-hash.c: Likewise.
* gcc.target/bpf/helper-msg-redirect-map.c: Likewise.
* gcc.target/bpf/helper-override-return.c: Likewise.
* gcc.target/bpf/helper-perf-event-output.c: Likewise.
* gcc.target/bpf/helper-perf-event-read-value.c: Likewise.
* gcc.target/bpf/helper-perf-event-read.c: Likewise.
* gcc.target/bpf/helper-perf-prog-read-value.c: Likewise.
* gcc.target/bpf/helper-probe-read-str.c: Likewise.
* gcc.target/bpf/helper-probe-read.c: Likewise.
* gcc.target/bpf/helper-probe-write-user.c: Likewise.
* gcc.target/bpf/helper-rc-keydown.c: Likewise.
* gcc.target/bpf/helper-rc-pointer-rel.c: Likewise.
* gcc.target/bpf/helper-rc-repeat.c: Likewise.
* gcc.target/bpf/helper-redirect-map.c: Likewise.
* gcc.target/bpf/helper-set-hash-invalid.c: Likewise.
* gcc.target/bpf/helper-set-hash.c: Likewise.
* gcc.target/bpf/helper-setsockopt.c: Likewise.
* gcc.target/bpf/helper-sk-fullsock.c: Likewise.
* gcc.target/bpf/helper-sk-lookup-tcp.c: Likewise.
* gcc.target/bpf/helper-sk-lookup-upd.c: Likewise.
* gcc.target/bpf/helper-sk-redirect-hash.c: Likewise.
* gcc.target/bpf/helper-sk-redirect-map.c: Likewise.
* gcc.target/bpf/helper-sk-release.c: Likewise.
* gcc.target/bpf/helper-sk-select-reuseport.c: Likewise.
* gcc.target/bpf/helper-sk-storage-delete.c: Likewise.
* gcc.target/bpf/helper-sk-storage-get.c: Likewise.
* gcc.target/bpf/helper-skb-adjust-room.c: Likewise.
* gcc.target/bpf/helper-skb-cgroup-id.c: Likewise.
* gcc.target/bpf/helper-skb-change-head.c: Likewise.
* gcc.target/bpf/helper-skb-change-proto.c: Likewise.
* gcc.target/bpf/helper-skb-change-tail.c: Likewise.
* gcc.target/bpf/helper-skb-change-type.c: Likewise.
* gcc.target/bpf/helper-skb-ecn-set-ce.c: Likewise.
* gcc.target/bpf/helper-skb-get-tunnel-key.c: Likewise.
* gcc.target/bpf/helper-skb-get-tunnel-opt.c: Likewise.
* gcc.target/bpf/helper-skb-get-xfrm-state.c: Likewise.
* gcc.target/bpf/helper-skb-load-bytes-relative.c: Likewise.
* gcc.target/bpf/helper-skb-load-bytes.c: Likewise.
* gcc.target/bpf/helper-skb-pull-data.c: Likewise.
* gcc.target/bpf/helper-skb-set-tunnel-key.c: Likewise.
* gcc.target/bpf/helper-skb-set-tunnel-opt.c: Likewise.
* gcc.target/bpf/helper-skb-store-bytes.c: Likewise.
* gcc.target/bpf/helper-skb-under-cgroup.c: Likewise.
* gcc.target/bpf/helper-skb-vlan-pop.c: Likewise.
* gcc.target/bpf/helper-skb-vlan-push.c: Likewise.
* gcc.target/bpf/helper-skc-lookup-tcp.c: Likewise.
* gcc.target/bpf/helper-sock-hash-update.c: Likewise.
* gcc.target/bpf/helper-sock-map-update.c: Likewise.
* gcc.target/bpf/helper-sock-ops-cb-flags-set.c: Likewise.
* gcc.target/bpf/helper-spin-lock.c: Likewise.
* gcc.target/bpf/helper-spin-unlock.c: Likewise.
* gcc.target/bpf/helper-strtol.c: Likewise.
* gcc.target/bpf/helper-strtoul.c: Likewise.
* gcc.target/bpf/helper-sysctl-get-current-value.c: Likewise.
* gcc.target/bpf/helper-sysctl-get-name.c: Likewise.
* gcc.target/bpf/helper-sysctl-get-new-value.c: Likewise.
* gcc.target/bpf/helper-sysctl-set-new-value.c: Likewise.
* gcc.target/bpf/helper-tail-call.c: Likewise.
* gcc.target/bpf/helper-tcp-check-syncookie.c: Likewise.
* gcc.target/bpf/helper-tcp-sock.c: Likewise.
* gcc.target/bpf/helper-trace-printk.c: Likewise.
* gcc.target/bpf/helper-xdp-adjust-head.c: Likewise.
* gcc.target/bpf/helper-xdp-adjust-meta.c: Likewise.
* gcc.target/bpf/helper-xdp-adjust-tail.c: Likewise.
* gcc.target/bpf/skb-ancestor-cgroup-id.c: Likewise.
112 files changed:
gcc/config/bpf/bpf-helpers.def [deleted file]
gcc/config/bpf/bpf-helpers.h
gcc/config/bpf/bpf.c
gcc/doc/extend.texi
gcc/testsuite/gcc.target/bpf/helper-bind.c
gcc/testsuite/gcc.target/bpf/helper-bpf-redirect.c
gcc/testsuite/gcc.target/bpf/helper-clone-redirect.c
gcc/testsuite/gcc.target/bpf/helper-csum-diff.c
gcc/testsuite/gcc.target/bpf/helper-csum-update.c
gcc/testsuite/gcc.target/bpf/helper-current-task-under-cgroup.c
gcc/testsuite/gcc.target/bpf/helper-fib-lookup.c
gcc/testsuite/gcc.target/bpf/helper-get-cgroup-classid.c
gcc/testsuite/gcc.target/bpf/helper-get-current-cgroup-id.c
gcc/testsuite/gcc.target/bpf/helper-get-current-comm.c
gcc/testsuite/gcc.target/bpf/helper-get-current-pid-tgid.c
gcc/testsuite/gcc.target/bpf/helper-get-current-task.c
gcc/testsuite/gcc.target/bpf/helper-get-current-uid-gid.c
gcc/testsuite/gcc.target/bpf/helper-get-hash-recalc.c
gcc/testsuite/gcc.target/bpf/helper-get-listener-sock.c
gcc/testsuite/gcc.target/bpf/helper-get-local-storage.c
gcc/testsuite/gcc.target/bpf/helper-get-numa-node-id.c
gcc/testsuite/gcc.target/bpf/helper-get-prandom-u32.c
gcc/testsuite/gcc.target/bpf/helper-get-route-realm.c
gcc/testsuite/gcc.target/bpf/helper-get-smp-processor-id.c
gcc/testsuite/gcc.target/bpf/helper-get-socket-cookie.c
gcc/testsuite/gcc.target/bpf/helper-get-socket-uid.c
gcc/testsuite/gcc.target/bpf/helper-get-stack.c
gcc/testsuite/gcc.target/bpf/helper-get-stackid.c
gcc/testsuite/gcc.target/bpf/helper-getsockopt.c
gcc/testsuite/gcc.target/bpf/helper-ktime-get-ns.c
gcc/testsuite/gcc.target/bpf/helper-l3-csum-replace.c
gcc/testsuite/gcc.target/bpf/helper-l4-csum-replace.c
gcc/testsuite/gcc.target/bpf/helper-lwt-push-encap.c
gcc/testsuite/gcc.target/bpf/helper-lwt-seg6-action.c
gcc/testsuite/gcc.target/bpf/helper-lwt-seg6-adjust-srh.c
gcc/testsuite/gcc.target/bpf/helper-lwt-seg6-store-bytes.c
gcc/testsuite/gcc.target/bpf/helper-map-delete-elem.c
gcc/testsuite/gcc.target/bpf/helper-map-lookup-elem.c
gcc/testsuite/gcc.target/bpf/helper-map-peek-elem.c
gcc/testsuite/gcc.target/bpf/helper-map-pop-elem.c
gcc/testsuite/gcc.target/bpf/helper-map-push-elem.c
gcc/testsuite/gcc.target/bpf/helper-map-update-elem.c
gcc/testsuite/gcc.target/bpf/helper-msg-apply-bytes.c
gcc/testsuite/gcc.target/bpf/helper-msg-cork-bytes.c
gcc/testsuite/gcc.target/bpf/helper-msg-pop-data.c
gcc/testsuite/gcc.target/bpf/helper-msg-pull-data.c
gcc/testsuite/gcc.target/bpf/helper-msg-push-data.c
gcc/testsuite/gcc.target/bpf/helper-msg-redirect-hash.c
gcc/testsuite/gcc.target/bpf/helper-msg-redirect-map.c
gcc/testsuite/gcc.target/bpf/helper-override-return.c
gcc/testsuite/gcc.target/bpf/helper-perf-event-output.c
gcc/testsuite/gcc.target/bpf/helper-perf-event-read-value.c
gcc/testsuite/gcc.target/bpf/helper-perf-event-read.c
gcc/testsuite/gcc.target/bpf/helper-perf-prog-read-value.c
gcc/testsuite/gcc.target/bpf/helper-probe-read-str.c
gcc/testsuite/gcc.target/bpf/helper-probe-read.c
gcc/testsuite/gcc.target/bpf/helper-probe-write-user.c
gcc/testsuite/gcc.target/bpf/helper-rc-keydown.c
gcc/testsuite/gcc.target/bpf/helper-rc-pointer-rel.c
gcc/testsuite/gcc.target/bpf/helper-rc-repeat.c
gcc/testsuite/gcc.target/bpf/helper-redirect-map.c
gcc/testsuite/gcc.target/bpf/helper-set-hash-invalid.c
gcc/testsuite/gcc.target/bpf/helper-set-hash.c
gcc/testsuite/gcc.target/bpf/helper-setsockopt.c
gcc/testsuite/gcc.target/bpf/helper-sk-fullsock.c
gcc/testsuite/gcc.target/bpf/helper-sk-lookup-tcp.c
gcc/testsuite/gcc.target/bpf/helper-sk-lookup-upd.c
gcc/testsuite/gcc.target/bpf/helper-sk-redirect-hash.c
gcc/testsuite/gcc.target/bpf/helper-sk-redirect-map.c
gcc/testsuite/gcc.target/bpf/helper-sk-release.c
gcc/testsuite/gcc.target/bpf/helper-sk-select-reuseport.c
gcc/testsuite/gcc.target/bpf/helper-sk-storage-delete.c
gcc/testsuite/gcc.target/bpf/helper-sk-storage-get.c
gcc/testsuite/gcc.target/bpf/helper-skb-adjust-room.c
gcc/testsuite/gcc.target/bpf/helper-skb-cgroup-id.c
gcc/testsuite/gcc.target/bpf/helper-skb-change-head.c
gcc/testsuite/gcc.target/bpf/helper-skb-change-proto.c
gcc/testsuite/gcc.target/bpf/helper-skb-change-tail.c
gcc/testsuite/gcc.target/bpf/helper-skb-change-type.c
gcc/testsuite/gcc.target/bpf/helper-skb-ecn-set-ce.c
gcc/testsuite/gcc.target/bpf/helper-skb-get-tunnel-key.c
gcc/testsuite/gcc.target/bpf/helper-skb-get-tunnel-opt.c
gcc/testsuite/gcc.target/bpf/helper-skb-get-xfrm-state.c
gcc/testsuite/gcc.target/bpf/helper-skb-load-bytes-relative.c
gcc/testsuite/gcc.target/bpf/helper-skb-load-bytes.c
gcc/testsuite/gcc.target/bpf/helper-skb-pull-data.c
gcc/testsuite/gcc.target/bpf/helper-skb-set-tunnel-key.c
gcc/testsuite/gcc.target/bpf/helper-skb-set-tunnel-opt.c
gcc/testsuite/gcc.target/bpf/helper-skb-store-bytes.c
gcc/testsuite/gcc.target/bpf/helper-skb-under-cgroup.c
gcc/testsuite/gcc.target/bpf/helper-skb-vlan-pop.c
gcc/testsuite/gcc.target/bpf/helper-skb-vlan-push.c
gcc/testsuite/gcc.target/bpf/helper-skc-lookup-tcp.c
gcc/testsuite/gcc.target/bpf/helper-sock-hash-update.c
gcc/testsuite/gcc.target/bpf/helper-sock-map-update.c
gcc/testsuite/gcc.target/bpf/helper-sock-ops-cb-flags-set.c
gcc/testsuite/gcc.target/bpf/helper-spin-lock.c
gcc/testsuite/gcc.target/bpf/helper-spin-unlock.c
gcc/testsuite/gcc.target/bpf/helper-strtol.c
gcc/testsuite/gcc.target/bpf/helper-strtoul.c
gcc/testsuite/gcc.target/bpf/helper-sysctl-get-current-value.c
gcc/testsuite/gcc.target/bpf/helper-sysctl-get-name.c
gcc/testsuite/gcc.target/bpf/helper-sysctl-get-new-value.c
gcc/testsuite/gcc.target/bpf/helper-sysctl-set-new-value.c
gcc/testsuite/gcc.target/bpf/helper-tail-call.c
gcc/testsuite/gcc.target/bpf/helper-tcp-check-syncookie.c
gcc/testsuite/gcc.target/bpf/helper-tcp-sock.c
gcc/testsuite/gcc.target/bpf/helper-trace-printk.c
gcc/testsuite/gcc.target/bpf/helper-xdp-adjust-head.c
gcc/testsuite/gcc.target/bpf/helper-xdp-adjust-meta.c
gcc/testsuite/gcc.target/bpf/helper-xdp-adjust-tail.c
gcc/testsuite/gcc.target/bpf/skb-ancestor-cgroup-id.c