Skip to contentSkip to conversation

perf cs-etm: Fix corrupt data after perf inject from

PATCH Applied Leo Yan 4 participants 11 messages Aug 19, 2020 – Sep 2, 2020

Subsystems (3)
lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH 1/2 perf cs-etm: Fix corrupt data after perf inject from

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from CoreSight ETM trace were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/cs-etm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +8 -1
index c283223fb31f..a2a369e2fbb6 100644
@@ -1344,8 +1344,15 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
 	}
 
-	if (etm->synth_opts.last_branch)
+	if (etm->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}
 
 	if (etm->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 2/2 perf intel-pt: Fix corrupt data after perf inject from

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from Intel PT were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/intel-pt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +8 -1
index 2a8d245351e7..0af4e81c46e2 100644
@@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 
 	if (pt->synth_opts.callchain)
 		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-	if (pt->synth_opts.last_branch)
+	if (pt->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}
 
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
Signature · 1 line
2.17.1
reviewer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] perf intel-pt: Fix corrupt data after perf inject from

Quoted 10 lines · Leo Yan

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from Intel PT were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Quoted 3 lines
Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
Quoted 26 lines
---
 tools/perf/util/intel-pt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +8 -1
index 2a8d245351e7..0af4e81c46e2 100644
@@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 
 	if (pt->synth_opts.callchain)
 		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-	if (pt->synth_opts.last_branch)
+	if (pt->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}
 
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] perf intel-pt: Fix corrupt data after perf inject from

In reply to Leo Yan
Quoted 10 lines · Leo Yan

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from Intel PT were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Quoted 3 lines
Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")

Arnaldo, please consider.

Quoted 28 lines
---
 tools/perf/util/intel-pt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +8 -1
index 2a8d245351e7..0af4e81c46e2 100644
@@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 
 	if (pt->synth_opts.callchain)
 		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-	if (pt->synth_opts.last_branch)
+	if (pt->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}
 
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
Signature · 1 line
2.17.1
maintainer Applied
#4 lore raw

Re: [PATCH 2/2] perf intel-pt: Fix corrupt data after perf inject from

Em Mon, Aug 31, 2020 at 02:38:32PM -0600, Mathieu Poirier escreveu:

Quoted 11 lines · Leo Yan
Quoted 10 lines

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from Intel PT were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Quoted 7 lines
Quoted 3 lines
Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")

Arnaldo, please consider.

Thanks, applied, and 1/2 too.

- Arnaldo

Quoted 28 lines
Quoted 28 lines
---
 tools/perf/util/intel-pt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/intel-pt.c +8 -1
index 2a8d245351e7..0af4e81c46e2 100644
@@ -3017,8 +3017,15 @@ static int intel_pt_synth_events(struct intel_pt *pt,
 
 	if (pt->synth_opts.callchain)
 		attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
-	if (pt->synth_opts.last_branch)
+	if (pt->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}
 
 	if (pt->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#5 lore raw
In reply to Leo Yan

Hi Leo and Al,

Quoted 26 lines · Leo Yan

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from CoreSight ETM trace were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/cs-etm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +0 -0
index c283223fb31f..a2a369e2fbb6 100644
@@ -1344,8 +1344,15 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
 	}
 

tools/perf/util/cs-etm.c static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, · line 1355

Quoted 10 lines
tools/perf/util/cs-etm.c +8 -1
-	if (etm->synth_opts.last_branch)
+	if (etm->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}

I've see this patch before... I thought it had been merged - what happened?

Thanks,
Mathieu

Quoted 6 lines
tools/perf/util/cs-etm.c +0 -0
 	if (etm->synth_opts.instructions) {
 		attr.config = PERF_COUNT_HW_INSTRUCTIONS;
Signature · 1 line
2.17.1
author
#6 lore raw

Hi Mathieu,

Quoted 29 lines · Mathieu Poirier

Hi Leo and Al,

Quoted 26 lines · Leo Yan

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from CoreSight ETM trace were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/cs-etm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +0 -0
index c283223fb31f..a2a369e2fbb6 100644
@@ -1344,8 +1344,15 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
 	}
 
Quoted 12 lines

tools/perf/util/cs-etm.c static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, · line 1355

Quoted 10 lines
tools/perf/util/cs-etm.c +8 -1
-	if (etm->synth_opts.last_branch)
+	if (etm->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}

I've see this patch before... I thought it had been merged - what happened?

This patch before has been sent by Al to CoreSight mailing list but has not sent to LKML, this is why I resent it to LKML in case it's missed.

Thanks,
Leo

#7 lore raw

Em Mon, Aug 31, 2020 at 08:04:32AM +0800, Leo Yan escreveu:

Quoted 45 lines

Hi Mathieu,

Quoted 29 lines · Mathieu Poirier

Hi Leo and Al,

Quoted 26 lines · Leo Yan

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from CoreSight ETM trace were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/cs-etm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +0 -0
index c283223fb31f..a2a369e2fbb6 100644
@@ -1344,8 +1344,15 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
 	}
 
Quoted 12 lines

tools/perf/util/cs-etm.c static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, · line 1355

Quoted 10 lines
tools/perf/util/cs-etm.c +8 -1
-	if (etm->synth_opts.last_branch)
+	if (etm->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}

I've see this patch before... I thought it had been merged - what happened?

Quoted 2 lines

This patch before has been sent by Al to CoreSight mailing list but has not sent to LKML, this is why I resent it to LKML in case it's missed.

So, was it Acked on the CoreSight mailing list? Are we missing any Acked-by or Reviewed-by for this 1/2 patch as we got for 2/2?

- Arnaldo

author
#8 lore raw

Hi Arnaldo,

Quoted 46 lines · Arnaldo Carvalho de Melo

Em Mon, Aug 31, 2020 at 08:04:32AM +0800, Leo Yan escreveu:

Quoted 45 lines

Hi Mathieu,

Quoted 41 lines · Mathieu Poirier

Hi Leo and Al,

Quoted 26 lines · Leo Yan

From: Al Grant <[email protected]>

Commit 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack") changed the format of branch stacks in perf samples. When samples use this new format, a flag must be set in the corresponding event. Synthesized branch stacks generated from CoreSight ETM trace were using the new format, but not setting the event attribute, leading to consumers seeing corrupt data. This patch fixes the issue by setting the event attribute to indicate use of the new format.

Fixes 42bbabed09ce ("perf tools: Add hw_idx in struct branch_stack")
---
 tools/perf/util/cs-etm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/cs-etm.c +0 -0
index c283223fb31f..a2a369e2fbb6 100644
@@ -1344,8 +1344,15 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 		attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR;
 	}
 

tools/perf/util/cs-etm.c static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, · line 1355

Quoted 10 lines
tools/perf/util/cs-etm.c +8 -1
-	if (etm->synth_opts.last_branch)
+	if (etm->synth_opts.last_branch) {
 		attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+		/*
+		 * We don't use the hardware index, but the sample generation
+		 * code uses the new format branch_stack with this field,
+		 * so the event attributes must indicate that it's present.
+		 */
+		attr.branch_sample_type |= PERF_SAMPLE_BRANCH_HW_INDEX;
+	}

I've see this patch before... I thought it had been merged - what happened?

Quoted 5 lines
Quoted 2 lines

This patch before has been sent by Al to CoreSight mailing list but has not sent to LKML, this is why I resent it to LKML in case it's missed.

So, was it Acked on the CoreSight mailing list? Are we missing any Acked-by or Reviewed-by for this 1/2 patch as we got for 2/2?

The CoreSight mailing list has some discussion for this patch set, when respin this patch set, I confirmed we don't miss any 'Acked' or 'Reviewed' tags.

Thanks,
Leo

#9 lore raw

Em Wed, Sep 02, 2020 at 08:39:32AM +0800, Leo Yan escreveu:

Quoted 9 lines · Arnaldo Carvalho de Melo
Quoted 7 lines

Em Mon, Aug 31, 2020 at 08:04:32AM +0800, Leo Yan escreveu:

Quoted 6 lines · Mathieu Poirier
Quoted 2 lines · Leo Yan

I've see this patch before... I thought it had been merged - what happened?

This patch before has been sent by Al to CoreSight mailing list but has not sent to LKML, this is why I resent it to LKML in case it's missed.

Quoted 6 lines
Quoted 2 lines

So, was it Acked on the CoreSight mailing list? Are we missing any Acked-by or Reviewed-by for this 1/2 patch as we got for 2/2?

The CoreSight mailing list has some discussion for this patch set, when respin this patch set, I confirmed we don't miss any 'Acked' or 'Reviewed' tags.

So, this patch was included in today's perf-tools-fixes-for-v5.9-2020-09-01 signed tag sent to Linus in a pull req, please update your perf/urgent branch, and go on from there, I'll merge that into my perf/core branch as soon as Linus merges it.

- Arnaldo

author
#10 lore raw
Quoted 13 lines · Arnaldo Carvalho de Melo

Em Wed, Sep 02, 2020 at 08:39:32AM +0800, Leo Yan escreveu:

Quoted 11 lines · Arnaldo Carvalho de Melo
Quoted 10 lines

Em Mon, Aug 31, 2020 at 08:04:32AM +0800, Leo Yan escreveu:

Quoted 6 lines · Mathieu Poirier
Quoted 2 lines · Leo Yan

I've see this patch before... I thought it had been merged - what happened?

This patch before has been sent by Al to CoreSight mailing list but has not sent to LKML, this is why I resent it to LKML in case it's missed.

So, was it Acked on the CoreSight mailing list? Are we missing any Acked-by or Reviewed-by for this 1/2 patch as we got for 2/2?

Quoted 8 lines
Quoted 3 lines

The CoreSight mailing list has some discussion for this patch set, when respin this patch set, I confirmed we don't miss any 'Acked' or 'Reviewed' tags.

So, this patch was included in today's perf-tools-fixes-for-v5.9-2020-09-01 signed tag sent to Linus in a pull req, please update your perf/urgent branch, and go on from there, I'll merge that into my perf/core branch as soon as Linus merges it.

Thanks for the info!

Leo