--- /dev/null
+From f77af15165847406b15d8f70c382c4cb15846b2a Mon Sep 17 00:00:00 2001
+From: Josh Zimmerman <joshz@google.com>
+Date: Sun, 25 Jun 2017 14:53:23 -0700
+Subject: Add "shutdown" to "struct class".
+
+From: Josh Zimmerman <joshz@google.com>
+
+commit f77af15165847406b15d8f70c382c4cb15846b2a upstream.
+
+The TPM class has some common shutdown code that must be executed for
+all drivers. This adds some needed functionality for that.
+
+Signed-off-by: Josh Zimmerman <joshz@google.com>
+Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+Fixes: 74d6b3ceaa17 ("tpm: fix suspend/resume paths for TPM 2.0")
+Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Signed-off-by: James Morris <james.l.morris@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/base/core.c | 6 +++++-
+ include/linux/device.h | 2 ++
+ 2 files changed, 7 insertions(+), 1 deletion(-)
+
+--- a/drivers/base/core.c
++++ b/drivers/base/core.c
+@@ -2095,7 +2095,11 @@ void device_shutdown(void)
+ pm_runtime_get_noresume(dev);
+ pm_runtime_barrier(dev);
+
+- if (dev->bus && dev->bus->shutdown) {
++ if (dev->class && dev->class->shutdown) {
++ if (initcall_debug)
++ dev_info(dev, "shutdown\n");
++ dev->class->shutdown(dev);
++ } else if (dev->bus && dev->bus->shutdown) {
+ if (initcall_debug)
+ dev_info(dev, "shutdown\n");
+ dev->bus->shutdown(dev);
+--- a/include/linux/device.h
++++ b/include/linux/device.h
+@@ -373,6 +373,7 @@ int subsys_virtual_register(struct bus_t
+ * @suspend: Used to put the device to sleep mode, usually to a low power
+ * state.
+ * @resume: Used to bring the device from the sleep mode.
++ * @shutdown: Called at shut-down time to quiesce the device.
+ * @ns_type: Callbacks so sysfs can detemine namespaces.
+ * @namespace: Namespace of the device belongs to this class.
+ * @pm: The default device power management operations of this class.
+@@ -401,6 +402,7 @@ struct class {
+
+ int (*suspend)(struct device *dev, pm_message_t state);
+ int (*resume)(struct device *dev);
++ int (*shutdown)(struct device *dev);
+
+ const struct kobj_ns_type_operations *ns_type;
+ const void *(*namespace)(struct device *dev);
--- /dev/null
+From 3aff8ba0a4c9c9191bb788171a1c54778e1246a2 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 9 Feb 2017 14:39:42 -0300
+Subject: perf bench numa: Avoid possible truncation when using snprintf()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 3aff8ba0a4c9c9191bb788171a1c54778e1246a2 upstream.
+
+Addressing this warning from gcc 7:
+
+ CC /tmp/build/perf/bench/numa.o
+ bench/numa.c: In function '__bench_numa':
+ bench/numa.c:1582:42: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size between 8 and 17 [-Werror=format-truncation=]
+ snprintf(tname, 32, "process%d:thread%d", p, t);
+ ^~
+ bench/numa.c:1582:25: note: directive argument in the range [0, 2147483647]
+ snprintf(tname, 32, "process%d:thread%d", p, t);
+ ^~~~~~~~~~~~~~~~~~~~
+ In file included from /usr/include/stdio.h:939:0,
+ from bench/../util/util.h:47,
+ from bench/../builtin.h:4,
+ from bench/numa.c:11:
+ /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 17 and 35 bytes into a destination of size 32
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ cc1: all warnings being treated as errors
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Petr Holasek <pholasek@redhat.com>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-twa37vsfqcie5gwpqwnjuuz9@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/bench/numa.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/tools/perf/bench/numa.c
++++ b/tools/perf/bench/numa.c
+@@ -1573,13 +1573,13 @@ static int __bench_numa(const char *name
+ "GB/sec,", "total-speed", "GB/sec total speed");
+
+ if (g->p.show_details >= 2) {
+- char tname[32];
++ char tname[14 + 2 * 10 + 1];
+ struct thread_data *td;
+ for (p = 0; p < g->p.nr_proc; p++) {
+ for (t = 0; t < g->p.nr_threads; t++) {
+- memset(tname, 0, 32);
++ memset(tname, 0, sizeof(tname));
+ td = g->threads + p*g->p.nr_threads + t;
+- snprintf(tname, 32, "process%d:thread%d", p, t);
++ snprintf(tname, sizeof(tname), "process%d:thread%d", p, t);
+ print_res(tname, td->speed_gbs,
+ "GB/sec", "thread-speed", "GB/sec/thread speed");
+ print_res(tname, td->system_time_ns / NSEC_PER_SEC,
--- /dev/null
+From 8434a2ec13d5c8cb25716950bfbf7c9d7b64628a Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 21:57:22 -0300
+Subject: perf header: Fix handling of PERF_EVENT_UPDATE__SCALE
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 8434a2ec13d5c8cb25716950bfbf7c9d7b64628a upstream.
+
+In commit daeecbc0c431 ("perf tools: Add event_update event scale type"), the
+handling of PERF_EVENT_UPDATE__SCALE cast struct event_update_event->data to a
+pointer to event_update_event_scale, uses some field from this casted struct
+and then ends up falling through to the handling of another event type,
+PERF_EVENT_UPDATE__CPUS were it casts that ev->data to yet another type, oops,
+fix it by inserting the missing break.
+
+Noticed when building perf using gcc 7 on Fedora Rawhide:
+
+ util/header.c: In function 'perf_event__process_event_update':
+ util/header.c:3207:16: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ evsel->scale = ev_scale->scale;
+ ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
+ util/header.c:3208:2: note: here
+ case PERF_EVENT_UPDATE__CPUS:
+ ^~~~
+
+This wasn't noticed because probably PERF_EVENT_UPDATE__CPUS comes after
+PERF_EVENT_UPDATE__SCALE, so we would just create a bogus evsel->own_cpus when
+processing a PERF_EVENT_UPDATE__SCALE to then leak it and create a new cpu map
+with the correct data.
+
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Kan Liang <kan.liang@intel.com>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
+Fixes: daeecbc0c431 ("perf tools: Add event_update event scale type")
+Link: http://lkml.kernel.org/n/tip-lukcf9hdj092ax2914ss95at@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/header.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/tools/perf/util/header.c
++++ b/tools/perf/util/header.c
+@@ -3184,6 +3184,7 @@ int perf_event__process_event_update(str
+ case PERF_EVENT_UPDATE__SCALE:
+ ev_scale = (struct event_update_event_scale *) ev->data;
+ evsel->scale = ev_scale->scale;
++ break;
+ case PERF_EVENT_UPDATE__CPUS:
+ ev_cpus = (struct event_update_event_cpus *) ev->data;
+
--- /dev/null
+From 7ea6856d6f5629d742edc23b8b76e6263371ef45 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 9 Feb 2017 15:22:22 -0300
+Subject: perf intel-pt: Use __fallthrough
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 7ea6856d6f5629d742edc23b8b76e6263371ef45 upstream.
+
+To address new warnings emmited by gcc 7, e.g.::
+
+ CC /tmp/build/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.o
+ CC /tmp/build/perf/tests/parse-events.o
+ util/intel-pt-decoder/intel-pt-pkt-decoder.c: In function 'intel_pt_pkt_desc':
+ util/intel-pt-decoder/intel-pt-pkt-decoder.c:499:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (!(packet->count))
+ ^
+ util/intel-pt-decoder/intel-pt-pkt-decoder.c:501:2: note: here
+ case INTEL_PT_CYC:
+ ^~~~
+ CC /tmp/build/perf/util/intel-pt-decoder/intel-pt-decoder.o
+ cc1: all warnings being treated as errors
+
+Acked-by: Andi Kleen <ak@linux.intel.com>
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-mf0hw789pu9x855us5l32c83@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/intel-pt-decoder/intel-pt-decoder.c | 5 +++++
+ tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c | 2 ++
+ 2 files changed, 7 insertions(+)
+
+--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+@@ -22,6 +22,7 @@
+ #include <errno.h>
+ #include <stdint.h>
+ #include <inttypes.h>
++#include <linux/compiler.h>
+
+ #include "../cache.h"
+ #include "../util.h"
+@@ -1744,6 +1745,7 @@ static int intel_pt_walk_psb(struct inte
+ switch (decoder->packet.type) {
+ case INTEL_PT_TIP_PGD:
+ decoder->continuous_period = false;
++ __fallthrough;
+ case INTEL_PT_TIP_PGE:
+ case INTEL_PT_TIP:
+ intel_pt_log("ERROR: Unexpected packet\n");
+@@ -1797,6 +1799,8 @@ static int intel_pt_walk_psb(struct inte
+ decoder->pge = false;
+ decoder->continuous_period = false;
+ intel_pt_clear_tx_flags(decoder);
++ __fallthrough;
++
+ case INTEL_PT_TNT:
+ decoder->have_tma = false;
+ intel_pt_log("ERROR: Unexpected packet\n");
+@@ -1837,6 +1841,7 @@ static int intel_pt_walk_to_ip(struct in
+ switch (decoder->packet.type) {
+ case INTEL_PT_TIP_PGD:
+ decoder->continuous_period = false;
++ __fallthrough;
+ case INTEL_PT_TIP_PGE:
+ case INTEL_PT_TIP:
+ decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD;
+--- a/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
++++ b/tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c
+@@ -17,6 +17,7 @@
+ #include <string.h>
+ #include <endian.h>
+ #include <byteswap.h>
++#include <linux/compiler.h>
+
+ #include "intel-pt-pkt-decoder.h"
+
+@@ -498,6 +499,7 @@ int intel_pt_pkt_desc(const struct intel
+ case INTEL_PT_FUP:
+ if (!(packet->count))
+ return snprintf(buf, buf_len, "%s no ip", name);
++ __fallthrough;
+ case INTEL_PT_CYC:
+ case INTEL_PT_VMCS:
+ case INTEL_PT_MTC:
--- /dev/null
+From 3e96dac7c956089d3f23aca98c4dfca57b6aaf8a Mon Sep 17 00:00:00 2001
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Wed, 11 Jan 2017 15:00:47 +0900
+Subject: perf probe: Add error checks to offline probe post-processing
+
+From: Masami Hiramatsu <mhiramat@kernel.org>
+
+commit 3e96dac7c956089d3f23aca98c4dfca57b6aaf8a upstream.
+
+Add error check codes on post processing and improve it for offline
+probe events as:
+
+ - post processing fails if no matched symbol found in map(-ENOENT)
+ or strdup() failed(-ENOMEM).
+
+ - Even if the symbol name is the same, it updates symbol address
+ and offset.
+
+Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
+Cc: Jiri Olsa <jolsa@redhat.com>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Link: http://lkml.kernel.org/r/148411443738.9978.4617979132625405545.stgit@devbox
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Krister Johansen <kjlx@templeofstupid.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/probe-event.c | 50 +++++++++++++++++++++++++++---------------
+ 1 file changed, 33 insertions(+), 17 deletions(-)
+
+--- a/tools/perf/util/probe-event.c
++++ b/tools/perf/util/probe-event.c
+@@ -618,6 +618,33 @@ error:
+ return ret ? : -ENOENT;
+ }
+
++/* Adjust symbol name and address */
++static int post_process_probe_trace_point(struct probe_trace_point *tp,
++ struct map *map, unsigned long offs)
++{
++ struct symbol *sym;
++ u64 addr = tp->address + tp->offset - offs;
++
++ sym = map__find_symbol(map, addr);
++ if (!sym)
++ return -ENOENT;
++
++ if (strcmp(sym->name, tp->symbol)) {
++ /* If we have no realname, use symbol for it */
++ if (!tp->realname)
++ tp->realname = tp->symbol;
++ else
++ free(tp->symbol);
++ tp->symbol = strdup(sym->name);
++ if (!tp->symbol)
++ return -ENOMEM;
++ }
++ tp->offset = addr - sym->start;
++ tp->address -= offs;
++
++ return 0;
++}
++
+ /*
+ * Rename DWARF symbols to ELF symbols -- gcc sometimes optimizes functions
+ * and generate new symbols with suffixes such as .constprop.N or .isra.N
+@@ -630,11 +657,9 @@ static int
+ post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
+ int ntevs, const char *pathname)
+ {
+- struct symbol *sym;
+ struct map *map;
+ unsigned long stext = 0;
+- u64 addr;
+- int i;
++ int i, ret = 0;
+
+ /* Prepare a map for offline binary */
+ map = dso__new_map(pathname);
+@@ -644,23 +669,14 @@ post_process_offline_probe_trace_events(
+ }
+
+ for (i = 0; i < ntevs; i++) {
+- addr = tevs[i].point.address + tevs[i].point.offset - stext;
+- sym = map__find_symbol(map, addr);
+- if (!sym)
+- continue;
+- if (!strcmp(sym->name, tevs[i].point.symbol))
+- continue;
+- /* If we have no realname, use symbol for it */
+- if (!tevs[i].point.realname)
+- tevs[i].point.realname = tevs[i].point.symbol;
+- else
+- free(tevs[i].point.symbol);
+- tevs[i].point.symbol = strdup(sym->name);
+- tevs[i].point.offset = addr - sym->start;
++ ret = post_process_probe_trace_point(&tevs[i].point,
++ map, stext);
++ if (ret < 0)
++ break;
+ }
+ map__put(map);
+
+- return 0;
++ return ret;
+ }
+
+ static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
--- /dev/null
+From 8a937a25a7e3c19d5fb3f9d92f605cf5fda219d8 Mon Sep 17 00:00:00 2001
+From: Masami Hiramatsu <mhiramat@kernel.org>
+Date: Wed, 4 Jan 2017 12:30:19 +0900
+Subject: perf probe: Fix to probe on gcc generated symbols for offline kernel
+
+From: Masami Hiramatsu <mhiramat@kernel.org>
+
+commit 8a937a25a7e3c19d5fb3f9d92f605cf5fda219d8 upstream.
+
+Fix perf-probe to show probe definition on gcc generated symbols for
+offline kernel (including cross-arch kernel image).
+
+gcc sometimes optimizes functions and generate new symbols with suffixes
+such as ".constprop.N" or ".isra.N" etc. Since those symbol names are
+not recorded in DWARF, we have to find correct generated symbols from
+offline ELF binary to probe on it (kallsyms doesn't correct it). For
+online kernel or uprobes we don't need it because those are rebased on
+_text, or a section relative address.
+
+E.g. Without this:
+
+ $ perf probe -k build-arm/vmlinux -F __slab_alloc*
+ __slab_alloc.constprop.9
+ $ perf probe -k build-arm/vmlinux -D __slab_alloc
+ p:probe/__slab_alloc __slab_alloc+0
+
+If you put above definition on target machine, it should fail
+because there is no __slab_alloc in kallsyms.
+
+With this fix, perf probe shows correct probe definition on
+__slab_alloc.constprop.9:
+
+ $ perf probe -k build-arm/vmlinux -D __slab_alloc
+ p:probe/__slab_alloc __slab_alloc.constprop.9+0
+
+Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
+Cc: Jiri Olsa <jolsa@redhat.com>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Link: http://lkml.kernel.org/r/148350060434.19001.11864836288580083501.stgit@devbox
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Cc: Krister Johansen <kjlx@templeofstupid.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/probe-event.c | 48 +++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 47 insertions(+), 1 deletion(-)
+
+--- a/tools/perf/util/probe-event.c
++++ b/tools/perf/util/probe-event.c
+@@ -618,6 +618,51 @@ error:
+ return ret ? : -ENOENT;
+ }
+
++/*
++ * Rename DWARF symbols to ELF symbols -- gcc sometimes optimizes functions
++ * and generate new symbols with suffixes such as .constprop.N or .isra.N
++ * etc. Since those symbols are not recorded in DWARF, we have to find
++ * correct generated symbols from offline ELF binary.
++ * For online kernel or uprobes we don't need this because those are
++ * rebased on _text, or already a section relative address.
++ */
++static int
++post_process_offline_probe_trace_events(struct probe_trace_event *tevs,
++ int ntevs, const char *pathname)
++{
++ struct symbol *sym;
++ struct map *map;
++ unsigned long stext = 0;
++ u64 addr;
++ int i;
++
++ /* Prepare a map for offline binary */
++ map = dso__new_map(pathname);
++ if (!map || get_text_start_address(pathname, &stext) < 0) {
++ pr_warning("Failed to get ELF symbols for %s\n", pathname);
++ return -EINVAL;
++ }
++
++ for (i = 0; i < ntevs; i++) {
++ addr = tevs[i].point.address + tevs[i].point.offset - stext;
++ sym = map__find_symbol(map, addr);
++ if (!sym)
++ continue;
++ if (!strcmp(sym->name, tevs[i].point.symbol))
++ continue;
++ /* If we have no realname, use symbol for it */
++ if (!tevs[i].point.realname)
++ tevs[i].point.realname = tevs[i].point.symbol;
++ else
++ free(tevs[i].point.symbol);
++ tevs[i].point.symbol = strdup(sym->name);
++ tevs[i].point.offset = addr - sym->start;
++ }
++ map__put(map);
++
++ return 0;
++}
++
+ static int add_exec_to_probe_trace_events(struct probe_trace_event *tevs,
+ int ntevs, const char *exec)
+ {
+@@ -694,7 +739,8 @@ post_process_kernel_probe_trace_events(s
+
+ /* Skip post process if the target is an offline kernel */
+ if (symbol_conf.ignore_vmlinux_buildid)
+- return 0;
++ return post_process_offline_probe_trace_events(tevs, ntevs,
++ symbol_conf.vmlinux_name);
+
+ reloc_sym = kernel_get_ref_reloc_sym();
+ if (!reloc_sym) {
--- /dev/null
+From d7dd112ea5cacf91ae72c0714c3b911eb6016fea Mon Sep 17 00:00:00 2001
+From: Wang YanQing <udknight@gmail.com>
+Date: Sun, 12 Feb 2017 10:46:55 +0800
+Subject: perf scripting perl: Fix compile error with some perl5 versions
+
+From: Wang YanQing <udknight@gmail.com>
+
+commit d7dd112ea5cacf91ae72c0714c3b911eb6016fea upstream.
+
+Fix below compile error:
+
+ CC util/scripting-engines/trace-event-perl.o
+ In file included from /usr/lib/perl5/5.22.2/i686-linux/CORE/perl.h:5673:0,
+ from util/scripting-engines/trace-event-perl.c:31:
+ /usr/lib/perl5/5.22.2/i686-linux/CORE/inline.h: In function 'S__is_utf8_char_slow':
+ /usr/lib/perl5/5.22.2/i686-linux/CORE/inline.h:270:5: error: nested extern declaration of 'Perl___notused' [-Werror=nested-externs]
+ dTHX; /* The function called below requires thread context */
+ ^
+ cc1: all warnings being treated as errors
+
+After digging perl5 repository, I find out that we will meet this
+compile error with perl from v5.21.1 to v5.25.4
+
+Signed-off-by: Wang YanQing <udknight@gmail.com>
+Acked-by: Jiri Olsa <jolsa@kernel.org>
+Link: http://lkml.kernel.org/r/20170212024655.GA15997@udknight
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/util/scripting-engines/Build | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/util/scripting-engines/Build
++++ b/tools/perf/util/scripting-engines/Build
+@@ -1,6 +1,6 @@
+ libperf-$(CONFIG_LIBPERL) += trace-event-perl.o
+ libperf-$(CONFIG_LIBPYTHON) += trace-event-python.o
+
+-CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-undef -Wno-switch-default
++CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-nested-externs -Wno-undef -Wno-switch-default
+
+ CFLAGS_trace-event-python.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow
--- /dev/null
+From 2e2bbc039fad9eabad6c4c1a473c8b2554cdd2d4 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Thu, 9 Feb 2017 14:48:46 -0300
+Subject: perf tests: Avoid possible truncation with dirent->d_name + snprintf
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 2e2bbc039fad9eabad6c4c1a473c8b2554cdd2d4 upstream.
+
+Addressing a few cases spotted by a new warning in gcc 7:
+
+ tests/parse-events.c: In function 'test_pmu_events':
+ tests/parse-events.c:1790:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 90 [-Werror=format-truncation=]
+ snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
+ ^~
+ In file included from /usr/include/stdio.h:939:0,
+ from /git/linux/tools/perf/util/map.h:9,
+ from /git/linux/tools/perf/util/symbol.h:7,
+ from /git/linux/tools/perf/util/evsel.h:10,
+ from tests/parse-events.c:3:
+ /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 13 and 268 bytes into a destination of size 100
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ tests/parse-events.c:1798:29: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 100 [-Werror=format-truncation=]
+ snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Fixes: 945aea220bb8 ("perf tests: Move test objects into 'tests' directory")
+Link: http://lkml.kernel.org/n/tip-ty4q2p8zp1dp3mskvubxskm5@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/tests/parse-events.c | 8 +++-----
+ 1 file changed, 3 insertions(+), 5 deletions(-)
+
+--- a/tools/perf/tests/parse-events.c
++++ b/tools/perf/tests/parse-events.c
+@@ -1779,15 +1779,14 @@ static int test_pmu_events(void)
+ }
+
+ while (!ret && (ent = readdir(dir))) {
+-#define MAX_NAME 100
+ struct evlist_test e;
+- char name[MAX_NAME];
++ char name[2 * NAME_MAX + 1 + 12 + 3];
+
+ /* Names containing . are special and cannot be used directly */
+ if (strchr(ent->d_name, '.'))
+ continue;
+
+- snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
++ snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name);
+
+ e.name = name;
+ e.check = test__checkevent_pmu_events;
+@@ -1795,11 +1794,10 @@ static int test_pmu_events(void)
+ ret = test_event(&e);
+ if (ret)
+ break;
+- snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
++ snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
+ e.name = name;
+ e.check = test__checkevent_pmu_events_mix;
+ ret = test_event(&e);
+-#undef MAX_NAME
+ }
+
+ closedir(dir);
--- /dev/null
+From bdf23a9a190d7ecea092fd5c4aabb7d4bd0a9980 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: perf thread_map: Correctly size buffer used with dirent->dt_name
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit bdf23a9a190d7ecea092fd5c4aabb7d4bd0a9980 upstream.
+
+The size of dirent->dt_name is NAME_MAX + 1, but the size for the 'path'
+buffer is hard coded at 256, which may truncate it because we also
+prepend "/proc/", so that all that into account and thank gcc 7 for this
+warning:
+
+ /git/linux/tools/perf/util/thread_map.c: In function 'thread_map__new_by_uid':
+ /git/linux/tools/perf/util/thread_map.c:119:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 250 [-Werror=format-truncation=]
+ snprintf(path, sizeof(path), "/proc/%s", dirent->d_name);
+ ^~
+ In file included from /usr/include/stdio.h:939:0,
+ from /git/linux/tools/perf/util/thread_map.c:5:
+ /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 7 and 262 bytes into a destination of size 256
+ return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
+ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ __bos (__s), __fmt, __va_arg_pack ());
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-csy0r8zrvz5efccgd4k12c82@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/thread_map.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/util/thread_map.c
++++ b/tools/perf/util/thread_map.c
+@@ -93,7 +93,7 @@ struct thread_map *thread_map__new_by_ui
+ {
+ DIR *proc;
+ int max_threads = 32, items, i;
+- char path[256];
++ char path[NAME_MAX + 1 + 6];
+ struct dirent *dirent, **namelist = NULL;
+ struct thread_map *threads = thread_map__alloc(max_threads);
+
--- /dev/null
+From 7b0214b702ad8e124e039a317beeebb3f020d125 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: perf top: Use __fallthrough
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 7b0214b702ad8e124e039a317beeebb3f020d125 upstream.
+
+The implicit fall through case label here is intended, so let us inform
+that to gcc >= 7:
+
+ CC /tmp/build/perf/builtin-top.o
+ builtin-top.c: In function 'display_thread':
+ builtin-top.c:644:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (errno == EINTR)
+ ^
+ builtin-top.c:647:3: note: here
+ default:
+ ^~~~~~~
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-lmcfnnyx9ic0m6j0aud98p4e@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/perf/builtin-top.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/tools/perf/builtin-top.c
++++ b/tools/perf/builtin-top.c
+@@ -643,7 +643,7 @@ repeat:
+ case -1:
+ if (errno == EINTR)
+ continue;
+- /* Fall trhu */
++ __fallthrough;
+ default:
+ c = getc(stdin);
+ tcsetattr(0, TCSAFLUSH, &save);
mqueue-fix-a-use-after-free-in-sys_mq_notify.patch
+add-shutdown-to-struct-class.patch
+tpm-issue-a-tpm2_shutdown-for-tpm2-devices.patch
+tools-include-add-a-__fallthrough-statement.patch
+tools-string-use-__fallthrough-in-perf_atoll.patch
+tools-strfilter-use-__fallthrough.patch
+perf-top-use-__fallthrough.patch
+perf-thread_map-correctly-size-buffer-used-with-dirent-dt_name.patch
+perf-intel-pt-use-__fallthrough.patch
+perf-tests-avoid-possible-truncation-with-dirent-d_name-snprintf.patch
+perf-bench-numa-avoid-possible-truncation-when-using-snprintf.patch
+perf-header-fix-handling-of-perf_event_update__scale.patch
+perf-scripting-perl-fix-compile-error-with-some-perl5-versions.patch
+perf-probe-fix-to-probe-on-gcc-generated-symbols-for-offline-kernel.patch
+perf-probe-add-error-checks-to-offline-probe-post-processing.patch
--- /dev/null
+From b5bf1733d6a391c4e90ea8f8468d83023be74a2a Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: tools include: Add a __fallthrough statement
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit b5bf1733d6a391c4e90ea8f8468d83023be74a2a upstream.
+
+For cases where implicit fall through case labels are intended,
+to let us inform that to gcc >= 7:
+
+ CC /tmp/build/perf/util/string.o
+ util/string.c: In function 'perf_atoll':
+ util/string.c:22:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (*p)
+ ^
+ util/string.c:24:3: note: here
+ case '\0':
+ ^~~~
+
+So we introduce:
+
+ #define __fallthrough __attribute__ ((fallthrough))
+
+And use it in such cases.
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Cc: William Cohen <wcohen@redhat.com>
+Link: http://lkml.kernel.org/n/tip-qnpig0xfop4hwv6k4mv1wts5@git.kernel.org
+Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ tools/include/linux/compiler.h | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+--- a/tools/include/linux/compiler.h
++++ b/tools/include/linux/compiler.h
+@@ -126,4 +126,13 @@ static __always_inline void __write_once
+ #define WRITE_ONCE(x, val) \
+ ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
+
++
++#ifndef __fallthrough
++# if defined(__GNUC__) && __GNUC__ >= 7
++# define __fallthrough __attribute__ ((fallthrough))
++# else
++# define __fallthrough
++# endif
++#endif
++
+ #endif /* _TOOLS_LINUX_COMPILER_H */
--- /dev/null
+From d64b721d27aef3fbeb16ecda9dd22ee34818ff70 Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: tools strfilter: Use __fallthrough
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit d64b721d27aef3fbeb16ecda9dd22ee34818ff70 upstream.
+
+The implicit fall through case label here is intended, so let us inform
+that to gcc >= 7:
+
+ util/strfilter.c: In function 'strfilter_node__sprint':
+ util/strfilter.c:270:6: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (len < 0)
+ ^
+ util/strfilter.c:272:2: note: here
+ case '!':
+ ^~~~
+ cc1: all warnings being treated as errors
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-z2dpywg7u8fim000hjfbpyfm@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/strfilter.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/tools/perf/util/strfilter.c
++++ b/tools/perf/util/strfilter.c
+@@ -269,6 +269,7 @@ static int strfilter_node__sprint(struct
+ len = strfilter_node__sprint_pt(node->l, buf);
+ if (len < 0)
+ return len;
++ __fallthrough;
+ case '!':
+ if (buf) {
+ *(buf + len++) = *node->p;
--- /dev/null
+From 94bdd5edb34e472980d1e18b4600d6fb92bd6b0a Mon Sep 17 00:00:00 2001
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+Date: Wed, 8 Feb 2017 17:01:46 -0300
+Subject: tools string: Use __fallthrough in perf_atoll()
+
+From: Arnaldo Carvalho de Melo <acme@redhat.com>
+
+commit 94bdd5edb34e472980d1e18b4600d6fb92bd6b0a upstream.
+
+The implicit fall through case label here is intended, so let us inform
+that to gcc >= 7:
+
+ CC /tmp/build/perf/util/string.o
+ util/string.c: In function 'perf_atoll':
+ util/string.c:22:7: error: this statement may fall through [-Werror=implicit-fallthrough=]
+ if (*p)
+ ^
+ util/string.c:24:3: note: here
+ case '\0':
+ ^~~~
+
+Cc: Adrian Hunter <adrian.hunter@intel.com>
+Cc: David Ahern <dsahern@gmail.com>
+Cc: Jiri Olsa <jolsa@kernel.org>
+Cc: Namhyung Kim <namhyung@kernel.org>
+Cc: Wang Nan <wangnan0@huawei.com>
+Link: http://lkml.kernel.org/n/tip-0ophb30v9apkk6o95el0rqlq@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/string.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+--- a/tools/perf/util/string.c
++++ b/tools/perf/util/string.c
+@@ -21,6 +21,8 @@ s64 perf_atoll(const char *str)
+ case 'b': case 'B':
+ if (*p)
+ goto out_err;
++
++ __fallthrough;
+ case '\0':
+ return length;
+ default:
--- /dev/null
+From d1bd4a792d3961a04e6154118816b00167aad91a Mon Sep 17 00:00:00 2001
+From: Josh Zimmerman <joshz@google.com>
+Date: Sun, 25 Jun 2017 14:53:24 -0700
+Subject: tpm: Issue a TPM2_Shutdown for TPM2 devices.
+
+From: Josh Zimmerman <joshz@google.com>
+
+commit d1bd4a792d3961a04e6154118816b00167aad91a upstream.
+
+If a TPM2 loses power without a TPM2_Shutdown command being issued (a
+"disorderly reboot"), it may lose some state that has yet to be
+persisted to NVRam, and will increment the DA counter. After the DA
+counter gets sufficiently large, the TPM will lock the user out.
+
+NOTE: This only changes behavior on TPM2 devices. Since TPM1 uses sysfs,
+and sysfs relies on implicit locking on chip->ops, it is not safe to
+allow this code to run in TPM1, or to add sysfs support to TPM2, until
+that locking is made explicit.
+
+Signed-off-by: Josh Zimmerman <joshz@google.com>
+Fixes: 74d6b3ceaa17 ("tpm: fix suspend/resume paths for TPM 2.0")
+Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
+Signed-off-by: James Morris <james.l.morris@oracle.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ drivers/char/tpm/tpm-chip.c | 36 ++++++++++++++++++++++++++++++++++++
+ drivers/char/tpm/tpm-sysfs.c | 5 +++++
+ 2 files changed, 41 insertions(+)
+
+--- a/drivers/char/tpm/tpm-chip.c
++++ b/drivers/char/tpm/tpm-chip.c
+@@ -130,6 +130,41 @@ static void tpm_dev_release(struct devic
+ kfree(chip);
+ }
+
++
++/**
++ * tpm_class_shutdown() - prepare the TPM device for loss of power.
++ * @dev: device to which the chip is associated.
++ *
++ * Issues a TPM2_Shutdown command prior to loss of power, as required by the
++ * TPM 2.0 spec.
++ * Then, calls bus- and device- specific shutdown code.
++ *
++ * XXX: This codepath relies on the fact that sysfs is not enabled for
++ * TPM2: sysfs uses an implicit lock on chip->ops, so this could race if TPM2
++ * has sysfs support enabled before TPM sysfs's implicit locking is fixed.
++ */
++static int tpm_class_shutdown(struct device *dev)
++{
++ struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev);
++
++ if (chip->flags & TPM_CHIP_FLAG_TPM2) {
++ down_write(&chip->ops_sem);
++ tpm2_shutdown(chip, TPM2_SU_CLEAR);
++ chip->ops = NULL;
++ up_write(&chip->ops_sem);
++ }
++ /* Allow bus- and device-specific code to run. Note: since chip->ops
++ * is NULL, more-specific shutdown code will not be able to issue TPM
++ * commands.
++ */
++ if (dev->bus && dev->bus->shutdown)
++ dev->bus->shutdown(dev);
++ else if (dev->driver && dev->driver->shutdown)
++ dev->driver->shutdown(dev);
++ return 0;
++}
++
++
+ /**
+ * tpm_chip_alloc() - allocate a new struct tpm_chip instance
+ * @pdev: device to which the chip is associated
+@@ -168,6 +203,7 @@ struct tpm_chip *tpm_chip_alloc(struct d
+ device_initialize(&chip->dev);
+
+ chip->dev.class = tpm_class;
++ chip->dev.class->shutdown = tpm_class_shutdown;
+ chip->dev.release = tpm_dev_release;
+ chip->dev.parent = pdev;
+ chip->dev.groups = chip->groups;
+--- a/drivers/char/tpm/tpm-sysfs.c
++++ b/drivers/char/tpm/tpm-sysfs.c
+@@ -285,6 +285,11 @@ static const struct attribute_group tpm_
+
+ void tpm_sysfs_add_device(struct tpm_chip *chip)
+ {
++ /* XXX: If you wish to remove this restriction, you must first update
++ * tpm_sysfs to explicitly lock chip->ops.
++ */
++ if (chip->flags & TPM_CHIP_FLAG_TPM2)
++ return;
+ /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
+ * is called before ops is null'd and the sysfs core synchronizes this
+ * removal so that no callbacks are running or can run again