-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2018-04-21 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Initial work on BPF Type Format (BTF) is added, which is a meta data format which describes the data types of BPF programs / maps. BTF has its roots from CTF (Compact C-Type format) with a number of changes to it. First use case is to provide a generic pretty print capability for BPF maps inspection, later work will also add BTF to bpftool. pahole support to convert dwarf to BTF will be upstreamed as well (https://github.com/iamkafai/pahole/tree/btf), from Martin. 2) Add a new xdp_bpf_adjust_tail() BPF helper for XDP that allows for changing the data_end pointer. Only shrinking is currently supported which helps for crafting ICMP control messages. Minor changes in drivers have been added where needed so they recalc the packet's length also when data_end was adjusted, from Nikita. 3) Improve bpftool to make it easier to feed hex bytes via cmdline for map operations, from Quentin. 4) Add support for various missing BPF prog types and attach types that have been added to kernel recently but neither to bpftool nor libbpf yet. Doc and bash completion updates have been added as well for bpftool, from Andrey. 5) Proper fix for avoiding to leak info stored in frame data on page reuse for the two bpf_xdp_adjust_{head,meta} helpers by disallowing to move the pointers into struct xdp_frame area, from Jesper. 6) Follow-up compile fix from BTF in order to include stdbool.h in libbpf, from Björn. 7) Few fixes in BPF sample code, that is, a typo on the netdevice in a comment and fixup proper dump of XDP action code in the tracepoint exception, from Wang and Jesper. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
45 changed files
with
5,591 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* Copyright (c) 2018 Facebook */ | ||
|
||
#ifndef _LINUX_BTF_H | ||
#define _LINUX_BTF_H 1 | ||
|
||
#include <linux/types.h> | ||
|
||
struct btf; | ||
struct btf_type; | ||
union bpf_attr; | ||
|
||
extern const struct file_operations btf_fops; | ||
|
||
void btf_put(struct btf *btf); | ||
int btf_new_fd(const union bpf_attr *attr); | ||
struct btf *btf_get_by_fd(int fd); | ||
int btf_get_info_by_fd(const struct btf *btf, | ||
const union bpf_attr *attr, | ||
union bpf_attr __user *uattr); | ||
/* Figure out the size of a type_id. If type_id is a modifier | ||
* (e.g. const), it will be resolved to find out the type with size. | ||
* | ||
* For example: | ||
* In describing "const void *", type_id is "const" and "const" | ||
* refers to "void *". The return type will be "void *". | ||
* | ||
* If type_id is a simple "int", then return type will be "int". | ||
* | ||
* @btf: struct btf object | ||
* @type_id: Find out the size of type_id. The type_id of the return | ||
* type is set to *type_id. | ||
* @ret_size: It can be NULL. If not NULL, the size of the return | ||
* type is set to *ret_size. | ||
* Return: The btf_type (resolved to another type with size info if needed). | ||
* NULL is returned if type_id itself does not have size info | ||
* (e.g. void) or it cannot be resolved to another type that | ||
* has size info. | ||
* *type_id and *ret_size will not be changed in the | ||
* NULL return case. | ||
*/ | ||
const struct btf_type *btf_type_id_size(const struct btf *btf, | ||
u32 *type_id, | ||
u32 *ret_size); | ||
void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj, | ||
struct seq_file *m); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | ||
/* Copyright (c) 2018 Facebook */ | ||
#ifndef _UAPI__LINUX_BTF_H__ | ||
#define _UAPI__LINUX_BTF_H__ | ||
|
||
#include <linux/types.h> | ||
|
||
#define BTF_MAGIC 0xeB9F | ||
#define BTF_MAGIC_SWAP 0x9FeB | ||
#define BTF_VERSION 1 | ||
#define BTF_FLAGS_COMPR 0x01 | ||
|
||
struct btf_header { | ||
__u16 magic; | ||
__u8 version; | ||
__u8 flags; | ||
|
||
__u32 parent_label; | ||
__u32 parent_name; | ||
|
||
/* All offsets are in bytes relative to the end of this header */ | ||
__u32 label_off; /* offset of label section */ | ||
__u32 object_off; /* offset of data object section*/ | ||
__u32 func_off; /* offset of function section */ | ||
__u32 type_off; /* offset of type section */ | ||
__u32 str_off; /* offset of string section */ | ||
__u32 str_len; /* length of string section */ | ||
}; | ||
|
||
/* Max # of type identifier */ | ||
#define BTF_MAX_TYPE 0x7fffffff | ||
/* Max offset into the string section */ | ||
#define BTF_MAX_NAME_OFFSET 0x7fffffff | ||
/* Max # of struct/union/enum members or func args */ | ||
#define BTF_MAX_VLEN 0xffff | ||
|
||
/* The type id is referring to a parent BTF */ | ||
#define BTF_TYPE_PARENT(id) (((id) >> 31) & 0x1) | ||
#define BTF_TYPE_ID(id) ((id) & BTF_MAX_TYPE) | ||
|
||
/* String is in the ELF string section */ | ||
#define BTF_STR_TBL_ELF_ID(ref) (((ref) >> 31) & 0x1) | ||
#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET) | ||
|
||
struct btf_type { | ||
__u32 name; | ||
/* "info" bits arrangement | ||
* bits 0-15: vlen (e.g. # of struct's members) | ||
* bits 16-23: unused | ||
* bits 24-28: kind (e.g. int, ptr, array...etc) | ||
* bits 29-30: unused | ||
* bits 31: root | ||
*/ | ||
__u32 info; | ||
/* "size" is used by INT, ENUM, STRUCT and UNION. | ||
* "size" tells the size of the type it is describing. | ||
* | ||
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST and RESTRICT. | ||
* "type" is a type_id referring to another type. | ||
*/ | ||
union { | ||
__u32 size; | ||
__u32 type; | ||
}; | ||
}; | ||
|
||
#define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f) | ||
#define BTF_INFO_ISROOT(info) (!!(((info) >> 24) & 0x80)) | ||
#define BTF_INFO_VLEN(info) ((info) & 0xffff) | ||
|
||
#define BTF_KIND_UNKN 0 /* Unknown */ | ||
#define BTF_KIND_INT 1 /* Integer */ | ||
#define BTF_KIND_PTR 2 /* Pointer */ | ||
#define BTF_KIND_ARRAY 3 /* Array */ | ||
#define BTF_KIND_STRUCT 4 /* Struct */ | ||
#define BTF_KIND_UNION 5 /* Union */ | ||
#define BTF_KIND_ENUM 6 /* Enumeration */ | ||
#define BTF_KIND_FWD 7 /* Forward */ | ||
#define BTF_KIND_TYPEDEF 8 /* Typedef */ | ||
#define BTF_KIND_VOLATILE 9 /* Volatile */ | ||
#define BTF_KIND_CONST 10 /* Const */ | ||
#define BTF_KIND_RESTRICT 11 /* Restrict */ | ||
#define BTF_KIND_MAX 11 | ||
#define NR_BTF_KINDS 12 | ||
|
||
/* For some specific BTF_KIND, "struct btf_type" is immediately | ||
* followed by extra data. | ||
*/ | ||
|
||
/* BTF_KIND_INT is followed by a u32 and the following | ||
* is the 32 bits arrangement: | ||
*/ | ||
#define BTF_INT_ENCODING(VAL) (((VAL) & 0xff000000) >> 24) | ||
#define BTF_INT_OFFSET(VAL) (((VAL & 0x00ff0000)) >> 16) | ||
#define BTF_INT_BITS(VAL) ((VAL) & 0x0000ffff) | ||
|
||
/* Attributes stored in the BTF_INT_ENCODING */ | ||
#define BTF_INT_SIGNED 0x1 | ||
#define BTF_INT_CHAR 0x2 | ||
#define BTF_INT_BOOL 0x4 | ||
#define BTF_INT_VARARGS 0x8 | ||
|
||
/* BTF_KIND_ENUM is followed by multiple "struct btf_enum". | ||
* The exact number of btf_enum is stored in the vlen (of the | ||
* info in "struct btf_type"). | ||
*/ | ||
struct btf_enum { | ||
__u32 name; | ||
__s32 val; | ||
}; | ||
|
||
/* BTF_KIND_ARRAY is followed by one "struct btf_array" */ | ||
struct btf_array { | ||
__u32 type; | ||
__u32 index_type; | ||
__u32 nelems; | ||
}; | ||
|
||
/* BTF_KIND_STRUCT and BTF_KIND_UNION are followed | ||
* by multiple "struct btf_member". The exact number | ||
* of btf_member is stored in the vlen (of the info in | ||
* "struct btf_type"). | ||
*/ | ||
struct btf_member { | ||
__u32 name; | ||
__u32 type; | ||
__u32 offset; /* offset in bits */ | ||
}; | ||
|
||
#endif /* _UAPI__LINUX_BTF_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.