Commit 06087114 authored by Daniel Borkmann's avatar Daniel Borkmann
Browse files

Merge branch 'bpf-cleanup-btf-raw-tp'



Alexei Starovoitov says:

====================
v1->v2: addressed Andrii's feedback

When BTF-enabled raw_tp were introduced the plan was to follow up
with BTF-enabled kprobe and kretprobe reusing PROG_RAW_TRACEPOINT
and PROG_KPROBE types. But k[ret]probe expect pt_regs while
BTF-enabled program ctx will be the same as raw_tp.
kretprobe is indistinguishable from kprobe while BTF-enabled
kretprobe will have access to retval while kprobe will not.
Hence PROG_KPROBE type is not reusable and reusing
PROG_RAW_TRACEPOINT no longer fits well.
Hence introduce 'umbrella' prog type BPF_PROG_TYPE_TRACING
that will cover different BTF-enabled tracing attach points.
The changes make libbpf side cleaner as well.
check_attach_btf_id() is cleaner too.
====================

Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents af91acbc 12a8654b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -373,6 +373,11 @@ enum bpf_cgroup_storage_type {

#define MAX_BPF_CGROUP_STORAGE_TYPE __BPF_CGROUP_STORAGE_MAX

/* The longest tracepoint has 12 args.
 * See include/trace/bpf_probe.h
 */
#define MAX_BPF_FUNC_ARGS 12

struct bpf_prog_stats {
	u64 cnt;
	u64 nsecs;
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_TRACEPOINT, tracepoint)
BPF_PROG_TYPE(BPF_PROG_TYPE_PERF_EVENT, perf_event)
BPF_PROG_TYPE(BPF_PROG_TYPE_RAW_TRACEPOINT, raw_tracepoint)
BPF_PROG_TYPE(BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, raw_tracepoint_writable)
BPF_PROG_TYPE(BPF_PROG_TYPE_TRACING, tracing)
#endif
#ifdef CONFIG_CGROUP_BPF
BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_DEVICE, cg_dev)
+2 −0
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ enum bpf_prog_type {
	BPF_PROG_TYPE_CGROUP_SYSCTL,
	BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
	BPF_PROG_TYPE_CGROUP_SOCKOPT,
	BPF_PROG_TYPE_TRACING,
};

enum bpf_attach_type {
@@ -199,6 +200,7 @@ enum bpf_attach_type {
	BPF_CGROUP_UDP6_RECVMSG,
	BPF_CGROUP_GETSOCKOPT,
	BPF_CGROUP_SETSOCKOPT,
	BPF_TRACE_RAW_TP,
	__MAX_BPF_ATTACH_TYPE
};

+3 −3
Original line number Diff line number Diff line
@@ -1571,7 +1571,7 @@ bpf_prog_load_check_attach(enum bpf_prog_type prog_type,
			   u32 btf_id)
{
	switch (prog_type) {
	case BPF_PROG_TYPE_RAW_TRACEPOINT:
	case BPF_PROG_TYPE_TRACING:
		if (btf_id > BTF_MAX_TYPE)
			return -EINVAL;
		break;
@@ -1833,13 +1833,13 @@ static int bpf_raw_tracepoint_open(const union bpf_attr *attr)
		return PTR_ERR(prog);

	if (prog->type != BPF_PROG_TYPE_RAW_TRACEPOINT &&
	    prog->type != BPF_PROG_TYPE_TRACING &&
	    prog->type != BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE) {
		err = -EINVAL;
		goto out_put_prog;
	}

	if (prog->type == BPF_PROG_TYPE_RAW_TRACEPOINT &&
	    prog->aux->attach_btf_id) {
	if (prog->type == BPF_PROG_TYPE_TRACING) {
		if (attr->raw_tracepoint.name) {
			/* raw_tp name should not be specified in raw_tp
			 * programs that were verified via in-kernel BTF info
+24 −10
Original line number Diff line number Diff line
@@ -9381,24 +9381,36 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
{
	struct bpf_prog *prog = env->prog;
	u32 btf_id = prog->aux->attach_btf_id;
	const char prefix[] = "btf_trace_";
	const struct btf_type *t;
	const char *tname;

	if (prog->type == BPF_PROG_TYPE_RAW_TRACEPOINT && btf_id) {
		const char prefix[] = "btf_trace_";
	if (prog->type != BPF_PROG_TYPE_TRACING)
		return 0;

	if (!btf_id) {
		verbose(env, "Tracing programs must provide btf_id\n");
		return -EINVAL;
	}
	t = btf_type_by_id(btf_vmlinux, btf_id);
	if (!t) {
		verbose(env, "attach_btf_id %u is invalid\n", btf_id);
		return -EINVAL;
	}
	tname = btf_name_by_offset(btf_vmlinux, t->name_off);
	if (!tname) {
		verbose(env, "attach_btf_id %u doesn't have a name\n", btf_id);
		return -EINVAL;
	}

	switch (prog->expected_attach_type) {
	case BPF_TRACE_RAW_TP:
		if (!btf_type_is_typedef(t)) {
			verbose(env, "attach_btf_id %u is not a typedef\n",
				btf_id);
			return -EINVAL;
		}
		tname = btf_name_by_offset(btf_vmlinux, t->name_off);
		if (!tname || strncmp(prefix, tname, sizeof(prefix) - 1)) {
		if (strncmp(prefix, tname, sizeof(prefix) - 1)) {
			verbose(env, "attach_btf_id %u points to wrong type name %s\n",
				btf_id, tname);
			return -EINVAL;
@@ -9419,8 +9431,10 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
		prog->aux->attach_func_name = tname;
		prog->aux->attach_func_proto = t;
		prog->aux->attach_btf_trace = true;
	}
		return 0;
	default:
		return -EINVAL;
	}
}

int bpf_check(struct bpf_prog **prog, union bpf_attr *attr,
Loading