From: Greg Kroah-Hartman Date: Sat, 22 Jul 2017 13:08:57 +0000 (+0200) Subject: 4.12-stable patches X-Git-Tag: v3.18.63~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f19888a5063463683211cf68e7f715b475960c8f;p=thirdparty%2Fkernel%2Fstable-queue.git 4.12-stable patches added patches: bluetooth-use-constant-time-memory-comparison-for-secret-values.patch perf-intel-pt-clear-fup-flag-on-error.patch perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch perf-intel-pt-fix-last_ip-usage.patch perf-intel-pt-fix-missing-stack-clear.patch perf-intel-pt-improve-sample-timestamp.patch perf-intel-pt-move-decoder-error-setting-into-one-condition.patch perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch --- diff --git a/queue-4.12/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch b/queue-4.12/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch new file mode 100644 index 00000000000..5be75a0c3b9 --- /dev/null +++ b/queue-4.12/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch @@ -0,0 +1,193 @@ +From 329d82309824ff1082dc4a91a5bbed8c3bec1580 Mon Sep 17 00:00:00 2001 +From: "Jason A. Donenfeld" +Date: Sat, 10 Jun 2017 04:59:11 +0200 +Subject: Bluetooth: use constant time memory comparison for secret values + +From: Jason A. Donenfeld + +commit 329d82309824ff1082dc4a91a5bbed8c3bec1580 upstream. + +This file is filled with complex cryptography. Thus, the comparisons of +MACs and secret keys and curve points and so forth should not add timing +attacks, which could either result in a direct forgery, or, given the +complexity, some other type of attack. + +Signed-off-by: Jason A. Donenfeld +Signed-off-by: Marcel Holtmann +Signed-off-by: Greg Kroah-Hartman + +--- + net/bluetooth/smp.c | 39 ++++++++++++++++++++------------------- + 1 file changed, 20 insertions(+), 19 deletions(-) + +--- a/net/bluetooth/smp.c ++++ b/net/bluetooth/smp.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -523,7 +524,7 @@ bool smp_irk_matches(struct hci_dev *hde + if (err) + return false; + +- return !memcmp(bdaddr->b, hash, 3); ++ return !crypto_memneq(bdaddr->b, hash, 3); + } + + int smp_generate_rpa(struct hci_dev *hdev, const u8 irk[16], bdaddr_t *rpa) +@@ -579,7 +580,7 @@ int smp_generate_oob(struct hci_dev *hde + /* This is unlikely, but we need to check that + * we didn't accidentially generate a debug key. + */ +- if (memcmp(smp->local_sk, debug_sk, 32)) ++ if (crypto_memneq(smp->local_sk, debug_sk, 32)) + break; + } + smp->debug_key = false; +@@ -993,7 +994,7 @@ static u8 smp_random(struct smp_chan *sm + if (ret) + return SMP_UNSPECIFIED; + +- if (memcmp(smp->pcnf, confirm, sizeof(smp->pcnf)) != 0) { ++ if (crypto_memneq(smp->pcnf, confirm, sizeof(smp->pcnf))) { + BT_ERR("Pairing failed (confirmation values mismatch)"); + return SMP_CONFIRM_FAILED; + } +@@ -1512,7 +1513,7 @@ static u8 sc_passkey_round(struct smp_ch + smp->rrnd, r, cfm)) + return SMP_UNSPECIFIED; + +- if (memcmp(smp->pcnf, cfm, 16)) ++ if (crypto_memneq(smp->pcnf, cfm, 16)) + return SMP_CONFIRM_FAILED; + + smp->passkey_round++; +@@ -1908,7 +1909,7 @@ static u8 sc_send_public_key(struct smp_ + /* This is unlikely, but we need to check that + * we didn't accidentially generate a debug key. + */ +- if (memcmp(smp->local_sk, debug_sk, 32)) ++ if (crypto_memneq(smp->local_sk, debug_sk, 32)) + break; + } + } +@@ -2176,7 +2177,7 @@ static u8 smp_cmd_pairing_random(struct + if (err) + return SMP_UNSPECIFIED; + +- if (memcmp(smp->pcnf, cfm, 16)) ++ if (crypto_memneq(smp->pcnf, cfm, 16)) + return SMP_CONFIRM_FAILED; + } else { + smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), +@@ -2660,7 +2661,7 @@ static int smp_cmd_public_key(struct l2c + if (err) + return SMP_UNSPECIFIED; + +- if (memcmp(cfm.confirm_val, smp->pcnf, 16)) ++ if (crypto_memneq(cfm.confirm_val, smp->pcnf, 16)) + return SMP_CONFIRM_FAILED; + } + +@@ -2693,7 +2694,7 @@ static int smp_cmd_public_key(struct l2c + else + hcon->pending_sec_level = BT_SECURITY_FIPS; + +- if (!memcmp(debug_pk, smp->remote_pk, 64)) ++ if (!crypto_memneq(debug_pk, smp->remote_pk, 64)) + set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags); + + if (smp->method == DSP_PASSKEY) { +@@ -2792,7 +2793,7 @@ static int smp_cmd_dhkey_check(struct l2 + if (err) + return SMP_UNSPECIFIED; + +- if (memcmp(check->e, e, 16)) ++ if (crypto_memneq(check->e, e, 16)) + return SMP_DHKEY_CHECK_FAILED; + + if (!hcon->out) { +@@ -3506,10 +3507,10 @@ static int __init test_debug_key(void) + if (!generate_ecdh_keys(pk, sk)) + return -EINVAL; + +- if (memcmp(sk, debug_sk, 32)) ++ if (crypto_memneq(sk, debug_sk, 32)) + return -EINVAL; + +- if (memcmp(pk, debug_pk, 64)) ++ if (crypto_memneq(pk, debug_pk, 64)) + return -EINVAL; + + return 0; +@@ -3529,7 +3530,7 @@ static int __init test_ah(struct crypto_ + if (err) + return err; + +- if (memcmp(res, exp, 3)) ++ if (crypto_memneq(res, exp, 3)) + return -EINVAL; + + return 0; +@@ -3559,7 +3560,7 @@ static int __init test_c1(struct crypto_ + if (err) + return err; + +- if (memcmp(res, exp, 16)) ++ if (crypto_memneq(res, exp, 16)) + return -EINVAL; + + return 0; +@@ -3584,7 +3585,7 @@ static int __init test_s1(struct crypto_ + if (err) + return err; + +- if (memcmp(res, exp, 16)) ++ if (crypto_memneq(res, exp, 16)) + return -EINVAL; + + return 0; +@@ -3616,7 +3617,7 @@ static int __init test_f4(struct crypto_ + if (err) + return err; + +- if (memcmp(res, exp, 16)) ++ if (crypto_memneq(res, exp, 16)) + return -EINVAL; + + return 0; +@@ -3650,10 +3651,10 @@ static int __init test_f5(struct crypto_ + if (err) + return err; + +- if (memcmp(mackey, exp_mackey, 16)) ++ if (crypto_memneq(mackey, exp_mackey, 16)) + return -EINVAL; + +- if (memcmp(ltk, exp_ltk, 16)) ++ if (crypto_memneq(ltk, exp_ltk, 16)) + return -EINVAL; + + return 0; +@@ -3686,7 +3687,7 @@ static int __init test_f6(struct crypto_ + if (err) + return err; + +- if (memcmp(res, exp, 16)) ++ if (crypto_memneq(res, exp, 16)) + return -EINVAL; + + return 0; +@@ -3740,7 +3741,7 @@ static int __init test_h6(struct crypto_ + if (err) + return err; + +- if (memcmp(res, exp, 16)) ++ if (crypto_memneq(res, exp, 16)) + return -EINVAL; + + return 0; diff --git a/queue-4.12/perf-intel-pt-clear-fup-flag-on-error.patch b/queue-4.12/perf-intel-pt-clear-fup-flag-on-error.patch new file mode 100644 index 00000000000..77ecf4b287c --- /dev/null +++ b/queue-4.12/perf-intel-pt-clear-fup-flag-on-error.patch @@ -0,0 +1,34 @@ +From 6a558f12dbe85437acbdec5e149ea07b5554eced Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:09 +0300 +Subject: perf intel-pt: Clear FUP flag on error + +From: Adrian Hunter + +commit 6a558f12dbe85437acbdec5e149ea07b5554eced upstream. + +Sometimes a FUP packet is associated with a TSX transaction and a flag is +set to indicate that. Ensure that flag is cleared on any error condition +because at that point the decoder can no longer assume it is correct. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-9-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -1962,6 +1962,8 @@ static int intel_pt_sync_ip(struct intel + { + int err; + ++ decoder->set_fup_tx_flags = false; ++ + intel_pt_log("Scanning for full IP\n"); + err = intel_pt_walk_to_ip(decoder); + if (err) diff --git a/queue-4.12/perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch b/queue-4.12/perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch new file mode 100644 index 00000000000..eddf8475dc6 --- /dev/null +++ b/queue-4.12/perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch @@ -0,0 +1,32 @@ +From ad7167a8cd174ba7d8c0d0ed8d8410521206d104 Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:05 +0300 +Subject: perf intel-pt: Ensure IP is zero when state is INTEL_PT_STATE_NO_IP + +From: Adrian Hunter + +commit ad7167a8cd174ba7d8c0d0ed8d8410521206d104 upstream. + +A value of zero is used to indicate that there is no IP. Ensure the +value is zero when the state is INTEL_PT_STATE_NO_IP. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-5-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -2117,6 +2117,7 @@ const struct intel_pt_state *intel_pt_de + break; + case INTEL_PT_STATE_NO_IP: + decoder->last_ip = 0; ++ decoder->ip = 0; + /* Fall through */ + case INTEL_PT_STATE_ERR_RESYNC: + err = intel_pt_sync_ip(decoder); diff --git a/queue-4.12/perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch b/queue-4.12/perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch new file mode 100644 index 00000000000..32bd1e11216 --- /dev/null +++ b/queue-4.12/perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch @@ -0,0 +1,48 @@ +From f952eaceb089b691eba7c4e13686e742a8f26bf5 Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:07 +0300 +Subject: perf intel-pt: Ensure never to set 'last_ip' when packet 'count' is zero + +From: Adrian Hunter + +commit f952eaceb089b691eba7c4e13686e742a8f26bf5 upstream. + +Intel PT uses IP compression based on the last IP. For decoding purposes, +'last IP' is not updated when a branch target has been suppressed, which is +indicated by IPBytes == 0. IPBytes is stored in the packet 'count', so +ensure never to set 'last_ip' when packet 'count' is zero. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-7-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -1470,7 +1470,8 @@ static int intel_pt_walk_psbend(struct i + + case INTEL_PT_FUP: + decoder->pge = true; +- intel_pt_set_last_ip(decoder); ++ if (decoder->packet.count) ++ intel_pt_set_last_ip(decoder); + break; + + case INTEL_PT_MODE_TSX: +@@ -1756,8 +1757,9 @@ next: + + static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder) + { +- return decoder->have_last_ip || decoder->packet.count == 0 || +- decoder->packet.count == 3 || decoder->packet.count == 6; ++ return decoder->packet.count && ++ (decoder->have_last_ip || decoder->packet.count == 3 || ++ decoder->packet.count == 6); + } + + /* Walk PSB+ packets to get in sync. */ diff --git a/queue-4.12/perf-intel-pt-fix-last_ip-usage.patch b/queue-4.12/perf-intel-pt-fix-last_ip-usage.patch new file mode 100644 index 00000000000..66305a47760 --- /dev/null +++ b/queue-4.12/perf-intel-pt-fix-last_ip-usage.patch @@ -0,0 +1,104 @@ +From ee14ac0ef6827cd6f9a572cc83dd0191ea17812c Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:06 +0300 +Subject: perf intel-pt: Fix last_ip usage + +From: Adrian Hunter + +commit ee14ac0ef6827cd6f9a572cc83dd0191ea17812c upstream. + +Intel PT uses IP compression based on the last IP. For decoding +purposes, 'last IP' is considered to be reset to zero whenever there is +a synchronization packet (PSB). The decoder wasn't doing that, and was +treating the zero value to mean that there was no last IP, whereas +compression can be done against the zero value. Fix by setting last_ip +to zero when a PSB is received and keep track of have_last_ip. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-6-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 13 +++++++++++-- + 1 file changed, 11 insertions(+), 2 deletions(-) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -111,6 +111,7 @@ struct intel_pt_decoder { + bool have_tma; + bool have_cyc; + bool fixup_last_mtc; ++ bool have_last_ip; + uint64_t pos; + uint64_t last_ip; + uint64_t ip; +@@ -419,6 +420,7 @@ static uint64_t intel_pt_calc_ip(const s + static inline void intel_pt_set_last_ip(struct intel_pt_decoder *decoder) + { + decoder->last_ip = intel_pt_calc_ip(&decoder->packet, decoder->last_ip); ++ decoder->have_last_ip = true; + } + + static inline void intel_pt_set_ip(struct intel_pt_decoder *decoder) +@@ -1672,6 +1674,8 @@ next: + break; + + case INTEL_PT_PSB: ++ decoder->last_ip = 0; ++ decoder->have_last_ip = true; + intel_pt_clear_stack(&decoder->stack); + err = intel_pt_walk_psbend(decoder); + if (err == -EAGAIN) +@@ -1752,7 +1756,7 @@ next: + + static inline bool intel_pt_have_ip(struct intel_pt_decoder *decoder) + { +- return decoder->last_ip || decoder->packet.count == 0 || ++ return decoder->have_last_ip || decoder->packet.count == 0 || + decoder->packet.count == 3 || decoder->packet.count == 6; + } + +@@ -1882,7 +1886,7 @@ static int intel_pt_walk_to_ip(struct in + if (decoder->ip) + return 0; + } +- if (decoder->packet.count) ++ if (decoder->packet.count && decoder->have_last_ip) + intel_pt_set_last_ip(decoder); + break; + +@@ -1932,6 +1936,8 @@ static int intel_pt_walk_to_ip(struct in + break; + + case INTEL_PT_PSB: ++ decoder->last_ip = 0; ++ decoder->have_last_ip = true; + intel_pt_clear_stack(&decoder->stack); + err = intel_pt_walk_psb(decoder); + if (err) +@@ -2066,6 +2072,7 @@ static int intel_pt_sync(struct intel_pt + + decoder->pge = false; + decoder->continuous_period = false; ++ decoder->have_last_ip = false; + decoder->last_ip = 0; + decoder->ip = 0; + intel_pt_clear_stack(&decoder->stack); +@@ -2074,6 +2081,7 @@ static int intel_pt_sync(struct intel_pt + if (err) + return err; + ++ decoder->have_last_ip = true; + decoder->pkt_state = INTEL_PT_STATE_NO_IP; + + err = intel_pt_walk_psb(decoder); +@@ -2116,6 +2124,7 @@ const struct intel_pt_state *intel_pt_de + err = intel_pt_sync(decoder); + break; + case INTEL_PT_STATE_NO_IP: ++ decoder->have_last_ip = false; + decoder->last_ip = 0; + decoder->ip = 0; + /* Fall through */ diff --git a/queue-4.12/perf-intel-pt-fix-missing-stack-clear.patch b/queue-4.12/perf-intel-pt-fix-missing-stack-clear.patch new file mode 100644 index 00000000000..9c8685560e3 --- /dev/null +++ b/queue-4.12/perf-intel-pt-fix-missing-stack-clear.patch @@ -0,0 +1,32 @@ +From 12b7080609097753fd8198cc1daf589be3ec1cca Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:04 +0300 +Subject: perf intel-pt: Fix missing stack clear + +From: Adrian Hunter + +commit 12b7080609097753fd8198cc1daf589be3ec1cca upstream. + +The return compression stack must be cleared whenever there is a PSB. Fix +one case where that was not happening. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-4-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -1932,6 +1932,7 @@ static int intel_pt_walk_to_ip(struct in + break; + + case INTEL_PT_PSB: ++ intel_pt_clear_stack(&decoder->stack); + err = intel_pt_walk_psb(decoder); + if (err) + return err; diff --git a/queue-4.12/perf-intel-pt-improve-sample-timestamp.patch b/queue-4.12/perf-intel-pt-improve-sample-timestamp.patch new file mode 100644 index 00000000000..70e28d4600a --- /dev/null +++ b/queue-4.12/perf-intel-pt-improve-sample-timestamp.patch @@ -0,0 +1,114 @@ +From 3f04d98e972b59706bd43d6cc75efac91f8fba50 Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:03 +0300 +Subject: perf intel-pt: Improve sample timestamp + +From: Adrian Hunter + +commit 3f04d98e972b59706bd43d6cc75efac91f8fba50 upstream. + +The decoder uses its current timestamp in samples. Usually that is a +timestamp that has already passed, but in some cases it is a timestamp +for a branch that the decoder is walking towards, and consequently +hasn't reached. Improve that situation by using the pkt_state to +determine when to use the current or previous timestamp. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-3-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 34 ++++++++++++++++++-- + 1 file changed, 31 insertions(+), 3 deletions(-) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -64,6 +64,25 @@ enum intel_pt_pkt_state { + INTEL_PT_STATE_FUP_NO_TIP, + }; + ++static inline bool intel_pt_sample_time(enum intel_pt_pkt_state pkt_state) ++{ ++ switch (pkt_state) { ++ case INTEL_PT_STATE_NO_PSB: ++ case INTEL_PT_STATE_NO_IP: ++ case INTEL_PT_STATE_ERR_RESYNC: ++ case INTEL_PT_STATE_IN_SYNC: ++ case INTEL_PT_STATE_TNT: ++ return true; ++ case INTEL_PT_STATE_TIP: ++ case INTEL_PT_STATE_TIP_PGD: ++ case INTEL_PT_STATE_FUP: ++ case INTEL_PT_STATE_FUP_NO_TIP: ++ return false; ++ default: ++ return true; ++ }; ++} ++ + #ifdef INTEL_PT_STRICT + #define INTEL_PT_STATE_ERR1 INTEL_PT_STATE_NO_PSB + #define INTEL_PT_STATE_ERR2 INTEL_PT_STATE_NO_PSB +@@ -99,6 +118,7 @@ struct intel_pt_decoder { + uint64_t timestamp; + uint64_t tsc_timestamp; + uint64_t ref_timestamp; ++ uint64_t sample_timestamp; + uint64_t ret_addr; + uint64_t ctc_timestamp; + uint64_t ctc_delta; +@@ -139,6 +159,7 @@ struct intel_pt_decoder { + unsigned int fup_tx_flags; + unsigned int tx_flags; + uint64_t timestamp_insn_cnt; ++ uint64_t sample_insn_cnt; + uint64_t stuck_ip; + int no_progress; + int stuck_ip_prd; +@@ -898,6 +919,7 @@ static int intel_pt_walk_insn(struct int + + decoder->tot_insn_cnt += insn_cnt; + decoder->timestamp_insn_cnt += insn_cnt; ++ decoder->sample_insn_cnt += insn_cnt; + decoder->period_insn_cnt += insn_cnt; + + if (err) { +@@ -2069,7 +2091,7 @@ static int intel_pt_sync(struct intel_pt + + static uint64_t intel_pt_est_timestamp(struct intel_pt_decoder *decoder) + { +- uint64_t est = decoder->timestamp_insn_cnt << 1; ++ uint64_t est = decoder->sample_insn_cnt << 1; + + if (!decoder->cbr || !decoder->max_non_turbo_ratio) + goto out; +@@ -2077,7 +2099,7 @@ static uint64_t intel_pt_est_timestamp(s + est *= decoder->max_non_turbo_ratio; + est /= decoder->cbr; + out: +- return decoder->timestamp + est; ++ return decoder->sample_timestamp + est; + } + + const struct intel_pt_state *intel_pt_decode(struct intel_pt_decoder *decoder) +@@ -2133,11 +2155,17 @@ const struct intel_pt_state *intel_pt_de + if (err) { + decoder->state.err = intel_pt_ext_err(err); + decoder->state.from_ip = decoder->ip; ++ decoder->sample_timestamp = decoder->timestamp; ++ decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; + } else { + decoder->state.err = 0; ++ if (intel_pt_sample_time(decoder->pkt_state)) { ++ decoder->sample_timestamp = decoder->timestamp; ++ decoder->sample_insn_cnt = decoder->timestamp_insn_cnt; ++ } + } + +- decoder->state.timestamp = decoder->timestamp; ++ decoder->state.timestamp = decoder->sample_timestamp; + decoder->state.est_timestamp = intel_pt_est_timestamp(decoder); + decoder->state.cr3 = decoder->cr3; + decoder->state.tot_insn_cnt = decoder->tot_insn_cnt; diff --git a/queue-4.12/perf-intel-pt-move-decoder-error-setting-into-one-condition.patch b/queue-4.12/perf-intel-pt-move-decoder-error-setting-into-one-condition.patch new file mode 100644 index 00000000000..0c9cc8f4fcf --- /dev/null +++ b/queue-4.12/perf-intel-pt-move-decoder-error-setting-into-one-condition.patch @@ -0,0 +1,48 @@ +From 22c06892332d8916115525145b78e606e9cc6492 Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:02 +0300 +Subject: perf intel-pt: Move decoder error setting into one condition + +From: Adrian Hunter + +commit 22c06892332d8916115525145b78e606e9cc6492 upstream. + +Move decoder error setting into one condition. + +Cc'ed to stable because later fixes depend on it. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-2-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -2130,15 +2130,18 @@ const struct intel_pt_state *intel_pt_de + } + } while (err == -ENOLINK); + +- decoder->state.err = err ? intel_pt_ext_err(err) : 0; ++ if (err) { ++ decoder->state.err = intel_pt_ext_err(err); ++ decoder->state.from_ip = decoder->ip; ++ } else { ++ decoder->state.err = 0; ++ } ++ + decoder->state.timestamp = decoder->timestamp; + decoder->state.est_timestamp = intel_pt_est_timestamp(decoder); + decoder->state.cr3 = decoder->cr3; + decoder->state.tot_insn_cnt = decoder->tot_insn_cnt; + +- if (err) +- decoder->state.from_ip = decoder->ip; +- + return &decoder->state; + } + diff --git a/queue-4.12/perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch b/queue-4.12/perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch new file mode 100644 index 00000000000..86efc5d4803 --- /dev/null +++ b/queue-4.12/perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch @@ -0,0 +1,45 @@ +From 622b7a47b843c78626f40c1d1aeef8483383fba2 Mon Sep 17 00:00:00 2001 +From: Adrian Hunter +Date: Fri, 26 May 2017 11:17:08 +0300 +Subject: perf intel-pt: Use FUP always when scanning for an IP + +From: Adrian Hunter + +commit 622b7a47b843c78626f40c1d1aeef8483383fba2 upstream. + +The decoder will try to use branch packets to find an IP to start decoding +or to recover from errors. Currently the FUP packet is used only in the +case of an overflow, however there is no reason for that to be a special +case. So just use FUP always when scanning for an IP. + +Signed-off-by: Adrian Hunter +Cc: Andi Kleen +Link: http://lkml.kernel.org/r/1495786658-18063-8-git-send-email-adrian.hunter@intel.com +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman + +--- + tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 12 ++++-------- + 1 file changed, 4 insertions(+), 8 deletions(-) + +--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c ++++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +@@ -1882,14 +1882,10 @@ static int intel_pt_walk_to_ip(struct in + break; + + case INTEL_PT_FUP: +- if (decoder->overflow) { +- if (intel_pt_have_ip(decoder)) +- intel_pt_set_ip(decoder); +- if (decoder->ip) +- return 0; +- } +- if (decoder->packet.count && decoder->have_last_ip) +- intel_pt_set_last_ip(decoder); ++ if (intel_pt_have_ip(decoder)) ++ intel_pt_set_ip(decoder); ++ if (decoder->ip) ++ return 0; + break; + + case INTEL_PT_MTC: diff --git a/queue-4.12/series b/queue-4.12/series index e0de56a609b..08060b50cec 100644 --- a/queue-4.12/series +++ b/queue-4.12/series @@ -15,3 +15,12 @@ nfc-nfcmrvl-fix-firmware-management-initialisation.patch nfc-ensure-presence-of-required-attributes-in-the-activate_target-handler.patch nfc-fix-the-sockaddr-length-sanitization-in-llcp_sock_connect.patch nfc-add-sockaddr-length-checks-before-accessing-sa_family-in-bind-handlers.patch +perf-intel-pt-move-decoder-error-setting-into-one-condition.patch +perf-intel-pt-improve-sample-timestamp.patch +perf-intel-pt-fix-missing-stack-clear.patch +perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch +perf-intel-pt-fix-last_ip-usage.patch +perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch +perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch +perf-intel-pt-clear-fup-flag-on-error.patch +bluetooth-use-constant-time-memory-comparison-for-secret-values.patch