Commit 93029d7d authored by David S. Miller's avatar David S. Miller
Browse files


Daniel Borkmann says:

====================
bpf-next 2018-11-30

The following pull-request contains BPF updates for your *net-next* tree.

(Getting out bit earlier this time to pull in a dependency from bpf.)

The main changes are:

1) Add libbpf ABI versioning and document API naming conventions
   as well as ABI versioning process, from Andrey.

2) Add a new sk_msg_pop_data() helper for sk_msg based BPF
   programs that is used in conjunction with sk_msg_push_data()
   for adding / removing meta data to the msg data, from John.

3) Optimize convert_bpf_ld_abs() for 0 offset and fix various
   lib and testsuite build failures on 32 bit, from David.

4) Make BPF prog dump for !JIT identical to how we dump subprogs
   when JIT is in use, from Yonghong.

5) Rename btf_get_from_id() to make it more conform with libbpf
   API naming conventions, from Martin.

6) Add a missing BPF kselftest config item, from Naresh.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 3d58c9c9 b4269954
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -299,7 +299,8 @@ struct bpf_prog_aux {
	u32 max_pkt_offset;
	u32 max_pkt_offset;
	u32 stack_depth;
	u32 stack_depth;
	u32 id;
	u32 id;
	u32 func_cnt;
	u32 func_cnt; /* used by non-func prog as the number of func progs */
	u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */
	bool offload_requested;
	bool offload_requested;
	struct bpf_prog **func;
	struct bpf_prog **func;
	void *jit_data; /* JIT specific data. arch dependent */
	void *jit_data; /* JIT specific data. arch dependent */
@@ -317,7 +318,8 @@ struct bpf_prog_aux {
#endif
#endif
	struct bpf_prog_offload *offload;
	struct bpf_prog_offload *offload;
	struct btf *btf;
	struct btf *btf;
	u32 type_id; /* type id for this prog/func */
	struct bpf_func_info *func_info;
	u32 func_info_cnt;
	union {
	union {
		struct work_struct work;
		struct work_struct work;
		struct rcu_head	rcu;
		struct rcu_head	rcu;
+0 −1
Original line number Original line Diff line number Diff line
@@ -204,7 +204,6 @@ static inline bool bpf_verifier_log_needed(const struct bpf_verifier_log *log)
struct bpf_subprog_info {
struct bpf_subprog_info {
	u32 start; /* insn idx of function entry point */
	u32 start; /* insn idx of function entry point */
	u16 stack_depth; /* max. stack depth used by this function */
	u16 stack_depth; /* max. stack depth used by this function */
	u32 type_id; /* btf type_id for this subprog */
};
};


/* single container for all structs
/* single container for all structs
+15 −1
Original line number Original line Diff line number Diff line
@@ -2268,6 +2268,19 @@ union bpf_attr {
 *
 *
 *	Return
 *	Return
 *		0 on success, or a negative error in case of failure.
 *		0 on success, or a negative error in case of failure.
 *
 * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 pop, u64 flags)
 *	 Description
 *		Will remove *pop* bytes from a *msg* starting at byte *start*.
 *		This may result in **ENOMEM** errors under certain situations if
 *		an allocation and copy are required due to a full ring buffer.
 *		However, the helper will try to avoid doing the allocation
 *		if possible. Other errors can occur if input parameters are
 *		invalid either due to *start* byte not being valid part of msg
 *		payload and/or *pop* value being to large.
 *
 *	Return
 *		0 on success, or a negative erro in case of failure.
 */
 */
#define __BPF_FUNC_MAPPER(FN)		\
#define __BPF_FUNC_MAPPER(FN)		\
	FN(unspec),			\
	FN(unspec),			\
@@ -2360,7 +2373,8 @@ union bpf_attr {
	FN(map_push_elem),		\
	FN(map_push_elem),		\
	FN(map_pop_elem),		\
	FN(map_pop_elem),		\
	FN(map_peek_elem),		\
	FN(map_peek_elem),		\
	FN(msg_push_data),
	FN(msg_push_data),		\
	FN(msg_pop_data),


/* integer value in 'imm' field of BPF_CALL instruction selects which helper
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
 * function eBPF program intends to call
 * function eBPF program intends to call
+2 −1
Original line number Original line Diff line number Diff line
@@ -411,7 +411,8 @@ static void bpf_get_prog_name(const struct bpf_prog *prog, char *sym)


	/* prog->aux->name will be ignored if full btf name is available */
	/* prog->aux->name will be ignored if full btf name is available */
	if (prog->aux->btf) {
	if (prog->aux->btf) {
		type = btf_type_by_id(prog->aux->btf, prog->aux->type_id);
		type = btf_type_by_id(prog->aux->btf,
				      prog->aux->func_info[prog->aux->func_idx].type_id);
		func_name = btf_name_by_offset(prog->aux->btf, type->name_off);
		func_name = btf_name_by_offset(prog->aux->btf, type->name_off);
		snprintf(sym, (size_t)(end - sym), "_%s", func_name);
		snprintf(sym, (size_t)(end - sym), "_%s", func_name);
		return;
		return;
+8 −25
Original line number Original line Diff line number Diff line
@@ -1214,6 +1214,7 @@ static void __bpf_prog_put(struct bpf_prog *prog, bool do_idr_lock)
		bpf_prog_free_id(prog, do_idr_lock);
		bpf_prog_free_id(prog, do_idr_lock);
		bpf_prog_kallsyms_del_all(prog);
		bpf_prog_kallsyms_del_all(prog);
		btf_put(prog->aux->btf);
		btf_put(prog->aux->btf);
		kvfree(prog->aux->func_info);


		call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
		call_rcu(&prog->aux->rcu, __bpf_prog_put_rcu);
	}
	}
@@ -2219,46 +2220,28 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
	}
	}


	if (prog->aux->btf) {
	if (prog->aux->btf) {
		u32 krec_size = sizeof(struct bpf_func_info);
		u32 ucnt, urec_size;
		u32 ucnt, urec_size;


		info.btf_id = btf_id(prog->aux->btf);
		info.btf_id = btf_id(prog->aux->btf);


		ucnt = info.func_info_cnt;
		ucnt = info.func_info_cnt;
		info.func_info_cnt = prog->aux->func_cnt ? : 1;
		info.func_info_cnt = prog->aux->func_info_cnt;
		urec_size = info.func_info_rec_size;
		urec_size = info.func_info_rec_size;
		info.func_info_rec_size = sizeof(struct bpf_func_info);
		info.func_info_rec_size = krec_size;
		if (ucnt) {
		if (ucnt) {
			/* expect passed-in urec_size is what the kernel expects */
			/* expect passed-in urec_size is what the kernel expects */
			if (urec_size != info.func_info_rec_size)
			if (urec_size != info.func_info_rec_size)
				return -EINVAL;
				return -EINVAL;


			if (bpf_dump_raw_ok()) {
			if (bpf_dump_raw_ok()) {
				struct bpf_func_info kern_finfo;
				char __user *user_finfo;
				char __user *user_finfo;
				u32 i, insn_offset;


				user_finfo = u64_to_user_ptr(info.func_info);
				user_finfo = u64_to_user_ptr(info.func_info);
				if (prog->aux->func_cnt) {
				ucnt = min_t(u32, info.func_info_cnt, ucnt);
				ucnt = min_t(u32, info.func_info_cnt, ucnt);
					insn_offset = 0;
				if (copy_to_user(user_finfo, prog->aux->func_info,
					for (i = 0; i < ucnt; i++) {
						 krec_size * ucnt))
						kern_finfo.insn_offset = insn_offset;
						kern_finfo.type_id = prog->aux->func[i]->aux->type_id;
						if (copy_to_user(user_finfo, &kern_finfo,
								 sizeof(kern_finfo)))
							return -EFAULT;

						/* func[i]->len holds the prog len */
						insn_offset += prog->aux->func[i]->len;
						user_finfo += urec_size;
					}
				} else {
					kern_finfo.insn_offset = 0;
					kern_finfo.type_id = prog->aux->type_id;
					if (copy_to_user(user_finfo, &kern_finfo,
							 sizeof(kern_finfo)))
					return -EFAULT;
					return -EFAULT;
				}
			} else {
			} else {
				info.func_info_cnt = 0;
				info.func_info_cnt = 0;
			}
			}
Loading