--- /dev/null
+From foo@baz Thu 30 Jul 2020 09:36:06 AM CEST
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Tue, 30 Jun 2020 23:45:49 +0900
+Subject: perf annotate: Use asprintf when formatting objdump command line
+To: stable@vger.kernel.org
+Cc: Changbin Du <changbin.du@gmail.com>, Jiri Olsa <jolsa@redhat.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, mhiramat@kernel.org
+Message-ID: <159352834905.45385.1129399396205769928.stgit@devnote2>
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 6810158d526e483868e519befff407b91e76b3db upstream.
+
+We were using a local buffer with an arbitrary size, that would have to
+get increased to avoid truncation as warned by gcc 8:
+
+ util/annotate.c: In function 'symbol__disassemble':
+ util/annotate.c:1488:4: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 3966 and 8086 [-Werror=format-truncation=]
+ "%s %s%s --start-address=0x%016" PRIx64
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ util/annotate.c:1498:20:
+ symfs_filename, symfs_filename);
+ ~~~~~~~~~~~~~~
+ util/annotate.c:1490:50: note: format string is defined here
+ " -l -d %s %s -C \"%s\" 2>/dev/null|grep -v \"%s:\"|expand",
+ ^~
+ In file included from /usr/include/stdio.h:861,
+ from util/color.h:5,
+ from util/sort.h:8,
+ from util/annotate.c:14:
+ /usr/include/bits/stdio2.h:67:10: note: '__builtin___snprintf_chk' output 116 or more bytes (assuming 8331) into a destination of size 8192
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+So switch to asprintf, that will make sure enough space is available.
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jin Yao <yao.jin@linux.intel.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: https://lkml.kernel.org/n/tip-qagoy2dmbjpc9gdnaj0r3mml@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/perf/util/annotate.c | 17 ++++++++++++-----
+ 1 file changed, 12 insertions(+), 5 deletions(-)
+
+--- a/tools/perf/util/annotate.c
++++ b/tools/perf/util/annotate.c
+@@ -1302,7 +1302,7 @@ fallback:
+ int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize)
+ {
+ struct dso *dso = map->dso;
+- char command[PATH_MAX * 2];
++ char *command;
+ FILE *file;
+ char symfs_filename[PATH_MAX];
+ struct kcore_extract kce;
+@@ -1364,7 +1364,7 @@ int symbol__disassemble(struct symbol *s
+ strcpy(symfs_filename, tmp);
+ }
+
+- snprintf(command, sizeof(command),
++ err = asprintf(&command,
+ "%s %s%s --start-address=0x%016" PRIx64
+ " --stop-address=0x%016" PRIx64
+ " -l -d %s %s -C %s 2>/dev/null|grep -v %s|expand",
+@@ -1377,12 +1377,17 @@ int symbol__disassemble(struct symbol *s
+ symbol_conf.annotate_src ? "-S" : "",
+ symfs_filename, symfs_filename);
+
++ if (err < 0) {
++ pr_err("Failure allocating memory for the command to run\n");
++ goto out_remove_tmp;
++ }
++
+ pr_debug("Executing: %s\n", command);
+
+ err = -1;
+ if (pipe(stdout_fd) < 0) {
+ pr_err("Failure creating the pipe to run %s\n", command);
+- goto out_remove_tmp;
++ goto out_free_command;
+ }
+
+ pid = fork();
+@@ -1409,7 +1414,7 @@ int symbol__disassemble(struct symbol *s
+ * If we were using debug info should retry with
+ * original binary.
+ */
+- goto out_remove_tmp;
++ goto out_free_command;
+ }
+
+ nline = 0;
+@@ -1432,6 +1437,8 @@ int symbol__disassemble(struct symbol *s
+
+ fclose(file);
+ err = 0;
++out_free_command:
++ free(command);
+ out_remove_tmp:
+ close(stdout_fd[0]);
+
+@@ -1445,7 +1452,7 @@ out:
+
+ out_close_stdout:
+ close(stdout_fd[1]);
+- goto out_remove_tmp;
++ goto out_free_command;
+ }
+
+ static void insert_source_line(struct rb_root *root, struct source_line *src_line)
--- /dev/null
+From foo@baz Thu 30 Jul 2020 09:36:06 AM CEST
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Tue, 30 Jun 2020 23:46:07 +0900
+Subject: perf: Make perf able to build with latest libbfd
+To: stable@vger.kernel.org
+Cc: Changbin Du <changbin.du@gmail.com>, Jiri Olsa <jolsa@redhat.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, mhiramat@kernel.org
+Message-ID: <159352836699.45385.3033296707456805894.stgit@devnote2>
+
+From: Changbin Du <changbin.du@gmail.com>
+
+commit 0ada120c883d4f1f6aafd01cf0fbb10d8bbba015 upstream.
+
+libbfd has changed the bfd_section_* macros to inline functions
+bfd_section_<field> since 2019-09-18. See below two commits:
+ o http://www.sourceware.org/ml/gdb-cvs/2019-09/msg00064.html
+ o https://www.sourceware.org/ml/gdb-cvs/2019-09/msg00072.html
+
+This fix make perf able to build with both old and new libbfd.
+
+Signed-off-by: Changbin Du <changbin.du@gmail.com>
+Acked-by: Jiri Olsa <jolsa@redhat.com>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Link: http://lore.kernel.org/lkml/20200128152938.31413-1-changbin.du@gmail.com
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/perf/util/srcline.c | 16 +++++++++++++++-
+ 1 file changed, 15 insertions(+), 1 deletion(-)
+
+--- a/tools/perf/util/srcline.c
++++ b/tools/perf/util/srcline.c
+@@ -86,16 +86,30 @@ static void find_address_in_section(bfd
+ bfd_vma pc, vma;
+ bfd_size_type size;
+ struct a2l_data *a2l = data;
++ flagword flags;
+
+ if (a2l->found)
+ return;
+
+- if ((bfd_get_section_flags(abfd, section) & SEC_ALLOC) == 0)
++#ifdef bfd_get_section_flags
++ flags = bfd_get_section_flags(abfd, section);
++#else
++ flags = bfd_section_flags(section);
++#endif
++ if ((flags & SEC_ALLOC) == 0)
+ return;
+
+ pc = a2l->addr;
++#ifdef bfd_get_section_vma
+ vma = bfd_get_section_vma(abfd, section);
++#else
++ vma = bfd_section_vma(section);
++#endif
++#ifdef bfd_get_section_size
+ size = bfd_get_section_size(section);
++#else
++ size = bfd_section_size(section);
++#endif
+
+ if (pc < vma || pc >= vma + size)
+ return;
--- /dev/null
+From foo@baz Thu 30 Jul 2020 09:36:06 AM CEST
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Tue, 30 Jun 2020 23:45:40 +0900
+Subject: perf probe: Fix to check blacklist address correctly
+To: stable@vger.kernel.org
+Cc: Changbin Du <changbin.du@gmail.com>, Jiri Olsa <jolsa@redhat.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, mhiramat@kernel.org
+Message-ID: <159352834007.45385.3483905196357537826.stgit@devnote2>
+
+From: Masami Hiramatsu <mhiramat@kernel.org>
+
+commit 80526491c2ca6abc028c0f0dbb0707a1f35fb18a upstream.
+
+Fix to check kprobe blacklist address correctly with relocated address
+by adjusting debuginfo address.
+
+Since the address in the debuginfo is same as objdump, it is different
+from relocated kernel address with KASLR. Thus, 'perf probe' always
+misses to catch the blacklisted addresses.
+
+Without this patch, 'perf probe' can not detect the blacklist addresses
+on a KASLR enabled kernel.
+
+ # perf probe kprobe_dispatcher
+ Failed to write event: Invalid argument
+ Error: Failed to add events.
+ #
+
+With this patch, it correctly shows the error message.
+
+ # perf probe kprobe_dispatcher
+ kprobe_dispatcher is blacklisted function, skip it.
+ Probe point 'kprobe_dispatcher' not found.
+ Error: Failed to add events.
+ #
+
+Fixes: 9aaf5a5f479b ("perf probe: Check kprobes blacklist when adding new events")
+Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
+Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: stable@vger.kernel.org
+Link: http://lore.kernel.org/lkml/158763966411.30755.5882376357738273695.stgit@devnote2
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/perf/util/probe-event.c | 21 +++++++++++++++------
+ 1 file changed, 15 insertions(+), 6 deletions(-)
+
+--- a/tools/perf/util/probe-event.c
++++ b/tools/perf/util/probe-event.c
+@@ -118,7 +118,7 @@ static struct symbol *__find_kernel_func
+ return machine__find_kernel_function(host_machine, addr, mapp);
+ }
+
+-static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void)
++static struct ref_reloc_sym *kernel_get_ref_reloc_sym(struct map **pmap)
+ {
+ /* kmap->ref_reloc_sym should be set if host_machine is initialized */
+ struct kmap *kmap;
+@@ -130,6 +130,10 @@ static struct ref_reloc_sym *kernel_get_
+ kmap = map__kmap(map);
+ if (!kmap)
+ return NULL;
++
++ if (pmap)
++ *pmap = map;
++
+ return kmap->ref_reloc_sym;
+ }
+
+@@ -141,7 +145,7 @@ static int kernel_get_symbol_address_by_
+ struct map *map;
+
+ /* ref_reloc_sym is just a label. Need a special fix*/
+- reloc_sym = kernel_get_ref_reloc_sym();
++ reloc_sym = kernel_get_ref_reloc_sym(NULL);
+ if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
+ *addr = (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr;
+ else {
+@@ -742,6 +746,7 @@ post_process_kernel_probe_trace_events(s
+ int ntevs)
+ {
+ struct ref_reloc_sym *reloc_sym;
++ struct map *map;
+ char *tmp;
+ int i, skipped = 0;
+
+@@ -750,7 +755,7 @@ post_process_kernel_probe_trace_events(s
+ return post_process_offline_probe_trace_events(tevs, ntevs,
+ symbol_conf.vmlinux_name);
+
+- reloc_sym = kernel_get_ref_reloc_sym();
++ reloc_sym = kernel_get_ref_reloc_sym(&map);
+ if (!reloc_sym) {
+ pr_warning("Relocated base symbol is not found!\n");
+ return -EINVAL;
+@@ -759,9 +764,13 @@ post_process_kernel_probe_trace_events(s
+ for (i = 0; i < ntevs; i++) {
+ if (!tevs[i].point.address || tevs[i].point.retprobe)
+ continue;
+- /* If we found a wrong one, mark it by NULL symbol */
++ /*
++ * If we found a wrong one, mark it by NULL symbol.
++ * Since addresses in debuginfo is same as objdump, we need
++ * to convert it to addresses on memory.
++ */
+ if (kprobe_warn_out_range(tevs[i].point.symbol,
+- tevs[i].point.address)) {
++ map__objdump_2mem(map, tevs[i].point.address))) {
+ tmp = NULL;
+ skipped++;
+ } else {
+@@ -2850,7 +2859,7 @@ static int find_probe_trace_events_from_
+
+ /* Note that the symbols in the kmodule are not relocated */
+ if (!pev->uprobes && !pp->retprobe && !pev->target) {
+- reloc_sym = kernel_get_ref_reloc_sym();
++ reloc_sym = kernel_get_ref_reloc_sym(NULL);
+ if (!reloc_sym) {
+ pr_warning("Relocated base symbol is not found!\n");
+ ret = -EINVAL;
--- /dev/null
+From foo@baz Thu 30 Jul 2020 09:36:06 AM CEST
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Tue, 30 Jun 2020 23:45:58 +0900
+Subject: perf tools: Fix snprint warnings for gcc 8
+To: stable@vger.kernel.org
+Cc: Changbin Du <changbin.du@gmail.com>, Jiri Olsa <jolsa@redhat.com>, Arnaldo Carvalho de Melo <acme@redhat.com>, mhiramat@kernel.org
+Message-ID: <159352835807.45385.17785754791011271503.stgit@devnote2>
+
+From: Jiri Olsa <jolsa@kernel.org>
+
+commit 77f18153c080855e1c3fb520ca31a4e61530121d upstream.
+
+[Add an additional sprintf replacement in tools/perf/builtin-script.c]
+
+With gcc 8 we get new set of snprintf() warnings that breaks the
+compilation, one example:
+
+ tests/mem.c: In function ‘check’:
+ tests/mem.c:19:48: error: ‘%s’ directive output may be truncated writing \
+ up to 99 bytes into a region of size 89 [-Werror=format-truncation=]
+ snprintf(failure, sizeof failure, "unexpected %s", out);
+
+The gcc docs says:
+
+ To avoid the warning either use a bigger buffer or handle the
+ function's return value which indicates whether or not its output
+ has been truncated.
+
+Given that all these warnings are harmless, because the code either
+properly fails due to uncomplete file path or we don't care for
+truncated output at all, I'm changing all those snprintf() calls to
+scnprintf(), which actually 'checks' for the snprint return value so the
+gcc stays silent.
+
+Signed-off-by: Jiri Olsa <jolsa@kernel.org>
+Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Josh Poimboeuf <jpoimboe@redhat.com>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
+Link: http://lkml.kernel.org/r/20180319082902.4518-1-jolsa@kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ tools/perf/builtin-script.c | 24 ++++++++++++------------
+ tools/perf/tests/attr.c | 4 ++--
+ tools/perf/tests/pmu.c | 2 +-
+ tools/perf/util/cgroup.c | 2 +-
+ tools/perf/util/parse-events.c | 4 ++--
+ tools/perf/util/pmu.c | 2 +-
+ 6 files changed, 19 insertions(+), 19 deletions(-)
+
+--- a/tools/perf/builtin-script.c
++++ b/tools/perf/builtin-script.c
+@@ -1516,7 +1516,7 @@ static int is_directory(const char *base
+ char path[PATH_MAX];
+ struct stat st;
+
+- sprintf(path, "%s/%s", base_path, dent->d_name);
++ scnprintf(path, PATH_MAX, "%s/%s", base_path, dent->d_name);
+ if (stat(path, &st))
+ return 0;
+
+@@ -1702,8 +1702,8 @@ static int list_available_scripts(const
+ }
+
+ for_each_lang(scripts_path, scripts_dir, lang_dirent) {
+- snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+- lang_dirent->d_name);
++ scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
++ lang_dirent->d_name);
+ lang_dir = opendir(lang_path);
+ if (!lang_dir)
+ continue;
+@@ -1712,8 +1712,8 @@ static int list_available_scripts(const
+ script_root = get_script_root(script_dirent, REPORT_SUFFIX);
+ if (script_root) {
+ desc = script_desc__findnew(script_root);
+- snprintf(script_path, MAXPATHLEN, "%s/%s",
+- lang_path, script_dirent->d_name);
++ scnprintf(script_path, MAXPATHLEN, "%s/%s",
++ lang_path, script_dirent->d_name);
+ read_script_info(desc, script_path);
+ free(script_root);
+ }
+@@ -1749,7 +1749,7 @@ static int check_ev_match(char *dir_name
+ int match, len;
+ FILE *fp;
+
+- sprintf(filename, "%s/bin/%s-record", dir_name, scriptname);
++ scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname);
+
+ fp = fopen(filename, "r");
+ if (!fp)
+@@ -1825,8 +1825,8 @@ int find_scripts(char **scripts_array, c
+ }
+
+ for_each_lang(scripts_path, scripts_dir, lang_dirent) {
+- snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+- lang_dirent->d_name);
++ scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
++ lang_dirent->d_name);
+ #ifdef NO_LIBPERL
+ if (strstr(lang_path, "perl"))
+ continue;
+@@ -1881,8 +1881,8 @@ static char *get_script_path(const char
+ return NULL;
+
+ for_each_lang(scripts_path, scripts_dir, lang_dirent) {
+- snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+- lang_dirent->d_name);
++ scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
++ lang_dirent->d_name);
+ lang_dir = opendir(lang_path);
+ if (!lang_dir)
+ continue;
+@@ -1893,8 +1893,8 @@ static char *get_script_path(const char
+ free(__script_root);
+ closedir(lang_dir);
+ closedir(scripts_dir);
+- snprintf(script_path, MAXPATHLEN, "%s/%s",
+- lang_path, script_dirent->d_name);
++ scnprintf(script_path, MAXPATHLEN, "%s/%s",
++ lang_path, script_dirent->d_name);
+ return strdup(script_path);
+ }
+ free(__script_root);
+--- a/tools/perf/tests/attr.c
++++ b/tools/perf/tests/attr.c
+@@ -147,8 +147,8 @@ static int run_dir(const char *d, const
+ if (verbose)
+ vcnt++;
+
+- snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
+- d, d, perf, vcnt, v);
++ scnprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
++ d, d, perf, vcnt, v);
+
+ return system(cmd) ? TEST_FAIL : TEST_OK;
+ }
+--- a/tools/perf/tests/pmu.c
++++ b/tools/perf/tests/pmu.c
+@@ -95,7 +95,7 @@ static char *test_format_dir_get(void)
+ struct test_format *format = &test_formats[i];
+ FILE *file;
+
+- snprintf(name, PATH_MAX, "%s/%s", dir, format->name);
++ scnprintf(name, PATH_MAX, "%s/%s", dir, format->name);
+
+ file = fopen(name, "w");
+ if (!file)
+--- a/tools/perf/util/cgroup.c
++++ b/tools/perf/util/cgroup.c
+@@ -64,7 +64,7 @@ static int open_cgroup(char *name)
+ if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1))
+ return -1;
+
+- snprintf(path, PATH_MAX, "%s/%s", mnt, name);
++ scnprintf(path, PATH_MAX, "%s/%s", mnt, name);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1)
+--- a/tools/perf/util/parse-events.c
++++ b/tools/perf/util/parse-events.c
+@@ -195,8 +195,8 @@ struct tracepoint_path *tracepoint_id_to
+
+ for_each_event(sys_dirent, evt_dir, evt_dirent) {
+
+- snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
+- evt_dirent->d_name);
++ scnprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
++ evt_dirent->d_name);
+ fd = open(evt_path, O_RDONLY);
+ if (fd < 0)
+ continue;
+--- a/tools/perf/util/pmu.c
++++ b/tools/perf/util/pmu.c
+@@ -325,7 +325,7 @@ static int pmu_aliases_parse(char *dir,
+ if (pmu_alias_info_file(name))
+ continue;
+
+- snprintf(path, PATH_MAX, "%s/%s", dir, name);
++ scnprintf(path, PATH_MAX, "%s/%s", dir, name);
+
+ file = fopen(path, "r");
+ if (!file) {
drivers-net-wan-x25_asy-fix-to-make-it-work.patch
regmap-debugfs-check-count-when-read-regmap-file.patch
xfs-set-format-back-to-extents-if-xfs_bmap_extents_to_btree.patch
+perf-probe-fix-to-check-blacklist-address-correctly.patch
+perf-annotate-use-asprintf-when-formatting-objdump-command-line.patch
+perf-tools-fix-snprint-warnings-for-gcc-8.patch
+perf-make-perf-able-to-build-with-latest-libbfd.patch