Skip to contentSkip to conversation

coresight: etm3x: Fix buffer overwrite in cntr_val_show()

PATCH In review Kuan-Wei Chiu 5 participants 21 messages Nov 21, 2025 – Nov 28, 2025

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

PATCH 1/1 coresight: etm3x: Fix buffer overwrite in cntr_val_show()

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

 drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
 	if (!coresight_get_mode(drvdata->csdev)) {
 		spin_lock(&drvdata->spinlock);
 		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
+			ret += sprintf(buf + ret, "counter %d: %x\n",
 				       i, config->cntr_val[i]);
 		spin_unlock(&drvdata->spinlock);
 		return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
 
 	for (i = 0; i < drvdata->nr_cntr; i++) {
 		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
 	}
 
 	return ret;
Signature · 1 line
2.52.0.rc2.455.g230fcf2819-goog
reviewer
#1 lore raw
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 26 lines
  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
  	if (!coresight_get_mode(drvdata->csdev)) {
  		spin_lock(&drvdata->spinlock);
  		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
+			ret += sprintf(buf + ret, "counter %d: %x\n",
  				       i, config->cntr_val[i]);
  		spin_unlock(&drvdata->spinlock);
  		return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
 
  	for (i = 0; i < drvdata->nr_cntr; i++) {
  		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
  	}
 
  	return ret;
#2 lore raw

Hi James,

Quoted 25 lines · James Clark
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Quoted 6 lines

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

Thanks for your feedback.

I agree that if any tool relies on the current behavior, this patch would break the ABI and violate the hard rule that we must never break userspace.

However, I am not sure how to determine if any userspace tools are actually using this sysfs interface. Is there a recommended way to verify this, or a standard procedure/convention to follow in this situation?

Regards,
Kuan-Wei

Quoted 31 lines

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 24 lines
  drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
  	if (!coresight_get_mode(drvdata->csdev)) {
  		spin_lock(&drvdata->spinlock);
  		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
+			ret += sprintf(buf + ret, "counter %d: %x\n",
  				       i, config->cntr_val[i]);
  		spin_unlock(&drvdata->spinlock);
  		return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
  	for (i = 0; i < drvdata->nr_cntr; i++) {
  		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
  	}
  	return ret;
reviewer
#3 lore raw
Quoted 41 lines · Kuan-Wei Chiu

Hi James,

Quoted 25 lines · James Clark
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Quoted 6 lines

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

Thanks for your feedback.

I agree that if any tool relies on the current behavior, this patch would break the ABI and violate the hard rule that we must never break userspace.

Quoted 8 lines

However, I am not sure how to determine if any userspace tools are actually using this sysfs interface. Is there a recommended way to verify this, or a standard procedure/convention to follow in this situation?

Regards,
Kuan-Wei

There's no way of knowing apart from deducing that there are 0 users of the 'correct' version of the API because it never existed. This isn't even a regression, it was broken from the beginning.

I suppose it does work when hardware only has one counter, but I don't know how likely that is?

Looking at cntr_val_store() I think I was wrong before when I said it should be a separate file for each counter. Writing to it already writes to the counter currently selected by cntr_idx and splitting it out to separate files would have to break that too. So we can fix the display bug by making show operate on the currently selected counter in the same way as store. Then it makes a bit more sense and we can delete the "counter %d: " prefix.

ETM4 already does it this way too.

Quoted 31 lines
Quoted 31 lines

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 24 lines
   drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
   	if (!coresight_get_mode(drvdata->csdev)) {
   		spin_lock(&drvdata->spinlock);
   		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
+			ret += sprintf(buf + ret, "counter %d: %x\n",
   				       i, config->cntr_val[i]);
   		spin_unlock(&drvdata->spinlock);
   		return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
   	for (i = 0; i < drvdata->nr_cntr; i++) {
   		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
   	}
   	return ret;
#4 lore raw

Hi,

Quoted 69 lines · James Clark
Quoted 41 lines · Kuan-Wei Chiu

Hi James,

Quoted 25 lines · James Clark
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Quoted 6 lines

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

Thanks for your feedback.

I agree that if any tool relies on the current behavior, this patch would break the ABI and violate the hard rule that we must never break userspace.

Quoted 8 lines

However, I am not sure how to determine if any userspace tools are actually using this sysfs interface. Is there a recommended way to verify this, or a standard procedure/convention to follow in this situation?

Regards,
Kuan-Wei

There's no way of knowing apart from deducing that there are 0 users of the 'correct' version of the API because it never existed. This isn't even a regression, it was broken from the beginning.

I suppose it does work when hardware only has one counter, but I don't know how likely that is?

Looking at cntr_val_store() I think I was wrong before when I said it should be a separate file for each counter. Writing to it already writes to the counter currently selected by cntr_idx and splitting it out to separate files would have to break that too. So we can fix the display bug by making show operate on the currently selected counter in the same way as store. Then it makes a bit more sense and we can delete the "counter %d: " prefix.

Quoted 2 lines

ETM4 already does it this way too.

I agree with this.

The difficulty in having a file per counter is that different implementations have different numbers of counters. Rather than complicate the driver by dynamically generating the sysfs files, the single file + selector paradigm makes things easier. The index is validated against the actual number of counters for this instance, and read/write occurs for the selected one.

Regards

Mike

Quoted 32 lines
Quoted 31 lines
Quoted 31 lines

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 24 lines
   drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
    if (!coresight_get_mode(drvdata->csdev)) {
            spin_lock(&drvdata->spinlock);
            for (i = 0; i < drvdata->nr_cntr; i++)
-                   ret += sprintf(buf, "counter %d: %x\n",
+                   ret += sprintf(buf + ret, "counter %d: %x\n",
                                   i, config->cntr_val[i]);
            spin_unlock(&drvdata->spinlock);
            return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
    for (i = 0; i < drvdata->nr_cntr; i++) {
            val = etm_readl(drvdata, ETMCNTVRn(i));
-           ret += sprintf(buf, "counter %d: %x\n", i, val);
+           ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
    }
    return ret;
Signature · 3 lines
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
reviewer
#5 lore raw
Quoted 72 lines · Mike Leach

Hi,

Quoted 69 lines · James Clark
Quoted 41 lines · Kuan-Wei Chiu

Hi James,

Quoted 25 lines · James Clark
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Quoted 6 lines

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

Thanks for your feedback.

I agree that if any tool relies on the current behavior, this patch would break the ABI and violate the hard rule that we must never break userspace.

Quoted 8 lines

However, I am not sure how to determine if any userspace tools are actually using this sysfs interface. Is there a recommended way to verify this, or a standard procedure/convention to follow in this situation?

Regards,
Kuan-Wei

There's no way of knowing apart from deducing that there are 0 users of the 'correct' version of the API because it never existed. This isn't even a regression, it was broken from the beginning.

I suppose it does work when hardware only has one counter, but I don't know how likely that is?

Looking at cntr_val_store() I think I was wrong before when I said it should be a separate file for each counter. Writing to it already writes to the counter currently selected by cntr_idx and splitting it out to separate files would have to break that too. So we can fix the display bug by making show operate on the currently selected counter in the same way as store. Then it makes a bit more sense and we can delete the "counter %d: " prefix.

Quoted 7 lines
Quoted 2 lines

ETM4 already does it this way too.

I agree with this.

The difficulty in having a file per counter is that different implementations have different numbers of counters. Rather than complicate the driver by dynamically generating the sysfs files, the

It wouldn't be that hard because there is a maximum number of counters. You'd generate them all and then use the is_visible() thing to hide ones that didn't exist on that device.

But it looks like we don't want to do it that way for other reasons anyway.

Quoted 42 lines

single file + selector paradigm makes things easier. The index is validated against the actual number of counters for this instance, and read/write occurs for the selected one.

Regards

Mike

Quoted 32 lines
Quoted 31 lines
Quoted 31 lines

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 24 lines
    drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
     if (!coresight_get_mode(drvdata->csdev)) {
             spin_lock(&drvdata->spinlock);
             for (i = 0; i < drvdata->nr_cntr; i++)
-                   ret += sprintf(buf, "counter %d: %x\n",
+                   ret += sprintf(buf + ret, "counter %d: %x\n",
                                    i, config->cntr_val[i]);
             spin_unlock(&drvdata->spinlock);
             return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
     for (i = 0; i < drvdata->nr_cntr; i++) {
             val = etm_readl(drvdata, ETMCNTVRn(i));
-           ret += sprintf(buf, "counter %d: %x\n", i, val);
+           ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
     }
     return ret;
#6 lore raw
Quoted 83 lines · James Clark
Quoted 72 lines · Mike Leach

Hi,

Quoted 69 lines · James Clark
Quoted 41 lines · Kuan-Wei Chiu

Hi James,

Quoted 25 lines · James Clark
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Quoted 6 lines

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

Thanks for your feedback.

I agree that if any tool relies on the current behavior, this patch would break the ABI and violate the hard rule that we must never break userspace.

Quoted 8 lines

However, I am not sure how to determine if any userspace tools are actually using this sysfs interface. Is there a recommended way to verify this, or a standard procedure/convention to follow in this situation?

Regards,
Kuan-Wei

There's no way of knowing apart from deducing that there are 0 users of the 'correct' version of the API because it never existed. This isn't even a regression, it was broken from the beginning.

I suppose it does work when hardware only has one counter, but I don't know how likely that is?

Looking at cntr_val_store() I think I was wrong before when I said it should be a separate file for each counter. Writing to it already writes to the counter currently selected by cntr_idx and splitting it out to separate files would have to break that too. So we can fix the display bug by making show operate on the currently selected counter in the same way as store. Then it makes a bit more sense and we can delete the "counter %d: " prefix.

Quoted 7 lines
Quoted 2 lines

ETM4 already does it this way too.

I agree with this.

The difficulty in having a file per counter is that different implementations have different numbers of counters. Rather than complicate the driver by dynamically generating the sysfs files, the

Quoted 6 lines

It wouldn't be that hard because there is a maximum number of counters. You'd generate them all and then use the is_visible() thing to hide ones that didn't exist on that device.

But it looks like we don't want to do it that way for other reasons anyway.

I don't feel it is my place to say whether the etm3x driver should be removed entirely.

However, if we decide to keep it, I agree that aligning cntr_val_show with the cntr_val_store behavior (using cntr_idx) makes more sense.

Here is my plan for v2:

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +4 -11
index 762109307b86..77578885e8f3 100644
@@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event);
 static ssize_t cntr_val_show(struct device *dev,
 			     struct device_attribute *attr, char *buf)
 {
-	int i, ret = 0;
 	u32 val;
 	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	struct etm_config *config = &drvdata->config;
 
 	if (!coresight_get_mode(drvdata->csdev)) {
 		spin_lock(&drvdata->spinlock);
-		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
-				       i, config->cntr_val[i]);
+		val = config->cntr_val[config->cntr_idx];
 		spin_unlock(&drvdata->spinlock);
-		return ret;
-	}
-
-	for (i = 0; i < drvdata->nr_cntr; i++) {
-		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		return sprintf(buf, "%x\n", val);
 	}
 
-	return ret;
+	val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));
+	return sprintf(buf, "%x\n", val);
 }
 
 static ssize_t cntr_val_store(struct device *dev,

Given the upcoming merge window, I plan to submit this v2 after -rc1 is released.

Alternatively, if the consensus is to drop the driver, I am happy to submit a patch for that instead.

Regards,
Kuan-Wei

Quoted 43 lines
Quoted 42 lines

single file + selector paradigm makes things easier. The index is validated against the actual number of counters for this instance, and read/write occurs for the selected one.

Regards

Mike

Quoted 32 lines
Quoted 31 lines
Quoted 31 lines

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 24 lines
    drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
     if (!coresight_get_mode(drvdata->csdev)) {
             spin_lock(&drvdata->spinlock);
             for (i = 0; i < drvdata->nr_cntr; i++)
-                   ret += sprintf(buf, "counter %d: %x\n",
+                   ret += sprintf(buf + ret, "counter %d: %x\n",
                                    i, config->cntr_val[i]);
             spin_unlock(&drvdata->spinlock);
             return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
     for (i = 0; i < drvdata->nr_cntr; i++) {
             val = etm_readl(drvdata, ETMCNTVRn(i));
-           ret += sprintf(buf, "counter %d: %x\n", i, val);
+           ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
     }
     return ret;
reviewer
#7 lore raw
Quoted 136 lines · Kuan-Wei Chiu
Quoted 83 lines · James Clark
Quoted 72 lines · Mike Leach

Hi,

Quoted 69 lines · James Clark
Quoted 41 lines · Kuan-Wei Chiu

Hi James,

Quoted 25 lines · James Clark
Quoted 16 lines · Kuan-Wei Chiu

The cntr_val_show() function is meant to display the values of all available counters. However, the sprintf() call inside the loop was always writing to the beginning of the buffer, causing the output of previous iterations to be overwritten. As a result, only the value of the last counter was actually returned to the user.

Fix this by using the return value of sprintf() to calculate the correct offset into the buffer for the next write, ensuring that all counter values are appended sequentially.

Fixes a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")

---
Build tested only. I do not have the hardware to run the etm3x driver, so I would be grateful if someone could verify this on actual hardware.

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

Quoted 6 lines

Nice find. I think the point that it wasn't caught changes how we fix it. Either nobody used it ever - so we can just delete it. Or someone was using it and they expect it to always return a single entry with the value of the last counter and this is a potentially breaking change. So maybe instead of fixing this we should add a new cntr_vals_show() which works correctly. But then again if nobody is using it we shouldn't do that either.

Thanks for your feedback.

I agree that if any tool relies on the current behavior, this patch would break the ABI and violate the hard rule that we must never break userspace.

Quoted 8 lines

However, I am not sure how to determine if any userspace tools are actually using this sysfs interface. Is there a recommended way to verify this, or a standard procedure/convention to follow in this situation?

Regards,
Kuan-Wei

There's no way of knowing apart from deducing that there are 0 users of the 'correct' version of the API because it never existed. This isn't even a regression, it was broken from the beginning.

I suppose it does work when hardware only has one counter, but I don't know how likely that is?

Looking at cntr_val_store() I think I was wrong before when I said it should be a separate file for each counter. Writing to it already writes to the counter currently selected by cntr_idx and splitting it out to separate files would have to break that too. So we can fix the display bug by making show operate on the currently selected counter in the same way as store. Then it makes a bit more sense and we can delete the "counter %d: " prefix.

Quoted 7 lines
Quoted 2 lines

ETM4 already does it this way too.

I agree with this.

The difficulty in having a file per counter is that different implementations have different numbers of counters. Rather than complicate the driver by dynamically generating the sysfs files, the

Quoted 6 lines

It wouldn't be that hard because there is a maximum number of counters. You'd generate them all and then use the is_visible() thing to hide ones that didn't exist on that device.

But it looks like we don't want to do it that way for other reasons anyway.

I don't feel it is my place to say whether the etm3x driver should be removed entirely.

However, if we decide to keep it, I agree that aligning cntr_val_show with the cntr_val_store behavior (using cntr_idx) makes more sense.

Here is my plan for v2:

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +4 -11
index 762109307b86..77578885e8f3 100644
@@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event);
  static ssize_t cntr_val_show(struct device *dev,
  			     struct device_attribute *attr, char *buf)
  {
-	int i, ret = 0;
  	u32 val;
  	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
  	struct etm_config *config = &drvdata->config;
 
  	if (!coresight_get_mode(drvdata->csdev)) {
  		spin_lock(&drvdata->spinlock);
-		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
-				       i, config->cntr_val[i]);
+		val = config->cntr_val[config->cntr_idx];
  		spin_unlock(&drvdata->spinlock);
-		return ret;
-	}
-
-	for (i = 0; i < drvdata->nr_cntr; i++) {
-		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		return sprintf(buf, "%x\n", val);
  	}
 
-	return ret;
+	val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));
+	return sprintf(buf, "%x\n", val);
  }
 
  static ssize_t cntr_val_store(struct device *dev,
Quoted 10 lines

Given the upcoming merge window, I plan to submit this v2 after -rc1 is released.

Alternatively, if the consensus is to drop the driver, I am happy to submit a patch for that instead.

Regards,
Kuan-Wei

The change looks good. I wouldn't wait for rc1, nobody else is touching these files so nothing will change, so makes sense to send it now.

Quoted 43 lines
Quoted 43 lines
Quoted 42 lines

single file + selector paradigm makes things easier. The index is validated against the actual number of counters for this instance, and read/write occurs for the selected one.

Regards

Mike

Quoted 32 lines
Quoted 31 lines
Quoted 31 lines

The interface isn't even that great, it should be a separate file per counter. You don't want to be parsing strings and colons to try to read a single value, especially in C. Separate files allows you to read it directly without any hassle.

Quoted 24 lines
     drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -2
index 762109307b86..312033e74b7a 100644
@@ -725,7 +725,7 @@ static ssize_t cntr_val_show(struct device *dev,
      if (!coresight_get_mode(drvdata->csdev)) {
              spin_lock(&drvdata->spinlock);
              for (i = 0; i < drvdata->nr_cntr; i++)
-                   ret += sprintf(buf, "counter %d: %x\n",
+                   ret += sprintf(buf + ret, "counter %d: %x\n",
                                     i, config->cntr_val[i]);
              spin_unlock(&drvdata->spinlock);
              return ret;
@@ -733,7 +733,7 @@ static ssize_t cntr_val_show(struct device *dev,
      for (i = 0; i < drvdata->nr_cntr; i++) {
              val = etm_readl(drvdata, ETMCNTVRn(i));
-           ret += sprintf(buf, "counter %d: %x\n", i, val);
+           ret += sprintf(buf + ret, "counter %d: %x\n", i, val);
      }
      return ret;
reviewer
#8 lore raw
In reply to Kuan-Wei Chiu

On Thu, Nov 27, 2025 at 04:44:53PM +0800, Kuan-Wei Chiu wrote:

[...]

Quoted 2 lines

I don't feel it is my place to say whether the etm3x driver should be removed entirely.

Sorry for confusion. Your fix patch is welcome, this is useful no matter if remove the ETMv3 driver or not.

Quoted 26 lines

However, if we decide to keep it, I agree that aligning cntr_val_show with the cntr_val_store behavior (using cntr_idx) makes more sense.

Here is my plan for v2:

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -5
index 762109307b86..77578885e8f3 100644
@@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event);
 static ssize_t cntr_val_show(struct device *dev,
 			     struct device_attribute *attr, char *buf)
 {
-	int i, ret = 0;
 	u32 val;
 	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
 	struct etm_config *config = &drvdata->config;
 
 	if (!coresight_get_mode(drvdata->csdev)) {
 		spin_lock(&drvdata->spinlock);
-		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
-				       i, config->cntr_val[i]);
+		val = config->cntr_val[config->cntr_idx];
 		spin_unlock(&drvdata->spinlock);
-		return ret;

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static DEVICE_ATTR_RW(cntr_rld_event); · line 731

Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -6
-	}
-
-	for (i = 0; i < drvdata->nr_cntr; i++) {
-		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		return sprintf(buf, "%x\n", val);
 	}
 
-	return ret;
+	val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));

It is not right to read register at here (it cannot promise to read the CPU (cp14) register on the target CPU).

Please refer to the same function in coresight-etm4x-sysfs.c. I think we can do the same thing at here.

Quoted 11 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -0
+	return sprintf(buf, "%x\n", val);
 }
 
 static ssize_t cntr_val_store(struct device *dev,

Given the upcoming merge window, I plan to submit this v2 after -rc1 is released.

Alternatively, if the consensus is to drop the driver, I am happy to submit a patch for that instead.

Please continue this patch. Thanks a lot!

Leo

reviewer
#9 lore raw
Quoted 44 lines · Leo Yan

On Thu, Nov 27, 2025 at 04:44:53PM +0800, Kuan-Wei Chiu wrote:

[...]

Quoted 2 lines

I don't feel it is my place to say whether the etm3x driver should be removed entirely.

Sorry for confusion. Your fix patch is welcome, this is useful no matter if remove the ETMv3 driver or not.

Quoted 34 lines

However, if we decide to keep it, I agree that aligning cntr_val_show with the cntr_val_store behavior (using cntr_idx) makes more sense.

Here is my plan for v2:

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -10
index 762109307b86..77578885e8f3 100644
@@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event);
  static ssize_t cntr_val_show(struct device *dev,
  			     struct device_attribute *attr, char *buf)
  {
-	int i, ret = 0;
  	u32 val;
  	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
  	struct etm_config *config = &drvdata->config;
 
  	if (!coresight_get_mode(drvdata->csdev)) {
  		spin_lock(&drvdata->spinlock);
-		for (i = 0; i < drvdata->nr_cntr; i++)
-			ret += sprintf(buf, "counter %d: %x\n",
-				       i, config->cntr_val[i]);
+		val = config->cntr_val[config->cntr_idx];
  		spin_unlock(&drvdata->spinlock);
-		return ret;
-	}
-
-	for (i = 0; i < drvdata->nr_cntr; i++) {
-		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		return sprintf(buf, "%x\n", val);
  	}
 
Quoted 9 lines

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static DEVICE_ATTR_RW(cntr_rld_event); · line 731

Quoted 2 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -1
-	return ret;
+	val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));

It is not right to read register at here (it cannot promise to read the CPU (cp14) register on the target CPU).

Please refer to the same function in coresight-etm4x-sysfs.c. I think we can do the same thing at here.

That's a different fix than the display bug though. This change doesn't change that if it's already wrong. The display fix should go in alone and then if there is an issue with not running things on the right CPU that should go in separately.

Quoted 15 lines
Quoted 11 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -0
+	return sprintf(buf, "%x\n", val);
  }
 
  static ssize_t cntr_val_store(struct device *dev,

Given the upcoming merge window, I plan to submit this v2 after -rc1 is released.

Alternatively, if the consensus is to drop the driver, I am happy to submit a patch for that instead.

Please continue this patch. Thanks a lot!

Leo

reviewer
#10 lore raw

On Thu, Nov 27, 2025 at 09:30:28AM +0000, James Clark wrote:

[...]

Quoted 11 lines
Quoted 11 lines

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static DEVICE_ATTR_RW(cntr_rld_event); · line 731

Quoted 7 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +2 -4
-	for (i = 0; i < drvdata->nr_cntr; i++) {
-		val = etm_readl(drvdata, ETMCNTVRn(i));
-		ret += sprintf(buf, "counter %d: %x\n", i, val);
+		return sprintf(buf, "%x\n", val);
  	}
-	return ret;
+	val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));

It is not right to read register at here (it cannot promise to read the CPU (cp14) register on the target CPU).

Quoted 8 lines
Quoted 3 lines

Please refer to the same function in coresight-etm4x-sysfs.c. I think we can do the same thing at here.

That's a different fix than the display bug though. This change doesn't change that if it's already wrong. The display fix should go in alone and then if there is an issue with not running things on the right CPU that should go in separately.

Makes sense. So the pasted change is fine for me.

Thanks for correcting!

#11 lore raw
In reply to James Clark

Slight simplification...

Quoted 32 lines · James Clark
Quoted 28 lines · Leo Yan

On Thu, Nov 27, 2025 at 04:44:53PM +0800, Kuan-Wei Chiu wrote:

[...]

Quoted 2 lines

I don't feel it is my place to say whether the etm3x driver should be removed entirely.

Sorry for confusion. Your fix patch is welcome, this is useful no matter if remove the ETMv3 driver or not.

Quoted 18 lines

However, if we decide to keep it, I agree that aligning cntr_val_show with the cntr_val_store behavior (using cntr_idx) makes more sense.

Here is my plan for v2:

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +0 -1
index 762109307b86..77578885e8f3 100644
@@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event);
  static ssize_t cntr_val_show(struct device *dev,
                          struct device_attribute *attr, char *buf)
  {
-    int i, ret = 0;
     u32 val;
     struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
     struct etm_config *config = &drvdata->config;
 
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -3
     if (!coresight_get_mode(drvdata->csdev)) {
             spin_lock(&drvdata->spinlock);
-            for (i = 0; i < drvdata->nr_cntr; i++)
-                    ret += sprintf(buf, "counter %d: %x\n",
-                                   i, config->cntr_val[i]);
+            val = config->cntr_val[config->cntr_idx];
Quoted 8 lines

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static DEVICE_ATTR_RW(cntr_rld_event); · line 728

Quoted 8 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -6
             spin_unlock(&drvdata->spinlock);
-            return ret;
-    }
-
-    for (i = 0; i < drvdata->nr_cntr; i++) {
-            val = etm_readl(drvdata, ETMCNTVRn(i));
-            ret += sprintf(buf, "counter %d: %x\n", i, val);
+            return sprintf(buf, "%x\n", val);

remove this return...

Quoted 3 lines
Quoted 3 lines

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static DEVICE_ATTR_RW(cntr_rld_event); · line 739

Quoted 3 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +0 -1
     }
 
-    return ret;

else here to set val.

Quoted 5 lines
Quoted 5 lines

drivers/hwtracing/coresight/coresight-etm3x-sysfs.c static DEVICE_ATTR_RW(cntr_rld_event); · line 731

Quoted 1 line
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -0
+    val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));

It is not right to read register at here (it cannot promise to read the CPU (cp14) register on the target CPU).

Quoted 10 lines
Quoted 3 lines

Please refer to the same function in coresight-etm4x-sysfs.c. I think we can do the same thing at here.

That's a different fix than the display bug though. This change doesn't change that if it's already wrong. The display fix should go in alone and then if there is an issue with not running things on the right CPU that should go in separately.

Quoted 1 line
Quoted 1 line
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +1 -0
+    return sprintf(buf, "%x\n", val);

just this return point - but emit_sysfs is now the standard way to do this, since we are making a change.

Mike

Quoted 15 lines
Quoted 14 lines
Quoted 10 lines
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +0 -0
  }
 
  static ssize_t cntr_val_store(struct device *dev,

Given the upcoming merge window, I plan to submit this v2 after -rc1 is released.

Alternatively, if the consensus is to drop the driver, I am happy to submit a patch for that instead.

Please continue this patch. Thanks a lot!

Leo

Signature · 3 lines
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
reviewer
#12 lore raw
In reply to Kuan-Wei Chiu

On Fri, Nov 21, 2025 at 12:23:50AM +0000, Kuan-Wei Chiu wrote:

[...]

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

I have a question for maintainers.

The ETMv4 architecture specification shows that ETMv4 was released as a non-confidential module in May 2013 (with the confidential release even a year earlier). So ETMv4 has been a public IP for more than 12+ years, and ETMv3 has been gradually retired since then.

This fix can still be applied to older kernels, but seems to me that now might be an appropriate time to consider removing the ETMv3 driver from the mainline kernel?

Thanks,
Leo

reviewer
#13 lore raw
Quoted 17 lines · Leo Yan

On Fri, Nov 21, 2025 at 12:23:50AM +0000, Kuan-Wei Chiu wrote:

[...]

Quoted 5 lines

I noticed this issue while browsing the coresight code after attending a technical talk on the subject. This code dates back to the initial driver submission over 10 years ago, so I was surprised it hadn't been caught earlier. Although I cannot perform runtime testing, the logic error seems obvious to me, so I still decided to submit this patch.

I have a question for maintainers.

The ETMv4 architecture specification shows that ETMv4 was released as a non-confidential module in May 2013 (with the confidential release even a year earlier). So ETMv4 has been a public IP for more than 12+ years, and ETMv3 has been gradually retired since then.

Quoted 6 lines

This fix can still be applied to older kernels, but seems to me that now might be an appropriate time to consider removing the ETMv3 driver from the mainline kernel?

Thanks,
Leo

Yeah, if anyone is using it it would be on an old kernel surely?

reviewer
#14 lore raw

On Wed, Nov 26, 2025 at 12:11:05PM +0000, James Clark wrote:

[...]

Quoted 5 lines
Quoted 3 lines

This fix can still be applied to older kernels, but seems to me that now might be an appropriate time to consider removing the ETMv3 driver from the mainline kernel?

Yeah, if anyone is using it it would be on an old kernel surely?

We can confirm this in another way: if I don't miss anything, over the past several years (since 2017), we have not received any questions or bug reports based on hands-on practice regarding ETMv3 on the Coresight or perf mailing lists.

Thanks,
Leo

#15 lore raw

Hi,

Quoted 11 lines · Leo Yan

On Wed, Nov 26, 2025 at 12:11:05PM +0000, James Clark wrote:

[...]

Quoted 5 lines
Quoted 3 lines

This fix can still be applied to older kernels, but seems to me that now might be an appropriate time to consider removing the ETMv3 driver from the mainline kernel?

Yeah, if anyone is using it it would be on an old kernel surely?

Quoted 7 lines

We can confirm this in another way: if I don't miss anything, over the past several years (since 2017), we have not received any questions or bug reports based on hands-on practice regarding ETMv3 on the Coresight or perf mailing lists.

Thanks,
Leo

The key to this is not the questions we are asked, but which platforms are still supported by the linux kernel.

The ETMv3 driver supports both ETMv3 and PTM trace (the programming model is the same, even if the trace decode is vastly different).

So as long as there are platforms supported that use either of those, we need to keep the driver in.

Mike

Signature · 3 lines
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
reviewer
#16 lore raw
Quoted 25 lines · Mike Leach

Hi,

Quoted 11 lines · Leo Yan

On Wed, Nov 26, 2025 at 12:11:05PM +0000, James Clark wrote:

[...]

Quoted 5 lines
Quoted 3 lines

This fix can still be applied to older kernels, but seems to me that now might be an appropriate time to consider removing the ETMv3 driver from the mainline kernel?

Yeah, if anyone is using it it would be on an old kernel surely?

Quoted 7 lines

We can confirm this in another way: if I don't miss anything, over the past several years (since 2017), we have not received any questions or bug reports based on hands-on practice regarding ETMv3 on the Coresight or perf mailing lists.

Thanks,
Leo

The key to this is not the questions we are asked, but which platforms are still supported by the linux kernel.

Quoted 8 lines

The ETMv3 driver supports both ETMv3 and PTM trace (the programming model is the same, even if the trace decode is vastly different).

So as long as there are platforms supported that use either of those, we need to keep the driver in.

Mike

We're not running tests though, so if we find out it's fundamentally broken somehow it could be another justification to remove it, even if the kernel supports the devices. Do you have a board that you can test on Mike?

Maintenance hasn't been zero cost either, even build testing for arm32 is annoying enough.

#17 lore raw
Quoted 35 lines · James Clark
Quoted 31 lines · Mike Leach

Hi,

Quoted 11 lines · Leo Yan

On Wed, Nov 26, 2025 at 12:11:05PM +0000, James Clark wrote:

[...]

Quoted 5 lines
Quoted 3 lines

This fix can still be applied to older kernels, but seems to me that now might be an appropriate time to consider removing the ETMv3 driver from the mainline kernel?

Yeah, if anyone is using it it would be on an old kernel surely?

Quoted 7 lines

We can confirm this in another way: if I don't miss anything, over the past several years (since 2017), we have not received any questions or bug reports based on hands-on practice regarding ETMv3 on the Coresight or perf mailing lists.

Thanks,
Leo

The key to this is not the questions we are asked, but which platforms are still supported by the linux kernel.

The ETMv3 driver supports both ETMv3 and PTM trace (the programming model is the same, even if the trace decode is vastly different).

So as long as there are platforms supported that use either of those, we need to keep the driver in.

Quoted 8 lines
Quoted 2 lines

Mike

We're not running tests though, so if we find out it's fundamentally broken somehow it could be another justification to remove it, even if the kernel supports the devices. Do you have a board that you can test on Mike?

Don't have one myself, but I believe the TC2 was used in development, (that's the A15/A7 32 bit part - not total compute!) which somewhat conveniently had both etmv3 and ptm trace.

Quoted 3 lines

Maintenance hasn't been zero cost either, even build testing for arm32 is annoying enough.

Pretty much the seem for any of the arm32 drivers I guess.

Until arm32 kernels are no longer supported, not sure it is safe to drop the etm3 driver as we do not know who out there might be using it.

Mike

--
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

reviewer
#18 lore raw

On Wed, Nov 26, 2025 at 04:14:19PM +0000, Mike Leach wrote:

[...]

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

The key to this is not the questions we are asked, but which platforms are still supported by the linux kernel.

The ETMv3 driver supports both ETMv3 and PTM trace (the programming model is the same, even if the trace decode is vastly different).

So as long as there are platforms supported that use either of those, we need to keep the driver in.

Quoted 8 lines
Quoted 4 lines

We're not running tests though, so if we find out it's fundamentally broken somehow it could be another justification to remove it, even if the kernel supports the devices. Do you have a board that you can test on Mike?

Don't have one myself, but I believe the TC2 was used in development, (that's the A15/A7 32 bit part - not total compute!) which somewhat conveniently had both etmv3 and ptm trace.

If ETMv4 can be used by Armv7 (arm32) CPUs, and nowdays if Armv7 + ETMv4 is a popular design, it makes sense for me to remove ETMv3 driver.

If Armv7 CPUs are always bound to ETMv3 / PTM, then we should keep the driver.

Thanks,
Leo

reviewer
#19 lore raw
Quoted 23 lines · Leo Yan

On Wed, Nov 26, 2025 at 04:14:19PM +0000, Mike Leach wrote:

[...]

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

The key to this is not the questions we are asked, but which platforms are still supported by the linux kernel.

The ETMv3 driver supports both ETMv3 and PTM trace (the programming model is the same, even if the trace decode is vastly different).

So as long as there are platforms supported that use either of those, we need to keep the driver in.

Quoted 8 lines
Quoted 4 lines

We're not running tests though, so if we find out it's fundamentally broken somehow it could be another justification to remove it, even if the kernel supports the devices. Do you have a board that you can test on Mike?

Don't have one myself, but I believe the TC2 was used in development, (that's the A15/A7 32 bit part - not total compute!) which somewhat conveniently had both etmv3 and ptm trace.

Quoted 8 lines

If ETMv4 can be used by Armv7 (arm32) CPUs, and nowdays if Armv7 + ETMv4 is a popular design, it makes sense for me to remove ETMv3 driver.

If Armv7 CPUs are always bound to ETMv3 / PTM, then we should keep the driver.

Thanks,
Leo

Based on the the build system I don't think what the hardware supports matters that much. We've always only built the ETM4 driver on Arm64 and only build the ETM3 driver on Arm32.

I just found another bug which I think makes sense to log here. We've pretty much always turned on timestamps automatically in Perf, but for some reason the option validator in Perf thinks they're not supported in ETM3. The driver has always accepted it as an option so I'm not sure why. The end result is that the command will always fail, and you couldn't even undo it with "timestamp=0" until more recently when I fixed that.

Sysfs or per-thread Perf mode would be working, but it's one more bit of evidence to take in.

#20 lore raw
Quoted 3 lines

Based on the the build system I don't think what the hardware supports matters that much. We've always only built the ETM4 driver on Arm64 and only build the ETM3 driver on Arm32.

ETMv3/PTM don't support Arm64, so a trace driver in an Arm64 kernel will only need to drive ETMv4 (or ETE). There's no need to build ETMv3/PTM in 64-bit kernels.

But a 32-bit kernel could be running on a CPU with ETMv4 - this could be a legacy 32-bit kernel on a 64-bit-capable CPU, but there are pure 32-bit CPUs with ETMv4: Cortex-A32 is a 32-bit-only Armv8-A CPU with ETMv4 and all kernels on this CPU will be 32-bit. If the 32-bit kernel only builds the ETMv3/PTM driver, then it won't support trace on this CPU.

Al

Quoted 14 lines

I just found another bug which I think makes sense to log here. We've pretty much always turned on timestamps automatically in Perf, but for some reason the option validator in Perf thinks they're not supported in ETM3. The driver has always accepted it as an option so I'm not sure why. The end result is that the command will always fail, and you couldn't even undo it with "timestamp=0" until more recently when I fixed that.

Sysfs or per-thread Perf mode would be working, but it's one more bit of evidence to take in.

_______________________________________________
CoreSight mailing list -- [email protected] To unsubscribe send an email to [email protected]