Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bpftool sync 2023-08-29 #113

Merged
merged 29 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ae4a112
bpf: Support ->fill_link_info for kprobe_multi
laoar Jul 9, 2023
da69013
bpftool: Dump the kernel symbol's module name
laoar Jul 9, 2023
adb2fe1
bpftool: Show kprobe_multi link info
laoar Jul 9, 2023
9626287
bpf: Support ->fill_link_info for perf_event
laoar Jul 9, 2023
ca14739
bpftool: Add perf event names
laoar Jul 9, 2023
86820ac
bpftool: Show perf link info
laoar Jul 9, 2023
6052c9a
bpftool: Use "fallthrough;" keyword instead of comments
qmonnet Jul 12, 2023
46ee985
bpf: Add generic attach/detach/query API for multi-progs
borkmann Jul 19, 2023
ae4b11a
bpf: Add fd-based tcx multi-prog infra with link support
borkmann Jul 19, 2023
5c3e113
bpftool: Extend net dump with tcx progs
borkmann Jul 19, 2023
94b64a4
bpf: sync tools/ uapi header with
alan-maguire Jul 19, 2023
786bfb6
bpf, net: Support SO_REUSEPORT sockets with bpf_sk_assign
lmb Jul 20, 2023
81d76fa
netfilter: bpf: Support BPF_F_NETFILTER_IP_DEFRAG in netfilter link
danobi Jul 21, 2023
31ec51a
bpf: Support new sign-extension load insns
Jul 28, 2023
a33fafc
bpf: Add kernel/bpftool asm support for new instructions
Jun 28, 2023
ff2cbfb
bpf: Fix an array-index-out-of-bounds issue in disasm.c
Jul 31, 2023
554a1b2
bpf: change bpf_alu_sign_string and bpf_movsx_string to static
Aug 3, 2023
f5ad0df
bpf: Add support for bpf_get_func_ip helper for uprobe program
olsajiri Aug 7, 2023
c84d14f
bpf: Add multi uprobe link
olsajiri Aug 9, 2023
1a3a19d
bpf: Add cookies support for uprobe_multi link
olsajiri Aug 9, 2023
a8e6b8e
bpf: Add pid filter support for uprobe_multi link
olsajiri Aug 9, 2023
ffd6e4d
bpftool: fix perf help message
DanielTimLee Aug 11, 2023
c0bb967
bpftool: Implement link show support for tcx
borkmann Aug 16, 2023
54fcada
bpftool: Implement link show support for xdp
borkmann Aug 16, 2023
d780634
bpf: Switch BPF_F_KPROBE_MULTI_RETURN macro to enum
olsajiri Aug 9, 2023
634eeb5
sync: Update libbpf submodule
qmonnet Aug 29, 2023
938e3a6
asm-generic: Unify uapi bitsperlong.h for arm64, riscv and loongarch
Jun 22, 2023
0fbbac2
sync: Pull latest bpftool changes from kernel
qmonnet Aug 29, 2023
a8dbc3d
mirror: Update "fallthrough" keyword definition
qmonnet Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BPF-CHECKPOINT-COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
496720b7cfb6574a8f6f4d434f23e3d1e6cfaeb9
23d775f12dcd23d052a4927195f15e970e27ab26
2 changes: 1 addition & 1 deletion CHECKPOINT-COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a3e7e6b17946f48badce98d7ac360678a0ea7393
9e3b47abeb8f76c39c570ffc924ac0b35f132274
26 changes: 15 additions & 11 deletions docs/bpftool-net.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
bpftool-net
================
-------------------------------------------------------------------------------
tool for inspection of netdev/tc related bpf prog attachments
tool for inspection of networking related bpf prog attachments
-------------------------------------------------------------------------------

:Manual section: 8
Expand Down Expand Up @@ -37,10 +37,13 @@ DESCRIPTION
**bpftool net { show | list }** [ **dev** *NAME* ]
List bpf program attachments in the kernel networking subsystem.

Currently, only device driver xdp attachments and tc filter
classification/action attachments are implemented, i.e., for
program types **BPF_PROG_TYPE_SCHED_CLS**,
**BPF_PROG_TYPE_SCHED_ACT** and **BPF_PROG_TYPE_XDP**.
Currently, device driver xdp attachments, tcx and old-style tc
classifier/action attachments, flow_dissector as well as netfilter
attachments are implemented, i.e., for
program types **BPF_PROG_TYPE_XDP**, **BPF_PROG_TYPE_SCHED_CLS**,
**BPF_PROG_TYPE_SCHED_ACT**, **BPF_PROG_TYPE_FLOW_DISSECTOR**,
**BPF_PROG_TYPE_NETFILTER**.

For programs attached to a particular cgroup, e.g.,
**BPF_PROG_TYPE_CGROUP_SKB**, **BPF_PROG_TYPE_CGROUP_SOCK**,
**BPF_PROG_TYPE_SOCK_OPS** and **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
Expand All @@ -49,12 +52,13 @@ DESCRIPTION
bpf programs, users should consult other tools, e.g., iproute2.

The current output will start with all xdp program attachments, followed by
all tc class/qdisc bpf program attachments. Both xdp programs and
tc programs are ordered based on ifindex number. If multiple bpf
programs attached to the same networking device through **tc filter**,
the order will be first all bpf programs attached to tc classes, then
all bpf programs attached to non clsact qdiscs, and finally all
bpf programs attached to root and clsact qdisc.
all tcx, then tc class/qdisc bpf program attachments, then flow_dissector
and finally netfilter programs. Both xdp programs and tcx/tc programs are
ordered based on ifindex number. If multiple bpf programs attached
to the same networking device through **tc**, the order will be first
all bpf programs attached to tcx, then tc classes, then all bpf programs
attached to non clsact qdiscs, and finally all bpf programs attached
to root and clsact qdisc.

**bpftool** **net attach** *ATTACH_TYPE* *PROG* **dev** *NAME* [ **overwrite** ]
Attach bpf program *PROG* to network interface *NAME* with
Expand Down
6 changes: 4 additions & 2 deletions include/linux/compiler-gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
+ __GNUC_PATCHLEVEL__)
#endif

#if GCC_VERSION >= 70000 && !defined(__CHECKER__)
# define __fallthrough __attribute__ ((fallthrough))
#if __has_attribute(__fallthrough__)
# define fallthrough __attribute__((__fallthrough__))
#else
# define fallthrough do {} while (0) /* fallthrough */
#endif

#if __has_attribute(__error__)
Expand Down
4 changes: 0 additions & 4 deletions include/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,4 @@
# define __weak __attribute__((weak))
#endif

#ifndef __fallthrough
# define __fallthrough
#endif

#endif
14 changes: 13 additions & 1 deletion include/uapi/asm-generic/bitsperlong.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef _UAPI__ASM_GENERIC_BITS_PER_LONG
#define _UAPI__ASM_GENERIC_BITS_PER_LONG

#ifndef __BITS_PER_LONG
/*
* In order to keep safe and avoid regression, only unify uapi
* bitsperlong.h for some archs which are using newer toolchains
* that have the definitions of __CHAR_BIT__ and __SIZEOF_LONG__.
* See the following link for more info:
* https://lore.kernel.org/linux-arch/b9624545-2c80-49a1-ac3c-39264a591f7b@app.fastmail.com/
*/
#if defined(__CHAR_BIT__) && defined(__SIZEOF_LONG__)
#define __BITS_PER_LONG (__CHAR_BIT__ * __SIZEOF_LONG__)
#else
/*
* There seems to be no way of detecting this automatically from user
* space, so 64 bit architectures should override this in their
* bitsperlong.h. In particular, an architecture that supports
* both 32 and 64 bit user space must not rely on CONFIG_64BIT
* to decide it, but rather check a compiler provided macro.
*/
#ifndef __BITS_PER_LONG
#define __BITS_PER_LONG 32
#endif
#endif

#endif /* _UAPI__ASM_GENERIC_BITS_PER_LONG */
150 changes: 133 additions & 17 deletions include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/* ld/ldx fields */
#define BPF_DW 0x18 /* double word (64-bit) */
#define BPF_MEMSX 0x80 /* load with sign extension */
#define BPF_ATOMIC 0xc0 /* atomic memory ops - op type in immediate */
#define BPF_XADD 0xc0 /* exclusive add - legacy name */

Expand Down Expand Up @@ -1036,6 +1037,9 @@ enum bpf_attach_type {
BPF_LSM_CGROUP,
BPF_STRUCT_OPS,
BPF_NETFILTER,
BPF_TCX_INGRESS,
BPF_TCX_EGRESS,
BPF_TRACE_UPROBE_MULTI,
__MAX_BPF_ATTACH_TYPE
};

Expand All @@ -1053,10 +1057,21 @@ enum bpf_link_type {
BPF_LINK_TYPE_KPROBE_MULTI = 8,
BPF_LINK_TYPE_STRUCT_OPS = 9,
BPF_LINK_TYPE_NETFILTER = 10,

BPF_LINK_TYPE_TCX = 11,
BPF_LINK_TYPE_UPROBE_MULTI = 12,
MAX_BPF_LINK_TYPE,
};

enum bpf_perf_event_type {
BPF_PERF_EVENT_UNSPEC = 0,
BPF_PERF_EVENT_UPROBE = 1,
BPF_PERF_EVENT_URETPROBE = 2,
BPF_PERF_EVENT_KPROBE = 3,
BPF_PERF_EVENT_KRETPROBE = 4,
BPF_PERF_EVENT_TRACEPOINT = 5,
BPF_PERF_EVENT_EVENT = 6,
};

/* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
*
* NONE(default): No further bpf programs allowed in the subtree.
Expand Down Expand Up @@ -1103,7 +1118,12 @@ enum bpf_link_type {
*/
#define BPF_F_ALLOW_OVERRIDE (1U << 0)
#define BPF_F_ALLOW_MULTI (1U << 1)
/* Generic attachment flags. */
#define BPF_F_REPLACE (1U << 2)
#define BPF_F_BEFORE (1U << 3)
#define BPF_F_AFTER (1U << 4)
#define BPF_F_ID (1U << 5)
#define BPF_F_LINK BPF_F_LINK /* 1 << 13 */

/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
* verifier will perform strict alignment checking as if the kernel
Expand Down Expand Up @@ -1168,7 +1188,21 @@ enum bpf_link_type {
/* link_create.kprobe_multi.flags used in LINK_CREATE command for
* BPF_TRACE_KPROBE_MULTI attach type to create return probe.
*/
#define BPF_F_KPROBE_MULTI_RETURN (1U << 0)
enum {
BPF_F_KPROBE_MULTI_RETURN = (1U << 0)
};

/* link_create.uprobe_multi.flags used in LINK_CREATE command for
* BPF_TRACE_UPROBE_MULTI attach type to create return probe.
*/
enum {
BPF_F_UPROBE_MULTI_RETURN = (1U << 0)
};

/* link_create.netfilter.flags used in LINK_CREATE command for
* BPF_PROG_TYPE_NETFILTER to enable IP packet defragmentation.
*/
#define BPF_F_NETFILTER_IP_DEFRAG (1U << 0)

/* When BPF ldimm64's insn[0].src_reg != 0 then this can have
* the following extensions:
Expand Down Expand Up @@ -1434,14 +1468,19 @@ union bpf_attr {
};

struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
__u32 target_fd; /* container object to attach to */
__u32 attach_bpf_fd; /* eBPF program to attach */
union {
__u32 target_fd; /* target object to attach to or ... */
__u32 target_ifindex; /* target ifindex */
};
__u32 attach_bpf_fd;
__u32 attach_type;
__u32 attach_flags;
__u32 replace_bpf_fd; /* previously attached eBPF
* program to replace if
* BPF_F_REPLACE is used
*/
__u32 replace_bpf_fd;
union {
__u32 relative_fd;
__u32 relative_id;
};
__u64 expected_revision;
};

struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
Expand Down Expand Up @@ -1487,16 +1526,26 @@ union bpf_attr {
} info;

struct { /* anonymous struct used by BPF_PROG_QUERY command */
__u32 target_fd; /* container object to query */
union {
__u32 target_fd; /* target object to query or ... */
__u32 target_ifindex; /* target ifindex */
};
__u32 attach_type;
__u32 query_flags;
__u32 attach_flags;
__aligned_u64 prog_ids;
__u32 prog_cnt;
union {
__u32 prog_cnt;
__u32 count;
};
__u32 :32;
/* output: per-program attach_flags.
* not allowed to be set during effective query.
*/
__aligned_u64 prog_attach_flags;
__aligned_u64 link_ids;
__aligned_u64 link_attach_flags;
__u64 revision;
} query;

struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
Expand Down Expand Up @@ -1539,13 +1588,13 @@ union bpf_attr {
__u32 map_fd; /* struct_ops to attach */
};
union {
__u32 target_fd; /* object to attach to */
__u32 target_ifindex; /* target ifindex */
__u32 target_fd; /* target object to attach to or ... */
__u32 target_ifindex; /* target ifindex */
};
__u32 attach_type; /* attach type */
__u32 flags; /* extra flags */
union {
__u32 target_btf_id; /* btf_id of target to attach to */
__u32 target_btf_id; /* btf_id of target to attach to */
struct {
__aligned_u64 iter_info; /* extra bpf_iter_link_info */
__u32 iter_info_len; /* iter_info length */
Expand Down Expand Up @@ -1579,6 +1628,22 @@ union bpf_attr {
__s32 priority;
__u32 flags;
} netfilter;
struct {
union {
__u32 relative_fd;
__u32 relative_id;
};
__u64 expected_revision;
} tcx;
struct {
__aligned_u64 path;
__aligned_u64 offsets;
__aligned_u64 ref_ctr_offsets;
__aligned_u64 cookies;
__u32 cnt;
__u32 flags;
__u32 pid;
} uprobe_multi;
};
} link_create;

Expand Down Expand Up @@ -4159,9 +4224,6 @@ union bpf_attr {
* **-EOPNOTSUPP** if the operation is not supported, for example
* a call from outside of TC ingress.
*
* **-ESOCKTNOSUPPORT** if the socket type is not supported
* (reuseport).
*
* long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)
* Description
* Helper is overloaded depending on BPF program type. This
Expand Down Expand Up @@ -5044,9 +5106,14 @@ union bpf_attr {
* u64 bpf_get_func_ip(void *ctx)
* Description
* Get address of the traced function (for tracing and kprobe programs).
*
* When called for kprobe program attached as uprobe it returns
* probe address for both entry and return uprobe.
*
* Return
* Address of the traced function.
* Address of the traced function for kprobe.
* 0 for kprobes placed within the function (not at the entry).
* Address of the probe for uprobe and return uprobe.
*
* u64 bpf_get_attach_cookie(void *ctx)
* Description
Expand Down Expand Up @@ -6187,6 +6254,19 @@ struct bpf_sock_tuple {
};
};

/* (Simplified) user return codes for tcx prog type.
* A valid tcx program must return one of these defined values. All other
* return codes are reserved for future use. Must remain compatible with
* their TC_ACT_* counter-parts. For compatibility in behavior, unknown
* return codes are mapped to TCX_NEXT.
*/
enum tcx_action_base {
TCX_NEXT = -1,
TCX_PASS = 0,
TCX_DROP = 2,
TCX_REDIRECT = 7,
};

struct bpf_xdp_sock {
__u32 queue_id;
};
Expand Down Expand Up @@ -6439,6 +6519,40 @@ struct bpf_link_info {
__s32 priority;
__u32 flags;
} netfilter;
struct {
__aligned_u64 addrs;
__u32 count; /* in/out: kprobe_multi function count */
__u32 flags;
} kprobe_multi;
struct {
__u32 type; /* enum bpf_perf_event_type */
__u32 :32;
union {
struct {
__aligned_u64 file_name; /* in/out */
__u32 name_len;
__u32 offset; /* offset from file_name */
} uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */
struct {
__aligned_u64 func_name; /* in/out */
__u32 name_len;
__u32 offset; /* offset from func_name */
__u64 addr;
} kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */
struct {
__aligned_u64 tp_name; /* in/out */
__u32 name_len;
} tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */
struct {
__u64 config;
__u32 type;
} event; /* BPF_PERF_EVENT_EVENT */
};
} perf_event;
struct {
__u32 ifindex;
__u32 attach_type;
} tcx;
};
} __attribute__((aligned(8)));

Expand Down Expand Up @@ -7012,6 +7126,7 @@ struct bpf_list_head {
struct bpf_list_node {
__u64 :64;
__u64 :64;
__u64 :64;
} __attribute__((aligned(8)));

struct bpf_rb_root {
Expand All @@ -7023,6 +7138,7 @@ struct bpf_rb_node {
__u64 :64;
__u64 :64;
__u64 :64;
__u64 :64;
} __attribute__((aligned(8)));

struct bpf_refcount {
Expand Down
2 changes: 1 addition & 1 deletion src/btf_dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ static void dotlabel_puts(const char *s)
case '|':
case ' ':
putchar('\\');
/* fallthrough */
fallthrough;
default:
putchar(*s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type,
case BPF_FUNC_probe_write_user:
if (!full_mode)
continue;
/* fallthrough */
fallthrough;
default:
probe_res |= probe_helper_for_progtype(prog_type, supported_type,
define_prefix, id, prog_type_str,
Expand Down
Loading
Loading