Currently, CTI driver releases resource by deferring
cti_device_release() to the device unregistration:
cti_remove()
`> coresight_unregister()
`> cti_remove_assoc_from_csdev()
`> device_unregister()
`> cti_device_release()
`> mutex_lock(&ect_mutex)
`> release CTI resource
`> mutex_unlock(&ect_mutex)
In the above flow, two different CTI release callbacks are involved:
cti_remove_assoc_from_csdev() and cti_device_release(). The former is
used by a CoreSight device to unbind its associated CTI helper device,
while the latter releases resources for the CTI device itself. Since
there is no dependency between them, it is unnecessary to defer the CTI
resource release until device unregistration.
This commit releases the resources directly in cti_remove() and remove
the injected release callback.
Signed-off-by: Leo Yan <leo.yan(a)arm.com>
---
drivers/hwtracing/coresight/coresight-cti-core.c | 24 +++---------------------
drivers/hwtracing/coresight/coresight-cti.h | 2 --
2 files changed, 3 insertions(+), 23 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-cti-core.c b/drivers/hwtracing/coresight/coresight-cti-core.c
index bfbc365bb2ef2744efab11c056b8450472957005..7a8f1ef6b94e8ab3363ea62db95b0bc302292cd7 100644
--- a/drivers/hwtracing/coresight/coresight-cti-core.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -823,16 +823,13 @@ static const struct coresight_ops cti_ops = {
.helper_ops = &cti_ops_ect,
};
-/*
- * Free up CTI specific resources
- * called by dev->release, need to call down to underlying csdev release.
- */
-static void cti_device_release(struct device *dev)
+static void cti_remove(struct amba_device *adev)
{
- struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
+ struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
struct cti_drvdata *ect_item, *ect_tmp;
mutex_lock(&ect_mutex);
+ cti_remove_conn_xrefs(drvdata);
cti_pm_release(drvdata);
/* remove from the list */
@@ -844,17 +841,6 @@ static void cti_device_release(struct device *dev)
}
mutex_unlock(&ect_mutex);
- if (drvdata->csdev_release)
- drvdata->csdev_release(dev);
-}
-static void cti_remove(struct amba_device *adev)
-{
- struct cti_drvdata *drvdata = dev_get_drvdata(&adev->dev);
-
- mutex_lock(&ect_mutex);
- cti_remove_conn_xrefs(drvdata);
- mutex_unlock(&ect_mutex);
-
coresight_unregister(drvdata->csdev);
}
@@ -947,10 +933,6 @@ static int cti_probe(struct amba_device *adev, const struct amba_id *id)
cti_update_conn_xrefs(drvdata);
mutex_unlock(&ect_mutex);
- /* set up release chain */
- drvdata->csdev_release = drvdata->csdev->dev.release;
- drvdata->csdev->dev.release = cti_device_release;
-
/* all done - dec pm refcount */
pm_runtime_put(&adev->dev);
dev_info(&drvdata->csdev->dev, "CTI initialized\n");
diff --git a/drivers/hwtracing/coresight/coresight-cti.h b/drivers/hwtracing/coresight/coresight-cti.h
index 4f89091ee93f5fb046d93b97a4085051fca6b39d..daff9e32a6daca90f4d5f4726f163fdd9106191c 100644
--- a/drivers/hwtracing/coresight/coresight-cti.h
+++ b/drivers/hwtracing/coresight/coresight-cti.h
@@ -170,7 +170,6 @@ struct cti_config {
* @spinlock: Control data access to one at a time.
* @config: Configuration data for this CTI device.
* @node: List entry of this device in the list of CTI devices.
- * @csdev_release: release function for underlying coresight_device.
*/
struct cti_drvdata {
void __iomem *base;
@@ -179,7 +178,6 @@ struct cti_drvdata {
raw_spinlock_t spinlock;
struct cti_config config;
struct list_head node;
- void (*csdev_release)(struct device *dev);
};
/*
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260224-arm_coresight_refactor_cti_resource_release-24d9bde4f13c
Best regards,
--
Leo Yan <leo.yan(a)arm.com>
When specifying a 2GB AUX buffer, the ETR driver ends up allocating only
a 1MB buffer instead:
# echo 'file coresight-tmc-etr.c +p' > \
/sys/kernel/debug/dynamic_debug/control
# perf record -e cs_etm/@tmc_etr0,timestamp=0/u -C 0 -m ,2G -- test
coresight tmc_etr0: allocated buffer of size 1024KB in mode 0
The page index is an 'int' type, and shifting it by PAGE_SHIFT overflows
when the resulting value exceeds 2GB. This produces a negative value,
causing the driver to fall back to the minimum buffer size (1MB).
Cast the page index to a wider type to accommodate large buffer sizes.
Also fix a similar issue in the buffer offset calculation.
Reported-by: Michiel van Tol <michiel.vantol(a)arm.com>
Fixes: 99443ea19e8b ("coresight: Add generic TMC sg table framework")
Fixes: eebe8dbd8630 ("coresight: tmc: Decouple the perf buffer allocation from sysfs mode")
Signed-off-by: Leo Yan <leo.yan(a)arm.com>
---
drivers/hwtracing/coresight/coresight-tmc-etr.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index cee82e52c4ea96b035f1db71b2d9a006bfc1c51e..990bbb721e1d712d7b93f1e36087fdaf9d3baa3b 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -154,7 +154,7 @@ tmc_pages_get_offset(struct tmc_pages *tmc_pages, dma_addr_t addr)
for (i = 0; i < tmc_pages->nr_pages; i++) {
page_start = tmc_pages->daddrs[i];
if (addr >= page_start && addr < (page_start + PAGE_SIZE))
- return i * PAGE_SIZE + (addr - page_start);
+ return (long)i * PAGE_SIZE + (addr - page_start);
}
return -EINVAL;
@@ -1381,7 +1381,7 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
node = (event->cpu == -1) ? NUMA_NO_NODE : cpu_to_node(event->cpu);
/* Use the minimum limit if the required size is smaller */
- size = nr_pages << PAGE_SHIFT;
+ size = (ssize_t)nr_pages << PAGE_SHIFT;
size = max_t(ssize_t, size, TMC_ETR_PERF_MIN_BUF_SIZE);
/*
---
base-commit: eebe8dbd8630f51cf70b1f68a440cd3d7f7a914d
change-id: 20260217-arm_coresight_fix_big_buffer_size-a8a41298369d
Best regards,
--
Leo Yan <leo.yan(a)arm.com>
On 19/02/2026 2:46 pm, Jie Gan wrote:
> Acquiring an uninitialized raw_spin_lock is invalid and may trigger
> unexpected behavior or spin_bug.
>
> Fixes: f78d206f3d73 ("Coresight: Add Coresight TMC Control Unit driver")
> Signed-off-by: Jie Gan <jie.gan(a)oss.qualcomm.com>
> ---
> drivers/hwtracing/coresight/coresight-ctcu-core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/hwtracing/coresight/coresight-ctcu-core.c b/drivers/hwtracing/coresight/coresight-ctcu-core.c
> index abed15eb72b4..a505b90c09e3 100644
> --- a/drivers/hwtracing/coresight/coresight-ctcu-core.c
> +++ b/drivers/hwtracing/coresight/coresight-ctcu-core.c
> @@ -228,6 +228,7 @@ static int ctcu_probe(struct platform_device *pdev)
> desc.dev = dev;
> desc.ops = &ctcu_ops;
> desc.access = CSDEV_ACCESS_IOMEM(base);
> + raw_spin_lock_init(&drvdata->spin_lock);
>
> drvdata->csdev = coresight_register(&desc);
> if (IS_ERR(drvdata->csdev))
>
> ---
> base-commit: 44982d352c33767cd8d19f8044e7e1161a587ff7
> change-id: 20260219-fix-spin-lock-issue-c563c32c5441
>
> Best regards,
Reviewed-by: James Clark <james.clark(a)linaro.org>
I checked the other ones and they're all initialized, this was the only
missing one.
OpenCSD has been released at version 1.8.0
This includes:-
- Support for FEAT_S!PE01.
- Support for additional Arm V8M class instructions.
- Support for windows build with ARM64 tools.
- Build fixes for later CLANG versions.
- Other minor build updates & fixes.
Regards
Mike
This series is to fix and refactor CoreSight device registration and
unregistration, it can be divided into three small parts:
Patches 01-03: Three fixes for memory leak, device reference and mutex
protection.
Patches 04-05: Move connection cleanup operations into
coresight_remove_conns().
Patches 06-08: Refactor error handling in coresight_register().
This series is verified on Juno board with kmemleak detector.
For kmemleak verifying:
echo clear > /sys/kernel/debug/kmemleak
insmod coresight modules
rmmod coresight modules
echo scan > /sys/kernel/debug/kmemleak
The result shows no memory leak during a cycle of device registration
and unregistration.
---
Changes in v3:
- Updated patch 01 to use coesight core layer for device index list
(Suzuki).
- Link to v2: https://lore.kernel.org/r/20260126-arm_coresight_refactor_dev_register-v2-0…
Changes in v2:
- Refined the commit log in patch 06 (Suzuki).
- Unified to call coresight_unregister() for error handling (Suzuki).
- Refactor connection and sysfs group release.
- Link to v1: https://lore.kernel.org/linux-arm-kernel/20250512154108.23920-1-leo.yan@arm…
To: Suzuki K Poulose <suzuki.poulose(a)arm.com>
To: Mike Leach <mike.leach(a)arm.com>
To: James Clark <james.clark(a)linaro.org>
To: Alexander Shishkin <alexander.shishkin(a)linux.intel.com>
To: Greg Kroah-Hartman <gregkh(a)linuxfoundation.org>
To: Mathieu Poirier <mathieu.poirier(a)linaro.org>
To: Mao Jinlong <quic_jinlmao(a)quicinc.com>
Cc: coresight(a)lists.linaro.org
Cc: linux-arm-kernel(a)lists.infradead.org
Cc: linux-kernel(a)vger.kernel.org
Signed-off-by: Leo Yan <leo.yan(a)arm.com>
---
Leo Yan (8):
coresight: Fix memory leak in coresight_alloc_device_name()
coresight: Get parent device reference after sink ID map allocation
coresight: Protect unregistration with mutex
coresight: Refactor output connection sysfs link cleanup
coresight: Refactor sysfs connection group cleanup
coresight: Move sink validation into etm_perf_add_symlink_sink()
coresight: Do not mix success path with failure handling
coresight: Unify error handling in coresight_register()
drivers/hwtracing/coresight/coresight-catu.c | 4 +-
drivers/hwtracing/coresight/coresight-core.c | 230 +++++++++++++--------
drivers/hwtracing/coresight/coresight-ctcu-core.c | 4 +-
drivers/hwtracing/coresight/coresight-cti-core.c | 19 +-
drivers/hwtracing/coresight/coresight-dummy.c | 7 +-
drivers/hwtracing/coresight/coresight-etb10.c | 4 +-
drivers/hwtracing/coresight/coresight-etm-perf.c | 5 +-
drivers/hwtracing/coresight/coresight-funnel.c | 4 +-
drivers/hwtracing/coresight/coresight-platform.c | 2 +-
drivers/hwtracing/coresight/coresight-priv.h | 3 +-
drivers/hwtracing/coresight/coresight-replicator.c | 4 +-
drivers/hwtracing/coresight/coresight-stm.c | 4 +-
drivers/hwtracing/coresight/coresight-tmc-core.c | 12 +-
drivers/hwtracing/coresight/coresight-tnoc.c | 4 +-
drivers/hwtracing/coresight/coresight-tpda.c | 4 +-
drivers/hwtracing/coresight/coresight-tpdm.c | 4 +-
drivers/hwtracing/coresight/coresight-tpiu.c | 4 +-
drivers/hwtracing/coresight/ultrasoc-smb.c | 4 +-
include/linux/coresight.h | 14 +-
19 files changed, 175 insertions(+), 161 deletions(-)
---
base-commit: eebe8dbd8630f51cf70b1f68a440cd3d7f7a914d
change-id: 20260120-arm_coresight_refactor_dev_register-f16c069db41d
Best regards,
--
Leo Yan <leo.yan(a)arm.com>
On 03/02/2026 09:36, Konrad Dybcio wrote:
> On 2/3/26 10:31 AM, Suzuki K Poulose wrote:
>> On 03/02/2026 09:00, Jie Gan wrote:
>>>
>>>
>>> On 2/3/2026 4:50 PM, Konrad Dybcio wrote:
>>>> On 2/3/26 9:08 AM, Jie Gan wrote:
>>>>> Document the platforms that fallback to using the qcom,sa8775p-ctcu
>>>>> compatible for probing.
>>>>>
>>>>> Signed-off-by: Jie Gan <jie.gan(a)oss.qualcomm.com>
>>>>> ---
>>>>> Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml | 4 ++++
>>>>> 1 file changed, 4 insertions(+)
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight- ctcu.yaml b/Documentation/devicetree/bindings/arm/qcom,coresight- ctcu.yaml
>>>>> index e002f87361ad..68853db52bef 100644
>>>>> --- a/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml
>>>>> +++ b/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml
>>>>> @@ -29,6 +29,10 @@ properties:
>>>>> oneOf:
>>>>> - items:
>>>>> - enum:
>>>>> + - qcom,glymur-ctcu
>>>>> + - qcom,hamoa-ctcu
>>>>> + - qcom,kaanapali-ctcu
>>>>> + - qcom,pakala-ctcu
>>>>
>>>> Platforms with existing numeric compatibles should continue to use them,
>>>> so that the mess is somewhat containable
>>>
>>> Sure Konrad. So for Pakala, I will change it back to qcom,sm8750-ctcu
>>
>> Why do we need different compatibles for the others ? Are they not all compliant to the CTCU programming model ? i.e., sa8775p-ctcu ? or even,
>> a generic,
>>
>> qcom,coresight-ctcu
>
> It's a huge anti-pattern with the DT maintainers, since a compatible is
> the only way to effectively differentiate different implementations (i.e.
> instances on different SoCs) of an IP block
Do you mean, same IP block integrated to different SoC ? Or are they
different implementations altogether ? Why are these not applicable for
other components ? (e.g., Tnoc, I-Tnoc, TPDA, TPDM etc ?)
>
> This is important for the case where a DTB is shipped as part of firmware
> and can not be replaced - if some quirk needs to be applied retroactively,
> we can look for "qcom,glymur-ctcu" without affecting all the 50 other'
> users of the effectively-identical IP block
Fair enough, thank for the explanation.
Kind regards
Suzuki
>
> In this case, we're already reducing the impact on the driver, as that
> only looks for the single fallback compatible (qcom,sa8775p-ctcu)
>
> Konrad
On 03/02/2026 09:00, Jie Gan wrote:
>
>
> On 2/3/2026 4:50 PM, Konrad Dybcio wrote:
>> On 2/3/26 9:08 AM, Jie Gan wrote:
>>> Document the platforms that fallback to using the qcom,sa8775p-ctcu
>>> compatible for probing.
>>>
>>> Signed-off-by: Jie Gan <jie.gan(a)oss.qualcomm.com>
>>> ---
>>> Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml | 4
>>> ++++
>>> 1 file changed, 4 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/arm/qcom,coresight-
>>> ctcu.yaml b/Documentation/devicetree/bindings/arm/qcom,coresight-
>>> ctcu.yaml
>>> index e002f87361ad..68853db52bef 100644
>>> --- a/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml
>>> +++ b/Documentation/devicetree/bindings/arm/qcom,coresight-ctcu.yaml
>>> @@ -29,6 +29,10 @@ properties:
>>> oneOf:
>>> - items:
>>> - enum:
>>> + - qcom,glymur-ctcu
>>> + - qcom,hamoa-ctcu
>>> + - qcom,kaanapali-ctcu
>>> + - qcom,pakala-ctcu
>>
>> Platforms with existing numeric compatibles should continue to use them,
>> so that the mess is somewhat containable
>
> Sure Konrad. So for Pakala, I will change it back to qcom,sm8750-ctcu
Why do we need different compatibles for the others ? Are they not all
compliant to the CTCU programming model ? i.e., sa8775p-ctcu ? or even,
a generic,
qcom,coresight-ctcu
Suzuki
>
> Thanks,
> Jie
>
>>
>> Konrad
>
Hello
On 02/02/2026 05:09, Kuan-Wei Chiu wrote:
> On Tue, Dec 02, 2025 at 09:26:19AM +0000, James Clark wrote:
>>
>>
>> On 02/12/2025 8:26 am, Kuan-Wei Chiu wrote:
>>> The cntr_val_show() function was intended to print the values of all
>>> counters using a loop. However, due to a buffer overwrite issue with
>>> sprintf(), it effectively only displayed the value of the last counter.
>>>
>>> The companion function, cntr_val_store(), allows users to modify a
>>> specific counter selected by 'cntr_idx'. To maintain consistency
>>> between read and write operations and to align with the ETM4x driver
>>> behavior, modify cntr_val_show() to report only the value of the
>>> currently selected counter.
>>>
>>> This change removes the loop and the "counter %d:" prefix, printing
>>> only the hexadecimal value. It also adopts sysfs_emit() for standard
>>> sysfs output formatting.
>>>
>>> Fixes: a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")
>>> Cc: stable(a)vger.kernel.org
>>> Signed-off-by: Kuan-Wei Chiu <visitorckw(a)gmail.com>
>>> ---
>>> Build test only.
>>>
>>> Changes in v3:
>>> - Switch format specifier to %#x to include the 0x prefix.
>>> - Add Cc stable
>>>
>>> v2: https://lore.kernel.org/lkml/20251201095228.1905489-1-visitorckw@gmail.com/
>>>
>>> .../hwtracing/coresight/coresight-etm3x-sysfs.c | 15 ++++-----------
>>> 1 file changed, 4 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
>>> index 762109307b86..b3c67e96a82a 100644
>>> --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
>>> +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
>>> @@ -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);
>>> + } else {
>>> + val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));
>>> }
>>> - return ret;
>>> + return sysfs_emit(buf, "%#x\n", val);
>>> }
>>> static ssize_t cntr_val_store(struct device *dev,
>>
>> Reviewed-by: James Clark <james.clark(a)linaro.org>
>>
> Thanks for the review!
> Is there anything else I need to do for this fix to land?
Thanks for the patch, I will queue this for the next release (v7.1).
Suzuki
>
> Regards,
> Kuan-Wei
>
Kconfig symbols must not include the CONFIG_ prefix. Remove the CONFIG_
prefix for default values to work.
The STM_PROTO_SYS_T config is selected by default when STM is enabled.
However, its description currently says "If you don't know what this is,
say N," which contradicts the default behavior. Update the description
to say "Y" to align with the default setting.
Fixes: a02509f301c6 ("stm class: Factor out default framing protocol")
Fixes: d69d5e83110f ("stm class: Add MIPI SyS-T protocol support")
Signed-off-by: Leo Yan <leo.yan(a)arm.com>
---
Changes in v2:
- Updated STM_PROTO_BASIC description to align with default selection
(James).
- Link to v1: https://lore.kernel.org/r/20251217-fix_stm_kconfig-v1-1-531fb3674549@arm.com
---
drivers/hwtracing/stm/Kconfig | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/hwtracing/stm/Kconfig b/drivers/hwtracing/stm/Kconfig
index eda6b11d40a1f9ab49a1ec1e6faae8ee178c5ed3..8ab079785189052945521e9b0a93a0d458de37e0 100644
--- a/drivers/hwtracing/stm/Kconfig
+++ b/drivers/hwtracing/stm/Kconfig
@@ -13,7 +13,7 @@ if STM
config STM_PROTO_BASIC
tristate "Basic STM framing protocol driver"
- default CONFIG_STM
+ default STM
help
This is a simple framing protocol for sending data over STM
devices. This was the protocol that the STM framework used
@@ -28,7 +28,7 @@ config STM_PROTO_BASIC
config STM_PROTO_SYS_T
tristate "MIPI SyS-T STM framing protocol driver"
- default CONFIG_STM
+ default STM
help
This is an implementation of MIPI SyS-T protocol to be used
over the STP transport. In addition to the data payload, it
@@ -38,7 +38,7 @@ config STM_PROTO_SYS_T
The receiving side must be able to decode this protocol in
addition to the MIPI STP, in order to extract the data.
- If you don't know what this is, say N.
+ If you don't know what this is, say Y.
config STM_DUMMY
tristate "Dummy STM driver"
---
base-commit: fcb70a56f4d81450114034b2c61f48ce7444a0e2
change-id: 20251216-fix_stm_kconfig-a72f40c7612c
Best regards,
--
Leo Yan <leo.yan(a)arm.com>