Skip to contentSkip to conversation

perf/arm-cmn: Fix {wp_dev_sel2, wp_dev_sel} limited to 0/1 when MXP_MULTIPLE_DTM_EN is TRUE

PATCH In review Shouping Wang 4 participants 9 messages Aug 19 – Sep 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/arm-cmn: Fix {wp_dev_sel2, wp_dev_sel} limited to 0/1 when MXP_MULTIPLE_DTM_EN is TRUE

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Fix this by applying dev %= 2 to clamp the selection value to the valid range when MXP_MULTIPLE_DTM_EN is TRUE.

Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")
---
 drivers/perf/arm-cmn.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/perf/arm-cmn.c +4 -0
index 40c05c519a1d..13ccbf2a7345 100644
@@ -1392,6 +1392,7 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm,
 
 static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 {
+	struct arm_cmn *cmn = to_cmn(event->pmu);
 	u32 config;
 	u32 dev = CMN_EVENT_WP_DEV_SEL(event);
 	u32 chn = CMN_EVENT_WP_CHN_SEL(event);
@@ -1404,6 +1405,9 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 	if (is_cmn600)
 		grp &= 1;
 
+	if (cmn->multi_dtm)
+		dev %=  2;
+
 	config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
 		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
 		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
Signature · 1 line
2.43.0
author
#1 lore raw

Hi,

Gentle ping on this patch.

Could someone please review it when time permits?

Thanks!
Allen

Quoted 39 lines · Shouping Wang

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Fix this by applying dev %= 2 to clamp the selection value to the valid range when MXP_MULTIPLE_DTM_EN is TRUE.

Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")
---
 drivers/perf/arm-cmn.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/perf/arm-cmn.c +4 -0
index 40c05c519a1d..13ccbf2a7345 100644
@@ -1392,6 +1392,7 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm,
 
 static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 {
+	struct arm_cmn *cmn = to_cmn(event->pmu);
 	u32 config;
 	u32 dev = CMN_EVENT_WP_DEV_SEL(event);
 	u32 chn = CMN_EVENT_WP_CHN_SEL(event);
@@ -1404,6 +1405,9 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 	if (is_cmn600)
 		grp &= 1;
 
+	if (cmn->multi_dtm)
+		dev %=  2;
+
 	config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
 		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
 		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
maintainer
#2 lore raw
Quoted 13 lines · allen.wang

Hi,

Gentle ping on this patch.

Could someone please review it when time permits?

Thanks!
Allen

Quoted 3 lines · Shouping Wang

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Hmm, I read the "each DTM will only use..." wording[1] as implying that the hardware itself would ignore wp_dev_sel2 (especially since that would seem to be the obvious thing to do) - are you saying that that isn't the case? (I've never had access to any actual multi-DTM hardware...)

Thanks,
Robin.

[1] https://support.arm.com/documentation/102308/0307/Debug-trace-and-PMU/Debug-Trace-system-overview/DTM-watchpoint?lang=en

Quoted 36 lines
Quoted 35 lines

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Fix this by applying dev %= 2 to clamp the selection value to the valid range when MXP_MULTIPLE_DTM_EN is TRUE.

Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")
---
  drivers/perf/arm-cmn.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/perf/arm-cmn.c +4 -0
index 40c05c519a1d..13ccbf2a7345 100644
@@ -1392,6 +1392,7 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm,
 
  static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
  {
+	struct arm_cmn *cmn = to_cmn(event->pmu);
  	u32 config;
  	u32 dev = CMN_EVENT_WP_DEV_SEL(event);
  	u32 chn = CMN_EVENT_WP_CHN_SEL(event);
@@ -1404,6 +1405,9 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
  	if (is_cmn600)
  		grp &= 1;
 
+	if (cmn->multi_dtm)
+		dev %=  2;
+
  	config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
  		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
  		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
maintainer
#4 lore raw
In reply to Shouping Wang
Quoted 22 lines · Shouping Wang

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Fix this by applying dev %= 2 to clamp the selection value to the valid range when MXP_MULTIPLE_DTM_EN is TRUE.

Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")
---
  drivers/perf/arm-cmn.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/perf/arm-cmn.c +0 -0
index 40c05c519a1d..13ccbf2a7345 100644

drivers/perf/arm-cmn.c static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm, · line 1395

Quoted 4 lines
drivers/perf/arm-cmn.c +1 -0
@@ -1392,6 +1392,7 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm,
 
  static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
  {
+	struct arm_cmn *cmn = to_cmn(event->pmu);

Nit: may as well refactor the is_cmn600 condition to reference cmn->part directly too.

drivers/perf/arm-cmn.c static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx) · line 1410

Quoted 10 lines
drivers/perf/arm-cmn.c +3 -0
  	u32 config;
  	u32 dev = CMN_EVENT_WP_DEV_SEL(event);
  	u32 chn = CMN_EVENT_WP_CHN_SEL(event);
@@ -1404,6 +1405,9 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
  	if (is_cmn600)
  		grp &= 1;
 
+	if (cmn->multi_dtm)
+		dev %=  2;
+

Let's just make the whole setting of CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 conditional on !multi_dtm, like for exclusive and combine further down (note that the CMN-600 "grp &= 1" is different, since that's more about sanitising invalid input values rather than the register encoding itself.)

Thanks,
Robin.

Quoted 3 lines
drivers/perf/arm-cmn.c +0 -0
  	config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
  		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
  		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
#5 lore raw

PATCH v2 1/1 perf/arm-cmn: Fix wp_dev_sel2 setting for multi-DTM configurations

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Fix this by only setting CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 when !multi_dtm.

Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")

---

Changes in v2:
- Made the setting of CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 conditional on !multi_dtm, instead of clamping with dev %= 2.
- Refactored is_cmn600 to use cmn->part directly.
- Updated the commit message.

Link to v1: https://lore.kernel.org/lkml/[email protected]/

 drivers/perf/arm-cmn.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/perf/arm-cmn.c +7 -3
index 6e5cc4086a9e..7e7590381171 100644
@@ -1393,13 +1393,14 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm,
 
 static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 {
+	struct arm_cmn *cmn = to_cmn(event->pmu);
 	u32 config;
 	u32 dev = CMN_EVENT_WP_DEV_SEL(event);
 	u32 chn = CMN_EVENT_WP_CHN_SEL(event);
 	u32 grp = CMN_EVENT_WP_GRP(event);
 	u32 exc = CMN_EVENT_WP_EXCLUSIVE(event);
 	u32 combine = CMN_EVENT_WP_COMBINE(event);
-	bool is_cmn600 = to_cmn(event->pmu)->part == PART_CMN600;
+	bool is_cmn600 = cmn->part == PART_CMN600;
 
 	/* CMN-600 supports only primary and secondary matching groups */
 	if (is_cmn600)
@@ -1407,8 +1408,11 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 
 	config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
 		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
-		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
-		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL2, dev >> 1);
+		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp);
+
+	if (!cmn->multi_dtm)
+		config |= FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL2, dev >> 1);
+
 	if (exc)
 		config |= is_cmn600 ? CMN600_WPn_CONFIG_WP_EXCLUSIVE :
 				      CMN_DTM_WPn_CONFIG_WP_EXCLUSIVE;
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v2] perf/arm-cmn: Fix wp_dev_sel2 setting for multi-DTM configurations

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Quoted 5 lines

Fix this by only setting CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 when !multi_dtm.

Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v2 1/1
#7 lore raw

Re: [PATCH v2] perf/arm-cmn: Fix wp_dev_sel2 setting for multi-DTM configurations

In reply to Shouping Wang
Quoted 3 lines · Shouping Wang

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Poor documentation strikes again!

Quoted 6 lines

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

Fix this by only setting CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 when !multi_dtm.

Thanks for the fix!
Robin.

Quoted 49 lines
Fixes 60d1504070c2 ("perf/arm-cmn: Support new IP features")

---

Changes in v2:
- Made the setting of CMN_DTM_WPn_CONFIG_WP_DEV_SEL2 conditional on !multi_dtm, instead of clamping with dev %= 2.
- Refactored is_cmn600 to use cmn->part directly.
- Updated the commit message.

Link to v1: https://lore.kernel.org/lkml/[email protected]/

  drivers/perf/arm-cmn.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/perf/arm-cmn.c +7 -3
index 6e5cc4086a9e..7e7590381171 100644
@@ -1393,13 +1393,14 @@ static void arm_cmn_claim_wp_idx(struct arm_cmn_dtm *dtm,
 
  static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
  {
+	struct arm_cmn *cmn = to_cmn(event->pmu);
  	u32 config;
  	u32 dev = CMN_EVENT_WP_DEV_SEL(event);
  	u32 chn = CMN_EVENT_WP_CHN_SEL(event);
  	u32 grp = CMN_EVENT_WP_GRP(event);
  	u32 exc = CMN_EVENT_WP_EXCLUSIVE(event);
  	u32 combine = CMN_EVENT_WP_COMBINE(event);
-	bool is_cmn600 = to_cmn(event->pmu)->part == PART_CMN600;
+	bool is_cmn600 = cmn->part == PART_CMN600;
 
  	/* CMN-600 supports only primary and secondary matching groups */
  	if (is_cmn600)
@@ -1407,8 +1408,11 @@ static u32 arm_cmn_wp_config(struct perf_event *event, int wp_idx)
 
  	config = FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL, dev) |
  		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_CHN_SEL, chn) |
-		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp) |
-		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL2, dev >> 1);
+		 FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_GRP, grp);
+
+	if (!cmn->multi_dtm)
+		config |= FIELD_PREP(CMN_DTM_WPn_CONFIG_WP_DEV_SEL2, dev >> 1);
+
  	if (exc)
  		config |= is_cmn600 ? CMN600_WPn_CONFIG_WP_EXCLUSIVE :
  				      CMN_DTM_WPn_CONFIG_WP_EXCLUSIVE;
maintainer Applied
#8 lore raw

Re: [PATCH v2] perf/arm-cmn: Fix wp_dev_sel2 setting for multi-DTM configurations

In reply to Shouping Wang
Quoted 9 lines · Shouping Wang

When MXP_MULTIPLE_DTM_EN is TRUE, each DTM will monitor at most two device ports. In this case, {wp_dev_sel2, wp_dev_sel} will only use values 2'b00 and 2'b01 per DTM.

Previously the setting allowed values beyond the supported range per DTM, which could cause each DTM to select invalid ports when MXP_MULTIPLE_DTM_EN is TRUE.

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] perf/arm-cmn: Fix wp_dev_sel2 setting for multi-DTM configurations

      https://git.kernel.org/arm64/c/49daa3d668b6

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev