Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49ef0156 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf updates from Thomas Gleixner:
 "A larger set of perf updates.

  Not all of them are strictly fixes, but that's solely the tip
  maintainers fault as they let the timely -rc1 pull request fall
  through the cracks for various reasons including travel. So I'm
  sending this nevertheless because rebasing and distangling fixes and
  updates would be a mess and risky as well. As of tomorrow, a strict
  fixes separation is happening again. Sorry for the slip-up.

  Kernel:

   - Handle RECORD_MMAP vs. RECORD_MMAP2 correctly so different
     consumers of the mmap event get what they requested.

  Tools:

   - A larger set of updates to perf record/report/scripts vs. time
     stamp handling

   - More Python3 fixups

   - A pile of memory leak plumbing

   - perf BPF improvements and fixes

   - Finalize the perf.data directory storage"

[ Note: the kernel part is strictly a fix, the updates are purely to
  tooling       - Linus ]

* 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (75 commits)
  perf bpf: Show more BPF program info in print_bpf_prog_info()
  perf bpf: Extract logic to create program names from perf_event__synthesize_one_bpf_prog()
  perf tools: Save bpf_prog_info and BTF of new BPF programs
  perf evlist: Introduce side band thread
  perf annotate: Enable annotation of BPF programs
  perf build: Check what binutils's 'disassembler()' signature to use
  perf bpf: Process PERF_BPF_EVENT_PROG_LOAD for annotation
  perf symbols: Introduce DSO_BINARY_TYPE__BPF_PROG_INFO
  perf feature detection: Add -lopcodes to feature-libbfd
  perf top: Add option --no-bpf-event
  perf bpf: Save BTF information as headers to perf.data
  perf bpf: Save BTF in a rbtree in perf_env
  perf bpf: Save bpf_prog_info information as headers to perf.data
  perf bpf: Save bpf_prog_info in a rbtree in perf_env
  perf bpf: Make synthesize_bpf_events() receive perf_session pointer instead of perf_tool
  perf bpf: Synthesize bpf events with bpf_program__get_prog_info_linear()
  bpftool: use bpf_program__get_prog_info_linear() in prog.c:do_dump()
  tools lib bpf: Introduce bpf_program__get_prog_info_linear()
  perf record: Replace option --bpf-event with --no-bpf-event
  perf tests: Fix a memory leak in test__perf_evsel__tp_sched_test()
  ...
parents 19caf581 d8b5297f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7189,6 +7189,7 @@ static void perf_event_mmap_output(struct perf_event *event,
	struct perf_output_handle handle;
	struct perf_sample_data sample;
	int size = mmap_event->event_id.header.size;
	u32 type = mmap_event->event_id.header.type;
	int ret;

	if (!perf_event_mmap_match(event, data))
@@ -7232,6 +7233,7 @@ static void perf_event_mmap_output(struct perf_event *event,
	perf_output_end(&handle);
out:
	mmap_event->event_id.header.size = size;
	mmap_event->event_id.header.type = type;
}

static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
+2 −0
Original line number Diff line number Diff line
@@ -17,5 +17,7 @@

#define __ARCH_WANT_RENAMEAT
#define __ARCH_WANT_NEW_STAT
#define __ARCH_WANT_SET_GET_RLIMIT
#define __ARCH_WANT_TIME32_SYSCALLS

#include <asm-generic/unistd.h>
+59 −207
Original line number Diff line number Diff line
@@ -401,41 +401,31 @@ static int do_show(int argc, char **argv)

static int do_dump(int argc, char **argv)
{
	unsigned int finfo_rec_size, linfo_rec_size, jited_linfo_rec_size;
	void *func_info = NULL, *linfo = NULL, *jited_linfo = NULL;
	unsigned int nr_finfo, nr_linfo = 0, nr_jited_linfo = 0;
	struct bpf_prog_info_linear *info_linear;
	struct bpf_prog_linfo *prog_linfo = NULL;
	unsigned long *func_ksyms = NULL;
	struct bpf_prog_info info = {};
	unsigned int *func_lens = NULL;
	enum {DUMP_JITED, DUMP_XLATED} mode;
	const char *disasm_opt = NULL;
	unsigned int nr_func_ksyms;
	unsigned int nr_func_lens;
	struct bpf_prog_info *info;
	struct dump_data dd = {};
	__u32 len = sizeof(info);
	void *func_info = NULL;
	struct btf *btf = NULL;
	unsigned int buf_size;
	char *filepath = NULL;
	bool opcodes = false;
	bool visual = false;
	char func_sig[1024];
	unsigned char *buf;
	bool linum = false;
	__u32 *member_len;
	__u64 *member_ptr;
	__u32 member_len;
	__u64 arrays;
	ssize_t n;
	int err;
	int fd;

	if (is_prefix(*argv, "jited")) {
		if (disasm_init())
			return -1;

		member_len = &info.jited_prog_len;
		member_ptr = &info.jited_prog_insns;
		mode = DUMP_JITED;
	} else if (is_prefix(*argv, "xlated")) {
		member_len = &info.xlated_prog_len;
		member_ptr = &info.xlated_prog_insns;
		mode = DUMP_XLATED;
	} else {
		p_err("expected 'xlated' or 'jited', got: %s", *argv);
		return -1;
@@ -474,175 +464,50 @@ static int do_dump(int argc, char **argv)
		return -1;
	}

	err = bpf_obj_get_info_by_fd(fd, &info, &len);
	if (err) {
		p_err("can't get prog info: %s", strerror(errno));
		return -1;
	}

	if (!*member_len) {
		p_info("no instructions returned");
		close(fd);
		return 0;
	}

	buf_size = *member_len;

	buf = malloc(buf_size);
	if (!buf) {
		p_err("mem alloc failed");
		close(fd);
		return -1;
	}

	nr_func_ksyms = info.nr_jited_ksyms;
	if (nr_func_ksyms) {
		func_ksyms = malloc(nr_func_ksyms * sizeof(__u64));
		if (!func_ksyms) {
			p_err("mem alloc failed");
			close(fd);
			goto err_free;
		}
	}

	nr_func_lens = info.nr_jited_func_lens;
	if (nr_func_lens) {
		func_lens = malloc(nr_func_lens * sizeof(__u32));
		if (!func_lens) {
			p_err("mem alloc failed");
			close(fd);
			goto err_free;
		}
	}

	nr_finfo = info.nr_func_info;
	finfo_rec_size = info.func_info_rec_size;
	if (nr_finfo && finfo_rec_size) {
		func_info = malloc(nr_finfo * finfo_rec_size);
		if (!func_info) {
			p_err("mem alloc failed");
			close(fd);
			goto err_free;
		}
	}

	linfo_rec_size = info.line_info_rec_size;
	if (info.nr_line_info && linfo_rec_size && info.btf_id) {
		nr_linfo = info.nr_line_info;
		linfo = malloc(nr_linfo * linfo_rec_size);
		if (!linfo) {
			p_err("mem alloc failed");
			close(fd);
			goto err_free;
		}
	}

	jited_linfo_rec_size = info.jited_line_info_rec_size;
	if (info.nr_jited_line_info &&
	    jited_linfo_rec_size &&
	    info.nr_jited_ksyms &&
	    info.nr_jited_func_lens &&
	    info.btf_id) {
		nr_jited_linfo = info.nr_jited_line_info;
		jited_linfo = malloc(nr_jited_linfo * jited_linfo_rec_size);
		if (!jited_linfo) {
			p_err("mem alloc failed");
			close(fd);
			goto err_free;
		}
	}

	memset(&info, 0, sizeof(info));
	if (mode == DUMP_JITED)
		arrays = 1UL << BPF_PROG_INFO_JITED_INSNS;
	else
		arrays = 1UL << BPF_PROG_INFO_XLATED_INSNS;

	*member_ptr = ptr_to_u64(buf);
	*member_len = buf_size;
	info.jited_ksyms = ptr_to_u64(func_ksyms);
	info.nr_jited_ksyms = nr_func_ksyms;
	info.jited_func_lens = ptr_to_u64(func_lens);
	info.nr_jited_func_lens = nr_func_lens;
	info.nr_func_info = nr_finfo;
	info.func_info_rec_size = finfo_rec_size;
	info.func_info = ptr_to_u64(func_info);
	info.nr_line_info = nr_linfo;
	info.line_info_rec_size = linfo_rec_size;
	info.line_info = ptr_to_u64(linfo);
	info.nr_jited_line_info = nr_jited_linfo;
	info.jited_line_info_rec_size = jited_linfo_rec_size;
	info.jited_line_info = ptr_to_u64(jited_linfo);
	arrays |= 1UL << BPF_PROG_INFO_JITED_KSYMS;
	arrays |= 1UL << BPF_PROG_INFO_JITED_FUNC_LENS;
	arrays |= 1UL << BPF_PROG_INFO_FUNC_INFO;
	arrays |= 1UL << BPF_PROG_INFO_LINE_INFO;
	arrays |= 1UL << BPF_PROG_INFO_JITED_LINE_INFO;

	err = bpf_obj_get_info_by_fd(fd, &info, &len);
	info_linear = bpf_program__get_prog_info_linear(fd, arrays);
	close(fd);
	if (err) {
	if (IS_ERR_OR_NULL(info_linear)) {
		p_err("can't get prog info: %s", strerror(errno));
		goto err_free;
	}

	if (*member_len > buf_size) {
		p_err("too many instructions returned");
		goto err_free;
	}

	if (info.nr_jited_ksyms > nr_func_ksyms) {
		p_err("too many addresses returned");
		goto err_free;
	}

	if (info.nr_jited_func_lens > nr_func_lens) {
		p_err("too many values returned");
		goto err_free;
	}

	if (info.nr_func_info != nr_finfo) {
		p_err("incorrect nr_func_info %d vs. expected %d",
		      info.nr_func_info, nr_finfo);
		goto err_free;
	}

	if (info.func_info_rec_size != finfo_rec_size) {
		p_err("incorrect func_info_rec_size %d vs. expected %d",
		      info.func_info_rec_size, finfo_rec_size);
		goto err_free;
	}

	if (linfo && info.nr_line_info != nr_linfo) {
		p_err("incorrect nr_line_info %u vs. expected %u",
		      info.nr_line_info, nr_linfo);
		goto err_free;
	}

	if (info.line_info_rec_size != linfo_rec_size) {
		p_err("incorrect line_info_rec_size %u vs. expected %u",
		      info.line_info_rec_size, linfo_rec_size);
		goto err_free;
	}

	if (jited_linfo && info.nr_jited_line_info != nr_jited_linfo) {
		p_err("incorrect nr_jited_line_info %u vs. expected %u",
		      info.nr_jited_line_info, nr_jited_linfo);
		goto err_free;
		return -1;
	}

	if (info.jited_line_info_rec_size != jited_linfo_rec_size) {
		p_err("incorrect jited_line_info_rec_size %u vs. expected %u",
		      info.jited_line_info_rec_size, jited_linfo_rec_size);
	info = &info_linear->info;
	if (mode == DUMP_JITED) {
		if (info->jited_prog_len == 0) {
			p_info("no instructions returned");
			goto err_free;
		}

	if ((member_len == &info.jited_prog_len &&
	     info.jited_prog_insns == 0) ||
	    (member_len == &info.xlated_prog_len &&
	     info.xlated_prog_insns == 0)) {
		buf = (unsigned char *)(info->jited_prog_insns);
		member_len = info->jited_prog_len;
	} else {	/* DUMP_XLATED */
		if (info->xlated_prog_len == 0) {
			p_err("error retrieving insn dump: kernel.kptr_restrict set?");
			goto err_free;
		}
		buf = (unsigned char *)info->xlated_prog_insns;
		member_len = info->xlated_prog_len;
	}

	if (info.btf_id && btf__get_from_id(info.btf_id, &btf)) {
	if (info->btf_id && btf__get_from_id(info->btf_id, &btf)) {
		p_err("failed to get btf");
		goto err_free;
	}

	if (nr_linfo) {
		prog_linfo = bpf_prog_linfo__new(&info);
	func_info = (void *)info->func_info;

	if (info->nr_line_info) {
		prog_linfo = bpf_prog_linfo__new(info);
		if (!prog_linfo)
			p_info("error in processing bpf_line_info.  continue without it.");
	}
@@ -655,9 +520,9 @@ static int do_dump(int argc, char **argv)
			goto err_free;
		}

		n = write(fd, buf, *member_len);
		n = write(fd, buf, member_len);
		close(fd);
		if (n != *member_len) {
		if (n != member_len) {
			p_err("error writing output file: %s",
			      n < 0 ? strerror(errno) : "short write");
			goto err_free;
@@ -665,19 +530,19 @@ static int do_dump(int argc, char **argv)

		if (json_output)
			jsonw_null(json_wtr);
	} else if (member_len == &info.jited_prog_len) {
	} else if (mode == DUMP_JITED) {
		const char *name = NULL;

		if (info.ifindex) {
			name = ifindex_to_bfd_params(info.ifindex,
						     info.netns_dev,
						     info.netns_ino,
		if (info->ifindex) {
			name = ifindex_to_bfd_params(info->ifindex,
						     info->netns_dev,
						     info->netns_ino,
						     &disasm_opt);
			if (!name)
				goto err_free;
		}

		if (info.nr_jited_func_lens && info.jited_func_lens) {
		if (info->nr_jited_func_lens && info->jited_func_lens) {
			struct kernel_sym *sym = NULL;
			struct bpf_func_info *record;
			char sym_name[SYM_MAX_NAME];
@@ -685,17 +550,16 @@ static int do_dump(int argc, char **argv)
			__u64 *ksyms = NULL;
			__u32 *lens;
			__u32 i;

			if (info.nr_jited_ksyms) {
			if (info->nr_jited_ksyms) {
				kernel_syms_load(&dd);
				ksyms = (__u64 *) info.jited_ksyms;
				ksyms = (__u64 *) info->jited_ksyms;
			}

			if (json_output)
				jsonw_start_array(json_wtr);

			lens = (__u32 *) info.jited_func_lens;
			for (i = 0; i < info.nr_jited_func_lens; i++) {
			lens = (__u32 *) info->jited_func_lens;
			for (i = 0; i < info->nr_jited_func_lens; i++) {
				if (ksyms) {
					sym = kernel_syms_search(&dd, ksyms[i]);
					if (sym)
@@ -707,7 +571,7 @@ static int do_dump(int argc, char **argv)
				}

				if (func_info) {
					record = func_info + i * finfo_rec_size;
					record = func_info + i * info->func_info_rec_size;
					btf_dumper_type_only(btf, record->type_id,
							     func_sig,
							     sizeof(func_sig));
@@ -744,49 +608,37 @@ static int do_dump(int argc, char **argv)
			if (json_output)
				jsonw_end_array(json_wtr);
		} else {
			disasm_print_insn(buf, *member_len, opcodes, name,
			disasm_print_insn(buf, member_len, opcodes, name,
					  disasm_opt, btf, NULL, 0, 0, false);
		}
	} else if (visual) {
		if (json_output)
			jsonw_null(json_wtr);
		else
			dump_xlated_cfg(buf, *member_len);
			dump_xlated_cfg(buf, member_len);
	} else {
		kernel_syms_load(&dd);
		dd.nr_jited_ksyms = info.nr_jited_ksyms;
		dd.jited_ksyms = (__u64 *) info.jited_ksyms;
		dd.nr_jited_ksyms = info->nr_jited_ksyms;
		dd.jited_ksyms = (__u64 *) info->jited_ksyms;
		dd.btf = btf;
		dd.func_info = func_info;
		dd.finfo_rec_size = finfo_rec_size;
		dd.finfo_rec_size = info->func_info_rec_size;
		dd.prog_linfo = prog_linfo;

		if (json_output)
			dump_xlated_json(&dd, buf, *member_len, opcodes,
			dump_xlated_json(&dd, buf, member_len, opcodes,
					 linum);
		else
			dump_xlated_plain(&dd, buf, *member_len, opcodes,
			dump_xlated_plain(&dd, buf, member_len, opcodes,
					  linum);
		kernel_syms_destroy(&dd);
	}

	free(buf);
	free(func_ksyms);
	free(func_lens);
	free(func_info);
	free(linfo);
	free(jited_linfo);
	bpf_prog_linfo__free(prog_linfo);
	free(info_linear);
	return 0;

err_free:
	free(buf);
	free(func_ksyms);
	free(func_lens);
	free(func_info);
	free(linfo);
	free(jited_linfo);
	bpf_prog_linfo__free(prog_linfo);
	free(info_linear);
	return -1;
}

+4 −2
Original line number Diff line number Diff line
@@ -66,7 +66,8 @@ FEATURE_TESTS_BASIC := \
        sched_getcpu			\
        sdt				\
        setns				\
        libaio
        libaio				\
        disassembler-four-args

# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
# of all feature tests
@@ -118,7 +119,8 @@ FEATURE_DISPLAY ?= \
         lzma                   \
         get_cpuid              \
         bpf			\
         libaio
         libaio			\
         disassembler-four-args

# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
# If in the future we need per-feature checks/flags for features not
+5 −0
Original line number Diff line number Diff line
@@ -178,6 +178,10 @@
# include "test-reallocarray.c"
#undef main

#define main main_test_disassembler_four_args
# include "test-disassembler-four-args.c"
#undef main

int main(int argc, char *argv[])
{
	main_test_libpython();
@@ -219,6 +223,7 @@ int main(int argc, char *argv[])
	main_test_setns();
	main_test_libaio();
	main_test_reallocarray();
	main_test_disassembler_four_args();

	return 0;
}
Loading