From patchwork Sat Aug 17 00:50:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 1148554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-507168-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="grDZhFfr"; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="kPL8yYwZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 469M8k1Sb9z9sDQ for ; Sat, 17 Aug 2019 10:52:05 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=ScEo2QS+75oxambDhmJDHAQCET7WLFqsYGLCIHbOIuZoHYx3esNtK Gbzb+vQ1rQSHUDVQAE/y742ht0a1RvD8B2fC4AbpBR7TjkHl1TGFZIN7aeyPsWsi JXSOOUigqdI8ESxuAaIb++4q5CDonnVq6cvuZ2z5dK+XqR/CNkQXuM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references; s=default; bh=u/TZ6goC5M/iC+oiv15RI59q0SI=; b=grDZhFfr8/0BHCPwr8u4nkiOYzeu VbyyZQYXAqHsKr1llu3/LsRzneZ9wZnfkDewe8hlhyHPZOWDIOkObyrzRfG0+Ort pk1FDs5kIY9NZ5e8NscGSCjb+Rj8bfxzZv37QUYQ/UPIUjM4+wbXlAUJ+ujb5j8N d+BeLNH9RVcBUp0= Received: (qmail 119488 invoked by alias); 17 Aug 2019 00:51:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 119260 invoked by uid 89); 17 Aug 2019 00:51:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 spammy=DEC X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Aug 2019 00:51:13 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7H0n4rv161636 for ; Sat, 17 Aug 2019 00:51:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2019-08-05; bh=CId9HALTu8LQjdCM6x8ohTn1A7Ec7p7hhqfU9kiO4Wc=; b=kPL8yYwZRzHOmCg6F56g0C0av5eN41MAFCdWg6x+xUn7boA11CveOm7b9KgpGpnOk+RC nS8iLROXgexssEpYzKskYoLwEN2XI62nSkWAbjStTa3Km61tBjysHP7s+NoYEbekiHvi LoO1kumGe3d7xv2u4/kx5Lw9pkiyQ5uBA2NBkFm9ktQ2G9qw7rFgWbnqora1VOm8V5bY /kHLDKPt5qyzjRXO5C/1rvS6+HbLmxRvK9cLlOkdHo8+7xvPp0mVIgHa1IXg6LEb+bVt Rbpbhmu7meXjfhjVM1ivFj1D8DqDMDNAPqcb+SVM5LdZ+T7HIV/4IB3HlBEXQHjactdK Ag== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2u9pjr30vx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 17 Aug 2019 00:51:12 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7H0lqhS189188 for ; Sat, 17 Aug 2019 00:51:11 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2ue6qcgxch-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 17 Aug 2019 00:51:11 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x7H0pAnv029677 for ; Sat, 17 Aug 2019 00:51:10 GMT Received: from termi.localdomain (/10.175.36.100) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 16 Aug 2019 17:51:10 -0700 From: "Jose E. Marchesi" To: gcc-patches@gcc.gnu.org Subject: [PATCH V2 7/8] bpf: manual updates for eBPF Date: Sat, 17 Aug 2019 02:50:55 +0200 Message-Id: <20190817005056.15749-8-jose.marchesi@oracle.com> In-Reply-To: <20190817005056.15749-1-jose.marchesi@oracle.com> References: <20190817005056.15749-1-jose.marchesi@oracle.com> X-IsSubscribed: yes gcc/ChangeLog: * doc/invoke.texi (Option Summary): Cover eBPF. (eBPF Options): New section. * doc/extend.texi (BPF Built-in Functions): Likewise. (BPF Kernel Helpers): Likewise. --- gcc/ChangeLog | 7 +++ gcc/doc/extend.texi | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/doc/invoke.texi | 30 +++++++++ 3 files changed, 208 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 2ba9b74811a..7b75326590c 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -13603,6 +13603,8 @@ instructions, but allow the compiler to schedule those calls. * ARM ARMv8-M Security Extensions:: * AVR Built-in Functions:: * Blackfin Built-in Functions:: +* BPF Built-in Functions:: +* BPF Kernel Helpers:: * FR-V Built-in Functions:: * MIPS DSP Built-in Functions:: * MIPS Paired-Single Support:: @@ -14600,6 +14602,175 @@ void __builtin_bfin_csync (void) void __builtin_bfin_ssync (void) @end smallexample +@node BPF Built-in Functions +@subsection BPF Built-in Functions + +The following built-in functions are available for eBPF targets. + +@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_byte (unsigned long long @var{offset}) +Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. +@end deftypefn + +@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_half (unsigned long long @var{offset}) +Load 16-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. +@end deftypefn + +@deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_word (unsigned long long @var{offset}) +Load 32-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. +@end deftypefn + +@node BPF Kernel Helpers +@subsection BPF Kernel Helpers + +These built-in functions are available for calling kernel helpers, and +they are available depending on the kernel version selected as the +CPU. + +Rather than using the built-ins directly, it is preferred for programs +to include @file{bpf-helpers.h} and use the wrappers defined there. + +For a full description of what the helpers do, the arguments they +take, and the returned value, see the +@file{linux/include/uapi/linux/bpf.h} in a Linux source tree. + +@smallexample +void *__builtin_bpf_helper_map_lookup_elem (void *map, void *key) +int __builtin_bpf_helper_map_update_elem (void *map, void *key, + void *value, + unsigned long long flags) +int __builtin_bpf_helper_map_delete_elem (void *map, const void *key) +int __builtin_bpf_helper_map_push_elem (void *map, const void *value, + unsigned long long flags) +int __builtin_bpf_helper_map_pop_elem (void *map, void *value) +int __builtin_bpf_helper_map_peek_elem (void *map, void *value) +int __builtin_bpf_helper_clone_redirect (void *skb, + unsigned int ifindex, + unsigned long long flags) +int __builtin_bpf_helper_skb_get_tunnel_key (void *ctx, void *key, int size, int flags) +int __builtin_bpf_helper_skb_set_tunnel_key (void *ctx, void *key, int size, int flags) +int __builtin_bpf_helper_skb_get_tunnel_opt (void *ctx, void *md, int size) +int __builtin_bpf_helper_skb_set_tunnel_opt (void *ctx, void *md, int size) +int __builtin_bpf_helper_skb_get_xfrm_state (void *ctx, int index, void *state, + int size, int flags) +static unsigned long long __builtin_bpf_helper_skb_cgroup_id (void *ctx) +static unsigned long long __builtin_bpf_helper_skb_ancestor_cgroup_id + (void *ctx, int level) +int __builtin_bpf_helper_skb_vlan_push (void *ctx, __be16 vlan_proto, __u16 vlan_tci) +int __builtin_bpf_helper_skb_vlan_pop (void *ctx) +int __builtin_bpf_helper_skb_ecn_set_ce (void *ctx) + +int __builtin_bpf_helper_skb_load_bytes (void *ctx, int off, void *to, int len) +int __builtin_bpf_helper_skb_load_bytes_relative (void *ctx, int off, void *to, int len, __u32 start_header) +int __builtin_bpf_helper_skb_store_bytes (void *ctx, int off, void *from, int len, int flags) +int __builtin_bpf_helper_skb_under_cgroup (void *ctx, void *map, int index) +int __builtin_bpf_helper_skb_change_head (void *, int len, int flags) +int __builtin_bpf_helper_skb_pull_data (void *, int len) +int __builtin_bpf_helper_skb_change_proto (void *ctx, __be16 proto, __u64 flags) +int __builtin_bpf_helper_skb_change_type (void *ctx, __u32 type) +int __builtin_bpf_helper_skb_change_tail (void *ctx, __u32 len, __u64 flags) +int __builtin_bpf_helper_skb_adjust_room (void *ctx, __s32 len_diff, __u32 mode, + unsigned long long flags) +@end smallexample + +Other helpers: + +@smallexample +int __builtin_bpf_helper_probe_read (void *dst, unsigned int size, void *src) +unsigned long long __builtin_bpf_helper_ktime_get_ns (void) +int __builtin_bpf_helper_trace_printk (const char *fmt, unsigned int fmt_size, ...) +void __builtin_bpf_helper_tail_call (void *ctx, void *prog_array_map, unsigned int index) +unsigned int __builtin_bpf_helper_get_smp_processor_id (void) +unsigned long long __builtin_bpf_helper_get_current_pid_tgid (void) +unsigned long long __builtin_bpf_helper_get_current_uid_gid (void) +int __builtin_bpf_helper_get_current_comm (void *buf, unsigned int size_of_buf) +unsigned long long __builtin_bpf_helper_perf_event_read (void *map, unsigned long long flags) + +int __builtin_bpf_helper_redirect (unsigned int ifindex, unsigned long long flags) +int __builtin_bpf_helper_redirect_map (void *map, unsigned int key, unsigned long long flags) +int __builtin_bpf_helper_perf_event_output (void *ctx,void *map, unsigned long long flags, void *data, unsigned long long size) +int __builtin_bpf_helper_get_stackid (void *ctx, void *map, unsigned long long flags) +int __builtin_bpf_helper_probe_write_user (void *dst, const void *src, unsigned int len) +int __builtin_bpf_helper_current_task_under_cgroup (void *map, unsigned int index) + +static unsigned long long __builtin_bpf_helper_get_prandom_u32 (void) +int __builtin_bpf_helper_xdp_adjust_head (void *ctx, int offset) +int __builtin_bpf_helper_xdp_adjust_meta (void *ctx, int offset) +int __builtin_bpf_helper_get_socket_cookie (void *ctx) +int __builtin_bpf_helper_setsockopt (void *ctx, int level, int optname, void *optval, + int optlen) +int __builtin_bpf_helper_getsockopt (void *ctx, int level, int optname, void *optval, + int optlen) +int __builtin_bpf_helper_sock_ops_cb_flags_set (void *ctx, int flags) +int __builtin_bpf_helper_sk_redirect_map (void *ctx, void *map, int key, int flags) +int __builtin_bpf_helper_sk_redirect_hash (void *ctx, void *map, void *key, int flags) +int __builtin_bpf_helper_sock_map_update (void *map, void *key, void *value, + unsigned long long flags) +int __builtin_bpf_helper_sock_hash_update (void *map, void *key, void *value, + unsigned long long flags) +int __builtin_bpf_helper_perf_event_read_value (void *map, unsigned long long flags, + void *buf, unsigned int buf_size) +int __builtin_bpf_helper_perf_prog_read_value (void *ctx, void *buf, + unsigned int buf_size) + +int __builtin_bpf_helper_override_return (void *ctx, unsigned long rc) +int __builtin_bpf_helper_msg_redirect_map (void *ctx, void *map, int key, int flags) +int __builtin_bpf_helper_msg_redirect_hash (void *ctx, + void *map, void *key, int flags) +int __builtin_bpf_helper_msg_apply_bytes (void *ctx, int len) +int __builtin_bpf_helper_msg_cork_bytes (void *ctx, int len) +int __builtin_bpf_helper_msg_pull_data (void *ctx, int start, int end, int flags) +int __builtin_bpf_helper_msg_push_data (void *ctx, int start, int end, int flags) +int __builtin_bpf_helper_msg_pop_data (void *ctx, int start, int cut, int flags) +int __builtin_bpf_helper_bind (void *ctx, void *addr, int addr_len) +int __builtin_bpf_helper_xdp_adjust_tail (void *ctx, int offset) +int __builtin_bpf_helper_sk_select_reuseport (void *ctx, void *map, void *key, __u32 flags) +int __builtin_bpf_helper_get_stack (void *ctx, void *buf, int size, int flags) +int __builtin_bpf_helper_fib_lookup (void *ctx, struct bpf_fib_lookup *params, + int plen, __u32 flags) + +int __builtin_bpf_helper_lwt_push_encap (void *ctx, unsigned int type, void *hdr, + unsigned int len) +int __builtin_bpf_helper_lwt_seg6_store_bytes (void *ctx, unsigned int offset, + void *from, unsigned int len) +int __builtin_bpf_helper_lwt_seg6_action (void *ctx, unsigned int action, void *param, + unsigned int param_len) +int __builtin_bpf_helper_lwt_seg6_adjust_srh (void *ctx, unsigned int offset, + unsigned int len) +int __builtin_bpf_helper_rc_repeat (void *ctx) +int __builtin_bpf_helper_rc_keydown (void *ctx, unsigned int protocol, + unsigned long long scancode, unsigned int toggle) +static unsigned long long __builtin_bpf_helper_get_current_cgroup_id (void) +static void *__builtin_bpf_helper_get_local_storage (void *map, unsigned long long flags) +static struct bpf_sock *__builtin_bpf_helper_sk_lookup_tcp (void *ctx, void *tuple, int size, unsigned long long netns_id, unsigned long long flags) +static struct bpf_sock *__builtin_bpf_helper_sk_lookup_udp (void *ctx, void *tuple, int size, unsigned long long netns_id, unsigned long long flags) +int __builtin_bpf_helper_sk_release (struct bpf_sock *sk) +int __builtin_bpf_helper_rc_pointer_rel (void *ctx, int rel_x, int rel_y) +static void __builtin_bpf_helper_spin_lock (struct bpf_spin_lock *lock) +static void __builtin_bpf_helper_spin_unlock (struct bpf_spin_lock *lock) + +static struct bpf_sock *__builtin_bpf_helper_sk_fullsock (struct bpf_sock *sk) +static struct bpf_tcp_sock *__builtin_bpf_helper_tcp_sock (struct bpf_sock *sk) +static struct bpf_sock *__builtin_bpf_helper_get_listener_sock (struct bpf_sock *sk) + +int __builtin_bpf_helper_l3_csum_replace (void *ctx, int off, int from, int to, int flags) +int __builtin_bpf_helper_l4_csum_replace (void *ctx, int off, int from, int to, int flags) +int __builtin_bpf_helper_csum_diff (void *from, int from_size, void *to, int to_size, int seed) + +static unsigned int __builtin_bpf_helper_get_cgroup_classid (void *ctx) +static unsigned int __builtin_bpf_helper_get_route_realm (void *ctx) +static unsigned int __builtin_bpf_helper_get_hash_recalc (void *ctx) +static unsigned long long __builtin_bpf_helper_get_current_task (void *ctx) + +static long long __builtin_bpf_helper_csum_update (void *ctx, __u32 csum) +static void __builtin_bpf_helper_set_hash_invalid (void *ctx) +int __builtin_bpf_helper_get_numa_node_id (void) +int __builtin_bpf_helper_probe_read_str (void *ctx, __u32 size, + const void *unsafe_ptr) +static unsigned int __builtin_bpf_helper_get_socket_uid (void *ctx) +static unsigned int __builtin_bpf_helper_set_hash (void *ctx, __u32 hash) +@end smallexample + + @node FR-V Built-in Functions @subsection FR-V Built-in Functions diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index ca111792885..621416aa40b 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -800,6 +800,9 @@ Objective-C and Objective-C++ Dialects}. -msmall-text -mlarge-text @gol -mmemory-latency=@var{time}} +@emph{eBPF Options} +@gccoptlist{-mbig-endian -mlittle-endian -mkernel=@var{version}} + @emph{FR30 Options} @gccoptlist{-msmall-model -mno-lsim} @@ -15660,6 +15663,7 @@ platform. * C-SKY Options:: * Darwin Options:: * DEC Alpha Options:: +* eBPF Options:: * FR30 Options:: * FT32 Options:: * FRV Options:: @@ -19780,6 +19784,32 @@ Note that L3 is only valid for EV5. @end table @end table +@node eBPF Options +@subsection eBPF Options +@cindex eBPF Options + +@table @gcctabopt +@item -mkernel=@var{version} +@opindex mkernel +This specifies the minimum version of the kernel that will run the +compiled program. GCC uses this version to determine which +instructions to use, what kernel helpers to allow, etc. Currently, +@var{version} can be one of @samp{4.0}, @samp{4.1}, @samp{4.2}, +@samp{4.3}, @samp{4.4}, @samp{4.5}, @samp{4.6}, @samp{4.7}, +@samp{4.8}, @samp{4.9}, @samp{4.10}, @samp{4.11}, @samp{4.12}, +@samp{4.13}, @samp{4.14}, @samp{4.15}, @samp{4.16}, @samp{4.17}, +@samp{4.18}, @samp{4.19}, @samp{4.20}, @samp{5.0}, @samp{5.1}, +@samp{5.2}, @samp{latest} and @samp{native}. + +@item -mbig-endian +@opindex mbig-endian +Generate code for a big-endian target. + +@item -mlittle-endian +@opindex mlittle-endian +Generate code for a little-endian target. This is the default. +@end table + @node FR30 Options @subsection FR30 Options @cindex FR30 Options