Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions include/asm-generic/vmlinux.lds.h
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
. = ALIGN(PAGE_SIZE); \
.BTF_ids : AT(ADDR(.BTF_ids) - LOAD_OFFSET) { \
*(.BTF_ids) \
} \
. = ALIGN(PAGE_SIZE); \
.BTF.extra : AT(ADDR(.BTF.extra) - LOAD_OFFSET) { \
BOUNDED_SECTION_BY(.BTF.extra, _BTF_extra) \
}
#else
#define BTF
Expand Down
1 change: 1 addition & 0 deletions include/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct inode;
extern struct idr btf_idr;
extern spinlock_t btf_idr_lock;
extern struct kobject *btf_kobj;
extern struct kobject *btf_extra_kobj;
extern struct bpf_mem_alloc bpf_global_ma, bpf_global_percpu_ma;
extern bool bpf_global_ma_set;

Expand Down
31 changes: 30 additions & 1 deletion include/linux/btf.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,33 @@ static inline struct btf_enum64 *btf_enum64(const struct btf_type *t)
return (struct btf_enum64 *)(t + 1);
}

static inline struct btf_loc_param *btf_loc_param(const struct btf_type *t)
{
return (struct btf_loc_param *)(t + 1);
}

static inline __s32 btf_loc_param_size(const struct btf_type *t)
{
return (__s32)t->size;
}

static inline __u64 btf_loc_param_value(const struct btf_type *t)
{
__u32 *v = (__u32 *)(t + 1);

return *v + ((__u64)(*(v + 1)) << 32);
}

static inline __u32 *btf_loc_params(const struct btf_type *t)
{
return (__u32 *)(t + 1);
}

static inline struct btf_loc *btf_type_loc_secinfo(const struct btf_type *t)
{
return (struct btf_loc *)(t + 1);
}

static inline const struct btf_var_secinfo *btf_type_var_secinfo(
const struct btf_type *t)
{
Expand Down Expand Up @@ -552,7 +579,7 @@ struct btf_field_desc {
/* member struct size, or zero, if no members */
int m_sz;
/* repeated per-member offsets */
int m_off_cnt, m_offs[1];
int m_off_cnt, m_offs[2];
};

struct btf_field_iter {
Expand Down Expand Up @@ -594,6 +621,8 @@ int get_kern_ctx_btf_id(struct bpf_verifier_log *log, enum bpf_prog_type prog_ty
bool btf_types_are_same(const struct btf *btf1, u32 id1,
const struct btf *btf2, u32 id2);
int btf_check_iter_arg(struct btf *btf, const struct btf_type *func, int arg_idx);
struct bin_attribute *sysfs_btf_add(struct kobject *kobj, const char *name,
void *data, size_t data_size);

static inline bool btf_type_is_struct_ptr(struct btf *btf, const struct btf_type *t)
{
Expand Down
4 changes: 4 additions & 0 deletions include/linux/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ struct module {
unsigned int btf_base_data_size;
void *btf_data;
void *btf_base_data;
#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_EXTRA)
unsigned int btf_extra_data_size;
void *btf_extra_data;
#endif
#endif
#ifdef CONFIG_JUMP_LABEL
struct jump_entry *jump_entries;
Expand Down
85 changes: 82 additions & 3 deletions include/uapi/linux/btf.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ struct btf_type {
* bits 29-30: unused
* bit 31: kind_flag, currently used by
* struct, union, enum, fwd, enum64,
* decl_tag and type_tag
* decl_tag, type_tag and loc
*/
__u32 info;
/* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64.
/* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC, ENUM64
* and LOC.
*
* "size" tells the size of the type it is describing.
*
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
* FUNC, FUNC_PROTO, VAR, DECL_TAG and TYPE_TAG.
* FUNC, FUNC_PROTO, VAR, DECL_TAG, TYPE_TAG and LOC_PROTO.
* "type" is a type_id referring to another type.
*/
union {
Expand Down Expand Up @@ -78,6 +80,9 @@ enum {
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
BTF_KIND_TYPE_TAG = 18, /* Type Tag */
BTF_KIND_ENUM64 = 19, /* Enumeration up to 64-bit values */
BTF_KIND_LOC_PARAM = 20, /* Location parameter information */
BTF_KIND_LOC_PROTO = 21, /* Location prototype for site */
BTF_KIND_LOCSEC = 22, /* Location section */

NR_BTF_KINDS,
BTF_KIND_MAX = NR_BTF_KINDS - 1,
Expand Down Expand Up @@ -198,4 +203,78 @@ struct btf_enum64 {
__u32 val_hi32;
};

/* BTF_KIND_LOC_PARAM consists a btf_type specifying a vlen of 0, name_off is 0
* and is followed by a singular "struct btf_loc_param". type/size specifies
* the size of the associated location value. The size value should be
* cast to a __s32 as negative sizes can be specified; -8 to indicate a signed
* 8 byte value for example.
*
* If kind_flag is 1 the btf_loc is a constant value, otherwise it represents
* a register, possibly dereferencing it with the specified offset.
*
* "struct btf_type" is followed by a "struct btf_loc_param" which consists
* of either the 64-bit value or the register number, offset etc.
* Interpretation depends on whether the kind_flag is set as described above.
*/

/* BTF_KIND_LOC_PARAM specifies a signed size; negative values represent signed
* values of the specific size, for example -8 is an 8-byte signed value.
*/
#define BTF_TYPE_LOC_PARAM_SIZE(t) ((__s32)((t)->size))

/* location param specified by reg + offset is a dereference */
#define BTF_LOC_FLAG_REG_DEREF 0x1
/* next location param is needed to specify parameter location also; for example
* when two registers are used to store a 16-byte struct by value.
*/
#define BTF_LOC_FLAG_CONTINUE 0x2

struct btf_loc_param {
union {
struct {
__u16 reg; /* register number */
__u16 flags; /* register dereference */
__s32 offset; /* offset from register-stored address */
};
struct {
__u32 val_lo32; /* lo 32 bits of 64-bit value */
__u32 val_hi32; /* hi 32 bits of 64-bit value */
};
};
};

/* BTF_KIND_LOC_PROTO specifies location prototypes; i.e. how locations relate
* to parameters; a struct btf_type of BTF_KIND_LOC_PROTO is followed by a
* a vlen-specified number of __u32 which specify the associated
* BTF_KIND_LOC_PARAM for each function parameter associated with the
* location. The type should either be 0 (no location info) or point at
* a BTF_KIND_LOC_PARAM. Multiple BTF_KIND_LOC_PARAMs can be used to
* represent a single function parameter; in such a case each should specify
* BTF_LOC_FLAG_CONTINUE.
*
* The type field in the associated "struct btf_type" should point at an
* associated BTF_KIND_FUNC_PROTO.
*/

/* BTF_KIND_LOCSEC consists of vlen-specified number of "struct btf_loc"
* containing location site-specific information;
*
* - name associated with the location (name_off)
* - function prototype type id (func_proto)
* - location prototype type id (loc_proto)
* - address offset (offset)
*/

struct btf_loc {
__u32 name_off;
__u32 func_proto;
__u32 loc_proto;
__u32 offset;
};

/* helps libbpf know that location declarations are present; libbpf
* can then work around absence if this value is not set.
*/
#define BTF_KIND_LOC_UAPI_DEFINED 1

#endif /* _UAPI__LINUX_BTF_H__ */
1 change: 1 addition & 0 deletions kernel/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o
endif
ifeq ($(CONFIG_SYSFS),y)
obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o
obj-$(CONFIG_DEBUG_INFO_BTF_EXTRA) += btf_extra.o
endif
ifeq ($(CONFIG_BPF_JIT),y)
obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o
Expand Down
Loading
Loading