From 71c85404178db5e8ef7acd11dc051c7af7ccf8d4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sat, 22 Jul 2017 15:09:03 +0200 Subject: [PATCH] 4.9-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 --- ...-memory-comparison-for-secret-values.patch | 180 ++++++++++++++++++ ...erf-intel-pt-clear-fup-flag-on-error.patch | 34 ++++ ...o-when-state-is-intel_pt_state_no_ip.patch | 32 ++++ ...et-last_ip-when-packet-count-is-zero.patch | 48 +++++ .../perf-intel-pt-fix-last_ip-usage.patch | 104 ++++++++++ ...erf-intel-pt-fix-missing-stack-clear.patch | 32 ++++ ...rf-intel-pt-improve-sample-timestamp.patch | 114 +++++++++++ ...der-error-setting-into-one-condition.patch | 48 +++++ ...e-fup-always-when-scanning-for-an-ip.patch | 45 +++++ queue-4.9/series | 9 + 10 files changed, 646 insertions(+) create mode 100644 queue-4.9/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch create mode 100644 queue-4.9/perf-intel-pt-clear-fup-flag-on-error.patch create mode 100644 queue-4.9/perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch create mode 100644 queue-4.9/perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch create mode 100644 queue-4.9/perf-intel-pt-fix-last_ip-usage.patch create mode 100644 queue-4.9/perf-intel-pt-fix-missing-stack-clear.patch create mode 100644 queue-4.9/perf-intel-pt-improve-sample-timestamp.patch create mode 100644 queue-4.9/perf-intel-pt-move-decoder-error-setting-into-one-condition.patch create mode 100644 queue-4.9/perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch diff --git a/queue-4.9/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch b/queue-4.9/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch new file mode 100644 index 00000000000..42f107a1b6e --- /dev/null +++ b/queue-4.9/bluetooth-use-constant-time-memory-comparison-for-secret-values.patch @@ -0,0 +1,180 @@ +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 | 35 ++++++++++++++++++----------------- + 1 file changed, 18 insertions(+), 17 deletions(-) + +--- a/net/bluetooth/smp.c ++++ b/net/bluetooth/smp.c +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -506,7 +507,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) +@@ -559,7 +560,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; +@@ -973,7 +974,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; + } +@@ -1473,7 +1474,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++; +@@ -1857,7 +1858,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; + } + } +@@ -2122,7 +2123,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), +@@ -2603,7 +2604,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; + } + +@@ -2636,7 +2637,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) { +@@ -2735,7 +2736,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) { +@@ -3446,7 +3447,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; +@@ -3476,7 +3477,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; +@@ -3501,7 +3502,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; +@@ -3533,7 +3534,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; +@@ -3567,10 +3568,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; +@@ -3603,7 +3604,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; +@@ -3657,7 +3658,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.9/perf-intel-pt-clear-fup-flag-on-error.patch b/queue-4.9/perf-intel-pt-clear-fup-flag-on-error.patch new file mode 100644 index 00000000000..94e3ab794c8 --- /dev/null +++ b/queue-4.9/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 +@@ -1960,6 +1960,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.9/perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch b/queue-4.9/perf-intel-pt-ensure-ip-is-zero-when-state-is-intel_pt_state_no_ip.patch new file mode 100644 index 00000000000..d3565a5708c --- /dev/null +++ b/queue-4.9/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 +@@ -2115,6 +2115,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.9/perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch b/queue-4.9/perf-intel-pt-ensure-never-to-set-last_ip-when-packet-count-is-zero.patch new file mode 100644 index 00000000000..2a7a3dcd775 --- /dev/null +++ b/queue-4.9/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 +@@ -1468,7 +1468,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: +@@ -1754,8 +1755,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.9/perf-intel-pt-fix-last_ip-usage.patch b/queue-4.9/perf-intel-pt-fix-last_ip-usage.patch new file mode 100644 index 00000000000..46a29aac660 --- /dev/null +++ b/queue-4.9/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) +@@ -1670,6 +1672,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) +@@ -1750,7 +1754,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; + } + +@@ -1880,7 +1884,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; + +@@ -1930,6 +1934,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) +@@ -2064,6 +2070,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); +@@ -2072,6 +2079,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); +@@ -2114,6 +2122,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.9/perf-intel-pt-fix-missing-stack-clear.patch b/queue-4.9/perf-intel-pt-fix-missing-stack-clear.patch new file mode 100644 index 00000000000..eb4077f3567 --- /dev/null +++ b/queue-4.9/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 +@@ -1930,6 +1930,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.9/perf-intel-pt-improve-sample-timestamp.patch b/queue-4.9/perf-intel-pt-improve-sample-timestamp.patch new file mode 100644 index 00000000000..c9cd84a6670 --- /dev/null +++ b/queue-4.9/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) { +@@ -2067,7 +2089,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; +@@ -2075,7 +2097,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) +@@ -2131,11 +2153,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.9/perf-intel-pt-move-decoder-error-setting-into-one-condition.patch b/queue-4.9/perf-intel-pt-move-decoder-error-setting-into-one-condition.patch new file mode 100644 index 00000000000..cecb4fcd2d2 --- /dev/null +++ b/queue-4.9/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 +@@ -2128,15 +2128,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.9/perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch b/queue-4.9/perf-intel-pt-use-fup-always-when-scanning-for-an-ip.patch new file mode 100644 index 00000000000..c3e9bae2a11 --- /dev/null +++ b/queue-4.9/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 +@@ -1880,14 +1880,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.9/series b/queue-4.9/series index c33f19e9743..46e8e00c8c4 100644 --- a/queue-4.9/series +++ b/queue-4.9/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 -- 2.47.3